fix(core): properly throw error when failing to read workspace (#8835)

This commit is contained in:
Jason Jean 2022-02-04 18:58:00 -05:00 committed by GitHub
parent 045c8dc9eb
commit f069d8ec71
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -15,6 +15,7 @@ import { parseRunOneOptions } from './parse-run-one-options';
process.env.NX_CLI_SET = 'true';
export function initLocal(workspace: Workspace) {
try {
performance.mark('init-local');
//nx-ignore-next-line
require('@nrwl/workspace/src/utilities/perf-logging');
@ -23,18 +24,27 @@ export function initLocal(workspace: Workspace) {
//nx-ignore-next-line
require('@nrwl/workspace/src/command-line/supported-nx-commands').supportedNxCommands;
const runOpts = runOneOptions(workspace);
const running = runOpts !== false;
if (supportedNxCommands.includes(process.argv[2])) {
// required to make sure nrwl/workspace import works
//nx-ignore-next-line
require('@nrwl/workspace/src/command-line/nx-commands').commandsObject.argv;
} else if (running) {
require('@nrwl/workspace/src/command-line/nx-commands').commandsObject
.argv;
return;
}
if (generating()) {
loadCli(workspace, '@nrwl/tao/index.js');
return;
}
const runOpts = runOneOptions(workspace);
const running = runOpts !== false;
if (running) {
//nx-ignore-next-line
require('@nrwl/workspace/src/command-line/run-one').runOne(runOpts);
} else if (generating()) {
loadCli(workspace, '@nrwl/tao/index.js');
} else {
return;
}
if (workspace.type === 'nx') {
loadCli(workspace, '@nrwl/tao/index.js');
} else {
@ -96,6 +106,9 @@ export function initLocal(workspace: Workspace) {
loadCli(workspace, '@angular/cli/lib/init.js');
}
}
} catch (e) {
console.error(e.message);
process.exit(1);
}
}
@ -112,7 +125,6 @@ function loadCli(workspace: Workspace, cliPath: string) {
function runOneOptions(
workspace: Workspace
): false | { project; target; configuration; parsedArgs } {
try {
const workspaceConfig = new Workspaces(
workspace.dir
).readWorkspaceConfiguration();
@ -122,9 +134,6 @@ function runOneOptions(
workspaceConfig,
process.argv.slice(2)
);
} catch {
return false;
}
}
function generating(): boolean {