Skip to content

Commit 1ae7916

Browse files
committed
fix(@angular-devkit/schematics): better error when no schematics field in package.json
cf. angular/angular-cli#10467
1 parent fb9daad commit 1ae7916

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
* Use of this source code is governed by an MIT-style license that can be
66
* found in the LICENSE file at https://angular.io/license
77
*/
8+
import { BaseException } from '@angular-devkit/core';
89
import * as core from '@angular-devkit/core/node';
910
import { dirname, join, resolve as resolvePath } from 'path';
1011
import { RuleFactory } from '../src';
@@ -22,6 +23,13 @@ import { FileSystemEngineHostBase } from './file-system-engine-host-base';
2223
import { readJsonFile } from './file-system-utility';
2324

2425

26+
export class NodePackageDoesNotSupportSchematics extends BaseException {
27+
constructor(name: string) {
28+
super(`Package ${JSON.stringify(name)} was found but does not support schematics.`);
29+
}
30+
}
31+
32+
2533
/**
2634
* A simple EngineHost that uses NodeModules to resolve collections.
2735
*/
@@ -81,6 +89,9 @@ export class NodeModulesEngineHost extends FileSystemEngineHostBase {
8189
}
8290

8391
const pkgJsonSchematics = require(packageJsonPath)['schematics'];
92+
if (!pkgJsonSchematics || typeof pkgJsonSchematics != 'string') {
93+
throw new NodePackageDoesNotSupportSchematics(name);
94+
}
8495
collectionPath = this._resolvePath(pkgJsonSchematics, dirname(packageJsonPath));
8596
}
8697

0 commit comments

Comments
 (0)