Skip to content

Commit 5364bbc

Browse files
committed
build: fix bootstrap-local when linked locally
Before it would try to load the package from the CLI project, as a regular require() call, now it adds a check to see if it can be resolved from the process.cwd(), before doing the previous behaviour.
1 parent 3ec0629 commit 5364bbc

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

lib/bootstrap-local.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,14 @@ require.extensions['.ts'] = function (m, filename) {
4646
// lazy: true
4747
// });
4848

49+
const resolve = require('resolve');
50+
51+
52+
// Look if there's a .angular-cli.json file, and if so toggle process.cwd() resolution.
53+
const isAngularProject = fs.existsSync(path.join(process.cwd(), '.angular-cli.json'))
54+
|| fs.existsSync(path.join(process.cwd(), 'angular-cli.json'));
55+
56+
4957
// If we're running locally, meaning npm linked. This is basically "developer mode".
5058
if (!__dirname.match(new RegExp(`\\${path.sep}node_modules\\${path.sep}`))) {
5159
const packages = require('./packages').packages;
@@ -71,6 +79,14 @@ if (!__dirname.match(new RegExp(`\\${path.sep}node_modules\\${path.sep}`))) {
7179
const p = path.join(packages[match].root, request.substr(match.length));
7280
return oldLoad.call(this, p, parent);
7381
} else {
82+
try {
83+
if (isAngularProject) {
84+
return oldLoad.call(this, resolve.sync(request, { basedir: process.cwd() }), parent);
85+
}
86+
} catch (e) {
87+
// Do nothing. Fallback to the old method.
88+
}
89+
7490
return oldLoad.apply(this, arguments);
7591
}
7692
}

0 commit comments

Comments
 (0)