From d871eb72277970f0c491cf2a144489e299fa2c3b Mon Sep 17 00:00:00 2001 From: Michael Bromley Date: Mon, 29 Apr 2024 11:17:31 +0200 Subject: [PATCH] fix(cli): Improve support for multiple tsconfig files --- .../cli/src/commands/add/codegen/add-codegen.ts | 7 +++---- .../commands/add/codegen/codegen-config-ref.ts | 16 +++++++--------- .../src/commands/add/plugin/create-new-plugin.ts | 4 ++-- packages/cli/src/shared/shared-prompts.ts | 2 +- packages/cli/src/utilities/ast-utils.ts | 5 +++-- 5 files changed, 16 insertions(+), 18 deletions(-) diff --git a/packages/cli/src/commands/add/codegen/add-codegen.ts b/packages/cli/src/commands/add/codegen/add-codegen.ts index 8fea3e7fba..4f0697d245 100644 --- a/packages/cli/src/commands/add/codegen/add-codegen.ts +++ b/packages/cli/src/commands/add/codegen/add-codegen.ts @@ -62,7 +62,7 @@ async function addCodegen(options?: AddCodegenOptions): Promise { if (featureType === 'no') { done = true; } else { - const newProject = getTsMorphProject(); + const newProject = await getTsMorphProject(); workingProject = newProject; const newPlugin = newProject .getSourceFile(workingPlugin.getSourceFile().getFilePath()) @@ -158,7 +158,7 @@ export async function generatePlugin( const projectSpinner = spinner(); projectSpinner.start('Generating plugin scaffold...'); await pauseForPromptDisplay(); - const project = getTsMorphProject({ skipAddingFilesFromTsConfig: true }); + const project = await getTsMorphProject({ skipAddingFilesFromTsConfig: true }); const pluginFile = createFile(project, path.join(__dirname, 'templates/plugin.template.ts')); const pluginClass = pluginFile.getClass('TemplatePlugin'); diff --git a/packages/cli/src/shared/shared-prompts.ts b/packages/cli/src/shared/shared-prompts.ts index 8aca758e52..332667f5ed 100644 --- a/packages/cli/src/shared/shared-prompts.ts +++ b/packages/cli/src/shared/shared-prompts.ts @@ -20,7 +20,7 @@ export async function analyzeProject(options: { const projectSpinner = spinner(); projectSpinner.start('Analyzing project...'); await pauseForPromptDisplay(); - project = getTsMorphProject(); + project = await getTsMorphProject(); projectSpinner.stop('Project analyzed'); } return project as Project; diff --git a/packages/cli/src/utilities/ast-utils.ts b/packages/cli/src/utilities/ast-utils.ts index e333e68a22..81c6f04330 100644 --- a/packages/cli/src/utilities/ast-utils.ts +++ b/packages/cli/src/utilities/ast-utils.ts @@ -29,8 +29,9 @@ export async function selectTsConfigFile() { return selectedConfigFile as string; } -export function getTsMorphProject(options: ProjectOptions = {}) { - const tsConfigPath = path.join(process.cwd(), 'tsconfig.json'); +export async function getTsMorphProject(options: ProjectOptions = {}) { + const tsConfigFile = await selectTsConfigFile(); + const tsConfigPath = path.join(process.cwd(), tsConfigFile); if (!fs.existsSync(tsConfigPath)) { throw new Error('No tsconfig.json found in current directory'); }