@analogjs/vite-plugin-nitro 3.0.0-alpha.4 → 3.0.0-alpha.41

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 (57) hide show
  1. package/package.json +26 -11
  2. package/src/index.d.ts +11 -9
  3. package/src/index.js +7 -2
  4. package/src/index.js.map +1 -1
  5. package/src/lib/build-server.d.ts +2 -2
  6. package/src/lib/build-server.js +45 -149
  7. package/src/lib/build-server.js.map +1 -1
  8. package/src/lib/build-sitemap.d.ts +23 -9
  9. package/src/lib/build-sitemap.js +132 -63
  10. package/src/lib/build-sitemap.js.map +1 -1
  11. package/src/lib/build-ssr.d.ts +3 -2
  12. package/src/lib/build-ssr.js +26 -18
  13. package/src/lib/build-ssr.js.map +1 -1
  14. package/src/lib/hooks/post-rendering-hook.d.ts +1 -1
  15. package/src/lib/hooks/post-rendering-hook.js +10 -6
  16. package/src/lib/hooks/post-rendering-hook.js.map +1 -1
  17. package/src/lib/options.d.ts +143 -106
  18. package/src/lib/plugins/dev-server-plugin.d.ts +3 -3
  19. package/src/lib/plugins/dev-server-plugin.js +98 -101
  20. package/src/lib/plugins/dev-server-plugin.js.map +1 -1
  21. package/src/lib/plugins/page-endpoints.d.ts +5 -5
  22. package/src/lib/plugins/page-endpoints.js +26 -57
  23. package/src/lib/plugins/page-endpoints.js.map +1 -1
  24. package/src/lib/utils/debug.d.ts +5 -0
  25. package/src/lib/utils/debug.js +15 -0
  26. package/src/lib/utils/debug.js.map +1 -0
  27. package/src/lib/utils/get-content-files.d.ts +54 -54
  28. package/src/lib/utils/get-content-files.js +88 -97
  29. package/src/lib/utils/get-content-files.js.map +1 -1
  30. package/src/lib/utils/get-page-handlers.d.ts +58 -58
  31. package/src/lib/utils/get-page-handlers.js +70 -84
  32. package/src/lib/utils/get-page-handlers.js.map +1 -1
  33. package/src/lib/utils/i18n-prerender.d.ts +36 -0
  34. package/src/lib/utils/i18n-prerender.js +23 -0
  35. package/src/lib/utils/i18n-prerender.js.map +1 -0
  36. package/src/lib/utils/load-esm.d.ts +18 -18
  37. package/src/lib/utils/node-web-bridge.d.ts +1 -1
  38. package/src/lib/utils/node-web-bridge.js +50 -45
  39. package/src/lib/utils/node-web-bridge.js.map +1 -1
  40. package/src/lib/utils/register-dev-middleware.d.ts +12 -12
  41. package/src/lib/utils/register-dev-middleware.js +41 -47
  42. package/src/lib/utils/register-dev-middleware.js.map +1 -1
  43. package/src/lib/utils/register-i18n-watcher.d.ts +15 -0
  44. package/src/lib/utils/renderers.d.ts +47 -47
  45. package/src/lib/utils/renderers.js +57 -56
  46. package/src/lib/utils/renderers.js.map +1 -1
  47. package/src/lib/utils/rolldown.d.ts +2 -0
  48. package/src/lib/utils/rolldown.js +12 -0
  49. package/src/lib/utils/rolldown.js.map +1 -0
  50. package/src/lib/vite-plugin-nitro.d.ts +3 -3
  51. package/src/lib/vite-plugin-nitro.js +790 -677
  52. package/src/lib/vite-plugin-nitro.js.map +1 -1
  53. package/README.md +0 -125
  54. package/src/lib/options.js +0 -2
  55. package/src/lib/options.js.map +0 -1
  56. package/src/lib/utils/load-esm.js +0 -23
  57. package/src/lib/utils/load-esm.js.map +0 -1
