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): skip caching output properties missing in options and arguments #6743

Merged
merged 2 commits into from
Aug 18, 2021
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions e2e/linter/src/linter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
newProject,
readFile,
readJson,
removeFile,
runCLI,
uniq,
updateFile,
Expand Down Expand Up @@ -188,4 +189,28 @@ describe('Linter', () => {
'Unexpected console statement.'
);
}, 1000000);

it('linting should cache the output file if defined in outputs', () => {
newProject();
const myapp = uniq('myapp');
const outputFile = 'a/b/c/lint-output.json';

runCLI(`generate @nrwl/react:app ${myapp}`);
const workspaceJson = readJson(`workspace.json`);
workspaceJson.projects[myapp].targets.lint.outputs = [
'{options.outputFile}',
];
updateFile('workspace.json', JSON.stringify(workspaceJson, null, 2));

expect(() => checkFilesExist(outputFile)).toThrow();
runCLI(`lint ${myapp} --output-file="${outputFile}" --format=json`, {
silenceError: true,
});
expect(() => checkFilesExist(outputFile)).not.toThrow();
removeFile(outputFile);
runCLI(`lint ${myapp} --output-file="${outputFile}" --format=json`, {
silenceError: true,
});
expect(() => checkFilesExist(outputFile)).not.toThrow();
}, 1000000);
});
5 changes: 5 additions & 0 deletions e2e/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -547,6 +547,11 @@ export function readFile(f: string) {
return readFileSync(ff, 'utf-8');
}

export function removeFile(f: string) {
const ff = f.startsWith('/') ? f : tmpProjPath(f);
removeSync(ff);
}

export function rmDist() {
removeSync(`${tmpProjPath()}/dist`);
}
Expand Down
17 changes: 17 additions & 0 deletions e2e/workspace/src/run-commands.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,4 +131,21 @@ describe('Run Commands', () => {
);
}
});

it('run command should not break if output property is missing in options and arguments', () => {
const myapp = uniq('myapp');

runCLI(`generate @nrwl/web:app ${myapp}`);
const workspaceJson = readJson(`workspace.json`);
workspaceJson.projects[myapp].targets.lint.outputs = [
Copy link
Collaborator

Choose a reason for hiding this comment

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

We should add this when generating a lint project.

'{options.outputFile}',
];
updateFile('workspace.json', JSON.stringify(workspaceJson, null, 2));

expect(() =>
runCLI(`run ${myapp}:lint --format=json`, {
silenceError: true,
})
).not.toThrow();
}, 1000000);
});
1 change: 0 additions & 1 deletion packages/linter/src/executors/lint/lint.impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ export default async function run(
createProgram(path.resolve(systemRoot, tsConfig))
);

let i = 0;
for (const program of allPrograms) {
lintReports = [
...lintReports,
Expand Down
6 changes: 2 additions & 4 deletions packages/workspace/src/tasks-runner/task-orchestrator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,8 @@ export class TaskOrchestrator {

private async applyCachedResult(t: TaskWithCachedResult) {
const outputs = getOutputs(this.projectGraph.nodes, t.task);
const shouldCopyOutputsFromCache = this.cache.shouldCopyOutputsFromCache(
t,
outputs
);
const shouldCopyOutputsFromCache =
!!outputs.length && this.cache.shouldCopyOutputsFromCache(t, outputs);
if (shouldCopyOutputsFromCache) {
this.cache.copyFilesFromCache(t.task.hash, t.cachedResult, outputs);
}
Expand Down
8 changes: 4 additions & 4 deletions packages/workspace/src/tasks-runner/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,9 @@ export function getOutputsForTargetAndConfiguration(
};

if (targets?.outputs) {
return targets.outputs.map((output: string) =>
interpolateOutputs(output, options)
);
return targets.outputs
.map((output: string) => interpolateOutputs(output, options))
.filter((output) => !!output);
}

// Keep backwards compatibility in case `outputs` doesn't exist
Expand Down Expand Up @@ -169,7 +169,7 @@ function interpolateOutputs(template: string, data: any): string {
let path = match.slice(1, -1).trim().split('.').slice(1);
for (let idx = 0; idx < path.length; idx++) {
if (!value[path[idx]]) {
throw new Error(`Could not interpolate output {${match}}!`);
return;
}
value = value[path[idx]];
}
Expand Down