當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript node.resolve函數代碼示例

本文整理匯總了TypeScript中@angular-devkit/core/node.resolve函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript resolve函數的具體用法?TypeScript resolve怎麽用?TypeScript resolve使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了resolve函數的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: _resolvePath

  protected _resolvePath(name: string, basedir = process.cwd()) {
    // Allow relative / absolute paths.
    if (name.startsWith('.') || name.startsWith('/')) {
      return resolvePath(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 resolvePath(core.resolve(packageName, {
          basedir,
          checkLocal: true,
          checkGlobal: true,
          resolvePackageJson: true,
        }), '..', ...rest);
      }

      return core.resolve(name, {
        basedir,
        checkLocal: true,
        checkGlobal: true,
      });
    }
  }
開發者ID:DevIntent,項目名稱:angular-cli,代碼行數:25,代碼來源:node-module-engine-host.ts

示例2: _resolvePackageJson

 protected _resolvePackageJson(name: string, basedir = process.cwd()) {
   return core.resolve(name, {
     basedir,
     checkLocal: true,
     checkGlobal: true,
     resolvePackageJson: true,
   });
 }
開發者ID:DevIntent,項目名稱:angular-cli,代碼行數:8,代碼來源:node-module-engine-host.ts

示例3: it

  it('works', () => {
    expect(resolve('tslint', { basedir: __dirname }))
      .toBe(path.join(devKitRoot, 'node_modules/tslint/lib/index.js'));

    expect(() => resolve('npm', { basedir: '/' })).toThrow();

    expect(() => resolve('npm', { basedir: '/', checkGlobal: true })).not.toThrow();
  });
開發者ID:fmalcher,項目名稱:angular-cli,代碼行數:8,代碼來源:resolve_spec.ts

示例4: it

  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();
  });
開發者ID:DevIntent,項目名稱:angular-cli,代碼行數:8,代碼來源:resolve_spec.ts

示例5: resolveProjectModule

export function resolveProjectModule(root: string, moduleName: string) {
  return resolve(
    moduleName,
    {
      basedir: root,
      checkGlobal: false,
      checkLocal: true,
    },
  );
}
開發者ID:DevIntent,項目名稱:angular-cli,代碼行數:10,代碼來源:require-project-module.ts

示例6: function

export default async function (packageName: string,
                               logger: logging.Logger,
                               packageManager: string,
                               projectRoot: string,
                               save: boolean) {
  if (packageManager === 'default') {
    packageManager = 'npm';
  }

  logger.info(chalk.green(`Installing packages for tooling via ${packageManager}.`));

  const installArgs = ['install'];
  if (packageManager === 'npm') {
    installArgs.push('--quiet');
  }
  if (packageName) {
    try {
      // Verify if we need to install the package (it might already be there).
      // If it's available and we shouldn't save, simply return. Nothing to be done.
      resolve(packageName, { checkLocal: true, basedir: projectRoot });

      if (!save) {
        return;
      }
    } catch (e) {
      if (!(e instanceof ModuleNotFoundException)) {
        throw e;
      }
    }
    installArgs.push(packageName);
  }

  if (!save) {
    installArgs.push('--no-save');
  }
  const installOptions = {
    stdio: 'inherit',
    shell: true
  };

  await new Promise((resolve, reject) => {
    spawn(packageManager, installArgs, installOptions)
      .on('close', (code: number) => {
        if (code === 0) {
          logger.info(chalk.green(`Installed packages for tooling via ${packageManager}.`));
          resolve();
        } else {
          const message = 'Package install failed, see above.';
          logger.info(chalk.red(message));
          reject(message);
        }
      });
  });
}
開發者ID:samsif,項目名稱:angular-cli,代碼行數:54,代碼來源:npm-install.ts

示例7: getTemplateDir

export async function getTemplateDir(host: Host, root: Path): Promise<Path> {
  const packageJson = resolve('@angular/bazel', {
    basedir: root,
    resolvePackageJson: true,
  });
  const packageDir = dirname(packageJson as Path);
  const templateDir = join(packageDir, 'src', 'builders', 'files');
  if (!await host.isDirectory(templateDir).toPromise()) {
    throw new Error('Could not find Bazel template directory in "@angular/bazel".');
  }
  return templateDir;
}
開發者ID:StephenFluin,項目名稱:angular,代碼行數:12,代碼來源:bazel.ts

示例8: checkInstallation

export function checkInstallation(name: Executable, projectDir: Path): string {
  const packageName = `@bazel/${name}`;
  try {
    return resolve(packageName, {
      basedir: projectDir,
    });
  } catch (error) {
    if (error.code === 'MODULE_NOT_FOUND') {
      throw new Error(
          `Could not run ${name}. Please make sure that the ` +
          `"${name}" command is installed by running ` +
          `"npm install ${packageName}" or "yarn install ${packageName}".`);
    }
    throw error;
  }
}
開發者ID:StephenFluin,項目名稱:angular,代碼行數:16,代碼來源:bazel.ts

示例9: resolveBuilder

  /**
   * Resolve a builder. This needs to be a string which will be used in a dynamic `import()`
   * clause. This should throw if no builder can be found. The dynamic import will throw if
   * it is unsupported.
   * @param builderStr The name of the builder to be used.
   * @returns All the info needed for the builder itself.
   */
  resolveBuilder(builderStr: string): Promise<NodeModulesBuilderInfo> {
    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];

    if (!builder) {
      throw new Error(`Cannot find builder ${JSON.stringify(builderStr)}.`);
    }

    const importPath = builder.implementation;
    if (!importPath) {
      throw new Error('Could not find the implementation for builder ' + builderStr);
    }

    return Promise.resolve({
      name: builderStr,
      builderName,
      description: builder['description'],
      optionSchema: require(path.resolve(path.dirname(builderJsonPath), builder.schema)),
      import: path.resolve(path.dirname(builderJsonPath), importPath),
    });
  }
開發者ID:angular,項目名稱:angular-cli,代碼行數:47,代碼來源:node-modules-architect-host.ts

示例10: exitHandler

    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 = resolve(
    '@angular/cli',
    {
      checkGlobal: false,
      basedir: process.cwd(),
      preserveSymlinks: true,
    },
  );

  // This was run from a global, check local version.
  const globalVersion = new 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);
開發者ID:baconwaffles,項目名稱:angular-cli,代碼行數:32,代碼來源:init.ts


注:本文中的@angular-devkit/core/node.resolve函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。