rwsdk 1.0.8 → 1.0.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,3 +1,4 @@
1
+ import path from "node:path";
1
2
  /**
2
3
  * Find the number of common ancestor segments between two absolute paths.
3
4
  * Returns the count of shared directory segments from the root.
@@ -28,4 +29,4 @@ export declare function findCommonAncestorDepth(path1: string, path2: string): n
28
29
  export declare function normalizeModulePath(modulePath: string, projectRootDir: string, options?: {
29
30
  absolute?: boolean;
30
31
  isViteStyle?: boolean;
31
- }): string;
32
+ }, _path?: typeof path): string;
@@ -1,5 +1,10 @@
1
- import { posix as path } from "node:path";
2
- import { normalizePath as normalizePathSeparators } from "vite";
1
+ import path from "node:path";
2
+ import { normalizePath } from "vite";
3
+ const windowsDriveAbsoluteRE = /^[A-Za-z]:\//;
4
+ // Vite's normalizePath only converts backslashes on Windows. This wrapper
5
+ // ensures forward slashes regardless of platform, which matters when win32
6
+ // path functions are injected for testing on Linux.
7
+ const normalizePathSeparators = (p) => normalizePath(p.replace(/\\/g, "/"));
3
8
  /**
4
9
  * Find the number of common ancestor segments between two absolute paths.
5
10
  * Returns the count of shared directory segments from the root.
@@ -41,16 +46,16 @@ export function findCommonAncestorDepth(path1, path2) {
41
46
  * /opt/tools/logger.ts → /opt/tools/logger.ts (resolved as Vite-style)
42
47
  * /src/page.tsx, { absolute: true } → /Users/justin/my-app/src/page.tsx
43
48
  */
