Skip to content

Commit

Permalink
chore: update resolve (#9872)
Browse files Browse the repository at this point in the history
  • Loading branch information
SimenB authored Apr 23, 2020
1 parent a154014 commit 9443889
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 18 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

### Performance

- `[jest-resolve]` Update `resolve` to a version using native `realpath`, which is faster than the default JS implementation ([#9872](https://github.com/facebook/jest/pull/9872))

## 25.4.0

- `[expect]` Support `async function`s in `toThrow` ([#9817](https://github.com/facebook/jest/pull/9817))
Expand Down
2 changes: 1 addition & 1 deletion packages/jest-resolve/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"jest-pnp-resolver": "^1.2.1",
"read-pkg-up": "^7.0.1",
"realpath-native": "^2.0.0",
"resolve": "^1.16.1",
"resolve": "^1.17.0",
"slash": "^3.0.0"
},
"devDependencies": {
Expand Down
39 changes: 26 additions & 13 deletions packages/jest-resolve/src/defaultResolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,21 +41,13 @@ export default function defaultResolver(
moduleDirectory: options.moduleDirectory,
paths: options.paths,
preserveSymlinks: false,
// @ts-ignore: https://github.com/DefinitelyTyped/DefinitelyTyped/pull/44137
realpathSync,
});

try {
// Dereference symlinks to ensure we don't create a separate
// module instance depending on how it was referenced.
const resolved = realpath(result);

if (resolved) {
return resolved;
}
} catch {
// ignore
}

return result;
// Dereference symlinks to ensure we don't create a separate
// module instance depending on how it was referenced.
return realpathSync(result);
}

export function clearDefaultResolverCache(): void {
Expand Down Expand Up @@ -97,6 +89,23 @@ function statSyncCached(path: string): IPathType {
return IPathType.OTHER;
}

function tolerantRealpath(path: Config.Path): Config.Path {
let result: Config.Path | undefined = undefined;
try {
result = realpath(path);
} catch (error) {
if (error.code !== 'ENOENT') {
throw error;
}
}

if (!result) {
result = path;
}

return result;
}

/*
* helper functions
*/
Expand All @@ -107,3 +116,7 @@ function isFile(file: Config.Path): boolean {
function isDirectory(dir: Config.Path): boolean {
return statSyncCached(dir) === IPathType.DIRECTORY;
}

function realpathSync(file: Config.Path): Config.Path {
return tolerantRealpath(file);
}
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -12708,10 +12708,10 @@ [email protected]:
resolved "https://registry.yarnpkg.com/resolve/-/resolve-1.1.7.tgz#203114d82ad2c5ed9e8e0411b3932875e889e97b"
integrity sha1-IDEU2CrSxe2ejgQRs5ModeiJ6Xs=

resolve@^1.1.6, resolve@^1.10.0, resolve@^1.12.0, resolve@^1.13.1, resolve@^1.15.0, resolve@^1.15.1, resolve@^1.16.1, resolve@^1.3.2, resolve@^1.5.0, resolve@^1.8.1:
version "1.16.1"
resolved "https://registry.yarnpkg.com/resolve/-/resolve-1.16.1.tgz#49fac5d8bacf1fd53f200fa51247ae736175832c"
integrity sha512-rmAglCSqWWMrrBv/XM6sW0NuRFiKViw/W4d9EbC4pt+49H8JwHy+mcGmALTEg504AUDcLTvb1T2q3E9AnmY+ig==
resolve@^1.1.6, resolve@^1.10.0, resolve@^1.12.0, resolve@^1.13.1, resolve@^1.15.0, resolve@^1.15.1, resolve@^1.17.0, resolve@^1.3.2, resolve@^1.5.0, resolve@^1.8.1:
version "1.17.0"
resolved "https://registry.yarnpkg.com/resolve/-/resolve-1.17.0.tgz#b25941b54968231cc2d1bb76a79cb7f2c0bf8444"
integrity sha512-ic+7JYiV8Vi2yzQGFWOkiZD5Z9z7O2Zhm9XMaTxdJExKasieFCr+yXZ/WmXsckHiKl12ar0y6XiXDx3m4RHn1w==
dependencies:
path-parse "^1.0.6"

Expand Down

0 comments on commit 9443889

Please sign in to comment.