@analogjs/vite-plugin-nitro 3.0.0-alpha.8 → 3.0.0-alpha.9

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 (35) hide show
  1. package/package.json +3 -6
  2. package/src/index.d.ts +1 -1
  3. package/src/index.js +6 -2
  4. package/src/index.js.map +1 -1
  5. package/src/lib/build-server.js +97 -140
  6. package/src/lib/build-server.js.map +1 -1
  7. package/src/lib/build-sitemap.js +48 -60
  8. package/src/lib/build-sitemap.js.map +1 -1
  9. package/src/lib/build-ssr.js +16 -19
  10. package/src/lib/build-ssr.js.map +1 -1
  11. package/src/lib/hooks/post-rendering-hook.js +10 -6
  12. package/src/lib/hooks/post-rendering-hook.js.map +1 -1
  13. package/src/lib/plugins/dev-server-plugin.js +91 -101
  14. package/src/lib/plugins/dev-server-plugin.js.map +1 -1
  15. package/src/lib/plugins/page-endpoints.js +26 -46
  16. package/src/lib/plugins/page-endpoints.js.map +1 -1
  17. package/src/lib/utils/get-content-files.js +88 -97
  18. package/src/lib/utils/get-content-files.js.map +1 -1
  19. package/src/lib/utils/get-page-handlers.js +70 -84
  20. package/src/lib/utils/get-page-handlers.js.map +1 -1
  21. package/src/lib/utils/node-web-bridge.js +34 -45
  22. package/src/lib/utils/node-web-bridge.js.map +1 -1
  23. package/src/lib/utils/register-dev-middleware.js +41 -47
  24. package/src/lib/utils/register-dev-middleware.js.map +1 -1
  25. package/src/lib/utils/renderers.js +55 -51
  26. package/src/lib/utils/renderers.js.map +1 -1
  27. package/src/lib/utils/rolldown.js +9 -5
  28. package/src/lib/utils/rolldown.js.map +1 -1
  29. package/src/lib/vite-plugin-nitro.js +442 -701
  30. package/src/lib/vite-plugin-nitro.js.map +1 -1
  31. package/README.md +0 -125
  32. package/src/lib/options.js +0 -2
  33. package/src/lib/options.js.map +0 -1
  34. package/src/lib/utils/load-esm.js +0 -23
  35. package/src/lib/utils/load-esm.js.map +0 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@analogjs/vite-plugin-nitro",
3
- "version": "3.0.0-alpha.8",
3
+ "version": "3.0.0-alpha.9",
4
4
  "description": "A Vite plugin for adding a nitro API server",
5
5
  "type": "module",
6
6
  "author": "Brandon Roberts <robertsbt@gmail.com>",
