Skip to content
This repository has been archived by the owner on Nov 9, 2022. It is now read-only.

Commit

Permalink
new: Migrate to new @boost/module for config loading.
Browse files Browse the repository at this point in the history
  • Loading branch information
milesj committed Aug 25, 2021
1 parent 0c18751 commit 2ab021b
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 6 deletions.
1 change: 1 addition & 0 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
"@boost/event": "^2.3.3",
"@boost/internal": "^2.2.3",
"@boost/log": "^2.2.8",
"@boost/module": "^2.0.0",
"@boost/pipeline": "^2.2.8",
"@boost/plugin": "^2.4.2",
"@boost/terminal": "^2.2.3",
Expand Down
6 changes: 3 additions & 3 deletions packages/core/src/Tool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ import {
PortablePath,
Predicates,
Project,
requireModule,
} from '@boost/common';
import { createDebugger, Debugger } from '@boost/debug';
import { Event } from '@boost/event';
import { color } from '@boost/internal';
import { Writable } from '@boost/log';
import { ModuleLike, requireModule } from '@boost/module';
import { WaterfallPipeline } from '@boost/pipeline';
import { Registry } from '@boost/plugin';
import { createTranslator, Translator } from '@boost/translate';
Expand Down Expand Up @@ -141,7 +141,7 @@ export class Tool extends Contract<ToolOptions> {
this.debug('Bootstrapping configuration module');

const { module } = this.config;
let bootstrapModule: BootstrapFile | null = null;
let bootstrapModule: ModuleLike<BootstrapFile, { bootstrap?: BootstrapFile }> | null = null;

try {
const root = this.getConfigModuleRoot();
Expand All @@ -164,7 +164,7 @@ export class Tool extends Contract<ToolOptions> {
return this;
}

const bootstrap = bootstrapModule?.bootstrap ?? bootstrapModule?.default ?? bootstrapModule;
const bootstrap = bootstrapModule?.bootstrap ?? bootstrapModule?.default;
const isFunction = typeof bootstrap === 'function';

this.debug.invariant(isFunction, 'Executing bootstrap function', 'Found', 'Not found');
Expand Down
7 changes: 4 additions & 3 deletions packages/core/src/routines/CreateConfigRoutine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@

import fs from 'fs-extra';
import camelCase from 'lodash/camelCase';
import { Bind, Blueprint, Path, PathResolver, Predicates, requireModule } from '@boost/common';
import { Bind, Blueprint, Path, PathResolver, Predicates } from '@boost/common';
import { color } from '@boost/internal';
import { requireModule } from '@boost/module';
import { Routine } from '@boost/pipeline';
import {
STRATEGY_COPY,
Expand Down Expand Up @@ -150,7 +151,7 @@ export class CreateConfigRoutine<Ctx extends ConfigContext> extends Routine<
}

try {
template = requireModule(templatePath);
template = requireModule<ConfigTemplate>(templatePath).default;
} catch {
throw new Error(
tool.msg('errors:templatePathMissing', {
Expand Down Expand Up @@ -283,7 +284,7 @@ export class CreateConfigRoutine<Ctx extends ConfigContext> extends Routine<
* Load a config file with passing the args and tool to the file.
*/
loadConfigAtPath(filePath: Path): ConfigObject {
const config: ConfigObject = requireModule(filePath);
const config = requireModule<ConfigObject>(filePath).default;

if (typeof config === 'function') {
throw new TypeError(
Expand Down
13 changes: 13 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1844,6 +1844,7 @@ __metadata:
"@boost/event": ^2.3.3
"@boost/internal": ^2.2.3
"@boost/log": ^2.2.8
"@boost/module": ^2.0.0
"@boost/pipeline": ^2.2.8
"@boost/plugin": ^2.4.2
"@boost/terminal": ^2.2.3
Expand Down Expand Up @@ -2169,6 +2170,18 @@ __metadata:
languageName: node
linkType: hard

"@boost/module@npm:^2.0.0":
version: 2.0.0
resolution: "@boost/module@npm:2.0.0"
peerDependencies:
typescript: ^4.0.0
peerDependenciesMeta:
typescript:
optional: true
checksum: eeb61576d3c197123b9bce3d8c329fdf1703062e6ab6a69675fe9c3589d01b26e82ef7174f83d2a046fc1e6aa065cc96efcc18d2d9284e83080bc6f4f14c0263
languageName: node
linkType: hard

"@boost/pipeline@npm:^2.2.7, @boost/pipeline@npm:^2.2.8":
version: 2.2.8
resolution: "@boost/pipeline@npm:2.2.8"
Expand Down

0 comments on commit 2ab021b

Please sign in to comment.