rwsdk 1.0.0-beta.30-test.20251119220440 → 1.0.0-beta.30-test.20251120210809
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.
- package/dist/runtime/entries/no-react-server-ssr-bridge.d.ts +0 -0
- package/dist/runtime/entries/no-react-server-ssr-bridge.js +2 -0
- package/dist/vite/cloudflarePreInitPlugin.d.mts +11 -0
- package/dist/vite/cloudflarePreInitPlugin.mjs +40 -0
- package/dist/vite/createDirectiveLookupPlugin.mjs +6 -7
- package/dist/vite/directivesPlugin.mjs +0 -4
- package/dist/vite/injectVitePreamblePlugin.mjs +0 -4
- package/dist/vite/knownDepsResolverPlugin.mjs +6 -16
- package/dist/vite/redwoodPlugin.mjs +2 -0
- package/dist/vite/runDirectivesScan.mjs +13 -4
- package/dist/vite/ssrBridgePlugin.mjs +10 -7
- package/dist/vite/transformJsxScriptTagsPlugin.mjs +0 -4
- package/dist/vite/virtualPlugin.mjs +6 -7
- package/package.json +1 -1
|
File without changes
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { Plugin } from "vite";
|
|
2
|
+
/**
|
|
3
|
+
* Plugin that performs initialization workarounds that must run before
|
|
4
|
+
* the Cloudflare plugin's `configureServer` hook executes.
|
|
5
|
+
*
|
|
6
|
+
* Cloudflare plugin v1.15.0 executes the worker entry file during
|
|
7
|
+
* `configureServer` to detect exports, which triggers SSR code evaluation
|
|
8
|
+
* before normal server initialization completes. This plugin ensures
|
|
9
|
+
* required systems are initialized beforehand.
|
|
10
|
+
*/
|
|
11
|
+
export declare const cloudflarePreInitPlugin: () => Plugin;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Plugin that performs initialization workarounds that must run before
|
|
3
|
+
* the Cloudflare plugin's `configureServer` hook executes.
|
|
4
|
+
*
|
|
5
|
+
* Cloudflare plugin v1.15.0 executes the worker entry file during
|
|
6
|
+
* `configureServer` to detect exports, which triggers SSR code evaluation
|
|
7
|
+
* before normal server initialization completes. This plugin ensures
|
|
8
|
+
* required systems are initialized beforehand.
|
|
9
|
+
*/
|
|
10
|
+
export const cloudflarePreInitPlugin = () => {
|
|
11
|
+
return {
|
|
12
|
+
name: "rwsdk:cloudflare-pre-init",
|
|
13
|
+
// context(justinvdm, 20 Jan 2025): This plugin must run before the
|
|
14
|
+
// Cloudflare plugin's `configureServer` hook. The Cloudflare plugin
|
|
15
|
+
// executes the worker entry file during `configureServer` to detect
|
|
16
|
+
// exports, and blocks the rest of the configureServer plugins until the
|
|
17
|
+
// request is complete. We must initialize required systems (SSR dependency
|
|
18
|
+
// optimizer + our own plugins to them, as well as CSS plugin's moduleCache)
|
|
19
|
+
// before this happens to prevent errors.
|
|
20
|
+
enforce: "pre",
|
|
21
|
+
async configureServer(server) {
|
|
22
|
+
// context(justinvdm, 20 Jan 2025): Initialize SSR dependency optimizer before
|
|
23
|
+
// Cloudflare plugin triggers SSR code evaluation. This ensures dependencies
|
|
24
|
+
// in `optimizeDeps.include` (like `react-dom/server.edge`) are correctly
|
|
25
|
+
// registered before they are discovered lazily.
|
|
26
|
+
if (server.environments.ssr?.depsOptimizer) {
|
|
27
|
+
await server.environments.ssr.depsOptimizer.init();
|
|
28
|
+
}
|
|
29
|
+
// context(justinvdm, 20 Jan 2025): Initialize CSS plugin's shared moduleCache
|
|
30
|
+
// before CSS modules are processed. The Cloudflare plugin's export detection
|
|
31
|
+
// can trigger CSS module processing in the SSR environment during `configureServer`,
|
|
32
|
+
// which happens before `initServer` runs. Vite's CSS plugin uses a shared
|
|
33
|
+
// `moduleCache` that is initialized in the client environment's `buildStart` hook.
|
|
34
|
+
// By calling `buildStart` here (which is idempotent), we ensure the CSS plugin's
|
|
35
|
+
// cache is initialized before CSS modules are processed, preventing "Cannot read
|
|
36
|
+
// properties of undefined (reading 'set')" errors.
|
|
37
|
+
await server.environments.client.pluginContainer.buildStart();
|
|
38
|
+
},
|
|
39
|
+
};
|
|
40
|
+
};
|
|
@@ -101,9 +101,12 @@ export const createDirectiveLookupPlugin = async ({ projectRootDir, files, confi
|
|
|
101
101
|
log("Skipping optimizeDeps and aliasing for environment: %s", env);
|
|
102
102
|
}
|
|
103
103
|
},
|
|
104
|
-
resolveId(source) {
|
|
105
|
-
// Skip during directive scanning to avoid performance issues
|
|
106
|
-
|
|
104
|
+
resolveId(source, _importer, options) {
|
|
105
|
+
// Skip during our directive scanning to avoid performance issues
|
|
106
|
+
// context(justinvdm, 20 Jan 2025): We check options.custom?.rwsdk?.directiveScan to distinguish
|
|
107
|
+
// between our directive scan (which should skip) and external calls like Cloudflare's early
|
|
108
|
+
// dispatch (which should be handled normally).
|
|
109
|
+
if (options?.custom?.rwsdk?.directiveScan === true) {
|
|
107
110
|
return;
|
|
108
111
|
}
|
|
109
112
|
if (source !== `${config.virtualModuleName}.js`) {
|
|
@@ -144,10 +147,6 @@ export const createDirectiveLookupPlugin = async ({ projectRootDir, files, confi
|
|
|
144
147
|
return source;
|
|
145
148
|
},
|
|
146
149
|
async load(id) {
|
|
147
|
-
// Skip during directive scanning to avoid performance issues
|
|
148
|
-
if (process.env.RWSDK_DIRECTIVE_SCAN_ACTIVE) {
|
|
149
|
-
return;
|
|
150
|
-
}
|
|
151
150
|
if (id === config.virtualModuleName + ".js") {
|
|
152
151
|
log("Loading %s module with %d files", config.virtualModuleName, files.size);
|
|
153
152
|
const environment = this.environment?.name || "client";
|
|
@@ -56,10 +56,6 @@ export const directivesPlugin = ({ projectRootDir, clientFiles, serverFiles, })
|
|
|
56
56
|
});
|
|
57
57
|
},
|
|
58
58
|
async transform(code, id) {
|
|
59
|
-
// Skip during directive scanning to avoid performance issues
|
|
60
|
-
if (process.env.RWSDK_DIRECTIVE_SCAN_ACTIVE) {
|
|
61
|
-
return;
|
|
62
|
-
}
|
|
63
59
|
if (isBuild &&
|
|
64
60
|
this.environment?.name === "worker" &&
|
|
65
61
|
process.env.RWSDK_BUILD_PASS !== "worker") {
|
|
@@ -4,10 +4,6 @@ export const injectVitePreamble = ({ clientEntryPoints, projectRootDir, }) => ({
|
|
|
4
4
|
name: "rwsdk:inject-vite-preamble",
|
|
5
5
|
apply: "serve",
|
|
6
6
|
transform(code, id) {
|
|
7
|
-
// Skip during directive scanning to avoid performance issues
|
|
8
|
-
if (process.env.RWSDK_DIRECTIVE_SCAN_ACTIVE) {
|
|
9
|
-
return;
|
|
10
|
-
}
|
|
11
7
|
if (this.environment.name !== "client") {
|
|
12
8
|
return;
|
|
13
9
|
}
|
|
@@ -135,23 +135,10 @@ export const knownDepsResolverPlugin = ({ projectRootDir, }) => {
|
|
|
135
135
|
return [
|
|
136
136
|
{
|
|
137
137
|
name: "rwsdk:known-dependencies-resolver:config",
|
|
138
|
-
enforce: "pre",
|
|
139
138
|
config(config, { command }) {
|
|
140
139
|
isBuild = command === "build";
|
|
141
140
|
log("Configuring plugin for command=%s", command);
|
|
142
141
|
},
|
|
143
|
-
async configureServer(server) {
|
|
144
|
-
// context(justinvdm, 19 Nov 2025): This hook must run before the
|
|
145
|
-
// Cloudflare plugin's `configureServer` hook, so we use `enforce: 'pre'`.
|
|
146
|
-
// The Cloudflare plugin's hook executes the worker entry file to discover
|
|
147
|
-
// its exports. This can trigger the evaluation of SSR code. We must initialize
|
|
148
|
-
// the SSR dependency optimizer *before* that happens to ensure that any
|
|
149
|
-
// dependencies in `optimizeDeps.include` (like `react-dom/server.edge`)
|
|
150
|
-
// are correctly registered before they are discovered lazily.
|
|
151
|
-
if (server.environments.ssr?.depsOptimizer) {
|
|
152
|
-
await server.environments.ssr.depsOptimizer.init();
|
|
153
|
-
}
|
|
154
|
-
},
|
|
155
142
|
configResolved(config) {
|
|
156
143
|
log("Setting up resolve aliases and optimizeDeps for each environment");
|
|
157
144
|
// Set up aliases and optimizeDeps for each environment
|
|
@@ -191,9 +178,12 @@ export const knownDepsResolverPlugin = ({ projectRootDir, }) => {
|
|
|
191
178
|
{
|
|
192
179
|
name: "rwsdk:known-dependencies-resolver:resolveId",
|
|
193
180
|
enforce: "pre",
|
|
194
|
-
async resolveId(id, importer) {
|
|
195
|
-
// Skip during directive scanning to avoid performance issues
|
|
196
|
-
|
|
181
|
+
async resolveId(id, importer, options) {
|
|
182
|
+
// Skip during our directive scanning to avoid performance issues
|
|
183
|
+
// context(justinvdm, 20 Jan 2025): We check options.custom?.rwsdk?.directiveScan to distinguish
|
|
184
|
+
// between our directive scan (which should skip) and external calls like Cloudflare's early
|
|
185
|
+
// dispatch (which should be handled normally).
|
|
186
|
+
if (options?.custom?.rwsdk?.directiveScan === true) {
|
|
197
187
|
return;
|
|
198
188
|
}
|
|
199
189
|
if (!isBuild) {
|
|
@@ -10,6 +10,7 @@ import { pathExists } from "fs-extra";
|
|
|
10
10
|
import { $ } from "../lib/$.mjs";
|
|
11
11
|
import { findWranglerConfig } from "../lib/findWranglerConfig.mjs";
|
|
12
12
|
import { hasPkgScript } from "../lib/hasPkgScript.mjs";
|
|
13
|
+
import { cloudflarePreInitPlugin } from "./cloudflarePreInitPlugin.mjs";
|
|
13
14
|
import { configPlugin } from "./configPlugin.mjs";
|
|
14
15
|
import { devServerTimingPlugin } from "./devServerTimingPlugin.mjs";
|
|
15
16
|
import { directiveModulesDevPlugin } from "./directiveModulesDevPlugin.mjs";
|
|
@@ -106,6 +107,7 @@ export const redwoodPlugin = async (options = {}) => {
|
|
|
106
107
|
projectRootDir,
|
|
107
108
|
}),
|
|
108
109
|
knownDepsResolverPlugin({ projectRootDir }),
|
|
110
|
+
cloudflarePreInitPlugin(),
|
|
109
111
|
tsconfigPaths({ root: projectRootDir }),
|
|
110
112
|
shouldIncludeCloudflarePlugin
|
|
111
113
|
? cloudflare({
|
|
@@ -87,8 +87,6 @@ export function classifyModule({ contents, inheritedEnv, }) {
|
|
|
87
87
|
}
|
|
88
88
|
export const runDirectivesScan = async ({ rootConfig, environments, clientFiles, serverFiles, entries: initialEntries, }) => {
|
|
89
89
|
deferredLog("\n… (rwsdk) Scanning for 'use client' and 'use server' directives...");
|
|
90
|
-
// Set environment variable to indicate scanning is in progress
|
|
91
|
-
process.env.RWSDK_DIRECTIVE_SCAN_ACTIVE = "true";
|
|
92
90
|
try {
|
|
93
91
|
const fileContentCache = new Map();
|
|
94
92
|
const directiveCheckCache = new Map();
|
|
@@ -197,6 +195,19 @@ export const runDirectivesScan = async ({ rootConfig, environments, clientFiles,
|
|
|
197
195
|
log("Resolution result:", resolved);
|
|
198
196
|
const resolvedPath = resolved?.id;
|
|
199
197
|
if (resolvedPath && path.isAbsolute(resolvedPath)) {
|
|
198
|
+
try {
|
|
199
|
+
const stats = await fsp.stat(resolvedPath);
|
|
200
|
+
if (stats.isDirectory()) {
|
|
201
|
+
log("Resolved path is a directory, marking as external to avoid scan error:", resolvedPath);
|
|
202
|
+
return { external: true };
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
catch (e) {
|
|
206
|
+
// This can happen for virtual modules or special paths that don't
|
|
207
|
+
// exist on the filesystem. We can safely externalize them.
|
|
208
|
+
log("Could not stat resolved path, marking as external:", resolvedPath);
|
|
209
|
+
return { external: true };
|
|
210
|
+
}
|
|
200
211
|
// Normalize the path for esbuild compatibility
|
|
201
212
|
const normalizedPath = normalizeModulePath(resolvedPath, rootConfig.root, { absolute: true });
|
|
202
213
|
log("Normalized path:", normalizedPath);
|
|
@@ -290,8 +301,6 @@ export const runDirectivesScan = async ({ rootConfig, environments, clientFiles,
|
|
|
290
301
|
throw new Error(`RWSDK directive scan failed:\n${e.stack}`);
|
|
291
302
|
}
|
|
292
303
|
finally {
|
|
293
|
-
// Always clear the scanning flag when done
|
|
294
|
-
delete process.env.RWSDK_DIRECTIVE_SCAN_ACTIVE;
|
|
295
304
|
deferredLog("✔ (rwsdk) Done scanning for 'use client' and 'use server' directives.");
|
|
296
305
|
process.env.VERBOSE &&
|
|
297
306
|
log("Client/server files after scanning: client=%O, server=%O", Array.from(clientFiles), Array.from(serverFiles));
|
|
@@ -58,12 +58,14 @@ export const ssrBridgePlugin = ({ clientFiles, serverFiles, }) => {
|
|
|
58
58
|
config.optimizeDeps.esbuildOptions.plugins.push({
|
|
59
59
|
name: "rwsdk-ssr-external",
|
|
60
60
|
setup(build) {
|
|
61
|
+
console.log("[TIMING] rwsdk-ssr-external.setup: START - Plugin setup function called");
|
|
61
62
|
log("Setting up esbuild plugin to mark rwsdk/__ssr paths as external for worker");
|
|
62
63
|
build.onResolve({ filter: /.*$/ }, (args) => {
|
|
63
64
|
process.env.VERBOSE &&
|
|
64
65
|
log("Esbuild onResolve called for path=%s, args=%O", args.path, args);
|
|
65
66
|
if (args.path === "rwsdk/__ssr_bridge" ||
|
|
66
67
|
args.path.startsWith(VIRTUAL_SSR_PREFIX)) {
|
|
68
|
+
console.log(`[TIMING] rwsdk-ssr-external.onResolve: Intercepted ${args.path}`);
|
|
67
69
|
log("Marking as external: %s", args.path);
|
|
68
70
|
return {
|
|
69
71
|
path: args.path,
|
|
@@ -71,14 +73,19 @@ export const ssrBridgePlugin = ({ clientFiles, serverFiles, }) => {
|
|
|
71
73
|
};
|
|
72
74
|
}
|
|
73
75
|
});
|
|
76
|
+
console.log("[TIMING] rwsdk-ssr-external.setup: COMPLETE - onResolve hook registered");
|
|
74
77
|
},
|
|
75
78
|
});
|
|
76
79
|
log("Worker environment esbuild configuration complete");
|
|
77
80
|
}
|
|
78
81
|
},
|
|
79
|
-
async resolveId(id, importer) {
|
|
80
|
-
// Skip during directive scanning to avoid performance issues
|
|
81
|
-
|
|
82
|
+
async resolveId(id, importer, options) {
|
|
83
|
+
// Skip during our directive scanning to avoid performance issues
|
|
84
|
+
// context(justinvdm, 20 Jan 2025): We check options.custom?.rwsdk?.directiveScan to distinguish
|
|
85
|
+
// between our directive scan (which should skip) and external calls like Cloudflare's early
|
|
86
|
+
// dispatch (which should be handled normally). This prevents race conditions where external
|
|
87
|
+
// calls happen during directive scanning.
|
|
88
|
+
if (options?.custom?.rwsdk?.directiveScan === true) {
|
|
82
89
|
return;
|
|
83
90
|
}
|
|
84
91
|
// context(justinvdm, 19 Nov 2025):
|
|
@@ -137,10 +144,6 @@ export const ssrBridgePlugin = ({ clientFiles, serverFiles, }) => {
|
|
|
137
144
|
}
|
|
138
145
|
},
|
|
139
146
|
async load(id) {
|
|
140
|
-
// Skip during directive scanning to avoid performance issues
|
|
141
|
-
if (process.env.RWSDK_DIRECTIVE_SCAN_ACTIVE) {
|
|
142
|
-
return;
|
|
143
|
-
}
|
|
144
147
|
if (id.startsWith(VIRTUAL_SSR_PREFIX) &&
|
|
145
148
|
this.environment.name === "worker") {
|
|
146
149
|
const realId = id.slice(VIRTUAL_SSR_PREFIX.length);
|
|
@@ -319,10 +319,6 @@ export const transformJsxScriptTagsPlugin = ({ clientEntryPoints, projectRootDir
|
|
|
319
319
|
isBuild = config.command === "build";
|
|
320
320
|
},
|
|
321
321
|
async transform(code, id) {
|
|
322
|
-
// Skip during directive scanning to avoid performance issues
|
|
323
|
-
if (process.env.RWSDK_DIRECTIVE_SCAN_ACTIVE) {
|
|
324
|
-
return;
|
|
325
|
-
}
|
|
326
322
|
if (isBuild &&
|
|
327
323
|
this.environment?.name === "worker" &&
|
|
328
324
|
process.env.RWSDK_BUILD_PASS !== "worker") {
|
|
@@ -3,9 +3,12 @@ export const virtualPlugin = (name, load) => {
|
|
|
3
3
|
name = "virtual:" + name;
|
|
4
4
|
return {
|
|
5
5
|
name: `rwsdk:virtual-${name}`,
|
|
6
|
-
resolveId(source, _importer,
|
|
7
|
-
// Skip during directive scanning to avoid performance issues
|
|
8
|
-
|
|
6
|
+
resolveId(source, _importer, options) {
|
|
7
|
+
// Skip during our directive scanning to avoid performance issues
|
|
8
|
+
// context(justinvdm, 20 Jan 2025): We check options.custom?.rwsdk?.directiveScan to distinguish
|
|
9
|
+
// between our directive scan (which should skip) and external calls like Cloudflare's early
|
|
10
|
+
// dispatch (which should be handled normally).
|
|
11
|
+
if (options?.custom?.rwsdk?.directiveScan === true) {
|
|
9
12
|
return;
|
|
10
13
|
}
|
|
11
14
|
if (source === name || source.startsWith(`${name}?`)) {
|
|
@@ -14,10 +17,6 @@ export const virtualPlugin = (name, load) => {
|
|
|
14
17
|
return;
|
|
15
18
|
},
|
|
16
19
|
load(id, options) {
|
|
17
|
-
// Skip during directive scanning to avoid performance issues
|
|
18
|
-
if (process.env.RWSDK_DIRECTIVE_SCAN_ACTIVE) {
|
|
19
|
-
return;
|
|
20
|
-
}
|
|
21
20
|
if (id === `\0${name}` || id.startsWith(`\0${name}?`)) {
|
|
22
21
|
return load.apply(this, [id, options]);
|
|
23
22
|
}
|
package/package.json
CHANGED