rwsdk 1.0.0-beta.1 → 1.0.0-beta.10

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.
Files changed (42) hide show
  1. package/dist/lib/e2e/constants.d.mts +13 -0
  2. package/dist/lib/e2e/constants.mjs +67 -0
  3. package/dist/lib/e2e/environment.d.mts +1 -1
  4. package/dist/lib/e2e/environment.mjs +16 -6
  5. package/dist/lib/e2e/index.d.mts +1 -0
  6. package/dist/lib/e2e/index.mjs +1 -0
  7. package/dist/lib/e2e/testHarness.d.mts +33 -3
  8. package/dist/lib/e2e/testHarness.mjs +181 -109
  9. package/dist/runtime/client/client.d.ts +1 -0
  10. package/dist/runtime/client/client.js +2 -0
  11. package/dist/runtime/client/navigation.d.ts +8 -0
  12. package/dist/runtime/client/navigation.js +39 -31
  13. package/dist/runtime/entries/clientSSR.d.ts +1 -0
  14. package/dist/runtime/entries/clientSSR.js +3 -0
  15. package/dist/runtime/lib/db/createDb.d.ts +1 -2
  16. package/dist/runtime/lib/db/createDb.js +4 -0
  17. package/dist/runtime/lib/manifest.d.ts +1 -1
  18. package/dist/runtime/lib/manifest.js +7 -4
  19. package/dist/runtime/lib/realtime/client.js +8 -2
  20. package/dist/runtime/lib/router.d.ts +1 -19
  21. package/dist/runtime/lib/router.test.js +2 -0
  22. package/dist/runtime/lib/{rwContext.d.ts → types.d.ts} +1 -0
  23. package/dist/runtime/render/renderDocumentHtmlStream.d.ts +1 -1
  24. package/dist/runtime/render/renderToStream.d.ts +1 -1
  25. package/dist/runtime/render/renderToString.d.ts +1 -1
  26. package/dist/runtime/requestInfo/types.d.ts +1 -1
  27. package/dist/runtime/script.d.ts +1 -3
  28. package/dist/runtime/script.js +1 -10
  29. package/dist/runtime/worker.js +25 -0
  30. package/dist/scripts/addon.mjs +1 -1
  31. package/dist/scripts/smoke-test.mjs +4 -2
  32. package/dist/scripts/worker-run.d.mts +1 -1
  33. package/dist/scripts/worker-run.mjs +50 -113
  34. package/dist/vite/buildApp.mjs +2 -0
  35. package/dist/vite/directiveModulesDevPlugin.mjs +1 -1
  36. package/dist/vite/linkerPlugin.mjs +1 -1
  37. package/dist/vite/redwoodPlugin.mjs +0 -4
  38. package/dist/vite/runDirectivesScan.mjs +57 -12
  39. package/package.json +9 -7
  40. package/dist/vite/manifestPlugin.d.mts +0 -4
  41. package/dist/vite/manifestPlugin.mjs +0 -63
  42. /package/dist/runtime/lib/{rwContext.js → types.js} +0 -0
@@ -1,6 +1,7 @@
1
1
  // @ts-ignore
2
2
  import { compile } from "@mdx-js/mdx";
3
3
  import debug from "debug";
4
+ import { glob } from "glob";
4
5
  import fsp from "node:fs/promises";
5
6
  import path from "node:path";
6
7
  import { INTERMEDIATES_OUTPUT_DIR } from "../lib/constants.mjs";
@@ -17,6 +18,39 @@ const isObject = (value) => Object.prototype.toString.call(value) === "[object O
17
18
  // https://github.com/vitejs/vite/blob/main/packages/vite/src/node/utils.ts
18
19
  const externalRE = /^(https?:)?\/\//;
19
20
  const isExternalUrl = (url) => externalRE.test(url);
