How to use the @angular-devkit/core/node.resolve function in @angular-devkit/core

To help you get started, we’ve selected a few @angular-devkit/core examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github johandb / svg-drawing-tool / node_modules / @angular / cli / lib / init.js View on Github external
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;
github angular / angular-devkit-schematics-builds / tools / node-module-engine-host.js View on Github external
_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) {
github angular / angular-devkit-schematics-builds / tools / node-module-engine-host.js View on Github external
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) {
github johandb / svg-drawing-tool / node_modules / @angular-devkit / architect / src / architect.js View on Github external
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));
github seccubus / seccubus / angular-seccubus.old / bak / node_modules / @angular-devkit / schematics / tools / node-module-engine-host.js View on Github external
_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) {
github apollographql / apollo-angular / packages / apollo-angular / schematics / install / index.ts View on Github external
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;
    }
github angular / angular-cli / packages / angular_devkit / architect / node / node-modules-architect-host.ts View on Github external
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];
github angular / angular-cli / packages / angular_devkit / core / node / resolve_spec.ts View on Github external
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();
  });
github angular / angular-devkit-schematics-builds / tools / node-module-engine-host.js View on Github external
_resolvePackageJson(name, basedir = process.cwd()) {
        return core.resolve(name, {
            basedir,
            checkLocal: true,
            checkGlobal: true,
            resolvePackageJson: true,
        });
    }
    _resolvePath(name, basedir = process.cwd()) {
github johandb / svg-drawing-tool / node_modules / @angular-devkit / build-angular / src / angular-cli-files / utilities / require-project-module.js View on Github external
function resolveProjectModule(root, moduleName) {
    return node_1.resolve(moduleName, {
        basedir: root,
        checkGlobal: false,
        checkLocal: true,
    });
}
exports.resolveProjectModule = resolveProjectModule;