rwsdk 0.2.0 → 0.3.0
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/lib/constants.d.mts +6 -1
- package/dist/lib/constants.mjs +6 -1
- package/dist/lib/smokeTests/browser.mjs +5 -21
- package/dist/lib/smokeTests/codeUpdates.d.mts +1 -1
- package/dist/lib/smokeTests/codeUpdates.mjs +41 -5
- package/dist/lib/smokeTests/development.d.mts +1 -1
- package/dist/lib/smokeTests/development.mjs +4 -10
- package/dist/lib/smokeTests/release.d.mts +1 -1
- package/dist/lib/smokeTests/release.mjs +4 -9
- package/dist/lib/smokeTests/runSmokeTests.mjs +2 -2
- package/dist/lib/smokeTests/templates/SmokeTest.template.js +3 -2
- package/dist/lib/testUtils/stubEnvVars.d.mts +2 -0
- package/dist/lib/testUtils/stubEnvVars.mjs +11 -0
- package/dist/runtime/imports/client.js +4 -9
- package/dist/runtime/imports/worker.js +2 -1
- package/dist/runtime/register/ssr.js +2 -1
- package/dist/runtime/requestInfo/worker.js +9 -1
- package/dist/runtime/worker.d.ts +0 -3
- package/dist/runtime/worker.js +1 -10
- package/dist/scripts/debug-sync.mjs +0 -23
- package/dist/scripts/smoke-test.mjs +0 -10
- package/dist/vite/buildApp.d.mts +15 -0
- package/dist/vite/buildApp.mjs +53 -0
- package/dist/vite/configPlugin.d.mts +4 -2
- package/dist/vite/configPlugin.mjs +69 -62
- package/dist/vite/createDirectiveLookupPlugin.d.mts +0 -6
- package/dist/vite/createDirectiveLookupPlugin.mjs +61 -145
- package/dist/vite/directiveModulesDevPlugin.d.mts +8 -0
- package/dist/vite/directiveModulesDevPlugin.mjs +62 -0
- package/dist/vite/directivesFilteringPlugin.d.mts +6 -0
- package/dist/vite/directivesFilteringPlugin.mjs +31 -0
- package/dist/vite/directivesPlugin.mjs +28 -42
- package/dist/vite/getViteEsbuild.d.mts +1 -0
- package/dist/vite/getViteEsbuild.mjs +12 -0
- package/dist/vite/injectVitePreamblePlugin.d.mts +3 -2
- package/dist/vite/injectVitePreamblePlugin.mjs +4 -2
- package/dist/vite/linkerPlugin.d.mts +4 -0
- package/dist/vite/linkerPlugin.mjs +41 -0
- package/dist/vite/manifestPlugin.d.mts +2 -2
- package/dist/vite/manifestPlugin.mjs +12 -37
- package/dist/vite/moveStaticAssetsPlugin.mjs +2 -1
- package/dist/vite/prismaPlugin.mjs +1 -1
- package/dist/vite/reactConditionsResolverPlugin.mjs +11 -16
- package/dist/vite/redwoodPlugin.d.mts +0 -1
- package/dist/vite/redwoodPlugin.mjs +27 -9
- package/dist/vite/runDirectivesScan.d.mts +7 -0
- package/dist/vite/runDirectivesScan.mjs +152 -0
- package/dist/vite/ssrBridgePlugin.mjs +13 -14
- package/dist/vite/transformClientComponents.d.mts +0 -1
- package/dist/vite/transformClientComponents.mjs +1 -9
- package/dist/vite/transformJsxScriptTagsPlugin.d.mts +4 -3
- package/dist/vite/transformJsxScriptTagsPlugin.mjs +62 -84
- package/dist/vite/transformJsxScriptTagsPlugin.test.mjs +67 -41
- package/dist/vite/transformServerFunctions.d.mts +1 -1
- package/dist/vite/transformServerFunctions.mjs +11 -12
- package/package.json +7 -1
- package/dist/runtime/clientNavigation.d.ts +0 -9
- package/dist/runtime/clientNavigation.js +0 -88
|
@@ -1,10 +1,15 @@
|
|
|
1
|
-
import { describe, it, expect } from "vitest";
|
|
1
|
+
import { describe, it, expect, beforeEach } from "vitest";
|
|
2
2
|
import { transformJsxScriptTagsCode } from "./transformJsxScriptTagsPlugin.mjs";
|
|
3
3
|
import jsBeautify from "js-beautify";
|
|
4
|
+
import stubEnvVars from "../lib/testUtils/stubEnvVars.mjs";
|
|
4
5
|
// Helper function to normalize code formatting for test comparisons
|
|
5
6
|
function normalizeCode(code) {
|
|
6
7
|
return jsBeautify(code, { indent_size: 2 });
|
|
7
8
|
}
|
|
9
|
+
stubEnvVars();
|
|
10
|
+
beforeEach(() => {
|
|
11
|
+
process.env.RWSDK_BUILD_PASS = "worker";
|
|
12
|
+
});
|
|
8
13
|
describe("transformJsxScriptTagsCode", () => {
|
|
9
14
|
const mockManifest = {
|
|
10
15
|
"src/client.tsx": { file: "assets/client-a1b2c3d4.js" },
|
|
@@ -18,13 +23,14 @@ describe("transformJsxScriptTagsCode", () => {
|
|
|
18
23
|
type: "module"
|
|
19
24
|
})
|
|
20
25
|
`;
|
|
21
|
-
const
|
|
26
|
+
const clientEntryPoints = new Set();
|
|
27
|
+
const result = await transformJsxScriptTagsCode(code, clientEntryPoints, mockManifest, "/Users/justin/rw/forks/workers-sdk/sdk/sdk");
|
|
22
28
|
const expected = `import { requestInfo } from "rwsdk/worker";
|
|
23
29
|
|
|
24
30
|
(
|
|
25
31
|
(requestInfo.rw.scriptsToBeLoaded.add("/src/client.tsx")),
|
|
26
32
|
jsx("script", {
|
|
27
|
-
src: "/
|
|
33
|
+
src: "rwsdk_asset:/src/client.tsx",
|
|
28
34
|
type: "module",
|
|
29
35
|
nonce: requestInfo.rw.nonce
|
|
30
36
|
})
|
|
@@ -38,14 +44,15 @@ nonce: requestInfo.rw.nonce
|
|
|
38
44
|
children: "import('/src/client.tsx').then(module => { console.log(module); })"
|
|
39
45
|
})
|
|
40
46
|
`;
|
|
41
|
-
const
|
|
47
|
+
const clientEntryPoints = new Set();
|
|
48
|
+
const result = await transformJsxScriptTagsCode(code, clientEntryPoints, mockManifest, "/project/root/dir");
|
|
42
49
|
const expected = `import { requestInfo } from "rwsdk/worker";
|
|
43
50
|
|
|
44
51
|
(
|
|
45
52
|
(requestInfo.rw.scriptsToBeLoaded.add("/src/client.tsx")),
|
|
46
53
|
jsx("script", {
|
|
47
54
|
type: "module",
|
|
48
|
-
children: "import('/
|
|
55
|
+
children: "import('rwsdk_asset:/src/client.tsx').then(module => { console.log(module); })",
|
|
49
56
|
nonce: requestInfo.rw.nonce
|
|
50
57
|
})
|
|
51
58
|
)`;
|
|
@@ -55,12 +62,13 @@ nonce: requestInfo.rw.nonce
|
|
|
55
62
|
const code = `
|
|
56
63
|
jsx("script", { type: "module", children: "import('/src/client.tsx')" })
|
|
57
64
|
`;
|
|
58
|
-
const
|
|
65
|
+
const clientEntryPoints = new Set();
|
|
66
|
+
const result = await transformJsxScriptTagsCode(code, clientEntryPoints, mockManifest, "/project/root/dir");
|
|
59
67
|
const expected = `import { requestInfo } from "rwsdk/worker";
|
|
60
68
|
|
|
61
69
|
(
|
|
62
70
|
(requestInfo.rw.scriptsToBeLoaded.add("/src/client.tsx")),
|
|
63
|
-
jsx("script", { type: "module", children: "import('/
|
|
71
|
+
jsx("script", { type: "module", children: "import('rwsdk_asset:/src/client.tsx')",
|
|
64
72
|
nonce: requestInfo.rw.nonce
|
|
65
73
|
})
|
|
66
74
|
)`;
|
|
@@ -80,7 +88,8 @@ nonce: requestInfo.rw.nonce
|
|
|
80
88
|
\`
|
|
81
89
|
})
|
|
82
90
|
`;
|
|
83
|
-
const
|
|
91
|
+
const clientEntryPoints = new Set();
|
|
92
|
+
const result = await transformJsxScriptTagsCode(code, clientEntryPoints, mockManifest, "/project/root/dir");
|
|
84
93
|
const expected = `import { requestInfo } from "rwsdk/worker";
|
|
85
94
|
|
|
86
95
|
(
|
|
@@ -90,7 +99,7 @@ type: "module",
|
|
|
90
99
|
children: \`
|
|
91
100
|
// Some comments here
|
|
92
101
|
const init = async () => {
|
|
93
|
-
await import('/
|
|
102
|
+
await import('rwsdk_asset:/src/entry.js');
|
|
94
103
|
console.log('initialized');
|
|
95
104
|
};
|
|
96
105
|
init();
|
|
@@ -110,7 +119,8 @@ import('/src/entry.js');
|
|
|
110
119
|
\`
|
|
111
120
|
})
|
|
112
121
|
`;
|
|
113
|
-
const
|
|
122
|
+
const clientEntryPoints = new Set();
|
|
123
|
+
const result = await transformJsxScriptTagsCode(code, clientEntryPoints, mockManifest, "/project/root/dir");
|
|
114
124
|
const expected = `import { requestInfo } from "rwsdk/worker";
|
|
115
125
|
|
|
116
126
|
(
|
|
@@ -119,8 +129,8 @@ import('/src/entry.js');
|
|
|
119
129
|
jsx("script", {
|
|
120
130
|
type: "module",
|
|
121
131
|
children: \`
|
|
122
|
-
import('/
|
|
123
|
-
import('/
|
|
132
|
+
import('rwsdk_asset:/src/client.tsx');
|
|
133
|
+
import('rwsdk_asset:/src/entry.js');
|
|
124
134
|
\`,
|
|
125
135
|
nonce: requestInfo.rw.nonce
|
|
126
136
|
})
|
|
@@ -135,14 +145,17 @@ nonce: requestInfo.rw.nonce
|
|
|
135
145
|
as: "script"
|
|
136
146
|
})
|
|
137
147
|
`;
|
|
138
|
-
const
|
|
139
|
-
|
|
148
|
+
const clientEntryPoints = new Set();
|
|
149
|
+
const result = await transformJsxScriptTagsCode(code, clientEntryPoints, mockManifest, "/project/root/dir");
|
|
150
|
+
const expected = `
|
|
140
151
|
jsx("link", {
|
|
141
152
|
rel: "preload",
|
|
142
|
-
href: "/
|
|
153
|
+
href: "rwsdk_asset:/src/client.tsx",
|
|
143
154
|
as: "script"
|
|
144
155
|
})
|
|
145
|
-
|
|
156
|
+
`;
|
|
157
|
+
expect(normalizeCode(result?.code || "")).toEqual(normalizeCode(expected));
|
|
158
|
+
expect(clientEntryPoints.size).toBe(0); // Make sure it doesn't incorrectly add to entry points
|
|
146
159
|
});
|
|
147
160
|
it("transforms link href attributes with modulepreload rel", async () => {
|
|
148
161
|
const code = `
|
|
@@ -151,13 +164,15 @@ nonce: requestInfo.rw.nonce
|
|
|
151
164
|
rel: "modulepreload"
|
|
152
165
|
})
|
|
153
166
|
`;
|
|
154
|
-
const
|
|
155
|
-
|
|
167
|
+
const clientEntryPoints = new Set();
|
|
168
|
+
const result = await transformJsxScriptTagsCode(code, clientEntryPoints, mockManifest, "/project/root/dir");
|
|
169
|
+
const expected = `
|
|
156
170
|
jsx("link", {
|
|
157
|
-
href: "/
|
|
171
|
+
href: "rwsdk_asset:/src/client.tsx",
|
|
158
172
|
rel: "modulepreload"
|
|
159
173
|
})
|
|
160
|
-
|
|
174
|
+
`;
|
|
175
|
+
expect(normalizeCode(result?.code || "")).toEqual(normalizeCode(expected));
|
|
161
176
|
});
|
|
162
177
|
it("transforms real-world Document component example", async () => {
|
|
163
178
|
const code = `
|
|
@@ -169,7 +184,7 @@ nonce: requestInfo.rw.nonce
|
|
|
169
184
|
jsx("meta", { charSet: "utf-8" }),
|
|
170
185
|
jsx("meta", { name: "viewport", content: "width=device-width, initial-scale=1" }),
|
|
171
186
|
jsx("title", { children: "@redwoodjs/starter-standard" }),
|
|
172
|
-
jsx("link", { rel: "modulepreload", href: "
|
|
187
|
+
jsx("link", { rel: "modulepreload", href: "rwsdk_asset:/src/client.tsx", as: "script" })
|
|
173
188
|
]
|
|
174
189
|
}),
|
|
175
190
|
jsx("body", {
|
|
@@ -181,7 +196,8 @@ nonce: requestInfo.rw.nonce
|
|
|
181
196
|
]
|
|
182
197
|
})
|
|
183
198
|
`;
|
|
184
|
-
const
|
|
199
|
+
const clientEntryPoints = new Set();
|
|
200
|
+
const result = await transformJsxScriptTagsCode(code, clientEntryPoints, mockManifest, "/project/root/dir");
|
|
185
201
|
const expected = `import { requestInfo } from "rwsdk/worker";
|
|
186
202
|
|
|
187
203
|
jsx("html", {
|
|
@@ -192,7 +208,7 @@ children: [
|
|
|
192
208
|
jsx("meta", { charSet: "utf-8" }),
|
|
193
209
|
jsx("meta", { name: "viewport", content: "width=device-width, initial-scale=1" }),
|
|
194
210
|
jsx("title", { children: "@redwoodjs/starter-standard" }),
|
|
195
|
-
jsx("link", { rel: "modulepreload", href: "/
|
|
211
|
+
jsx("link", { rel: "modulepreload", href: "rwsdk_asset:/src/client.tsx", as: "script" })
|
|
196
212
|
]
|
|
197
213
|
}),
|
|
198
214
|
jsx("body", {
|
|
@@ -200,7 +216,7 @@ children: [
|
|
|
200
216
|
jsx("div", { id: "root", children: props.children }),
|
|
201
217
|
(
|
|
202
218
|
(requestInfo.rw.scriptsToBeLoaded.add("/src/client.tsx")),
|
|
203
|
-
jsx("script", { children: "import(\\"/
|
|
219
|
+
jsx("script", { children: "import(\\"rwsdk_asset:/src/client.tsx\\")",
|
|
204
220
|
nonce: requestInfo.rw.nonce
|
|
205
221
|
})
|
|
206
222
|
)
|
|
@@ -214,7 +230,8 @@ nonce: requestInfo.rw.nonce
|
|
|
214
230
|
const code = `
|
|
215
231
|
jsx("div", { children: "No scripts or links here" })
|
|
216
232
|
`;
|
|
217
|
-
const
|
|
233
|
+
const clientEntryPoints = new Set();
|
|
234
|
+
const result = await transformJsxScriptTagsCode(code, clientEntryPoints, mockManifest, "/project/root/dir");
|
|
218
235
|
expect(result).toBeUndefined();
|
|
219
236
|
});
|
|
220
237
|
it("handles paths not found in manifest", async () => {
|
|
@@ -224,13 +241,14 @@ nonce: requestInfo.rw.nonce
|
|
|
224
241
|
type: "module"
|
|
225
242
|
})
|
|
226
243
|
`;
|
|
227
|
-
const
|
|
244
|
+
const clientEntryPoints = new Set();
|
|
245
|
+
const result = await transformJsxScriptTagsCode(code, clientEntryPoints, mockManifest, "/project/root/dir");
|
|
228
246
|
const expected = `import { requestInfo } from "rwsdk/worker";
|
|
229
247
|
|
|
230
248
|
(
|
|
231
249
|
(requestInfo.rw.scriptsToBeLoaded.add("/src/non-existent.js")),
|
|
232
250
|
jsx("script", {
|
|
233
|
-
src: "
|
|
251
|
+
src: "rwsdk_asset:/src/non-existent.js",
|
|
234
252
|
type: "module",
|
|
235
253
|
nonce: requestInfo.rw.nonce
|
|
236
254
|
})
|
|
@@ -244,13 +262,14 @@ nonce: requestInfo.rw.nonce
|
|
|
244
262
|
type: "module"
|
|
245
263
|
})
|
|
246
264
|
`;
|
|
247
|
-
const
|
|
265
|
+
const clientEntryPoints = new Set();
|
|
266
|
+
const result = await transformJsxScriptTagsCode(code, clientEntryPoints, mockManifest, "/project/root/dir");
|
|
248
267
|
const expected = `import { requestInfo } from "rwsdk/worker";
|
|
249
268
|
|
|
250
269
|
(
|
|
251
270
|
(requestInfo.rw.scriptsToBeLoaded.add("/src/client.tsx")),
|
|
252
271
|
jsx("script", {
|
|
253
|
-
src: "/
|
|
272
|
+
src: "rwsdk_asset:/src/client.tsx",
|
|
254
273
|
type: "module",
|
|
255
274
|
nonce: requestInfo.rw.nonce
|
|
256
275
|
})
|
|
@@ -264,7 +283,8 @@ nonce: requestInfo.rw.nonce
|
|
|
264
283
|
children: "console.log('hello world')"
|
|
265
284
|
})
|
|
266
285
|
`;
|
|
267
|
-
const
|
|
286
|
+
const clientEntryPoints = new Set();
|
|
287
|
+
const result = await transformJsxScriptTagsCode(code, clientEntryPoints, mockManifest, "/project/root/dir");
|
|
268
288
|
expect(result?.code).toEqual(`import { requestInfo } from "rwsdk/worker";
|
|
269
289
|
|
|
270
290
|
jsx("script", {
|
|
@@ -281,7 +301,8 @@ nonce: requestInfo.rw.nonce
|
|
|
281
301
|
dangerouslySetInnerHTML: { __html: "console.log('hello world')" }
|
|
282
302
|
})
|
|
283
303
|
`;
|
|
284
|
-
const
|
|
304
|
+
const clientEntryPoints = new Set();
|
|
305
|
+
const result = await transformJsxScriptTagsCode(code, clientEntryPoints, mockManifest, "/project/root/dir");
|
|
285
306
|
expect(result?.code).toEqual(undefined);
|
|
286
307
|
});
|
|
287
308
|
it("does not add nonce to script tags that already have nonce", async () => {
|
|
@@ -292,7 +313,8 @@ nonce: requestInfo.rw.nonce
|
|
|
292
313
|
nonce: "existing-nonce"
|
|
293
314
|
})
|
|
294
315
|
`;
|
|
295
|
-
const
|
|
316
|
+
const clientEntryPoints = new Set();
|
|
317
|
+
const result = await transformJsxScriptTagsCode(code, clientEntryPoints, mockManifest, "/project/root/dir");
|
|
296
318
|
expect(result?.code).toEqual(undefined);
|
|
297
319
|
});
|
|
298
320
|
it("uses existing requestInfo import if already present", async () => {
|
|
@@ -305,7 +327,8 @@ nonce: requestInfo.rw.nonce
|
|
|
305
327
|
children: "console.log('hello world')"
|
|
306
328
|
})
|
|
307
329
|
`;
|
|
308
|
-
const
|
|
330
|
+
const clientEntryPoints = new Set();
|
|
331
|
+
const result = await transformJsxScriptTagsCode(code, clientEntryPoints, mockManifest, "/project/root/dir");
|
|
309
332
|
expect(result?.code).toEqual(`
|
|
310
333
|
import { foo } from 'bar';
|
|
311
334
|
import { requestInfo, someOtherThing } from "rwsdk/worker";
|
|
@@ -331,7 +354,8 @@ nonce: requestInfo.rw.nonce
|
|
|
331
354
|
children: "console.log('hello world')"
|
|
332
355
|
})
|
|
333
356
|
`;
|
|
334
|
-
const
|
|
357
|
+
const clientEntryPoints = new Set();
|
|
358
|
+
const result = await transformJsxScriptTagsCode(code, clientEntryPoints, mockManifest, "/project/root/dir");
|
|
335
359
|
expect(result?.code).toEqual(`
|
|
336
360
|
import { foo } from 'bar';
|
|
337
361
|
import { someOtherThing, requestInfo } from "rwsdk/worker";
|
|
@@ -351,13 +375,14 @@ nonce: requestInfo.rw.nonce
|
|
|
351
375
|
})
|
|
352
376
|
`;
|
|
353
377
|
// Call without providing manifest (simulating dev mode)
|
|
354
|
-
const
|
|
378
|
+
const clientEntryPoints = new Set();
|
|
379
|
+
const result = await transformJsxScriptTagsCode(code, clientEntryPoints, mockManifest, "/project/root/dir");
|
|
355
380
|
const expected = `import { requestInfo } from "rwsdk/worker";
|
|
356
381
|
|
|
357
382
|
(
|
|
358
383
|
(requestInfo.rw.scriptsToBeLoaded.add("/src/client.tsx")),
|
|
359
384
|
jsx("script", {
|
|
360
|
-
src: "
|
|
385
|
+
src: "rwsdk_asset:/src/client.tsx",
|
|
361
386
|
type: "module",
|
|
362
387
|
nonce: requestInfo.rw.nonce
|
|
363
388
|
})
|
|
@@ -433,7 +458,7 @@ export const Document = ({
|
|
|
433
458
|
lineNumber: 22,
|
|
434
459
|
columnNumber: 4
|
|
435
460
|
}, this),
|
|
436
|
-
/* @__PURE__ */ jsxDEV("link", { rel: "modulepreload", href: "
|
|
461
|
+
/* @__PURE__ */ jsxDEV("link", { rel: "modulepreload", href: "rwsdk_asset:/src/client.tsx" }, void 0, false, {
|
|
437
462
|
fileName: "/Users/justin/rw/blotter/rwsdk-guestbook/src/app/document/Document.tsx",
|
|
438
463
|
lineNumber: 23,
|
|
439
464
|
columnNumber: 4
|
|
@@ -470,7 +495,8 @@ export const Document = ({
|
|
|
470
495
|
columnNumber: 2
|
|
471
496
|
}, this);
|
|
472
497
|
`;
|
|
473
|
-
const
|
|
498
|
+
const clientEntryPoints = new Set();
|
|
499
|
+
const result = await transformJsxScriptTagsCode(code, clientEntryPoints, mockManifest, "/project/root/dir");
|
|
474
500
|
// For this complex test, we'll just verify the key transformations
|
|
475
501
|
const expected = `
|
|
476
502
|
import { jsxDEV } from "react/jsx-dev-runtime";
|
|
@@ -534,7 +560,7 @@ children
|
|
|
534
560
|
),
|
|
535
561
|
(
|
|
536
562
|
(requestInfo.rw.scriptsToBeLoaded.add("/theme-script.js")),
|
|
537
|
-
/* @__PURE__ */ jsxDEV("script", { src: "
|
|
563
|
+
/* @__PURE__ */ jsxDEV("script", { src: "rwsdk_asset:/theme-script.js",
|
|
538
564
|
nonce: requestInfo.rw.nonce
|
|
539
565
|
}, void 0, false, {
|
|
540
566
|
fileName: "/Users/justin/rw/blotter/rwsdk-guestbook/src/app/document/Document.tsx",
|
|
@@ -547,7 +573,7 @@ children
|
|
|
547
573
|
lineNumber: 22,
|
|
548
574
|
columnNumber: 4
|
|
549
575
|
}, this),
|
|
550
|
-
/* @__PURE__ */ jsxDEV("link", { rel: "modulepreload", href: "/
|
|
576
|
+
/* @__PURE__ */ jsxDEV("link", { rel: "modulepreload", href: "rwsdk_asset:/src/client.tsx" }, void 0, false, {
|
|
551
577
|
fileName: "/Users/justin/rw/blotter/rwsdk-guestbook/src/app/document/Document.tsx",
|
|
552
578
|
lineNumber: 23,
|
|
553
579
|
columnNumber: 4
|
|
@@ -570,7 +596,7 @@ children
|
|
|
570
596
|
}, this),
|
|
571
597
|
(
|
|
572
598
|
(requestInfo.rw.scriptsToBeLoaded.add("/src/client.tsx")),
|
|
573
|
-
/* @__PURE__ */ jsxDEV("script", { children: "import(\\"/
|
|
599
|
+
/* @__PURE__ */ jsxDEV("script", { children: "import(\\"rwsdk_asset:/src/client.tsx\\")",
|
|
574
600
|
nonce: requestInfo.rw.nonce
|
|
575
601
|
}, void 0, false, {
|
|
576
602
|
fileName: "/Users/justin/rw/blotter/rwsdk-guestbook/src/app/document/Document.tsx",
|
|
@@ -12,5 +12,5 @@ type ExportInfoCompat = {
|
|
|
12
12
|
};
|
|
13
13
|
export declare const findExportedFunctions: (code: string, normalizedId?: string) => Set<string>;
|
|
14
14
|
export declare const findExportInfo: (code: string, normalizedId?: string) => ExportInfoCompat;
|
|
15
|
-
export declare const transformServerFunctions: (code: string, normalizedId: string, environment: "client" | "worker" | "ssr", serverFiles?: Set<string
|
|
15
|
+
export declare const transformServerFunctions: (code: string, normalizedId: string, environment: "client" | "worker" | "ssr", serverFiles?: Set<string>) => TransformResult | undefined;
|
|
16
16
|
export type { TransformResult };
|
|
@@ -84,19 +84,15 @@ function hasDefaultExport(code, normalizedId) {
|
|
|
84
84
|
}
|
|
85
85
|
return false;
|
|
86
86
|
}
|
|
87
|
-
export const transformServerFunctions = (code, normalizedId, environment, serverFiles
|
|
88
|
-
process.env.VERBOSE &&
|
|
89
|
-
log("Transform server functions called for normalizedId=%s, environment=%s", normalizedId, environment);
|
|
87
|
+
export const transformServerFunctions = (code, normalizedId, environment, serverFiles) => {
|
|
90
88
|
if (!hasDirective(code, "use server")) {
|
|
91
|
-
log("Skipping: no 'use server' directive in id=%s", normalizedId);
|
|
92
|
-
process.env.VERBOSE &&
|
|
93
|
-
log(":VERBOSE: Returning code unchanged for id=%s:\n%s", normalizedId, code);
|
|
94
89
|
return;
|
|
95
90
|
}
|
|
96
|
-
|
|
97
|
-
|
|
91
|
+
process.env.VERBOSE &&
|
|
92
|
+
log("Processing 'use server' module: normalizedId=%s, environment=%s", normalizedId, environment);
|
|
98
93
|
if (environment === "ssr" || environment === "client") {
|
|
99
|
-
|
|
94
|
+
process.env.VERBOSE &&
|
|
95
|
+
log(`Transforming for ${environment} environment: normalizedId=%s`, normalizedId);
|
|
100
96
|
const exportInfo = findExportInfo(code, normalizedId);
|
|
101
97
|
const allExports = new Set([
|
|
102
98
|
...exportInfo.localFunctions,
|
|
@@ -126,7 +122,8 @@ export const transformServerFunctions = (code, normalizedId, environment, server
|
|
|
126
122
|
s.append(`\nexport default createServerReference(${JSON.stringify(normalizedId)}, "default");\n`);
|
|
127
123
|
log(`Added ${environment} server reference for default export in normalizedId=%s`, normalizedId);
|
|
128
124
|
}
|
|
129
|
-
|
|
125
|
+
process.env.VERBOSE &&
|
|
126
|
+
log(`${environment} transformation complete for normalizedId=%s`, normalizedId);
|
|
130
127
|
return {
|
|
131
128
|
code: s.toString(),
|
|
132
129
|
map: s.generateMap({
|
|
@@ -137,7 +134,8 @@ export const transformServerFunctions = (code, normalizedId, environment, server
|
|
|
137
134
|
};
|
|
138
135
|
}
|
|
139
136
|
else if (environment === "worker") {
|
|
140
|
-
|
|
137
|
+
process.env.VERBOSE &&
|
|
138
|
+
log("Transforming for worker environment: normalizedId=%s", normalizedId);
|
|
141
139
|
const exportInfo = findExportInfo(code, normalizedId);
|
|
142
140
|
const s = new MagicString(code);
|
|
143
141
|
// Remove "use server" directive first
|
|
@@ -281,7 +279,8 @@ export const transformServerFunctions = (code, normalizedId, environment, server
|
|
|
281
279
|
if (registrationCalls.length > 0) {
|
|
282
280
|
s.append(registrationCalls.join("\n") + "\n");
|
|
283
281
|
}
|
|
284
|
-
|
|
282
|
+
process.env.VERBOSE &&
|
|
283
|
+
log("Worker transformation complete for normalizedId=%s", normalizedId);
|
|
285
284
|
return {
|
|
286
285
|
code: s.toString(),
|
|
287
286
|
map: s.generateMap({
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "rwsdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "Build fast, server-driven webapps on Cloudflare with SSR, RSC, and realtime",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -45,6 +45,12 @@
|
|
|
45
45
|
"types": "./dist/runtime/ssrBridge.d.ts",
|
|
46
46
|
"default": "./dist/runtime/ssrBridge.js"
|
|
47
47
|
},
|
|
48
|
+
"./__client_barrel": {
|
|
49
|
+
"default": "./dist/__intermediate_builds/rwsdk-client-barrel.js"
|
|
50
|
+
},
|
|
51
|
+
"./__server_barrel": {
|
|
52
|
+
"default": "./dist/__intermediate_builds/rwsdk-server-barrel.js"
|
|
53
|
+
},
|
|
48
54
|
"./router": {
|
|
49
55
|
"types": "./dist/runtime/entries/router.d.ts",
|
|
50
56
|
"default": "./dist/runtime/entries/router.js"
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
export interface ClientNavigationOptions {
|
|
2
|
-
onNavigate?: () => void;
|
|
3
|
-
scrollToTop?: boolean;
|
|
4
|
-
scrollBehavior?: "auto" | "smooth" | "instant";
|
|
5
|
-
}
|
|
6
|
-
export declare function validateClickEvent(event: MouseEvent, target: HTMLElement): boolean;
|
|
7
|
-
export declare function initClientNavigation(opts?: ClientNavigationOptions): {
|
|
8
|
-
handleResponse: (response: Response) => boolean;
|
|
9
|
-
};
|
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
function saveScrollPosition(x, y) {
|
|
2
|
-
window.history.replaceState({
|
|
3
|
-
...window.history.state,
|
|
4
|
-
scrollX: x,
|
|
5
|
-
scrollY: y,
|
|
6
|
-
}, "", window.location.href);
|
|
7
|
-
}
|
|
8
|
-
export function validateClickEvent(event, target) {
|
|
9
|
-
// should this only work for left click?
|
|
10
|
-
if (event.button !== 0) {
|
|
11
|
-
return false;
|
|
12
|
-
}
|
|
13
|
-
if (event.ctrlKey || event.metaKey || event.shiftKey || event.altKey) {
|
|
14
|
-
return false;
|
|
15
|
-
}
|
|
16
|
-
const link = target.closest("a");
|
|
17
|
-
if (!link) {
|
|
18
|
-
return false;
|
|
19
|
-
}
|
|
20
|
-
const href = link.getAttribute("href");
|
|
21
|
-
if (!href) {
|
|
22
|
-
return false;
|
|
23
|
-
}
|
|
24
|
-
if (href.includes("#")) {
|
|
25
|
-
return false;
|
|
26
|
-
}
|
|
27
|
-
// Skip if target="_blank" or similar
|
|
28
|
-
if (link.target && link.target !== "_self") {
|
|
29
|
-
return false;
|
|
30
|
-
}
|
|
31
|
-
if (href.startsWith("http")) {
|
|
32
|
-
return false;
|
|
33
|
-
}
|
|
34
|
-
// Skip if download attribute
|
|
35
|
-
if (link.hasAttribute("download")) {
|
|
36
|
-
return false;
|
|
37
|
-
}
|
|
38
|
-
return true;
|
|
39
|
-
}
|
|
40
|
-
export function initClientNavigation(opts = {}) {
|
|
41
|
-
const options = {
|
|
42
|
-
onNavigate: async function onNavigate() {
|
|
43
|
-
// @ts-expect-error
|
|
44
|
-
await globalThis.__rsc_callServer();
|
|
45
|
-
},
|
|
46
|
-
scrollToTop: true,
|
|
47
|
-
scrollBehavior: "instant",
|
|
48
|
-
...opts,
|
|
49
|
-
};
|
|
50
|
-
history.scrollRestoration = "auto";
|
|
51
|
-
document.addEventListener("click", async function handleClickEvent(event) {
|
|
52
|
-
// Prevent default navigation
|
|
53
|
-
if (!validateClickEvent(event, event.target)) {
|
|
54
|
-
return;
|
|
55
|
-
}
|
|
56
|
-
event.preventDefault();
|
|
57
|
-
const el = event.target;
|
|
58
|
-
const a = el.closest("a");
|
|
59
|
-
const href = a?.getAttribute("href");
|
|
60
|
-
saveScrollPosition(window.scrollX, window.scrollY);
|
|
61
|
-
window.history.pushState({ path: href }, "", window.location.origin + href);
|
|
62
|
-
await options.onNavigate();
|
|
63
|
-
if (options.scrollToTop && history.scrollRestoration === "auto") {
|
|
64
|
-
window.scrollTo({
|
|
65
|
-
top: 0,
|
|
66
|
-
left: 0,
|
|
67
|
-
behavior: options.scrollBehavior,
|
|
68
|
-
});
|
|
69
|
-
saveScrollPosition(0, 0);
|
|
70
|
-
}
|
|
71
|
-
history.scrollRestoration = "auto";
|
|
72
|
-
}, true);
|
|
73
|
-
window.addEventListener("popstate", async function handlePopState() {
|
|
74
|
-
saveScrollPosition(window.scrollX, window.scrollY);
|
|
75
|
-
await options.onNavigate();
|
|
76
|
-
});
|
|
77
|
-
// Return a handleResponse function for use with initClient
|
|
78
|
-
return {
|
|
79
|
-
handleResponse: function handleResponse(response) {
|
|
80
|
-
if (!response.ok) {
|
|
81
|
-
// Redirect to the current page (window.location) to show the error
|
|
82
|
-
window.location.href = window.location.href;
|
|
83
|
-
return false;
|
|
84
|
-
}
|
|
85
|
-
return true;
|
|
86
|
-
},
|
|
87
|
-
};
|
|
88
|
-
}
|