diff options
author | David Sherret <dsherret@users.noreply.github.com> | 2024-04-30 23:41:29 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-04-30 23:41:29 -0400 |
commit | 56bf634fa9721832b605dd91ced5329e0329a8f8 (patch) | |
tree | 15595d6beca6d712ad502c830c42fe533c25c237 /tests | |
parent | 486437fee1ac53610a901b07bda91909844ec9ab (diff) |
fix(node): require.resolve - fallback to global cache when bare specifier 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)
Diffstat (limited to 'tests')
5 files changed, 29 insertions, 0 deletions
diff --git a/tests/specs/npm/require_resolve_bad_paths_global_cache/__test__.jsonc b/tests/specs/npm/require_resolve_bad_paths_global_cache/__test__.jsonc new file mode 100644 index 000000000..70840dee2 --- /dev/null +++ b/tests/specs/npm/require_resolve_bad_paths_global_cache/__test__.jsonc @@ -0,0 +1,4 @@ +{ + "args": "run --allow-read main.ts", + "output": "main.out" +} diff --git a/tests/specs/npm/require_resolve_bad_paths_global_cache/main.out b/tests/specs/npm/require_resolve_bad_paths_global_cache/main.out new file mode 100644 index 000000000..563d84ac4 --- /dev/null +++ b/tests/specs/npm/require_resolve_bad_paths_global_cache/main.out @@ -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 diff --git a/tests/specs/npm/require_resolve_bad_paths_global_cache/main.ts b/tests/specs/npm/require_resolve_bad_paths_global_cache/main.ts new file mode 100644 index 000000000..c3b236c8f --- /dev/null +++ b/tests/specs/npm/require_resolve_bad_paths_global_cache/main.ts @@ -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"], +})); diff --git a/tests/testdata/npm/registry/@denotest/require-resolve/1.0.0/index.cjs b/tests/testdata/npm/registry/@denotest/require-resolve/1.0.0/index.cjs new file mode 100644 index 000000000..b76925077 --- /dev/null +++ b/tests/testdata/npm/registry/@denotest/require-resolve/1.0.0/index.cjs @@ -0,0 +1,3 @@ +exports.resolve = (...args) => { + return require.resolve(...args); +}; diff --git a/tests/testdata/npm/registry/@denotest/require-resolve/1.0.0/package.json b/tests/testdata/npm/registry/@denotest/require-resolve/1.0.0/package.json new file mode 100644 index 000000000..03631e993 --- /dev/null +++ b/tests/testdata/npm/registry/@denotest/require-resolve/1.0.0/package.json @@ -0,0 +1,5 @@ +{ + "name": "@denotest/require-resolve", + "version": "1.0.0", + "main": "index.cjs" + } |