Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const exitHandler = (options) => {
if (options.cleanup) {
const cpuProfile = profiler.stopProfiling();
fs.writeFileSync(path.resolve(process.cwd(), process.env.NG_CLI_PROFILING || '') + '.cpuprofile', JSON.stringify(cpuProfile));
}
if (options.exit) {
process.exit();
}
};
process.on('exit', () => exitHandler({ cleanup: true }));
process.on('SIGINT', () => exitHandler({ exit: true }));
process.on('uncaughtException', () => exitHandler({ exit: true }));
}
let cli;
try {
const projectLocalCli = node_1.resolve('@angular/cli', {
checkGlobal: false,
basedir: process.cwd(),
preserveSymlinks: true,
});
// This was run from a global, check local version.
const globalVersion = new semver_1.SemVer(packageJson['version']);
let localVersion;
let shouldWarn = false;
try {
localVersion = _fromPackageJson();
shouldWarn = localVersion != null && globalVersion.compare(localVersion) > 0;
}
catch (e) {
// eslint-disable-next-line no-console
console.error(e);
shouldWarn = true;
_resolvePath(name, basedir = process.cwd()) {
// Allow relative / absolute paths.
if (name.startsWith('.') || name.startsWith('/')) {
return path_1.resolve(basedir, name);
}
else {
// If it's a file inside a package, resolve the package then return the file...
if (name.split('/').length > (name[0] == '@' ? 2 : 1)) {
const rest = name.split('/');
const packageName = rest.shift() + (name[0] == '@' ? '/' + rest.shift() : '');
return path_1.resolve(core.resolve(packageName, {
basedir,
checkLocal: true,
checkGlobal: true,
resolvePackageJson: true,
}), '..', ...rest);
}
return core.resolve(name, {
basedir,
checkLocal: true,
checkGlobal: true,
});
}
}
_resolveCollectionPath(name) {
if (name.startsWith('.') || name.startsWith('/')) {
return path_1.resolve(basedir, name);
}
else {
// If it's a file inside a package, resolve the package then return the file...
if (name.split('/').length > (name[0] == '@' ? 2 : 1)) {
const rest = name.split('/');
const packageName = rest.shift() + (name[0] == '@' ? '/' + rest.shift() : '');
return path_1.resolve(core.resolve(packageName, {
basedir,
checkLocal: true,
checkGlobal: true,
resolvePackageJson: true,
}), '..', ...rest);
}
return core.resolve(name, {
basedir,
checkLocal: true,
checkGlobal: true,
});
}
}
_resolveCollectionPath(name) {
return new rxjs_1.Observable((obs) => {
// TODO: this probably needs to be more like NodeModulesEngineHost.
const basedir = core_1.getSystemPath(this._workspace.root);
const [pkg, builderName] = builderConfig.builder.split(':');
const pkgJsonPath = node_1.resolve(pkg, { basedir, resolvePackageJson: true, checkLocal: true });
let buildersJsonPath;
let builderPaths;
// Read the `builders` entry of package.json.
return this._loadJsonFile(core_1.normalize(pkgJsonPath)).pipe(operators_1.concatMap((pkgJson) => {
const pkgJsonBuildersentry = pkgJson['builders'];
if (!pkgJsonBuildersentry) {
return rxjs_1.throwError(new BuilderCannotBeResolvedException(builderConfig.builder));
}
buildersJsonPath = core_1.join(core_1.dirname(core_1.normalize(pkgJsonPath)), pkgJsonBuildersentry);
return this._loadJsonFile(buildersJsonPath);
}),
// Validate builders json.
operators_1.concatMap((builderPathsMap) => this._workspace.validateAgainstSchema(builderPathsMap, this._buildersSchema)), operators_1.concatMap((builderPathsMap) => {
builderPaths = builderPathsMap.builders[builderName];
if (!builderPaths) {
return rxjs_1.throwError(new BuilderCannotBeResolvedException(builderConfig.builder));
_resolvePath(name, basedir = process.cwd()) {
// Allow relative / absolute paths.
if (name.startsWith('.') || name.startsWith('/')) {
return path_1.resolve(basedir, name);
}
else {
return core.resolve(name, {
basedir,
checkLocal: true,
checkGlobal: true,
});
}
}
_resolveCollectionPath(name) {
return (host: Tree) => {
const allowed = '>=2.8.0';
let tsVersion: string;
try {
const resolveOptions = {
basedir: host.root.path,
checkGlobal: false,
checkLocal: true,
};
tsVersion = require(resolve('typescript', resolveOptions)).version;
} catch {
console.error(
terminal.bold(
terminal.red(tags.stripIndents`
Versions of typescript could not be determined.
The most common reason for this is a broken npm install.
Please make sure your package.json contains typescript in
devDependencies, then delete node_modules and package-lock.json (if you have one) and
run npm install again.
`),
),
);
process.exit(2);
return;
}
resolveBuilder(builderStr: string): Promise {
const [packageName, builderName] = builderStr.split(':', 2);
if (!builderName) {
throw new Error('No builder name specified.');
}
const packageJsonPath = resolve(packageName, {
basedir: this._root,
checkLocal: true,
checkGlobal: true,
resolvePackageJson: true,
});
const packageJson = require(packageJsonPath);
if (!packageJson['builders']) {
throw new Error(`Package ${JSON.stringify(packageName)} has no builders defined.`);
}
const builderJsonPath = path.resolve(path.dirname(packageJsonPath), packageJson['builders']);
const builderJson = require(builderJsonPath) as BuilderSchema;
const builder = builderJson.builders && builderJson.builders[builderName];
it('works', () => {
const tslintRe = /[\\/]node_modules[\\/]tslint[\\/]lib[\\/]index.js$/;
expect(resolve('tslint', { basedir: __dirname })).toMatch(tslintRe);
expect(() => resolve('npm', { basedir: '/' })).toThrow();
expect(() => resolve('npm', { basedir: '/', checkGlobal: true })).not.toThrow();
});
_resolvePackageJson(name, basedir = process.cwd()) {
return core.resolve(name, {
basedir,
checkLocal: true,
checkGlobal: true,
resolvePackageJson: true,
});
}
_resolvePath(name, basedir = process.cwd()) {
function resolveProjectModule(root, moduleName) {
return node_1.resolve(moduleName, {
basedir: root,
checkGlobal: false,
checkLocal: true,
});
}
exports.resolveProjectModule = resolveProjectModule;