Skip to content

Commit cf3b22d

Browse files
committed
fix(@angular/cli): correctly redirect nested Angular schematic dependency requests
Closes #21075
1 parent 82c438b commit cf3b22d

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

packages/angular/cli/models/schematic-engine-host.ts

+9-6
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,20 @@ function shouldWrapSchematic(schematicFile: string): boolean {
3333
}
3434
}
3535

36+
const normalizedSchematicFile = schematicFile.replace(/\\/g, '/');
3637
// Never wrap the internal update schematic when executed directly
3738
// It communicates with the update command via `global`
38-
if (/[\/\\]node_modules[\/\\]@angular[\/\\]cli[\/\\]/.test(schematicFile)) {
39+
// But we still want to redirect schematics located in `@angular/cli/node_modules`.
40+
if (
41+
normalizedSchematicFile.includes('node_modules/@angular/cli/') &&
42+
!normalizedSchematicFile.includes('node_modules/@angular/cli/node_modules/')
43+
) {
3944
return false;
4045
}
4146

4247
// Default is only first-party Angular schematic packages
4348
// Angular schematics are safe to use in the wrapped VM context
44-
return /[\/\\]node_modules[\/\\]@(?:angular|schematics|nguniversal)[\/\\]/.test(schematicFile);
49+
return /\/node_modules\/@(?:angular|schematics|nguniversal)\//.test(normalizedSchematicFile);
4550
}
4651

4752
export class SchematicEngineHost extends NodeModulesEngineHost {
@@ -115,10 +120,8 @@ function wrap(
115120
moduleCache: Map<string, unknown>,
116121
exportName?: string,
117122
): () => unknown {
118-
const { createRequire, createRequireFromPath } = require('module');
119-
// Node.js 10.x does not support `createRequire` so fallback to `createRequireFromPath`
120-
// `createRequireFromPath` is deprecated in 12+ and can be removed once 10.x support is removed
121-
const scopedRequire = createRequire?.(schematicFile) || createRequireFromPath(schematicFile);
123+
const { createRequire } = require('module');
124+
const scopedRequire = createRequire(schematicFile);
122125

123126
const customRequire = function (id: string) {
124127
if (legacyModules[id]) {

0 commit comments

Comments
 (0)