44
- export function normalizeModulePath(modulePath, projectRootDir, options = {}) {
49
+ export function normalizeModulePath(modulePath, projectRootDir, options = {}, _path = path) {
45
50
  modulePath = normalizePathSeparators(modulePath);
46
- projectRootDir = normalizePathSeparators(path.resolve(projectRootDir));
51
+ projectRootDir = normalizePathSeparators(_path.resolve(projectRootDir));
47
52
  // Handle empty string or current directory
48
53
  if (modulePath === "" || modulePath === ".") {
49
54
  return options.absolute ? projectRootDir : "/";
50
55
  }
51
56
  // For relative paths, resolve them first
52
57
  let resolved;
53
- if (path.isAbsolute(modulePath)) {
58
+ if (_path.isAbsolute(modulePath)) {
54
59
  if (modulePath.startsWith(projectRootDir + "/") ||
55
60
  modulePath === projectRootDir) {
56
61
  // Path starts with project root - it's a real absolute path inside project
@@ -61,7 +66,7 @@ export function normalizeModulePath(modulePath, projectRootDir, options = {}) {
61
66
  if (options.isViteStyle !== undefined) {
62
67
  // User explicitly specified whether this should be treated as Vite-style
63
68
  if (options.isViteStyle) {
64
- resolved = path.resolve(projectRootDir, modulePath.slice(1));
69
+ resolved = _path.resolve(projectRootDir, modulePath.slice(1));
65
70
  }
66
71
  else {
67
72
  resolved = modulePath;
@@ -70,19 +75,20 @@ export function normalizeModulePath(modulePath, projectRootDir, options = {}) {
70
75
  else {
71
76
  // Fall back to heuristics using common ancestor depth
72
77
  const commonDepth = findCommonAncestorDepth(modulePath, projectRootDir);
73
- if (commonDepth > 0) {
74
- // Paths share meaningful common ancestor - treat as real absolute path
78
+ if (commonDepth > 0 || windowsDriveAbsoluteRE.test(modulePath)) {
79
+ // Paths share meaningful common ancestor, or this is a Windows absolute
80
+ // path on a different drive — treat as a real external absolute path
75
81
  resolved = modulePath;
76
82
  }
77
83
  else {
78
84
  // No meaningful common ancestor - assume Vite-style path within project
79
- resolved = path.resolve(projectRootDir, modulePath.slice(1));
85
+ resolved = _path.resolve(projectRootDir, modulePath.slice(1));
80
86
  }
81
87
  }
82
88
  }
83
89
  }
84
90
  else {
85
- resolved = path.resolve(projectRootDir, modulePath);
91
+ resolved = _path.resolve(projectRootDir, modulePath);
86
92
  }
87
93
  resolved = normalizePathSeparators(resolved);
88
94
  // If absolute option is set, always return absolute paths
@@ -90,9 +96,10 @@ export function normalizeModulePath(modulePath, projectRootDir, options = {}) {
90
96
  return resolved;
91
97
  }
92
98
  // Check if the resolved path is within the project root
93
- const relative = path.relative(projectRootDir, resolved);
94
- // If the path goes outside the project root (starts with ..), return absolute
95
- if (relative.startsWith("..")) {
99
+ const relative = _path.relative(projectRootDir, resolved);
100
+ // If the path goes outside the project root (starts with ..) or is on a
101
+ // different drive (Windows: path.relative returns an absolute path), return absolute
102
+ if (relative.startsWith("..") || _path.isAbsolute(relative)) {
96
103
  return resolved;
97
104
  }
98
105
  // Path is within project root, return as Vite-style relative path
@@ -1,3 +1,4 @@
1
+ import { win32 as windowsPath } from "node:path";
1
2
  import { describe, expect, it } from "vitest";
2
3
  import { findCommonAncestorDepth, normalizeModulePath, } from "./normalizeModulePath.mjs";
3
4
  describe("findCommonAncestorDepth", () => {
@@ -220,3 +221,21 @@ describe("normalizeModulePath", () => {
220
221
  });
221
222
  });
222
223
  });
224
+ describe("Windows paths (path.win32)", () => {
225
+ const root = "C:/Projects/app";
226
+ it("Windows absolute path inside project", () => {
227
+ expect(normalizeModulePath("C:/Projects/app/src/page.tsx", root, {}, windowsPath)).toBe("/src/page.tsx");
228
+ });
229
+ it("Windows absolute path outside project (same drive)", () => {
230
+ expect(normalizeModulePath("C:/other/utils.ts", root, {}, windowsPath)).toBe("C:/other/utils.ts");
231
+ });
232
+ it("Cross-drive path is treated as external", () => {
233
+ expect(normalizeModulePath("D:/other/utils.ts", root, {}, windowsPath)).toBe("D:/other/utils.ts");
234
+ });
235
+ it("Relative path resolves correctly", () => {
236
+ expect(normalizeModulePath("src/page.tsx", root, {}, windowsPath)).toBe("/src/page.tsx");
237
+ });
238
+ it("Windows absolute path inside project with absolute option", () => {
239
+ expect(normalizeModulePath("C:/Projects/app/src/page.tsx", root, { absolute: true }, windowsPath)).toBe("C:/Projects/app/src/page.tsx");
240
+ });
241
+ });
@@ -1,5 +1,6 @@
1
1
  import { cloudflare } from "@cloudflare/vite-plugin";
2
- import { resolve } from "node:path/posix";
2
+ import { resolve } from "node:path";
3
+ import { normalizePath } from "vite";
3
4
  import { unstable_readConfig } from "wrangler";
4
5
  import { devServerConstantPlugin } from "./devServerConstant.mjs";
5
6
  import { hasOwnCloudflareVitePlugin } from "./hasOwnCloudflareVitePlugin.mjs";
@@ -32,10 +33,10 @@ import { useServerLookupPlugin } from "./useServerLookupPlugin.mjs";
32
33
  import { vitePreamblePlugin } from "./vitePreamblePlugin.mjs";
33
34
  export const determineWorkerEntryPathname = async ({ projectRootDir, workerConfigPath, options, readConfig = unstable_readConfig, }) => {
34
35
  if (options.entry?.worker) {
35
- return resolve(projectRootDir, options.entry.worker);
36
+ return normalizePath(resolve(projectRootDir, options.entry.worker));
36
37
  }
37
38
  const workerConfig = readConfig({ config: workerConfigPath });
38
- return resolve(projectRootDir, workerConfig.main ?? "src/worker.tsx");
39
+ return normalizePath(resolve(projectRootDir, workerConfig.main ?? "src/worker.tsx"));
39
40
  };
40
41
  const clientFiles = new Set();
41
42
  const serverFiles = new Set();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rwsdk",
3
- "version": "1.0.8",
3
+ "version": "1.0.9",
4
4
  "description": "Build fast, server-driven webapps on Cloudflare with SSR, RSC, and realtime",
5
5
  "type": "module",
6
6
  "bin": {