fix(workspace): delegate to local ng script to allow customization
This commit is contained in:
parent
429e25b07d
commit
82ee4f10ba
@ -89,8 +89,9 @@ describe('Affected', () => {
|
||||
const build = runCommand(
|
||||
`npm run affected:build -- --files="libs/${mylib}/src/index.ts"`
|
||||
);
|
||||
expect(build).toContain(`Running build for ${mypublishablelib}`);
|
||||
expect(build).toContain(`Running build for ${myapp}`);
|
||||
expect(build).toContain(
|
||||
`Running build for projects:\n ${myapp},\n ${mypublishablelib}`
|
||||
);
|
||||
expect(build).not.toContain('is not registered with the build command');
|
||||
expect(build).not.toContain('with flags:');
|
||||
|
||||
@ -108,14 +109,18 @@ describe('Affected', () => {
|
||||
const buildExcluded = runCommand(
|
||||
`npm run affected:build -- --files="libs/${mylib}/src/index.ts" --exclude ${myapp}`
|
||||
);
|
||||
expect(buildExcluded).toContain(`Running build for ${mypublishablelib}`);
|
||||
expect(buildExcluded).toContain(
|
||||
`Running build for projects:\n ${mypublishablelib}`
|
||||
);
|
||||
|
||||
// affected:build should pass non-nx flags to the CLI
|
||||
const buildWithFlags = runCommand(
|
||||
`npm run affected:build -- --files="libs/${mylib}/src/index.ts" --stats-json`
|
||||
);
|
||||
expect(buildWithFlags).toContain(`Running build for ${mypublishablelib}`);
|
||||
expect(buildWithFlags).toContain(`Running build for ${myapp}`);
|
||||
|
||||
expect(buildWithFlags).toContain(
|
||||
`Running build for projects:\n ${myapp},\n ${mypublishablelib}`
|
||||
);
|
||||
expect(buildWithFlags).toContain('With flags: --stats-json=true');
|
||||
|
||||
if (!runsInWSL()) {
|
||||
@ -128,9 +133,9 @@ describe('Affected', () => {
|
||||
const unitTests = runCommand(
|
||||
`npm run affected:test -- --files="libs/${mylib}/src/index.ts"`
|
||||
);
|
||||
expect(unitTests).toContain(`Running test for ${mylib}`);
|
||||
expect(unitTests).toContain(`Running test for ${mypublishablelib}`);
|
||||
expect(unitTests).toContain(`Running test for ${myapp}`);
|
||||
expect(unitTests).toContain(
|
||||
`Running test for projects:\n ${mylib},\n ${myapp},\n ${mypublishablelib}`
|
||||
);
|
||||
|
||||
// Fail a Unit Test
|
||||
updateFile(
|
||||
@ -144,10 +149,9 @@ describe('Affected', () => {
|
||||
const failedTests = runCommand(
|
||||
`npm run affected:test -- --files="libs/${mylib}/src/index.ts"`
|
||||
);
|
||||
|
||||
expect(failedTests).toContain(`Running test for ${mylib}`);
|
||||
expect(failedTests).toContain(`Running test for ${mypublishablelib}`);
|
||||
expect(failedTests).toContain(`Running test for ${myapp}`);
|
||||
expect(failedTests).toContain(
|
||||
`Running test for projects:\n ${mylib},\n ${mypublishablelib},\n ${myapp}`
|
||||
);
|
||||
expect(failedTests).toContain(`Failed projects: ${myapp}`);
|
||||
expect(failedTests).toContain(
|
||||
'You can isolate the above projects by passing --only-failed'
|
||||
@ -173,15 +177,14 @@ describe('Affected', () => {
|
||||
const isolatedTests = runCommand(
|
||||
`npm run affected:test -- --files="libs/${mylib}/src/index.ts" --only-failed`
|
||||
);
|
||||
expect(isolatedTests).toContain(`Running test for ${myapp}`);
|
||||
expect(isolatedTests).toContain(`Running test for projects:\n ${myapp}`);
|
||||
|
||||
const linting = runCommand(
|
||||
`npm run affected:lint -- --files="libs/${mylib}/src/index.ts"`
|
||||
);
|
||||
expect(linting).toContain(`Running lint for ${mylib}`);
|
||||
expect(linting).toContain(`Running lint for ${myapp}`);
|
||||
expect(linting).toContain(`Running lint for ${myapp}-e2e`);
|
||||
expect(linting).toContain(`Running lint for ${mypublishablelib}`);
|
||||
expect(linting).toContain(
|
||||
`Running lint for projects:\n ${mylib},\n ${myapp},\n ${myapp}-e2e,\n ${mypublishablelib}`
|
||||
);
|
||||
|
||||
const lintWithJsonFormating = runCommand(
|
||||
`npm run affected:lint -- --files="libs/${mylib}/src/index.ts" -- --format json`
|
||||
@ -191,12 +194,14 @@ describe('Affected', () => {
|
||||
const unitTestsExcluded = runCommand(
|
||||
`npm run affected:test -- --files="libs/${mylib}/src/index.ts" --exclude=${myapp},${mypublishablelib}`
|
||||
);
|
||||
expect(unitTestsExcluded).toContain(`Running test for ${mylib}`);
|
||||
expect(unitTestsExcluded).toContain(
|
||||
`Running test for projects:\n ${mylib}`
|
||||
);
|
||||
|
||||
const i18n = runCommand(
|
||||
`npm run affected -- --target extract-i18n --files="libs/${mylib}/src/index.ts"`
|
||||
);
|
||||
expect(i18n).toContain(`Running extract-i18n for ${myapp}`);
|
||||
expect(i18n).toContain(`Running extract-i18n for projects:\n ${myapp}`);
|
||||
|
||||
const interpolatedTests = runCommand(
|
||||
`npm run affected -- --target test --files="libs/${mylib}/src/index.ts" -- --jest-config {project.root}/jest.config.js`
|
||||
|
||||
@ -171,99 +171,65 @@ async function runCommand(
|
||||
projects.forEach(project => {
|
||||
projectMetadata.set(project, angularJson.projects[project]);
|
||||
});
|
||||
if (parsedArgs.parallel) {
|
||||
// Make sure the `package.json` has the `ng: "ng"` command needed by `npm-run-all`
|
||||
const packageJson = JSON.parse(
|
||||
fs.readFileSync('./package.json').toString('utf-8')
|
||||
|
||||
// Make sure the `package.json` has the `ng: "ng"` command needed by `npm-run-all`
|
||||
const packageJson = JSON.parse(
|
||||
fs.readFileSync('./package.json').toString('utf-8')
|
||||
);
|
||||
if (!packageJson.scripts || !packageJson.scripts.ng) {
|
||||
console.error(
|
||||
'\nError: Your `package.json` file should contain the `ng: "ng"` command in the `scripts` section.\n'
|
||||
);
|
||||
if (!packageJson.scripts || !packageJson.scripts.ng) {
|
||||
console.error(
|
||||
'\nError: Your `package.json` file should contain the `ng: "ng"` command in the `scripts` section.\n'
|
||||
);
|
||||
return process.exit(1);
|
||||
}
|
||||
try {
|
||||
await runAll(
|
||||
projects.map(app => {
|
||||
return ngCommands.includes(command)
|
||||
? `ng ${command} --project=${app} ${transformArgs(
|
||||
args,
|
||||
app,
|
||||
projectMetadata.get(app)
|
||||
).join(' ')} `
|
||||
: `ng run ${app}:${command} ${transformArgs(
|
||||
args,
|
||||
app,
|
||||
projectMetadata.get(app)
|
||||
).join(' ')} `;
|
||||
}),
|
||||
{
|
||||
parallel: parsedArgs.parallel,
|
||||
maxParallel: parsedArgs.maxParallel,
|
||||
continueOnError: true,
|
||||
stdin: process.stdin,
|
||||
stdout: process.stdout,
|
||||
stderr: process.stderr
|
||||
}
|
||||
);
|
||||
projects.forEach(project => {
|
||||
workspaceResults.success(project);
|
||||
});
|
||||
} catch (e) {
|
||||
e.results.forEach((result, i) => {
|
||||
if (result.code === 0) {
|
||||
workspaceResults.success(projects[i]);
|
||||
} else {
|
||||
workspaceResults.fail(projects[i]);
|
||||
}
|
||||
});
|
||||
}
|
||||
workspaceResults.saveResults();
|
||||
workspaceResults.printResults(
|
||||
parsedArgs.onlyFailed,
|
||||
successMessage,
|
||||
errorMessage
|
||||
return process.exit(1);
|
||||
}
|
||||
|
||||
try {
|
||||
await runAll(
|
||||
projects.map(app => {
|
||||
return ngCommands.includes(command)
|
||||
? `ng -- ${command} --project=${app} ${transformArgs(
|
||||
args,
|
||||
app,
|
||||
projectMetadata.get(app)
|
||||
).join(' ')} `
|
||||
: `ng -- run ${app}:${command} ${transformArgs(
|
||||
args,
|
||||
app,
|
||||
projectMetadata.get(app)
|
||||
).join(' ')} `;
|
||||
}),
|
||||
{
|
||||
parallel: parsedArgs.parallel || false,
|
||||
maxParallel: parsedArgs.maxParallel || 1,
|
||||
continueOnError: true,
|
||||
stdin: process.stdin,
|
||||
stdout: process.stdout,
|
||||
stderr: process.stderr
|
||||
}
|
||||
);
|
||||
|
||||
if (workspaceResults.hasFailure) {
|
||||
process.exit(1);
|
||||
}
|
||||
} else {
|
||||
let failedProjects = [];
|
||||
projects.forEach(project => {
|
||||
console.log(`${iterationMessage} ${project}`);
|
||||
const task = ngCommands.includes(command)
|
||||
? `node ${ngPath()} ${command} --project=${project} ${transformArgs(
|
||||
args,
|
||||
project,
|
||||
projectMetadata.get(project)
|
||||
).join(' ')} `
|
||||
: `node ${ngPath()} run ${project}:${command} ${transformArgs(
|
||||
args,
|
||||
project,
|
||||
projectMetadata.get(project)
|
||||
).join(' ')} `;
|
||||
try {
|
||||
execSync(task, {
|
||||
stdio: [0, 1, 2]
|
||||
});
|
||||
workspaceResults.success(project);
|
||||
} catch (e) {
|
||||
failedProjects.push(project);
|
||||
workspaceResults.fail(project);
|
||||
workspaceResults.success(project);
|
||||
});
|
||||
} catch (e) {
|
||||
e.results.forEach((result, i) => {
|
||||
if (result.code === 0) {
|
||||
workspaceResults.success(projects[i]);
|
||||
} else {
|
||||
workspaceResults.fail(projects[i]);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
workspaceResults.saveResults();
|
||||
workspaceResults.printResults(
|
||||
parsedArgs.onlyFailed,
|
||||
successMessage,
|
||||
errorMessage
|
||||
);
|
||||
workspaceResults.saveResults();
|
||||
workspaceResults.printResults(
|
||||
parsedArgs.onlyFailed,
|
||||
successMessage,
|
||||
errorMessage
|
||||
);
|
||||
|
||||
if (workspaceResults.hasFailure) {
|
||||
process.exit(1);
|
||||
}
|
||||
if (workspaceResults.hasFailure) {
|
||||
process.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user