@@ -1,50 +1,44 @@
1
- import { H3 } from 'nitro/h3';
2
- import { globSync } from 'tinyglobby';
3
- import { toWebRequest, writeWebResponseToNode } from './node-web-bridge.js';
4
- const PASSTHROUGH_HEADER = 'x-analog-passthrough';
1
+ import { toWebRequest, writeWebResponseToNode } from "./node-web-bridge.js";
2
+ import { globSync } from "tinyglobby";
3
+ import { H3 } from "nitro/h3";
4
+ //#region packages/vite-plugin-nitro/src/lib/utils/register-dev-middleware.ts
5
+ var PASSTHROUGH_HEADER = "x-analog-passthrough";
5
6
  /**
6
- * Registers development server middleware by discovering and loading middleware files.
7
- *
8
- * Each discovered h3 middleware module is loaded through Vite's SSR loader,
9
- * wrapped in a temporary H3 app, then bridged back into Vite's Connect stack.
10
- * If the middleware does not write a response, control falls through to the
11
- * next Vite middleware.
12
- *
13
- * @param root The project root directory path
14
- * @param sourceRoot The source directory path (e.g., 'src')
15
- * @param viteServer The Vite development server instance
16
- */
17
- export async function registerDevServerMiddleware(root, sourceRoot, viteServer) {
18
- const middlewareFiles = globSync([`${root}/${sourceRoot}/server/middleware/**/*.ts`], {
19
- dot: true,
20
- absolute: true,
21
- });
22
- middlewareFiles.forEach((file) => {
23
- // Create the H3 app once per middleware file (not per request).
24
- // The dynamic handler inside still loads the module fresh each request
25
- // via ssrLoadModule, preserving HMR.
26
- const app = new H3();
27
- app.use(async (event) => {
28
- const handler = await viteServer
29
- .ssrLoadModule(file)
30
- .then((m) => m.default);
31
- return handler(event);
32
- });
33
- // Sentinel catch-all: when the middleware returns undefined (does not
34
- // handle the request), h3 does not emit its default 404 — instead we
35
- // detect the passthrough header and let the Connect stack continue.
36
- app.use(() => new Response(null, {
37
- status: 204,
38
- headers: { [PASSTHROUGH_HEADER]: '1' },
39
- }));
40
- viteServer.middlewares.use(async (req, res, next) => {
41
- const response = await app.fetch(toWebRequest(req));
42
- if (response.headers.get(PASSTHROUGH_HEADER) === '1') {
43
- next();
44
- return;
45
- }
46
- await writeWebResponseToNode(res, response);
47
- });
48
- });
7
+ * Registers development server middleware by discovering and loading middleware files.
8
+ *
9
+ * Each discovered h3 middleware module is loaded through Vite's SSR loader,
10
+ * wrapped in a temporary H3 app, then bridged back into Vite's Connect stack.
11
+ * If the middleware does not write a response, control falls through to the
12
+ * next Vite middleware.
13
+ *
14
+ * @param root The project root directory path
15
+ * @param sourceRoot The source directory path (e.g., 'src')
16
+ * @param viteServer The Vite development server instance
17
+ */
18
+ async function registerDevServerMiddleware(root, sourceRoot, viteServer) {
19
+ globSync([`${root}/${sourceRoot}/server/middleware/**/*.ts`], {
20
+ dot: true,
21
+ absolute: true
22
+ }).forEach((file) => {
23
+ const app = new H3();
24
+ app.use(async (event) => {
25
+ return (await viteServer.ssrLoadModule(file).then((m) => m.default))(event);
26
+ });
27
+ app.use(() => new Response(null, {
28
+ status: 204,
29
+ headers: { [PASSTHROUGH_HEADER]: "1" }
30
+ }));
31
+ viteServer.middlewares.use(async (req, res, next) => {
32
+ const response = await app.fetch(toWebRequest(req));
33
+ if (response.headers.get(PASSTHROUGH_HEADER) === "1") {
34
+ next();
35
+ return;
36
+ }
37
+ await writeWebResponseToNode(res, response);
38
+ });
39
+ });
49
40
  }
41
+ //#endregion
42
+ export { registerDevServerMiddleware };
43
+
50
44
  //# sourceMappingURL=register-dev-middleware.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"register-dev-middleware.js","sourceRoot":"","sources":["../../../../../../packages/vite-plugin-nitro/src/lib/utils/register-dev-middleware.ts"],"names":[],"mappings":"AACA,OAAO,EAAgB,EAAE,EAAE,MAAM,UAAU,CAAC;AAC5C,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAEtC,OAAO,EAAE,YAAY,EAAE,sBAAsB,EAAE,MAAM,sBAAsB,CAAC;AAE5E,MAAM,kBAAkB,GAAG,sBAAsB,CAAC;AAElD;;;;;;;;;;;GAWG;AACH,MAAM,CAAC,KAAK,UAAU,2BAA2B,CAC/C,IAAY,EACZ,UAAkB,EAClB,UAAyB;IAEzB,MAAM,eAAe,GAAG,QAAQ,CAC9B,CAAC,GAAG,IAAI,IAAI,UAAU,4BAA4B,CAAC,EACnD;QACE,GAAG,EAAE,IAAI;QACT,QAAQ,EAAE,IAAI;KACf,CACF,CAAC;IAEF,eAAe,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE;QAC/B,gEAAgE;QAChE,uEAAuE;QACvE,qCAAqC;QACrC,MAAM,GAAG,GAAG,IAAI,EAAE,EAAE,CAAC;QACrB,GAAG,CAAC,GAAG,CAAC,KAAK,EAAE,KAAK,EAAE,EAAE;YACtB,MAAM,OAAO,GAAiB,MAAM,UAAU;iBAC3C,aAAa,CAAC,IAAI,CAAC;iBACnB,IAAI,CAAC,CAAC,CAAU,EAAE,EAAE,CAAE,CAA+B,CAAC,OAAO,CAAC,CAAC;YAClE,OAAO,OAAO,CAAC,KAAK,CAAC,CAAC;QACxB,CAAC,CAAC,CAAC;QACH,sEAAsE;QACtE,qEAAqE;QACrE,oEAAoE;QACpE,GAAG,CAAC,GAAG,CACL,GAAG,EAAE,CACH,IAAI,QAAQ,CAAC,IAAI,EAAE;YACjB,MAAM,EAAE,GAAG;YACX,OAAO,EAAE,EAAE,CAAC,kBAAkB,CAAC,EAAE,GAAG,EAAE;SACvC,CAAC,CACL,CAAC;QAEF,UAAU,CAAC,WAAW,CAAC,GAAG,CAAC,KAAK,EAAE,GAAG,EAAE,GAAG,EAAE,IAAI,EAAE,EAAE;YAClD,MAAM,QAAQ,GAAG,MAAM,GAAG,CAAC,KAAK,CAAC,YAAY,CAAC,GAAG,CAAC,CAAC,CAAC;YAEpD,IAAI,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,kBAAkB,CAAC,KAAK,GAAG,EAAE,CAAC;gBACrD,IAAI,EAAE,CAAC;gBACP,OAAO;YACT,CAAC;YAED,MAAM,sBAAsB,CAAC,GAAG,EAAE,QAAQ,CAAC,CAAC;QAC9C,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC"}
1
+ {"version":3,"file":"register-dev-middleware.js","names":[],"sources":["../../../../src/lib/utils/register-dev-middleware.ts"],"sourcesContent":["import { ViteDevServer } from 'vite';\nimport { EventHandler, H3 } from 'nitro/h3';\nimport { globSync } from 'tinyglobby';\n\nimport { toWebRequest, writeWebResponseToNode } from './node-web-bridge.js';\n\nconst PASSTHROUGH_HEADER = 'x-analog-passthrough';\n\n/**\n * Registers development server middleware by discovering and loading middleware files.\n *\n * Each discovered h3 middleware module is loaded through Vite's SSR loader,\n * wrapped in a temporary H3 app, then bridged back into Vite's Connect stack.\n * If the middleware does not write a response, control falls through to the\n * next Vite middleware.\n *\n * @param root The project root directory path\n * @param sourceRoot The source directory path (e.g., 'src')\n * @param viteServer The Vite development server instance\n */\nexport async function registerDevServerMiddleware(\n root: string,\n sourceRoot: string,\n viteServer: ViteDevServer,\n): Promise<void> {\n const middlewareFiles = globSync(\n [`${root}/${sourceRoot}/server/middleware/**/*.ts`],\n {\n dot: true,\n absolute: true,\n },\n );\n\n middlewareFiles.forEach((file) => {\n // Create the H3 app once per middleware file (not per request).\n // The dynamic handler inside still loads the module fresh each request\n // via ssrLoadModule, preserving HMR.\n const app = new H3();\n app.use(async (event) => {\n const handler: EventHandler = await viteServer\n .ssrLoadModule(file)\n .then((m: unknown) => (m as { default: EventHandler }).default);\n return handler(event);\n });\n // Sentinel catch-all: when the middleware returns undefined (does not\n // handle the request), h3 does not emit its default 404 — instead we\n // detect the passthrough header and let the Connect stack continue.\n app.use(\n () =>\n new Response(null, {\n status: 204,\n headers: { [PASSTHROUGH_HEADER]: '1' },\n }),\n );\n\n viteServer.middlewares.use(async (req, res, next) => {\n const response = await app.fetch(toWebRequest(req));\n\n if (response.headers.get(PASSTHROUGH_HEADER) === '1') {\n next();\n return;\n }\n\n await writeWebResponseToNode(res, response);\n });\n });\n}\n"],"mappings":";;;;AAMA,IAAM,qBAAqB;;;;;;;;;;;;;AAc3B,eAAsB,4BACpB,MACA,YACA,YACe;AACS,UACtB,CAAC,GAAG,KAAK,GAAG,WAAW,4BAA4B,EACnD;EACE,KAAK;EACL,UAAU;EACX,CACF,CAEe,SAAS,SAAS;EAIhC,MAAM,MAAM,IAAI,IAAI;AACpB,MAAI,IAAI,OAAO,UAAU;AAIvB,WAH8B,MAAM,WACjC,cAAc,KAAK,CACnB,MAAM,MAAgB,EAAgC,QAAQ,EAClD,MAAM;IACrB;AAIF,MAAI,UAEA,IAAI,SAAS,MAAM;GACjB,QAAQ;GACR,SAAS,GAAG,qBAAqB,KAAK;GACvC,CAAC,CACL;AAED,aAAW,YAAY,IAAI,OAAO,KAAK,KAAK,SAAS;GACnD,MAAM,WAAW,MAAM,IAAI,MAAM,aAAa,IAAI,CAAC;AAEnD,OAAI,SAAS,QAAQ,IAAI,mBAAmB,KAAK,KAAK;AACpD,UAAM;AACN;;AAGF,SAAM,uBAAuB,KAAK,SAAS;IAC3C;GACF"}
@@ -0,0 +1,15 @@
1
+ import { ViteDevServer } from "vite";
2
+ /**
3
+ * Registers a file watcher that triggers a full page reload
4
+ * when translation files are added or modified.
5
+ *
6
+ * Matches files in i18n directories with .json, .xlf, .xmb, or .arb extensions.
7
+ *
8
+ * @param viteServer The Vite development server instance
9
+ */
10
+ export declare function registerI18nWatcher(viteServer: ViteDevServer): void;
11
+ /**
12
+ * Checks whether a file path looks like a translation file
13
+ * based on its location in an i18n directory and its extension.
14
+ */
15
+ export declare function isTranslationFile(path: string): boolean;
@@ -1,53 +1,53 @@
1
1
  /**
2
- * Code snippet emitted into virtual modules to create a request-scoped
3
- * fetch using ofetch's `createFetch` + h3's `fetchWithEvent`.
4
- *
5
- * Shared between the SSR renderer and page-endpoint virtual modules so
6
- * the fetch-wiring logic stays in sync.
7
- *
8
- * The emitted variable is named `serverFetch` — callers should reference it
9
- * by that name.
10
- */
2
+ * Code snippet emitted into virtual modules to create a request-scoped
3
+ * fetch using ofetch's `createFetch` + h3's `fetchWithEvent`.
4
+ *
5
+ * Shared between the SSR renderer and page-endpoint virtual modules so
6
+ * the fetch-wiring logic stays in sync.
7
+ *
8
+ * The emitted variable is named `serverFetch` — callers should reference it
9
+ * by that name.
10
+ */
11
11
  export declare const SERVER_FETCH_FACTORY_SNIPPET = "\n const serverFetch = createFetch({\n fetch: (resource, init) => {\n const url = resource instanceof Request ? resource.url : resource.toString();\n return fetchWithEvent(event, url, init);\n }\n });";
12
12
  /**
13
- * SSR renderer virtual module content.
14
- *
15
- * This code runs inside Nitro's server runtime (Node.js context) where
16
- * event.node is always populated. In h3 v2, event.node is typed as optional,
17
- * so we use h3's first-class event properties (event.path, event.method) where
18
- * possible and apply optional chaining when accessing the Node.js context for
19
- * the Angular renderer which requires raw req/res objects.
20
- *
21
- * h3 v2 idiomatic APIs used:
22
- * - defineHandler (replaces defineEventHandler / eventHandler)
23
- * - event.path (replaces event.node.req.url)
24
- * - getResponseHeader compat shim (still available in h3 v2)
25
- */
26
- export declare function ssrRenderer(templatePath: string): string;
13
+ * SSR renderer virtual module content.
14
+ *
15
+ * This code runs inside Nitro's server runtime (Node.js context) where
16
+ * event.node is always populated. In h3 v2, event.node is typed as optional,
17
+ * so we use h3's first-class event properties (event.path, event.method) where
18
+ * possible and apply optional chaining when accessing the Node.js context for
19
+ * the Angular renderer which requires raw req/res objects.
20
+ *
21
+ * h3 v2 idiomatic APIs used:
22
+ * - defineHandler (replaces defineEventHandler / eventHandler)
23
+ * - event.path (replaces event.node.req.url)
24
+ * - getResponseHeader compat shim (still available in h3 v2)
25
+ */
26
+ export declare function ssrRenderer(): string;
27
27
  /**
28
- * Client-only renderer virtual module content.
29
- *
30
- * Used when SSR is disabled — simply serves the static index.html template
31
- * for every route, letting the client-side Angular router handle navigation.
32
- */
33
- export declare function clientRenderer(templatePath: string): string;
28
+ * Client-only renderer virtual module content.
29
+ *
30
+ * Used when SSR is disabled — simply serves the static index.html template
31
+ * for every route, letting the client-side Angular router handle navigation.
32
+ */
33
+ export declare function clientRenderer(): string;
34
34
  /**
35
- * API middleware virtual module content.
36
- *
37
- * Intercepts requests matching the configured API prefix and either:
38
- * - Uses event-bound internal forwarding for GET requests (except .xml routes)
39
- * - Uses request proxying for all other methods to forward the full request
40
- *
41
- * h3 v2 idiomatic APIs used:
42
- * - defineHandler (replaces defineEventHandler / eventHandler)
43
- * - event.path (replaces event.node.req.url)
44
- * - event.method (replaces event.node.req.method)
45
- * - proxyRequest is retained internally because it preserves Nitro route
46
- * matching for event-bound server requests during SSR/prerender
47
- * - Object.fromEntries(event.req.headers.entries()) replaces direct event.node.req.headers access
48
- *
49
- * `fetchWithEvent` keeps the active event context while forwarding to a
50
- * rewritten path, which avoids falling through to the HTML renderer when
51
- * SSR code makes relative API requests.
52
- */
35
+ * API middleware virtual module content.
36
+ *
37
+ * Intercepts requests matching the configured API prefix and either:
38
+ * - Uses event-bound internal forwarding for GET requests (except .xml routes)
39
+ * - Uses request proxying for all other methods to forward the full request
40
+ *
41
+ * h3 v2 idiomatic APIs used:
42
+ * - defineHandler (replaces defineEventHandler / eventHandler)
43
+ * - event.path (replaces event.node.req.url)
44
+ * - event.method (replaces event.node.req.method)
45
+ * - proxyRequest is retained internally because it preserves Nitro route
46
+ * matching for event-bound server requests during SSR/prerender
47
+ * - Object.fromEntries(event.req.headers.entries()) replaces direct event.node.req.headers access
48
+ *
49
+ * `fetchWithEvent` keeps the active event context while forwarding to a
50
+ * rewritten path, which avoids falling through to the HTML renderer when
51
+ * SSR code makes relative API requests.
52
+ */
53
53
  export declare const apiMiddleware = "\nimport { defineHandler, fetchWithEvent, proxyRequest } from 'nitro/h3';\nimport { useRuntimeConfig } from 'nitro/runtime-config';\n\nexport default defineHandler(async (event) => {\n const prefix = useRuntimeConfig().prefix;\n const apiPrefix = `${prefix}/${useRuntimeConfig().apiPrefix}`;\n\n if (event.path?.startsWith(apiPrefix)) {\n const reqUrl = event.path?.replace(apiPrefix, '');\n\n if (\n event.method === 'GET' &&\n // in the case of XML routes, we want to proxy the request so that nitro gets the correct headers\n // and can render the XML correctly as a static asset\n !event.path?.endsWith('.xml')\n ) {\n return fetchWithEvent(event, reqUrl, {\n headers: Object.fromEntries(event.req.headers.entries()),\n });\n }\n\n return proxyRequest(event, reqUrl);\n }\n});";
@@ -1,14 +1,15 @@
1
+ //#region packages/vite-plugin-nitro/src/lib/utils/renderers.ts
1
2
  /**
2
- * Code snippet emitted into virtual modules to create a request-scoped
3
- * fetch using ofetch's `createFetch` + h3's `fetchWithEvent`.
4
- *
5
- * Shared between the SSR renderer and page-endpoint virtual modules so
6
- * the fetch-wiring logic stays in sync.
7
- *
8
- * The emitted variable is named `serverFetch` — callers should reference it
9
- * by that name.
10
- */
11
- export const SERVER_FETCH_FACTORY_SNIPPET = `
3
+ * Code snippet emitted into virtual modules to create a request-scoped
4
+ * fetch using ofetch's `createFetch` + h3's `fetchWithEvent`.
5
+ *
6
+ * Shared between the SSR renderer and page-endpoint virtual modules so
7
+ * the fetch-wiring logic stays in sync.
8
+ *
9
+ * The emitted variable is named `serverFetch` — callers should reference it
10
+ * by that name.
11
+ */
12
+ var SERVER_FETCH_FACTORY_SNIPPET = `
12
13
  const serverFetch = createFetch({
13
14
  fetch: (resource, init) => {
14
15
  const url = resource instanceof Request ? resource.url : resource.toString();
@@ -16,28 +17,27 @@ export const SERVER_FETCH_FACTORY_SNIPPET = `
16
17
  }
17
18
  });`;
18
19
  /**
19
- * SSR renderer virtual module content.
20
- *
21
- * This code runs inside Nitro's server runtime (Node.js context) where
22
- * event.node is always populated. In h3 v2, event.node is typed as optional,
23
- * so we use h3's first-class event properties (event.path, event.method) where
24
- * possible and apply optional chaining when accessing the Node.js context for
25
- * the Angular renderer which requires raw req/res objects.
26
- *
27
- * h3 v2 idiomatic APIs used:
28
- * - defineHandler (replaces defineEventHandler / eventHandler)
29
- * - event.path (replaces event.node.req.url)
30
- * - getResponseHeader compat shim (still available in h3 v2)
31
- */
32
- export function ssrRenderer(templatePath) {
33
- return `
34
- import { readFileSync } from 'node:fs';
20
+ * SSR renderer virtual module content.
21
+ *
22
+ * This code runs inside Nitro's server runtime (Node.js context) where
23
+ * event.node is always populated. In h3 v2, event.node is typed as optional,
24
+ * so we use h3's first-class event properties (event.path, event.method) where
25
+ * possible and apply optional chaining when accessing the Node.js context for
26
+ * the Angular renderer which requires raw req/res objects.
27
+ *
28
+ * h3 v2 idiomatic APIs used:
29
+ * - defineHandler (replaces defineEventHandler / eventHandler)
30
+ * - event.path (replaces event.node.req.url)
31
+ * - getResponseHeader compat shim (still available in h3 v2)
32
+ */
33
+ function ssrRenderer() {
34
+ return `
35
35
  import { createFetch } from 'ofetch';
36
36
  import { defineHandler, fetchWithEvent } from 'nitro/h3';
37
37
  // @ts-ignore
38
38
  import renderer from '#analog/ssr';
39
+ import template from '#analog/index';
39
40
 
40
- const template = readFileSync(${JSON.stringify(templatePath)}, 'utf8');
41
41
  const normalizeHtmlRequestUrl = (url) =>
42
42
  url.replace(/\\/index\\.html(?=$|[?#])/, '/');
43
43
 
@@ -77,17 +77,15 @@ ${SERVER_FETCH_FACTORY_SNIPPET}
77
77
  });`;
78
78
  }
79
79
  /**
80
- * Client-only renderer virtual module content.
81
- *
82
- * Used when SSR is disabled — simply serves the static index.html template
83
- * for every route, letting the client-side Angular router handle navigation.
84
- */
85
- export function clientRenderer(templatePath) {
86
- return `
87
- import { readFileSync } from 'node:fs';
80
+ * Client-only renderer virtual module content.
81
+ *
82
+ * Used when SSR is disabled — simply serves the static index.html template
83
+ * for every route, letting the client-side Angular router handle navigation.
84
+ */
85
+ function clientRenderer() {
86
+ return `
88
87
  import { defineHandler } from 'nitro/h3';
89
-
90
- const template = readFileSync(${JSON.stringify(templatePath)}, 'utf8');
88
+ import template from '#analog/index';
91
89
 
92
90
  export default defineHandler(async (event) => {
93
91
  event.res.headers.set('content-type', 'text/html; charset=utf-8');
@@ -96,25 +94,25 @@ export default defineHandler(async (event) => {
96
94
  `;
97
95
  }
98
96
  /**
99
- * API middleware virtual module content.
100
- *
101
- * Intercepts requests matching the configured API prefix and either:
102
- * - Uses event-bound internal forwarding for GET requests (except .xml routes)
103
- * - Uses request proxying for all other methods to forward the full request
104
- *
105
- * h3 v2 idiomatic APIs used:
106
- * - defineHandler (replaces defineEventHandler / eventHandler)
107
- * - event.path (replaces event.node.req.url)
108
- * - event.method (replaces event.node.req.method)
109
- * - proxyRequest is retained internally because it preserves Nitro route
110
- * matching for event-bound server requests during SSR/prerender
111
- * - Object.fromEntries(event.req.headers.entries()) replaces direct event.node.req.headers access
112
- *
113
- * `fetchWithEvent` keeps the active event context while forwarding to a
114
- * rewritten path, which avoids falling through to the HTML renderer when
115
- * SSR code makes relative API requests.
116
- */
117
- export const apiMiddleware = `
97
+ * API middleware virtual module content.
98
+ *
99
+ * Intercepts requests matching the configured API prefix and either:
100
+ * - Uses event-bound internal forwarding for GET requests (except .xml routes)
101
+ * - Uses request proxying for all other methods to forward the full request
102
+ *
103
+ * h3 v2 idiomatic APIs used:
104
+ * - defineHandler (replaces defineEventHandler / eventHandler)
105
+ * - event.path (replaces event.node.req.url)
106
+ * - event.method (replaces event.node.req.method)
107
+ * - proxyRequest is retained internally because it preserves Nitro route
108
+ * matching for event-bound server requests during SSR/prerender
109
+ * - Object.fromEntries(event.req.headers.entries()) replaces direct event.node.req.headers access
110
+ *
111
+ * `fetchWithEvent` keeps the active event context while forwarding to a
112
+ * rewritten path, which avoids falling through to the HTML renderer when
113
+ * SSR code makes relative API requests.
114
+ */
115
+ var apiMiddleware = `
118
116
  import { defineHandler, fetchWithEvent, proxyRequest } from 'nitro/h3';
119
117
  import { useRuntimeConfig } from 'nitro/runtime-config';
120
118
 
@@ -139,4 +137,7 @@ export default defineHandler(async (event) => {
139
137
  return proxyRequest(event, reqUrl);
140
138
  }
141
139
  });`;
140
+ //#endregion
141
+ export { SERVER_FETCH_FACTORY_SNIPPET, apiMiddleware, clientRenderer, ssrRenderer };
142
+
142
143
  //# sourceMappingURL=renderers.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"renderers.js","sourceRoot":"","sources":["../../../../../../packages/vite-plugin-nitro/src/lib/utils/renderers.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,MAAM,CAAC,MAAM,4BAA4B,GAAG;;;;;;MAMtC,CAAC;AAEP;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,WAAW,CAAC,YAAoB;IAC9C,OAAO;;;;;;;gCAOuB,IAAI,CAAC,SAAS,CAAC,YAAY,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAgC1D,4BAA4B;;;;;IAK1B,CAAC;AACL,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,cAAc,CAAC,YAAoB;IACjD,OAAO;;;;gCAIuB,IAAI,CAAC,SAAS,CAAC,YAAY,CAAC;;;;;;CAM3D,CAAC;AACF,CAAC;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG;;;;;;;;;;;;;;;;;;;;;;;;IAwBzB,CAAC"}
1
+ {"version":3,"file":"renderers.js","names":[],"sources":["../../../../src/lib/utils/renderers.ts"],"sourcesContent":["/**\n * Code snippet emitted into virtual modules to create a request-scoped\n * fetch using ofetch's `createFetch` + h3's `fetchWithEvent`.\n *\n * Shared between the SSR renderer and page-endpoint virtual modules so\n * the fetch-wiring logic stays in sync.\n *\n * The emitted variable is named `serverFetch` — callers should reference it\n * by that name.\n */\nexport const SERVER_FETCH_FACTORY_SNIPPET = `\n const serverFetch = createFetch({\n fetch: (resource, init) => {\n const url = resource instanceof Request ? resource.url : resource.toString();\n return fetchWithEvent(event, url, init);\n }\n });`;\n\n/**\n * SSR renderer virtual module content.\n *\n * This code runs inside Nitro's server runtime (Node.js context) where\n * event.node is always populated. In h3 v2, event.node is typed as optional,\n * so we use h3's first-class event properties (event.path, event.method) where\n * possible and apply optional chaining when accessing the Node.js context for\n * the Angular renderer which requires raw req/res objects.\n *\n * h3 v2 idiomatic APIs used:\n * - defineHandler (replaces defineEventHandler / eventHandler)\n * - event.path (replaces event.node.req.url)\n * - getResponseHeader compat shim (still available in h3 v2)\n */\nexport function ssrRenderer() {\n return `\nimport { createFetch } from 'ofetch';\nimport { defineHandler, fetchWithEvent } from 'nitro/h3';\n// @ts-ignore\nimport renderer from '#analog/ssr';\nimport template from '#analog/index';\n\nconst normalizeHtmlRequestUrl = (url) =>\n url.replace(/\\\\/index\\\\.html(?=$|[?#])/, '/');\n\nexport default defineHandler(async (event) => {\n event.res.headers.set('content-type', 'text/html; charset=utf-8');\n const noSSR = event.res.headers.get('x-analog-no-ssr');\n const requestPath = normalizeHtmlRequestUrl(event.path);\n\n if (noSSR === 'true') {\n return template;\n }\n\n // event.path is the canonical h3 v2 way to access the request URL.\n // event.node?.req and event.node?.res are needed by the Angular SSR renderer\n // which operates on raw Node.js request/response objects.\n // During prerendering (Nitro v3 fetch-based pipeline), event.node is undefined.\n // The Angular renderer requires a req object with at least { headers, url },\n // so we provide a minimal stub to avoid runtime errors in prerender context.\n const req = event.node?.req\n ? {\n ...event.node.req,\n url: requestPath,\n originalUrl: requestPath,\n }\n : {\n headers: { host: 'localhost' },\n url: requestPath,\n originalUrl: requestPath,\n connection: {},\n };\n const res = event.node?.res;\n${SERVER_FETCH_FACTORY_SNIPPET}\n\n const html = await renderer(requestPath, template, { req, res, fetch: serverFetch });\n\n return html;\n});`;\n}\n\n/**\n * Client-only renderer virtual module content.\n *\n * Used when SSR is disabled — simply serves the static index.html template\n * for every route, letting the client-side Angular router handle navigation.\n */\nexport function clientRenderer() {\n return `\nimport { defineHandler } from 'nitro/h3';\nimport template from '#analog/index';\n\nexport default defineHandler(async (event) => {\n event.res.headers.set('content-type', 'text/html; charset=utf-8');\n return template;\n});\n`;\n}\n\n/**\n * API middleware virtual module content.\n *\n * Intercepts requests matching the configured API prefix and either:\n * - Uses event-bound internal forwarding for GET requests (except .xml routes)\n * - Uses request proxying for all other methods to forward the full request\n *\n * h3 v2 idiomatic APIs used:\n * - defineHandler (replaces defineEventHandler / eventHandler)\n * - event.path (replaces event.node.req.url)\n * - event.method (replaces event.node.req.method)\n * - proxyRequest is retained internally because it preserves Nitro route\n * matching for event-bound server requests during SSR/prerender\n * - Object.fromEntries(event.req.headers.entries()) replaces direct event.node.req.headers access\n *\n * `fetchWithEvent` keeps the active event context while forwarding to a\n * rewritten path, which avoids falling through to the HTML renderer when\n * SSR code makes relative API requests.\n */\nexport const apiMiddleware = `\nimport { defineHandler, fetchWithEvent, proxyRequest } from 'nitro/h3';\nimport { useRuntimeConfig } from 'nitro/runtime-config';\n\nexport default defineHandler(async (event) => {\n const prefix = useRuntimeConfig().prefix;\n const apiPrefix = \\`\\${prefix}/\\${useRuntimeConfig().apiPrefix}\\`;\n\n if (event.path?.startsWith(apiPrefix)) {\n const reqUrl = event.path?.replace(apiPrefix, '');\n\n if (\n event.method === 'GET' &&\n // in the case of XML routes, we want to proxy the request so that nitro gets the correct headers\n // and can render the XML correctly as a static asset\n !event.path?.endsWith('.xml')\n ) {\n return fetchWithEvent(event, reqUrl, {\n headers: Object.fromEntries(event.req.headers.entries()),\n });\n }\n\n return proxyRequest(event, reqUrl);\n }\n});`;\n"],"mappings":";;;;;;;;;;;AAUA,IAAa,+BAA+B;;;;;;;;;;;;;;;;;;;;;AAsB5C,SAAgB,cAAc;AAC5B,QAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAsCP,6BAA6B;;;;;;;;;;;;;AAc/B,SAAgB,iBAAiB;AAC/B,QAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA8BT,IAAa,gBAAgB"}
@@ -0,0 +1,2 @@
1
+ export declare function isRolldown(): boolean;
2
+ export declare function getBundleOptionsKey(): "rolldownOptions" | "rollupOptions";
@@ -0,0 +1,12 @@
1
+ import * as vite from "vite";
2
+ //#region packages/vite-plugin-nitro/src/lib/utils/rolldown.ts
3
+ function isRolldown() {
4
+ return !!vite.rolldownVersion;
5
+ }
6
+ function getBundleOptionsKey() {
7
+ return isRolldown() ? "rolldownOptions" : "rollupOptions";
8
+ }
9
+ //#endregion
10
+ export { getBundleOptionsKey, isRolldown };
11
+
12
+ //# sourceMappingURL=rolldown.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rolldown.js","names":[],"sources":["../../../../src/lib/utils/rolldown.ts"],"sourcesContent":["import * as vite from 'vite';\n\nexport function isRolldown(): boolean {\n return !!vite.rolldownVersion;\n}\n\nexport function getBundleOptionsKey(): 'rolldownOptions' | 'rollupOptions' {\n return isRolldown() ? 'rolldownOptions' : 'rollupOptions';\n}\n"],"mappings":";;AAEA,SAAgB,aAAsB;AACpC,QAAO,CAAC,CAAC,KAAK;;AAGhB,SAAgB,sBAA2D;AACzE,QAAO,YAAY,GAAG,oBAAoB"}
@@ -1,4 +1,4 @@
1
- import type { NitroConfig } from 'nitro/types';
2
- import type { Plugin } from 'vite';
3
- import { Options } from './options.js';
1
+ import type { NitroConfig } from "nitro/types";
2
+ import type { Plugin } from "vite";
3
+ import { Options } from "./options.js";
4
4
  export declare function nitro(options?: Options, nitroOptions?: NitroConfig): Plugin[];