fix(angular): scope eslint migration to angular projects (#4263)
This commit is contained in:
parent
112e000445
commit
f70fa2d78f
@ -1,5 +1,9 @@
|
|||||||
import { Tree } from '@angular-devkit/schematics';
|
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 { callRule, createEmptyWorkspace } from '@nrwl/workspace/testing';
|
||||||
import { runMigration } from '../../utils/testing';
|
import { runMigration } from '../../utils/testing';
|
||||||
|
|
||||||
@ -50,6 +54,23 @@ describe('add-template-support-and-presets-to-eslint', () => {
|
|||||||
}),
|
}),
|
||||||
tree
|
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 () => {
|
it('should do nothing', async () => {
|
||||||
@ -129,6 +150,26 @@ describe('add-template-support-and-presets-to-eslint', () => {
|
|||||||
}),
|
}),
|
||||||
tree
|
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 () => {
|
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(`
|
expect(packageJsonBefore).toMatchInlineSnapshot(`
|
||||||
Object {
|
Object {
|
||||||
"dependencies": Object {},
|
"dependencies": Object {
|
||||||
|
"@angular/core": "11.0.0",
|
||||||
|
},
|
||||||
"devDependencies": Object {},
|
"devDependencies": Object {},
|
||||||
"name": "test-name",
|
"name": "test-name",
|
||||||
}
|
}
|
||||||
@ -189,7 +232,9 @@ describe('add-template-support-and-presets-to-eslint', () => {
|
|||||||
expect(JSON.parse(result.read('package.json').toString()))
|
expect(JSON.parse(result.read('package.json').toString()))
|
||||||
.toMatchInlineSnapshot(`
|
.toMatchInlineSnapshot(`
|
||||||
Object {
|
Object {
|
||||||
"dependencies": Object {},
|
"dependencies": Object {
|
||||||
|
"@angular/core": "11.0.0",
|
||||||
|
},
|
||||||
"devDependencies": Object {
|
"devDependencies": Object {
|
||||||
"@angular-eslint/eslint-plugin": "0.8.0-beta.1",
|
"@angular-eslint/eslint-plugin": "0.8.0-beta.1",
|
||||||
"@angular-eslint/eslint-plugin-template": "0.8.0-beta.1",
|
"@angular-eslint/eslint-plugin-template": "0.8.0-beta.1",
|
||||||
|
|||||||
@ -11,6 +11,7 @@ import {
|
|||||||
} from '@nrwl/workspace';
|
} from '@nrwl/workspace';
|
||||||
import { join } from 'path';
|
import { join } from 'path';
|
||||||
import { offsetFromRoot } from '@nrwl/devkit';
|
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
|
* 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 {
|
function updateProjectESLintConfigsAndBuilders(host: Tree): Rule {
|
||||||
|
const graph = getFullProjectGraphFromHost(host);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Make sure user is already using ESLint and is up to date with
|
* Make sure user is already using ESLint and is up to date with
|
||||||
* previous migrations
|
* previous migrations
|
||||||
@ -58,6 +61,15 @@ function updateProjectESLintConfigsAndBuilders(host: Tree): Rule {
|
|||||||
Object.keys(workspace.projects).forEach((projectName) => {
|
Object.keys(workspace.projects).forEach((projectName) => {
|
||||||
const project = workspace.projects[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) => {
|
Object.keys(project.architect).forEach((targetName) => {
|
||||||
const target = project.architect[targetName];
|
const target = project.architect[targetName];
|
||||||
if (target.builder !== '@nrwl/linter:eslint') {
|
if (target.builder !== '@nrwl/linter:eslint') {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user