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(
|
const build = runCommand(
|
||||||
`npm run affected:build -- --files="libs/${mylib}/src/index.ts"`
|
`npm run affected:build -- --files="libs/${mylib}/src/index.ts"`
|
||||||
);
|
);
|
||||||
expect(build).toContain(`Running build for ${mypublishablelib}`);
|
expect(build).toContain(
|
||||||
expect(build).toContain(`Running build for ${myapp}`);
|
`Running build for projects:\n ${myapp},\n ${mypublishablelib}`
|
||||||
|
);
|
||||||
expect(build).not.toContain('is not registered with the build command');
|
expect(build).not.toContain('is not registered with the build command');
|
||||||
expect(build).not.toContain('with flags:');
|
expect(build).not.toContain('with flags:');
|
||||||
|
|
||||||
@ -108,14 +109,18 @@ describe('Affected', () => {
|
|||||||
const buildExcluded = runCommand(
|
const buildExcluded = runCommand(
|
||||||
`npm run affected:build -- --files="libs/${mylib}/src/index.ts" --exclude ${myapp}`
|
`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
|
// affected:build should pass non-nx flags to the CLI
|
||||||
const buildWithFlags = runCommand(
|
const buildWithFlags = runCommand(
|
||||||
`npm run affected:build -- --files="libs/${mylib}/src/index.ts" --stats-json`
|
`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');
|
expect(buildWithFlags).toContain('With flags: --stats-json=true');
|
||||||
|
|
||||||
if (!runsInWSL()) {
|
if (!runsInWSL()) {
|
||||||
@ -128,9 +133,9 @@ describe('Affected', () => {
|
|||||||
const unitTests = runCommand(
|
const unitTests = runCommand(
|
||||||
`npm run affected:test -- --files="libs/${mylib}/src/index.ts"`
|
`npm run affected:test -- --files="libs/${mylib}/src/index.ts"`
|
||||||
);
|
);
|
||||||
expect(unitTests).toContain(`Running test for ${mylib}`);
|
expect(unitTests).toContain(
|
||||||
expect(unitTests).toContain(`Running test for ${mypublishablelib}`);
|
`Running test for projects:\n ${mylib},\n ${myapp},\n ${mypublishablelib}`
|
||||||
expect(unitTests).toContain(`Running test for ${myapp}`);
|
);
|
||||||
|
|
||||||
// Fail a Unit Test
|
// Fail a Unit Test
|
||||||
updateFile(
|
updateFile(
|
||||||
@ -144,10 +149,9 @@ describe('Affected', () => {
|
|||||||
const failedTests = runCommand(
|
const failedTests = runCommand(
|
||||||
`npm run affected:test -- --files="libs/${mylib}/src/index.ts"`
|
`npm run affected:test -- --files="libs/${mylib}/src/index.ts"`
|
||||||
);
|
);
|
||||||
|
expect(failedTests).toContain(
|
||||||
expect(failedTests).toContain(`Running test for ${mylib}`);
|
`Running test for projects:\n ${mylib},\n ${mypublishablelib},\n ${myapp}`
|
||||||
expect(failedTests).toContain(`Running test for ${mypublishablelib}`);
|
);
|
||||||
expect(failedTests).toContain(`Running test for ${myapp}`);
|
|
||||||
expect(failedTests).toContain(`Failed projects: ${myapp}`);
|
expect(failedTests).toContain(`Failed projects: ${myapp}`);
|
||||||
expect(failedTests).toContain(
|
expect(failedTests).toContain(
|
||||||
'You can isolate the above projects by passing --only-failed'
|
'You can isolate the above projects by passing --only-failed'
|
||||||
@ -173,15 +177,14 @@ describe('Affected', () => {
|
|||||||
const isolatedTests = runCommand(
|
const isolatedTests = runCommand(
|
||||||
`npm run affected:test -- --files="libs/${mylib}/src/index.ts" --only-failed`
|
`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(
|
const linting = runCommand(
|
||||||
`npm run affected:lint -- --files="libs/${mylib}/src/index.ts"`
|
`npm run affected:lint -- --files="libs/${mylib}/src/index.ts"`
|
||||||
);
|
);
|
||||||
expect(linting).toContain(`Running lint for ${mylib}`);
|
expect(linting).toContain(
|
||||||
expect(linting).toContain(`Running lint for ${myapp}`);
|
`Running lint for projects:\n ${mylib},\n ${myapp},\n ${myapp}-e2e,\n ${mypublishablelib}`
|
||||||
expect(linting).toContain(`Running lint for ${myapp}-e2e`);
|
);
|
||||||
expect(linting).toContain(`Running lint for ${mypublishablelib}`);
|
|
||||||
|
|
||||||
const lintWithJsonFormating = runCommand(
|
const lintWithJsonFormating = runCommand(
|
||||||
`npm run affected:lint -- --files="libs/${mylib}/src/index.ts" -- --format json`
|
`npm run affected:lint -- --files="libs/${mylib}/src/index.ts" -- --format json`
|
||||||
@ -191,12 +194,14 @@ describe('Affected', () => {
|
|||||||
const unitTestsExcluded = runCommand(
|
const unitTestsExcluded = runCommand(
|
||||||
`npm run affected:test -- --files="libs/${mylib}/src/index.ts" --exclude=${myapp},${mypublishablelib}`
|
`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(
|
const i18n = runCommand(
|
||||||
`npm run affected -- --target extract-i18n --files="libs/${mylib}/src/index.ts"`
|
`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(
|
const interpolatedTests = runCommand(
|
||||||
`npm run affected -- --target test --files="libs/${mylib}/src/index.ts" -- --jest-config {project.root}/jest.config.js`
|
`npm run affected -- --target test --files="libs/${mylib}/src/index.ts" -- --jest-config {project.root}/jest.config.js`
|
||||||
|
|||||||
@ -171,7 +171,7 @@ async function runCommand(
|
|||||||
projects.forEach(project => {
|
projects.forEach(project => {
|
||||||
projectMetadata.set(project, angularJson.projects[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`
|
// Make sure the `package.json` has the `ng: "ng"` command needed by `npm-run-all`
|
||||||
const packageJson = JSON.parse(
|
const packageJson = JSON.parse(
|
||||||
fs.readFileSync('./package.json').toString('utf-8')
|
fs.readFileSync('./package.json').toString('utf-8')
|
||||||
@ -182,30 +182,32 @@ async function runCommand(
|
|||||||
);
|
);
|
||||||
return process.exit(1);
|
return process.exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await runAll(
|
await runAll(
|
||||||
projects.map(app => {
|
projects.map(app => {
|
||||||
return ngCommands.includes(command)
|
return ngCommands.includes(command)
|
||||||
? `ng ${command} --project=${app} ${transformArgs(
|
? `ng -- ${command} --project=${app} ${transformArgs(
|
||||||
args,
|
args,
|
||||||
app,
|
app,
|
||||||
projectMetadata.get(app)
|
projectMetadata.get(app)
|
||||||
).join(' ')} `
|
).join(' ')} `
|
||||||
: `ng run ${app}:${command} ${transformArgs(
|
: `ng -- run ${app}:${command} ${transformArgs(
|
||||||
args,
|
args,
|
||||||
app,
|
app,
|
||||||
projectMetadata.get(app)
|
projectMetadata.get(app)
|
||||||
).join(' ')} `;
|
).join(' ')} `;
|
||||||
}),
|
}),
|
||||||
{
|
{
|
||||||
parallel: parsedArgs.parallel,
|
parallel: parsedArgs.parallel || false,
|
||||||
maxParallel: parsedArgs.maxParallel,
|
maxParallel: parsedArgs.maxParallel || 1,
|
||||||
continueOnError: true,
|
continueOnError: true,
|
||||||
stdin: process.stdin,
|
stdin: process.stdin,
|
||||||
stdout: process.stdout,
|
stdout: process.stdout,
|
||||||
stderr: process.stderr
|
stderr: process.stderr
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
projects.forEach(project => {
|
projects.forEach(project => {
|
||||||
workspaceResults.success(project);
|
workspaceResults.success(project);
|
||||||
});
|
});
|
||||||
@ -218,41 +220,6 @@ async function runCommand(
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
workspaceResults.saveResults();
|
|
||||||
workspaceResults.printResults(
|
|
||||||
parsedArgs.onlyFailed,
|
|
||||||
successMessage,
|
|
||||||
errorMessage
|
|
||||||
);
|
|
||||||
|
|
||||||
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.saveResults();
|
workspaceResults.saveResults();
|
||||||
workspaceResults.printResults(
|
workspaceResults.printResults(
|
||||||
@ -264,7 +231,6 @@ async function runCommand(
|
|||||||
if (workspaceResults.hasFailure) {
|
if (workspaceResults.hasFailure) {
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function transformArgs(
|
function transformArgs(
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user