本文整理匯總了TypeScript中jest-haste-map.FS.exists方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript FS.exists方法的具體用法?TypeScript FS.exists怎麽用?TypeScript FS.exists使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類jest-haste-map.FS
的用法示例。
在下文中一共展示了FS.exists方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: resolveInverseModuleMap
resolveInverseModuleMap(
paths: Set<Config.Path>,
filter: (file: Config.Path) => boolean,
options?: Resolver.ResolveModuleConfig,
): Array<DependencyResolver.ResolvedModule> {
if (!paths.size) {
return [];
}
const collectModules = (
related: Set<Config.Path>,
moduleMap: Array<DependencyResolver.ResolvedModule>,
changed: Set<Config.Path>,
) => {
const visitedModules = new Set();
const result: Array<DependencyResolver.ResolvedModule> = [];
while (changed.size) {
changed = new Set(
moduleMap.reduce<Array<Config.Path>>((acc, module) => {
if (
visitedModules.has(module.file) ||
!module.dependencies.some(dep => changed.has(dep))
) {
return acc;
}
const file = module.file;
if (filter(file)) {
result.push(module);
related.delete(file);
}
visitedModules.add(file);
acc.push(module.file);
return acc;
}, []),
);
}
return result.concat(
Array.from(related).map(file => ({dependencies: [], file})),
);
};
const relatedPaths = new Set<Config.Path>();
const changed: Set<Config.Path> = new Set();
for (const path of paths) {
if (this._hasteFS.exists(path)) {
const modulePath = isSnapshotPath(path)
? this._snapshotResolver.resolveTestPath(path)
: path;
changed.add(modulePath);
if (filter(modulePath)) {
relatedPaths.add(modulePath);
}
}
}
const modules: Array<DependencyResolver.ResolvedModule> = [];
for (const file of this._hasteFS.getAbsoluteFileIterator()) {
modules.push({
dependencies: this.resolve(file, options),
file,
});
}
return collectModules(relatedPaths, modules, changed);
}
示例2:
const fileExists = (filePath: Config.Path, hasteFS: HasteFS): boolean =>
hasteFS.exists(filePath) || fs.existsSync(filePath);