diff --git a/lib/bootstrap-local.js b/lib/bootstrap-local.js index 87c26379d3..977eccade9 100644 --- a/lib/bootstrap-local.js +++ b/lib/bootstrap-local.js @@ -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); } }