Skip to content

Commit

Permalink
refactor: always pass root into loadConfig
Browse files Browse the repository at this point in the history
  • Loading branch information
apaleslimghost committed Nov 8, 2024
1 parent d9d7a77 commit a22b46c
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 14 deletions.
14 changes: 6 additions & 8 deletions core/cli/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down Expand Up @@ -139,14 +137,14 @@ export function validateConfig(config: ValidPluginsConfig): ValidConfig {
return validConfig
}

export function loadConfig(logger: Logger, options?: { validate?: true; root?: string }): Promise<ValidConfig>
export function loadConfig(logger: Logger, options?: { validate?: false; root?: string }): Promise<RawConfig>
export function loadConfig(logger: Logger, options: { validate?: true; root: string }): Promise<ValidConfig>
export function loadConfig(logger: Logger, options: { validate?: false; root: string }): Promise<RawConfig>

export async function loadConfig(
logger: Logger,
{ validate = true, root }: { validate?: boolean; root?: string } = {}
{ validate = true, root }: { validate?: boolean; root: string }
): Promise<ValidConfig | RawConfig> {
const config = createConfig()
const config = createConfig(root)

// start loading config and child plugins, starting from the consumer app directory
const rootPlugin = await loadPlugin(
Expand Down
2 changes: 1 addition & 1 deletion core/cli/src/help.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ const formatHooks = (config: ValidConfig) =>
)

export default async function showHelp(logger: Logger, commands: string[]): Promise<void> {
const config = await loadConfig(logger)
const config = await loadConfig(logger, { root: process.cwd() })
const printAllCommands = commands.length === 0

if (printAllCommands) {
Expand Down
4 changes: 2 additions & 2 deletions core/cli/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export { runTasks } from './tasks'
export { shouldDisableNativeFetch } from './fetch'

export async function listPlugins(logger: Logger): Promise<void> {
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) {
Expand All @@ -16,7 +16,7 @@ export async function listPlugins(logger: Logger): Promise<void> {
}

export async function printConfig(logger: Logger): Promise<void> {
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 }))
}
2 changes: 1 addition & 1 deletion core/cli/src/install.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ export async function checkInstall(logger: Logger, config: ValidConfig): Promise
}

export default async function installHooks(logger: Logger): Promise<ValidConfig> {
const config = await loadConfig(logger)
const config = await loadConfig(logger, { root: process.cwd() })

for (const pluginOptions of Object.values(config.pluginOptions)) {
if (pluginOptions.forPlugin) {
Expand Down
2 changes: 1 addition & 1 deletion core/cli/src/tasks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ ${error.details}`
}

export async function runTasks(logger: Logger, commands: string[], files?: string[]): Promise<void> {
const config = await loadConfig(logger)
const config = await loadConfig(logger, { root: process.cwd() })

return runTasksFromConfig(logger, config, commands, files)
}
2 changes: 1 addition & 1 deletion core/create/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 })
Expand Down

0 comments on commit a22b46c

Please sign in to comment.