@analogjs/platform 3.0.0-beta.6 → 3.0.0-beta.61
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/migrations/migrate-setup-testbed-browser-mode/migrate-setup-testbed-browser-mode.js +1 -2
- package/migrations/migrate-to-separated-plugins/migrate-to-separated-plugins.js +3 -3
- package/migrations/migrate-to-separated-plugins/migrate-to-separated-plugins.js.map +1 -1
- package/migrations/migrate-vitest-builder-aliases/migrate-vitest-builder-aliases.js +3 -3
- package/migrations/migrate-vitest-builder-aliases/migrate-vitest-builder-aliases.js.map +1 -1
- package/migrations/utils/source-edits.js +1 -2
- package/package.json +14 -11
- package/src/index.js +2 -3
- package/src/lib/analog-integration-plugin.js +1 -2
- package/src/lib/clear-client-page-endpoint.js +2 -3
- package/src/lib/content/marked/index.js +1 -2
- package/src/lib/content/marked/marked-content-highlighter.js +1 -2
- package/src/lib/content/marked/marked-setup.service.js +1 -2
- package/src/lib/content/prism/angular.js +1 -2
- package/src/lib/content/prism/index.js +1 -2
- package/src/lib/content/prism/prism-highlighter.js +1 -2
- package/src/lib/content/shiki/index.js +1 -2
- package/src/lib/content/shiki/shiki-highlighter.js +2 -3
- package/src/lib/content/utils/escape-html.js +1 -2
- package/src/lib/content-plugin.js +13 -5
- package/src/lib/content-plugin.js.map +1 -1
- package/src/lib/deps-plugin.d.ts +1 -1
- package/src/lib/deps-plugin.js +13 -10
- package/src/lib/deps-plugin.js.map +1 -1
- package/src/lib/discover-library-routes.d.ts +3 -3
- package/src/lib/discover-library-routes.js +5 -6
- package/src/lib/discover-library-routes.js.map +1 -1
- package/src/lib/get-page-endpoints.d.ts +25 -0
- package/src/lib/get-page-endpoints.js +28 -0
- package/src/lib/get-page-endpoints.js.map +1 -0
- package/src/lib/inject-server-fn-ids.js +1 -2
- package/src/lib/nitro/analog-nitro-plugin.d.ts +6 -6
- package/src/lib/nitro/analog-nitro-plugin.js +119 -51
- package/src/lib/nitro/analog-nitro-plugin.js.map +1 -1
- package/src/lib/nitro/angular-linker-plugin.d.ts +4 -2
- package/src/lib/nitro/angular-linker-plugin.js +25 -40
- package/src/lib/nitro/angular-linker-plugin.js.map +1 -1
- package/src/lib/nitro/build-sitemap.js +3 -4
- package/src/lib/nitro/build-sitemap.js.map +1 -1
- package/src/lib/nitro/debug.js +1 -2
- package/src/lib/nitro/get-content-files.js +1 -2
- package/src/lib/nitro/get-page-handlers.d.ts +4 -19
- package/src/lib/nitro/get-page-handlers.js +10 -28
- package/src/lib/nitro/get-page-handlers.js.map +1 -1
- package/src/lib/nitro/get-server-fn-handlers.js +1 -2
- package/src/lib/nitro/i18n-prerender.d.ts +2 -1
- package/src/lib/nitro/i18n-prerender.js +11 -9
- package/src/lib/nitro/i18n-prerender.js.map +1 -1
- package/src/lib/nitro/page-endpoints-plugin.js +1 -2
- package/src/lib/nitro/post-rendering-hook.js +1 -2
- package/src/lib/nitro/renderers.js +1 -2
- package/src/lib/nitro/server-fn-endpoints.d.ts +3 -1
- package/src/lib/nitro/server-fn-endpoints.js +15 -7
- package/src/lib/nitro/server-fn-endpoints.js.map +1 -1
- package/src/lib/nx-plugin/_virtual/_rolldown/runtime.js +1 -2
- package/src/lib/nx-plugin/executors.json +0 -7
- package/src/lib/nx-plugin/node_modules/.pnpm/es-toolkit@1.45.1/node_modules/es-toolkit/dist/string/camelCase.js +1 -2
- package/src/lib/nx-plugin/node_modules/.pnpm/es-toolkit@1.45.1/node_modules/es-toolkit/dist/string/camelCase.js.map +1 -1
- package/src/lib/nx-plugin/node_modules/.pnpm/es-toolkit@1.45.1/node_modules/es-toolkit/dist/string/capitalize.js +1 -2
- package/src/lib/nx-plugin/node_modules/.pnpm/es-toolkit@1.45.1/node_modules/es-toolkit/dist/string/capitalize.js.map +1 -1
- package/src/lib/nx-plugin/node_modules/.pnpm/es-toolkit@1.45.1/node_modules/es-toolkit/dist/string/words.js +1 -2
- package/src/lib/nx-plugin/node_modules/.pnpm/es-toolkit@1.45.1/node_modules/es-toolkit/dist/string/words.js.map +1 -1
- package/src/lib/nx-plugin/src/builders/vite/vite-build.js +1 -2
- package/src/lib/nx-plugin/src/builders/vite/vite-build.js.map +1 -1
- package/src/lib/nx-plugin/src/builders/vite-dev-server/dev-server.js +1 -2
- package/src/lib/nx-plugin/src/builders/vite-dev-server/dev-server.js.map +1 -1
- package/src/lib/nx-plugin/src/generators/app/compat.d.ts +2 -1
- package/src/lib/nx-plugin/src/generators/app/compat.js +5 -3
- package/src/lib/nx-plugin/src/generators/app/compat.js.map +1 -1
- package/src/lib/nx-plugin/src/generators/app/generator.js +8 -4
- package/src/lib/nx-plugin/src/generators/app/generator.js.map +1 -1
- package/src/lib/nx-plugin/src/generators/app/lib/add-agent-context.js +1 -2
- package/src/lib/nx-plugin/src/generators/app/lib/add-agent-context.js.map +1 -1
- package/src/lib/nx-plugin/src/generators/app/lib/add-analog-project-config.js +1 -2
- package/src/lib/nx-plugin/src/generators/app/lib/add-analog-project-config.js.map +1 -1
- package/src/lib/nx-plugin/src/generators/app/lib/add-angular-app.js +13 -3
- package/src/lib/nx-plugin/src/generators/app/lib/add-angular-app.js.map +1 -1
- package/src/lib/nx-plugin/src/generators/app/lib/add-files.js +1 -2
- package/src/lib/nx-plugin/src/generators/app/lib/add-files.js.map +1 -1
- package/src/lib/nx-plugin/src/generators/app/lib/add-home-page.js +1 -2
- package/src/lib/nx-plugin/src/generators/app/lib/add-home-page.js.map +1 -1
- package/src/lib/nx-plugin/src/generators/app/lib/add-tailwind-config.js +1 -2
- package/src/lib/nx-plugin/src/generators/app/lib/add-tailwind-config.js.map +1 -1
- package/src/lib/nx-plugin/src/generators/app/lib/add-tailwind-helpers.js +3 -4
- package/src/lib/nx-plugin/src/generators/app/lib/add-tailwind-helpers.js.map +1 -1
- package/src/lib/nx-plugin/src/generators/app/lib/cleanup-files.js +1 -2
- package/src/lib/nx-plugin/src/generators/app/lib/update-index-html.js +1 -2
- package/src/lib/nx-plugin/src/generators/app/lib/update-index-html.js.map +1 -1
- package/src/lib/nx-plugin/src/generators/app/versions/minimum-supported-versions.d.ts +3 -1
- package/src/lib/nx-plugin/src/generators/app/versions/minimum-supported-versions.js +6 -3
- package/src/lib/nx-plugin/src/generators/app/versions/minimum-supported-versions.js.map +1 -1
- package/src/lib/nx-plugin/src/generators/app/versions/tailwind-dependencies.js +1 -2
- package/src/lib/nx-plugin/src/generators/app/versions/tailwind-dependencies.js.map +1 -1
- package/src/lib/nx-plugin/src/generators/app/versions/versions.js +1 -2
- package/src/lib/nx-plugin/src/generators/init/compat.d.ts +2 -1
- package/src/lib/nx-plugin/src/generators/init/compat.js +5 -3
- package/src/lib/nx-plugin/src/generators/init/compat.js.map +1 -1
- package/src/lib/nx-plugin/src/generators/init/files/src/server/routes/api/v1/hello.ts__template__ +2 -2
- package/src/lib/nx-plugin/src/generators/init/files/vite.config.ts__template__ +5 -1
- package/src/lib/nx-plugin/src/generators/init/generator.js +1 -2
- package/src/lib/nx-plugin/src/generators/init/generator.js.map +1 -1
- package/src/lib/nx-plugin/src/generators/init/lib/add-analog-dependencies.js +3 -4
- package/src/lib/nx-plugin/src/generators/init/lib/add-analog-dependencies.js.map +1 -1
- package/src/lib/nx-plugin/src/generators/init/lib/update-app-tsconfig.js +1 -2
- package/src/lib/nx-plugin/src/generators/init/lib/update-app-tsconfig.js.map +1 -1
- package/src/lib/nx-plugin/src/generators/init/lib/update-build-target.js +1 -2
- package/src/lib/nx-plugin/src/generators/init/lib/update-build-target.js.map +1 -1
- package/src/lib/nx-plugin/src/generators/init/lib/update-git-ignore.js +1 -2
- package/src/lib/nx-plugin/src/generators/init/lib/update-index-html.js +1 -2
- package/src/lib/nx-plugin/src/generators/init/lib/update-index-html.js.map +1 -1
- package/src/lib/nx-plugin/src/generators/init/lib/update-main.js +1 -2
- package/src/lib/nx-plugin/src/generators/init/lib/update-main.js.map +1 -1
- package/src/lib/nx-plugin/src/generators/init/lib/update-package-json.js +1 -2
- package/src/lib/nx-plugin/src/generators/init/lib/update-package-json.js.map +1 -1
- package/src/lib/nx-plugin/src/generators/init/lib/update-serve-target.js +1 -2
- package/src/lib/nx-plugin/src/generators/init/lib/update-serve-target.js.map +1 -1
- package/src/lib/nx-plugin/src/generators/init/lib/update-test-target.js +1 -2
- package/src/lib/nx-plugin/src/generators/init/lib/update-test-target.js.map +1 -1
- package/src/lib/nx-plugin/src/generators/init/lib/update-test-tsconfig.js +1 -2
- package/src/lib/nx-plugin/src/generators/init/lib/update-test-tsconfig.js.map +1 -1
- package/src/lib/nx-plugin/src/generators/page/compat.d.ts +2 -1
- package/src/lib/nx-plugin/src/generators/page/compat.js +5 -3
- package/src/lib/nx-plugin/src/generators/page/compat.js.map +1 -1
- package/src/lib/nx-plugin/src/generators/page/generator.js +1 -2
- package/src/lib/nx-plugin/src/generators/page/generator.js.map +1 -1
- package/src/lib/nx-plugin/src/generators/preset/__snapshots__/generator.spec.ts.snap +4 -0
- package/src/lib/nx-plugin/src/generators/preset/generator.js +6 -4
- package/src/lib/nx-plugin/src/generators/preset/generator.js.map +1 -1
- package/src/lib/nx-plugin/src/utils/version-utils.js +1 -2
- package/src/lib/nx-plugin/src/utils/version-utils.js.map +1 -1
- package/src/lib/nx-plugin/src/utils/versions/dependencies.d.ts +1 -1
- package/src/lib/nx-plugin/src/utils/versions/dependencies.js +2 -2
- package/src/lib/nx-plugin/src/utils/versions/dependencies.js.map +1 -1
- package/src/lib/nx-plugin/src/utils/versions/dev-dependencies.d.ts +2 -2
- package/src/lib/nx-plugin/src/utils/versions/dev-dependencies.js +9 -5
- package/src/lib/nx-plugin/src/utils/versions/dev-dependencies.js.map +1 -1
- package/src/lib/nx-plugin/src/utils/versions/versions.d.ts +9 -6
- package/src/lib/nx-plugin/src/utils/versions/versions.js +14 -9
- package/src/lib/nx-plugin/src/utils/versions/versions.js.map +1 -1
- package/src/lib/options.d.ts +16 -0
- package/src/lib/platform-plugin.js +3 -2
- package/src/lib/platform-plugin.js.map +1 -1
- package/src/lib/route-file-discovery.js +9 -6
- package/src/lib/route-file-discovery.js.map +1 -1
- package/src/lib/route-idiom-diagnostics.js +24 -10
- package/src/lib/route-idiom-diagnostics.js.map +1 -1
- package/src/lib/route-manifest.d.ts +1 -1
- package/src/lib/route-manifest.js +7 -8
- package/src/lib/route-manifest.js.map +1 -1
- package/src/lib/router-plugin.js +8 -5
- package/src/lib/router-plugin.js.map +1 -1
- package/src/lib/server-fn-client-transform.js +1 -2
- package/src/lib/server-fn-id.js +1 -2
- package/src/lib/server-plugin.d.ts +9 -0
- package/src/lib/server-plugin.js +169 -0
- package/src/lib/server-plugin.js.map +1 -0
- package/src/lib/ssr/defer-streaming-plugin.js +0 -1
- package/src/lib/ssr/inject-html-plugin.js +1 -2
- package/src/lib/ssr/ssr-build-plugin.js +1 -2
- package/src/lib/typed-routes-plugin.js +7 -7
- package/src/lib/typed-routes-plugin.js.map +1 -1
- package/src/lib/utils/debug-harness.js +1 -2
- package/src/lib/utils/debug-log-file.js +1 -2
- package/src/lib/utils/debug.js +1 -2
- package/src/lib/utils/rolldown.js +1 -2
- package/src/server-mode-plugin.js +2 -2
- package/src/server-mode-plugin.js.map +1 -1
- package/src/lib/nx-plugin/src/executors/vite-dev-server/compat.d.ts +0 -3
- package/src/lib/nx-plugin/src/executors/vite-dev-server/compat.js +0 -7
- package/src/lib/nx-plugin/src/executors/vite-dev-server/compat.js.map +0 -1
- package/src/lib/nx-plugin/src/executors/vite-dev-server/schema.d.ts +0 -1
- package/src/lib/nx-plugin/src/executors/vite-dev-server/schema.json +0 -101
- package/src/lib/nx-plugin/src/executors/vite-dev-server/vite-dev-server.impl.d.ts +0 -2
- package/src/lib/nx-plugin/src/executors/vite-dev-server/vite-dev-server.impl.js +0 -6
- package/src/lib/nx-plugin/src/executors/vite-dev-server/vite-dev-server.impl.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"deps-plugin.js","names":[],"sources":["../../../src/lib/deps-plugin.ts"],"sourcesContent":["import
|
|
1
|
+
{"version":3,"file":"deps-plugin.js","names":[],"sources":["../../../src/lib/deps-plugin.ts"],"sourcesContent":["import { dirname, resolve } from 'node:path';\nimport { normalizePath, type Plugin } from 'vite';\nimport { crawlFrameworkPkgs } from 'vitefu';\n\nimport { angularLinkerPlugin } from './nitro/angular-linker-plugin.js';\nimport { Options } from './options.js';\nimport { debugPlatform } from './utils/debug.js';\nimport { getJsTransformConfigKey, isRolldown } from './utils/rolldown.js';\n\nconst ANGULAR_LINKED_SSR_DEPS = [\n '@angular/compiler',\n '@angular/core',\n '@angular/platform-browser',\n '@angular/platform-server',\n];\n\nexport function depsPlugin(options?: Options): Plugin[] {\n const workspaceRoot =\n options?.workspaceRoot ?? process.env['NX_WORKSPACE_ROOT'] ?? process.cwd();\n\n return [\n {\n name: 'analogjs-deps-plugin',\n config(userConfig) {\n // Skip Vite's built-in ts/js transform so `@analogjs/vite-plugin-angular`\n // (when the user includes it) owns Angular file compilation. Users who\n // run an alternative compiler, or compile non-Angular server code with\n // Vite, set the transform in their own Vite config. Theirs is kept\n // as-is: merging would concatenate these excludes into it, and an\n // exclude wins over any include they set.\n const jsTransformKey = getJsTransformConfigKey();\n // Vite 8 still converts a user's `esbuild` object to `oxc` (unless\n // `oxc` is set), but `esbuild: false` no longer has any effect there.\n const userTransform =\n userConfig?.[jsTransformKey] !== undefined ||\n (jsTransformKey === 'oxc' && !!userConfig?.esbuild);\n // With `server`, Vite compiles the server entry's directory instead,\n // which the Angular compiler leaves alone.\n const transform = options?.server\n ? {\n include: [\n `${normalizePath(\n resolve(\n userConfig?.root ?? process.cwd(),\n dirname(options.server.entry),\n ),\n )}/**/*.ts`,\n ],\n }\n : { exclude: ['**/*.ts', '**/*.js'] };\n debugPlatform('deps transform config', {\n jsTransformKey,\n transform: userTransform ? 'user' : transform,\n });\n\n return {\n ...(userTransform ? {} : { [jsTransformKey]: transform }),\n ssr: {\n noExternal: [\n '@analogjs/**',\n 'es-toolkit',\n 'firebase/**',\n 'firebase-admin/**',\n 'rxfire',\n '@ng-web-apis/**',\n '@taiga-ui/**',\n /^@tanstack\\/angular-/,\n ],\n // The server pre-bundle is resolved separately from the client\n // one, so a secondary entry point left out of it loads its own\n // copy of `@angular/core`. `inject()` then runs against a runtime\n // with no active injection context and SSR fails with NG0203.\n // With Rolldown, the rest of Angular is pre-bundled too and the\n // partial-compilation packages are linked, so the server needs no JIT.\n optimizeDeps: {\n include: [\n ...(isRolldown() ? ANGULAR_LINKED_SSR_DEPS : []),\n '@angular/common',\n '@angular/common/http',\n '@angular/core/rxjs-interop',\n ],\n ...(isRolldown()\n ? { rolldownOptions: { plugins: [angularLinkerPlugin()] } }\n : {}),\n },\n },\n optimizeDeps: {\n include: [\n '@angular/common',\n '@angular/common/http',\n '@angular/core/rxjs-interop',\n 'front-matter',\n ],\n exclude: [\n '@angular/platform-server',\n '@analogjs/content',\n '@analogjs/router',\n '@nx/angular',\n '@nx/vite',\n '@nx/devkit',\n '@nx/js',\n '@nx/devkit',\n '@nx/cypress',\n '@nx/jest',\n '@nx/js',\n '@nx/eslint',\n '@nx/webpack',\n '@nx/web',\n '@nx/workspace',\n '@nx/eslint',\n '@nx/module-federation',\n '@nx/rspack',\n 'webpack',\n 'fsevents',\n 'nx',\n ],\n },\n };\n },\n },\n {\n name: 'analogjs-auto-discover-deps',\n async config(config, { command }) {\n const pkgConfig = await crawlFrameworkPkgs({\n root: workspaceRoot,\n isBuild: command === 'build',\n viteUserConfig: config,\n isSemiFrameworkPkgByJson(pkgJson) {\n return pkgJson['module'] && pkgJson['module'].includes('fesm');\n },\n });\n return pkgConfig;\n },\n },\n ];\n}\n"],"mappings":";;;;;;;AASA,IAAM,0BAA0B;CAC9B;CACA;CACA;CACA;AACF;AAEA,SAAgB,WAAW,SAA6B;CACtD,MAAM,gBACJ,SAAS,iBAAiB,QAAQ,IAAI,wBAAwB,QAAQ,IAAI;CAE5E,OAAO,CACL;EACE,MAAM;EACN,OAAO,YAAY;GAOjB,MAAM,iBAAiB,wBAAwB;GAG/C,MAAM,gBACJ,aAAa,oBAAoB,KAAA,KAChC,mBAAmB,SAAS,CAAC,CAAC,YAAY;GAG7C,MAAM,YAAY,SAAS,SACvB,EACE,SAAS,CACP,GAAG,cACD,QACE,YAAY,QAAQ,QAAQ,IAAI,GAChC,QAAQ,QAAQ,OAAO,KAAK,CAC9B,CACF,EAAE,SACJ,EACF,IACA,EAAE,SAAS,CAAC,WAAW,SAAS,EAAE;GACtC,cAAc,yBAAyB;IACrC;IACA,WAAW,gBAAgB,SAAS;GACtC,CAAC;GAED,OAAO;IACL,GAAI,gBAAgB,CAAC,IAAI,GAAG,iBAAiB,UAAU;IACvD,KAAK;KACH,YAAY;MACV;MACA;MACA;MACA;MACA;MACA;MACA;MACA;KACF;KAOA,cAAc;MACZ,SAAS;OACP,GAAI,WAAW,IAAI,0BAA0B,CAAC;OAC9C;OACA;OACA;MACF;MACA,GAAI,WAAW,IACX,EAAE,iBAAiB,EAAE,SAAS,CAAC,oBAAoB,CAAC,EAAE,EAAE,IACxD,CAAC;KACP;IACF;IACA,cAAc;KACZ,SAAS;MACP;MACA;MACA;MACA;KACF;KACA,SAAS;MACP;MACA;MACA;MACA;MACA;MACA;MACA;MACA;MACA;MACA;MACA;MACA;MACA;MACA;MACA;MACA;MACA;MACA;MACA;MACA;MACA;KACF;IACF;GACF;EACF;CACF,GACA;EACE,MAAM;EACN,MAAM,OAAO,QAAQ,EAAE,WAAW;GAShC,OAAO,MARiB,mBAAmB;IACzC,MAAM;IACN,SAAS,YAAY;IACrB,gBAAgB;IAChB,yBAAyB,SAAS;KAChC,OAAO,QAAQ,aAAa,QAAQ,SAAS,CAAC,SAAS,MAAM;IAC/D;GACF,CAAC;EAEH;CACF,CACF;AACF"}
|
|
@@ -12,8 +12,8 @@ export interface DiscoveredLibraryRoutes {
|
|
|
12
12
|
*/
|
|
13
13
|
export declare function discoverLibraryRoutes(workspaceRoot: string): DiscoveredLibraryRoutes;
|
|
14
14
|
/**
|
|
15
|
-
* Builds `${dir}/**\/*.page.ts` globs for each
|
|
16
|
-
* platform registers these with Angular compilation
|
|
17
|
-
* for every `additionalPagesDirs` entry.
|
|
15
|
+
* Builds `${dir}/**\/*.page.ts` and `${dir}/**\/*.page.tsrx` globs for each
|
|
16
|
+
* provided directory. The platform registers these with Angular compilation
|
|
17
|
+
* through `analog.setup()` for every `additionalPagesDirs` entry.
|
|
18
18
|
*/
|
|
19
19
|
export declare function pageGlobs(dirs: string[]): string[];
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { normalizePath } from "vite";
|
|
2
2
|
import { globSync } from "tinyglobby";
|
|
3
|
-
|
|
3
|
+
// packages/platform/src/lib/discover-library-routes.ts
|
|
4
4
|
Object.freeze({
|
|
5
5
|
additionalPagesDirs: Object.freeze([]),
|
|
6
6
|
additionalContentDirs: Object.freeze([]),
|
|
@@ -59,14 +59,13 @@ function discoverLibraryRoutes(workspaceRoot) {
|
|
|
59
59
|
return result;
|
|
60
60
|
}
|
|
61
61
|
/**
|
|
62
|
-
* Builds `${dir}/**\/*.page.ts` globs for each
|
|
63
|
-
* platform registers these with Angular compilation
|
|
64
|
-
* for every `additionalPagesDirs` entry.
|
|
62
|
+
* Builds `${dir}/**\/*.page.ts` and `${dir}/**\/*.page.tsrx` globs for each
|
|
63
|
+
* provided directory. The platform registers these with Angular compilation
|
|
64
|
+
* through `analog.setup()` for every `additionalPagesDirs` entry.
|
|
65
65
|
*/
|
|
66
66
|
function pageGlobs(dirs) {
|
|
67
|
-
return dirs.
|
|
67
|
+
return dirs.flatMap((dir) => [`${dir}/**/*.page.ts`, `${dir}/**/*.page.tsrx`]);
|
|
68
68
|
}
|
|
69
|
-
//#endregion
|
|
70
69
|
export { discoverLibraryRoutes, pageGlobs };
|
|
71
70
|
|
|
72
71
|
//# sourceMappingURL=discover-library-routes.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"discover-library-routes.js","names":[],"sources":["../../../src/lib/discover-library-routes.ts"],"sourcesContent":["import { normalizePath } from 'vite';\nimport { globSync } from 'tinyglobby';\n\nexport interface DiscoveredLibraryRoutes {\n additionalPagesDirs: string[];\n additionalContentDirs: string[];\n additionalAPIDirs: string[];\n}\n\nconst empty: DiscoveredLibraryRoutes = Object.freeze({\n additionalPagesDirs: Object.freeze([] as string[]),\n additionalContentDirs: Object.freeze([] as string[]),\n additionalAPIDirs: Object.freeze([] as string[]),\n});\n\nconst discoverableLibRouteDirs = [\n 'libs/**/src/pages',\n 'libs/**/src/content',\n 'libs/**/src/api',\n] as const;\n\nfunction toWorkspacePath(path: string) {\n return normalizePath(path).replace(/\\/$/, '');\n}\n\n/**\n * Scans workspace libraries directly for conventional route directories\n * (`src/pages`, `src/content`, `src/api`).\n *\n * Returns workspace-relative paths (e.g. `/libs/shared/feature`) suitable\n * for merging into the `additional*Dirs` options.\n */\nexport function discoverLibraryRoutes(\n workspaceRoot: string,\n): DiscoveredLibraryRoutes {\n const result: DiscoveredLibraryRoutes = {\n additionalPagesDirs: [],\n additionalContentDirs: [],\n additionalAPIDirs: [],\n };\n const normalizedWorkspaceRoot = toWorkspacePath(workspaceRoot);\n const discovered = new Map<\n string,\n {\n pages: boolean;\n content: boolean;\n api: boolean;\n }\n >();\n\n for (const dir of globSync(discoverableLibRouteDirs, {\n cwd: normalizedWorkspaceRoot,\n dot: true,\n onlyDirectories: true,\n })) {\n const normalizedDir = toWorkspacePath(dir);\n const workspaceRelativeDir = normalizedDir.startsWith(\n `${normalizedWorkspaceRoot}/`,\n )\n ? normalizedDir.slice(normalizedWorkspaceRoot.length + 1)\n : normalizedDir;\n\n if (!workspaceRelativeDir.startsWith('libs/')) {\n continue;\n }\n\n const srcIndex = workspaceRelativeDir.indexOf('/src/');\n if (srcIndex === -1) {\n continue;\n }\n\n const libRoot = workspaceRelativeDir.slice(0, srcIndex);\n const entry = discovered.get(libRoot) ?? {\n pages: false,\n content: false,\n api: false,\n };\n\n if (workspaceRelativeDir.endsWith('/src/pages')) {\n entry.pages = true;\n }\n\n if (workspaceRelativeDir.endsWith('/src/content')) {\n entry.content = true;\n }\n\n if (workspaceRelativeDir.endsWith('/src/api')) {\n entry.api = true;\n }\n\n discovered.set(libRoot, entry);\n }\n\n for (const libRoot of [...discovered.keys()].sort()) {\n const entry = discovered.get(libRoot)!;\n\n if (entry.pages) {\n result.additionalPagesDirs.push(`/${libRoot}`);\n }\n\n if (entry.content) {\n result.additionalContentDirs.push(`/${libRoot}/src/content`);\n }\n\n if (entry.api) {\n result.additionalAPIDirs.push(`/${libRoot}/src/api`);\n }\n }\n\n return result;\n}\n\n/**\n * Builds `${dir}/**\\/*.page.ts` globs for each provided directory. The
|
|
1
|
+
{"version":3,"file":"discover-library-routes.js","names":[],"sources":["../../../src/lib/discover-library-routes.ts"],"sourcesContent":["import { normalizePath } from 'vite';\nimport { globSync } from 'tinyglobby';\n\nexport interface DiscoveredLibraryRoutes {\n additionalPagesDirs: string[];\n additionalContentDirs: string[];\n additionalAPIDirs: string[];\n}\n\nconst empty: DiscoveredLibraryRoutes = Object.freeze({\n additionalPagesDirs: Object.freeze([] as string[]),\n additionalContentDirs: Object.freeze([] as string[]),\n additionalAPIDirs: Object.freeze([] as string[]),\n});\n\nconst discoverableLibRouteDirs = [\n 'libs/**/src/pages',\n 'libs/**/src/content',\n 'libs/**/src/api',\n] as const;\n\nfunction toWorkspacePath(path: string) {\n return normalizePath(path).replace(/\\/$/, '');\n}\n\n/**\n * Scans workspace libraries directly for conventional route directories\n * (`src/pages`, `src/content`, `src/api`).\n *\n * Returns workspace-relative paths (e.g. `/libs/shared/feature`) suitable\n * for merging into the `additional*Dirs` options.\n */\nexport function discoverLibraryRoutes(\n workspaceRoot: string,\n): DiscoveredLibraryRoutes {\n const result: DiscoveredLibraryRoutes = {\n additionalPagesDirs: [],\n additionalContentDirs: [],\n additionalAPIDirs: [],\n };\n const normalizedWorkspaceRoot = toWorkspacePath(workspaceRoot);\n const discovered = new Map<\n string,\n {\n pages: boolean;\n content: boolean;\n api: boolean;\n }\n >();\n\n for (const dir of globSync(discoverableLibRouteDirs, {\n cwd: normalizedWorkspaceRoot,\n dot: true,\n onlyDirectories: true,\n })) {\n const normalizedDir = toWorkspacePath(dir);\n const workspaceRelativeDir = normalizedDir.startsWith(\n `${normalizedWorkspaceRoot}/`,\n )\n ? normalizedDir.slice(normalizedWorkspaceRoot.length + 1)\n : normalizedDir;\n\n if (!workspaceRelativeDir.startsWith('libs/')) {\n continue;\n }\n\n const srcIndex = workspaceRelativeDir.indexOf('/src/');\n if (srcIndex === -1) {\n continue;\n }\n\n const libRoot = workspaceRelativeDir.slice(0, srcIndex);\n const entry = discovered.get(libRoot) ?? {\n pages: false,\n content: false,\n api: false,\n };\n\n if (workspaceRelativeDir.endsWith('/src/pages')) {\n entry.pages = true;\n }\n\n if (workspaceRelativeDir.endsWith('/src/content')) {\n entry.content = true;\n }\n\n if (workspaceRelativeDir.endsWith('/src/api')) {\n entry.api = true;\n }\n\n discovered.set(libRoot, entry);\n }\n\n for (const libRoot of [...discovered.keys()].sort()) {\n const entry = discovered.get(libRoot)!;\n\n if (entry.pages) {\n result.additionalPagesDirs.push(`/${libRoot}`);\n }\n\n if (entry.content) {\n result.additionalContentDirs.push(`/${libRoot}/src/content`);\n }\n\n if (entry.api) {\n result.additionalAPIDirs.push(`/${libRoot}/src/api`);\n }\n }\n\n return result;\n}\n\n/**\n * Builds `${dir}/**\\/*.page.ts` and `${dir}/**\\/*.page.tsrx` globs for each\n * provided directory. The platform registers these with Angular compilation\n * through `analog.setup()` for every `additionalPagesDirs` entry.\n */\nexport function pageGlobs(dirs: string[]): string[] {\n return dirs.flatMap((dir) => [\n `${dir}/**/*.page.ts`,\n `${dir}/**/*.page.tsrx`,\n ]);\n}\n"],"mappings":";;;AASuC,OAAO,OAAO;CACnD,qBAAqB,OAAO,OAAO,CAAC,CAAa;CACjD,uBAAuB,OAAO,OAAO,CAAC,CAAa;CACnD,mBAAmB,OAAO,OAAO,CAAC,CAAa;AACjD,CAAC;AAED,IAAM,2BAA2B;CAC/B;CACA;CACA;AACF;AAEA,SAAS,gBAAgB,MAAc;CACrC,OAAO,cAAc,IAAI,CAAC,CAAC,QAAQ,OAAO,EAAE;AAC9C;;;;;;;;AASA,SAAgB,sBACd,eACyB;CACzB,MAAM,SAAkC;EACtC,qBAAqB,CAAC;EACtB,uBAAuB,CAAC;EACxB,mBAAmB,CAAC;CACtB;CACA,MAAM,0BAA0B,gBAAgB,aAAa;CAC7D,MAAM,6BAAa,IAAI,IAOrB;CAEF,KAAK,MAAM,OAAO,SAAS,0BAA0B;EACnD,KAAK;EACL,KAAK;EACL,iBAAiB;CACnB,CAAC,GAAG;EACF,MAAM,gBAAgB,gBAAgB,GAAG;EACzC,MAAM,uBAAuB,cAAc,WACzC,GAAG,wBAAwB,EAC7B,IACI,cAAc,MAAM,wBAAwB,SAAS,CAAC,IACtD;EAEJ,IAAI,CAAC,qBAAqB,WAAW,OAAO,GAC1C;EAGF,MAAM,WAAW,qBAAqB,QAAQ,OAAO;EACrD,IAAI,aAAa,IACf;EAGF,MAAM,UAAU,qBAAqB,MAAM,GAAG,QAAQ;EACtD,MAAM,QAAQ,WAAW,IAAI,OAAO,KAAK;GACvC,OAAO;GACP,SAAS;GACT,KAAK;EACP;EAEA,IAAI,qBAAqB,SAAS,YAAY,GAC5C,MAAM,QAAQ;EAGhB,IAAI,qBAAqB,SAAS,cAAc,GAC9C,MAAM,UAAU;EAGlB,IAAI,qBAAqB,SAAS,UAAU,GAC1C,MAAM,MAAM;EAGd,WAAW,IAAI,SAAS,KAAK;CAC/B;CAEA,KAAK,MAAM,WAAW,CAAC,GAAG,WAAW,KAAK,CAAC,CAAC,CAAC,KAAK,GAAG;EACnD,MAAM,QAAQ,WAAW,IAAI,OAAO;EAEpC,IAAI,MAAM,OACR,OAAO,oBAAoB,KAAK,IAAI,SAAS;EAG/C,IAAI,MAAM,SACR,OAAO,sBAAsB,KAAK,IAAI,QAAQ,aAAa;EAG7D,IAAI,MAAM,KACR,OAAO,kBAAkB,KAAK,IAAI,QAAQ,SAAS;CAEvD;CAEA,OAAO;AACT;;;;;;AAOA,SAAgB,UAAU,MAA0B;CAClD,OAAO,KAAK,SAAS,QAAQ,CAC3B,GAAG,IAAI,gBACP,GAAG,IAAI,gBACT,CAAC;AACH"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
type GetPageEndpointsArgs = {
|
|
2
|
+
workspaceRoot: string;
|
|
3
|
+
sourceRoot: string;
|
|
4
|
+
rootDir: string;
|
|
5
|
+
additionalPagesDirs?: string[];
|
|
6
|
+
};
|
|
7
|
+
export type PageEndpoint = {
|
|
8
|
+
/** Absolute path to the page's `.server.ts` file. */
|
|
9
|
+
file: string;
|
|
10
|
+
/** Route relative to the endpoint root, e.g. `/pages/users/:id`. */
|
|
11
|
+
route: string;
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* Discovers server-side page endpoints: every `.server.ts` file under
|
|
15
|
+
* `app/pages/**` and any additional pages directories, mapped to a route
|
|
16
|
+
* pattern. Servers mount them under their own prefix.
|
|
17
|
+
*
|
|
18
|
+
* Route transformation examples:
|
|
19
|
+
* - index.server.ts → /pages/index
|
|
20
|
+
* - users/[id].server.ts → /pages/users/:id
|
|
21
|
+
* - products/[...slug].server.ts → /pages/products/**:slug
|
|
22
|
+
* - (auth)/login.server.ts → /pages/-auth-/login
|
|
23
|
+
*/
|
|
24
|
+
export declare function getPageEndpoints({ workspaceRoot, sourceRoot, rootDir, additionalPagesDirs }: GetPageEndpointsArgs): PageEndpoint[];
|
|
25
|
+
export {};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { resolve } from "node:path";
|
|
2
|
+
import { normalizePath } from "vite";
|
|
3
|
+
import { globSync } from "tinyglobby";
|
|
4
|
+
// packages/platform/src/lib/get-page-endpoints.ts
|
|
5
|
+
/**
|
|
6
|
+
* Discovers server-side page endpoints: every `.server.ts` file under
|
|
7
|
+
* `app/pages/**` and any additional pages directories, mapped to a route
|
|
8
|
+
* pattern. Servers mount them under their own prefix.
|
|
9
|
+
*
|
|
10
|
+
* Route transformation examples:
|
|
11
|
+
* - index.server.ts → /pages/index
|
|
12
|
+
* - users/[id].server.ts → /pages/users/:id
|
|
13
|
+
* - products/[...slug].server.ts → /pages/products/**:slug
|
|
14
|
+
* - (auth)/login.server.ts → /pages/-auth-/login
|
|
15
|
+
*/
|
|
16
|
+
function getPageEndpoints({ workspaceRoot, sourceRoot, rootDir, additionalPagesDirs }) {
|
|
17
|
+
const root = normalizePath(resolve(workspaceRoot, rootDir));
|
|
18
|
+
return globSync([`${root}/${sourceRoot}/app/pages/**/*.server.ts`, ...(additionalPagesDirs || []).map((dir) => `${workspaceRoot}${dir}/**/*.server.ts`)], {
|
|
19
|
+
dot: true,
|
|
20
|
+
absolute: true
|
|
21
|
+
}).map((file) => ({
|
|
22
|
+
file,
|
|
23
|
+
route: normalizePath(file).replace(/^(.*?)\/pages/, "/pages").replace(/\.server\.ts$/, "").replace(/\[\.{3}(.+)\]/g, "**:$1").replace(/\[\.{3}(\w+)\]/g, "**:$1").replace(/\/\(([^/]+)\)/g, "/-$1-").replace(/\[(\w+)\]/g, ":$1").replace(/\./g, "/")
|
|
24
|
+
}));
|
|
25
|
+
}
|
|
26
|
+
export { getPageEndpoints };
|
|
27
|
+
|
|
28
|
+
//# sourceMappingURL=get-page-endpoints.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get-page-endpoints.js","names":[],"sources":["../../../src/lib/get-page-endpoints.ts"],"sourcesContent":["import { resolve } from 'node:path';\nimport { globSync } from 'tinyglobby';\nimport { normalizePath } from 'vite';\n\ntype GetPageEndpointsArgs = {\n workspaceRoot: string;\n sourceRoot: string;\n rootDir: string;\n additionalPagesDirs?: string[];\n};\n\nexport type PageEndpoint = {\n /** Absolute path to the page's `.server.ts` file. */\n file: string;\n /** Route relative to the endpoint root, e.g. `/pages/users/:id`. */\n route: string;\n};\n\n/**\n * Discovers server-side page endpoints: every `.server.ts` file under\n * `app/pages/**` and any additional pages directories, mapped to a route\n * pattern. Servers mount them under their own prefix.\n *\n * Route transformation examples:\n * - index.server.ts → /pages/index\n * - users/[id].server.ts → /pages/users/:id\n * - products/[...slug].server.ts → /pages/products/**:slug\n * - (auth)/login.server.ts → /pages/-auth-/login\n */\nexport function getPageEndpoints({\n workspaceRoot,\n sourceRoot,\n rootDir,\n additionalPagesDirs,\n}: GetPageEndpointsArgs): PageEndpoint[] {\n const root = normalizePath(resolve(workspaceRoot, rootDir));\n\n const endpointFiles: string[] = globSync(\n [\n `${root}/${sourceRoot}/app/pages/**/*.server.ts`,\n ...(additionalPagesDirs || []).map(\n (dir) => `${workspaceRoot}${dir}/**/*.server.ts`,\n ),\n ],\n { dot: true, absolute: true },\n );\n\n return endpointFiles.map((file) => ({\n file,\n route: normalizePath(file)\n .replace(/^(.*?)\\/pages/, '/pages')\n .replace(/\\.server\\.ts$/, '')\n .replace(/\\[\\.{3}(.+)\\]/g, '**:$1')\n .replace(/\\[\\.{3}(\\w+)\\]/g, '**:$1')\n // Strip Angular Router group syntax `(group)` from any segment, not\n // just trailing ones. Routes like `(auth)/login.server.ts` need to\n // become `/-auth-/login`, otherwise the literal parens leak through\n // and the endpoint is mounted under an invalid path.\n .replace(/\\/\\(([^/]+)\\)/g, '/-$1-')\n .replace(/\\[(\\w+)\\]/g, ':$1')\n .replace(/\\./g, '/'),\n }));\n}\n"],"mappings":";;;;;;;;;;;;;;;AA6BA,SAAgB,iBAAiB,EAC/B,eACA,YACA,SACA,uBACuC;CACvC,MAAM,OAAO,cAAc,QAAQ,eAAe,OAAO,CAAC;CAY1D,OAVgC,SAC9B,CACE,GAAG,KAAK,GAAG,WAAW,4BACtB,IAAI,uBAAuB,CAAC,EAAA,CAAG,KAC5B,QAAQ,GAAG,gBAAgB,IAAI,gBAClC,CACF,GACA;EAAE,KAAK;EAAM,UAAU;CAAK,CAGvB,CAAA,CAAc,KAAK,UAAU;EAClC;EACA,OAAO,cAAc,IAAI,CAAC,CACvB,QAAQ,iBAAiB,QAAQ,CAAC,CAClC,QAAQ,iBAAiB,EAAE,CAAC,CAC5B,QAAQ,kBAAkB,OAAO,CAAC,CAClC,QAAQ,mBAAmB,OAAO,CAAC,CAKnC,QAAQ,kBAAkB,OAAO,CAAC,CAClC,QAAQ,cAAc,KAAK,CAAC,CAC5B,QAAQ,OAAO,GAAG;CACvB,EAAE;AACJ"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { deriveServerFnId } from "./server-fn-id.js";
|
|
2
2
|
import { parseSync } from "oxc-parser";
|
|
3
3
|
import MagicString from "magic-string";
|
|
4
|
-
|
|
4
|
+
// packages/platform/src/lib/inject-server-fn-ids.ts
|
|
5
5
|
var SERVER_FN_SOURCE = "@analogjs/router/server";
|
|
6
6
|
/**
|
|
7
7
|
* Server/SSR-build transform: injects the derived `id` into each
|
|
@@ -88,7 +88,6 @@ function collectServerFnLocalNames(body) {
|
|
|
88
88
|
if (names.size === 0) names.add("serverFn");
|
|
89
89
|
return names;
|
|
90
90
|
}
|
|
91
|
-
//#endregion
|
|
92
91
|
export { injectServerFnIds };
|
|
93
92
|
|
|
94
93
|
//# sourceMappingURL=inject-server-fn-ids.js.map
|
|
@@ -8,11 +8,11 @@ import type { Options } from "../options.js";
|
|
|
8
8
|
*/
|
|
9
9
|
export declare function analogNitroPlugin(options?: Options): Plugin;
|
|
10
10
|
/**
|
|
11
|
-
* Walks Nitro's resolved routeRules and stamps `x-analog-no-ssr
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
11
|
+
* Walks Nitro's resolved routeRules and stamps `x-analog-no-ssr` onto any rule
|
|
12
|
+
* setting `ssr`, and `x-analog-no-streaming` onto any rule setting
|
|
13
|
+
* `streaming`. Nitro drops `false` values when it merges rules, so the headers
|
|
14
|
+
* carry them, and a narrower `true` rule overrides with `'false'`. The SSR
|
|
15
|
+
* renderer virtual above reads them from the matched rules, and they reach
|
|
16
|
+
* the response as hints for downstream consumers (CDN, edge logic).
|
|
17
17
|
*/
|
|
18
18
|
export declare function injectAnalogRouteRuleHeaders(nitro: Nitro): void;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { serverFnFileId } from "../server-fn-id.js";
|
|
2
|
-
import { injectServerFnIds } from "../inject-server-fn-ids.js";
|
|
3
1
|
import { SERVER_MODE_ID } from "../../server-mode-plugin.js";
|
|
2
|
+
import { injectServerFnIds } from "../inject-server-fn-ids.js";
|
|
3
|
+
import { serverFnFileId } from "../server-fn-id.js";
|
|
4
4
|
import { getPageHandlers } from "./get-page-handlers.js";
|
|
5
5
|
import { pageEndpointsPlugin } from "./page-endpoints-plugin.js";
|
|
6
6
|
import { getMatchingContentFilesWithFrontMatter } from "./get-content-files.js";
|
|
@@ -13,7 +13,7 @@ import { createRequire } from "node:module";
|
|
|
13
13
|
import { basename, dirname, join, relative, resolve } from "node:path";
|
|
14
14
|
import { existsSync, readFileSync, readdirSync, unlinkSync } from "node:fs";
|
|
15
15
|
import { mkdir, writeFile } from "node:fs/promises";
|
|
16
|
-
|
|
16
|
+
// packages/platform/src/lib/nitro/analog-nitro-plugin.ts
|
|
17
17
|
var SSR_ENTRY_VIRTUAL_ID = "\0virtual:@analogjs/nitro/ssr-entry";
|
|
18
18
|
/**
|
|
19
19
|
* Analog's NitroModule. Plug it into the Vite plugin chain alongside
|
|
@@ -88,13 +88,10 @@ function analogNitroPlugin(options = {}) {
|
|
|
88
88
|
server: { fs: { allow: [context.workspaceRoot] } },
|
|
89
89
|
environments: { client: { build: { rollupOptions: { input: indexHtmlPath() } } } }
|
|
90
90
|
};
|
|
91
|
-
if (ssr) {
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
rollupOptions: { input: { index: ssrEntryMarkerPath } }
|
|
96
|
-
} };
|
|
97
|
-
}
|
|
91
|
+
if (ssr) overrides.environments["ssr"] = { build: {
|
|
92
|
+
outDir: resolve(context.workspaceRoot, "dist", context.rootDir, "ssr"),
|
|
93
|
+
rollupOptions: { input: { index: ssrEntryMarkerPath } }
|
|
94
|
+
} };
|
|
98
95
|
return overrides;
|
|
99
96
|
},
|
|
100
97
|
configureServer(server) {
|
|
@@ -212,9 +209,10 @@ function analogNitroPlugin(options = {}) {
|
|
|
212
209
|
const serverDir = resolve(context.workspaceRoot, context.rootDir, `${context.sourceRoot}/server`);
|
|
213
210
|
const apiDirs = (options.additionalAPIDirs ?? []).map((dir) => resolve(context.workspaceRoot, `.${dir}`));
|
|
214
211
|
for (const dir of [serverDir, ...apiDirs]) if (existsSync(dir) && !nitro.options.scanDirs.includes(dir)) nitro.options.scanDirs.push(dir);
|
|
215
|
-
nitro.hooks.hook("
|
|
212
|
+
nitro.hooks.hook("build:config", (_n, buildConfig) => {
|
|
213
|
+
const rollupConfig = buildConfig.rollup ?? buildConfig.rolldown;
|
|
216
214
|
if (Array.isArray(rollupConfig.plugins)) rollupConfig.plugins.push(nitroH3Resolver, pageEndpointsPlugin(), serverFnIdPlugin(resolve(context.workspaceRoot, context.rootDir)));
|
|
217
|
-
applyAnalogNitroExternals(rollupConfig);
|
|
215
|
+
if (nitro.options.node && nitro.options.noExternals !== true) applyAnalogNitroExternals(rollupConfig);
|
|
218
216
|
sanitizeNitroBundlerConfig(rollupConfig);
|
|
219
217
|
});
|
|
220
218
|
if (ssr) {
|
|
@@ -284,7 +282,8 @@ function registerServerFns(nitro, context) {
|
|
|
284
282
|
nitro.options.handlers.push(getServerFnDispatchHandler());
|
|
285
283
|
nitro.options.virtual[SERVER_FN_DISPATCH_VIRTUAL] = buildServerFnDispatchModule({
|
|
286
284
|
modules,
|
|
287
|
-
appConfigModule
|
|
285
|
+
appConfigModule,
|
|
286
|
+
root
|
|
288
287
|
});
|
|
289
288
|
}
|
|
290
289
|
/**
|
|
@@ -307,7 +306,7 @@ function serverFnIdPlugin(projectRoot) {
|
|
|
307
306
|
/**
|
|
308
307
|
* Builds the h3 handler installed as Nitro's `renderer.handler`. Short-circuits
|
|
309
308
|
* `ssr: false` routes to the raw client template; otherwise dispatches the
|
|
310
|
-
* request to the SSR service env (`
|
|
309
|
+
* request to the SSR service env (`fetchService("ssr", req)` works in dev via
|
|
311
310
|
* the env-runner and in prod via the `__nitro_vite_envs__` global set up by
|
|
312
311
|
* nitro/vite's `prodSetup`).
|
|
313
312
|
*/
|
|
@@ -322,23 +321,29 @@ const TEMPLATE = ${JSON.stringify(template)};
|
|
|
322
321
|
export default defineHandler(async (event) => {
|
|
323
322
|
event.res.headers.set('content-type', 'text/html; charset=utf-8');
|
|
324
323
|
// 'x-analog-no-ssr' is stamped on the route rule headers by
|
|
325
|
-
// injectAnalogRouteRuleHeaders
|
|
326
|
-
//
|
|
324
|
+
// injectAnalogRouteRuleHeaders. Nitro writes those headers after the
|
|
325
|
+
// handler runs, so read the matched rules.
|
|
327
326
|
const { routeRules } = getRouteRules(event.req.method, event.url.pathname);
|
|
328
327
|
if (routeRules?.headers?.['x-analog-no-ssr'] === 'true') {
|
|
329
328
|
return TEMPLATE;
|
|
330
329
|
}
|
|
331
330
|
const service = ssr.default ?? ssr;
|
|
332
331
|
// The SSR service renders without a Node response, so forward the
|
|
333
|
-
// \`streaming: false\` rule on the request for the renderer to read.
|
|
332
|
+
// \`streaming: false\` rule on the request for the renderer to read. Only
|
|
333
|
+
// the route rule decides it, never the client.
|
|
334
|
+
const headers = new Headers(event.req.headers);
|
|
335
|
+
headers.delete('x-analog-no-ssr');
|
|
336
|
+
headers.delete('x-analog-no-streaming');
|
|
334
337
|
if (routeRules?.headers?.['x-analog-no-streaming'] === 'true') {
|
|
335
|
-
const headers = new Headers(event.req.headers);
|
|
336
338
|
headers.set('x-analog-no-streaming', 'true');
|
|
337
|
-
return service.fetch(
|
|
338
|
-
new Request(event.req.url, { method: event.req.method, headers }),
|
|
339
|
-
);
|
|
340
339
|
}
|
|
341
|
-
|
|
340
|
+
const request = new Request(event.req.url, {
|
|
341
|
+
method: event.req.method,
|
|
342
|
+
headers,
|
|
343
|
+
signal: event.req.signal,
|
|
344
|
+
});
|
|
345
|
+
request.waitUntil = (task) => event.waitUntil(task);
|
|
346
|
+
return service.fetch(request);
|
|
342
347
|
});
|
|
343
348
|
`;
|
|
344
349
|
}
|
|
@@ -347,7 +352,7 @@ export default defineHandler(async (event) => {
|
|
|
347
352
|
* this function is bundler-agnostic: works in Vite-built main bundles and
|
|
348
353
|
* Rolldown-built prerender bundles alike.
|
|
349
354
|
*
|
|
350
|
-
* - Dev: dispatch through nitro/vite's env runner (\`
|
|
355
|
+
* - Dev: dispatch through nitro/vite's env runner (\`fetchService\`); the SSR
|
|
351
356
|
* service module isn't on disk yet, so we delegate to the runner.
|
|
352
357
|
* - Build / prerender: re-export the built SSR entry directly from the
|
|
353
358
|
* filesystem. By the time Nitro's bundlers ask for \`#analog/ssr\`, Vite has
|
|
@@ -356,14 +361,14 @@ export default defineHandler(async (event) => {
|
|
|
356
361
|
*/
|
|
357
362
|
function generateSsrServiceVirtual(nitro) {
|
|
358
363
|
if (nitro.options.dev) return `
|
|
359
|
-
import {
|
|
364
|
+
import { fetchService } from 'nitro/services';
|
|
360
365
|
export default {
|
|
361
366
|
// The dev runner answers from a worker, and a rejection there comes back as
|
|
362
367
|
// something Nitro cannot turn into a response, so the request hangs with no
|
|
363
368
|
// status and no message. Answer with the failure instead.
|
|
364
369
|
async fetch(req) {
|
|
365
370
|
try {
|
|
366
|
-
return await
|
|
371
|
+
return await fetchService('ssr', req);
|
|
367
372
|
} catch (err) {
|
|
368
373
|
console.error('[analog ssr]', err);
|
|
369
374
|
const message = err instanceof Error ? (err.stack ?? err.message) : String(err);
|
|
@@ -432,24 +437,24 @@ function sanitizeNitroBundlerConfig(rollupConfig) {
|
|
|
432
437
|
}
|
|
433
438
|
}
|
|
434
439
|
/**
|
|
435
|
-
* Walks Nitro's resolved routeRules and stamps `x-analog-no-ssr
|
|
436
|
-
*
|
|
437
|
-
*
|
|
438
|
-
*
|
|
439
|
-
*
|
|
440
|
-
*
|
|
440
|
+
* Walks Nitro's resolved routeRules and stamps `x-analog-no-ssr` onto any rule
|
|
441
|
+
* setting `ssr`, and `x-analog-no-streaming` onto any rule setting
|
|
442
|
+
* `streaming`. Nitro drops `false` values when it merges rules, so the headers
|
|
443
|
+
* carry them, and a narrower `true` rule overrides with `'false'`. The SSR
|
|
444
|
+
* renderer virtual above reads them from the matched rules, and they reach
|
|
445
|
+
* the response as hints for downstream consumers (CDN, edge logic).
|
|
441
446
|
*/
|
|
442
447
|
function injectAnalogRouteRuleHeaders(nitro) {
|
|
443
448
|
const routeRules = nitro.options.routeRules;
|
|
444
449
|
if (!routeRules) return;
|
|
445
450
|
for (const rule of Object.values(routeRules)) {
|
|
446
|
-
if (rule?.ssr ===
|
|
451
|
+
if (typeof rule?.ssr === "boolean") rule.headers = {
|
|
447
452
|
...rule.headers,
|
|
448
|
-
"x-analog-no-ssr":
|
|
453
|
+
"x-analog-no-ssr": String(!rule.ssr)
|
|
449
454
|
};
|
|
450
|
-
if (rule?.streaming ===
|
|
455
|
+
if (typeof rule?.streaming === "boolean") rule.headers = {
|
|
451
456
|
...rule.headers,
|
|
452
|
-
"x-analog-no-streaming":
|
|
457
|
+
"x-analog-no-streaming": String(!rule.streaming)
|
|
453
458
|
};
|
|
454
459
|
}
|
|
455
460
|
}
|
|
@@ -472,6 +477,7 @@ function generateSsrEntryWrapper(entryServer, template) {
|
|
|
472
477
|
// as event replay on the server.
|
|
473
478
|
import ${JSON.stringify(SERVER_MODE_ID)};
|
|
474
479
|
import { serverFetch as nitroServerFetch } from 'nitro';
|
|
480
|
+
import { getProxyRequestHeaders } from 'nitro/h3';
|
|
475
481
|
import { createFetch } from 'ofetch';
|
|
476
482
|
import renderer from ${JSON.stringify(entryServer)};
|
|
477
483
|
|
|
@@ -510,6 +516,34 @@ if (typeof globalThis.$fetch === 'undefined') {
|
|
|
510
516
|
globalThis.$fetch = ssrOFetch;
|
|
511
517
|
}
|
|
512
518
|
|
|
519
|
+
// Like h3's fetchWithEvent: in-process requests carry the incoming request's
|
|
520
|
+
// headers (minus hop-by-hop) and are cancelled with it. Conditional and range
|
|
521
|
+
// headers describe the document, not the data it loads.
|
|
522
|
+
const DOCUMENT_ONLY_HEADERS = [
|
|
523
|
+
'if-match',
|
|
524
|
+
'if-none-match',
|
|
525
|
+
'if-modified-since',
|
|
526
|
+
'if-unmodified-since',
|
|
527
|
+
'if-range',
|
|
528
|
+
'range',
|
|
529
|
+
];
|
|
530
|
+
const requestOFetch = (req) =>
|
|
531
|
+
createFetch({
|
|
532
|
+
fetch: (resource, init) => {
|
|
533
|
+
const headers = new Headers(
|
|
534
|
+
getProxyRequestHeaders(
|
|
535
|
+
{ req },
|
|
536
|
+
{ host: true, filterHeaders: DOCUMENT_ONLY_HEADERS },
|
|
537
|
+
),
|
|
538
|
+
);
|
|
539
|
+
new Headers(init?.headers).forEach((value, name) => headers.set(name, value));
|
|
540
|
+
const signal = init?.signal
|
|
541
|
+
? AbortSignal.any([req.signal, init.signal])
|
|
542
|
+
: req.signal;
|
|
543
|
+
return ssrFetch(resource, { ...init, headers, signal });
|
|
544
|
+
},
|
|
545
|
+
});
|
|
546
|
+
|
|
513
547
|
export default {
|
|
514
548
|
async fetch(req) {
|
|
515
549
|
const url = new URL(req.url);
|
|
@@ -518,38 +552,73 @@ export default {
|
|
|
518
552
|
// server data loaders that read from req.url see the full path+query.
|
|
519
553
|
const requestUrl = requestPath + url.search;
|
|
520
554
|
|
|
521
|
-
if (req.headers.get('x-analog-no-ssr') === 'true') {
|
|
522
|
-
return new Response(TEMPLATE, {
|
|
523
|
-
status: 200,
|
|
524
|
-
headers: { 'content-type': 'text/html; charset=utf-8' },
|
|
525
|
-
});
|
|
526
|
-
}
|
|
527
|
-
|
|
528
555
|
const reqShim = {
|
|
529
556
|
headers: Object.fromEntries(req.headers.entries()),
|
|
530
557
|
url: requestUrl,
|
|
531
558
|
originalUrl: requestUrl,
|
|
532
559
|
connection: {},
|
|
533
560
|
};
|
|
561
|
+
// Carries the status and headers the app sets through RESPONSE.
|
|
562
|
+
const resHeaders = new Headers();
|
|
563
|
+
const resShim = {
|
|
564
|
+
statusCode: 200,
|
|
565
|
+
getHeader(name) {
|
|
566
|
+
if (name.toLowerCase() !== 'set-cookie') {
|
|
567
|
+
return resHeaders.get(name) ?? undefined;
|
|
568
|
+
}
|
|
569
|
+
const cookies = resHeaders.getSetCookie();
|
|
570
|
+
return cookies.length ? cookies : undefined;
|
|
571
|
+
},
|
|
572
|
+
hasHeader: (name) => resHeaders.has(name),
|
|
573
|
+
setHeader(name, value) {
|
|
574
|
+
resHeaders.delete(name);
|
|
575
|
+
for (const item of [value].flat()) {
|
|
576
|
+
resHeaders.append(name, String(item));
|
|
577
|
+
}
|
|
578
|
+
return resShim;
|
|
579
|
+
},
|
|
580
|
+
removeHeader: (name) => resHeaders.delete(name),
|
|
581
|
+
};
|
|
534
582
|
|
|
535
583
|
try {
|
|
536
584
|
const html = await renderer(requestUrl, TEMPLATE, {
|
|
537
585
|
req: reqShim,
|
|
586
|
+
res: resShim,
|
|
538
587
|
// Pass the ofetch-wrapped fetch — INTERNAL_FETCH is consumed by the
|
|
539
588
|
// router's request-context interceptor via \`serverFetch.raw(...)\`,
|
|
540
589
|
// which is ofetch's response-shape API. Plain fetch lacks \`.raw\`
|
|
541
590
|
// and throws TypeError during prerender/SSR.
|
|
542
|
-
fetch:
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
headers: { 'content-type': 'text/html; charset=utf-8' },
|
|
591
|
+
fetch: requestOFetch(req),
|
|
592
|
+
signal: req.signal,
|
|
593
|
+
waitUntil: req.waitUntil?.bind(req),
|
|
594
|
+
renderErrorsAsHtml: true,
|
|
547
595
|
});
|
|
596
|
+
const headers = new Headers(resHeaders);
|
|
597
|
+
if (!headers.has('content-type')) {
|
|
598
|
+
headers.set('content-type', 'text/html; charset=utf-8');
|
|
599
|
+
}
|
|
600
|
+
const status = resShim.statusCode;
|
|
601
|
+
if ([204, 205, 304].includes(status)) {
|
|
602
|
+
if (typeof html !== 'string') {
|
|
603
|
+
await html.cancel();
|
|
604
|
+
}
|
|
605
|
+
return new Response(null, { status, headers });
|
|
606
|
+
}
|
|
607
|
+
// So intermediaries don't cache or buffer partial HTML.
|
|
608
|
+
if (typeof html !== 'string' && !html[Symbol.for('analog.bufferedStream')]) {
|
|
609
|
+
headers.set('content-encoding', 'identity');
|
|
610
|
+
headers.set('cache-control', 'no-store, no-transform');
|
|
611
|
+
}
|
|
612
|
+
return new Response(html, { status, headers });
|
|
548
613
|
} catch (err) {
|
|
549
614
|
console.error('[analog ssr]', err);
|
|
615
|
+
const status = err?.statusCode ?? err?.status;
|
|
550
616
|
return new Response(TEMPLATE, {
|
|
551
|
-
status: 500,
|
|
552
|
-
headers: {
|
|
617
|
+
status: status >= 400 && status <= 599 ? status : 500,
|
|
618
|
+
headers: {
|
|
619
|
+
'content-type': 'text/html; charset=utf-8',
|
|
620
|
+
'cache-control': 'no-store',
|
|
621
|
+
},
|
|
553
622
|
});
|
|
554
623
|
}
|
|
555
624
|
},
|
|
@@ -563,7 +632,7 @@ async function wirePrerender(nitro, options, context, apiPrefix) {
|
|
|
563
632
|
const expanded = options.i18n ? expandRoutesWithLocales(collected, {
|
|
564
633
|
defaultLocale: options.i18n.defaultLocale,
|
|
565
634
|
locales: options.i18n.locales
|
|
566
|
-
}) : collected;
|
|
635
|
+
}, apiPrefix) : collected;
|
|
567
636
|
const nitroPrerender = nitro.options.prerender ??= {};
|
|
568
637
|
nitroPrerender.routes ??= [];
|
|
569
638
|
nitroPrerender.routes.push(...expanded);
|
|
@@ -638,7 +707,6 @@ async function collectRoutes(routesInput, context, apiPrefix) {
|
|
|
638
707
|
routeSourceFiles
|
|
639
708
|
};
|
|
640
709
|
}
|
|
641
|
-
//#endregion
|
|
642
710
|
export { analogNitroPlugin, injectAnalogRouteRuleHeaders };
|
|
643
711
|
|
|
644
712
|
//# sourceMappingURL=analog-nitro-plugin.js.map
|