本文整理汇总了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;
};