@tanstack/start-plugin-core 1.121.0-alpha.8 → 1.121.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/cjs/compilers.cjs +24 -10
- package/dist/cjs/compilers.cjs.map +1 -1
- package/dist/cjs/constants.cjs +10 -0
- package/dist/cjs/constants.cjs.map +1 -1
- package/dist/cjs/constants.d.cts +2 -0
- package/dist/cjs/debug.cjs +5 -0
- package/dist/cjs/debug.cjs.map +1 -0
- package/dist/cjs/debug.d.cts +1 -0
- package/dist/cjs/{extractHtmlScripts.cjs → dev-server-plugin/extract-html-scripts.cjs} +1 -1
- package/dist/cjs/dev-server-plugin/extract-html-scripts.cjs.map +1 -0
- package/dist/cjs/{nitro/dev-server-plugin.cjs → dev-server-plugin/plugin.cjs} +2 -2
- package/dist/cjs/dev-server-plugin/plugin.cjs.map +1 -0
- package/dist/cjs/load-env-plugin/plugin.cjs +34 -0
- package/dist/cjs/load-env-plugin/plugin.cjs.map +1 -0
- package/dist/cjs/load-env-plugin/plugin.d.cts +3 -0
- package/dist/cjs/{build-sitemap.cjs → nitro-plugin/build-sitemap.cjs} +12 -10
- package/dist/cjs/nitro-plugin/build-sitemap.cjs.map +1 -0
- package/dist/cjs/{build-sitemap.d.cts → nitro-plugin/build-sitemap.d.cts} +2 -2
- package/dist/cjs/{nitro/nitro-plugin.cjs → nitro-plugin/plugin.cjs} +79 -65
- package/dist/cjs/nitro-plugin/plugin.cjs.map +1 -0
- package/dist/cjs/{prerender.cjs → nitro-plugin/prerender.cjs} +18 -14
- package/dist/cjs/nitro-plugin/prerender.cjs.map +1 -0
- package/dist/cjs/{prerender.d.cts → nitro-plugin/prerender.d.cts} +1 -1
- package/dist/cjs/nitro-plugin/queue.cjs.map +1 -0
- package/dist/cjs/plugin.cjs +50 -38
- package/dist/cjs/plugin.cjs.map +1 -1
- package/dist/cjs/plugin.d.cts +14 -2657
- package/dist/cjs/resolve-virtual-entries-plugin/plugin.cjs +66 -0
- package/dist/cjs/resolve-virtual-entries-plugin/plugin.cjs.map +1 -0
- package/dist/cjs/resolve-virtual-entries-plugin/plugin.d.cts +3 -0
- package/dist/cjs/schema.cjs +5 -5
- package/dist/cjs/schema.cjs.map +1 -1
- package/dist/cjs/schema.d.cts +32 -16
- package/dist/cjs/start-compiler-plugin.cjs +21 -19
- package/dist/cjs/start-compiler-plugin.cjs.map +1 -1
- package/dist/cjs/start-compiler-plugin.d.cts +1 -1
- package/dist/cjs/start-manifest-plugin/plugin.cjs +182 -0
- package/dist/cjs/start-manifest-plugin/plugin.cjs.map +1 -0
- package/dist/{esm/routesManifestPlugin.d.ts → cjs/start-manifest-plugin/plugin.d.cts} +1 -1
- package/dist/cjs/start-router-plugin/generator-plugins/routes-manifest-plugin.cjs +39 -0
- package/dist/cjs/start-router-plugin/generator-plugins/routes-manifest-plugin.cjs.map +1 -0
- package/dist/cjs/start-router-plugin/generator-plugins/routes-manifest-plugin.d.cts +6 -0
- package/dist/cjs/start-router-plugin/generator-plugins/server-routes-plugin.cjs +121 -0
- package/dist/cjs/start-router-plugin/generator-plugins/server-routes-plugin.cjs.map +1 -0
- package/dist/cjs/start-router-plugin/generator-plugins/server-routes-plugin.d.cts +2 -0
- package/dist/cjs/start-router-plugin/plugin.cjs +21 -0
- package/dist/cjs/start-router-plugin/plugin.cjs.map +1 -0
- package/dist/cjs/start-router-plugin/plugin.d.cts +3 -0
- package/dist/cjs/start-router-plugin/route-tree-client-plugin.cjs +72 -0
- package/dist/cjs/start-router-plugin/route-tree-client-plugin.cjs.map +1 -0
- package/dist/cjs/start-router-plugin/route-tree-client-plugin.d.cts +6 -0
- package/dist/cjs/start-router-plugin/virtual-route-tree-plugin.cjs +30 -0
- package/dist/cjs/start-router-plugin/virtual-route-tree-plugin.cjs.map +1 -0
- package/dist/cjs/start-router-plugin/virtual-route-tree-plugin.d.cts +4 -0
- package/dist/cjs/utils.cjs +11 -0
- package/dist/cjs/utils.cjs.map +1 -1
- package/dist/cjs/utils.d.cts +7 -0
- package/dist/esm/compilers.js +24 -10
- package/dist/esm/compilers.js.map +1 -1
- package/dist/esm/constants.d.ts +2 -0
- package/dist/esm/constants.js +10 -0
- package/dist/esm/constants.js.map +1 -1
- package/dist/esm/debug.d.ts +1 -0
- package/dist/esm/debug.js +5 -0
- package/dist/esm/debug.js.map +1 -0
- package/dist/esm/{extractHtmlScripts.js → dev-server-plugin/extract-html-scripts.js} +1 -1
- package/dist/esm/dev-server-plugin/extract-html-scripts.js.map +1 -0
- package/dist/esm/{nitro/dev-server-plugin.js → dev-server-plugin/plugin.js} +2 -2
- package/dist/esm/dev-server-plugin/plugin.js.map +1 -0
- package/dist/esm/load-env-plugin/plugin.d.ts +3 -0
- package/dist/esm/load-env-plugin/plugin.js +17 -0
- package/dist/esm/load-env-plugin/plugin.js.map +1 -0
- package/dist/esm/{build-sitemap.d.ts → nitro-plugin/build-sitemap.d.ts} +2 -2
- package/dist/esm/{build-sitemap.js → nitro-plugin/build-sitemap.js} +9 -7
- package/dist/esm/nitro-plugin/build-sitemap.js.map +1 -0
- package/dist/esm/nitro-plugin/plugin.js +181 -0
- package/dist/esm/nitro-plugin/plugin.js.map +1 -0
- package/dist/esm/{prerender.d.ts → nitro-plugin/prerender.d.ts} +1 -1
- package/dist/esm/{prerender.js → nitro-plugin/prerender.js} +15 -11
- package/dist/esm/nitro-plugin/prerender.js.map +1 -0
- package/dist/esm/nitro-plugin/queue.js.map +1 -0
- package/dist/esm/plugin.d.ts +14 -2657
- package/dist/esm/plugin.js +51 -39
- package/dist/esm/plugin.js.map +1 -1
- package/dist/esm/resolve-virtual-entries-plugin/plugin.d.ts +3 -0
- package/dist/esm/resolve-virtual-entries-plugin/plugin.js +49 -0
- package/dist/esm/resolve-virtual-entries-plugin/plugin.js.map +1 -0
- package/dist/esm/schema.d.ts +32 -16
- package/dist/esm/start-compiler-plugin.d.ts +1 -1
- package/dist/esm/start-compiler-plugin.js +21 -19
- package/dist/esm/start-compiler-plugin.js.map +1 -1
- package/dist/{cjs/routesManifestPlugin.d.cts → esm/start-manifest-plugin/plugin.d.ts} +1 -1
- package/dist/esm/start-manifest-plugin/plugin.js +182 -0
- package/dist/esm/start-manifest-plugin/plugin.js.map +1 -0
- package/dist/esm/start-router-plugin/generator-plugins/routes-manifest-plugin.d.ts +6 -0
- package/dist/esm/start-router-plugin/generator-plugins/routes-manifest-plugin.js +39 -0
- package/dist/esm/start-router-plugin/generator-plugins/routes-manifest-plugin.js.map +1 -0
- package/dist/esm/start-router-plugin/generator-plugins/server-routes-plugin.d.ts +2 -0
- package/dist/esm/start-router-plugin/generator-plugins/server-routes-plugin.js +121 -0
- package/dist/esm/start-router-plugin/generator-plugins/server-routes-plugin.js.map +1 -0
- package/dist/esm/start-router-plugin/plugin.d.ts +3 -0
- package/dist/esm/start-router-plugin/plugin.js +21 -0
- package/dist/esm/start-router-plugin/plugin.js.map +1 -0
- package/dist/esm/start-router-plugin/route-tree-client-plugin.d.ts +6 -0
- package/dist/esm/start-router-plugin/route-tree-client-plugin.js +55 -0
- package/dist/esm/start-router-plugin/route-tree-client-plugin.js.map +1 -0
- package/dist/esm/start-router-plugin/virtual-route-tree-plugin.d.ts +4 -0
- package/dist/esm/start-router-plugin/virtual-route-tree-plugin.js +30 -0
- package/dist/esm/start-router-plugin/virtual-route-tree-plugin.js.map +1 -0
- package/dist/esm/utils.d.ts +7 -0
- package/dist/esm/utils.js +11 -0
- package/dist/esm/utils.js.map +1 -1
- package/package.json +8 -7
- package/src/compilers.ts +31 -131
- package/src/constants.ts +10 -0
- package/src/debug.ts +3 -0
- package/src/{nitro/dev-server-plugin.ts → dev-server-plugin/plugin.ts} +11 -1
- package/src/global.d.ts +8 -0
- package/src/load-env-plugin/plugin.ts +17 -0
- package/src/{build-sitemap.ts → nitro-plugin/build-sitemap.ts} +11 -8
- package/src/nitro-plugin/plugin.ts +244 -0
- package/src/{prerender.ts → nitro-plugin/prerender.ts} +17 -13
- package/src/plugin.ts +63 -41
- package/src/resolve-virtual-entries-plugin/plugin.ts +63 -0
- package/src/start-compiler-plugin.ts +25 -25
- package/src/start-manifest-plugin/plugin.ts +249 -0
- package/src/start-router-plugin/generator-plugins/routes-manifest-plugin.ts +43 -0
- package/src/start-router-plugin/generator-plugins/server-routes-plugin.ts +138 -0
- package/src/start-router-plugin/plugin.ts +35 -0
- package/src/start-router-plugin/route-tree-client-plugin.ts +76 -0
- package/src/start-router-plugin/virtual-route-tree-plugin.ts +30 -0
- package/src/utils.ts +11 -0
- package/dist/cjs/build-sitemap.cjs.map +0 -1
- package/dist/cjs/extractHtmlScripts.cjs.map +0 -1
- package/dist/cjs/nitro/build-nitro.cjs +0 -18
- package/dist/cjs/nitro/build-nitro.cjs.map +0 -1
- package/dist/cjs/nitro/build-nitro.d.cts +0 -2
- package/dist/cjs/nitro/dev-server-plugin.cjs.map +0 -1
- package/dist/cjs/nitro/nitro-plugin.cjs.map +0 -1
- package/dist/cjs/prerender.cjs.map +0 -1
- package/dist/cjs/queue.cjs.map +0 -1
- package/dist/cjs/routesManifestPlugin.cjs +0 -168
- package/dist/cjs/routesManifestPlugin.cjs.map +0 -1
- package/dist/cjs/start-server-routes-plugin/config.d.cts +0 -49
- package/dist/cjs/start-server-routes-plugin/plugin.cjs +0 -613
- package/dist/cjs/start-server-routes-plugin/plugin.cjs.map +0 -1
- package/dist/cjs/start-server-routes-plugin/plugin.d.cts +0 -3
- package/dist/cjs/start-server-routes-plugin/template.cjs +0 -111
- package/dist/cjs/start-server-routes-plugin/template.cjs.map +0 -1
- package/dist/cjs/start-server-routes-plugin/template.d.cts +0 -34
- package/dist/esm/build-sitemap.js.map +0 -1
- package/dist/esm/extractHtmlScripts.js.map +0 -1
- package/dist/esm/nitro/build-nitro.d.ts +0 -2
- package/dist/esm/nitro/build-nitro.js +0 -18
- package/dist/esm/nitro/build-nitro.js.map +0 -1
- package/dist/esm/nitro/dev-server-plugin.js.map +0 -1
- package/dist/esm/nitro/nitro-plugin.js +0 -167
- package/dist/esm/nitro/nitro-plugin.js.map +0 -1
- package/dist/esm/prerender.js.map +0 -1
- package/dist/esm/queue.js.map +0 -1
- package/dist/esm/routesManifestPlugin.js +0 -168
- package/dist/esm/routesManifestPlugin.js.map +0 -1
- package/dist/esm/start-server-routes-plugin/config.d.ts +0 -49
- package/dist/esm/start-server-routes-plugin/plugin.d.ts +0 -3
- package/dist/esm/start-server-routes-plugin/plugin.js +0 -613
- package/dist/esm/start-server-routes-plugin/plugin.js.map +0 -1
- package/dist/esm/start-server-routes-plugin/template.d.ts +0 -34
- package/dist/esm/start-server-routes-plugin/template.js +0 -111
- package/dist/esm/start-server-routes-plugin/template.js.map +0 -1
- package/src/nitro/build-nitro.ts +0 -27
- package/src/nitro/nitro-plugin.ts +0 -195
- package/src/routesManifestPlugin.ts +0 -220
- package/src/start-server-routes-plugin/config.ts +0 -8
- package/src/start-server-routes-plugin/plugin.ts +0 -899
- package/src/start-server-routes-plugin/template.ts +0 -164
- /package/dist/cjs/{extractHtmlScripts.d.cts → dev-server-plugin/extract-html-scripts.d.cts} +0 -0
- /package/dist/cjs/{nitro/dev-server-plugin.d.cts → dev-server-plugin/plugin.d.cts} +0 -0
- /package/dist/cjs/{nitro/nitro-plugin.d.cts → nitro-plugin/plugin.d.cts} +0 -0
- /package/dist/cjs/{queue.cjs → nitro-plugin/queue.cjs} +0 -0
- /package/dist/cjs/{queue.d.cts → nitro-plugin/queue.d.cts} +0 -0
- /package/dist/esm/{extractHtmlScripts.d.ts → dev-server-plugin/extract-html-scripts.d.ts} +0 -0
- /package/dist/esm/{nitro/dev-server-plugin.d.ts → dev-server-plugin/plugin.d.ts} +0 -0
- /package/dist/esm/{nitro/nitro-plugin.d.ts → nitro-plugin/plugin.d.ts} +0 -0
- /package/dist/esm/{queue.d.ts → nitro-plugin/queue.d.ts} +0 -0
- /package/dist/esm/{queue.js → nitro-plugin/queue.js} +0 -0
- /package/src/{extractHtmlScripts.ts → dev-server-plugin/extract-html-scripts.ts} +0 -0
- /package/src/{queue.ts → nitro-plugin/queue.ts} +0 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tanstack/start-plugin-core",
|
|
3
|
-
"version": "1.121.0
|
|
3
|
+
"version": "1.121.0",
|
|
4
4
|
"description": "Modern and scalable routing for React applications",
|
|
5
5
|
"author": "Tanner Linsley",
|
|
6
6
|
"license": "MIT",
|
|
@@ -58,16 +58,17 @@
|
|
|
58
58
|
"babel-dead-code-elimination": "^1.0.9",
|
|
59
59
|
"cheerio": "^1.0.0",
|
|
60
60
|
"h3": "1.13.0",
|
|
61
|
-
"nitropack": "^2.11.
|
|
61
|
+
"nitropack": "^2.11.12",
|
|
62
62
|
"pathe": "^2.0.3",
|
|
63
63
|
"ufo": "^1.5.4",
|
|
64
64
|
"xmlbuilder2": "^3.1.1",
|
|
65
65
|
"zod": "^3.24.2",
|
|
66
|
-
"@tanstack/router-
|
|
67
|
-
"@tanstack/router-
|
|
68
|
-
"@tanstack/router-
|
|
69
|
-
"@tanstack/server-functions-plugin": "^1.121.0
|
|
70
|
-
"@tanstack/router-
|
|
66
|
+
"@tanstack/router-core": "^1.121.0",
|
|
67
|
+
"@tanstack/router-generator": "^1.121.0",
|
|
68
|
+
"@tanstack/router-plugin": "^1.121.0",
|
|
69
|
+
"@tanstack/server-functions-plugin": "^1.121.0",
|
|
70
|
+
"@tanstack/router-utils": "^1.121.0",
|
|
71
|
+
"@tanstack/start-server-core": "^1.121.0"
|
|
71
72
|
},
|
|
72
73
|
"devDependencies": {
|
|
73
74
|
"vite": "^6.0.0"
|
package/src/compilers.ts
CHANGED
|
@@ -25,17 +25,40 @@ export function compileStartOutputFactory(
|
|
|
25
25
|
Program: {
|
|
26
26
|
enter(programPath) {
|
|
27
27
|
const identifiers: {
|
|
28
|
+
createServerRoute: IdentifierConfig
|
|
28
29
|
createServerFileRoute: IdentifierConfig
|
|
29
30
|
createServerFn: IdentifierConfig
|
|
30
31
|
createMiddleware: IdentifierConfig
|
|
31
32
|
serverOnly: IdentifierConfig
|
|
32
33
|
clientOnly: IdentifierConfig
|
|
33
34
|
createIsomorphicFn: IdentifierConfig
|
|
35
|
+
createServerRootRoute: IdentifierConfig
|
|
34
36
|
} = {
|
|
37
|
+
createServerRootRoute: {
|
|
38
|
+
name: 'createServerRootRoute',
|
|
39
|
+
handleCallExpression:
|
|
40
|
+
handleCreateServerFileRouteCallExpressionFactory(
|
|
41
|
+
framework,
|
|
42
|
+
'createServerRootRoute',
|
|
43
|
+
),
|
|
44
|
+
paths: [],
|
|
45
|
+
},
|
|
46
|
+
createServerRoute: {
|
|
47
|
+
name: 'createServerRoute',
|
|
48
|
+
handleCallExpression:
|
|
49
|
+
handleCreateServerFileRouteCallExpressionFactory(
|
|
50
|
+
framework,
|
|
51
|
+
'createServerRoute',
|
|
52
|
+
),
|
|
53
|
+
paths: [],
|
|
54
|
+
},
|
|
35
55
|
createServerFileRoute: {
|
|
36
56
|
name: 'createServerFileRoute',
|
|
37
57
|
handleCallExpression:
|
|
38
|
-
handleCreateServerFileRouteCallExpressionFactory(
|
|
58
|
+
handleCreateServerFileRouteCallExpressionFactory(
|
|
59
|
+
framework,
|
|
60
|
+
'createServerFileRoute',
|
|
61
|
+
),
|
|
39
62
|
paths: [],
|
|
40
63
|
},
|
|
41
64
|
createServerFn: {
|
|
@@ -71,10 +94,7 @@ export function compileStartOutputFactory(
|
|
|
71
94
|
|
|
72
95
|
programPath.traverse({
|
|
73
96
|
ImportDeclaration: (path) => {
|
|
74
|
-
if (
|
|
75
|
-
path.node.source.value !== '@tanstack/react-start' &&
|
|
76
|
-
path.node.source.value !== '@tanstack/solid-start'
|
|
77
|
-
) {
|
|
97
|
+
if (path.node.source.value !== `@tanstack/${framework}-start`) {
|
|
78
98
|
return
|
|
79
99
|
}
|
|
80
100
|
|
|
@@ -169,6 +189,10 @@ export function compileStartOutputFactory(
|
|
|
169
189
|
|
|
170
190
|
function handleCreateServerFileRouteCallExpressionFactory(
|
|
171
191
|
factory: CompileStartFrameworkOptions,
|
|
192
|
+
method:
|
|
193
|
+
| 'createServerFileRoute'
|
|
194
|
+
| 'createServerRoute'
|
|
195
|
+
| 'createServerRootRoute',
|
|
172
196
|
) {
|
|
173
197
|
return function handleCreateServerFileRouteCallExpression(
|
|
174
198
|
path: babel.NodePath<t.CallExpression>,
|
|
@@ -184,95 +208,6 @@ function handleCreateServerFileRouteCallExpressionFactory(
|
|
|
184
208
|
|
|
185
209
|
const programPath = highestParent.parentPath as babel.NodePath<t.Program>
|
|
186
210
|
|
|
187
|
-
// // Find the root call expression and all of the methods that are called on it
|
|
188
|
-
// const rootCallExpression = getRootCallExpression(path)
|
|
189
|
-
|
|
190
|
-
// const callExpressionPaths = {
|
|
191
|
-
// validator: null as babel.NodePath<t.CallExpression> | null,
|
|
192
|
-
// middleware: null as babel.NodePath<t.CallExpression> | null,
|
|
193
|
-
// methods: null as babel.NodePath<t.CallExpression> | null,
|
|
194
|
-
// }
|
|
195
|
-
|
|
196
|
-
// const validMethods = Object.keys(callExpressionPaths)
|
|
197
|
-
|
|
198
|
-
// rootCallExpression.traverse({
|
|
199
|
-
// MemberExpression(memberExpressionPath) {
|
|
200
|
-
// if (t.isIdentifier(memberExpressionPath.node.property)) {
|
|
201
|
-
// const name = memberExpressionPath.node.property
|
|
202
|
-
// .name as keyof typeof callExpressionPaths
|
|
203
|
-
|
|
204
|
-
// if (
|
|
205
|
-
// validMethods.includes(name) &&
|
|
206
|
-
// memberExpressionPath.parentPath.isCallExpression()
|
|
207
|
-
// ) {
|
|
208
|
-
// callExpressionPaths[name] = memberExpressionPath.parentPath
|
|
209
|
-
// }
|
|
210
|
-
// }
|
|
211
|
-
// },
|
|
212
|
-
// })
|
|
213
|
-
|
|
214
|
-
// const manifest = { middleware: false, methods: {} as any }
|
|
215
|
-
|
|
216
|
-
// Object.entries(callExpressionPaths).forEach(([key, callPath]) => {
|
|
217
|
-
// if (callPath && t.isMemberExpression(callPath.node.callee)) {
|
|
218
|
-
// if (key === 'middleware') {
|
|
219
|
-
// manifest.middleware = true
|
|
220
|
-
// } else if (key === 'methods') {
|
|
221
|
-
// // Get the methods object from the methods call
|
|
222
|
-
// const methodsArg = callPath.node.arguments[0]
|
|
223
|
-
|
|
224
|
-
// // Handle the case where methods is a function that returns an object
|
|
225
|
-
// if (
|
|
226
|
-
// t.isArrowFunctionExpression(methodsArg) &&
|
|
227
|
-
// t.isObjectExpression(methodsArg.body)
|
|
228
|
-
// ) {
|
|
229
|
-
// methodsArg.body.properties.forEach((prop) => {
|
|
230
|
-
// if (t.isObjectProperty(prop) && t.isIdentifier(prop.key)) {
|
|
231
|
-
// const methodName = prop.key.name
|
|
232
|
-
// manifest.methods[methodName] = {
|
|
233
|
-
// middleware: false,
|
|
234
|
-
// }
|
|
235
|
-
|
|
236
|
-
// // Check if this method has a middleware
|
|
237
|
-
// if (t.isCallExpression(prop.value)) {
|
|
238
|
-
// const method = prop.value
|
|
239
|
-
// method.arguments.forEach((arg) => {
|
|
240
|
-
// if (t.isObjectExpression(arg)) {
|
|
241
|
-
// arg.properties.forEach((methodProp) => {
|
|
242
|
-
// if (
|
|
243
|
-
// t.isObjectProperty(methodProp) &&
|
|
244
|
-
// t.isIdentifier(methodProp.key)
|
|
245
|
-
// ) {
|
|
246
|
-
// if (methodProp.key.name === 'middleware') {
|
|
247
|
-
// manifest.methods[methodName].middleware = true
|
|
248
|
-
// }
|
|
249
|
-
// }
|
|
250
|
-
// })
|
|
251
|
-
// }
|
|
252
|
-
// })
|
|
253
|
-
// }
|
|
254
|
-
// }
|
|
255
|
-
// })
|
|
256
|
-
// }
|
|
257
|
-
// // Handle the case where methods is a direct object
|
|
258
|
-
// else if (t.isObjectExpression(methodsArg)) {
|
|
259
|
-
// methodsArg.properties.forEach((prop) => {
|
|
260
|
-
// if (t.isObjectProperty(prop) && t.isIdentifier(prop.key)) {
|
|
261
|
-
// const methodName = prop.key.name
|
|
262
|
-
// manifest.methods[methodName] = {
|
|
263
|
-
// middleware: false,
|
|
264
|
-
// }
|
|
265
|
-
// }
|
|
266
|
-
// })
|
|
267
|
-
// }
|
|
268
|
-
// }
|
|
269
|
-
|
|
270
|
-
// if (opts.env === 'client') {
|
|
271
|
-
// callPath.replaceWith(callPath.node.callee.object)
|
|
272
|
-
// }
|
|
273
|
-
// }
|
|
274
|
-
// })
|
|
275
|
-
|
|
276
211
|
// If we're on the client, remove the entire variable
|
|
277
212
|
if (opts.env === 'client') {
|
|
278
213
|
// console.debug('createServerFileRoute -> manifest:\n', manifest)
|
|
@@ -280,36 +215,6 @@ function handleCreateServerFileRouteCallExpressionFactory(
|
|
|
280
215
|
return
|
|
281
216
|
}
|
|
282
217
|
|
|
283
|
-
// path.replaceWith(
|
|
284
|
-
// t.callExpression(t.identifier('createServerFileRoute'), [
|
|
285
|
-
// t.identifier('undefined'),
|
|
286
|
-
// t.callExpression(
|
|
287
|
-
// t.memberExpression(t.identifier('Object'), t.identifier('assign')),
|
|
288
|
-
// [
|
|
289
|
-
// t.objectExpression(
|
|
290
|
-
// path.node.arguments
|
|
291
|
-
// .map((arg) => {
|
|
292
|
-
// if (t.isIdentifier(arg)) {
|
|
293
|
-
// return t.objectProperty(t.identifier(arg.name), arg)
|
|
294
|
-
// }
|
|
295
|
-
// // Handle other cases or return a default value if necessary
|
|
296
|
-
// return null // or throw an error, or handle accordingly
|
|
297
|
-
// })
|
|
298
|
-
// .filter(
|
|
299
|
-
// (property): property is t.ObjectProperty => property !== null,
|
|
300
|
-
// ),
|
|
301
|
-
// ),
|
|
302
|
-
// t.objectExpression([
|
|
303
|
-
// t.objectProperty(
|
|
304
|
-
// t.identifier('manifest'),
|
|
305
|
-
// t.valueToNode(manifest),
|
|
306
|
-
// ),
|
|
307
|
-
// ]),
|
|
308
|
-
// ],
|
|
309
|
-
// ),
|
|
310
|
-
// ]),
|
|
311
|
-
// )
|
|
312
|
-
|
|
313
218
|
let isCreateServerFileRouteImported = false as boolean
|
|
314
219
|
|
|
315
220
|
programPath.traverse({
|
|
@@ -321,7 +226,7 @@ function handleCreateServerFileRouteCallExpressionFactory(
|
|
|
321
226
|
return (
|
|
322
227
|
t.isImportSpecifier(specifier) &&
|
|
323
228
|
t.isIdentifier(specifier.imported) &&
|
|
324
|
-
specifier.imported.name ===
|
|
229
|
+
specifier.imported.name === method
|
|
325
230
|
)
|
|
326
231
|
})
|
|
327
232
|
}
|
|
@@ -330,12 +235,7 @@ function handleCreateServerFileRouteCallExpressionFactory(
|
|
|
330
235
|
|
|
331
236
|
if (!isCreateServerFileRouteImported) {
|
|
332
237
|
const importDeclaration = t.importDeclaration(
|
|
333
|
-
[
|
|
334
|
-
t.importSpecifier(
|
|
335
|
-
t.identifier('createServerFileRoute'),
|
|
336
|
-
t.identifier('createServerFileRoute'),
|
|
337
|
-
),
|
|
338
|
-
],
|
|
238
|
+
[t.importSpecifier(t.identifier(method), t.identifier(method))],
|
|
339
239
|
t.stringLiteral(PACKAGES.start),
|
|
340
240
|
)
|
|
341
241
|
programPath.node.body.unshift(importDeclaration)
|
package/src/constants.ts
CHANGED
|
@@ -1,6 +1,16 @@
|
|
|
1
|
+
import path from 'node:path'
|
|
2
|
+
|
|
1
3
|
export const VITE_ENVIRONMENT_NAMES = {
|
|
2
4
|
// 'ssr' is chosen as the name for the server environment to ensure backwards compatibility
|
|
3
5
|
// with vite plugins that are not compatible with the new vite environment API (e.g. tailwindcss)
|
|
4
6
|
server: 'ssr',
|
|
5
7
|
client: 'client',
|
|
6
8
|
} as const
|
|
9
|
+
|
|
10
|
+
export const CLIENT_DIST_DIR = path.join(
|
|
11
|
+
'.tanstack',
|
|
12
|
+
'start',
|
|
13
|
+
'build',
|
|
14
|
+
'client-dist',
|
|
15
|
+
)
|
|
16
|
+
export const SSR_ENTRY_FILE = 'ssr.mjs'
|
package/src/debug.ts
ADDED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { createEvent, getHeader, sendWebResponse } from 'h3'
|
|
2
2
|
import { isRunnableDevEnvironment } from 'vite'
|
|
3
|
-
import { extractHtmlScripts } from '../extractHtmlScripts'
|
|
4
3
|
import { VITE_ENVIRONMENT_NAMES } from '../constants'
|
|
4
|
+
import { extractHtmlScripts } from './extract-html-scripts'
|
|
5
5
|
import type { Connect, DevEnvironment, Plugin, ViteDevServer } from 'vite'
|
|
6
6
|
|
|
7
7
|
declare global {
|
|
@@ -29,8 +29,12 @@ export function devServerPlugin(): Plugin {
|
|
|
29
29
|
return () => {
|
|
30
30
|
remove_html_middlewares(viteDevServer.middlewares)
|
|
31
31
|
let cachedScripts: string | undefined
|
|
32
|
+
|
|
32
33
|
viteDevServer.middlewares.use(async (req, res) => {
|
|
34
|
+
// Create an H3Event to have it passed into the server entry
|
|
35
|
+
// i.e: event => defineEventHandler(event)
|
|
33
36
|
const event = createEvent(req, res)
|
|
37
|
+
|
|
34
38
|
const serverEnv = viteDevServer.environments[
|
|
35
39
|
VITE_ENVIRONMENT_NAMES.server
|
|
36
40
|
] as DevEnvironment | undefined
|
|
@@ -41,11 +45,14 @@ export function devServerPlugin(): Plugin {
|
|
|
41
45
|
`Server environment ${VITE_ENVIRONMENT_NAMES.server} not found`,
|
|
42
46
|
)
|
|
43
47
|
}
|
|
48
|
+
|
|
44
49
|
if (!isRunnableDevEnvironment(serverEnv)) {
|
|
45
50
|
throw new Error(
|
|
46
51
|
`Expected server environment ${VITE_ENVIRONMENT_NAMES.server} to be a RunnableDevEnvironment. This can be caused by multiple vite versions being installed in the project.`,
|
|
47
52
|
)
|
|
48
53
|
}
|
|
54
|
+
|
|
55
|
+
// Extract the scripts that Vite plugins would inject into the initial HTML
|
|
49
56
|
if (cachedScripts === undefined) {
|
|
50
57
|
const templateHtml = `<html><head></head><body></body></html>`
|
|
51
58
|
const transformedHtml = await viteDevServer.transformIndexHtml(
|
|
@@ -57,6 +64,9 @@ export function devServerPlugin(): Plugin {
|
|
|
57
64
|
.map((script) => script.content ?? '')
|
|
58
65
|
.join(';')
|
|
59
66
|
}
|
|
67
|
+
|
|
68
|
+
// Import and resolve the request by running the server entry point
|
|
69
|
+
// i.e export default defineEventHandler((event) => { ... })
|
|
60
70
|
const serverEntry = await serverEnv.runner.import(
|
|
61
71
|
'/~start/server-entry',
|
|
62
72
|
)
|
package/src/global.d.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import * as vite from 'vite'
|
|
2
|
+
import type { TanStackStartOutputConfig } from '../plugin'
|
|
3
|
+
|
|
4
|
+
export function loadEnvPlugin(
|
|
5
|
+
startOpts: TanStackStartOutputConfig,
|
|
6
|
+
): vite.Plugin {
|
|
7
|
+
return {
|
|
8
|
+
name: 'tanstack-vite-plugin-nitro-load-env',
|
|
9
|
+
enforce: 'pre',
|
|
10
|
+
config(userConfig, envConfig) {
|
|
11
|
+
Object.assign(
|
|
12
|
+
process.env,
|
|
13
|
+
vite.loadEnv(envConfig.mode, userConfig.root ?? startOpts.root, ''),
|
|
14
|
+
)
|
|
15
|
+
},
|
|
16
|
+
}
|
|
17
|
+
}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { writeFileSync } from 'node:fs'
|
|
2
2
|
import path from 'node:path'
|
|
3
3
|
import { create } from 'xmlbuilder2'
|
|
4
|
-
import
|
|
4
|
+
import { createLogger } from '../utils'
|
|
5
|
+
import type { TanStackStartOutputConfig } from '../plugin'
|
|
5
6
|
import type { XMLBuilder } from 'xmlbuilder2/lib/interfaces'
|
|
6
7
|
|
|
7
8
|
export type SitemapUrl = {
|
|
@@ -121,13 +122,15 @@ function jsonToXml(sitemapData: SitemapData): string {
|
|
|
121
122
|
return sitemap.end({ prettyPrint: true })
|
|
122
123
|
}
|
|
123
124
|
|
|
124
|
-
export
|
|
125
|
+
export function buildSitemap({
|
|
125
126
|
options,
|
|
126
127
|
publicDir,
|
|
127
128
|
}: {
|
|
128
129
|
options: TanStackStartOutputConfig
|
|
129
130
|
publicDir: string
|
|
130
131
|
}) {
|
|
132
|
+
const logger = createLogger('sitemap')
|
|
133
|
+
|
|
131
134
|
let sitemapOptions = options.sitemap
|
|
132
135
|
|
|
133
136
|
if (!sitemapOptions && options.pages.length) {
|
|
@@ -142,7 +145,7 @@ export async function buildSitemap({
|
|
|
142
145
|
|
|
143
146
|
if (!host) {
|
|
144
147
|
if (!options.sitemap) {
|
|
145
|
-
|
|
148
|
+
logger.info(
|
|
146
149
|
'Hint: Pages found, but no sitemap host has been set. To enable sitemap generation, set the `sitemap.host` option.',
|
|
147
150
|
)
|
|
148
151
|
return
|
|
@@ -159,11 +162,11 @@ export async function buildSitemap({
|
|
|
159
162
|
const { pages } = options
|
|
160
163
|
|
|
161
164
|
if (!pages.length) {
|
|
162
|
-
|
|
165
|
+
logger.info('No pages were found to build the sitemap. Skipping...')
|
|
163
166
|
return
|
|
164
167
|
}
|
|
165
168
|
|
|
166
|
-
|
|
169
|
+
logger.info('Building Sitemap...')
|
|
167
170
|
|
|
168
171
|
// Build the sitemap data
|
|
169
172
|
const sitemapData = buildSitemapJson(pages, host)
|
|
@@ -174,11 +177,11 @@ export async function buildSitemap({
|
|
|
174
177
|
|
|
175
178
|
try {
|
|
176
179
|
// Write XML sitemap
|
|
177
|
-
|
|
180
|
+
logger.info(`Writing sitemap XML at ${xmlOutputPath}`)
|
|
178
181
|
writeFileSync(xmlOutputPath, jsonToXml(sitemapData))
|
|
179
182
|
|
|
180
183
|
// Write pages data for runtime use
|
|
181
|
-
|
|
184
|
+
logger.info(`Writing pages data at ${pagesOutputPath}`)
|
|
182
185
|
writeFileSync(
|
|
183
186
|
pagesOutputPath,
|
|
184
187
|
JSON.stringify(
|
|
@@ -192,7 +195,7 @@ export async function buildSitemap({
|
|
|
192
195
|
),
|
|
193
196
|
)
|
|
194
197
|
} catch (e) {
|
|
195
|
-
|
|
198
|
+
logger.error(`Unable to write sitemap files`, e)
|
|
196
199
|
}
|
|
197
200
|
}
|
|
198
201
|
|
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
import path from 'node:path'
|
|
2
|
+
import { rmSync } from 'node:fs'
|
|
3
|
+
import { build, copyPublicAssets, createNitro, prepare } from 'nitropack'
|
|
4
|
+
import { dirname, resolve } from 'pathe'
|
|
5
|
+
import {
|
|
6
|
+
CLIENT_DIST_DIR,
|
|
7
|
+
SSR_ENTRY_FILE,
|
|
8
|
+
VITE_ENVIRONMENT_NAMES,
|
|
9
|
+
} from '../constants'
|
|
10
|
+
import { buildSitemap } from './build-sitemap'
|
|
11
|
+
import { prerender } from './prerender'
|
|
12
|
+
import type {
|
|
13
|
+
EnvironmentOptions,
|
|
14
|
+
PluginOption,
|
|
15
|
+
Rollup,
|
|
16
|
+
ViteBuilder,
|
|
17
|
+
} from 'vite'
|
|
18
|
+
import type { Nitro, NitroConfig } from 'nitropack'
|
|
19
|
+
import type { TanStackStartOutputConfig } from '../plugin'
|
|
20
|
+
|
|
21
|
+
export function nitroPlugin(
|
|
22
|
+
options: TanStackStartOutputConfig,
|
|
23
|
+
getSsrBundle: () => Rollup.OutputBundle,
|
|
24
|
+
): Array<PluginOption> {
|
|
25
|
+
const buildPreset =
|
|
26
|
+
process.env['START_TARGET'] ?? (options.target as string | undefined)
|
|
27
|
+
return [
|
|
28
|
+
{
|
|
29
|
+
name: 'tanstack-vite-plugin-nitro',
|
|
30
|
+
configEnvironment(name) {
|
|
31
|
+
if (name === VITE_ENVIRONMENT_NAMES.server) {
|
|
32
|
+
return {
|
|
33
|
+
build: {
|
|
34
|
+
commonjsOptions: {
|
|
35
|
+
include: [],
|
|
36
|
+
},
|
|
37
|
+
ssr: true,
|
|
38
|
+
sourcemap: true,
|
|
39
|
+
rollupOptions: {
|
|
40
|
+
input: '/~start/server-entry',
|
|
41
|
+
},
|
|
42
|
+
},
|
|
43
|
+
} satisfies EnvironmentOptions
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
return null
|
|
47
|
+
},
|
|
48
|
+
config() {
|
|
49
|
+
return {
|
|
50
|
+
builder: {
|
|
51
|
+
sharedPlugins: true,
|
|
52
|
+
async buildApp(builder) {
|
|
53
|
+
const client = builder.environments[VITE_ENVIRONMENT_NAMES.client]
|
|
54
|
+
const server = builder.environments[VITE_ENVIRONMENT_NAMES.server]
|
|
55
|
+
|
|
56
|
+
if (!client) {
|
|
57
|
+
throw new Error('Client environment not found')
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
if (!server) {
|
|
61
|
+
throw new Error('SSR environment not found')
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// Build the client bundle
|
|
65
|
+
// i.e client entry file with `hydrateRoot(...)`
|
|
66
|
+
const clientOutputDir = resolve(options.root, CLIENT_DIST_DIR)
|
|
67
|
+
rmSync(clientOutputDir, { recursive: true, force: true })
|
|
68
|
+
await builder.build(client)
|
|
69
|
+
|
|
70
|
+
// Build the SSR bundle
|
|
71
|
+
await builder.build(server)
|
|
72
|
+
|
|
73
|
+
const nitroConfig: NitroConfig = {
|
|
74
|
+
dev: false,
|
|
75
|
+
// TODO: do we need this? should this be made configurable?
|
|
76
|
+
compatibilityDate: '2024-11-19',
|
|
77
|
+
logLevel: 3,
|
|
78
|
+
preset: buildPreset,
|
|
79
|
+
baseURL: globalThis.TSS_APP_BASE,
|
|
80
|
+
publicAssets: [
|
|
81
|
+
{
|
|
82
|
+
dir: path.resolve(options.root, CLIENT_DIST_DIR),
|
|
83
|
+
baseURL: '/',
|
|
84
|
+
maxAge: 31536000, // 1 year
|
|
85
|
+
},
|
|
86
|
+
],
|
|
87
|
+
typescript: {
|
|
88
|
+
generateTsConfig: false,
|
|
89
|
+
},
|
|
90
|
+
prerender: undefined,
|
|
91
|
+
renderer: SSR_ENTRY_FILE,
|
|
92
|
+
plugins: [], // Nitro's plugins
|
|
93
|
+
appConfigFiles: [],
|
|
94
|
+
scanDirs: [],
|
|
95
|
+
imports: false, // unjs/unimport for global/magic imports
|
|
96
|
+
rollupConfig: {
|
|
97
|
+
plugins: [virtualBundlePlugin(getSsrBundle())],
|
|
98
|
+
},
|
|
99
|
+
virtual: {
|
|
100
|
+
// This is Nitro's way of defining virtual modules
|
|
101
|
+
// Should we define the ones for TanStack Start's here as well?
|
|
102
|
+
},
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
const nitro = await createNitro(nitroConfig)
|
|
106
|
+
|
|
107
|
+
await buildNitroApp(builder, nitro, options)
|
|
108
|
+
},
|
|
109
|
+
},
|
|
110
|
+
}
|
|
111
|
+
},
|
|
112
|
+
},
|
|
113
|
+
]
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* Correctly co-ordinates the nitro app build process to make sure that the
|
|
118
|
+
* app is built, while also correctly handling the prerendering and sitemap
|
|
119
|
+
* generation and including their outputs in the final build.
|
|
120
|
+
*/
|
|
121
|
+
async function buildNitroApp(
|
|
122
|
+
builder: ViteBuilder,
|
|
123
|
+
nitro: Nitro,
|
|
124
|
+
options: TanStackStartOutputConfig,
|
|
125
|
+
) {
|
|
126
|
+
// Cleans the public and server directories for a fresh build
|
|
127
|
+
// i.e the `.output/public` and `.output/server` directories
|
|
128
|
+
await prepare(nitro)
|
|
129
|
+
|
|
130
|
+
// Creates the `.output/public` directory and copies the public assets
|
|
131
|
+
await copyPublicAssets(nitro)
|
|
132
|
+
|
|
133
|
+
// If the user has not set a prerender option, we need to set it to true
|
|
134
|
+
// if the pages array is not empty and has sub options requiring for prerendering
|
|
135
|
+
if (options.prerender?.enabled !== false) {
|
|
136
|
+
options.prerender = {
|
|
137
|
+
...options.prerender,
|
|
138
|
+
enabled: options.pages.some((d) =>
|
|
139
|
+
typeof d === 'string' ? false : !!d.prerender?.enabled,
|
|
140
|
+
),
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
// Setup the options for prerendering the SPA shell (i.e `src/routes/__root.tsx`)
|
|
145
|
+
if (options.spa?.enabled) {
|
|
146
|
+
options.prerender = {
|
|
147
|
+
...options.prerender,
|
|
148
|
+
enabled: true,
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
const maskUrl = new URL(options.spa.maskPath, 'http://localhost')
|
|
152
|
+
|
|
153
|
+
maskUrl.searchParams.set('__TSS_SHELL', 'true')
|
|
154
|
+
|
|
155
|
+
options.pages.push({
|
|
156
|
+
path: maskUrl.toString().replace('http://localhost', ''),
|
|
157
|
+
prerender: options.spa.prerender,
|
|
158
|
+
sitemap: {
|
|
159
|
+
exclude: true,
|
|
160
|
+
},
|
|
161
|
+
})
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
// Run the prerendering process
|
|
165
|
+
if (options.prerender.enabled) {
|
|
166
|
+
await prerender({
|
|
167
|
+
options,
|
|
168
|
+
nitro,
|
|
169
|
+
builder,
|
|
170
|
+
})
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
// Run the sitemap build process
|
|
174
|
+
if (options.pages.length) {
|
|
175
|
+
buildSitemap({
|
|
176
|
+
options,
|
|
177
|
+
publicDir: nitro.options.output.publicDir,
|
|
178
|
+
})
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
// Build the nitro app
|
|
182
|
+
// We only build the nitro app, once we've prepared the public assets,
|
|
183
|
+
// prerendered the pages and built the sitemap.
|
|
184
|
+
// If we try to do this earlier, then the public assets may not be available
|
|
185
|
+
// in the production build.
|
|
186
|
+
await build(nitro)
|
|
187
|
+
|
|
188
|
+
// Close the nitro instance
|
|
189
|
+
await nitro.close()
|
|
190
|
+
nitro.logger.success(
|
|
191
|
+
'Client and Server bundles for TanStack Start have been successfully built.',
|
|
192
|
+
)
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
type NitroRollupPluginOption = NonNullable<
|
|
196
|
+
NitroConfig['rollupConfig']
|
|
197
|
+
>['plugins']
|
|
198
|
+
|
|
199
|
+
function virtualBundlePlugin(
|
|
200
|
+
ssrBundle: Rollup.OutputBundle,
|
|
201
|
+
): NitroRollupPluginOption {
|
|
202
|
+
type VirtualModule = { code: string; map: string | null }
|
|
203
|
+
const _modules = new Map<string, VirtualModule>()
|
|
204
|
+
|
|
205
|
+
// group chunks and source maps
|
|
206
|
+
for (const [fileName, content] of Object.entries(ssrBundle)) {
|
|
207
|
+
if (content.type === 'chunk') {
|
|
208
|
+
const virtualModule: VirtualModule = {
|
|
209
|
+
code: content.code,
|
|
210
|
+
map: null,
|
|
211
|
+
}
|
|
212
|
+
const maybeMap = ssrBundle[`${fileName}.map`]
|
|
213
|
+
if (maybeMap && maybeMap.type === 'asset') {
|
|
214
|
+
virtualModule.map = maybeMap.source as string
|
|
215
|
+
}
|
|
216
|
+
_modules.set(fileName, virtualModule)
|
|
217
|
+
_modules.set(resolve(fileName), virtualModule)
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
return {
|
|
222
|
+
name: 'virtual-bundle',
|
|
223
|
+
resolveId(id, importer) {
|
|
224
|
+
if (_modules.has(id)) {
|
|
225
|
+
return resolve(id)
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
if (importer) {
|
|
229
|
+
const resolved = resolve(dirname(importer), id)
|
|
230
|
+
if (_modules.has(resolved)) {
|
|
231
|
+
return resolved
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
return null
|
|
235
|
+
},
|
|
236
|
+
load(id) {
|
|
237
|
+
const m = _modules.get(id)
|
|
238
|
+
if (!m) {
|
|
239
|
+
return null
|
|
240
|
+
}
|
|
241
|
+
return m
|
|
242
|
+
},
|
|
243
|
+
}
|
|
244
|
+
}
|