From affa97964206a0d204aa74fecd34462bd952fcf9 Mon Sep 17 00:00:00 2001 From: Colum Ferry Date: Fri, 27 May 2022 21:23:40 +0100 Subject: [PATCH] fix(core): new and migrate commands should exit with code (#10491) --- .../src/create-nx-workspace.test.ts | 23 +++++++++++++++++-- packages/nx/src/command-line/nx-commands.ts | 12 ++++++---- 2 files changed, 29 insertions(+), 6 deletions(-) diff --git a/e2e/workspace-create/src/create-nx-workspace.test.ts b/e2e/workspace-create/src/create-nx-workspace.test.ts index 74f34f69b5f1f..61bd2070ddf46 100644 --- a/e2e/workspace-create/src/create-nx-workspace.test.ts +++ b/e2e/workspace-create/src/create-nx-workspace.test.ts @@ -10,9 +10,9 @@ import { readJson, runCLI, runCreateWorkspace, - updateJson, - updateFile, uniq, + updateFile, + updateJson, } from '@nrwl/e2e/utils'; import { existsSync, mkdirSync } from 'fs-extra'; import { execSync } from 'child_process'; @@ -93,9 +93,28 @@ describe('create-nx-workspace', () => { }); }); + it('should fail correctly when preset errors', () => { + // Using Angular Preset as the example here to test + // It will error when npmScope is of form `--` + // Due to a validation error Angular will throw. + const wsName = uniq('angular-1-test'); + const appName = uniq('app'); + try { + runCreateWorkspace(wsName, { + preset: 'angular', + style: 'css', + appName, + packageManager, + }); + } catch (e) { + expect(e).toBeTruthy(); + } + }); + it('should be able to create an react workspace', () => { const wsName = uniq('react'); const appName = uniq('app'); + runCreateWorkspace(wsName, { preset: 'react', style: 'css', diff --git a/packages/nx/src/command-line/nx-commands.ts b/packages/nx/src/command-line/nx-commands.ts index 79815cccb3cd0..5e93c3c00617d 100644 --- a/packages/nx/src/command-line/nx-commands.ts +++ b/packages/nx/src/command-line/nx-commands.ts @@ -293,9 +293,10 @@ ${daemonHelpOutput} builder: (yargs) => withNewOptions(yargs), handler: async (args) => { args._ = args._.slice(1); - return (await import('./generate')).newWorkspace( - args['nxWorkspaceRoot'] as string, - args + process.exit( + await ( + await import('./generate') + ).newWorkspace(args['nxWorkspaceRoot'] as string, args) ); }, }) @@ -303,7 +304,10 @@ ${daemonHelpOutput} '_migrate [packageAndVersion]', false, (yargs) => withMigrationOptions(yargs), - async (args) => (await import('./migrate')).migrate(process.cwd(), args) + async (args) => + process.exit( + await (await import('./migrate')).migrate(process.cwd(), args) + ) ) .help('help') .version(nxVersion);