diff --git a/e2e/workspace/src/workspace.test.ts b/e2e/workspace/src/workspace.test.ts index 7837add93af96..e0a3a42bf3544 100644 --- a/e2e/workspace/src/workspace.test.ts +++ b/e2e/workspace/src/workspace.test.ts @@ -815,7 +815,7 @@ describe('cache', () => { expect(outputWithBothLintTasksCached).toContain( 'read the output from cache' ); - expectMatchedOutput(outputWithBothLintTasksCached, [ + expectCached(outputWithBothLintTasksCached, [ myapp1, myapp2, `${myapp1}-e2e`, 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 0744e41aa51a6..cf2e3d5b6331a 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 af7d63433ac97..f50e13baa005c 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 bf8e215ddc5f5..6f9e44bd9cc21 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 60fa3d80cf814..9190b676a05bd 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 1eab1f8e5f460..fb850af3f9084 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 9f41e70ba8d5d..c49373877b605 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 543843e7f0f98..2a540253f339f 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 0000000000000..d67a97dfcbd54 --- /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 0000000000000..7ec85927a0283 --- /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 33d024d514daa..ebbbdf885ac6a 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 b1e671c875e51..23f6a2d339537 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 cbe17dc2eee0f..7c26c6836df0a 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 83d485716c445..e96eac2496ce3 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 385ad62a04cef..ff0939a8fee9d 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 5c94a0229de61..02b8e320cf8d1 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 7545fe1a7086c..da1ed109b170d 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 6379502573cf7..10e1f7aeb4998 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 b777d2e9aac92..95bb0ee72d56a 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 1d1c99d784e6f..5bc869b20f88d 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 d9cdc5d4176ac..a13e2a3e0af97 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}", + ], } `); });