Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(@angular/cli): ng-update migrations not running with --migrate-only #14567

Merged
merged 1 commit into from
May 30, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export class NodeModulesEngineHost extends FileSystemEngineHostBase {
protected _resolveCollectionPath(name: string): string {
let collectionPath: string | undefined = undefined;

if (name.replace(/\\/, '/').split('/').length > (name[0] == '@' ? 2 : 1)) {
if (name.replace(/\\/g, '/').split('/').length > (name[0] == '@' ? 2 : 1)) {
try {
collectionPath = this._resolvePath(name, process.cwd());
} catch {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/**
* @license
* Copyright Google Inc. All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/

// tslint:disable:no-implicit-dependencies

import { SchematicEngine } from '@angular-devkit/schematics';
import * as fs from 'fs';
import * as os from 'os';
import * as path from 'path';
import { NodeModulesEngineHost } from './node-module-engine-host';

const TMP_DIR = process.env['$TEST_TMPDIR'] || os.tmpdir();

describe('NodeModulesEngineHost', () => {
let tmpDir!: string;
let previousDir!: string;

beforeEach(() => {
tmpDir = fs.mkdtempSync(path.join(TMP_DIR,
'angular-devkit-schematics-tools-node-module-engine-host'));
previousDir = process.cwd();
process.chdir(tmpDir);
});

afterEach(() => process.chdir(previousDir));

/** Creates a fake NPM module that can be used to test the node module engine host. */
function createFakeNpmModule() {
fs.mkdirSync(path.join(tmpDir, 'node_modules'));
fs.mkdirSync(path.join(tmpDir, 'node_modules/@angular/'));
fs.mkdirSync(path.join(tmpDir, 'node_modules/@angular/core'));
fs.mkdirSync(path.join(tmpDir, 'node_modules/@angular/core/schematics'));
fs.writeFileSync(path.join(tmpDir, 'node_modules/@angular/core/package.json'),
JSON.stringify({name: '@angular/core'}));
fs.writeFileSync(path.join(tmpDir, 'node_modules/@angular/core/schematics/migrations.json'),
JSON.stringify({schematics: {}}));
}

it('should properly create collections with explicit collection path', () => {
createFakeNpmModule();

const engineHost = new NodeModulesEngineHost();
const engine = new SchematicEngine(engineHost);

expect(() => {
engine.createCollection(path.join('@angular/core', './schematics/migrations.json'));
}).not.toThrow();
});
});