@analogjs/platform 3.0.0-alpha.55 → 3.0.0-alpha.56

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 (144) hide show
  1. package/migrations/migration.json +7 -1
  2. package/package.json +8 -5
  3. package/src/index.d.ts +2 -0
  4. package/src/index.js +2 -1
  5. package/src/index.js.map +1 -1
  6. package/src/lib/deps-plugin.js +2 -5
  7. package/src/lib/deps-plugin.js.map +1 -1
  8. package/src/lib/discover-library-routes.d.ts +9 -0
  9. package/src/lib/discover-library-routes.js +12 -1
  10. package/src/lib/discover-library-routes.js.map +1 -1
  11. package/src/lib/nitro/analog-nitro-plugin.d.ts +8 -0
  12. package/src/lib/nitro/analog-nitro-plugin.js +502 -0
  13. package/src/lib/nitro/analog-nitro-plugin.js.map +1 -0
  14. package/src/lib/nitro/angular-linker-plugin.d.ts +17 -0
  15. package/src/lib/nitro/angular-linker-plugin.js +51 -0
  16. package/src/lib/nitro/angular-linker-plugin.js.map +1 -0
  17. package/src/lib/nitro/build-sitemap.d.ts +23 -0
  18. package/src/lib/nitro/build-sitemap.js +137 -0
  19. package/src/lib/nitro/build-sitemap.js.map +1 -0
  20. package/src/lib/nitro/debug.d.ts +5 -0
  21. package/src/lib/nitro/debug.js +11 -0
  22. package/src/lib/nitro/debug.js.map +1 -0
  23. package/src/lib/nitro/get-content-files.d.ts +13 -0
  24. package/src/lib/nitro/get-content-files.js +52 -0
  25. package/src/lib/nitro/get-content-files.js.map +1 -0
  26. package/src/lib/nitro/get-page-handlers.d.ts +23 -0
  27. package/src/lib/nitro/get-page-handlers.js +34 -0
  28. package/src/lib/nitro/get-page-handlers.js.map +1 -0
  29. package/src/lib/nitro/i18n-prerender.d.ts +29 -0
  30. package/src/lib/nitro/i18n-prerender.js +61 -0
  31. package/src/lib/nitro/i18n-prerender.js.map +1 -0
  32. package/src/lib/nitro/page-endpoints-plugin.d.ts +7 -0
  33. package/src/lib/nitro/page-endpoints-plugin.js +72 -0
  34. package/src/lib/nitro/page-endpoints-plugin.js.map +1 -0
  35. package/src/lib/nitro/post-rendering-hook.d.ts +2 -0
  36. package/src/lib/nitro/post-rendering-hook.js +10 -0
  37. package/src/lib/nitro/post-rendering-hook.js.map +1 -0
  38. package/src/lib/nitro/renderers.d.ts +53 -0
  39. package/src/lib/nitro/renderers.js +22 -0
  40. package/src/lib/nitro/renderers.js.map +1 -0
  41. package/src/lib/nitro/types.d.ts +122 -0
  42. package/src/lib/nx-plugin/_virtual/_rolldown/runtime.js +23 -0
  43. package/src/lib/nx-plugin/builders.json +10 -2
  44. package/src/lib/nx-plugin/executors.json +10 -7
  45. package/src/lib/nx-plugin/src/builders/vite/schema.json +39 -0
  46. package/src/lib/nx-plugin/src/builders/vite/vite-build.d.ts +11 -0
  47. package/src/lib/nx-plugin/src/builders/vite/vite-build.js +18 -0
  48. package/src/lib/nx-plugin/src/builders/vite/vite-build.js.map +1 -0
  49. package/src/lib/nx-plugin/src/builders/vite-dev-server/dev-server.d.ts +7 -0
  50. package/src/lib/nx-plugin/src/builders/vite-dev-server/dev-server.js +14 -0
  51. package/src/lib/nx-plugin/src/builders/vite-dev-server/dev-server.js.map +1 -0
  52. package/src/lib/nx-plugin/src/builders/vite-dev-server/schema.json +27 -0
  53. package/src/lib/nx-plugin/src/executors/vite-dev-server/compat.js +1 -0
  54. package/src/lib/nx-plugin/src/executors/vite-dev-server/compat.js.map +1 -1
  55. package/src/lib/nx-plugin/src/executors/vite-dev-server/vite-dev-server.impl.js +1 -0
  56. package/src/lib/nx-plugin/src/executors/vite-dev-server/vite-dev-server.impl.js.map +1 -1
  57. package/src/lib/nx-plugin/src/executors/vitest/compat.js +1 -0
  58. package/src/lib/nx-plugin/src/executors/vitest/compat.js.map +1 -1
  59. package/src/lib/nx-plugin/src/executors/vitest/vitest.impl.js +1 -0
  60. package/src/lib/nx-plugin/src/executors/vitest/vitest.impl.js.map +1 -1
  61. package/src/lib/nx-plugin/src/generators/app/compat.js +1 -0
  62. package/src/lib/nx-plugin/src/generators/app/compat.js.map +1 -1
  63. package/src/lib/nx-plugin/src/generators/app/generator.js +1 -0
  64. package/src/lib/nx-plugin/src/generators/app/generator.js.map +1 -1
  65. package/src/lib/nx-plugin/src/generators/app/lib/add-analog-project-config.js +1 -0
  66. package/src/lib/nx-plugin/src/generators/app/lib/add-analog-project-config.js.map +1 -1
  67. package/src/lib/nx-plugin/src/generators/app/lib/add-angular-app.js +1 -0
  68. package/src/lib/nx-plugin/src/generators/app/lib/add-angular-app.js.map +1 -1
  69. package/src/lib/nx-plugin/src/generators/app/lib/add-files.js +1 -0
  70. package/src/lib/nx-plugin/src/generators/app/lib/add-files.js.map +1 -1
  71. package/src/lib/nx-plugin/src/generators/app/lib/add-home-page.js +1 -0
  72. package/src/lib/nx-plugin/src/generators/app/lib/add-home-page.js.map +1 -1
  73. package/src/lib/nx-plugin/src/generators/app/lib/add-tailwind-config.js +1 -0
  74. package/src/lib/nx-plugin/src/generators/app/lib/add-tailwind-config.js.map +1 -1
  75. package/src/lib/nx-plugin/src/generators/app/lib/add-tailwind-helpers.js +1 -0
  76. package/src/lib/nx-plugin/src/generators/app/lib/add-tailwind-helpers.js.map +1 -1
  77. package/src/lib/nx-plugin/src/generators/app/lib/update-index-html.js +1 -0
  78. package/src/lib/nx-plugin/src/generators/app/lib/update-index-html.js.map +1 -1
  79. package/src/lib/nx-plugin/src/generators/app/versions/minimum-supported-versions.js +1 -0
  80. package/src/lib/nx-plugin/src/generators/app/versions/minimum-supported-versions.js.map +1 -1
  81. package/src/lib/nx-plugin/src/generators/app/versions/nx_18_X/versions.d.ts +5 -5
  82. package/src/lib/nx-plugin/src/generators/app/versions/nx_18_X/versions.js.map +1 -1
  83. package/src/lib/nx-plugin/src/generators/init/compat.js +1 -0
  84. package/src/lib/nx-plugin/src/generators/init/compat.js.map +1 -1
  85. package/src/lib/nx-plugin/src/generators/init/generator.js +1 -0
  86. package/src/lib/nx-plugin/src/generators/init/generator.js.map +1 -1
  87. package/src/lib/nx-plugin/src/generators/init/lib/add-analog-dependencies.js +1 -0
  88. package/src/lib/nx-plugin/src/generators/init/lib/add-analog-dependencies.js.map +1 -1
  89. package/src/lib/nx-plugin/src/generators/init/lib/update-app-tsconfig.js +1 -0
  90. package/src/lib/nx-plugin/src/generators/init/lib/update-app-tsconfig.js.map +1 -1
  91. package/src/lib/nx-plugin/src/generators/init/lib/update-build-target.js +1 -0
  92. package/src/lib/nx-plugin/src/generators/init/lib/update-build-target.js.map +1 -1
  93. package/src/lib/nx-plugin/src/generators/init/lib/update-index-html.js +1 -0
  94. package/src/lib/nx-plugin/src/generators/init/lib/update-index-html.js.map +1 -1
  95. package/src/lib/nx-plugin/src/generators/init/lib/update-main.js +1 -0
  96. package/src/lib/nx-plugin/src/generators/init/lib/update-main.js.map +1 -1
  97. package/src/lib/nx-plugin/src/generators/init/lib/update-package-json.js +1 -0
  98. package/src/lib/nx-plugin/src/generators/init/lib/update-package-json.js.map +1 -1
  99. package/src/lib/nx-plugin/src/generators/init/lib/update-serve-target.js +1 -0
  100. package/src/lib/nx-plugin/src/generators/init/lib/update-serve-target.js.map +1 -1
  101. package/src/lib/nx-plugin/src/generators/init/lib/update-test-target.js +1 -0
  102. package/src/lib/nx-plugin/src/generators/init/lib/update-test-target.js.map +1 -1
  103. package/src/lib/nx-plugin/src/generators/init/lib/update-test-tsconfig.js +1 -0
  104. package/src/lib/nx-plugin/src/generators/init/lib/update-test-tsconfig.js.map +1 -1
  105. package/src/lib/nx-plugin/src/generators/page/compat.js +1 -0
  106. package/src/lib/nx-plugin/src/generators/page/compat.js.map +1 -1
  107. package/src/lib/nx-plugin/src/generators/page/generator.js +1 -0
  108. package/src/lib/nx-plugin/src/generators/page/generator.js.map +1 -1
  109. package/src/lib/nx-plugin/src/generators/preset/generator.js +1 -0
  110. package/src/lib/nx-plugin/src/generators/preset/generator.js.map +1 -1
  111. package/src/lib/nx-plugin/src/generators/setup-vitest/compat.js +1 -0
  112. package/src/lib/nx-plugin/src/generators/setup-vitest/compat.js.map +1 -1
  113. package/src/lib/nx-plugin/src/generators/setup-vitest/generator.js +1 -0
  114. package/src/lib/nx-plugin/src/generators/setup-vitest/generator.js.map +1 -1
  115. package/src/lib/nx-plugin/src/generators/setup-vitest/lib/add-analog-dependencies.js +1 -0
  116. package/src/lib/nx-plugin/src/generators/setup-vitest/lib/add-analog-dependencies.js.map +1 -1
  117. package/src/lib/nx-plugin/src/generators/setup-vitest/lib/update-test-target.js +1 -0
  118. package/src/lib/nx-plugin/src/generators/setup-vitest/lib/update-test-target.js.map +1 -1
  119. package/src/lib/nx-plugin/src/generators/setup-vitest/lib/update-tsconfig.js +1 -0
  120. package/src/lib/nx-plugin/src/generators/setup-vitest/lib/update-tsconfig.js.map +1 -1
  121. package/src/lib/nx-plugin/src/utils/version-utils.js +1 -0
  122. package/src/lib/nx-plugin/src/utils/version-utils.js.map +1 -1
  123. package/src/lib/nx-plugin/src/utils/versions/dependencies.js +1 -0
  124. package/src/lib/nx-plugin/src/utils/versions/dependencies.js.map +1 -1
  125. package/src/lib/nx-plugin/src/utils/versions/dev-dependencies.js +1 -0
  126. package/src/lib/nx-plugin/src/utils/versions/dev-dependencies.js.map +1 -1
  127. package/src/lib/nx-plugin/src/utils/versions/ng_19_X/versions.d.ts +5 -5
  128. package/src/lib/nx-plugin/src/utils/versions/ng_19_X/versions.js +5 -5
  129. package/src/lib/nx-plugin/src/utils/versions/ng_19_X/versions.js.map +1 -1
  130. package/src/lib/options.d.ts +9 -146
  131. package/src/lib/platform-plugin.js +3 -40
  132. package/src/lib/platform-plugin.js.map +1 -1
  133. package/src/lib/style-pipeline.d.ts +0 -1
  134. package/src/lib/style-pipeline.js.map +1 -1
  135. package/src/lib/utils/debug.js +2 -2
  136. package/src/lib/utils/debug.js.map +1 -1
  137. package/src/lib/nx-plugin/src/executors/vite/compat.d.ts +0 -3
  138. package/src/lib/nx-plugin/src/executors/vite/compat.js +0 -7
  139. package/src/lib/nx-plugin/src/executors/vite/compat.js.map +0 -1
  140. package/src/lib/nx-plugin/src/executors/vite/schema.d.ts +0 -2
  141. package/src/lib/nx-plugin/src/executors/vite/schema.json +0 -147
  142. package/src/lib/nx-plugin/src/executors/vite/vite.impl.d.ts +0 -2
  143. package/src/lib/nx-plugin/src/executors/vite/vite.impl.js +0 -6
  144. package/src/lib/nx-plugin/src/executors/vite/vite.impl.js.map +0 -1
