Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(core): new and migrate commands should exit with code #10491

Merged
merged 1 commit into from
May 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
23 changes: 21 additions & 2 deletions e2e/workspace-create/src/create-nx-workspace.test.ts
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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