Skip to content

Commit 5df7767

Browse files
clydinvikerman
authored andcommitted
fix(@angular-devkit/schematics): use NodeWorkflow root to resolve collections
1 parent a269213 commit 5df7767

File tree

5 files changed

+15
-5
lines changed

5 files changed

+15
-5
lines changed

etc/api/angular_devkit/schematics/tools/index.d.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ export declare class InvalidCollectionJsonException extends BaseException {
105105
}
106106

107107
export declare class NodeModulesEngineHost extends FileSystemEngineHostBase {
108-
constructor();
108+
constructor(paths?: string[] | undefined);
109109
protected _resolveCollectionPath(name: string): string;
110110
protected _resolveReferenceString(refString: string, parentPath: string): {
111111
ref: RuleFactory<{}>;
@@ -136,6 +136,7 @@ export declare class NodeWorkflow extends workflow.BaseWorkflow {
136136
root?: Path;
137137
packageManager?: string;
138138
registry?: schema.CoreSchemaRegistry;
139+
resolvePaths?: string[];
139140
});
140141
}
141142

packages/angular/cli/commands/update-impl.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ export class UpdateCommand extends Command<UpdateCommandSchema> {
5050
{
5151
packageManager: this.packageManager,
5252
root: normalize(this.workspace.root),
53+
// __dirname -> favor @schematics/update from this package
54+
// Otherwise, use packages from the active workspace (migrations)
55+
resolvePaths: [__dirname, this.workspace.root],
5356
},
5457
);
5558
this.workflow.engineHost.registerOptionsTransform(

packages/angular/cli/models/schematic-command.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,11 @@ export abstract class SchematicCommand<
253253
packageManager: await getPackageManager(this.workspace.root),
254254
root: normalize(this.workspace.root),
255255
registry: new schema.CoreSchemaRegistry(formats.standardFormats),
256+
resolvePaths: !!this.workspace.configFile
257+
// Workspace
258+
? [process.cwd(), this.workspace.root]
259+
// Global
260+
: [__dirname, process.cwd()],
256261
});
257262
workflow.engineHost.registerContextTransform(context => {
258263
// This is run by ALL schematics, so if someone uses `externalSchematics(...)` which

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ export class NodePackageDoesNotSupportSchematics extends BaseException {
3737
* A simple EngineHost that uses NodeModules to resolve collections.
3838
*/
3939
export class NodeModulesEngineHost extends FileSystemEngineHostBase {
40-
constructor() { super(); }
40+
constructor(private readonly paths?: string[]) { super(); }
4141

4242
protected _resolveCollectionPath(name: string): string {
4343
let collectionPath: string | undefined = undefined;
@@ -47,9 +47,9 @@ export class NodeModulesEngineHost extends FileSystemEngineHostBase {
4747

4848
if (extname(name)) {
4949
// When having an extension let's just resolve the provided path.
50-
collectionPath = require.resolve(name);
50+
collectionPath = require.resolve(name, { paths: this.paths });
5151
} else {
52-
const packageJsonPath = require.resolve(join(name, 'package.json'));
52+
const packageJsonPath = require.resolve(join(name, 'package.json'), { paths: this.paths });
5353
const { schematics } = require(packageJsonPath);
5454

5555
if (!schematics || typeof schematics !== 'string') {

packages/angular_devkit/schematics/tools/workflow/node-workflow.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,10 @@ export class NodeWorkflow extends workflow.BaseWorkflow {
2525
root?: Path;
2626
packageManager?: string;
2727
registry?: schema.CoreSchemaRegistry;
28+
resolvePaths?: string[],
2829
},
2930
) {
30-
const engineHost = new NodeModulesEngineHost();
31+
const engineHost = new NodeModulesEngineHost(options.resolvePaths);
3132
super({
3233
host,
3334
engineHost,

0 commit comments

Comments
 (0)