Skip to content

Commit a57f053

Browse files
devversionalexeagle
authored andcommitted
fix(@angular/cli): ng-update migrations not running with --migrate-only
With Angular CLI version 8, migrations cannot be re-run with the `--migrate-only` flag as there was a recent regression introduced in e406f00#diff-0d0a748fb9a38a7ccde08d9b42e70bce as it now passes a normalized platform path to the `engine.createCollection` call. This breaks as there is incorrect logic within `node-modules-engine-host` that causes the schematic collection to be searched within the `package.json#schematics` entry. This is incorrect as migration schematics specify their migration schematics in a separate schematic collection file which is part of `package.json#ng-update`. Fixes #14565
1 parent 410b56e commit a57f053

File tree

2 files changed

+55
-1
lines changed

2 files changed

+55
-1
lines changed

packages/angular_devkit/schematics/tools/node-module-engine-host.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ export class NodeModulesEngineHost extends FileSystemEngineHostBase {
7979
protected _resolveCollectionPath(name: string): string {
8080
let collectionPath: string | undefined = undefined;
8181

82-
if (name.replace(/\\/, '/').split('/').length > (name[0] == '@' ? 2 : 1)) {
82+
if (name.replace(/\\/g, '/').split('/').length > (name[0] == '@' ? 2 : 1)) {
8383
try {
8484
collectionPath = this._resolvePath(name, process.cwd());
8585
} catch {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
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+
9+
// tslint:disable:no-implicit-dependencies
10+
11+
import { SchematicEngine } from '@angular-devkit/schematics';
12+
import * as fs from 'fs';
13+
import * as os from 'os';
14+
import * as path from 'path';
15+
import { NodeModulesEngineHost } from './node-module-engine-host';
16+
17+
const TMP_DIR = process.env['$TEST_TMPDIR'] || os.tmpdir();
18+
19+
describe('NodeModulesEngineHost', () => {
20+
let tmpDir!: string;
21+
let previousDir!: string;
22+
23+
beforeEach(() => {
24+
tmpDir = fs.mkdtempSync(path.join(TMP_DIR,
25+
'angular-devkit-schematics-tools-node-module-engine-host'));
26+
previousDir = process.cwd();
27+
process.chdir(tmpDir);
28+
});
29+
30+
afterEach(() => process.chdir(previousDir));
31+
32+
/** Creates a fake NPM module that can be used to test the node module engine host. */
33+
function createFakeNpmModule() {
34+
fs.mkdirSync(path.join(tmpDir, 'node_modules'));
35+
fs.mkdirSync(path.join(tmpDir, 'node_modules/@angular/'));
36+
fs.mkdirSync(path.join(tmpDir, 'node_modules/@angular/core'));
37+
fs.mkdirSync(path.join(tmpDir, 'node_modules/@angular/core/schematics'));
38+
fs.writeFileSync(path.join(tmpDir, 'node_modules/@angular/core/package.json'),
39+
JSON.stringify({name: '@angular/core'}));
40+
fs.writeFileSync(path.join(tmpDir, 'node_modules/@angular/core/schematics/migrations.json'),
41+
JSON.stringify({schematics: {}}));
42+
}
43+
44+
it('should properly create collections with explicit collection path', () => {
45+
createFakeNpmModule();
46+
47+
const engineHost = new NodeModulesEngineHost();
48+
const engine = new SchematicEngine(engineHost);
49+
50+
expect(() => {
51+
engine.createCollection(path.join('@angular/core', './schematics/migrations.json'));
52+
}).not.toThrow();
53+
});
54+
});

0 commit comments

Comments
 (0)