@tanstack/start-plugin-core 1.132.0-alpha.1 → 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 (63) 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/output-directory.js +5 -2
  11. package/dist/esm/output-directory.js.map +1 -1
  12. package/dist/esm/plugin.d.ts +1 -1
  13. package/dist/esm/plugin.js +12 -15
  14. package/dist/esm/plugin.js.map +1 -1
  15. package/dist/esm/schema.d.ts +20 -28
  16. package/dist/esm/schema.js +10 -14
  17. package/dist/esm/schema.js.map +1 -1
  18. package/dist/esm/start-compiler-plugin/compilers.d.ts +15 -0
  19. package/dist/esm/start-compiler-plugin/compilers.js +131 -0
  20. package/dist/esm/start-compiler-plugin/compilers.js.map +1 -0
  21. package/dist/esm/start-compiler-plugin/constants.d.ts +1 -0
  22. package/dist/esm/start-compiler-plugin/constants.js +13 -0
  23. package/dist/esm/start-compiler-plugin/constants.js.map +1 -0
  24. package/dist/esm/start-compiler-plugin/envOnly.d.ts +5 -0
  25. package/dist/esm/start-compiler-plugin/envOnly.js +41 -0
  26. package/dist/esm/start-compiler-plugin/envOnly.js.map +1 -0
  27. package/dist/esm/start-compiler-plugin/isomorphicFn.d.ts +4 -0
  28. package/dist/esm/start-compiler-plugin/isomorphicFn.js +49 -0
  29. package/dist/esm/start-compiler-plugin/isomorphicFn.js.map +1 -0
  30. package/dist/esm/start-compiler-plugin/middleware.d.ts +4 -0
  31. package/dist/esm/start-compiler-plugin/middleware.js +51 -0
  32. package/dist/esm/start-compiler-plugin/middleware.js.map +1 -0
  33. package/dist/esm/{start-compiler-plugin.d.ts → start-compiler-plugin/plugin.d.ts} +1 -8
  34. package/dist/esm/start-compiler-plugin/plugin.js +96 -0
  35. package/dist/esm/start-compiler-plugin/plugin.js.map +1 -0
  36. package/dist/esm/start-compiler-plugin/serverFileRoute.d.ts +4 -0
  37. package/dist/esm/start-compiler-plugin/serverFileRoute.js +38 -0
  38. package/dist/esm/start-compiler-plugin/serverFileRoute.js.map +1 -0
  39. package/dist/esm/start-compiler-plugin/utils.d.ts +13 -0
  40. package/dist/esm/start-compiler-plugin/utils.js +30 -0
  41. package/dist/esm/start-compiler-plugin/utils.js.map +1 -0
  42. package/package.json +8 -8
  43. package/src/create-server-fn-plugin/compiler.ts +456 -0
  44. package/src/create-server-fn-plugin/handleCreateServerFn.ts +153 -0
  45. package/src/create-server-fn-plugin/plugin.ts +138 -0
  46. package/src/output-directory.ts +13 -6
  47. package/src/plugin.ts +13 -22
  48. package/src/schema.ts +10 -16
  49. package/src/start-compiler-plugin/compilers.ts +195 -0
  50. package/src/start-compiler-plugin/constants.ts +9 -0
  51. package/src/start-compiler-plugin/envOnly.ts +58 -0
  52. package/src/start-compiler-plugin/isomorphicFn.ts +78 -0
  53. package/src/start-compiler-plugin/middleware.ts +79 -0
  54. package/src/start-compiler-plugin/plugin.ts +122 -0
  55. package/src/start-compiler-plugin/serverFileRoute.ts +59 -0
  56. package/src/start-compiler-plugin/utils.ts +41 -0
  57. package/dist/esm/compilers.d.ts +0 -21
  58. package/dist/esm/compilers.js +0 -395
  59. package/dist/esm/compilers.js.map +0 -1
  60. package/dist/esm/start-compiler-plugin.js +0 -78
  61. package/dist/esm/start-compiler-plugin.js.map +0 -1
  62. package/src/compilers.ts +0 -659
  63. package/src/start-compiler-plugin.ts +0 -115
@@ -1,115 +0,0 @@
1
- import { fileURLToPath, pathToFileURL } from 'node:url'
2
- import { logDiff } from '@tanstack/router-utils'
3
-
4
- import { VIRTUAL_MODULES } from '@tanstack/start-server-core'
5
- import { compileStartOutputFactory } from './compilers'
6
- import type { Plugin } from 'vite'
7
- import type { CompileStartFrameworkOptions } from './compilers'
8
-
9
- const debug =
10
- process.env.TSR_VITE_DEBUG &&
11
- ['true', 'start-plugin'].includes(process.env.TSR_VITE_DEBUG)
12
-
13
- export type TanStackStartViteOptions = {
14
- globalMiddlewareEntry: string
15
- }
16
-
17
- const transformFuncs = [
18
- 'createServerFn',
19
- 'createMiddleware',
20
- 'serverOnly',
21
- 'clientOnly',
22
- 'createIsomorphicFn',
23
- 'createServerFileRoute',
24
- 'createServerRootRoute',
25
- ]
26
-
27
- const tokenRegex = new RegExp(transformFuncs.join('|'))
28
-
29
- export function startCompilerPlugin(
30
- framework: CompileStartFrameworkOptions,
31
- inputOpts?: {
32
- client?: {
33
- envName?: string
34
- }
35
- server?: {
36
- envName?: string
37
- }
38
- },
39
- ): Plugin {
40
- const opts = {
41
- client: {
42
- envName: 'client',
43
- ...inputOpts?.client,
44
- },
45
- server: {
46
- envName: 'server',
47
- ...inputOpts?.server,
48
- },
49
- }
50
-
51
- return {
52
- name: 'vite-plugin-tanstack-start-create-server-fn',
53
- enforce: 'pre',
54
- applyToEnvironment(env) {
55
- return [opts.client.envName, opts.server.envName].includes(env.name)
56
- },
57
- transform: {
58
- filter: {
59
- code: tokenRegex,
60
- id: {
61
- exclude: VIRTUAL_MODULES.serverFnManifest,
62
- },
63
- },
64
- handler(code, id) {
65
- const env =
66
- this.environment.name === opts.client.envName
67
- ? 'client'
68
- : this.environment.name === opts.server.envName
69
- ? 'server'
70
- : (() => {
71
- throw new Error(
72
- `Environment ${this.environment.name} not configured`,
73
- )
74
- })()
75
-
76
- return transformCode({
77
- code,
78
- id,
79
- env,
80
- framework,
81
- })
82
- },
83
- },
84
- }
85
- }
86
-
87
- function transformCode(opts: {
88
- code: string
89
- id: string
90
- env: 'server' | 'client'
91
- framework: CompileStartFrameworkOptions
92
- }) {
93
- const { code, env, framework } = opts
94
- let { id } = opts
95
-
96
- const url = pathToFileURL(id)
97
- url.searchParams.delete('v')
98
- id = fileURLToPath(url).replace(/\\/g, '/')
99
-
100
- if (debug) console.info(`${env} Compiling Start: `, id)
101
-
102
- const compileStartOutput = compileStartOutputFactory(framework)
103
- const compiled = compileStartOutput({
104
- code,
105
- filename: id,
106
- env,
107
- })
108
-
109
- if (debug) {
110
- logDiff(code, compiled.code)
111
- console.log('Output:\n', compiled.code + '\n\n')
112
- }
113
-
114
- return compiled
115
- }