@kithinji/pod 1.0.11 → 1.0.13
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/main.js +158 -110
- package/dist/main.js.map +3 -3
- package/dist/types/dev/server.d.ts.map +1 -1
- package/dist/types/plugins/analyzers/graph.d.ts.map +1 -1
- package/dist/types/plugins/generators/tsx_server_stub.d.ts +2 -0
- package/dist/types/plugins/generators/tsx_server_stub.d.ts.map +1 -1
- package/dist/types/plugins/my.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/dev/server.ts +1 -0
- package/src/main.ts +1 -1
- package/src/plugins/analyzers/graph.ts +103 -115
- package/src/plugins/generators/tsx_server_stub.ts +30 -10
- package/src/plugins/my.ts +12 -4
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../../../src/dev/server.ts"],"names":[],"mappings":"AAyDA,wBAAsB,cAAc,IAAI,OAAO,CAAC,IAAI,CAAC,
|
|
1
|
+
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../../../src/dev/server.ts"],"names":[],"mappings":"AAyDA,wBAAsB,cAAc,IAAI,OAAO,CAAC,IAAI,CAAC,CAqIpD"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"graph.d.ts","sourceRoot":"","sources":["../../../../src/plugins/analyzers/graph.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"graph.d.ts","sourceRoot":"","sources":["../../../../src/plugins/analyzers/graph.ts"],"names":[],"mappings":"AAMA,KAAK,UAAU,GACX,OAAO,GACP,UAAU,GACV,UAAU,GACV,WAAW,GACX,MAAM,GACN,MAAM,GACN,WAAW,GACX,SAAS,CAAC;AAEd,UAAU,UAAU;IAClB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,UAAU,CAAC;IACjB,UAAU,CAAC,EAAE,MAAM,EAAE,CAAC;IACtB,SAAS,CAAC,EAAE,OAAO,CAAC;CACrB;AAED,UAAU,UAAU;IAClB,UAAU,EAAE,MAAM,CAAC;IACnB,YAAY,EAAE,MAAM,GAAG,IAAI,CAAC;IAC5B,OAAO,EAAE,UAAU,EAAE,CAAC;CACvB;AAED,MAAM,WAAW,QAAQ;IACvB,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,OAAO,CAAC;IACf,SAAS,EAAE,QAAQ,GAAG,aAAa,GAAG,IAAI,CAAC;IAC3C,OAAO,EAAE,UAAU,EAAE,CAAC;IACtB,OAAO,EAAE,UAAU,EAAE,CAAC;CACvB;AAED,MAAM,WAAW,eAAe;IAC9B,CAAC,QAAQ,EAAE,MAAM,GAAG,QAAQ,CAAC;CAC9B;AAiKD,wBAAgB,UAAU,CAAC,WAAW,EAAE,MAAM,EAAE,GAAG,eAAe,CA8EjE"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tsx_server_stub.d.ts","sourceRoot":"","sources":["../../../../src/plugins/generators/tsx_server_stub.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"tsx_server_stub.d.ts","sourceRoot":"","sources":["../../../../src/plugins/generators/tsx_server_stub.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAGV,SAAS,EAEV,MAAM,WAAW,CAAC;AAanB,wBAAgB,kBAAkB,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CA2EzE;AAwDD,wBAAgB,kBAAkB,CAAC,SAAS,EAAE,SAAS,GAAG,MAAM,CAiB/D"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"my.d.ts","sourceRoot":"","sources":["../../../src/plugins/my.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAA4B,MAAM,SAAS,CAAC;AAMhE,OAAO,EAAE,eAAe,EAAY,MAAM,mBAAmB,CAAC;
|
|
1
|
+
{"version":3,"file":"my.d.ts","sourceRoot":"","sources":["../../../src/plugins/my.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAA4B,MAAM,SAAS,CAAC;AAMhE,OAAO,EAAE,eAAe,EAAY,MAAM,mBAAmB,CAAC;AAQ9D,UAAU,cAAc;IACtB,aAAa,EAAE,OAAO,CAAC;IACvB,KAAK,CAAC,EAAE,eAAe,CAAC;IACxB,aAAa,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;CACvC;AAoOD,wBAAgB,WAAW,CAAC,OAAO,EAAE,cAAc,GAAG,MAAM,CAmC3D"}
|
package/package.json
CHANGED
package/src/dev/server.ts
CHANGED
package/src/main.ts
CHANGED
|
@@ -2,6 +2,7 @@ import { parseSync } from "@swc/core";
|
|
|
2
2
|
import * as fs from "fs";
|
|
3
3
|
import * as path from "path";
|
|
4
4
|
import type { Module, Decorator } from "@swc/core";
|
|
5
|
+
import { Store } from "@/store";
|
|
5
6
|
|
|
6
7
|
type SymbolKind =
|
|
7
8
|
| "class"
|
|
@@ -39,9 +40,7 @@ export interface DependencyGraph {
|
|
|
39
40
|
}
|
|
40
41
|
|
|
41
42
|
function resolveFilePath(fromFile: string, importPath: string): string | null {
|
|
42
|
-
if (!importPath.startsWith("."))
|
|
43
|
-
return null;
|
|
44
|
-
}
|
|
43
|
+
if (!importPath.startsWith(".")) return null;
|
|
45
44
|
|
|
46
45
|
const dir = path.dirname(fromFile);
|
|
47
46
|
const basePath = path.resolve(dir, importPath);
|
|
@@ -49,37 +48,31 @@ function resolveFilePath(fromFile: string, importPath: string): string | null {
|
|
|
49
48
|
const extensions = ["", ".ts", ".tsx", ".js", ".jsx"];
|
|
50
49
|
for (const ext of extensions) {
|
|
51
50
|
const fullPath = basePath + ext;
|
|
52
|
-
if (fs.existsSync(fullPath) && fs.statSync(fullPath).isFile())
|
|
51
|
+
if (fs.existsSync(fullPath) && fs.statSync(fullPath).isFile())
|
|
53
52
|
return fullPath;
|
|
54
|
-
}
|
|
55
53
|
}
|
|
56
54
|
|
|
57
55
|
const indexFiles = ["/index.ts", "/index.tsx", "/index.js", "/index.jsx"];
|
|
58
56
|
for (const indexFile of indexFiles) {
|
|
59
57
|
const fullPath = basePath + indexFile;
|
|
60
|
-
if (fs.existsSync(fullPath))
|
|
58
|
+
if (fs.existsSync(fullPath) && fs.statSync(fullPath).isFile())
|
|
61
59
|
return fullPath;
|
|
62
|
-
}
|
|
63
60
|
}
|
|
64
61
|
|
|
65
62
|
return null;
|
|
66
63
|
}
|
|
67
64
|
|
|
68
65
|
function extractDecorators(decorators?: Decorator[]): string[] {
|
|
69
|
-
if (!decorators
|
|
70
|
-
|
|
66
|
+
if (!decorators) return [];
|
|
71
67
|
return decorators
|
|
72
|
-
.map((
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
} else if (decorator.expression.type === "Identifier") {
|
|
78
|
-
return decorator.expression.value;
|
|
79
|
-
}
|
|
68
|
+
.map((d) => {
|
|
69
|
+
const exp = d.expression;
|
|
70
|
+
if (exp.type === "CallExpression" && exp.callee.type === "Identifier")
|
|
71
|
+
return exp.callee.value;
|
|
72
|
+
if (exp.type === "Identifier") return exp.value;
|
|
80
73
|
return "unknown";
|
|
81
74
|
})
|
|
82
|
-
.filter((
|
|
75
|
+
.filter((n) => n !== "unknown");
|
|
83
76
|
}
|
|
84
77
|
|
|
85
78
|
function extractDirective(ast: Module): "public" | "interactive" | null {
|
|
@@ -88,21 +81,34 @@ function extractDirective(ast: Module): "public" | "interactive" | null {
|
|
|
88
81
|
item.type === "ExpressionStatement" &&
|
|
89
82
|
item.expression.type === "StringLiteral"
|
|
90
83
|
) {
|
|
91
|
-
const
|
|
92
|
-
if (
|
|
93
|
-
if (
|
|
94
|
-
}
|
|
95
|
-
if (
|
|
96
|
-
item.type !== "ExpressionStatement" ||
|
|
97
|
-
item.expression.type !== "StringLiteral"
|
|
98
|
-
) {
|
|
84
|
+
const val = item.expression.value;
|
|
85
|
+
if (val === "use public") return "public";
|
|
86
|
+
if (val === "use interactive") return "interactive";
|
|
87
|
+
} else {
|
|
99
88
|
break;
|
|
100
89
|
}
|
|
101
90
|
}
|
|
102
91
|
return null;
|
|
103
92
|
}
|
|
104
93
|
|
|
105
|
-
function
|
|
94
|
+
function extractImports(
|
|
95
|
+
ast: Module
|
|
96
|
+
): Array<{ path: string; specifiers: any[] }> {
|
|
97
|
+
const imports: Array<{ path: string; specifiers: any[] }> = [];
|
|
98
|
+
for (const item of ast.body) {
|
|
99
|
+
if (item.type === "ImportDeclaration") {
|
|
100
|
+
imports.push({ path: item.source.value, specifiers: item.specifiers });
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
return imports;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
function extractExports(
|
|
107
|
+
ast: Module,
|
|
108
|
+
currentFile: string,
|
|
109
|
+
graph: DependencyGraph,
|
|
110
|
+
processFile: (fp: string) => void
|
|
111
|
+
): SymbolInfo[] {
|
|
106
112
|
const exports: SymbolInfo[] = [];
|
|
107
113
|
|
|
108
114
|
for (const item of ast.body) {
|
|
@@ -133,10 +139,31 @@ function extractExports(ast: Module): SymbolInfo[] {
|
|
|
133
139
|
}
|
|
134
140
|
}
|
|
135
141
|
|
|
136
|
-
if (item.type === "ExportNamedDeclaration") {
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
142
|
+
if (item.type === "ExportNamedDeclaration" && item.source) {
|
|
143
|
+
const resolved = resolveFilePath(currentFile, item.source.value);
|
|
144
|
+
if (resolved) {
|
|
145
|
+
processFile(resolved);
|
|
146
|
+
const sourceExports = graph[resolved]?.exports || [];
|
|
147
|
+
for (const spec of item.specifiers) {
|
|
148
|
+
if (spec.type === "ExportSpecifier") {
|
|
149
|
+
const exp = sourceExports.find((e) => e.name === spec.orig.value);
|
|
150
|
+
exports.push({
|
|
151
|
+
name: spec.exported?.value || spec.orig.value,
|
|
152
|
+
kind: exp?.kind || "unknown",
|
|
153
|
+
decorators: exp?.decorators,
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
if (item.type === "ExportAllDeclaration") {
|
|
161
|
+
const resolved = resolveFilePath(currentFile, item.source.value);
|
|
162
|
+
if (resolved) {
|
|
163
|
+
processFile(resolved);
|
|
164
|
+
const sourceExports = graph[resolved]?.exports || [];
|
|
165
|
+
for (const exp of sourceExports) {
|
|
166
|
+
exports.push({ ...exp });
|
|
140
167
|
}
|
|
141
168
|
}
|
|
142
169
|
}
|
|
@@ -159,8 +186,7 @@ function extractExports(ast: Module): SymbolInfo[] {
|
|
|
159
186
|
name: "default",
|
|
160
187
|
kind,
|
|
161
188
|
isDefault: true,
|
|
162
|
-
decorators:
|
|
163
|
-
decorators && decorators.length > 0 ? decorators : undefined,
|
|
189
|
+
decorators: decorators?.length ? decorators : undefined,
|
|
164
190
|
});
|
|
165
191
|
}
|
|
166
192
|
|
|
@@ -172,36 +198,13 @@ function extractExports(ast: Module): SymbolInfo[] {
|
|
|
172
198
|
return exports;
|
|
173
199
|
}
|
|
174
200
|
|
|
175
|
-
function extractImports(
|
|
176
|
-
ast: Module
|
|
177
|
-
): Array<{ path: string; specifiers: any[] }> {
|
|
178
|
-
const imports: Array<{ path: string; specifiers: any[] }> = [];
|
|
179
|
-
|
|
180
|
-
for (const item of ast.body) {
|
|
181
|
-
if (item.type === "ImportDeclaration") {
|
|
182
|
-
imports.push({
|
|
183
|
-
path: item.source.value,
|
|
184
|
-
specifiers: item.specifiers,
|
|
185
|
-
});
|
|
186
|
-
}
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
return imports;
|
|
190
|
-
}
|
|
191
|
-
|
|
192
201
|
export function buildGraph(entryPoints: string[]): DependencyGraph {
|
|
193
202
|
const graph: DependencyGraph = {};
|
|
194
203
|
const visited = new Set<string>();
|
|
195
204
|
|
|
196
205
|
function processFile(filePath: string): void {
|
|
197
|
-
const
|
|
198
|
-
|
|
199
|
-
filePath.endsWith(".tsx") ||
|
|
200
|
-
filePath.endsWith(".js") ||
|
|
201
|
-
filePath.endsWith(".jsx");
|
|
202
|
-
|
|
203
|
-
if (!allowed) return;
|
|
204
|
-
|
|
206
|
+
const allowedExt = [".ts", ".tsx", ".js", ".jsx"];
|
|
207
|
+
if (!allowedExt.includes(path.extname(filePath))) return;
|
|
205
208
|
if (visited.has(filePath)) return;
|
|
206
209
|
visited.add(filePath);
|
|
207
210
|
|
|
@@ -210,9 +213,11 @@ export function buildGraph(entryPoints: string[]): DependencyGraph {
|
|
|
210
213
|
return;
|
|
211
214
|
}
|
|
212
215
|
|
|
213
|
-
const isTsx =
|
|
216
|
+
const isTsx = [".tsx", ".jsx"].includes(path.extname(filePath));
|
|
217
|
+
const store = Store.getInstance();
|
|
218
|
+
const newCode = store.get<string>(filePath);
|
|
219
|
+
const content = newCode ? newCode[0] : fs.readFileSync(filePath, "utf-8");
|
|
214
220
|
|
|
215
|
-
const content = fs.readFileSync(filePath, "utf-8");
|
|
216
221
|
const ast = parseSync(content, {
|
|
217
222
|
syntax: "typescript",
|
|
218
223
|
tsx: isTsx,
|
|
@@ -220,72 +225,55 @@ export function buildGraph(entryPoints: string[]): DependencyGraph {
|
|
|
220
225
|
});
|
|
221
226
|
|
|
222
227
|
const directive = extractDirective(ast);
|
|
223
|
-
const exports = extractExports(ast);
|
|
224
228
|
const rawImports = extractImports(ast);
|
|
229
|
+
const exports = extractExports(ast, filePath, graph, processFile);
|
|
225
230
|
|
|
226
231
|
for (const { path: importPath } of rawImports) {
|
|
227
232
|
const resolved = resolveFilePath(filePath, importPath);
|
|
228
|
-
if (resolved)
|
|
229
|
-
processFile(resolved);
|
|
230
|
-
}
|
|
233
|
+
if (resolved) processFile(resolved);
|
|
231
234
|
}
|
|
232
235
|
|
|
233
|
-
const imports: ImportInfo[] =
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
kind: "namespace"
|
|
253
|
-
})
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
decorators: exportedSymbol?.decorators,
|
|
265
|
-
});
|
|
236
|
+
const imports: ImportInfo[] = rawImports.map(
|
|
237
|
+
({ path: importPath, specifiers }) => {
|
|
238
|
+
const resolvedPath = resolveFilePath(filePath, importPath);
|
|
239
|
+
const sourceExports =
|
|
240
|
+
resolvedPath && graph[resolvedPath]
|
|
241
|
+
? graph[resolvedPath].exports
|
|
242
|
+
: [];
|
|
243
|
+
const symbols: SymbolInfo[] = [];
|
|
244
|
+
|
|
245
|
+
for (const spec of specifiers) {
|
|
246
|
+
if (spec.type === "ImportDefaultSpecifier") {
|
|
247
|
+
const def = sourceExports.find((e) => e.isDefault);
|
|
248
|
+
symbols.push({
|
|
249
|
+
name: spec.local.value,
|
|
250
|
+
kind: def?.kind || "unknown",
|
|
251
|
+
decorators: def?.decorators,
|
|
252
|
+
isDefault: true,
|
|
253
|
+
});
|
|
254
|
+
} else if (spec.type === "ImportNamespaceSpecifier") {
|
|
255
|
+
symbols.push({ name: spec.local.value, kind: "namespace" });
|
|
256
|
+
} else if (spec.type === "ImportSpecifier") {
|
|
257
|
+
const importedName = spec.imported
|
|
258
|
+
? spec.imported.value
|
|
259
|
+
: spec.local.value;
|
|
260
|
+
const exp = sourceExports.find((e) => e.name === importedName);
|
|
261
|
+
symbols.push({
|
|
262
|
+
name: importedName,
|
|
263
|
+
kind: exp?.kind || "unknown",
|
|
264
|
+
decorators: exp?.decorators,
|
|
265
|
+
});
|
|
266
|
+
}
|
|
266
267
|
}
|
|
267
|
-
}
|
|
268
268
|
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
symbols,
|
|
273
|
-
});
|
|
274
|
-
}
|
|
269
|
+
return { sourcePath: importPath, resolvedPath, symbols };
|
|
270
|
+
}
|
|
271
|
+
);
|
|
275
272
|
|
|
276
|
-
graph[filePath] = {
|
|
277
|
-
filePath,
|
|
278
|
-
isTsx,
|
|
279
|
-
directive,
|
|
280
|
-
imports,
|
|
281
|
-
exports,
|
|
282
|
-
};
|
|
273
|
+
graph[filePath] = { filePath, isTsx, directive, imports, exports };
|
|
283
274
|
}
|
|
284
275
|
|
|
285
|
-
for (const entry of entryPoints)
|
|
286
|
-
const resolved = path.resolve(entry);
|
|
287
|
-
processFile(resolved);
|
|
288
|
-
}
|
|
276
|
+
for (const entry of entryPoints) processFile(path.resolve(entry));
|
|
289
277
|
|
|
290
278
|
return graph;
|
|
291
279
|
}
|
|
@@ -12,6 +12,7 @@ interface ClassStub {
|
|
|
12
12
|
name: string;
|
|
13
13
|
propsType: string;
|
|
14
14
|
decorators: string[];
|
|
15
|
+
constructorParams: string[]; // added for constructor arguments
|
|
15
16
|
}
|
|
16
17
|
|
|
17
18
|
interface ImportMap {
|
|
@@ -119,6 +120,7 @@ function extractClassStub(classDecl: ClassDeclaration): ClassStub | null {
|
|
|
119
120
|
|
|
120
121
|
let propsType = "{}";
|
|
121
122
|
const decorators: string[] = [];
|
|
123
|
+
const constructorParams: string[] = [];
|
|
122
124
|
|
|
123
125
|
if (classDecl.decorators) {
|
|
124
126
|
for (const dec of classDecl.decorators) {
|
|
@@ -132,6 +134,11 @@ function extractClassStub(classDecl: ClassDeclaration): ClassStub | null {
|
|
|
132
134
|
if (member.key.type === "Identifier" && member.key.value === "props") {
|
|
133
135
|
propsType = extractPropsType(member);
|
|
134
136
|
}
|
|
137
|
+
} else if (member.type === "Constructor") {
|
|
138
|
+
for (const param of member.params) {
|
|
139
|
+
const paramStr = stringifyParam(param);
|
|
140
|
+
if (paramStr) constructorParams.push(paramStr);
|
|
141
|
+
}
|
|
135
142
|
}
|
|
136
143
|
}
|
|
137
144
|
|
|
@@ -139,18 +146,27 @@ function extractClassStub(classDecl: ClassDeclaration): ClassStub | null {
|
|
|
139
146
|
name: className,
|
|
140
147
|
propsType,
|
|
141
148
|
decorators,
|
|
149
|
+
constructorParams,
|
|
142
150
|
};
|
|
143
151
|
}
|
|
144
152
|
|
|
145
|
-
function stringifyDecorator(decorator: Decorator): string {
|
|
146
|
-
const
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
153
|
+
export function stringifyDecorator(decorator: Decorator): string {
|
|
154
|
+
const exprCode = printSync({
|
|
155
|
+
type: "Module",
|
|
156
|
+
span: { start: 0, end: 0, ctxt: 0 },
|
|
157
|
+
body: [
|
|
158
|
+
{
|
|
159
|
+
type: "ExpressionStatement",
|
|
160
|
+
expression: decorator.expression,
|
|
161
|
+
span: { start: 0, end: 0, ctxt: 0 },
|
|
162
|
+
},
|
|
163
|
+
],
|
|
164
|
+
interpreter: "",
|
|
165
|
+
}).code;
|
|
166
|
+
|
|
167
|
+
const cleanCode = exprCode.replace(/^#!.*\n/, "").trim();
|
|
168
|
+
|
|
169
|
+
return `@${cleanCode.replace(/;$/, "")}`;
|
|
154
170
|
}
|
|
155
171
|
|
|
156
172
|
function extractPropsType(member: any): string {
|
|
@@ -269,10 +285,14 @@ function generateClassCode(
|
|
|
269
285
|
const decoratorsStr =
|
|
270
286
|
stub.decorators.length > 0 ? stub.decorators.join("\n") + "\n" : "";
|
|
271
287
|
|
|
288
|
+
const constructorStr = stub.constructorParams.length
|
|
289
|
+
? `constructor(${stub.constructorParams.join(", ")}) {}`
|
|
290
|
+
: "constructor() {}";
|
|
291
|
+
|
|
272
292
|
return `
|
|
273
293
|
${decoratorsStr}export class ${stub.name} {
|
|
274
294
|
props!: ${stub.propsType};
|
|
275
|
-
|
|
295
|
+
${constructorStr}
|
|
276
296
|
build() {
|
|
277
297
|
const inputProps = { ...this.props };
|
|
278
298
|
return {
|
package/src/plugins/my.ts
CHANGED
|
@@ -10,6 +10,7 @@ import { generateServerStub } from "./generators/tsx_server_stub";
|
|
|
10
10
|
import { j2d } from "./transformers/j2d";
|
|
11
11
|
import { generateServerComponent } from "./generators/generate_server_component";
|
|
12
12
|
import { generateRscStub } from "./generators/generate_rsc";
|
|
13
|
+
import { Store } from "@/store";
|
|
13
14
|
|
|
14
15
|
interface MyPluginParams {
|
|
15
16
|
isServerBuild: boolean;
|
|
@@ -123,6 +124,7 @@ class ServerBuildTransformer {
|
|
|
123
124
|
path: string
|
|
124
125
|
): Promise<OnLoadResult> {
|
|
125
126
|
const stubSource = generateServerStub(path, source);
|
|
127
|
+
|
|
126
128
|
return swcTransform(stubSource, path);
|
|
127
129
|
}
|
|
128
130
|
|
|
@@ -139,7 +141,13 @@ class ServerBuildTransformer {
|
|
|
139
141
|
if (isTsx) {
|
|
140
142
|
if (isInteractiveFile) {
|
|
141
143
|
onClientFound(path);
|
|
142
|
-
|
|
144
|
+
const clientCode = await this.transformInteractiveTsxStub(source, path);
|
|
145
|
+
|
|
146
|
+
const store = Store.getInstance();
|
|
147
|
+
|
|
148
|
+
store.set(path, clientCode.contents);
|
|
149
|
+
|
|
150
|
+
return clientCode;
|
|
143
151
|
}
|
|
144
152
|
return this.transformServerTsx(source, path);
|
|
145
153
|
}
|
|
@@ -260,10 +268,10 @@ export function useMyPlugin(options: MyPluginParams): Plugin {
|
|
|
260
268
|
}
|
|
261
269
|
|
|
262
270
|
const node = options.graph[args.path];
|
|
271
|
+
|
|
263
272
|
if (!node) {
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
);
|
|
273
|
+
console.log(`File node not found in depend graph: ${args.path}`);
|
|
274
|
+
throw new Error("900");
|
|
267
275
|
}
|
|
268
276
|
|
|
269
277
|
return clientTransformer.process(node, metadata);
|