Skip to content

Commit

Permalink
fix(core): new and migrate commands should exit with code (#10491)
Browse files Browse the repository at this point in the history
  • Loading branch information
Coly010 committed May 27, 2022
1 parent 7aec02e commit affa979
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 6 deletions.
23 changes: 21 additions & 2 deletions e2e/workspace-create/src/create-nx-workspace.test.ts
Expand Up @@ -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';
Expand Down Expand Up @@ -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 `<char>-<num>-<char>`
// 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',
Expand Down
12 changes: 8 additions & 4 deletions packages/nx/src/command-line/nx-commands.ts
Expand Up @@ -293,17 +293,21 @@ ${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)
);
},
})
.command(
'_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);
Expand Down

1 comment on commit affa979

@vercel
Copy link

@vercel vercel bot commented on affa979 May 27, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

nx-dev – ./

nx-five.vercel.app
nx-dev-git-master-nrwl.vercel.app
nx-dev-nrwl.vercel.app
nx.dev

Please sign in to comment.