本文整理匯總了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,
});
}
}
示例2: _resolvePackageJson
protected _resolvePackageJson(name: string, basedir = process.cwd()) {
return core.resolve(name, {
basedir,
checkLocal: true,
checkGlobal: true,
resolvePackageJson: true,
});
}
示例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();
});
示例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();
});
示例5: resolveProjectModule
export function resolveProjectModule(root: string, moduleName: string) {
return resolve(
moduleName,
{
basedir: root,
checkGlobal: false,
checkLocal: true,
},
);
}
示例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);
}
});
});
}
示例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;
}
示例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;
}
}
示例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),
});
}
示例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);