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:
Hans Larsen 2017-10-20 15:59:47 -07:00 committed by Hans
parent ca5e18c66c
commit dd9e69e1ae

View File

@ -46,6 +46,14 @@ require.extensions['.ts'] = function (m, filename) {
// lazy: true // 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 we're running locally, meaning npm linked. This is basically "developer mode".
if (!__dirname.match(new RegExp(`\\${path.sep}node_modules\\${path.sep}`))) { if (!__dirname.match(new RegExp(`\\${path.sep}node_modules\\${path.sep}`))) {
const packages = require('./packages').packages; 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)); const p = path.join(packages[match].root, request.substr(match.length));
return oldLoad.call(this, p, parent); return oldLoad.call(this, p, parent);
} else { } 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); return oldLoad.apply(this, arguments);
} }
} }