Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
11 changes: 8 additions & 3 deletions src/bun.js.zig
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,14 @@ pub const Run = struct {
bun.jsc.initialize(false);
bun.analytics.Features.standalone_executable += 1;

const graph_ptr = try bun.default_allocator.create(bun.StandaloneModuleGraph);
graph_ptr.* = graph;
graph_ptr.set();
// Use existing graph if already set (set early in cli.zig for execArgv case),
// otherwise create and set it now
const graph_ptr = bun.StandaloneModuleGraph.get() orelse blk: {
const ptr = try bun.default_allocator.create(bun.StandaloneModuleGraph);
ptr.* = graph;
ptr.set();
break :blk ptr;
};

js_ast.Expr.Data.Store.create();
js_ast.Stmt.Data.Store.create();
Expand Down
6 changes: 6 additions & 0 deletions src/cli.zig
Original file line number Diff line number Diff line change
Expand Up @@ -683,6 +683,12 @@ pub const Command = struct {
if (try bun.StandaloneModuleGraph.fromExecutable(bun.default_allocator)) |graph| {
var offset_for_passthrough: usize = 0;

// Set the graph globally early so loadConfig can check compile flags
// (e.g., disable_autoload_bunfig) before Command.init loads config
const graph_ptr = try bun.default_allocator.create(bun.StandaloneModuleGraph);
graph_ptr.* = graph;
graph_ptr.set();

const ctx: *ContextData = brk: {
if (graph.compile_exec_argv.len > 0) {
const original_argv_len = bun.argv.len;
Expand Down
7 changes: 7 additions & 0 deletions src/cli/Arguments.zig
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,13 @@ fn getHomeConfigPath(buf: *bun.PathBuffer) ?[:0]const u8 {
return null;
}
pub fn loadConfig(allocator: std.mem.Allocator, user_config_path_: ?string, ctx: Command.Context, comptime cmd: Command.Tag) OOM!void {
// For standalone executables, respect compile-time flag to disable bunfig autoloading
if (bun.StandaloneModuleGraph.get()) |graph| {
if (graph.flags.disable_autoload_bunfig) {
return;
}
}

var config_buf: bun.PathBuffer = undefined;
if (comptime cmd.readGlobalConfig()) {
if (!ctx.has_loaded_global_config) {
Expand Down
53 changes: 53 additions & 0 deletions test/bundler/bundler_compile_autoload.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,59 @@ console.log("PRELOAD");
},
});

// Test that autoloadBunfig: false is respected when execArgv is set
// Regression test: execArgv was causing bunfig.toml to be loaded even when disabled
itBundled("compile/AutoloadBunfigDisabledWithExecArgv", {
compile: {
autoloadBunfig: false,
execArgv: ["--smol"],
},
files: {
"/entry.ts": /* js */ `
console.log("ENTRY");
`,
},
runtimeFiles: {
"/bunfig.toml": `
preload = ["./preload.ts"]
`,
"/preload.ts": `
console.log("PRELOAD");
`,
},
run: {
// When bunfig is disabled, preload should NOT execute even with execArgv
stdout: "ENTRY",
setCwd: true,
},
});

// Test CLI backend: autoloadBunfig: false with execArgv
itBundled("compile/AutoloadBunfigDisabledWithExecArgvCLI", {
compile: {
autoloadBunfig: false,
execArgv: ["--smol"],
},
backend: "cli",
files: {
"/entry.ts": /* js */ `
console.log("ENTRY");
`,
},
runtimeFiles: {
"/bunfig.toml": `
preload = ["./preload.ts"]
`,
"/preload.ts": `
console.log("PRELOAD");
`,
},
run: {
stdout: "ENTRY",
setCwd: true,
},
});

// Test CLI backend with autoloadBunfig: true
itBundled("compile/AutoloadBunfigEnabledCLI", {
compile: {
Expand Down