fix(angular): scope eslint migration to angular projects (#4263)

This commit is contained in:
Jason Jean 2020-12-11 16:39:20 -05:00 committed by GitHub
parent 112e000445
commit f70fa2d78f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 60 additions and 3 deletions

View File

@ -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",

View File

@ -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') {