mirror of
https://github.com/oven-sh/bun
synced 2026-02-17 22:32:06 +00:00
fix(compile): enable package.json loading by default in compiled executables
Compiled executables could not resolve external modules that use `main`, `exports`, or `module` fields in their package.json. This was a regression from #25340 which introduced `--compile-autoload-package-json` defaulting to `false`, causing the resolver to skip reading package.json files at runtime. Closes #27058 Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -276,7 +276,7 @@ pub const JSBundler = struct {
|
||||
autoload_dotenv: bool = true,
|
||||
autoload_bunfig: bool = true,
|
||||
autoload_tsconfig: bool = false,
|
||||
autoload_package_json: bool = false,
|
||||
autoload_package_json: bool = true,
|
||||
|
||||
pub fn fromJS(globalThis: *jsc.JSGlobalObject, config: jsc.JSValue, allocator: std.mem.Allocator, compile_target: ?CompileTarget) JSError!?CompileOptions {
|
||||
var this = CompileOptions{
|
||||
|
||||
@@ -477,7 +477,7 @@ pub const Command = struct {
|
||||
compile_autoload_dotenv: bool = true,
|
||||
compile_autoload_bunfig: bool = true,
|
||||
compile_autoload_tsconfig: bool = false,
|
||||
compile_autoload_package_json: bool = false,
|
||||
compile_autoload_package_json: bool = true,
|
||||
compile_executable_path: ?[]const u8 = null,
|
||||
windows: options.WindowsOptions = .{},
|
||||
};
|
||||
|
||||
@@ -564,6 +564,54 @@ describe("bundler", () => {
|
||||
},
|
||||
compile: true,
|
||||
});
|
||||
// https://github.com/oven-sh/bun/issues/27058
|
||||
itBundled("compile/DynamicRequireWithPackageJsonMain", {
|
||||
files: {
|
||||
"/entry.tsx": /* tsx */ `
|
||||
const req = (x) => require(x);
|
||||
const result = req('pkg-with-main');
|
||||
console.log(JSON.stringify(result));
|
||||
`,
|
||||
"/node_modules/pkg-with-main/package.json": JSON.stringify({ name: "pkg-with-main", main: "lib/index.js" }),
|
||||
"/node_modules/pkg-with-main/lib/index.js": "throw new Error('Must be runtime import.')",
|
||||
},
|
||||
runtimeFiles: {
|
||||
"/node_modules/pkg-with-main/package.json": JSON.stringify({ name: "pkg-with-main", main: "lib/index.js" }),
|
||||
"/node_modules/pkg-with-main/lib/index.js": `module.exports = { hello: "world" };`,
|
||||
},
|
||||
run: {
|
||||
stdout: '{"hello":"world"}',
|
||||
setCwd: true,
|
||||
},
|
||||
compile: true,
|
||||
});
|
||||
// https://github.com/oven-sh/bun/issues/27058
|
||||
itBundled("compile/DynamicRequireWithPackageJsonExports", {
|
||||
files: {
|
||||
"/entry.tsx": /* tsx */ `
|
||||
const req = (x) => require(x);
|
||||
const result = req('pkg-with-exports');
|
||||
console.log(JSON.stringify(result));
|
||||
`,
|
||||
"/node_modules/pkg-with-exports/package.json": JSON.stringify({
|
||||
name: "pkg-with-exports",
|
||||
exports: { ".": "./src/entry.js" },
|
||||
}),
|
||||
"/node_modules/pkg-with-exports/src/entry.js": "throw new Error('Must be runtime import.')",
|
||||
},
|
||||
runtimeFiles: {
|
||||
"/node_modules/pkg-with-exports/package.json": JSON.stringify({
|
||||
name: "pkg-with-exports",
|
||||
exports: { ".": "./src/entry.js" },
|
||||
}),
|
||||
"/node_modules/pkg-with-exports/src/entry.js": `module.exports = { status: "ok" };`,
|
||||
},
|
||||
run: {
|
||||
stdout: '{"status":"ok"}',
|
||||
setCwd: true,
|
||||
},
|
||||
compile: true,
|
||||
});
|
||||
// see comment in `usePackageManager` for why this is a test
|
||||
itBundled("compile/NoAutoInstall", {
|
||||
files: {
|
||||
|
||||
Reference in New Issue
Block a user