Skip to content

Commit

Permalink
feat: improved symlink support
Browse files Browse the repository at this point in the history
- Every symlink found in a node_modules directory (or a scope thereof) is treated as a project root
- All symlink paths (as opposed to only node_modules) are now cached in `data.links`
- Simplify and add more comments
- Find and watch linked dependencies before crawling them all in parallel

Tested manually on a project using PNPM and yarn link.

"Fresh install" startup perf could be improved by searching for linked dependencies in parallel instead of in batches.

When `watchman watch-del-all` is not used, startup perf is lovely. The difference between using and not using the `--reset-cache` flag is negligible. Startup perf for projects _not_ using symlinks remains unaffected.
  • Loading branch information
aleclarson committed Dec 26, 2018
1 parent 2545368 commit 6c33a8f
Show file tree
Hide file tree
Showing 4 changed files with 258 additions and 176 deletions.
18 changes: 11 additions & 7 deletions packages/jest-haste-map/src/HasteFS.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import type {FileData, LinkData} from 'types/HasteMap';

import * as fastPath from './lib/fast_path';
import micromatch from 'micromatch';
import path from 'path';
import {sync as realpath} from 'realpath-native';
import H from './constants';

Expand Down Expand Up @@ -54,14 +55,17 @@ export default class HasteFS {
}

follow(file: Path): Path {
const link = this._links[file];
if (link === undefined) {
return file;
}
if (link[0] === undefined) {
link[0] = realpath(file);
let link;
for (const key of this._links.keys()) {
const linkRoot = path.resolve(this._rootDir, key);
if (file.startsWith(linkRoot + path.sep)) {
const cache = this._links.get(key);
link = cache && cache.get(fastPath.relative(linkRoot, file));
break;
}
}
return link[0];
if (link === undefined) return file;
return link[0] || (link[0] = realpath(file));
}

getAllFiles(): Array<string> {
Expand Down
Loading

0 comments on commit 6c33a8f

Please sign in to comment.