@tanstack/start-plugin-core 1.142.11 → 1.142.13
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 +25 -4
- package/dist/esm/create-server-fn-plugin/compiler.js +242 -79
- package/dist/esm/create-server-fn-plugin/compiler.js.map +1 -1
- package/dist/esm/create-server-fn-plugin/plugin.js +24 -24
- package/dist/esm/create-server-fn-plugin/plugin.js.map +1 -1
- package/package.json +7 -7
- package/src/create-server-fn-plugin/compiler.ts +397 -111
- package/src/create-server-fn-plugin/plugin.ts +37 -32
|
@@ -1,28 +1,35 @@
|
|
|
1
1
|
import { TRANSFORM_ID_REGEX } from '../constants'
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
KindDetectionPatterns,
|
|
4
|
+
LookupKindsPerEnv,
|
|
5
|
+
ServerFnCompiler,
|
|
6
|
+
detectKindsInCode,
|
|
7
|
+
} from './compiler'
|
|
3
8
|
import type { CompileStartFrameworkOptions } from '../types'
|
|
4
9
|
import type { LookupConfig, LookupKind } from './compiler'
|
|
5
10
|
import type { PluginOption } from 'vite'
|
|
6
11
|
|
|
7
12
|
function cleanId(id: string): string {
|
|
13
|
+
// Remove null byte prefix used by Vite/Rollup for virtual modules
|
|
14
|
+
if (id.startsWith('\0')) {
|
|
15
|
+
id = id.slice(1)
|
|
16
|
+
}
|
|
8
17
|
const queryIndex = id.indexOf('?')
|
|
9
18
|
return queryIndex === -1 ? id : id.substring(0, queryIndex)
|
|
10
19
|
}
|
|
11
20
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
'ClientOnlyFn',
|
|
25
|
-
] as const),
|
|
21
|
+
// Derive transform code filter from KindDetectionPatterns (single source of truth)
|
|
22
|
+
function getTransformCodeFilterForEnv(env: 'client' | 'server'): Array<RegExp> {
|
|
23
|
+
const validKinds = LookupKindsPerEnv[env]
|
|
24
|
+
const patterns: Array<RegExp> = []
|
|
25
|
+
for (const [kind, pattern] of Object.entries(KindDetectionPatterns) as Array<
|
|
26
|
+
[LookupKind, RegExp]
|
|
27
|
+
>) {
|
|
28
|
+
if (validKinds.has(kind)) {
|
|
29
|
+
patterns.push(pattern)
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
return patterns
|
|
26
33
|
}
|
|
27
34
|
|
|
28
35
|
const getLookupConfigurationsForEnv = (
|
|
@@ -77,12 +84,6 @@ function buildDirectiveSplitParam(directive: string) {
|
|
|
77
84
|
return `tsr-directive-${directive.replace(/[^a-zA-Z0-9]/g, '-')}`
|
|
78
85
|
}
|
|
79
86
|
|
|
80
|
-
const commonTransformCodeFilter = [
|
|
81
|
-
/\.\s*handler\(/,
|
|
82
|
-
/createIsomorphicFn/,
|
|
83
|
-
/createServerOnlyFn/,
|
|
84
|
-
/createClientOnlyFn/,
|
|
85
|
-
]
|
|
86
87
|
export function createServerFnPlugin(opts: {
|
|
87
88
|
framework: CompileStartFrameworkOptions
|
|
88
89
|
directive: string
|
|
@@ -95,16 +96,8 @@ export function createServerFnPlugin(opts: {
|
|
|
95
96
|
name: string
|
|
96
97
|
type: 'client' | 'server'
|
|
97
98
|
}): PluginOption {
|
|
98
|
-
//
|
|
99
|
-
|
|
100
|
-
// - `createMiddleware(` for middleware (client only)
|
|
101
|
-
// - `createIsomorphicFn` for isomorphic functions
|
|
102
|
-
// - `createServerOnlyFn` for server-only functions
|
|
103
|
-
// - `createClientOnlyFn` for client-only functions
|
|
104
|
-
const transformCodeFilter =
|
|
105
|
-
environment.type === 'client'
|
|
106
|
-
? [...commonTransformCodeFilter, /createMiddleware\s*\(/]
|
|
107
|
-
: commonTransformCodeFilter
|
|
99
|
+
// Derive transform code filter from KindDetectionPatterns (single source of truth)
|
|
100
|
+
const transformCodeFilter = getTransformCodeFilterForEnv(environment.type)
|
|
108
101
|
|
|
109
102
|
return {
|
|
110
103
|
name: `tanstack-start-core::server-fn:${environment.name}`,
|
|
@@ -125,6 +118,9 @@ export function createServerFnPlugin(opts: {
|
|
|
125
118
|
async handler(code, id) {
|
|
126
119
|
let compiler = compilers[this.environment.name]
|
|
127
120
|
if (!compiler) {
|
|
121
|
+
// Default to 'dev' mode for unknown environments (conservative: no caching)
|
|
122
|
+
const mode =
|
|
123
|
+
this.environment.mode === 'build' ? 'build' : ('dev' as const)
|
|
128
124
|
compiler = new ServerFnCompiler({
|
|
129
125
|
env: environment.type,
|
|
130
126
|
directive: opts.directive,
|
|
@@ -133,6 +129,7 @@ export function createServerFnPlugin(opts: {
|
|
|
133
129
|
environment.type,
|
|
134
130
|
opts.framework,
|
|
135
131
|
),
|
|
132
|
+
mode,
|
|
136
133
|
loadModule: async (id: string) => {
|
|
137
134
|
if (this.environment.mode === 'build') {
|
|
138
135
|
const loaded = await this.load({ id })
|
|
@@ -172,8 +169,16 @@ export function createServerFnPlugin(opts: {
|
|
|
172
169
|
|
|
173
170
|
const isProviderFile = id.includes(directiveSplitParam)
|
|
174
171
|
|
|
172
|
+
// Detect which kinds are present in this file before parsing
|
|
173
|
+
const detectedKinds = detectKindsInCode(code, environment.type)
|
|
174
|
+
|
|
175
175
|
id = cleanId(id)
|
|
176
|
-
const result = await compiler.compile({
|
|
176
|
+
const result = await compiler.compile({
|
|
177
|
+
id,
|
|
178
|
+
code,
|
|
179
|
+
isProviderFile,
|
|
180
|
+
detectedKinds,
|
|
181
|
+
})
|
|
177
182
|
return result
|
|
178
183
|
},
|
|
179
184
|
},
|