本文整理匯總了TypeScript中jest-resolve.findNodeModule函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript findNodeModule函數的具體用法?TypeScript findNodeModule怎麽用?TypeScript findNodeModule使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了findNodeModule函數的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: replaceRootDirInPath
export const resolveWithPrefix = (
resolver: string | undefined | null,
{
filePath,
humanOptionName,
optionName,
prefix,
rootDir,
}: {
filePath: string;
humanOptionName: string;
optionName: string;
prefix: string;
rootDir: Config.Path;
},
) => {
const fileName = replaceRootDirInPath(rootDir, filePath);
let module = Resolver.findNodeModule(`${prefix}${fileName}`, {
basedir: rootDir,
resolver: resolver || undefined,
});
if (module) {
return module;
}
try {
return require.resolve(`${prefix}${fileName}`);
} catch (e) {}
module = Resolver.findNodeModule(fileName, {
basedir: rootDir,
resolver: resolver || undefined,
});
if (module) {
return module;
}
try {
return require.resolve(fileName);
} catch (e) {}
throw createValidationError(
` ${humanOptionName} ${chalk.bold(
fileName,
)} cannot be found. Make sure the ${chalk.bold(
optionName,
)} configuration option points to an existing node module.`,
);
};
示例2: replaceRootDirInPath
options.reporters = reporters.map(reporterConfig => {
const normalizedReporterConfig: Config.ReporterConfig =
typeof reporterConfig === 'string'
? // if reporter config is a string, we wrap it in an array
// and pass an empty object for options argument, to normalize
// the shape.
[reporterConfig, {}]
: reporterConfig;
const reporterPath = replaceRootDirInPath(
options.rootDir,
normalizedReporterConfig[0],
);
if (reporterPath !== DEFAULT_REPORTER_LABEL) {
const reporter = Resolver.findNodeModule(reporterPath, {
basedir: options.rootDir,
});
if (!reporter) {
throw new Error(
`Could not resolve a module for a custom reporter.\n` +
` Module name: ${reporterPath}`,
);
}
normalizedReporterConfig[0] = reporter;
}
return normalizedReporterConfig;
});
示例3: createValidationError
export const resolve = (
resolver: string | null | undefined,
{key, filePath, rootDir, optional}: ResolveOptions,
) => {
const module = Resolver.findNodeModule(
replaceRootDirInPath(rootDir, filePath),
{
basedir: rootDir,
resolver: resolver || undefined,
},
);
if (!module && !optional) {
throw createValidationError(
` Module ${chalk.bold(filePath)} in the ${chalk.bold(
key,
)} option was not found.
${chalk.bold('<rootDir>')} is: ${rootDir}`,
);
}
return module;
};