From f9161bbc09b803cf252b75d6e6185142cd043f39 Mon Sep 17 00:00:00 2001 From: Jarred Sumner Date: Fri, 19 Apr 2024 13:13:31 -0700 Subject: [PATCH] Fixes #8697 --- src/cli/build_command.zig | 11 ++++++++++- test/bundler/bundler_compile.test.ts | 16 ++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/src/cli/build_command.zig b/src/cli/build_command.zig index 0c696f714b9971..76f10c47ec0122 100644 --- a/src/cli/build_command.zig +++ b/src/cli/build_command.zig @@ -323,7 +323,16 @@ pub const BuildCommand = struct { defer Output.flush(); var writer = Output.writer(); var output_dir = this_bundler.options.output_dir; - if (outfile.len > 0 and output_files.len == 1 and output_files[0].value == .buffer) { + + const will_be_one_file = + // --outdir is not supported with --compile + // but you can still use --outfile + // in which case, we should set the output dir to the dirname of the outfile + // https://github.com/oven-sh/bun/issues/8697 + ctx.bundler_options.compile or + (output_files.len == 1 and output_files[0].value == .buffer); + + if (output_dir.len == 0 and outfile.len > 0 and will_be_one_file) { output_dir = std.fs.path.dirname(outfile) orelse "."; output_files[0].dest_path = std.fs.path.basename(outfile); } diff --git a/test/bundler/bundler_compile.test.ts b/test/bundler/bundler_compile.test.ts index 842a7a8609e95e..568651952645b7 100644 --- a/test/bundler/bundler_compile.test.ts +++ b/test/bundler/bundler_compile.test.ts @@ -15,6 +15,22 @@ describe("bundler", () => { }, run: { stdout: "Hello, world!" }, }); + // https://github.com/oven-sh/bun/issues/8697 + itBundled("compile/EmbeddedFileOutfile", { + compile: true, + files: { + "/entry.ts": /* js */ ` + import bar from './foo.file' with {type: "file"}; + if ((await Bun.file(bar).text()).trim() !== "abcd") throw "fail"; + console.log("Hello, world!"); + `, + "/foo.file": /* js */ ` + abcd + `.trim(), + }, + outfile: "dist/out", + run: { stdout: "Hello, world!" }, + }); itBundled("compile/pathToFileURLWorks", { compile: true, files: {