@@ -56,8 +56,5 @@
56
56
  "publishConfig": {
57
57
  "access": "public",
58
58
  "provenance": true
59
- },
60
- "types": "./src/index.d.ts",
61
- "module": "./src/index.js",
62
- "main": "./src/index.js"
63
- }
59
+ }
60
+ }
package/src/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { nitro } from './lib/vite-plugin-nitro.js';
2
- export { Options, SitemapConfig, PrerenderRouteConfig, PrerenderContentDir, PrerenderContentFile, } from './lib/options.js';
2
+ export type { Options, SitemapConfig, PrerenderRouteConfig, PrerenderContentDir, PrerenderContentFile, } from './lib/options.js';
3
3
  declare module 'nitro/types' {
4
4
  interface NitroRouteConfig {
5
5
  ssr?: boolean;
package/src/index.js CHANGED
@@ -1,3 +1,7 @@
1
- import { nitro } from './lib/vite-plugin-nitro.js';
2
- export default nitro;
1
+ import { nitro } from "./lib/vite-plugin-nitro.js";
2
+ //#region packages/vite-plugin-nitro/src/index.ts
3
+ var src_default = nitro;
4
+ //#endregion
5
+ export { src_default as default };
6
+
3
7
  //# sourceMappingURL=index.js.map
package/src/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../packages/vite-plugin-nitro/src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,4BAA4B,CAAC;AAmBnD,eAAe,KAAK,CAAC"}
1
+ {"version":3,"file":"index.js","names":[],"sources":["../../../../packages/vite-plugin-nitro/src/index.ts"],"sourcesContent":["import { nitro } from './lib/vite-plugin-nitro.js';\nexport type {\n Options,\n SitemapConfig,\n PrerenderRouteConfig,\n PrerenderContentDir,\n PrerenderContentFile,\n} from './lib/options.js';\n\ndeclare module 'nitro/types' {\n interface NitroRouteConfig {\n ssr?: boolean;\n }\n\n interface NitroRouteRules {\n ssr?: boolean;\n }\n}\n\nexport default nitro;\n"],"mappings":";;AAmBA,IAAA,cAAe"}
@@ -1,152 +1,109 @@
1
- import { build, copyPublicAssets, createNitro, prepare, prerender, } from 'nitro/builder';
2
- import { existsSync, mkdirSync, readFileSync, rmSync, writeFileSync, } from 'node:fs';
3
- import { dirname, join } from 'node:path';
4
- import { addPostRenderingHooks } from './hooks/post-rendering-hook.js';
1
+ import { addPostRenderingHooks } from "./hooks/post-rendering-hook.js";
2
+ import { build, copyPublicAssets, createNitro, prepare, prerender } from "nitro/builder";
3
+ import { dirname, join } from "node:path";
4
+ import { existsSync, mkdirSync, readFileSync, rmSync, writeFileSync } from "node:fs";
5
+ //#region packages/vite-plugin-nitro/src/lib/build-server.ts
5
6
  /**
6
- * Ensures a minimal `tsconfig.json` exists in the SSR output directory.
7
- *
8
- * Nitro v3's `nitro:oxc` Rollup plugin uses OXC's resolver for every
9
- * file it transforms. OXC walks up the directory tree looking for a
10
- * `tsconfig.json` to load path aliases. The SSR output directory
11
- * (`dist/<app>/ssr/`) is outside the source tree, so no tsconfig
12
- * exists there. On Windows, OXC's upward directory walk also fails to
13
- * reach the project root's tsconfig due to path normalisation issues,
14
- * causing:
15
- *
16
- * [TSCONFIG_ERROR] Failed to load tsconfig for
17
- * '../../dist/apps/blog-app/ssr/main.server.js': Tsconfig not found
18
- *
19
- * Writing a minimal tsconfig satisfies the resolver without adding any
20
- * path aliases that would interfere with Nitro's own module resolution.
21
- */
7
+ * Ensures a minimal `tsconfig.json` exists in the SSR output directory.
8
+ *
9
+ * Nitro v3's `nitro:oxc` Rollup plugin uses OXC's resolver for every
10
+ * file it transforms. OXC walks up the directory tree looking for a
11
+ * `tsconfig.json` to load path aliases. The SSR output directory
12
+ * (`dist/<app>/ssr/`) is outside the source tree, so no tsconfig
13
+ * exists there. On Windows, OXC's upward directory walk also fails to
14
+ * reach the project root's tsconfig due to path normalisation issues,
15
+ * causing:
16
+ *
17
+ * [TSCONFIG_ERROR] Failed to load tsconfig for
18
+ * '../../dist/apps/blog-app/ssr/main.server.js': Tsconfig not found
19
+ *
20
+ * Writing a minimal tsconfig satisfies the resolver without adding any
21
+ * path aliases that would interfere with Nitro's own module resolution.
22
+ */
22
23
  function ensureSsrTsconfig(nitroConfig) {
23
- const ssrEntry = nitroConfig?.alias?.['#analog/ssr'];
24
- if (!ssrEntry) {
25
- return;
26
- }
27
- // The alias value is a normalized absolute path (forward slashes on
28
- // all platforms). Convert to a native path for dirname().
29
- const ssrDir = dirname(ssrEntry.replace(/\//g, join('a', 'b')[1]));
30
- const tsconfigPath = join(ssrDir, 'tsconfig.json');
31
- if (existsSync(tsconfigPath)) {
32
- return;
33
- }
34
- writeFileSync(tsconfigPath, JSON.stringify({ compilerOptions: { module: 'ESNext', moduleResolution: 'bundler' } }, null, 2), 'utf8');
24
+ const ssrEntry = nitroConfig?.alias?.["#analog/ssr"];
25
+ if (!ssrEntry) return;
26
+ const tsconfigPath = join(dirname(ssrEntry.replace(/\//g, join("a", "b")[1])), "tsconfig.json");
27
+ if (existsSync(tsconfigPath)) return;
28
+ writeFileSync(tsconfigPath, JSON.stringify({ compilerOptions: {
29
+ module: "ESNext",
30
+ moduleResolution: "bundler"
31
+ } }, null, 2), "utf8");
35
32
  }
36
- export function isVercelPreset(preset) {
37
- return !!preset?.toLowerCase().includes('vercel');
33
+ function isVercelPreset(preset) {
34
+ return !!preset?.toLowerCase().includes("vercel");
38
35
  }
39
36
  function getVercelBuildConfigPath(nitro) {
40
- return join(nitro.options.output.dir, 'config.json');
37
+ return join(nitro.options.output.dir, "config.json");
41
38
  }
42
39
  function assertValidVercelBuildConfig(nitro) {
43
- if (!isVercelPreset(nitro.options.preset)) {
44
- return;
45
- }
46
- const buildConfigPath = getVercelBuildConfigPath(nitro);
47
- if (!existsSync(buildConfigPath)) {
48
- throw new Error(`Nitro did not generate the expected Vercel build output config at "${buildConfigPath}".`);
49
- }
50
- const buildConfig = readFileSync(buildConfigPath, 'utf8').trim();
51
- if (!buildConfig) {
52
- throw new Error(`Nitro generated an empty Vercel build output config at "${buildConfigPath}".`);
53
- }
54
- try {
55
- JSON.parse(buildConfig);
56
- }
57
- catch (error) {
58
- const symptomError = new Error(`Nitro generated an invalid Vercel build output config at "${buildConfigPath}": ${error instanceof Error ? error.message : String(error)}`);
59
- symptomError.cause = error;
60
- throw symptomError;
61
- }
40
+ if (!isVercelPreset(nitro.options.preset)) return;
41
+ const buildConfigPath = getVercelBuildConfigPath(nitro);
42
+ if (!existsSync(buildConfigPath)) throw new Error(`Nitro did not generate the expected Vercel build output config at "${buildConfigPath}".`);
43
+ const buildConfig = readFileSync(buildConfigPath, "utf8").trim();
44
+ if (!buildConfig) throw new Error(`Nitro generated an empty Vercel build output config at "${buildConfigPath}".`);
45
+ try {
46
+ JSON.parse(buildConfig);
47
+ } catch (error) {
48
+ const symptomError = /* @__PURE__ */ new Error(`Nitro generated an invalid Vercel build output config at "${buildConfigPath}": ${error instanceof Error ? error.message : String(error)}`);
49
+ symptomError.cause = error;
50
+ throw symptomError;
51
+ }
62
52
  }
63
53
  function ensureVercelFunctionConfig(nitro) {
64
- if (!isVercelPreset(nitro.options.preset)) {
65
- return;
66
- }
67
- const serverDir = nitro.options.output.serverDir;
68
- const functionConfigPath = join(serverDir, '.vc-config.json');
69
- if (existsSync(functionConfigPath)) {
70
- return;
71
- }
72
- mkdirSync(serverDir, { recursive: true });
73
- writeFileSync(functionConfigPath, JSON.stringify({
74
- handler: 'index.mjs',
75
- launcherType: 'Nodejs',
76
- shouldAddHelpers: false,
77
- supportsResponseStreaming: true,
78
- ...nitro.options.vercel?.functions,
79
- }, null, 2), 'utf8');
54
+ if (!isVercelPreset(nitro.options.preset)) return;
55
+ const serverDir = nitro.options.output.serverDir;
56
+ const functionConfigPath = join(serverDir, ".vc-config.json");
57
+ if (existsSync(functionConfigPath)) return;
58
+ mkdirSync(serverDir, { recursive: true });
59
+ writeFileSync(functionConfigPath, JSON.stringify({
60
+ handler: "index.mjs",
61
+ launcherType: "Nodejs",
62
+ shouldAddHelpers: false,
63
+ supportsResponseStreaming: true,
64
+ ...nitro.options.vercel?.functions
65
+ }, null, 2), "utf8");
80
66
  }
81
- export async function buildServer(options, nitroConfig, routeSourceFiles) {
82
- // ── Ensure the SSR output has a tsconfig for OXC ─────────────────
83
- //
84
- // Must run before createNitro() so the tsconfig is on disk when the
85
- // nitro:oxc plugin initialises its resolver.
86
- ensureSsrTsconfig(nitroConfig);
87
- // ── Force Rollup as the server bundler ────────────────────────────
88
- //
89
- // Nitro v3 defaults to Rolldown when available. Rolldown is faster,
90
- // but its module resolver cannot resolve relative chunk imports
91
- // (e.g. `./assets/core-DTazUigR.js`) from a rebundled SSR entry on
92
- // Windows. The prerender build fails with:
93
- //
94
- // [RESOLVE_ERROR] Could not resolve './assets/core-DTazUigR.js'
95
- // in ../../dist/apps/blog-app/ssr/main.server.js
96
- //
97
- // This is a known Rolldown limitation with cross-directory relative
98
- // paths on Windows (backslash vs forward-slash normalisation).
99
- // Rollup handles these paths correctly on all platforms.
100
- //
101
- // The dev server already uses `builder: 'rollup'` for the same
102
- // reason. Default to Rollup here too until Rolldown's resolver
103
- // matures. The caller can still opt in to Rolldown explicitly via
104
- // nitroConfig.builder if their platform supports it.
105
- const nitro = await createNitro({
106
- dev: false,
107
- preset: process.env['BUILD_PRESET'],
108
- ...nitroConfig,
109
- builder: nitroConfig?.builder ?? 'rollup',
110
- });
111
- if (options?.prerender?.postRenderingHooks) {
112
- addPostRenderingHooks(nitro, options.prerender.postRenderingHooks);
113
- }
114
- await prepare(nitro);
115
- await copyPublicAssets(nitro);
116
- if (options?.ssr &&
117
- nitroConfig?.prerender?.routes &&
118
- (nitroConfig?.prerender?.routes.find((route) => route === '/') ||
119
- nitroConfig?.prerender?.routes?.length === 0)) {
120
- const indexFileExts = ['', '.br', '.gz'];
121
- indexFileExts.forEach((fileExt) => {
122
- // Remove the root index.html(.br|.gz) files
123
- const indexFilePath = join(nitroConfig?.output?.publicDir ?? '', `index.html${fileExt}`);
124
- rmSync(indexFilePath, { force: true });
125
- });
126
- }
127
- if (nitroConfig?.prerender?.routes &&
128
- nitroConfig?.prerender?.routes?.length > 0) {
129
- console.log(`Prerendering static pages...`);
130
- await prerender(nitro);
131
- }
132
- if (routeSourceFiles && Object.keys(routeSourceFiles).length > 0) {
133
- const publicDir = nitroConfig?.output?.publicDir;
134
- if (!publicDir) {
135
- throw new Error('Nitro public output directory is required to write route source files.');
136
- }
137
- for (const [route, content] of Object.entries(routeSourceFiles)) {
138
- const outputPath = join(publicDir, `${route}.md`);
139
- const outputDir = dirname(outputPath);
140
- mkdirSync(outputDir, { recursive: true });
141
- writeFileSync(outputPath, content, 'utf8');
142
- }
143
- }
144
- if (!options?.static) {
145
- console.log('Building Server...');
146
- await build(nitro);
147
- ensureVercelFunctionConfig(nitro);
148
- }
149
- await nitro.close();
150
- assertValidVercelBuildConfig(nitro);
67
+ async function buildServer(options, nitroConfig, routeSourceFiles) {
68
+ ensureSsrTsconfig(nitroConfig);
69
+ const nitro = await createNitro({
70
+ dev: false,
71
+ preset: process.env["BUILD_PRESET"],
72
+ ...nitroConfig,
73
+ builder: nitroConfig?.builder ?? "rollup"
74
+ });
75
+ if (options?.prerender?.postRenderingHooks) addPostRenderingHooks(nitro, options.prerender.postRenderingHooks);
76
+ await prepare(nitro);
77
+ await copyPublicAssets(nitro);
78
+ if (options?.ssr && nitroConfig?.prerender?.routes && (nitroConfig?.prerender?.routes.find((route) => route === "/") || nitroConfig?.prerender?.routes?.length === 0)) [
79
+ "",
80
+ ".br",
81
+ ".gz"
82
+ ].forEach((fileExt) => {
83
+ rmSync(join(nitroConfig?.output?.publicDir ?? "", `index.html${fileExt}`), { force: true });
84
+ });
85
+ if (nitroConfig?.prerender?.routes && nitroConfig?.prerender?.routes?.length > 0) {
86
+ console.log(`Prerendering static pages...`);
87
+ await prerender(nitro);
88
+ }
89
+ if (routeSourceFiles && Object.keys(routeSourceFiles).length > 0) {
90
+ const publicDir = nitroConfig?.output?.publicDir;
91
+ if (!publicDir) throw new Error("Nitro public output directory is required to write route source files.");
92
+ for (const [route, content] of Object.entries(routeSourceFiles)) {
93
+ const outputPath = join(publicDir, `${route}.md`);
94
+ mkdirSync(dirname(outputPath), { recursive: true });
95
+ writeFileSync(outputPath, content, "utf8");
96
+ }
97
+ }
98
+ if (!options?.static) {
99
+ console.log("Building Server...");
100
+ await build(nitro);
101
+ ensureVercelFunctionConfig(nitro);
102
+ }
103
+ await nitro.close();
104
+ assertValidVercelBuildConfig(nitro);
151
105
  }
106
+ //#endregion
107
+ export { buildServer, isVercelPreset };
108
+
152
109
  //# sourceMappingURL=build-server.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"build-server.js","sourceRoot":"","sources":["../../../../../packages/vite-plugin-nitro/src/lib/build-server.ts"],"names":[],"mappings":"AACA,OAAO,EACL,KAAK,EACL,gBAAgB,EAChB,WAAW,EACX,OAAO,EACP,SAAS,GACV,MAAM,eAAe,CAAC;AACvB,OAAO,EACL,UAAU,EACV,SAAS,EACT,YAAY,EACZ,MAAM,EACN,aAAa,GACd,MAAM,SAAS,CAAC;AACjB,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAG1C,OAAO,EAAE,qBAAqB,EAAE,MAAM,gCAAgC,CAAC;AAEvE;;;;;;;;;;;;;;;;GAgBG;AACH,SAAS,iBAAiB,CAAC,WAAoC;IAC7D,MAAM,QAAQ,GAAG,WAAW,EAAE,KAAK,EAAE,CAAC,aAAa,CAAC,CAAC;IACrD,IAAI,CAAC,QAAQ,EAAE,CAAC;QACd,OAAO;IACT,CAAC;IAED,oEAAoE;IACpE,0DAA0D;IAC1D,MAAM,MAAM,GAAG,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAC,KAAK,EAAE,IAAI,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC,C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],"sourcesContent":["import type { NitroConfig } from 'nitro/types';\nimport {\n build,\n copyPublicAssets,\n createNitro,\n prepare,\n prerender,\n} from 'nitro/builder';\nimport {\n existsSync,\n mkdirSync,\n readFileSync,\n rmSync,\n writeFileSync,\n} from 'node:fs';\nimport { dirname, join } from 'node:path';\n\nimport { Options } from './options.js';\nimport { addPostRenderingHooks } from './hooks/post-rendering-hook.js';\n\n/**\n * Ensures a minimal `tsconfig.json` exists in the SSR output directory.\n *\n * Nitro v3's `nitro:oxc` Rollup plugin uses OXC's resolver for every\n * file it transforms. OXC walks up the directory tree looking for a\n * `tsconfig.json` to load path aliases. The SSR output directory\n * (`dist/<app>/ssr/`) is outside the source tree, so no tsconfig\n * exists there. On Windows, OXC's upward directory walk also fails to\n * reach the project root's tsconfig due to path normalisation issues,\n * causing:\n *\n * [TSCONFIG_ERROR] Failed to load tsconfig for\n * '../../dist/apps/blog-app/ssr/main.server.js': Tsconfig not found\n *\n * Writing a minimal tsconfig satisfies the resolver without adding any\n * path aliases that would interfere with Nitro's own module resolution.\n */\nfunction ensureSsrTsconfig(nitroConfig: NitroConfig | undefined) {\n const ssrEntry = nitroConfig?.alias?.['#analog/ssr'];\n if (!ssrEntry) {\n return;\n }\n\n // The alias value is a normalized absolute path (forward slashes on\n // all platforms). Convert to a native path for dirname().\n const ssrDir = dirname(ssrEntry.replace(/\\//g, join('a', 'b')[1]));\n const tsconfigPath = join(ssrDir, 'tsconfig.json');\n\n if (existsSync(tsconfigPath)) {\n return;\n }\n\n writeFileSync(\n tsconfigPath,\n JSON.stringify(\n { compilerOptions: { module: 'ESNext', moduleResolution: 'bundler' } },\n null,\n 2,\n ),\n 'utf8',\n );\n}\n\nexport function isVercelPreset(preset: string | undefined): boolean {\n return !!preset?.toLowerCase().includes('vercel');\n}\n\nfunction getVercelBuildConfigPath(\n nitro: Awaited<ReturnType<typeof createNitro>>,\n) {\n return join(nitro.options.output.dir, 'config.json');\n}\n\nfunction assertValidVercelBuildConfig(\n nitro: Awaited<ReturnType<typeof createNitro>>,\n) {\n if (!isVercelPreset(nitro.options.preset)) {\n return;\n }\n\n const buildConfigPath = getVercelBuildConfigPath(nitro);\n if (!existsSync(buildConfigPath)) {\n throw new Error(\n `Nitro did not generate the expected Vercel build output config at \"${buildConfigPath}\".`,\n );\n }\n\n const buildConfig = readFileSync(buildConfigPath, 'utf8').trim();\n if (!buildConfig) {\n throw new Error(\n `Nitro generated an empty Vercel build output config at \"${buildConfigPath}\".`,\n );\n }\n\n try {\n JSON.parse(buildConfig);\n } catch (error) {\n const symptomError = new Error(\n `Nitro generated an invalid Vercel build output config at \"${buildConfigPath}\": ${\n error instanceof Error ? error.message : String(error)\n }`,\n );\n\n (symptomError as Error & { cause?: unknown }).cause = error;\n throw symptomError;\n }\n}\n\nfunction ensureVercelFunctionConfig(\n nitro: Awaited<ReturnType<typeof createNitro>>,\n) {\n if (!isVercelPreset(nitro.options.preset)) {\n return;\n }\n\n const serverDir = nitro.options.output.serverDir;\n const functionConfigPath = join(serverDir, '.vc-config.json');\n\n if (existsSync(functionConfigPath)) {\n return;\n }\n\n mkdirSync(serverDir, { recursive: true });\n\n writeFileSync(\n functionConfigPath,\n JSON.stringify(\n {\n handler: 'index.mjs',\n launcherType: 'Nodejs',\n shouldAddHelpers: false,\n supportsResponseStreaming: true,\n ...nitro.options.vercel?.functions,\n },\n null,\n 2,\n ),\n 'utf8',\n );\n}\n\nexport async function buildServer(\n options?: Options,\n nitroConfig?: NitroConfig,\n routeSourceFiles?: Record<string, string>,\n): Promise<void> {\n // ── Ensure the SSR output has a tsconfig for OXC ─────────────────\n //\n // Must run before createNitro() so the tsconfig is on disk when the\n // nitro:oxc plugin initialises its resolver.\n ensureSsrTsconfig(nitroConfig);\n\n // ── Force Rollup as the server bundler ────────────────────────────\n //\n // Nitro v3 defaults to Rolldown when available. Rolldown is faster,\n // but its module resolver cannot resolve relative chunk imports\n // (e.g. `./assets/core-DTazUigR.js`) from a rebundled SSR entry on\n // Windows. The prerender build fails with:\n //\n // [RESOLVE_ERROR] Could not resolve './assets/core-DTazUigR.js'\n // in ../../dist/apps/blog-app/ssr/main.server.js\n //\n // This is a known Rolldown limitation with cross-directory relative\n // paths on Windows (backslash vs forward-slash normalisation).\n // Rollup handles these paths correctly on all platforms.\n //\n // The dev server already uses `builder: 'rollup'` for the same\n // reason. Default to Rollup here too until Rolldown's resolver\n // matures. The caller can still opt in to Rolldown explicitly via\n // nitroConfig.builder if their platform supports it.\n const nitro = await createNitro({\n dev: false,\n preset: process.env['BUILD_PRESET'],\n ...nitroConfig,\n builder: nitroConfig?.builder ?? 'rollup',\n });\n\n if (options?.prerender?.postRenderingHooks) {\n addPostRenderingHooks(nitro, options.prerender.postRenderingHooks);\n }\n\n await prepare(nitro);\n await copyPublicAssets(nitro);\n\n if (\n options?.ssr &&\n nitroConfig?.prerender?.routes &&\n (nitroConfig?.prerender?.routes.find((route) => route === '/') ||\n nitroConfig?.prerender?.routes?.length === 0)\n ) {\n const indexFileExts = ['', '.br', '.gz'];\n\n indexFileExts.forEach((fileExt) => {\n // Remove the root index.html(.br|.gz) files\n const indexFilePath = join(\n nitroConfig?.output?.publicDir ?? '',\n `index.html${fileExt}`,\n );\n\n rmSync(indexFilePath, { force: true });\n });\n }\n\n if (\n nitroConfig?.prerender?.routes &&\n nitroConfig?.prerender?.routes?.length > 0\n ) {\n console.log(`Prerendering static pages...`);\n await prerender(nitro);\n }\n\n if (routeSourceFiles && Object.keys(routeSourceFiles).length > 0) {\n const publicDir = nitroConfig?.output?.publicDir;\n if (!publicDir) {\n throw new Error(\n 'Nitro public output directory is required to write route source files.',\n );\n }\n\n for (const [route, content] of Object.entries(routeSourceFiles)) {\n const outputPath = join(publicDir, `${route}.md`);\n const outputDir = dirname(outputPath);\n mkdirSync(outputDir, { recursive: true });\n\n writeFileSync(outputPath, content, 'utf8');\n }\n }\n\n if (!options?.static) {\n console.log('Building Server...');\n await build(nitro);\n ensureVercelFunctionConfig(nitro);\n }\n\n await nitro.close();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B;AACjC,QAAM,MAAM,MAAM;AAClB,6BAA2B,MAAM;;AAGnC,OAAM,MAAM,OAAO;AACnB,8BAA6B,MAAM"}
@@ -1,68 +1,56 @@
1
- import { writeFileSync } from 'node:fs';
2
- import { create } from 'xmlbuilder2';
3
- import { resolve } from 'node:path';
4
- export async function buildSitemap(config, sitemapConfig, routes, outputDir, routeSitemaps) {
5
- const routeList = await optionHasRoutes(routes);
6
- if (routeList.length) {
7
- const slash = checkSlash(sitemapConfig.host || '');
8
- const sitemapData = routeList.map((page) => {
9
- const url = `${slash}${page.replace(/^\/+/g, '')}`;
10
- const config = routeSitemaps[url];
11
- const props = typeof config === 'object' ? config : config?.();
12
- return {
13
- page: `${sitemapConfig.host}${url}`,
14
- lastMod: props?.lastmod ?? new Date().toISOString().split('T')[0],
15
- changefreq: props?.changefreq,
16
- priority: props?.priority,
17
- };
18
- });
19
- const sitemap = createXml('urlset');
20
- for (const item of sitemapData) {
21
- const page = sitemap.ele('url');
22
- page.ele('loc').txt(item.page);
23
- page.ele('lastmod').txt(item.lastMod);
24
- if (item.changefreq) {
25
- page.ele('changefreq').txt(item.changefreq);
26
- }
27
- if (item.priority) {
28
- page.ele('priority').txt(item.priority);
29
- }
30
- }
31
- const mapPath = `${resolve(outputDir)}/sitemap.xml`;
32
- try {
33
- console.log(`Writing sitemap at ${mapPath}`);
34
- writeFileSync(mapPath, sitemap.end({ prettyPrint: true }));
35
- }
36
- catch (e) {
37
- console.error(`Unable to write file at ${mapPath}`, e);
38
- }
39
- }
1
+ import { resolve } from "node:path";
2
+ import { writeFileSync } from "node:fs";
3
+ import { create } from "xmlbuilder2";
4
+ //#region packages/vite-plugin-nitro/src/lib/build-sitemap.ts
5
+ async function buildSitemap(config, sitemapConfig, routes, outputDir, routeSitemaps) {
6
+ const routeList = await optionHasRoutes(routes);
7
+ if (routeList.length) {
8
+ const slash = checkSlash(sitemapConfig.host || "");
9
+ const sitemapData = routeList.map((page) => {
10
+ const url = `${slash}${page.replace(/^\/+/g, "")}`;
11
+ const config = routeSitemaps[url];
12
+ const props = typeof config === "object" ? config : config?.();
13
+ return {
14
+ page: `${sitemapConfig.host}${url}`,
15
+ lastMod: props?.lastmod ?? (/* @__PURE__ */ new Date()).toISOString().split("T")[0],
16
+ changefreq: props?.changefreq,
17
+ priority: props?.priority
18
+ };
19
+ });
20
+ const sitemap = createXml("urlset");
21
+ for (const item of sitemapData) {
22
+ const page = sitemap.ele("url");
23
+ page.ele("loc").txt(item.page);
24
+ page.ele("lastmod").txt(item.lastMod);
25
+ if (item.changefreq) page.ele("changefreq").txt(item.changefreq);
26
+ if (item.priority) page.ele("priority").txt(item.priority);
27
+ }
28
+ const mapPath = `${resolve(outputDir)}/sitemap.xml`;
29
+ try {
30
+ console.log(`Writing sitemap at ${mapPath}`);
31
+ writeFileSync(mapPath, sitemap.end({ prettyPrint: true }));
32
+ } catch (e) {
33
+ console.error(`Unable to write file at ${mapPath}`, e);
34
+ }
35
+ }
40
36
  }
41
37
  function createXml(elementName) {
42
- return create({ version: '1.0', encoding: 'UTF-8' })
43
- .ele(elementName, {
44
- xmlns: 'https://www.sitemaps.org/schemas/sitemap/0.9',
45
- })
46
- .com(`This file was automatically generated by Analog.`);
38
+ return create({
39
+ version: "1.0",
40
+ encoding: "UTF-8"
41
+ }).ele(elementName, { xmlns: "https://www.sitemaps.org/schemas/sitemap/0.9" }).com(`This file was automatically generated by Analog.`);
47
42
  }
48
43
  function checkSlash(host) {
49
- const finalChar = host.slice(-1);
50
- return finalChar === '/' ? '' : '/';
44
+ return host.slice(-1) === "/" ? "" : "/";
51
45
  }
52
46
  async function optionHasRoutes(routes) {
53
- let routeList;
54
- if (typeof routes === 'function') {
55
- // returns an array or undefined
56
- routeList = await routes();
57
- }
58
- else if (Array.isArray(routes)) {
59
- // returns an array of strings
60
- routeList = routes;
61
- }
62
- else {
63
- // default it to an empty of array
64
- routeList = [];
65
- }
66
- return routeList.filter(Boolean);
47
+ let routeList;
48
+ if (typeof routes === "function") routeList = await routes();
49
+ else if (Array.isArray(routes)) routeList = routes;
50
+ else routeList = [];
51
+ return routeList.filter(Boolean);
67
52
  }
53
+ //#endregion
54
+ export { buildSitemap };
55
+
68
56
  //# sourceMappingURL=build-sitemap.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"build-sitemap.js","sourceRoot":"","sources":["../../../../../packages/vite-plugin-nitro/src/lib/build-sitemap.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAExC,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAErC,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAcpC,MAAM,CAAC,KAAK,UAAU,YAAY,CAChC,MAAkB,EAClB,aAA4B,EAC5B,MAAwE,EACxE,SAAiB,EACjB,aAGC;IAED,MAAM,SAAS,GAAa,MAAM,eAAe,CAAC,MAAM,CAAC,CAAC;IAE1D,IAAI,SAAS,CAAC,MAAM,EAAE,CAAC;QACrB,MAAM,KAAK,GAAG,UAAU,CAAC,aAAa,CAAC,IAAI,IAAI,EAAE,CAAC,CAAC;QACnD,MAAM,WAAW,GAAgB,SAAS,CAAC,GAAG,CAAC,CAAC,IAAY,EAAE,EAAE;YAC9D,MAAM,GAAG,GAAG,GAAG,KAAK,GAAG,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE,EAAE,CAAC,EAAE,CAAC;YACnD,MAAM,MAAM,GAAG,aAAa,CAAC,GAAG,CAAC,CAAC;YAClC,MAAM,KAAK,GAAG,OAAO,MAAM,KAAK,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC;YAE/D,OAAO;gBACL,IAAI,EAAE,GAAG,aAAa,CAAC,IAAI,GAAG,GAAG,EAAE;gBACnC,OAAO,EAAE,KAAK,EAAE,OAAO,IAAI,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,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C,EAAE,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,OAAO,EAAE,CAAC;SACjD,GAAG,CAAC,WAAW,EAAE;QAChB,KAAK,EAAE,8CAA8C;KACtD,CAAC;SACD,GAAG,CAAC,kDAAkD,CAAC,CAAC;AAC7D,CAAC;AAED,SAAS,UAAU,CAAC,IAAY;IAC9B,MAAM,SAAS,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;IACjC,OAAO,SAAS,KAAK,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC;AACtC,CAAC;AAED,KAAK,UAAU,eAAe,CAC5B,MAAwE;IAExE,IAAI,SAAiC,CAAC;IAEtC,IAAI,OAAO,MAAM,KAAK,UAAU,EAAE,CAAC;QACjC,gCAAgC;QAChC,SAAS,GAAG,MAAM,MAAM,EAAE,CAAC;IAC7B,CAAC;SAAM,IAAI,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC;QACjC,8BAA8B;QAC9B,SAAS,GAAG,MAAM,CAAC;IACrB,CAAC;SAAM,CAAC;QACN,kCAAkC;QAClC,SAAS,GAAG,EAAE,CAAC;IACjB,CAAC;IAED,OAAO,SAAS,CAAC,MAAM,CAAC,OAAO,CAAa,CAAC;AAC/C,CAAC"}
1
+ {"version":3,"file":"build-sitemap.js","names":[],"sources":["../../../../../packages/vite-plugin-nitro/src/lib/build-sitemap.ts"],"sourcesContent":["import { writeFileSync } from 'node:fs';\nimport { XMLBuilder } from 'xmlbuilder2/lib/interfaces';\nimport { create } from 'xmlbuilder2';\nimport { UserConfig } from 'vite';\nimport { resolve } from 'node:path';\nimport {\n PrerenderContentFile,\n PrerenderSitemapConfig,\n SitemapConfig,\n} from './options';\n\nexport type PagesJson = {\n page: string;\n lastMod: string;\n changefreq?: string;\n priority?: string;\n};\n\nexport async function buildSitemap(\n config: UserConfig,\n sitemapConfig: SitemapConfig,\n routes: (string | undefined)[] | (() => Promise<(string | undefined)[]>),\n outputDir: string,\n routeSitemaps: Record<\n string,\n PrerenderSitemapConfig | (() => PrerenderSitemapConfig) | undefined\n >,\n): Promise<void> {\n const routeList: string[] = await optionHasRoutes(routes);\n\n if (routeList.length) {\n const slash = checkSlash(sitemapConfig.host || '');\n const sitemapData: PagesJson[] = routeList.map((page: string) => {\n const url = `${slash}${page.replace(/^\\/+/g, '')}`;\n const config = routeSitemaps[url];\n const props = typeof config === 'object' ? config : config?.();\n\n return {\n page: `${sitemapConfig.host}${url}`,\n lastMod: props?.lastmod ?? new Date().toISOString().split('T')[0],\n changefreq: props?.changefreq,\n priority: props?.priority,\n };\n });\n\n const sitemap = createXml('urlset');\n\n for (const item of sitemapData) {\n const page = sitemap.ele('url');\n page.ele('loc').txt(item.page);\n page.ele('lastmod').txt(item.lastMod);\n\n if (item.changefreq) {\n page.ele('changefreq').txt(item.changefreq);\n }\n\n if (item.priority) {\n page.ele('priority').txt(item.priority);\n }\n }\n\n const mapPath = `${resolve(outputDir)}/sitemap.xml`;\n try {\n console.log(`Writing sitemap at ${mapPath}`);\n writeFileSync(mapPath, sitemap.end({ prettyPrint: true }));\n } catch (e) {\n console.error(`Unable to write file at ${mapPath}`, e);\n }\n }\n}\n\nfunction createXml(elementName: 'urlset' | 'sitemapindex'): XMLBuilder {\n return create({ version: '1.0', encoding: 'UTF-8' })\n .ele(elementName, {\n xmlns: 'https://www.sitemaps.org/schemas/sitemap/0.9',\n })\n .com(`This file was automatically generated by Analog.`);\n}\n\nfunction checkSlash(host: string): string {\n const finalChar = host.slice(-1);\n return finalChar === '/' ? '' : '/';\n}\n\nasync function optionHasRoutes(\n routes: (string | undefined)[] | (() => Promise<(string | undefined)[]>),\n): Promise<string[]> {\n let routeList: (string | undefined)[];\n\n if (typeof routes === 'function') {\n // returns an array or undefined\n routeList = await routes();\n } else if (Array.isArray(routes)) {\n // returns an array of strings\n routeList = routes;\n } else {\n // default it to an empty of array\n routeList = [];\n }\n\n return routeList.filter(Boolean) as string[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,KAAK,MAAM,GAAG,KACX,MAAM,KAAK;;AAGlC,eAAe,gBACb,QACmB;CACnB,IAAI;AAEJ,KAAI,OAAO,WAAW,WAEpB,aAAY,MAAM,QAAQ;UACjB,MAAM,QAAQ,OAAO,CAE9B,aAAY;KAGZ,aAAY,EAAE;AAGhB,QAAO,UAAU,OAAO,QAAQ"}
@@ -1,21 +1,18 @@
1
- import { build, mergeConfig } from 'vite';
2
- import { relative, resolve } from 'node:path';
3
- import { getBundleOptionsKey } from './utils/rolldown.js';
4
- export async function buildSSRApp(config, options) {
5
- const workspaceRoot = options?.workspaceRoot ?? process.cwd();
6
- const sourceRoot = options?.sourceRoot ?? 'src';
7
- const rootDir = relative(workspaceRoot, config.root || '.') || '.';
8
- const bundleOptionsKey = getBundleOptionsKey();
9
- const ssrBuildConfig = mergeConfig(config, {
10
- build: {
11
- ssr: true,
12
- [bundleOptionsKey]: {
13
- input: options?.entryServer ||
14
- resolve(workspaceRoot, rootDir, `${sourceRoot}/main.server.ts`),
15
- },
16
- outDir: options?.ssrBuildDir || resolve(workspaceRoot, 'dist', rootDir, 'ssr'),
17
- },
18
- });
19
- await build(ssrBuildConfig);
1
+ import { getBundleOptionsKey } from "./utils/rolldown.js";
2
+ import { build, mergeConfig } from "vite";
3
+ import { relative, resolve } from "node:path";
4
+ //#region packages/vite-plugin-nitro/src/lib/build-ssr.ts
5
+ async function buildSSRApp(config, options) {
6
+ const workspaceRoot = options?.workspaceRoot ?? process.cwd();
7
+ const sourceRoot = options?.sourceRoot ?? "src";
8
+ const rootDir = relative(workspaceRoot, config.root || ".") || ".";
9
+ await build(mergeConfig(config, { build: {
10
+ ssr: true,
11
+ [getBundleOptionsKey()]: { input: options?.entryServer || resolve(workspaceRoot, rootDir, `${sourceRoot}/main.server.ts`) },
12
+ outDir: options?.ssrBuildDir || resolve(workspaceRoot, "dist", rootDir, "ssr")
13
+ } }));
20
14
  }
15
+ //#endregion
16
+ export { buildSSRApp };
17
+
21
18
  //# sourceMappingURL=build-ssr.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"build-ssr.js","sourceRoot":"","sources":["../../../../../packages/vite-plugin-nitro/src/lib/build-ssr.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,WAAW,EAAc,MAAM,MAAM,CAAC;AACtD,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAG9C,OAAO,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AAE1D,MAAM,CAAC,KAAK,UAAU,WAAW,CAC/B,MAAkB,EAClB,OAAiB;IAEjB,MAAM,aAAa,GAAG,OAAO,EAAE,aAAa,IAAI,OAAO,CAAC,GAAG,EAAE,CAAC;IAC9D,MAAM,UAAU,GAAG,OAAO,EAAE,UAAU,IAAI,KAAK,CAAC;IAChD,MAAM,OAAO,GAAG,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC,IAAI,IAAI,GAAG,CAAC,IAAI,GAAG,CAAC;IACnE,MAAM,gBAAgB,GAAG,mBAAmB,EAAE,CAAC;IAC/C,MAAM,cAAc,GAAG,WAAW,CAAC,MAAM,EAAc;QACrD,KAAK,EAAE;YACL,GAAG,EAAE,IAAI;YACT,CAAC,gBAAgB,CAAC,EAAE;gBAClB,KAAK,EACH,OAAO,EAAE,WAAW;oBACpB,OAAO,CAAC,aAAa,EAAE,OAAO,EAAE,GAAG,UAAU,iBAAiB,CAAC;aAClE;YACD,MAAM,EACJ,OAAO,EAAE,WAAW,IAAI,OAAO,CAAC,aAAa,EAAE,MAAM,EAAE,OAAO,EAAE,KAAK,CAAC;SACzE;KACF,CAAC,CAAC;IAEH,MAAM,KAAK,CAAC,cAAc,CAAC,CAAC;AAC9B,CAAC"}
1
+ {"version":3,"file":"build-ssr.js","names":[],"sources":["../../../../../packages/vite-plugin-nitro/src/lib/build-ssr.ts"],"sourcesContent":["import { build, mergeConfig, UserConfig } from 'vite';\nimport { relative, resolve } from 'node:path';\n\nimport { Options } from './options.js';\nimport { getBundleOptionsKey } from './utils/rolldown.js';\n\nexport async function buildSSRApp(\n config: UserConfig,\n options?: Options,\n): Promise<void> {\n const workspaceRoot = options?.workspaceRoot ?? process.cwd();\n const sourceRoot = options?.sourceRoot ?? 'src';\n const rootDir = relative(workspaceRoot, config.root || '.') || '.';\n const bundleOptionsKey = getBundleOptionsKey();\n const ssrBuildConfig = mergeConfig(config, <UserConfig>{\n build: {\n ssr: true,\n [bundleOptionsKey]: {\n input:\n options?.entryServer ||\n resolve(workspaceRoot, rootDir, `${sourceRoot}/main.server.ts`),\n },\n outDir:\n options?.ssrBuildDir || resolve(workspaceRoot, 'dist', rootDir, 'ssr'),\n },\n });\n\n await build(ssrBuildConfig);\n}\n"],"mappings":";;;;AAMA,eAAsB,YACpB,QACA,SACe;CACf,MAAM,gBAAgB,SAAS,iBAAiB,QAAQ,KAAK;CAC7D,MAAM,aAAa,SAAS,cAAc;CAC1C,MAAM,UAAU,SAAS,eAAe,OAAO,QAAQ,IAAI,IAAI;AAe/D,OAAM,MAbiB,YAAY,QAAoB,EACrD,OAAO;EACL,KAAK;GAHgB,qBAAqB,GAItB,EAClB,OACE,SAAS,eACT,QAAQ,eAAe,SAAS,GAAG,WAAW,iBAAiB,EAClE;EACD,QACE,SAAS,eAAe,QAAQ,eAAe,QAAQ,SAAS,MAAM;EACzE,EACF,CAAC,CAEyB"}
@@ -1,8 +1,12 @@
1
- export function addPostRenderingHooks(nitro, hooks) {
2
- hooks.forEach((hook) => {
3
- nitro.hooks.hook('prerender:generate', (route) => {
4
- hook(route);
5
- });
6
- });
1
+ //#region packages/vite-plugin-nitro/src/lib/hooks/post-rendering-hook.ts
2
+ function addPostRenderingHooks(nitro, hooks) {
3
+ hooks.forEach((hook) => {
4
+ nitro.hooks.hook("prerender:generate", (route) => {
5
+ hook(route);
6
+ });
7
+ });
7
8
  }
9
+ //#endregion
10
+ export { addPostRenderingHooks };
11
+
8
12
  //# sourceMappingURL=post-rendering-hook.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"post-rendering-hook.js","sourceRoot":"","sources":["../../../../../../packages/vite-plugin-nitro/src/lib/hooks/post-rendering-hook.ts"],"names":[],"mappings":"AAEA,MAAM,UAAU,qBAAqB,CACnC,KAAY,EACZ,KAAgD;IAEhD,KAAK,CAAC,OAAO,CAAC,CAAC,IAAwC,EAAE,EAAE;QACzD,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,oBAAoB,EAAE,CAAC,KAAqB,EAAE,EAAE;YAC/D,IAAI,CAAC,KAAK,CAAC,CAAC;QACd,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC"}
1
+ {"version":3,"file":"post-rendering-hook.js","names":[],"sources":["../../../../../../packages/vite-plugin-nitro/src/lib/hooks/post-rendering-hook.ts"],"sourcesContent":["import type { Nitro, PrerenderRoute } from 'nitro/types';\n\nexport function addPostRenderingHooks(\n nitro: Nitro,\n hooks: ((pr: PrerenderRoute) => Promise<void>)[],\n): void {\n hooks.forEach((hook: (preRoute: PrerenderRoute) => void) => {\n nitro.hooks.hook('prerender:generate', (route: PrerenderRoute) => {\n hook(route);\n });\n });\n}\n"],"mappings":";AAEA,SAAgB,sBACd,OACA,OACM;AACN,OAAM,SAAS,SAA6C;AAC1D,QAAM,MAAM,KAAK,uBAAuB,UAA0B;AAChE,QAAK,MAAM;IACX;GACF"}