diff --git a/packages/md/src/plugin.ts b/packages/md/src/plugin.ts index 201195bbd..3373eb7a3 100644 --- a/packages/md/src/plugin.ts +++ b/packages/md/src/plugin.ts @@ -1,4 +1,4 @@ -import type { Plugin, ResolvedConfig, ViteDevServer } from "vite"; +import { normalizePath, type Plugin, type ResolvedConfig, type ViteDevServer } from "vite"; import { createHash } from "node:crypto"; import { existsSync, readFileSync, readdirSync } from "node:fs"; import { dirname, join, relative, resolve } from "node:path"; @@ -297,7 +297,7 @@ export function useFrontmatter() { return useContext(FrontmatterContext) ?? {}; } for (const imp of islandImports) { const absPath = resolve(dirname(_id), imp.specifier); - imp.islandId = relative(root, absPath).replace(/\.[^.]+$/, ""); + imp.islandId = normalizePath(relative(root, absPath)).replace(/\.[^.]+$/, ""); } const { compile } = await import("./compile"); diff --git a/packages/react/src/plugin-islands.ts b/packages/react/src/plugin-islands.ts index 1455dc9a7..c32b310c6 100644 --- a/packages/react/src/plugin-islands.ts +++ b/packages/react/src/plugin-islands.ts @@ -1,4 +1,4 @@ -import type { Plugin } from "vite"; +import { normalizePath, type Plugin } from "vite"; import { existsSync, readFileSync } from "node:fs"; import { dirname, resolve, relative } from "node:path"; import { scanPages, resolveEffectiveLayoutChain } from "void/pages"; @@ -76,7 +76,7 @@ export function islandsPlugin(pagesDir: string): Plugin[] { const strategy = m[2].slice(1, -1); const absPath = resolveSpecifier(spec, importerDir, COMPONENT_EXTENSIONS); if (absPath) { - const islandId = relative(root, absPath).replace(/\.[^.]+$/, ""); + const islandId = normalizePath(relative(root, absPath)).replace(/\.[^.]+$/, ""); islandManifest.set(islandId, { componentPath: absPath, islandId, @@ -198,7 +198,7 @@ export function islandsPlugin(pagesDir: string): Plugin[] { // Resolve to absolute path for the island manifest const absPath = resolveSpecifier(spec, importerDir, COMPONENT_EXTENSIONS); if (absPath) { - const islandId = relative(root, absPath).replace(/\.[^.]+$/, ""); + const islandId = normalizePath(relative(root, absPath)).replace(/\.[^.]+$/, ""); islandManifest.set(islandId, { componentPath: absPath, islandId, @@ -206,7 +206,9 @@ export function islandsPlugin(pagesDir: string): Plugin[] { }); } - const islandId = absPath ? relative(root, absPath).replace(/\.[^.]+$/, "") : spec; + const islandId = absPath + ? normalizePath(relative(root, absPath)).replace(/\.[^.]+$/, "") + : spec; // Replace the import with a renamed import const replacement = `import ${rawName} from ${specRaw}`; diff --git a/packages/solid/src/plugin-islands.ts b/packages/solid/src/plugin-islands.ts index 67239d323..bf9c9f9fe 100644 --- a/packages/solid/src/plugin-islands.ts +++ b/packages/solid/src/plugin-islands.ts @@ -1,4 +1,4 @@ -import type { Plugin } from "vite"; +import { normalizePath, type Plugin } from "vite"; import { existsSync, readFileSync } from "node:fs"; import { dirname, resolve, relative } from "node:path"; import { scanPages, resolveEffectiveLayoutChain } from "void/pages"; @@ -95,7 +95,7 @@ export function islandsPlugin(pagesDir: string): Plugin[] { const strategy = m[2].slice(1, -1); const absPath = resolveSpecifier(spec, importerDir, COMPONENT_EXTENSIONS); if (absPath) { - const islandId = relative(root, absPath).replace(/\.[^.]+$/, ""); + const islandId = normalizePath(relative(root, absPath)).replace(/\.[^.]+$/, ""); islandManifest.set(islandId, { componentPath: absPath, islandId, @@ -226,7 +226,7 @@ export function islandsPlugin(pagesDir: string): Plugin[] { // Resolve to absolute path for the island manifest const absPath = resolveSpecifier(spec, importerDir, COMPONENT_EXTENSIONS); if (absPath) { - const islandId = relative(root, absPath).replace(/\.[^.]+$/, ""); + const islandId = normalizePath(relative(root, absPath)).replace(/\.[^.]+$/, ""); islandManifest.set(islandId, { componentPath: absPath, islandId, @@ -234,7 +234,9 @@ export function islandsPlugin(pagesDir: string): Plugin[] { }); } - const islandId = absPath ? relative(root, absPath).replace(/\.[^.]+$/, "") : spec; + const islandId = absPath + ? normalizePath(relative(root, absPath)).replace(/\.[^.]+$/, "") + : spec; // Rewrite import to point to virtual wrapper component. // Use a clean .tsx path (no query params) so rolldown can detect the diff --git a/packages/svelte/src/plugin-islands.ts b/packages/svelte/src/plugin-islands.ts index dcfbea387..a5bf510a9 100644 --- a/packages/svelte/src/plugin-islands.ts +++ b/packages/svelte/src/plugin-islands.ts @@ -1,4 +1,4 @@ -import type { Plugin } from "vite"; +import { normalizePath, type Plugin } from "vite"; import { existsSync, readFileSync } from "node:fs"; import { dirname, resolve, relative } from "node:path"; import { scanPages, resolveEffectiveLayoutChain } from "void/pages"; @@ -85,7 +85,7 @@ export function islandsPlugin(pagesDir: string): Plugin[] { const strategy = m[2].slice(1, -1); const absPath = resolveSpecifier(spec, importerDir, COMPONENT_EXTENSIONS); if (absPath) { - const islandId = relative(root, absPath).replace(/\.[^.]+$/, ""); + const islandId = normalizePath(relative(root, absPath)).replace(/\.[^.]+$/, ""); islandManifest.set(islandId, { componentPath: absPath, islandId, @@ -215,7 +215,7 @@ export function islandsPlugin(pagesDir: string): Plugin[] { // Resolve to absolute path for the island manifest const absPath = resolveSpecifier(spec, importerDir, COMPONENT_EXTENSIONS); if (absPath) { - const islandId = relative(root, absPath).replace(/\.[^.]+$/, ""); + const islandId = normalizePath(relative(root, absPath)).replace(/\.[^.]+$/, ""); islandManifest.set(islandId, { componentPath: absPath, islandId, @@ -223,7 +223,9 @@ export function islandsPlugin(pagesDir: string): Plugin[] { }); } - const islandId = absPath ? relative(root, absPath).replace(/\.[^.]+$/, "") : spec; + const islandId = absPath + ? normalizePath(relative(root, absPath)).replace(/\.[^.]+$/, "") + : spec; // Rewrite import to point to virtual wrapper component const wrapperUrl = diff --git a/packages/vue/src/plugin-islands.ts b/packages/vue/src/plugin-islands.ts index ee562f756..dffe60668 100644 --- a/packages/vue/src/plugin-islands.ts +++ b/packages/vue/src/plugin-islands.ts @@ -1,4 +1,4 @@ -import type { Plugin } from "vite"; +import { normalizePath, type Plugin } from "vite"; import { existsSync, readFileSync } from "node:fs"; import { dirname, resolve, relative } from "node:path"; import { scanPages, resolveEffectiveLayoutChain } from "void/pages"; @@ -114,7 +114,7 @@ export function islandsPlugin(pagesDir: string): Plugin[] { const strategy = m[2].slice(1, -1); const absPath = resolveSpecifier(spec, importerDir, COMPONENT_EXTENSIONS); if (absPath) { - const islandId = relative(root, absPath).replace(/\.[^.]+$/, ""); + const islandId = normalizePath(relative(root, absPath)).replace(/\.[^.]+$/, ""); islandManifest.set(islandId, { componentPath: absPath, islandId, @@ -236,7 +236,7 @@ export function islandsPlugin(pagesDir: string): Plugin[] { // Resolve to absolute path for the island manifest const absPath = resolveSpecifier(spec, importerDir, COMPONENT_EXTENSIONS); if (absPath) { - const islandId = relative(root, absPath).replace(/\.[^.]+$/, ""); + const islandId = normalizePath(relative(root, absPath)).replace(/\.[^.]+$/, ""); islandManifest.set(islandId, { componentPath: absPath, islandId, @@ -244,7 +244,9 @@ export function islandsPlugin(pagesDir: string): Plugin[] { }); } - const islandId = absPath ? relative(root, absPath).replace(/\.[^.]+$/, "") : spec; + const islandId = absPath + ? normalizePath(relative(root, absPath)).replace(/\.[^.]+$/, "") + : spec; // Replace the import with a renamed import const replacement = `import ${rawName} from ${specRaw}`;