rwsdk 0.2.0-alpha.9 → 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.
Files changed (93) hide show
  1. package/dist/lib/constants.d.mts +6 -1
  2. package/dist/lib/constants.mjs +6 -1
  3. package/dist/lib/smokeTests/browser.mjs +5 -21
  4. package/dist/lib/smokeTests/codeUpdates.d.mts +1 -1
  5. package/dist/lib/smokeTests/codeUpdates.mjs +41 -5
  6. package/dist/lib/smokeTests/development.d.mts +1 -1
  7. package/dist/lib/smokeTests/development.mjs +4 -10
  8. package/dist/lib/smokeTests/release.d.mts +1 -1
  9. package/dist/lib/smokeTests/release.mjs +4 -9
  10. package/dist/lib/smokeTests/runSmokeTests.mjs +2 -2
  11. package/dist/lib/smokeTests/templates/SmokeTest.template.js +3 -2
  12. package/dist/lib/testUtils/stubEnvVars.d.mts +2 -0
  13. package/dist/lib/testUtils/stubEnvVars.mjs +11 -0
  14. package/dist/runtime/client/client.d.ts +10 -0
  15. package/dist/runtime/{client.js → client/client.js} +13 -10
  16. package/dist/runtime/{clientNavigation.test.js → client/navigation.test.js} +1 -1
  17. package/dist/runtime/client/setWebpackRequire.d.ts +1 -0
  18. package/dist/runtime/client/setWebpackRequire.js +2 -0
  19. package/dist/runtime/{client.d.ts → client/types.d.ts} +4 -10
  20. package/dist/runtime/client/types.js +1 -0
  21. package/dist/runtime/entries/client.d.ts +2 -2
  22. package/dist/runtime/entries/client.js +2 -2
  23. package/dist/runtime/imports/client.d.ts +3 -3
  24. package/dist/runtime/imports/client.js +11 -15
  25. package/dist/runtime/imports/ssr.d.ts +3 -3
  26. package/dist/runtime/imports/ssr.js +3 -3
  27. package/dist/runtime/imports/worker.d.ts +3 -3
  28. package/dist/runtime/imports/worker.js +5 -4
  29. package/dist/runtime/lib/manifest.d.ts +11 -2
  30. package/dist/runtime/lib/manifest.js +1 -1
  31. package/dist/runtime/lib/memoizeOnId.d.ts +1 -0
  32. package/dist/runtime/lib/memoizeOnId.js +11 -0
  33. package/dist/runtime/lib/realtime/client.d.ts +1 -1
  34. package/dist/runtime/lib/realtime/client.js +1 -1
  35. package/dist/runtime/lib/router.d.ts +3 -3
  36. package/dist/runtime/lib/router.js +77 -33
  37. package/dist/runtime/register/ssr.d.ts +1 -1
  38. package/dist/runtime/register/ssr.js +4 -3
  39. package/dist/runtime/render/preloads.d.ts +6 -0
  40. package/dist/runtime/render/preloads.js +40 -0
  41. package/dist/runtime/render/renderRscThenableToHtmlStream.js +2 -1
  42. package/dist/runtime/render/stylesheets.js +1 -1
  43. package/dist/runtime/requestInfo/types.d.ts +3 -1
  44. package/dist/runtime/requestInfo/worker.js +9 -1
  45. package/dist/runtime/worker.d.ts +0 -3
  46. package/dist/runtime/worker.js +2 -11
  47. package/dist/scripts/debug-sync.mjs +142 -39
  48. package/dist/scripts/smoke-test.mjs +0 -10
  49. package/dist/scripts/worker-run.mjs +8 -3
  50. package/dist/vite/buildApp.d.mts +15 -0
  51. package/dist/vite/buildApp.mjs +53 -0
  52. package/dist/vite/configPlugin.d.mts +4 -2
  53. package/dist/vite/configPlugin.mjs +69 -62
  54. package/dist/vite/createDirectiveLookupPlugin.d.mts +0 -6
  55. package/dist/vite/createDirectiveLookupPlugin.mjs +61 -145
  56. package/dist/vite/directiveModulesDevPlugin.d.mts +8 -0
  57. package/dist/vite/directiveModulesDevPlugin.mjs +62 -0
  58. package/dist/vite/directivesFilteringPlugin.d.mts +6 -0
  59. package/dist/vite/directivesFilteringPlugin.mjs +31 -0
  60. package/dist/vite/directivesPlugin.mjs +28 -42
  61. package/dist/vite/getViteEsbuild.d.mts +1 -0
  62. package/dist/vite/getViteEsbuild.mjs +12 -0
  63. package/dist/vite/hasOwnReactVitePlugin.d.mts +3 -0
  64. package/dist/vite/hasOwnReactVitePlugin.mjs +14 -0
  65. package/dist/vite/injectVitePreamblePlugin.d.mts +3 -2
  66. package/dist/vite/injectVitePreamblePlugin.mjs +4 -2
  67. package/dist/vite/linkerPlugin.d.mts +4 -0
  68. package/dist/vite/linkerPlugin.mjs +41 -0
  69. package/dist/vite/manifestPlugin.d.mts +2 -2
  70. package/dist/vite/manifestPlugin.mjs +12 -37
  71. package/dist/vite/miniflareHMRPlugin.mjs +17 -2
  72. package/dist/vite/moveStaticAssetsPlugin.mjs +2 -1
  73. package/dist/vite/prismaPlugin.mjs +1 -1
  74. package/dist/vite/reactConditionsResolverPlugin.d.mts +3 -4
  75. package/dist/vite/reactConditionsResolverPlugin.mjs +74 -56
  76. package/dist/vite/redwoodPlugin.d.mts +1 -1
  77. package/dist/vite/redwoodPlugin.mjs +36 -12
  78. package/dist/vite/runDirectivesScan.d.mts +7 -0
  79. package/dist/vite/runDirectivesScan.mjs +152 -0
  80. package/dist/vite/ssrBridgePlugin.mjs +13 -14
  81. package/dist/vite/transformClientComponents.d.mts +0 -1
  82. package/dist/vite/transformClientComponents.mjs +1 -9
  83. package/dist/vite/transformJsxScriptTagsPlugin.d.mts +4 -3
  84. package/dist/vite/transformJsxScriptTagsPlugin.mjs +151 -158
  85. package/dist/vite/transformJsxScriptTagsPlugin.test.mjs +393 -136
  86. package/dist/vite/transformServerFunctions.d.mts +1 -1
  87. package/dist/vite/transformServerFunctions.mjs +11 -12
  88. package/package.json +28 -4
  89. /package/dist/runtime/{imports → client}/ClientOnly.d.ts +0 -0
  90. /package/dist/runtime/{imports → client}/ClientOnly.js +0 -0
  91. /package/dist/runtime/{clientNavigation.d.ts → client/navigation.d.ts} +0 -0
  92. /package/dist/runtime/{clientNavigation.js → client/navigation.js} +0 -0
  93. /package/dist/runtime/{clientNavigation.test.d.ts → client/navigation.test.d.ts} +0 -0
