@tanstack/start-plugin-core 1.131.10 → 1.132.0-alpha.1

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 (145) 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.js +7 -10
  5. package/dist/esm/compilers.js.map +1 -1
  6. package/dist/esm/constants.d.ts +6 -2
  7. package/dist/esm/constants.js +7 -10
  8. package/dist/esm/constants.js.map +1 -1
  9. package/dist/esm/debug.js.map +1 -1
  10. package/dist/esm/dev-server-plugin/extract-html-scripts.js.map +1 -1
  11. package/dist/esm/dev-server-plugin/plugin.d.ts +5 -5
  12. package/dist/esm/dev-server-plugin/plugin.js +117 -79
  13. package/dist/esm/dev-server-plugin/plugin.js.map +1 -1
  14. package/dist/esm/index.d.ts +2 -1
  15. package/dist/esm/index.js +2 -4
  16. package/dist/esm/load-env-plugin/plugin.d.ts +2 -3
  17. package/dist/esm/load-env-plugin/plugin.js +5 -8
  18. package/dist/esm/load-env-plugin/plugin.js.map +1 -1
  19. package/dist/esm/output-directory.d.ts +3 -0
  20. package/dist/esm/output-directory.js +14 -0
  21. package/dist/esm/output-directory.js.map +1 -0
  22. package/dist/esm/plugin.d.ts +6 -290
  23. package/dist/esm/plugin.js +135 -76
  24. package/dist/esm/plugin.js.map +1 -1
  25. package/dist/esm/post-server-build.d.ts +7 -0
  26. package/dist/esm/post-server-build.js +55 -0
  27. package/dist/esm/post-server-build.js.map +1 -0
  28. package/dist/esm/prerender.d.ts +11 -0
  29. package/dist/esm/{nitro-plugin/prerender.js → prerender.js} +85 -73
  30. package/dist/esm/prerender.js.map +1 -0
  31. package/dist/esm/{nitro-plugin/queue.js → queue.js} +7 -10
  32. package/dist/esm/queue.js.map +1 -0
  33. package/dist/esm/resolve-entries.d.ts +8 -0
  34. package/dist/esm/resolve-entries.js +37 -0
  35. package/dist/esm/resolve-entries.js.map +1 -0
  36. package/dist/esm/schema.d.ts +1369 -6719
  37. package/dist/esm/schema.js +52 -85
  38. package/dist/esm/schema.js.map +1 -1
  39. package/dist/esm/start-compiler-plugin.js +2 -2
  40. package/dist/esm/start-compiler-plugin.js.map +1 -1
  41. package/dist/esm/start-manifest-plugin/plugin.d.ts +1 -1
  42. package/dist/esm/start-manifest-plugin/plugin.js +8 -13
  43. package/dist/esm/start-manifest-plugin/plugin.js.map +1 -1
  44. package/dist/esm/start-router-plugin/generator-plugins/routes-manifest-plugin.js +2 -3
  45. package/dist/esm/start-router-plugin/generator-plugins/routes-manifest-plugin.js.map +1 -1
  46. package/dist/esm/start-router-plugin/generator-plugins/server-routes-plugin.js +2 -4
  47. package/dist/esm/start-router-plugin/generator-plugins/server-routes-plugin.js.map +1 -1
  48. package/dist/esm/start-router-plugin/plugin.js.map +1 -1
  49. package/dist/esm/start-router-plugin/route-tree-client-plugin.js.map +1 -1
  50. package/dist/esm/start-router-plugin/virtual-route-tree-plugin.js.map +1 -1
  51. package/dist/esm/utils.js.map +1 -1
  52. package/package.json +13 -18
  53. package/src/{nitro-plugin/build-sitemap.ts → build-sitemap.ts} +8 -8
  54. package/src/constants.ts +12 -9
  55. package/src/dev-server-plugin/plugin.ts +140 -99
  56. package/src/global.d.ts +0 -2
  57. package/src/index.ts +3 -5
  58. package/src/load-env-plugin/plugin.ts +6 -11
  59. package/src/output-directory.ts +18 -0
  60. package/src/plugin.ts +172 -98
  61. package/src/post-server-build.ts +73 -0
  62. package/src/{nitro-plugin/prerender.ts → prerender.ts} +93 -86
  63. package/src/resolve-entries.ts +52 -0
  64. package/src/schema.ts +88 -121
  65. package/src/start-manifest-plugin/plugin.ts +8 -14
  66. package/dist/cjs/compilers.cjs +0 -416
  67. package/dist/cjs/compilers.cjs.map +0 -1
  68. package/dist/cjs/compilers.d.cts +0 -21
  69. package/dist/cjs/constants.cjs +0 -20
  70. package/dist/cjs/constants.cjs.map +0 -1
  71. package/dist/cjs/constants.d.cts +0 -6
  72. package/dist/cjs/debug.cjs +0 -5
  73. package/dist/cjs/debug.cjs.map +0 -1
  74. package/dist/cjs/debug.d.cts +0 -1
  75. package/dist/cjs/dev-server-plugin/extract-html-scripts.cjs +0 -35
  76. package/dist/cjs/dev-server-plugin/extract-html-scripts.cjs.map +0 -1
  77. package/dist/cjs/dev-server-plugin/extract-html-scripts.d.cts +0 -4
  78. package/dist/cjs/dev-server-plugin/plugin.cjs +0 -121
  79. package/dist/cjs/dev-server-plugin/plugin.cjs.map +0 -1
  80. package/dist/cjs/dev-server-plugin/plugin.d.cts +0 -5
  81. package/dist/cjs/index.cjs +0 -11
  82. package/dist/cjs/index.cjs.map +0 -1
  83. package/dist/cjs/index.d.cts +0 -3
  84. package/dist/cjs/load-env-plugin/plugin.cjs +0 -34
  85. package/dist/cjs/load-env-plugin/plugin.cjs.map +0 -1
  86. package/dist/cjs/load-env-plugin/plugin.d.cts +0 -3
  87. package/dist/cjs/nitro-plugin/build-sitemap.cjs +0 -138
  88. package/dist/cjs/nitro-plugin/build-sitemap.cjs.map +0 -1
  89. package/dist/cjs/nitro-plugin/build-sitemap.d.cts +0 -31
  90. package/dist/cjs/nitro-plugin/plugin.cjs +0 -187
  91. package/dist/cjs/nitro-plugin/plugin.cjs.map +0 -1
  92. package/dist/cjs/nitro-plugin/plugin.d.cts +0 -3
  93. package/dist/cjs/nitro-plugin/prerender.cjs +0 -178
  94. package/dist/cjs/nitro-plugin/prerender.cjs.map +0 -1
  95. package/dist/cjs/nitro-plugin/prerender.d.cts +0 -8
  96. package/dist/cjs/nitro-plugin/queue.cjs +0 -131
  97. package/dist/cjs/nitro-plugin/queue.cjs.map +0 -1
  98. package/dist/cjs/nitro-plugin/queue.d.cts +0 -32
  99. package/dist/cjs/plugin.cjs +0 -227
  100. package/dist/cjs/plugin.cjs.map +0 -1
  101. package/dist/cjs/plugin.d.cts +0 -300
  102. package/dist/cjs/resolve-virtual-entries-plugin/plugin.cjs +0 -80
  103. package/dist/cjs/resolve-virtual-entries-plugin/plugin.cjs.map +0 -1
  104. package/dist/cjs/resolve-virtual-entries-plugin/plugin.d.cts +0 -3
  105. package/dist/cjs/schema.cjs +0 -158
  106. package/dist/cjs/schema.cjs.map +0 -1
  107. package/dist/cjs/schema.d.cts +0 -8878
  108. package/dist/cjs/start-compiler-plugin.cjs +0 -78
  109. package/dist/cjs/start-compiler-plugin.cjs.map +0 -1
  110. package/dist/cjs/start-compiler-plugin.d.cts +0 -13
  111. package/dist/cjs/start-manifest-plugin/plugin.cjs +0 -182
  112. package/dist/cjs/start-manifest-plugin/plugin.cjs.map +0 -1
  113. package/dist/cjs/start-manifest-plugin/plugin.d.cts +0 -6
  114. package/dist/cjs/start-router-plugin/generator-plugins/routes-manifest-plugin.cjs +0 -39
  115. package/dist/cjs/start-router-plugin/generator-plugins/routes-manifest-plugin.cjs.map +0 -1
  116. package/dist/cjs/start-router-plugin/generator-plugins/routes-manifest-plugin.d.cts +0 -6
  117. package/dist/cjs/start-router-plugin/generator-plugins/server-routes-plugin.cjs +0 -121
  118. package/dist/cjs/start-router-plugin/generator-plugins/server-routes-plugin.cjs.map +0 -1
  119. package/dist/cjs/start-router-plugin/generator-plugins/server-routes-plugin.d.cts +0 -2
  120. package/dist/cjs/start-router-plugin/plugin.cjs +0 -45
  121. package/dist/cjs/start-router-plugin/plugin.cjs.map +0 -1
  122. package/dist/cjs/start-router-plugin/plugin.d.cts +0 -3
  123. package/dist/cjs/start-router-plugin/route-tree-client-plugin.cjs +0 -73
  124. package/dist/cjs/start-router-plugin/route-tree-client-plugin.cjs.map +0 -1
  125. package/dist/cjs/start-router-plugin/route-tree-client-plugin.d.cts +0 -6
  126. package/dist/cjs/start-router-plugin/virtual-route-tree-plugin.cjs +0 -29
  127. package/dist/cjs/start-router-plugin/virtual-route-tree-plugin.cjs.map +0 -1
  128. package/dist/cjs/start-router-plugin/virtual-route-tree-plugin.d.cts +0 -3
  129. package/dist/cjs/utils.cjs +0 -18
  130. package/dist/cjs/utils.cjs.map +0 -1
  131. package/dist/cjs/utils.d.cts +0 -8
  132. package/dist/esm/nitro-plugin/build-sitemap.js.map +0 -1
  133. package/dist/esm/nitro-plugin/plugin.d.ts +0 -3
  134. package/dist/esm/nitro-plugin/plugin.js +0 -187
  135. package/dist/esm/nitro-plugin/plugin.js.map +0 -1
  136. package/dist/esm/nitro-plugin/prerender.d.ts +0 -8
  137. package/dist/esm/nitro-plugin/prerender.js.map +0 -1
  138. package/dist/esm/nitro-plugin/queue.js.map +0 -1
  139. package/dist/esm/resolve-virtual-entries-plugin/plugin.d.ts +0 -3
  140. package/dist/esm/resolve-virtual-entries-plugin/plugin.js +0 -63
  141. package/dist/esm/resolve-virtual-entries-plugin/plugin.js.map +0 -1
  142. package/src/nitro-plugin/plugin.ts +0 -252
  143. package/src/resolve-virtual-entries-plugin/plugin.ts +0 -77
  144. /package/dist/esm/{nitro-plugin/queue.d.ts → queue.d.ts} +0 -0
  145. /package/src/{nitro-plugin/queue.ts → queue.ts} +0 -0
