diff --git a/packages/angular/src/migrations/update-10-5-0/add-template-support-and-presets-to-eslint.spec.ts b/packages/angular/src/migrations/update-10-5-0/add-template-support-and-presets-to-eslint.spec.ts index 6ea373b3c4..76722bf53a 100644 --- a/packages/angular/src/migrations/update-10-5-0/add-template-support-and-presets-to-eslint.spec.ts +++ b/packages/angular/src/migrations/update-10-5-0/add-template-support-and-presets-to-eslint.spec.ts @@ -1,5 +1,9 @@ import { Tree } from '@angular-devkit/schematics'; -import { readJsonInTree, updateWorkspace } from '@nrwl/workspace'; +import { + readJsonInTree, + updateJsonInTree, + updateWorkspace, +} from '@nrwl/workspace'; import { callRule, createEmptyWorkspace } from '@nrwl/workspace/testing'; import { runMigration } from '../../utils/testing'; @@ -50,6 +54,23 @@ describe('add-template-support-and-presets-to-eslint', () => { }), tree ); + tree = await callRule( + updateJsonInTree('nx.json', (json) => { + json.projects['app1'] = {}; + json.projects['lib1'] = {}; + + return json; + }), + tree + ); + tree = await callRule( + updateJsonInTree('package.json', (json) => { + json.dependencies['@angular/core'] = '11.0.0'; + + return json; + }), + tree + ); }); it('should do nothing', async () => { @@ -129,6 +150,26 @@ describe('add-template-support-and-presets-to-eslint', () => { }), tree ); + tree = await callRule( + updateJsonInTree('nx.json', (json) => { + json.projects['app1'] = {}; + json.projects['app2'] = {}; + json.projects['lib1'] = {}; + + return json; + }), + tree + ); + tree = await callRule( + updateJsonInTree('package.json', (json) => { + json.dependencies['@angular/core'] = '11.0.0'; + + return json; + }), + tree + ); + tree.create('apps/app1/src/main.ts', `import '@angular/core';`); + tree.create('libs/lib1/src/index.ts', `import '@angular/core';`); }); it('should do nothing if the root eslint config has not been updated to use overrides by the latest migrations', async () => { @@ -180,7 +221,9 @@ describe('add-template-support-and-presets-to-eslint', () => { expect(packageJsonBefore).toMatchInlineSnapshot(` Object { - "dependencies": Object {}, + "dependencies": Object { + "@angular/core": "11.0.0", + }, "devDependencies": Object {}, "name": "test-name", } @@ -189,7 +232,9 @@ describe('add-template-support-and-presets-to-eslint', () => { expect(JSON.parse(result.read('package.json').toString())) .toMatchInlineSnapshot(` Object { - "dependencies": Object {}, + "dependencies": Object { + "@angular/core": "11.0.0", + }, "devDependencies": Object { "@angular-eslint/eslint-plugin": "0.8.0-beta.1", "@angular-eslint/eslint-plugin-template": "0.8.0-beta.1", diff --git a/packages/angular/src/migrations/update-10-5-0/add-template-support-and-presets-to-eslint.ts b/packages/angular/src/migrations/update-10-5-0/add-template-support-and-presets-to-eslint.ts index 9b78255c7f..e04191a733 100644 --- a/packages/angular/src/migrations/update-10-5-0/add-template-support-and-presets-to-eslint.ts +++ b/packages/angular/src/migrations/update-10-5-0/add-template-support-and-presets-to-eslint.ts @@ -11,6 +11,7 @@ import { } from '@nrwl/workspace'; import { join } from 'path'; import { offsetFromRoot } from '@nrwl/devkit'; +import { getFullProjectGraphFromHost } from '@nrwl/workspace/src/utils/ast-utils'; /** * It was decided with Jason that we would do a simple replacement in this migration @@ -39,6 +40,8 @@ function addHTMLPatternToBuilderConfig( } function updateProjectESLintConfigsAndBuilders(host: Tree): Rule { + const graph = getFullProjectGraphFromHost(host); + /** * Make sure user is already using ESLint and is up to date with * previous migrations @@ -58,6 +61,15 @@ function updateProjectESLintConfigsAndBuilders(host: Tree): Rule { Object.keys(workspace.projects).forEach((projectName) => { const project = workspace.projects[projectName]; + if ( + !graph.dependencies[projectName].some( + (dependency) => + dependency.target.startsWith('npm:@angular/') && + graph.nodes[dependency.target].type === 'npm' + ) + ) { + return; + } Object.keys(project.architect).forEach((targetName) => { const target = project.architect[targetName]; if (target.builder !== '@nrwl/linter:eslint') {