@tanstack/start-plugin-core 1.167.18 → 1.167.19
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 +12 -1
- 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/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
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
/* eslint-disable @typescript-eslint/prefer-for-of */
|
|
2
2
|
import { joinURL } from 'ufo'
|
|
3
3
|
import { resolveManifestAssetLink, rootRouteId } from '@tanstack/router-core'
|
|
4
|
-
import {
|
|
4
|
+
import {
|
|
5
|
+
getRouteFilePathsFromModuleIds,
|
|
6
|
+
normalizeViteClientBuild,
|
|
7
|
+
normalizeViteClientChunk,
|
|
8
|
+
} from '../vite/start-manifest-plugin/normalized-client-build'
|
|
5
9
|
import type { ManifestAssetLink, RouterManagedTag } from '@tanstack/router-core'
|
|
6
|
-
import type {
|
|
10
|
+
import type { NormalizedClientBuild, NormalizedClientChunk } from '../types'
|
|
7
11
|
|
|
8
12
|
const ROUTER_MANAGED_MODE = 1
|
|
9
13
|
const NON_ROUTE_DYNAMIC_MODE = 2
|
|
@@ -19,15 +23,15 @@ type RouteTreeRoute = {
|
|
|
19
23
|
type RouteTreeRoutes = Record<string, RouteTreeRoute>
|
|
20
24
|
|
|
21
25
|
interface ScannedClientChunks {
|
|
22
|
-
entryChunk:
|
|
23
|
-
chunksByFileName:
|
|
24
|
-
routeChunksByFilePath:
|
|
25
|
-
routeEntryChunks:
|
|
26
|
+
entryChunk: NormalizedClientChunk
|
|
27
|
+
chunksByFileName: ReadonlyMap<string, NormalizedClientChunk>
|
|
28
|
+
routeChunksByFilePath: ReadonlyMap<string, Array<NormalizedClientChunk>>
|
|
29
|
+
routeEntryChunks: ReadonlySet<NormalizedClientChunk>
|
|
26
30
|
}
|
|
27
31
|
|
|
28
32
|
interface ManifestAssetResolvers {
|
|
29
33
|
getAssetPath: (fileName: string) => string
|
|
30
|
-
getChunkPreloads: (chunk:
|
|
34
|
+
getChunkPreloads: (chunk: NormalizedClientChunk) => Array<string>
|
|
31
35
|
getStylesheetAsset: (cssFile: string) => RouterManagedTag
|
|
32
36
|
}
|
|
33
37
|
|
|
@@ -121,9 +125,9 @@ function getAssetIdentity(asset: RouterManagedTag) {
|
|
|
121
125
|
|
|
122
126
|
function mergeRouteChunkData(options: {
|
|
123
127
|
route: RouteTreeRoute
|
|
124
|
-
chunk:
|
|
125
|
-
getChunkCssAssets: (chunk:
|
|
126
|
-
getChunkPreloads: (chunk:
|
|
128
|
+
chunk: NormalizedClientChunk
|
|
129
|
+
getChunkCssAssets: (chunk: NormalizedClientChunk) => Array<RouterManagedTag>
|
|
130
|
+
getChunkPreloads: (chunk: NormalizedClientChunk) => Array<string>
|
|
127
131
|
}) {
|
|
128
132
|
const chunkAssets = options.getChunkCssAssets(options.chunk)
|
|
129
133
|
const chunkPreloads = options.getChunkPreloads(options.chunk)
|
|
@@ -136,11 +140,11 @@ function mergeRouteChunkData(options: {
|
|
|
136
140
|
}
|
|
137
141
|
|
|
138
142
|
export function buildStartManifest(options: {
|
|
139
|
-
|
|
143
|
+
clientBuild: NormalizedClientBuild
|
|
140
144
|
routeTreeRoutes: RouteTreeRoutes
|
|
141
145
|
basePath: string
|
|
142
146
|
}) {
|
|
143
|
-
const scannedChunks = scanClientChunks(options.
|
|
147
|
+
const scannedChunks = scanClientChunks(options.clientBuild)
|
|
144
148
|
const hashedCssFiles = collectDynamicImportCss(
|
|
145
149
|
scannedChunks.routeEntryChunks,
|
|
146
150
|
scannedChunks.chunksByFileName,
|
|
@@ -178,110 +182,52 @@ export function buildStartManifest(options: {
|
|
|
178
182
|
}
|
|
179
183
|
|
|
180
184
|
export function scanClientChunks(
|
|
181
|
-
|
|
185
|
+
clientBuild: NormalizedClientBuild,
|
|
182
186
|
): ScannedClientChunks {
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
const routeEntryChunks = new Set<Rollup.OutputChunk>()
|
|
187
|
-
|
|
188
|
-
for (const fileName in clientBundle) {
|
|
189
|
-
const bundleEntry = clientBundle[fileName]!
|
|
190
|
-
if (bundleEntry.type !== 'chunk') {
|
|
191
|
-
continue
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
chunksByFileName.set(bundleEntry.fileName, bundleEntry)
|
|
187
|
+
const entryChunk = clientBuild.chunksByFileName.get(
|
|
188
|
+
clientBuild.entryChunkFileName,
|
|
189
|
+
)
|
|
195
190
|
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
`multiple entries detected: ${entryChunk.fileName} ${bundleEntry.fileName}`,
|
|
200
|
-
)
|
|
201
|
-
}
|
|
202
|
-
entryChunk = bundleEntry
|
|
203
|
-
}
|
|
191
|
+
if (!entryChunk) {
|
|
192
|
+
throw new Error(`Missing entry chunk: ${clientBuild.entryChunkFileName}`)
|
|
193
|
+
}
|
|
204
194
|
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
continue
|
|
208
|
-
}
|
|
195
|
+
const routeEntryChunks = new Set<NormalizedClientChunk>()
|
|
196
|
+
const routeChunksByFilePath = new Map<string, Array<NormalizedClientChunk>>()
|
|
209
197
|
|
|
210
|
-
|
|
198
|
+
for (const chunk of clientBuild.chunksByFileName.values()) {
|
|
199
|
+
if (chunk.routeFilePaths.length > 0) {
|
|
200
|
+
routeEntryChunks.add(chunk)
|
|
211
201
|
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
202
|
+
for (const routeFilePath of chunk.routeFilePaths) {
|
|
203
|
+
let chunks = routeChunksByFilePath.get(routeFilePath)
|
|
204
|
+
if (chunks === undefined) {
|
|
205
|
+
chunks = []
|
|
206
|
+
routeChunksByFilePath.set(routeFilePath, chunks)
|
|
207
|
+
}
|
|
208
|
+
chunks.push(chunk)
|
|
218
209
|
}
|
|
219
|
-
chunks.push(bundleEntry)
|
|
220
210
|
}
|
|
221
211
|
}
|
|
222
212
|
|
|
223
|
-
if (!entryChunk) {
|
|
224
|
-
throw new Error('No entry file found')
|
|
225
|
-
}
|
|
226
|
-
|
|
227
213
|
return {
|
|
228
214
|
entryChunk,
|
|
229
|
-
chunksByFileName,
|
|
215
|
+
chunksByFileName: clientBuild.chunksByFileName,
|
|
230
216
|
routeChunksByFilePath,
|
|
231
217
|
routeEntryChunks,
|
|
232
218
|
}
|
|
233
219
|
}
|
|
234
220
|
|
|
235
|
-
export function getRouteFilePathsFromModuleIds(moduleIds: Array<string>) {
|
|
236
|
-
let routeFilePaths: Array<string> | undefined
|
|
237
|
-
let seenRouteFilePaths: Set<string> | undefined
|
|
238
|
-
|
|
239
|
-
for (const moduleId of moduleIds) {
|
|
240
|
-
const queryIndex = moduleId.indexOf('?')
|
|
241
|
-
|
|
242
|
-
if (queryIndex < 0) {
|
|
243
|
-
continue
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
const query = moduleId.slice(queryIndex + 1)
|
|
247
|
-
|
|
248
|
-
// Fast check before allocating URLSearchParams
|
|
249
|
-
if (!query.includes(tsrSplit)) {
|
|
250
|
-
continue
|
|
251
|
-
}
|
|
252
|
-
|
|
253
|
-
if (!new URLSearchParams(query).has(tsrSplit)) {
|
|
254
|
-
continue
|
|
255
|
-
}
|
|
256
|
-
|
|
257
|
-
const routeFilePath = moduleId.slice(0, queryIndex)
|
|
258
|
-
|
|
259
|
-
if (seenRouteFilePaths?.has(routeFilePath)) {
|
|
260
|
-
continue
|
|
261
|
-
}
|
|
262
|
-
|
|
263
|
-
if (routeFilePaths === undefined) {
|
|
264
|
-
routeFilePaths = []
|
|
265
|
-
seenRouteFilePaths = new Set<string>()
|
|
266
|
-
}
|
|
267
|
-
|
|
268
|
-
routeFilePaths.push(routeFilePath)
|
|
269
|
-
seenRouteFilePaths!.add(routeFilePath)
|
|
270
|
-
}
|
|
271
|
-
|
|
272
|
-
return routeFilePaths ?? []
|
|
273
|
-
}
|
|
274
|
-
|
|
275
221
|
export function collectDynamicImportCss(
|
|
276
|
-
routeEntryChunks:
|
|
277
|
-
chunksByFileName:
|
|
278
|
-
entryChunk?:
|
|
222
|
+
routeEntryChunks: ReadonlySet<NormalizedClientChunk>,
|
|
223
|
+
chunksByFileName: ReadonlyMap<string, NormalizedClientChunk>,
|
|
224
|
+
entryChunk?: NormalizedClientChunk,
|
|
279
225
|
) {
|
|
280
226
|
const routerManagedCssFiles = new Set<string>()
|
|
281
227
|
const nonRouteDynamicCssFiles = new Set<string>()
|
|
282
228
|
const hashedCssFiles = new Set<string>()
|
|
283
|
-
const visitedByChunk = new Map<
|
|
284
|
-
const chunkStack: Array<
|
|
229
|
+
const visitedByChunk = new Map<NormalizedClientChunk, number>()
|
|
230
|
+
const chunkStack: Array<NormalizedClientChunk> = []
|
|
285
231
|
const modeStack: Array<number> = []
|
|
286
232
|
|
|
287
233
|
for (const routeEntryChunk of routeEntryChunks) {
|
|
@@ -306,13 +252,13 @@ export function collectDynamicImportCss(
|
|
|
306
252
|
visitedByChunk.set(chunk, previousMode | mode)
|
|
307
253
|
|
|
308
254
|
if ((mode & ROUTER_MANAGED_MODE) !== 0) {
|
|
309
|
-
for (const cssFile of chunk.
|
|
255
|
+
for (const cssFile of chunk.css) {
|
|
310
256
|
routerManagedCssFiles.add(cssFile)
|
|
311
257
|
}
|
|
312
258
|
}
|
|
313
259
|
|
|
314
260
|
if ((mode & NON_ROUTE_DYNAMIC_MODE) !== 0) {
|
|
315
|
-
for (const cssFile of chunk.
|
|
261
|
+
for (const cssFile of chunk.css) {
|
|
316
262
|
nonRouteDynamicCssFiles.add(cssFile)
|
|
317
263
|
}
|
|
318
264
|
}
|
|
@@ -356,7 +302,7 @@ export function createManifestAssetResolvers(options: {
|
|
|
356
302
|
}): ManifestAssetResolvers {
|
|
357
303
|
const assetPathByFileName = new Map<string, string>()
|
|
358
304
|
const stylesheetAssetByFileName = new Map<string, RouterManagedTag>()
|
|
359
|
-
const preloadsByChunk = new Map<
|
|
305
|
+
const preloadsByChunk = new Map<NormalizedClientChunk, Array<string>>()
|
|
360
306
|
|
|
361
307
|
const getAssetPath = (fileName: string) => {
|
|
362
308
|
const cachedPath = assetPathByFileName.get(fileName)
|
|
@@ -389,7 +335,7 @@ export function createManifestAssetResolvers(options: {
|
|
|
389
335
|
return asset
|
|
390
336
|
}
|
|
391
337
|
|
|
392
|
-
const getChunkPreloads = (chunk:
|
|
338
|
+
const getChunkPreloads = (chunk: NormalizedClientChunk) => {
|
|
393
339
|
const cachedPreloads = preloadsByChunk.get(chunk)
|
|
394
340
|
if (cachedPreloads) {
|
|
395
341
|
return cachedPreloads
|
|
@@ -413,11 +359,14 @@ export function createManifestAssetResolvers(options: {
|
|
|
413
359
|
}
|
|
414
360
|
|
|
415
361
|
export function createChunkCssAssetCollector(options: {
|
|
416
|
-
chunksByFileName:
|
|
362
|
+
chunksByFileName: ReadonlyMap<string, NormalizedClientChunk>
|
|
417
363
|
getStylesheetAsset: (cssFile: string) => RouterManagedTag
|
|
418
364
|
}) {
|
|
419
|
-
const assetsByChunk = new Map<
|
|
420
|
-
|
|
365
|
+
const assetsByChunk = new Map<
|
|
366
|
+
NormalizedClientChunk,
|
|
367
|
+
Array<RouterManagedTag>
|
|
368
|
+
>()
|
|
369
|
+
const stateByChunk = new Map<NormalizedClientChunk, number>()
|
|
421
370
|
|
|
422
371
|
const appendAsset = (
|
|
423
372
|
assets: Array<RouterManagedTag>,
|
|
@@ -434,7 +383,7 @@ export function createChunkCssAssetCollector(options: {
|
|
|
434
383
|
}
|
|
435
384
|
|
|
436
385
|
const getChunkCssAssets = (
|
|
437
|
-
chunk:
|
|
386
|
+
chunk: NormalizedClientChunk,
|
|
438
387
|
): Array<RouterManagedTag> => {
|
|
439
388
|
const cachedAssets = assetsByChunk.get(chunk)
|
|
440
389
|
if (cachedAssets) {
|
|
@@ -449,7 +398,7 @@ export function createChunkCssAssetCollector(options: {
|
|
|
449
398
|
const assets: Array<RouterManagedTag> = []
|
|
450
399
|
const seenAssets = new Set<string>()
|
|
451
400
|
|
|
452
|
-
for (const cssFile of chunk.
|
|
401
|
+
for (const cssFile of chunk.css) {
|
|
453
402
|
appendAsset(assets, seenAssets, options.getStylesheetAsset(cssFile))
|
|
454
403
|
}
|
|
455
404
|
|
|
@@ -475,9 +424,12 @@ export function createChunkCssAssetCollector(options: {
|
|
|
475
424
|
|
|
476
425
|
export function buildRouteManifestRoutes(options: {
|
|
477
426
|
routeTreeRoutes: RouteTreeRoutes
|
|
478
|
-
routeChunksByFilePath:
|
|
479
|
-
|
|
480
|
-
|
|
427
|
+
routeChunksByFilePath: ReadonlyMap<
|
|
428
|
+
string,
|
|
429
|
+
ReadonlyArray<NormalizedClientChunk>
|
|
430
|
+
>
|
|
431
|
+
chunksByFileName: ReadonlyMap<string, NormalizedClientChunk>
|
|
432
|
+
entryChunk: NormalizedClientChunk
|
|
481
433
|
assetResolvers: ManifestAssetResolvers
|
|
482
434
|
}) {
|
|
483
435
|
const routes: Record<string, RouteTreeRoute> = {}
|
|
@@ -526,6 +478,12 @@ export function buildRouteManifestRoutes(options: {
|
|
|
526
478
|
return routes
|
|
527
479
|
}
|
|
528
480
|
|
|
481
|
+
export {
|
|
482
|
+
getRouteFilePathsFromModuleIds,
|
|
483
|
+
normalizeViteClientBuild,
|
|
484
|
+
normalizeViteClientChunk,
|
|
485
|
+
}
|
|
486
|
+
|
|
529
487
|
function dedupeNestedRouteManifestEntries(
|
|
530
488
|
routeId: string,
|
|
531
489
|
route: DedupeRoute,
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import path from 'pathe'
|
|
2
|
+
import type { GetConfigFn, TanStackStartCoreOptions } from '../types'
|
|
3
|
+
|
|
4
|
+
function buildRouteTreeFileFooter(opts: {
|
|
5
|
+
generatedRouteTreePath: string
|
|
6
|
+
startFilePath: string | undefined
|
|
7
|
+
routerFilePath: string
|
|
8
|
+
framework: TanStackStartCoreOptions['framework']
|
|
9
|
+
userFooter?: Array<string> | (() => Array<string>)
|
|
10
|
+
}): Array<string> {
|
|
11
|
+
function getImportPath(absolutePath: string) {
|
|
12
|
+
let relativePath = path.relative(
|
|
13
|
+
path.dirname(opts.generatedRouteTreePath),
|
|
14
|
+
absolutePath,
|
|
15
|
+
)
|
|
16
|
+
|
|
17
|
+
if (!relativePath.startsWith('.')) {
|
|
18
|
+
relativePath = './' + relativePath
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
return relativePath.split(path.sep).join('/')
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function appendFooterBlock(lines: Array<string>, block: string) {
|
|
25
|
+
if (!block) {
|
|
26
|
+
return
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
if (lines.length > 0) {
|
|
30
|
+
lines[lines.length - 1] += `\n${block}`
|
|
31
|
+
return
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
lines.push(block)
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const footer: Array<string> = []
|
|
38
|
+
|
|
39
|
+
appendFooterBlock(
|
|
40
|
+
footer,
|
|
41
|
+
`import type { getRouter } from '${getImportPath(opts.routerFilePath)}'`,
|
|
42
|
+
)
|
|
43
|
+
|
|
44
|
+
if (opts.startFilePath) {
|
|
45
|
+
appendFooterBlock(
|
|
46
|
+
footer,
|
|
47
|
+
`import type { startInstance } from '${getImportPath(opts.startFilePath)}'`,
|
|
48
|
+
)
|
|
49
|
+
} else {
|
|
50
|
+
appendFooterBlock(
|
|
51
|
+
footer,
|
|
52
|
+
`import type { createStart } from '@tanstack/${opts.framework}-start'`,
|
|
53
|
+
)
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
appendFooterBlock(
|
|
57
|
+
footer,
|
|
58
|
+
`declare module '@tanstack/${opts.framework}-start' {
|
|
59
|
+
interface Register {
|
|
60
|
+
ssr: true
|
|
61
|
+
router: Awaited<ReturnType<typeof getRouter>>`,
|
|
62
|
+
)
|
|
63
|
+
|
|
64
|
+
if (opts.startFilePath) {
|
|
65
|
+
appendFooterBlock(
|
|
66
|
+
footer,
|
|
67
|
+
` config: Awaited<ReturnType<typeof startInstance.getOptions>>`,
|
|
68
|
+
)
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
appendFooterBlock(
|
|
72
|
+
footer,
|
|
73
|
+
` }
|
|
74
|
+
}`,
|
|
75
|
+
)
|
|
76
|
+
|
|
77
|
+
if (opts.userFooter) {
|
|
78
|
+
footer.push(
|
|
79
|
+
...(Array.isArray(opts.userFooter) ? opts.userFooter : opts.userFooter()),
|
|
80
|
+
)
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
return footer
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
export function buildRouteTreeFileFooterFromConfig(opts: {
|
|
87
|
+
generatedRouteTreePath: string
|
|
88
|
+
getConfig: GetConfigFn
|
|
89
|
+
corePluginOpts: TanStackStartCoreOptions
|
|
90
|
+
}): Array<string> {
|
|
91
|
+
const { startConfig, resolvedStartConfig } = opts.getConfig()
|
|
92
|
+
return buildRouteTreeFileFooter({
|
|
93
|
+
generatedRouteTreePath: opts.generatedRouteTreePath,
|
|
94
|
+
startFilePath: resolvedStartConfig.startFilePath,
|
|
95
|
+
routerFilePath: resolvedStartConfig.routerFilePath,
|
|
96
|
+
framework: opts.corePluginOpts.framework,
|
|
97
|
+
userFooter: startConfig.router.routeTreeFileFooter,
|
|
98
|
+
})
|
|
99
|
+
}
|
package/src/types.ts
CHANGED
|
@@ -2,19 +2,63 @@ import type { TanStackStartOutputConfig } from './schema'
|
|
|
2
2
|
|
|
3
3
|
export type CompileStartFrameworkOptions = 'react' | 'solid' | 'vue'
|
|
4
4
|
|
|
5
|
-
export
|
|
5
|
+
export type ServerFnLookupAccess = { origin: 'client' } | { origin: 'server' }
|
|
6
|
+
|
|
7
|
+
export type SerializationRuntime = 'client' | 'server'
|
|
8
|
+
|
|
9
|
+
export interface SerializationAdapterModuleRef {
|
|
10
|
+
module: string
|
|
11
|
+
export: string
|
|
12
|
+
isFactory?: boolean
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export type SerializationAdapterByRuntime = Partial<
|
|
16
|
+
Record<SerializationRuntime, SerializationAdapterModuleRef>
|
|
17
|
+
>
|
|
18
|
+
|
|
19
|
+
export type SerializationAdapterConfig =
|
|
20
|
+
| SerializationAdapterModuleRef
|
|
21
|
+
| SerializationAdapterByRuntime
|
|
22
|
+
|
|
23
|
+
export interface NormalizedBasePaths {
|
|
24
|
+
publicBase: string
|
|
25
|
+
assetBase: {
|
|
26
|
+
dev: string
|
|
27
|
+
build: string
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export interface NormalizedOutputDirectories {
|
|
32
|
+
client: string
|
|
33
|
+
server: string
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export interface NormalizedClientChunk {
|
|
37
|
+
fileName: string
|
|
38
|
+
isEntry: boolean
|
|
39
|
+
imports: Array<string>
|
|
40
|
+
dynamicImports: Array<string>
|
|
41
|
+
css: Array<string>
|
|
42
|
+
routeFilePaths: Array<string>
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export interface NormalizedClientBuild {
|
|
46
|
+
entryChunkFileName: string
|
|
47
|
+
chunksByFileName: ReadonlyMap<string, NormalizedClientChunk>
|
|
48
|
+
chunkFileNamesByRouteFilePath: ReadonlyMap<string, ReadonlyArray<string>>
|
|
49
|
+
cssFilesBySourcePath: ReadonlyMap<string, ReadonlyArray<string>>
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export interface TanStackStartCoreOptions {
|
|
6
53
|
framework: CompileStartFrameworkOptions
|
|
7
54
|
defaultEntryPaths: {
|
|
8
55
|
client: string
|
|
9
56
|
server: string
|
|
10
57
|
start: string
|
|
11
58
|
}
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
}
|
|
16
|
-
providerEnv?: string
|
|
17
|
-
}
|
|
59
|
+
providerEnvironmentName: string
|
|
60
|
+
ssrIsProvider: boolean
|
|
61
|
+
serializationAdapters?: Array<SerializationAdapterConfig> | undefined
|
|
18
62
|
}
|
|
19
63
|
|
|
20
64
|
export interface ResolvedStartConfig {
|
|
@@ -22,12 +66,11 @@ export interface ResolvedStartConfig {
|
|
|
22
66
|
startFilePath: string | undefined
|
|
23
67
|
routerFilePath: string
|
|
24
68
|
srcDirectory: string
|
|
25
|
-
|
|
26
|
-
|
|
69
|
+
basePaths: NormalizedBasePaths
|
|
70
|
+
outputDirectories: NormalizedOutputDirectories
|
|
27
71
|
}
|
|
28
72
|
|
|
29
73
|
export type GetConfigFn = () => {
|
|
30
74
|
startConfig: TanStackStartOutputConfig
|
|
31
75
|
resolvedStartConfig: ResolvedStartConfig
|
|
32
|
-
corePluginOpts: TanStackStartVitePluginCoreOptions
|
|
33
76
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { isRunnableDevEnvironment } from 'vite'
|
|
2
2
|
import { VIRTUAL_MODULES } from '@tanstack/start-server-core'
|
|
3
3
|
import { NodeRequest, sendNodeResponse } from 'srvx/node'
|
|
4
|
-
import { ENTRY_POINTS, VITE_ENVIRONMENT_NAMES } from '
|
|
5
|
-
import { resolveViteId } from '
|
|
4
|
+
import { ENTRY_POINTS, VITE_ENVIRONMENT_NAMES } from '../../constants'
|
|
5
|
+
import { resolveViteId } from '../../utils'
|
|
6
6
|
import { extractHtmlScripts } from './extract-html-scripts'
|
|
7
7
|
import {
|
|
8
8
|
CSS_MODULES_REGEX,
|
|
@@ -10,14 +10,16 @@ import {
|
|
|
10
10
|
normalizeCssModuleCacheKey,
|
|
11
11
|
} from './dev-styles'
|
|
12
12
|
import type { Connect, DevEnvironment, PluginOption } from 'vite'
|
|
13
|
-
import type { GetConfigFn } from '
|
|
13
|
+
import type { GetConfigFn } from '../../types'
|
|
14
14
|
|
|
15
15
|
export function devServerPlugin({
|
|
16
|
-
getConfig,
|
|
16
|
+
getConfig: _getConfig,
|
|
17
17
|
devSsrStylesEnabled,
|
|
18
|
+
installDevServerMiddleware,
|
|
18
19
|
}: {
|
|
19
20
|
getConfig: GetConfigFn
|
|
20
21
|
devSsrStylesEnabled: boolean
|
|
22
|
+
installDevServerMiddleware: boolean | undefined
|
|
21
23
|
}): PluginOption {
|
|
22
24
|
let isTest = false
|
|
23
25
|
|
|
@@ -132,8 +134,7 @@ export function devServerPlugin({
|
|
|
132
134
|
)
|
|
133
135
|
}
|
|
134
136
|
|
|
135
|
-
const
|
|
136
|
-
const installMiddleware = startConfig.vite?.installDevServerMiddleware
|
|
137
|
+
const installMiddleware = installDevServerMiddleware
|
|
137
138
|
if (installMiddleware === false) {
|
|
138
139
|
return
|
|
139
140
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { join } from 'pathe'
|
|
2
|
-
import { VITE_ENVIRONMENT_NAMES } from '
|
|
3
|
-
import type { ViteEnvironmentNames } from '
|
|
2
|
+
import { VITE_ENVIRONMENT_NAMES } from '../constants'
|
|
3
|
+
import type { ViteEnvironmentNames } from '../constants'
|
|
4
4
|
import type * as vite from 'vite'
|
|
5
5
|
|
|
6
6
|
export function getClientOutputDirectory(
|