mirror of
https://github.com/angular/angular-cli.git
synced 2025-05-15 18:13:38 +08:00
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.
This commit is contained in:
parent
ca5e18c66c
commit
dd9e69e1ae
16
lib/bootstrap-local.js
vendored
16
lib/bootstrap-local.js
vendored
@ -46,6 +46,14 @@ require.extensions['.ts'] = function (m, filename) {
|
||||
// lazy: true
|
||||
// });
|
||||
|
||||
const resolve = require('resolve');
|
||||
|
||||
|
||||
// Look if there's a .angular-cli.json file, and if so toggle process.cwd() resolution.
|
||||
const isAngularProject = fs.existsSync(path.join(process.cwd(), '.angular-cli.json'))
|
||||
|| fs.existsSync(path.join(process.cwd(), 'angular-cli.json'));
|
||||
|
||||
|
||||
// If we're running locally, meaning npm linked. This is basically "developer mode".
|
||||
if (!__dirname.match(new RegExp(`\\${path.sep}node_modules\\${path.sep}`))) {
|
||||
const packages = require('./packages').packages;
|
||||
@ -71,6 +79,14 @@ if (!__dirname.match(new RegExp(`\\${path.sep}node_modules\\${path.sep}`))) {
|
||||
const p = path.join(packages[match].root, request.substr(match.length));
|
||||
return oldLoad.call(this, p, parent);
|
||||
} else {
|
||||
try {
|
||||
if (isAngularProject) {
|
||||
return oldLoad.call(this, resolve.sync(request, { basedir: process.cwd() }), parent);
|
||||
}
|
||||
} catch (e) {
|
||||
// Do nothing. Fallback to the old method.
|
||||
}
|
||||
|
||||
return oldLoad.apply(this, arguments);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user