@tanstack/start-plugin-core 1.120.4-alpha.2 → 1.120.4-alpha.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/constants.cjs +10 -0
- package/dist/cjs/constants.cjs.map +1 -0
- package/dist/cjs/constants.d.cts +4 -0
- package/dist/cjs/nitro/dev-server-plugin.cjs +11 -3
- package/dist/cjs/nitro/dev-server-plugin.cjs.map +1 -1
- package/dist/cjs/nitro/nitro-plugin.cjs +24 -5
- package/dist/cjs/nitro/nitro-plugin.cjs.map +1 -1
- package/dist/cjs/plugin.cjs +49 -15
- package/dist/cjs/plugin.cjs.map +1 -1
- package/dist/cjs/plugin.d.cts +620 -1
- package/dist/cjs/prerender.cjs +19 -15
- package/dist/cjs/prerender.cjs.map +1 -1
- package/dist/cjs/schema.cjs +21 -2
- package/dist/cjs/schema.cjs.map +1 -1
- package/dist/cjs/schema.d.cts +2281 -520
- package/dist/cjs/start-server-routes-plugin/plugin.cjs +6 -2
- package/dist/cjs/start-server-routes-plugin/plugin.cjs.map +1 -1
- package/dist/esm/constants.d.ts +4 -0
- package/dist/esm/constants.js +10 -0
- package/dist/esm/constants.js.map +1 -0
- package/dist/esm/nitro/dev-server-plugin.js +11 -3
- package/dist/esm/nitro/dev-server-plugin.js.map +1 -1
- package/dist/esm/nitro/nitro-plugin.js +24 -5
- package/dist/esm/nitro/nitro-plugin.js.map +1 -1
- package/dist/esm/plugin.d.ts +620 -1
- package/dist/esm/plugin.js +49 -15
- package/dist/esm/plugin.js.map +1 -1
- package/dist/esm/prerender.js +19 -15
- package/dist/esm/prerender.js.map +1 -1
- package/dist/esm/schema.d.ts +2281 -520
- package/dist/esm/schema.js +21 -2
- package/dist/esm/schema.js.map +1 -1
- package/dist/esm/start-server-routes-plugin/plugin.js +6 -2
- package/dist/esm/start-server-routes-plugin/plugin.js.map +1 -1
- package/package.json +11 -5
- package/src/constants.ts +6 -0
- package/src/nitro/dev-server-plugin.ts +14 -4
- package/src/nitro/nitro-plugin.ts +28 -3
- package/src/plugin.ts +64 -15
- package/src/prerender.ts +26 -19
- package/src/schema.ts +26 -1
- package/src/start-server-routes-plugin/plugin.ts +10 -2
package/src/prerender.ts
CHANGED
|
@@ -6,6 +6,7 @@ import { build as buildNitro, createNitro } from 'nitropack'
|
|
|
6
6
|
import { joinURL, withBase, withoutBase } from 'ufo'
|
|
7
7
|
import { Queue } from './queue'
|
|
8
8
|
import { buildNitroEnvironment } from './nitro/build-nitro'
|
|
9
|
+
import { VITE_ENVIRONMENT_NAMES } from './constants'
|
|
9
10
|
import type { ViteBuilder } from 'vite'
|
|
10
11
|
import type { $Fetch, Nitro } from 'nitropack'
|
|
11
12
|
import type { TanStackStartOutputConfig } from './plugin'
|
|
@@ -20,7 +21,7 @@ export async function prerender({
|
|
|
20
21
|
nitro: Nitro
|
|
21
22
|
builder: ViteBuilder
|
|
22
23
|
}) {
|
|
23
|
-
|
|
24
|
+
console.info('Prendering pages...')
|
|
24
25
|
|
|
25
26
|
// If prerender is enabled but no pages are provided, default to prerendering the root page
|
|
26
27
|
if (options.prerender?.enabled && !options.pages.length) {
|
|
@@ -31,10 +32,12 @@ export async function prerender({
|
|
|
31
32
|
]
|
|
32
33
|
}
|
|
33
34
|
|
|
34
|
-
const serverEnv = builder.environments[
|
|
35
|
+
const serverEnv = builder.environments[VITE_ENVIRONMENT_NAMES.server]
|
|
35
36
|
|
|
36
37
|
if (!serverEnv) {
|
|
37
|
-
throw new Error(
|
|
38
|
+
throw new Error(
|
|
39
|
+
`Vite's "${VITE_ENVIRONMENT_NAMES.server}" environment not found`,
|
|
40
|
+
)
|
|
38
41
|
}
|
|
39
42
|
|
|
40
43
|
const prerenderOutputDir = path.resolve(
|
|
@@ -90,14 +93,14 @@ export async function prerender({
|
|
|
90
93
|
// Crawl all pages
|
|
91
94
|
const pages = await prerenderPages()
|
|
92
95
|
|
|
93
|
-
|
|
96
|
+
console.info(`Prerendered ${pages.length} pages:`)
|
|
94
97
|
pages.forEach((page) => {
|
|
95
|
-
|
|
98
|
+
console.info(`- ${page}`)
|
|
96
99
|
})
|
|
97
100
|
|
|
98
101
|
// TODO: Write the prerendered pages to the output directory
|
|
99
102
|
} catch (error) {
|
|
100
|
-
|
|
103
|
+
console.error(error)
|
|
101
104
|
} finally {
|
|
102
105
|
// Ensure server is always closed
|
|
103
106
|
// server.process.kill()
|
|
@@ -123,7 +126,7 @@ export async function prerender({
|
|
|
123
126
|
const seen = new Set<string>()
|
|
124
127
|
const retriesByPath = new Map<string, number>()
|
|
125
128
|
const concurrency = options.prerender?.concurrency ?? os.cpus().length
|
|
126
|
-
|
|
129
|
+
console.info(`Concurrency: ${concurrency}`)
|
|
127
130
|
const queue = new Queue({ concurrency })
|
|
128
131
|
|
|
129
132
|
options.pages.forEach((_page) => {
|
|
@@ -165,7 +168,7 @@ export async function prerender({
|
|
|
165
168
|
|
|
166
169
|
// Add the task
|
|
167
170
|
queue.add(async () => {
|
|
168
|
-
|
|
171
|
+
console.info(`Crawling: ${page.path}`)
|
|
169
172
|
const retries = retriesByPath.get(page.path) || 0
|
|
170
173
|
try {
|
|
171
174
|
// Fetch the route
|
|
@@ -179,23 +182,29 @@ export async function prerender({
|
|
|
179
182
|
)
|
|
180
183
|
|
|
181
184
|
if (!res.ok) {
|
|
182
|
-
throw new Error(`Failed to fetch ${page.path}: ${res.statusText}
|
|
185
|
+
throw new Error(`Failed to fetch ${page.path}: ${res.statusText}`, {
|
|
186
|
+
cause: res,
|
|
187
|
+
})
|
|
183
188
|
}
|
|
184
189
|
|
|
190
|
+
const cleanPagePath = (
|
|
191
|
+
prerenderOptions.outputPath || page.path
|
|
192
|
+
).split(/[?#]/)[0]!
|
|
193
|
+
|
|
185
194
|
// Guess route type and populate fileName
|
|
186
195
|
const contentType = res.headers.get('content-type') || ''
|
|
187
196
|
const isImplicitHTML =
|
|
188
|
-
!
|
|
197
|
+
!cleanPagePath.endsWith('.html') && contentType.includes('html')
|
|
189
198
|
// &&
|
|
190
199
|
// !JsonSigRx.test(dataBuff.subarray(0, 32).toString('utf8'))
|
|
191
|
-
const routeWithIndex =
|
|
192
|
-
?
|
|
193
|
-
:
|
|
200
|
+
const routeWithIndex = cleanPagePath.endsWith('/')
|
|
201
|
+
? cleanPagePath + 'index'
|
|
202
|
+
: cleanPagePath
|
|
194
203
|
|
|
195
204
|
const htmlPath =
|
|
196
|
-
|
|
197
|
-
? joinURL(
|
|
198
|
-
:
|
|
205
|
+
cleanPagePath.endsWith('/') || prerenderOptions.autoSubfolderIndex
|
|
206
|
+
? joinURL(cleanPagePath, 'index.html')
|
|
207
|
+
: cleanPagePath + '.html'
|
|
199
208
|
|
|
200
209
|
const filename = withoutBase(
|
|
201
210
|
isImplicitHTML ? htmlPath : routeWithIndex,
|
|
@@ -227,9 +236,7 @@ export async function prerender({
|
|
|
227
236
|
}
|
|
228
237
|
} catch (error) {
|
|
229
238
|
if (retries < (prerenderOptions.retryCount ?? 0)) {
|
|
230
|
-
|
|
231
|
-
`Encountered error, retrying: ${page.path} in 500ms`,
|
|
232
|
-
)
|
|
239
|
+
console.warn(`Encountered error, retrying: ${page.path} in 500ms`)
|
|
233
240
|
await new Promise((resolve) =>
|
|
234
241
|
setTimeout(resolve, prerenderOptions.retryDelay),
|
|
235
242
|
)
|
package/src/schema.ts
CHANGED
|
@@ -48,6 +48,14 @@ export function createTanStackConfig<
|
|
|
48
48
|
return path.join(srcDirectory, 'server.tsx')
|
|
49
49
|
}
|
|
50
50
|
|
|
51
|
+
if (existsSync(path.join(srcDirectory, 'server.ts'))) {
|
|
52
|
+
return path.join(srcDirectory, 'server.ts')
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
if (existsSync(path.join(srcDirectory, 'server.js'))) {
|
|
56
|
+
return path.join(srcDirectory, 'server.js')
|
|
57
|
+
}
|
|
58
|
+
|
|
51
59
|
return '/~start/default-server-entry'
|
|
52
60
|
})()
|
|
53
61
|
|
|
@@ -92,7 +100,7 @@ export function createTanStackStartOptionsSchema(
|
|
|
92
100
|
.default({}),
|
|
93
101
|
serverFns: z
|
|
94
102
|
.object({
|
|
95
|
-
base: z.string().optional().default('/
|
|
103
|
+
base: z.string().optional().default('/_serverFn'),
|
|
96
104
|
})
|
|
97
105
|
.optional()
|
|
98
106
|
.default({}),
|
|
@@ -121,6 +129,7 @@ export function createTanStackStartOptionsSchema(
|
|
|
121
129
|
})
|
|
122
130
|
.and(pagePrerenderOptionsSchema.optional())
|
|
123
131
|
.optional(),
|
|
132
|
+
spa: spaSchema.optional(),
|
|
124
133
|
})
|
|
125
134
|
.optional()
|
|
126
135
|
.default({})
|
|
@@ -170,6 +179,7 @@ const pageBaseSchema = z.object({
|
|
|
170
179
|
|
|
171
180
|
const pagePrerenderOptionsSchema = z.object({
|
|
172
181
|
enabled: z.boolean().optional(),
|
|
182
|
+
outputPath: z.string().optional(),
|
|
173
183
|
autoSubfolderIndex: z.boolean().optional(),
|
|
174
184
|
crawlLinks: z.boolean().optional(),
|
|
175
185
|
retryCount: z.number().optional(),
|
|
@@ -186,6 +196,21 @@ const pagePrerenderOptionsSchema = z.object({
|
|
|
186
196
|
.optional(),
|
|
187
197
|
})
|
|
188
198
|
|
|
199
|
+
const spaSchema = z.object({
|
|
200
|
+
enabled: z.boolean().optional().default(true),
|
|
201
|
+
maskPath: z.string().optional().default('/'),
|
|
202
|
+
prerender: pagePrerenderOptionsSchema
|
|
203
|
+
.optional()
|
|
204
|
+
.default({})
|
|
205
|
+
.transform((opts) => ({
|
|
206
|
+
outputPath: opts.outputPath ?? '/_shell',
|
|
207
|
+
crawlLinks: false,
|
|
208
|
+
retryCount: 0,
|
|
209
|
+
...opts,
|
|
210
|
+
enabled: true,
|
|
211
|
+
})),
|
|
212
|
+
})
|
|
213
|
+
|
|
189
214
|
export const pageSchema = pageBaseSchema.extend({
|
|
190
215
|
prerender: pagePrerenderOptionsSchema.optional(),
|
|
191
216
|
})
|
|
@@ -244,7 +244,9 @@ async function generator(config: Config, root: string) {
|
|
|
244
244
|
removeUnderscores(removeLayoutSegments(node.path)) ?? '',
|
|
245
245
|
)
|
|
246
246
|
|
|
247
|
-
const routeCode =
|
|
247
|
+
const routeCode = node.fullPath
|
|
248
|
+
? fs.readFileSync(node.fullPath, 'utf-8')
|
|
249
|
+
: ''
|
|
248
250
|
|
|
249
251
|
// Ensure the boilerplate for the route exists, which can be skipped for virtual parent routes and virtual routes
|
|
250
252
|
if (!node.isVirtualParentRoute && !node.isVirtual) {
|
|
@@ -682,7 +684,13 @@ function buildStartDeclarationFile({
|
|
|
682
684
|
}: {
|
|
683
685
|
serverRoutesRelativePath: string
|
|
684
686
|
}) {
|
|
685
|
-
|
|
687
|
+
const serverRoutesPath = replaceBackslash(serverRoutesRelativePath)
|
|
688
|
+
return (
|
|
689
|
+
[
|
|
690
|
+
'/// <reference types="vite/client" />',
|
|
691
|
+
`import '${serverRoutesPath}'`,
|
|
692
|
+
].join('\n') + '\n'
|
|
693
|
+
)
|
|
686
694
|
}
|
|
687
695
|
|
|
688
696
|
function removeGroups(s: string) {
|