21
+ async function findDirectiveRoots({ root, readFileWithCache, directiveCheckCache, }) {
22
+ const srcDir = path.resolve(root, "src");
23
+ const files = await glob("**/*.{ts,tsx,js,jsx,mjs,mts,cjs,cts,mdx}", {
24
+ cwd: srcDir,
25
+ absolute: true,
26
+ });
27
+ const directiveFiles = new Set();
28
+ for (const file of files) {
29
+ if (directiveCheckCache.has(file)) {
30
+ if (directiveCheckCache.get(file)) {
31
+ directiveFiles.add(file);
32
+ }
33
+ continue;
34
+ }
35
+ try {
36
+ const content = await readFileWithCache(file);
37
+ const hasClient = hasDirective(content, "use client");
38
+ const hasServer = hasDirective(content, "use server");
39
+ const hasAnyDirective = hasClient || hasServer;
40
+ directiveCheckCache.set(file, hasAnyDirective);
41
+ if (hasAnyDirective) {
42
+ directiveFiles.add(file);
43
+ }
44
+ }
45
+ catch (e) {
46
+ log("Could not read file during pre-scan, skipping:", file);
47
+ // Cache the failure to avoid re-reading a problematic file
48
+ directiveCheckCache.set(file, false);
49
+ }
50
+ }
51
+ log("Pre-scan found directive files:", Array.from(directiveFiles));
52
+ return directiveFiles;
53
+ }
20
54
  export async function resolveModuleWithEnvironment({ path, importer, importerEnv, clientResolver, workerResolver, }) {
21
55
  const resolver = importerEnv === "client" ? clientResolver : workerResolver;
22
56
  return new Promise((resolvePromise) => {
@@ -56,6 +90,16 @@ export const runDirectivesScan = async ({ rootConfig, environments, clientFiles,
56
90
  // Set environment variable to indicate scanning is in progress
57
91
  process.env.RWSDK_DIRECTIVE_SCAN_ACTIVE = "true";
58
92
  try {
93
+ const fileContentCache = new Map();
94
+ const directiveCheckCache = new Map();
95
+ const readFileWithCache = async (path) => {
96
+ if (fileContentCache.has(path)) {
97
+ return fileContentCache.get(path);
98
+ }
99
+ const contents = await fsp.readFile(path, "utf-8");
100
+ fileContentCache.set(path, contents);
101
+ return contents;
102
+ };
59
103
  const esbuild = await getViteEsbuild(rootConfig.root);
60
104
  const input = initialEntries ?? environments.worker.config.build.rollupOptions?.input;
61
105
  let entries;
@@ -78,19 +122,19 @@ export const runDirectivesScan = async ({ rootConfig, environments, clientFiles,
78
122
  // Filter out virtual modules since they can't be scanned by esbuild
79
123
  const realEntries = entries.filter((entry) => !entry.includes("virtual:"));
80
124
  const absoluteEntries = realEntries.map((entry) => path.resolve(rootConfig.root, entry));
81
- log("Starting directives scan for worker environment with entries:", absoluteEntries);
125
+ const applicationDirectiveFiles = await findDirectiveRoots({
126
+ root: rootConfig.root,
127
+ readFileWithCache,
128
+ directiveCheckCache,
129
+ });
130
+ const combinedEntries = new Set([
131
+ ...absoluteEntries,
132
+ ...applicationDirectiveFiles,
133
+ ]);
134
+ log("Starting directives scan with combined entries:", Array.from(combinedEntries));
82
135
  const workerResolver = createViteAwareResolver(rootConfig, environments.worker);
83
136
  const clientResolver = createViteAwareResolver(rootConfig, environments.client);
84
137
  const moduleEnvironments = new Map();
85
- const fileContentCache = new Map();
86
- const readFileWithCache = async (path) => {
87
- if (fileContentCache.has(path)) {
88
- return fileContentCache.get(path);
89
- }
90
- const contents = await fsp.readFile(path, "utf-8");
91
- fileContentCache.set(path, contents);
92
- return contents;
93
- };
94
138
  const esbuildScanPlugin = {
95
139
  name: "rwsdk:esbuild-scan-plugin",
96
140
  setup(build) {
@@ -232,7 +276,7 @@ export const runDirectivesScan = async ({ rootConfig, environments, clientFiles,
232
276
  },
233
277
  };
234
278
  await esbuild.build({
235
- entryPoints: absoluteEntries,
279
+ entryPoints: Array.from(combinedEntries),
236
280
  bundle: true,
237
281
  write: false,
238
282
  outdir: path.join(INTERMEDIATES_OUTPUT_DIR, "directive-scan"),
@@ -254,7 +298,8 @@ export const runDirectivesScan = async ({ rootConfig, environments, clientFiles,
254
298
  }
255
299
  };
256
300
  const deferredLog = (message) => {
301
+ const doLog = process.env.RWSDK_WORKER_RUN ? log : console.log;
257
302
  setTimeout(() => {
258
- console.log(message);
303
+ doLog(message);
259
304
  }, 500);
260
305
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rwsdk",
3
- "version": "1.0.0-beta.1",
3
+ "version": "v1.0.0-beta.10",
4
4
  "description": "Build fast, server-driven webapps on Cloudflare with SSR, RSC, and realtime",
5
5
  "type": "module",
6
6
  "bin": {
@@ -145,11 +145,13 @@
145
145
  "@vitejs/plugin-react": "~5.0.0",
146
146
  "chokidar": "~4.0.0",
147
147
  "debug": "~4.4.0",
148
+ "decompress": "~4.2.1",
148
149
  "enhanced-resolve": "~5.18.1",
149
150
  "eventsource-parser": "~3.0.0",
150
151
  "execa": "~9.6.0",
151
152
  "find-up": "~8.0.0",
152
153
  "fs-extra": "~11.3.0",
154
+ "get-port": "^7.1.0",
153
155
  "glob": "~11.0.1",
154
156
  "ignore": "~7.0.4",
155
157
  "jsonc-parser": "~3.3.1",
@@ -167,13 +169,13 @@
167
169
  "unique-names-generator": "~4.7.1",
168
170
  "vibe-rules": "~0.3.0",
169
171
  "vite-tsconfig-paths": "~5.1.4",
170
- "decompress": "~4.2.1"
172
+ "@types/glob": "^8.1.0"
171
173
  },
172
174
  "peerDependencies": {
173
- "@cloudflare/vite-plugin": "^1.12.4",
174
- "react": ">=19.2.0-canary-3fb190f7-20250908 <20.0.0",
175
- "react-dom": ">=19.2.0-canary-3fb190f7-20250908 <20.0.0",
176
- "react-server-dom-webpack": ">=19.2.0-canary-3fb190f7-20250908 <20.0.0",
175
+ "@cloudflare/vite-plugin": "^1.13.10",
176
+ "react": ">=19.3.0-canary-4fdf7cf2-20251003 <20.0.0",
177
+ "react-dom": ">=19.3.0-canary-4fdf7cf2-20251003 <20.0.0",
178
+ "react-server-dom-webpack": ">=19.3.0-canary-4fdf7cf2-20251003 <20.0.0",
177
179
  "vite": "^6.2.6 || 7.x",
178
180
  "wrangler": "^4.35.0"
179
181
  },
@@ -189,7 +191,7 @@
189
191
  "semver": "~7.7.1",
190
192
  "tsx": "~4.20.0",
191
193
  "typescript": "~5.9.0",
192
- "vite": "7.1.6",
194
+ "vite": "~7.1.9",
193
195
  "vitest": "~3.2.0"
194
196
  }
195
197
  }
@@ -1,4 +0,0 @@
1
- import { type Plugin } from "vite";
2
- export declare const manifestPlugin: ({ projectRootDir, }: {
3
- projectRootDir: string;
4
- }) => Plugin;
@@ -1,63 +0,0 @@
1
- import debug from "debug";
2
- const log = debug("rwsdk:vite:manifest-plugin");
3
- const virtualModuleId = "virtual:rwsdk:manifest.js";
4
- const resolvedVirtualModuleId = "\0" + virtualModuleId;
5
- export const manifestPlugin = ({ projectRootDir, }) => {
6
- let isBuild = false;
7
- return {
8
- name: "rwsdk:vite:manifest-plugin",
9
- enforce: "pre",
10
- configResolved(config) {
11
- isBuild = config.command === "build";
12
- },
13
- resolveId(id) {
14
- // Skip during directive scanning to avoid performance issues
15
- if (process.env.RWSDK_DIRECTIVE_SCAN_ACTIVE) {
16
- return;
17
- }
18
- if (id === virtualModuleId) {
19
- return resolvedVirtualModuleId;
20
- }
21
- },
22
- async load(id) {
23
- // Skip during directive scanning to avoid performance issues
24
- if (process.env.RWSDK_DIRECTIVE_SCAN_ACTIVE) {
25
- return;
26
- }
27
- if (id === resolvedVirtualModuleId) {
28
- if (isBuild) {
29
- // context(justinvdm, 28 Aug 2025): During the build, we don't have
30
- // the manifest yet. We insert a placeholder that the linker plugin
31
- // will replace in the final phase.
32
- log("Returning manifest placeholder for build");
33
- return `export default "__RWSDK_MANIFEST_PLACEHOLDER__"`;
34
- }
35
- // In dev, we can return an empty object.
36
- log("Not a build, returning empty manifest");
37
- return `export default {}`;
38
- }
39
- },
40
- configEnvironment(name, config) {
41
- if (name !== "worker" && name !== "ssr") {
42
- return;
43
- }
44
- log("Configuring environment: name=%s", name);
45
- config.optimizeDeps ??= {};
46
- config.optimizeDeps.esbuildOptions ??= {};
47
- config.optimizeDeps.esbuildOptions.plugins ??= [];
48
- config.optimizeDeps.esbuildOptions.plugins.push({
49
- name: "rwsdk:manifest:esbuild",
50
- setup(build) {
51
- log("Setting up esbuild plugin for environment: %s", name);
52
- build.onResolve({ filter: /^virtual:rwsdk:manifest\.js$/ }, () => {
53
- log("Resolving virtual manifest module in esbuild");
54
- return {
55
- path: "virtual:rwsdk:manifest.js",
56
- external: true,
57
- };
58
- });
59
- },
60
- });
61
- },
62
- };
63
- };
File without changes