@analogjs/vite-plugin-nitro 3.0.0-alpha.7 → 3.0.0-alpha.70
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 +31 -11
- package/src/index.d.ts +19 -9
- package/src/index.js +9 -2
- package/src/index.js.map +1 -1
- package/src/lib/build-server.d.ts +2 -2
- package/src/lib/build-server.js +45 -149
- package/src/lib/build-server.js.map +1 -1
- package/src/lib/build-sitemap.d.ts +23 -9
- package/src/lib/build-sitemap.js +132 -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 +148 -106
- package/src/lib/plugins/dev-server-plugin.d.ts +3 -3
- package/src/lib/plugins/dev-server-plugin.js +99 -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 +26 -46
- package/src/lib/plugins/page-endpoints.js.map +1 -1
- package/src/lib/plugins/server-fn-id-plugin.d.ts +11 -0
- package/src/lib/plugins/server-fn-id-plugin.js +27 -0
- package/src/lib/plugins/server-fn-id-plugin.js.map +1 -0
- package/src/lib/utils/debug.d.ts +5 -0
- package/src/lib/utils/debug.js +15 -0
- package/src/lib/utils/debug.js.map +1 -0
- package/src/lib/utils/derive-server-fn-id.d.ts +25 -0
- package/src/lib/utils/derive-server-fn-id.js +37 -0
- package/src/lib/utils/derive-server-fn-id.js.map +1 -0
- package/src/lib/utils/get-content-files.d.ts +55 -55
- package/src/lib/utils/get-content-files.js +95 -97
- package/src/lib/utils/get-content-files.js.map +1 -1
- package/src/lib/utils/get-page-handlers.d.ts +55 -58
- package/src/lib/utils/get-page-handlers.js +67 -84
- package/src/lib/utils/get-page-handlers.js.map +1 -1
- package/src/lib/utils/get-server-fn-handlers.d.ts +28 -0
- package/src/lib/utils/get-server-fn-handlers.js +45 -0
- package/src/lib/utils/get-server-fn-handlers.js.map +1 -0
- package/src/lib/utils/i18n-prerender.d.ts +36 -0
- package/src/lib/utils/i18n-prerender.js +23 -0
- package/src/lib/utils/i18n-prerender.js.map +1 -0
- package/src/lib/utils/inject-server-fn-ids.d.ts +17 -0
- package/src/lib/utils/inject-server-fn-ids.js +94 -0
- package/src/lib/utils/inject-server-fn-ids.js.map +1 -0
- 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 -47
- package/src/lib/utils/register-dev-middleware.js.map +1 -1
- package/src/lib/utils/register-i18n-watcher.d.ts +15 -0
- package/src/lib/utils/register-i18n-watcher.js +27 -0
- package/src/lib/utils/register-i18n-watcher.js.map +1 -0
- package/src/lib/utils/renderers.d.ts +29 -49
- package/src/lib/utils/renderers.js +37 -80
- 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/utils/server-fn-endpoints.d.ts +41 -0
- package/src/lib/utils/server-fn-endpoints.js +57 -0
- package/src/lib/utils/server-fn-endpoints.js.map +1 -0
- package/src/lib/vite-plugin-nitro.d.ts +3 -3
- package/src/lib/vite-plugin-nitro.js +793 -678
- 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
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import type { NitroEventHandler } from "nitropack";
|
|
2
|
+
import type { ServerFnHandlerModule } from "./get-server-fn-handlers";
|
|
3
|
+
/**
|
|
4
|
+
* Nitro virtual-module id for the generated server-function dispatch handler.
|
|
5
|
+
* Referenced from `nitroConfig.handlers` and provided via `nitroConfig.virtual`.
|
|
6
|
+
*/
|
|
7
|
+
export declare const SERVER_FN_DISPATCH_VIRTUAL = "#ANALOG_SERVER_FN_DISPATCH";
|
|
8
|
+
/** The single transport route all server functions dispatch through. */
|
|
9
|
+
export declare const SERVER_FN_DISPATCH_ROUTE = "/_analog/fn/:id";
|
|
10
|
+
/** URL prefix of that route, for matching requests before the id is known. */
|
|
11
|
+
export declare const SERVER_FN_DISPATCH_PREFIX = "/_analog/fn/";
|
|
12
|
+
/**
|
|
13
|
+
* The Nitro handler registration for the server-function dispatch route.
|
|
14
|
+
* Unlike page endpoints (one handler per file), every server function shares
|
|
15
|
+
* this one `/_analog/fn/:id` route; the id selects the function at runtime.
|
|
16
|
+
*
|
|
17
|
+
* The route is fixed and NOT `/api`-prefixed: client proxies always call the
|
|
18
|
+
* absolute `/_analog/fn/:id` URL, so an `/api` prefix (as page endpoints use)
|
|
19
|
+
* would leave the handler unreachable in apps that have an API directory.
|
|
20
|
+
*/
|
|
21
|
+
export declare function getServerFnDispatchHandler(): NitroEventHandler;
|
|
22
|
+
export type BuildServerFnDispatchModuleArgs = {
|
|
23
|
+
/** Discovered `*.server.ts` modules, imported for registration side-effects. */
|
|
24
|
+
modules: ServerFnHandlerModule[];
|
|
25
|
+
/**
|
|
26
|
+
* Absolute path to the app's server config module (`app.config.server.ts`),
|
|
27
|
+
* which exports the `ApplicationConfig` (as `config`) that `main.server.ts`
|
|
28
|
+
* renders with. Handlers bootstrap against it, so they see the same DI the
|
|
29
|
+
* app configured. When absent, handlers run with only `providedIn: 'root'`.
|
|
30
|
+
*/
|
|
31
|
+
appConfigModule?: string;
|
|
32
|
+
};
|
|
33
|
+
/**
|
|
34
|
+
* Generates the source of the Nitro dispatch handler.
|
|
35
|
+
*
|
|
36
|
+
* The handler imports every discovered `*.server.ts` module so each
|
|
37
|
+
* `serverFn(...)` registers itself, imports the app's server config, then on
|
|
38
|
+
* each request looks up the function by id and runs it via `dispatchServerFn` —
|
|
39
|
+
* the same call path the validation harnesses exercise.
|
|
40
|
+
*/
|
|
41
|
+
export declare function buildServerFnDispatchModule({ modules, appConfigModule }: BuildServerFnDispatchModuleArgs): string;
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { normalizePath } from "vite";
|
|
2
|
+
//#region packages/vite-plugin-nitro/src/lib/utils/server-fn-endpoints.ts
|
|
3
|
+
/**
|
|
4
|
+
* Nitro virtual-module id for the generated server-function dispatch handler.
|
|
5
|
+
* Referenced from `nitroConfig.handlers` and provided via `nitroConfig.virtual`.
|
|
6
|
+
*/
|
|
7
|
+
var SERVER_FN_DISPATCH_VIRTUAL = "#ANALOG_SERVER_FN_DISPATCH";
|
|
8
|
+
/** The single transport route all server functions dispatch through. */
|
|
9
|
+
var SERVER_FN_DISPATCH_ROUTE = "/_analog/fn/:id";
|
|
10
|
+
/**
|
|
11
|
+
* The Nitro handler registration for the server-function dispatch route.
|
|
12
|
+
* Unlike page endpoints (one handler per file), every server function shares
|
|
13
|
+
* this one `/_analog/fn/:id` route; the id selects the function at runtime.
|
|
14
|
+
*
|
|
15
|
+
* The route is fixed and NOT `/api`-prefixed: client proxies always call the
|
|
16
|
+
* absolute `/_analog/fn/:id` URL, so an `/api` prefix (as page endpoints use)
|
|
17
|
+
* would leave the handler unreachable in apps that have an API directory.
|
|
18
|
+
*/
|
|
19
|
+
function getServerFnDispatchHandler() {
|
|
20
|
+
return {
|
|
21
|
+
route: SERVER_FN_DISPATCH_ROUTE,
|
|
22
|
+
handler: SERVER_FN_DISPATCH_VIRTUAL,
|
|
23
|
+
lazy: true
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Generates the source of the Nitro dispatch handler.
|
|
28
|
+
*
|
|
29
|
+
* The handler imports every discovered `*.server.ts` module so each
|
|
30
|
+
* `serverFn(...)` registers itself, imports the app's server config, then on
|
|
31
|
+
* each request looks up the function by id and runs it via `dispatchServerFn` —
|
|
32
|
+
* the same call path the validation harnesses exercise.
|
|
33
|
+
*/
|
|
34
|
+
function buildServerFnDispatchModule({ modules, appConfigModule }) {
|
|
35
|
+
return `import '@angular/compiler';
|
|
36
|
+
import 'zone.js/node';
|
|
37
|
+
import '@angular/platform-server/init';
|
|
38
|
+
import { createServerFnAppInjector, createServerFnEventHandler } from '@analogjs/router/server';
|
|
39
|
+
|
|
40
|
+
// Discovered server-function modules (registration side-effects).
|
|
41
|
+
${modules.map((m) => `import ${JSON.stringify(normalizePath(m.file))};`).join("\n")}
|
|
42
|
+
|
|
43
|
+
${appConfigModule ? `import { config as serverFnAppConfig } from ${JSON.stringify(normalizePath(appConfigModule))};` : `const serverFnAppConfig = { providers: [] };`}
|
|
44
|
+
|
|
45
|
+
// Bootstrapped once from the app's own server config, so a handler resolves the
|
|
46
|
+
// same DI as an SSR render (\`providedIn: 'root'\` and listed providers alike).
|
|
47
|
+
// No component is bootstrapped, so nothing renders and the router never
|
|
48
|
+
// navigates. Only REQUEST/RESPONSE are rebuilt per call.
|
|
49
|
+
export default createServerFnEventHandler(
|
|
50
|
+
createServerFnAppInjector(serverFnAppConfig),
|
|
51
|
+
);
|
|
52
|
+
`;
|
|
53
|
+
}
|
|
54
|
+
//#endregion
|
|
55
|
+
export { buildServerFnDispatchModule, getServerFnDispatchHandler };
|
|
56
|
+
|
|
57
|
+
//# sourceMappingURL=server-fn-endpoints.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"server-fn-endpoints.js","names":[],"sources":["../../../../src/lib/utils/server-fn-endpoints.ts"],"sourcesContent":["import type { NitroEventHandler } from 'nitropack';\nimport { normalizePath } from 'vite';\n\nimport type { ServerFnHandlerModule } from './get-server-fn-handlers';\n\n/**\n * Nitro virtual-module id for the generated server-function dispatch handler.\n * Referenced from `nitroConfig.handlers` and provided via `nitroConfig.virtual`.\n */\nexport const SERVER_FN_DISPATCH_VIRTUAL = '#ANALOG_SERVER_FN_DISPATCH';\n\n/** The single transport route all server functions dispatch through. */\nexport const SERVER_FN_DISPATCH_ROUTE = '/_analog/fn/:id';\n\n/** URL prefix of that route, for matching requests before the id is known. */\nexport const SERVER_FN_DISPATCH_PREFIX = '/_analog/fn/';\n\n/**\n * The Nitro handler registration for the server-function dispatch route.\n * Unlike page endpoints (one handler per file), every server function shares\n * this one `/_analog/fn/:id` route; the id selects the function at runtime.\n *\n * The route is fixed and NOT `/api`-prefixed: client proxies always call the\n * absolute `/_analog/fn/:id` URL, so an `/api` prefix (as page endpoints use)\n * would leave the handler unreachable in apps that have an API directory.\n */\nexport function getServerFnDispatchHandler(): NitroEventHandler {\n return {\n route: SERVER_FN_DISPATCH_ROUTE,\n handler: SERVER_FN_DISPATCH_VIRTUAL,\n lazy: true,\n };\n}\n\nexport type BuildServerFnDispatchModuleArgs = {\n /** Discovered `*.server.ts` modules, imported for registration side-effects. */\n modules: ServerFnHandlerModule[];\n /**\n * Absolute path to the app's server config module (`app.config.server.ts`),\n * which exports the `ApplicationConfig` (as `config`) that `main.server.ts`\n * renders with. Handlers bootstrap against it, so they see the same DI the\n * app configured. When absent, handlers run with only `providedIn: 'root'`.\n */\n appConfigModule?: string;\n};\n\n/**\n * Generates the source of the Nitro dispatch handler.\n *\n * The handler imports every discovered `*.server.ts` module so each\n * `serverFn(...)` registers itself, imports the app's server config, then on\n * each request looks up the function by id and runs it via `dispatchServerFn` —\n * the same call path the validation harnesses exercise.\n */\nexport function buildServerFnDispatchModule({\n modules,\n appConfigModule,\n}: BuildServerFnDispatchModuleArgs): string {\n const registrationImports = modules\n .map((m) => `import ${JSON.stringify(normalizePath(m.file))};`)\n .join('\\n');\n\n // Bootstrap against the app's own server config so a handler resolves exactly\n // the services, tokens, and interceptors the app configured — one config, no\n // second provider list. Fall back to an empty config when the app has none.\n const appConfig = appConfigModule\n ? `import { config as serverFnAppConfig } from ${JSON.stringify(\n normalizePath(appConfigModule),\n )};`\n : `const serverFnAppConfig = { providers: [] };`;\n\n // `@analogjs/router/server` is a partially-compiled Angular library, and this\n // module is bundled by Nitro rather than by the app's Angular pipeline, so the\n // linker never runs over it. Loading the compiler gives it the JIT fallback.\n // `zone.js` and the server platform init match the SSR entry, so bootstrapping\n // the app injector below runs in the same environment a render would.\n //\n // The transport itself — id decoding, the malformed-body contract, dispatch,\n // and response writing — lives in `createServerFnEventHandler`, so this module\n // is only wiring: bootstrap the app injector from the app's server config, and\n // hand it to that handler.\n return `import '@angular/compiler';\nimport 'zone.js/node';\nimport '@angular/platform-server/init';\nimport { createServerFnAppInjector, createServerFnEventHandler } from '@analogjs/router/server';\n\n// Discovered server-function modules (registration side-effects).\n${registrationImports}\n\n${appConfig}\n\n// Bootstrapped once from the app's own server config, so a handler resolves the\n// same DI as an SSR render (\\`providedIn: 'root'\\` and listed providers alike).\n// No component is bootstrapped, so nothing renders and the router never\n// navigates. Only REQUEST/RESPONSE are rebuilt per call.\nexport default createServerFnEventHandler(\n createServerFnAppInjector(serverFnAppConfig),\n);\n`;\n}\n"],"mappings":";;;;;;AASA,IAAa,6BAA6B;;AAG1C,IAAa,2BAA2B;;;;;;;;;;AAcxC,SAAgB,6BAAgD;AAC9D,QAAO;EACL,OAAO;EACP,SAAS;EACT,MAAM;EACP;;;;;;;;;;AAuBH,SAAgB,4BAA4B,EAC1C,SACA,mBAC0C;AAwB1C,QAAO;;;;;;EAvBqB,QACzB,KAAK,MAAM,UAAU,KAAK,UAAU,cAAc,EAAE,KAAK,CAAC,CAAC,GAAG,CAC9D,KAAK,KAAK,CA2BO;;EAtBF,kBACd,+CAA+C,KAAK,UAClD,cAAc,gBAAgB,CAC/B,CAAC,KACF,+CAoBM"}
|
|
@@ -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[];
|