@tanstack/start-plugin-core 1.132.0-alpha.2 → 1.132.0-alpha.21
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/compiler.d.ts +61 -0
- package/dist/esm/create-server-fn-plugin/compiler.js +336 -0
- package/dist/esm/create-server-fn-plugin/compiler.js.map +1 -0
- package/dist/esm/create-server-fn-plugin/handleCreateServerFn.d.ts +6 -0
- package/dist/esm/create-server-fn-plugin/handleCreateServerFn.js +85 -0
- package/dist/esm/create-server-fn-plugin/handleCreateServerFn.js.map +1 -0
- package/dist/esm/create-server-fn-plugin/plugin.d.ts +3 -0
- package/dist/esm/create-server-fn-plugin/plugin.js +113 -0
- package/dist/esm/create-server-fn-plugin/plugin.js.map +1 -0
- package/dist/esm/output-directory.js +5 -2
- package/dist/esm/output-directory.js.map +1 -1
- package/dist/esm/plugin.d.ts +1 -6
- package/dist/esm/plugin.js +14 -61
- package/dist/esm/plugin.js.map +1 -1
- package/dist/esm/schema.d.ts +20 -28
- package/dist/esm/schema.js +10 -14
- package/dist/esm/schema.js.map +1 -1
- package/dist/esm/start-compiler-plugin/compilers.d.ts +15 -0
- package/dist/esm/start-compiler-plugin/compilers.js +131 -0
- package/dist/esm/start-compiler-plugin/compilers.js.map +1 -0
- package/dist/esm/start-compiler-plugin/constants.d.ts +1 -0
- package/dist/esm/start-compiler-plugin/constants.js +13 -0
- package/dist/esm/start-compiler-plugin/constants.js.map +1 -0
- package/dist/esm/start-compiler-plugin/envOnly.d.ts +5 -0
- package/dist/esm/start-compiler-plugin/envOnly.js +41 -0
- package/dist/esm/start-compiler-plugin/envOnly.js.map +1 -0
- package/dist/esm/start-compiler-plugin/isomorphicFn.d.ts +4 -0
- package/dist/esm/start-compiler-plugin/isomorphicFn.js +49 -0
- package/dist/esm/start-compiler-plugin/isomorphicFn.js.map +1 -0
- package/dist/esm/start-compiler-plugin/middleware.d.ts +4 -0
- package/dist/esm/start-compiler-plugin/middleware.js +51 -0
- package/dist/esm/start-compiler-plugin/middleware.js.map +1 -0
- package/dist/esm/{start-compiler-plugin.d.ts → start-compiler-plugin/plugin.d.ts} +1 -8
- package/dist/esm/start-compiler-plugin/plugin.js +96 -0
- package/dist/esm/start-compiler-plugin/plugin.js.map +1 -0
- package/dist/esm/start-compiler-plugin/serverFileRoute.d.ts +4 -0
- package/dist/esm/start-compiler-plugin/serverFileRoute.js +38 -0
- package/dist/esm/start-compiler-plugin/serverFileRoute.js.map +1 -0
- package/dist/esm/start-compiler-plugin/utils.d.ts +13 -0
- package/dist/esm/start-compiler-plugin/utils.js +30 -0
- package/dist/esm/start-compiler-plugin/utils.js.map +1 -0
- package/package.json +8 -8
- package/src/create-server-fn-plugin/compiler.ts +456 -0
- package/src/create-server-fn-plugin/handleCreateServerFn.ts +153 -0
- package/src/create-server-fn-plugin/plugin.ts +138 -0
- package/src/output-directory.ts +13 -6
- package/src/plugin.ts +18 -79
- package/src/schema.ts +10 -16
- package/src/start-compiler-plugin/compilers.ts +195 -0
- package/src/start-compiler-plugin/constants.ts +9 -0
- package/src/start-compiler-plugin/envOnly.ts +58 -0
- package/src/start-compiler-plugin/isomorphicFn.ts +78 -0
- package/src/start-compiler-plugin/middleware.ts +79 -0
- package/src/start-compiler-plugin/plugin.ts +122 -0
- package/src/start-compiler-plugin/serverFileRoute.ts +59 -0
- package/src/start-compiler-plugin/utils.ts +41 -0
- package/dist/esm/compilers.d.ts +0 -21
- package/dist/esm/compilers.js +0 -395
- package/dist/esm/compilers.js.map +0 -1
- package/dist/esm/start-compiler-plugin.js +0 -78
- package/dist/esm/start-compiler-plugin.js.map +0 -1
- package/src/compilers.ts +0 -659
- 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
|
-
}
|