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