-
Notifications
You must be signed in to change notification settings - Fork 5.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(node): require.resolve - fallback to global cache when bare speci…
…fier from paths not found (#23618) Part of #22607 (probably closes it, but I haven't done thorough testing) Makes it so that `require.resolve` with `paths` specified will fallback to using the global cache when the paths can't be found when using a global cache (not when using a node_modules folder)
- Loading branch information
Showing
6 changed files
with
54 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
tests/specs/npm/require_resolve_bad_paths_global_cache/__test__.jsonc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"args": "run --allow-read main.ts", | ||
"output": "main.out" | ||
} |
9 changes: 9 additions & 0 deletions
9
tests/specs/npm/require_resolve_bad_paths_global_cache/main.out
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
[UNORDERED_START] | ||
Download http://localhost:4545/npm/registry/@denotest/esm-basic | ||
Download http://localhost:4545/npm/registry/@denotest/require-resolve | ||
[UNORDERED_END] | ||
[UNORDERED_START] | ||
Download http://localhost:4545/npm/registry/@denotest/esm-basic/1.0.0.tgz | ||
Download http://localhost:4545/npm/registry/@denotest/require-resolve/1.0.0.tgz | ||
[UNORDERED_END] | ||
[WILDLINE]@denotest[WILDCHAR]esm-basic[WILDCHAR]1.0.0[WILDCHAR]main.mjs |
8 changes: 8 additions & 0 deletions
8
tests/specs/npm/require_resolve_bad_paths_global_cache/main.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import "npm:@denotest/esm-basic"; | ||
import { resolve } from "npm:@denotest/require-resolve"; | ||
|
||
console.log(resolve("@denotest/esm-basic", { | ||
// when using the global cache, it should fallback to resolving bare | ||
// specifiers with the global cache when it can't find it via the paths | ||
paths: ["/home"], | ||
})); |
3 changes: 3 additions & 0 deletions
3
tests/testdata/npm/registry/@denotest/require-resolve/1.0.0/index.cjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
exports.resolve = (...args) => { | ||
return require.resolve(...args); | ||
}; |
5 changes: 5 additions & 0 deletions
5
tests/testdata/npm/registry/@denotest/require-resolve/1.0.0/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"name": "@denotest/require-resolve", | ||
"version": "1.0.0", | ||
"main": "index.cjs" | ||
} |