Skip to content

Commit 10bf932

Browse files
author
g-mero
authored
fix: resolve path on windows (#2041)
1 parent 7077a49 commit 10bf932

File tree

3 files changed

+22
-16
lines changed

3 files changed

+22
-16
lines changed

.changeset/calm-paths-pull.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@solidjs/start": minor
3+
---
4+
5+
Fix path resolution on Windows

packages/start/src/config/fs-routes/router.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
1-
import { init } from "es-module-lexer";
2-
import { parse } from "es-module-lexer";
1+
import { init, parse } from "es-module-lexer";
32
import esbuild from "esbuild";
43
import fg from "fast-glob";
54
import fs from "fs";
65
import micromatch from "micromatch";
76
import { posix } from "path";
87
import { pathToRegexp } from "path-to-regexp";
98

10-
import { normalize } from "node:path";
9+
import { normalizePath } from "vite";
1110

1211
export { pathToRegexp };
1312

@@ -104,7 +103,7 @@ export class BaseFileSystemRouter extends EventTarget {
104103
}
105104

106105
async addRoute(src: string) {
107-
src = normalize(src);
106+
src = normalizePath(src);
108107
if (this.isRoute(src)) {
109108
try {
110109
const route = this.toRoute(src);
@@ -130,7 +129,7 @@ export class BaseFileSystemRouter extends EventTarget {
130129
}
131130

132131
async updateRoute(src: string) {
133-
src = normalize(src);
132+
src = normalizePath(src);
134133
if (this.isRoute(src)) {
135134
try {
136135
const route = this.toRoute(src);
@@ -146,7 +145,7 @@ export class BaseFileSystemRouter extends EventTarget {
146145
}
147146

148147
removeRoute(src: string) {
149-
src = normalize(src);
148+
src = normalizePath(src);
150149
if (this.isRoute(src)) {
151150
const path = this.toPath(src);
152151
if (path === undefined) {

packages/start/src/config/index.ts

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import { TanStackServerFnPlugin } from "@tanstack/server-functions-plugin";
22
import { defu } from "defu";
33
import { globSync } from "node:fs";
4-
import { extname, isAbsolute, join, normalize } from "node:path";
4+
import { extname, isAbsolute, join } from "node:path";
55
import { fileURLToPath } from "node:url";
6-
import { type PluginOption } from "vite";
6+
import { normalizePath, type PluginOption } from "vite";
77
import solid, { type Options as SolidOptions } from "vite-plugin-solid";
88

99
import { DEFAULT_EXTENSIONS, VIRTUAL_MODULES, VITE_ENVIRONMENTS } from "./constants.ts";
@@ -126,8 +126,10 @@ export function solidStart(options?: SolidStartOptions): Array<PluginOption> {
126126
define: {
127127
"import.meta.env.MANIFEST": `globalThis.MANIFEST`,
128128
"import.meta.env.START_SSR": JSON.stringify(start.ssr),
129-
"import.meta.env.START_APP_ENTRY": `"${appEntryPath}"`,
130-
"import.meta.env.START_CLIENT_ENTRY": `"${handlers.client}"`,
129+
// Use JSON.stringify so backslashes on Windows are escaped and
130+
// esbuild receives a valid JS string literal for the define value
131+
"import.meta.env.START_APP_ENTRY": JSON.stringify(appEntryPath),
132+
"import.meta.env.START_CLIENT_ENTRY": JSON.stringify(handlers.client),
131133
"import.meta.env.START_DEV_OVERLAY": JSON.stringify(start.devOverlay),
132134
},
133135
builder: {
@@ -173,26 +175,26 @@ export function solidStart(options?: SolidStartOptions): Array<PluginOption> {
173175
envConsumer: "client",
174176
envName: VITE_ENVIRONMENTS.client,
175177
getRuntimeCode: () =>
176-
`import { createServerReference } from "${normalize(
177-
fileURLToPath(new URL("../server/server-runtime", import.meta.url)),
178+
`import { createServerReference } from "${normalizePath(
179+
fileURLToPath(new URL("../server/server-runtime", import.meta.url))
178180
)}"`,
179181
replacer: opts => `createServerReference('${opts.functionId}')`,
180182
},
181183
{
182184
envConsumer: "server",
183185
envName: VITE_ENVIRONMENTS.server,
184186
getRuntimeCode: () =>
185-
`import { createServerReference } from '${normalize(
186-
fileURLToPath(new URL("../server/server-fns-runtime", import.meta.url)),
187+
`import { createServerReference } from '${normalizePath(
188+
fileURLToPath(new URL("../server/server-fns-runtime", import.meta.url))
187189
)}'`,
188190
replacer: opts => `createServerReference(${opts.fn}, '${opts.functionId}')`,
189191
},
190192
],
191193
provider: {
192194
envName: VITE_ENVIRONMENTS.server,
193195
getRuntimeCode: () =>
194-
`import { createServerReference } from '${normalize(
195-
fileURLToPath(new URL("../server/server-fns-runtime", import.meta.url)),
196+
`import { createServerReference } from '${normalizePath(
197+
fileURLToPath(new URL("../server/server-fns-runtime", import.meta.url))
196198
)}'`,
197199
replacer: opts => `createServerReference(${opts.fn}, '${opts.functionId}')`,
198200
},

0 commit comments

Comments
 (0)