Fix virtual mode path comments by using relative paths

Use relative paths (strip leading /) for virtual files to get consistent
path comments in CSS output regardless of working directory.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
Claude Bot
2026-01-18 22:44:31 +00:00
parent c04ee28892
commit 18322da1e9
5 changed files with 37 additions and 32 deletions

View File

@@ -16,7 +16,7 @@ h1 {
onAfterBundle(api) {
api.expectFile("/out.css").toEqualIgnoringWhitespace(`
/* ../../a.css */
/* a.css */
h1 {
${property}: ${expected};
}

View File

@@ -16,7 +16,7 @@ h1 {
onAfterBundle(api) {
api.expectFile("/out.css").toEqualIgnoringWhitespace(`
/* ../../a.css */
/* a.css */
h1 {
color: ${expected};
}

View File

@@ -15,7 +15,7 @@ h1 {
onAfterBundle(api) {
api.expectFile("/out.css").toEqualIgnoringWhitespace(`
/* ../../a.css */
/* a.css */
h1 {
color: ${expected};
}

View File

@@ -17,7 +17,7 @@ h1 {
onAfterBundle(api) {
api.expectFile("/out.css").toEqualIgnoringWhitespace(`
/* ../../a.css */
/* a.css */
h1 {
color: #00f942;
}
@@ -38,7 +38,7 @@ h1 {
onAfterBundle(api) {
api.expectFile("/out.css").toEqualIgnoringWhitespace(`
/* ../../a.css */
/* a.css */
h1 {
color: rgb(from lab(100 104.3 -50.9) r g b);
}
@@ -59,7 +59,7 @@ h1 {
onAfterBundle(api) {
api.expectFile("/out.css").toEqualIgnoringWhitespace(`
/* ../../a.css */
/* a.css */
h1 {
color: rgb(from lab(0 104.3 -50.9) r g b);
}
@@ -80,7 +80,7 @@ h1 {
onAfterBundle(api) {
api.expectFile("/out.css").toEqualIgnoringWhitespace(`
/* ../../a.css */
/* a.css */
h1 {
color: rgb(from lch(100 116 334) r g b);
}
@@ -101,7 +101,7 @@ h1 {
onAfterBundle(api) {
api.expectFile("/out.css").toEqualIgnoringWhitespace(`
/* ../../a.css */
/* a.css */
h1 {
color: rgb(from lch(0 116 334) r g b);
}
@@ -122,7 +122,7 @@ h1 {
onAfterBundle(api) {
api.expectFile("/out.css").toEqualIgnoringWhitespace(`
/* ../../a.css */
/* a.css */
h1 {
color: rgb(from oklab(1 .365 -.16) r g b);
}
@@ -143,7 +143,7 @@ h1 {
onAfterBundle(api) {
api.expectFile("/out.css").toEqualIgnoringWhitespace(`
/* ../../a.css */
/* a.css */
h1 {
color: rgb(from oklab(0 .365 -.16) r g b);
}
@@ -164,7 +164,7 @@ h1 {
onAfterBundle(api) {
api.expectFile("/out.css").toEqualIgnoringWhitespace(`
/* ../../a.css */
/* a.css */
h1 {
color: rgb(from oklch(1 .399 336.3) r g b);
}
@@ -185,7 +185,7 @@ h1 {
onAfterBundle(api) {
api.expectFile("/out.css").toEqualIgnoringWhitespace(`
/* ../../a.css */
/* a.css */
h1 {
color: rgb(from oklch(0 .399 336.3) r g b);
}
@@ -206,7 +206,7 @@ h1 {
onAfterBundle(api) {
api.expectFile("/out.css").toEqualIgnoringWhitespace(`
/* ../../a.css */
/* a.css */
h1 {
color: #00f942;
}
@@ -227,7 +227,7 @@ h1 {
onAfterBundle(api) {
api.expectFile("/out.css").toEqualIgnoringWhitespace(`
/* ../../a.css */
/* a.css */
h1 {
color: hsl(from lab(100 104.3 -50.9) h s l);
}
@@ -248,7 +248,7 @@ h1 {
onAfterBundle(api) {
api.expectFile("/out.css").toEqualIgnoringWhitespace(`
/* ../../a.css */
/* a.css */
h1 {
color: hsl(from lab(0 104.3 -50.9) h s l);
}
@@ -269,7 +269,7 @@ h1 {
onAfterBundle(api) {
api.expectFile("/out.css").toEqualIgnoringWhitespace(`
/* ../../a.css */
/* a.css */
h1 {
color: hsl(from lch(100 116 334) h s l);
}
@@ -290,7 +290,7 @@ h1 {
onAfterBundle(api) {
api.expectFile("/out.css").toEqualIgnoringWhitespace(`
/* ../../a.css */
/* a.css */
h1 {
color: hsl(from lch(0 116 334) h s l);
}
@@ -311,7 +311,7 @@ h1 {
onAfterBundle(api) {
api.expectFile("/out.css").toEqualIgnoringWhitespace(`
/* ../../a.css */
/* a.css */
h1 {
color: hsl(from oklab(1 .365 -.16) h s l);
}
@@ -332,7 +332,7 @@ h1 {
onAfterBundle(api) {
api.expectFile("/out.css").toEqualIgnoringWhitespace(`
/* ../../a.css */
/* a.css */
h1 {
color: hsl(from oklab(0 .365 -.16) h s l);
}
@@ -353,7 +353,7 @@ h1 {
onAfterBundle(api) {
api.expectFile("/out.css").toEqualIgnoringWhitespace(`
/* ../../a.css */
/* a.css */
h1 {
color: hsl(from oklch(1 .399 336.3) h s l);
}
@@ -374,7 +374,7 @@ h1 {
onAfterBundle(api) {
api.expectFile("/out.css").toEqualIgnoringWhitespace(`
/* ../../a.css */
/* a.css */
h1 {
color: hsl(from oklch(0 .399 336.3) h s l);
}
@@ -395,7 +395,7 @@ h1 {
onAfterBundle(api) {
api.expectFile("/out.css").toEqualIgnoringWhitespace(`
/* ../../a.css */
/* a.css */
h1 {
color: #00f942;
}
@@ -416,7 +416,7 @@ h1 {
onAfterBundle(api) {
api.expectFile("/out.css").toEqualIgnoringWhitespace(`
/* ../../a.css */
/* a.css */
h1 {
color: hwb(from lab(100 104.3 -50.9) h w b);
}
@@ -437,7 +437,7 @@ h1 {
onAfterBundle(api) {
api.expectFile("/out.css").toEqualIgnoringWhitespace(`
/* ../../a.css */
/* a.css */
h1 {
color: hwb(from lab(0 104.3 -50.9) h w b);
}
@@ -458,7 +458,7 @@ h1 {
onAfterBundle(api) {
api.expectFile("/out.css").toEqualIgnoringWhitespace(`
/* ../../a.css */
/* a.css */
h1 {
color: hwb(from lch(100 116 334) h w b);
}
@@ -479,7 +479,7 @@ h1 {
onAfterBundle(api) {
api.expectFile("/out.css").toEqualIgnoringWhitespace(`
/* ../../a.css */
/* a.css */
h1 {
color: hwb(from lch(0 116 334) h w b);
}
@@ -500,7 +500,7 @@ h1 {
onAfterBundle(api) {
api.expectFile("/out.css").toEqualIgnoringWhitespace(`
/* ../../a.css */
/* a.css */
h1 {
color: hwb(from oklab(1 .365 -.16) h w b);
}
@@ -521,7 +521,7 @@ h1 {
onAfterBundle(api) {
api.expectFile("/out.css").toEqualIgnoringWhitespace(`
/* ../../a.css */
/* a.css */
h1 {
color: hwb(from oklab(0 .365 -.16) h w b);
}
@@ -542,7 +542,7 @@ h1 {
onAfterBundle(api) {
api.expectFile("/out.css").toEqualIgnoringWhitespace(`
/* ../../a.css */
/* a.css */
h1 {
color: hwb(from oklch(1 .399 336.3) h w b);
}
@@ -563,7 +563,7 @@ h1 {
onAfterBundle(api) {
api.expectFile("/out.css").toEqualIgnoringWhitespace(`
/* ../../a.css */
/* a.css */
h1 {
color: hwb(from oklch(0 .399 336.3) h w b);
}

View File

@@ -649,13 +649,18 @@ function expectBundled(
return (async () => {
// Prepare virtual files with dedent applied for strings, preserve binary content as-is
// Use relative paths (strip leading /) to get consistent path comments in CSS output
const virtualFiles: Record<string, string | Buffer | Uint8Array | Blob> = {};
for (const [file, contents] of Object.entries(files)) {
virtualFiles[file] = typeof contents === "string" ? dedent(contents) : contents;
const relativePath = file.startsWith("/") ? file.slice(1) : file;
virtualFiles[relativePath] = typeof contents === "string" ? dedent(contents) : contents;
}
// Convert entrypoints to relative paths too
const relativeEntryPoints = entryPoints.map(ep => (ep.startsWith("/") ? ep.slice(1) : ep));
const build = await Bun.build({
entrypoints: entryPoints,
entrypoints: relativeEntryPoints,
files: virtualFiles,
target,
format,