@@ -1,5 +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
+ import jsBeautify from "js-beautify";
4
+ import stubEnvVars from "../lib/testUtils/stubEnvVars.mjs";
5
+ // Helper function to normalize code formatting for test comparisons
6
+ function normalizeCode(code) {
7
+ return jsBeautify(code, { indent_size: 2 });
8
+ }
9
+ stubEnvVars();
10
+ beforeEach(() => {
11
+ process.env.RWSDK_BUILD_PASS = "worker";
12
+ });
3
13
  describe("transformJsxScriptTagsCode", () => {
4
14
  const mockManifest = {
5
15
  "src/client.tsx": { file: "assets/client-a1b2c3d4.js" },
@@ -13,18 +23,19 @@ describe("transformJsxScriptTagsCode", () => {
13
23
  type: "module"
14
24
  })
15
25
  `;
16
- const result = await transformJsxScriptTagsCode(code, mockManifest);
17
- expect(result?.code).toEqual(`import { requestInfo } from "rwsdk/worker";
26
+ const clientEntryPoints = new Set();
27
+ const result = await transformJsxScriptTagsCode(code, clientEntryPoints, mockManifest, "/Users/justin/rw/forks/workers-sdk/sdk/sdk");
28
+ const expected = `import { requestInfo } from "rwsdk/worker";
18
29
 
19
- (
20
- (requestInfo.rw.scriptsToBeLoaded.add("/src/client.tsx")),
21
- jsx("script", {
22
- src: "/assets/client-a1b2c3d4.js",
23
- type: "module",
24
- nonce: requestInfo.rw.nonce
25
- })
26
- )
27
- `);
30
+ (
31
+ (requestInfo.rw.scriptsToBeLoaded.add("/src/client.tsx")),
32
+ jsx("script", {
33
+ src: "rwsdk_asset:/src/client.tsx",
34
+ type: "module",
35
+ nonce: requestInfo.rw.nonce
36
+ })
37
+ )`;
38
+ expect(normalizeCode(result?.code || "")).toEqual(normalizeCode(expected));
28
39
  });
29
40
  it("transforms inline scripts with dynamic imports", async () => {
30
41
  const code = `
@@ -33,33 +44,35 @@ describe("transformJsxScriptTagsCode", () => {
33
44
  children: "import('/src/client.tsx').then(module => { console.log(module); })"
34
45
  })
35
46
  `;
36
- const result = await transformJsxScriptTagsCode(code, mockManifest);
37
- expect(result?.code).toEqual(`import { requestInfo } from "rwsdk/worker";
47
+ const clientEntryPoints = new Set();
48
+ const result = await transformJsxScriptTagsCode(code, clientEntryPoints, mockManifest, "/project/root/dir");
49
+ const expected = `import { requestInfo } from "rwsdk/worker";
38
50
 
39
- (
40
- (requestInfo.rw.scriptsToBeLoaded.add("/src/client.tsx")),
41
- jsx("script", {
42
- type: "module",
43
- children: "import('/assets/client-a1b2c3d4.js').then(module => { console.log(module); })",
44
- nonce: requestInfo.rw.nonce
45
- })
46
- )
47
- `);
51
+ (
52
+ (requestInfo.rw.scriptsToBeLoaded.add("/src/client.tsx")),
53
+ jsx("script", {
54
+ type: "module",
55
+ children: "import('rwsdk_asset:/src/client.tsx').then(module => { console.log(module); })",
56
+ nonce: requestInfo.rw.nonce
57
+ })
58
+ )`;
59
+ expect(normalizeCode(result?.code || "")).toEqual(normalizeCode(expected));
48
60
  });
49
61
  it("transforms inline scripts with type=module", async () => {
50
62
  const code = `
51
63
  jsx("script", { type: "module", children: "import('/src/client.tsx')" })
52
64
  `;
53
- const result = await transformJsxScriptTagsCode(code, mockManifest);
54
- expect(result?.code).toEqual(`import { requestInfo } from "rwsdk/worker";
65
+ const clientEntryPoints = new Set();
66
+ const result = await transformJsxScriptTagsCode(code, clientEntryPoints, mockManifest, "/project/root/dir");
67
+ const expected = `import { requestInfo } from "rwsdk/worker";
55
68
 
56
- (
57
- (requestInfo.rw.scriptsToBeLoaded.add("/src/client.tsx")),
58
- jsx("script", { type: "module", children: "import('/assets/client-a1b2c3d4.js')",
59
- nonce: requestInfo.rw.nonce
60
- })
61
- )
62
- `);
69
+ (
70
+ (requestInfo.rw.scriptsToBeLoaded.add("/src/client.tsx")),
71
+ jsx("script", { type: "module", children: "import('rwsdk_asset:/src/client.tsx')",
72
+ nonce: requestInfo.rw.nonce
73
+ })
74
+ )`;
75
+ expect(normalizeCode(result?.code || "")).toEqual(normalizeCode(expected));
63
76
  });
64
77
  it("transforms inline scripts with multiline content", async () => {
65
78
  const code = `
