Compare commits

...

2 Commits

Author SHA1 Message Date
autofix-ci[bot]
a01ab00ac8 [autofix.ci] apply automated fixes 2025-08-14 05:08:48 +00:00
Claude Bot
716a91d5c4 fix: Use correct MIME type for CSS files in Bun.build outputs
This fixes an issue where CSS files processed through Bun.build() would
return "text/javascript;charset=utf-8" instead of "text/css;charset=utf-8"
in their type property.

The bug was caused by two issues:
1. BuildArtifact objects used input_loader (which defaults to .js) instead
   of the actual output loader in OutputFile.zig
2. The loader field was hardcoded to .js in writeOutputFilesToDisk.zig

Fixes #20131

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-08-14 05:06:11 +00:00
3 changed files with 36 additions and 4 deletions

View File

@@ -368,7 +368,7 @@ pub fn toJS(
var build_output = bun.new(jsc.API.BuildArtifact, .{
.blob = jsc.WebCore.Blob.initWithStore(file_blob, globalObject),
.hash = this.hash,
.loader = this.input_loader,
.loader = this.loader,
.output_kind = this.output_kind,
.path = bun.default_allocator.dupe(u8, copy.pathname) catch @panic("Failed to allocate path"),
});
@@ -406,7 +406,7 @@ pub fn toJS(
build_output.* = jsc.API.BuildArtifact{
.blob = jsc.WebCore.Blob.initWithStore(file_blob, globalObject),
.hash = this.hash,
.loader = this.input_loader,
.loader = this.loader,
.output_kind = this.output_kind,
.path = bun.default_allocator.dupe(u8, path_to_use) catch @panic("Failed to allocate path"),
};
@@ -428,7 +428,7 @@ pub fn toJS(
build_output.* = jsc.API.BuildArtifact{
.blob = blob,
.hash = this.hash,
.loader = this.input_loader,
.loader = this.loader,
.output_kind = this.output_kind,
.path = owned_pathname orelse bun.default_allocator.dupe(u8, this.src_path.text) catch unreachable,
};

View File

@@ -317,7 +317,7 @@ pub fn writeOutputFilesToDisk(
.js,
.hash = chunk.template.placeholder.hash,
.output_kind = output_kind,
.loader = .js,
.loader = chunk.content.loader(),
.source_map_index = source_map_index,
.bytecode_index = bytecode_index,
.size = @as(u32, @truncate(code_result.buffer.len)),

View File

@@ -0,0 +1,32 @@
import { expect, test } from "bun:test";
import { tempDirWithFiles } from "harness";
test("CSS file has correct MIME type in Bun.build result", async () => {
const dir = tempDirWithFiles("css-mime-type-test", {
"styles.css": `.test { color: red; }`,
});
const result = await Bun.build({
entrypoints: [`${dir}/styles.css`],
outdir: `${dir}/out`,
});
expect(result.outputs).toHaveLength(1);
expect(result.outputs[0].type).toBe("text/css;charset=utf-8");
expect(result.outputs[0].kind).toBe("asset");
});
test("CSS file has correct MIME type in Bun.build result (in-memory)", async () => {
const dir = tempDirWithFiles("css-mime-type-test-memory", {
"styles.css": `.test { color: blue; }`,
});
const result = await Bun.build({
entrypoints: [`${dir}/styles.css`],
// No outdir = in-memory build
});
expect(result.outputs).toHaveLength(1);
expect(result.outputs[0].type).toBe("text/css;charset=utf-8");
expect(result.outputs[0].kind).toBe("asset");
});