@tanstack/start-plugin-core 1.167.18 → 1.167.20
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/config-context.d.ts +26 -0
- package/dist/esm/config-context.js +81 -0
- package/dist/esm/config-context.js.map +1 -0
- package/dist/esm/constants.d.ts +6 -1
- package/dist/esm/constants.js +3 -2
- package/dist/esm/constants.js.map +1 -1
- package/dist/esm/import-protection-plugin/extensionlessAbsoluteIdResolver.js +1 -1
- package/dist/esm/import-protection-plugin/plugin.js +1 -1
- package/dist/esm/import-protection-plugin/virtualModules.js +1 -1
- package/dist/esm/index.d.ts +5 -3
- package/dist/esm/index.js +3 -4
- package/dist/esm/planning.d.ts +40 -0
- package/dist/esm/planning.js +107 -0
- package/dist/esm/planning.js.map +1 -0
- package/dist/esm/schema.d.ts +3093 -44
- package/dist/esm/schema.js +5 -5
- package/dist/esm/schema.js.map +1 -1
- package/dist/esm/serialization-adapters-module.d.ts +17 -0
- package/dist/esm/serialization-adapters-module.js +39 -0
- package/dist/esm/serialization-adapters-module.js.map +1 -0
- package/dist/esm/{start-compiler-plugin → start-compiler}/compiler.d.ts +2 -3
- package/dist/esm/{start-compiler-plugin → start-compiler}/compiler.js +17 -16
- package/dist/esm/start-compiler/compiler.js.map +1 -0
- package/dist/esm/start-compiler/config.d.ts +4 -0
- package/dist/esm/start-compiler/config.js +54 -0
- package/dist/esm/start-compiler/config.js.map +1 -0
- package/dist/esm/{start-compiler-plugin → start-compiler}/handleClientOnlyJSX.js +1 -1
- package/dist/esm/start-compiler/handleClientOnlyJSX.js.map +1 -0
- package/dist/esm/{start-compiler-plugin → start-compiler}/handleCreateIsomorphicFn.js +1 -1
- package/dist/esm/start-compiler/handleCreateIsomorphicFn.js.map +1 -0
- package/dist/esm/{start-compiler-plugin → start-compiler}/handleCreateMiddleware.js +1 -1
- package/dist/esm/start-compiler/handleCreateMiddleware.js.map +1 -0
- package/dist/esm/{start-compiler-plugin → start-compiler}/handleCreateServerFn.js +6 -17
- package/dist/esm/start-compiler/handleCreateServerFn.js.map +1 -0
- package/dist/esm/{start-compiler-plugin → start-compiler}/handleEnvOnly.js +1 -1
- package/dist/esm/start-compiler/handleEnvOnly.js.map +1 -0
- package/dist/esm/start-compiler/host.d.ts +20 -0
- package/dist/esm/start-compiler/host.js +38 -0
- package/dist/esm/start-compiler/host.js.map +1 -0
- package/dist/esm/start-compiler/load-module.d.ts +14 -0
- package/dist/esm/start-compiler/load-module.js +18 -0
- package/dist/esm/start-compiler/load-module.js.map +1 -0
- package/dist/esm/start-compiler/server-fn-resolver-module.d.ts +8 -0
- package/dist/esm/start-compiler/server-fn-resolver-module.js +77 -0
- package/dist/esm/start-compiler/server-fn-resolver-module.js.map +1 -0
- package/dist/esm/{start-compiler-plugin → start-compiler}/types.d.ts +4 -0
- package/dist/esm/{start-compiler-plugin → start-compiler}/utils.js +1 -1
- package/dist/esm/start-compiler/utils.js.map +1 -0
- package/dist/esm/start-manifest-plugin/manifestBuilder.d.ts +16 -16
- package/dist/esm/start-manifest-plugin/manifestBuilder.js +14 -45
- package/dist/esm/start-manifest-plugin/manifestBuilder.js.map +1 -1
- package/dist/esm/start-router-plugin/route-tree-footer.d.ts +6 -0
- package/dist/esm/start-router-plugin/route-tree-footer.js +44 -0
- package/dist/esm/start-router-plugin/route-tree-footer.js.map +1 -0
- package/dist/esm/types.d.ts +44 -10
- package/dist/esm/{dev-server-plugin → vite/dev-server-plugin}/dev-styles.js +1 -1
- package/dist/esm/vite/dev-server-plugin/dev-styles.js.map +1 -0
- package/dist/esm/{dev-server-plugin → vite/dev-server-plugin}/extract-html-scripts.js +1 -1
- package/dist/esm/vite/dev-server-plugin/extract-html-scripts.js.map +1 -0
- package/dist/esm/vite/dev-server-plugin/plugin.d.ts +7 -0
- package/dist/esm/{dev-server-plugin → vite/dev-server-plugin}/plugin.js +5 -6
- package/dist/esm/vite/dev-server-plugin/plugin.js.map +1 -0
- package/dist/esm/{load-env-plugin → vite/load-env-plugin}/plugin.js +1 -1
- package/dist/esm/vite/load-env-plugin/plugin.js.map +1 -0
- package/dist/esm/{output-directory.js → vite/output-directory.js} +2 -2
- package/dist/esm/vite/output-directory.js.map +1 -0
- package/dist/esm/vite/planning.d.ts +105 -0
- package/dist/esm/vite/planning.js +116 -0
- package/dist/esm/vite/planning.js.map +1 -0
- package/dist/esm/vite/plugin.d.ts +4 -0
- package/dist/esm/vite/plugin.js +169 -0
- package/dist/esm/vite/plugin.js.map +1 -0
- package/dist/esm/vite/plugins.d.ts +17 -0
- package/dist/esm/vite/plugins.js +50 -0
- package/dist/esm/vite/plugins.js.map +1 -0
- package/dist/esm/{post-server-build.d.ts → vite/post-server-build.d.ts} +1 -1
- package/dist/esm/{post-server-build.js → vite/post-server-build.js} +4 -4
- package/dist/esm/vite/post-server-build.js.map +1 -0
- package/dist/esm/{prerender.d.ts → vite/prerender.d.ts} +1 -1
- package/dist/esm/{prerender.js → vite/prerender.js} +5 -10
- package/dist/esm/vite/prerender.js.map +1 -0
- package/dist/esm/{preview-server-plugin → vite/preview-server-plugin}/plugin.js +4 -4
- package/dist/esm/vite/preview-server-plugin/plugin.js.map +1 -0
- package/dist/esm/vite/schema.d.ts +3373 -0
- package/dist/esm/vite/schema.js +12 -0
- package/dist/esm/vite/schema.js.map +1 -0
- package/dist/esm/vite/serialization-adapters-plugin.d.ts +5 -0
- package/dist/esm/vite/serialization-adapters-plugin.js +42 -0
- package/dist/esm/vite/serialization-adapters-plugin.js.map +1 -0
- package/dist/esm/vite/start-compiler-plugin/module-specifier.d.ts +3 -0
- package/dist/esm/vite/start-compiler-plugin/module-specifier.js +19 -0
- package/dist/esm/vite/start-compiler-plugin/module-specifier.js.map +1 -0
- package/dist/esm/{start-compiler-plugin → vite/start-compiler-plugin}/plugin.d.ts +4 -3
- package/dist/esm/vite/start-compiler-plugin/plugin.js +202 -0
- package/dist/esm/vite/start-compiler-plugin/plugin.js.map +1 -0
- package/dist/esm/vite/start-manifest-plugin/normalized-client-build.d.ts +6 -0
- package/dist/esm/vite/start-manifest-plugin/normalized-client-build.js +81 -0
- package/dist/esm/vite/start-manifest-plugin/normalized-client-build.js.map +1 -0
- package/dist/esm/vite/start-manifest-plugin/plugin.d.ts +6 -0
- package/dist/esm/{start-manifest-plugin → vite/start-manifest-plugin}/plugin.js +14 -9
- package/dist/esm/vite/start-manifest-plugin/plugin.js.map +1 -0
- package/dist/esm/{start-router-plugin → vite/start-router-plugin}/plugin.d.ts +3 -2
- package/dist/esm/{start-router-plugin → vite/start-router-plugin}/plugin.js +14 -37
- package/dist/esm/vite/start-router-plugin/plugin.js.map +1 -0
- package/dist/esm/vite/types.d.ts +15 -0
- package/package.json +36 -25
- package/src/config-context.ts +138 -0
- package/src/constants.ts +7 -3
- package/src/index.ts +5 -5
- package/src/planning.ts +151 -0
- package/src/schema.ts +93 -93
- package/src/serialization-adapters-module.ts +82 -0
- package/src/{start-compiler-plugin → start-compiler}/compiler.ts +67 -61
- package/src/start-compiler/config.ts +73 -0
- package/src/{start-compiler-plugin → start-compiler}/handleCreateServerFn.ts +14 -41
- package/src/start-compiler/host.ts +80 -0
- package/src/start-compiler/load-module.ts +31 -0
- package/src/start-compiler/server-fn-resolver-module.ts +129 -0
- package/src/{start-compiler-plugin → start-compiler}/types.ts +5 -0
- package/src/start-manifest-plugin/manifestBuilder.ts +65 -107
- package/src/start-router-plugin/route-tree-footer.ts +99 -0
- package/src/types.ts +53 -10
- package/src/{dev-server-plugin → vite/dev-server-plugin}/plugin.ts +7 -6
- package/src/{output-directory.ts → vite/output-directory.ts} +2 -2
- package/src/vite/planning.ts +234 -0
- package/src/vite/plugin.ts +276 -0
- package/src/vite/plugins.ts +81 -0
- package/src/{post-server-build.ts → vite/post-server-build.ts} +4 -6
- package/src/{prerender.ts → vite/prerender.ts} +21 -46
- package/src/{preview-server-plugin → vite/preview-server-plugin}/plugin.ts +2 -2
- package/src/vite/schema.ts +30 -0
- package/src/vite/serialization-adapters-plugin.ts +69 -0
- package/src/vite/start-compiler-plugin/module-specifier.ts +31 -0
- package/src/vite/start-compiler-plugin/plugin.ts +345 -0
- package/src/vite/start-manifest-plugin/normalized-client-build.ts +131 -0
- package/src/{start-manifest-plugin → vite/start-manifest-plugin}/plugin.ts +21 -13
- package/src/{start-router-plugin → vite/start-router-plugin}/plugin.ts +14 -80
- package/src/vite/types.ts +18 -0
- package/LICENSE +0 -21
- package/dist/esm/dev-server-plugin/dev-styles.js.map +0 -1
- package/dist/esm/dev-server-plugin/extract-html-scripts.js.map +0 -1
- package/dist/esm/dev-server-plugin/plugin.d.ts +0 -6
- package/dist/esm/dev-server-plugin/plugin.js.map +0 -1
- package/dist/esm/load-env-plugin/plugin.js.map +0 -1
- package/dist/esm/output-directory.js.map +0 -1
- package/dist/esm/plugin.d.ts +0 -4
- package/dist/esm/plugin.js +0 -301
- package/dist/esm/plugin.js.map +0 -1
- package/dist/esm/post-server-build.js.map +0 -1
- package/dist/esm/prerender.js.map +0 -1
- package/dist/esm/preview-server-plugin/plugin.js.map +0 -1
- package/dist/esm/start-compiler-plugin/compiler.js.map +0 -1
- package/dist/esm/start-compiler-plugin/handleClientOnlyJSX.js.map +0 -1
- package/dist/esm/start-compiler-plugin/handleCreateIsomorphicFn.js.map +0 -1
- package/dist/esm/start-compiler-plugin/handleCreateMiddleware.js.map +0 -1
- package/dist/esm/start-compiler-plugin/handleCreateServerFn.js.map +0 -1
- package/dist/esm/start-compiler-plugin/handleEnvOnly.js.map +0 -1
- package/dist/esm/start-compiler-plugin/plugin.js +0 -297
- package/dist/esm/start-compiler-plugin/plugin.js.map +0 -1
- package/dist/esm/start-compiler-plugin/utils.js.map +0 -1
- package/dist/esm/start-manifest-plugin/plugin.d.ts +0 -6
- package/dist/esm/start-manifest-plugin/plugin.js.map +0 -1
- package/dist/esm/start-router-plugin/plugin.js.map +0 -1
- package/src/plugin.ts +0 -471
- package/src/start-compiler-plugin/plugin.ts +0 -478
- /package/dist/esm/{start-compiler-plugin → start-compiler}/handleClientOnlyJSX.d.ts +0 -0
- /package/dist/esm/{start-compiler-plugin → start-compiler}/handleCreateIsomorphicFn.d.ts +0 -0
- /package/dist/esm/{start-compiler-plugin → start-compiler}/handleCreateMiddleware.d.ts +0 -0
- /package/dist/esm/{start-compiler-plugin → start-compiler}/handleCreateServerFn.d.ts +0 -0
- /package/dist/esm/{start-compiler-plugin → start-compiler}/handleEnvOnly.d.ts +0 -0
- /package/dist/esm/{start-compiler-plugin → start-compiler}/utils.d.ts +0 -0
- /package/dist/esm/{dev-server-plugin → vite/dev-server-plugin}/dev-styles.d.ts +0 -0
- /package/dist/esm/{dev-server-plugin → vite/dev-server-plugin}/extract-html-scripts.d.ts +0 -0
- /package/dist/esm/{load-env-plugin → vite/load-env-plugin}/plugin.d.ts +0 -0
- /package/dist/esm/{output-directory.d.ts → vite/output-directory.d.ts} +0 -0
- /package/dist/esm/{preview-server-plugin → vite/preview-server-plugin}/plugin.d.ts +0 -0
- /package/src/{start-compiler-plugin → start-compiler}/handleClientOnlyJSX.ts +0 -0
- /package/src/{start-compiler-plugin → start-compiler}/handleCreateIsomorphicFn.ts +0 -0
- /package/src/{start-compiler-plugin → start-compiler}/handleCreateMiddleware.ts +0 -0
- /package/src/{start-compiler-plugin → start-compiler}/handleEnvOnly.ts +0 -0
- /package/src/{start-compiler-plugin → start-compiler}/utils.ts +0 -0
- /package/src/{dev-server-plugin → vite/dev-server-plugin}/dev-styles.ts +0 -0
- /package/src/{dev-server-plugin → vite/dev-server-plugin}/extract-html-scripts.ts +0 -0
- /package/src/{load-env-plugin → vite/load-env-plugin}/plugin.ts +0 -0
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import type { SerializationAdapterConfig } from './types'
|
|
2
|
+
|
|
3
|
+
export const EMPTY_SERIALIZATION_ADAPTERS_MODULE = `export const pluginSerializationAdapters = []
|
|
4
|
+
export const hasPluginAdapters = false`
|
|
5
|
+
|
|
6
|
+
interface ResolvedAdapterModule {
|
|
7
|
+
module: string
|
|
8
|
+
export: string
|
|
9
|
+
isFactory: boolean
|
|
10
|
+
index: number
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function resolveSerializationAdaptersForRuntime(opts: {
|
|
14
|
+
adapters: Array<SerializationAdapterConfig> | undefined
|
|
15
|
+
runtime: 'client' | 'server'
|
|
16
|
+
}): Array<ResolvedAdapterModule> {
|
|
17
|
+
if (!opts.adapters?.length) {
|
|
18
|
+
return []
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const resolvedAdapters: Array<ResolvedAdapterModule> = []
|
|
22
|
+
|
|
23
|
+
for (let i = 0; i < opts.adapters.length; i++) {
|
|
24
|
+
const adapter = opts.adapters[i]!
|
|
25
|
+
|
|
26
|
+
if ('module' in adapter) {
|
|
27
|
+
resolvedAdapters.push({
|
|
28
|
+
module: adapter.module,
|
|
29
|
+
export: adapter.export,
|
|
30
|
+
isFactory: adapter.isFactory ?? true,
|
|
31
|
+
index: i,
|
|
32
|
+
})
|
|
33
|
+
continue
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const runtimeAdapter =
|
|
37
|
+
opts.runtime === 'client' ? adapter.client : adapter.server
|
|
38
|
+
|
|
39
|
+
if (!runtimeAdapter) {
|
|
40
|
+
continue
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
resolvedAdapters.push({
|
|
44
|
+
module: runtimeAdapter.module,
|
|
45
|
+
export: runtimeAdapter.export,
|
|
46
|
+
isFactory: runtimeAdapter.isFactory ?? true,
|
|
47
|
+
index: i,
|
|
48
|
+
})
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
return resolvedAdapters
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export function generateSerializationAdaptersModule(opts: {
|
|
55
|
+
adapters: Array<SerializationAdapterConfig> | undefined
|
|
56
|
+
runtime: 'client' | 'server'
|
|
57
|
+
}): string {
|
|
58
|
+
const resolvedAdapters = resolveSerializationAdaptersForRuntime(opts)
|
|
59
|
+
|
|
60
|
+
if (resolvedAdapters.length === 0) {
|
|
61
|
+
return EMPTY_SERIALIZATION_ADAPTERS_MODULE
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const imports = resolvedAdapters
|
|
65
|
+
.map(
|
|
66
|
+
(adapter) =>
|
|
67
|
+
`import { ${adapter.export} as adapter${adapter.index} } from '${adapter.module}'`,
|
|
68
|
+
)
|
|
69
|
+
.join('\n')
|
|
70
|
+
|
|
71
|
+
const items = resolvedAdapters
|
|
72
|
+
.map((adapter) =>
|
|
73
|
+
adapter.isFactory
|
|
74
|
+
? `...(Array.isArray(adapter${adapter.index}()) ? adapter${adapter.index}() : [adapter${adapter.index}()])`
|
|
75
|
+
: `adapter${adapter.index}`,
|
|
76
|
+
)
|
|
77
|
+
.join(', ')
|
|
78
|
+
|
|
79
|
+
return `${imports}
|
|
80
|
+
export const pluginSerializationAdapters = [${items}]
|
|
81
|
+
export const hasPluginAdapters = true`
|
|
82
|
+
}
|
|
@@ -15,6 +15,7 @@ import { handleEnvOnlyFn } from './handleEnvOnly'
|
|
|
15
15
|
import { handleClientOnlyJSX } from './handleClientOnlyJSX'
|
|
16
16
|
import type {
|
|
17
17
|
CompilationContext,
|
|
18
|
+
DevServerFnModuleSpecifierEncoder,
|
|
18
19
|
MethodChainPaths,
|
|
19
20
|
RewriteCandidate,
|
|
20
21
|
ServerFn,
|
|
@@ -311,9 +312,6 @@ export class StartCompiler {
|
|
|
311
312
|
private entryIdToFunctionId = new Map<string, string>()
|
|
312
313
|
private functionIds = new Set<string>()
|
|
313
314
|
|
|
314
|
-
// Cached root path with trailing slash for dev mode function ID generation
|
|
315
|
-
private _rootWithTrailingSlash: string | undefined
|
|
316
|
-
|
|
317
315
|
constructor(
|
|
318
316
|
private options: {
|
|
319
317
|
env: 'client' | 'server'
|
|
@@ -353,6 +351,7 @@ export class StartCompiler {
|
|
|
353
351
|
* Used by server callers to look up canonical extracted filenames.
|
|
354
352
|
*/
|
|
355
353
|
getKnownServerFns?: () => Record<string, ServerFn>
|
|
354
|
+
devServerFnModuleSpecifierEncoder?: DevServerFnModuleSpecifierEncoder
|
|
356
355
|
},
|
|
357
356
|
) {
|
|
358
357
|
this.validLookupKinds = options.lookupKinds
|
|
@@ -369,12 +368,20 @@ export class StartCompiler {
|
|
|
369
368
|
extractedFilename: string
|
|
370
369
|
}): string {
|
|
371
370
|
if (this.mode === 'dev') {
|
|
372
|
-
// In dev, encode the file path and export name for direct lookup
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
371
|
+
// In dev, encode the file path and export name for direct lookup.
|
|
372
|
+
// Each bundler adapter supplies its own strategy for encoding
|
|
373
|
+
// module specifiers that work with its dev server runtime.
|
|
374
|
+
const encodeModuleSpecifier =
|
|
375
|
+
this.options.devServerFnModuleSpecifierEncoder
|
|
376
|
+
if (!encodeModuleSpecifier) {
|
|
377
|
+
throw new Error(
|
|
378
|
+
'devServerFnModuleSpecifierEncoder is required in dev mode.',
|
|
379
|
+
)
|
|
376
380
|
}
|
|
377
|
-
file =
|
|
381
|
+
const file = encodeModuleSpecifier({
|
|
382
|
+
extractedFilename: opts.extractedFilename,
|
|
383
|
+
root: this.options.root,
|
|
384
|
+
})
|
|
378
385
|
|
|
379
386
|
const serverFn = {
|
|
380
387
|
file,
|
|
@@ -415,15 +422,6 @@ export class StartCompiler {
|
|
|
415
422
|
return this.options.mode ?? 'dev'
|
|
416
423
|
}
|
|
417
424
|
|
|
418
|
-
private get rootWithTrailingSlash(): string {
|
|
419
|
-
if (this._rootWithTrailingSlash === undefined) {
|
|
420
|
-
this._rootWithTrailingSlash = this.options.root.endsWith('/')
|
|
421
|
-
? this.options.root
|
|
422
|
-
: `${this.options.root}/`
|
|
423
|
-
}
|
|
424
|
-
return this._rootWithTrailingSlash
|
|
425
|
-
}
|
|
426
|
-
|
|
427
425
|
private async resolveIdCached(id: string, importer?: string) {
|
|
428
426
|
if (this.mode === 'dev') {
|
|
429
427
|
return this.options.resolveId(id, importer)
|
|
@@ -460,54 +458,62 @@ export class StartCompiler {
|
|
|
460
458
|
]),
|
|
461
459
|
)
|
|
462
460
|
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
// For JSX lookups (e.g., ClientOnlyJSX), we only need the knownRootImports
|
|
475
|
-
// fast path to verify imports. Skip module resolution which may fail if
|
|
476
|
-
// the package isn't a direct dependency (e.g., @tanstack/react-router from
|
|
477
|
-
// within start-plugin-core).
|
|
478
|
-
if (config.kind !== 'Root') {
|
|
479
|
-
const setup = LookupSetup[config.kind]
|
|
480
|
-
if (setup.type === 'jsx') {
|
|
481
|
-
return
|
|
482
|
-
}
|
|
483
|
-
}
|
|
461
|
+
// Register start-client-core exports for internal package usage (e.g., react-start-rsc).
|
|
462
|
+
// These don't need module resolution - only the knownRootImports fast path.
|
|
463
|
+
this.knownRootImports.set(
|
|
464
|
+
'@tanstack/start-client-core',
|
|
465
|
+
new Map<string, Kind>([
|
|
466
|
+
['createIsomorphicFn', 'IsomorphicFn'],
|
|
467
|
+
['createServerOnlyFn', 'ServerOnlyFn'],
|
|
468
|
+
['createClientOnlyFn', 'ClientOnlyFn'],
|
|
469
|
+
]),
|
|
470
|
+
)
|
|
484
471
|
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
472
|
+
for (const config of this.options.lookupConfigurations) {
|
|
473
|
+
// Populate the fast lookup map for direct imports (by package name)
|
|
474
|
+
// This allows O(1) recognition of imports from known packages.
|
|
475
|
+
let libExports = this.knownRootImports.get(config.libName)
|
|
476
|
+
if (!libExports) {
|
|
477
|
+
libExports = new Map()
|
|
478
|
+
this.knownRootImports.set(config.libName, libExports)
|
|
479
|
+
}
|
|
480
|
+
libExports.set(config.rootExport, config.kind)
|
|
481
|
+
|
|
482
|
+
// For JSX lookups (e.g., ClientOnlyJSX), we only need the knownRootImports
|
|
483
|
+
// fast path to verify imports. Skip synthetic root module setup.
|
|
484
|
+
if (config.kind !== 'Root') {
|
|
485
|
+
const setup = LookupSetup[config.kind]
|
|
486
|
+
if (setup.type === 'jsx') {
|
|
487
|
+
continue
|
|
499
488
|
}
|
|
489
|
+
}
|
|
500
490
|
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
491
|
+
// Root lookup metadata is synthetic package-level state, not a real
|
|
492
|
+
// resolved module. Keep the ID stable across bundlers and export-map
|
|
493
|
+
// behavior by always keying it to the package specifier itself.
|
|
494
|
+
const libId = config.libName
|
|
495
|
+
|
|
496
|
+
let rootModule = this.moduleCache.get(libId)
|
|
497
|
+
if (!rootModule) {
|
|
498
|
+
// insert root binding
|
|
499
|
+
rootModule = {
|
|
500
|
+
bindings: new Map(),
|
|
501
|
+
exports: new Map(),
|
|
502
|
+
id: libId,
|
|
503
|
+
reExportAllSources: [],
|
|
504
|
+
}
|
|
508
505
|
this.moduleCache.set(libId, rootModule)
|
|
509
|
-
}
|
|
510
|
-
|
|
506
|
+
}
|
|
507
|
+
|
|
508
|
+
rootModule.exports.set(config.rootExport, config.rootExport)
|
|
509
|
+
rootModule.exports.set('*', config.rootExport)
|
|
510
|
+
rootModule.bindings.set(config.rootExport, {
|
|
511
|
+
type: 'var',
|
|
512
|
+
init: null, // Not needed since resolvedKind is set
|
|
513
|
+
resolvedKind: config.kind satisfies Kind,
|
|
514
|
+
})
|
|
515
|
+
this.moduleCache.set(libId, rootModule)
|
|
516
|
+
}
|
|
511
517
|
|
|
512
518
|
this.initialized = true
|
|
513
519
|
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { KindDetectionPatterns, LookupKindsPerEnv } from './compiler'
|
|
2
|
+
import type { LookupConfig, LookupKind } from './compiler'
|
|
3
|
+
import type { CompileStartFrameworkOptions } from '../types'
|
|
4
|
+
|
|
5
|
+
export function getTransformCodeFilterForEnv(
|
|
6
|
+
env: 'client' | 'server',
|
|
7
|
+
): Array<RegExp> {
|
|
8
|
+
const validKinds = LookupKindsPerEnv[env]
|
|
9
|
+
const patterns: Array<RegExp> = []
|
|
10
|
+
|
|
11
|
+
for (const [kind, pattern] of Object.entries(KindDetectionPatterns) as Array<
|
|
12
|
+
[LookupKind, RegExp]
|
|
13
|
+
>) {
|
|
14
|
+
if (validKinds.has(kind)) {
|
|
15
|
+
patterns.push(pattern)
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
return patterns
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export function getLookupConfigurationsForEnv(
|
|
23
|
+
env: 'client' | 'server',
|
|
24
|
+
framework: CompileStartFrameworkOptions,
|
|
25
|
+
): Array<LookupConfig> {
|
|
26
|
+
const commonConfigs: Array<LookupConfig> = [
|
|
27
|
+
{
|
|
28
|
+
libName: `@tanstack/${framework}-start`,
|
|
29
|
+
rootExport: 'createServerFn',
|
|
30
|
+
kind: 'Root',
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
libName: `@tanstack/${framework}-start`,
|
|
34
|
+
rootExport: 'createIsomorphicFn',
|
|
35
|
+
kind: 'IsomorphicFn',
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
libName: `@tanstack/${framework}-start`,
|
|
39
|
+
rootExport: 'createServerOnlyFn',
|
|
40
|
+
kind: 'ServerOnlyFn',
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
libName: `@tanstack/${framework}-start`,
|
|
44
|
+
rootExport: 'createClientOnlyFn',
|
|
45
|
+
kind: 'ClientOnlyFn',
|
|
46
|
+
},
|
|
47
|
+
]
|
|
48
|
+
|
|
49
|
+
if (env === 'client') {
|
|
50
|
+
return [
|
|
51
|
+
{
|
|
52
|
+
libName: `@tanstack/${framework}-start`,
|
|
53
|
+
rootExport: 'createMiddleware',
|
|
54
|
+
kind: 'Root',
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
libName: `@tanstack/${framework}-start`,
|
|
58
|
+
rootExport: 'createStart',
|
|
59
|
+
kind: 'Root',
|
|
60
|
+
},
|
|
61
|
+
...commonConfigs,
|
|
62
|
+
]
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
return [
|
|
66
|
+
...commonConfigs,
|
|
67
|
+
{
|
|
68
|
+
libName: `@tanstack/${framework}-router`,
|
|
69
|
+
rootExport: 'ClientOnly',
|
|
70
|
+
kind: 'ClientOnlyJSX',
|
|
71
|
+
},
|
|
72
|
+
]
|
|
73
|
+
}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import * as t from '@babel/types'
|
|
2
2
|
import babel from '@babel/core'
|
|
3
3
|
import path from 'pathe'
|
|
4
|
-
import { VITE_ENVIRONMENT_NAMES } from '../constants'
|
|
5
4
|
import { cleanId, codeFrameError, stripMethodCall } from './utils'
|
|
6
5
|
import type { CompilationContext, RewriteCandidate, ServerFn } from './types'
|
|
7
6
|
import type { CompileStartFrameworkOptions } from '../types'
|
|
@@ -22,16 +21,11 @@ const clientRpcTemplate = babel.template.expression(
|
|
|
22
21
|
`createClientRpc(%%functionId%%)`,
|
|
23
22
|
)
|
|
24
23
|
|
|
25
|
-
// Template for SSR caller files
|
|
24
|
+
// Template for SSR caller files: createSsrRpc(functionId)
|
|
26
25
|
const ssrRpcManifestTemplate = babel.template.expression(
|
|
27
26
|
`createSsrRpc(%%functionId%%)`,
|
|
28
27
|
)
|
|
29
28
|
|
|
30
|
-
// Template for SSR caller files (with importer): createSsrRpc(functionId, () => import(...).then(m => m['name']))
|
|
31
|
-
const ssrRpcImporterTemplate = babel.template.expression(
|
|
32
|
-
`createSsrRpc(%%functionId%%, () => import(%%extractedFilename%%).then(m => m[%%functionName%%]))`,
|
|
33
|
-
)
|
|
34
|
-
|
|
35
29
|
// ============================================================================
|
|
36
30
|
// Runtime code cache (cached per framework to avoid repeated AST generation)
|
|
37
31
|
// ============================================================================
|
|
@@ -75,8 +69,6 @@ function getCachedRuntimeCode(
|
|
|
75
69
|
interface EnvConfig {
|
|
76
70
|
/** Whether this environment is a client environment */
|
|
77
71
|
isClientEnvironment: boolean
|
|
78
|
-
/** Whether SSR is the provider environment */
|
|
79
|
-
ssrIsProvider: boolean
|
|
80
72
|
/** The runtime code type to use for imports */
|
|
81
73
|
runtimeCodeType: RuntimeCodeType
|
|
82
74
|
}
|
|
@@ -88,15 +80,11 @@ function getEnvConfig(
|
|
|
88
80
|
context: CompilationContext,
|
|
89
81
|
isProviderFile: boolean,
|
|
90
82
|
): EnvConfig {
|
|
91
|
-
const {
|
|
92
|
-
|
|
93
|
-
// SSR is the provider when the provider environment is the default server environment
|
|
94
|
-
const ssrIsProvider = providerEnvName === VITE_ENVIRONMENT_NAMES.server
|
|
83
|
+
const { env } = context
|
|
95
84
|
|
|
96
85
|
if (isProviderFile) {
|
|
97
86
|
return {
|
|
98
87
|
isClientEnvironment: false,
|
|
99
|
-
ssrIsProvider,
|
|
100
88
|
runtimeCodeType: 'provider',
|
|
101
89
|
}
|
|
102
90
|
}
|
|
@@ -104,7 +92,6 @@ function getEnvConfig(
|
|
|
104
92
|
if (env === 'client') {
|
|
105
93
|
return {
|
|
106
94
|
isClientEnvironment: true,
|
|
107
|
-
ssrIsProvider,
|
|
108
95
|
runtimeCodeType: 'client',
|
|
109
96
|
}
|
|
110
97
|
}
|
|
@@ -112,7 +99,6 @@ function getEnvConfig(
|
|
|
112
99
|
// Server caller (SSR)
|
|
113
100
|
return {
|
|
114
101
|
isClientEnvironment: false,
|
|
115
|
-
ssrIsProvider,
|
|
116
102
|
runtimeCodeType: 'ssr',
|
|
117
103
|
}
|
|
118
104
|
}
|
|
@@ -154,9 +140,6 @@ function generateProviderRpcStub(
|
|
|
154
140
|
*/
|
|
155
141
|
function generateCallerRpcStub(
|
|
156
142
|
functionId: string,
|
|
157
|
-
functionName: string,
|
|
158
|
-
extractedFilename: string,
|
|
159
|
-
isClientReferenced: boolean,
|
|
160
143
|
envConfig: EnvConfig,
|
|
161
144
|
): t.Expression {
|
|
162
145
|
const functionIdLiteral = t.stringLiteral(functionId)
|
|
@@ -167,20 +150,8 @@ function generateCallerRpcStub(
|
|
|
167
150
|
})
|
|
168
151
|
}
|
|
169
152
|
|
|
170
|
-
|
|
171
|
-
// When the function is client-referenced, it's in the manifest - use manifest lookup
|
|
172
|
-
// When SSR is NOT the provider, always use manifest lookup (no import() for different env)
|
|
173
|
-
// Otherwise, use the importer for functions only referenced on the server when SSR is the provider
|
|
174
|
-
if (isClientReferenced || !envConfig.ssrIsProvider) {
|
|
175
|
-
return ssrRpcManifestTemplate({
|
|
176
|
-
functionId: functionIdLiteral,
|
|
177
|
-
})
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
return ssrRpcImporterTemplate({
|
|
153
|
+
return ssrRpcManifestTemplate({
|
|
181
154
|
functionId: functionIdLiteral,
|
|
182
|
-
extractedFilename: t.stringLiteral(extractedFilename),
|
|
183
|
-
functionName: t.stringLiteral(functionName),
|
|
184
155
|
})
|
|
185
156
|
}
|
|
186
157
|
|
|
@@ -262,7 +233,15 @@ export function handleCreateServerFn(
|
|
|
262
233
|
|
|
263
234
|
// Check if this function was already discovered by the client build
|
|
264
235
|
const knownFn = knownFns[functionId]
|
|
265
|
-
|
|
236
|
+
// A server function is client-referenced when:
|
|
237
|
+
// 1. We're in the client (browser) environment, OR
|
|
238
|
+
// 2. It was already discovered by another environment (knownFn), OR
|
|
239
|
+
// 3. We're in an SSR caller environment — any server function reachable from
|
|
240
|
+
// SSR module graph is callable via client navigation HTTP requests
|
|
241
|
+
const isClientReferenced =
|
|
242
|
+
envConfig.isClientEnvironment ||
|
|
243
|
+
!!knownFn ||
|
|
244
|
+
envConfig.runtimeCodeType === 'ssr'
|
|
266
245
|
|
|
267
246
|
// Use canonical extracted filename from known functions if available
|
|
268
247
|
const canonicalExtractedFilename =
|
|
@@ -395,7 +374,7 @@ export function handleCreateServerFn(
|
|
|
395
374
|
// Expected output format:
|
|
396
375
|
// const myFn = createServerFn().handler(createClientRpc("id"))
|
|
397
376
|
// or
|
|
398
|
-
// const myFn = createServerFn().handler(createSsrRpc("id"
|
|
377
|
+
// const myFn = createServerFn().handler(createSsrRpc("id"))
|
|
399
378
|
|
|
400
379
|
// If the handler function is an identifier, we need to remove the bound function
|
|
401
380
|
// from the file since it won't be needed
|
|
@@ -408,13 +387,7 @@ export function handleCreateServerFn(
|
|
|
408
387
|
|
|
409
388
|
// Generate the RPC stub using pre-compiled templates
|
|
410
389
|
// Note: Caller files only pass functionId, not the full serverFnMeta
|
|
411
|
-
const rpcStub = generateCallerRpcStub(
|
|
412
|
-
functionId,
|
|
413
|
-
functionName,
|
|
414
|
-
canonicalExtractedFilename,
|
|
415
|
-
isClientReferenced,
|
|
416
|
-
envConfig,
|
|
417
|
-
)
|
|
390
|
+
const rpcStub = generateCallerRpcStub(functionId, envConfig)
|
|
418
391
|
|
|
419
392
|
// Replace ONLY the handler argument with the RPC stub
|
|
420
393
|
// Keep the createServerFn().handler() wrapper intact for client middleware
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { LookupKindsPerEnv, StartCompiler } from './compiler'
|
|
2
|
+
import { getLookupConfigurationsForEnv } from './config'
|
|
3
|
+
import type { CompileStartFrameworkOptions } from '../types'
|
|
4
|
+
import type {
|
|
5
|
+
DevServerFnModuleSpecifierEncoder,
|
|
6
|
+
GenerateFunctionIdFnOptional,
|
|
7
|
+
ServerFn,
|
|
8
|
+
} from './types'
|
|
9
|
+
|
|
10
|
+
export interface CreateStartCompilerOptions {
|
|
11
|
+
env: 'client' | 'server'
|
|
12
|
+
envName: string
|
|
13
|
+
root: string
|
|
14
|
+
framework: CompileStartFrameworkOptions
|
|
15
|
+
providerEnvName: string
|
|
16
|
+
mode: 'dev' | 'build'
|
|
17
|
+
generateFunctionId?: GenerateFunctionIdFnOptional
|
|
18
|
+
onServerFnsById?: (d: Record<string, ServerFn>) => void
|
|
19
|
+
getKnownServerFns?: () => Record<string, ServerFn>
|
|
20
|
+
encodeModuleSpecifierInDev?: DevServerFnModuleSpecifierEncoder
|
|
21
|
+
loadModule: (id: string) => Promise<void>
|
|
22
|
+
resolveId: (id: string, importer?: string) => Promise<string | null>
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function createStartCompiler(
|
|
26
|
+
options: CreateStartCompilerOptions,
|
|
27
|
+
): StartCompiler {
|
|
28
|
+
return new StartCompiler({
|
|
29
|
+
env: options.env,
|
|
30
|
+
envName: options.envName,
|
|
31
|
+
root: options.root,
|
|
32
|
+
lookupKinds: LookupKindsPerEnv[options.env],
|
|
33
|
+
lookupConfigurations: getLookupConfigurationsForEnv(
|
|
34
|
+
options.env,
|
|
35
|
+
options.framework,
|
|
36
|
+
),
|
|
37
|
+
mode: options.mode,
|
|
38
|
+
framework: options.framework,
|
|
39
|
+
providerEnvName: options.providerEnvName,
|
|
40
|
+
generateFunctionId: options.generateFunctionId,
|
|
41
|
+
onServerFnsById: options.onServerFnsById,
|
|
42
|
+
getKnownServerFns: options.getKnownServerFns,
|
|
43
|
+
devServerFnModuleSpecifierEncoder: options.encodeModuleSpecifierInDev,
|
|
44
|
+
loadModule: options.loadModule,
|
|
45
|
+
resolveId: options.resolveId,
|
|
46
|
+
})
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export function mergeServerFnsById(
|
|
50
|
+
current: Record<string, ServerFn>,
|
|
51
|
+
next: Record<string, ServerFn>,
|
|
52
|
+
): void {
|
|
53
|
+
for (const [id, fn] of Object.entries(next)) {
|
|
54
|
+
const existing = current[id]
|
|
55
|
+
|
|
56
|
+
if (existing) {
|
|
57
|
+
current[id] = {
|
|
58
|
+
...fn,
|
|
59
|
+
isClientReferenced:
|
|
60
|
+
existing.isClientReferenced || fn.isClientReferenced,
|
|
61
|
+
}
|
|
62
|
+
continue
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
current[id] = fn
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export function matchesCodeFilters(
|
|
70
|
+
code: string,
|
|
71
|
+
filters: ReadonlyArray<RegExp>,
|
|
72
|
+
): boolean {
|
|
73
|
+
for (const pattern of filters) {
|
|
74
|
+
if (pattern.test(code)) {
|
|
75
|
+
return true
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
return false
|
|
80
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { SERVER_FN_LOOKUP } from '../constants'
|
|
2
|
+
import type { StartCompiler } from './compiler'
|
|
3
|
+
|
|
4
|
+
interface ViteCompilerModuleLoaderOptions {
|
|
5
|
+
compiler: StartCompiler
|
|
6
|
+
mode: string
|
|
7
|
+
fetchModule?: (id: string) => Promise<unknown>
|
|
8
|
+
loadModule: (opts: { id: string }) => Promise<{ code?: string | null }>
|
|
9
|
+
id: string
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export async function loadModuleForViteCompiler(
|
|
13
|
+
opts: ViteCompilerModuleLoaderOptions,
|
|
14
|
+
): Promise<void> {
|
|
15
|
+
if (opts.mode === 'build') {
|
|
16
|
+
const loaded = await opts.loadModule({ id: opts.id })
|
|
17
|
+
const code = loaded.code ?? ''
|
|
18
|
+
|
|
19
|
+
opts.compiler.ingestModule({ code, id: opts.id })
|
|
20
|
+
|
|
21
|
+
return
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
if (opts.mode !== 'dev' || !opts.fetchModule) {
|
|
25
|
+
throw new Error(
|
|
26
|
+
`could not load module ${opts.id}: unknown environment mode ${opts.mode}`,
|
|
27
|
+
)
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
await opts.fetchModule(`${opts.id}?${SERVER_FN_LOOKUP}`)
|
|
31
|
+
}
|