@@ -75,52 +88,54 @@ describe("transformJsxScriptTagsCode", () => {
75
88
  \`
76
89
  })
77
90
  `;
78
- const result = await transformJsxScriptTagsCode(code, mockManifest);
79
- expect(result?.code).toEqual(`import { requestInfo } from "rwsdk/worker";
91
+ const clientEntryPoints = new Set();
92
+ const result = await transformJsxScriptTagsCode(code, clientEntryPoints, mockManifest, "/project/root/dir");
93
+ const expected = `import { requestInfo } from "rwsdk/worker";
80
94
 
81
- (
82
- (requestInfo.rw.scriptsToBeLoaded.add("/src/entry.js")),
83
- jsx("script", {
84
- type: "module",
85
- children: \`
95
+ (
96
+ (requestInfo.rw.scriptsToBeLoaded.add("/src/entry.js")),
97
+ jsx("script", {
98
+ type: "module",
99
+ children: \`
86
100
  // Some comments here
87
101
  const init = async () => {
88
- await import('/assets/entry-e5f6g7h8.js');
102
+ await import('rwsdk_asset:/src/entry.js');
89
103
  console.log('initialized');
90
104
  };
91
105
  init();
92
106
  \`,
93
- nonce: requestInfo.rw.nonce
94
- })
95
- )
96
- `);
107
+ nonce: requestInfo.rw.nonce
108
+ })
109
+ )`;
110
+ expect(normalizeCode(result?.code || "")).toEqual(normalizeCode(expected));
97
111
  });
98
112
  it("transforms multiple imports in the same inline script", async () => {
99
113
  const code = `
100
114
  jsx("script", {
101
115
  type: "module",
102
116
  children: \`
103
- import('/src/client.tsx');
104
- import('/src/entry.js');
105
- \`
117
+ import('/src/client.tsx');
118
+ import('/src/entry.js');
119
+ \`
106
120
  })
107
121
  `;
108
- const result = await transformJsxScriptTagsCode(code, mockManifest);
109
- expect(result?.code).toEqual(`import { requestInfo } from "rwsdk/worker";
122
+ const clientEntryPoints = new Set();
123
+ const result = await transformJsxScriptTagsCode(code, clientEntryPoints, mockManifest, "/project/root/dir");
124
+ const expected = `import { requestInfo } from "rwsdk/worker";
110
125
 
111
- (
112
- (requestInfo.rw.scriptsToBeLoaded.add("/src/client.tsx")),
126
+ (
127
+ (requestInfo.rw.scriptsToBeLoaded.add("/src/client.tsx")),
113
128
  (requestInfo.rw.scriptsToBeLoaded.add("/src/entry.js")),
114
- jsx("script", {
115
- type: "module",
116
- children: \`
117
- import('/assets/client-a1b2c3d4.js');
118
- import('/assets/entry-e5f6g7h8.js');
119
- \`,
120
- nonce: requestInfo.rw.nonce
121
- })
122
- )
123
- `);
129
+ jsx("script", {
130
+ type: "module",
131
+ children: \`
132
+ import('rwsdk_asset:/src/client.tsx');
133
+ import('rwsdk_asset:/src/entry.js');
134
+ \`,
135
+ nonce: requestInfo.rw.nonce
136
+ })
137
+ )`;
138
+ expect(normalizeCode(result?.code || "")).toEqual(normalizeCode(expected));
124
139
  });
125
140
  it("transforms link href attributes with preload rel", async () => {
126
141
  const code = `
@@ -130,14 +145,17 @@ describe("transformJsxScriptTagsCode", () => {
130
145
  as: "script"
131
146
  })
132
147
  `;
133
- const result = await transformJsxScriptTagsCode(code, mockManifest);
134
- expect(result?.code).toEqual(`
148
+ const clientEntryPoints = new Set();
149
+ const result = await transformJsxScriptTagsCode(code, clientEntryPoints, mockManifest, "/project/root/dir");
150
+ const expected = `
135
151
  jsx("link", {
136
152
  rel: "preload",
137
- href: "/assets/client-a1b2c3d4.js",
153
+ href: "rwsdk_asset:/src/client.tsx",
138
154
  as: "script"
139
155
  })
140
- `);
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
141
159
  });
142
160
  it("transforms link href attributes with modulepreload rel", async () => {
143
161
  const code = `
@@ -146,13 +164,15 @@ describe("transformJsxScriptTagsCode", () => {
146
164
  rel: "modulepreload"
147
165
  })
148
166
  `;
149
- const result = await transformJsxScriptTagsCode(code, mockManifest);
150
- expect(result?.code).toEqual(`
167
+ const clientEntryPoints = new Set();
168
+ const result = await transformJsxScriptTagsCode(code, clientEntryPoints, mockManifest, "/project/root/dir");
169
+ const expected = `
151
170
  jsx("link", {
152
- href: "/assets/client-a1b2c3d4.js",
171
+ href: "rwsdk_asset:/src/client.tsx",
153
172
  rel: "modulepreload"
154
173
  })
155
- `);
174
+ `;
175
+ expect(normalizeCode(result?.code || "")).toEqual(normalizeCode(expected));
156
176
  });
157
177
  it("transforms real-world Document component example", async () => {
158
178
  const code = `
@@ -164,7 +184,7 @@ describe("transformJsxScriptTagsCode", () => {
164
184
  jsx("meta", { charSet: "utf-8" }),
165
185
  jsx("meta", { name: "viewport", content: "width=device-width, initial-scale=1" }),
166
186
  jsx("title", { children: "@redwoodjs/starter-standard" }),
167
- jsx("link", { rel: "modulepreload", href: "/src/client.tsx", as: "script" })
187
+ jsx("link", { rel: "modulepreload", href: "rwsdk_asset:/src/client.tsx", as: "script" })
168
188
  ]
169
189
  }),
170
190
  jsx("body", {
@@ -176,40 +196,42 @@ describe("transformJsxScriptTagsCode", () => {
176
196
  ]
177
197
  })
178
198
  `;
179
- const result = await transformJsxScriptTagsCode(code, mockManifest);
180
- expect(result?.code).toEqual(`import { requestInfo } from "rwsdk/worker";
199
+ const clientEntryPoints = new Set();
200
+ const result = await transformJsxScriptTagsCode(code, clientEntryPoints, mockManifest, "/project/root/dir");
201
+ const expected = `import { requestInfo } from "rwsdk/worker";
181
202
 
182
- jsx("html", {
183
- lang: "en",
184
- children: [
185
- jsx("head", {
186
- children: [
187
- jsx("meta", { charSet: "utf-8" }),
188
- jsx("meta", { name: "viewport", content: "width=device-width, initial-scale=1" }),
189
- jsx("title", { children: "@redwoodjs/starter-standard" }),
190
- jsx("link", { rel: "modulepreload", href: "/assets/client-a1b2c3d4.js", as: "script" })
191
- ]
192
- }),
193
- jsx("body", {
194
- children: [
195
- jsx("div", { id: "root", children: props.children }),
196
- (
197
- (requestInfo.rw.scriptsToBeLoaded.add("/src/client.tsx")),
198
- jsx("script", { children: "import(\\"\/assets\/client-a1b2c3d4.js\\")",
199
- nonce: requestInfo.rw.nonce
200
- })
201
- )
202
- ]
203
- })
204
- ]
205
- })
206
- `);
203
+ jsx("html", {
204
+ lang: "en",
205
+ children: [
206
+ jsx("head", {
207
+ children: [
208
+ jsx("meta", { charSet: "utf-8" }),
209
+ jsx("meta", { name: "viewport", content: "width=device-width, initial-scale=1" }),
210
+ jsx("title", { children: "@redwoodjs/starter-standard" }),
211
+ jsx("link", { rel: "modulepreload", href: "rwsdk_asset:/src/client.tsx", as: "script" })
212
+ ]
213
+ }),
214
+ jsx("body", {
215
+ children: [
216
+ jsx("div", { id: "root", children: props.children }),
217
+ (
218
+ (requestInfo.rw.scriptsToBeLoaded.add("/src/client.tsx")),
219
+ jsx("script", { children: "import(\\"rwsdk_asset:/src/client.tsx\\")",
220
+ nonce: requestInfo.rw.nonce
221
+ })
222
+ )
223
+ ]
224
+ })
225
+ ]
226
+ })`;
227
+ expect(normalizeCode(result?.code || "")).toEqual(normalizeCode(expected));
207
228
  });
208
229
  it("returns null when no transformations are needed", async () => {
209
230
  const code = `
210
231
  jsx("div", { children: "No scripts or links here" })
211
232
  `;
212
- const result = await transformJsxScriptTagsCode(code, mockManifest);
233
+ const clientEntryPoints = new Set();
234
+ const result = await transformJsxScriptTagsCode(code, clientEntryPoints, mockManifest, "/project/root/dir");
213
235
  expect(result).toBeUndefined();
214
236
  });
215
237
  it("handles paths not found in manifest", async () => {
@@ -219,18 +241,19 @@ describe("transformJsxScriptTagsCode", () => {
219
241
  type: "module"
220
242
  })
221
243
  `;
222
- const result = await transformJsxScriptTagsCode(code, mockManifest);
223
- expect(result?.code).toEqual(`import { requestInfo } from "rwsdk/worker";
244
+ const clientEntryPoints = new Set();
245
+ const result = await transformJsxScriptTagsCode(code, clientEntryPoints, mockManifest, "/project/root/dir");
246
+ const expected = `import { requestInfo } from "rwsdk/worker";
224
247
 
225
- (
226
- (requestInfo.rw.scriptsToBeLoaded.add("/src/non-existent.js")),
227
- jsx("script", {
228
- src: "/src/non-existent.js",
229
- type: "module",
230
- nonce: requestInfo.rw.nonce
231
- })
232
- )
233
- `);
248
+ (
249
+ (requestInfo.rw.scriptsToBeLoaded.add("/src/non-existent.js")),
250
+ jsx("script", {
251
+ src: "rwsdk_asset:/src/non-existent.js",
252
+ type: "module",
253
+ nonce: requestInfo.rw.nonce
254
+ })
255
+ )`;
256
+ expect(normalizeCode(result?.code || "")).toEqual(normalizeCode(expected));
234
257
  });
235
258
  it("adds nonce to script tags with src attribute and imports requestInfo", async () => {
236
259
  const code = `
@@ -239,18 +262,19 @@ describe("transformJsxScriptTagsCode", () => {
239
262
  type: "module"
240
263
  })
241
264
  `;
242
- const result = await transformJsxScriptTagsCode(code, mockManifest);
243
- expect(result?.code).toEqual(`import { requestInfo } from "rwsdk/worker";
265
+ const clientEntryPoints = new Set();
266
+ const result = await transformJsxScriptTagsCode(code, clientEntryPoints, mockManifest, "/project/root/dir");
267
+ const expected = `import { requestInfo } from "rwsdk/worker";
244
268
 
245
- (
246
- (requestInfo.rw.scriptsToBeLoaded.add("/src/client.tsx")),
247
- jsx("script", {
248
- src: "/assets/client-a1b2c3d4.js",
249
- type: "module",
250
- nonce: requestInfo.rw.nonce
251
- })
252
- )
253
- `);
269
+ (
270
+ (requestInfo.rw.scriptsToBeLoaded.add("/src/client.tsx")),
271
+ jsx("script", {
272
+ src: "rwsdk_asset:/src/client.tsx",
273
+ type: "module",
274
+ nonce: requestInfo.rw.nonce
275
+ })
276
+ )`;
277
+ expect(normalizeCode(result?.code || "")).toEqual(normalizeCode(expected));
254
278
  });
255
279
  it("adds nonce to script tags with string literal children", async () => {
256
280
  const code = `
@@ -259,7 +283,8 @@ describe("transformJsxScriptTagsCode", () => {
259
283
  children: "console.log('hello world')"
260
284
  })
261
285
  `;
262
- const result = await transformJsxScriptTagsCode(code, {});
286
+ const clientEntryPoints = new Set();
287
+ const result = await transformJsxScriptTagsCode(code, clientEntryPoints, mockManifest, "/project/root/dir");
263
288
  expect(result?.code).toEqual(`import { requestInfo } from "rwsdk/worker";
264
289
 
265
290
  jsx("script", {
@@ -276,7 +301,8 @@ describe("transformJsxScriptTagsCode", () => {
276
301
  dangerouslySetInnerHTML: { __html: "console.log('hello world')" }
277
302
  })
278
303
  `;
279
- const result = await transformJsxScriptTagsCode(code, {});
304
+ const clientEntryPoints = new Set();
305
+ const result = await transformJsxScriptTagsCode(code, clientEntryPoints, mockManifest, "/project/root/dir");
280
306
  expect(result?.code).toEqual(undefined);
281
307
  });
282
308
  it("does not add nonce to script tags that already have nonce", async () => {
@@ -287,7 +313,8 @@ describe("transformJsxScriptTagsCode", () => {
287
313
  nonce: "existing-nonce"
288
314
  })
289
315
  `;
290
- const result = await transformJsxScriptTagsCode(code, {});
316
+ const clientEntryPoints = new Set();
317
+ const result = await transformJsxScriptTagsCode(code, clientEntryPoints, mockManifest, "/project/root/dir");
291
318
  expect(result?.code).toEqual(undefined);
292
319
  });
293
320
  it("uses existing requestInfo import if already present", async () => {
@@ -300,7 +327,8 @@ describe("transformJsxScriptTagsCode", () => {
300
327
  children: "console.log('hello world')"
301
328
  })
302
329
  `;
303
- const result = await transformJsxScriptTagsCode(code, {});
330
+ const clientEntryPoints = new Set();
331
+ const result = await transformJsxScriptTagsCode(code, clientEntryPoints, mockManifest, "/project/root/dir");
304
332
  expect(result?.code).toEqual(`
305
333
  import { foo } from 'bar';
306
334
  import { requestInfo, someOtherThing } from "rwsdk/worker";
@@ -326,7 +354,8 @@ describe("transformJsxScriptTagsCode", () => {
326
354
  children: "console.log('hello world')"
327
355
  })
328
356
  `;
329
- const result = await transformJsxScriptTagsCode(code, {});
357
+ const clientEntryPoints = new Set();
358
+ const result = await transformJsxScriptTagsCode(code, clientEntryPoints, mockManifest, "/project/root/dir");
330
359
  expect(result?.code).toEqual(`
331
360
  import { foo } from 'bar';
332
361
  import { someOtherThing, requestInfo } from "rwsdk/worker";
@@ -346,17 +375,245 @@ describe("transformJsxScriptTagsCode", () => {
346
375
  })
347
376
  `;
348
377
  // Call without providing manifest (simulating dev mode)
349
- const result = await transformJsxScriptTagsCode(code);
350
- expect(result?.code).toEqual(`import { requestInfo } from "rwsdk/worker";
378
+ const clientEntryPoints = new Set();
379
+ const result = await transformJsxScriptTagsCode(code, clientEntryPoints, mockManifest, "/project/root/dir");
380
+ const expected = `import { requestInfo } from "rwsdk/worker";
351
381
 
352
- (
353
- (requestInfo.rw.scriptsToBeLoaded.add("/src/client.tsx")),
354
- jsx("script", {
355
- src: "/src/client.tsx",
356
- type: "module",
357
- nonce: requestInfo.rw.nonce
358
- })
359
- )
360
- `);
382
+ (
383
+ (requestInfo.rw.scriptsToBeLoaded.add("/src/client.tsx")),
384
+ jsx("script", {
385
+ src: "rwsdk_asset:/src/client.tsx",
386
+ type: "module",
387
+ nonce: requestInfo.rw.nonce
388
+ })
389
+ )`;
390
+ expect(normalizeCode(result?.code || "")).toEqual(normalizeCode(expected));
391
+ });
392
+ it("regression favicon links", async () => {
393
+ const code = `
394
+ import { jsxDEV } from "react/jsx-dev-runtime";
395
+ import styles from "./index.css?url";
396
+ export const Document = ({
397
+ children
398
+ }) => /* @__PURE__ */ jsxDEV("html", { lang: "en", children: [
399
+ /* @__PURE__ */ jsxDEV("head", { children: [
400
+ /* @__PURE__ */ jsxDEV("meta", { charSet: "utf-8" }, void 0, false, {
401
+ fileName: "/Users/justin/rw/blotter/rwsdk-guestbook/src/app/document/Document.tsx",
402
+ lineNumber: 8,
403
+ columnNumber: 4
404
+ }, this),
405
+ /* @__PURE__ */ jsxDEV("meta", { name: "viewport", content: "width=device-width, initial-scale=1" }, void 0, false, {
406
+ fileName: "/Users/justin/rw/blotter/rwsdk-guestbook/src/app/document/Document.tsx",
407
+ lineNumber: 9,
408
+ columnNumber: 4
409
+ }, this),
410
+ /* @__PURE__ */ jsxDEV("title", { children: "rwsdk-guestbook" }, void 0, false, {
411
+ fileName: "/Users/justin/rw/blotter/rwsdk-guestbook/src/app/document/Document.tsx",
412
+ lineNumber: 10,
413
+ columnNumber: 4
414
+ }, this),
415
+ /* @__PURE__ */ jsxDEV("link", { rel: "preconnect", href: "https://fonts.googleapis.com" }, void 0, false, {
416
+ fileName: "/Users/justin/rw/blotter/rwsdk-guestbook/src/app/document/Document.tsx",
417
+ lineNumber: 11,
418
+ columnNumber: 4
419
+ }, this),
420
+ /* @__PURE__ */ jsxDEV(
421
+ "link",
422
+ {
423
+ rel: "preconnect",
424
+ href: "https://fonts.gstatic.com",
425
+ crossOrigin: "anonymous"
426
+ },
427
+ void 0,
428
+ false,
429
+ {
430
+ fileName: "/Users/justin/rw/blotter/rwsdk-guestbook/src/app/document/Document.tsx",
431
+ lineNumber: 12,
432
+ columnNumber: 4
433
+ },
434
+ this
435
+ ),
436
+ /* @__PURE__ */ jsxDEV(
437
+ "link",
438
+ {
439
+ href: "https://fonts.googleapis.com/css2?family=Geist+Mono:wght@100..900&display=swap",
440
+ rel: "stylesheet"
441
+ },
442
+ void 0,
443
+ false,
444
+ {
445
+ fileName: "/Users/justin/rw/blotter/rwsdk-guestbook/src/app/document/Document.tsx",
446
+ lineNumber: 17,
447
+ columnNumber: 4
448
+ },
449
+ this
450
+ ),
451
+ /* @__PURE__ */ jsxDEV("script", { src: "/theme-script.js" }, void 0, false, {
452
+ fileName: "/Users/justin/rw/blotter/rwsdk-guestbook/src/app/document/Document.tsx",
453
+ lineNumber: 21,
454
+ columnNumber: 4
455
+ }, this),
456
+ /* @__PURE__ */ jsxDEV("link", { rel: "icon", href: "/favicon.svg" }, void 0, false, {
457
+ fileName: "/Users/justin/rw/blotter/rwsdk-guestbook/src/app/document/Document.tsx",
458
+ lineNumber: 22,
459
+ columnNumber: 4
460
+ }, this),
461
+ /* @__PURE__ */ jsxDEV("link", { rel: "modulepreload", href: "rwsdk_asset:/src/client.tsx" }, void 0, false, {
462
+ fileName: "/Users/justin/rw/blotter/rwsdk-guestbook/src/app/document/Document.tsx",
463
+ lineNumber: 23,
464
+ columnNumber: 4
465
+ }, this),
466
+ /* @__PURE__ */ jsxDEV("link", { rel: "stylesheet", href: styles }, void 0, false, {
467
+ fileName: "/Users/justin/rw/blotter/rwsdk-guestbook/src/app/document/Document.tsx",
468
+ lineNumber: 24,
469
+ columnNumber: 4
470
+ }, this)
471
+ ] }, void 0, true, {
472
+ fileName: "/Users/justin/rw/blotter/rwsdk-guestbook/src/app/document/Document.tsx",
473
+ lineNumber: 7,
474
+ columnNumber: 3
475
+ }, this),
476
+ /* @__PURE__ */ jsxDEV("body", { children: [
477
+ /* @__PURE__ */ jsxDEV("div", { id: "root", children }, void 0, false, {
478
+ fileName: "/Users/justin/rw/blotter/rwsdk-guestbook/src/app/document/Document.tsx",
479
+ lineNumber: 27,
480
+ columnNumber: 4
481
+ }, this),
482
+ /* @__PURE__ */ jsxDEV("script", { children: 'import("/src/client.tsx")' }, void 0, false, {
483
+ fileName: "/Users/justin/rw/blotter/rwsdk-guestbook/src/app/document/Document.tsx",
484
+ lineNumber: 28,
485
+ columnNumber: 4
486
+ }, this)
487
+ ] }, void 0, true, {
488
+ fileName: "/Users/justin/rw/blotter/rwsdk-guestbook/src/app/document/Document.tsx",
489
+ lineNumber: 26,
490
+ columnNumber: 3
491
+ }, this)
492
+ ] }, void 0, true, {
493
+ fileName: "/Users/justin/rw/blotter/rwsdk-guestbook/src/app/document/Document.tsx",
494
+ lineNumber: 6,
495
+ columnNumber: 2
496
+ }, this);
497
+ `;
498
+ const clientEntryPoints = new Set();
499
+ const result = await transformJsxScriptTagsCode(code, clientEntryPoints, mockManifest, "/project/root/dir");
500
+ // For this complex test, we'll just verify the key transformations
501
+ const expected = `
502
+ import { jsxDEV } from "react/jsx-dev-runtime";
503
+ import styles from "./index.css?url";
504
+ import { requestInfo } from "rwsdk/worker";
505
+
506
+ export const Document = ({
507
+ children
508
+ }) => /* @__PURE__ */ jsxDEV("html", { lang: "en", children: [
509
+ /* @__PURE__ */ jsxDEV("head", { children: [
510
+ /* @__PURE__ */ jsxDEV("meta", { charSet: "utf-8" }, void 0, false, {
511
+ fileName: "/Users/justin/rw/blotter/rwsdk-guestbook/src/app/document/Document.tsx",
512
+ lineNumber: 8,
513
+ columnNumber: 4
514
+ }, this),
515
+ /* @__PURE__ */ jsxDEV("meta", { name: "viewport", content: "width=device-width, initial-scale=1" }, void 0, false, {
516
+ fileName: "/Users/justin/rw/blotter/rwsdk-guestbook/src/app/document/Document.tsx",
517
+ lineNumber: 9,
518
+ columnNumber: 4
519
+ }, this),
520
+ /* @__PURE__ */ jsxDEV("title", { children: "rwsdk-guestbook" }, void 0, false, {
521
+ fileName: "/Users/justin/rw/blotter/rwsdk-guestbook/src/app/document/Document.tsx",
522
+ lineNumber: 10,
523
+ columnNumber: 4
524
+ }, this),
525
+ /* @__PURE__ */ jsxDEV("link", { rel: "preconnect", href: "https://fonts.googleapis.com" }, void 0, false, {
526
+ fileName: "/Users/justin/rw/blotter/rwsdk-guestbook/src/app/document/Document.tsx",
527
+ lineNumber: 11,
528
+ columnNumber: 4
529
+ }, this),
530
+ /* @__PURE__ */ jsxDEV(
531
+ "link",
532
+ {
533
+ rel: "preconnect",
534
+ href: "https://fonts.gstatic.com",
535
+ crossOrigin: "anonymous"
536
+ },
537
+ void 0,
538
+ false,
539
+ {
540
+ fileName: "/Users/justin/rw/blotter/rwsdk-guestbook/src/app/document/Document.tsx",
541
+ lineNumber: 12,
542
+ columnNumber: 4
543
+ },
544
+ this
545
+ ),
546
+ /* @__PURE__ */ jsxDEV(
547
+ "link",
548
+ {
549
+ href: "https://fonts.googleapis.com/css2?family=Geist+Mono:wght@100..900&display=swap",
550
+ rel: "stylesheet"
551
+ },
552
+ void 0,
553
+ false,
554
+ {
555
+ fileName: "/Users/justin/rw/blotter/rwsdk-guestbook/src/app/document/Document.tsx",
556
+ lineNumber: 17,
557
+ columnNumber: 4
558
+ },
559
+ this
560
+ ),
561
+ (
562
+ (requestInfo.rw.scriptsToBeLoaded.add("/theme-script.js")),
563
+ /* @__PURE__ */ jsxDEV("script", { src: "rwsdk_asset:/theme-script.js",
564
+ nonce: requestInfo.rw.nonce
565
+ }, void 0, false, {
566
+ fileName: "/Users/justin/rw/blotter/rwsdk-guestbook/src/app/document/Document.tsx",
567
+ lineNumber: 21,
568
+ columnNumber: 4
569
+ }, this)
570
+ ),
571
+ /* @__PURE__ */ jsxDEV("link", { rel: "icon", href: "/favicon.svg" }, void 0, false, {
572
+ fileName: "/Users/justin/rw/blotter/rwsdk-guestbook/src/app/document/Document.tsx",
573
+ lineNumber: 22,
574
+ columnNumber: 4
575
+ }, this),
576
+ /* @__PURE__ */ jsxDEV("link", { rel: "modulepreload", href: "rwsdk_asset:/src/client.tsx" }, void 0, false, {
577
+ fileName: "/Users/justin/rw/blotter/rwsdk-guestbook/src/app/document/Document.tsx",
578
+ lineNumber: 23,
579
+ columnNumber: 4
580
+ }, this),
581
+ /* @__PURE__ */ jsxDEV("link", { rel: "stylesheet", href: styles }, void 0, false, {
582
+ fileName: "/Users/justin/rw/blotter/rwsdk-guestbook/src/app/document/Document.tsx",
583
+ lineNumber: 24,
584
+ columnNumber: 4
585
+ }, this)
586
+ ] }, void 0, true, {
587
+ fileName: "/Users/justin/rw/blotter/rwsdk-guestbook/src/app/document/Document.tsx",
588
+ lineNumber: 7,
589
+ columnNumber: 3
590
+ }, this),
591
+ /* @__PURE__ */ jsxDEV("body", { children: [
592
+ /* @__PURE__ */ jsxDEV("div", { id: "root", children }, void 0, false, {
593
+ fileName: "/Users/justin/rw/blotter/rwsdk-guestbook/src/app/document/Document.tsx",
594
+ lineNumber: 27,
595
+ columnNumber: 4
596
+ }, this),
597
+ (
598
+ (requestInfo.rw.scriptsToBeLoaded.add("/src/client.tsx")),
599
+ /* @__PURE__ */ jsxDEV("script", { children: "import(\\"rwsdk_asset:/src/client.tsx\\")",
600
+ nonce: requestInfo.rw.nonce
601
+ }, void 0, false, {
602
+ fileName: "/Users/justin/rw/blotter/rwsdk-guestbook/src/app/document/Document.tsx",
603
+ lineNumber: 28,
604
+ columnNumber: 4
605
+ }, this)
606
+ )
607
+ ] }, void 0, true, {
608
+ fileName: "/Users/justin/rw/blotter/rwsdk-guestbook/src/app/document/Document.tsx",
609
+ lineNumber: 26,
610
+ columnNumber: 3
611
+ }, this)
612
+ ] }, void 0, true, {
613
+ fileName: "/Users/justin/rw/blotter/rwsdk-guestbook/src/app/document/Document.tsx",
614
+ lineNumber: 6,
615
+ columnNumber: 2
616
+ }, this);`;
617
+ expect(normalizeCode(result?.code || "")).toEqual(normalizeCode(expected));
361
618
  });
362
619
  });