@tanstack/start-plugin-core 1.121.0-alpha.1 → 1.121.0-alpha.10
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/build-sitemap.cjs +138 -0
- package/dist/cjs/build-sitemap.cjs.map +1 -0
- package/dist/cjs/build-sitemap.d.cts +31 -0
- package/dist/cjs/index.cjs +2 -0
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/index.d.cts +1 -0
- package/dist/cjs/nitro/nitro-plugin.cjs +74 -39
- package/dist/cjs/nitro/nitro-plugin.cjs.map +1 -1
- package/dist/cjs/plugin.cjs +8 -4
- package/dist/cjs/plugin.cjs.map +1 -1
- package/dist/cjs/plugin.d.cts +88 -486
- package/dist/cjs/prerender.cjs +11 -16
- package/dist/cjs/prerender.cjs.map +1 -1
- package/dist/cjs/routesManifestPlugin.cjs +6 -3
- package/dist/cjs/routesManifestPlugin.cjs.map +1 -1
- package/dist/cjs/schema.cjs +6 -4
- package/dist/cjs/schema.cjs.map +1 -1
- package/dist/cjs/schema.d.cts +530 -1656
- package/dist/cjs/start-server-routes-plugin/plugin.cjs +2 -1
- package/dist/cjs/start-server-routes-plugin/plugin.cjs.map +1 -1
- package/dist/cjs/utils.cjs +18 -0
- package/dist/cjs/utils.cjs.map +1 -0
- package/dist/cjs/utils.d.cts +8 -0
- package/dist/esm/build-sitemap.d.ts +31 -0
- package/dist/esm/build-sitemap.js +138 -0
- package/dist/esm/build-sitemap.js.map +1 -0
- package/dist/esm/index.d.ts +1 -0
- package/dist/esm/index.js +3 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/nitro/nitro-plugin.js +58 -40
- package/dist/esm/nitro/nitro-plugin.js.map +1 -1
- package/dist/esm/plugin.d.ts +88 -486
- package/dist/esm/plugin.js +8 -4
- package/dist/esm/plugin.js.map +1 -1
- package/dist/esm/prerender.js +11 -16
- package/dist/esm/prerender.js.map +1 -1
- package/dist/esm/routesManifestPlugin.js +6 -3
- package/dist/esm/routesManifestPlugin.js.map +1 -1
- package/dist/esm/schema.d.ts +530 -1656
- package/dist/esm/schema.js +6 -4
- package/dist/esm/schema.js.map +1 -1
- package/dist/esm/start-server-routes-plugin/plugin.js +6 -5
- package/dist/esm/start-server-routes-plugin/plugin.js.map +1 -1
- package/dist/esm/utils.d.ts +8 -0
- package/dist/esm/utils.js +18 -0
- package/dist/esm/utils.js.map +1 -0
- package/package.json +6 -6
- package/src/build-sitemap.ts +213 -0
- package/src/index.ts +1 -0
- package/src/nitro/nitro-plugin.ts +98 -62
- package/src/plugin.ts +9 -4
- package/src/prerender.ts +11 -18
- package/src/routesManifestPlugin.ts +7 -3
- package/src/schema.ts +11 -9
- package/src/start-server-routes-plugin/plugin.ts +2 -1
- package/src/utils.ts +14 -0
- 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/build-sitemap.d.cts +0 -9
- 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/build-sitemap.d.ts +0 -9
- package/src/nitro/build-nitro.ts +0 -27
- package/src/nitro/build-sitemap.ts +0 -79
|
@@ -1,14 +1,20 @@
|
|
|
1
1
|
import path from 'node:path'
|
|
2
2
|
import { rmSync } from 'node:fs'
|
|
3
|
-
import
|
|
3
|
+
import * as fsp from 'node:fs/promises'
|
|
4
|
+
import { build, copyPublicAssets, createNitro, prepare } from 'nitropack'
|
|
4
5
|
import { dirname, resolve } from 'pathe'
|
|
5
6
|
import { clientDistDir, ssrEntryFile } from '../plugin'
|
|
6
7
|
import { prerender } from '../prerender'
|
|
7
8
|
import { VITE_ENVIRONMENT_NAMES } from '../constants'
|
|
9
|
+
import { buildSitemap } from '../build-sitemap'
|
|
8
10
|
import { devServerPlugin } from './dev-server-plugin'
|
|
9
|
-
import {
|
|
10
|
-
|
|
11
|
-
|
|
11
|
+
import type {
|
|
12
|
+
EnvironmentOptions,
|
|
13
|
+
PluginOption,
|
|
14
|
+
Rollup,
|
|
15
|
+
ViteBuilder,
|
|
16
|
+
} from 'vite'
|
|
17
|
+
import type { Nitro, NitroConfig } from 'nitropack'
|
|
12
18
|
import type { TanStackStartOutputConfig } from '../plugin'
|
|
13
19
|
|
|
14
20
|
export function nitroPlugin(
|
|
@@ -87,64 +93,7 @@ export function nitroPlugin(
|
|
|
87
93
|
|
|
88
94
|
const nitro = await createNitro(nitroConfig)
|
|
89
95
|
|
|
90
|
-
await
|
|
91
|
-
|
|
92
|
-
// If the user has not set a prerender option, we need to set it to true
|
|
93
|
-
// if the pages array is not empty and has sub options requiring for prerendering
|
|
94
|
-
if (options.prerender?.enabled !== false) {
|
|
95
|
-
options.prerender = {
|
|
96
|
-
...options.prerender,
|
|
97
|
-
enabled: options.pages.some((d) =>
|
|
98
|
-
typeof d === 'string' ? false : !!d.prerender?.enabled,
|
|
99
|
-
),
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
// Setup the options for prerendering the SPA shell (i.e `src/routes/__root.tsx`)
|
|
104
|
-
if (options.spa?.enabled) {
|
|
105
|
-
options.prerender = {
|
|
106
|
-
...options.prerender,
|
|
107
|
-
enabled: true,
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
const maskUrl = new URL(
|
|
111
|
-
options.spa.maskPath,
|
|
112
|
-
'http://localhost',
|
|
113
|
-
)
|
|
114
|
-
|
|
115
|
-
maskUrl.searchParams.set('__TSS_SHELL', 'true')
|
|
116
|
-
|
|
117
|
-
options.pages.push({
|
|
118
|
-
path: maskUrl.toString().replace('http://localhost', ''),
|
|
119
|
-
prerender: options.spa.prerender,
|
|
120
|
-
sitemap: {
|
|
121
|
-
exclude: true,
|
|
122
|
-
},
|
|
123
|
-
})
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
// Start prerendering!!!
|
|
127
|
-
if (options.prerender.enabled) {
|
|
128
|
-
await prerender({
|
|
129
|
-
options,
|
|
130
|
-
nitro,
|
|
131
|
-
builder,
|
|
132
|
-
})
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
// if (nitroConfig.prerender?.routes?.length && options.sitemap) {
|
|
136
|
-
// console.log('Building Sitemap...')
|
|
137
|
-
// // sitemap needs to be built after all directories are built
|
|
138
|
-
// await buildSitemap({
|
|
139
|
-
// host: options.sitemap.host,
|
|
140
|
-
// routes: nitroConfig.prerender.routes,
|
|
141
|
-
// outputDir: resolve(options.root, 'dist/public'),
|
|
142
|
-
// })
|
|
143
|
-
// }
|
|
144
|
-
|
|
145
|
-
// console.log(
|
|
146
|
-
// `\n\n✅ Client and server bundles successfully built.`,
|
|
147
|
-
// )
|
|
96
|
+
await buildNitroApp(builder, nitro, options)
|
|
148
97
|
},
|
|
149
98
|
},
|
|
150
99
|
}
|
|
@@ -153,6 +102,93 @@ export function nitroPlugin(
|
|
|
153
102
|
]
|
|
154
103
|
}
|
|
155
104
|
|
|
105
|
+
/**
|
|
106
|
+
* Correctly co-ordinates the nitro app build process to make sure that the
|
|
107
|
+
* app is built, while also correctly handling the prerendering and sitemap
|
|
108
|
+
* generation and including their outputs in the final build.
|
|
109
|
+
*/
|
|
110
|
+
async function buildNitroApp(
|
|
111
|
+
builder: ViteBuilder,
|
|
112
|
+
nitro: Nitro,
|
|
113
|
+
options: TanStackStartOutputConfig,
|
|
114
|
+
) {
|
|
115
|
+
// Cleans the public and server directories for a fresh build
|
|
116
|
+
// i.e the `.output/public` and `.output/server` directories
|
|
117
|
+
await prepare(nitro)
|
|
118
|
+
|
|
119
|
+
// Creates the `.output/public` directory and copies the public assets
|
|
120
|
+
await copyPublicAssets(nitro)
|
|
121
|
+
|
|
122
|
+
// If the user has not set a prerender option, we need to set it to true
|
|
123
|
+
// if the pages array is not empty and has sub options requiring for prerendering
|
|
124
|
+
if (options.prerender?.enabled !== false) {
|
|
125
|
+
options.prerender = {
|
|
126
|
+
...options.prerender,
|
|
127
|
+
enabled: options.pages.some((d) =>
|
|
128
|
+
typeof d === 'string' ? false : !!d.prerender?.enabled,
|
|
129
|
+
),
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
// Setup the options for prerendering the SPA shell (i.e `src/routes/__root.tsx`)
|
|
134
|
+
if (options.spa?.enabled) {
|
|
135
|
+
options.prerender = {
|
|
136
|
+
...options.prerender,
|
|
137
|
+
enabled: true,
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
const maskUrl = new URL(options.spa.maskPath, 'http://localhost')
|
|
141
|
+
|
|
142
|
+
maskUrl.searchParams.set('__TSS_SHELL', 'true')
|
|
143
|
+
|
|
144
|
+
options.pages.push({
|
|
145
|
+
path: maskUrl.toString().replace('http://localhost', ''),
|
|
146
|
+
prerender: options.spa.prerender,
|
|
147
|
+
sitemap: {
|
|
148
|
+
exclude: true,
|
|
149
|
+
},
|
|
150
|
+
})
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
// Run the prerendering process
|
|
154
|
+
if (options.prerender.enabled) {
|
|
155
|
+
await prerender({
|
|
156
|
+
options,
|
|
157
|
+
nitro,
|
|
158
|
+
builder,
|
|
159
|
+
})
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
// Run the sitemap build process
|
|
163
|
+
if (options.pages.length) {
|
|
164
|
+
buildSitemap({
|
|
165
|
+
options,
|
|
166
|
+
publicDir: nitro.options.output.publicDir,
|
|
167
|
+
})
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
// Build the nitro app
|
|
171
|
+
await build(nitro)
|
|
172
|
+
|
|
173
|
+
// Cleanup the vite public directory
|
|
174
|
+
// As a part of the build process, a `.vite/` directory
|
|
175
|
+
// is copied over from `.tanstack-start/build/client-dist/`
|
|
176
|
+
// to the nitro `publicDir` (e.g. `.output/public/`).
|
|
177
|
+
// This directory (and its contents including the vite client manifest)
|
|
178
|
+
// should not be included in the final build, so we remove it.
|
|
179
|
+
const nitroPublicDir = nitro.options.output.publicDir
|
|
180
|
+
const viteDir = path.resolve(nitroPublicDir, '.vite')
|
|
181
|
+
if (await fsp.stat(viteDir).catch(() => false)) {
|
|
182
|
+
await fsp.rm(viteDir, { recursive: true, force: true })
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
// Close the nitro instance
|
|
186
|
+
await nitro.close()
|
|
187
|
+
nitro.logger.success(
|
|
188
|
+
'Client and Server bundles for TanStack Start have been successfully built.',
|
|
189
|
+
)
|
|
190
|
+
}
|
|
191
|
+
|
|
156
192
|
function virtualBundlePlugin(ssrBundle: Rollup.OutputBundle): Rollup.Plugin {
|
|
157
193
|
type VirtualModule = { code: string; map: string | null }
|
|
158
194
|
const _modules = new Map<string, VirtualModule>()
|
package/src/plugin.ts
CHANGED
|
@@ -77,7 +77,10 @@ export function TanStackStartVitePluginCore(
|
|
|
77
77
|
)
|
|
78
78
|
? startConfig.clientEntryPath
|
|
79
79
|
: vite.normalizePath(
|
|
80
|
-
path.
|
|
80
|
+
path.join(
|
|
81
|
+
'/@fs',
|
|
82
|
+
path.resolve(startConfig.root, startConfig.clientEntryPath),
|
|
83
|
+
),
|
|
81
84
|
)
|
|
82
85
|
|
|
83
86
|
return entry
|
|
@@ -141,8 +144,8 @@ export function TanStackStartVitePluginCore(
|
|
|
141
144
|
'@tanstack/start-router-manifest',
|
|
142
145
|
'@tanstack/start-config',
|
|
143
146
|
'@tanstack/server-functions-plugin',
|
|
144
|
-
'tanstack
|
|
145
|
-
'tanstack
|
|
147
|
+
'tanstack-start-router-manifest:v',
|
|
148
|
+
'tanstack-start-server-fn-manifest:v',
|
|
146
149
|
'nitropack',
|
|
147
150
|
'@tanstack/**',
|
|
148
151
|
],
|
|
@@ -166,7 +169,9 @@ export function TanStackStartVitePluginCore(
|
|
|
166
169
|
TanStackServerFnPluginEnv({
|
|
167
170
|
// This is the ID that will be available to look up and import
|
|
168
171
|
// our server function manifest and resolve its module
|
|
169
|
-
manifestVirtualImportId: 'tanstack
|
|
172
|
+
manifestVirtualImportId: 'tanstack-start-server-fn-manifest:v',
|
|
173
|
+
manifestOutputFilename:
|
|
174
|
+
'.tanstack-start/build/server/server-functions-manifest.json',
|
|
170
175
|
client: {
|
|
171
176
|
getRuntimeCode: () =>
|
|
172
177
|
`import { createClientRpc } from '@tanstack/${opts.framework}-start/server-functions-client'`,
|
package/src/prerender.ts
CHANGED
|
@@ -5,8 +5,8 @@ import { getRollupConfig } from 'nitropack/rollup'
|
|
|
5
5
|
import { build as buildNitro, createNitro } from 'nitropack'
|
|
6
6
|
import { joinURL, withBase, withoutBase } from 'ufo'
|
|
7
7
|
import { Queue } from './queue'
|
|
8
|
-
import { buildNitroEnvironment } from './nitro/build-nitro'
|
|
9
8
|
import { VITE_ENVIRONMENT_NAMES } from './constants'
|
|
9
|
+
import { createLogger } from './utils'
|
|
10
10
|
import type { ViteBuilder } from 'vite'
|
|
11
11
|
import type { $Fetch, Nitro } from 'nitropack'
|
|
12
12
|
import type { TanStackStartOutputConfig } from './plugin'
|
|
@@ -21,7 +21,8 @@ export async function prerender({
|
|
|
21
21
|
nitro: Nitro
|
|
22
22
|
builder: ViteBuilder
|
|
23
23
|
}) {
|
|
24
|
-
|
|
24
|
+
const logger = createLogger('prerender')
|
|
25
|
+
logger.info('Prendering pages...')
|
|
25
26
|
|
|
26
27
|
// If prerender is enabled but no pages are provided, default to prerendering the root page
|
|
27
28
|
if (options.prerender?.enabled && !options.pages.length) {
|
|
@@ -72,7 +73,7 @@ export async function prerender({
|
|
|
72
73
|
},
|
|
73
74
|
}
|
|
74
75
|
|
|
75
|
-
await
|
|
76
|
+
await buildNitro(nodeNitro)
|
|
76
77
|
|
|
77
78
|
// Import renderer entry
|
|
78
79
|
const serverFilename =
|
|
@@ -93,14 +94,14 @@ export async function prerender({
|
|
|
93
94
|
// Crawl all pages
|
|
94
95
|
const pages = await prerenderPages()
|
|
95
96
|
|
|
96
|
-
|
|
97
|
+
logger.info(`Prerendered ${pages.length} pages:`)
|
|
97
98
|
pages.forEach((page) => {
|
|
98
|
-
|
|
99
|
+
logger.info(`- ${page}`)
|
|
99
100
|
})
|
|
100
101
|
|
|
101
102
|
// TODO: Write the prerendered pages to the output directory
|
|
102
103
|
} catch (error) {
|
|
103
|
-
|
|
104
|
+
logger.error(error)
|
|
104
105
|
} finally {
|
|
105
106
|
// Ensure server is always closed
|
|
106
107
|
// server.process.kill()
|
|
@@ -126,18 +127,10 @@ export async function prerender({
|
|
|
126
127
|
const seen = new Set<string>()
|
|
127
128
|
const retriesByPath = new Map<string, number>()
|
|
128
129
|
const concurrency = options.prerender?.concurrency ?? os.cpus().length
|
|
129
|
-
|
|
130
|
+
logger.info(`Concurrency: ${concurrency}`)
|
|
130
131
|
const queue = new Queue({ concurrency })
|
|
131
132
|
|
|
132
|
-
options.pages.forEach((
|
|
133
|
-
let page = _page as Page
|
|
134
|
-
|
|
135
|
-
if (typeof _page === 'string') {
|
|
136
|
-
page = { path: _page }
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
addCrawlPageTask(page)
|
|
140
|
-
})
|
|
133
|
+
options.pages.forEach((page) => addCrawlPageTask(page))
|
|
141
134
|
|
|
142
135
|
await queue.start()
|
|
143
136
|
|
|
@@ -168,7 +161,7 @@ export async function prerender({
|
|
|
168
161
|
|
|
169
162
|
// Add the task
|
|
170
163
|
queue.add(async () => {
|
|
171
|
-
|
|
164
|
+
logger.info(`Crawling: ${page.path}`)
|
|
172
165
|
const retries = retriesByPath.get(page.path) || 0
|
|
173
166
|
try {
|
|
174
167
|
// Fetch the route
|
|
@@ -236,7 +229,7 @@ export async function prerender({
|
|
|
236
229
|
}
|
|
237
230
|
} catch (error) {
|
|
238
231
|
if (retries < (prerenderOptions.retryCount ?? 0)) {
|
|
239
|
-
|
|
232
|
+
logger.warn(`Encountered error, retrying: ${page.path} in 500ms`)
|
|
240
233
|
await new Promise((resolve) =>
|
|
241
234
|
setTimeout(resolve, prerenderOptions.retryDelay),
|
|
242
235
|
)
|
|
@@ -2,6 +2,7 @@ import { readFileSync } from 'node:fs'
|
|
|
2
2
|
import path from 'node:path'
|
|
3
3
|
import { joinURL } from 'ufo'
|
|
4
4
|
import { rootRouteId } from '@tanstack/router-core'
|
|
5
|
+
import { resolveViteId } from './utils'
|
|
5
6
|
import type {
|
|
6
7
|
PluginOption,
|
|
7
8
|
ResolvedConfig,
|
|
@@ -16,6 +17,9 @@ export function startManifestPlugin(
|
|
|
16
17
|
): PluginOption {
|
|
17
18
|
let config: ResolvedConfig
|
|
18
19
|
|
|
20
|
+
const moduleId = 'tanstack-start-router-manifest:v'
|
|
21
|
+
const resolvedModuleId = resolveViteId(moduleId)
|
|
22
|
+
|
|
19
23
|
return {
|
|
20
24
|
name: 'tsr-routes-manifest',
|
|
21
25
|
enforce: 'pre',
|
|
@@ -27,13 +31,13 @@ export function startManifestPlugin(
|
|
|
27
31
|
// config = envConfig.
|
|
28
32
|
// },
|
|
29
33
|
resolveId(id) {
|
|
30
|
-
if (id ===
|
|
31
|
-
return
|
|
34
|
+
if (id === moduleId) {
|
|
35
|
+
return resolvedModuleId
|
|
32
36
|
}
|
|
33
37
|
return
|
|
34
38
|
},
|
|
35
39
|
load(id) {
|
|
36
|
-
if (id ===
|
|
40
|
+
if (id === resolvedModuleId) {
|
|
37
41
|
if (this.environment.config.consumer !== 'server') {
|
|
38
42
|
// this will ultimately fail the build if the plugin is used outside the server environment
|
|
39
43
|
// TODO: do we need special handling for `serve`?
|
package/src/schema.ts
CHANGED
|
@@ -4,9 +4,12 @@ import { z } from 'zod'
|
|
|
4
4
|
import { configSchema, getConfig } from '@tanstack/router-generator'
|
|
5
5
|
import type { NitroConfig } from 'nitropack'
|
|
6
6
|
|
|
7
|
-
const tsrConfig = configSchema
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
const tsrConfig = configSchema
|
|
8
|
+
.omit({ autoCodeSplitting: true })
|
|
9
|
+
.partial()
|
|
10
|
+
.extend({
|
|
11
|
+
srcDirectory: z.string().optional().default('src'),
|
|
12
|
+
})
|
|
10
13
|
|
|
11
14
|
export function createTanStackConfig<
|
|
12
15
|
TFrameworkPlugin extends Record<string, unknown>,
|
|
@@ -111,13 +114,12 @@ export function createTanStackStartOptionsSchema(
|
|
|
111
114
|
})
|
|
112
115
|
.optional()
|
|
113
116
|
.default({}),
|
|
114
|
-
pages: z
|
|
115
|
-
|
|
116
|
-
.
|
|
117
|
-
|
|
118
|
-
sitemap: pagePrerenderOptionsSchema
|
|
119
|
-
.extend({
|
|
117
|
+
pages: z.array(pageSchema).optional().default([]),
|
|
118
|
+
sitemap: z
|
|
119
|
+
.object({
|
|
120
|
+
enabled: z.boolean().optional().default(true),
|
|
120
121
|
host: z.string().optional(),
|
|
122
|
+
outputPath: z.string().optional().default('sitemap.xml'),
|
|
121
123
|
})
|
|
122
124
|
.optional(),
|
|
123
125
|
prerender: z
|
|
@@ -30,6 +30,7 @@ const setLock = (bool: boolean) => {
|
|
|
30
30
|
|
|
31
31
|
export function TanStackStartServerRoutesVite(config: Config): Plugin {
|
|
32
32
|
let ROOT: string = process.cwd()
|
|
33
|
+
const moduleId = 'tanstack-start-server-routes-manifest:v'
|
|
33
34
|
|
|
34
35
|
const getRoutesDirectoryPath = () => {
|
|
35
36
|
return isAbsolute(config.routesDirectory)
|
|
@@ -80,7 +81,7 @@ export function TanStackStartServerRoutesVite(config: Config): Plugin {
|
|
|
80
81
|
},
|
|
81
82
|
sharedDuringBuild: true,
|
|
82
83
|
resolveId(id) {
|
|
83
|
-
if (id ===
|
|
84
|
+
if (id === moduleId) {
|
|
84
85
|
const generatedRouteTreePath = getGeneratedRouteTreePath(ROOT)
|
|
85
86
|
return generatedRouteTreePath
|
|
86
87
|
}
|
package/src/utils.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export function resolveViteId(id: string) {
|
|
2
|
+
return `\0${id}`
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
export function createLogger(prefix: string) {
|
|
6
|
+
const label = `[${prefix}]`
|
|
7
|
+
return {
|
|
8
|
+
log: (...args: any) => console.log(label, ...args),
|
|
9
|
+
debug: (...args: any) => console.debug(label, ...args),
|
|
10
|
+
info: (...args: any) => console.info(label, ...args),
|
|
11
|
+
warn: (...args: any) => console.warn(label, ...args),
|
|
12
|
+
error: (...args: any) => console.error(label, ...args),
|
|
13
|
+
}
|
|
14
|
+
}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
-
const fs = require("node:fs");
|
|
4
|
-
const path = require("node:path");
|
|
5
|
-
const nitropack = require("nitropack");
|
|
6
|
-
async function buildNitroEnvironment(nitro, build) {
|
|
7
|
-
await nitropack.prepare(nitro);
|
|
8
|
-
await nitropack.copyPublicAssets(nitro);
|
|
9
|
-
await build();
|
|
10
|
-
const publicDir = nitro.options.output.publicDir;
|
|
11
|
-
const viteDir = path.resolve(publicDir, ".vite");
|
|
12
|
-
if (await fs.promises.stat(viteDir).catch(() => false)) {
|
|
13
|
-
await fs.promises.rm(viteDir, { recursive: true, force: true });
|
|
14
|
-
}
|
|
15
|
-
await nitro.close();
|
|
16
|
-
}
|
|
17
|
-
exports.buildNitroEnvironment = buildNitroEnvironment;
|
|
18
|
-
//# sourceMappingURL=build-nitro.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"build-nitro.cjs","sources":["../../../src/nitro/build-nitro.ts"],"sourcesContent":["import { promises as fsp } from 'node:fs'\nimport path from 'node:path'\nimport { copyPublicAssets, prepare } from 'nitropack'\nimport type { Nitro } from 'nitropack'\n\nexport async function buildNitroEnvironment(\n nitro: Nitro,\n build: () => Promise<any>,\n) {\n await prepare(nitro)\n await copyPublicAssets(nitro)\n await build()\n\n const publicDir = nitro.options.output.publicDir\n\n // As a part of the build process, the `.vite/` directory\n // is copied over from `.tanstack-start/build/client-dist/`\n // to the `publicDir` (e.g. `.output/public/`).\n // This directory (containing the vite manifest) should not be\n // included in the final build, so we remove it here.\n const viteDir = path.resolve(publicDir, '.vite')\n if (await fsp.stat(viteDir).catch(() => false)) {\n await fsp.rm(viteDir, { recursive: true, force: true })\n }\n\n await nitro.close()\n}\n"],"names":["prepare","copyPublicAssets","fsp"],"mappings":";;;;;AAKsB,eAAA,sBACpB,OACA,OACA;AACA,QAAMA,UAAAA,QAAQ,KAAK;AACnB,QAAMC,UAAAA,iBAAiB,KAAK;AAC5B,QAAM,MAAM;AAEN,QAAA,YAAY,MAAM,QAAQ,OAAO;AAOvC,QAAM,UAAU,KAAK,QAAQ,WAAW,OAAO;AAC3C,MAAA,MAAMC,YAAI,KAAK,OAAO,EAAE,MAAM,MAAM,KAAK,GAAG;AACxC,UAAAA,GAAA,SAAI,GAAG,SAAS,EAAE,WAAW,MAAM,OAAO,MAAM;AAAA,EAAA;AAGxD,QAAM,MAAM,MAAM;AACpB;;"}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
export type PagesJson = {
|
|
2
|
-
page: string;
|
|
3
|
-
lastMod: string;
|
|
4
|
-
};
|
|
5
|
-
export declare function buildSitemap({ host, routes, outputDir, }: {
|
|
6
|
-
host: string;
|
|
7
|
-
routes: Array<string | undefined> | (() => Promise<Array<string | undefined>>);
|
|
8
|
-
outputDir: string;
|
|
9
|
-
}): Promise<void>;
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { promises } from "node:fs";
|
|
2
|
-
import path from "node:path";
|
|
3
|
-
import { prepare, copyPublicAssets } from "nitropack";
|
|
4
|
-
async function buildNitroEnvironment(nitro, build) {
|
|
5
|
-
await prepare(nitro);
|
|
6
|
-
await copyPublicAssets(nitro);
|
|
7
|
-
await build();
|
|
8
|
-
const publicDir = nitro.options.output.publicDir;
|
|
9
|
-
const viteDir = path.resolve(publicDir, ".vite");
|
|
10
|
-
if (await promises.stat(viteDir).catch(() => false)) {
|
|
11
|
-
await promises.rm(viteDir, { recursive: true, force: true });
|
|
12
|
-
}
|
|
13
|
-
await nitro.close();
|
|
14
|
-
}
|
|
15
|
-
export {
|
|
16
|
-
buildNitroEnvironment
|
|
17
|
-
};
|
|
18
|
-
//# sourceMappingURL=build-nitro.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"build-nitro.js","sources":["../../../src/nitro/build-nitro.ts"],"sourcesContent":["import { promises as fsp } from 'node:fs'\nimport path from 'node:path'\nimport { copyPublicAssets, prepare } from 'nitropack'\nimport type { Nitro } from 'nitropack'\n\nexport async function buildNitroEnvironment(\n nitro: Nitro,\n build: () => Promise<any>,\n) {\n await prepare(nitro)\n await copyPublicAssets(nitro)\n await build()\n\n const publicDir = nitro.options.output.publicDir\n\n // As a part of the build process, the `.vite/` directory\n // is copied over from `.tanstack-start/build/client-dist/`\n // to the `publicDir` (e.g. `.output/public/`).\n // This directory (containing the vite manifest) should not be\n // included in the final build, so we remove it here.\n const viteDir = path.resolve(publicDir, '.vite')\n if (await fsp.stat(viteDir).catch(() => false)) {\n await fsp.rm(viteDir, { recursive: true, force: true })\n }\n\n await nitro.close()\n}\n"],"names":["fsp"],"mappings":";;;AAKsB,eAAA,sBACpB,OACA,OACA;AACA,QAAM,QAAQ,KAAK;AACnB,QAAM,iBAAiB,KAAK;AAC5B,QAAM,MAAM;AAEN,QAAA,YAAY,MAAM,QAAQ,OAAO;AAOvC,QAAM,UAAU,KAAK,QAAQ,WAAW,OAAO;AAC3C,MAAA,MAAMA,SAAI,KAAK,OAAO,EAAE,MAAM,MAAM,KAAK,GAAG;AACxC,UAAAA,SAAI,GAAG,SAAS,EAAE,WAAW,MAAM,OAAO,MAAM;AAAA,EAAA;AAGxD,QAAM,MAAM,MAAM;AACpB;"}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
export type PagesJson = {
|
|
2
|
-
page: string;
|
|
3
|
-
lastMod: string;
|
|
4
|
-
};
|
|
5
|
-
export declare function buildSitemap({ host, routes, outputDir, }: {
|
|
6
|
-
host: string;
|
|
7
|
-
routes: Array<string | undefined> | (() => Promise<Array<string | undefined>>);
|
|
8
|
-
outputDir: string;
|
|
9
|
-
}): Promise<void>;
|
package/src/nitro/build-nitro.ts
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { promises as fsp } from 'node:fs'
|
|
2
|
-
import path from 'node:path'
|
|
3
|
-
import { copyPublicAssets, prepare } from 'nitropack'
|
|
4
|
-
import type { Nitro } from 'nitropack'
|
|
5
|
-
|
|
6
|
-
export async function buildNitroEnvironment(
|
|
7
|
-
nitro: Nitro,
|
|
8
|
-
build: () => Promise<any>,
|
|
9
|
-
) {
|
|
10
|
-
await prepare(nitro)
|
|
11
|
-
await copyPublicAssets(nitro)
|
|
12
|
-
await build()
|
|
13
|
-
|
|
14
|
-
const publicDir = nitro.options.output.publicDir
|
|
15
|
-
|
|
16
|
-
// As a part of the build process, the `.vite/` directory
|
|
17
|
-
// is copied over from `.tanstack-start/build/client-dist/`
|
|
18
|
-
// to the `publicDir` (e.g. `.output/public/`).
|
|
19
|
-
// This directory (containing the vite manifest) should not be
|
|
20
|
-
// included in the final build, so we remove it here.
|
|
21
|
-
const viteDir = path.resolve(publicDir, '.vite')
|
|
22
|
-
if (await fsp.stat(viteDir).catch(() => false)) {
|
|
23
|
-
await fsp.rm(viteDir, { recursive: true, force: true })
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
await nitro.close()
|
|
27
|
-
}
|
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
import { writeFileSync } from 'node:fs'
|
|
2
|
-
import { resolve } from 'node:path'
|
|
3
|
-
import { create } from 'xmlbuilder2'
|
|
4
|
-
import type { XMLBuilder } from 'xmlbuilder2/lib/interfaces'
|
|
5
|
-
|
|
6
|
-
export type PagesJson = {
|
|
7
|
-
page: string
|
|
8
|
-
lastMod: string
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export async function buildSitemap({
|
|
12
|
-
host,
|
|
13
|
-
routes,
|
|
14
|
-
outputDir,
|
|
15
|
-
}: {
|
|
16
|
-
host: string
|
|
17
|
-
routes: Array<string | undefined> | (() => Promise<Array<string | undefined>>)
|
|
18
|
-
outputDir: string
|
|
19
|
-
}) {
|
|
20
|
-
const routeList: Array<string> = await optionHasRoutes(routes)
|
|
21
|
-
|
|
22
|
-
if (routeList.length) {
|
|
23
|
-
const slash = checkSlash(host)
|
|
24
|
-
const sitemapData: Array<PagesJson> = routeList.map((page: string) => ({
|
|
25
|
-
page: `${host}${slash}${page.replace(/^\/+/g, '')}`,
|
|
26
|
-
lastMod: new Date().toISOString().split('T')[0]!,
|
|
27
|
-
}))
|
|
28
|
-
|
|
29
|
-
const sitemap = createXml('urlset')
|
|
30
|
-
|
|
31
|
-
for (const item of sitemapData) {
|
|
32
|
-
const page = sitemap.ele('url')
|
|
33
|
-
page.ele('loc').txt(item.page)
|
|
34
|
-
page.ele('lastmod').txt(item.lastMod)
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
const mapPath = `${resolve(outputDir)}/sitemap.xml`
|
|
38
|
-
try {
|
|
39
|
-
console.log(`Writing sitemap at ${mapPath}`)
|
|
40
|
-
writeFileSync(mapPath, sitemap.end({ prettyPrint: true }))
|
|
41
|
-
} catch (e) {
|
|
42
|
-
console.error(`Unable to write file at ${mapPath}`, e)
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
function createXml(elementName: 'urlset' | 'sitemapindex'): XMLBuilder {
|
|
48
|
-
return create({ version: '1.0', encoding: 'UTF-8' })
|
|
49
|
-
.ele(elementName, {
|
|
50
|
-
xmlns: 'https://www.sitemaps.org/schemas/sitemap/0.9',
|
|
51
|
-
})
|
|
52
|
-
.com(`This file was automatically generated by Analog.`)
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
function checkSlash(host: string): string {
|
|
56
|
-
const finalChar = host.slice(-1)
|
|
57
|
-
return finalChar === '/' ? '' : '/'
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
async function optionHasRoutes(
|
|
61
|
-
routes:
|
|
62
|
-
| Array<string | undefined>
|
|
63
|
-
| (() => Promise<Array<string | undefined>>),
|
|
64
|
-
): Promise<Array<string>> {
|
|
65
|
-
let routeList: Array<string | undefined>
|
|
66
|
-
|
|
67
|
-
if (typeof routes === 'function') {
|
|
68
|
-
// returns an array or undefined
|
|
69
|
-
routeList = await routes()
|
|
70
|
-
} else if (Array.isArray(routes)) {
|
|
71
|
-
// returns an array of strings
|
|
72
|
-
routeList = routes
|
|
73
|
-
} else {
|
|
74
|
-
// default it to an empty of array
|
|
75
|
-
routeList = []
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
return routeList.filter(Boolean) as Array<string>
|
|
79
|
-
}
|