diff --git a/packages/cli/src/commands/add/codegen/add-codegen.ts b/packages/cli/src/commands/add/codegen/add-codegen.ts index 4a4884b265..fc4c156622 100644 --- a/packages/cli/src/commands/add/codegen/add-codegen.ts +++ b/packages/cli/src/commands/add/codegen/add-codegen.ts @@ -1,4 +1,4 @@ -import { log, note, outro, spinner } from '@clack/prompts'; +import { cancel, log, note, outro, spinner } from '@clack/prompts'; import path from 'path'; import { StructureKind } from 'ts-morph'; @@ -51,6 +51,14 @@ async function addCodegen(options?: AddCodegenOptions): Promise((resolve, reject) => { const packageManager = this.determinePackageManager(); @@ -99,6 +157,12 @@ export class PackageJson { } args = args.concat(dependencies); + } else if (packageManager === 'pnpm') { + command = 'pnpm'; + args = ['add', '--save-exact'].concat(dependencies); + if (isDev) { + args.push('--save-dev', '--workspace-root'); + } } else { command = 'npm'; args = ['install', '--save', '--save-exact', '--loglevel', 'error'].concat(dependencies); @@ -106,7 +170,7 @@ export class PackageJson { args.push('--save-dev'); } } - const child = spawn(command, args, { stdio: 'ignore' }); + const child = spawn(command, args, { stdio: 'inherit' }); child.on('close', code => { if (code !== 0) { const message = 'An error occurred when installing dependencies.'; diff --git a/packages/cli/src/shared/shared-prompts.ts b/packages/cli/src/shared/shared-prompts.ts index 44bd5654ef..a702ee91f8 100644 --- a/packages/cli/src/shared/shared-prompts.ts +++ b/packages/cli/src/shared/shared-prompts.ts @@ -3,7 +3,7 @@ import { ClassDeclaration, Project } from 'ts-morph'; import { addServiceCommand } from '../commands/add/service/add-service'; import { Messages } from '../constants'; -import { getPluginClasses, getTsMorphProject } from '../utilities/ast-utils'; +import { getPluginClasses, getTsMorphProject, selectTsConfigFile } from '../utilities/ast-utils'; import { pauseForPromptDisplay } from '../utilities/utils'; import { EntityRef } from './entity-ref'; @@ -20,9 +20,10 @@ export async function analyzeProject(options: { if (!providedVendurePlugin) { const projectSpinner = spinner(); + const tsConfigFile = await selectTsConfigFile(); projectSpinner.start('Analyzing project...'); await pauseForPromptDisplay(); - const { project: _project, tsConfigPath: _tsConfigPath } = await getTsMorphProject(); + const { project: _project, tsConfigPath: _tsConfigPath } = await getTsMorphProject({}, tsConfigFile); project = _project; tsConfigPath = _tsConfigPath; projectSpinner.stop('Project analyzed'); diff --git a/packages/cli/src/utilities/ast-utils.ts b/packages/cli/src/utilities/ast-utils.ts index 7f7780363c..4a3873540d 100644 --- a/packages/cli/src/utilities/ast-utils.ts +++ b/packages/cli/src/utilities/ast-utils.ts @@ -29,8 +29,8 @@ export async function selectTsConfigFile() { return selectedConfigFile as string; } -export async function getTsMorphProject(options: ProjectOptions = {}) { - const tsConfigFile = await selectTsConfigFile(); +export async function getTsMorphProject(options: ProjectOptions = {}, providedTsConfigPath?: string) { + const tsConfigFile = providedTsConfigPath ?? (await selectTsConfigFile()); const tsConfigPath = path.join(process.cwd(), tsConfigFile); if (!fs.existsSync(tsConfigPath)) { throw new Error('No tsconfig.json found in current directory');