@@ -1,252 +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 { HEADERS } from '@tanstack/start-server-core'
6
- import {
7
- CLIENT_DIST_DIR,
8
- SSR_ENTRY_FILE,
9
- VITE_ENVIRONMENT_NAMES,
10
- } from '../constants'
11
- import { buildSitemap } from './build-sitemap'
12
- import { prerender } from './prerender'
13
- import type {
14
- EnvironmentOptions,
15
- PluginOption,
16
- Rollup,
17
- ViteBuilder,
18
- } from 'vite'
19
- import type { Nitro, NitroConfig } from 'nitropack'
20
- import type { TanStackStartOutputConfig } from '../plugin'
21
-
22
- export function nitroPlugin(
23
- options: TanStackStartOutputConfig,
24
- getSsrBundle: () => Rollup.OutputBundle,
25
- ): Array<PluginOption> {
26
- const buildPreset =
27
- process.env['START_TARGET'] ?? (options.target as string | undefined)
28
- return [
29
- {
30
- name: 'tanstack-vite-plugin-nitro',
31
- configEnvironment(name) {
32
- if (name === VITE_ENVIRONMENT_NAMES.server) {
33
- return {
34
- build: {
35
- commonjsOptions: {
36
- include: [],
37
- },
38
- ssr: true,
39
- sourcemap: true,
40
- rollupOptions: {
41
- input: '/~start/server-entry',
42
- },
43
- },
44
- } satisfies EnvironmentOptions
45
- }
46
-
47
- return null
48
- },
49
- config() {
50
- return {
51
- builder: {
52
- sharedPlugins: true,
53
- async buildApp(builder) {
54
- const client = builder.environments[VITE_ENVIRONMENT_NAMES.client]
55
- const server = builder.environments[VITE_ENVIRONMENT_NAMES.server]
56
-
57
- if (!client) {
58
- throw new Error('Client environment not found')
59
- }
60
-
61
- if (!server) {
62
- throw new Error('SSR environment not found')
63
- }
64
-
65
- // Build the client bundle
66
- // i.e client entry file with `hydrateRoot(...)`
67
- const clientOutputDir = resolve(options.root, CLIENT_DIST_DIR)
68
- rmSync(clientOutputDir, { recursive: true, force: true })
69
- await builder.build(client)
70
-
71
- // Build the SSR bundle
72
- await builder.build(server)
73
-
74
- const nitroConfig: NitroConfig = {
75
- dev: false,
76
- // TODO: do we need this? should this be made configurable?
77
- compatibilityDate: '2024-11-19',
78
- logLevel: 3,
79
- preset: buildPreset,
80
- baseURL: globalThis.TSS_APP_BASE,
81
- publicAssets: [
82
- {
83
- dir: path.resolve(options.root, CLIENT_DIST_DIR),
84
- baseURL: '/',
85
- maxAge: 31536000, // 1 year
86
- },
87
- ],
88
- typescript: {
89
- generateTsConfig: false,
90
- },
91
- prerender: undefined,
92
- renderer: SSR_ENTRY_FILE,
93
- plugins: [], // Nitro's plugins
94
- appConfigFiles: [],
95
- scanDirs: [],
96
- imports: false, // unjs/unimport for global/magic imports
97
- rollupConfig: {
98
- plugins: [virtualBundlePlugin(getSsrBundle())],
99
- },
100
- virtual: {
101
- // This is Nitro's way of defining virtual modules
102
- // Should we define the ones for TanStack Start's here as well?
103
- },
104
- }
105
-
106
- const nitro = await createNitro(nitroConfig)
107
-
108
- await buildNitroApp(builder, nitro, options)
109
- },
110
- },
111
- }
112
- },
113
- },
114
- ]
115
- }
116
-
117
- /**
118
- * Correctly co-ordinates the nitro app build process to make sure that the
119
- * app is built, while also correctly handling the prerendering and sitemap
120
- * generation and including their outputs in the final build.
121
- */
122
- async function buildNitroApp(
123
- builder: ViteBuilder,
124
- nitro: Nitro,
125
- options: TanStackStartOutputConfig,
126
- ) {
127
- // Cleans the public and server directories for a fresh build
128
- // i.e the `.output/public` and `.output/server` directories
129
- await prepare(nitro)
130
-
131
- // Creates the `.output/public` directory and copies the public assets
132
- await copyPublicAssets(nitro)
133
-
134
- // If the user has not set a prerender option, we need to set it to true
135
- // if the pages array is not empty and has sub options requiring for prerendering
136
- // If the user has explicitly set prerender.enabled, this should be respected
137
- if (options.prerender?.enabled !== false) {
138
- options.prerender = {
139
- ...options.prerender,
140
- enabled:
141
- options.prerender?.enabled ??
142
- options.pages.some((d) =>
143
- typeof d === 'string' ? false : !!d.prerender?.enabled,
144
- ),
145
- }
146
- }
147
-
148
- // Setup the options for prerendering the SPA shell (i.e `src/routes/__root.tsx`)
149
- if (options.spa?.enabled) {
150
- options.prerender = {
151
- ...options.prerender,
152
- enabled: true,
153
- }
154
-
155
- const maskUrl = new URL(options.spa.maskPath, 'http://localhost')
156
-
157
- options.pages.push({
158
- path: maskUrl.toString().replace('http://localhost', ''),
159
- prerender: {
160
- ...options.spa.prerender,
161
- headers: {
162
- ...options.spa.prerender.headers,
163
- [HEADERS.TSS_SHELL]: 'true',
164
- },
165
- },
166
- sitemap: {
167
- exclude: true,
168
- },
169
- })
170
- }
171
-
172
- // Run the prerendering process
173
- if (options.prerender.enabled) {
174
- await prerender({
175
- options,
176
- nitro,
177
- builder,
178
- })
179
- }
180
-
181
- // Run the sitemap build process
182
- if (options.pages.length) {
183
- buildSitemap({
184
- options,
185
- publicDir: nitro.options.output.publicDir,
186
- })
187
- }
188
-
189
- // Build the nitro app
190
- // We only build the nitro app, once we've prepared the public assets,
191
- // prerendered the pages and built the sitemap.
192
- // If we try to do this earlier, then the public assets may not be available
193
- // in the production build.
194
- await build(nitro)
195
-
196
- // Close the nitro instance
197
- await nitro.close()
198
- nitro.logger.success(
199
- 'Client and Server bundles for TanStack Start have been successfully built.',
200
- )
201
- }
202
-
203
- type NitroRollupPluginOption = NonNullable<
204
- NitroConfig['rollupConfig']
205
- >['plugins']
206
-
207
- function virtualBundlePlugin(
208
- ssrBundle: Rollup.OutputBundle,
209
- ): NitroRollupPluginOption {
210
- type VirtualModule = { code: string; map: string | null }
211
- const _modules = new Map<string, VirtualModule>()
212
-
213
- // group chunks and source maps
214
- for (const [fileName, content] of Object.entries(ssrBundle)) {
215
- if (content.type === 'chunk') {
216
- const virtualModule: VirtualModule = {
217
- code: content.code,
218
- map: null,
219
- }
220
- const maybeMap = ssrBundle[`${fileName}.map`]
221
- if (maybeMap && maybeMap.type === 'asset') {
222
- virtualModule.map = maybeMap.source as string
223
- }
224
- _modules.set(fileName, virtualModule)
225
- _modules.set(resolve(fileName), virtualModule)
226
- }
227
- }
228
-
229
- return {
230
- name: 'virtual-bundle',
231
- resolveId(id, importer) {
232
- if (_modules.has(id)) {
233
- return resolve(id)
234
- }
235
-
236
- if (importer) {
237
- const resolved = resolve(dirname(importer), id)
238
- if (_modules.has(resolved)) {
239
- return resolved
240
- }
241
- }
242
- return null
243
- },
244
- load(id) {
245
- const m = _modules.get(id)
246
- if (!m) {
247
- return null
248
- }
249
- return m
250
- },
251
- }
252
- }
@@ -1,77 +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: {
26
- filter: {
27
- id: new RegExp([...modules].join('|')),
28
- },
29
- handler(id) {
30
- if (modules.has(id)) {
31
- return `${id}.tsx`
32
- }
33
-
34
- return undefined
35
- },
36
- },
37
- load: {
38
- filter: {
39
- id: new RegExp([...modules].map((m) => `${m}.tsx`).join('|')),
40
- },
41
- handler(id) {
42
- const routerFilepath = vite.normalizePath(
43
- path.resolve(
44
- startConfig.root,
45
- startConfig.tsr.srcDirectory,
46
- 'router',
47
- ),
48
- )
49
-
50
- if (id === '/~start/server-entry.tsx') {
51
- const ssrEntryFilepath = startConfig.serverEntryPath.startsWith(
52
- '/~start/default-server-entry',
53
- )
54
- ? startConfig.serverEntryPath
55
- : vite.normalizePath(
56
- path.resolve(resolvedConfig.root, startConfig.serverEntryPath),
57
- )
58
-
59
- return opts.getVirtualServerRootHandler({
60
- routerFilepath,
61
- serverEntryFilepath: ssrEntryFilepath,
62
- })
63
- }
64
-
65
- if (id === '/~start/default-client-entry.tsx') {
66
- return opts.getVirtualClientEntry({ routerFilepath })
67
- }
68
-
69
- if (id === '/~start/default-server-entry.tsx') {
70
- return opts.getVirtualServerEntry({ routerFilepath })
71
- }
72
-
73
- return undefined
74
- },
75
- },
76
- }
77
- }
File without changes