From a7dc035d03b34bcf9b7097ed4347b7e505cb8fef Mon Sep 17 00:00:00 2001 From: Jason Jean Date: Wed, 25 Aug 2021 17:13:44 -0400 Subject: [PATCH] feat(linter): cache --outputFile --- .../__snapshots__/application.spec.ts.snap | 6 ++ .../application/application.spec.ts | 7 ++ .../convert-tslint-to-eslint.spec.ts.snap | 3 + .../cypress-project/cypress-project.spec.ts | 1 + packages/linter/migrations.json | 6 ++ .../lint-project/lint-project.spec.ts | 3 + .../generators/lint-project/lint-project.ts | 1 + .../update-12-9-0/add-outputs.spec.ts | 69 +++++++++++++++++++ .../migrations/update-12-9-0/add-outputs.ts | 26 +++++++ .../convert-tslint-to-eslint.spec.ts.snap | 6 ++ .../__snapshots__/library.spec.ts.snap | 3 + .../src/generators/library/library.spec.ts | 2 + .../application/application.spec.ts | 5 ++ .../src/generators/library/library.spec.ts | 5 ++ .../src/generators/plugin/plugin.spec.ts | 1 + .../src/generators/library/library.spec.ts | 5 ++ .../application/application.spec.ts | 22 +++--- .../src/generators/library/library.spec.ts | 5 ++ .../configuration/configuration.spec.ts | 1 + .../application/application.spec.ts | 38 +++++----- 20 files changed, 189 insertions(+), 26 deletions(-) create mode 100644 packages/linter/src/migrations/update-12-9-0/add-outputs.spec.ts create mode 100644 packages/linter/src/migrations/update-12-9-0/add-outputs.ts diff --git a/packages/angular/src/generators/application/__snapshots__/application.spec.ts.snap b/packages/angular/src/generators/application/__snapshots__/application.spec.ts.snap index 0744e41aa51a62..cf2e3d5b6331a6 100644 --- a/packages/angular/src/generators/application/__snapshots__/application.spec.ts.snap +++ b/packages/angular/src/generators/application/__snapshots__/application.spec.ts.snap @@ -300,6 +300,9 @@ Object { "apps/my-dir/my-app-e2e/**/*.{js,ts}", ], }, + "outputs": Array [ + "{options.outputFile}", + ], }, }, "projectType": "application", @@ -459,6 +462,9 @@ Object { "apps/my-app-e2e/**/*.{js,ts}", ], }, + "outputs": Array [ + "{options.outputFile}", + ], }, }, "projectType": "application", diff --git a/packages/angular/src/generators/application/application.spec.ts b/packages/angular/src/generators/application/application.spec.ts index af7d63433ac973..f50e13baa005c2 100644 --- a/packages/angular/src/generators/application/application.spec.ts +++ b/packages/angular/src/generators/application/application.spec.ts @@ -360,6 +360,9 @@ describe('app', () => { "apps/my-app-e2e/**/*.{js,ts}", ], }, + "outputs": Array [ + "{options.outputFile}", + ], } `); }); @@ -392,6 +395,9 @@ describe('app', () => { "apps/my-app-e2e/**/*.ts", ], }, + "outputs": Array [ + "{options.outputFile}", + ], } `); }); @@ -566,6 +572,7 @@ describe('app', () => { }, lint: { builder: '@nrwl/linter:eslint', + outputs: ['{options.outputFile}'], options: { lintFilePatterns: ['apps/my-app-e2e/**/*.ts'], }, diff --git a/packages/cypress/src/generators/convert-tslint-to-eslint/__snapshots__/convert-tslint-to-eslint.spec.ts.snap b/packages/cypress/src/generators/convert-tslint-to-eslint/__snapshots__/convert-tslint-to-eslint.spec.ts.snap index bf8e215ddc5f5f..6f9e44bd9cc21d 100644 --- a/packages/cypress/src/generators/convert-tslint-to-eslint/__snapshots__/convert-tslint-to-eslint.spec.ts.snap +++ b/packages/cypress/src/generators/convert-tslint-to-eslint/__snapshots__/convert-tslint-to-eslint.spec.ts.snap @@ -29,6 +29,9 @@ Object { "apps/e2e-app-1/**/*.{js,ts}", ], }, + "outputs": Array [ + "{options.outputFile}", + ], }, }, } diff --git a/packages/cypress/src/generators/cypress-project/cypress-project.spec.ts b/packages/cypress/src/generators/cypress-project/cypress-project.spec.ts index 60fa3d80cf8141..9190b676a05bd6 100644 --- a/packages/cypress/src/generators/cypress-project/cypress-project.spec.ts +++ b/packages/cypress/src/generators/cypress-project/cypress-project.spec.ts @@ -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}'], }, diff --git a/packages/linter/migrations.json b/packages/linter/migrations.json index 1eab1f8e5f4601..fb850af3f90845 100644 --- a/packages/linter/migrations.json +++ b/packages/linter/migrations.json @@ -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": { diff --git a/packages/linter/src/generators/lint-project/lint-project.spec.ts b/packages/linter/src/generators/lint-project/lint-project.spec.ts index 9f41e70ba8d5d0..c49373877b6059 100644 --- a/packages/linter/src/generators/lint-project/lint-project.spec.ts +++ b/packages/linter/src/generators/lint-project/lint-project.spec.ts @@ -57,6 +57,9 @@ describe('@nrwl/linter:lint-project', () => { "**/*.ts", ], }, + "outputs": Array [ + "{options.outputFile}", + ], } `); }); diff --git a/packages/linter/src/generators/lint-project/lint-project.ts b/packages/linter/src/generators/lint-project/lint-project.ts index 543843e7f0f982..2a540253f339f4 100644 --- a/packages/linter/src/generators/lint-project/lint-project.ts +++ b/packages/linter/src/generators/lint-project/lint-project.ts @@ -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, }, diff --git a/packages/linter/src/migrations/update-12-9-0/add-outputs.spec.ts b/packages/linter/src/migrations/update-12-9-0/add-outputs.spec.ts new file mode 100644 index 00000000000000..d67a97dfcbd54a --- /dev/null +++ b/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 {}, + }, + }, +} +`); + }); +}); diff --git a/packages/linter/src/migrations/update-12-9-0/add-outputs.ts b/packages/linter/src/migrations/update-12-9-0/add-outputs.ts new file mode 100644 index 00000000000000..7ec85927a0283b --- /dev/null +++ b/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); +} diff --git a/packages/nest/src/generators/convert-tslint-to-eslint/__snapshots__/convert-tslint-to-eslint.spec.ts.snap b/packages/nest/src/generators/convert-tslint-to-eslint/__snapshots__/convert-tslint-to-eslint.spec.ts.snap index 33d024d514daad..ebbbdf885ac6ae 100644 --- a/packages/nest/src/generators/convert-tslint-to-eslint/__snapshots__/convert-tslint-to-eslint.spec.ts.snap +++ b/packages/nest/src/generators/convert-tslint-to-eslint/__snapshots__/convert-tslint-to-eslint.spec.ts.snap @@ -28,6 +28,9 @@ Object { "apps/nest-app-1/**/*.ts", ], }, + "outputs": Array [ + "{options.outputFile}", + ], }, }, } @@ -314,6 +317,9 @@ Object { "libs/nest-lib-1/**/*.ts", ], }, + "outputs": Array [ + "{options.outputFile}", + ], }, }, } diff --git a/packages/nest/src/generators/library/__snapshots__/library.spec.ts.snap b/packages/nest/src/generators/library/__snapshots__/library.spec.ts.snap index b1e671c875e51d..23f6a2d3395374 100644 --- a/packages/nest/src/generators/library/__snapshots__/library.spec.ts.snap +++ b/packages/nest/src/generators/library/__snapshots__/library.spec.ts.snap @@ -59,6 +59,9 @@ Object { "libs/my-lib/**/*.ts", ], }, + "outputs": Array [ + "{options.outputFile}", + ], } `; diff --git a/packages/nest/src/generators/library/library.spec.ts b/packages/nest/src/generators/library/library.spec.ts index cbe17dc2eee0f6..7c26c6836df0ab 100644 --- a/packages/nest/src/generators/library/library.spec.ts +++ b/packages/nest/src/generators/library/library.spec.ts @@ -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`], }, @@ -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`], }, diff --git a/packages/node/src/generators/application/application.spec.ts b/packages/node/src/generators/application/application.spec.ts index 83d485716c4453..e96eac2496ce3e 100644 --- a/packages/node/src/generators/application/application.spec.ts +++ b/packages/node/src/generators/application/application.spec.ts @@ -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'], }, @@ -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'], }, @@ -272,6 +274,9 @@ describe('app', () => { "apps/my-node-app/**/*.ts", ], }, + "outputs": Array [ + "{options.outputFile}", + ], } `); }); diff --git a/packages/node/src/generators/library/library.spec.ts b/packages/node/src/generators/library/library.spec.ts index 385ad62a04cefc..ff0939a8fee9de 100644 --- a/packages/node/src/generators/library/library.spec.ts +++ b/packages/node/src/generators/library/library.spec.ts @@ -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'], }, @@ -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'], }, @@ -304,6 +306,9 @@ describe('lib', () => { "libs/my-lib/**/*.ts", ], }, + "outputs": Array [ + "{options.outputFile}", + ], } `); }); diff --git a/packages/nx-plugin/src/generators/plugin/plugin.spec.ts b/packages/nx-plugin/src/generators/plugin/plugin.spec.ts index 5c94a0229de611..02b8e320cf8d10 100644 --- a/packages/nx-plugin/src/generators/plugin/plugin.spec.ts +++ b/packages/nx-plugin/src/generators/plugin/plugin.spec.ts @@ -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'], }, diff --git a/packages/react-native/src/generators/library/library.spec.ts b/packages/react-native/src/generators/library/library.spec.ts index 7545fe1a7086c9..da1ed109b170dd 100644 --- a/packages/react-native/src/generators/library/library.spec.ts +++ b/packages/react-native/src/generators/library/library.spec.ts @@ -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}'], }, @@ -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}'], }, @@ -196,6 +198,9 @@ describe('lib', () => { "libs/my-lib/**/*.{ts,tsx,js,jsx}", ], }, + "outputs": Array [ + "{options.outputFile}", + ], } `); }); diff --git a/packages/react/src/generators/application/application.spec.ts b/packages/react/src/generators/application/application.spec.ts index 6379502573cf76..10e1f7aeb4998a 100644 --- a/packages/react/src/generators/application/application.spec.ts +++ b/packages/react/src/generators/application/application.spec.ts @@ -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}'], }, @@ -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}", + ], +} +`); }); }); diff --git a/packages/react/src/generators/library/library.spec.ts b/packages/react/src/generators/library/library.spec.ts index b777d2e9aac921..95bb0ee72d56a2 100644 --- a/packages/react/src/generators/library/library.spec.ts +++ b/packages/react/src/generators/library/library.spec.ts @@ -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}'], }, @@ -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}'], }, @@ -334,6 +336,9 @@ describe('lib', () => { "libs/my-lib/**/*.{ts,tsx,js,jsx}", ], }, + "outputs": Array [ + "{options.outputFile}", + ], } `); }); diff --git a/packages/storybook/src/generators/configuration/configuration.spec.ts b/packages/storybook/src/generators/configuration/configuration.spec.ts index 1d1c99d784e6f9..5bc869b20f88d7 100644 --- a/packages/storybook/src/generators/configuration/configuration.spec.ts +++ b/packages/storybook/src/generators/configuration/configuration.spec.ts @@ -158,6 +158,7 @@ describe('@nrwl/storybook:configuration', () => { expect(project.targets.lint).toEqual({ executor: '@nrwl/linter:eslint', + outputs: ['{options.outputFile}'], options: { lintFilePatterns: ['libs/test-ui-lib/**/*.ts'], }, diff --git a/packages/web/src/generators/application/application.spec.ts b/packages/web/src/generators/application/application.spec.ts index d9cdc5d4176aca..a13e2a3e0af97b 100644 --- a/packages/web/src/generators/application/application.spec.ts +++ b/packages/web/src/generators/application/application.spec.ts @@ -74,23 +74,23 @@ describe('app', () => { expect(tree.exists('apps/my-app-e2e/cypress.json')).toBeTruthy(); const tsconfigE2E = readJson(tree, 'apps/my-app-e2e/tsconfig.json'); expect(tsconfigE2E).toMatchInlineSnapshot(` -Object { - "compilerOptions": Object { - "allowJs": true, - "outDir": "../../dist/out-tsc", - "sourceMap": false, - "types": Array [ - "cypress", - "node", - ], - }, - "extends": "../../tsconfig.base.json", - "include": Array [ - "src/**/*.ts", - "src/**/*.js", - ], -} -`); + Object { + "compilerOptions": Object { + "allowJs": true, + "outDir": "../../dist/out-tsc", + "sourceMap": false, + "types": Array [ + "cypress", + "node", + ], + }, + "extends": "../../tsconfig.base.json", + "include": Array [ + "src/**/*.ts", + "src/**/*.js", + ], + } + `); const eslintJson = readJson(tree, '/apps/my-app/.eslintrc.json'); expect(eslintJson).toMatchInlineSnapshot(` @@ -314,6 +314,7 @@ Object { expect(workspaceJson.projects['my-app'].architect.lint).toEqual({ builder: '@nrwl/linter:eslint', + outputs: ['{options.outputFile}'], options: { lintFilePatterns: ['apps/my-app/**/*.ts'], }, @@ -358,6 +359,9 @@ Object { "apps/my-app/**/*.ts", ], }, + "outputs": Array [ + "{options.outputFile}", + ], } `); });