@@ -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 ( / [ \/ \\ ] n o d e _ m o d u l e s [ \/ \\ ] @ a n g u l a r [ \/ \\ ] c l i [ \/ \\ ] / . 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 / [ \/ \\ ] n o d e _ m o d u l e s [ \/ \\ ] @ (?: a n g u l a r | s c h e m a t i c s | n g u n i v e r s a l ) [ \/ \\ ] / . test ( schematicFile ) ;
49+ return / \/ n o d e _ m o d u l e s \/ @ (?: a n g u l a r | s c h e m a t i c s | n g u n i v e r s a l ) \/ / . test ( normalizedSchematicFile ) ;
4550}
4651
4752export 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