@tanstack/start-plugin-core 1.142.1 → 1.142.2
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/esm/create-server-fn-plugin/handleCreateMiddleware.js +8 -7
- package/dist/esm/create-server-fn-plugin/handleCreateMiddleware.js.map +1 -1
- package/dist/esm/plugin.js +7 -2
- package/dist/esm/plugin.js.map +1 -1
- package/dist/esm/schema.d.ts +3 -3
- package/dist/esm/start-compiler-plugin/compilers.js +0 -8
- package/dist/esm/start-compiler-plugin/compilers.js.map +1 -1
- package/dist/esm/start-compiler-plugin/constants.d.ts +1 -1
- package/dist/esm/start-compiler-plugin/constants.js +1 -2
- package/dist/esm/start-compiler-plugin/constants.js.map +1 -1
- package/package.json +2 -2
- package/src/create-server-fn-plugin/handleCreateMiddleware.ts +10 -21
- package/src/plugin.ts +7 -3
- package/src/start-compiler-plugin/compilers.ts +0 -11
- package/src/start-compiler-plugin/constants.ts +0 -1
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import * as t from "@babel/types";
|
|
2
2
|
import { getRootCallExpression } from "../start-compiler-plugin/utils.js";
|
|
3
3
|
function handleCreateMiddleware(path, opts) {
|
|
4
|
+
if (opts.env === "server") {
|
|
5
|
+
throw new Error("handleCreateMiddleware should not be called on the server");
|
|
6
|
+
}
|
|
4
7
|
const rootCallExpression = getRootCallExpression(path);
|
|
5
8
|
const callExpressionPaths = {
|
|
6
9
|
middleware: null,
|
|
@@ -26,18 +29,16 @@ function handleCreateMiddleware(path, opts) {
|
|
|
26
29
|
"createMiddleware().inputValidator() must be called with a validator!"
|
|
27
30
|
);
|
|
28
31
|
}
|
|
29
|
-
if (
|
|
30
|
-
|
|
31
|
-
callExpressionPaths.inputValidator.
|
|
32
|
-
|
|
33
|
-
);
|
|
34
|
-
}
|
|
32
|
+
if (t.isMemberExpression(callExpressionPaths.inputValidator.node.callee)) {
|
|
33
|
+
callExpressionPaths.inputValidator.replaceWith(
|
|
34
|
+
callExpressionPaths.inputValidator.node.callee.object
|
|
35
|
+
);
|
|
35
36
|
}
|
|
36
37
|
}
|
|
37
38
|
const serverFnPath = callExpressionPaths.server?.get(
|
|
38
39
|
"arguments.0"
|
|
39
40
|
);
|
|
40
|
-
if (callExpressionPaths.server && serverFnPath.node
|
|
41
|
+
if (callExpressionPaths.server && serverFnPath.node) {
|
|
41
42
|
if (t.isMemberExpression(callExpressionPaths.server.node.callee)) {
|
|
42
43
|
callExpressionPaths.server.replaceWith(
|
|
43
44
|
callExpressionPaths.server.node.callee.object
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"handleCreateMiddleware.js","sources":["../../../src/create-server-fn-plugin/handleCreateMiddleware.ts"],"sourcesContent":["import * as t from '@babel/types'\nimport { getRootCallExpression } from '../start-compiler-plugin/utils'\nimport type * as babel from '@babel/core'\n\nexport function handleCreateMiddleware(\n path: babel.NodePath<t.CallExpression>,\n opts: {\n env: 'client' | 'server'\n },\n) {\n
|
|
1
|
+
{"version":3,"file":"handleCreateMiddleware.js","sources":["../../../src/create-server-fn-plugin/handleCreateMiddleware.ts"],"sourcesContent":["import * as t from '@babel/types'\nimport { getRootCallExpression } from '../start-compiler-plugin/utils'\nimport type * as babel from '@babel/core'\n\nexport function handleCreateMiddleware(\n path: babel.NodePath<t.CallExpression>,\n opts: {\n env: 'client' | 'server'\n },\n) {\n if (opts.env === 'server') {\n throw new Error('handleCreateMiddleware should not be called on the server')\n }\n const rootCallExpression = getRootCallExpression(path)\n\n const callExpressionPaths = {\n middleware: null as babel.NodePath<t.CallExpression> | null,\n inputValidator: null as babel.NodePath<t.CallExpression> | null,\n client: null as babel.NodePath<t.CallExpression> | null,\n server: null as babel.NodePath<t.CallExpression> | null,\n }\n\n const validMethods = Object.keys(callExpressionPaths)\n\n rootCallExpression.traverse({\n MemberExpression(memberExpressionPath) {\n if (t.isIdentifier(memberExpressionPath.node.property)) {\n const name = memberExpressionPath.node.property\n .name as keyof typeof callExpressionPaths\n\n if (\n validMethods.includes(name) &&\n memberExpressionPath.parentPath.isCallExpression()\n ) {\n callExpressionPaths[name] = memberExpressionPath.parentPath\n }\n }\n },\n })\n\n if (callExpressionPaths.inputValidator) {\n const innerInputExpression =\n callExpressionPaths.inputValidator.node.arguments[0]\n\n if (!innerInputExpression) {\n throw new Error(\n 'createMiddleware().inputValidator() must be called with a validator!',\n )\n }\n\n // remove the validator call expression\n if (t.isMemberExpression(callExpressionPaths.inputValidator.node.callee)) {\n callExpressionPaths.inputValidator.replaceWith(\n callExpressionPaths.inputValidator.node.callee.object,\n )\n }\n }\n\n const serverFnPath = callExpressionPaths.server?.get(\n 'arguments.0',\n ) as babel.NodePath<any>\n\n if (callExpressionPaths.server && serverFnPath.node) {\n // remove the server call expression\n if (t.isMemberExpression(callExpressionPaths.server.node.callee)) {\n callExpressionPaths.server.replaceWith(\n callExpressionPaths.server.node.callee.object,\n )\n }\n }\n}\n"],"names":[],"mappings":";;AAIO,SAAS,uBACd,MACA,MAGA;AACA,MAAI,KAAK,QAAQ,UAAU;AACzB,UAAM,IAAI,MAAM,2DAA2D;AAAA,EAC7E;AACA,QAAM,qBAAqB,sBAAsB,IAAI;AAErD,QAAM,sBAAsB;AAAA,IAC1B,YAAY;AAAA,IACZ,gBAAgB;AAAA,IAChB,QAAQ;AAAA,IACR,QAAQ;AAAA,EAAA;AAGV,QAAM,eAAe,OAAO,KAAK,mBAAmB;AAEpD,qBAAmB,SAAS;AAAA,IAC1B,iBAAiB,sBAAsB;AACrC,UAAI,EAAE,aAAa,qBAAqB,KAAK,QAAQ,GAAG;AACtD,cAAM,OAAO,qBAAqB,KAAK,SACpC;AAEH,YACE,aAAa,SAAS,IAAI,KAC1B,qBAAqB,WAAW,oBAChC;AACA,8BAAoB,IAAI,IAAI,qBAAqB;AAAA,QACnD;AAAA,MACF;AAAA,IACF;AAAA,EAAA,CACD;AAED,MAAI,oBAAoB,gBAAgB;AACtC,UAAM,uBACJ,oBAAoB,eAAe,KAAK,UAAU,CAAC;AAErD,QAAI,CAAC,sBAAsB;AACzB,YAAM,IAAI;AAAA,QACR;AAAA,MAAA;AAAA,IAEJ;AAGA,QAAI,EAAE,mBAAmB,oBAAoB,eAAe,KAAK,MAAM,GAAG;AACxE,0BAAoB,eAAe;AAAA,QACjC,oBAAoB,eAAe,KAAK,OAAO;AAAA,MAAA;AAAA,IAEnD;AAAA,EACF;AAEA,QAAM,eAAe,oBAAoB,QAAQ;AAAA,IAC/C;AAAA,EAAA;AAGF,MAAI,oBAAoB,UAAU,aAAa,MAAM;AAEnD,QAAI,EAAE,mBAAmB,oBAAoB,OAAO,KAAK,MAAM,GAAG;AAChE,0BAAoB,OAAO;AAAA,QACzB,oBAAoB,OAAO,KAAK,OAAO;AAAA,MAAA;AAAA,IAE3C;AAAA,EACF;AACF;"}
|
package/dist/esm/plugin.js
CHANGED
|
@@ -283,8 +283,12 @@ function TanStackStartVitePluginCore(corePluginOpts, startPluginOpts) {
|
|
|
283
283
|
}
|
|
284
284
|
},
|
|
285
285
|
tanStackStartRouter(startPluginOpts, getConfig, corePluginOpts),
|
|
286
|
-
// N.B.
|
|
287
|
-
|
|
286
|
+
// N.B. Server function plugins must run BEFORE startCompilerPlugin because:
|
|
287
|
+
// 1. createServerFnPlugin transforms createServerFn().handler() to inject 'use server' directive
|
|
288
|
+
// 2. TanStackServerFnPlugin extracts 'use server' functions and registers them in the manifest
|
|
289
|
+
// 3. startCompilerPlugin handles createClientOnlyFn/createServerOnlyFn and runs DCE
|
|
290
|
+
// If startCompilerPlugin runs first, DCE may remove server function code before it can be registered
|
|
291
|
+
// (e.g., when a server function is only referenced inside a createClientOnlyFn callback)
|
|
288
292
|
createServerFnPlugin({
|
|
289
293
|
framework: corePluginOpts.framework,
|
|
290
294
|
directive,
|
|
@@ -321,6 +325,7 @@ function TanStackStartVitePluginCore(corePluginOpts, startPluginOpts) {
|
|
|
321
325
|
envName: serverFnProviderEnv
|
|
322
326
|
}
|
|
323
327
|
}),
|
|
328
|
+
startCompilerPlugin({ framework: corePluginOpts.framework, environments }),
|
|
324
329
|
loadEnvPlugin(),
|
|
325
330
|
startManifestPlugin({
|
|
326
331
|
getClientBundle: () => getBundle(VITE_ENVIRONMENT_NAMES.client),
|
package/dist/esm/plugin.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.js","sources":["../../src/plugin.ts"],"sourcesContent":["import { joinPaths } from '@tanstack/router-core'\nimport { VIRTUAL_MODULES } from '@tanstack/start-server-core'\nimport { TanStackServerFnPlugin } from '@tanstack/server-functions-plugin'\nimport * as vite from 'vite'\nimport { crawlFrameworkPkgs } from 'vitefu'\nimport { join } from 'pathe'\nimport { escapePath } from 'tinyglobby'\nimport { startManifestPlugin } from './start-manifest-plugin/plugin'\nimport { startCompilerPlugin } from './start-compiler-plugin/plugin'\nimport { ENTRY_POINTS, VITE_ENVIRONMENT_NAMES } from './constants'\nimport { tanStackStartRouter } from './start-router-plugin/plugin'\nimport { loadEnvPlugin } from './load-env-plugin/plugin'\nimport { devServerPlugin } from './dev-server-plugin/plugin'\nimport { previewServerPlugin } from './preview-server-plugin/plugin'\nimport { parseStartConfig } from './schema'\nimport { resolveEntry } from './resolve-entries'\nimport {\n getClientOutputDirectory,\n getServerOutputDirectory,\n} from './output-directory'\nimport { postServerBuild } from './post-server-build'\nimport { createServerFnPlugin } from './create-server-fn-plugin/plugin'\nimport type { ViteEnvironmentNames } from './constants'\nimport type {\n TanStackStartInputConfig,\n TanStackStartOutputConfig,\n} from './schema'\nimport type { PluginOption } from 'vite'\nimport type { CompileStartFrameworkOptions } from './start-compiler-plugin/compilers'\n\nexport interface TanStackStartVitePluginCoreOptions {\n framework: CompileStartFrameworkOptions\n defaultEntryPaths: {\n client: string\n server: string\n start: string\n }\n serverFn?: {\n directive?: string\n ssr?: {\n getServerFnById?: string\n }\n providerEnv?: string\n }\n}\n\nexport interface ResolvedStartConfig {\n root: string\n startFilePath: string | undefined\n routerFilePath: string\n srcDirectory: string\n viteAppBase: string\n serverFnProviderEnv: string\n}\n\nexport type GetConfigFn = () => {\n startConfig: TanStackStartOutputConfig\n resolvedStartConfig: ResolvedStartConfig\n corePluginOpts: TanStackStartVitePluginCoreOptions\n}\n\nfunction isFullUrl(str: string): boolean {\n try {\n new URL(str)\n return true\n } catch {\n return false\n }\n}\n\nexport function TanStackStartVitePluginCore(\n corePluginOpts: TanStackStartVitePluginCoreOptions,\n startPluginOpts: TanStackStartInputConfig,\n): Array<PluginOption> {\n // Determine the provider environment for server functions\n // If providerEnv is set, use that; otherwise default to SSR as the provider\n const serverFnProviderEnv =\n corePluginOpts.serverFn?.providerEnv || VITE_ENVIRONMENT_NAMES.server\n const ssrIsProvider = serverFnProviderEnv === VITE_ENVIRONMENT_NAMES.server\n\n const resolvedStartConfig: ResolvedStartConfig = {\n root: '',\n startFilePath: undefined,\n routerFilePath: '',\n srcDirectory: '',\n viteAppBase: '',\n serverFnProviderEnv,\n }\n\n const directive = corePluginOpts.serverFn?.directive ?? 'use server'\n\n let startConfig: TanStackStartOutputConfig | null\n const getConfig: GetConfigFn = () => {\n if (!resolvedStartConfig.root) {\n throw new Error(`Cannot get config before root is resolved`)\n }\n if (!startConfig) {\n startConfig = parseStartConfig(\n startPluginOpts,\n corePluginOpts,\n resolvedStartConfig.root,\n )\n }\n return { startConfig, resolvedStartConfig, corePluginOpts }\n }\n\n const capturedBundle: Partial<\n Record<ViteEnvironmentNames, vite.Rollup.OutputBundle>\n > = {}\n\n function getBundle(envName: ViteEnvironmentNames): vite.Rollup.OutputBundle {\n const bundle = capturedBundle[envName]\n if (!bundle) {\n throw new Error(`No bundle captured for environment: ${envName}`)\n }\n return bundle\n }\n\n const environments: Array<{ name: string; type: 'client' | 'server' }> = [\n { name: VITE_ENVIRONMENT_NAMES.client, type: 'client' },\n { name: VITE_ENVIRONMENT_NAMES.server, type: 'server' },\n ]\n if (\n corePluginOpts.serverFn?.providerEnv &&\n !environments.find((e) => e.name === corePluginOpts.serverFn?.providerEnv)\n ) {\n environments.push({\n name: corePluginOpts.serverFn.providerEnv,\n type: 'server',\n })\n }\n return [\n {\n name: 'tanstack-start-core:config',\n enforce: 'pre',\n async config(viteConfig, { command }) {\n resolvedStartConfig.viteAppBase = viteConfig.base ?? '/'\n if (!isFullUrl(resolvedStartConfig.viteAppBase)) {\n resolvedStartConfig.viteAppBase = joinPaths([\n '/',\n viteConfig.base,\n '/',\n ])\n }\n const root = viteConfig.root || process.cwd()\n resolvedStartConfig.root = root\n\n const { startConfig } = getConfig()\n if (startConfig.router.basepath === undefined) {\n if (!isFullUrl(resolvedStartConfig.viteAppBase)) {\n startConfig.router.basepath =\n resolvedStartConfig.viteAppBase.replace(/^\\/|\\/$/g, '')\n } else {\n startConfig.router.basepath = '/'\n }\n } else {\n if (command === 'serve' && !viteConfig.server?.middlewareMode) {\n // when serving, we must ensure that router basepath and viteAppBase are aligned\n if (\n !joinPaths(['/', startConfig.router.basepath, '/']).startsWith(\n joinPaths(['/', resolvedStartConfig.viteAppBase, '/']),\n )\n ) {\n this.error(\n '[tanstack-start]: During `vite dev`, `router.basepath` must start with the vite `base` config value',\n )\n }\n }\n }\n\n const TSS_SERVER_FN_BASE = joinPaths([\n '/',\n startConfig.router.basepath,\n startConfig.serverFns.base,\n '/',\n ])\n const resolvedSrcDirectory = join(root, startConfig.srcDirectory)\n resolvedStartConfig.srcDirectory = resolvedSrcDirectory\n\n const startFilePath = resolveEntry({\n type: 'start entry',\n configuredEntry: startConfig.start.entry,\n defaultEntry: 'start',\n resolvedSrcDirectory,\n required: false,\n })\n resolvedStartConfig.startFilePath = startFilePath\n\n const routerFilePath = resolveEntry({\n type: 'router entry',\n configuredEntry: startConfig.router.entry,\n defaultEntry: 'router',\n resolvedSrcDirectory,\n required: true,\n })\n resolvedStartConfig.routerFilePath = routerFilePath\n\n const clientEntryPath = resolveEntry({\n type: 'client entry',\n configuredEntry: startConfig.client.entry,\n defaultEntry: 'client',\n resolvedSrcDirectory,\n required: false,\n })\n\n const serverEntryPath = resolveEntry({\n type: 'server entry',\n configuredEntry: startConfig.server.entry,\n defaultEntry: 'server',\n resolvedSrcDirectory,\n required: false,\n })\n\n const clientAlias = vite.normalizePath(\n clientEntryPath ?? corePluginOpts.defaultEntryPaths.client,\n )\n const serverAlias = vite.normalizePath(\n serverEntryPath ?? corePluginOpts.defaultEntryPaths.server,\n )\n const startAlias = vite.normalizePath(\n startFilePath ?? corePluginOpts.defaultEntryPaths.start,\n )\n const routerAlias = vite.normalizePath(routerFilePath)\n\n const entryAliasConfiguration: Record<\n (typeof ENTRY_POINTS)[keyof typeof ENTRY_POINTS],\n string\n > = {\n [ENTRY_POINTS.client]: clientAlias,\n [ENTRY_POINTS.server]: serverAlias,\n [ENTRY_POINTS.start]: startAlias,\n [ENTRY_POINTS.router]: routerAlias,\n }\n\n const startPackageName =\n `@tanstack/${corePluginOpts.framework}-start` as const\n\n // crawl packages that have start in \"peerDependencies\"\n // see https://github.com/svitejs/vitefu/blob/d8d82fa121e3b2215ba437107093c77bde51b63b/src/index.js#L95-L101\n\n // this is currently uncached; could be implemented similarly as vite handles lock file changes\n // see https://github.com/vitejs/vite/blob/557f797d29422027e8c451ca50dd84bf8c41b5f0/packages/vite/src/node/optimizer/index.ts#L1282\n\n const crawlFrameworkPkgsResult = await crawlFrameworkPkgs({\n root: process.cwd(),\n isBuild: command === 'build',\n isFrameworkPkgByJson(pkgJson) {\n const peerDependencies = pkgJson['peerDependencies']\n\n if (peerDependencies) {\n if (\n startPackageName in peerDependencies ||\n '@tanstack/start-client-core' in peerDependencies\n ) {\n return true\n }\n }\n\n return false\n },\n })\n\n return {\n // see https://vite.dev/config/shared-options.html#apptype\n // this will prevent vite from injecting middlewares that we don't want\n appType: viteConfig.appType ?? 'custom',\n environments: {\n [VITE_ENVIRONMENT_NAMES.client]: {\n consumer: 'client',\n build: {\n rollupOptions: {\n input: {\n main: ENTRY_POINTS.client,\n },\n },\n outDir: getClientOutputDirectory(viteConfig),\n },\n optimizeDeps: {\n exclude: crawlFrameworkPkgsResult.optimizeDeps.exclude,\n // Ensure user code can be crawled for dependencies\n entries: [clientAlias, routerAlias].map((entry) =>\n // Entries are treated as `tinyglobby` patterns so need to be escaped\n escapePath(entry),\n ),\n },\n },\n [VITE_ENVIRONMENT_NAMES.server]: {\n consumer: 'server',\n build: {\n ssr: true,\n rollupOptions: {\n input:\n viteConfig.environments?.[VITE_ENVIRONMENT_NAMES.server]\n ?.build?.rollupOptions?.input ?? serverAlias,\n },\n outDir: getServerOutputDirectory(viteConfig),\n commonjsOptions: {\n include: [/node_modules/],\n },\n copyPublicDir:\n viteConfig.environments?.[VITE_ENVIRONMENT_NAMES.server]\n ?.build?.copyPublicDir ?? false,\n },\n optimizeDeps: {\n // Ensure user code can be crawled for dependencies\n entries: [serverAlias, startAlias, routerAlias].map((entry) =>\n // Entries are treated as `tinyglobby` patterns so need to be escaped\n escapePath(entry),\n ),\n },\n },\n },\n\n resolve: {\n noExternal: [\n // ENTRY_POINTS.start,\n '@tanstack/start**',\n `@tanstack/${corePluginOpts.framework}-start**`,\n ...crawlFrameworkPkgsResult.ssr.noExternal.sort(),\n ],\n alias: {\n ...entryAliasConfiguration,\n },\n },\n /* prettier-ignore */\n define: {\n // define is an esbuild function that replaces the any instances of given keys with the given values\n // i.e: __FRAMEWORK_NAME__ can be replaced with JSON.stringify(\"TanStack Start\")\n // This is not the same as injecting environment variables.\n\n ...defineReplaceEnv('TSS_SERVER_FN_BASE', TSS_SERVER_FN_BASE),\n ...defineReplaceEnv('TSS_CLIENT_OUTPUT_DIR', getClientOutputDirectory(viteConfig)),\n ...defineReplaceEnv('TSS_ROUTER_BASEPATH', startConfig.router.basepath),\n ...(command === 'serve' ? defineReplaceEnv('TSS_SHELL', startConfig.spa?.enabled ? 'true' : 'false') : {}),\n ...defineReplaceEnv('TSS_DEV_SERVER', command === 'serve' ? 'true' : 'false'),\n },\n builder: {\n sharedPlugins: true,\n async buildApp(builder) {\n const client = builder.environments[VITE_ENVIRONMENT_NAMES.client]\n const server = builder.environments[VITE_ENVIRONMENT_NAMES.server]\n\n if (!client) {\n throw new Error('Client environment not found')\n }\n\n if (!server) {\n throw new Error('SSR environment not found')\n }\n\n if (!client.isBuilt) {\n // Build the client bundle first\n await builder.build(client)\n }\n if (!server.isBuilt) {\n // Build the SSR bundle\n await builder.build(server)\n }\n\n // If a custom provider environment is configured (not SSR),\n // build it last so the manifest includes functions from all environments\n if (!ssrIsProvider) {\n const providerEnv = builder.environments[serverFnProviderEnv]\n if (!providerEnv) {\n throw new Error(\n `Provider environment \"${serverFnProviderEnv}\" not found`,\n )\n }\n if (!providerEnv.isBuilt) {\n // Build the provider environment last\n // This ensures all server functions are discovered from client/ssr builds\n await builder.build(providerEnv)\n }\n }\n },\n },\n }\n },\n buildApp: {\n order: 'post',\n async handler(builder) {\n const { startConfig } = getConfig()\n await postServerBuild({ builder, startConfig })\n },\n },\n },\n tanStackStartRouter(startPluginOpts, getConfig, corePluginOpts),\n // N.B. TanStackStartCompilerPlugin must be before the TanStackServerFnPlugin\n startCompilerPlugin({ framework: corePluginOpts.framework, environments }),\n createServerFnPlugin({\n framework: corePluginOpts.framework,\n directive,\n environments,\n }),\n\n TanStackServerFnPlugin({\n // This is the ID that will be available to look up and import\n // our server function manifest and resolve its module\n manifestVirtualImportId: VIRTUAL_MODULES.serverFnManifest,\n directive,\n generateFunctionId: startPluginOpts?.serverFns?.generateFunctionId,\n callers: [\n {\n envConsumer: 'client',\n getRuntimeCode: () =>\n `import { createClientRpc } from '@tanstack/${corePluginOpts.framework}-start/client-rpc'`,\n replacer: (d) => `createClientRpc('${d.functionId}')`,\n envName: VITE_ENVIRONMENT_NAMES.client,\n },\n {\n envConsumer: 'server' as const,\n getRuntimeCode: () =>\n `import { createSsrRpc } from '@tanstack/${corePluginOpts.framework}-start/ssr-rpc'`,\n envName: VITE_ENVIRONMENT_NAMES.server,\n replacer: (d: any) =>\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 d.isClientReferenced || !ssrIsProvider\n ? `createSsrRpc('${d.functionId}')`\n : `createSsrRpc('${d.functionId}', () => import(${JSON.stringify(d.extractedFilename)}).then(m => m['${d.functionName}']))`,\n },\n ],\n provider: {\n getRuntimeCode: () =>\n `import { createServerRpc } from '@tanstack/${corePluginOpts.framework}-start/server-rpc'`,\n replacer: (d) => `createServerRpc('${d.functionId}', ${d.fn})`,\n envName: serverFnProviderEnv,\n },\n }),\n loadEnvPlugin(),\n startManifestPlugin({\n getClientBundle: () => getBundle(VITE_ENVIRONMENT_NAMES.client),\n getConfig,\n }),\n devServerPlugin({ getConfig }),\n previewServerPlugin(),\n {\n name: 'tanstack-start:core:capture-bundle',\n applyToEnvironment(e) {\n return (\n e.name === VITE_ENVIRONMENT_NAMES.client ||\n e.name === VITE_ENVIRONMENT_NAMES.server\n )\n },\n enforce: 'post',\n generateBundle(_options, bundle) {\n const environment = this.environment.name as ViteEnvironmentNames\n if (!Object.values(VITE_ENVIRONMENT_NAMES).includes(environment)) {\n throw new Error(`Unknown environment: ${environment}`)\n }\n capturedBundle[environment] = bundle\n },\n },\n ]\n}\n\nfunction defineReplaceEnv<TKey extends string, TValue extends string>(\n key: TKey,\n value: TValue,\n): { [P in `process.env.${TKey}` | `import.meta.env.${TKey}`]: TValue } {\n return {\n [`process.env.${key}`]: JSON.stringify(value),\n [`import.meta.env.${key}`]: JSON.stringify(value),\n } as { [P in `process.env.${TKey}` | `import.meta.env.${TKey}`]: TValue }\n}\n"],"names":["startConfig"],"mappings":";;;;;;;;;;;;;;;;;;;AA6DA,SAAS,UAAU,KAAsB;AACvC,MAAI;AACF,QAAI,IAAI,GAAG;AACX,WAAO;AAAA,EACT,QAAQ;AACN,WAAO;AAAA,EACT;AACF;AAEO,SAAS,4BACd,gBACA,iBACqB;AAGrB,QAAM,sBACJ,eAAe,UAAU,eAAe,uBAAuB;AACjE,Q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AACA,uBAAe,WAAW,IAAI;AAAA,MAChC;AAAA,IAAA;AAAA,EACF;AAEJ;AAEA,SAAS,iBACP,KACA,OACsE;AACtE,SAAO;AAAA,IACL,CAAC,eAAe,GAAG,EAAE,GAAG,KAAK,UAAU,KAAK;AAAA,IAC5C,CAAC,mBAAmB,GAAG,EAAE,GAAG,KAAK,UAAU,KAAK;AAAA,EAAA;AAEpD;"}
|
|
1
|
+
{"version":3,"file":"plugin.js","sources":["../../src/plugin.ts"],"sourcesContent":["import { joinPaths } from '@tanstack/router-core'\nimport { VIRTUAL_MODULES } from '@tanstack/start-server-core'\nimport { TanStackServerFnPlugin } from '@tanstack/server-functions-plugin'\nimport * as vite from 'vite'\nimport { crawlFrameworkPkgs } from 'vitefu'\nimport { join } from 'pathe'\nimport { escapePath } from 'tinyglobby'\nimport { startManifestPlugin } from './start-manifest-plugin/plugin'\nimport { startCompilerPlugin } from './start-compiler-plugin/plugin'\nimport { ENTRY_POINTS, VITE_ENVIRONMENT_NAMES } from './constants'\nimport { tanStackStartRouter } from './start-router-plugin/plugin'\nimport { loadEnvPlugin } from './load-env-plugin/plugin'\nimport { devServerPlugin } from './dev-server-plugin/plugin'\nimport { previewServerPlugin } from './preview-server-plugin/plugin'\nimport { parseStartConfig } from './schema'\nimport { resolveEntry } from './resolve-entries'\nimport {\n getClientOutputDirectory,\n getServerOutputDirectory,\n} from './output-directory'\nimport { postServerBuild } from './post-server-build'\nimport { createServerFnPlugin } from './create-server-fn-plugin/plugin'\nimport type { ViteEnvironmentNames } from './constants'\nimport type {\n TanStackStartInputConfig,\n TanStackStartOutputConfig,\n} from './schema'\nimport type { PluginOption } from 'vite'\nimport type { CompileStartFrameworkOptions } from './start-compiler-plugin/compilers'\n\nexport interface TanStackStartVitePluginCoreOptions {\n framework: CompileStartFrameworkOptions\n defaultEntryPaths: {\n client: string\n server: string\n start: string\n }\n serverFn?: {\n directive?: string\n ssr?: {\n getServerFnById?: string\n }\n providerEnv?: string\n }\n}\n\nexport interface ResolvedStartConfig {\n root: string\n startFilePath: string | undefined\n routerFilePath: string\n srcDirectory: string\n viteAppBase: string\n serverFnProviderEnv: string\n}\n\nexport type GetConfigFn = () => {\n startConfig: TanStackStartOutputConfig\n resolvedStartConfig: ResolvedStartConfig\n corePluginOpts: TanStackStartVitePluginCoreOptions\n}\n\nfunction isFullUrl(str: string): boolean {\n try {\n new URL(str)\n return true\n } catch {\n return false\n }\n}\n\nexport function TanStackStartVitePluginCore(\n corePluginOpts: TanStackStartVitePluginCoreOptions,\n startPluginOpts: TanStackStartInputConfig,\n): Array<PluginOption> {\n // Determine the provider environment for server functions\n // If providerEnv is set, use that; otherwise default to SSR as the provider\n const serverFnProviderEnv =\n corePluginOpts.serverFn?.providerEnv || VITE_ENVIRONMENT_NAMES.server\n const ssrIsProvider = serverFnProviderEnv === VITE_ENVIRONMENT_NAMES.server\n\n const resolvedStartConfig: ResolvedStartConfig = {\n root: '',\n startFilePath: undefined,\n routerFilePath: '',\n srcDirectory: '',\n viteAppBase: '',\n serverFnProviderEnv,\n }\n\n const directive = corePluginOpts.serverFn?.directive ?? 'use server'\n\n let startConfig: TanStackStartOutputConfig | null\n const getConfig: GetConfigFn = () => {\n if (!resolvedStartConfig.root) {\n throw new Error(`Cannot get config before root is resolved`)\n }\n if (!startConfig) {\n startConfig = parseStartConfig(\n startPluginOpts,\n corePluginOpts,\n resolvedStartConfig.root,\n )\n }\n return { startConfig, resolvedStartConfig, corePluginOpts }\n }\n\n const capturedBundle: Partial<\n Record<ViteEnvironmentNames, vite.Rollup.OutputBundle>\n > = {}\n\n function getBundle(envName: ViteEnvironmentNames): vite.Rollup.OutputBundle {\n const bundle = capturedBundle[envName]\n if (!bundle) {\n throw new Error(`No bundle captured for environment: ${envName}`)\n }\n return bundle\n }\n\n const environments: Array<{ name: string; type: 'client' | 'server' }> = [\n { name: VITE_ENVIRONMENT_NAMES.client, type: 'client' },\n { name: VITE_ENVIRONMENT_NAMES.server, type: 'server' },\n ]\n if (\n corePluginOpts.serverFn?.providerEnv &&\n !environments.find((e) => e.name === corePluginOpts.serverFn?.providerEnv)\n ) {\n environments.push({\n name: corePluginOpts.serverFn.providerEnv,\n type: 'server',\n })\n }\n return [\n {\n name: 'tanstack-start-core:config',\n enforce: 'pre',\n async config(viteConfig, { command }) {\n resolvedStartConfig.viteAppBase = viteConfig.base ?? '/'\n if (!isFullUrl(resolvedStartConfig.viteAppBase)) {\n resolvedStartConfig.viteAppBase = joinPaths([\n '/',\n viteConfig.base,\n '/',\n ])\n }\n const root = viteConfig.root || process.cwd()\n resolvedStartConfig.root = root\n\n const { startConfig } = getConfig()\n if (startConfig.router.basepath === undefined) {\n if (!isFullUrl(resolvedStartConfig.viteAppBase)) {\n startConfig.router.basepath =\n resolvedStartConfig.viteAppBase.replace(/^\\/|\\/$/g, '')\n } else {\n startConfig.router.basepath = '/'\n }\n } else {\n if (command === 'serve' && !viteConfig.server?.middlewareMode) {\n // when serving, we must ensure that router basepath and viteAppBase are aligned\n if (\n !joinPaths(['/', startConfig.router.basepath, '/']).startsWith(\n joinPaths(['/', resolvedStartConfig.viteAppBase, '/']),\n )\n ) {\n this.error(\n '[tanstack-start]: During `vite dev`, `router.basepath` must start with the vite `base` config value',\n )\n }\n }\n }\n\n const TSS_SERVER_FN_BASE = joinPaths([\n '/',\n startConfig.router.basepath,\n startConfig.serverFns.base,\n '/',\n ])\n const resolvedSrcDirectory = join(root, startConfig.srcDirectory)\n resolvedStartConfig.srcDirectory = resolvedSrcDirectory\n\n const startFilePath = resolveEntry({\n type: 'start entry',\n configuredEntry: startConfig.start.entry,\n defaultEntry: 'start',\n resolvedSrcDirectory,\n required: false,\n })\n resolvedStartConfig.startFilePath = startFilePath\n\n const routerFilePath = resolveEntry({\n type: 'router entry',\n configuredEntry: startConfig.router.entry,\n defaultEntry: 'router',\n resolvedSrcDirectory,\n required: true,\n })\n resolvedStartConfig.routerFilePath = routerFilePath\n\n const clientEntryPath = resolveEntry({\n type: 'client entry',\n configuredEntry: startConfig.client.entry,\n defaultEntry: 'client',\n resolvedSrcDirectory,\n required: false,\n })\n\n const serverEntryPath = resolveEntry({\n type: 'server entry',\n configuredEntry: startConfig.server.entry,\n defaultEntry: 'server',\n resolvedSrcDirectory,\n required: false,\n })\n\n const clientAlias = vite.normalizePath(\n clientEntryPath ?? corePluginOpts.defaultEntryPaths.client,\n )\n const serverAlias = vite.normalizePath(\n serverEntryPath ?? corePluginOpts.defaultEntryPaths.server,\n )\n const startAlias = vite.normalizePath(\n startFilePath ?? corePluginOpts.defaultEntryPaths.start,\n )\n const routerAlias = vite.normalizePath(routerFilePath)\n\n const entryAliasConfiguration: Record<\n (typeof ENTRY_POINTS)[keyof typeof ENTRY_POINTS],\n string\n > = {\n [ENTRY_POINTS.client]: clientAlias,\n [ENTRY_POINTS.server]: serverAlias,\n [ENTRY_POINTS.start]: startAlias,\n [ENTRY_POINTS.router]: routerAlias,\n }\n\n const startPackageName =\n `@tanstack/${corePluginOpts.framework}-start` as const\n\n // crawl packages that have start in \"peerDependencies\"\n // see https://github.com/svitejs/vitefu/blob/d8d82fa121e3b2215ba437107093c77bde51b63b/src/index.js#L95-L101\n\n // this is currently uncached; could be implemented similarly as vite handles lock file changes\n // see https://github.com/vitejs/vite/blob/557f797d29422027e8c451ca50dd84bf8c41b5f0/packages/vite/src/node/optimizer/index.ts#L1282\n\n const crawlFrameworkPkgsResult = await crawlFrameworkPkgs({\n root: process.cwd(),\n isBuild: command === 'build',\n isFrameworkPkgByJson(pkgJson) {\n const peerDependencies = pkgJson['peerDependencies']\n\n if (peerDependencies) {\n if (\n startPackageName in peerDependencies ||\n '@tanstack/start-client-core' in peerDependencies\n ) {\n return true\n }\n }\n\n return false\n },\n })\n\n return {\n // see https://vite.dev/config/shared-options.html#apptype\n // this will prevent vite from injecting middlewares that we don't want\n appType: viteConfig.appType ?? 'custom',\n environments: {\n [VITE_ENVIRONMENT_NAMES.client]: {\n consumer: 'client',\n build: {\n rollupOptions: {\n input: {\n main: ENTRY_POINTS.client,\n },\n },\n outDir: getClientOutputDirectory(viteConfig),\n },\n optimizeDeps: {\n exclude: crawlFrameworkPkgsResult.optimizeDeps.exclude,\n // Ensure user code can be crawled for dependencies\n entries: [clientAlias, routerAlias].map((entry) =>\n // Entries are treated as `tinyglobby` patterns so need to be escaped\n escapePath(entry),\n ),\n },\n },\n [VITE_ENVIRONMENT_NAMES.server]: {\n consumer: 'server',\n build: {\n ssr: true,\n rollupOptions: {\n input:\n viteConfig.environments?.[VITE_ENVIRONMENT_NAMES.server]\n ?.build?.rollupOptions?.input ?? serverAlias,\n },\n outDir: getServerOutputDirectory(viteConfig),\n commonjsOptions: {\n include: [/node_modules/],\n },\n copyPublicDir:\n viteConfig.environments?.[VITE_ENVIRONMENT_NAMES.server]\n ?.build?.copyPublicDir ?? false,\n },\n optimizeDeps: {\n // Ensure user code can be crawled for dependencies\n entries: [serverAlias, startAlias, routerAlias].map((entry) =>\n // Entries are treated as `tinyglobby` patterns so need to be escaped\n escapePath(entry),\n ),\n },\n },\n },\n\n resolve: {\n noExternal: [\n // ENTRY_POINTS.start,\n '@tanstack/start**',\n `@tanstack/${corePluginOpts.framework}-start**`,\n ...crawlFrameworkPkgsResult.ssr.noExternal.sort(),\n ],\n alias: {\n ...entryAliasConfiguration,\n },\n },\n /* prettier-ignore */\n define: {\n // define is an esbuild function that replaces the any instances of given keys with the given values\n // i.e: __FRAMEWORK_NAME__ can be replaced with JSON.stringify(\"TanStack Start\")\n // This is not the same as injecting environment variables.\n\n ...defineReplaceEnv('TSS_SERVER_FN_BASE', TSS_SERVER_FN_BASE),\n ...defineReplaceEnv('TSS_CLIENT_OUTPUT_DIR', getClientOutputDirectory(viteConfig)),\n ...defineReplaceEnv('TSS_ROUTER_BASEPATH', startConfig.router.basepath),\n ...(command === 'serve' ? defineReplaceEnv('TSS_SHELL', startConfig.spa?.enabled ? 'true' : 'false') : {}),\n ...defineReplaceEnv('TSS_DEV_SERVER', command === 'serve' ? 'true' : 'false'),\n },\n builder: {\n sharedPlugins: true,\n async buildApp(builder) {\n const client = builder.environments[VITE_ENVIRONMENT_NAMES.client]\n const server = builder.environments[VITE_ENVIRONMENT_NAMES.server]\n\n if (!client) {\n throw new Error('Client environment not found')\n }\n\n if (!server) {\n throw new Error('SSR environment not found')\n }\n\n if (!client.isBuilt) {\n // Build the client bundle first\n await builder.build(client)\n }\n if (!server.isBuilt) {\n // Build the SSR bundle\n await builder.build(server)\n }\n\n // If a custom provider environment is configured (not SSR),\n // build it last so the manifest includes functions from all environments\n if (!ssrIsProvider) {\n const providerEnv = builder.environments[serverFnProviderEnv]\n if (!providerEnv) {\n throw new Error(\n `Provider environment \"${serverFnProviderEnv}\" not found`,\n )\n }\n if (!providerEnv.isBuilt) {\n // Build the provider environment last\n // This ensures all server functions are discovered from client/ssr builds\n await builder.build(providerEnv)\n }\n }\n },\n },\n }\n },\n buildApp: {\n order: 'post',\n async handler(builder) {\n const { startConfig } = getConfig()\n await postServerBuild({ builder, startConfig })\n },\n },\n },\n tanStackStartRouter(startPluginOpts, getConfig, corePluginOpts),\n // N.B. Server function plugins must run BEFORE startCompilerPlugin because:\n // 1. createServerFnPlugin transforms createServerFn().handler() to inject 'use server' directive\n // 2. TanStackServerFnPlugin extracts 'use server' functions and registers them in the manifest\n // 3. startCompilerPlugin handles createClientOnlyFn/createServerOnlyFn and runs DCE\n // If startCompilerPlugin runs first, DCE may remove server function code before it can be registered\n // (e.g., when a server function is only referenced inside a createClientOnlyFn callback)\n createServerFnPlugin({\n framework: corePluginOpts.framework,\n directive,\n environments,\n }),\n TanStackServerFnPlugin({\n // This is the ID that will be available to look up and import\n // our server function manifest and resolve its module\n manifestVirtualImportId: VIRTUAL_MODULES.serverFnManifest,\n directive,\n generateFunctionId: startPluginOpts?.serverFns?.generateFunctionId,\n callers: [\n {\n envConsumer: 'client',\n getRuntimeCode: () =>\n `import { createClientRpc } from '@tanstack/${corePluginOpts.framework}-start/client-rpc'`,\n replacer: (d) => `createClientRpc('${d.functionId}')`,\n envName: VITE_ENVIRONMENT_NAMES.client,\n },\n {\n envConsumer: 'server' as const,\n getRuntimeCode: () =>\n `import { createSsrRpc } from '@tanstack/${corePluginOpts.framework}-start/ssr-rpc'`,\n envName: VITE_ENVIRONMENT_NAMES.server,\n replacer: (d: any) =>\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 d.isClientReferenced || !ssrIsProvider\n ? `createSsrRpc('${d.functionId}')`\n : `createSsrRpc('${d.functionId}', () => import(${JSON.stringify(d.extractedFilename)}).then(m => m['${d.functionName}']))`,\n },\n ],\n provider: {\n getRuntimeCode: () =>\n `import { createServerRpc } from '@tanstack/${corePluginOpts.framework}-start/server-rpc'`,\n replacer: (d) => `createServerRpc('${d.functionId}', ${d.fn})`,\n envName: serverFnProviderEnv,\n },\n }),\n startCompilerPlugin({ framework: corePluginOpts.framework, environments }),\n loadEnvPlugin(),\n startManifestPlugin({\n getClientBundle: () => getBundle(VITE_ENVIRONMENT_NAMES.client),\n getConfig,\n }),\n devServerPlugin({ getConfig }),\n previewServerPlugin(),\n {\n name: 'tanstack-start:core:capture-bundle',\n applyToEnvironment(e) {\n return (\n e.name === VITE_ENVIRONMENT_NAMES.client ||\n e.name === VITE_ENVIRONMENT_NAMES.server\n )\n },\n enforce: 'post',\n generateBundle(_options, bundle) {\n const environment = this.environment.name as ViteEnvironmentNames\n if (!Object.values(VITE_ENVIRONMENT_NAMES).includes(environment)) {\n throw new Error(`Unknown environment: ${environment}`)\n }\n capturedBundle[environment] = bundle\n },\n },\n ]\n}\n\nfunction defineReplaceEnv<TKey extends string, TValue extends string>(\n key: TKey,\n value: TValue,\n): { [P in `process.env.${TKey}` | `import.meta.env.${TKey}`]: TValue } {\n return {\n [`process.env.${key}`]: JSON.stringify(value),\n [`import.meta.env.${key}`]: JSON.stringify(value),\n } as { [P in `process.env.${TKey}` | `import.meta.env.${T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AAA,MACN,mBAAmB,GAAG;AACpB,eACE,EAAE,SAAS,uBAAuB,UAClC,EAAE,SAAS,uBAAuB;AAAA,MAEtC;AAAA,MACA,SAAS;AAAA,MACT,eAAe,UAAU,QAAQ;AAC/B,cAAM,cAAc,KAAK,YAAY;AACrC,YAAI,CAAC,OAAO,OAAO,sBAAsB,EAAE,SAAS,WAAW,GAAG;AAChE,gBAAM,IAAI,MAAM,wBAAwB,WAAW,EAAE;AAAA,QACvD;AACA,uBAAe,WAAW,IAAI;AAAA,MAChC;AAAA,IAAA;AAAA,EACF;AAEJ;AAEA,SAAS,iBACP,KACA,OACsE;AACtE,SAAO;AAAA,IACL,CAAC,eAAe,GAAG,EAAE,GAAG,KAAK,UAAU,KAAK;AAAA,IAC5C,CAAC,mBAAmB,GAAG,EAAE,GAAG,KAAK,UAAU,KAAK;AAAA,EAAA;AAEpD;"}
|
package/dist/esm/schema.d.ts
CHANGED
|
@@ -49,10 +49,10 @@ export declare function parseStartConfig(opts: z.input<typeof tanstackStartOptio
|
|
|
49
49
|
server: {
|
|
50
50
|
entry?: string | undefined;
|
|
51
51
|
};
|
|
52
|
+
srcDirectory: string;
|
|
52
53
|
start: {
|
|
53
54
|
entry?: string | undefined;
|
|
54
55
|
};
|
|
55
|
-
srcDirectory: string;
|
|
56
56
|
serverFns: {
|
|
57
57
|
base: string;
|
|
58
58
|
generateFunctionId?: ((args_0: {
|
|
@@ -3042,10 +3042,10 @@ declare const tanstackStartOptionsSchema: z.ZodDefault<z.ZodOptional<z.ZodObject
|
|
|
3042
3042
|
server: {
|
|
3043
3043
|
entry?: string | undefined;
|
|
3044
3044
|
};
|
|
3045
|
+
srcDirectory: string;
|
|
3045
3046
|
start: {
|
|
3046
3047
|
entry?: string | undefined;
|
|
3047
3048
|
};
|
|
3048
|
-
srcDirectory: string;
|
|
3049
3049
|
router: {
|
|
3050
3050
|
entry?: string | undefined;
|
|
3051
3051
|
basepath?: string | undefined;
|
|
@@ -3371,10 +3371,10 @@ declare const tanstackStartOptionsSchema: z.ZodDefault<z.ZodOptional<z.ZodObject
|
|
|
3371
3371
|
} | undefined;
|
|
3372
3372
|
maskPath?: string | undefined;
|
|
3373
3373
|
} | undefined;
|
|
3374
|
+
srcDirectory?: string | undefined;
|
|
3374
3375
|
start?: {
|
|
3375
3376
|
entry?: string | undefined;
|
|
3376
3377
|
} | undefined;
|
|
3377
|
-
srcDirectory?: string | undefined;
|
|
3378
3378
|
router?: ({
|
|
3379
3379
|
entry?: string | undefined;
|
|
3380
3380
|
basepath?: string | undefined;
|
|
@@ -2,7 +2,6 @@ import * as babel from "@babel/core";
|
|
|
2
2
|
import * as t from "@babel/types";
|
|
3
3
|
import { findReferencedIdentifiers, deadCodeElimination } from "babel-dead-code-elimination";
|
|
4
4
|
import { parseAst, generateFromAst } from "@tanstack/router-utils";
|
|
5
|
-
import { handleCreateMiddleware } from "../create-server-fn-plugin/handleCreateMiddleware.js";
|
|
6
5
|
import { transformFuncs } from "./constants.js";
|
|
7
6
|
import { handleCreateIsomorphicFnCallExpression } from "./isomorphicFn.js";
|
|
8
7
|
import { handleCreateClientOnlyFnCallExpression, handleCreateServerOnlyFnCallExpression } from "./envOnly.js";
|
|
@@ -25,13 +24,6 @@ function compileStartOutputFactory(framework) {
|
|
|
25
24
|
paths: []
|
|
26
25
|
}
|
|
27
26
|
};
|
|
28
|
-
if (opts.env === "client") {
|
|
29
|
-
identifiers.createMiddleware = {
|
|
30
|
-
name: "createMiddleware",
|
|
31
|
-
handleCallExpression: handleCreateMiddleware,
|
|
32
|
-
paths: []
|
|
33
|
-
};
|
|
34
|
-
}
|
|
35
27
|
const ast = parseAst(opts);
|
|
36
28
|
const doDce = opts.dce ?? true;
|
|
37
29
|
const refIdents = doDce ? findReferencedIdentifiers(ast) : void 0;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"compilers.js","sources":["../../../src/start-compiler-plugin/compilers.ts"],"sourcesContent":["import * as babel from '@babel/core'\nimport * as t from '@babel/types'\n\nimport {\n deadCodeElimination,\n findReferencedIdentifiers,\n} from 'babel-dead-code-elimination'\nimport { generateFromAst, parseAst } from '@tanstack/router-utils'\nimport {
|
|
1
|
+
{"version":3,"file":"compilers.js","sources":["../../../src/start-compiler-plugin/compilers.ts"],"sourcesContent":["import * as babel from '@babel/core'\nimport * as t from '@babel/types'\n\nimport {\n deadCodeElimination,\n findReferencedIdentifiers,\n} from 'babel-dead-code-elimination'\nimport { generateFromAst, parseAst } from '@tanstack/router-utils'\nimport { transformFuncs } from './constants'\nimport { handleCreateIsomorphicFnCallExpression } from './isomorphicFn'\nimport {\n handleCreateClientOnlyFnCallExpression,\n handleCreateServerOnlyFnCallExpression,\n} from './envOnly'\nimport type { GeneratorResult, ParseAstOptions } from '@tanstack/router-utils'\n\nexport type CompileStartFrameworkOptions = 'react' | 'solid' | 'vue'\n\ntype Identifiers = { [K in (typeof transformFuncs)[number]]: IdentifierConfig }\n\nexport function compileStartOutputFactory(\n framework: CompileStartFrameworkOptions,\n) {\n return function compileStartOutput(opts: CompileOptions): GeneratorResult {\n const identifiers: Partial<Identifiers> = {\n createServerOnlyFn: {\n name: 'createServerOnlyFn',\n handleCallExpression: handleCreateServerOnlyFnCallExpression,\n paths: [],\n },\n createClientOnlyFn: {\n name: 'createClientOnlyFn',\n handleCallExpression: handleCreateClientOnlyFnCallExpression,\n paths: [],\n },\n createIsomorphicFn: {\n name: 'createIsomorphicFn',\n handleCallExpression: handleCreateIsomorphicFnCallExpression,\n paths: [],\n },\n }\n\n const ast = parseAst(opts)\n\n const doDce = opts.dce ?? true\n // find referenced identifiers *before* we transform anything\n const refIdents = doDce ? findReferencedIdentifiers(ast) : undefined\n\n const validImportSources = [\n `@tanstack/${framework}-start`,\n '@tanstack/start-client-core',\n ]\n babel.traverse(ast, {\n Program: {\n enter(programPath) {\n programPath.traverse({\n ImportDeclaration: (path) => {\n if (!validImportSources.includes(path.node.source.value)) {\n return\n }\n\n // handle a destructured imports being renamed like \"import { createServerFn as myCreateServerFn } from '@tanstack/react-start';\"\n path.node.specifiers.forEach((specifier) => {\n transformFuncs.forEach((identifierKey) => {\n const identifier = identifiers[identifierKey]\n if (!identifier) {\n return\n }\n if (\n specifier.type === 'ImportSpecifier' &&\n specifier.imported.type === 'Identifier'\n ) {\n if (specifier.imported.name === identifierKey) {\n identifier.name = specifier.local.name\n }\n }\n\n // handle namespace imports like \"import * as TanStackStart from '@tanstack/react-start';\"\n if (specifier.type === 'ImportNamespaceSpecifier') {\n identifier.name = `${specifier.local.name}.${identifierKey}`\n }\n })\n })\n },\n CallExpression: (path) => {\n transformFuncs.forEach((identifierKey) => {\n const identifier = identifiers[identifierKey]\n if (!identifier) {\n return\n }\n // Check to see if the call expression is a call to the\n // identifiers[identifierKey].name\n if (\n t.isIdentifier(path.node.callee) &&\n path.node.callee.name === identifier.name\n ) {\n // The identifier could be a call to the original function\n // in the source code. If this is case, we need to ignore it.\n // Check the scope to see if the identifier is a function declaration.\n // if it is, then we can ignore it.\n\n if (\n path.scope.getBinding(identifier.name)?.path.node.type ===\n 'FunctionDeclaration'\n ) {\n return\n }\n\n return identifier.paths.push(path)\n }\n\n // handle namespace imports like \"import * as TanStackStart from '@tanstack/react-start';\"\n // which are then called like \"TanStackStart.createServerFn()\"\n if (t.isMemberExpression(path.node.callee)) {\n if (\n t.isIdentifier(path.node.callee.object) &&\n t.isIdentifier(path.node.callee.property)\n ) {\n const callname = [\n path.node.callee.object.name,\n path.node.callee.property.name,\n ].join('.')\n\n if (callname === identifier.name) {\n identifier.paths.push(path)\n }\n }\n }\n\n return\n })\n },\n })\n\n transformFuncs.forEach((identifierKey) => {\n const identifier = identifiers[identifierKey]\n if (!identifier) {\n return\n }\n identifier.paths.forEach((path) => {\n identifier.handleCallExpression(\n path as babel.NodePath<t.CallExpression>,\n opts,\n )\n })\n })\n },\n },\n })\n\n if (doDce) {\n deadCodeElimination(ast, refIdents)\n }\n\n return generateFromAst(ast, {\n sourceMaps: true,\n sourceFileName: opts.filename,\n filename: opts.filename,\n })\n }\n}\n\nexport type CompileOptions = ParseAstOptions & {\n env: 'server' | 'client'\n dce?: boolean\n filename: string\n}\n\nexport type IdentifierConfig = {\n name: string\n handleCallExpression: (\n path: babel.NodePath<t.CallExpression>,\n opts: CompileOptions,\n ) => void\n paths: Array<babel.NodePath>\n}\n"],"names":[],"mappings":";;;;;;;AAoBO,SAAS,0BACd,WACA;AACA,SAAO,SAAS,mBAAmB,MAAuC;AACxE,UAAM,cAAoC;AAAA,MACxC,oBAAoB;AAAA,QAClB,MAAM;AAAA,QACN,sBAAsB;AAAA,QACtB,OAAO,CAAA;AAAA,MAAC;AAAA,MAEV,oBAAoB;AAAA,QAClB,MAAM;AAAA,QACN,sBAAsB;AAAA,QACtB,OAAO,CAAA;AAAA,MAAC;AAAA,MAEV,oBAAoB;AAAA,QAClB,MAAM;AAAA,QACN,sBAAsB;AAAA,QACtB,OAAO,CAAA;AAAA,MAAC;AAAA,IACV;AAGF,UAAM,MAAM,SAAS,IAAI;AAEzB,UAAM,QAAQ,KAAK,OAAO;AAE1B,UAAM,YAAY,QAAQ,0BAA0B,GAAG,IAAI;AAE3D,UAAM,qBAAqB;AAAA,MACzB,aAAa,SAAS;AAAA,MACtB;AAAA,IAAA;AAEF,UAAM,SAAS,KAAK;AAAA,MAClB,SAAS;AAAA,QACP,MAAM,aAAa;AACjB,sBAAY,SAAS;AAAA,YACnB,mBAAmB,CAAC,SAAS;AAC3B,kBAAI,CAAC,mBAAmB,SAAS,KAAK,KAAK,OAAO,KAAK,GAAG;AACxD;AAAA,cACF;AAGA,mBAAK,KAAK,WAAW,QAAQ,CAAC,cAAc;AAC1C,+BAAe,QAAQ,CAAC,kBAAkB;AACxC,wBAAM,aAAa,YAAY,aAAa;AAC5C,sBAAI,CAAC,YAAY;AACf;AAAA,kBACF;AACA,sBACE,UAAU,SAAS,qBACnB,UAAU,SAAS,SAAS,cAC5B;AACA,wBAAI,UAAU,SAAS,SAAS,eAAe;AAC7C,iCAAW,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AAA;AAAA,IACF,CACD;AAED,QAAI,OAAO;AACT,0BAAoB,KAAK,SAAS;AAAA,IACpC;AAEA,WAAO,gBAAgB,KAAK;AAAA,MAC1B,YAAY;AAAA,MACZ,gBAAgB,KAAK;AAAA,MACrB,UAAU,KAAK;AAAA,IAAA,CAChB;AAAA,EACH;AACF;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const transformFuncs: readonly ["createServerOnlyFn", "createClientOnlyFn", "createIsomorphicFn"
|
|
1
|
+
export declare const transformFuncs: readonly ["createServerOnlyFn", "createClientOnlyFn", "createIsomorphicFn"];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.js","sources":["../../../src/start-compiler-plugin/constants.ts"],"sourcesContent":["export const transformFuncs = [\n 'createServerOnlyFn',\n 'createClientOnlyFn',\n 'createIsomorphicFn',\n
|
|
1
|
+
{"version":3,"file":"constants.js","sources":["../../../src/start-compiler-plugin/constants.ts"],"sourcesContent":["export const transformFuncs = [\n 'createServerOnlyFn',\n 'createClientOnlyFn',\n 'createIsomorphicFn',\n] as const\n"],"names":[],"mappings":"AAAO,MAAM,iBAAiB;AAAA,EAC5B;AAAA,EACA;AAAA,EACA;AACF;"}
|
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.2",
|
|
4
4
|
"description": "Modern and scalable routing for React applications",
|
|
5
5
|
"author": "Tanner Linsley",
|
|
6
6
|
"license": "MIT",
|
|
@@ -59,8 +59,8 @@
|
|
|
59
59
|
"vitefu": "^1.1.1",
|
|
60
60
|
"xmlbuilder2": "^4.0.0",
|
|
61
61
|
"zod": "^3.24.2",
|
|
62
|
-
"@tanstack/router-generator": "1.142.0",
|
|
63
62
|
"@tanstack/router-core": "1.141.8",
|
|
63
|
+
"@tanstack/router-generator": "1.142.0",
|
|
64
64
|
"@tanstack/router-utils": "1.141.0",
|
|
65
65
|
"@tanstack/router-plugin": "1.142.0",
|
|
66
66
|
"@tanstack/server-functions-plugin": "1.142.1",
|
|
@@ -8,14 +8,11 @@ export function handleCreateMiddleware(
|
|
|
8
8
|
env: 'client' | 'server'
|
|
9
9
|
},
|
|
10
10
|
) {
|
|
11
|
+
if (opts.env === 'server') {
|
|
12
|
+
throw new Error('handleCreateMiddleware should not be called on the server')
|
|
13
|
+
}
|
|
11
14
|
const rootCallExpression = getRootCallExpression(path)
|
|
12
15
|
|
|
13
|
-
// if (debug)
|
|
14
|
-
// console.info(
|
|
15
|
-
// 'Handling createMiddleware call expression:',
|
|
16
|
-
// rootCallExpression.toString(),
|
|
17
|
-
// )
|
|
18
|
-
|
|
19
16
|
const callExpressionPaths = {
|
|
20
17
|
middleware: null as babel.NodePath<t.CallExpression> | null,
|
|
21
18
|
inputValidator: null as babel.NodePath<t.CallExpression> | null,
|
|
@@ -51,15 +48,11 @@ export function handleCreateMiddleware(
|
|
|
51
48
|
)
|
|
52
49
|
}
|
|
53
50
|
|
|
54
|
-
//
|
|
55
|
-
if (
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
)
|
|
59
|
-
callExpressionPaths.inputValidator.replaceWith(
|
|
60
|
-
callExpressionPaths.inputValidator.node.callee.object,
|
|
61
|
-
)
|
|
62
|
-
}
|
|
51
|
+
// remove the validator call expression
|
|
52
|
+
if (t.isMemberExpression(callExpressionPaths.inputValidator.node.callee)) {
|
|
53
|
+
callExpressionPaths.inputValidator.replaceWith(
|
|
54
|
+
callExpressionPaths.inputValidator.node.callee.object,
|
|
55
|
+
)
|
|
63
56
|
}
|
|
64
57
|
}
|
|
65
58
|
|
|
@@ -67,12 +60,8 @@ export function handleCreateMiddleware(
|
|
|
67
60
|
'arguments.0',
|
|
68
61
|
) as babel.NodePath<any>
|
|
69
62
|
|
|
70
|
-
if (
|
|
71
|
-
|
|
72
|
-
serverFnPath.node &&
|
|
73
|
-
opts.env === 'client'
|
|
74
|
-
) {
|
|
75
|
-
// If we're on the client, remove the server call expression
|
|
63
|
+
if (callExpressionPaths.server && serverFnPath.node) {
|
|
64
|
+
// remove the server call expression
|
|
76
65
|
if (t.isMemberExpression(callExpressionPaths.server.node.callee)) {
|
|
77
66
|
callExpressionPaths.server.replaceWith(
|
|
78
67
|
callExpressionPaths.server.node.callee.object,
|
package/src/plugin.ts
CHANGED
|
@@ -385,14 +385,17 @@ export function TanStackStartVitePluginCore(
|
|
|
385
385
|
},
|
|
386
386
|
},
|
|
387
387
|
tanStackStartRouter(startPluginOpts, getConfig, corePluginOpts),
|
|
388
|
-
// N.B.
|
|
389
|
-
|
|
388
|
+
// N.B. Server function plugins must run BEFORE startCompilerPlugin because:
|
|
389
|
+
// 1. createServerFnPlugin transforms createServerFn().handler() to inject 'use server' directive
|
|
390
|
+
// 2. TanStackServerFnPlugin extracts 'use server' functions and registers them in the manifest
|
|
391
|
+
// 3. startCompilerPlugin handles createClientOnlyFn/createServerOnlyFn and runs DCE
|
|
392
|
+
// If startCompilerPlugin runs first, DCE may remove server function code before it can be registered
|
|
393
|
+
// (e.g., when a server function is only referenced inside a createClientOnlyFn callback)
|
|
390
394
|
createServerFnPlugin({
|
|
391
395
|
framework: corePluginOpts.framework,
|
|
392
396
|
directive,
|
|
393
397
|
environments,
|
|
394
398
|
}),
|
|
395
|
-
|
|
396
399
|
TanStackServerFnPlugin({
|
|
397
400
|
// This is the ID that will be available to look up and import
|
|
398
401
|
// our server function manifest and resolve its module
|
|
@@ -428,6 +431,7 @@ export function TanStackStartVitePluginCore(
|
|
|
428
431
|
envName: serverFnProviderEnv,
|
|
429
432
|
},
|
|
430
433
|
}),
|
|
434
|
+
startCompilerPlugin({ framework: corePluginOpts.framework, environments }),
|
|
431
435
|
loadEnvPlugin(),
|
|
432
436
|
startManifestPlugin({
|
|
433
437
|
getClientBundle: () => getBundle(VITE_ENVIRONMENT_NAMES.client),
|
|
@@ -6,7 +6,6 @@ import {
|
|
|
6
6
|
findReferencedIdentifiers,
|
|
7
7
|
} from 'babel-dead-code-elimination'
|
|
8
8
|
import { generateFromAst, parseAst } from '@tanstack/router-utils'
|
|
9
|
-
import { handleCreateMiddleware } from '../create-server-fn-plugin/handleCreateMiddleware'
|
|
10
9
|
import { transformFuncs } from './constants'
|
|
11
10
|
import { handleCreateIsomorphicFnCallExpression } from './isomorphicFn'
|
|
12
11
|
import {
|
|
@@ -41,16 +40,6 @@ export function compileStartOutputFactory(
|
|
|
41
40
|
},
|
|
42
41
|
}
|
|
43
42
|
|
|
44
|
-
// createMiddleware only performs modifications in the client environment
|
|
45
|
-
// so we can avoid executing this on the server
|
|
46
|
-
if (opts.env === 'client') {
|
|
47
|
-
identifiers.createMiddleware = {
|
|
48
|
-
name: 'createMiddleware',
|
|
49
|
-
handleCallExpression: handleCreateMiddleware,
|
|
50
|
-
paths: [],
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
|
|
54
43
|
const ast = parseAst(opts)
|
|
55
44
|
|
|
56
45
|
const doDce = opts.dce ?? true
|