@analogjs/vite-plugin-nitro 3.0.0-alpha.2 → 3.0.0-alpha.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +18 -10
- package/src/index.d.ts +9 -9
- package/src/index.js +6 -2
- package/src/index.js.map +1 -1
- package/src/lib/build-server.d.ts +3 -2
- package/src/lib/build-server.js +100 -122
- package/src/lib/build-server.js.map +1 -1
- package/src/lib/build-sitemap.d.ts +9 -9
- package/src/lib/build-sitemap.js +130 -63
- package/src/lib/build-sitemap.js.map +1 -1
- package/src/lib/build-ssr.d.ts +3 -2
- package/src/lib/build-ssr.js +26 -18
- package/src/lib/build-ssr.js.map +1 -1
- package/src/lib/hooks/post-rendering-hook.d.ts +1 -1
- package/src/lib/hooks/post-rendering-hook.js +10 -6
- package/src/lib/hooks/post-rendering-hook.js.map +1 -1
- package/src/lib/options.d.ts +132 -106
- package/src/lib/plugins/dev-server-plugin.d.ts +3 -3
- package/src/lib/plugins/dev-server-plugin.js +91 -101
- package/src/lib/plugins/dev-server-plugin.js.map +1 -1
- package/src/lib/plugins/page-endpoints.d.ts +5 -5
- package/src/lib/plugins/page-endpoints.js +27 -62
- package/src/lib/plugins/page-endpoints.js.map +1 -1
- package/src/lib/utils/get-content-files.d.ts +54 -54
- package/src/lib/utils/get-content-files.js +88 -97
- package/src/lib/utils/get-content-files.js.map +1 -1
- package/src/lib/utils/get-page-handlers.d.ts +58 -58
- package/src/lib/utils/get-page-handlers.js +70 -84
- package/src/lib/utils/get-page-handlers.js.map +1 -1
- package/src/lib/utils/load-esm.d.ts +18 -18
- package/src/lib/utils/node-web-bridge.d.ts +1 -1
- package/src/lib/utils/node-web-bridge.js +50 -45
- package/src/lib/utils/node-web-bridge.js.map +1 -1
- package/src/lib/utils/register-dev-middleware.d.ts +12 -12
- package/src/lib/utils/register-dev-middleware.js +41 -44
- package/src/lib/utils/register-dev-middleware.js.map +1 -1
- package/src/lib/utils/renderers.d.ts +49 -38
- package/src/lib/utils/renderers.js +66 -53
- package/src/lib/utils/renderers.js.map +1 -1
- package/src/lib/utils/rolldown.d.ts +2 -0
- package/src/lib/utils/rolldown.js +12 -0
- package/src/lib/utils/rolldown.js.map +1 -0
- package/src/lib/vite-plugin-nitro.d.ts +3 -3
- package/src/lib/vite-plugin-nitro.js +741 -687
- package/src/lib/vite-plugin-nitro.js.map +1 -1
- package/README.md +0 -125
- package/src/lib/options.js +0 -2
- package/src/lib/options.js.map +0 -1
- package/src/lib/utils/load-esm.js +0 -23
- package/src/lib/utils/load-esm.js.map +0 -1
|
@@ -1,42 +1,53 @@
|
|
|
1
1
|
/**
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
* - event.path (replaces event.node.req.url)
|
|
13
|
-
* - getResponseHeader compat shim (still available in h3 v2)
|
|
14
|
-
*/
|
|
15
|
-
export declare function ssrRenderer(templatePath: string): string;
|
|
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 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 });";
|
|
16
12
|
/**
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
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;
|
|
23
27
|
/**
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
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
|
+
/**
|
|
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
|
+
*/
|
|
42
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,26 +1,43 @@
|
|
|
1
|
+
//#region packages/vite-plugin-nitro/src/lib/utils/renderers.ts
|
|
1
2
|
/**
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
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 = `
|
|
13
|
+
const serverFetch = createFetch({
|
|
14
|
+
fetch: (resource, init) => {
|
|
15
|
+
const url = resource instanceof Request ? resource.url : resource.toString();
|
|
16
|
+
return fetchWithEvent(event, url, init);
|
|
17
|
+
}
|
|
18
|
+
});`;
|
|
19
|
+
/**
|
|
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 `
|
|
18
35
|
import { createFetch } from 'ofetch';
|
|
19
36
|
import { defineHandler, fetchWithEvent } from 'nitro/h3';
|
|
20
37
|
// @ts-ignore
|
|
21
38
|
import renderer from '#analog/ssr';
|
|
39
|
+
import template from '#analog/index';
|
|
22
40
|
|
|
23
|
-
const template = readFileSync(${JSON.stringify(templatePath)}, 'utf8');
|
|
24
41
|
const normalizeHtmlRequestUrl = (url) =>
|
|
25
42
|
url.replace(/\\/index\\.html(?=$|[?#])/, '/');
|
|
26
43
|
|
|
@@ -52,30 +69,23 @@ export default defineHandler(async (event) => {
|
|
|
52
69
|
connection: {},
|
|
53
70
|
};
|
|
54
71
|
const res = event.node?.res;
|
|
55
|
-
|
|
56
|
-
fetch: (resource, init) => {
|
|
57
|
-
const url = resource instanceof Request ? resource.url : resource.toString();
|
|
58
|
-
return fetchWithEvent(event, url, init);
|
|
59
|
-
}
|
|
60
|
-
});
|
|
72
|
+
${SERVER_FETCH_FACTORY_SNIPPET}
|
|
61
73
|
|
|
62
|
-
const html = await renderer(requestPath, template, { req, res, fetch });
|
|
74
|
+
const html = await renderer(requestPath, template, { req, res, fetch: serverFetch });
|
|
63
75
|
|
|
64
76
|
return html;
|
|
65
77
|
});`;
|
|
66
78
|
}
|
|
67
79
|
/**
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
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 `
|
|
76
87
|
import { defineHandler } from 'nitro/h3';
|
|
77
|
-
|
|
78
|
-
const template = readFileSync(${JSON.stringify(templatePath)}, 'utf8');
|
|
88
|
+
import template from '#analog/index';
|
|
79
89
|
|
|
80
90
|
export default defineHandler(async (event) => {
|
|
81
91
|
event.res.headers.set('content-type', 'text/html; charset=utf-8');
|
|
@@ -84,25 +94,25 @@ export default defineHandler(async (event) => {
|
|
|
84
94
|
`;
|
|
85
95
|
}
|
|
86
96
|
/**
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
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 = `
|
|
106
116
|
import { defineHandler, fetchWithEvent, proxyRequest } from 'nitro/h3';
|
|
107
117
|
import { useRuntimeConfig } from 'nitro/runtime-config';
|
|
108
118
|
|
|
@@ -127,4 +137,7 @@ export default defineHandler(async (event) => {
|
|
|
127
137
|
return proxyRequest(event, reqUrl);
|
|
128
138
|
}
|
|
129
139
|
});`;
|
|
140
|
+
//#endregion
|
|
141
|
+
export { SERVER_FETCH_FACTORY_SNIPPET, apiMiddleware, clientRenderer, ssrRenderer };
|
|
142
|
+
|
|
130
143
|
//# sourceMappingURL=renderers.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"renderers.js","
|
|
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,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
|
|
2
|
-
import type { Plugin } from
|
|
3
|
-
import { Options } from
|
|
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[];
|