rwsdk 0.1.4 → 0.1.6-test.20250702132719

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 (81) hide show
  1. package/dist/runtime/client.js +6 -1
  2. package/dist/runtime/clientNavigation.d.ts +1 -0
  3. package/dist/runtime/clientNavigation.js +34 -24
  4. package/dist/runtime/clientNavigation.test.js +55 -0
  5. package/dist/runtime/lib/realtime/client.js +6 -0
  6. package/dist/runtime/lib/realtime/durableObject.js +8 -3
  7. package/dist/runtime/lib/realtime/worker.js +1 -3
  8. package/dist/runtime/render/renderRscThenableToHtmlStream.d.ts +2 -1
  9. package/dist/runtime/render/renderRscThenableToHtmlStream.js +22 -1
  10. package/dist/runtime/render/renderToStream.js +2 -1
  11. package/dist/runtime/render/transformRscToHtmlStream.d.ts +2 -1
  12. package/dist/runtime/render/transformRscToHtmlStream.js +2 -1
  13. package/dist/runtime/ssrBridge.js +2 -2
  14. package/dist/runtime/worker.js +1 -0
  15. package/dist/scripts/ensure-deploy-env.mjs +8 -8
  16. package/dist/vite/createDirectiveLookupPlugin.mjs +2 -1
  17. package/package.json +1 -1
  18. package/dist/lib/smokeTests/components.d.mts +0 -8
  19. package/dist/lib/smokeTests/components.mjs +0 -194
  20. package/dist/lib/smokeTests/templates/SmokeTestInfo.template.d.ts +0 -1
  21. package/dist/lib/smokeTests/templates/SmokeTestInfo.template.js +0 -82
  22. package/dist/runtime/components/HealthCheck.d.ts +0 -13
  23. package/dist/runtime/components/HealthCheck.js +0 -56
  24. package/dist/runtime/components/HealthCheckClient.d.ts +0 -2
  25. package/dist/runtime/components/HealthCheckClient.js +0 -78
  26. package/dist/runtime/imports/NoSSRStub.d.ts +0 -1
  27. package/dist/runtime/imports/NoSSRStub.js +0 -4
  28. package/dist/runtime/lib/db/create.d.ts +0 -3
  29. package/dist/runtime/lib/db/create.js +0 -36
  30. package/dist/runtime/lib/db/logger.d.ts +0 -2
  31. package/dist/runtime/lib/db/logger.js +0 -41
  32. package/dist/runtime/lib/db/types.d.ts +0 -0
  33. package/dist/runtime/lib/db/types.js +0 -1
  34. package/dist/runtime/render/__rwsdk_ssr_bridge.d.ts +0 -10
  35. package/dist/runtime/render/__rwsdk_ssr_bridge.js +0 -9
  36. package/dist/runtime/render/__rwsdkssr_render.d.ts +0 -9
  37. package/dist/runtime/render/__rwsdkssr_render.js +0 -13
  38. package/dist/runtime/render/injectRSCPayload.d.ts +0 -3
  39. package/dist/runtime/render/injectRSCPayload.js +0 -79
  40. package/dist/runtime/render/ssrBridge.d.ts +0 -2
  41. package/dist/runtime/render/ssrBridge.js +0 -2
  42. package/dist/runtime/render/ssrRenderToReadableStream.d.ts +0 -2
  43. package/dist/runtime/render/ssrRenderToReadableStream.js +0 -2
  44. package/dist/runtime/requestInfo/__rwsdknossr_worker.d.ts +0 -5
  45. package/dist/runtime/requestInfo/__rwsdknossr_worker.js +0 -33
  46. package/dist/scripts/build-vendor-bundles.d.mts +0 -1
  47. package/dist/scripts/build-vendor-bundles.mjs +0 -92
  48. package/dist/vite/aliasedModuleResolver.d.mts +0 -9
  49. package/dist/vite/aliasedModuleResolver.mjs +0 -62
  50. package/dist/vite/aliasedSSRResolver.d.mts +0 -5
  51. package/dist/vite/aliasedSSRResolver.mjs +0 -74
  52. package/dist/vite/copyPrismaWasmPlugin.d.mts +0 -4
  53. package/dist/vite/copyPrismaWasmPlugin.mjs +0 -32
  54. package/dist/vite/ensureConfigArrays.d.mts +0 -1
  55. package/dist/vite/ensureConfigArrays.mjs +0 -12
  56. package/dist/vite/findImportSpecifiers.d.mts +0 -30
  57. package/dist/vite/findImportSpecifiers.mjs +0 -228
  58. package/dist/vite/findImportSpecifiers.test.mjs +0 -73
  59. package/dist/vite/isBareImport.d.mts +0 -1
  60. package/dist/vite/isBareImport.mjs +0 -5
  61. package/dist/vite/miniflarePlugin.d.mts +0 -9
  62. package/dist/vite/miniflarePlugin.mjs +0 -135
  63. package/dist/vite/moduleResolver.d.mts +0 -10
  64. package/dist/vite/moduleResolver.mjs +0 -74
  65. package/dist/vite/resolveModuleId.d.mts +0 -6
  66. package/dist/vite/resolveModuleId.mjs +0 -14
  67. package/dist/vite/rscDirectivesPlugin.d.mts +0 -6
  68. package/dist/vite/rscDirectivesPlugin.mjs +0 -80
  69. package/dist/vite/transformServerReferences.d.mts +0 -11
  70. package/dist/vite/transformServerReferences.mjs +0 -74
  71. package/dist/vite/useClientPlugin.d.mts +0 -8
  72. package/dist/vite/useClientPlugin.mjs +0 -299
  73. package/dist/vite/useClientPlugin.test.d.mts +0 -1
  74. package/dist/vite/useClientPlugin.test.mjs +0 -1294
  75. package/dist/vite/useServerPlugin.test.d.mts +0 -1
  76. package/dist/vite/useServerPlugin.test.mjs +0 -99
  77. package/dist/vite/virtualizedSSRPlugin.d.mts +0 -56
  78. package/dist/vite/virtualizedSSRPlugin.mjs +0 -464
  79. package/dist/vite/wasmPlugin.d.mts +0 -2
  80. package/dist/vite/wasmPlugin.mjs +0 -14
  81. /package/dist/{vite/findImportSpecifiers.test.d.mts → runtime/clientNavigation.test.d.ts} +0 -0
