@tanstack/start-plugin-core 1.132.0-alpha.9 → 1.132.0
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/constants.d.ts +2 -1
- package/dist/esm/constants.js +3 -2
- package/dist/esm/constants.js.map +1 -1
- package/dist/esm/create-server-fn-plugin/compiler.d.ts +8 -5
- package/dist/esm/create-server-fn-plugin/compiler.js +74 -46
- package/dist/esm/create-server-fn-plugin/compiler.js.map +1 -1
- package/dist/esm/create-server-fn-plugin/handleCreateMiddleware.d.ts +5 -0
- package/dist/esm/{start-compiler-plugin/middleware.js → create-server-fn-plugin/handleCreateMiddleware.js} +11 -11
- package/dist/esm/create-server-fn-plugin/handleCreateMiddleware.js.map +1 -0
- package/dist/esm/create-server-fn-plugin/handleCreateServerFn.js +8 -8
- package/dist/esm/create-server-fn-plugin/handleCreateServerFn.js.map +1 -1
- package/dist/esm/create-server-fn-plugin/plugin.d.ts +1 -1
- package/dist/esm/create-server-fn-plugin/plugin.js +22 -7
- package/dist/esm/create-server-fn-plugin/plugin.js.map +1 -1
- package/dist/esm/dev-server-plugin/plugin.d.ts +4 -2
- package/dist/esm/dev-server-plugin/plugin.js +6 -2
- package/dist/esm/dev-server-plugin/plugin.js.map +1 -1
- package/dist/esm/plugin.d.ts +12 -6
- package/dist/esm/plugin.js +54 -65
- package/dist/esm/plugin.js.map +1 -1
- package/dist/esm/resolve-entries.d.ts +0 -1
- package/dist/esm/resolve-entries.js +1 -1
- package/dist/esm/resolve-entries.js.map +1 -1
- package/dist/esm/schema.d.ts +375 -308
- package/dist/esm/schema.js +23 -11
- package/dist/esm/schema.js.map +1 -1
- package/dist/esm/start-compiler-plugin/compilers.js +17 -49
- package/dist/esm/start-compiler-plugin/compilers.js.map +1 -1
- package/dist/esm/start-compiler-plugin/constants.d.ts +1 -1
- package/dist/esm/start-compiler-plugin/constants.js +1 -5
- package/dist/esm/start-compiler-plugin/constants.js.map +1 -1
- package/dist/esm/start-router-plugin/constants.d.ts +1 -0
- package/dist/esm/start-router-plugin/constants.js +5 -0
- package/dist/esm/start-router-plugin/constants.js.map +1 -0
- package/dist/esm/start-router-plugin/generator-plugins/routes-manifest-plugin.js +3 -9
- package/dist/esm/start-router-plugin/generator-plugins/routes-manifest-plugin.js.map +1 -1
- package/dist/esm/start-router-plugin/plugin.d.ts +3 -2
- package/dist/esm/start-router-plugin/plugin.js +191 -31
- package/dist/esm/start-router-plugin/plugin.js.map +1 -1
- package/dist/esm/start-router-plugin/pruneServerOnlySubtrees.d.ts +8 -0
- package/dist/esm/start-router-plugin/pruneServerOnlySubtrees.js +34 -0
- package/dist/esm/start-router-plugin/pruneServerOnlySubtrees.js.map +1 -0
- package/package.json +8 -8
- package/src/constants.ts +3 -2
- package/src/create-server-fn-plugin/compiler.ts +99 -57
- package/src/{start-compiler-plugin/middleware.ts → create-server-fn-plugin/handleCreateMiddleware.ts} +15 -12
- package/src/create-server-fn-plugin/handleCreateServerFn.ts +11 -8
- package/src/create-server-fn-plugin/plugin.ts +24 -9
- package/src/dev-server-plugin/plugin.ts +6 -3
- package/src/plugin.ts +76 -84
- package/src/resolve-entries.ts +1 -2
- package/src/schema.ts +31 -14
- package/src/start-compiler-plugin/compilers.ts +18 -51
- package/src/start-compiler-plugin/constants.ts +0 -4
- package/src/start-router-plugin/constants.ts +1 -0
- package/src/start-router-plugin/generator-plugins/routes-manifest-plugin.ts +3 -9
- package/src/start-router-plugin/plugin.ts +233 -45
- package/src/start-router-plugin/pruneServerOnlySubtrees.ts +51 -0
- package/dist/esm/debug.js +0 -5
- package/dist/esm/debug.js.map +0 -1
- package/dist/esm/start-compiler-plugin/middleware.d.ts +0 -4
- package/dist/esm/start-compiler-plugin/middleware.js.map +0 -1
- package/dist/esm/start-compiler-plugin/serverFileRoute.d.ts +0 -4
- package/dist/esm/start-compiler-plugin/serverFileRoute.js +0 -38
- package/dist/esm/start-compiler-plugin/serverFileRoute.js.map +0 -1
- package/dist/esm/start-router-plugin/generator-plugins/server-routes-plugin.d.ts +0 -2
- package/dist/esm/start-router-plugin/generator-plugins/server-routes-plugin.js +0 -119
- package/dist/esm/start-router-plugin/generator-plugins/server-routes-plugin.js.map +0 -1
- package/dist/esm/start-router-plugin/route-tree-client-plugin.d.ts +0 -6
- package/dist/esm/start-router-plugin/route-tree-client-plugin.js +0 -56
- package/dist/esm/start-router-plugin/route-tree-client-plugin.js.map +0 -1
- package/dist/esm/start-router-plugin/virtual-route-tree-plugin.d.ts +0 -3
- package/dist/esm/start-router-plugin/virtual-route-tree-plugin.js +0 -29
- package/dist/esm/start-router-plugin/virtual-route-tree-plugin.js.map +0 -1
- package/src/start-compiler-plugin/serverFileRoute.ts +0 -59
- package/src/start-router-plugin/generator-plugins/server-routes-plugin.ts +0 -138
- package/src/start-router-plugin/route-tree-client-plugin.ts +0 -77
- package/src/start-router-plugin/virtual-route-tree-plugin.ts +0 -29
package/src/plugin.ts
CHANGED
|
@@ -20,7 +20,10 @@ import {
|
|
|
20
20
|
import { postServerBuild } from './post-server-build'
|
|
21
21
|
import { createServerFnPlugin } from './create-server-fn-plugin/plugin'
|
|
22
22
|
import type { ViteEnvironmentNames } from './constants'
|
|
23
|
-
import type {
|
|
23
|
+
import type {
|
|
24
|
+
TanStackStartInputConfig,
|
|
25
|
+
TanStackStartOutputConfig,
|
|
26
|
+
} from './schema'
|
|
24
27
|
import type { PluginOption } from 'vite'
|
|
25
28
|
import type { CompileStartFrameworkOptions } from './start-compiler-plugin/compilers'
|
|
26
29
|
|
|
@@ -29,19 +32,46 @@ export interface TanStackStartVitePluginCoreOptions {
|
|
|
29
32
|
defaultEntryPaths: {
|
|
30
33
|
client: string
|
|
31
34
|
server: string
|
|
35
|
+
start: string
|
|
32
36
|
}
|
|
33
|
-
crawlPackages?: (opts: {
|
|
34
|
-
name: string
|
|
35
|
-
peerDependencies: Record<string, any>
|
|
36
|
-
exports?: Record<string, any> | string
|
|
37
|
-
}) => 'include' | 'exclude' | undefined
|
|
38
37
|
}
|
|
39
38
|
|
|
39
|
+
export interface ResolvedStartConfig {
|
|
40
|
+
root: string
|
|
41
|
+
startFilePath: string | undefined
|
|
42
|
+
routerFilePath: string
|
|
43
|
+
srcDirectory: string
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export type GetConfigFn = () => {
|
|
47
|
+
startConfig: TanStackStartOutputConfig
|
|
48
|
+
resolvedStartConfig: ResolvedStartConfig
|
|
49
|
+
}
|
|
40
50
|
export function TanStackStartVitePluginCore(
|
|
41
51
|
corePluginOpts: TanStackStartVitePluginCoreOptions,
|
|
42
52
|
startPluginOpts: TanStackStartInputConfig,
|
|
43
53
|
): Array<PluginOption> {
|
|
44
|
-
const
|
|
54
|
+
const resolvedStartConfig: ResolvedStartConfig = {
|
|
55
|
+
root: '',
|
|
56
|
+
startFilePath: undefined,
|
|
57
|
+
routerFilePath: '',
|
|
58
|
+
srcDirectory: '',
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
let startConfig: TanStackStartOutputConfig | null
|
|
62
|
+
const getConfig: GetConfigFn = () => {
|
|
63
|
+
if (!resolvedStartConfig.root) {
|
|
64
|
+
throw new Error(`Cannot get config before root is resolved`)
|
|
65
|
+
}
|
|
66
|
+
if (!startConfig) {
|
|
67
|
+
startConfig = parseStartConfig(
|
|
68
|
+
startPluginOpts,
|
|
69
|
+
corePluginOpts,
|
|
70
|
+
resolvedStartConfig.root,
|
|
71
|
+
)
|
|
72
|
+
}
|
|
73
|
+
return { startConfig, resolvedStartConfig }
|
|
74
|
+
}
|
|
45
75
|
|
|
46
76
|
const capturedBundle: Partial<
|
|
47
77
|
Record<ViteEnvironmentNames, vite.Rollup.OutputBundle>
|
|
@@ -56,33 +86,42 @@ export function TanStackStartVitePluginCore(
|
|
|
56
86
|
}
|
|
57
87
|
|
|
58
88
|
return [
|
|
59
|
-
tanStackStartRouter({
|
|
60
|
-
...startConfig.router,
|
|
61
|
-
target: corePluginOpts.framework,
|
|
62
|
-
autoCodeSplitting: true,
|
|
63
|
-
}),
|
|
64
89
|
{
|
|
65
90
|
name: 'tanstack-start-core:config',
|
|
91
|
+
enforce: 'pre',
|
|
66
92
|
async config(viteConfig, { command }) {
|
|
67
93
|
const viteAppBase = trimPathRight(viteConfig.base || '/')
|
|
68
94
|
globalThis.TSS_APP_BASE = viteAppBase
|
|
69
95
|
|
|
70
96
|
const root = viteConfig.root || process.cwd()
|
|
97
|
+
resolvedStartConfig.root = root
|
|
98
|
+
|
|
99
|
+
const { startConfig } = getConfig()
|
|
71
100
|
const resolvedSrcDirectory = join(root, startConfig.srcDirectory)
|
|
101
|
+
resolvedStartConfig.srcDirectory = resolvedSrcDirectory
|
|
102
|
+
|
|
103
|
+
const startFilePath = resolveEntry({
|
|
104
|
+
type: 'start entry',
|
|
105
|
+
configuredEntry: startConfig.start.entry,
|
|
106
|
+
defaultEntry: 'start',
|
|
107
|
+
resolvedSrcDirectory,
|
|
108
|
+
required: false,
|
|
109
|
+
})
|
|
110
|
+
resolvedStartConfig.startFilePath = startFilePath
|
|
72
111
|
|
|
73
112
|
const routerFilePath = resolveEntry({
|
|
74
113
|
type: 'router entry',
|
|
75
114
|
configuredEntry: startConfig.router.entry,
|
|
76
115
|
defaultEntry: 'router',
|
|
77
|
-
root,
|
|
78
116
|
resolvedSrcDirectory,
|
|
79
117
|
required: true,
|
|
80
118
|
})
|
|
119
|
+
resolvedStartConfig.routerFilePath = routerFilePath
|
|
120
|
+
|
|
81
121
|
const clientEntryPath = resolveEntry({
|
|
82
122
|
type: 'client entry',
|
|
83
123
|
configuredEntry: startConfig.client.entry,
|
|
84
124
|
defaultEntry: 'client',
|
|
85
|
-
root,
|
|
86
125
|
resolvedSrcDirectory,
|
|
87
126
|
required: false,
|
|
88
127
|
})
|
|
@@ -91,7 +130,6 @@ export function TanStackStartVitePluginCore(
|
|
|
91
130
|
type: 'server entry',
|
|
92
131
|
configuredEntry: startConfig.server.entry,
|
|
93
132
|
defaultEntry: 'server',
|
|
94
|
-
root,
|
|
95
133
|
resolvedSrcDirectory,
|
|
96
134
|
required: false,
|
|
97
135
|
})
|
|
@@ -104,42 +142,33 @@ export function TanStackStartVitePluginCore(
|
|
|
104
142
|
} else {
|
|
105
143
|
clientAlias = corePluginOpts.defaultEntryPaths.client
|
|
106
144
|
}
|
|
145
|
+
|
|
107
146
|
let serverAlias: string
|
|
108
147
|
if (serverEntryPath) {
|
|
109
148
|
serverAlias = vite.normalizePath(path.resolve(root, serverEntryPath))
|
|
110
149
|
} else {
|
|
111
150
|
serverAlias = corePluginOpts.defaultEntryPaths.server
|
|
112
151
|
}
|
|
152
|
+
|
|
153
|
+
let startAlias: string
|
|
154
|
+
if (startFilePath) {
|
|
155
|
+
startAlias = vite.normalizePath(path.resolve(root, startFilePath))
|
|
156
|
+
} else {
|
|
157
|
+
startAlias = corePluginOpts.defaultEntryPaths.start
|
|
158
|
+
}
|
|
159
|
+
|
|
113
160
|
const entryAliasConfiguration: Record<
|
|
114
161
|
(typeof ENTRY_POINTS)[keyof typeof ENTRY_POINTS],
|
|
115
162
|
string
|
|
116
163
|
> = {
|
|
164
|
+
[ENTRY_POINTS.start]: startAlias,
|
|
117
165
|
[ENTRY_POINTS.router]: routerFilePath,
|
|
118
166
|
[ENTRY_POINTS.client]: clientAlias,
|
|
119
167
|
[ENTRY_POINTS.server]: serverAlias,
|
|
120
168
|
}
|
|
121
169
|
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
// Create a dummy nitro app to get the resolved public output path
|
|
125
|
-
const dummyNitroApp = await createNitro({
|
|
126
|
-
preset: startConfig.target,
|
|
127
|
-
compatibilityDate: '2024-12-01',
|
|
128
|
-
})
|
|
129
|
-
|
|
130
|
-
const nitroOutputPublicDir = dummyNitroApp.options.output.publicDir
|
|
131
|
-
await dummyNitroApp.close()
|
|
132
|
-
|
|
133
|
-
return nitroOutputPublicDir
|
|
134
|
-
})()*/
|
|
135
|
-
|
|
136
|
-
const startPackageName = `@tanstack/${corePluginOpts.framework}-start`
|
|
137
|
-
const routerPackageName = `@tanstack/${corePluginOpts.framework}-router`
|
|
138
|
-
|
|
139
|
-
const additionalOptimizeDeps = {
|
|
140
|
-
include: new Set<string>(),
|
|
141
|
-
exclude: new Set<string>(),
|
|
142
|
-
}
|
|
170
|
+
const startPackageName =
|
|
171
|
+
`@tanstack/${corePluginOpts.framework}-start` as const
|
|
143
172
|
|
|
144
173
|
// crawl packages that have start in "peerDependencies"
|
|
145
174
|
// see https://github.com/svitejs/vitefu/blob/d8d82fa121e3b2215ba437107093c77bde51b63b/src/index.js#L95-L101
|
|
@@ -147,34 +176,16 @@ export function TanStackStartVitePluginCore(
|
|
|
147
176
|
// this is currently uncached; could be implemented similarly as vite handles lock file changes
|
|
148
177
|
// see https://github.com/vitejs/vite/blob/557f797d29422027e8c451ca50dd84bf8c41b5f0/packages/vite/src/node/optimizer/index.ts#L1282
|
|
149
178
|
|
|
150
|
-
const
|
|
179
|
+
const crawlFrameworkPkgsResult = await crawlFrameworkPkgs({
|
|
151
180
|
root: process.cwd(),
|
|
152
181
|
isBuild: command === 'build',
|
|
153
182
|
isFrameworkPkgByJson(pkgJson) {
|
|
154
|
-
if ([routerPackageName, startPackageName].includes(pkgJson.name)) {
|
|
155
|
-
return false
|
|
156
|
-
}
|
|
157
|
-
|
|
158
183
|
const peerDependencies = pkgJson['peerDependencies']
|
|
159
184
|
|
|
160
185
|
if (peerDependencies) {
|
|
161
|
-
|
|
162
|
-
name: pkgJson.name,
|
|
163
|
-
peerDependencies,
|
|
164
|
-
exports: pkgJson.exports,
|
|
165
|
-
})
|
|
166
|
-
if (internalResult) {
|
|
167
|
-
if (internalResult === 'exclude') {
|
|
168
|
-
additionalOptimizeDeps.exclude.add(pkgJson.name)
|
|
169
|
-
} else {
|
|
170
|
-
additionalOptimizeDeps.include.add(pkgJson.name)
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
return (
|
|
174
|
-
startPackageName in peerDependencies ||
|
|
175
|
-
routerPackageName in peerDependencies
|
|
176
|
-
)
|
|
186
|
+
return startPackageName in peerDependencies
|
|
177
187
|
}
|
|
188
|
+
|
|
178
189
|
return false
|
|
179
190
|
},
|
|
180
191
|
})
|
|
@@ -198,6 +209,7 @@ export function TanStackStartVitePluginCore(
|
|
|
198
209
|
},
|
|
199
210
|
[VITE_ENVIRONMENT_NAMES.server]: {
|
|
200
211
|
consumer: 'server',
|
|
212
|
+
|
|
201
213
|
build: {
|
|
202
214
|
ssr: true,
|
|
203
215
|
rollupOptions: {
|
|
@@ -213,42 +225,20 @@ export function TanStackStartVitePluginCore(
|
|
|
213
225
|
viteConfig.environments?.[VITE_ENVIRONMENT_NAMES.server]
|
|
214
226
|
?.build?.copyPublicDir ?? false,
|
|
215
227
|
},
|
|
216
|
-
optimizeDeps: {
|
|
217
|
-
exclude: [
|
|
218
|
-
...Object.values(VIRTUAL_MODULES),
|
|
219
|
-
...result.optimizeDeps.exclude.sort(),
|
|
220
|
-
...additionalOptimizeDeps.exclude,
|
|
221
|
-
`@tanstack/${corePluginOpts.framework}-start/server`,
|
|
222
|
-
],
|
|
223
|
-
include: [
|
|
224
|
-
...additionalOptimizeDeps.include,
|
|
225
|
-
...result.optimizeDeps.include.sort(),
|
|
226
|
-
],
|
|
227
|
-
},
|
|
228
228
|
},
|
|
229
229
|
},
|
|
230
|
+
|
|
230
231
|
resolve: {
|
|
231
232
|
noExternal: [
|
|
233
|
+
// ENTRY_POINTS.start,
|
|
232
234
|
'@tanstack/start**',
|
|
233
235
|
`@tanstack/${corePluginOpts.framework}-start**`,
|
|
234
|
-
...
|
|
235
|
-
startPackageName,
|
|
236
|
-
...result.ssr.noExternal.sort(),
|
|
236
|
+
...crawlFrameworkPkgsResult.ssr.noExternal.sort(),
|
|
237
237
|
],
|
|
238
|
-
dedupe: [startPackageName],
|
|
239
238
|
alias: {
|
|
240
239
|
...entryAliasConfiguration,
|
|
241
240
|
},
|
|
242
241
|
},
|
|
243
|
-
optimizeDeps: {
|
|
244
|
-
exclude: [
|
|
245
|
-
...Object.values(VIRTUAL_MODULES),
|
|
246
|
-
startPackageName,
|
|
247
|
-
...result.optimizeDeps.exclude.sort(),
|
|
248
|
-
...additionalOptimizeDeps.exclude,
|
|
249
|
-
],
|
|
250
|
-
include: [...additionalOptimizeDeps.include],
|
|
251
|
-
},
|
|
252
242
|
/* prettier-ignore */
|
|
253
243
|
define: {
|
|
254
244
|
// define is an esbuild function that replaces the any instances of given keys with the given values
|
|
@@ -290,9 +280,11 @@ export function TanStackStartVitePluginCore(
|
|
|
290
280
|
}
|
|
291
281
|
},
|
|
292
282
|
},
|
|
293
|
-
|
|
283
|
+
tanStackStartRouter(startPluginOpts, getConfig, corePluginOpts),
|
|
294
284
|
// N.B. TanStackStartCompilerPlugin must be before the TanStackServerFnPluginEnv
|
|
295
285
|
startCompilerPlugin(corePluginOpts.framework),
|
|
286
|
+
createServerFnPlugin(corePluginOpts.framework),
|
|
287
|
+
|
|
296
288
|
TanStackServerFnPluginEnv({
|
|
297
289
|
// This is the ID that will be available to look up and import
|
|
298
290
|
// our server function manifest and resolve its module
|
|
@@ -314,7 +306,7 @@ export function TanStackStartVitePluginCore(
|
|
|
314
306
|
startManifestPlugin({
|
|
315
307
|
getClientBundle: () => getBundle(VITE_ENVIRONMENT_NAMES.client),
|
|
316
308
|
}),
|
|
317
|
-
devServerPlugin({
|
|
309
|
+
devServerPlugin({ getConfig }),
|
|
318
310
|
{
|
|
319
311
|
name: 'tanstack-start:core:capture-bundle',
|
|
320
312
|
applyToEnvironment(e) {
|
package/src/resolve-entries.ts
CHANGED
|
@@ -24,7 +24,6 @@ export function resolveEntry<
|
|
|
24
24
|
configuredEntry?: string
|
|
25
25
|
defaultEntry: string
|
|
26
26
|
resolvedSrcDirectory: string
|
|
27
|
-
root: string
|
|
28
27
|
required: TRequired
|
|
29
28
|
}): TReturn {
|
|
30
29
|
let resolveOptions: ResolveModuleOptions
|
|
@@ -38,7 +37,7 @@ export function resolveEntry<
|
|
|
38
37
|
} else {
|
|
39
38
|
resolveOptions = {
|
|
40
39
|
baseName: opts.configuredEntry,
|
|
41
|
-
from: opts.
|
|
40
|
+
from: opts.resolvedSrcDirectory,
|
|
42
41
|
}
|
|
43
42
|
}
|
|
44
43
|
|
package/src/schema.ts
CHANGED
|
@@ -1,32 +1,44 @@
|
|
|
1
1
|
import path from 'node:path'
|
|
2
2
|
import { z } from 'zod'
|
|
3
|
-
import { configSchema, getConfig } from '@tanstack/router-
|
|
3
|
+
import { configSchema, getConfig } from '@tanstack/router-plugin'
|
|
4
|
+
import type { TanStackStartVitePluginCoreOptions } from './plugin'
|
|
4
5
|
|
|
5
|
-
const tsrConfig = configSchema
|
|
6
|
+
const tsrConfig = configSchema
|
|
7
|
+
.omit({ autoCodeSplitting: true, target: true, verboseFileRoutes: true })
|
|
8
|
+
.partial()
|
|
6
9
|
|
|
7
10
|
export function parseStartConfig(
|
|
8
|
-
opts
|
|
11
|
+
opts: z.input<typeof tanstackStartOptionsSchema>,
|
|
12
|
+
corePluginOpts: TanStackStartVitePluginCoreOptions,
|
|
13
|
+
root: string,
|
|
9
14
|
) {
|
|
10
15
|
const options = tanstackStartOptionsSchema.parse(opts)
|
|
11
16
|
|
|
12
17
|
const srcDirectory = options.srcDirectory
|
|
13
18
|
|
|
14
|
-
const routesDirectory =
|
|
15
|
-
|
|
19
|
+
const routesDirectory = path.resolve(
|
|
20
|
+
srcDirectory,
|
|
21
|
+
options.router.routesDirectory ?? 'routes',
|
|
22
|
+
)
|
|
16
23
|
|
|
17
|
-
const generatedRouteTree =
|
|
18
|
-
|
|
19
|
-
|
|
24
|
+
const generatedRouteTree = path.resolve(
|
|
25
|
+
srcDirectory,
|
|
26
|
+
options.router.generatedRouteTree ?? 'routeTree.gen.ts',
|
|
27
|
+
)
|
|
20
28
|
|
|
21
29
|
return {
|
|
22
30
|
...options,
|
|
23
31
|
router: {
|
|
24
32
|
...options.router,
|
|
25
|
-
...getConfig(
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
33
|
+
...getConfig(
|
|
34
|
+
{
|
|
35
|
+
...options.router,
|
|
36
|
+
routesDirectory,
|
|
37
|
+
generatedRouteTree,
|
|
38
|
+
},
|
|
39
|
+
root,
|
|
40
|
+
),
|
|
41
|
+
target: corePluginOpts.framework,
|
|
30
42
|
},
|
|
31
43
|
}
|
|
32
44
|
}
|
|
@@ -115,9 +127,14 @@ const pageSchema = pageBaseSchema.extend({
|
|
|
115
127
|
const tanstackStartOptionsSchema = z
|
|
116
128
|
.object({
|
|
117
129
|
srcDirectory: z.string().optional().default('src'),
|
|
130
|
+
start: z
|
|
131
|
+
.object({
|
|
132
|
+
entry: z.string().optional(),
|
|
133
|
+
})
|
|
134
|
+
.optional()
|
|
135
|
+
.default({}),
|
|
118
136
|
router: z
|
|
119
137
|
.object({
|
|
120
|
-
// TODO this will move to 'start' once we have `createStart`
|
|
121
138
|
entry: z.string().optional(),
|
|
122
139
|
})
|
|
123
140
|
.and(tsrConfig.optional().default({}))
|
|
@@ -7,9 +7,7 @@ import {
|
|
|
7
7
|
} from 'babel-dead-code-elimination'
|
|
8
8
|
import { generateFromAst, parseAst } from '@tanstack/router-utils'
|
|
9
9
|
import { transformFuncs } from './constants'
|
|
10
|
-
import { handleCreateServerFileRouteCallExpressionFactory } from './serverFileRoute'
|
|
11
10
|
import { handleCreateIsomorphicFnCallExpression } from './isomorphicFn'
|
|
12
|
-
import { handleCreateMiddlewareCallExpression } from './middleware'
|
|
13
11
|
import {
|
|
14
12
|
handleCreateClientOnlyFnCallExpression,
|
|
15
13
|
handleCreateServerOnlyFnCallExpression,
|
|
@@ -19,59 +17,29 @@ import type { GeneratorResult, ParseAstOptions } from '@tanstack/router-utils'
|
|
|
19
17
|
export type CompileStartFrameworkOptions = 'react' | 'solid'
|
|
20
18
|
|
|
21
19
|
type Identifiers = { [K in (typeof transformFuncs)[number]]: IdentifierConfig }
|
|
22
|
-
const getIdentifiers = (
|
|
23
|
-
framework: CompileStartFrameworkOptions,
|
|
24
|
-
): Identifiers => ({
|
|
25
|
-
createServerRootRoute: {
|
|
26
|
-
name: 'createServerRootRoute',
|
|
27
|
-
handleCallExpression: handleCreateServerFileRouteCallExpressionFactory(
|
|
28
|
-
framework,
|
|
29
|
-
'createServerRootRoute',
|
|
30
|
-
),
|
|
31
|
-
paths: [],
|
|
32
|
-
},
|
|
33
|
-
createServerRoute: {
|
|
34
|
-
name: 'createServerRoute',
|
|
35
|
-
handleCallExpression: handleCreateServerFileRouteCallExpressionFactory(
|
|
36
|
-
framework,
|
|
37
|
-
'createServerRoute',
|
|
38
|
-
),
|
|
39
|
-
paths: [],
|
|
40
|
-
},
|
|
41
|
-
createServerFileRoute: {
|
|
42
|
-
name: 'createServerFileRoute',
|
|
43
|
-
handleCallExpression: handleCreateServerFileRouteCallExpressionFactory(
|
|
44
|
-
framework,
|
|
45
|
-
'createServerFileRoute',
|
|
46
|
-
),
|
|
47
|
-
paths: [],
|
|
48
|
-
},
|
|
49
|
-
createMiddleware: {
|
|
50
|
-
name: 'createMiddleware',
|
|
51
|
-
handleCallExpression: handleCreateMiddlewareCallExpression,
|
|
52
|
-
paths: [],
|
|
53
|
-
},
|
|
54
|
-
createServerOnlyFn: {
|
|
55
|
-
name: 'createServerOnlyFn',
|
|
56
|
-
handleCallExpression: handleCreateServerOnlyFnCallExpression,
|
|
57
|
-
paths: [],
|
|
58
|
-
},
|
|
59
|
-
createClientOnlyFn: {
|
|
60
|
-
name: 'createClientOnlyFn',
|
|
61
|
-
handleCallExpression: handleCreateClientOnlyFnCallExpression,
|
|
62
|
-
paths: [],
|
|
63
|
-
},
|
|
64
|
-
createIsomorphicFn: {
|
|
65
|
-
name: 'createIsomorphicFn',
|
|
66
|
-
handleCallExpression: handleCreateIsomorphicFnCallExpression,
|
|
67
|
-
paths: [],
|
|
68
|
-
},
|
|
69
|
-
})
|
|
70
20
|
|
|
71
21
|
export function compileStartOutputFactory(
|
|
72
22
|
framework: CompileStartFrameworkOptions,
|
|
73
23
|
) {
|
|
74
24
|
return function compileStartOutput(opts: CompileOptions): GeneratorResult {
|
|
25
|
+
const identifiers: Identifiers = {
|
|
26
|
+
createServerOnlyFn: {
|
|
27
|
+
name: 'createServerOnlyFn',
|
|
28
|
+
handleCallExpression: handleCreateServerOnlyFnCallExpression,
|
|
29
|
+
paths: [],
|
|
30
|
+
},
|
|
31
|
+
createClientOnlyFn: {
|
|
32
|
+
name: 'createClientOnlyFn',
|
|
33
|
+
handleCallExpression: handleCreateClientOnlyFnCallExpression,
|
|
34
|
+
paths: [],
|
|
35
|
+
},
|
|
36
|
+
createIsomorphicFn: {
|
|
37
|
+
name: 'createIsomorphicFn',
|
|
38
|
+
handleCallExpression: handleCreateIsomorphicFnCallExpression,
|
|
39
|
+
paths: [],
|
|
40
|
+
},
|
|
41
|
+
}
|
|
42
|
+
|
|
75
43
|
const ast = parseAst(opts)
|
|
76
44
|
|
|
77
45
|
const doDce = opts.dce ?? true
|
|
@@ -81,7 +49,6 @@ export function compileStartOutputFactory(
|
|
|
81
49
|
babel.traverse(ast, {
|
|
82
50
|
Program: {
|
|
83
51
|
enter(programPath) {
|
|
84
|
-
const identifiers = getIdentifiers(framework)
|
|
85
52
|
programPath.traverse({
|
|
86
53
|
ImportDeclaration: (path) => {
|
|
87
54
|
if (path.node.source.value !== `@tanstack/${framework}-start`) {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const SERVER_PROP = 'server'
|
|
@@ -9,20 +9,14 @@ import type { GeneratorPlugin } from '@tanstack/router-generator'
|
|
|
9
9
|
export function routesManifestPlugin(): GeneratorPlugin {
|
|
10
10
|
return {
|
|
11
11
|
name: 'routes-manifest-plugin',
|
|
12
|
-
|
|
13
|
-
const routeTree = routeTrees.find((tree) => tree.exportName === 'Route')
|
|
14
|
-
if (!routeTree) {
|
|
15
|
-
throw new Error(
|
|
16
|
-
'No route tree found with export name "Route". Please ensure your routes are correctly defined.',
|
|
17
|
-
)
|
|
18
|
-
}
|
|
12
|
+
onRouteTreeChanged: ({ routeTree, rootRouteNode, routeNodes }) => {
|
|
19
13
|
const routesManifest = {
|
|
20
14
|
[rootRouteId]: {
|
|
21
15
|
filePath: rootRouteNode.fullPath,
|
|
22
|
-
children: routeTree.
|
|
16
|
+
children: routeTree.map((d) => d.routePath),
|
|
23
17
|
},
|
|
24
18
|
...Object.fromEntries(
|
|
25
|
-
|
|
19
|
+
routeNodes.map((d) => {
|
|
26
20
|
const filePathId = d.routePath
|
|
27
21
|
|
|
28
22
|
return [
|