Skip to content
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
7eda0b9
resolver: anchor a relative require.resolve paths entry at the cwd
robobun Sep 6, 2026
9c59071
resolver: join a relative paths entry with the shared abs_buf_checked…
robobun Sep 6, 2026
8012e2f
resolver: shorten the relative paths comment
robobun Sep 6, 2026
403d5a9
ci: retrigger
robobun Sep 6, 2026
748b5dd
Merge remote-tracking branch 'origin/main' into robobun/1099f95b/requ…
robobun Oct 25, 2026
849a01f
resolver: read a require.resolve paths entry with host path rules in …
robobun Oct 26, 2026
6ca0688
resolver: check that a paths entry is a directory only after a hit
robobun Oct 26, 2026
1443052
resolver: keep the paths change to relative entries of a bare request
robobun Oct 26, 2026
a45f957
resolver: search every paths entry before one of several installs a p…
robobun Oct 26, 2026
1b1d60c
Merge remote-tracking branch 'origin/main' into robobun/1099f95b/requ…
robobun Oct 26, 2026
8183359
resolver: keep --install=force to one search of the paths entries
robobun Oct 26, 2026
03f231a
resolver: a relative paths entry outside the cwd installs nothing
robobun Oct 26, 2026
722c983
resolver: a relative paths entry installs only through one search fro…
robobun Oct 27, 2026
ce923e5
Merge remote-tracking branch 'origin/main' into robobun/1099f95b/requ…
robobun Oct 27, 2026
bfda158
test: do not block on the paths child processes, and pin a cwd with a…
robobun Oct 27, 2026
98736da
Merge branch 'main' into robobun/1099f95b/require-resolve-relative-paths
robobun Nov 8, 2026
6118544
resolver: leave the paths loop in place and add the relative folder t…
robobun Nov 8, 2026
3090e3b
resolver: a relative paths entry does not answer after a refusal in e…
robobun Nov 9, 2026
40cd6ea
resolver: split the package name with strings::rsplit
robobun Nov 9, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 14 additions & 6 deletions src/resolver/resolver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1971,12 +1971,20 @@
bun_core::hint::cold();
for custom_path in custom_paths {
let custom_utf8 = custom_path.to_utf8();
match self.check_package_path(
custom_utf8.slice(),
import_path,
kind,
global_cache,
) {
// A relative entry is cwd-relative, like Node's `path.resolve(from)`.
let mut abs_buf = bun_paths::path_buffer_pool::get();
let custom_dir: &[u8] = if bun_paths::is_absolute(custom_utf8.slice()) {
custom_utf8.slice()
} else {
match self
.fs_ref()
.abs_buf_checked(&[custom_utf8.slice()], &mut *abs_buf)
{
Some(dir) => dir,
None => continue,
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
}
};
match self.check_package_path(custom_dir, import_path, kind, global_cache) {
ResultUnion::Success(res) => return ResultUnion::Success(res),
ResultUnion::Pending(p) => return ResultUnion::Pending(p),
ResultUnion::Failure(p) => return ResultUnion::Failure(p),
Expand All @@ -1984,7 +1992,7 @@
}
}
} else {
match self.check_package_path(source_dir, import_path, kind, global_cache) {

Check warning on line 1995 in src/resolver/resolver.rs

View workflow job for this annotation

GitHub Actions / mordant

this `match` on `result::ResultUnion` repeats an earlier one arm for arm. The mapping exists twice, and a change to one copy will miss the other
ResultUnion::Success(res) => return ResultUnion::Success(res),
ResultUnion::Pending(p) => return ResultUnion::Pending(p),
ResultUnion::Failure(p) => return ResultUnion::Failure(p),
Expand Down
37 changes: 37 additions & 0 deletions test/js/node/module/module-resolve-filename-paths.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -199,3 +199,40 @@ test("Module._resolveFilename throws ERR_INVALID_ARG_TYPE if options.paths is no
Module._resolveFilename("path", __filename, false, { paths: { 0: "/some/path" } });
}).toThrow();
});

test("require.resolve anchors a relative options.paths entry at the cwd", () => {
// Node resolves a relative entry with path.resolve(), so it is relative to process.cwd().
const { path: dir, cleanup } = createTempDir("require-resolve-relative-paths", {
"lib/node_modules/relative-paths-pkg/package.json": JSON.stringify({
name: "relative-paths-pkg",
main: "index.js",
}),
"lib/node_modules/relative-paths-pkg/index.js": "module.exports = 'relative-paths';",
});
const previousCwd = process.cwd();

try {
process.chdir(dir);
const expected = resolve(dir, "lib/node_modules/relative-paths-pkg/index.js");

expect(require.resolve("relative-paths-pkg", { paths: ["./lib"] })).toBe(expected);
expect(require.resolve("relative-paths-pkg", { paths: ["lib"] })).toBe(expected);

const fakeParent = new Module("/some/other/directory/file.js");
fakeParent.filename = "/some/other/directory/file.js";
fakeParent.paths = Module._nodeModulePaths("/some/other/directory");
expect(Module._resolveFilename("relative-paths-pkg", fakeParent, false, { paths: ["lib"] })).toBe(expected);

// An entry that does not exist under the cwd is not found.
let caught;
try {
require.resolve("relative-paths-pkg", { paths: ["./missing"] });
} catch (err) {
caught = err.code;
}
expect(caught).toBe("MODULE_NOT_FOUND");
} finally {
process.chdir(previousCwd);
cleanup();
}
});
Loading