@tanstack/start-plugin-core 1.158.2 → 1.158.3
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.
|
@@ -172,13 +172,13 @@ function handleCreateServerFn(candidates, context) {
|
|
|
172
172
|
}
|
|
173
173
|
if (isProviderFile) {
|
|
174
174
|
const executeServerArrowFn = t.arrowFunctionExpression(
|
|
175
|
-
[t.identifier("opts")
|
|
175
|
+
[t.identifier("opts")],
|
|
176
176
|
t.callExpression(
|
|
177
177
|
t.memberExpression(
|
|
178
178
|
t.identifier(existingVariableName),
|
|
179
179
|
t.identifier("__executeServer")
|
|
180
180
|
),
|
|
181
|
-
[t.identifier("opts")
|
|
181
|
+
[t.identifier("opts")]
|
|
182
182
|
)
|
|
183
183
|
);
|
|
184
184
|
const serverFnMeta = buildServerFnMetaObject(
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"handleCreateServerFn.js","sources":["../../../src/start-compiler-plugin/handleCreateServerFn.ts"],"sourcesContent":["import * as t from '@babel/types'\nimport babel from '@babel/core'\nimport path from 'pathe'\nimport { VITE_ENVIRONMENT_NAMES } from '../constants'\nimport { cleanId, codeFrameError, stripMethodCall } from './utils'\nimport type { CompilationContext, RewriteCandidate, ServerFn } from './types'\nimport type { CompileStartFrameworkOptions } from '../types'\n\nconst TSS_SERVERFN_SPLIT_PARAM = 'tss-serverfn-split'\n\n// ============================================================================\n// Pre-compiled babel templates (compiled once at module load time)\n// ============================================================================\n\n// Template for provider files: createServerRpc(serverFnMeta, fn)\nconst serverRpcTemplate = babel.template.expression(\n `createServerRpc(%%serverFnMeta%%, %%fn%%)`,\n)\n\n// Template for client caller files: createClientRpc(functionId)\nconst clientRpcTemplate = babel.template.expression(\n `createClientRpc(%%functionId%%)`,\n)\n\n// Template for SSR caller files (manifest lookup): createSsrRpc(functionId)\nconst ssrRpcManifestTemplate = babel.template.expression(\n `createSsrRpc(%%functionId%%)`,\n)\n\n// Template for SSR caller files (with importer): createSsrRpc(functionId, () => import(...).then(m => m['name']))\nconst ssrRpcImporterTemplate = babel.template.expression(\n `createSsrRpc(%%functionId%%, () => import(%%extractedFilename%%).then(m => m[%%functionName%%]))`,\n)\n\n// ============================================================================\n// Runtime code cache (cached per framework to avoid repeated AST generation)\n// ============================================================================\n\ntype RuntimeCodeType = 'provider' | 'client' | 'ssr'\ntype FrameworkRuntimeCache = Record<RuntimeCodeType, t.Statement>\nconst RuntimeCodeCache = new Map<\n CompileStartFrameworkOptions,\n FrameworkRuntimeCache\n>()\n\nfunction getCachedRuntimeCode(\n framework: CompileStartFrameworkOptions,\n type: RuntimeCodeType,\n): t.Statement {\n let cache = RuntimeCodeCache.get(framework)\n if (!cache) {\n cache = {\n provider: babel.template.ast(\n `import { createServerRpc } from '@tanstack/${framework}-start/server-rpc'`,\n { placeholderPattern: false },\n ) as t.Statement,\n client: babel.template.ast(\n `import { createClientRpc } from '@tanstack/${framework}-start/client-rpc'`,\n { placeholderPattern: false },\n ) as t.Statement,\n ssr: babel.template.ast(\n `import { createSsrRpc } from '@tanstack/${framework}-start/ssr-rpc'`,\n { placeholderPattern: false },\n ) as t.Statement,\n }\n RuntimeCodeCache.set(framework, cache)\n }\n return cache[type]\n}\n\n/**\n * Environment-specific configuration for server function transformation.\n * This is computed internally based on the compilation context.\n */\ninterface EnvConfig {\n /** Whether this environment is a client environment */\n isClientEnvironment: boolean\n /** Whether SSR is the provider environment */\n ssrIsProvider: boolean\n /** The runtime code type to use for imports */\n runtimeCodeType: RuntimeCodeType\n}\n\n/**\n * Gets the environment configuration for the current compilation context.\n */\nfunction getEnvConfig(\n context: CompilationContext,\n isProviderFile: boolean,\n): EnvConfig {\n const { providerEnvName, env } = context\n\n // SSR is the provider when the provider environment is the default server environment\n const ssrIsProvider = providerEnvName === VITE_ENVIRONMENT_NAMES.server\n\n if (isProviderFile) {\n return {\n isClientEnvironment: false,\n ssrIsProvider,\n runtimeCodeType: 'provider',\n }\n }\n\n if (env === 'client') {\n return {\n isClientEnvironment: true,\n ssrIsProvider,\n runtimeCodeType: 'client',\n }\n }\n\n // Server caller (SSR)\n return {\n isClientEnvironment: false,\n ssrIsProvider,\n runtimeCodeType: 'ssr',\n }\n}\n\n/**\n * Builds the serverFnMeta object literal AST node.\n * The object contains: { id, name, filename }\n */\nfunction buildServerFnMetaObject(\n functionId: string,\n variableName: string,\n filename: string,\n): t.ObjectExpression {\n return t.objectExpression([\n t.objectProperty(t.identifier('id'), t.stringLiteral(functionId)),\n t.objectProperty(t.identifier('name'), t.stringLiteral(variableName)),\n t.objectProperty(t.identifier('filename'), t.stringLiteral(filename)),\n ])\n}\n\n/**\n * Generates the RPC stub expression for provider files.\n * Uses pre-compiled template for performance.\n */\nfunction generateProviderRpcStub(\n serverFnMeta: t.ObjectExpression,\n fn: t.Expression,\n): t.Expression {\n return serverRpcTemplate({\n serverFnMeta,\n fn,\n })\n}\n\n/**\n * Generates the RPC stub expression for caller files.\n * Uses pre-compiled templates for performance.\n * Note: Client and SSR callers only receive the functionId string, not the full metadata.\n */\nfunction generateCallerRpcStub(\n functionId: string,\n functionName: string,\n extractedFilename: string,\n isClientReferenced: boolean,\n envConfig: EnvConfig,\n): t.Expression {\n const functionIdLiteral = t.stringLiteral(functionId)\n\n if (envConfig.runtimeCodeType === 'client') {\n return clientRpcTemplate({\n functionId: functionIdLiteral,\n })\n }\n\n // SSR caller\n // When the function is client-referenced, it's in the manifest - use manifest lookup\n // When SSR is NOT the provider, always use manifest lookup (no import() for different env)\n // Otherwise, use the importer for functions only referenced on the server when SSR is the provider\n if (isClientReferenced || !envConfig.ssrIsProvider) {\n return ssrRpcManifestTemplate({\n functionId: functionIdLiteral,\n })\n }\n\n return ssrRpcImporterTemplate({\n functionId: functionIdLiteral,\n extractedFilename: t.stringLiteral(extractedFilename),\n functionName: t.stringLiteral(functionName),\n })\n}\n\n/**\n * Handles createServerFn transformations for a batch of candidates.\n *\n * This function performs extraction and replacement of server functions\n *\n * For caller files (non-provider):\n * - Replaces the server function with an RPC stub\n * - Does not include the handler function body\n *\n * For provider files:\n * - Creates an extractedFn that calls __executeServer\n * - Modifies .handler() to pass (extractedFn, serverFn) - two arguments\n *\n * @param candidates - All ServerFn candidates to process\n * @param context - The compilation context with helpers and mutable state\n * @returns Result containing runtime code to add, or null if no candidates processed\n */\nexport function handleCreateServerFn(\n candidates: Array<RewriteCandidate>,\n context: CompilationContext,\n) {\n if (candidates.length === 0) {\n return\n }\n\n const isProviderFile = context.id.includes(TSS_SERVERFN_SPLIT_PARAM)\n // Get environment-specific configuration\n const envConfig = getEnvConfig(context, isProviderFile)\n\n // Track function names to ensure uniqueness within this file\n const functionNameSet = new Set<string>()\n\n const exportNames = new Set<string>()\n const serverFnsById: Record<string, ServerFn> = {}\n\n const [baseFilename] = context.id.split('?') as [string]\n const extractedFilename = `${baseFilename}?${TSS_SERVERFN_SPLIT_PARAM}`\n const relativeFilename = path.relative(context.root, baseFilename)\n const knownFns = context.getKnownServerFns()\n const cleanedContextId = cleanId(context.id)\n\n for (const candidate of candidates) {\n const { path: candidatePath, methodChain } = candidate\n const { inputValidator, handler } = methodChain\n\n // Check if the call is assigned to a variable\n if (!candidatePath.parentPath.isVariableDeclarator()) {\n throw new Error('createServerFn must be assigned to a variable!')\n }\n\n // Get the identifier name of the variable\n const variableDeclarator = candidatePath.parentPath.node\n if (!t.isIdentifier(variableDeclarator.id)) {\n throw codeFrameError(\n context.code,\n variableDeclarator.id.loc!,\n 'createServerFn must be assigned to a simple identifier, not a destructuring pattern',\n )\n }\n const existingVariableName = variableDeclarator.id.name\n\n // Generate unique function name with _createServerFn_handler suffix\n // The function name is derived from the variable name\n let functionName = `${existingVariableName}_createServerFn_handler`\n while (functionNameSet.has(functionName)) {\n functionName = incrementFunctionNameVersion(functionName)\n }\n functionNameSet.add(functionName)\n\n // Generate function ID using pre-computed relative filename\n const functionId = context.generateFunctionId({\n filename: relativeFilename,\n functionName,\n extractedFilename,\n })\n\n // Check if this function was already discovered by the client build\n const knownFn = knownFns[functionId]\n const isClientReferenced = envConfig.isClientEnvironment || !!knownFn\n\n // Use canonical extracted filename from known functions if available\n const canonicalExtractedFilename =\n knownFn?.extractedFilename ?? extractedFilename\n\n // Handle input validator - remove on client\n if (inputValidator) {\n const innerInputExpression = inputValidator.callPath.node.arguments[0]\n\n if (!innerInputExpression) {\n throw new Error(\n 'createServerFn().inputValidator() must be called with a validator!',\n )\n }\n\n // If we're on the client, remove the validator call expression\n if (context.env === 'client') {\n stripMethodCall(inputValidator.callPath)\n }\n }\n\n const handlerFnPath = handler?.firstArgPath\n\n if (!handler || !handlerFnPath?.node) {\n throw codeFrameError(\n context.code,\n candidatePath.node.callee.loc!,\n `createServerFn must be called with a \"handler\" property!`,\n )\n }\n\n // Validate the handler argument is an expression (not a SpreadElement, etc.)\n if (!t.isExpression(handlerFnPath.node)) {\n throw codeFrameError(\n context.code,\n handlerFnPath.node.loc!,\n `handler() must be called with an expression, not a ${handlerFnPath.node.type}`,\n )\n }\n\n const handlerFn = handlerFnPath.node\n\n // Register function only from caller files (not provider files)\n // to avoid duplicates - provider files process the same functions\n\n if (!isProviderFile) {\n serverFnsById[functionId] = {\n functionName,\n functionId,\n filename: cleanedContextId,\n extractedFilename: canonicalExtractedFilename,\n isClientReferenced,\n }\n }\n\n if (isProviderFile) {\n // PROVIDER FILE: This is the extracted file that contains the actual implementation\n // We need to:\n // 1. Create an extractedFn that calls __executeServer\n // 2. Modify .handler() to pass (extractedFn, serverFn) - two arguments\n //\n // Expected output format:\n // const extractedFn = createServerRpc({id, name, filename}, (opts) => varName.__executeServer(opts));\n // const varName = createServerFn().handler(extractedFn, originalHandler);\n\n // Build the arrow function: (opts, signal) => varName.__executeServer(opts, signal)\n // The signal parameter is passed through to allow abort signal propagation\n const executeServerArrowFn = t.arrowFunctionExpression(\n [t.identifier('opts'), t.identifier('signal')],\n t.callExpression(\n t.memberExpression(\n t.identifier(existingVariableName),\n t.identifier('__executeServer'),\n ),\n [t.identifier('opts'), t.identifier('signal')],\n ),\n )\n\n // Build the serverFnMeta object\n const serverFnMeta = buildServerFnMetaObject(\n functionId,\n existingVariableName,\n relativeFilename,\n )\n\n // Generate the replacement using pre-compiled template\n const extractedFnInit = generateProviderRpcStub(\n serverFnMeta,\n executeServerArrowFn,\n )\n\n // Build the extracted function statement\n const extractedFnStatement = t.variableDeclaration('const', [\n t.variableDeclarator(t.identifier(functionName), extractedFnInit),\n ])\n\n // Find the variable declaration statement containing our createServerFn\n const variableDeclaration = candidatePath.parentPath.parentPath\n if (!variableDeclaration.isVariableDeclaration()) {\n throw new Error(\n 'Expected createServerFn to be in a VariableDeclaration',\n )\n }\n\n // Insert the extracted function statement before the variable declaration\n variableDeclaration.insertBefore(extractedFnStatement)\n\n // Modify the .handler() call to pass two arguments: (extractedFn, serverFn)\n // The handlerFnPath.node contains the original serverFn\n const extractedFnIdentifier = t.identifier(functionName)\n const serverFnNode = t.cloneNode(handlerFn, true)\n\n // Replace handler's arguments with [extractedFn, serverFn]\n handler.callPath.node.arguments = [extractedFnIdentifier, serverFnNode]\n\n // Only export the extracted handler (e.g., myFn_createServerFn_handler)\n // The manifest and all import paths only look up this suffixed name.\n // The original variable (e.g., myFn) stays in the file but is not exported\n // since it's only used internally.\n exportNames.add(functionName)\n } else {\n // CALLER FILE: This file calls the server function but doesn't contain the implementation\n // We need to:\n // 1. Remove the handler function body (it will be in the provider file)\n // 2. Replace the handler argument with an RPC stub\n //\n // IMPORTANT: We must keep the createServerFn().handler(extractedFn) structure\n // so that the client middleware chain can unwrap the {result, error, context} response.\n //\n // Expected output format:\n // const myFn = createServerFn().handler(createClientRpc(\"id\"))\n // or\n // const myFn = createServerFn().handler(createSsrRpc(\"id\", () => import(...)))\n\n // If the handler function is an identifier, we need to remove the bound function\n // from the file since it won't be needed\n if (t.isIdentifier(handlerFn)) {\n const binding = handlerFnPath.scope.getBinding(handlerFn.name)\n if (binding) {\n binding.path.remove()\n }\n }\n\n // Generate the RPC stub using pre-compiled templates\n // Note: Caller files only pass functionId, not the full serverFnMeta\n const rpcStub = generateCallerRpcStub(\n functionId,\n functionName,\n canonicalExtractedFilename,\n isClientReferenced,\n envConfig,\n )\n\n // Replace ONLY the handler argument with the RPC stub\n // Keep the createServerFn().handler() wrapper intact for client middleware\n handlerFnPath.replaceWith(rpcStub)\n }\n }\n\n // For provider files, add exports for all extracted functions\n if (isProviderFile) {\n // Remove all existing exports first\n safeRemoveExports(context.ast)\n\n // Export all server function related variables from exportNames\n // These were populated by handleCreateServerFn:\n // 1. Extracted handlers: const fn_createServerFn_handler = createServerRpc(...)\n // 2. Original variables: const fn = createServerFn().handler(...)\n if (exportNames.size > 0) {\n context.ast.program.body.push(\n t.exportNamedDeclaration(\n undefined,\n Array.from(exportNames).map((name) =>\n t.exportSpecifier(t.identifier(name), t.identifier(name)),\n ),\n ),\n )\n }\n }\n\n // Notify about discovered functions (only for non-provider files)\n if (\n !isProviderFile &&\n Object.keys(serverFnsById).length > 0 &&\n context.onServerFnsById\n ) {\n context.onServerFnsById(serverFnsById)\n }\n\n // Add runtime import using cached AST node\n const runtimeCode = getCachedRuntimeCode(\n context.framework,\n envConfig.runtimeCodeType,\n )\n context.ast.program.body.unshift(t.cloneNode(runtimeCode))\n}\n\n/**\n * Makes an identifier safe for use as a JavaScript identifier.\n */\nfunction makeIdentifierSafe(identifier: string): string {\n return identifier\n .replace(/[^a-zA-Z0-9_$]/g, '_') // Replace unsafe chars with underscore\n .replace(/^[0-9]/, '_$&') // Prefix leading number with underscore\n .replace(/^\\$/, '_$') // Prefix leading $ with underscore\n .replace(/_{2,}/g, '_') // Collapse multiple underscores\n .replace(/^_|_$/g, '') // Trim leading/trailing underscores\n}\n\n/**\n * Increments the version number suffix on a function name.\n */\nfunction incrementFunctionNameVersion(functionName: string): string {\n const [realReferenceName, count] = functionName.split(/_(\\d+)$/)\n const resolvedCount = Number(count || '0')\n const suffix = `_${resolvedCount + 1}`\n return makeIdentifierSafe(realReferenceName!) + suffix\n}\n\n/**\n * Removes all exports from the AST while preserving the declarations.\n * Used for provider files where we want to re-export only the server functions.\n */\nfunction safeRemoveExports(ast: t.File): void {\n ast.program.body = ast.program.body.flatMap((node) => {\n if (\n t.isExportNamedDeclaration(node) ||\n t.isExportDefaultDeclaration(node)\n ) {\n if (\n t.isFunctionDeclaration(node.declaration) ||\n t.isClassDeclaration(node.declaration) ||\n t.isVariableDeclaration(node.declaration)\n ) {\n // do not remove export if it is an anonymous function / class,\n // otherwise this would produce a syntax error\n if (\n t.isFunctionDeclaration(node.declaration) ||\n t.isClassDeclaration(node.declaration)\n ) {\n if (!node.declaration.id) {\n return node\n }\n }\n return node.declaration\n } else if (node.declaration === null) {\n // remove e.g. `export { RouteComponent as component }`\n return []\n }\n }\n return node\n })\n}\n"],"names":[],"mappings":";;;;;AAQA,MAAM,2BAA2B;AAOjC,MAAM,oBAAoB,MAAM,SAAS;AAAA,EACvC;AACF;AAGA,MAAM,oBAAoB,MAAM,SAAS;AAAA,EACvC;AACF;AAGA,MAAM,yBAAyB,MAAM,SAAS;AAAA,EAC5C;AACF;AAGA,MAAM,yBAAyB,MAAM,SAAS;AAAA,EAC5C;AACF;AAQA,MAAM,uCAAuB,IAAA;AAK7B,SAAS,qBACP,WACA,MACa;AACb,MAAI,QAAQ,iBAAiB,IAAI,SAAS;AAC1C,MAAI,CAAC,OAAO;AACV,YAAQ;AAAA,MACN,UAAU,MAAM,SAAS;AAAA,QACvB,8CAA8C,SAAS;AAAA,QACvD,EAAE,oBAAoB,MAAA;AAAA,MAAM;AAAA,MAE9B,QAAQ,MAAM,SAAS;AAAA,QACrB,8CAA8C,SAAS;AAAA,QACvD,EAAE,oBAAoB,MAAA;AAAA,MAAM;AAAA,MAE9B,KAAK,MAAM,SAAS;AAAA,QAClB,2CAA2C,SAAS;AAAA,QACpD,EAAE,oBAAoB,MAAA;AAAA,MAAM;AAAA,IAC9B;AAEF,qBAAiB,IAAI,WAAW,KAAK;AAAA,EACvC;AACA,SAAO,MAAM,IAAI;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WAAW,CAAC;AAC3D;AAKA,SAAS,mBAAmB,YAA4B;AACtD,SAAO,WACJ,QAAQ,mBAAmB,GAAG,EAC9B,QAAQ,UAAU,KAAK,EACvB,QAAQ,OAAO,IAAI,EACnB,QAAQ,UAAU,GAAG,EACrB,QAAQ,UAAU,EAAE;AACzB;AAKA,SAAS,6BAA6B,cAA8B;AAClE,QAAM,CAAC,mBAAmB,KAAK,IAAI,aAAa,MAAM,SAAS;AAC/D,QAAM,gBAAgB,OAAO,SAAS,GAAG;AACzC,QAAM,SAAS,IAAI,gBAAgB,CAAC;AACpC,SAAO,mBAAmB,iBAAkB,IAAI;AAClD;AAMA,SAAS,kBAAkB,KAAmB;AAC5C,MAAI,QAAQ,OAAO,IAAI,QAAQ,KAAK,QAAQ,CAAC,SAAS;AACpD,QACE,EAAE,yBAAyB,IAAI,KAC/B,EAAE,2BAA2B,IAAI,GACjC;AACA,UACE,EAAE,sBAAsB,KAAK,WAAW,KACxC,EAAE,mBAAmB,KAAK,WAAW,KACrC,EAAE,sBAAsB,KAAK,WAAW,GACxC;AAGA,YACE,EAAE,sBAAsB,KAAK,WAAW,KACxC,EAAE,mBAAmB,KAAK,WAAW,GACrC;AACA,cAAI,CAAC,KAAK,YAAY,IAAI;AACxB,mBAAO;AAAA,UACT;AAAA,QACF;AACA,eAAO,KAAK;AAAA,MACd,WAAW,KAAK,gBAAgB,MAAM;AAEpC,eAAO,CAAA;AAAA,MACT;AAAA,IACF;AACA,WAAO;AAAA,EACT,CAAC;AACH;"}
|
|
1
|
+
{"version":3,"file":"handleCreateServerFn.js","sources":["../../../src/start-compiler-plugin/handleCreateServerFn.ts"],"sourcesContent":["import * as t from '@babel/types'\nimport babel from '@babel/core'\nimport path from 'pathe'\nimport { VITE_ENVIRONMENT_NAMES } from '../constants'\nimport { cleanId, codeFrameError, stripMethodCall } from './utils'\nimport type { CompilationContext, RewriteCandidate, ServerFn } from './types'\nimport type { CompileStartFrameworkOptions } from '../types'\n\nconst TSS_SERVERFN_SPLIT_PARAM = 'tss-serverfn-split'\n\n// ============================================================================\n// Pre-compiled babel templates (compiled once at module load time)\n// ============================================================================\n\n// Template for provider files: createServerRpc(serverFnMeta, fn)\nconst serverRpcTemplate = babel.template.expression(\n `createServerRpc(%%serverFnMeta%%, %%fn%%)`,\n)\n\n// Template for client caller files: createClientRpc(functionId)\nconst clientRpcTemplate = babel.template.expression(\n `createClientRpc(%%functionId%%)`,\n)\n\n// Template for SSR caller files (manifest lookup): createSsrRpc(functionId)\nconst ssrRpcManifestTemplate = babel.template.expression(\n `createSsrRpc(%%functionId%%)`,\n)\n\n// Template for SSR caller files (with importer): createSsrRpc(functionId, () => import(...).then(m => m['name']))\nconst ssrRpcImporterTemplate = babel.template.expression(\n `createSsrRpc(%%functionId%%, () => import(%%extractedFilename%%).then(m => m[%%functionName%%]))`,\n)\n\n// ============================================================================\n// Runtime code cache (cached per framework to avoid repeated AST generation)\n// ============================================================================\n\ntype RuntimeCodeType = 'provider' | 'client' | 'ssr'\ntype FrameworkRuntimeCache = Record<RuntimeCodeType, t.Statement>\nconst RuntimeCodeCache = new Map<\n CompileStartFrameworkOptions,\n FrameworkRuntimeCache\n>()\n\nfunction getCachedRuntimeCode(\n framework: CompileStartFrameworkOptions,\n type: RuntimeCodeType,\n): t.Statement {\n let cache = RuntimeCodeCache.get(framework)\n if (!cache) {\n cache = {\n provider: babel.template.ast(\n `import { createServerRpc } from '@tanstack/${framework}-start/server-rpc'`,\n { placeholderPattern: false },\n ) as t.Statement,\n client: babel.template.ast(\n `import { createClientRpc } from '@tanstack/${framework}-start/client-rpc'`,\n { placeholderPattern: false },\n ) as t.Statement,\n ssr: babel.template.ast(\n `import { createSsrRpc } from '@tanstack/${framework}-start/ssr-rpc'`,\n { placeholderPattern: false },\n ) as t.Statement,\n }\n RuntimeCodeCache.set(framework, cache)\n }\n return cache[type]\n}\n\n/**\n * Environment-specific configuration for server function transformation.\n * This is computed internally based on the compilation context.\n */\ninterface EnvConfig {\n /** Whether this environment is a client environment */\n isClientEnvironment: boolean\n /** Whether SSR is the provider environment */\n ssrIsProvider: boolean\n /** The runtime code type to use for imports */\n runtimeCodeType: RuntimeCodeType\n}\n\n/**\n * Gets the environment configuration for the current compilation context.\n */\nfunction getEnvConfig(\n context: CompilationContext,\n isProviderFile: boolean,\n): EnvConfig {\n const { providerEnvName, env } = context\n\n // SSR is the provider when the provider environment is the default server environment\n const ssrIsProvider = providerEnvName === VITE_ENVIRONMENT_NAMES.server\n\n if (isProviderFile) {\n return {\n isClientEnvironment: false,\n ssrIsProvider,\n runtimeCodeType: 'provider',\n }\n }\n\n if (env === 'client') {\n return {\n isClientEnvironment: true,\n ssrIsProvider,\n runtimeCodeType: 'client',\n }\n }\n\n // Server caller (SSR)\n return {\n isClientEnvironment: false,\n ssrIsProvider,\n runtimeCodeType: 'ssr',\n }\n}\n\n/**\n * Builds the serverFnMeta object literal AST node.\n * The object contains: { id, name, filename }\n */\nfunction buildServerFnMetaObject(\n functionId: string,\n variableName: string,\n filename: string,\n): t.ObjectExpression {\n return t.objectExpression([\n t.objectProperty(t.identifier('id'), t.stringLiteral(functionId)),\n t.objectProperty(t.identifier('name'), t.stringLiteral(variableName)),\n t.objectProperty(t.identifier('filename'), t.stringLiteral(filename)),\n ])\n}\n\n/**\n * Generates the RPC stub expression for provider files.\n * Uses pre-compiled template for performance.\n */\nfunction generateProviderRpcStub(\n serverFnMeta: t.ObjectExpression,\n fn: t.Expression,\n): t.Expression {\n return serverRpcTemplate({\n serverFnMeta,\n fn,\n })\n}\n\n/**\n * Generates the RPC stub expression for caller files.\n * Uses pre-compiled templates for performance.\n * Note: Client and SSR callers only receive the functionId string, not the full metadata.\n */\nfunction generateCallerRpcStub(\n functionId: string,\n functionName: string,\n extractedFilename: string,\n isClientReferenced: boolean,\n envConfig: EnvConfig,\n): t.Expression {\n const functionIdLiteral = t.stringLiteral(functionId)\n\n if (envConfig.runtimeCodeType === 'client') {\n return clientRpcTemplate({\n functionId: functionIdLiteral,\n })\n }\n\n // SSR caller\n // When the function is client-referenced, it's in the manifest - use manifest lookup\n // When SSR is NOT the provider, always use manifest lookup (no import() for different env)\n // Otherwise, use the importer for functions only referenced on the server when SSR is the provider\n if (isClientReferenced || !envConfig.ssrIsProvider) {\n return ssrRpcManifestTemplate({\n functionId: functionIdLiteral,\n })\n }\n\n return ssrRpcImporterTemplate({\n functionId: functionIdLiteral,\n extractedFilename: t.stringLiteral(extractedFilename),\n functionName: t.stringLiteral(functionName),\n })\n}\n\n/**\n * Handles createServerFn transformations for a batch of candidates.\n *\n * This function performs extraction and replacement of server functions\n *\n * For caller files (non-provider):\n * - Replaces the server function with an RPC stub\n * - Does not include the handler function body\n *\n * For provider files:\n * - Creates an extractedFn that calls __executeServer\n * - Modifies .handler() to pass (extractedFn, serverFn) - two arguments\n *\n * @param candidates - All ServerFn candidates to process\n * @param context - The compilation context with helpers and mutable state\n * @returns Result containing runtime code to add, or null if no candidates processed\n */\nexport function handleCreateServerFn(\n candidates: Array<RewriteCandidate>,\n context: CompilationContext,\n) {\n if (candidates.length === 0) {\n return\n }\n\n const isProviderFile = context.id.includes(TSS_SERVERFN_SPLIT_PARAM)\n // Get environment-specific configuration\n const envConfig = getEnvConfig(context, isProviderFile)\n\n // Track function names to ensure uniqueness within this file\n const functionNameSet = new Set<string>()\n\n const exportNames = new Set<string>()\n const serverFnsById: Record<string, ServerFn> = {}\n\n const [baseFilename] = context.id.split('?') as [string]\n const extractedFilename = `${baseFilename}?${TSS_SERVERFN_SPLIT_PARAM}`\n const relativeFilename = path.relative(context.root, baseFilename)\n const knownFns = context.getKnownServerFns()\n const cleanedContextId = cleanId(context.id)\n\n for (const candidate of candidates) {\n const { path: candidatePath, methodChain } = candidate\n const { inputValidator, handler } = methodChain\n\n // Check if the call is assigned to a variable\n if (!candidatePath.parentPath.isVariableDeclarator()) {\n throw new Error('createServerFn must be assigned to a variable!')\n }\n\n // Get the identifier name of the variable\n const variableDeclarator = candidatePath.parentPath.node\n if (!t.isIdentifier(variableDeclarator.id)) {\n throw codeFrameError(\n context.code,\n variableDeclarator.id.loc!,\n 'createServerFn must be assigned to a simple identifier, not a destructuring pattern',\n )\n }\n const existingVariableName = variableDeclarator.id.name\n\n // Generate unique function name with _createServerFn_handler suffix\n // The function name is derived from the variable name\n let functionName = `${existingVariableName}_createServerFn_handler`\n while (functionNameSet.has(functionName)) {\n functionName = incrementFunctionNameVersion(functionName)\n }\n functionNameSet.add(functionName)\n\n // Generate function ID using pre-computed relative filename\n const functionId = context.generateFunctionId({\n filename: relativeFilename,\n functionName,\n extractedFilename,\n })\n\n // Check if this function was already discovered by the client build\n const knownFn = knownFns[functionId]\n const isClientReferenced = envConfig.isClientEnvironment || !!knownFn\n\n // Use canonical extracted filename from known functions if available\n const canonicalExtractedFilename =\n knownFn?.extractedFilename ?? extractedFilename\n\n // Handle input validator - remove on client\n if (inputValidator) {\n const innerInputExpression = inputValidator.callPath.node.arguments[0]\n\n if (!innerInputExpression) {\n throw new Error(\n 'createServerFn().inputValidator() must be called with a validator!',\n )\n }\n\n // If we're on the client, remove the validator call expression\n if (context.env === 'client') {\n stripMethodCall(inputValidator.callPath)\n }\n }\n\n const handlerFnPath = handler?.firstArgPath\n\n if (!handler || !handlerFnPath?.node) {\n throw codeFrameError(\n context.code,\n candidatePath.node.callee.loc!,\n `createServerFn must be called with a \"handler\" property!`,\n )\n }\n\n // Validate the handler argument is an expression (not a SpreadElement, etc.)\n if (!t.isExpression(handlerFnPath.node)) {\n throw codeFrameError(\n context.code,\n handlerFnPath.node.loc!,\n `handler() must be called with an expression, not a ${handlerFnPath.node.type}`,\n )\n }\n\n const handlerFn = handlerFnPath.node\n\n // Register function only from caller files (not provider files)\n // to avoid duplicates - provider files process the same functions\n\n if (!isProviderFile) {\n serverFnsById[functionId] = {\n functionName,\n functionId,\n filename: cleanedContextId,\n extractedFilename: canonicalExtractedFilename,\n isClientReferenced,\n }\n }\n\n if (isProviderFile) {\n // PROVIDER FILE: This is the extracted file that contains the actual implementation\n // We need to:\n // 1. Create an extractedFn that calls __executeServer\n // 2. Modify .handler() to pass (extractedFn, serverFn) - two arguments\n //\n // Expected output format:\n // const extractedFn = createServerRpc({id, name, filename}, (opts) => varName.__executeServer(opts));\n // const varName = createServerFn().handler(extractedFn, originalHandler);\n\n // Build the arrow function: (opts) => varName.__executeServer(opts)\n // The signal parameter is passed through to allow abort signal propagation\n const executeServerArrowFn = t.arrowFunctionExpression(\n [t.identifier('opts')],\n t.callExpression(\n t.memberExpression(\n t.identifier(existingVariableName),\n t.identifier('__executeServer'),\n ),\n [t.identifier('opts')],\n ),\n )\n\n // Build the serverFnMeta object\n const serverFnMeta = buildServerFnMetaObject(\n functionId,\n existingVariableName,\n relativeFilename,\n )\n\n // Generate the replacement using pre-compiled template\n const extractedFnInit = generateProviderRpcStub(\n serverFnMeta,\n executeServerArrowFn,\n )\n\n // Build the extracted function statement\n const extractedFnStatement = t.variableDeclaration('const', [\n t.variableDeclarator(t.identifier(functionName), extractedFnInit),\n ])\n\n // Find the variable declaration statement containing our createServerFn\n const variableDeclaration = candidatePath.parentPath.parentPath\n if (!variableDeclaration.isVariableDeclaration()) {\n throw new Error(\n 'Expected createServerFn to be in a VariableDeclaration',\n )\n }\n\n // Insert the extracted function statement before the variable declaration\n variableDeclaration.insertBefore(extractedFnStatement)\n\n // Modify the .handler() call to pass two arguments: (extractedFn, serverFn)\n // The handlerFnPath.node contains the original serverFn\n const extractedFnIdentifier = t.identifier(functionName)\n const serverFnNode = t.cloneNode(handlerFn, true)\n\n // Replace handler's arguments with [extractedFn, serverFn]\n handler.callPath.node.arguments = [extractedFnIdentifier, serverFnNode]\n\n // Only export the extracted handler (e.g., myFn_createServerFn_handler)\n // The manifest and all import paths only look up this suffixed name.\n // The original variable (e.g., myFn) stays in the file but is not exported\n // since it's only used internally.\n exportNames.add(functionName)\n } else {\n // CALLER FILE: This file calls the server function but doesn't contain the implementation\n // We need to:\n // 1. Remove the handler function body (it will be in the provider file)\n // 2. Replace the handler argument with an RPC stub\n //\n // IMPORTANT: We must keep the createServerFn().handler(extractedFn) structure\n // so that the client middleware chain can unwrap the {result, error, context} response.\n //\n // Expected output format:\n // const myFn = createServerFn().handler(createClientRpc(\"id\"))\n // or\n // const myFn = createServerFn().handler(createSsrRpc(\"id\", () => import(...)))\n\n // If the handler function is an identifier, we need to remove the bound function\n // from the file since it won't be needed\n if (t.isIdentifier(handlerFn)) {\n const binding = handlerFnPath.scope.getBinding(handlerFn.name)\n if (binding) {\n binding.path.remove()\n }\n }\n\n // Generate the RPC stub using pre-compiled templates\n // Note: Caller files only pass functionId, not the full serverFnMeta\n const rpcStub = generateCallerRpcStub(\n functionId,\n functionName,\n canonicalExtractedFilename,\n isClientReferenced,\n envConfig,\n )\n\n // Replace ONLY the handler argument with the RPC stub\n // Keep the createServerFn().handler() wrapper intact for client middleware\n handlerFnPath.replaceWith(rpcStub)\n }\n }\n\n // For provider files, add exports for all extracted functions\n if (isProviderFile) {\n // Remove all existing exports first\n safeRemoveExports(context.ast)\n\n // Export all server function related variables from exportNames\n // These were populated by handleCreateServerFn:\n // 1. Extracted handlers: const fn_createServerFn_handler = createServerRpc(...)\n // 2. Original variables: const fn = createServerFn().handler(...)\n if (exportNames.size > 0) {\n context.ast.program.body.push(\n t.exportNamedDeclaration(\n undefined,\n Array.from(exportNames).map((name) =>\n t.exportSpecifier(t.identifier(name), t.identifier(name)),\n ),\n ),\n )\n }\n }\n\n // Notify about discovered functions (only for non-provider files)\n if (\n !isProviderFile &&\n Object.keys(serverFnsById).length > 0 &&\n context.onServerFnsById\n ) {\n context.onServerFnsById(serverFnsById)\n }\n\n // Add runtime import using cached AST node\n const runtimeCode = getCachedRuntimeCode(\n context.framework,\n envConfig.runtimeCodeType,\n )\n context.ast.program.body.unshift(t.cloneNode(runtimeCode))\n}\n\n/**\n * Makes an identifier safe for use as a JavaScript identifier.\n */\nfunction makeIdentifierSafe(identifier: string): string {\n return identifier\n .replace(/[^a-zA-Z0-9_$]/g, '_') // Replace unsafe chars with underscore\n .replace(/^[0-9]/, '_$&') // Prefix leading number with underscore\n .replace(/^\\$/, '_$') // Prefix leading $ with underscore\n .replace(/_{2,}/g, '_') // Collapse multiple underscores\n .replace(/^_|_$/g, '') // Trim leading/trailing underscores\n}\n\n/**\n * Increments the version number suffix on a function name.\n */\nfunction incrementFunctionNameVersion(functionName: string): string {\n const [realReferenceName, count] = functionName.split(/_(\\d+)$/)\n const resolvedCount = Number(count || '0')\n const suffix = `_${resolvedCount + 1}`\n return makeIdentifierSafe(realReferenceName!) + suffix\n}\n\n/**\n * Removes all exports from the AST while preserving the declarations.\n * Used for provider files where we want to re-export only the server functions.\n */\nfunction safeRemoveExports(ast: t.File): void {\n ast.program.body = ast.program.body.flatMap((node) => {\n if (\n t.isExportNamedDeclaration(node) ||\n t.isExportDefaultDeclaration(node)\n ) {\n if (\n t.isFunctionDeclaration(node.declaration) ||\n t.isClassDeclaration(node.declaration) ||\n t.isVariableDeclaration(node.declaration)\n ) {\n // do not remove export if it is an anonymous function / class,\n // otherwise this would produce a syntax error\n if (\n t.isFunctionDeclaration(node.declaration) ||\n t.isClassDeclaration(node.declaration)\n ) {\n if (!node.declaration.id) {\n return node\n }\n }\n return node.declaration\n } else if (node.declaration === null) {\n // remove e.g. `export { RouteComponent as component }`\n return []\n }\n }\n return node\n })\n}\n"],"names":[],"mappings":";;;;;AAQA,MAAM,2BAA2B;AAOjC,MAAM,oBAAoB,MAAM,SAAS;AAAA,EACvC;AACF;AAGA,MAAM,oBAAoB,MAAM,SAAS;AAAA,EACvC;AACF;AAGA,MAAM,yBAAyB,MAAM,SAAS;AAAA,EAC5C;AACF;AAGA,MAAM,yBAAyB,MAAM,SAAS;AAAA,EAC5C;AACF;AAQA,MAAM,uCAAuB,IAAA;AAK7B,SAAS,qBACP,WACA,MACa;AACb,MAAI,QAAQ,iBAAiB,IAAI,SAAS;AAC1C,MAAI,CAAC,OAAO;AACV,YAAQ;AAAA,MACN,UAAU,MAAM,SAAS;AA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;AACH;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tanstack/start-plugin-core",
|
|
3
|
-
"version": "1.158.
|
|
3
|
+
"version": "1.158.3",
|
|
4
4
|
"description": "Modern and scalable routing for React applications",
|
|
5
5
|
"author": "Tanner Linsley",
|
|
6
6
|
"license": "MIT",
|
|
@@ -60,10 +60,10 @@
|
|
|
60
60
|
"zod": "^3.24.2",
|
|
61
61
|
"@tanstack/router-core": "1.158.1",
|
|
62
62
|
"@tanstack/router-generator": "1.158.1",
|
|
63
|
+
"@tanstack/router-plugin": "1.158.1",
|
|
63
64
|
"@tanstack/router-utils": "1.158.0",
|
|
64
|
-
"@tanstack/start-
|
|
65
|
-
"@tanstack/start-
|
|
66
|
-
"@tanstack/router-plugin": "1.158.1"
|
|
65
|
+
"@tanstack/start-client-core": "1.158.3",
|
|
66
|
+
"@tanstack/start-server-core": "1.158.3"
|
|
67
67
|
},
|
|
68
68
|
"devDependencies": {
|
|
69
69
|
"@types/babel__code-frame": "^7.0.6",
|
|
@@ -328,16 +328,16 @@ export function handleCreateServerFn(
|
|
|
328
328
|
// const extractedFn = createServerRpc({id, name, filename}, (opts) => varName.__executeServer(opts));
|
|
329
329
|
// const varName = createServerFn().handler(extractedFn, originalHandler);
|
|
330
330
|
|
|
331
|
-
// Build the arrow function: (opts
|
|
331
|
+
// Build the arrow function: (opts) => varName.__executeServer(opts)
|
|
332
332
|
// The signal parameter is passed through to allow abort signal propagation
|
|
333
333
|
const executeServerArrowFn = t.arrowFunctionExpression(
|
|
334
|
-
[t.identifier('opts')
|
|
334
|
+
[t.identifier('opts')],
|
|
335
335
|
t.callExpression(
|
|
336
336
|
t.memberExpression(
|
|
337
337
|
t.identifier(existingVariableName),
|
|
338
338
|
t.identifier('__executeServer'),
|
|
339
339
|
),
|
|
340
|
-
[t.identifier('opts')
|
|
340
|
+
[t.identifier('opts')],
|
|
341
341
|
),
|
|
342
342
|
)
|
|
343
343
|
|