diff --git a/lib/package-managers/abstract.package-manager.ts b/lib/package-managers/abstract.package-manager.ts index 982828894..4e7e65ab5 100644 --- a/lib/package-managers/abstract.package-manager.ts +++ b/lib/package-managers/abstract.package-manager.ts @@ -21,11 +21,11 @@ export abstract class AbstractPackageManager { }); spinner.start(); try { - const commandArguments = `${this.cli.install} --silent`; + const commandArgs = `${this.cli.install} ${this.cli.silentFlag}`; const collect = true; - const dasherizedDirectory: string = dasherize(directory); + const dasherizedDirectory = dasherize(directory); await this.runner.run( - commandArguments, + commandArgs, collect, join(process.cwd(), dasherizedDirectory), ); @@ -39,7 +39,15 @@ export abstract class AbstractPackageManager { console.info(); } catch { spinner.fail(); - console.error(chalk.red(MESSAGES.PACKAGE_MANAGER_INSTALLATION_FAILED)); + const commandArgs = this.cli.install; + const commandToRun = this.runner.rawFullCommand(commandArgs); + console.error( + chalk.red( + MESSAGES.PACKAGE_MANAGER_INSTALLATION_FAILED( + chalk.bold(commandToRun), + ), + ), + ); } } diff --git a/lib/package-managers/npm.package-manager.ts b/lib/package-managers/npm.package-manager.ts index 48cd04b6b..180e6fe16 100644 --- a/lib/package-managers/npm.package-manager.ts +++ b/lib/package-managers/npm.package-manager.ts @@ -21,6 +21,7 @@ export class NpmPackageManager extends AbstractPackageManager { remove: 'uninstall', saveFlag: '--save', saveDevFlag: '--save-dev', + silentFlag: '--silent', }; } } diff --git a/lib/package-managers/package-manager-commands.ts b/lib/package-managers/package-manager-commands.ts index 167b72325..06a897d69 100644 --- a/lib/package-managers/package-manager-commands.ts +++ b/lib/package-managers/package-manager-commands.ts @@ -5,4 +5,5 @@ export interface PackageManagerCommands { remove: string; saveFlag: string; saveDevFlag: string; + silentFlag: string; } diff --git a/lib/package-managers/pnpm.package-manager.ts b/lib/package-managers/pnpm.package-manager.ts index 2ef350f65..11eb8b82a 100644 --- a/lib/package-managers/pnpm.package-manager.ts +++ b/lib/package-managers/pnpm.package-manager.ts @@ -22,6 +22,7 @@ export class PnpmPackageManager extends AbstractPackageManager { remove: 'uninstall', saveFlag: '--save', saveDevFlag: '--save-dev', + silentFlag: '--reporter=silent', }; } } diff --git a/lib/package-managers/yarn.package-manager.ts b/lib/package-managers/yarn.package-manager.ts index 0cba2580f..4048e8180 100644 --- a/lib/package-managers/yarn.package-manager.ts +++ b/lib/package-managers/yarn.package-manager.ts @@ -21,6 +21,7 @@ export class YarnPackageManager extends AbstractPackageManager { remove: 'remove', saveFlag: '', saveDevFlag: '-D', + silentFlag: '--silent', }; } } diff --git a/lib/runners/abstract.runner.ts b/lib/runners/abstract.runner.ts index 31007799b..2118030c5 100644 --- a/lib/runners/abstract.runner.ts +++ b/lib/runners/abstract.runner.ts @@ -41,4 +41,13 @@ export class AbstractRunner { }); }); } + + /** + * @param command + * @returns The entire command that will be ran when calling `run(command)`. + */ + public rawFullCommand(command: string): string { + const commandArgs: string[] = [...this.args, command]; + return `${this.binary} ${commandArgs.join(' ')}`; + } } diff --git a/lib/ui/messages.ts b/lib/ui/messages.ts index 9fb7284a4..0918468e5 100644 --- a/lib/ui/messages.ts +++ b/lib/ui/messages.ts @@ -22,7 +22,8 @@ export const MESSAGES = { GET_STARTED_INFORMATION: `${EMOJIS.POINT_RIGHT} Get started with the following commands:`, CHANGE_DIR_COMMAND: (name: string) => `$ cd ${name}`, START_COMMAND: (name: string) => `$ ${name} run start`, - PACKAGE_MANAGER_INSTALLATION_FAILED: `${EMOJIS.SCREAM} Packages installation failed, see above`, + PACKAGE_MANAGER_INSTALLATION_FAILED: (commandToRunManually: string) => + `${EMOJIS.SCREAM} Packages installation failed!\nIn case you don't see any errors above, consider manually running the failed command ${commandToRunManually} to see more details on why it errored out.`, // tslint:disable-next-line:max-line-length NEST_INFORMATION_PACKAGE_MANAGER_FAILED: `${EMOJIS.SMIRK} cannot read your project package.json file, are you inside your project directory?`, LIBRARY_INSTALLATION_FAILED_BAD_PACKAGE: (name: string) => diff --git a/test/lib/package-managers/npm.package-manager.spec.ts b/test/lib/package-managers/npm.package-manager.spec.ts index 4f2456854..3c0ec2c74 100644 --- a/test/lib/package-managers/npm.package-manager.spec.ts +++ b/test/lib/package-managers/npm.package-manager.spec.ts @@ -29,6 +29,7 @@ describe('NpmPackageManager', () => { remove: 'uninstall', saveFlag: '--save', saveDevFlag: '--save-dev', + silentFlag: '--silent', }; expect(packageManager.cli).toMatchObject(expectedValues); }); diff --git a/test/lib/package-managers/pnpm.package-manager.spec.ts b/test/lib/package-managers/pnpm.package-manager.spec.ts index df0e79310..7579ef2c3 100644 --- a/test/lib/package-managers/pnpm.package-manager.spec.ts +++ b/test/lib/package-managers/pnpm.package-manager.spec.ts @@ -7,7 +7,7 @@ import { PnpmRunner } from '../../../lib/runners/pnpm.runner'; jest.mock('../../../lib/runners/pnpm.runner'); -describe('NpmPackageManager', () => { +describe('PnpmPackageManager', () => { let packageManager: PnpmPackageManager; beforeEach(() => { (PnpmRunner as any).mockClear(); @@ -29,6 +29,7 @@ describe('NpmPackageManager', () => { remove: 'uninstall', saveFlag: '--save', saveDevFlag: '--save-dev', + silentFlag: '--reporter=silent', }; expect(packageManager.cli).toMatchObject(expectedValues); }); @@ -38,7 +39,7 @@ describe('NpmPackageManager', () => { const dirName = '/tmp'; const testDir = join(process.cwd(), dirName); packageManager.install(dirName, 'pnpm'); - expect(spy).toBeCalledWith('install --silent', true, testDir); + expect(spy).toBeCalledWith('install --reporter=silent', true, testDir); }); }); describe('addProduction', () => { @@ -47,8 +48,8 @@ describe('NpmPackageManager', () => { const dependencies = ['@nestjs/common', '@nestjs/core']; const tag = '5.0.0'; const command = `install --save ${dependencies - .map((dependency) => `${dependency}@${tag}`) - .join(' ')}`; + .map((dependency) => `${dependency}@${tag}`) + .join(' ')}`; packageManager.addProduction(dependencies, tag); expect(spy).toBeCalledWith(command, true); }); @@ -59,8 +60,8 @@ describe('NpmPackageManager', () => { const dependencies = ['@nestjs/common', '@nestjs/core']; const tag = '5.0.0'; const command = `install --save-dev ${dependencies - .map((dependency) => `${dependency}@${tag}`) - .join(' ')}`; + .map((dependency) => `${dependency}@${tag}`) + .join(' ')}`; packageManager.addDevelopment(dependencies, tag); expect(spy).toBeCalledWith(command, true); }); @@ -91,8 +92,8 @@ describe('NpmPackageManager', () => { const uninstallCommand = `uninstall --save ${dependencies.join(' ')}`; const installCommand = `install --save ${dependencies - .map((dependency) => `${dependency}@${tag}`) - .join(' ')}`; + .map((dependency) => `${dependency}@${tag}`) + .join(' ')}`; return packageManager.upgradeProduction(dependencies, tag).then(() => { expect(spy.mock.calls).toEqual([ @@ -110,8 +111,8 @@ describe('NpmPackageManager', () => { const uninstallCommand = `uninstall --save-dev ${dependencies.join(' ')}`; const installCommand = `install --save-dev ${dependencies - .map((dependency) => `${dependency}@${tag}`) - .join(' ')}`; + .map((dependency) => `${dependency}@${tag}`) + .join(' ')}`; return packageManager.upgradeDevelopment(dependencies, tag).then(() => { expect(spy.mock.calls).toEqual([ diff --git a/test/lib/package-managers/yarn.package-manager.spec.ts b/test/lib/package-managers/yarn.package-manager.spec.ts index 1c25a707b..a4ae2c0fe 100644 --- a/test/lib/package-managers/yarn.package-manager.spec.ts +++ b/test/lib/package-managers/yarn.package-manager.spec.ts @@ -29,6 +29,7 @@ describe('YarnPackageManager', () => { remove: 'remove', saveFlag: '', saveDevFlag: '-D', + silentFlag: '--silent', }; expect(packageManager.cli).toMatchObject(expectedValues); });