Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit c08eb54

Browse filesBrowse files
committed
chore: add simple migration schematic for v20
1 parent 9183385 commit c08eb54
Copy full SHA for c08eb54

File tree

Expand file treeCollapse file tree

4 files changed

+171
-0
lines changed
Filter options
Expand file treeCollapse file tree

4 files changed

+171
-0
lines changed

‎packages/schematics/src/migrations.json

Copy file name to clipboardExpand all lines: packages/schematics/src/migrations.json
+5Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,11 @@
5555
"version": "18.1.1-alpha.0",
5656
"description": "Updates @angular-eslint to v18.2",
5757
"factory": "./migrations/update-18-2-0/update-18-2-0"
58+
},
59+
"update-20-0-0": {
60+
"version": "20.0.0-alpha.0",
61+
"description": "Updates @angular-eslint to v20",
62+
"factory": "./migrations/update-20-0-0/update-20-0-0"
5863
}
5964
}
6065
}
+58Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
import type { Rule } from '@angular-devkit/schematics';
2+
import { chain } from '@angular-devkit/schematics';
3+
import { updateDependencies } from '../utils/dependencies';
4+
5+
const updatedTypeScriptESLintVersion = '8.33.1';
6+
const updatedESLintVersion = '9.28.0';
7+
8+
export default function migration(): Rule {
9+
return chain([
10+
(host) => {
11+
const packageJson = JSON.parse(host.read('package.json')!.toString());
12+
if (
13+
packageJson.devDependencies['typescript-eslint'] ||
14+
packageJson.devDependencies['@typescript-eslint/parser'].startsWith(
15+
'8.',
16+
) ||
17+
packageJson.devDependencies['@typescript-eslint/parser'].startsWith(
18+
'^8.',
19+
) ||
20+
packageJson.devDependencies['@typescript-eslint/parser'].startsWith(
21+
'~8.',
22+
)
23+
) {
24+
return updateDependencies([
25+
{
26+
packageName: '@typescript-eslint/eslint-plugin',
27+
version: `^${updatedTypeScriptESLintVersion}`,
28+
},
29+
{
30+
packageName: '@typescript-eslint/utils',
31+
version: `^${updatedTypeScriptESLintVersion}`,
32+
},
33+
{
34+
packageName: '@typescript-eslint/type-utils',
35+
version: `^${updatedTypeScriptESLintVersion}`,
36+
},
37+
{
38+
packageName: '@typescript-eslint/parser',
39+
version: `^${updatedTypeScriptESLintVersion}`,
40+
},
41+
{
42+
packageName: '@typescript-eslint/rule-tester',
43+
version: `^${updatedTypeScriptESLintVersion}`,
44+
},
45+
{
46+
packageName: 'typescript-eslint',
47+
version: `^${updatedTypeScriptESLintVersion}`,
48+
},
49+
{
50+
packageName: 'eslint',
51+
version: `^${updatedESLintVersion}`,
52+
},
53+
]);
54+
}
55+
return undefined;
56+
},
57+
]);
58+
}
+26Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`update-20-0-0 should not update typescript-eslint and eslint dependencies if the project is not already on v8 releases of typescript-eslint 1`] = `
4+
Object {
5+
"devDependencies": Object {
6+
"@typescript-eslint/eslint-plugin": "^7",
7+
"@typescript-eslint/parser": "^7",
8+
"@typescript-eslint/utils": "^7",
9+
"eslint": "^8.28.0",
10+
},
11+
}
12+
`;
13+
14+
exports[`update-20-0-0 should update typescript-eslint and eslint dependencies if the project is already on v8 releases of typescript-eslint 1`] = `
15+
Object {
16+
"devDependencies": Object {
17+
"@typescript-eslint/eslint-plugin": "^8.33.1",
18+
"@typescript-eslint/parser": "^8.33.1",
19+
"@typescript-eslint/rule-tester": "^8.33.1",
20+
"@typescript-eslint/type-utils": "^8.33.1",
21+
"@typescript-eslint/utils": "^8.33.1",
22+
"eslint": "^9.28.0",
23+
"typescript-eslint": "^8.33.1",
24+
},
25+
}
26+
`;
+82Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
import { Tree } from '@angular-devkit/schematics';
2+
import {
3+
SchematicTestRunner,
4+
UnitTestTree,
5+
} from '@angular-devkit/schematics/testing';
6+
import * as path from 'path';
7+
8+
const migrationSchematicRunner = new SchematicTestRunner(
9+
'@angular-eslint/schematics',
10+
path.join(__dirname, '../../../src/migrations.json'),
11+
);
12+
13+
describe('update-20-0-0', () => {
14+
let appTree: UnitTestTree;
15+
beforeEach(() => {
16+
appTree = new UnitTestTree(Tree.empty());
17+
appTree.create('package.json', JSON.stringify({}));
18+
appTree.create(
19+
'angular.json',
20+
JSON.stringify({
21+
$schema: './node_modules/@angular/cli/lib/config/schema.json',
22+
version: 1,
23+
newProjectRoot: 'projects',
24+
projects: {
25+
foo: {
26+
root: 'projects/foo',
27+
},
28+
bar: {
29+
root: 'projects/bar',
30+
},
31+
},
32+
}),
33+
);
34+
});
35+
36+
it('should not update typescript-eslint and eslint dependencies if the project is not already on v8 releases of typescript-eslint', async () => {
37+
appTree.overwrite(
38+
'package.json',
39+
JSON.stringify({
40+
devDependencies: {
41+
'@typescript-eslint/eslint-plugin': '^7',
42+
'@typescript-eslint/utils': '^7',
43+
'@typescript-eslint/parser': '^7',
44+
eslint: '^8.28.0',
45+
},
46+
}),
47+
);
48+
49+
const tree = await migrationSchematicRunner.runSchematic(
50+
'update-18-2-0',
51+
{},
52+
appTree,
53+
);
54+
const packageJSON = JSON.parse(tree.readContent('/package.json'));
55+
expect(packageJSON).toMatchSnapshot();
56+
});
57+
58+
it('should update typescript-eslint and eslint dependencies if the project is already on v8 releases of typescript-eslint', async () => {
59+
appTree.overwrite(
60+
'package.json',
61+
JSON.stringify({
62+
devDependencies: {
63+
'@typescript-eslint/eslint-plugin': '8.0.0',
64+
'typescript-eslint': '8.0.0',
65+
'@typescript-eslint/utils': '8.0.0',
66+
'@typescript-eslint/parser': '8.0.0',
67+
'@typescript-eslint/type-utils': '8.0.0',
68+
'@typescript-eslint/rule-tester': '8.0.0',
69+
eslint: '9.8.0',
70+
},
71+
}),
72+
);
73+
74+
const tree = await migrationSchematicRunner.runSchematic(
75+
'update-20-0-0',
76+
{},
77+
appTree,
78+
);
79+
const packageJSON = JSON.parse(tree.readContent('/package.json'));
80+
expect(packageJSON).toMatchSnapshot();
81+
});
82+
});

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.