Skip to content

Commit

Permalink
feat(linter): cache --outputFile
Browse files Browse the repository at this point in the history
  • Loading branch information
FrozenPandaz committed Aug 25, 2021
1 parent 387af0c commit bf99d26
Show file tree
Hide file tree
Showing 5 changed files with 105 additions and 0 deletions.
6 changes: 6 additions & 0 deletions packages/linter/migrations.json
Expand Up @@ -46,6 +46,12 @@
"version": "12.4.0-beta.0",
"description": "Remove ESLint parserOptions.project config if no rules requiring type-checking are in use",
"factory": "./src/migrations/update-12-4-0/remove-eslint-project-config-if-no-type-checking-rules"
},
"add-outputs": {
"cli": "nx",
"version": "12.9.0-beta.0",
"description": "Add outputs for caching",
"factory": "./src/migrations/update-12-9-0/add-outputs"
}
},
"packageJsonUpdates": {
Expand Down
Expand Up @@ -57,6 +57,9 @@ describe('@nrwl/linter:lint-project', () => {
"**/*.ts",
],
},
"outputs": Array [
"{options.outputFile}",
],
}
`);
});
Expand Down
Expand Up @@ -93,6 +93,7 @@ export async function lintProjectGenerator(
if (options.linter === Linter.EsLint) {
projectConfig.targets['lint'] = {
executor: '@nrwl/linter:eslint',
outputs: ['{options.outputFile}'],
options: {
lintFilePatterns: options.eslintFilePatterns,
},
Expand Down
69 changes: 69 additions & 0 deletions packages/linter/src/migrations/update-12-9-0/add-outputs.spec.ts
@@ -0,0 +1,69 @@
import {
addProjectConfiguration,
readProjectConfiguration,
TargetConfiguration,
Tree,
} from '@nrwl/devkit';
import { createTreeWithEmptyWorkspace } from '@nrwl/devkit/testing';
import addOutputs from './add-outputs';

describe('addOutputs', () => {
let tree: Tree;

beforeEach(() => {
tree = createTreeWithEmptyWorkspace();

const lintWithoutOutputs: TargetConfiguration = {
executor: '@nrwl/linter:eslint',
options: {},
};
const lintWithOutputs: TargetConfiguration = {
executor: '@nrwl/linter:eslint',
outputs: ['dist'],
options: {},
};
const notLint: TargetConfiguration = {
executor: '@nrwl/node:build',
options: {},
};

addProjectConfiguration(tree, 'proj', {
root: 'proj',
targets: {
lintWithoutOutputs,
lintWithOutputs,
notLint,
},
});
});

it('should add outputs to targets that do not have outputs', async () => {
await addOutputs(tree);

expect(readProjectConfiguration(tree, 'proj')).toMatchInlineSnapshot(`
Object {
"root": "proj",
"targets": Object {
"lintWithOutputs": Object {
"executor": "@nrwl/linter:eslint",
"options": Object {},
"outputs": Array [
"dist",
],
},
"lintWithoutOutputs": Object {
"executor": "@nrwl/linter:eslint",
"options": Object {},
"outputs": Array [
"{options.outputFile}",
],
},
"notLint": Object {
"executor": "@nrwl/node:build",
"options": Object {},
},
},
}
`);
});
});
26 changes: 26 additions & 0 deletions packages/linter/src/migrations/update-12-9-0/add-outputs.ts
@@ -0,0 +1,26 @@
import {
formatFiles,
getProjects,
Tree,
updateProjectConfiguration,
} from '@nrwl/devkit';

export default async function addOutputs(tree: Tree) {
for (const [projectName, project] of getProjects(tree)) {
if (!project.targets) {
continue;
}

for (const target of Object.values(project.targets)) {
if (target.executor !== '@nrwl/linter:eslint' || target.outputs) {
continue;
}

target.outputs = ['{options.outputFile}'];

updateProjectConfiguration(tree, projectName, project);
}
}

await formatFiles(tree);
}

0 comments on commit bf99d26

Please sign in to comment.