Skip to content
This repository was archived by the owner on Apr 4, 2025. It is now read-only.

Commit 822f1e5

Browse files
committed
fix(@schematics/update): fix major of angular compat with major + 1
When there are complex ranges, ltr(x) is not equal to !gtr(x). Fix angular/angular-cli#10540
1 parent b4f1a64 commit 822f1e5

File tree

3 files changed

+59
-3
lines changed

3 files changed

+59
-3
lines changed

packages/schematics/update/update/index.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,16 @@ const peerCompatibleWhitelist: { [name: string]: PeerVersionTransform } = {
3535
'@angular/core': (range: string) => {
3636
range = semver.validRange(range);
3737
let major = 1;
38-
while (semver.ltr(major + '.0.0', range)) {
38+
while (!semver.gtr(major + '.0.0', range)) {
3939
major++;
4040
if (major >= 99) {
4141
throw new SchematicsException(`Invalid range: ${JSON.stringify(range)}`);
4242
}
4343
}
4444

45-
// Add the major - 1 version as compatible with the angular compatible.
46-
return semver.validRange(`^${major + 1}.0.0-rc.0 || ${range}`) || range;
45+
// Add the major version as compatible with the angular compatible. This is already one
46+
// major above the greatest supported, because we increment `major` before checking.
47+
return semver.validRange(`^${major}.0.0-rc.0 || ${range}`) || range;
4748
},
4849
};
4950

packages/schematics/update/update/index_spec.ts

+45
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,51 @@ describe('@schematics/update', () => {
129129
).subscribe(undefined, done.fail, done);
130130
}, 45000);
131131

132+
it('updates Angular as compatible with Angular N-1 (2)', done => {
133+
// Add the basic migration package.
134+
const content = virtualFs.fileBufferToString(host.sync.read(normalize('/package.json')));
135+
const packageJson = JSON.parse(content);
136+
const dependencies = packageJson['dependencies'];
137+
dependencies['@angular-devkit-tests/update-peer-dependencies-angular-5-2'] = '1.0.0';
138+
dependencies['@angular/core'] = '5.1.0';
139+
dependencies['@angular/animations'] = '5.1.0';
140+
dependencies['@angular/common'] = '5.1.0';
141+
dependencies['@angular/compiler'] = '5.1.0';
142+
dependencies['@angular/platform-browser'] = '5.1.0';
143+
dependencies['rxjs'] = '5.5.0';
144+
dependencies['zone.js'] = '0.8.26';
145+
host.sync.write(
146+
normalize('/package.json'),
147+
virtualFs.stringToFileBuffer(JSON.stringify(packageJson)),
148+
);
149+
150+
schematicRunner.runSchematicAsync('update', {
151+
packages: ['@angular/core'],
152+
next: true,
153+
}, appTree).pipe(
154+
map(tree => {
155+
const packageJson = JSON.parse(tree.readContent('/package.json'));
156+
expect(packageJson['dependencies']['@angular/core'][0]).toBe('6');
157+
158+
// Check install task.
159+
expect(schematicRunner.tasks).toEqual([
160+
{
161+
name: 'node-package',
162+
options: jasmine.objectContaining({
163+
command: 'install',
164+
}),
165+
},
166+
{
167+
name: 'run-schematic',
168+
options: jasmine.objectContaining({
169+
name: 'migrate',
170+
}),
171+
},
172+
]);
173+
}),
174+
).subscribe(undefined, done.fail, done);
175+
}, 45000);
176+
132177
it('can migrate only', done => {
133178
// Add the basic migration package.
134179
const content = virtualFs.fileBufferToString(host.sync.read(normalize('/package.json')));
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"name": "@angular-devkit-tests/update-peer-dependencies-angular-5-2",
3+
"version": "1.0.0",
4+
"description": "Tests",
5+
"peerDependencies": {
6+
"@angular/animations": ">= 1 < 5.0.0 || >= 5.0.0-rc.0 < 6.0.0",
7+
"@angular/compiler": ">= 1 < 5.0.0 || >= 5.0.0-rc.0 < 6.0.0",
8+
"@angular/platform-browser": ">= 1 < 5.0.0 || >= 5.0.0-rc.0 < 6.0.0"
9+
}
10+
}

0 commit comments

Comments
 (0)