@tanstack/start-plugin-core 1.132.0-alpha.0 → 1.132.0-alpha.10

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.
Files changed (67) hide show
  1. package/dist/esm/create-server-fn-plugin/compiler.d.ts +61 -0
  2. package/dist/esm/create-server-fn-plugin/compiler.js +336 -0
  3. package/dist/esm/create-server-fn-plugin/compiler.js.map +1 -0
  4. package/dist/esm/create-server-fn-plugin/handleCreateServerFn.d.ts +6 -0
  5. package/dist/esm/create-server-fn-plugin/handleCreateServerFn.js +85 -0
  6. package/dist/esm/create-server-fn-plugin/handleCreateServerFn.js.map +1 -0
  7. package/dist/esm/create-server-fn-plugin/plugin.d.ts +3 -0
  8. package/dist/esm/create-server-fn-plugin/plugin.js +113 -0
  9. package/dist/esm/create-server-fn-plugin/plugin.js.map +1 -0
  10. package/dist/esm/index.d.ts +1 -0
  11. package/dist/esm/index.js +2 -0
  12. package/dist/esm/index.js.map +1 -1
  13. package/dist/esm/output-directory.js +5 -2
  14. package/dist/esm/output-directory.js.map +1 -1
  15. package/dist/esm/plugin.d.ts +1 -1
  16. package/dist/esm/plugin.js +23 -14
  17. package/dist/esm/plugin.js.map +1 -1
  18. package/dist/esm/schema.d.ts +20 -28
  19. package/dist/esm/schema.js +10 -14
  20. package/dist/esm/schema.js.map +1 -1
  21. package/dist/esm/start-compiler-plugin/compilers.d.ts +15 -0
  22. package/dist/esm/start-compiler-plugin/compilers.js +131 -0
  23. package/dist/esm/start-compiler-plugin/compilers.js.map +1 -0
  24. package/dist/esm/start-compiler-plugin/constants.d.ts +1 -0
  25. package/dist/esm/start-compiler-plugin/constants.js +13 -0
  26. package/dist/esm/start-compiler-plugin/constants.js.map +1 -0
  27. package/dist/esm/start-compiler-plugin/envOnly.d.ts +5 -0
  28. package/dist/esm/start-compiler-plugin/envOnly.js +41 -0
  29. package/dist/esm/start-compiler-plugin/envOnly.js.map +1 -0
  30. package/dist/esm/start-compiler-plugin/isomorphicFn.d.ts +4 -0
  31. package/dist/esm/start-compiler-plugin/isomorphicFn.js +49 -0
  32. package/dist/esm/start-compiler-plugin/isomorphicFn.js.map +1 -0
  33. package/dist/esm/start-compiler-plugin/middleware.d.ts +4 -0
  34. package/dist/esm/start-compiler-plugin/middleware.js +51 -0
  35. package/dist/esm/start-compiler-plugin/middleware.js.map +1 -0
  36. package/dist/esm/{start-compiler-plugin.d.ts → start-compiler-plugin/plugin.d.ts} +1 -8
  37. package/dist/esm/start-compiler-plugin/plugin.js +96 -0
  38. package/dist/esm/start-compiler-plugin/plugin.js.map +1 -0
  39. package/dist/esm/start-compiler-plugin/serverFileRoute.d.ts +4 -0
  40. package/dist/esm/start-compiler-plugin/serverFileRoute.js +38 -0
  41. package/dist/esm/start-compiler-plugin/serverFileRoute.js.map +1 -0
  42. package/dist/esm/start-compiler-plugin/utils.d.ts +13 -0
  43. package/dist/esm/start-compiler-plugin/utils.js +30 -0
  44. package/dist/esm/start-compiler-plugin/utils.js.map +1 -0
  45. package/package.json +8 -8
  46. package/src/create-server-fn-plugin/compiler.ts +456 -0
  47. package/src/create-server-fn-plugin/handleCreateServerFn.ts +153 -0
  48. package/src/create-server-fn-plugin/plugin.ts +138 -0
  49. package/src/index.ts +2 -0
  50. package/src/output-directory.ts +13 -6
  51. package/src/plugin.ts +24 -21
  52. package/src/schema.ts +10 -16
  53. package/src/start-compiler-plugin/compilers.ts +195 -0
  54. package/src/start-compiler-plugin/constants.ts +9 -0
  55. package/src/start-compiler-plugin/envOnly.ts +58 -0
  56. package/src/start-compiler-plugin/isomorphicFn.ts +78 -0
  57. package/src/start-compiler-plugin/middleware.ts +79 -0
  58. package/src/start-compiler-plugin/plugin.ts +122 -0
  59. package/src/start-compiler-plugin/serverFileRoute.ts +59 -0
  60. package/src/start-compiler-plugin/utils.ts +41 -0
  61. package/dist/esm/compilers.d.ts +0 -21
  62. package/dist/esm/compilers.js +0 -395
  63. package/dist/esm/compilers.js.map +0 -1
  64. package/dist/esm/start-compiler-plugin.js +0 -78
  65. package/dist/esm/start-compiler-plugin.js.map +0 -1
  66. package/src/compilers.ts +0 -659
  67. package/src/start-compiler-plugin.ts +0 -115
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plugin.js","sources":["../../../src/create-server-fn-plugin/plugin.ts"],"sourcesContent":["import { VITE_ENVIRONMENT_NAMES } from '../constants'\nimport { ServerFnCompiler } from './compiler'\nimport type { ViteEnvironmentNames } from '../constants'\nimport type { PluginOption } from 'vite'\nimport type { CompileStartFrameworkOptions } from '../start-compiler-plugin/compilers'\n\nfunction cleanId(id: string): string {\n return id.split('?')[0]!\n}\n\nexport function createServerFnPlugin(\n framework: CompileStartFrameworkOptions,\n): PluginOption {\n const libName = `@tanstack/${framework}-start`\n const rootExport = 'createServerFn'\n\n const SERVER_FN_LOOKUP = 'server-fn-module-lookup'\n\n const compilers: Partial<Record<ViteEnvironmentNames, ServerFnCompiler>> = {}\n return [\n {\n name: 'tanstack-start-core:capture-server-fn-module-lookup',\n // we only need this plugin in dev mode\n apply: 'serve',\n applyToEnvironment(env) {\n return [\n VITE_ENVIRONMENT_NAMES.client,\n VITE_ENVIRONMENT_NAMES.server,\n ].includes(env.name as ViteEnvironmentNames)\n },\n transform: {\n filter: {\n id: new RegExp(`${SERVER_FN_LOOKUP}$`),\n },\n handler(code, id) {\n const compiler =\n compilers[this.environment.name as ViteEnvironmentNames]\n compiler?.ingestModule({ code, id: cleanId(id) })\n },\n },\n },\n {\n name: 'tanstack-start-core::server-fn',\n enforce: 'pre',\n\n applyToEnvironment(env) {\n return [\n VITE_ENVIRONMENT_NAMES.client,\n VITE_ENVIRONMENT_NAMES.server,\n ].includes(env.name as ViteEnvironmentNames)\n },\n transform: {\n filter: {\n id: {\n exclude: new RegExp(`${SERVER_FN_LOOKUP}$`),\n },\n code: {\n // only scan files that mention `.handler(`\n include: [/\\.handler\\(/],\n },\n },\n async handler(code, id) {\n let compiler =\n compilers[this.environment.name as ViteEnvironmentNames]\n if (!compiler) {\n const env =\n this.environment.name === VITE_ENVIRONMENT_NAMES.client\n ? 'client'\n : this.environment.name === VITE_ENVIRONMENT_NAMES.server\n ? 'server'\n : (() => {\n throw new Error(\n `Environment ${this.environment.name} not configured`,\n )\n })()\n\n compiler = new ServerFnCompiler({\n env,\n libName,\n rootExport,\n loadModule: async (id: string) => {\n if (this.environment.mode === 'build') {\n const loaded = await this.load({ id })\n if (!loaded.code) {\n throw new Error(`could not load module ${id}`)\n }\n compiler!.ingestModule({ code: loaded.code, id })\n } else if (this.environment.mode === 'dev') {\n /**\n * in dev, vite does not return code from `ctx.load()`\n * so instead, we need to take a different approach\n * we must force vite to load the module and run it through the vite plugin pipeline\n * we can do this by using the `fetchModule` method\n * the `captureServerFnModuleLookupPlugin` captures the module code via its transform hook and invokes analyzeModuleAST\n */\n await this.environment.fetchModule(\n id + '?' + SERVER_FN_LOOKUP,\n )\n } else {\n throw new Error(\n `could not load module ${id}: unknown environment mode ${this.environment.mode}`,\n )\n }\n },\n resolveId: async (source: string, importer?: string) => {\n const r = await this.resolve(source, importer)\n return r ? cleanId(r.id) : null\n },\n })\n compilers[this.environment.name as ViteEnvironmentNames] = compiler\n }\n\n id = cleanId(id)\n const result = await compiler.compile({ id, code })\n return result\n },\n },\n\n hotUpdate(ctx) {\n const compiler =\n compilers[this.environment.name as ViteEnvironmentNames]\n\n ctx.modules.forEach((m) => {\n if (m.id) {\n const deleted = compiler?.invalidateModule(m.id)\n if (deleted) {\n m.importers.forEach((importer) => {\n if (importer.id) {\n compiler?.invalidateModule(importer.id)\n }\n })\n }\n }\n })\n },\n },\n ]\n}\n"],"names":["id"],"mappings":";;AAMA,SAAS,QAAQ,IAAoB;AACnC,SAAO,GAAG,MAAM,GAAG,EAAE,CAAC;AACxB;AAEO,SAAS,qBACd,WACc;AACd,QAAM,UAAU,aAAa,SAAS;AACtC,QAAM,aAAa;AAEnB,QAAM,mBAAmB;AAEzB,QAAM,YAAqE,CAAA;AAC3E,SAAO;AAAA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{ TanStackStartVitePluginCore } from './plugin.js';
3
3
  export { resolveViteId } from './utils.js';
4
+ export { VITE_ENVIRONMENT_NAMES } from './constants.js';
package/dist/esm/index.js CHANGED
@@ -1,7 +1,9 @@
1
1
  import { TanStackStartVitePluginCore } from "./plugin.js";
2
2
  import { resolveViteId } from "./utils.js";
3
+ import { VITE_ENVIRONMENT_NAMES } from "./constants.js";
3
4
  export {
4
5
  TanStackStartVitePluginCore,
6
+ VITE_ENVIRONMENT_NAMES,
5
7
  resolveViteId
6
8
  };
7
9
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;"}
1
+ {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;"}
@@ -1,11 +1,14 @@
1
1
  import { join } from "pathe";
2
2
  import { VITE_ENVIRONMENT_NAMES } from "./constants.js";
3
3
  function getClientOutputDirectory(userConfig) {
4
- return userConfig.environments?.[VITE_ENVIRONMENT_NAMES.client]?.build?.outDir ?? join(getServerOutputDirectory(userConfig), "public");
4
+ return getOutputDirectory(userConfig, VITE_ENVIRONMENT_NAMES.client, "client");
5
5
  }
6
6
  function getServerOutputDirectory(userConfig) {
7
+ return getOutputDirectory(userConfig, VITE_ENVIRONMENT_NAMES.server, "server");
8
+ }
9
+ function getOutputDirectory(userConfig, environmentName, directoryName) {
7
10
  const rootOutputDirectory = userConfig.build?.outDir ?? "dist";
8
- return userConfig.environments?.[VITE_ENVIRONMENT_NAMES.server]?.build?.outDir ?? rootOutputDirectory;
11
+ return userConfig.environments?.[environmentName]?.build?.outDir ?? join(rootOutputDirectory, directoryName);
9
12
  }
10
13
  export {
11
14
  getClientOutputDirectory,
@@ -1 +1 @@
1
- {"version":3,"file":"output-directory.js","sources":["../../src/output-directory.ts"],"sourcesContent":["import { join } from 'pathe'\nimport { VITE_ENVIRONMENT_NAMES } from './constants'\nimport type * as vite from 'vite'\n\nexport function getClientOutputDirectory(userConfig: vite.UserConfig) {\n return (\n userConfig.environments?.[VITE_ENVIRONMENT_NAMES.client]?.build?.outDir ??\n join(getServerOutputDirectory(userConfig), 'public')\n )\n}\n\nexport function getServerOutputDirectory(userConfig: vite.UserConfig) {\n const rootOutputDirectory = userConfig.build?.outDir ?? 'dist'\n return (\n userConfig.environments?.[VITE_ENVIRONMENT_NAMES.server]?.build?.outDir ??\n rootOutputDirectory\n )\n}\n"],"names":[],"mappings":";;AAIO,SAAS,yBAAyB,YAA6B;AACpE,SACE,WAAW,eAAe,uBAAuB,MAAM,GAAG,OAAO,UACjE,KAAK,yBAAyB,UAAU,GAAG,QAAQ;AAEvD;AAEO,SAAS,yBAAyB,YAA6B;AACpE,QAAM,sBAAsB,WAAW,OAAO,UAAU;AACxD,SACE,WAAW,eAAe,uBAAuB,MAAM,GAAG,OAAO,UACjE;AAEJ;"}
1
+ {"version":3,"file":"output-directory.js","sources":["../../src/output-directory.ts"],"sourcesContent":["import { join } from 'pathe'\nimport { VITE_ENVIRONMENT_NAMES } from './constants'\nimport type { ViteEnvironmentNames } from './constants'\nimport type * as vite from 'vite'\n\nexport function getClientOutputDirectory(userConfig: vite.UserConfig) {\n return getOutputDirectory(userConfig, VITE_ENVIRONMENT_NAMES.client, 'client')\n}\n\nexport function getServerOutputDirectory(userConfig: vite.UserConfig) {\n return getOutputDirectory(userConfig, VITE_ENVIRONMENT_NAMES.server, 'server')\n}\n\nfunction getOutputDirectory(\n userConfig: vite.UserConfig,\n environmentName: ViteEnvironmentNames,\n directoryName: string,\n) {\n const rootOutputDirectory = userConfig.build?.outDir ?? 'dist'\n\n return (\n userConfig.environments?.[environmentName]?.build?.outDir ??\n join(rootOutputDirectory, directoryName)\n )\n}\n"],"names":[],"mappings":";;AAKO,SAAS,yBAAyB,YAA6B;AACpE,SAAO,mBAAmB,YAAY,uBAAuB,QAAQ,QAAQ;AAC/E;AAEO,SAAS,yBAAyB,YAA6B;AACpE,SAAO,mBAAmB,YAAY,uBAAuB,QAAQ,QAAQ;AAC/E;AAEA,SAAS,mBACP,YACA,iBACA,eACA;AACA,QAAM,sBAAsB,WAAW,OAAO,UAAU;AAExD,SACE,WAAW,eAAe,eAAe,GAAG,OAAO,UACnD,KAAK,qBAAqB,aAAa;AAE3C;"}
@@ -1,6 +1,6 @@
1
1
  import { TanStackStartInputConfig } from './schema.js';
2
2
  import { PluginOption } from 'vite';
3
- import { CompileStartFrameworkOptions } from './compilers.js';
3
+ import { CompileStartFrameworkOptions } from './start-compiler-plugin/compilers.js';
4
4
  export interface TanStackStartVitePluginCoreOptions {
5
5
  framework: CompileStartFrameworkOptions;
6
6
  defaultEntryPaths: {
@@ -6,7 +6,7 @@ import * as vite from "vite";
6
6
  import { crawlFrameworkPkgs } from "vitefu";
7
7
  import { join } from "pathe";
8
8
  import { startManifestPlugin } from "./start-manifest-plugin/plugin.js";
9
- import { startCompilerPlugin } from "./start-compiler-plugin.js";
9
+ import { startCompilerPlugin } from "./start-compiler-plugin/plugin.js";
10
10
  import { ENTRY_POINTS, VITE_ENVIRONMENT_NAMES } from "./constants.js";
11
11
  import { tanStackStartRouter } from "./start-router-plugin/plugin.js";
12
12
  import { loadEnvPlugin } from "./load-env-plugin/plugin.js";
@@ -15,6 +15,7 @@ import { parseStartConfig } from "./schema.js";
15
15
  import { resolveEntry } from "./resolve-entries.js";
16
16
  import { getServerOutputDirectory, getClientOutputDirectory } from "./output-directory.js";
17
17
  import { postServerBuild } from "./post-server-build.js";
18
+ import { createServerFnPlugin } from "./create-server-fn-plugin/plugin.js";
18
19
  function TanStackStartVitePluginCore(corePluginOpts, startPluginOpts) {
19
20
  const startConfig = parseStartConfig(startPluginOpts);
20
21
  const capturedBundle = {};
@@ -27,7 +28,7 @@ function TanStackStartVitePluginCore(corePluginOpts, startPluginOpts) {
27
28
  }
28
29
  return [
29
30
  tanStackStartRouter({
30
- ...startConfig.tsr,
31
+ ...startConfig.router,
31
32
  target: corePluginOpts.framework,
32
33
  autoCodeSplitting: true
33
34
  }),
@@ -37,7 +38,7 @@ function TanStackStartVitePluginCore(corePluginOpts, startPluginOpts) {
37
38
  const viteAppBase = trimPathRight(viteConfig.base || "/");
38
39
  globalThis.TSS_APP_BASE = viteAppBase;
39
40
  const root = viteConfig.root || process.cwd();
40
- const resolvedSrcDirectory = join(root, startConfig.tsr.srcDirectory);
41
+ const resolvedSrcDirectory = join(root, startConfig.srcDirectory);
41
42
  const routerFilePath = resolveEntry({
42
43
  type: "router entry",
43
44
  configuredEntry: startConfig.router.entry,
@@ -122,7 +123,6 @@ function TanStackStartVitePluginCore(corePluginOpts, startPluginOpts) {
122
123
  [VITE_ENVIRONMENT_NAMES.client]: {
123
124
  consumer: "client",
124
125
  build: {
125
- emptyOutDir: viteConfig.environments?.[VITE_ENVIRONMENT_NAMES.client]?.build?.emptyOutDir ?? true,
126
126
  rollupOptions: {
127
127
  input: {
128
128
  main: ENTRY_POINTS.client
@@ -134,7 +134,6 @@ function TanStackStartVitePluginCore(corePluginOpts, startPluginOpts) {
134
134
  [VITE_ENVIRONMENT_NAMES.server]: {
135
135
  consumer: "server",
136
136
  build: {
137
- emptyOutDir: viteConfig.environments?.[VITE_ENVIRONMENT_NAMES.server]?.build?.emptyOutDir ?? false,
138
137
  ssr: true,
139
138
  rollupOptions: {
140
139
  input: viteConfig.environments?.[VITE_ENVIRONMENT_NAMES.server]?.build?.rollupOptions?.input ?? ENTRY_POINTS.server
@@ -144,6 +143,18 @@ function TanStackStartVitePluginCore(corePluginOpts, startPluginOpts) {
144
143
  include: [/node_modules/]
145
144
  },
146
145
  copyPublicDir: viteConfig.environments?.[VITE_ENVIRONMENT_NAMES.server]?.build?.copyPublicDir ?? false
146
+ },
147
+ optimizeDeps: {
148
+ exclude: [
149
+ ...Object.values(VIRTUAL_MODULES),
150
+ ...result.optimizeDeps.exclude.sort(),
151
+ ...additionalOptimizeDeps.exclude,
152
+ `@tanstack/${corePluginOpts.framework}-start/server`
153
+ ],
154
+ include: [
155
+ ...additionalOptimizeDeps.include,
156
+ ...result.optimizeDeps.include.sort()
157
+ ]
147
158
  }
148
159
  }
149
160
  },
@@ -175,7 +186,7 @@ function TanStackStartVitePluginCore(corePluginOpts, startPluginOpts) {
175
186
  // i.e: __FRAMEWORK_NAME__ can be replaced with JSON.stringify("TanStack Start")
176
187
  // This is not the same as injecting environment variables.
177
188
  ...defineReplaceEnv("TSS_SERVER_FN_BASE", startConfig.serverFns.base),
178
- ...defineReplaceEnv("TSS_OUTPUT_PUBLIC_DIR", getClientOutputDirectory(viteConfig)),
189
+ ...defineReplaceEnv("TSS_CLIENT_OUTPUT_DIR", getClientOutputDirectory(viteConfig)),
179
190
  ...defineReplaceEnv("TSS_APP_BASE", viteAppBase),
180
191
  ...command === "serve" ? defineReplaceEnv("TSS_SHELL", startConfig.spa?.enabled ? "true" : "false") : {},
181
192
  ...defineReplaceEnv("TSS_DEV_SERVER", command === "serve" ? "true" : "false")
@@ -204,23 +215,21 @@ function TanStackStartVitePluginCore(corePluginOpts, startPluginOpts) {
204
215
  };
205
216
  }
206
217
  },
218
+ createServerFnPlugin(corePluginOpts.framework),
207
219
  // N.B. TanStackStartCompilerPlugin must be before the TanStackServerFnPluginEnv
208
- startCompilerPlugin(corePluginOpts.framework, {
209
- client: { envName: VITE_ENVIRONMENT_NAMES.client },
210
- server: { envName: VITE_ENVIRONMENT_NAMES.server }
211
- }),
220
+ startCompilerPlugin(corePluginOpts.framework),
212
221
  TanStackServerFnPluginEnv({
213
222
  // This is the ID that will be available to look up and import
214
223
  // our server function manifest and resolve its module
215
224
  manifestVirtualImportId: VIRTUAL_MODULES.serverFnManifest,
216
225
  client: {
217
- getRuntimeCode: () => `import { createClientRpc } from '@tanstack/${corePluginOpts.framework}-start/server-functions-client'`,
218
- replacer: (d) => `createClientRpc('${d.functionId}', '${startConfig.serverFns.base}')`,
226
+ getRuntimeCode: () => `import { createClientRpc } from '@tanstack/${corePluginOpts.framework}-start/client'`,
227
+ replacer: (d) => `createClientRpc('${d.functionId}')`,
219
228
  envName: VITE_ENVIRONMENT_NAMES.client
220
229
  },
221
230
  server: {
222
- getRuntimeCode: () => `import { createServerRpc } from '@tanstack/${corePluginOpts.framework}-start/server-functions-server'`,
223
- replacer: (d) => `createServerRpc('${d.functionId}', '${startConfig.serverFns.base}', ${d.fn})`,
231
+ getRuntimeCode: () => `import { createServerRpc } from '@tanstack/${corePluginOpts.framework}-start/server'`,
232
+ replacer: (d) => `createServerRpc('${d.functionId}', ${d.fn})`,
224
233
  envName: VITE_ENVIRONMENT_NAMES.server
225
234
  }
226
235
  }),
@@ -1 +1 @@
1
- {"version":3,"file":"plugin.js","sources":["../../src/plugin.ts"],"sourcesContent":["import path from 'node:path'\nimport { trimPathRight } from '@tanstack/router-core'\nimport { VIRTUAL_MODULES } from '@tanstack/start-server-core'\nimport { TanStackServerFnPluginEnv } from '@tanstack/server-functions-plugin'\nimport * as vite from 'vite'\nimport { crawlFrameworkPkgs } from 'vitefu'\nimport { join } from 'pathe'\nimport { startManifestPlugin } from './start-manifest-plugin/plugin'\nimport { startCompilerPlugin } from './start-compiler-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 { parseStartConfig } from './schema'\nimport { resolveEntry } from './resolve-entries'\nimport {\n getClientOutputDirectory,\n getServerOutputDirectory,\n} from './output-directory'\nimport { postServerBuild } from './post-server-build'\nimport type { ViteEnvironmentNames } from './constants'\nimport type { TanStackStartInputConfig } from './schema'\nimport type { PluginOption } from 'vite'\nimport type { CompileStartFrameworkOptions } from './compilers'\n\nexport interface TanStackStartVitePluginCoreOptions {\n framework: CompileStartFrameworkOptions\n defaultEntryPaths: {\n client: string\n server: string\n }\n crawlPackages?: (opts: {\n name: string\n peerDependencies: Record<string, any>\n exports?: Record<string, any> | string\n }) => 'include' | 'exclude' | undefined\n}\n\nexport function TanStackStartVitePluginCore(\n corePluginOpts: TanStackStartVitePluginCoreOptions,\n startPluginOpts: TanStackStartInputConfig,\n): Array<PluginOption> {\n const startConfig = parseStartConfig(startPluginOpts)\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 return [\n tanStackStartRouter({\n ...startConfig.tsr,\n target: corePluginOpts.framework,\n autoCodeSplitting: true,\n }),\n {\n name: 'tanstack-start-core:config',\n async config(viteConfig, { command }) {\n const viteAppBase = trimPathRight(viteConfig.base || '/')\n globalThis.TSS_APP_BASE = viteAppBase\n\n const root = viteConfig.root || process.cwd()\n const resolvedSrcDirectory = join(root, startConfig.tsr.srcDirectory)\n\n const routerFilePath = resolveEntry({\n type: 'router entry',\n configuredEntry: startConfig.router.entry,\n defaultEntry: 'router',\n root,\n resolvedSrcDirectory,\n required: true,\n })\n const clientEntryPath = resolveEntry({\n type: 'client entry',\n configuredEntry: startConfig.client.entry,\n defaultEntry: 'client',\n root,\n resolvedSrcDirectory,\n required: false,\n })\n\n const serverEntryPath = resolveEntry({\n type: 'server entry',\n configuredEntry: startConfig.server.entry,\n defaultEntry: 'server',\n root,\n resolvedSrcDirectory,\n required: false,\n })\n\n let clientAlias: string\n if (clientEntryPath) {\n clientAlias = vite.normalizePath(\n path.join('/@fs', path.resolve(root, clientEntryPath)),\n )\n } else {\n clientAlias = corePluginOpts.defaultEntryPaths.client\n }\n let serverAlias: string\n if (serverEntryPath) {\n serverAlias = vite.normalizePath(path.resolve(root, serverEntryPath))\n } else {\n serverAlias = corePluginOpts.defaultEntryPaths.server\n }\n const entryAliasConfiguration: Record<\n (typeof ENTRY_POINTS)[keyof typeof ENTRY_POINTS],\n string\n > = {\n [ENTRY_POINTS.router]: routerFilePath,\n [ENTRY_POINTS.client]: clientAlias,\n [ENTRY_POINTS.server]: serverAlias,\n }\n\n // TODO\n /* const nitroOutputPublicDir = await (async () => {\n // Create a dummy nitro app to get the resolved public output path\n const dummyNitroApp = await createNitro({\n preset: startConfig.target,\n compatibilityDate: '2024-12-01',\n })\n\n const nitroOutputPublicDir = dummyNitroApp.options.output.publicDir\n await dummyNitroApp.close()\n\n return nitroOutputPublicDir\n })()*/\n\n const startPackageName = `@tanstack/${corePluginOpts.framework}-start`\n const routerPackageName = `@tanstack/${corePluginOpts.framework}-router`\n\n const additionalOptimizeDeps = {\n include: new Set<string>(),\n exclude: new Set<string>(),\n }\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 result = await crawlFrameworkPkgs({\n root: process.cwd(),\n isBuild: command === 'build',\n isFrameworkPkgByJson(pkgJson) {\n if ([routerPackageName, startPackageName].includes(pkgJson.name)) {\n return false\n }\n\n const peerDependencies = pkgJson['peerDependencies']\n\n if (peerDependencies) {\n const internalResult = corePluginOpts.crawlPackages?.({\n name: pkgJson.name,\n peerDependencies,\n exports: pkgJson.exports,\n })\n if (internalResult) {\n if (internalResult === 'exclude') {\n additionalOptimizeDeps.exclude.add(pkgJson.name)\n } else {\n additionalOptimizeDeps.include.add(pkgJson.name)\n }\n }\n return (\n startPackageName in peerDependencies ||\n routerPackageName in peerDependencies\n )\n }\n return false\n },\n })\n\n return {\n base: viteAppBase,\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 emptyOutDir:\n viteConfig.environments?.[VITE_ENVIRONMENT_NAMES.client]\n ?.build?.emptyOutDir ?? true,\n rollupOptions: {\n input: {\n main: ENTRY_POINTS.client,\n },\n },\n outDir: getClientOutputDirectory(viteConfig),\n },\n },\n [VITE_ENVIRONMENT_NAMES.server]: {\n consumer: 'server',\n build: {\n emptyOutDir:\n viteConfig.environments?.[VITE_ENVIRONMENT_NAMES.server]\n ?.build?.emptyOutDir ?? false,\n ssr: true,\n rollupOptions: {\n input:\n viteConfig.environments?.[VITE_ENVIRONMENT_NAMES.server]\n ?.build?.rollupOptions?.input ?? ENTRY_POINTS.server,\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 },\n },\n resolve: {\n noExternal: [\n '@tanstack/start**',\n `@tanstack/${corePluginOpts.framework}-start**`,\n ...Object.values(VIRTUAL_MODULES),\n startPackageName,\n ...result.ssr.noExternal.sort(),\n ],\n dedupe: [startPackageName],\n alias: {\n ...entryAliasConfiguration,\n },\n },\n optimizeDeps: {\n exclude: [\n ...Object.values(VIRTUAL_MODULES),\n startPackageName,\n ...result.optimizeDeps.exclude.sort(),\n ...additionalOptimizeDeps.exclude,\n ],\n include: [...additionalOptimizeDeps.include],\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', startConfig.serverFns.base),\n ...defineReplaceEnv('TSS_OUTPUT_PUBLIC_DIR', getClientOutputDirectory(viteConfig)),\n ...defineReplaceEnv('TSS_APP_BASE', viteAppBase),\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 const serverBundle = getBundle(VITE_ENVIRONMENT_NAMES.server)\n await postServerBuild({ builder, startConfig, serverBundle })\n },\n },\n }\n },\n },\n // N.B. TanStackStartCompilerPlugin must be before the TanStackServerFnPluginEnv\n startCompilerPlugin(corePluginOpts.framework, {\n client: { envName: VITE_ENVIRONMENT_NAMES.client },\n server: { envName: VITE_ENVIRONMENT_NAMES.server },\n }),\n TanStackServerFnPluginEnv({\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 client: {\n getRuntimeCode: () =>\n `import { createClientRpc } from '@tanstack/${corePluginOpts.framework}-start/server-functions-client'`,\n replacer: (d) =>\n `createClientRpc('${d.functionId}', '${startConfig.serverFns.base}')`,\n envName: VITE_ENVIRONMENT_NAMES.client,\n },\n server: {\n getRuntimeCode: () =>\n `import { createServerRpc } from '@tanstack/${corePluginOpts.framework}-start/server-functions-server'`,\n replacer: (d) =>\n `createServerRpc('${d.functionId}', '${startConfig.serverFns.base}', ${d.fn})`,\n envName: VITE_ENVIRONMENT_NAMES.server,\n },\n }),\n loadEnvPlugin(),\n startManifestPlugin({\n getClientBundle: () => getBundle(VITE_ENVIRONMENT_NAMES.client),\n }),\n devServerPlugin({ startConfig }),\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":[],"mappings":";;;;;;;;;;;;;;;;;AAsCO,SAAS,4BACd,gBACA,iBACqB;AACrB,QAAM,cAAc,iBAAiB,eAAe;AAEpD,QAAM,iBAEF,CAAA;AAEJ,WAAS,UAAU,SAAyD;AAC1E,UAAM,SAAS,eAAe,OAAO;AACrC,QAAI,CAAC,QAAQ;AACX,YAAM,IAAI,MAAM,uCAAuC,OAAO,EAAE;AAAA,IAClE;AACA,WAAO;AAAA,EACT;AAEA,SAAO;AAAA,IACL,oBAAoB;AAAA,MAClB,GAAG,YAAY;AAAA,MACf,QAAQ,eAAe;AAAA,MACvB,mBAAmB;AAAA,IAAA,CACpB;AAAA,IACD;AAAA,MACE,MAAM;AAAA,MACN,MAAM,OAAO,YAAY,EAAE,WAAW;AACpC,cAAM,cAAc,cAAc,WAAW,QAAQ,GAAG;AACxD,mBAAW,eAAe;AAE1B,cAAM,OAAO,WAAW,QAAQ,QAAQ,IAAA;AACxC,cAAM,uBAAuB,KAAK,MAAM,YAAY,IAAI,YAAY;AAEpE,cAAM,iBAAiB,aAAa;AAAA,UAClC,MAAM;AAAA,UACN,iBAAiB,YAAY,OAAO;AAAA,UACpC,cAAc;AAAA,UACd;AAAA,UACA;AAAA,UACA,UAAU;AAAA,QAAA,CACX;AACD,cAAM,kBAAkB,aAAa;AAAA,UACnC,MAAM;AAAA,UACN,iBAAiB,YAAY,OAAO;AAAA,UACpC,cAAc;AAAA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A,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 path from 'node:path'\nimport { trimPathRight } from '@tanstack/router-core'\nimport { VIRTUAL_MODULES } from '@tanstack/start-server-core'\nimport { TanStackServerFnPluginEnv } from '@tanstack/server-functions-plugin'\nimport * as vite from 'vite'\nimport { crawlFrameworkPkgs } from 'vitefu'\nimport { join } from 'pathe'\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 { 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 { TanStackStartInputConfig } 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 }\n crawlPackages?: (opts: {\n name: string\n peerDependencies: Record<string, any>\n exports?: Record<string, any> | string\n }) => 'include' | 'exclude' | undefined\n}\n\nexport function TanStackStartVitePluginCore(\n corePluginOpts: TanStackStartVitePluginCoreOptions,\n startPluginOpts: TanStackStartInputConfig,\n): Array<PluginOption> {\n const startConfig = parseStartConfig(startPluginOpts)\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 return [\n tanStackStartRouter({\n ...startConfig.router,\n target: corePluginOpts.framework,\n autoCodeSplitting: true,\n }),\n {\n name: 'tanstack-start-core:config',\n async config(viteConfig, { command }) {\n const viteAppBase = trimPathRight(viteConfig.base || '/')\n globalThis.TSS_APP_BASE = viteAppBase\n\n const root = viteConfig.root || process.cwd()\n const resolvedSrcDirectory = join(root, startConfig.srcDirectory)\n\n const routerFilePath = resolveEntry({\n type: 'router entry',\n configuredEntry: startConfig.router.entry,\n defaultEntry: 'router',\n root,\n resolvedSrcDirectory,\n required: true,\n })\n const clientEntryPath = resolveEntry({\n type: 'client entry',\n configuredEntry: startConfig.client.entry,\n defaultEntry: 'client',\n root,\n resolvedSrcDirectory,\n required: false,\n })\n\n const serverEntryPath = resolveEntry({\n type: 'server entry',\n configuredEntry: startConfig.server.entry,\n defaultEntry: 'server',\n root,\n resolvedSrcDirectory,\n required: false,\n })\n\n let clientAlias: string\n if (clientEntryPath) {\n clientAlias = vite.normalizePath(\n path.join('/@fs', path.resolve(root, clientEntryPath)),\n )\n } else {\n clientAlias = corePluginOpts.defaultEntryPaths.client\n }\n let serverAlias: string\n if (serverEntryPath) {\n serverAlias = vite.normalizePath(path.resolve(root, serverEntryPath))\n } else {\n serverAlias = corePluginOpts.defaultEntryPaths.server\n }\n const entryAliasConfiguration: Record<\n (typeof ENTRY_POINTS)[keyof typeof ENTRY_POINTS],\n string\n > = {\n [ENTRY_POINTS.router]: routerFilePath,\n [ENTRY_POINTS.client]: clientAlias,\n [ENTRY_POINTS.server]: serverAlias,\n }\n\n // TODO\n /* const nitroOutputPublicDir = await (async () => {\n // Create a dummy nitro app to get the resolved public output path\n const dummyNitroApp = await createNitro({\n preset: startConfig.target,\n compatibilityDate: '2024-12-01',\n })\n\n const nitroOutputPublicDir = dummyNitroApp.options.output.publicDir\n await dummyNitroApp.close()\n\n return nitroOutputPublicDir\n })()*/\n\n const startPackageName = `@tanstack/${corePluginOpts.framework}-start`\n const routerPackageName = `@tanstack/${corePluginOpts.framework}-router`\n\n const additionalOptimizeDeps = {\n include: new Set<string>(),\n exclude: new Set<string>(),\n }\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 result = await crawlFrameworkPkgs({\n root: process.cwd(),\n isBuild: command === 'build',\n isFrameworkPkgByJson(pkgJson) {\n if ([routerPackageName, startPackageName].includes(pkgJson.name)) {\n return false\n }\n\n const peerDependencies = pkgJson['peerDependencies']\n\n if (peerDependencies) {\n const internalResult = corePluginOpts.crawlPackages?.({\n name: pkgJson.name,\n peerDependencies,\n exports: pkgJson.exports,\n })\n if (internalResult) {\n if (internalResult === 'exclude') {\n additionalOptimizeDeps.exclude.add(pkgJson.name)\n } else {\n additionalOptimizeDeps.include.add(pkgJson.name)\n }\n }\n return (\n startPackageName in peerDependencies ||\n routerPackageName in peerDependencies\n )\n }\n return false\n },\n })\n\n return {\n base: viteAppBase,\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 },\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 ?? ENTRY_POINTS.server,\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 exclude: [\n ...Object.values(VIRTUAL_MODULES),\n ...result.optimizeDeps.exclude.sort(),\n ...additionalOptimizeDeps.exclude,\n `@tanstack/${corePluginOpts.framework}-start/server`,\n ],\n include: [\n ...additionalOptimizeDeps.include,\n ...result.optimizeDeps.include.sort(),\n ],\n },\n },\n },\n resolve: {\n noExternal: [\n '@tanstack/start**',\n `@tanstack/${corePluginOpts.framework}-start**`,\n ...Object.values(VIRTUAL_MODULES),\n startPackageName,\n ...result.ssr.noExternal.sort(),\n ],\n dedupe: [startPackageName],\n alias: {\n ...entryAliasConfiguration,\n },\n },\n optimizeDeps: {\n exclude: [\n ...Object.values(VIRTUAL_MODULES),\n startPackageName,\n ...result.optimizeDeps.exclude.sort(),\n ...additionalOptimizeDeps.exclude,\n ],\n include: [...additionalOptimizeDeps.include],\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', startConfig.serverFns.base),\n ...defineReplaceEnv('TSS_CLIENT_OUTPUT_DIR', getClientOutputDirectory(viteConfig)),\n ...defineReplaceEnv('TSS_APP_BASE', viteAppBase),\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 const serverBundle = getBundle(VITE_ENVIRONMENT_NAMES.server)\n await postServerBuild({ builder, startConfig, serverBundle })\n },\n },\n }\n },\n },\n createServerFnPlugin(corePluginOpts.framework),\n // N.B. TanStackStartCompilerPlugin must be before the TanStackServerFnPluginEnv\n startCompilerPlugin(corePluginOpts.framework),\n TanStackServerFnPluginEnv({\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 client: {\n getRuntimeCode: () =>\n `import { createClientRpc } from '@tanstack/${corePluginOpts.framework}-start/client'`,\n replacer: (d) => `createClientRpc('${d.functionId}')`,\n envName: VITE_ENVIRONMENT_NAMES.client,\n },\n server: {\n getRuntimeCode: () =>\n `import { createServerRpc } from '@tanstack/${corePluginOpts.framework}-start/server'`,\n replacer: (d) => `createServerRpc('${d.functionId}', ${d.fn})`,\n envName: VITE_ENVIRONMENT_NAMES.server,\n },\n }),\n loadEnvPlugin(),\n startManifestPlugin({\n getClientBundle: () => getBundle(VITE_ENVIRONMENT_NAMES.client),\n }),\n devServerPlugin({ startConfig }),\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":[],"mappings":";;;;;;;;;;;;;;;;;;AAuCO,SAAS,4BACd,gBACA,iBACqB;AACrB,QAAM,cAAc,iBAAiB,eAAe;AAEpD,QAAM,iBAEF,CAAA;AAEJ,WAAS,UAAU,SAAyD;AAC1E,UAAM,SAAS,eAAe,OAAO;AACrC,QAAI,CAAC,QAAQ;AACX,YAAM,IAAI,MAAM,uCAAuC,OAAO,EAAE;AAAA,IAClE;AACA,WAAO;AAAA,EACT;AAEA,SAAO;AAAA,IACL,oBAAoB;AAAA,MAClB,GAAG,YAAY;AAAA,MACf,QAAQ,eAAe;AAAA,MACvB,mBAAmB;AAAA,IAAA,CACpB;AAAA,IACD;AAAA,MACE,MAAM;AAAA,MACN,MAAM,OAAO,YAAY,EAAE,WAAW;AACpC,cAAM,cAAc,cAAc,WAAW,QAAQ,GAAG;AACxD,mBAAW,eAAe;AAE1B,cAAM,OAAO,WAAW,QAAQ,QAAQ,IAAA;AACxC,cAAM,uBAAuB,KAAK,MAAM,YAAY,YAAY;AAEhE,cAAM,iBAAiB,aAAa;AAAA,UAClC,MAAM;AAAA,UACN,iBAAiB,YAAY,OAAO;AAAA,UACpC,cAAc;AAAA,UACd;AAAA,UACA;AAAA,UACA,UAAU;AAAA,QAAA,CACX;AACD,cAAM,kBAAkB,aAAa;AAAA,UACnC,MAAM;AAAA,UACN,iBAAiB,YAAY,OAAO;AAAA,UACpC,cAAc;AAAA,UACd;AAAA,UACA;AAAA,UACA,UAAU;AAAA,QAAA,CACX;AAED,cAAM,kBAAkB,aAAa;AAAA,UACnC,MAAM;AAAA,UACN,iBAAiB,YAAY,OAAO;AAAA,UACpC,cAAc;AAAA,UACd;AAAA,UACA;AAAA,UACA,UAAU;AAAA,QAAA,CACX;AAED,YAAI;AACJ,YAAI,iBAAiB;AACn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from 'zod';
2
2
  export declare function parseStartConfig(opts?: z.input<typeof tanstackStartOptionsSchema>): {
3
- tsr: {
3
+ router: {
4
4
  target: "react" | "solid";
5
5
  routeFileIgnorePrefix: string;
6
6
  routesDirectory: string;
@@ -30,11 +30,9 @@ export declare function parseStartConfig(opts?: z.input<typeof tanstackStartOpti
30
30
  enableCodeSplitting?: boolean | undefined;
31
31
  } | undefined;
32
32
  plugins?: import('@tanstack/router-generator').GeneratorPlugin[] | undefined;
33
- srcDirectory: string;
34
- };
35
- router: {
36
33
  entry?: string | undefined;
37
34
  };
35
+ srcDirectory: string;
38
36
  client: {
39
37
  base: string;
40
38
  entry?: string | undefined;
@@ -816,7 +814,14 @@ declare const pageSchema: z.ZodObject<{
816
814
  } | undefined;
817
815
  }>;
818
816
  declare const tanstackStartOptionsSchema: z.ZodDefault<z.ZodOptional<z.ZodObject<{
819
- tsr: z.ZodDefault<z.ZodOptional<z.ZodObject<{
817
+ srcDirectory: z.ZodDefault<z.ZodOptional<z.ZodString>>;
818
+ router: z.ZodDefault<z.ZodOptional<z.ZodIntersection<z.ZodObject<{
819
+ entry: z.ZodOptional<z.ZodString>;
820
+ }, "strip", z.ZodTypeAny, {
821
+ entry?: string | undefined;
822
+ }, {
823
+ entry?: string | undefined;
824
+ }>, z.ZodDefault<z.ZodOptional<z.ZodObject<{
820
825
  target: z.ZodOptional<z.ZodDefault<z.ZodOptional<z.ZodEnum<["react", "solid"]>>>>;
821
826
  virtualRouteConfig: z.ZodOptional<z.ZodOptional<z.ZodUnion<[z.ZodType<import('@tanstack/virtual-file-routes').VirtualRootRoute, z.ZodTypeDef, import('@tanstack/virtual-file-routes').VirtualRootRoute>, z.ZodString]>>>;
822
827
  routeFilePrefix: z.ZodOptional<z.ZodOptional<z.ZodString>>;
@@ -855,10 +860,7 @@ declare const tanstackStartOptionsSchema: z.ZodDefault<z.ZodOptional<z.ZodObject
855
860
  }>>>;
856
861
  plugins: z.ZodOptional<z.ZodOptional<z.ZodArray<z.ZodType<import('@tanstack/router-generator').GeneratorPlugin, z.ZodTypeDef, import('@tanstack/router-generator').GeneratorPlugin>, "many">>>;
857
862
  tmpDir: z.ZodOptional<z.ZodDefault<z.ZodOptional<z.ZodString>>>;
858
- } & {
859
- srcDirectory: z.ZodDefault<z.ZodOptional<z.ZodString>>;
860
863
  }, "strip", z.ZodTypeAny, {
861
- srcDirectory: string;
862
864
  target?: "react" | "solid" | undefined;
863
865
  virtualRouteConfig?: string | import('@tanstack/virtual-file-routes').VirtualRootRoute | undefined;
864
866
  routeFilePrefix?: string | undefined;
@@ -916,15 +918,7 @@ declare const tanstackStartOptionsSchema: z.ZodDefault<z.ZodOptional<z.ZodObject
916
918
  } | undefined;
917
919
  plugins?: import('@tanstack/router-generator').GeneratorPlugin[] | undefined;
918
920
  tmpDir?: string | undefined;
919
- srcDirectory?: string | undefined;
920
- }>>>;
921
- router: z.ZodDefault<z.ZodOptional<z.ZodObject<{
922
- entry: z.ZodOptional<z.ZodString>;
923
- }, "strip", z.ZodTypeAny, {
924
- entry?: string | undefined;
925
- }, {
926
- entry?: string | undefined;
927
- }>>>;
921
+ }>>>>>>;
928
922
  client: z.ZodDefault<z.ZodOptional<z.ZodObject<{
929
923
  entry: z.ZodOptional<z.ZodString>;
930
924
  base: z.ZodDefault<z.ZodOptional<z.ZodString>>;
@@ -2972,8 +2966,10 @@ declare const tanstackStartOptionsSchema: z.ZodDefault<z.ZodOptional<z.ZodObject
2972
2966
  installDevServerMiddleware?: boolean | undefined;
2973
2967
  }>>;
2974
2968
  }, "strip", z.ZodTypeAny, {
2975
- tsr: {
2976
- srcDirectory: string;
2969
+ srcDirectory: string;
2970
+ router: {
2971
+ entry?: string | undefined;
2972
+ } & {
2977
2973
  target?: "react" | "solid" | undefined;
2978
2974
  virtualRouteConfig?: string | import('@tanstack/virtual-file-routes').VirtualRootRoute | undefined;
2979
2975
  routeFilePrefix?: string | undefined;
@@ -3003,9 +2999,6 @@ declare const tanstackStartOptionsSchema: z.ZodDefault<z.ZodOptional<z.ZodObject
3003
2999
  plugins?: import('@tanstack/router-generator').GeneratorPlugin[] | undefined;
3004
3000
  tmpDir?: string | undefined;
3005
3001
  };
3006
- router: {
3007
- entry?: string | undefined;
3008
- };
3009
3002
  client: {
3010
3003
  base: string;
3011
3004
  entry?: string | undefined;
@@ -3247,7 +3240,10 @@ declare const tanstackStartOptionsSchema: z.ZodDefault<z.ZodOptional<z.ZodObject
3247
3240
  installDevServerMiddleware?: boolean | undefined;
3248
3241
  } | undefined;
3249
3242
  }, {
3250
- tsr?: {
3243
+ srcDirectory?: string | undefined;
3244
+ router?: ({
3245
+ entry?: string | undefined;
3246
+ } & {
3251
3247
  target?: "react" | "solid" | undefined;
3252
3248
  virtualRouteConfig?: string | import('@tanstack/virtual-file-routes').VirtualRootRoute | undefined;
3253
3249
  routeFilePrefix?: string | undefined;
@@ -3276,11 +3272,7 @@ declare const tanstackStartOptionsSchema: z.ZodDefault<z.ZodOptional<z.ZodObject
3276
3272
  } | undefined;
3277
3273
  plugins?: import('@tanstack/router-generator').GeneratorPlugin[] | undefined;
3278
3274
  tmpDir?: string | undefined;
3279
- srcDirectory?: string | undefined;
3280
- } | undefined;
3281
- router?: {
3282
- entry?: string | undefined;
3283
- } | undefined;
3275
+ }) | undefined;
3284
3276
  client?: {
3285
3277
  entry?: string | undefined;
3286
3278
  base?: string | undefined;
@@ -1,22 +1,18 @@
1
1
  import path from "node:path";
2
2
  import { z } from "zod";
3
3
  import { getConfig, configSchema } from "@tanstack/router-generator";
4
- const tsrConfig = configSchema.omit({ autoCodeSplitting: true }).partial().extend({
5
- // this is relative to vite root
6
- // TODO why is this nested under tsr?
7
- srcDirectory: z.string().optional().default("src")
8
- });
4
+ const tsrConfig = configSchema.omit({ autoCodeSplitting: true }).partial();
9
5
  function parseStartConfig(opts) {
10
6
  const options = tanstackStartOptionsSchema.parse(opts);
11
- const srcDirectory = options.tsr.srcDirectory;
12
- const routesDirectory = options.tsr.routesDirectory ?? path.join(srcDirectory, "routes");
13
- const generatedRouteTree = options.tsr.generatedRouteTree ?? path.join(srcDirectory, "routeTree.gen.ts");
7
+ const srcDirectory = options.srcDirectory;
8
+ const routesDirectory = options.router.routesDirectory ?? path.join(srcDirectory, "routes");
9
+ const generatedRouteTree = options.router.generatedRouteTree ?? path.join(srcDirectory, "routeTree.gen.ts");
14
10
  return {
15
11
  ...options,
16
- tsr: {
17
- ...options.tsr,
12
+ router: {
13
+ ...options.router,
18
14
  ...getConfig({
19
- ...options.tsr,
15
+ ...options.router,
20
16
  routesDirectory,
21
17
  generatedRouteTree
22
18
  })
@@ -85,11 +81,11 @@ const pageSchema = pageBaseSchema.extend({
85
81
  prerender: pagePrerenderOptionsSchema.optional()
86
82
  });
87
83
  const tanstackStartOptionsSchema = z.object({
88
- tsr: tsrConfig.optional().default({}),
84
+ srcDirectory: z.string().optional().default("src"),
89
85
  router: z.object({
90
- // TODO naming?
86
+ // TODO this will move to 'start' once we have `createStart`
91
87
  entry: z.string().optional()
92
- }).optional().default({}),
88
+ }).and(tsrConfig.optional().default({})).optional().default({}),
93
89
  client: z.object({
94
90
  entry: z.string().optional(),
95
91
  base: z.string().optional().default("/_build")
@@ -1 +1 @@
1
- {"version":3,"file":"schema.js","sources":["../../src/schema.ts"],"sourcesContent":["import path from 'node:path'\nimport { z } from 'zod'\nimport { configSchema, getConfig } from '@tanstack/router-generator'\n\nconst tsrConfig = configSchema\n .omit({ autoCodeSplitting: true })\n .partial()\n .extend({\n // this is relative to vite root\n // TODO why is this nested under tsr?\n srcDirectory: z.string().optional().default('src'),\n })\n\nexport function parseStartConfig(\n opts?: z.input<typeof tanstackStartOptionsSchema>,\n) {\n const options = tanstackStartOptionsSchema.parse(opts)\n\n const srcDirectory = options.tsr.srcDirectory\n\n const routesDirectory =\n options.tsr.routesDirectory ?? path.join(srcDirectory, 'routes')\n\n const generatedRouteTree =\n options.tsr.generatedRouteTree ??\n path.join(srcDirectory, 'routeTree.gen.ts')\n\n return {\n ...options,\n tsr: {\n ...options.tsr,\n ...getConfig({\n ...options.tsr,\n routesDirectory,\n generatedRouteTree,\n }),\n },\n }\n}\n\nconst pageSitemapOptionsSchema = z.object({\n exclude: z.boolean().optional(),\n priority: z.number().min(0).max(1).optional(),\n changefreq: z\n .enum(['always', 'hourly', 'daily', 'weekly', 'monthly', 'yearly', 'never'])\n .optional(),\n lastmod: z.union([z.string(), z.date()]).optional(),\n alternateRefs: z\n .array(\n z.object({\n href: z.string(),\n hreflang: z.string(),\n }),\n )\n .optional(),\n images: z\n .array(\n z.object({\n loc: z.string(),\n caption: z.string().optional(),\n title: z.string().optional(),\n }),\n )\n .optional(),\n news: z\n .object({\n publication: z.object({\n name: z.string(),\n language: z.string(),\n }),\n publicationDate: z.union([z.string(), z.date()]),\n title: z.string(),\n })\n .optional(),\n})\n\nconst pageBaseSchema = z.object({\n path: z.string(),\n sitemap: pageSitemapOptionsSchema.optional(),\n fromCrawl: z.boolean().optional(),\n})\n\nconst pagePrerenderOptionsSchema = z.object({\n enabled: z.boolean().optional(),\n outputPath: z.string().optional(),\n autoSubfolderIndex: z.boolean().optional(),\n crawlLinks: z.boolean().optional(),\n retryCount: z.number().optional(),\n retryDelay: z.number().optional(),\n onSuccess: z\n .function()\n .args(\n z.object({\n page: pageBaseSchema,\n html: z.string(),\n }),\n )\n .returns(z.any())\n .optional(),\n headers: z.record(z.string(), z.string()).optional(),\n})\n\nconst spaSchema = z.object({\n enabled: z.boolean().optional().default(true),\n maskPath: z.string().optional().default('/'),\n prerender: pagePrerenderOptionsSchema\n .optional()\n .default({})\n .transform((opts) => ({\n outputPath: opts.outputPath ?? '/_shell',\n crawlLinks: false,\n retryCount: 0,\n ...opts,\n enabled: true,\n })),\n})\n\nconst pageSchema = pageBaseSchema.extend({\n prerender: pagePrerenderOptionsSchema.optional(),\n})\n\nconst tanstackStartOptionsSchema = z\n .object({\n tsr: tsrConfig.optional().default({}),\n router: z\n .object({\n // TODO naming?\n entry: z.string().optional(),\n })\n .optional()\n .default({}),\n client: z\n .object({\n entry: z.string().optional(),\n base: z.string().optional().default('/_build'),\n })\n .optional()\n .default({}),\n server: z\n .object({\n entry: z.string().optional(),\n })\n .optional()\n .default({}),\n serverFns: z\n .object({\n base: z.string().optional().default('/_serverFn'),\n })\n .optional()\n .default({}),\n public: z\n .object({\n dir: z.string().optional().default('public'),\n base: z.string().optional().default('/'),\n })\n .optional()\n .default({}),\n pages: z.array(pageSchema).optional().default([]),\n sitemap: z\n .object({\n enabled: z.boolean().optional().default(true),\n host: z.string().optional(),\n outputPath: z.string().optional().default('sitemap.xml'),\n })\n .optional(),\n prerender: z\n .object({\n enabled: z.boolean().optional(),\n concurrency: z.number().optional(),\n filter: z.function().args(pageSchema).returns(z.any()).optional(),\n failOnError: z.boolean().optional(),\n })\n .and(pagePrerenderOptionsSchema.optional())\n .optional(),\n spa: spaSchema.optional(),\n vite: z\n .object({ installDevServerMiddleware: z.boolean().optional() })\n .optional(),\n })\n .optional()\n .default({})\n\nexport type Page = z.infer<typeof pageSchema>\n\nexport type TanStackStartInputConfig = z.input<\n typeof tanstackStartOptionsSchema\n>\nexport type TanStackStartOutputConfig = ReturnType<typeof parseStartConfig>\n"],"names":[],"mappings":";;;AAIA,MAAM,YAAY,aACf,KAAK,EAAE,mBAAmB,MAAM,EAChC,QAAA,EACA,OAAO;AAAA;AAAA;AAAA,EAGN,cAAc,EAAE,OAAA,EAAS,SAAA,EAAW,QAAQ,KAAK;AACnD,CAAC;AAEI,SAAS,iBACd,MACA;AACA,QAAM,UAAU,2BAA2B,MAAM,IAAI;AAErD,QAAM,eAAe,QAAQ,IAAI;AAEjC,QAAM,kBACJ,QAAQ,IAAI,mBAAmB,KAAK,KAAK,cAAc,QAAQ;AAEjE,QAAM,qBACJ,QAAQ,IAAI,sBACZ,KAAK,KAAK,cAAc,kBAAkB;AAE5C,SAAO;AAAA,IACL,GAAG;AAAA,IACH,KAAK;AAAA,MACH,GAAG,QAAQ;AAAA,MACX,GAAG,UAAU;AAAA,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CAAG,EAC7D,SAAA;AACL,CAAC,EACA,SAAA,EACA,QAAQ,EAAE;"}
1
+ {"version":3,"file":"schema.js","sources":["../../src/schema.ts"],"sourcesContent":["import path from 'node:path'\nimport { z } from 'zod'\nimport { configSchema, getConfig } from '@tanstack/router-generator'\n\nconst tsrConfig = configSchema.omit({ autoCodeSplitting: true }).partial()\n\nexport function parseStartConfig(\n opts?: z.input<typeof tanstackStartOptionsSchema>,\n) {\n const options = tanstackStartOptionsSchema.parse(opts)\n\n const srcDirectory = options.srcDirectory\n\n const routesDirectory =\n options.router.routesDirectory ?? path.join(srcDirectory, 'routes')\n\n const generatedRouteTree =\n options.router.generatedRouteTree ??\n path.join(srcDirectory, 'routeTree.gen.ts')\n\n return {\n ...options,\n router: {\n ...options.router,\n ...getConfig({\n ...options.router,\n routesDirectory,\n generatedRouteTree,\n }),\n },\n }\n}\n\nconst pageSitemapOptionsSchema = z.object({\n exclude: z.boolean().optional(),\n priority: z.number().min(0).max(1).optional(),\n changefreq: z\n .enum(['always', 'hourly', 'daily', 'weekly', 'monthly', 'yearly', 'never'])\n .optional(),\n lastmod: z.union([z.string(), z.date()]).optional(),\n alternateRefs: z\n .array(\n z.object({\n href: z.string(),\n hreflang: z.string(),\n }),\n )\n .optional(),\n images: z\n .array(\n z.object({\n loc: z.string(),\n caption: z.string().optional(),\n title: z.string().optional(),\n }),\n )\n .optional(),\n news: z\n .object({\n publication: z.object({\n name: z.string(),\n language: z.string(),\n }),\n publicationDate: z.union([z.string(), z.date()]),\n title: z.string(),\n })\n .optional(),\n})\n\nconst pageBaseSchema = z.object({\n path: z.string(),\n sitemap: pageSitemapOptionsSchema.optional(),\n fromCrawl: z.boolean().optional(),\n})\n\nconst pagePrerenderOptionsSchema = z.object({\n enabled: z.boolean().optional(),\n outputPath: z.string().optional(),\n autoSubfolderIndex: z.boolean().optional(),\n crawlLinks: z.boolean().optional(),\n retryCount: z.number().optional(),\n retryDelay: z.number().optional(),\n onSuccess: z\n .function()\n .args(\n z.object({\n page: pageBaseSchema,\n html: z.string(),\n }),\n )\n .returns(z.any())\n .optional(),\n headers: z.record(z.string(), z.string()).optional(),\n})\n\nconst spaSchema = z.object({\n enabled: z.boolean().optional().default(true),\n maskPath: z.string().optional().default('/'),\n prerender: pagePrerenderOptionsSchema\n .optional()\n .default({})\n .transform((opts) => ({\n outputPath: opts.outputPath ?? '/_shell',\n crawlLinks: false,\n retryCount: 0,\n ...opts,\n enabled: true,\n })),\n})\n\nconst pageSchema = pageBaseSchema.extend({\n prerender: pagePrerenderOptionsSchema.optional(),\n})\n\nconst tanstackStartOptionsSchema = z\n .object({\n srcDirectory: z.string().optional().default('src'),\n router: z\n .object({\n // TODO this will move to 'start' once we have `createStart`\n entry: z.string().optional(),\n })\n .and(tsrConfig.optional().default({}))\n .optional()\n .default({}),\n client: z\n .object({\n entry: z.string().optional(),\n base: z.string().optional().default('/_build'),\n })\n .optional()\n .default({}),\n server: z\n .object({\n entry: z.string().optional(),\n })\n .optional()\n .default({}),\n serverFns: z\n .object({\n base: z.string().optional().default('/_serverFn'),\n })\n .optional()\n .default({}),\n public: z\n .object({\n dir: z.string().optional().default('public'),\n base: z.string().optional().default('/'),\n })\n .optional()\n .default({}),\n pages: z.array(pageSchema).optional().default([]),\n sitemap: z\n .object({\n enabled: z.boolean().optional().default(true),\n host: z.string().optional(),\n outputPath: z.string().optional().default('sitemap.xml'),\n })\n .optional(),\n prerender: z\n .object({\n enabled: z.boolean().optional(),\n concurrency: z.number().optional(),\n filter: z.function().args(pageSchema).returns(z.any()).optional(),\n failOnError: z.boolean().optional(),\n })\n .and(pagePrerenderOptionsSchema.optional())\n .optional(),\n spa: spaSchema.optional(),\n vite: z\n .object({ installDevServerMiddleware: z.boolean().optional() })\n .optional(),\n })\n .optional()\n .default({})\n\nexport type Page = z.infer<typeof pageSchema>\n\nexport type TanStackStartInputConfig = z.input<\n typeof tanstackStartOptionsSchema\n>\nexport type TanStackStartOutputConfig = ReturnType<typeof parseStartConfig>\n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,EAAE,OAAA,EAAS,SAAA,EAAW,QAAQ,aAAa;AAAA,EAAA,CACxD,EACA,SAAA;AAAA,EACH,WAAW,EACR,OAAO;AAAA,IACN,SAAS,EAAE,QAAA,EAAU,SAAA;AAAA,IACrB,aAAa,EAAE,OAAA,EAAS,SAAA;AAAA,IACxB,QAAQ,EAAE,SAAA,EAAW,KAAK,UAAU,EAAE,QAAQ,EAAE,IAAA,CAAK,EAAE,SAAA;AAAA,IACvD,aAAa,EAAE,QAAA,EAAU,SAAA;AAAA,EAAS,CACnC,EACA,IAAI,2BAA2B,SAAA,CAAU,EACzC,SAAA;AAAA,EACH,KAAK,UAAU,SAAA;AAAA,EACf,MAAM,EACH,OAAO,EAAE,4BAA4B,EAAE,UAAU,WAAS,CAAG,EAC7D,SAAA;AACL,CAAC,EACA,SAAA,EACA,QAAQ,EAAE;"}
@@ -0,0 +1,15 @@
1
+ import { GeneratorResult, ParseAstOptions } from '@tanstack/router-utils';
2
+ import * as babel from '@babel/core';
3
+ import * as t from '@babel/types';
4
+ export type CompileStartFrameworkOptions = 'react' | 'solid';
5
+ export declare function compileStartOutputFactory(framework: CompileStartFrameworkOptions): (opts: CompileOptions) => GeneratorResult;
6
+ export type CompileOptions = ParseAstOptions & {
7
+ env: 'server' | 'client';
8
+ dce?: boolean;
9
+ filename: string;
10
+ };
11
+ export type IdentifierConfig = {
12
+ name: string;
13
+ handleCallExpression: (path: babel.NodePath<t.CallExpression>, opts: CompileOptions) => void;
14
+ paths: Array<babel.NodePath>;
15
+ };
@@ -0,0 +1,131 @@
1
+ import * as babel from "@babel/core";
2
+ import * as t from "@babel/types";
3
+ import { findReferencedIdentifiers, deadCodeElimination } from "babel-dead-code-elimination";
4
+ import { parseAst, generateFromAst } from "@tanstack/router-utils";
5
+ import { transformFuncs } from "./constants.js";
6
+ import { handleCreateServerFileRouteCallExpressionFactory } from "./serverFileRoute.js";
7
+ import { handleCreateIsomorphicFnCallExpression } from "./isomorphicFn.js";
8
+ import { handleCreateMiddlewareCallExpression } from "./middleware.js";
9
+ import { handleCreateClientOnlyFnCallExpression, handleCreateServerOnlyFnCallExpression } from "./envOnly.js";
10
+ const getIdentifiers = (framework) => ({
11
+ createServerRootRoute: {
12
+ name: "createServerRootRoute",
13
+ handleCallExpression: handleCreateServerFileRouteCallExpressionFactory(
14
+ framework,
15
+ "createServerRootRoute"
16
+ ),
17
+ paths: []
18
+ },
19
+ createServerRoute: {
20
+ name: "createServerRoute",
21
+ handleCallExpression: handleCreateServerFileRouteCallExpressionFactory(
22
+ framework,
23
+ "createServerRoute"
24
+ ),
25
+ paths: []
26
+ },
27
+ createServerFileRoute: {
28
+ name: "createServerFileRoute",
29
+ handleCallExpression: handleCreateServerFileRouteCallExpressionFactory(
30
+ framework,
31
+ "createServerFileRoute"
32
+ ),
33
+ paths: []
34
+ },
35
+ createMiddleware: {
36
+ name: "createMiddleware",
37
+ handleCallExpression: handleCreateMiddlewareCallExpression,
38
+ paths: []
39
+ },
40
+ createServerOnlyFn: {
41
+ name: "createServerOnlyFn",
42
+ handleCallExpression: handleCreateServerOnlyFnCallExpression,
43
+ paths: []
44
+ },
45
+ createClientOnlyFn: {
46
+ name: "createClientOnlyFn",
47
+ handleCallExpression: handleCreateClientOnlyFnCallExpression,
48
+ paths: []
49
+ },
50
+ createIsomorphicFn: {
51
+ name: "createIsomorphicFn",
52
+ handleCallExpression: handleCreateIsomorphicFnCallExpression,
53
+ paths: []
54
+ }
55
+ });
56
+ function compileStartOutputFactory(framework) {
57
+ return function compileStartOutput(opts) {
58
+ const ast = parseAst(opts);
59
+ const doDce = opts.dce ?? true;
60
+ const refIdents = doDce ? findReferencedIdentifiers(ast) : void 0;
61
+ babel.traverse(ast, {
62
+ Program: {
63
+ enter(programPath) {
64
+ const identifiers = getIdentifiers(framework);
65
+ programPath.traverse({
66
+ ImportDeclaration: (path) => {
67
+ if (path.node.source.value !== `@tanstack/${framework}-start`) {
68
+ return;
69
+ }
70
+ path.node.specifiers.forEach((specifier) => {
71
+ transformFuncs.forEach((identifierKey) => {
72
+ const identifier = identifiers[identifierKey];
73
+ if (specifier.type === "ImportSpecifier" && specifier.imported.type === "Identifier") {
74
+ if (specifier.imported.name === identifierKey) {
75
+ identifier.name = specifier.local.name;
76
+ }
77
+ }
78
+ if (specifier.type === "ImportNamespaceSpecifier") {
79
+ identifier.name = `${specifier.local.name}.${identifierKey}`;
80
+ }
81
+ });
82
+ });
83
+ },
84
+ CallExpression: (path) => {
85
+ transformFuncs.forEach((identifierKey) => {
86
+ if (t.isIdentifier(path.node.callee) && path.node.callee.name === identifiers[identifierKey].name) {
87
+ if (path.scope.getBinding(identifiers[identifierKey].name)?.path.node.type === "FunctionDeclaration") {
88
+ return;
89
+ }
90
+ return identifiers[identifierKey].paths.push(path);
91
+ }
92
+ if (t.isMemberExpression(path.node.callee)) {
93
+ if (t.isIdentifier(path.node.callee.object) && t.isIdentifier(path.node.callee.property)) {
94
+ const callname = [
95
+ path.node.callee.object.name,
96
+ path.node.callee.property.name
97
+ ].join(".");
98
+ if (callname === identifiers[identifierKey].name) {
99
+ identifiers[identifierKey].paths.push(path);
100
+ }
101
+ }
102
+ }
103
+ return;
104
+ });
105
+ }
106
+ });
107
+ transformFuncs.forEach((identifierKey) => {
108
+ identifiers[identifierKey].paths.forEach((path) => {
109
+ identifiers[identifierKey].handleCallExpression(
110
+ path,
111
+ opts
112
+ );
113
+ });
114
+ });
115
+ }
116
+ }
117
+ });
118
+ if (doDce) {
119
+ deadCodeElimination(ast, refIdents);
120
+ }
121
+ return generateFromAst(ast, {
122
+ sourceMaps: true,
123
+ sourceFileName: opts.filename,
124
+ filename: opts.filename
125
+ });
126
+ };
127
+ }
128
+ export {
129
+ compileStartOutputFactory
130
+ };
131
+ //# sourceMappingURL=compilers.js.map