@tanstack/start-plugin-core 1.121.0-alpha.27 → 1.121.0-alpha.28

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.
Files changed (157) hide show
  1. package/dist/esm/{nitro-plugin/build-sitemap.d.ts → build-sitemap.d.ts} +3 -3
  2. package/dist/esm/{nitro-plugin/build-sitemap.js → build-sitemap.js} +19 -24
  3. package/dist/esm/build-sitemap.js.map +1 -0
  4. package/dist/esm/compilers.d.ts +1 -1
  5. package/dist/esm/compilers.js +6 -9
  6. package/dist/esm/compilers.js.map +1 -1
  7. package/dist/esm/constants.d.ts +6 -2
  8. package/dist/esm/constants.js +7 -10
  9. package/dist/esm/constants.js.map +1 -1
  10. package/dist/esm/debug.js.map +1 -1
  11. package/dist/esm/dev-server-plugin/extract-html-scripts.js.map +1 -1
  12. package/dist/esm/dev-server-plugin/plugin.d.ts +5 -5
  13. package/dist/esm/dev-server-plugin/plugin.js +118 -95
  14. package/dist/esm/dev-server-plugin/plugin.js.map +1 -1
  15. package/dist/esm/index.d.ts +1 -1
  16. package/dist/esm/index.js +0 -4
  17. package/dist/esm/index.js.map +1 -1
  18. package/dist/esm/load-env-plugin/plugin.d.ts +2 -3
  19. package/dist/esm/load-env-plugin/plugin.js +5 -8
  20. package/dist/esm/load-env-plugin/plugin.js.map +1 -1
  21. package/dist/esm/output-directory.d.ts +3 -0
  22. package/dist/esm/output-directory.js +14 -0
  23. package/dist/esm/output-directory.js.map +1 -0
  24. package/dist/esm/plugin.d.ts +11 -286
  25. package/dist/esm/plugin.js +171 -94
  26. package/dist/esm/plugin.js.map +1 -1
  27. package/dist/esm/post-server-build.d.ts +7 -0
  28. package/dist/esm/post-server-build.js +55 -0
  29. package/dist/esm/post-server-build.js.map +1 -0
  30. package/dist/esm/prerender.d.ts +11 -0
  31. package/dist/esm/{nitro-plugin/prerender.js → prerender.js} +88 -71
  32. package/dist/esm/prerender.js.map +1 -0
  33. package/dist/esm/{nitro-plugin/queue.js → queue.js} +7 -10
  34. package/dist/esm/queue.js.map +1 -0
  35. package/dist/esm/resolve-entries.d.ts +8 -0
  36. package/dist/esm/resolve-entries.js +37 -0
  37. package/dist/esm/resolve-entries.js.map +1 -0
  38. package/dist/esm/schema.d.ts +1334 -6585
  39. package/dist/esm/schema.js +54 -86
  40. package/dist/esm/schema.js.map +1 -1
  41. package/dist/esm/start-compiler-plugin.js +7 -3
  42. package/dist/esm/start-compiler-plugin.js.map +1 -1
  43. package/dist/esm/start-manifest-plugin/plugin.d.ts +6 -3
  44. package/dist/esm/start-manifest-plugin/plugin.js +95 -100
  45. package/dist/esm/start-manifest-plugin/plugin.js.map +1 -1
  46. package/dist/esm/start-router-plugin/generator-plugins/routes-manifest-plugin.js +4 -5
  47. package/dist/esm/start-router-plugin/generator-plugins/routes-manifest-plugin.js.map +1 -1
  48. package/dist/esm/start-router-plugin/generator-plugins/server-routes-plugin.js +2 -4
  49. package/dist/esm/start-router-plugin/generator-plugins/server-routes-plugin.js.map +1 -1
  50. package/dist/esm/start-router-plugin/plugin.d.ts +1 -1
  51. package/dist/esm/start-router-plugin/plugin.js +26 -2
  52. package/dist/esm/start-router-plugin/plugin.js.map +1 -1
  53. package/dist/esm/start-router-plugin/route-tree-client-plugin.js +2 -1
  54. package/dist/esm/start-router-plugin/route-tree-client-plugin.js.map +1 -1
  55. package/dist/esm/start-router-plugin/virtual-route-tree-plugin.d.ts +0 -1
  56. package/dist/esm/start-router-plugin/virtual-route-tree-plugin.js +3 -4
  57. package/dist/esm/start-router-plugin/virtual-route-tree-plugin.js.map +1 -1
  58. package/dist/esm/utils.js.map +1 -1
  59. package/package.json +14 -18
  60. package/src/{nitro-plugin/build-sitemap.ts → build-sitemap.ts} +8 -8
  61. package/src/compilers.ts +1 -1
  62. package/src/constants.ts +12 -9
  63. package/src/dev-server-plugin/plugin.ts +146 -124
  64. package/src/index.ts +1 -5
  65. package/src/load-env-plugin/plugin.ts +6 -11
  66. package/src/output-directory.ts +18 -0
  67. package/src/plugin.ts +227 -119
  68. package/src/post-server-build.ts +73 -0
  69. package/src/{nitro-plugin/prerender.ts → prerender.ts} +95 -82
  70. package/src/resolve-entries.ts +52 -0
  71. package/src/schema.ts +89 -121
  72. package/src/start-compiler-plugin.ts +4 -0
  73. package/src/start-manifest-plugin/plugin.ts +121 -139
  74. package/src/start-router-plugin/generator-plugins/routes-manifest-plugin.ts +2 -2
  75. package/src/start-router-plugin/plugin.ts +26 -2
  76. package/src/start-router-plugin/route-tree-client-plugin.ts +2 -1
  77. package/src/start-router-plugin/virtual-route-tree-plugin.ts +3 -4
  78. package/dist/cjs/compilers.cjs +0 -416
  79. package/dist/cjs/compilers.cjs.map +0 -1
  80. package/dist/cjs/compilers.d.cts +0 -21
  81. package/dist/cjs/constants.cjs +0 -20
  82. package/dist/cjs/constants.cjs.map +0 -1
  83. package/dist/cjs/constants.d.cts +0 -6
  84. package/dist/cjs/debug.cjs +0 -5
  85. package/dist/cjs/debug.cjs.map +0 -1
  86. package/dist/cjs/debug.d.cts +0 -1
  87. package/dist/cjs/dev-server-plugin/extract-html-scripts.cjs +0 -35
  88. package/dist/cjs/dev-server-plugin/extract-html-scripts.cjs.map +0 -1
  89. package/dist/cjs/dev-server-plugin/extract-html-scripts.d.cts +0 -4
  90. package/dist/cjs/dev-server-plugin/plugin.cjs +0 -136
  91. package/dist/cjs/dev-server-plugin/plugin.cjs.map +0 -1
  92. package/dist/cjs/dev-server-plugin/plugin.d.cts +0 -5
  93. package/dist/cjs/index.cjs +0 -11
  94. package/dist/cjs/index.cjs.map +0 -1
  95. package/dist/cjs/index.d.cts +0 -3
  96. package/dist/cjs/load-env-plugin/plugin.cjs +0 -34
  97. package/dist/cjs/load-env-plugin/plugin.cjs.map +0 -1
  98. package/dist/cjs/load-env-plugin/plugin.d.cts +0 -3
  99. package/dist/cjs/nitro-plugin/build-sitemap.cjs +0 -138
  100. package/dist/cjs/nitro-plugin/build-sitemap.cjs.map +0 -1
  101. package/dist/cjs/nitro-plugin/build-sitemap.d.cts +0 -31
  102. package/dist/cjs/nitro-plugin/plugin.cjs +0 -181
  103. package/dist/cjs/nitro-plugin/plugin.cjs.map +0 -1
  104. package/dist/cjs/nitro-plugin/plugin.d.cts +0 -3
  105. package/dist/cjs/nitro-plugin/prerender.cjs +0 -173
  106. package/dist/cjs/nitro-plugin/prerender.cjs.map +0 -1
  107. package/dist/cjs/nitro-plugin/prerender.d.cts +0 -8
  108. package/dist/cjs/nitro-plugin/queue.cjs +0 -131
  109. package/dist/cjs/nitro-plugin/queue.cjs.map +0 -1
  110. package/dist/cjs/nitro-plugin/queue.d.cts +0 -32
  111. package/dist/cjs/plugin.cjs +0 -197
  112. package/dist/cjs/plugin.cjs.map +0 -1
  113. package/dist/cjs/plugin.d.cts +0 -291
  114. package/dist/cjs/resolve-virtual-entries-plugin/plugin.cjs +0 -66
  115. package/dist/cjs/resolve-virtual-entries-plugin/plugin.cjs.map +0 -1
  116. package/dist/cjs/resolve-virtual-entries-plugin/plugin.d.cts +0 -3
  117. package/dist/cjs/schema.cjs +0 -157
  118. package/dist/cjs/schema.cjs.map +0 -1
  119. package/dist/cjs/schema.d.cts +0 -8779
  120. package/dist/cjs/start-compiler-plugin.cjs +0 -74
  121. package/dist/cjs/start-compiler-plugin.cjs.map +0 -1
  122. package/dist/cjs/start-compiler-plugin.d.cts +0 -13
  123. package/dist/cjs/start-manifest-plugin/plugin.cjs +0 -182
  124. package/dist/cjs/start-manifest-plugin/plugin.cjs.map +0 -1
  125. package/dist/cjs/start-manifest-plugin/plugin.d.cts +0 -3
  126. package/dist/cjs/start-router-plugin/generator-plugins/routes-manifest-plugin.cjs +0 -39
  127. package/dist/cjs/start-router-plugin/generator-plugins/routes-manifest-plugin.cjs.map +0 -1
  128. package/dist/cjs/start-router-plugin/generator-plugins/routes-manifest-plugin.d.cts +0 -6
  129. package/dist/cjs/start-router-plugin/generator-plugins/server-routes-plugin.cjs +0 -121
  130. package/dist/cjs/start-router-plugin/generator-plugins/server-routes-plugin.cjs.map +0 -1
  131. package/dist/cjs/start-router-plugin/generator-plugins/server-routes-plugin.d.cts +0 -2
  132. package/dist/cjs/start-router-plugin/plugin.cjs +0 -21
  133. package/dist/cjs/start-router-plugin/plugin.cjs.map +0 -1
  134. package/dist/cjs/start-router-plugin/plugin.d.cts +0 -3
  135. package/dist/cjs/start-router-plugin/route-tree-client-plugin.cjs +0 -72
  136. package/dist/cjs/start-router-plugin/route-tree-client-plugin.cjs.map +0 -1
  137. package/dist/cjs/start-router-plugin/route-tree-client-plugin.d.cts +0 -6
  138. package/dist/cjs/start-router-plugin/virtual-route-tree-plugin.cjs +0 -30
  139. package/dist/cjs/start-router-plugin/virtual-route-tree-plugin.cjs.map +0 -1
  140. package/dist/cjs/start-router-plugin/virtual-route-tree-plugin.d.cts +0 -4
  141. package/dist/cjs/utils.cjs +0 -18
  142. package/dist/cjs/utils.cjs.map +0 -1
  143. package/dist/cjs/utils.d.cts +0 -8
  144. package/dist/esm/nitro-plugin/build-sitemap.js.map +0 -1
  145. package/dist/esm/nitro-plugin/plugin.d.ts +0 -3
  146. package/dist/esm/nitro-plugin/plugin.js +0 -181
  147. package/dist/esm/nitro-plugin/plugin.js.map +0 -1
  148. package/dist/esm/nitro-plugin/prerender.d.ts +0 -8
  149. package/dist/esm/nitro-plugin/prerender.js.map +0 -1
  150. package/dist/esm/nitro-plugin/queue.js.map +0 -1
  151. package/dist/esm/resolve-virtual-entries-plugin/plugin.d.ts +0 -3
  152. package/dist/esm/resolve-virtual-entries-plugin/plugin.js +0 -49
  153. package/dist/esm/resolve-virtual-entries-plugin/plugin.js.map +0 -1
  154. package/src/nitro-plugin/plugin.ts +0 -244
  155. package/src/resolve-virtual-entries-plugin/plugin.ts +0 -63
  156. /package/dist/esm/{nitro-plugin/queue.d.ts → queue.d.ts} +0 -0
  157. /package/src/{nitro-plugin/queue.ts → queue.ts} +0 -0
