From af41ab32eb2ee9cbbab0f19c26a0b7b14f8c2ac2 Mon Sep 17 00:00:00 2001 From: Kara Brightwell Date: Fri, 8 Nov 2024 09:15:50 +0000 Subject: [PATCH] refactor: always pass root into loadConfig --- core/cli/src/config.ts | 14 ++++++-------- core/cli/src/help.ts | 2 +- core/cli/src/index.ts | 4 ++-- core/cli/src/install.ts | 2 +- core/cli/src/tasks.ts | 2 +- core/create/src/index.ts | 2 +- 6 files changed, 12 insertions(+), 14 deletions(-) diff --git a/core/cli/src/config.ts b/core/cli/src/config.ts index ff4bebc6c..9eab24e9d 100644 --- a/core/cli/src/config.ts +++ b/core/cli/src/config.ts @@ -24,10 +24,8 @@ import { import { validatePlugins } from './config/validate-plugins' import { substituteOptionTags, validatePluginOptions } from './plugin/options' -const coreRoot = path.resolve(__dirname, '../') - -export const createConfig = (): RawConfig => ({ - root: coreRoot, +export const createConfig = (root: string): RawConfig => ({ + root, plugins: {}, resolutionTrackers: { resolvedPluginOptions: new Set(), @@ -139,14 +137,14 @@ export function validateConfig(config: ValidPluginsConfig): ValidConfig { return validConfig } -export function loadConfig(logger: Logger, options?: { validate?: true; root?: string }): Promise -export function loadConfig(logger: Logger, options?: { validate?: false; root?: string }): Promise +export function loadConfig(logger: Logger, options: { validate?: true; root: string }): Promise +export function loadConfig(logger: Logger, options: { validate?: false; root: string }): Promise export async function loadConfig( logger: Logger, - { validate = true, root }: { validate?: boolean; root?: string } = {} + { validate = true, root }: { validate?: boolean; root: string } ): Promise { - const config = createConfig() + const config = createConfig(root) // start loading config and child plugins, starting from the consumer app directory const rootPlugin = await loadPlugin( diff --git a/core/cli/src/help.ts b/core/cli/src/help.ts index 744bc8f2b..52914c8f7 100644 --- a/core/cli/src/help.ts +++ b/core/cli/src/help.ts @@ -78,7 +78,7 @@ const formatHooks = (config: ValidConfig) => ) export default async function showHelp(logger: Logger, commands: string[]): Promise { - const config = await loadConfig(logger) + const config = await loadConfig(logger, { root: process.cwd() }) const printAllCommands = commands.length === 0 if (printAllCommands) { diff --git a/core/cli/src/index.ts b/core/cli/src/index.ts index 617101838..cc0049bef 100644 --- a/core/cli/src/index.ts +++ b/core/cli/src/index.ts @@ -7,7 +7,7 @@ export { runTasks } from './tasks' export { shouldDisableNativeFetch } from './fetch' export async function listPlugins(logger: Logger): Promise { - const config = await loadConfig(logger, { validate: false }) + const config = await loadConfig(logger, { validate: false, root: process.cwd() }) const rootPlugin = config.plugins['app root'] if (rootPlugin?.valid) { @@ -16,7 +16,7 @@ export async function listPlugins(logger: Logger): Promise { } export async function printConfig(logger: Logger): Promise { - const config = await loadConfig(logger, { validate: false }) + const config = await loadConfig(logger, { validate: false, root: process.cwd() }) logger.info(util.inspect(config, { depth: null, colors: true })) } diff --git a/core/cli/src/install.ts b/core/cli/src/install.ts index 95f14ac30..f8424faf8 100644 --- a/core/cli/src/install.ts +++ b/core/cli/src/install.ts @@ -115,7 +115,7 @@ export async function checkInstall(logger: Logger, config: ValidConfig): Promise } export default async function installHooks(logger: Logger): Promise { - const config = await loadConfig(logger) + const config = await loadConfig(logger, { root: process.cwd() }) for (const pluginOptions of Object.values(config.pluginOptions)) { if (pluginOptions.forPlugin) { diff --git a/core/cli/src/tasks.ts b/core/cli/src/tasks.ts index b65bbf503..6bf5f2b9b 100644 --- a/core/cli/src/tasks.ts +++ b/core/cli/src/tasks.ts @@ -136,7 +136,7 @@ ${error.details}` } export async function runTasks(logger: Logger, commands: string[], files?: string[]): Promise { - const config = await loadConfig(logger) + const config = await loadConfig(logger, { root: process.cwd() }) return runTasksFromConfig(logger, config, commands, files) } diff --git a/core/create/src/index.ts b/core/create/src/index.ts index a3787e9e1..b888c2c69 100644 --- a/core/create/src/index.ts +++ b/core/create/src/index.ts @@ -155,7 +155,7 @@ async function main() { // the config to avoid any incompatibilities with a version that create might // use const { loadConfig } = importCwd('dotcom-tool-kit/lib/config') as { loadConfig: typeof loadConfigType } - const config = await loadConfig(winstonLogger, { validate: false }) + const config = await loadConfig(winstonLogger, { validate: false, root: process.cwd() }) // Give the user a chance to set any configurable options for the plugins // they've installed. const optionsCancelled = await optionsPrompt({ logger, config, toolKitConfig, configPath, bizOpsSystem })