@@ -94,9 +94,9 @@ require.extensions['.ejs'] = function (m, filename) {
9494} ;
9595
9696
97+ const packages = require ( './packages' ) . packages ;
9798// If we're running locally, meaning npm linked. This is basically "developer mode".
9899if ( ! __dirname . match ( new RegExp ( `\\${ path . sep } node_modules\\${ path . sep } ` ) ) ) {
99- const packages = require ( './packages' ) . packages ;
100100
101101 // We mock the module loader so that we can fake our packages when running locally.
102102 const Module = require ( 'module' ) ;
@@ -107,7 +107,7 @@ if (!__dirname.match(new RegExp(`\\${path.sep}node_modules\\${path.sep}`))) {
107107 if ( request in packages ) {
108108 return packages [ request ] . main ;
109109 } else {
110- let match = Object . keys ( packages ) . find ( pkgName => request . startsWith ( pkgName + '/' ) ) ;
110+ const match = Object . keys ( packages ) . find ( pkgName => request . startsWith ( pkgName + '/' ) ) ;
111111 if ( match ) {
112112 const p = path . join ( packages [ match ] . root , request . substr ( match . length ) ) ;
113113 return oldResolve . call ( this , p , parent ) ;
@@ -117,3 +117,29 @@ if (!__dirname.match(new RegExp(`\\${path.sep}node_modules\\${path.sep}`))) {
117117 }
118118 } ;
119119}
120+
121+
122+ // Set the resolve hook to allow resolution of packages from a local dev environment.
123+ require ( '@angular-devkit/core/node/resolve' ) . setResolveHook ( function ( request , options ) {
124+ try {
125+ if ( request in packages ) {
126+ if ( options . resolvePackageJson ) {
127+ return path . join ( packages [ request ] . root , 'package.json' ) ;
128+ } else {
129+ return packages [ request ] . main ;
130+ }
131+ } else {
132+ const match = Object . keys ( packages ) . find ( function ( pkgName ) {
133+ return request . startsWith ( pkgName + '/' ) ;
134+ } ) ;
135+
136+ if ( match ) {
137+ return path . join ( packages [ match ] . root , request . substr ( match [ 0 ] . length ) ) ;
138+ } else {
139+ return null ;
140+ }
141+ }
142+ } catch ( _ ) {
143+ return null ;
144+ }
145+ } ) ;
0 commit comments