@@ -1,299 +0,0 @@
1
- import { relative } from "node:path";
2
- import { Project, Node, SyntaxKind, } from "ts-morph";
3
- function isJsxFunction(text) {
4
- return (text.includes("jsx(") || text.includes("jsxs(") || text.includes("jsxDEV("));
5
- }
6
- export async function transformUseClientCode(code, relativeId) {
7
- if (code.indexOf("use client") === -1) {
8
- return;
9
- }
10
- const project = new Project({
11
- useInMemoryFileSystem: true,
12
- compilerOptions: {
13
- sourceMap: true,
14
- target: 2, // ES6
15
- module: 1, // CommonJS
16
- jsx: 2, // React
17
- },
18
- });
19
- const sourceFile = project.createSourceFile("temp.tsx", code);
20
- const firstString = sourceFile.getFirstDescendantByKind(SyntaxKind.StringLiteral);
21
- if (firstString?.getText().indexOf("use client") === -1 &&
22
- firstString?.getStart() !== sourceFile.getStart() // `getStart` does not include the leading comments + whitespace
23
- ) {
24
- return;
25
- }
26
- // Add import declaration properly through the AST
27
- sourceFile.addImportDeclaration({
28
- moduleSpecifier: "rwsdk/worker",
29
- namedImports: [{ name: "registerClientReference" }],
30
- });
31
- const components = new Map();
32
- let anonymousDefaultCount = 0;
33
- // Pass 1: Collect all component information
34
- // Handle function declarations
35
- sourceFile
36
- .getDescendantsOfKind(SyntaxKind.FunctionDeclaration)
37
- .forEach((node) => {
38
- const name = node.getName() || `DefaultComponent${anonymousDefaultCount++}`;
39
- if (!name)
40
- return;
41
- // Only track if it's a component (has JSX return)
42
- if (isJsxFunction(node.getText())) {
43
- const ssrName = `${name}SSR`;
44
- const isInlineExport = node.hasModifier(SyntaxKind.ExportKeyword);
45
- // Check if this function is used in a default export
46
- const isDefault = node.hasModifier(SyntaxKind.DefaultKeyword) ||
47
- sourceFile
48
- .getDescendantsOfKind(SyntaxKind.ExportAssignment)
49
- .some((exp) => exp.getExpression().getText() === name);
50
- components.set(name, {
51
- name,
52
- ssrName,
53
- isDefault,
54
- isInlineExport,
55
- });
56
- }
57
- });
58
- // Handle arrow functions and anonymous default exports
59
- sourceFile
60
- .getDescendantsOfKind(SyntaxKind.VariableStatement)
61
- .forEach((statement) => {
62
- const declarations = statement.getDeclarationList().getDeclarations();
63
- declarations.forEach((varDecl) => {
64
- const arrowFunc = varDecl.getFirstDescendantByKind(SyntaxKind.ArrowFunction);
65
- if (!arrowFunc)
66
- return;
67
- // Only track if it's a component (has JSX return)
68
- if (isJsxFunction(arrowFunc.getText())) {
69
- const name = varDecl.getName();
70
- const isDefault = !!statement.getFirstAncestorByKind(SyntaxKind.ExportAssignment);
71
- const isInlineExport = statement.hasModifier(SyntaxKind.ExportKeyword);
72
- if (!name &&
73
- (isDefault || statement.getText().includes("export default"))) {
74
- // Handle anonymous default export
75
- const anonName = `DefaultComponent${anonymousDefaultCount++}`;
76
- components.set(anonName, {
77
- name: anonName,
78
- ssrName: anonName,
79
- isDefault: true,
80
- isInlineExport: true,
81
- isAnonymousDefault: true,
82
- });
83
- }
84
- else if (name) {
85
- components.set(name, {
86
- name,
87
- ssrName: `${name}SSR`,
88
- isDefault,
89
- isInlineExport,
90
- });
91
- }
92
- }
93
- });
94
- });
95
- // Pass 2: handle exports
96
- // Remove use client directives
97
- sourceFile.getDescendantsOfKind(SyntaxKind.StringLiteral).forEach((node) => {
98
- if (node.getText() === "'use client'" ||
99
- node.getText() === '"use client"') {
100
- const parentExpr = node.getFirstAncestorByKind(SyntaxKind.ExpressionStatement);
101
- if (parentExpr) {
102
- parentExpr.remove();
103
- }
104
- }
105
- });
106
- // Create lists of nodes to modify before making any changes
107
- const functionsToModify = [];
108
- const variableStatementsToModify = [];
109
- const exportDeclarationsToModify = [];
110
- const exportAssignmentsToModify = [];
111
- // Collect function declarations to modify
112
- sourceFile
113
- .getDescendantsOfKind(SyntaxKind.FunctionDeclaration)
114
- .forEach((node) => {
115
- const name = node.getName();
116
- if (!name || !components.has(name))
117
- return;
118
- const component = components.get(name);
119
- if (component.isInlineExport) {
120
- functionsToModify.push({
121
- node,
122
- nodeText: node.getText(),
123
- component,
124
- });
125
- }
126
- });
127
- // Collect variable statements to modify
128
- sourceFile
129
- .getDescendantsOfKind(SyntaxKind.VariableStatement)
130
- .forEach((statement) => {
131
- if (!statement.hasModifier(SyntaxKind.ExportKeyword))
132
- return;
133
- const declarations = statement.getDeclarationList().getDeclarations();
134
- let hasComponent = false;
135
- declarations.forEach((varDecl) => {
136
- const name = varDecl.getName();
137
- if (name && components.has(name)) {
138
- hasComponent = true;
139
- }
140
- });
141
- if (hasComponent) {
142
- variableStatementsToModify.push({
143
- node: statement,
144
- stmtText: statement.getText(),
145
- });
146
- }
147
- });
148
- // Collect export declarations to modify
149
- sourceFile
150
- .getDescendantsOfKind(SyntaxKind.ExportDeclaration)
151
- .forEach((node) => {
152
- const namedExports = node.getNamedExports();
153
- const nonComponentExports = namedExports.filter((exp) => !components.has(exp.getName()));
154
- if (nonComponentExports.length !== namedExports.length) {
155
- exportDeclarationsToModify.push({
156
- node,
157
- nonComponentExports,
158
- });
159
- }
160
- });
161
- // Collect export assignments to modify
162
- sourceFile
163
- .getDescendantsOfKind(SyntaxKind.ExportAssignment)
164
- .forEach((node) => {
165
- const expression = node.getExpression();
166
- if (Node.isArrowFunction(expression)) {
167
- exportAssignmentsToModify.push({
168
- node,
169
- expression,
170
- });
171
- }
172
- else {
173
- exportAssignmentsToModify.push({
174
- node,
175
- expression: null,
176
- });
177
- }
178
- });
179
- // Now apply all modifications in sequence to avoid operating on removed nodes
180
- // Modify function declarations
181
- functionsToModify.forEach(({ node, nodeText, component }) => {
182
- const newText = nodeText.replace(/^export\s+(default\s+)?(async\s+)?function/, "$2function");
183
- node.replaceWithText(newText);
184
- });
185
- // Modify variable statements
186
- variableStatementsToModify.forEach(({ node, stmtText }) => {
187
- const newText = stmtText.replace(/^export\s+/, "");
188
- node.replaceWithText(newText);
189
- });
190
- // Modify export declarations
191
- exportDeclarationsToModify.forEach(({ node, nonComponentExports }) => {
192
- if (nonComponentExports.length === 0) {
193
- // If all exports were components, remove the declaration
194
- node.remove();
195
- }
196
- else {
197
- // If some exports were components, update the export declaration
198
- const newExports = nonComponentExports
199
- .map((exp) => exp.getText())
200
- .join(", ");
201
- node.replaceWithText(`export { ${newExports} };`);
202
- }
203
- });
204
- // Handle export assignments with arrow functions
205
- exportAssignmentsToModify.forEach(({ node, expression }) => {
206
- if (expression && Node.isArrowFunction(expression)) {
207
- const anonName = `DefaultComponent${anonymousDefaultCount++}`;
208
- const ssrName = `${anonName}SSR`;
209
- // First add declarations
210
- sourceFile.addStatements(`const ${ssrName} = ${expression.getText()}`);
211
- sourceFile.addStatements(`const ${anonName} = registerClientReference("${relativeId}", "default", ${ssrName});`);
212
- // Store info for later export
213
- components.set(anonName, {
214
- name: anonName,
215
- ssrName,
216
- isDefault: true,
217
- isInlineExport: true,
218
- isAnonymousDefault: true,
219
- });
220
- }
221
- // Remove the original export default node
222
- node.remove();
223
- });
224
- // Pass 4: rename all identifiers to SSR version - collect first
225
- const identifiersToRename = [];
226
- components.forEach(({ name, ssrName, isAnonymousDefault }) => {
227
- if (isAnonymousDefault)
228
- return;
229
- // Find function declarations by name
230
- const funcDecls = sourceFile.getDescendantsOfKind(SyntaxKind.FunctionDeclaration);
231
- const funcNode = funcDecls.find((decl) => decl.getName() === name);
232
- if (funcNode) {
233
- identifiersToRename.push({ node: funcNode, newName: ssrName });
234
- return;
235
- }
236
- // Find variable declarations by name
237
- const varDecls = sourceFile.getDescendantsOfKind(SyntaxKind.VariableDeclaration);
238
- const varNode = varDecls.find((decl) => decl.getName() === name);
239
- if (varNode) {
240
- const identifier = varNode.getFirstChildByKind(SyntaxKind.Identifier);
241
- if (identifier) {
242
- identifiersToRename.push({ node: identifier, newName: ssrName });
243
- }
244
- }
245
- });
246
- // Now apply the renames
247
- identifiersToRename.forEach(({ node, newName }) => {
248
- node.rename(newName);
249
- });
250
- // Pass 5: Add client reference registrations
251
- // Add all declarations first
252
- components.forEach(({ name, ssrName, isDefault, isAnonymousDefault }) => {
253
- if (!isAnonymousDefault) {
254
- sourceFile.addStatements(`const ${name} = registerClientReference("${relativeId}", "${isDefault ? "default" : name}", ${ssrName});`);
255
- }
256
- });
257
- // Pass 6: add new exports
258
- // Then add all exports after declarations
259
- components.forEach(({ name, ssrName, isDefault }) => {
260
- if (isDefault) {
261
- // Export the registerClientReference version as default
262
- sourceFile.addStatements(`export { ${name} as default, ${ssrName} };`);
263
- }
264
- else {
265
- sourceFile.addStatements(`export { ${ssrName}, ${name} };`);
266
- }
267
- });
268
- // Clean up any remaining export assignments
269
- sourceFile
270
- .getDescendantsOfKind(SyntaxKind.ExportAssignment)
271
- .forEach((node) => {
272
- // If it's not an arrow function (which we handle separately),
273
- // just remove the export assignment
274
- node.remove();
275
- });
276
- const emitOutput = sourceFile.getEmitOutput();
277
- let sourceMap;
278
- for (const outputFile of emitOutput.getOutputFiles()) {
279
- if (outputFile.getFilePath().endsWith(".js.map")) {
280
- sourceMap = JSON.parse(outputFile.getText());
281
- }
282
- }
283
- return {
284
- code: sourceFile.getFullText(),
285
- map: sourceMap,
286
- };
287
- }
288
- export const useClientPlugin = () => ({
289
- name: "rwsdk:use-client",
290
- async transform(code, id) {
291
- if (id.includes(".vite/deps") ||
292
- id.includes("node_modules") ||
293
- this.environment.name !== "worker") {
294
- return;
295
- }
296
- const relativeId = `/${relative(this.environment.getTopLevelConfig().root, id)}`;
297
- return transformUseClientCode(code, relativeId);
298
- },
299
- });
@@ -1 +0,0 @@
1
- export {};