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.
- 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/client/client.d.ts +10 -0
- package/dist/runtime/{client.js → client/client.js} +13 -10
- package/dist/runtime/{clientNavigation.test.js → client/navigation.test.js} +1 -1
- package/dist/runtime/client/setWebpackRequire.d.ts +1 -0
- package/dist/runtime/client/setWebpackRequire.js +2 -0
- package/dist/runtime/{client.d.ts → client/types.d.ts} +4 -10
- package/dist/runtime/client/types.js +1 -0
- package/dist/runtime/entries/client.d.ts +2 -2
- package/dist/runtime/entries/client.js +2 -2
- package/dist/runtime/imports/client.d.ts +3 -3
- package/dist/runtime/imports/client.js +11 -15
- package/dist/runtime/imports/ssr.d.ts +3 -3
- package/dist/runtime/imports/ssr.js +3 -3
- package/dist/runtime/imports/worker.d.ts +3 -3
- package/dist/runtime/imports/worker.js +5 -4
- package/dist/runtime/lib/manifest.d.ts +11 -2
- package/dist/runtime/lib/manifest.js +1 -1
- package/dist/runtime/lib/memoizeOnId.d.ts +1 -0
- package/dist/runtime/lib/memoizeOnId.js +11 -0
- package/dist/runtime/lib/realtime/client.d.ts +1 -1
- package/dist/runtime/lib/realtime/client.js +1 -1
- package/dist/runtime/lib/router.d.ts +3 -3
- package/dist/runtime/lib/router.js +77 -33
- package/dist/runtime/register/ssr.d.ts +1 -1
- package/dist/runtime/register/ssr.js +4 -3
- package/dist/runtime/render/preloads.d.ts +6 -0
- package/dist/runtime/render/preloads.js +40 -0
- package/dist/runtime/render/renderRscThenableToHtmlStream.js +2 -1
- package/dist/runtime/render/stylesheets.js +1 -1
- package/dist/runtime/requestInfo/types.d.ts +3 -1
- package/dist/runtime/requestInfo/worker.js +9 -1
- package/dist/runtime/worker.d.ts +0 -3
- package/dist/runtime/worker.js +2 -11
- package/dist/scripts/debug-sync.mjs +142 -39
- package/dist/scripts/smoke-test.mjs +0 -10
- package/dist/scripts/worker-run.mjs +8 -3
- 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/hasOwnReactVitePlugin.d.mts +3 -0
- package/dist/vite/hasOwnReactVitePlugin.mjs +14 -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/miniflareHMRPlugin.mjs +17 -2
- package/dist/vite/moveStaticAssetsPlugin.mjs +2 -1
- package/dist/vite/prismaPlugin.mjs +1 -1
- package/dist/vite/reactConditionsResolverPlugin.d.mts +3 -4
- package/dist/vite/reactConditionsResolverPlugin.mjs +74 -56
- package/dist/vite/redwoodPlugin.d.mts +1 -1
- package/dist/vite/redwoodPlugin.mjs +36 -12
- 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 +151 -158
- package/dist/vite/transformJsxScriptTagsPlugin.test.mjs +393 -136
- package/dist/vite/transformServerFunctions.d.mts +1 -1
- package/dist/vite/transformServerFunctions.mjs +11 -12
- package/package.json +28 -4
- /package/dist/runtime/{imports → client}/ClientOnly.d.ts +0 -0
- /package/dist/runtime/{imports → client}/ClientOnly.js +0 -0
- /package/dist/runtime/{clientNavigation.d.ts → client/navigation.d.ts} +0 -0
- /package/dist/runtime/{clientNavigation.js → client/navigation.js} +0 -0
- /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
|
|
17
|
-
|
|
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
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
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
|
|
37
|
-
|
|
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
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
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
|
|
54
|
-
|
|
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
|
-
|
|
58
|
-
|
|
59
|
-
|
|
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
|
|
79
|
-
|
|
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
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
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('/
|
|
102
|
+
await import('rwsdk_asset:/src/entry.js');
|
|
89
103
|
console.log('initialized');
|
|
90
104
|
};
|
|
91
105
|
init();
|
|
92
106
|
\`,
|
|
93
|
-
|
|
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
|
-
|
|
104
|
-
|
|
105
|
-
|
|
117
|
+
import('/src/client.tsx');
|
|
118
|
+
import('/src/entry.js');
|
|
119
|
+
\`
|
|
106
120
|
})
|
|
107
121
|
`;
|
|
108
|
-
const
|
|
109
|
-
|
|
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
|
-
|
|
126
|
+
(
|
|
127
|
+
(requestInfo.rw.scriptsToBeLoaded.add("/src/client.tsx")),
|
|
113
128
|
(requestInfo.rw.scriptsToBeLoaded.add("/src/entry.js")),
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
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
|
|
134
|
-
|
|
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: "/
|
|
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
|
|
150
|
-
|
|
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: "/
|
|
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: "
|
|
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
|
|
180
|
-
|
|
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
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
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
|
|
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
|
|
223
|
-
|
|
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
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
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
|
|
243
|
-
|
|
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
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
350
|
-
|
|
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
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
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
|
});
|