@@ -0,0 +1,502 @@
1
+ import { getPageHandlers } from "./get-page-handlers.js";
2
+ import { pageEndpointsPlugin } from "./page-endpoints-plugin.js";
3
+ import { getMatchingContentFilesWithFrontMatter } from "./get-content-files.js";
4
+ import { buildSitemap } from "./build-sitemap.js";
5
+ import { addPostRenderingHooks } from "./post-rendering-hook.js";
6
+ import { createI18nPostRenderingHook, expandRoutesWithLocales } from "./i18n-prerender.js";
7
+ import { angularLinkerPlugin } from "./angular-linker-plugin.js";
8
+ import { dirname, relative, resolve } from "node:path";
9
+ import { existsSync, readFileSync, readdirSync } from "node:fs";
10
+ import { mkdir, writeFile } from "node:fs/promises";
11
+ //#region packages/platform/src/lib/nitro/analog-nitro-plugin.ts
12
+ var SSR_ENTRY_VIRTUAL_ID = "\0virtual:@analogjs/nitro/ssr-entry";
13
+ /**
14
+ * Angular packages that ship in partial-compilation form and must pass
15
+ * through the linker before the SSR / nitro bundle can execute without
16
+ * JIT. Wired into `ssr.optimizeDeps.rolldownOptions.plugins`.
17
+ */
18
+ var ANGULAR_SSR_DEPS = [
19
+ "@angular/compiler",
20
+ "@angular/core",
21
+ "@angular/common",
22
+ "@angular/platform-browser",
23
+ "@angular/platform-server"
24
+ ];
25
+ /**
26
+ * Analog's NitroModule. Plug it into the Vite plugin chain alongside
27
+ * `nitro()` from `nitro/vite`; nitro/vite picks up the `.nitro` property
28
+ * and runs `setup(nitro)` once the Nitro instance is ready.
29
+ */
30
+ function analogNitroPlugin(options = {}) {
31
+ const workspaceRoot = options.workspaceRoot ?? process.env["NX_WORKSPACE_ROOT"] ?? process.cwd();
32
+ const sourceRoot = "src";
33
+ const ssr = options.ssr ?? true;
34
+ const apiPrefix = options.apiPrefix ?? "api";
35
+ let context = {
36
+ workspaceRoot,
37
+ rootDir: ".",
38
+ sourceRoot
39
+ };
40
+ let ssrEntryMarkerPath = "";
41
+ let userPublicDir;
42
+ function refreshContext(viteRoot) {
43
+ context = {
44
+ workspaceRoot,
45
+ rootDir: relative(workspaceRoot, viteRoot ?? process.cwd()) || ".",
46
+ sourceRoot
47
+ };
48
+ ssrEntryMarkerPath = resolve(context.workspaceRoot, context.rootDir, ".analog/__ssr-entry.mjs");
49
+ }
50
+ function readIndexHtml() {
51
+ const indexFile = options.index ?? "index.html";
52
+ const candidates = [resolve(context.workspaceRoot, context.rootDir, indexFile), resolve(context.workspaceRoot, "dist", context.rootDir, "client", indexFile)];
53
+ for (const candidate of candidates) if (existsSync(candidate)) return readFileSync(candidate, "utf-8");
54
+ return "<!doctype html><html><body><div id=\"app\"></div></body></html>";
55
+ }
56
+ function resolveEntryServer() {
57
+ return options.entryServer ?? resolve(context.workspaceRoot, context.rootDir, `${sourceRoot}/main.server.ts`);
58
+ }
59
+ return {
60
+ name: "@analogjs/nitro",
61
+ enforce: "pre",
62
+ config(userConfig) {
63
+ refreshContext(userConfig.root);
64
+ if (userConfig.publicDir !== false) userPublicDir = resolve(context.workspaceRoot, context.rootDir, userConfig.publicDir ?? "public");
65
+ if (!process.env["NITRO_PRESET"]) {
66
+ if (process.env["BUILD_PRESET"]) process.env["NITRO_PRESET"] = process.env["BUILD_PRESET"];
67
+ else if (process.env["VERCEL"]) process.env["NITRO_PRESET"] = "vercel";
68
+ else if (process.env["NETLIFY"]) process.env["NITRO_PRESET"] = "netlify";
69
+ else if (process.env["CF_PAGES"]) process.env["NITRO_PRESET"] = "cloudflare-pages";
70
+ }
71
+ const overrides = { server: { fs: { allow: [context.workspaceRoot] } } };
72
+ if (ssr) {
73
+ overrides.experimental = { vite: { services: { ssr: { entry: ssrEntryMarkerPath } } } };
74
+ overrides.environments = { ssr: {
75
+ build: {
76
+ outDir: resolve(context.workspaceRoot, "dist", context.rootDir, "ssr"),
77
+ rollupOptions: { input: { index: ssrEntryMarkerPath } }
78
+ },
79
+ optimizeDeps: {
80
+ include: ANGULAR_SSR_DEPS,
81
+ rolldownOptions: { plugins: [angularLinkerPlugin()] }
82
+ }
83
+ } };
84
+ }
85
+ return overrides;
86
+ },
87
+ resolveId(id) {
88
+ if (id === ssrEntryMarkerPath || id === SSR_ENTRY_VIRTUAL_ID) return SSR_ENTRY_VIRTUAL_ID;
89
+ return null;
90
+ },
91
+ load(id) {
92
+ if (id !== SSR_ENTRY_VIRTUAL_ID) return null;
93
+ return generateSsrEntryWrapper(resolveEntryServer(), readIndexHtml());
94
+ },
95
+ nitro: { async setup(nitro) {
96
+ if (!context || context.rootDir === ".") refreshContext(nitro.options.rootDir);
97
+ if (!nitro.options.dev) {
98
+ const preset = (nitro.options.preset ?? "").toLowerCase();
99
+ const isManagedPreset = preset !== "" && preset !== "node-server" && preset !== "node" && preset !== "nitro-dev";
100
+ if (preset.includes("vercel")) {
101
+ const vercel = nitro.options.vercel;
102
+ nitro.options.vercel = {
103
+ ...vercel,
104
+ entryFormat: vercel?.entryFormat ?? "node",
105
+ functions: {
106
+ runtime: vercel?.functions?.runtime ?? "nodejs24.x",
107
+ ...vercel?.functions
108
+ }
109
+ };
110
+ const vercelDir = resolve(context.workspaceRoot, ".vercel/output");
111
+ nitro.options.output = {
112
+ ...nitro.options.output,
113
+ dir: vercelDir,
114
+ serverDir: resolve(vercelDir, "functions/__server.func"),
115
+ publicDir: resolve(vercelDir, "static")
116
+ };
117
+ }
118
+ if (preset === "netlify" || preset === "netlify-edge") {
119
+ const netlifyDir = resolve(context.workspaceRoot, ".netlify/functions-internal");
120
+ nitro.options.output = {
121
+ ...nitro.options.output,
122
+ dir: netlifyDir,
123
+ serverDir: resolve(netlifyDir, "server"),
124
+ publicDir: resolve(context.workspaceRoot, "dist", context.rootDir, "analog/public")
125
+ };
126
+ }
127
+ if (preset.includes("cloudflare")) {
128
+ const cfDir = resolve(context.workspaceRoot, "dist", context.rootDir);
129
+ nitro.options.output = {
130
+ ...nitro.options.output,
131
+ dir: cfDir,
132
+ publicDir: cfDir,
133
+ serverDir: resolve(cfDir, "_worker.js")
134
+ };
135
+ }
136
+ if (!isManagedPreset) {
137
+ const distRoot = resolve(context.workspaceRoot, "dist", context.rootDir);
138
+ nitro.options.output = {
139
+ ...nitro.options.output,
140
+ dir: resolve(distRoot, "analog"),
141
+ publicDir: resolve(distRoot, "analog/public"),
142
+ serverDir: resolve(distRoot, "analog/server")
143
+ };
144
+ }
145
+ nitro.hooks.hook("prerender:route", async (route) => {
146
+ if (!route.skip || route.error) return;
147
+ const buffer = route.data;
148
+ if (!buffer || !route.fileName) return;
149
+ const filePath = resolve(nitro.options.output.publicDir, route.fileName.replace(/^[\\/]+/, ""));
150
+ try {
151
+ await mkdir(dirname(filePath), { recursive: true });
152
+ await writeFile(filePath, Buffer.from(buffer));
153
+ route.skip = false;
154
+ } catch {}
155
+ });
156
+ }
157
+ if (userPublicDir && existsSync(userPublicDir)) {
158
+ if (!nitro.options.publicAssets.some((asset) => asset.dir === userPublicDir)) nitro.options.publicAssets.push({
159
+ dir: userPublicDir,
160
+ baseURL: "/",
161
+ maxAge: 0,
162
+ fallthrough: true
163
+ });
164
+ }
165
+ nitro.hooks.hook("prerender:config", (prerendererConfig) => {
166
+ prerendererConfig.output = {
167
+ ...prerendererConfig.output,
168
+ publicDir: nitro.options.output.publicDir
169
+ };
170
+ });
171
+ const hasAPIDir = existsSync(resolve(context.workspaceRoot, context.rootDir, `${context.sourceRoot}/server/routes/api`));
172
+ const pageHandlers = getPageHandlers({
173
+ workspaceRoot: context.workspaceRoot,
174
+ sourceRoot: context.sourceRoot,
175
+ rootDir: context.rootDir,
176
+ additionalPagesDirs: options.additionalPagesDirs,
177
+ hasAPIDir
178
+ });
179
+ nitro.options.handlers.push(...pageHandlers);
180
+ const serverDir = resolve(context.workspaceRoot, context.rootDir, `${context.sourceRoot}/server`);
181
+ if (existsSync(serverDir) && !nitro.options.scanDirs.includes(serverDir)) nitro.options.scanDirs.push(serverDir);
182
+ nitro.hooks.hook("rollup:before", (_n, rollupConfig) => {
183
+ if (Array.isArray(rollupConfig.plugins)) rollupConfig.plugins.push(pageEndpointsPlugin());
184
+ applyAnalogNitroExternals(rollupConfig);
185
+ sanitizeNitroBundlerConfig(rollupConfig);
186
+ });
187
+ if (ssr) {
188
+ nitro.options.virtual["#analog/ssr"] = () => generateSsrServiceVirtual(nitro);
189
+ nitro.options.virtual["#analog/ssr-renderer"] = generateSsrRendererVirtual(readIndexHtml());
190
+ nitro.options.renderer ??= {};
191
+ nitro.options.renderer.handler = "#analog/ssr-renderer";
192
+ delete nitro.options.renderer.template;
193
+ }
194
+ injectAnalogRouteRuleHeaders(nitro);
195
+ await wirePrerender(nitro, options, context, apiPrefix);
196
+ if (options.i18n) addPostRenderingHooks(nitro, [createI18nPostRenderingHook({
197
+ defaultLocale: options.i18n.defaultLocale,
198
+ locales: options.i18n.locales
199
+ })]);
200
+ } }
201
+ };
202
+ }
203
+ /**
204
+ * Builds the h3 handler installed as Nitro's `renderer.handler`. Short-circuits
205
+ * `ssr: false` routes to the raw client template; otherwise dispatches the
206
+ * request to the SSR service env (`fetchViteEnv("ssr", req)` works in dev via
207
+ * the env-runner and in prod via the `__nitro_vite_envs__` global set up by
208
+ * nitro/vite's `prodSetup`).
209
+ */
210
+ function generateSsrRendererVirtual(template) {
211
+ return `
212
+ import { defineHandler } from 'nitro/h3';
213
+ import ssr from '#analog/ssr';
214
+
215
+ const TEMPLATE = ${JSON.stringify(template)};
216
+
217
+ export default defineHandler(async (event) => {
218
+ event.res.headers.set('content-type', 'text/html; charset=utf-8');
219
+ // 'x-analog-no-ssr' is stamped on response headers by
220
+ // injectAnalogRouteRuleHeaders for routeRules with \`ssr: false\`. Nitro
221
+ // applies routeRule headers to the response before the renderer fires,
222
+ // so we can short-circuit by reading them here.
223
+ if (event.res.headers.get('x-analog-no-ssr') === 'true') {
224
+ return TEMPLATE;
225
+ }
226
+ const service = ssr.default ?? ssr;
227
+ return service.fetch(event.req);
228
+ });
229
+ `;
230
+ }
231
+ /**
232
+ * Resolves \`#analog/ssr\` to the SSR fetch handler. The shape returned by
233
+ * this function is bundler-agnostic: works in Vite-built main bundles and
234
+ * Rolldown-built prerender bundles alike.
235
+ *
236
+ * - Dev: dispatch through nitro/vite's env runner (\`fetchViteEnv\`); the SSR
237
+ * service module isn't on disk yet, so we delegate to the runner.
238
+ * - Build / prerender: re-export the built SSR entry directly from the
239
+ * filesystem. By the time Nitro's bundlers ask for \`#analog/ssr\`, Vite has
240
+ * already produced \`<buildDir>/vite/services/ssr/<entry>.mjs\`.
241
+ */
242
+ function generateSsrServiceVirtual(nitro) {
243
+ if (nitro.options.dev) return `
244
+ import { fetchViteEnv } from 'nitro/vite/runtime';
245
+ export default {
246
+ async fetch(req) {
247
+ return fetchViteEnv('ssr', req);
248
+ },
249
+ };
250
+ `;
251
+ const ssrDir = resolve(nitro.options.buildDir, "vite/services/ssr");
252
+ if (!existsSync(ssrDir)) return `export default { async fetch() { throw new Error('Analog SSR service directory missing: ${ssrDir}'); } };`;
253
+ const entries = readdirSync(ssrDir).filter((f) => f.endsWith(".mjs"));
254
+ if (entries.length === 0) return `export default { async fetch() { throw new Error('No Analog SSR entry file built in: ${ssrDir}'); } };`;
255
+ const entryPath = resolve(ssrDir, entries.find((f) => f === "main.server.mjs") ?? entries[0]);
256
+ return `export { default } from ${JSON.stringify(entryPath)};`;
257
+ }
258
+ /**
259
+ * Packages Analog forces external in the Nitro server bundle. Each entry is
260
+ * here for a specific reason — see comments.
261
+ */
262
+ var ANALOG_NITRO_EXTERNALS = [
263
+ "rxjs",
264
+ "node-fetch-native/dist/polyfill",
265
+ "sharp"
266
+ ];
267
+ function applyAnalogNitroExternals(rollupConfig) {
268
+ const prev = rollupConfig.external;
269
+ const existing = prev === void 0 ? [] : Array.isArray(prev) ? prev : prev instanceof RegExp ? [prev] : typeof prev === "string" ? [prev] : [];
270
+ const escapeRegExp = (s) => s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
271
+ for (const entry of ANALOG_NITRO_EXTERNALS) {
272
+ const pattern = new RegExp(`^${escapeRegExp(entry)}(?:/|$)`);
273
+ if (!existing.some((p) => String(p) === String(pattern))) existing.push(pattern);
274
+ }
275
+ rollupConfig.external = existing;
276
+ }
277
+ /**
278
+ * Workarounds for Nitro v3 + Rolldown bundler interaction quirks. Each
279
+ * is narrowly scoped and can be removed once the upstream bug is fixed:
280
+ *
281
+ * 1. `output.codeSplitting` — Nitro 3.0.x sets this; Rolldown rejects it
282
+ * as an unknown key.
283
+ * 2. `output.manualChunks` — Nitro's default manual chunking crashes
284
+ * Nitro's prerender rebundle.
285
+ * 3. `output.chunkFileNames` — Nitro's chunk-name function produces
286
+ * route-derived `[token]` patterns which Rollup/Rolldown interprets as
287
+ * placeholders; we rewrite non-standard tokens to `_token_`.
288
+ */
289
+ function sanitizeNitroBundlerConfig(rollupConfig) {
290
+ const output = rollupConfig.output;
291
+ if (!output || Array.isArray(output) || typeof output !== "object") return;
292
+ const out = output;
293
+ if ("codeSplitting" in out) delete out["codeSplitting"];
294
+ if ("manualChunks" in out) delete out["manualChunks"];
295
+ const VALID_ROLLUP_PLACEHOLDER = /^\[(?:name|hash|format|ext)\]$/;
296
+ const chunkFileNames = out["chunkFileNames"];
297
+ if (typeof chunkFileNames === "function") {
298
+ const originalFn = chunkFileNames;
299
+ out["chunkFileNames"] = (...args) => {
300
+ const result = originalFn(...args);
301
+ if (typeof result !== "string") return result;
302
+ return result.replace(/\[[^\]]+\]/g, (match) => VALID_ROLLUP_PLACEHOLDER.test(match) ? match : `_${match.slice(1, -1)}_`);
303
+ };
304
+ }
305
+ }
306
+ /**
307
+ * Walks Nitro's resolved routeRules and stamps `x-analog-no-ssr: true` onto
308
+ * any rule with `ssr: false`. Kept as a response-header hint for downstream
309
+ * consumers (CDN, edge logic); the actual SSR short-circuit happens inside
310
+ * the SSR renderer virtual above.
311
+ */
312
+ function injectAnalogRouteRuleHeaders(nitro) {
313
+ const routeRules = nitro.options.routeRules;
314
+ if (!routeRules) return;
315
+ for (const rule of Object.values(routeRules)) if (rule?.ssr === false) rule.headers = {
316
+ ...rule.headers,
317
+ "x-analog-no-ssr": "true"
318
+ };
319
+ }
320
+ /**
321
+ * Builds the SSR service entry source. The wrapper imports the user's
322
+ * `main.server.ts` Angular renderer and adapts it to the `{ fetch(req) }`
323
+ * shape that nitro/vite's service mechanism expects.
324
+ */
325
+ function generateSsrEntryWrapper(entryServer, template) {
326
+ return `
327
+ // Import \`serverFetch\` from the root \`nitro\` entry rather than \`nitro/app\`.
328
+ // The /app subpath creates a fresh \`useNitroApp()\` instance scoped to the
329
+ // importing bundle, which in our setup is the standalone SSR vite bundle —
330
+ // it has no route handlers, so every fetch 404s. The root entry instead
331
+ // reads \`globalThis.__nitro__.{default,prerender}\`, which the surrounding
332
+ // Nitro server (prerender pass or production runtime) has already
333
+ // populated with the real app + handlers.
334
+ import { serverFetch as nitroServerFetch } from 'nitro';
335
+ import { createFetch } from 'ofetch';
336
+ import renderer from ${JSON.stringify(entryServer)};
337
+
338
+ const TEMPLATE = ${JSON.stringify(template)};
339
+
340
+ const normalizeRequestPath = (url) =>
341
+ url.replace(/\\/index\\.html(?=$|[?#])/, '/');
342
+
343
+ // In-process fetch wired into Nitro's request pipeline. Angular's HttpClient
344
+ // (via withFetch()) and Analog's injectLoad() call this during SSR/prerender
345
+ // so they hit the running app's page-endpoint and API routes without going
346
+ // through the network — the prerender pipeline doesn't have a listening
347
+ // socket. Without this, every SSR data fetch ECONNREFUSEs and Angular's
348
+ // router fails to resolve any data-bound route, producing an empty
349
+ // <router-outlet/> in the prerendered HTML.
350
+ const ssrFetch = (resource, init) => {
351
+ let url = typeof resource === 'string'
352
+ ? resource
353
+ : resource instanceof URL
354
+ ? resource.href
355
+ : resource.url;
356
+ // Relative URLs from injectAPIPrefix() etc. need a host for Nitro's
357
+ // Request constructor to accept them.
358
+ if (typeof url === 'string' && url.startsWith('/')) {
359
+ url = 'http://localhost' + url;
360
+ }
361
+ return nitroServerFetch(url, init);
362
+ };
363
+
364
+ // Wrap in ofetch so consumers that expect \`$fetch.raw()\` (the router's
365
+ // request-context interceptor short-circuits SSR HttpClient calls through
366
+ // \`globalThis.$fetch.raw\`) can call it. Set on globalThis so router code
367
+ // running inside the Angular renderer can find it.
368
+ const ssrOFetch = createFetch({ fetch: ssrFetch });
369
+ if (typeof globalThis.$fetch === 'undefined') {
370
+ globalThis.$fetch = ssrOFetch;
371
+ }
372
+
373
+ export default {
374
+ async fetch(req) {
375
+ const url = new URL(req.url);
376
+ const requestPath = normalizeRequestPath(url.pathname);
377
+ // Preserve the query string so Angular's router + injectQuery() and
378
+ // server data loaders that read from req.url see the full path+query.
379
+ const requestUrl = requestPath + url.search;
380
+
381
+ if (req.headers.get('x-analog-no-ssr') === 'true') {
382
+ return new Response(TEMPLATE, {
383
+ status: 200,
384
+ headers: { 'content-type': 'text/html; charset=utf-8' },
385
+ });
386
+ }
387
+
388
+ const reqShim = {
389
+ headers: Object.fromEntries(req.headers.entries()),
390
+ url: requestUrl,
391
+ originalUrl: requestUrl,
392
+ connection: {},
393
+ };
394
+
395
+ try {
396
+ const html = await renderer(requestUrl, TEMPLATE, {
397
+ req: reqShim,
398
+ // Pass the ofetch-wrapped fetch — INTERNAL_FETCH is consumed by the
399
+ // router's request-context interceptor via \`serverFetch.raw(...)\`,
400
+ // which is ofetch's response-shape API. Plain fetch lacks \`.raw\`
401
+ // and throws TypeError during prerender/SSR.
402
+ fetch: ssrOFetch,
403
+ });
404
+ return new Response(html, {
405
+ status: 200,
406
+ headers: { 'content-type': 'text/html; charset=utf-8' },
407
+ });
408
+ } catch (err) {
409
+ console.error('[analog ssr]', err);
410
+ return new Response(TEMPLATE, {
411
+ status: 500,
412
+ headers: { 'content-type': 'text/html; charset=utf-8' },
413
+ });
414
+ }
415
+ },
416
+ };
417
+ `;
418
+ }
419
+ async function wirePrerender(nitro, options, context, apiPrefix) {
420
+ const prerender = options.prerender;
421
+ if (!prerender && !options.i18n) return;
422
+ const { routes: collected, sitemaps: routeSitemaps, routeSourceFiles } = await collectRoutes(prerender?.routes, context, apiPrefix);
423
+ const expanded = options.i18n ? expandRoutesWithLocales(collected, {
424
+ defaultLocale: options.i18n.defaultLocale,
425
+ locales: options.i18n.locales
426
+ }) : collected;
427
+ const nitroPrerender = nitro.options.prerender ??= {};
428
+ nitroPrerender.routes ??= [];
429
+ nitroPrerender.routes.push(...expanded);
430
+ if (prerender?.discover ?? false) nitroPrerender.crawlLinks = true;
431
+ if (prerender?.postRenderingHooks?.length) addPostRenderingHooks(nitro, prerender.postRenderingHooks);
432
+ if (Object.keys(routeSourceFiles).length > 0) nitro.hooks.hook("prerender:done", async () => {
433
+ const publicDir = resolve(nitro.options.output.publicDir);
434
+ const { mkdirSync, writeFileSync } = await import("node:fs");
435
+ const { dirname, join } = await import("node:path");
436
+ for (const [route, content] of Object.entries(routeSourceFiles)) {
437
+ const outputPath = join(publicDir, `${route}.md`);
438
+ mkdirSync(dirname(outputPath), { recursive: true });
439
+ writeFileSync(outputPath, content, "utf8");
440
+ }
441
+ });
442
+ const sitemapConfig = prerender?.sitemap;
443
+ if (sitemapConfig) nitro.hooks.hook("prerender:done", async (result) => {
444
+ await buildSitemap({}, sitemapConfig, (result?.prerenderedRoutes ?? []).map((r) => r.route), resolve(nitro.options.output.publicDir), routeSitemaps, { apiPrefix });
445
+ });
446
+ }
447
+ async function collectRoutes(routesInput, context, apiPrefix) {
448
+ const out = [];
449
+ const sitemaps = {};
450
+ const routeSourceFiles = {};
451
+ if (!routesInput) return {
452
+ routes: out,
453
+ sitemaps,
454
+ routeSourceFiles
455
+ };
456
+ const inputs = Array.isArray(routesInput) ? routesInput : typeof routesInput === "function" ? await routesInput() : [];
457
+ for (const entry of inputs) {
458
+ if (!entry) continue;
459
+ if (typeof entry === "string") {
460
+ out.push(entry);
461
+ continue;
462
+ }
463
+ if ("contentDir" in entry) {
464
+ const dir = entry;
465
+ const files = getMatchingContentFilesWithFrontMatter(context.workspaceRoot, context.rootDir, dir.contentDir, !!dir.recursive);
466
+ for (const file of files) {
467
+ const route = dir.transform(file);
468
+ if (route === false) continue;
469
+ out.push(route);
470
+ if (dir.sitemap) sitemaps[route] = typeof dir.sitemap === "function" ? dir.sitemap(file) : dir.sitemap;
471
+ if (dir.outputSourceFile) {
472
+ const sourceContent = dir.outputSourceFile(file);
473
+ if (typeof sourceContent === "string") routeSourceFiles[route] = sourceContent;
474
+ }
475
+ }
476
+ continue;
477
+ }
478
+ if ("route" in entry) {
479
+ const cfg = entry;
480
+ out.push(cfg.route);
481
+ if (cfg.sitemap) sitemaps[cfg.route] = cfg.sitemap;
482
+ if (cfg.outputSourceFile) {
483
+ const sourcePath = resolve(context.workspaceRoot, context.rootDir, cfg.outputSourceFile);
484
+ if (existsSync(sourcePath)) routeSourceFiles[cfg.route] = readFileSync(sourcePath, "utf8");
485
+ }
486
+ if (cfg.staticData) {
487
+ const prefix = apiPrefix.startsWith("/") ? apiPrefix : `/${apiPrefix}`;
488
+ const route = cfg.route.startsWith("/") ? cfg.route : `/${cfg.route}`;
489
+ out.push(`${prefix}/_analog/pages${route}`);
490
+ }
491
+ }
492
+ }
493
+ return {
494
+ routes: out,
495
+ sitemaps,
496
+ routeSourceFiles
497
+ };
498
+ }
499
+ //#endregion
500
+ export { analogNitroPlugin };
501
+
502
+ //# sourceMappingURL=analog-nitro-plugin.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"analog-nitro-plugin.js","names":[],"sources":["../../../../src/lib/nitro/analog-nitro-plugin.ts"],"sourcesContent":["import { existsSync, readFileSync, readdirSync } from 'node:fs';\nimport { mkdir, writeFile } from 'node:fs/promises';\nimport { dirname, relative, resolve } from 'node:path';\nimport type { Nitro, NitroEventHandler, PrerenderRoute } from 'nitro/types';\nimport type { Plugin, UserConfig } from 'vite';\n\nimport type { Options } from '../options.js';\nimport type {\n PrerenderContentDir,\n PrerenderContentFile,\n PrerenderRouteConfig,\n PrerenderSitemapConfig,\n} from './types.js';\nimport { getPageHandlers } from './get-page-handlers.js';\nimport { pageEndpointsPlugin } from './page-endpoints-plugin.js';\nimport { getMatchingContentFilesWithFrontMatter } from './get-content-files.js';\nimport { buildSitemap } from './build-sitemap.js';\nimport { addPostRenderingHooks } from './post-rendering-hook.js';\nimport {\n expandRoutesWithLocales,\n createI18nPostRenderingHook,\n} from './i18n-prerender.js';\nimport { angularLinkerPlugin } from './angular-linker-plugin.js';\n\nconst SSR_ENTRY_VIRTUAL_ID = '\\0virtual:@analogjs/nitro/ssr-entry';\n\n/**\n * Angular packages that ship in partial-compilation form and must pass\n * through the linker before the SSR / nitro bundle can execute without\n * JIT. Wired into `ssr.optimizeDeps.rolldownOptions.plugins`.\n */\nconst ANGULAR_SSR_DEPS = [\n '@angular/compiler',\n '@angular/core',\n '@angular/common',\n '@angular/platform-browser',\n '@angular/platform-server',\n];\n\ninterface NitroPluginContext {\n workspaceRoot: string;\n rootDir: string;\n sourceRoot: string;\n}\n\ntype RouteSitemap =\n | PrerenderSitemapConfig\n | (() => PrerenderSitemapConfig)\n | undefined;\n\n/**\n * Analog's NitroModule. Plug it into the Vite plugin chain alongside\n * `nitro()` from `nitro/vite`; nitro/vite picks up the `.nitro` property\n * and runs `setup(nitro)` once the Nitro instance is ready.\n */\nexport function analogNitroPlugin(options: Options = {}): Plugin {\n const workspaceRoot =\n options.workspaceRoot ?? process.env['NX_WORKSPACE_ROOT'] ?? process.cwd();\n const sourceRoot = 'src';\n const ssr = options.ssr ?? true;\n const apiPrefix = options.apiPrefix ?? 'api';\n\n let context: NitroPluginContext = {\n workspaceRoot,\n rootDir: '.',\n sourceRoot,\n };\n let ssrEntryMarkerPath = '';\n let userPublicDir: string | undefined;\n\n function refreshContext(viteRoot: string | undefined) {\n const root = viteRoot ?? process.cwd();\n context = {\n workspaceRoot,\n rootDir: relative(workspaceRoot, root) || '.',\n sourceRoot,\n };\n ssrEntryMarkerPath = resolve(\n context.workspaceRoot,\n context.rootDir,\n '.analog/__ssr-entry.mjs',\n );\n }\n\n function readIndexHtml(): string {\n const indexFile = options.index ?? 'index.html';\n const candidates = [\n resolve(context.workspaceRoot, context.rootDir, indexFile),\n resolve(\n context.workspaceRoot,\n 'dist',\n context.rootDir,\n 'client',\n indexFile,\n ),\n ];\n for (const candidate of candidates) {\n if (existsSync(candidate)) {\n return readFileSync(candidate, 'utf-8');\n }\n }\n return '<!doctype html><html><body><div id=\"app\"></div></body></html>';\n }\n\n function resolveEntryServer(): string {\n return (\n options.entryServer ??\n resolve(\n context.workspaceRoot,\n context.rootDir,\n `${sourceRoot}/main.server.ts`,\n )\n );\n }\n\n const plugin: Plugin & {\n nitro: { setup: (nitro: Nitro) => void | Promise<void> };\n } = {\n name: '@analogjs/nitro',\n enforce: 'pre',\n\n config(userConfig) {\n refreshContext(userConfig.root);\n\n // Capture the user's Vite `publicDir` so the nitro `setup()` hook can\n // register it as a Nitro `publicAssets` source. nitro/vite forces the\n // client environment's `build.copyPublicDir` to `false`\n // (vite.mjs:248), expecting Nitro to manage public assets — but\n // doesn't auto-add the user's `publicDir`. Without this, anything\n // under `src/public/` (e.g. `/assets/shipping.json`) 404s during SSR\n // and ofetch consumers parse the catch-all SSR HTML as JSON.\n if (userConfig.publicDir !== false) {\n userPublicDir = resolve(\n context.workspaceRoot,\n context.rootDir,\n (userConfig.publicDir as string | undefined) ?? 'public',\n );\n }\n\n // Bridge the legacy `BUILD_PRESET` env var that `@analogjs/vite-plugin-nitro`\n // accepted into Nitro v3's `NITRO_PRESET`, and auto-pick the matching\n // preset when the build runs inside a host's CI (each host sets its\n // own well-known env var). Mirrors the legacy plugin's behavior so\n // users upgrading don't need to change their CI configuration.\n if (!process.env['NITRO_PRESET']) {\n if (process.env['BUILD_PRESET']) {\n process.env['NITRO_PRESET'] = process.env['BUILD_PRESET'];\n } else if (process.env['VERCEL']) {\n process.env['NITRO_PRESET'] = 'vercel';\n } else if (process.env['NETLIFY']) {\n process.env['NITRO_PRESET'] = 'netlify';\n } else if (process.env['CF_PAGES']) {\n process.env['NITRO_PRESET'] = 'cloudflare-pages';\n }\n }\n\n const overrides: UserConfig = {\n // Vite 8 defaults `server.fs.allow` to `[searchForWorkspaceRoot(root)]`,\n // which should already cover the workspace root. In practice, nitro/vite's\n // env-runner loads its own `dev-entry.mjs` from a pnpm content-hash path\n // (`node_modules/.pnpm/nitro@.../...`) through Vite's ModuleRunner and\n // hits an `ERR_LOAD_URL`/\"Does the file exist?\" error unless an explicit\n // allow entry covers the same root. Whitelist the workspace root here so\n // users don't have to write the workaround in every vite.config.ts.\n server: {\n fs: {\n allow: [context.workspaceRoot],\n },\n },\n };\n\n if (ssr) {\n // Two-pronged registration: `experimental.vite.services.ssr.entry`\n // is the documented hook, but nitro/vite's setupNitroContext also\n // accepts an `environments.ssr.build.rollupOptions.input` entry\n // (see node_modules/nitro/dist/vite.mjs:710-734). When `analog()`\n // and `nitro()` are invoked separately, the `services` slot on\n // `nitro()`'s pluginConfig is empty, so the rollupOptions.input\n // path is how we get our wrapper entry recognized.\n overrides.experimental = {\n vite: {\n services: {\n ssr: { entry: ssrEntryMarkerPath },\n },\n },\n };\n overrides.environments = {\n ssr: {\n build: {\n outDir: resolve(\n context.workspaceRoot,\n 'dist',\n context.rootDir,\n 'ssr',\n ),\n rollupOptions: {\n input: { index: ssrEntryMarkerPath },\n },\n },\n optimizeDeps: {\n include: ANGULAR_SSR_DEPS,\n rolldownOptions: {\n plugins: [angularLinkerPlugin()],\n },\n },\n },\n } as UserConfig['environments'];\n }\n\n return overrides;\n },\n\n resolveId(id) {\n if (id === ssrEntryMarkerPath || id === SSR_ENTRY_VIRTUAL_ID) {\n return SSR_ENTRY_VIRTUAL_ID;\n }\n return null;\n },\n\n load(id) {\n if (id !== SSR_ENTRY_VIRTUAL_ID) return null;\n return generateSsrEntryWrapper(resolveEntryServer(), readIndexHtml());\n },\n\n nitro: {\n async setup(nitro) {\n // refreshContext may not have run yet if nitro/vite resolved the\n // plugin before `config()`; fall back to nitro's own root.\n if (!context || context.rootDir === '.') {\n refreshContext(nitro.options.rootDir);\n }\n\n // Preserve the legacy `@analogjs/vite-plugin-nitro` final output\n // layout so downstream tooling (deploy scripts, docs, the\n // `dist/analog/server` start command) keeps working. nitro/vite's\n // default `<rootDir>/.output` would otherwise drop artifacts in an\n // unexpected location for users upgrading from v2.\n //\n // Build only. During dev, leaving the output paths at Nitro's\n // defaults keeps the dev server's `readAsset` happy — those\n // virtuals expect to read from the in-memory module graph, not\n // from a `dist/` directory that doesn't exist yet.\n //\n // `buildDir` (Nitro's intermediate scratch dir) stays at its default\n // inside the project root. Nitro's prerender phase re-bundles SSR\n // chunks out of `<buildDir>/vite/services/ssr/`, and Rolldown's\n // resolver walks up from those files looking for `node_modules/`.\n // Keeping `buildDir` adjacent to the project root means workspace\n // packages installed at `<rootDir>/node_modules/` (the usual install\n // shape for both standalone and Nx setups) remain reachable.\n if (!nitro.options.dev) {\n // Deployment presets (Vercel, Netlify, Cloudflare, Firebase, ...)\n // own their own output layout — Vercel writes the Build Output API\n // tree under `.vercel/output/`, Netlify expects functions under\n // `.netlify/functions-internal/` with static assets under `dist/`,\n // and so on. Clobbering `output.{dir,publicDir,serverDir}` for\n // those presets leaves functions and static files in different\n // trees and breaks the deploy. Only override when running the\n // default node-server preset (or no preset at all) so docs and\n // the legacy `dist/analog/server` start command keep working for\n // standalone Node deployments.\n const preset = (nitro.options.preset ?? '').toLowerCase();\n const isManagedPreset =\n preset !== '' &&\n preset !== 'node-server' &&\n preset !== 'node' &&\n preset !== 'nitro-dev';\n\n // Vercel's Build Output API expects `.vercel/output/` at the cwd\n // `vercel build` runs from (the repo root). Nitro's preset anchors\n // to `{{rootDir}}`, so in Nx monorepos artifacts land at\n // `apps/<name>/.vercel/output/` and the deploy can't find them.\n // Hoist to workspace root and apply Analog's runtime defaults.\n if (preset.includes('vercel')) {\n const vercel = (nitro.options as { vercel?: Record<string, any> })\n .vercel;\n (nitro.options as { vercel?: Record<string, any> }).vercel = {\n ...vercel,\n entryFormat: vercel?.entryFormat ?? 'node',\n functions: {\n runtime: vercel?.functions?.runtime ?? 'nodejs24.x',\n ...vercel?.functions,\n },\n };\n const vercelDir = resolve(context.workspaceRoot, '.vercel/output');\n nitro.options.output = {\n ...nitro.options.output,\n dir: vercelDir,\n serverDir: resolve(vercelDir, 'functions/__server.func'),\n publicDir: resolve(vercelDir, 'static'),\n };\n }\n\n // Netlify auto-discovers functions under\n // `<workspaceRoot>/.netlify/functions-internal/`. Nitro's netlify\n // preset anchors that to `{{rootDir}}`, which in Nx monorepos\n // becomes `apps/<name>/.netlify/...` and is invisible to the\n // Netlify deploy. Hoist the functions to the workspace root so\n // `nx build <app>` produces a deploy-ready tree at the repo root.\n // Keep `publicDir` under `dist/<rootDir>/analog/public/` (the\n // legacy Analog Netlify publish layout) — the user wires their\n // `netlify.toml` publish path to it.\n if (preset === 'netlify' || preset === 'netlify-edge') {\n const netlifyDir = resolve(\n context.workspaceRoot,\n '.netlify/functions-internal',\n );\n nitro.options.output = {\n ...nitro.options.output,\n dir: netlifyDir,\n serverDir: resolve(netlifyDir, 'server'),\n publicDir: resolve(\n context.workspaceRoot,\n 'dist',\n context.rootDir,\n 'analog/public',\n ),\n };\n }\n\n // Cloudflare Pages/Workers presets anchor their output at\n // `{{rootDir}}/dist` or `{{rootDir}}/.output`, which puts the\n // deploy tree at `apps/<name>/...` for Nx monorepos. Hoist to\n // `<workspaceRoot>/dist/<rootDir>/` so `wrangler pages deploy\n // dist/<rootDir>` from the workspace root finds `_worker.js/`\n // alongside the static assets.\n if (preset.includes('cloudflare')) {\n const cfDir = resolve(\n context.workspaceRoot,\n 'dist',\n context.rootDir,\n );\n nitro.options.output = {\n ...nitro.options.output,\n dir: cfDir,\n publicDir: cfDir,\n serverDir: resolve(cfDir, '_worker.js'),\n };\n }\n\n if (!isManagedPreset) {\n const distRoot = resolve(\n context.workspaceRoot,\n 'dist',\n context.rootDir,\n );\n nitro.options.output = {\n ...nitro.options.output,\n dir: resolve(distRoot, 'analog'),\n publicDir: resolve(distRoot, 'analog/public'),\n serverDir: resolve(distRoot, 'analog/server'),\n };\n }\n\n // Nitro v3's prerender writer compares `filePath.startsWith(publicDir)`\n // with `filePath` built via `node:path.join` (platform-native\n // separators on Windows) and `publicDir` set via `resolveNitroPath`\n // (always forward slashes via pathe). On Windows the two sides\n // disagree and every route is marked `(skipped)` — no HTML is\n // written. Hook `prerender:route` and write the file ourselves\n // when Nitro has skipped it but the route generated content.\n nitro.hooks.hook('prerender:route', async (route) => {\n if (!route.skip || route.error) return;\n const buffer = route.data;\n if (!buffer || !route.fileName) return;\n const filePath = resolve(\n nitro.options.output.publicDir,\n route.fileName.replace(/^[\\\\/]+/, ''),\n );\n try {\n await mkdir(dirname(filePath), { recursive: true });\n await writeFile(filePath, Buffer.from(buffer));\n route.skip = false;\n } catch {\n // leave Nitro's skip in place if the manual write also fails\n }\n });\n }\n\n // Register the user's Vite `publicDir` (e.g. `src/public/`) as a\n // Nitro public asset source. nitro/vite turns off Vite's own copy\n // of publicDir so Nitro can take over, but doesn't auto-bridge the\n // user's setting — without this entry, files like\n // `src/public/assets/shipping.json` aren't served and `HttpClient`\n // SSR fetches fall through to the catch-all SSR renderer, leaking\n // HTML where consumers expected JSON.\n if (userPublicDir && existsSync(userPublicDir)) {\n const already = nitro.options.publicAssets.some(\n (asset) => asset.dir === userPublicDir,\n );\n if (!already) {\n nitro.options.publicAssets.push({\n dir: userPublicDir,\n baseURL: '/',\n maxAge: 0,\n fallthrough: true,\n });\n }\n }\n\n // Bridge the outer Nitro's `output.publicDir` into the prerender's\n // own Nitro instance. Nitro spawns a nested `nitroRenderer` for the\n // prerender pass (`createNitro({ preset: 'nitro-prerender' })`) and\n // builds the public-assets manifest by glob-scanning that\n // instance's `output.publicDir`. The nested config resets\n // `output.publicDir` to undefined and resolves it against the\n // prerender preset defaults (`<rootDir>/.output/public`), so the\n // scan hits an empty directory and the manifest is empty — every\n // `HttpClient.get('/assets/...')` during SSR then falls through to\n // the catch-all SSR renderer and the consumer parses HTML as JSON.\n // Force the nested publicDir to match the outer publicDir (which\n // `copyPublicAssets` has already populated by this point).\n nitro.hooks.hook(\n 'prerender:config',\n (prerendererConfig: { output?: Record<string, unknown> }) => {\n prerendererConfig.output = {\n ...prerendererConfig.output,\n publicDir: nitro.options.output.publicDir,\n };\n },\n );\n\n const hasAPIDir = existsSync(\n resolve(\n context.workspaceRoot,\n context.rootDir,\n `${context.sourceRoot}/server/routes/api`,\n ),\n );\n\n const pageHandlers: NitroEventHandler[] = getPageHandlers({\n workspaceRoot: context.workspaceRoot,\n sourceRoot: context.sourceRoot,\n rootDir: context.rootDir,\n additionalPagesDirs: options.additionalPagesDirs,\n hasAPIDir,\n });\n nitro.options.handlers.push(...pageHandlers);\n\n const serverDir = resolve(\n context.workspaceRoot,\n context.rootDir,\n `${context.sourceRoot}/server`,\n );\n if (\n existsSync(serverDir) &&\n !nitro.options.scanDirs.includes(serverDir)\n ) {\n nitro.options.scanDirs.push(serverDir);\n }\n\n nitro.hooks.hook('rollup:before', (_n, rollupConfig: any) => {\n if (Array.isArray(rollupConfig.plugins)) {\n rollupConfig.plugins.push(pageEndpointsPlugin());\n }\n applyAnalogNitroExternals(rollupConfig);\n sanitizeNitroBundlerConfig(rollupConfig);\n });\n\n if (ssr) {\n // Override Nitro's auto-detected template-serving renderer with one\n // that routes HTML requests to our SSR service. Nitro's\n // `resolveRendererOptions` finds `index.html` at the project root\n // and installs `internal/routes/renderer-template[.dev]`, which\n // just serves the raw template. nitro/vite's own SSR-routing\n // renderer only auto-installs when both `renderer.handler` and\n // `renderer.template` are empty (vite.mjs:574), which never holds\n // for a typical app — so we install our own renderer virtual\n // explicitly here.\n //\n // `#analog/ssr` is a Nitro virtual (not a Vite virtual) so it\n // resolves under both Vite-built bundles (main) and Rolldown-built\n // bundles (Nitro's prerender, which forces builder: 'rolldown' —\n // see nitro/dist/_chunks/nitro.mjs:769). That sidesteps nitro/vite's\n // prodSetup polyfill, which is Vite-only and leaves\n // `__nitro_vite_envs__` unset in the prerender bundle.\n nitro.options.virtual['#analog/ssr'] = () =>\n generateSsrServiceVirtual(nitro);\n nitro.options.virtual['#analog/ssr-renderer'] =\n generateSsrRendererVirtual(readIndexHtml());\n nitro.options.renderer ??= {};\n nitro.options.renderer.handler = '#analog/ssr-renderer';\n delete nitro.options.renderer.template;\n }\n // When ssr === false, Nitro's auto-detected template-serving\n // renderer is exactly what we want (serve the raw index.html for\n // every HTML request) — leave it in place.\n\n injectAnalogRouteRuleHeaders(nitro);\n\n await wirePrerender(nitro, options, context, apiPrefix);\n\n if (options.i18n) {\n addPostRenderingHooks(nitro, [\n createI18nPostRenderingHook({\n defaultLocale: options.i18n.defaultLocale,\n locales: options.i18n.locales,\n }),\n ]);\n }\n },\n },\n };\n\n return plugin;\n}\n\n/**\n * Builds the h3 handler installed as Nitro's `renderer.handler`. Short-circuits\n * `ssr: false` routes to the raw client template; otherwise dispatches the\n * request to the SSR service env (`fetchViteEnv(\"ssr\", req)` works in dev via\n * the env-runner and in prod via the `__nitro_vite_envs__` global set up by\n * nitro/vite's `prodSetup`).\n */\nfunction generateSsrRendererVirtual(template: string): string {\n return `\nimport { defineHandler } from 'nitro/h3';\nimport ssr from '#analog/ssr';\n\nconst TEMPLATE = ${JSON.stringify(template)};\n\nexport default defineHandler(async (event) => {\n event.res.headers.set('content-type', 'text/html; charset=utf-8');\n // 'x-analog-no-ssr' is stamped on response headers by\n // injectAnalogRouteRuleHeaders for routeRules with \\`ssr: false\\`. Nitro\n // applies routeRule headers to the response before the renderer fires,\n // so we can short-circuit by reading them here.\n if (event.res.headers.get('x-analog-no-ssr') === 'true') {\n return TEMPLATE;\n }\n const service = ssr.default ?? ssr;\n return service.fetch(event.req);\n});\n`;\n}\n\n/**\n * Resolves \\`#analog/ssr\\` to the SSR fetch handler. The shape returned by\n * this function is bundler-agnostic: works in Vite-built main bundles and\n * Rolldown-built prerender bundles alike.\n *\n * - Dev: dispatch through nitro/vite's env runner (\\`fetchViteEnv\\`); the SSR\n * service module isn't on disk yet, so we delegate to the runner.\n * - Build / prerender: re-export the built SSR entry directly from the\n * filesystem. By the time Nitro's bundlers ask for \\`#analog/ssr\\`, Vite has\n * already produced \\`<buildDir>/vite/services/ssr/<entry>.mjs\\`.\n */\nfunction generateSsrServiceVirtual(nitro: Nitro): string {\n if (nitro.options.dev) {\n return `\nimport { fetchViteEnv } from 'nitro/vite/runtime';\nexport default {\n async fetch(req) {\n return fetchViteEnv('ssr', req);\n },\n};\n`;\n }\n\n const ssrDir = resolve(nitro.options.buildDir, 'vite/services/ssr');\n if (!existsSync(ssrDir)) {\n return `export default { async fetch() { throw new Error('Analog SSR service directory missing: ${ssrDir}'); } };`;\n }\n const entries = readdirSync(ssrDir).filter((f) => f.endsWith('.mjs'));\n if (entries.length === 0) {\n return `export default { async fetch() { throw new Error('No Analog SSR entry file built in: ${ssrDir}'); } };`;\n }\n // Prefer 'main.server.mjs' if present; otherwise take the only entry.\n const entry = entries.find((f) => f === 'main.server.mjs') ?? entries[0];\n const entryPath = resolve(ssrDir, entry);\n return `export { default } from ${JSON.stringify(entryPath)};`;\n}\n\n/**\n * Packages Analog forces external in the Nitro server bundle. Each entry is\n * here for a specific reason — see comments.\n */\nconst ANALOG_NITRO_EXTERNALS = [\n // rxjs ships per-entry CJS/ESM facades that confuse the Nitro/Rolldown\n // resolver during bundling.\n 'rxjs',\n // node-fetch-native's polyfill subpath rewrites global fetch and isn't\n // safe to inline into the Nitro bundle.\n 'node-fetch-native/dist/polyfill',\n // sharp ships platform-specific native binaries under @img/sharp-*. pnpm\n // creates symlinks for ALL optional platform deps but only installs the\n // matching one, leaving broken symlinks that crash Nitro's externals\n // plugin with ENOENT during realpath(). Externalizing sharp avoids\n // bundling it; the user's app resolves it from node_modules at runtime.\n 'sharp',\n];\n\nfunction applyAnalogNitroExternals(rollupConfig: { external?: unknown }): void {\n // Rolldown's `external` only accepts `Array<string | RegExp>`; promote\n // whatever shape Nitro gave us (regex, single string, undefined) to an\n // array and append Analog's entries as regex patterns that also match\n // sub-paths (e.g. `sharp` matches `sharp/lib/foo`).\n const prev = rollupConfig.external;\n const existing: Array<string | RegExp> =\n prev === undefined\n ? []\n : Array.isArray(prev)\n ? (prev as Array<string | RegExp>)\n : prev instanceof RegExp\n ? [prev]\n : typeof prev === 'string'\n ? [prev]\n : [];\n\n const escapeRegExp = (s: string) => s.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&');\n\n for (const entry of ANALOG_NITRO_EXTERNALS) {\n const pattern = new RegExp(`^${escapeRegExp(entry)}(?:/|$)`);\n if (!existing.some((p) => String(p) === String(pattern))) {\n existing.push(pattern);\n }\n }\n\n rollupConfig.external = existing;\n}\n\n/**\n * Workarounds for Nitro v3 + Rolldown bundler interaction quirks. Each\n * is narrowly scoped and can be removed once the upstream bug is fixed:\n *\n * 1. `output.codeSplitting` — Nitro 3.0.x sets this; Rolldown rejects it\n * as an unknown key.\n * 2. `output.manualChunks` — Nitro's default manual chunking crashes\n * Nitro's prerender rebundle.\n * 3. `output.chunkFileNames` — Nitro's chunk-name function produces\n * route-derived `[token]` patterns which Rollup/Rolldown interprets as\n * placeholders; we rewrite non-standard tokens to `_token_`.\n */\nfunction sanitizeNitroBundlerConfig(rollupConfig: { output?: unknown }): void {\n const output = rollupConfig.output;\n if (!output || Array.isArray(output) || typeof output !== 'object') return;\n const out = output as Record<string, unknown>;\n\n if ('codeSplitting' in out) delete out['codeSplitting'];\n if ('manualChunks' in out) delete out['manualChunks'];\n\n const VALID_ROLLUP_PLACEHOLDER = /^\\[(?:name|hash|format|ext)\\]$/;\n const chunkFileNames = out['chunkFileNames'];\n if (typeof chunkFileNames === 'function') {\n const originalFn = chunkFileNames as (...args: unknown[]) => unknown;\n out['chunkFileNames'] = (...args: unknown[]) => {\n const result = originalFn(...args);\n if (typeof result !== 'string') return result;\n return result.replace(/\\[[^\\]]+\\]/g, (match: string) =>\n VALID_ROLLUP_PLACEHOLDER.test(match)\n ? match\n : `_${match.slice(1, -1)}_`,\n );\n };\n }\n}\n\n/**\n * Walks Nitro's resolved routeRules and stamps `x-analog-no-ssr: true` onto\n * any rule with `ssr: false`. Kept as a response-header hint for downstream\n * consumers (CDN, edge logic); the actual SSR short-circuit happens inside\n * the SSR renderer virtual above.\n */\nfunction injectAnalogRouteRuleHeaders(nitro: Nitro): void {\n const routeRules = nitro.options.routeRules as\n | Record<string, { ssr?: boolean; headers?: Record<string, string> }>\n | undefined;\n if (!routeRules) return;\n\n for (const rule of Object.values(routeRules)) {\n if (rule?.ssr === false) {\n rule.headers = { ...rule.headers, 'x-analog-no-ssr': 'true' };\n }\n }\n}\n\n/**\n * Builds the SSR service entry source. The wrapper imports the user's\n * `main.server.ts` Angular renderer and adapts it to the `{ fetch(req) }`\n * shape that nitro/vite's service mechanism expects.\n */\nfunction generateSsrEntryWrapper(\n entryServer: string,\n template: string,\n): string {\n return `\n// Import \\`serverFetch\\` from the root \\`nitro\\` entry rather than \\`nitro/app\\`.\n// The /app subpath creates a fresh \\`useNitroApp()\\` instance scoped to the\n// importing bundle, which in our setup is the standalone SSR vite bundle —\n// it has no route handlers, so every fetch 404s. The root entry instead\n// reads \\`globalThis.__nitro__.{default,prerender}\\`, which the surrounding\n// Nitro server (prerender pass or production runtime) has already\n// populated with the real app + handlers.\nimport { serverFetch as nitroServerFetch } from 'nitro';\nimport { createFetch } from 'ofetch';\nimport renderer from ${JSON.stringify(entryServer)};\n\nconst TEMPLATE = ${JSON.stringify(template)};\n\nconst normalizeRequestPath = (url) =>\n url.replace(/\\\\/index\\\\.html(?=$|[?#])/, '/');\n\n// In-process fetch wired into Nitro's request pipeline. Angular's HttpClient\n// (via withFetch()) and Analog's injectLoad() call this during SSR/prerender\n// so they hit the running app's page-endpoint and API routes without going\n// through the network — the prerender pipeline doesn't have a listening\n// socket. Without this, every SSR data fetch ECONNREFUSEs and Angular's\n// router fails to resolve any data-bound route, producing an empty\n// <router-outlet/> in the prerendered HTML.\nconst ssrFetch = (resource, init) => {\n let url = typeof resource === 'string'\n ? resource\n : resource instanceof URL\n ? resource.href\n : resource.url;\n // Relative URLs from injectAPIPrefix() etc. need a host for Nitro's\n // Request constructor to accept them.\n if (typeof url === 'string' && url.startsWith('/')) {\n url = 'http://localhost' + url;\n }\n return nitroServerFetch(url, init);\n};\n\n// Wrap in ofetch so consumers that expect \\`$fetch.raw()\\` (the router's\n// request-context interceptor short-circuits SSR HttpClient calls through\n// \\`globalThis.$fetch.raw\\`) can call it. Set on globalThis so router code\n// running inside the Angular renderer can find it.\nconst ssrOFetch = createFetch({ fetch: ssrFetch });\nif (typeof globalThis.$fetch === 'undefined') {\n globalThis.$fetch = ssrOFetch;\n}\n\nexport default {\n async fetch(req) {\n const url = new URL(req.url);\n const requestPath = normalizeRequestPath(url.pathname);\n // Preserve the query string so Angular's router + injectQuery() and\n // server data loaders that read from req.url see the full path+query.\n const requestUrl = requestPath + url.search;\n\n if (req.headers.get('x-analog-no-ssr') === 'true') {\n return new Response(TEMPLATE, {\n status: 200,\n headers: { 'content-type': 'text/html; charset=utf-8' },\n });\n }\n\n const reqShim = {\n headers: Object.fromEntries(req.headers.entries()),\n url: requestUrl,\n originalUrl: requestUrl,\n connection: {},\n };\n\n try {\n const html = await renderer(requestUrl, TEMPLATE, {\n req: reqShim,\n // Pass the ofetch-wrapped fetch — INTERNAL_FETCH is consumed by the\n // router's request-context interceptor via \\`serverFetch.raw(...)\\`,\n // which is ofetch's response-shape API. Plain fetch lacks \\`.raw\\`\n // and throws TypeError during prerender/SSR.\n fetch: ssrOFetch,\n });\n return new Response(html, {\n status: 200,\n headers: { 'content-type': 'text/html; charset=utf-8' },\n });\n } catch (err) {\n console.error('[analog ssr]', err);\n return new Response(TEMPLATE, {\n status: 500,\n headers: { 'content-type': 'text/html; charset=utf-8' },\n });\n }\n },\n};\n`;\n}\n\nasync function wirePrerender(\n nitro: Nitro,\n options: Options,\n context: NitroPluginContext,\n apiPrefix: string,\n): Promise<void> {\n const prerender = options.prerender;\n if (!prerender && !options.i18n) return;\n\n const {\n routes: collected,\n sitemaps: routeSitemaps,\n routeSourceFiles,\n } = await collectRoutes(prerender?.routes, context, apiPrefix);\n\n const expanded = options.i18n\n ? expandRoutesWithLocales(collected, {\n defaultLocale: options.i18n.defaultLocale,\n locales: options.i18n.locales,\n })\n : collected;\n\n const nitroPrerender = (nitro.options.prerender ??= {}) as Record<\n string,\n any\n >;\n nitroPrerender.routes ??= [];\n nitroPrerender.routes.push(...expanded);\n if (prerender?.discover ?? false) {\n nitroPrerender.crawlLinks = true;\n }\n\n if (prerender?.postRenderingHooks?.length) {\n addPostRenderingHooks(nitro, prerender.postRenderingHooks);\n }\n\n if (Object.keys(routeSourceFiles).length > 0) {\n // Mirror the legacy `@analogjs/vite-plugin-nitro` behavior: after\n // prerender completes, write the route's source content alongside the\n // prerendered HTML at `<publicDir>/<route>.md`. Drives the\n // `outputSourceFile` option on both `PrerenderRouteConfig` (string path\n // to source markdown) and `PrerenderContentDir` (per-file callback).\n nitro.hooks.hook('prerender:done', async () => {\n const publicDir = resolve(nitro.options.output.publicDir);\n const { mkdirSync, writeFileSync } = await import('node:fs');\n const { dirname, join } = await import('node:path');\n for (const [route, content] of Object.entries(routeSourceFiles)) {\n const outputPath = join(publicDir, `${route}.md`);\n mkdirSync(dirname(outputPath), { recursive: true });\n writeFileSync(outputPath, content, 'utf8');\n }\n });\n }\n\n const sitemapConfig = prerender?.sitemap;\n if (sitemapConfig) {\n nitro.hooks.hook('prerender:done', async (result) => {\n const prerenderedRoutes = (result?.prerenderedRoutes ?? []).map(\n (r: PrerenderRoute) => r.route,\n );\n const publicDir = resolve(nitro.options.output.publicDir);\n await buildSitemap(\n {} as any,\n sitemapConfig,\n prerenderedRoutes,\n publicDir,\n routeSitemaps,\n { apiPrefix },\n );\n });\n }\n}\n\nasync function collectRoutes(\n routesInput: Options['prerender'] extends infer P\n ? P extends { routes?: infer R }\n ? R\n : never\n : never,\n context: NitroPluginContext,\n apiPrefix: string,\n): Promise<{\n routes: string[];\n sitemaps: Record<string, RouteSitemap>;\n routeSourceFiles: Record<string, string>;\n}> {\n const out: string[] = [];\n const sitemaps: Record<string, RouteSitemap> = {};\n const routeSourceFiles: Record<string, string> = {};\n\n if (!routesInput) return { routes: out, sitemaps, routeSourceFiles };\n\n const inputs = Array.isArray(routesInput)\n ? routesInput\n : typeof routesInput === 'function'\n ? await routesInput()\n : [];\n\n for (const entry of inputs) {\n if (!entry) continue;\n\n if (typeof entry === 'string') {\n out.push(entry);\n continue;\n }\n\n if ('contentDir' in entry) {\n const dir = entry as PrerenderContentDir;\n const files = getMatchingContentFilesWithFrontMatter(\n context.workspaceRoot,\n context.rootDir,\n dir.contentDir,\n !!dir.recursive,\n );\n for (const file of files) {\n const route = dir.transform(file);\n if (route === false) continue;\n out.push(route);\n if (dir.sitemap) {\n sitemaps[route] =\n typeof dir.sitemap === 'function'\n ? (\n dir.sitemap as (\n f: PrerenderContentFile,\n ) => PrerenderSitemapConfig\n )(file)\n : dir.sitemap;\n }\n if (dir.outputSourceFile) {\n const sourceContent = dir.outputSourceFile(file);\n if (typeof sourceContent === 'string') {\n routeSourceFiles[route] = sourceContent;\n }\n }\n }\n continue;\n }\n\n if ('route' in entry) {\n const cfg = entry as PrerenderRouteConfig;\n out.push(cfg.route);\n if (cfg.sitemap) {\n sitemaps[cfg.route] = cfg.sitemap;\n }\n if (cfg.outputSourceFile) {\n const sourcePath = resolve(\n context.workspaceRoot,\n context.rootDir,\n cfg.outputSourceFile,\n );\n if (existsSync(sourcePath)) {\n routeSourceFiles[cfg.route] = readFileSync(sourcePath, 'utf8');\n }\n }\n if (cfg.staticData) {\n // Mirror the legacy plugin: when staticData is requested, also\n // prerender the page's data-fetching endpoint so the JSON payload\n // is available statically.\n const prefix = apiPrefix.startsWith('/') ? apiPrefix : `/${apiPrefix}`;\n const route = cfg.route.startsWith('/') ? cfg.route : `/${cfg.route}`;\n out.push(`${prefix}/_analog/pages${route}`);\n }\n }\n }\n\n return { routes: out, sitemaps, routeSourceFiles };\n}\n"],"mappings":";;;;;;;;;;;AAwBA,IAAM,uBAAuB;;;;;;AAO7B,IAAM,mBAAmB;CACvB;CACA;CACA;CACA;CACA;CACD;;;;;;AAkBD,SAAgB,kBAAkB,UAAmB,EAAE,EAAU;CAC/D,MAAM,gBACJ,QAAQ,iBAAiB,QAAQ,IAAI,wBAAwB,QAAQ,KAAK;CAC5E,MAAM,aAAa;CACnB,MAAM,MAAM,QAAQ,OAAO;CAC3B,MAAM,YAAY,QAAQ,aAAa;CAEvC,IAAI,UAA8B;EAChC;EACA,SAAS;EACT;EACD;CACD,IAAI,qBAAqB;CACzB,IAAI;CAEJ,SAAS,eAAe,UAA8B;AAEpD,YAAU;GACR;GACA,SAAS,SAAS,eAHP,YAAY,QAAQ,KAAK,CAGE,IAAI;GAC1C;GACD;AACD,uBAAqB,QACnB,QAAQ,eACR,QAAQ,SACR,0BACD;;CAGH,SAAS,gBAAwB;EAC/B,MAAM,YAAY,QAAQ,SAAS;EACnC,MAAM,aAAa,CACjB,QAAQ,QAAQ,eAAe,QAAQ,SAAS,UAAU,EAC1D,QACE,QAAQ,eACR,QACA,QAAQ,SACR,UACA,UACD,CACF;AACD,OAAK,MAAM,aAAa,WACtB,KAAI,WAAW,UAAU,CACvB,QAAO,aAAa,WAAW,QAAQ;AAG3C,SAAO;;CAGT,SAAS,qBAA6B;AACpC,SACE,QAAQ,eACR,QACE,QAAQ,eACR,QAAQ,SACR,GAAG,WAAW,iBACf;;AAyYL,QAnYI;EACF,MAAM;EACN,SAAS;EAET,OAAO,YAAY;AACjB,kBAAe,WAAW,KAAK;AAS/B,OAAI,WAAW,cAAc,MAC3B,iBAAgB,QACd,QAAQ,eACR,QAAQ,SACP,WAAW,aAAoC,SACjD;AAQH,OAAI,CAAC,QAAQ,IAAI;QACX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rolldownOptions.plugins` so the SSR /
6
+ * `nitro` environment's dep optimizer turns `ɵɵngDeclare*` partial
7
+ * declarations into fully-compiled definitions. Without this, the
8
+ * server bundle would need JIT (eval) at runtime — forbidden on
9
+ * `workerd` / edge runtimes and unnecessary anywhere else.
10
+ *
11
+ * Loaded lazily so apps that never trigger the SSR optimizer don't
12
+ * incur the babel + compiler-cli/linker cost.
13
+ */
14
+ export declare function angularLinkerPlugin(): {
15
+ name: string;
16
+ transform(code: string, id: string);
17
+ };