diff --git a/src/bundler.zig b/src/bundler.zig index d88ac80f50..cbfaea2c12 100644 --- a/src/bundler.zig +++ b/src/bundler.zig @@ -103,6 +103,12 @@ pub const PluginRunner = struct { pub fn extractNamespace(specifier: string) string { const colon = strings.indexOfChar(specifier, ':') orelse return ""; + if (Environment.isWindows and + colon == 1 and + specifier.len > 3 and + bun.path.isSepAny(specifier[2]) and + ((specifier[0] > 'a' and specifier[0] < 'z') or (specifier[0] > 'A' and specifier[0] < 'Z'))) + return ""; return specifier[0..colon]; } diff --git a/src/js/builtins/BundlerPlugin.ts b/src/js/builtins/BundlerPlugin.ts index d2c88b667d..db78902f2d 100644 --- a/src/js/builtins/BundlerPlugin.ts +++ b/src/js/builtins/BundlerPlugin.ts @@ -253,7 +253,9 @@ export function runOnResolvePlugins(this: BundlerPlugin, specifier, inputNamespa throw new TypeError('onResolve plugin "path" must be absolute when the namespace is "file"'); } } else { - // TODO: Windows + if (require("node:path").isAbsolute(path) === false || path.includes("..")) { + throw new TypeError('onResolve plugin "path" must be absolute when the namespace is "file"'); + } } } if (userNamespace === "dataurl") { diff --git a/src/string_immutable.zig b/src/string_immutable.zig index 733f6a5552..3b55d41beb 100644 --- a/src/string_immutable.zig +++ b/src/string_immutable.zig @@ -5841,3 +5841,17 @@ pub const QuoteEscapeFormat = struct { try writer.writeAll(self.data[i..]); } }; + +/// Generic. Works on []const u8, []const u16, etc +pub inline fn indexOfScalar(input: anytype, scalar: std.meta.Child(@TypeOf(input))) ?usize { + if (comptime std.meta.Child(@TypeOf(input)) == u8) { + return strings.indexOfCharUsize(input, scalar); + } else { + return std.mem.indexOfScalar(std.meta.Child(@TypeOf(input)), input, scalar); + } +} + +/// Generic. Works on []const u8, []const u16, etc +pub fn containsScalar(input: anytype, item: std.meta.Child(@TypeOf(input))) bool { + return indexOfScalar(input, item) != null; +} diff --git a/test/js/bun/plugin/muh.ts b/test/js/bun/plugin/muh.ts new file mode 100644 index 0000000000..d5fbbcd864 --- /dev/null +++ b/test/js/bun/plugin/muh.ts @@ -0,0 +1,24 @@ +import { plugin } from "bun"; + +await plugin({ + name: "svelte loader", + async setup(builder) { + var { compile } = await import("svelte/compiler"); + var { readFileSync } = await import("fs"); + await 2; + console.log(1); + builder.onLoad({ filter: /\.svelte$/ }, ({ path }) => { + console.log(2); + return { + contents: compile(readFileSync(path, "utf8"), { + filename: path, + generate: "ssr", + }).js.code, + loader: "js", + }; + }); + await 1; + }, +}); + +console.log(require("./hello.svelte")); diff --git a/test/js/bun/plugin/plugins.test.ts b/test/js/bun/plugin/plugins.test.ts index 9425afed8b..e82c357a28 100644 --- a/test/js/bun/plugin/plugins.test.ts +++ b/test/js/bun/plugin/plugins.test.ts @@ -320,7 +320,7 @@ describe("dynamic import", () => { describe("import statement", () => { it("SSRs `