Skip to content

Commit ca7e9ef

Browse files
authored
fix: normalize path separators in deploy packaging for Windows (#56)
close #55 In `packages/void/src/cli/package.ts`, `path.relative()` is used to compute relative paths for `formData.append()`. On Windows, `path.relative()` returns paths with `\` separators (e.g. `assets\defer-Dwmo8Go0-NWzFqTKN.js`), but the Vite-generated `index.js` uses `/` in its import statements. The path should be normalized to forward slashes before uploading.
1 parent 22065ff commit ca7e9ef

2 files changed

Lines changed: 22 additions & 6 deletions

File tree

‎packages/void/src/cli/package.ts‎

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import type {
1313
WebSocketManifestMeta,
1414
} from "./types";
1515
import type { WebSocketRouteDefinition } from "../router/websocket";
16+
import { toSlash } from "../shared/utils";
1617

1718
/**
1819
* Compute a CF-compatible asset hash: SHA-256, first 32 hex chars.
@@ -41,7 +42,7 @@ export function collectAndHashAssets(dir: string): {
4142
try {
4243
const files = collectFiles(dir);
4344
for (const filePath of files) {
44-
const relativePath = "/" + relative(dir, filePath);
45+
const relativePath = "/" + toSlash(relative(dir, filePath));
4546
const content = readFileSync(filePath);
4647
assetManifest[relativePath] = {
4748
hash: computeAssetHash(content),
@@ -223,7 +224,7 @@ export function packageBuild(
223224
const workerDir = join(distDir, workerDirName);
224225
const workerFiles = collectFiles(workerDir);
225226
for (const filePath of workerFiles) {
226-
const relativePath = relative(workerDir, filePath);
227+
const relativePath = toSlash(relative(workerDir, filePath));
227228
if (!isWorkerModule(relativePath)) continue;
228229
const content = readFileSync(filePath);
229230
formData.append(`worker:${relativePath}`, new Blob([content]), relativePath);
@@ -234,7 +235,7 @@ export function packageBuild(
234235
try {
235236
const clientFiles = collectFiles(clientDir);
236237
for (const filePath of clientFiles) {
237-
const relativePath = relative(clientDir, filePath);
238+
const relativePath = toSlash(relative(clientDir, filePath));
238239
if (neededAssets && !neededAssets.has("/" + relativePath)) continue;
239240
const content = readFileSync(filePath);
240241
formData.append(`asset:${relativePath}`, new Blob([content]), relativePath);
@@ -286,7 +287,7 @@ export function packageStaticBuild(
286287

287288
const files = collectFiles(outputDir);
288289
for (const filePath of files) {
289-
const relativePath = relative(outputDir, filePath);
290+
const relativePath = toSlash(relative(outputDir, filePath));
290291
if (neededAssets && !neededAssets.has("/" + relativePath)) continue;
291292
const content = readFileSync(filePath);
292293
formData.append(`asset:${relativePath}`, new Blob([content]), relativePath);
@@ -396,7 +397,7 @@ export function packageFrameworkBuild(opts: {
396397
// Worker files
397398
const workerFiles = collectFiles(opts.workerDir);
398399
for (const filePath of workerFiles) {
399-
const relativePath = relative(opts.workerDir, filePath);
400+
const relativePath = toSlash(relative(opts.workerDir, filePath));
400401
if (!isWorkerModule(relativePath)) continue;
401402
const content = readFileSync(filePath);
402403
formData.append(`worker:${relativePath}`, new Blob([content]), relativePath);
@@ -408,7 +409,7 @@ export function packageFrameworkBuild(opts: {
408409
for (const filePath of assetFiles) {
409410
// Skip worker files when workerDir overlaps with assetsDir
410411
if (isOverlap && filePath.replace(/\\/g, "/").startsWith(workerDirNorm)) continue;
411-
const relativePath = relative(opts.assetsDir, filePath);
412+
const relativePath = toSlash(relative(opts.assetsDir, filePath));
412413
if (opts.neededAssets && !opts.neededAssets.has("/" + relativePath)) continue;
413414
const content = readFileSync(filePath);
414415
formData.append(`asset:${relativePath}`, new Blob([content]), relativePath);

‎packages/void/src/shared/utils.ts‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { posix } from "node:path";
2+
3+
export const isWindows: boolean = typeof process !== "undefined" && process.platform === "win32";
4+
5+
export function slash(p: string): string {
6+
return p.replace(/\\/g, "/");
7+
}
8+
9+
export function toSlash(p: string): string {
10+
return isWindows ? slash(p) : p;
11+
}
12+
13+
export function normalizePath(id: string): string {
14+
return posix.normalize(toSlash(id));
15+
}

0 commit comments

Comments
 (0)