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

feat(linter): cache --outputFile #6852

Merged
merged 1 commit into from Aug 26, 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion e2e/workspace/src/workspace.test.ts
Expand Up @@ -815,7 +815,7 @@ describe('cache', () => {
expect(outputWithBothLintTasksCached).toContain(
'read the output from cache'
);
expectMatchedOutput(outputWithBothLintTasksCached, [
expectCached(outputWithBothLintTasksCached, [
myapp1,
myapp2,
`${myapp1}-e2e`,
Expand Down
Expand Up @@ -300,6 +300,9 @@ Object {
"apps/my-dir/my-app-e2e/**/*.{js,ts}",
],
},
"outputs": Array [
"{options.outputFile}",
],
},
},
"projectType": "application",
Expand Down Expand Up @@ -459,6 +462,9 @@ Object {
"apps/my-app-e2e/**/*.{js,ts}",
],
},
"outputs": Array [
"{options.outputFile}",
],
},
},
"projectType": "application",
Expand Down
Expand Up @@ -360,6 +360,9 @@ describe('app', () => {
"apps/my-app-e2e/**/*.{js,ts}",
],
},
"outputs": Array [
"{options.outputFile}",
],
}
`);
});
Expand Down Expand Up @@ -392,6 +395,9 @@ describe('app', () => {
"apps/my-app-e2e/**/*.ts",
],
},
"outputs": Array [
"{options.outputFile}",
],
}
`);
});
Expand Down Expand Up @@ -566,6 +572,7 @@ describe('app', () => {
},
lint: {
builder: '@nrwl/linter:eslint',
outputs: ['{options.outputFile}'],
options: {
lintFilePatterns: ['apps/my-app-e2e/**/*.ts'],
},
Expand Down
Expand Up @@ -29,6 +29,9 @@ Object {
"apps/e2e-app-1/**/*.{js,ts}",
],
},
"outputs": Array [
"{options.outputFile}",
],
},
},
}
Expand Down
Expand Up @@ -169,6 +169,7 @@ describe('schematic:cypress-project', () => {

expect(project.architect.lint).toEqual({
builder: '@nrwl/linter:eslint',
outputs: ['{options.outputFile}'],
options: {
lintFilePatterns: ['apps/my-app-e2e/**/*.{js,ts}'],
},
Expand Down
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
@@ -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);
}
Expand Up @@ -28,6 +28,9 @@ Object {
"apps/nest-app-1/**/*.ts",
],
},
"outputs": Array [
"{options.outputFile}",
],
},
},
}
Expand Down Expand Up @@ -314,6 +317,9 @@ Object {
"libs/nest-lib-1/**/*.ts",
],
},
"outputs": Array [
"{options.outputFile}",
],
},
},
}
Expand Down
Expand Up @@ -59,6 +59,9 @@ Object {
"libs/my-lib/**/*.ts",
],
},
"outputs": Array [
"{options.outputFile}",
],
}
`;

Expand Down
2 changes: 2 additions & 0 deletions packages/nest/src/generators/library/library.spec.ts
Expand Up @@ -27,6 +27,7 @@ describe('lib', () => {
).toBeUndefined();
expect(workspaceJson.projects[libFileName].architect.lint).toEqual({
builder: '@nrwl/linter:eslint',
outputs: ['{options.outputFile}'],
options: {
lintFilePatterns: [`libs/${libFileName}/**/*.ts`],
},
Expand Down Expand Up @@ -212,6 +213,7 @@ describe('lib', () => {
expect(project.root).toEqual(`libs/${dirFileName}/${libFileName}`);
expect(project.targets.lint).toEqual({
executor: '@nrwl/linter:eslint',
outputs: ['{options.outputFile}'],
options: {
lintFilePatterns: [`libs/${dirFileName}/${libFileName}/**/*.ts`],
},
Expand Down
Expand Up @@ -75,6 +75,7 @@ describe('app', () => {
);
expect(workspaceJson.projects['my-node-app'].architect.lint).toEqual({
builder: '@nrwl/linter:eslint',
outputs: ['{options.outputFile}'],
options: {
lintFilePatterns: ['apps/my-node-app/**/*.ts'],
},
Expand Down Expand Up @@ -182,6 +183,7 @@ describe('app', () => {
workspaceJson.projects['my-dir-my-node-app'].architect.lint
).toEqual({
builder: '@nrwl/linter:eslint',
outputs: ['{options.outputFile}'],
options: {
lintFilePatterns: ['apps/my-dir/my-node-app/**/*.ts'],
},
Expand Down Expand Up @@ -272,6 +274,9 @@ describe('app', () => {
"apps/my-node-app/**/*.ts",
],
},
"outputs": Array [
"{options.outputFile}",
],
}
`);
});
Expand Down
5 changes: 5 additions & 0 deletions packages/node/src/generators/library/library.spec.ts
Expand Up @@ -19,6 +19,7 @@ describe('lib', () => {
expect(workspaceJson.projects['my-lib'].architect.build).toBeUndefined();
expect(workspaceJson.projects['my-lib'].architect.lint).toEqual({
builder: '@nrwl/linter:eslint',
outputs: ['{options.outputFile}'],
options: {
lintFilePatterns: ['libs/my-lib/**/*.ts'],
},
Expand Down Expand Up @@ -201,6 +202,7 @@ describe('lib', () => {
);
expect(workspaceJson.projects['my-dir-my-lib'].architect.lint).toEqual({
builder: '@nrwl/linter:eslint',
outputs: ['{options.outputFile}'],
options: {
lintFilePatterns: ['libs/my-dir/my-lib/**/*.ts'],
},
Expand Down Expand Up @@ -304,6 +306,9 @@ describe('lib', () => {
"libs/my-lib/**/*.ts",
],
},
"outputs": Array [
"{options.outputFile}",
],
}
`);
});
Expand Down
1 change: 1 addition & 0 deletions packages/nx-plugin/src/generators/plugin/plugin.spec.ts
Expand Up @@ -48,6 +48,7 @@ describe('NxPlugin Plugin Generator', () => {
});
expect(project.targets.lint).toEqual({
executor: '@nrwl/linter:eslint',
outputs: ['{options.outputFile}'],
options: {
lintFilePatterns: ['libs/my-plugin/**/*.ts'],
},
Expand Down
Expand Up @@ -29,6 +29,7 @@ describe('lib', () => {
expect(workspaceJson.projects['my-lib'].architect.build).toBeUndefined();
expect(workspaceJson.projects['my-lib'].architect.lint).toEqual({
builder: '@nrwl/linter:eslint',
outputs: ['{options.outputFile}'],
options: {
lintFilePatterns: ['libs/my-lib/**/*.{ts,tsx,js,jsx}'],
},
Expand Down Expand Up @@ -141,6 +142,7 @@ describe('lib', () => {
);
expect(workspaceJson.projects['my-dir-my-lib'].architect.lint).toEqual({
builder: '@nrwl/linter:eslint',
outputs: ['{options.outputFile}'],
options: {
lintFilePatterns: ['libs/my-dir/my-lib/**/*.{ts,tsx,js,jsx}'],
},
Expand Down Expand Up @@ -196,6 +198,9 @@ describe('lib', () => {
"libs/my-lib/**/*.{ts,tsx,js,jsx}",
],
},
"outputs": Array [
"{options.outputFile}",
],
}
`);
});
Expand Down
22 changes: 13 additions & 9 deletions packages/react/src/generators/application/application.spec.ts
Expand Up @@ -306,6 +306,7 @@ Object {
const workspaceJson = getProjects(appTree);
expect(workspaceJson.get('my-app').targets.lint).toEqual({
executor: '@nrwl/linter:eslint',
outputs: ['{options.outputFile}'],
options: {
lintFilePatterns: ['apps/my-app/**/*.{ts,tsx,js,jsx}'],
},
Expand All @@ -326,15 +327,18 @@ Object {
const workspaceJson = getProjects(appTree);
expect(workspaceJson.get('my-app').targets.test).toBeUndefined();
expect(workspaceJson.get('my-app').targets.lint).toMatchInlineSnapshot(`
Object {
"executor": "@nrwl/linter:eslint",
"options": Object {
"lintFilePatterns": Array [
"apps/my-app/**/*.{ts,tsx,js,jsx}",
],
},
}
`);
Object {
"executor": "@nrwl/linter:eslint",
"options": Object {
"lintFilePatterns": Array [
"apps/my-app/**/*.{ts,tsx,js,jsx}",
],
},
"outputs": Array [
"{options.outputFile}",
],
}
`);
});
});

Expand Down
5 changes: 5 additions & 0 deletions packages/react/src/generators/library/library.spec.ts
Expand Up @@ -32,6 +32,7 @@ describe('lib', () => {
expect(workspaceJson.projects['my-lib'].architect.build).toBeUndefined();
expect(workspaceJson.projects['my-lib'].architect.lint).toEqual({
builder: '@nrwl/linter:eslint',
outputs: ['{options.outputFile}'],
options: {
lintFilePatterns: ['libs/my-lib/**/*.{ts,tsx,js,jsx}'],
},
Expand Down Expand Up @@ -224,6 +225,7 @@ describe('lib', () => {
);
expect(workspaceJson.projects['my-dir-my-lib'].architect.lint).toEqual({
builder: '@nrwl/linter:eslint',
outputs: ['{options.outputFile}'],
options: {
lintFilePatterns: ['libs/my-dir/my-lib/**/*.{ts,tsx,js,jsx}'],
},
Expand Down Expand Up @@ -334,6 +336,9 @@ describe('lib', () => {
"libs/my-lib/**/*.{ts,tsx,js,jsx}",
],
},
"outputs": Array [
"{options.outputFile}",
],
}
`);
});
Expand Down