mirror of
https://github.com/angular/angular-cli.git
synced 2025-05-18 03:23:57 +08:00
refactor(@angular/cli): remove resolve dependency
This commit is contained in:
parent
8b3cada6ea
commit
e54213e488
4
lib/bootstrap-local.js
vendored
4
lib/bootstrap-local.js
vendored
@ -46,8 +46,6 @@ require.extensions['.ts'] = function (m, filename) {
|
|||||||
// lazy: true
|
// lazy: true
|
||||||
// });
|
// });
|
||||||
|
|
||||||
const resolve = require('resolve');
|
|
||||||
|
|
||||||
const builtinModules = Object.keys(process.binding('natives'));
|
const builtinModules = Object.keys(process.binding('natives'));
|
||||||
|
|
||||||
// Look if there's a .angular-cli.json file, and if so toggle process.cwd() resolution.
|
// Look if there's a .angular-cli.json file, and if so toggle process.cwd() resolution.
|
||||||
@ -83,7 +81,7 @@ if (!__dirname.match(new RegExp(`\\${path.sep}node_modules\\${path.sep}`))) {
|
|||||||
if (!builtinModules.includes(request)) {
|
if (!builtinModules.includes(request)) {
|
||||||
try {
|
try {
|
||||||
if (isAngularProject) {
|
if (isAngularProject) {
|
||||||
return oldLoad.call(this, resolve.sync(request, { basedir: process.cwd() }), parent);
|
return oldLoad.call(this, require.resolve(request, { paths: [process.cwd()] }), parent);
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
// Do nothing. Fallback to the old method.
|
// Do nothing. Fallback to the old method.
|
||||||
|
4
package-lock.json
generated
4
package-lock.json
generated
@ -7167,7 +7167,8 @@
|
|||||||
"path-parse": {
|
"path-parse": {
|
||||||
"version": "1.0.5",
|
"version": "1.0.5",
|
||||||
"resolved": "https://registry.npmjs.org/path-parse/-/path-parse-1.0.5.tgz",
|
"resolved": "https://registry.npmjs.org/path-parse/-/path-parse-1.0.5.tgz",
|
||||||
"integrity": "sha1-PBrfhx6pzWyUMbbqK9dKD/BVxME="
|
"integrity": "sha1-PBrfhx6pzWyUMbbqK9dKD/BVxME=",
|
||||||
|
"dev": true
|
||||||
},
|
},
|
||||||
"path-to-regexp": {
|
"path-to-regexp": {
|
||||||
"version": "0.1.7",
|
"version": "0.1.7",
|
||||||
@ -7857,6 +7858,7 @@
|
|||||||
"version": "1.6.0",
|
"version": "1.6.0",
|
||||||
"resolved": "https://registry.npmjs.org/resolve/-/resolve-1.6.0.tgz",
|
"resolved": "https://registry.npmjs.org/resolve/-/resolve-1.6.0.tgz",
|
||||||
"integrity": "sha512-mw7JQNu5ExIkcw4LPih0owX/TZXjD/ZUF/ZQ/pDnkw3ZKhDcZZw5klmBlj6gVMwjQ3Pz5Jgu7F3d0jcDVuEWdw==",
|
"integrity": "sha512-mw7JQNu5ExIkcw4LPih0owX/TZXjD/ZUF/ZQ/pDnkw3ZKhDcZZw5klmBlj6gVMwjQ3Pz5Jgu7F3d0jcDVuEWdw==",
|
||||||
|
"dev": true,
|
||||||
"requires": {
|
"requires": {
|
||||||
"path-parse": "^1.0.5"
|
"path-parse": "^1.0.5"
|
||||||
}
|
}
|
||||||
|
@ -48,7 +48,6 @@
|
|||||||
"@schematics/angular": "github:angular/schematics-angular-builds",
|
"@schematics/angular": "github:angular/schematics-angular-builds",
|
||||||
"@schematics/update": "github:angular/schematics-update-builds",
|
"@schematics/update": "github:angular/schematics-update-builds",
|
||||||
"opn": "~5.3.0",
|
"opn": "~5.3.0",
|
||||||
"resolve": "^1.1.7",
|
|
||||||
"rxjs": "^6.0.0",
|
"rxjs": "^6.0.0",
|
||||||
"semver": "^5.3.0",
|
"semver": "^5.3.0",
|
||||||
"symbol-observable": "^1.2.0",
|
"symbol-observable": "^1.2.0",
|
||||||
|
@ -12,11 +12,9 @@ const isWarningEnabled = require('../utilities/config').isWarningEnabled;
|
|||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
const packageJson = require('../package.json');
|
const packageJson = require('../package.json');
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
const resolve = require('resolve');
|
|
||||||
const stripIndents = require('@angular-devkit/core').tags.stripIndents;
|
const stripIndents = require('@angular-devkit/core').tags.stripIndents;
|
||||||
const yellow = require('@angular-devkit/core').terminal.yellow;
|
const yellow = require('@angular-devkit/core').terminal.yellow;
|
||||||
const SemVer = require('semver').SemVer;
|
const SemVer = require('semver').SemVer;
|
||||||
const events = require('events');
|
|
||||||
|
|
||||||
function _fromPackageJson(cwd?: string) {
|
function _fromPackageJson(cwd?: string) {
|
||||||
cwd = cwd || process.cwd();
|
cwd = cwd || process.cwd();
|
||||||
@ -62,16 +60,10 @@ if (process.env['NG_CLI_PROFILING']) {
|
|||||||
process.on('uncaughtException', exitHandler.bind(null, { exit: true }));
|
process.on('uncaughtException', exitHandler.bind(null, { exit: true }));
|
||||||
}
|
}
|
||||||
|
|
||||||
resolve('@angular/cli', { basedir: process.cwd() },
|
let cli;
|
||||||
function (error: Error, projectLocalCli: string) {
|
try {
|
||||||
let cli;
|
const projectLocalCli = require.resolve('@angular/cli', { paths: [ process.cwd() ]});
|
||||||
if (error) {
|
|
||||||
// If there is an error, resolve could not find the ng-cli
|
|
||||||
// library from a package.json. Instead, include it from a relative
|
|
||||||
// path to this script file (which is likely a globally installed
|
|
||||||
// npm package). Most common cause for hitting this is `ng new`
|
|
||||||
cli = require('./cli');
|
|
||||||
} else {
|
|
||||||
// This was run from a global, check local version.
|
// This was run from a global, check local version.
|
||||||
const globalVersion = new SemVer(packageJson['version']);
|
const globalVersion = new SemVer(packageJson['version']);
|
||||||
let localVersion;
|
let localVersion;
|
||||||
@ -107,30 +99,23 @@ resolve('@angular/cli', { basedir: process.cwd() },
|
|||||||
// No error implies a projectLocalCli, which will load whatever
|
// No error implies a projectLocalCli, which will load whatever
|
||||||
// version of ng-cli you have installed in a local package.json
|
// version of ng-cli you have installed in a local package.json
|
||||||
cli = require(projectLocalCli);
|
cli = require(projectLocalCli);
|
||||||
}
|
} catch {
|
||||||
|
// If there is an error, resolve could not find the ng-cli
|
||||||
|
// library from a package.json. Instead, include it from a relative
|
||||||
|
// path to this script file (which is likely a globally installed
|
||||||
|
// npm package). Most common cause for hitting this is `ng new`
|
||||||
|
cli = require('./cli');
|
||||||
|
}
|
||||||
|
|
||||||
if ('default' in cli) {
|
if ('default' in cli) {
|
||||||
cli = cli['default'];
|
cli = cli['default'];
|
||||||
}
|
}
|
||||||
|
|
||||||
let standardInput;
|
cli({ cliArgs: process.argv.slice(2) })
|
||||||
try {
|
.then((exitCode: number) => {
|
||||||
standardInput = process.stdin;
|
|
||||||
} catch (e) {
|
|
||||||
delete process.stdin;
|
|
||||||
process.stdin = new events.EventEmitter();
|
|
||||||
standardInput = process.stdin;
|
|
||||||
}
|
|
||||||
|
|
||||||
cli({
|
|
||||||
cliArgs: process.argv.slice(2),
|
|
||||||
inputStream: standardInput,
|
|
||||||
outputStream: process.stdout
|
|
||||||
}).then(function (exitCode: number) {
|
|
||||||
process.exit(exitCode);
|
process.exit(exitCode);
|
||||||
}).catch(function(err: Error) {
|
})
|
||||||
|
.catch((err: Error) => {
|
||||||
console.log('Unknown error: ' + err.toString());
|
console.log('Unknown error: ' + err.toString());
|
||||||
process.exit(127);
|
process.exit(127);
|
||||||
});
|
});
|
||||||
}
|
|
||||||
);
|
|
||||||
|
@ -36,7 +36,6 @@
|
|||||||
"@schematics/angular": "0.6.1",
|
"@schematics/angular": "0.6.1",
|
||||||
"@schematics/update": "0.6.1",
|
"@schematics/update": "0.6.1",
|
||||||
"opn": "~5.3.0",
|
"opn": "~5.3.0",
|
||||||
"resolve": "^1.1.7",
|
|
||||||
"rxjs": "^6.0.0",
|
"rxjs": "^6.0.0",
|
||||||
"semver": "^5.1.0",
|
"semver": "^5.1.0",
|
||||||
"symbol-observable": "^1.2.0",
|
"symbol-observable": "^1.2.0",
|
||||||
|
@ -4,8 +4,6 @@ import * as path from 'path';
|
|||||||
import { isWarningEnabled } from '../utilities/config';
|
import { isWarningEnabled } from '../utilities/config';
|
||||||
import { requireProjectModule } from '../utilities/require-project-module';
|
import { requireProjectModule } from '../utilities/require-project-module';
|
||||||
|
|
||||||
const resolve = require('resolve');
|
|
||||||
|
|
||||||
|
|
||||||
export class Version {
|
export class Version {
|
||||||
private _semver: SemVer = null;
|
private _semver: SemVer = null;
|
||||||
@ -31,28 +29,6 @@ export class Version {
|
|||||||
|
|
||||||
toString() { return this._version; }
|
toString() { return this._version; }
|
||||||
|
|
||||||
static fromProject(): Version {
|
|
||||||
let packageJson: any = null;
|
|
||||||
|
|
||||||
try {
|
|
||||||
const angularCliPath = resolve.sync('@angular/cli', {
|
|
||||||
basedir: process.cwd(),
|
|
||||||
packageFilter: (pkg: any, _pkgFile: string) => {
|
|
||||||
return packageJson = pkg;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
if (angularCliPath && packageJson) {
|
|
||||||
try {
|
|
||||||
return new Version(packageJson.version);
|
|
||||||
} catch {
|
|
||||||
return new Version(null);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch {
|
|
||||||
return new Version(null);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static assertCompatibleAngularVersion(projectRoot: string) {
|
static assertCompatibleAngularVersion(projectRoot: string) {
|
||||||
let angularPkgJson;
|
let angularPkgJson;
|
||||||
let rxjsPkgJson;
|
let rxjsPkgJson;
|
||||||
|
@ -1,8 +1,7 @@
|
|||||||
const resolve = require('resolve');
|
|
||||||
|
|
||||||
// resolve dependencies within the target project
|
// resolve dependencies within the target project
|
||||||
export function resolveProjectModule(root: string, moduleName: string) {
|
export function resolveProjectModule(root: string, moduleName: string) {
|
||||||
return resolve.sync(moduleName, { basedir: root });
|
return require.resolve(moduleName, { paths: [root] });
|
||||||
}
|
}
|
||||||
|
|
||||||
// require dependencies within the target project
|
// require dependencies within the target project
|
||||||
|
Loading…
x
Reference in New Issue
Block a user