Skip to content

Commit b4e32db

Browse files
committed
fix(@schematics/angular): migrate project dependencies to new project versions
This change reuses the v10 migration with update package versions to ensure that an updated project matches the development dependency versions of a newly generated project. (cherry picked from commit 644c2d7)
1 parent 2e766c9 commit b4e32db

File tree

2 files changed

+56
-0
lines changed

2 files changed

+56
-0
lines changed

packages/schematics/angular/migrations/migration-collection.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,11 @@
119119
"version": "11.0.0-next.8",
120120
"factory": "./update-11/update-angular-config",
121121
"description": "Remove deprecated options from 'angular.json' that are no longer present in v11."
122+
},
123+
"update-workspace-dependencies-v11": {
124+
"version": "11.0.0",
125+
"factory": "./update-11/update-dependencies",
126+
"description": "Update workspace dependencies to match a new v11 project."
122127
}
123128
}
124129
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/**
2+
* @license
3+
* Copyright Google Inc. All Rights Reserved.
4+
*
5+
* Use of this source code is governed by an MIT-style license that can be
6+
* found in the LICENSE file at https://angular.io/license
7+
*/
8+
import { Rule } from '@angular-devkit/schematics';
9+
import { NodePackageInstallTask } from '@angular-devkit/schematics/tasks';
10+
import {
11+
addPackageJsonDependency,
12+
getPackageJsonDependency,
13+
} from '../../utility/dependencies';
14+
import { latestVersions } from '../../utility/latest-versions';
15+
16+
export default function (): Rule {
17+
return (host, context) => {
18+
const dependenciesToUpdate: Record<string, string> = {
19+
'@types/jasmine': '~3.6.0',
20+
'codelyzer': '^6.0.0',
21+
'jasmine-core': '~3.6.0',
22+
'jasmine-spec-reporter': '~5.0.0',
23+
'karma-chrome-launcher': '~3.1.0',
24+
'karma-coverage': '~2.0.3',
25+
'karma-jasmine': '~4.0.0',
26+
'karma-jasmine-html-reporter': '^1.5.0',
27+
'tslib': '^2.0.0',
28+
};
29+
30+
let hasChanges = false;
31+
for (const [name, version] of Object.entries(dependenciesToUpdate)) {
32+
const current = getPackageJsonDependency(host, name);
33+
if (!current || current.version === version) {
34+
continue;
35+
}
36+
37+
addPackageJsonDependency(host, {
38+
type: current.type,
39+
name,
40+
version,
41+
overwrite: true,
42+
});
43+
44+
hasChanges = true;
45+
}
46+
47+
if (hasChanges) {
48+
context.addTask(new NodePackageInstallTask());
49+
}
50+
};
51+
}

0 commit comments

Comments
 (0)