Address review comments: use URL API and static import

- Use new URL(import.meta.url).pathname to parse the URL and check for
  /$bunfs/ in the pathname instead of checking the raw URL string
- Remove Windows-specific B:\\~BUN\\ check as URL pathname normalization
  handles platform differences
- Move pathToFileURL import to module-level static import instead of
  dynamic import inside the plugin handler

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
Claude Bot
2026-02-01 06:19:32 +00:00
parent 7ab2b36495
commit d80f5fc703

View File

@@ -3,6 +3,7 @@ import { describe, expect, test } from "bun:test";
import { rmSync } from "fs"; import { rmSync } from "fs";
import { bunEnv, bunExe, isWindows, tempDir, tempDirWithFiles } from "harness"; import { bunEnv, bunExe, isWindows, tempDir, tempDirWithFiles } from "harness";
import { join } from "path"; import { join } from "path";
import { pathToFileURL } from "url";
import { itBundled } from "./expectBundled"; import { itBundled } from "./expectBundled";
describe("bundler", () => { describe("bundler", () => {
@@ -967,11 +968,12 @@ const server = serve({
export function helper() { export function helper() {
const url = import.meta.url; const url = import.meta.url;
console.log("Utils URL:", url); console.log("Utils URL:", url);
// Verify the URL is the virtual path // Verify the URL is the virtual path by parsing it with URL API
if (url.includes("/$bunfs/") || url.includes("B:\\\\~BUN\\\\")) { const pathname = new URL(url).pathname;
if (pathname.includes("/$bunfs/")) {
return "success"; return "success";
} else { } else {
return "FAIL: import.meta.url is not virtual path: " + url; return "FAIL: import.meta.url pathname is not virtual path: " + pathname;
} }
} }
`, `,
@@ -981,7 +983,6 @@ const server = serve({
name: "transform-model", name: "transform-model",
setup(api) { setup(api) {
api.onLoad({ filter: /model\.ts$/ }, async args => { api.onLoad({ filter: /model\.ts$/ }, async args => {
const { pathToFileURL } = await import("url");
const contents = await Bun.file(args.path).text(); const contents = await Bun.file(args.path).text();
// Replace placeholder with actual filesystem path // Replace placeholder with actual filesystem path
const fileUrl = pathToFileURL(args.path).href; const fileUrl = pathToFileURL(args.path).href;