本文整理汇总了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;未经允许,请勿转载。 |
请发表评论