@tanstack/start-plugin-core 1.142.2 → 1.142.4
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.
|
@@ -32,7 +32,8 @@ class ServerFnCompiler {
|
|
|
32
32
|
bindings: /* @__PURE__ */ new Map(),
|
|
33
33
|
exports: /* @__PURE__ */ new Map(),
|
|
34
34
|
code: "",
|
|
35
|
-
id: libId
|
|
35
|
+
id: libId,
|
|
36
|
+
reExportAllSources: []
|
|
36
37
|
};
|
|
37
38
|
this.moduleCache.set(libId, rootModule);
|
|
38
39
|
}
|
|
@@ -59,6 +60,7 @@ class ServerFnCompiler {
|
|
|
59
60
|
const ast = parseAst({ code });
|
|
60
61
|
const bindings = /* @__PURE__ */ new Map();
|
|
61
62
|
const exports = /* @__PURE__ */ new Map();
|
|
63
|
+
const reExportAllSources = [];
|
|
62
64
|
for (const node of ast.program.body) {
|
|
63
65
|
if (t.isImportDeclaration(node)) {
|
|
64
66
|
const source = node.source.value;
|
|
@@ -111,6 +113,13 @@ class ServerFnCompiler {
|
|
|
111
113
|
const local = sp.local.name;
|
|
112
114
|
const exported = t.isIdentifier(sp.exported) ? sp.exported.name : sp.exported.value;
|
|
113
115
|
exports.set(exported, { tag: "Normal", name: local });
|
|
116
|
+
if (node.source) {
|
|
117
|
+
bindings.set(local, {
|
|
118
|
+
type: "import",
|
|
119
|
+
source: node.source.value,
|
|
120
|
+
importedName: local
|
|
121
|
+
});
|
|
122
|
+
}
|
|
114
123
|
}
|
|
115
124
|
}
|
|
116
125
|
} else if (t.isExportDefaultDeclaration(node)) {
|
|
@@ -122,9 +131,18 @@ class ServerFnCompiler {
|
|
|
122
131
|
bindings.set(synth, { type: "var", init: d });
|
|
123
132
|
exports.set("default", { tag: "Default", name: synth });
|
|
124
133
|
}
|
|
134
|
+
} else if (t.isExportAllDeclaration(node)) {
|
|
135
|
+
reExportAllSources.push(node.source.value);
|
|
125
136
|
}
|
|
126
137
|
}
|
|
127
|
-
const info = {
|
|
138
|
+
const info = {
|
|
139
|
+
code,
|
|
140
|
+
id,
|
|
141
|
+
ast,
|
|
142
|
+
bindings,
|
|
143
|
+
exports,
|
|
144
|
+
reExportAllSources
|
|
145
|
+
};
|
|
128
146
|
this.moduleCache.set(id, info);
|
|
129
147
|
return info;
|
|
130
148
|
}
|
|
@@ -234,6 +252,37 @@ class ServerFnCompiler {
|
|
|
234
252
|
}
|
|
235
253
|
const importedModule = await this.getModuleInfo(target);
|
|
236
254
|
const moduleExport = importedModule.exports.get(binding.importedName);
|
|
255
|
+
if (!moduleExport && importedModule.reExportAllSources.length > 0) {
|
|
256
|
+
for (const reExportSource of importedModule.reExportAllSources) {
|
|
257
|
+
const reExportTarget = await this.options.resolveId(
|
|
258
|
+
reExportSource,
|
|
259
|
+
importedModule.id
|
|
260
|
+
);
|
|
261
|
+
if (reExportTarget) {
|
|
262
|
+
const reExportModule = await this.getModuleInfo(reExportTarget);
|
|
263
|
+
const reExportEntry = reExportModule.exports.get(
|
|
264
|
+
binding.importedName
|
|
265
|
+
);
|
|
266
|
+
if (reExportEntry) {
|
|
267
|
+
const reExportBinding = reExportModule.bindings.get(
|
|
268
|
+
reExportEntry.name
|
|
269
|
+
);
|
|
270
|
+
if (reExportBinding) {
|
|
271
|
+
if (reExportBinding.resolvedKind) {
|
|
272
|
+
return reExportBinding.resolvedKind;
|
|
273
|
+
}
|
|
274
|
+
const resolvedKind3 = await this.resolveBindingKind(
|
|
275
|
+
reExportBinding,
|
|
276
|
+
reExportModule.id,
|
|
277
|
+
visited
|
|
278
|
+
);
|
|
279
|
+
reExportBinding.resolvedKind = resolvedKind3;
|
|
280
|
+
return resolvedKind3;
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
}
|
|
237
286
|
if (!moduleExport) {
|
|
238
287
|
return "None";
|
|
239
288
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"compiler.js","sources":["../../../src/create-server-fn-plugin/compiler.ts"],"sourcesContent":["/* eslint-disable import/no-commonjs */\nimport * as t from '@babel/types'\nimport { generateFromAst, parseAst } from '@tanstack/router-utils'\nimport babel from '@babel/core'\nimport {\n deadCodeElimination,\n findReferencedIdentifiers,\n} from 'babel-dead-code-elimination'\nimport { handleCreateServerFn } from './handleCreateServerFn'\nimport { handleCreateMiddleware } from './handleCreateMiddleware'\n\ntype Binding =\n | {\n type: 'import'\n source: string\n importedName: string\n resolvedKind?: Kind\n }\n | {\n type: 'var'\n init: t.Expression | null\n resolvedKind?: Kind\n }\n\ntype ExportEntry =\n | { tag: 'Normal'; name: string }\n | { tag: 'Default'; name: string }\n | { tag: 'Namespace'; name: string; targetId: string } // for `export * as ns from './x'`\n\ntype Kind = 'None' | `Root` | `Builder` | LookupKind\n\nexport type LookupKind = 'ServerFn' | 'Middleware'\n\nconst LookupSetup: Record<\n LookupKind,\n { candidateCallIdentifier: Set<string> }\n> = {\n ServerFn: { candidateCallIdentifier: new Set(['handler']) },\n Middleware: {\n candidateCallIdentifier: new Set(['server', 'client', 'createMiddlewares']),\n },\n}\n\nexport type LookupConfig = {\n libName: string\n rootExport: string\n}\ninterface ModuleInfo {\n id: string\n code: string\n ast: ReturnType<typeof parseAst>\n bindings: Map<string, Binding>\n exports: Map<string, ExportEntry>\n}\n\nexport class ServerFnCompiler {\n private moduleCache = new Map<string, ModuleInfo>()\n private initialized = false\n private validLookupKinds: Set<LookupKind>\n constructor(\n private options: {\n env: 'client' | 'server'\n directive: string\n lookupConfigurations: Array<LookupConfig>\n lookupKinds: Set<LookupKind>\n loadModule: (id: string) => Promise<void>\n resolveId: (id: string, importer?: string) => Promise<string | null>\n },\n ) {\n this.validLookupKinds = options.lookupKinds\n }\n\n private async init(id: string) {\n await Promise.all(\n this.options.lookupConfigurations.map(async (config) => {\n const libId = await this.options.resolveId(config.libName, id)\n if (!libId) {\n throw new Error(`could not resolve \"${config.libName}\"`)\n }\n let rootModule = this.moduleCache.get(libId)\n if (!rootModule) {\n // insert root binding\n rootModule = {\n ast: null as any,\n bindings: new Map(),\n exports: new Map(),\n code: '',\n id: libId,\n }\n this.moduleCache.set(libId, rootModule)\n }\n\n rootModule.exports.set(config.rootExport, {\n tag: 'Normal',\n name: config.rootExport,\n })\n rootModule.exports.set('*', {\n tag: 'Namespace',\n name: config.rootExport,\n targetId: libId,\n })\n rootModule.bindings.set(config.rootExport, {\n type: 'var',\n init: t.identifier(config.rootExport),\n resolvedKind: `Root` satisfies Kind,\n })\n this.moduleCache.set(libId, rootModule)\n }),\n )\n\n this.initialized = true\n }\n\n public ingestModule({ code, id }: { code: string; id: string }) {\n const ast = parseAst({ code })\n\n const bindings = new Map<string, Binding>()\n const exports = new Map<string, ExportEntry>()\n\n // we are only interested in top-level bindings, hence we don't traverse the AST\n // instead we only iterate over the program body\n for (const node of ast.program.body) {\n if (t.isImportDeclaration(node)) {\n const source = node.source.value\n for (const s of node.specifiers) {\n if (t.isImportSpecifier(s)) {\n const importedName = t.isIdentifier(s.imported)\n ? s.imported.name\n : s.imported.value\n bindings.set(s.local.name, { type: 'import', source, importedName })\n } else if (t.isImportDefaultSpecifier(s)) {\n bindings.set(s.local.name, {\n type: 'import',\n source,\n importedName: 'default',\n })\n } else if (t.isImportNamespaceSpecifier(s)) {\n bindings.set(s.local.name, {\n type: 'import',\n source,\n importedName: '*',\n })\n }\n }\n } else if (t.isVariableDeclaration(node)) {\n for (const decl of node.declarations) {\n if (t.isIdentifier(decl.id)) {\n bindings.set(decl.id.name, {\n type: 'var',\n init: decl.init ?? null,\n })\n }\n }\n } else if (t.isExportNamedDeclaration(node)) {\n // export const foo = ...\n if (node.declaration) {\n if (t.isVariableDeclaration(node.declaration)) {\n for (const d of node.declaration.declarations) {\n if (t.isIdentifier(d.id)) {\n exports.set(d.id.name, { tag: 'Normal', name: d.id.name })\n bindings.set(d.id.name, { type: 'var', init: d.init ?? null })\n }\n }\n }\n }\n for (const sp of node.specifiers) {\n if (t.isExportNamespaceSpecifier(sp)) {\n exports.set(sp.exported.name, {\n tag: 'Namespace',\n name: sp.exported.name,\n targetId: node.source?.value || '',\n })\n }\n // export { local as exported }\n else if (t.isExportSpecifier(sp)) {\n const local = sp.local.name\n const exported = t.isIdentifier(sp.exported)\n ? sp.exported.name\n : sp.exported.value\n exports.set(exported, { tag: 'Normal', name: local })\n }\n }\n } else if (t.isExportDefaultDeclaration(node)) {\n const d = node.declaration\n if (t.isIdentifier(d)) {\n exports.set('default', { tag: 'Default', name: d.name })\n } else {\n const synth = '__default_export__'\n bindings.set(synth, { type: 'var', init: d as t.Expression })\n exports.set('default', { tag: 'Default', name: synth })\n }\n }\n }\n\n const info: ModuleInfo = { code, id, ast, bindings, exports }\n this.moduleCache.set(id, info)\n return info\n }\n\n public invalidateModule(id: string) {\n return this.moduleCache.delete(id)\n }\n\n public async compile({\n code,\n id,\n isProviderFile,\n }: {\n code: string\n id: string\n isProviderFile: boolean\n }) {\n if (!this.initialized) {\n await this.init(id)\n }\n const { bindings, ast } = this.ingestModule({ code, id })\n const candidates = this.collectCandidates(bindings)\n if (candidates.length === 0) {\n // this hook will only be invoked if there is `.handler(` | `.server(` | `.client(` in the code,\n // so not discovering a handler candidate is rather unlikely, but maybe possible?\n return null\n }\n\n // let's find out which of the candidates are actually server functions\n const toRewrite: Array<{\n callExpression: t.CallExpression\n kind: LookupKind\n }> = []\n for (const handler of candidates) {\n const kind = await this.resolveExprKind(handler, id)\n if (this.validLookupKinds.has(kind as LookupKind)) {\n toRewrite.push({ callExpression: handler, kind: kind as LookupKind })\n }\n }\n if (toRewrite.length === 0) {\n return null\n }\n\n const pathsToRewrite: Array<{\n nodePath: babel.NodePath<t.CallExpression>\n kind: LookupKind\n }> = []\n babel.traverse(ast, {\n CallExpression(path) {\n const found = toRewrite.findIndex((h) => path.node === h.callExpression)\n if (found !== -1) {\n pathsToRewrite.push({ nodePath: path, kind: toRewrite[found]!.kind })\n // delete from toRewrite\n toRewrite.splice(found, 1)\n }\n },\n })\n\n if (toRewrite.length > 0) {\n throw new Error(\n `Internal error: could not find all paths to rewrite. please file an issue`,\n )\n }\n\n const refIdents = findReferencedIdentifiers(ast)\n\n pathsToRewrite.map((p) => {\n if (p.kind === 'ServerFn') {\n handleCreateServerFn(p.nodePath, {\n env: this.options.env,\n code,\n directive: this.options.directive,\n isProviderFile,\n })\n } else {\n handleCreateMiddleware(p.nodePath, { env: this.options.env })\n }\n })\n\n deadCodeElimination(ast, refIdents)\n\n return generateFromAst(ast, {\n sourceMaps: true,\n sourceFileName: id,\n filename: id,\n })\n }\n\n // collects all candidate CallExpressions at top-level\n private collectCandidates(bindings: Map<string, Binding>) {\n const candidates: Array<t.CallExpression> = []\n\n for (const binding of bindings.values()) {\n if (binding.type === 'var') {\n const handler = isCandidateCallExpression(\n binding.init,\n this.validLookupKinds,\n )\n if (handler) {\n candidates.push(handler)\n }\n }\n }\n return candidates\n }\n\n private async resolveIdentifierKind(\n ident: string,\n id: string,\n visited = new Set<string>(),\n ): Promise<Kind> {\n const info = await this.getModuleInfo(id)\n\n const binding = info.bindings.get(ident)\n if (!binding) {\n return 'None'\n }\n if (binding.resolvedKind) {\n return binding.resolvedKind\n }\n\n // TODO improve cycle detection? should we throw here instead of returning 'None'?\n // prevent cycles\n const vKey = `${id}:${ident}`\n if (visited.has(vKey)) {\n return 'None'\n }\n visited.add(vKey)\n\n const resolvedKind = await this.resolveBindingKind(binding, id, visited)\n binding.resolvedKind = resolvedKind\n return resolvedKind\n }\n\n private async resolveBindingKind(\n binding: Binding,\n fileId: string,\n visited = new Set<string>(),\n ): Promise<Kind> {\n if (binding.resolvedKind) {\n return binding.resolvedKind\n }\n if (binding.type === 'import') {\n const target = await this.options.resolveId(binding.source, fileId)\n if (!target) {\n return 'None'\n }\n\n const importedModule = await this.getModuleInfo(target)\n\n const moduleExport = importedModule.exports.get(binding.importedName)\n if (!moduleExport) {\n return 'None'\n }\n const importedBinding = importedModule.bindings.get(moduleExport.name)\n if (!importedBinding) {\n return 'None'\n }\n if (importedBinding.resolvedKind) {\n return importedBinding.resolvedKind\n }\n\n const resolvedKind = await this.resolveBindingKind(\n importedBinding,\n importedModule.id,\n visited,\n )\n importedBinding.resolvedKind = resolvedKind\n return resolvedKind\n }\n\n const resolvedKind = await this.resolveExprKind(\n binding.init,\n fileId,\n visited,\n )\n binding.resolvedKind = resolvedKind\n return resolvedKind\n }\n\n private async resolveExprKind(\n expr: t.Expression | null,\n fileId: string,\n visited = new Set<string>(),\n ): Promise<Kind> {\n if (!expr) {\n return 'None'\n }\n\n let result: Kind = 'None'\n\n if (t.isCallExpression(expr)) {\n if (!t.isExpression(expr.callee)) {\n return 'None'\n }\n const calleeKind = await this.resolveCalleeKind(\n expr.callee,\n fileId,\n visited,\n )\n if (calleeKind !== 'None') {\n if (calleeKind === `Root` || calleeKind === `Builder`) {\n return `Builder`\n }\n for (const kind of this.validLookupKinds) {\n if (calleeKind === kind) {\n return kind\n }\n }\n }\n } else if (t.isMemberExpression(expr) && t.isIdentifier(expr.property)) {\n result = await this.resolveCalleeKind(expr.object, fileId, visited)\n }\n\n if (result === 'None' && t.isIdentifier(expr)) {\n result = await this.resolveIdentifierKind(expr.name, fileId, visited)\n }\n\n if (result === 'None' && t.isTSAsExpression(expr)) {\n result = await this.resolveExprKind(expr.expression, fileId, visited)\n }\n if (result === 'None' && t.isTSNonNullExpression(expr)) {\n result = await this.resolveExprKind(expr.expression, fileId, visited)\n }\n if (result === 'None' && t.isParenthesizedExpression(expr)) {\n result = await this.resolveExprKind(expr.expression, fileId, visited)\n }\n\n return result\n }\n\n private async resolveCalleeKind(\n callee: t.Expression,\n fileId: string,\n visited = new Set<string>(),\n ): Promise<Kind> {\n if (t.isIdentifier(callee)) {\n return this.resolveIdentifierKind(callee.name, fileId, visited)\n }\n\n if (t.isMemberExpression(callee) && t.isIdentifier(callee.property)) {\n const prop = callee.property.name\n\n if (\n this.validLookupKinds.has('ServerFn') &&\n LookupSetup['ServerFn'].candidateCallIdentifier.has(prop)\n ) {\n const base = await this.resolveExprKind(callee.object, fileId, visited)\n if (base === 'Root' || base === 'Builder') {\n return 'ServerFn'\n }\n return 'None'\n } else if (\n this.validLookupKinds.has('Middleware') &&\n LookupSetup['Middleware'].candidateCallIdentifier.has(prop)\n ) {\n const base = await this.resolveExprKind(callee.object, fileId, visited)\n if (base === 'Root' || base === 'Builder' || base === 'Middleware') {\n return 'Middleware'\n }\n return 'None'\n }\n // Check if the object is a namespace import\n if (t.isIdentifier(callee.object)) {\n const info = await this.getModuleInfo(fileId)\n const binding = info.bindings.get(callee.object.name)\n if (\n binding &&\n binding.type === 'import' &&\n binding.importedName === '*'\n ) {\n // resolve the property from the target module\n const targetModuleId = await this.options.resolveId(\n binding.source,\n fileId,\n )\n if (targetModuleId) {\n const targetModule = await this.getModuleInfo(targetModuleId)\n const exportEntry = targetModule.exports.get(callee.property.name)\n if (exportEntry) {\n const exportedBinding = targetModule.bindings.get(\n exportEntry.name,\n )\n if (exportedBinding) {\n return await this.resolveBindingKind(\n exportedBinding,\n targetModule.id,\n visited,\n )\n }\n }\n } else {\n return 'None'\n }\n }\n }\n return this.resolveExprKind(callee.object, fileId, visited)\n }\n\n // handle nested expressions\n return this.resolveExprKind(callee, fileId, visited)\n }\n\n private async getModuleInfo(id: string) {\n let cached = this.moduleCache.get(id)\n if (cached) {\n return cached\n }\n\n await this.options.loadModule(id)\n\n cached = this.moduleCache.get(id)\n if (!cached) {\n throw new Error(`could not load module info for ${id}`)\n }\n return cached\n }\n}\n\nfunction isCandidateCallExpression(\n node: t.Node | null | undefined,\n lookupKinds: Set<LookupKind>,\n): undefined | t.CallExpression {\n if (!t.isCallExpression(node)) return undefined\n\n const callee = node.callee\n if (!t.isMemberExpression(callee) || !t.isIdentifier(callee.property)) {\n return undefined\n }\n for (const kind of lookupKinds) {\n if (LookupSetup[kind].candidateCallIdentifier.has(callee.property.name)) {\n return node\n }\n }\n\n return undefined\n}\n"],"names":["babel","resolvedKind"],"mappings":";;;;;;AAiCA,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a;AAC9B,QAAI,YAAY,IAAI,EAAE,wBAAwB,IAAI,OAAO,SAAS,IAAI,GAAG;AACvE,aAAO;AAAA,IACT;AAAA,EACF;AAEA,SAAO;AACT;"}
|
|
1
|
+
{"version":3,"file":"compiler.js","sources":["../../../src/create-server-fn-plugin/compiler.ts"],"sourcesContent":["/* eslint-disable import/no-commonjs */\nimport * as t from '@babel/types'\nimport { generateFromAst, parseAst } from '@tanstack/router-utils'\nimport babel from '@babel/core'\nimport {\n deadCodeElimination,\n findReferencedIdentifiers,\n} from 'babel-dead-code-elimination'\nimport { handleCreateServerFn } from './handleCreateServerFn'\nimport { handleCreateMiddleware } from './handleCreateMiddleware'\n\ntype Binding =\n | {\n type: 'import'\n source: string\n importedName: string\n resolvedKind?: Kind\n }\n | {\n type: 'var'\n init: t.Expression | null\n resolvedKind?: Kind\n }\n\ntype ExportEntry =\n | { tag: 'Normal'; name: string }\n | { tag: 'Default'; name: string }\n | { tag: 'Namespace'; name: string; targetId: string } // for `export * as ns from './x'`\n\ntype Kind = 'None' | `Root` | `Builder` | LookupKind\n\nexport type LookupKind = 'ServerFn' | 'Middleware'\n\nconst LookupSetup: Record<\n LookupKind,\n { candidateCallIdentifier: Set<string> }\n> = {\n ServerFn: { candidateCallIdentifier: new Set(['handler']) },\n Middleware: {\n candidateCallIdentifier: new Set(['server', 'client', 'createMiddlewares']),\n },\n}\n\nexport type LookupConfig = {\n libName: string\n rootExport: string\n}\ninterface ModuleInfo {\n id: string\n code: string\n ast: ReturnType<typeof parseAst>\n bindings: Map<string, Binding>\n exports: Map<string, ExportEntry>\n // Track `export * from './module'` declarations for re-export resolution\n reExportAllSources: Array<string>\n}\n\nexport class ServerFnCompiler {\n private moduleCache = new Map<string, ModuleInfo>()\n private initialized = false\n private validLookupKinds: Set<LookupKind>\n constructor(\n private options: {\n env: 'client' | 'server'\n directive: string\n lookupConfigurations: Array<LookupConfig>\n lookupKinds: Set<LookupKind>\n loadModule: (id: string) => Promise<void>\n resolveId: (id: string, importer?: string) => Promise<string | null>\n },\n ) {\n this.validLookupKinds = options.lookupKinds\n }\n\n private async init(id: string) {\n await Promise.all(\n this.options.lookupConfigurations.map(async (config) => {\n const libId = await this.options.resolveId(config.libName, id)\n if (!libId) {\n throw new Error(`could not resolve \"${config.libName}\"`)\n }\n let rootModule = this.moduleCache.get(libId)\n if (!rootModule) {\n // insert root binding\n rootModule = {\n ast: null as any,\n bindings: new Map(),\n exports: new Map(),\n code: '',\n id: libId,\n reExportAllSources: [],\n }\n this.moduleCache.set(libId, rootModule)\n }\n\n rootModule.exports.set(config.rootExport, {\n tag: 'Normal',\n name: config.rootExport,\n })\n rootModule.exports.set('*', {\n tag: 'Namespace',\n name: config.rootExport,\n targetId: libId,\n })\n rootModule.bindings.set(config.rootExport, {\n type: 'var',\n init: t.identifier(config.rootExport),\n resolvedKind: `Root` satisfies Kind,\n })\n this.moduleCache.set(libId, rootModule)\n }),\n )\n\n this.initialized = true\n }\n\n public ingestModule({ code, id }: { code: string; id: string }) {\n const ast = parseAst({ code })\n\n const bindings = new Map<string, Binding>()\n const exports = new Map<string, ExportEntry>()\n const reExportAllSources: Array<string> = []\n\n // we are only interested in top-level bindings, hence we don't traverse the AST\n // instead we only iterate over the program body\n for (const node of ast.program.body) {\n if (t.isImportDeclaration(node)) {\n const source = node.source.value\n for (const s of node.specifiers) {\n if (t.isImportSpecifier(s)) {\n const importedName = t.isIdentifier(s.imported)\n ? s.imported.name\n : s.imported.value\n bindings.set(s.local.name, { type: 'import', source, importedName })\n } else if (t.isImportDefaultSpecifier(s)) {\n bindings.set(s.local.name, {\n type: 'import',\n source,\n importedName: 'default',\n })\n } else if (t.isImportNamespaceSpecifier(s)) {\n bindings.set(s.local.name, {\n type: 'import',\n source,\n importedName: '*',\n })\n }\n }\n } else if (t.isVariableDeclaration(node)) {\n for (const decl of node.declarations) {\n if (t.isIdentifier(decl.id)) {\n bindings.set(decl.id.name, {\n type: 'var',\n init: decl.init ?? null,\n })\n }\n }\n } else if (t.isExportNamedDeclaration(node)) {\n // export const foo = ...\n if (node.declaration) {\n if (t.isVariableDeclaration(node.declaration)) {\n for (const d of node.declaration.declarations) {\n if (t.isIdentifier(d.id)) {\n exports.set(d.id.name, { tag: 'Normal', name: d.id.name })\n bindings.set(d.id.name, { type: 'var', init: d.init ?? null })\n }\n }\n }\n }\n for (const sp of node.specifiers) {\n if (t.isExportNamespaceSpecifier(sp)) {\n exports.set(sp.exported.name, {\n tag: 'Namespace',\n name: sp.exported.name,\n targetId: node.source?.value || '',\n })\n }\n // export { local as exported }\n else if (t.isExportSpecifier(sp)) {\n const local = sp.local.name\n const exported = t.isIdentifier(sp.exported)\n ? sp.exported.name\n : sp.exported.value\n exports.set(exported, { tag: 'Normal', name: local })\n\n // When re-exporting from another module (export { foo } from './module'),\n // create an import binding so the server function can be resolved\n if (node.source) {\n bindings.set(local, {\n type: 'import',\n source: node.source.value,\n importedName: local,\n })\n }\n }\n }\n } else if (t.isExportDefaultDeclaration(node)) {\n const d = node.declaration\n if (t.isIdentifier(d)) {\n exports.set('default', { tag: 'Default', name: d.name })\n } else {\n const synth = '__default_export__'\n bindings.set(synth, { type: 'var', init: d as t.Expression })\n exports.set('default', { tag: 'Default', name: synth })\n }\n } else if (t.isExportAllDeclaration(node)) {\n // Handle `export * from './module'` syntax\n // Track the source so we can look up exports from it when needed\n reExportAllSources.push(node.source.value)\n }\n }\n\n const info: ModuleInfo = {\n code,\n id,\n ast,\n bindings,\n exports,\n reExportAllSources,\n }\n this.moduleCache.set(id, info)\n return info\n }\n\n public invalidateModule(id: string) {\n return this.moduleCache.delete(id)\n }\n\n public async compile({\n code,\n id,\n isProviderFile,\n }: {\n code: string\n id: string\n isProviderFile: boolean\n }) {\n if (!this.initialized) {\n await this.init(id)\n }\n const { bindings, ast } = this.ingestModule({ code, id })\n const candidates = this.collectCandidates(bindings)\n if (candidates.length === 0) {\n // this hook will only be invoked if there is `.handler(` | `.server(` | `.client(` in the code,\n // so not discovering a handler candidate is rather unlikely, but maybe possible?\n return null\n }\n\n // let's find out which of the candidates are actually server functions\n const toRewrite: Array<{\n callExpression: t.CallExpression\n kind: LookupKind\n }> = []\n for (const handler of candidates) {\n const kind = await this.resolveExprKind(handler, id)\n if (this.validLookupKinds.has(kind as LookupKind)) {\n toRewrite.push({ callExpression: handler, kind: kind as LookupKind })\n }\n }\n if (toRewrite.length === 0) {\n return null\n }\n\n const pathsToRewrite: Array<{\n nodePath: babel.NodePath<t.CallExpression>\n kind: LookupKind\n }> = []\n babel.traverse(ast, {\n CallExpression(path) {\n const found = toRewrite.findIndex((h) => path.node === h.callExpression)\n if (found !== -1) {\n pathsToRewrite.push({ nodePath: path, kind: toRewrite[found]!.kind })\n // delete from toRewrite\n toRewrite.splice(found, 1)\n }\n },\n })\n\n if (toRewrite.length > 0) {\n throw new Error(\n `Internal error: could not find all paths to rewrite. please file an issue`,\n )\n }\n\n const refIdents = findReferencedIdentifiers(ast)\n\n pathsToRewrite.map((p) => {\n if (p.kind === 'ServerFn') {\n handleCreateServerFn(p.nodePath, {\n env: this.options.env,\n code,\n directive: this.options.directive,\n isProviderFile,\n })\n } else {\n handleCreateMiddleware(p.nodePath, { env: this.options.env })\n }\n })\n\n deadCodeElimination(ast, refIdents)\n\n return generateFromAst(ast, {\n sourceMaps: true,\n sourceFileName: id,\n filename: id,\n })\n }\n\n // collects all candidate CallExpressions at top-level\n private collectCandidates(bindings: Map<string, Binding>) {\n const candidates: Array<t.CallExpression> = []\n\n for (const binding of bindings.values()) {\n if (binding.type === 'var') {\n const handler = isCandidateCallExpression(\n binding.init,\n this.validLookupKinds,\n )\n if (handler) {\n candidates.push(handler)\n }\n }\n }\n return candidates\n }\n\n private async resolveIdentifierKind(\n ident: string,\n id: string,\n visited = new Set<string>(),\n ): Promise<Kind> {\n const info = await this.getModuleInfo(id)\n\n const binding = info.bindings.get(ident)\n if (!binding) {\n return 'None'\n }\n if (binding.resolvedKind) {\n return binding.resolvedKind\n }\n\n // TODO improve cycle detection? should we throw here instead of returning 'None'?\n // prevent cycles\n const vKey = `${id}:${ident}`\n if (visited.has(vKey)) {\n return 'None'\n }\n visited.add(vKey)\n\n const resolvedKind = await this.resolveBindingKind(binding, id, visited)\n binding.resolvedKind = resolvedKind\n return resolvedKind\n }\n\n private async resolveBindingKind(\n binding: Binding,\n fileId: string,\n visited = new Set<string>(),\n ): Promise<Kind> {\n if (binding.resolvedKind) {\n return binding.resolvedKind\n }\n if (binding.type === 'import') {\n const target = await this.options.resolveId(binding.source, fileId)\n if (!target) {\n return 'None'\n }\n\n const importedModule = await this.getModuleInfo(target)\n\n // Try to find the export in the module's direct exports\n const moduleExport = importedModule.exports.get(binding.importedName)\n\n // If not found directly, check re-export-all sources (`export * from './module'`)\n if (!moduleExport && importedModule.reExportAllSources.length > 0) {\n for (const reExportSource of importedModule.reExportAllSources) {\n const reExportTarget = await this.options.resolveId(\n reExportSource,\n importedModule.id,\n )\n if (reExportTarget) {\n const reExportModule = await this.getModuleInfo(reExportTarget)\n const reExportEntry = reExportModule.exports.get(\n binding.importedName,\n )\n if (reExportEntry) {\n // Found the export in a re-exported module, resolve from there\n const reExportBinding = reExportModule.bindings.get(\n reExportEntry.name,\n )\n if (reExportBinding) {\n if (reExportBinding.resolvedKind) {\n return reExportBinding.resolvedKind\n }\n const resolvedKind = await this.resolveBindingKind(\n reExportBinding,\n reExportModule.id,\n visited,\n )\n reExportBinding.resolvedKind = resolvedKind\n return resolvedKind\n }\n }\n }\n }\n }\n\n if (!moduleExport) {\n return 'None'\n }\n const importedBinding = importedModule.bindings.get(moduleExport.name)\n if (!importedBinding) {\n return 'None'\n }\n if (importedBinding.resolvedKind) {\n return importedBinding.resolvedKind\n }\n\n const resolvedKind = await this.resolveBindingKind(\n importedBinding,\n importedModule.id,\n visited,\n )\n importedBinding.resolvedKind = resolvedKind\n return resolvedKind\n }\n\n const resolvedKind = await this.resolveExprKind(\n binding.init,\n fileId,\n visited,\n )\n binding.resolvedKind = resolvedKind\n return resolvedKind\n }\n\n private async resolveExprKind(\n expr: t.Expression | null,\n fileId: string,\n visited = new Set<string>(),\n ): Promise<Kind> {\n if (!expr) {\n return 'None'\n }\n\n let result: Kind = 'None'\n\n if (t.isCallExpression(expr)) {\n if (!t.isExpression(expr.callee)) {\n return 'None'\n }\n const calleeKind = await this.resolveCalleeKind(\n expr.callee,\n fileId,\n visited,\n )\n if (calleeKind !== 'None') {\n if (calleeKind === `Root` || calleeKind === `Builder`) {\n return `Builder`\n }\n for (const kind of this.validLookupKinds) {\n if (calleeKind === kind) {\n return kind\n }\n }\n }\n } else if (t.isMemberExpression(expr) && t.isIdentifier(expr.property)) {\n result = await this.resolveCalleeKind(expr.object, fileId, visited)\n }\n\n if (result === 'None' && t.isIdentifier(expr)) {\n result = await this.resolveIdentifierKind(expr.name, fileId, visited)\n }\n\n if (result === 'None' && t.isTSAsExpression(expr)) {\n result = await this.resolveExprKind(expr.expression, fileId, visited)\n }\n if (result === 'None' && t.isTSNonNullExpression(expr)) {\n result = await this.resolveExprKind(expr.expression, fileId, visited)\n }\n if (result === 'None' && t.isParenthesizedExpression(expr)) {\n result = await this.resolveExprKind(expr.expression, fileId, visited)\n }\n\n return result\n }\n\n private async resolveCalleeKind(\n callee: t.Expression,\n fileId: string,\n visited = new Set<string>(),\n ): Promise<Kind> {\n if (t.isIdentifier(callee)) {\n return this.resolveIdentifierKind(callee.name, fileId, visited)\n }\n\n if (t.isMemberExpression(callee) && t.isIdentifier(callee.property)) {\n const prop = callee.property.name\n\n if (\n this.validLookupKinds.has('ServerFn') &&\n LookupSetup['ServerFn'].candidateCallIdentifier.has(prop)\n ) {\n const base = await this.resolveExprKind(callee.object, fileId, visited)\n if (base === 'Root' || base === 'Builder') {\n return 'ServerFn'\n }\n return 'None'\n } else if (\n this.validLookupKinds.has('Middleware') &&\n LookupSetup['Middleware'].candidateCallIdentifier.has(prop)\n ) {\n const base = await this.resolveExprKind(callee.object, fileId, visited)\n if (base === 'Root' || base === 'Builder' || base === 'Middleware') {\n return 'Middleware'\n }\n return 'None'\n }\n // Check if the object is a namespace import\n if (t.isIdentifier(callee.object)) {\n const info = await this.getModuleInfo(fileId)\n const binding = info.bindings.get(callee.object.name)\n if (\n binding &&\n binding.type === 'import' &&\n binding.importedName === '*'\n ) {\n // resolve the property from the target module\n const targetModuleId = await this.options.resolveId(\n binding.source,\n fileId,\n )\n if (targetModuleId) {\n const targetModule = await this.getModuleInfo(targetModuleId)\n const exportEntry = targetModule.exports.get(callee.property.name)\n if (exportEntry) {\n const exportedBinding = targetModule.bindings.get(\n exportEntry.name,\n )\n if (exportedBinding) {\n return await this.resolveBindingKind(\n exportedBinding,\n targetModule.id,\n visited,\n )\n }\n }\n } else {\n return 'None'\n }\n }\n }\n return this.resolveExprKind(callee.object, fileId, visited)\n }\n\n // handle nested expressions\n return this.resolveExprKind(callee, fileId, visited)\n }\n\n private async getModuleInfo(id: string) {\n let cached = this.moduleCache.get(id)\n if (cached) {\n return cached\n }\n\n await this.options.loadModule(id)\n\n cached = this.moduleCache.get(id)\n if (!cached) {\n throw new Error(`could not load module info for ${id}`)\n }\n return cached\n }\n}\n\nfunction isCandidateCallExpression(\n node: t.Node | null | undefined,\n lookupKinds: Set<LookupKind>,\n): undefined | t.CallExpression {\n if (!t.isCallExpression(node)) return undefined\n\n const callee = node.callee\n if (!t.isMemberExpression(callee) || !t.isIdentifier(callee.property)) {\n return undefined\n }\n for (const kind of lookupKinds) {\n if (LookupSetup[kind].candidateCallIdentifier.has(callee.property.name)) {\n return node\n }\n }\n\n return undefined\n}\n"],"names":["babel","resolvedKind"],"mappings":";;;;;;AAiCA,MAAM,cAGF;AAAA,EACF,UAAU,EAAE,yBAAyB,oBAAI,IAAI,CAAC,SAAS,CAAC,EAAA;AAAA,EACxD,YAAY;AAAA,IACV,yBAAyB,oBAAI,IAAI,CAAC,UAAU,UAAU,mBAAmB,CAAC;AAAA,EAAA;AAE9E;AAgBO,MAAM,iBAAiB;AAAA,EAI5B,YACU,SAQR;AARQ,SA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,kBACb;AAAA,gBAAA;AAAA,cAEJ;AAAA,YACF;AAAA,UACF,OAAO;AACL,mBAAO;AAAA,UACT;AAAA,QACF;AAAA,MACF;AACA,aAAO,KAAK,gBAAgB,OAAO,QAAQ,QAAQ,OAAO;AAAA,IAC5D;AAGA,WAAO,KAAK,gBAAgB,QAAQ,QAAQ,OAAO;AAAA,EACrD;AAAA,EAEA,MAAc,cAAc,IAAY;AACtC,QAAI,SAAS,KAAK,YAAY,IAAI,EAAE;AACpC,QAAI,QAAQ;AACV,aAAO;AAAA,IACT;AAEA,UAAM,KAAK,QAAQ,WAAW,EAAE;AAEhC,aAAS,KAAK,YAAY,IAAI,EAAE;AAChC,QAAI,CAAC,QAAQ;AACX,YAAM,IAAI,MAAM,kCAAkC,EAAE,EAAE;AAAA,IACxD;AACA,WAAO;AAAA,EACT;AACF;AAEA,SAAS,0BACP,MACA,aAC8B;AAC9B,MAAI,CAAC,EAAE,iBAAiB,IAAI,EAAG,QAAO;AAEtC,QAAM,SAAS,KAAK;AACpB,MAAI,CAAC,EAAE,mBAAmB,MAAM,KAAK,CAAC,EAAE,aAAa,OAAO,QAAQ,GAAG;AACrE,WAAO;AAAA,EACT;AACA,aAAW,QAAQ,aAAa;AAC9B,QAAI,YAAY,IAAI,EAAE,wBAAwB,IAAI,OAAO,SAAS,IAAI,GAAG;AACvE,aAAO;AAAA,IACT;AAAA,EACF;AAEA,SAAO;AACT;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tanstack/start-plugin-core",
|
|
3
|
-
"version": "1.142.
|
|
3
|
+
"version": "1.142.4",
|
|
4
4
|
"description": "Modern and scalable routing for React applications",
|
|
5
5
|
"author": "Tanner Linsley",
|
|
6
6
|
"license": "MIT",
|
|
@@ -61,11 +61,11 @@
|
|
|
61
61
|
"zod": "^3.24.2",
|
|
62
62
|
"@tanstack/router-core": "1.141.8",
|
|
63
63
|
"@tanstack/router-generator": "1.142.0",
|
|
64
|
-
"@tanstack/router-utils": "1.141.0",
|
|
65
64
|
"@tanstack/router-plugin": "1.142.0",
|
|
65
|
+
"@tanstack/router-utils": "1.141.0",
|
|
66
66
|
"@tanstack/server-functions-plugin": "1.142.1",
|
|
67
67
|
"@tanstack/start-client-core": "1.142.1",
|
|
68
|
-
"@tanstack/start-server-core": "1.142.
|
|
68
|
+
"@tanstack/start-server-core": "1.142.4"
|
|
69
69
|
},
|
|
70
70
|
"devDependencies": {
|
|
71
71
|
"@types/babel__code-frame": "^7.0.6",
|
|
@@ -51,6 +51,8 @@ interface ModuleInfo {
|
|
|
51
51
|
ast: ReturnType<typeof parseAst>
|
|
52
52
|
bindings: Map<string, Binding>
|
|
53
53
|
exports: Map<string, ExportEntry>
|
|
54
|
+
// Track `export * from './module'` declarations for re-export resolution
|
|
55
|
+
reExportAllSources: Array<string>
|
|
54
56
|
}
|
|
55
57
|
|
|
56
58
|
export class ServerFnCompiler {
|
|
@@ -86,6 +88,7 @@ export class ServerFnCompiler {
|
|
|
86
88
|
exports: new Map(),
|
|
87
89
|
code: '',
|
|
88
90
|
id: libId,
|
|
91
|
+
reExportAllSources: [],
|
|
89
92
|
}
|
|
90
93
|
this.moduleCache.set(libId, rootModule)
|
|
91
94
|
}
|
|
@@ -116,6 +119,7 @@ export class ServerFnCompiler {
|
|
|
116
119
|
|
|
117
120
|
const bindings = new Map<string, Binding>()
|
|
118
121
|
const exports = new Map<string, ExportEntry>()
|
|
122
|
+
const reExportAllSources: Array<string> = []
|
|
119
123
|
|
|
120
124
|
// we are only interested in top-level bindings, hence we don't traverse the AST
|
|
121
125
|
// instead we only iterate over the program body
|
|
@@ -178,6 +182,16 @@ export class ServerFnCompiler {
|
|
|
178
182
|
? sp.exported.name
|
|
179
183
|
: sp.exported.value
|
|
180
184
|
exports.set(exported, { tag: 'Normal', name: local })
|
|
185
|
+
|
|
186
|
+
// When re-exporting from another module (export { foo } from './module'),
|
|
187
|
+
// create an import binding so the server function can be resolved
|
|
188
|
+
if (node.source) {
|
|
189
|
+
bindings.set(local, {
|
|
190
|
+
type: 'import',
|
|
191
|
+
source: node.source.value,
|
|
192
|
+
importedName: local,
|
|
193
|
+
})
|
|
194
|
+
}
|
|
181
195
|
}
|
|
182
196
|
}
|
|
183
197
|
} else if (t.isExportDefaultDeclaration(node)) {
|
|
@@ -189,10 +203,21 @@ export class ServerFnCompiler {
|
|
|
189
203
|
bindings.set(synth, { type: 'var', init: d as t.Expression })
|
|
190
204
|
exports.set('default', { tag: 'Default', name: synth })
|
|
191
205
|
}
|
|
206
|
+
} else if (t.isExportAllDeclaration(node)) {
|
|
207
|
+
// Handle `export * from './module'` syntax
|
|
208
|
+
// Track the source so we can look up exports from it when needed
|
|
209
|
+
reExportAllSources.push(node.source.value)
|
|
192
210
|
}
|
|
193
211
|
}
|
|
194
212
|
|
|
195
|
-
const info: ModuleInfo = {
|
|
213
|
+
const info: ModuleInfo = {
|
|
214
|
+
code,
|
|
215
|
+
id,
|
|
216
|
+
ast,
|
|
217
|
+
bindings,
|
|
218
|
+
exports,
|
|
219
|
+
reExportAllSources,
|
|
220
|
+
}
|
|
196
221
|
this.moduleCache.set(id, info)
|
|
197
222
|
return info
|
|
198
223
|
}
|
|
@@ -343,7 +368,43 @@ export class ServerFnCompiler {
|
|
|
343
368
|
|
|
344
369
|
const importedModule = await this.getModuleInfo(target)
|
|
345
370
|
|
|
371
|
+
// Try to find the export in the module's direct exports
|
|
346
372
|
const moduleExport = importedModule.exports.get(binding.importedName)
|
|
373
|
+
|
|
374
|
+
// If not found directly, check re-export-all sources (`export * from './module'`)
|
|
375
|
+
if (!moduleExport && importedModule.reExportAllSources.length > 0) {
|
|
376
|
+
for (const reExportSource of importedModule.reExportAllSources) {
|
|
377
|
+
const reExportTarget = await this.options.resolveId(
|
|
378
|
+
reExportSource,
|
|
379
|
+
importedModule.id,
|
|
380
|
+
)
|
|
381
|
+
if (reExportTarget) {
|
|
382
|
+
const reExportModule = await this.getModuleInfo(reExportTarget)
|
|
383
|
+
const reExportEntry = reExportModule.exports.get(
|
|
384
|
+
binding.importedName,
|
|
385
|
+
)
|
|
386
|
+
if (reExportEntry) {
|
|
387
|
+
// Found the export in a re-exported module, resolve from there
|
|
388
|
+
const reExportBinding = reExportModule.bindings.get(
|
|
389
|
+
reExportEntry.name,
|
|
390
|
+
)
|
|
391
|
+
if (reExportBinding) {
|
|
392
|
+
if (reExportBinding.resolvedKind) {
|
|
393
|
+
return reExportBinding.resolvedKind
|
|
394
|
+
}
|
|
395
|
+
const resolvedKind = await this.resolveBindingKind(
|
|
396
|
+
reExportBinding,
|
|
397
|
+
reExportModule.id,
|
|
398
|
+
visited,
|
|
399
|
+
)
|
|
400
|
+
reExportBinding.resolvedKind = resolvedKind
|
|
401
|
+
return resolvedKind
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
|
|
347
408
|
if (!moduleExport) {
|
|
348
409
|
return 'None'
|
|
349
410
|
}
|