@@ -1,244 +0,0 @@
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
- }
@@ -1,63 +0,0 @@
1
- import path from 'node:path'
2
- import * as vite from 'vite'
3
- import type {
4
- TanStackStartOutputConfig,
5
- TanStackStartVitePluginCoreOptions,
6
- } from '../plugin'
7
-
8
- export function resolveVirtualEntriesPlugin(
9
- opts: TanStackStartVitePluginCoreOptions,
10
- startConfig: TanStackStartOutputConfig,
11
- ): vite.Plugin {
12
- let resolvedConfig: vite.ResolvedConfig
13
-
14
- const modules = new Set<string>([
15
- '/~start/server-entry',
16
- '/~start/default-server-entry',
17
- '/~start/default-client-entry',
18
- ])
19
-
20
- return {
21
- name: 'tanstack-start-core:resolve-virtual-entries',
22
- configResolved(config) {
23
- resolvedConfig = config
24
- },
25
- resolveId(id) {
26
- if (modules.has(id)) {
27
- return `${id}.tsx`
28
- }
29
-
30
- return undefined
31
- },
32
- load(id) {
33
- const routerFilepath = vite.normalizePath(
34
- path.resolve(startConfig.root, startConfig.tsr.srcDirectory, 'router'),
35
- )
36
-
37
- if (id === '/~start/server-entry.tsx') {
38
- const ssrEntryFilepath = startConfig.serverEntryPath.startsWith(
39
- '/~start/default-server-entry',
40
- )
41
- ? startConfig.serverEntryPath
42
- : vite.normalizePath(
43
- path.resolve(resolvedConfig.root, startConfig.serverEntryPath),
44
- )
45
-
46
- return opts.getVirtualServerRootHandler({
47
- routerFilepath,
48
- serverEntryFilepath: ssrEntryFilepath,
49
- })
50
- }
51
-
52
- if (id === '/~start/default-client-entry.tsx') {
53
- return opts.getVirtualClientEntry({ routerFilepath })
54
- }
55
-
56
- if (id === '/~start/default-server-entry.tsx') {
57
- return opts.getVirtualServerEntry({ routerFilepath })
58
- }
59
-
60
- return undefined
61
- },
62
- }
63
- }
File without changes