From 2ab021bdc7680e194459236d66873821fb807343 Mon Sep 17 00:00:00 2001 From: Miles Johnson Date: Tue, 24 Aug 2021 17:12:13 -0700 Subject: [PATCH] new: Migrate to new @boost/module for config loading. --- packages/core/package.json | 1 + packages/core/src/Tool.ts | 6 +++--- packages/core/src/routines/CreateConfigRoutine.ts | 7 ++++--- yarn.lock | 13 +++++++++++++ 4 files changed, 21 insertions(+), 6 deletions(-) diff --git a/packages/core/package.json b/packages/core/package.json index 7b2b97af..1a45f2dc 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -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", diff --git a/packages/core/src/Tool.ts b/packages/core/src/Tool.ts index 42b908cc..f640408d 100644 --- a/packages/core/src/Tool.ts +++ b/packages/core/src/Tool.ts @@ -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'; @@ -141,7 +141,7 @@ export class Tool extends Contract { this.debug('Bootstrapping configuration module'); const { module } = this.config; - let bootstrapModule: BootstrapFile | null = null; + let bootstrapModule: ModuleLike | null = null; try { const root = this.getConfigModuleRoot(); @@ -164,7 +164,7 @@ export class Tool extends Contract { 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'); diff --git a/packages/core/src/routines/CreateConfigRoutine.ts b/packages/core/src/routines/CreateConfigRoutine.ts index c7df9c47..6690f9bb 100644 --- a/packages/core/src/routines/CreateConfigRoutine.ts +++ b/packages/core/src/routines/CreateConfigRoutine.ts @@ -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, @@ -150,7 +151,7 @@ export class CreateConfigRoutine extends Routine< } try { - template = requireModule(templatePath); + template = requireModule(templatePath).default; } catch { throw new Error( tool.msg('errors:templatePathMissing', { @@ -283,7 +284,7 @@ export class CreateConfigRoutine 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(filePath).default; if (typeof config === 'function') { throw new TypeError( diff --git a/yarn.lock b/yarn.lock index 9df2f6a3..38195f62 100644 --- a/yarn.lock +++ b/yarn.lock @@ -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 @@ -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"