@analogjs/platform 3.0.0-beta.5 → 3.0.0-beta.51

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 (88) hide show
  1. package/migrations/migrate-to-separated-plugins/migrate-to-separated-plugins.js +2 -1
  2. package/migrations/migrate-to-separated-plugins/migrate-to-separated-plugins.js.map +1 -1
  3. package/migrations/migrate-vitest-builder-aliases/migrate-vitest-builder-aliases.js +2 -1
  4. package/migrations/migrate-vitest-builder-aliases/migrate-vitest-builder-aliases.js.map +1 -1
  5. package/package.json +12 -9
  6. package/src/lib/content-plugin.js +12 -3
  7. package/src/lib/content-plugin.js.map +1 -1
  8. package/src/lib/deps-plugin.d.ts +1 -1
  9. package/src/lib/deps-plugin.js +11 -7
  10. package/src/lib/deps-plugin.js.map +1 -1
  11. package/src/lib/discover-library-routes.d.ts +3 -3
  12. package/src/lib/discover-library-routes.js +4 -4
  13. package/src/lib/discover-library-routes.js.map +1 -1
  14. package/src/lib/get-page-endpoints.d.ts +25 -0
  15. package/src/lib/get-page-endpoints.js +29 -0
  16. package/src/lib/get-page-endpoints.js.map +1 -0
  17. package/src/lib/nitro/analog-nitro-plugin.d.ts +6 -6
  18. package/src/lib/nitro/analog-nitro-plugin.js +116 -47
  19. package/src/lib/nitro/analog-nitro-plugin.js.map +1 -1
  20. package/src/lib/nitro/angular-linker-plugin.d.ts +4 -2
  21. package/src/lib/nitro/angular-linker-plugin.js +24 -38
  22. package/src/lib/nitro/angular-linker-plugin.js.map +1 -1
  23. package/src/lib/nitro/build-sitemap.js +2 -2
  24. package/src/lib/nitro/build-sitemap.js.map +1 -1
  25. package/src/lib/nitro/get-page-handlers.d.ts +4 -19
  26. package/src/lib/nitro/get-page-handlers.js +9 -26
  27. package/src/lib/nitro/get-page-handlers.js.map +1 -1
  28. package/src/lib/nitro/i18n-prerender.d.ts +2 -1
  29. package/src/lib/nitro/i18n-prerender.js +10 -7
  30. package/src/lib/nitro/i18n-prerender.js.map +1 -1
  31. package/src/lib/nitro/server-fn-endpoints.d.ts +3 -1
  32. package/src/lib/nitro/server-fn-endpoints.js +14 -5
  33. package/src/lib/nitro/server-fn-endpoints.js.map +1 -1
  34. package/src/lib/nx-plugin/executors.json +0 -7
  35. package/src/lib/nx-plugin/src/generators/app/compat.d.ts +2 -1
  36. package/src/lib/nx-plugin/src/generators/app/compat.js +4 -1
  37. package/src/lib/nx-plugin/src/generators/app/compat.js.map +1 -1
  38. package/src/lib/nx-plugin/src/generators/app/generator.js +7 -2
  39. package/src/lib/nx-plugin/src/generators/app/generator.js.map +1 -1
  40. package/src/lib/nx-plugin/src/generators/app/lib/add-tailwind-helpers.js +2 -2
  41. package/src/lib/nx-plugin/src/generators/app/lib/add-tailwind-helpers.js.map +1 -1
  42. package/src/lib/nx-plugin/src/generators/app/versions/minimum-supported-versions.d.ts +3 -1
  43. package/src/lib/nx-plugin/src/generators/app/versions/minimum-supported-versions.js +5 -1
  44. package/src/lib/nx-plugin/src/generators/app/versions/minimum-supported-versions.js.map +1 -1
  45. package/src/lib/nx-plugin/src/generators/init/compat.d.ts +2 -1
  46. package/src/lib/nx-plugin/src/generators/init/compat.js +4 -1
  47. package/src/lib/nx-plugin/src/generators/init/compat.js.map +1 -1
  48. package/src/lib/nx-plugin/src/generators/init/lib/add-analog-dependencies.js +2 -2
  49. package/src/lib/nx-plugin/src/generators/init/lib/add-analog-dependencies.js.map +1 -1
  50. package/src/lib/nx-plugin/src/generators/page/compat.d.ts +2 -1
  51. package/src/lib/nx-plugin/src/generators/page/compat.js +4 -1
  52. package/src/lib/nx-plugin/src/generators/page/compat.js.map +1 -1
  53. package/src/lib/nx-plugin/src/generators/preset/__snapshots__/generator.spec.ts.snap +4 -0
  54. package/src/lib/nx-plugin/src/generators/preset/generator.js +5 -2
  55. package/src/lib/nx-plugin/src/generators/preset/generator.js.map +1 -1
  56. package/src/lib/nx-plugin/src/utils/versions/dev-dependencies.d.ts +2 -2
  57. package/src/lib/nx-plugin/src/utils/versions/dev-dependencies.js +7 -3
  58. package/src/lib/nx-plugin/src/utils/versions/dev-dependencies.js.map +1 -1
  59. package/src/lib/nx-plugin/src/utils/versions/versions.d.ts +9 -6
  60. package/src/lib/nx-plugin/src/utils/versions/versions.js +13 -7
  61. package/src/lib/nx-plugin/src/utils/versions/versions.js.map +1 -1
  62. package/src/lib/options.d.ts +16 -0
  63. package/src/lib/platform-plugin.js +2 -0
  64. package/src/lib/platform-plugin.js.map +1 -1
  65. package/src/lib/route-file-discovery.js +8 -4
  66. package/src/lib/route-file-discovery.js.map +1 -1
  67. package/src/lib/route-idiom-diagnostics.js +23 -8
  68. package/src/lib/route-idiom-diagnostics.js.map +1 -1
  69. package/src/lib/route-manifest.d.ts +1 -1
  70. package/src/lib/route-manifest.js +6 -6
  71. package/src/lib/route-manifest.js.map +1 -1
  72. package/src/lib/router-plugin.js +7 -3
  73. package/src/lib/router-plugin.js.map +1 -1
  74. package/src/lib/server-plugin.d.ts +9 -0
  75. package/src/lib/server-plugin.js +170 -0
  76. package/src/lib/server-plugin.js.map +1 -0
  77. package/src/lib/typed-routes-plugin.js +6 -5
  78. package/src/lib/typed-routes-plugin.js.map +1 -1
  79. package/src/server-mode-plugin.js +1 -0
  80. package/src/server-mode-plugin.js.map +1 -1
  81. package/src/lib/nx-plugin/src/executors/vite-dev-server/compat.d.ts +0 -3
  82. package/src/lib/nx-plugin/src/executors/vite-dev-server/compat.js +0 -7
  83. package/src/lib/nx-plugin/src/executors/vite-dev-server/compat.js.map +0 -1
  84. package/src/lib/nx-plugin/src/executors/vite-dev-server/schema.d.ts +0 -1
  85. package/src/lib/nx-plugin/src/executors/vite-dev-server/schema.json +0 -101
  86. package/src/lib/nx-plugin/src/executors/vite-dev-server/vite-dev-server.impl.d.ts +0 -2
  87. package/src/lib/nx-plugin/src/executors/vite-dev-server/vite-dev-server.impl.js +0 -6
  88. package/src/lib/nx-plugin/src/executors/vite-dev-server/vite-dev-server.impl.js.map +0 -1
@@ -1,18 +1,6 @@
1
1
  import { createRequire } from "node:module";
2
- import { pathToFileURL } from "node:url";
3
2
  //#region packages/platform/src/lib/nitro/angular-linker-plugin.ts
4
- var require = createRequire(import.meta.url);
5
- /**
6
- * Loads the `@babel/core` release that `@angular/compiler-cli` depends on.
7
- * The linker Babel plugin asserts the Babel major it was built against
8
- * (Angular 22.0 needs Babel 7, Angular 22.1+ needs Babel 8), so resolving
9
- * through compiler-cli keeps both in sync, including in strict pnpm layouts.
10
- */
11
- async function loadBabel() {
12
- const babelEntry = createRequire(require.resolve("@angular/compiler-cli/package.json")).resolve("@babel/core");
13
- const babel = await import(pathToFileURL(babelEntry).href);
14
- return babel.transformAsync ? babel : babel.default;
15
- }
3
+ var require = createRequire(createRequire(import.meta.url).resolve("@analogjs/vite-plugin-angular/package.json"));
16
4
  /**
17
5
  * Rolldown plugin that runs the Angular Linker against partially-compiled
18
6
  * Angular npm packages.
@@ -23,42 +11,40 @@ async function loadBabel() {
23
11
  * server bundle would need JIT (eval) at runtime — forbidden on
24
12
  * `workerd` / edge runtimes and unnecessary anywhere else.
25
13
  *
26
- * Loaded lazily so apps that never trigger the SSR optimizer don't
27
- * incur the babel + compiler-cli/linker cost.
14
+ * Links through `@angular/build`'s JavaScript transformer, which uses
15
+ * Angular's native (OXC) linker on 22.2+ and the Babel linker before that.
16
+ * The constructor and `transformData` calls stay within the subset shared
17
+ * by every supported `@angular/build` version.
28
18
  */
29
19
  function angularLinkerPlugin() {
30
- let linkerBabelPlugin;
31
- let needsLinkingFn;
32
- let transformAsyncFn;
33
- async function ensureLoaded() {
34
- if (linkerBabelPlugin && needsLinkingFn && transformAsyncFn) return;
35
- needsLinkingFn = (await import("@angular/compiler-cli/linker")).needsLinking;
36
- const linkerBabel = await import("@angular/compiler-cli/linker/babel");
37
- linkerBabelPlugin = linkerBabel.default ?? linkerBabel;
38
- transformAsyncFn = (await loadBabel()).transformAsync;
39
- }
20
+ let transformer;
40
21
  return {
41
22
  name: "analogjs-platform-angular-linker",
42
23
  async transform(code, id) {
43
24
  if (!id.endsWith(".mjs") && !id.endsWith(".js")) return;
44
25
  if (!code.includes("ɵɵngDeclare")) return;
45
- await ensureLoaded();
46
- if (!needsLinkingFn(id, code)) return;
47
- const result = await transformAsyncFn(code, {
48
- filename: id,
49
- plugins: [linkerBabelPlugin],
50
- sourceMaps: true,
51
- compact: false,
52
- configFile: false,
53
- babelrc: false
26
+ transformer ??= new (require("@angular/build/private")).JavaScriptTransformer({
27
+ sourcemap: true,
28
+ thirdPartySourcemaps: true,
29
+ maxConcurrency: 1
54
30
  });
55
- if (result?.code) return {
56
- code: result.code,
57
- map: result.map ?? null
58
- };
31
+ const result = Buffer.from(await transformer.transformData(id, code)).toString();
32
+ return result === code ? void 0 : splitInlineSourceMap(result);
33
+ },
34
+ async buildEnd() {
35
+ await transformer?.close();
36
+ transformer = void 0;
59
37
  }
60
38
  };
61
39
  }
40
+ function splitInlineSourceMap(code) {
41
+ const match = code.match(/\n?\/\/# sourceMappingURL=data:application\/json(?:;charset=[^;,]+)?;base64,([A-Za-z0-9+/=]+)\s*$/);
42
+ if (match?.index === void 0) return { code };
43
+ return {
44
+ code: code.slice(0, match.index),
45
+ map: Buffer.from(match[1], "base64").toString()
46
+ };
47
+ }
62
48
  //#endregion
63
49
  export { angularLinkerPlugin };
64
50
 
@@ -1 +1 @@
1
- {"version":3,"file":"angular-linker-plugin.js","names":[],"sources":["../../../../src/lib/nitro/angular-linker-plugin.ts"],"sourcesContent":["import { createRequire } from 'node:module';\nimport { pathToFileURL } from 'node:url';\n\nimport type { PluginItem, transformAsync } from '@babel/core';\nimport type { Plugin, SourceMapInput } from 'rolldown';\n\nconst require = createRequire(import.meta.url);\n\ntype BabelCore = { transformAsync: typeof transformAsync };\n\n/**\n * Loads the `@babel/core` release that `@angular/compiler-cli` depends on.\n * The linker Babel plugin asserts the Babel major it was built against\n * (Angular 22.0 needs Babel 7, Angular 22.1+ needs Babel 8), so resolving\n * through compiler-cli keeps both in sync, including in strict pnpm layouts.\n */\nasync function loadBabel(): Promise<BabelCore> {\n const compilerCliRequire = createRequire(\n require.resolve('@angular/compiler-cli/package.json'),\n );\n const babelEntry = compilerCliRequire.resolve('@babel/core');\n const babel = await import(pathToFileURL(babelEntry).href);\n return babel.transformAsync ? babel : babel.default;\n}\n\n/**\n * Rolldown plugin that runs the Angular Linker against partially-compiled\n * Angular npm packages.\n *\n * Wired into `ssr.optimizeDeps.rolldownOptions.plugins` so the SSR /\n * `nitro` environment's dep optimizer turns `ɵɵngDeclare*` partial\n * declarations into fully-compiled definitions. Without this, the\n * server bundle would need JIT (eval) at runtime — forbidden on\n * `workerd` / edge runtimes and unnecessary anywhere else.\n *\n * Loaded lazily so apps that never trigger the SSR optimizer don't\n * incur the babel + compiler-cli/linker cost.\n */\nexport function angularLinkerPlugin(): Plugin {\n let linkerBabelPlugin: PluginItem | undefined;\n let needsLinkingFn: ((id: string, code: string) => boolean) | undefined;\n let transformAsyncFn: BabelCore['transformAsync'] | undefined;\n\n async function ensureLoaded() {\n if (linkerBabelPlugin && needsLinkingFn && transformAsyncFn) return;\n\n const linker = await import('@angular/compiler-cli/linker');\n needsLinkingFn = linker.needsLinking;\n\n const linkerBabel = await import('@angular/compiler-cli/linker/babel');\n linkerBabelPlugin =\n (linkerBabel as { default?: PluginItem }).default ??\n (linkerBabel as PluginItem);\n\n transformAsyncFn = (await loadBabel()).transformAsync;\n }\n\n return {\n name: 'analogjs-platform-angular-linker',\n async transform(code: string, id: string) {\n if (!id.endsWith('.mjs') && !id.endsWith('.js')) return;\n\n // Cheap pre-check before pulling babel/compiler-cli into memory.\n if (!code.includes('ɵɵngDeclare')) return;\n\n await ensureLoaded();\n if (!needsLinkingFn!(id, code)) return;\n\n const result = await transformAsyncFn!(code, {\n filename: id,\n plugins: [linkerBabelPlugin!],\n sourceMaps: true,\n compact: false,\n configFile: false,\n babelrc: false,\n });\n\n if (result?.code) {\n return {\n code: result.code,\n map: (result.map ?? null) as SourceMapInput,\n };\n }\n return;\n },\n };\n}\n"],"mappings":";;;AAMA,IAAM,UAAU,cAAc,YAAY,GAAG;;;;;;;AAU7C,eAAe,YAAgC;CAI7C,MAAM,aAHqB,cACzB,QAAQ,QAAQ,oCAAoC,CAEnC,CAAA,CAAmB,QAAQ,aAAa;CAC3D,MAAM,QAAQ,MAAM,OAAO,cAAc,UAAU,CAAC,CAAC;CACrD,OAAO,MAAM,iBAAiB,QAAQ,MAAM;AAC9C;;;;;;;;;;;;;;AAeA,SAAgB,sBAA8B;CAC5C,IAAI;CACJ,IAAI;CACJ,IAAI;CAEJ,eAAe,eAAe;EAC5B,IAAI,qBAAqB,kBAAkB,kBAAkB;EAG7D,kBAAiB,MADI,OAAO,gCAAA,CACJ;EAExB,MAAM,cAAc,MAAM,OAAO;EACjC,oBACG,YAAyC,WACzC;EAEH,oBAAoB,MAAM,UAAU,EAAA,CAAG;CACzC;CAEA,OAAO;EACL,MAAM;EACN,MAAM,UAAU,MAAc,IAAY;GACxC,IAAI,CAAC,GAAG,SAAS,MAAM,KAAK,CAAC,GAAG,SAAS,KAAK,GAAG;GAGjD,IAAI,CAAC,KAAK,SAAS,aAAa,GAAG;GAEnC,MAAM,aAAa;GACnB,IAAI,CAAC,eAAgB,IAAI,IAAI,GAAG;GAEhC,MAAM,SAAS,MAAM,iBAAkB,MAAM;IAC3C,UAAU;IACV,SAAS,CAAC,iBAAkB;IAC5B,YAAY;IACZ,SAAS;IACT,YAAY;IACZ,SAAS;GACX,CAAC;GAED,IAAI,QAAQ,MACV,OAAO;IACL,MAAM,OAAO;IACb,KAAM,OAAO,OAAO;GACtB;EAGJ;CACF;AACF"}
1
+ {"version":3,"file":"angular-linker-plugin.js","names":[],"sources":["../../../../src/lib/nitro/angular-linker-plugin.ts"],"sourcesContent":["import { createRequire } from 'node:module';\n\nimport type { JavaScriptTransformer } from '@angular/build/private';\nimport type { Plugin } from 'rolldown';\n\n// Resolve `@angular/build` through `@analogjs/vite-plugin-angular`, which\n// declares it as a peer, so strict pnpm layouts find the consumer's copy.\nconst require = createRequire(\n createRequire(import.meta.url).resolve(\n '@analogjs/vite-plugin-angular/package.json',\n ),\n);\n\n/**\n * Rolldown plugin that runs the Angular Linker against partially-compiled\n * Angular npm packages.\n *\n * Wired into `ssr.optimizeDeps.rolldownOptions.plugins` so the SSR /\n * `nitro` environment's dep optimizer turns `ɵɵngDeclare*` partial\n * declarations into fully-compiled definitions. Without this, the\n * server bundle would need JIT (eval) at runtime — forbidden on\n * `workerd` / edge runtimes and unnecessary anywhere else.\n *\n * Links through `@angular/build`'s JavaScript transformer, which uses\n * Angular's native (OXC) linker on 22.2+ and the Babel linker before that.\n * The constructor and `transformData` calls stay within the subset shared\n * by every supported `@angular/build` version.\n */\nexport function angularLinkerPlugin(): Plugin {\n let transformer: JavaScriptTransformer | undefined;\n\n return {\n name: 'analogjs-platform-angular-linker',\n async transform(code: string, id: string) {\n if (!id.endsWith('.mjs') && !id.endsWith('.js')) return;\n\n // Cheap pre-check before starting the transformer's worker pool.\n if (!code.includes('ɵɵngDeclare')) return;\n\n transformer ??= new (require('@angular/build/private')\n .JavaScriptTransformer as typeof JavaScriptTransformer)({\n sourcemap: true,\n thirdPartySourcemaps: true,\n maxConcurrency: 1,\n });\n const result = Buffer.from(\n await transformer.transformData(id, code),\n ).toString();\n\n return result === code ? undefined : splitInlineSourceMap(result);\n },\n async buildEnd() {\n await transformer?.close();\n transformer = undefined;\n },\n };\n}\n\nfunction splitInlineSourceMap(code: string): { code: string; map?: string } {\n const match = code.match(\n /\\n?\\/\\/# sourceMappingURL=data:application\\/json(?:;charset=[^;,]+)?;base64,([A-Za-z0-9+/=]+)\\s*$/,\n );\n if (match?.index === undefined) return { code };\n return {\n code: code.slice(0, match.index),\n map: Buffer.from(match[1]!, 'base64').toString(),\n };\n}\n"],"mappings":";;AAOA,IAAM,UAAU,cACd,cAAc,YAAY,GAAG,CAAC,CAAC,QAC7B,4CACF,CACF;;;;;;;;;;;;;;;;AAiBA,SAAgB,sBAA8B;CAC5C,IAAI;CAEJ,OAAO;EACL,MAAM;EACN,MAAM,UAAU,MAAc,IAAY;GACxC,IAAI,CAAC,GAAG,SAAS,MAAM,KAAK,CAAC,GAAG,SAAS,KAAK,GAAG;GAGjD,IAAI,CAAC,KAAK,SAAS,aAAa,GAAG;GAEnC,gBAAgB,KAAK,QAAQ,wBAAwB,EAAA,CAClD,sBAAuD;IACxD,WAAW;IACX,sBAAsB;IACtB,gBAAgB;GAClB,CAAC;GACD,MAAM,SAAS,OAAO,KACpB,MAAM,YAAY,cAAc,IAAI,IAAI,CAC1C,CAAC,CAAC,SAAS;GAEX,OAAO,WAAW,OAAO,KAAA,IAAY,qBAAqB,MAAM;EAClE;EACA,MAAM,WAAW;GACf,MAAM,aAAa,MAAM;GACzB,cAAc,KAAA;EAChB;CACF;AACF;AAEA,SAAS,qBAAqB,MAA8C;CAC1E,MAAM,QAAQ,KAAK,MACjB,mGACF;CACA,IAAI,OAAO,UAAU,KAAA,GAAW,OAAO,EAAE,KAAK;CAC9C,OAAO;EACL,MAAM,KAAK,MAAM,GAAG,MAAM,KAAK;EAC/B,KAAK,OAAO,KAAK,MAAM,IAAK,QAAQ,CAAC,CAAC,SAAS;CACjD;AACF"}
@@ -124,8 +124,8 @@ async function resolveRouteInputs(routes) {
124
124
  return routeList.filter(Boolean);
125
125
  }
126
126
  function createXml(elementName, includeXhtml = false) {
127
- const attrs = { xmlns: "https://www.sitemaps.org/schemas/sitemap/0.9" };
128
- if (includeXhtml) attrs["xmlns:xhtml"] = "https://www.w3.org/1999/xhtml";
127
+ const attrs = { xmlns: "http://www.sitemaps.org/schemas/sitemap/0.9" };
128
+ if (includeXhtml) attrs["xmlns:xhtml"] = "http://www.w3.org/1999/xhtml";
129
129
  return create({
130
130
  version: "1.0",
131
131
  encoding: "UTF-8"
@@ -1 +1 @@
1
- {"version":3,"file":"build-sitemap.js","names":[],"sources":["../../../../src/lib/nitro/build-sitemap.ts"],"sourcesContent":["import { existsSync, mkdirSync, writeFileSync } from 'node:fs';\nimport { resolve } from 'node:path';\nimport { create } from 'xmlbuilder2';\nimport type { XMLBuilder } from 'xmlbuilder2/lib/interfaces';\nimport { UserConfig } from 'vite';\nimport type {\n I18nPrerenderOptions,\n PrerenderSitemapConfig,\n SitemapConfig,\n SitemapEntry,\n SitemapExcludeRule,\n SitemapRouteDefinition,\n SitemapRouteInput,\n SitemapRouteSource,\n} from './types.js';\n\ntype RouteSitemapConfig =\n | PrerenderSitemapConfig\n | (() => PrerenderSitemapConfig)\n | undefined;\n\nexport type PagesJson = SitemapEntry;\n\nexport interface BuildSitemapOptions {\n apiPrefix?: string;\n}\n\nexport async function buildSitemap(\n _config: UserConfig,\n sitemapConfig: SitemapConfig,\n routes: (string | undefined)[] | (() => Promise<(string | undefined)[]>),\n outputDir: string,\n routeSitemaps: Record<string, RouteSitemapConfig>,\n buildOptions: BuildSitemapOptions = {},\n): Promise<void> {\n const host = normalizeSitemapHost(sitemapConfig.host);\n const routeList = await collectSitemapRoutes(routes, sitemapConfig.include);\n const sitemapData = await resolveSitemapEntries(\n routeList,\n host,\n routeSitemaps,\n sitemapConfig,\n buildOptions,\n );\n\n if (!sitemapData.length) {\n return;\n }\n\n const sitemap = createXml('urlset');\n\n for (const item of sitemapData) {\n const page = sitemap.ele('url');\n page.ele('loc').txt(item.loc);\n\n if (item.lastmod) {\n page.ele('lastmod').txt(item.lastmod);\n }\n\n if (item.changefreq) {\n page.ele('changefreq').txt(item.changefreq);\n }\n\n if (item.priority !== undefined) {\n page.ele('priority').txt(String(item.priority));\n }\n }\n\n const resolvedOutputDir = resolve(outputDir);\n const mapPath = resolve(resolvedOutputDir, 'sitemap.xml');\n try {\n if (!resolvedOutputDir || resolvedOutputDir === resolve()) {\n throw new Error(\n 'Refusing to write the sitemap to the current working directory. Expected the Nitro public output directory instead.',\n );\n }\n\n if (!existsSync(resolvedOutputDir)) {\n mkdirSync(resolvedOutputDir, { recursive: true });\n }\n console.log(`Writing sitemap at ${mapPath}`);\n writeFileSync(mapPath, sitemap.end({ prettyPrint: true }));\n } catch (e) {\n console.error(`Unable to write file at ${mapPath}`, e);\n }\n}\n\nasync function resolveSitemapEntries(\n routes: SitemapRouteInput[],\n host: string,\n routeSitemaps: Record<string, RouteSitemapConfig>,\n sitemapConfig: SitemapConfig,\n buildOptions: BuildSitemapOptions,\n): Promise<SitemapEntry[]> {\n const defaults = sitemapConfig.defaults ?? {};\n const seen = new Set<string>();\n const entries: SitemapEntry[] = [];\n\n for (const route of routes) {\n const entry = await toSitemapEntry(\n route,\n host,\n routeSitemaps,\n defaults,\n sitemapConfig.transform,\n );\n\n if (!entry) {\n continue;\n }\n\n if (\n isInternalSitemapRoute(entry.route, buildOptions.apiPrefix) ||\n (await isExcludedSitemapRoute(entry, sitemapConfig.exclude))\n ) {\n continue;\n }\n\n if (seen.has(entry.loc)) {\n continue;\n }\n\n seen.add(entry.loc);\n entries.push(entry);\n }\n\n return entries;\n}\n\nasync function toSitemapEntry(\n route: SitemapRouteInput,\n host: string,\n routeSitemaps: Record<string, RouteSitemapConfig>,\n defaults: PrerenderSitemapConfig,\n transform: SitemapConfig['transform'],\n): Promise<SitemapEntry | undefined> {\n const normalizedRoute = normalizeSitemapRoute(\n typeof route === 'string' ? route : route?.route,\n );\n if (!normalizedRoute) {\n return undefined;\n }\n\n const baseEntry = createSitemapEntry(\n {\n ...defaults,\n ...resolveRouteSitemapConfig(routeSitemaps[normalizedRoute]),\n ...(typeof route === 'object' ? route : {}),\n route: normalizedRoute,\n },\n host,\n );\n\n if (!transform) {\n return baseEntry;\n }\n\n const transformed = await transform(baseEntry);\n if (!transformed) {\n return undefined;\n }\n\n return createSitemapEntry(\n {\n ...baseEntry,\n ...transformed,\n },\n host,\n );\n}\n\nfunction createSitemapEntry(\n routeDefinition: SitemapRouteDefinition,\n host: string,\n): SitemapEntry {\n const route = normalizeSitemapRoute(routeDefinition.route) ?? '/';\n\n return {\n route,\n loc: new URL(route, ensureTrailingSlash(host)).toString(),\n lastmod: routeDefinition.lastmod,\n changefreq: routeDefinition.changefreq,\n priority: routeDefinition.priority,\n };\n}\n\nfunction resolveRouteSitemapConfig(\n config: RouteSitemapConfig,\n): PrerenderSitemapConfig {\n if (!config) {\n return {};\n }\n\n return typeof config === 'function' ? config() : config;\n}\n\nfunction normalizeSitemapHost(host: string): string {\n const resolvedHost = new URL(host);\n resolvedHost.hash = '';\n return resolvedHost.toString();\n}\n\nfunction ensureTrailingSlash(host: string): string {\n return host.endsWith('/') ? host : `${host}/`;\n}\n\nfunction normalizeSitemapRoute(route: string | undefined): string | undefined {\n if (!route) {\n return undefined;\n }\n\n const trimmedRoute = route.trim();\n if (!trimmedRoute) {\n return undefined;\n }\n\n const pathWithQuery = trimmedRoute.split('#', 1)[0] ?? '';\n const [pathname, search] = pathWithQuery.split('?', 2);\n const normalizedPathname = pathname\n ? `/${pathname.replace(/^\\/+/, '').replace(/\\/{2,}/g, '/')}`\n : '/';\n\n return search ? `${normalizedPathname}?${search}` : normalizedPathname;\n}\n\nfunction isInternalSitemapRoute(route: string, apiPrefix = 'api'): boolean {\n const normalizedApiPrefix = normalizeSitemapRoute(`/${apiPrefix}`) ?? '/api';\n return (\n route === `${normalizedApiPrefix}/_analog/pages` ||\n route.startsWith(`${normalizedApiPrefix}/_analog/pages/`)\n );\n}\n\nasync function isExcludedSitemapRoute(\n entry: SitemapEntry,\n excludeRules: SitemapExcludeRule[] | undefined,\n): Promise<boolean> {\n if (!excludeRules?.length) {\n return false;\n }\n\n for (const rule of excludeRules) {\n if (typeof rule === 'function') {\n if (await rule(entry)) {\n return true;\n }\n continue;\n }\n\n if (rule instanceof RegExp) {\n if (rule.test(entry.route)) {\n return true;\n }\n continue;\n }\n\n if (toGlobRegExp(rule).test(entry.route)) {\n return true;\n }\n }\n\n return false;\n}\n\nfunction toGlobRegExp(pattern: string): RegExp {\n const doubleStarToken = '__ANALOG_DOUBLE_STAR__';\n const singleStarToken = '__ANALOG_SINGLE_STAR__';\n const escapedPattern = pattern\n .replace(/\\*\\*/g, doubleStarToken)\n .replace(/\\*/g, singleStarToken)\n .replace(/[.+^${}()|[\\]\\\\]/g, '\\\\$&');\n const regexPattern = escapedPattern\n .replace(new RegExp(doubleStarToken, 'g'), '.*')\n .replace(new RegExp(singleStarToken, 'g'), '[^/]*');\n return new RegExp(`^${regexPattern}$`);\n}\n\nasync function collectSitemapRoutes(\n routes: (string | undefined)[] | (() => Promise<(string | undefined)[]>),\n include?: SitemapRouteSource,\n): Promise<SitemapRouteInput[]> {\n const routeList = await resolveRouteInputs(routes);\n const includedRoutes = include ? await resolveRouteInputs(include) : [];\n return [...routeList, ...includedRoutes];\n}\n\nasync function resolveRouteInputs(\n routes:\n | SitemapRouteSource\n | (string | undefined)[]\n | (() => Promise<(string | undefined)[]>),\n): Promise<SitemapRouteInput[]> {\n let routeList: SitemapRouteInput[];\n\n if (typeof routes === 'function') {\n routeList = await routes();\n } else if (Array.isArray(routes)) {\n routeList = routes;\n } else {\n routeList = [];\n }\n\n return routeList.filter(Boolean);\n}\n\n/**\n * Generates hreflang alternate URLs for a given page URL.\n * For a URL like `https://example.com/fr/about`, it produces alternates\n * for all configured locales.\n */\nexport function getHreflangAlternates(\n pageUrl: string,\n host: string,\n i18n: I18nPrerenderOptions,\n): { locale: string; href: string }[] {\n const alternates: { locale: string; href: string }[] = [];\n const normalizedHost = host.replace(/\\/+$/, '');\n\n const path = pageUrl.replace(normalizedHost, '');\n const basePath = stripLocalePrefix(path, i18n.locales);\n\n for (const locale of i18n.locales) {\n const localizedPath =\n basePath === '/' || basePath === ''\n ? `/${locale}`\n : `/${locale}${basePath}`;\n alternates.push({\n locale,\n href: `${normalizedHost}${localizedPath}`,\n });\n }\n\n const defaultPath =\n basePath === '/' || basePath === ''\n ? `/${i18n.defaultLocale}`\n : `/${i18n.defaultLocale}${basePath}`;\n alternates.push({\n locale: 'x-default',\n href: `${normalizedHost}${defaultPath}`,\n });\n\n return alternates;\n}\n\n/**\n * Strips a locale prefix from a URL path.\n * E.g., '/fr/about' -> '/about', '/en' -> '/'\n */\nexport function stripLocalePrefix(path: string, locales: string[]): string {\n const segments = path.split('/').filter(Boolean);\n if (segments.length > 0 && locales.includes(segments[0])) {\n const rest = segments.slice(1).join('/');\n return rest ? `/${rest}` : '/';\n }\n return path || '/';\n}\n\nfunction createXml(\n elementName: 'urlset' | 'sitemapindex',\n includeXhtml = false,\n): XMLBuilder {\n const attrs: Record<string, string> = {\n xmlns: 'https://www.sitemaps.org/schemas/sitemap/0.9',\n };\n if (includeXhtml) {\n attrs['xmlns:xhtml'] = 'https://www.w3.org/1999/xhtml';\n }\n\n return create({ version: '1.0', encoding: 'UTF-8' })\n .ele(elementName, attrs)\n .com(`This file was automatically generated by Analog.`);\n}\n"],"mappings":";;;;AA2BA,eAAsB,aACpB,SACA,eACA,QACA,WACA,eACA,eAAoC,CAAC,GACtB;CACf,MAAM,OAAO,qBAAqB,cAAc,IAAI;CAEpD,MAAM,cAAc,MAAM,sBACxB,MAFsB,qBAAqB,QAAQ,cAAc,OAAO,GAGxE,MACA,eACA,eACA,YACF;CAEA,IAAI,CAAC,YAAY,QACf;CAGF,MAAM,UAAU,UAAU,QAAQ;CAElC,KAAK,MAAM,QAAQ,aAAa;EAC9B,MAAM,OAAO,QAAQ,IAAI,KAAK;EAC9B,KAAK,IAAI,KAAK,CAAC,CAAC,IAAI,KAAK,GAAG;EAE5B,IAAI,KAAK,SACP,KAAK,IAAI,SAAS,CAAC,CAAC,IAAI,KAAK,OAAO;EAGtC,IAAI,KAAK,YACP,KAAK,IAAI,YAAY,CAAC,CAAC,IAAI,KAAK,UAAU;EAG5C,IAAI,KAAK,aAAa,KAAA,GACpB,KAAK,IAAI,UAAU,CAAC,CAAC,IAAI,OAAO,KAAK,QAAQ,CAAC;CAElD;CAEA,MAAM,oBAAoB,QAAQ,SAAS;CAC3C,MAAM,UAAU,QAAQ,mBAAmB,aAAa;CACxD,IAAI;EACF,IAAI,CAAC,qBAAqB,sBAAsB,QAAQ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KAAK,GACvB,OAAO;GAET;EACF;EAEA,IAAI,aAAa,IAAI,CAAC,CAAC,KAAK,MAAM,KAAK,GACrC,OAAO;CAEX;CAEA,OAAO;AACT;AAEA,SAAS,aAAa,SAAyB;CAC7C,MAAM,kBAAkB;CACxB,MAAM,kBAAkB;CAKxB,MAAM,eAJiB,QACpB,QAAQ,SAAS,eAAe,CAAC,CACjC,QAAQ,OAAO,eAAe,CAAC,CAC/B,QAAQ,qBAAqB,MACX,CAAA,CAClB,QAAQ,IAAI,OAAO,iBAAiB,GAAG,GAAG,IAAI,CAAC,CAC/C,QAAQ,IAAI,OAAO,iBAAiB,GAAG,GAAG,OAAO;CACpD,OAAO,IAAI,OAAO,IAAI,aAAa,EAAE;AACvC;AAEA,eAAe,qBACb,QACA,SAC8B;CAC9B,MAAM,YAAY,MAAM,mBAAmB,MAAM;CACjD,MAAM,iBAAiB,UAAU,MAAM,mBAAmB,OAAO,IAAI,CAAC;CACtE,OAAO,CAAC,GAAG,WAAW,GAAG,cAAc;AACzC;AAEA,eAAe,mBACb,QAI8B;CAC9B,IAAI;CAEJ,IAAI,OAAO,WAAW,YACpB,YAAY,MAAM,OAAO;MACpB,IAAI,MAAM,QAAQ,MAAM,GAC7B,YAAY;MAEZ,YAAY,CAAC;CAGf,OAAO,UAAU,OAAO,OAAO;AACjC;AAsDA,SAAS,UACP,aACA,eAAe,OACH;CACZ,MAAM,QAAgC,EACpC,OAAO,+CACT;CACA,IAAI,cACF,MAAM,iBAAiB;CAGzB,OAAO,OAAO;EAAE,SAAS;EAAO,UAAU;CAAQ,CAAC,CAAC,CACjD,IAAI,aAAa,KAAK,CAAC,CACvB,IAAI,kDAAkD;AAC3D"}
1
+ {"version":3,"file":"build-sitemap.js","names":[],"sources":["../../../../src/lib/nitro/build-sitemap.ts"],"sourcesContent":["import { existsSync, mkdirSync, writeFileSync } from 'node:fs';\nimport { resolve } from 'node:path';\nimport { create } from 'xmlbuilder2';\nimport type { XMLBuilder } from 'xmlbuilder2/lib/interfaces';\nimport { UserConfig } from 'vite';\nimport type {\n I18nPrerenderOptions,\n PrerenderSitemapConfig,\n SitemapConfig,\n SitemapEntry,\n SitemapExcludeRule,\n SitemapRouteDefinition,\n SitemapRouteInput,\n SitemapRouteSource,\n} from './types.js';\n\ntype RouteSitemapConfig =\n | PrerenderSitemapConfig\n | (() => PrerenderSitemapConfig)\n | undefined;\n\nexport type PagesJson = SitemapEntry;\n\nexport interface BuildSitemapOptions {\n apiPrefix?: string;\n}\n\nexport async function buildSitemap(\n _config: UserConfig,\n sitemapConfig: SitemapConfig,\n routes: (string | undefined)[] | (() => Promise<(string | undefined)[]>),\n outputDir: string,\n routeSitemaps: Record<string, RouteSitemapConfig>,\n buildOptions: BuildSitemapOptions = {},\n): Promise<void> {\n const host = normalizeSitemapHost(sitemapConfig.host);\n const routeList = await collectSitemapRoutes(routes, sitemapConfig.include);\n const sitemapData = await resolveSitemapEntries(\n routeList,\n host,\n routeSitemaps,\n sitemapConfig,\n buildOptions,\n );\n\n if (!sitemapData.length) {\n return;\n }\n\n const sitemap = createXml('urlset');\n\n for (const item of sitemapData) {\n const page = sitemap.ele('url');\n page.ele('loc').txt(item.loc);\n\n if (item.lastmod) {\n page.ele('lastmod').txt(item.lastmod);\n }\n\n if (item.changefreq) {\n page.ele('changefreq').txt(item.changefreq);\n }\n\n if (item.priority !== undefined) {\n page.ele('priority').txt(String(item.priority));\n }\n }\n\n const resolvedOutputDir = resolve(outputDir);\n const mapPath = resolve(resolvedOutputDir, 'sitemap.xml');\n try {\n if (!resolvedOutputDir || resolvedOutputDir === resolve()) {\n throw new Error(\n 'Refusing to write the sitemap to the current working directory. Expected the Nitro public output directory instead.',\n );\n }\n\n if (!existsSync(resolvedOutputDir)) {\n mkdirSync(resolvedOutputDir, { recursive: true });\n }\n console.log(`Writing sitemap at ${mapPath}`);\n writeFileSync(mapPath, sitemap.end({ prettyPrint: true }));\n } catch (e) {\n console.error(`Unable to write file at ${mapPath}`, e);\n }\n}\n\nasync function resolveSitemapEntries(\n routes: SitemapRouteInput[],\n host: string,\n routeSitemaps: Record<string, RouteSitemapConfig>,\n sitemapConfig: SitemapConfig,\n buildOptions: BuildSitemapOptions,\n): Promise<SitemapEntry[]> {\n const defaults = sitemapConfig.defaults ?? {};\n const seen = new Set<string>();\n const entries: SitemapEntry[] = [];\n\n for (const route of routes) {\n const entry = await toSitemapEntry(\n route,\n host,\n routeSitemaps,\n defaults,\n sitemapConfig.transform,\n );\n\n if (!entry) {\n continue;\n }\n\n if (\n isInternalSitemapRoute(entry.route, buildOptions.apiPrefix) ||\n (await isExcludedSitemapRoute(entry, sitemapConfig.exclude))\n ) {\n continue;\n }\n\n if (seen.has(entry.loc)) {\n continue;\n }\n\n seen.add(entry.loc);\n entries.push(entry);\n }\n\n return entries;\n}\n\nasync function toSitemapEntry(\n route: SitemapRouteInput,\n host: string,\n routeSitemaps: Record<string, RouteSitemapConfig>,\n defaults: PrerenderSitemapConfig,\n transform: SitemapConfig['transform'],\n): Promise<SitemapEntry | undefined> {\n const normalizedRoute = normalizeSitemapRoute(\n typeof route === 'string' ? route : route?.route,\n );\n if (!normalizedRoute) {\n return undefined;\n }\n\n const baseEntry = createSitemapEntry(\n {\n ...defaults,\n ...resolveRouteSitemapConfig(routeSitemaps[normalizedRoute]),\n ...(typeof route === 'object' ? route : {}),\n route: normalizedRoute,\n },\n host,\n );\n\n if (!transform) {\n return baseEntry;\n }\n\n const transformed = await transform(baseEntry);\n if (!transformed) {\n return undefined;\n }\n\n return createSitemapEntry(\n {\n ...baseEntry,\n ...transformed,\n },\n host,\n );\n}\n\nfunction createSitemapEntry(\n routeDefinition: SitemapRouteDefinition,\n host: string,\n): SitemapEntry {\n const route = normalizeSitemapRoute(routeDefinition.route) ?? '/';\n\n return {\n route,\n loc: new URL(route, ensureTrailingSlash(host)).toString(),\n lastmod: routeDefinition.lastmod,\n changefreq: routeDefinition.changefreq,\n priority: routeDefinition.priority,\n };\n}\n\nfunction resolveRouteSitemapConfig(\n config: RouteSitemapConfig,\n): PrerenderSitemapConfig {\n if (!config) {\n return {};\n }\n\n return typeof config === 'function' ? config() : config;\n}\n\nfunction normalizeSitemapHost(host: string): string {\n const resolvedHost = new URL(host);\n resolvedHost.hash = '';\n return resolvedHost.toString();\n}\n\nfunction ensureTrailingSlash(host: string): string {\n return host.endsWith('/') ? host : `${host}/`;\n}\n\nfunction normalizeSitemapRoute(route: string | undefined): string | undefined {\n if (!route) {\n return undefined;\n }\n\n const trimmedRoute = route.trim();\n if (!trimmedRoute) {\n return undefined;\n }\n\n const pathWithQuery = trimmedRoute.split('#', 1)[0] ?? '';\n const [pathname, search] = pathWithQuery.split('?', 2);\n const normalizedPathname = pathname\n ? `/${pathname.replace(/^\\/+/, '').replace(/\\/{2,}/g, '/')}`\n : '/';\n\n return search ? `${normalizedPathname}?${search}` : normalizedPathname;\n}\n\nfunction isInternalSitemapRoute(route: string, apiPrefix = 'api'): boolean {\n const normalizedApiPrefix = normalizeSitemapRoute(`/${apiPrefix}`) ?? '/api';\n return (\n route === `${normalizedApiPrefix}/_analog/pages` ||\n route.startsWith(`${normalizedApiPrefix}/_analog/pages/`)\n );\n}\n\nasync function isExcludedSitemapRoute(\n entry: SitemapEntry,\n excludeRules: SitemapExcludeRule[] | undefined,\n): Promise<boolean> {\n if (!excludeRules?.length) {\n return false;\n }\n\n for (const rule of excludeRules) {\n if (typeof rule === 'function') {\n if (await rule(entry)) {\n return true;\n }\n continue;\n }\n\n if (rule instanceof RegExp) {\n if (rule.test(entry.route)) {\n return true;\n }\n continue;\n }\n\n if (toGlobRegExp(rule).test(entry.route)) {\n return true;\n }\n }\n\n return false;\n}\n\nfunction toGlobRegExp(pattern: string): RegExp {\n const doubleStarToken = '__ANALOG_DOUBLE_STAR__';\n const singleStarToken = '__ANALOG_SINGLE_STAR__';\n const escapedPattern = pattern\n .replace(/\\*\\*/g, doubleStarToken)\n .replace(/\\*/g, singleStarToken)\n .replace(/[.+^${}()|[\\]\\\\]/g, '\\\\$&');\n const regexPattern = escapedPattern\n .replace(new RegExp(doubleStarToken, 'g'), '.*')\n .replace(new RegExp(singleStarToken, 'g'), '[^/]*');\n return new RegExp(`^${regexPattern}$`);\n}\n\nasync function collectSitemapRoutes(\n routes: (string | undefined)[] | (() => Promise<(string | undefined)[]>),\n include?: SitemapRouteSource,\n): Promise<SitemapRouteInput[]> {\n const routeList = await resolveRouteInputs(routes);\n const includedRoutes = include ? await resolveRouteInputs(include) : [];\n return [...routeList, ...includedRoutes];\n}\n\nasync function resolveRouteInputs(\n routes:\n | SitemapRouteSource\n | (string | undefined)[]\n | (() => Promise<(string | undefined)[]>),\n): Promise<SitemapRouteInput[]> {\n let routeList: SitemapRouteInput[];\n\n if (typeof routes === 'function') {\n routeList = await routes();\n } else if (Array.isArray(routes)) {\n routeList = routes;\n } else {\n routeList = [];\n }\n\n return routeList.filter(Boolean);\n}\n\n/**\n * Generates hreflang alternate URLs for a given page URL.\n * For a URL like `https://example.com/fr/about`, it produces alternates\n * for all configured locales.\n */\nexport function getHreflangAlternates(\n pageUrl: string,\n host: string,\n i18n: I18nPrerenderOptions,\n): { locale: string; href: string }[] {\n const alternates: { locale: string; href: string }[] = [];\n const normalizedHost = host.replace(/\\/+$/, '');\n\n const path = pageUrl.replace(normalizedHost, '');\n const basePath = stripLocalePrefix(path, i18n.locales);\n\n for (const locale of i18n.locales) {\n const localizedPath =\n basePath === '/' || basePath === ''\n ? `/${locale}`\n : `/${locale}${basePath}`;\n alternates.push({\n locale,\n href: `${normalizedHost}${localizedPath}`,\n });\n }\n\n const defaultPath =\n basePath === '/' || basePath === ''\n ? `/${i18n.defaultLocale}`\n : `/${i18n.defaultLocale}${basePath}`;\n alternates.push({\n locale: 'x-default',\n href: `${normalizedHost}${defaultPath}`,\n });\n\n return alternates;\n}\n\n/**\n * Strips a locale prefix from a URL path.\n * E.g., '/fr/about' -> '/about', '/en' -> '/'\n */\nexport function stripLocalePrefix(path: string, locales: string[]): string {\n const segments = path.split('/').filter(Boolean);\n if (segments.length > 0 && locales.includes(segments[0])) {\n const rest = segments.slice(1).join('/');\n return rest ? `/${rest}` : '/';\n }\n return path || '/';\n}\n\nfunction createXml(\n elementName: 'urlset' | 'sitemapindex',\n includeXhtml = false,\n): XMLBuilder {\n const attrs: Record<string, string> = {\n xmlns: 'http://www.sitemaps.org/schemas/sitemap/0.9',\n };\n if (includeXhtml) {\n attrs['xmlns:xhtml'] = 'http://www.w3.org/1999/xhtml';\n }\n\n return create({ version: '1.0', encoding: 'UTF-8' })\n .ele(elementName, attrs)\n .com(`This file was automatically generated by Analog.`);\n}\n"],"mappings":";;;;AA2BA,eAAsB,aACpB,SACA,eACA,QACA,WACA,eACA,eAAoC,CAAC,GACtB;CACf,MAAM,OAAO,qBAAqB,cAAc,IAAI;CAEpD,MAAM,cAAc,MAAM,sBACxB,MAFsB,qBAAqB,QAAQ,cAAc,OAAO,GAGxE,MACA,eACA,eACA,YACF;CAEA,IAAI,CAAC,YAAY,QACf;CAGF,MAAM,UAAU,UAAU,QAAQ;CAElC,KAAK,MAAM,QAAQ,aAAa;EAC9B,MAAM,OAAO,QAAQ,IAAI,KAAK;EAC9B,KAAK,IAAI,KAAK,CAAC,CAAC,IAAI,KAAK,GAAG;EAE5B,IAAI,KAAK,SACP,KAAK,IAAI,SAAS,CAAC,CAAC,IAAI,KAAK,OAAO;EAGtC,IAAI,KAAK,YACP,KAAK,IAAI,YAAY,CAAC,CAAC,IAAI,KAAK,UAAU;EAG5C,IAAI,KAAK,aAAa,KAAA,GACpB,KAAK,IAAI,UAAU,CAAC,CAAC,IAAI,OAAO,KAAK,QAAQ,CAAC;CAElD;CAEA,MAAM,oBAAoB,QAAQ,SAAS;CAC3C,MAAM,UAAU,QAAQ,mBAAmB,aAAa;CACxD,IAAI;EACF,IAAI,CAAC,qBAAqB,sBAAsB,QAAQ,GACtD,MAAM,IAAI,MACR,qHACF;EAGF,IAAI,CAAC,WAAW,iBAAiB,GAC/B,UAAU,mBAAmB,EAAE,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AO;CAEX;CAEA,OAAO;AACT;AAEA,SAAS,aAAa,SAAyB;CAC7C,MAAM,kBAAkB;CACxB,MAAM,kBAAkB;CAKxB,MAAM,eAJiB,QACpB,QAAQ,SAAS,eAAe,CAAC,CACjC,QAAQ,OAAO,eAAe,CAAC,CAC/B,QAAQ,qBAAqB,MACX,CAAA,CAClB,QAAQ,IAAI,OAAO,iBAAiB,GAAG,GAAG,IAAI,CAAC,CAC/C,QAAQ,IAAI,OAAO,iBAAiB,GAAG,GAAG,OAAO;CACpD,OAAO,IAAI,OAAO,IAAI,aAAa,EAAE;AACvC;AAEA,eAAe,qBACb,QACA,SAC8B;CAC9B,MAAM,YAAY,MAAM,mBAAmB,MAAM;CACjD,MAAM,iBAAiB,UAAU,MAAM,mBAAmB,OAAO,IAAI,CAAC;CACtE,OAAO,CAAC,GAAG,WAAW,GAAG,cAAc;AACzC;AAEA,eAAe,mBACb,QAI8B;CAC9B,IAAI;CAEJ,IAAI,OAAO,WAAW,YACpB,YAAY,MAAM,OAAO;MACpB,IAAI,MAAM,QAAQ,MAAM,GAC7B,YAAY;MAEZ,YAAY,CAAC;CAGf,OAAO,UAAU,OAAO,OAAO;AACjC;AAsDA,SAAS,UACP,aACA,eAAe,OACH;CACZ,MAAM,QAAgC,EACpC,OAAO,8CACT;CACA,IAAI,cACF,MAAM,iBAAiB;CAGzB,OAAO,OAAO;EAAE,SAAS;EAAO,UAAU;CAAQ,CAAC,CAAC,CACjD,IAAI,aAAa,KAAK,CAAC,CACvB,IAAI,kDAAkD;AAC3D"}
@@ -1,22 +1,7 @@
1
1
  import type { NitroEventHandler } from "nitro/types";
2
- type GetHandlersArgs = {
3
- workspaceRoot: string;
4
- sourceRoot: string;
5
- rootDir: string;
6
- additionalPagesDirs?: string[];
7
- };
2
+ import { getPageEndpoints } from "../get-page-endpoints.js";
8
3
  /**
9
- * Discovers and generates Nitro event handlers for server-side page routes.
10
- *
11
- * Discovers all `.server.ts` files under `app/pages/**` and any additional
12
- * pages directories, then maps each file to a Nitro route pattern under
13
- * `/api/_analog/pages/...`.
14
- *
15
- * Route transformation examples:
16
- * - index.server.ts → /api/_analog/pages/index
17
- * - users/[id].server.ts → /api/_analog/pages/users/:id
18
- * - products/[...slug].server.ts → /api/_analog/pages/products/**:slug
19
- * - (auth)/login.server.ts → /api/_analog/pages/-auth-/login
4
+ * Nitro event handlers for server-side page routes: each discovered page
5
+ * endpoint, mounted under `/api/_analog`.
20
6
  */
21
- export declare function getPageHandlers({ workspaceRoot, sourceRoot, rootDir, additionalPagesDirs }: GetHandlersArgs): NitroEventHandler[];
22
- export {};
7
+ export declare function getPageHandlers(args: Parameters<typeof getPageEndpoints>[0]): NitroEventHandler[];
@@ -1,32 +1,15 @@
1
- import { resolve } from "node:path";
2
- import { normalizePath } from "vite";
3
- import { globSync } from "tinyglobby";
1
+ import { getPageEndpoints } from "../get-page-endpoints.js";
4
2
  //#region packages/platform/src/lib/nitro/get-page-handlers.ts
5
3
  /**
6
- * Discovers and generates Nitro event handlers for server-side page routes.
7
- *
8
- * Discovers all `.server.ts` files under `app/pages/**` and any additional
9
- * pages directories, then maps each file to a Nitro route pattern under
10
- * `/api/_analog/pages/...`.
11
- *
12
- * Route transformation examples:
13
- * - index.server.ts → /api/_analog/pages/index
14
- * - users/[id].server.ts → /api/_analog/pages/users/:id
15
- * - products/[...slug].server.ts → /api/_analog/pages/products/**:slug
16
- * - (auth)/login.server.ts → /api/_analog/pages/-auth-/login
4
+ * Nitro event handlers for server-side page routes: each discovered page
5
+ * endpoint, mounted under `/api/_analog`.
17
6
  */
18
- function getPageHandlers({ workspaceRoot, sourceRoot, rootDir, additionalPagesDirs }) {
19
- const root = normalizePath(resolve(workspaceRoot, rootDir));
20
- return globSync([`${root}/${sourceRoot}/app/pages/**/*.server.ts`, ...(additionalPagesDirs || []).map((dir) => `${workspaceRoot}${dir}/**/*.server.ts`)], {
21
- dot: true,
22
- absolute: true
23
- }).map((endpointFile) => {
24
- return {
25
- handler: endpointFile,
26
- route: `/api/_analog${normalizePath(endpointFile).replace(/^(.*?)\/pages/, "/pages").replace(/\.server\.ts$/, "").replace(/\[\.{3}(.+)\]/g, "**:$1").replace(/\[\.{3}(\w+)\]/g, "**:$1").replace(/\/\(([^/]+)\)/g, "/-$1-").replace(/\[(\w+)\]/g, ":$1").replace(/\./g, "/")}`,
27
- lazy: true
28
- };
29
- });
7
+ function getPageHandlers(args) {
8
+ return getPageEndpoints(args).map(({ file, route }) => ({
9
+ handler: file,
10
+ route: `/api/_analog${route}`,
11
+ lazy: true
12
+ }));
30
13
  }
31
14
  //#endregion
32
15
  export { getPageHandlers };
@@ -1 +1 @@
1
- {"version":3,"file":"get-page-handlers.js","names":[],"sources":["../../../../src/lib/nitro/get-page-handlers.ts"],"sourcesContent":["import { resolve } from 'node:path';\nimport { globSync } from 'tinyglobby';\n\nimport type { NitroEventHandler } from 'nitro/types';\nimport { normalizePath } from 'vite';\n\ntype GetHandlersArgs = {\n workspaceRoot: string;\n sourceRoot: string;\n rootDir: string;\n additionalPagesDirs?: string[];\n};\n\n/**\n * Discovers and generates Nitro event handlers for server-side page routes.\n *\n * Discovers all `.server.ts` files under `app/pages/**` and any additional\n * pages directories, then maps each file to a Nitro route pattern under\n * `/api/_analog/pages/...`.\n *\n * Route transformation examples:\n * - index.server.ts → /api/_analog/pages/index\n * - users/[id].server.ts → /api/_analog/pages/users/:id\n * - products/[...slug].server.ts → /api/_analog/pages/products/**:slug\n * - (auth)/login.server.ts → /api/_analog/pages/-auth-/login\n */\nexport function getPageHandlers({\n workspaceRoot,\n sourceRoot,\n rootDir,\n additionalPagesDirs,\n}: GetHandlersArgs): NitroEventHandler[] {\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 const handlers: NitroEventHandler[] = endpointFiles.map((endpointFile) => {\n const normalized = normalizePath(endpointFile);\n const route = normalized\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 handler is mounted under an invalid Nitro path.\n .replace(/\\/\\(([^/]+)\\)/g, '/-$1-')\n .replace(/\\[(\\w+)\\]/g, ':$1')\n .replace(/\\./g, '/');\n\n return {\n handler: endpointFile,\n route: `/api/_analog${route}`,\n lazy: true,\n };\n });\n\n return handlers;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AA0BA,SAAgB,gBAAgB,EAC9B,eACA,YACA,SACA,uBACuC;CACvC,MAAM,OAAO,cAAc,QAAQ,eAAe,OAAO,CAAC;CAkC1D,OAhCgC,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,CAGQ,CAAA,CAAc,KAAK,iBAAiB;EAexE,OAAO;GACL,SAAS;GACT,OAAO,eAhBU,cAAc,YACnB,CAAA,CACX,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,GAIM;GACtB,MAAM;EACR;CACF,CAEO;AACT"}
1
+ {"version":3,"file":"get-page-handlers.js","names":[],"sources":["../../../../src/lib/nitro/get-page-handlers.ts"],"sourcesContent":["import type { NitroEventHandler } from 'nitro/types';\n\nimport { getPageEndpoints } from '../get-page-endpoints.js';\n\n/**\n * Nitro event handlers for server-side page routes: each discovered page\n * endpoint, mounted under `/api/_analog`.\n */\nexport function getPageHandlers(\n args: Parameters<typeof getPageEndpoints>[0],\n): NitroEventHandler[] {\n return getPageEndpoints(args).map(({ file, route }) => ({\n handler: file,\n route: `/api/_analog${route}`,\n lazy: true,\n }));\n}\n"],"mappings":";;;;;;AAQA,SAAgB,gBACd,MACqB;CACrB,OAAO,iBAAiB,IAAI,CAAC,CAAC,KAAK,EAAE,MAAM,aAAa;EACtD,SAAS;EACT,OAAO,eAAe;EACtB,MAAM;CACR,EAAE;AACJ"}
@@ -8,8 +8,9 @@ import type { I18nPrerenderOptions } from "./types.js";
8
8
  *
9
9
  * The default locale's routes are included both with and without the prefix
10
10
  * so that `/about` and `/en/about` both render.
11
+ * Routes that already have a configured locale prefix are kept as-is.
11
12
  */
12
- export declare function expandRoutesWithLocales(routes: string[], i18n: I18nPrerenderOptions): string[];
13
+ export declare function expandRoutesWithLocales(routes: string[], i18n: I18nPrerenderOptions, apiPrefix?: string): string[];
13
14
  /**
14
15
  * Creates a post-rendering hook that injects the `lang` attribute
15
16
  * into the `<html>` tag of prerendered pages based on the route's
@@ -7,22 +7,25 @@
7
7
  *
8
8
  * The default locale's routes are included both with and without the prefix
9
9
  * so that `/about` and `/en/about` both render.
10
+ * Routes that already have a configured locale prefix are kept as-is.
10
11
  */
11
- function expandRoutesWithLocales(routes, i18n) {
12
- const expanded = [];
12
+ function expandRoutesWithLocales(routes, i18n, apiPrefix = "api") {
13
+ const expanded = /* @__PURE__ */ new Set();
14
+ const apiRoute = `/${apiPrefix.replace(/^\/+|\/+$/g, "")}`;
13
15
  for (const route of routes) {
14
- if (route.includes("/_analog/") || route === "/api" || route.startsWith("/api/")) {
15
- expanded.push(route);
16
+ const firstSegment = route.split("/").filter(Boolean)[0];
17
+ if (route.includes("/_analog/") || route === apiRoute || route.startsWith(`${apiRoute}/`) || i18n.locales.includes(firstSegment)) {
18
+ expanded.add(route);
16
19
  continue;
17
20
  }
18
21
  for (const locale of i18n.locales) {
19
22
  const prefix = `/${locale}`;
20
23
  const localizedRoute = route === "/" ? prefix : `${prefix}${route}`;
21
- expanded.push(localizedRoute);
24
+ expanded.add(localizedRoute);
22
25
  }
23
- if (!expanded.includes(route)) expanded.push(route);
26
+ expanded.add(route);
24
27
  }
25
- return expanded;
28
+ return [...expanded];
26
29
  }
27
30
  /**
28
31
  * Creates a post-rendering hook that injects the `lang` attribute
@@ -1 +1 @@
1
- {"version":3,"file":"i18n-prerender.js","names":[],"sources":["../../../../src/lib/nitro/i18n-prerender.ts"],"sourcesContent":["import type { PrerenderRoute } from 'nitro/types';\nimport type { I18nPrerenderOptions } from './types.js';\n\n/**\n * Expands a list of routes to include locale-prefixed variants.\n *\n * For each route and each locale, generates a prefixed route:\n * '/' + locale + route\n *\n * The default locale's routes are included both with and without the prefix\n * so that `/about` and `/en/about` both render.\n */\nexport function expandRoutesWithLocales(\n routes: string[],\n i18n: I18nPrerenderOptions,\n): string[] {\n const expanded: string[] = [];\n\n for (const route of routes) {\n // Skip locale expansion for internal analog endpoints and API routes.\n // `startsWith('/api/')` alone misses the bare `/api` path, which\n // would otherwise get locale-prefixed and produce phantom routes like\n // `/en/api`.\n if (\n route.includes('/_analog/') ||\n route === '/api' ||\n route.startsWith('/api/')\n ) {\n expanded.push(route);\n continue;\n }\n\n for (const locale of i18n.locales) {\n const prefix = `/${locale}`;\n const localizedRoute = route === '/' ? prefix : `${prefix}${route}`;\n expanded.push(localizedRoute);\n }\n\n if (!expanded.includes(route)) {\n expanded.push(route);\n }\n }\n\n return expanded;\n}\n\n/**\n * Creates a post-rendering hook that injects the `lang` attribute\n * into the `<html>` tag of prerendered pages based on the route's\n * locale prefix.\n */\nexport function createI18nPostRenderingHook(\n i18n: I18nPrerenderOptions,\n): (route: PrerenderRoute) => Promise<void> {\n return async (route: PrerenderRoute) => {\n if (!route.contents || typeof route.contents !== 'string') {\n return;\n }\n\n const locale = detectLocaleFromRoute(route.route, i18n);\n if (!locale) {\n return;\n }\n\n route.contents = setHtmlLang(route.contents, locale);\n };\n}\n\n/**\n * Detects the locale from a prerendered route path by checking\n * the first path segment against the configured locales.\n */\nexport function detectLocaleFromRoute(\n route: string,\n i18n: I18nPrerenderOptions,\n): string {\n const segments = route.split('/').filter(Boolean);\n const firstSegment = segments[0];\n\n if (firstSegment && i18n.locales.includes(firstSegment)) {\n return firstSegment;\n }\n\n return i18n.defaultLocale;\n}\n\n/**\n * Sets the `lang` attribute on the `<html>` tag in an HTML string.\n * If a `lang` attribute already exists, it is replaced.\n * If no `lang` attribute exists, it is added.\n */\nexport function setHtmlLang(html: string, locale: string): string {\n if (/<html[^>]*\\slang\\s*=\\s*[\"'][^\"']*[\"']/i.test(html)) {\n return html.replace(\n /(<html[^>]*\\s)lang\\s*=\\s*[\"'][^\"']*[\"']/i,\n `$1lang=\"${locale}\"`,\n );\n }\n\n return html.replace(/<html/i, `<html lang=\"${locale}\"`);\n}\n"],"mappings":";;;;;;;;;;AAYA,SAAgB,wBACd,QACA,MACU;CACV,MAAM,WAAqB,CAAC;CAE5B,KAAK,MAAM,SAAS,QAAQ;EAK1B,IACE,MAAM,SAAS,WAAW,KAC1B,UAAU,UACV,MAAM,WAAW,OAAO,GACxB;GACA,SAAS,KAAK,KAAK;GACnB;EACF;EAEA,KAAK,MAAM,UAAU,KAAK,SAAS;GACjC,MAAM,SAAS,IAAI;GACnB,MAAM,iBAAiB,UAAU,MAAM,SAAS,GAAG,SAAS;GAC5D,SAAS,KAAK,cAAc;EAC9B;EAEA,IAAI,CAAC,SAAS,SAAS,KAAK,GAC1B,SAAS,KAAK,KAAK;CAEvB;CAEA,OAAO;AACT;;;;;;AAOA,SAAgB,4BACd,MAC0C;CAC1C,OAAO,OAAO,UAA0B;EACtC,IAAI,CAAC,MAAM,YAAY,OAAO,MAAM,aAAa,UAC/C;EAGF,MAAM,SAAS,sBAAsB,MAAM,OAAO,IAAI;EACtD,IAAI,CAAC,QACH;EAGF,MAAM,WAAW,YAAY,MAAM,UAAU,MAAM;CACrD;AACF;;;;;AAMA,SAAgB,sBACd,OACA,MACQ;CAER,MAAM,eADW,MAAM,MAAM,GAAG,CAAC,CAAC,OAAO,OACpB,CAAA,CAAS;CAE9B,IAAI,gBAAgB,KAAK,QAAQ,SAAS,YAAY,GACpD,OAAO;CAGT,OAAO,KAAK;AACd;;;;;;AAOA,SAAgB,YAAY,MAAc,QAAwB;CAChE,IAAI,yCAAyC,KAAK,IAAI,GACpD,OAAO,KAAK,QACV,4CACA,WAAW,OAAO,EACpB;CAGF,OAAO,KAAK,QAAQ,UAAU,eAAe,OAAO,EAAE;AACxD"}
1
+ {"version":3,"file":"i18n-prerender.js","names":[],"sources":["../../../../src/lib/nitro/i18n-prerender.ts"],"sourcesContent":["import type { PrerenderRoute } from 'nitro/types';\nimport type { I18nPrerenderOptions } from './types.js';\n\n/**\n * Expands a list of routes to include locale-prefixed variants.\n *\n * For each route and each locale, generates a prefixed route:\n * '/' + locale + route\n *\n * The default locale's routes are included both with and without the prefix\n * so that `/about` and `/en/about` both render.\n * Routes that already have a configured locale prefix are kept as-is.\n */\nexport function expandRoutesWithLocales(\n routes: string[],\n i18n: I18nPrerenderOptions,\n apiPrefix = 'api',\n): string[] {\n const expanded = new Set<string>();\n const apiRoute = `/${apiPrefix.replace(/^\\/+|\\/+$/g, '')}`;\n\n for (const route of routes) {\n // Skip locale expansion for internal analog endpoints, API routes and\n // explicitly localized routes.\n // The bare API route (e.g. `/api`) is skipped too, which would otherwise\n // get locale-prefixed and produce phantom routes like `/en/api`.\n const firstSegment = route.split('/').filter(Boolean)[0];\n if (\n route.includes('/_analog/') ||\n route === apiRoute ||\n route.startsWith(`${apiRoute}/`) ||\n i18n.locales.includes(firstSegment)\n ) {\n expanded.add(route);\n continue;\n }\n\n for (const locale of i18n.locales) {\n const prefix = `/${locale}`;\n const localizedRoute = route === '/' ? prefix : `${prefix}${route}`;\n expanded.add(localizedRoute);\n }\n\n expanded.add(route);\n }\n\n return [...expanded];\n}\n\n/**\n * Creates a post-rendering hook that injects the `lang` attribute\n * into the `<html>` tag of prerendered pages based on the route's\n * locale prefix.\n */\nexport function createI18nPostRenderingHook(\n i18n: I18nPrerenderOptions,\n): (route: PrerenderRoute) => Promise<void> {\n return async (route: PrerenderRoute) => {\n if (!route.contents || typeof route.contents !== 'string') {\n return;\n }\n\n const locale = detectLocaleFromRoute(route.route, i18n);\n if (!locale) {\n return;\n }\n\n route.contents = setHtmlLang(route.contents, locale);\n };\n}\n\n/**\n * Detects the locale from a prerendered route path by checking\n * the first path segment against the configured locales.\n */\nexport function detectLocaleFromRoute(\n route: string,\n i18n: I18nPrerenderOptions,\n): string {\n const segments = route.split('/').filter(Boolean);\n const firstSegment = segments[0];\n\n if (firstSegment && i18n.locales.includes(firstSegment)) {\n return firstSegment;\n }\n\n return i18n.defaultLocale;\n}\n\n/**\n * Sets the `lang` attribute on the `<html>` tag in an HTML string.\n * If a `lang` attribute already exists, it is replaced.\n * If no `lang` attribute exists, it is added.\n */\nexport function setHtmlLang(html: string, locale: string): string {\n if (/<html[^>]*\\slang\\s*=\\s*[\"'][^\"']*[\"']/i.test(html)) {\n return html.replace(\n /(<html[^>]*\\s)lang\\s*=\\s*[\"'][^\"']*[\"']/i,\n `$1lang=\"${locale}\"`,\n );\n }\n\n return html.replace(/<html/i, `<html lang=\"${locale}\"`);\n}\n"],"mappings":";;;;;;;;;;;AAaA,SAAgB,wBACd,QACA,MACA,YAAY,OACF;CACV,MAAM,2BAAW,IAAI,IAAY;CACjC,MAAM,WAAW,IAAI,UAAU,QAAQ,cAAc,EAAE;CAEvD,KAAK,MAAM,SAAS,QAAQ;EAK1B,MAAM,eAAe,MAAM,MAAM,GAAG,CAAC,CAAC,OAAO,OAAO,CAAC,CAAC;EACtD,IACE,MAAM,SAAS,WAAW,KAC1B,UAAU,YACV,MAAM,WAAW,GAAG,SAAS,EAAE,KAC/B,KAAK,QAAQ,SAAS,YAAY,GAClC;GACA,SAAS,IAAI,KAAK;GAClB;EACF;EAEA,KAAK,MAAM,UAAU,KAAK,SAAS;GACjC,MAAM,SAAS,IAAI;GACnB,MAAM,iBAAiB,UAAU,MAAM,SAAS,GAAG,SAAS;GAC5D,SAAS,IAAI,cAAc;EAC7B;EAEA,SAAS,IAAI,KAAK;CACpB;CAEA,OAAO,CAAC,GAAG,QAAQ;AACrB;;;;;;AAOA,SAAgB,4BACd,MAC0C;CAC1C,OAAO,OAAO,UAA0B;EACtC,IAAI,CAAC,MAAM,YAAY,OAAO,MAAM,aAAa,UAC/C;EAGF,MAAM,SAAS,sBAAsB,MAAM,OAAO,IAAI;EACtD,IAAI,CAAC,QACH;EAGF,MAAM,WAAW,YAAY,MAAM,UAAU,MAAM;CACrD;AACF;;;;;AAMA,SAAgB,sBACd,OACA,MACQ;CAER,MAAM,eADW,MAAM,MAAM,GAAG,CAAC,CAAC,OAAO,OACpB,CAAA,CAAS;CAE9B,IAAI,gBAAgB,KAAK,QAAQ,SAAS,YAAY,GACpD,OAAO;CAGT,OAAO,KAAK;AACd;;;;;;AAOA,SAAgB,YAAY,MAAc,QAAwB;CAChE,IAAI,yCAAyC,KAAK,IAAI,GACpD,OAAO,KAAK,QACV,4CACA,WAAW,OAAO,EACpB;CAGF,OAAO,KAAK,QAAQ,UAAU,eAAe,OAAO,EAAE;AACxD"}
@@ -29,6 +29,8 @@ export type BuildServerFnDispatchModuleArgs = {
29
29
  * app configured. When absent, handlers run with only `providedIn: 'root'`.
30
30
  */
31
31
  appConfigModule?: string;
32
+ /** The app's root directory, where `zone.js` is resolved from. */
33
+ root: string;
32
34
  };
33
35
  /**
34
36
  * Generates the source of the Nitro dispatch handler.
@@ -38,4 +40,4 @@ export type BuildServerFnDispatchModuleArgs = {
38
40
  * each request looks up the function by id and runs it via `dispatchServerFn` —
39
41
  * the same call path the validation harnesses exercise.
40
42
  */
41
- export declare function buildServerFnDispatchModule({ modules, appConfigModule }: BuildServerFnDispatchModuleArgs): string;
43
+ export declare function buildServerFnDispatchModule({ modules, appConfigModule, root }: BuildServerFnDispatchModuleArgs): string;
@@ -1,3 +1,5 @@
1
+ import { dirname, join } from "node:path";
2
+ import { existsSync } from "node:fs";
1
3
  import { normalizePath } from "vite";
2
4
  //#region packages/platform/src/lib/nitro/server-fn-endpoints.ts
3
5
  /**
@@ -31,16 +33,17 @@ function getServerFnDispatchHandler() {
31
33
  * each request looks up the function by id and runs it via `dispatchServerFn` —
32
34
  * the same call path the validation harnesses exercise.
33
35
  */
34
- function buildServerFnDispatchModule({ modules, appConfigModule }) {
36
+ function buildServerFnDispatchModule({ modules, appConfigModule, root }) {
37
+ const registrationImports = modules.map((m) => `import ${JSON.stringify(normalizePath(m.file))};`).join("\n");
38
+ const appConfig = appConfigModule ? `import { config as serverFnAppConfig } from ${JSON.stringify(normalizePath(appConfigModule))};` : `const serverFnAppConfig = { providers: [] };`;
35
39
  return `import '@angular/compiler';
36
- import 'zone.js/node';
37
- import '@angular/platform-server/init';
40
+ ${hasZoneJs(root) ? `import 'zone.js/node';\n` : ""}import '@angular/platform-server/init';
38
41
  import { createServerFnAppInjector, createServerFnEventHandler } from '@analogjs/router/server';
39
42
 
40
43
  // Discovered server-function modules (registration side-effects).
41
- ${modules.map((m) => `import ${JSON.stringify(normalizePath(m.file))};`).join("\n")}
44
+ ${registrationImports}
42
45
 
43
- ${appConfigModule ? `import { config as serverFnAppConfig } from ${JSON.stringify(normalizePath(appConfigModule))};` : `const serverFnAppConfig = { providers: [] };`}
46
+ ${appConfig}
44
47
 
45
48
  // Bootstrapped once from the app's own server config, so a handler resolves the
46
49
  // same DI as an SSR render (\`providedIn: 'root'\` and listed providers alike).
@@ -51,6 +54,12 @@ export default createServerFnEventHandler(
51
54
  );
52
55
  `;
53
56
  }
57
+ function hasZoneJs(root) {
58
+ for (let dir = root;; dir = dirname(dir)) {
59
+ if (existsSync(join(dir, "node_modules/zone.js/package.json"))) return true;
60
+ if (dirname(dir) === dir) return false;
61
+ }
62
+ }
54
63
  //#endregion
55
64
  export { SERVER_FN_DISPATCH_ROUTE, SERVER_FN_DISPATCH_VIRTUAL, buildServerFnDispatchModule, getServerFnDispatchHandler };
56
65
 
@@ -1 +1 @@
1
- {"version":3,"file":"server-fn-endpoints.js","names":[],"sources":["../../../../src/lib/nitro/server-fn-endpoints.ts"],"sourcesContent":["import type { NitroEventHandler } from 'nitro/types';\nimport { normalizePath } from 'vite';\n\nimport type { ServerFnHandlerModule } from './get-server-fn-handlers.js';\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;CAC9D,OAAO;EACL,OAAO;EACP,SAAS;EACT,MAAM;CACR;AACF;;;;;;;;;AAsBA,SAAgB,4BAA4B,EAC1C,SACA,mBAC0C;CAwB1C,OAAO;;;;;;EAvBqB,QACzB,KAAK,MAAM,UAAU,KAAK,UAAU,cAAc,EAAE,IAAI,CAAC,EAAE,EAAE,CAAC,CAC9D,KAAK,IA2BR,EAAoB;;EAtBF,kBACd,+CAA+C,KAAK,UAClD,cAAc,eAAe,CAC/B,EAAE,KACF,+CAoBM;;;;;;;;;;AAUZ"}
1
+ {"version":3,"file":"server-fn-endpoints.js","names":[],"sources":["../../../../src/lib/nitro/server-fn-endpoints.ts"],"sourcesContent":["import type { NitroEventHandler } from 'nitro/types';\nimport { existsSync } from 'node:fs';\nimport { dirname, join } from 'node:path';\nimport { normalizePath } from 'vite';\n\nimport type { ServerFnHandlerModule } from './get-server-fn-handlers.js';\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 /** The app's root directory, where `zone.js` is resolved from. */\n root: 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 root,\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` (when installed; zoneless apps may omit it) and the server\n // platform init match the SSR entry, so bootstrapping the app injector below\n // 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 const zoneImport = hasZoneJs(root) ? `import 'zone.js/node';\\n` : '';\n\n return `import '@angular/compiler';\n${zoneImport}import '@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\nfunction hasZoneJs(root: string): boolean {\n for (let dir = root; ; dir = dirname(dir)) {\n if (existsSync(join(dir, 'node_modules/zone.js/package.json'))) {\n return true;\n }\n if (dirname(dir) === dir) {\n return false;\n }\n }\n}\n"],"mappings":";;;;;;;;AAWA,IAAa,6BAA6B;;AAG1C,IAAa,2BAA2B;;;;;;;;;;AAcxC,SAAgB,6BAAgD;CAC9D,OAAO;EACL,OAAO;EACP,SAAS;EACT,MAAM;CACR;AACF;;;;;;;;;AAwBA,SAAgB,4BAA4B,EAC1C,SACA,iBACA,QAC0C;CAC1C,MAAM,sBAAsB,QACzB,KAAK,MAAM,UAAU,KAAK,UAAU,cAAc,EAAE,IAAI,CAAC,EAAE,EAAE,CAAC,CAC9D,KAAK,IAAI;CAKZ,MAAM,YAAY,kBACd,+CAA+C,KAAK,UAClD,cAAc,eAAe,CAC/B,EAAE,KACF;CAeJ,OAAO;EAFY,UAAU,IAAI,IAAI,6BAA6B,GAGvD;;;;EAIX,oBAAoB;;EAEpB,UAAU;;;;;;;;;;AAUZ;AAEA,SAAS,UAAU,MAAuB;CACxC,KAAK,IAAI,MAAM,OAAQ,MAAM,QAAQ,GAAG,GAAG;EACzC,IAAI,WAAW,KAAK,KAAK,mCAAmC,CAAC,GAC3D,OAAO;EAET,IAAI,QAAQ,GAAG,MAAM,KACnB,OAAO;CAEX;AACF"}
@@ -10,12 +10,5 @@
10
10
  "schema": "./src/builders/vite/schema.json",
11
11
  "description": "Build with Vite."
12
12
  }
13
- },
14
- "executors": {
15
- "vite-dev-server": {
16
- "implementation": "./src/executors/vite-dev-server/vite-dev-server.impl",
17
- "schema": "./src/executors/vite-dev-server/schema.json",
18
- "description": "Vite dev server."
19
- }
20
13
  }
21
14
  }
@@ -1,9 +1,10 @@
1
1
  import { convertNxGenerator } from "@nx/devkit";
2
+ import generator from "./generator";
2
3
  /**
3
4
  * Angular CLI schematic wrapper for the Analog application generator.
4
5
  * Referenced by `generators.json#schematics.application.factory` so that
5
6
  * `ng generate @analogjs/platform:application` resolves through the
6
7
  * Angular schematics engine (which uses named exports, not default).
7
8
  */
8
- export declare const applicationSchematic: ReturnType<typeof convertNxGenerator>;
9
+ export declare function applicationSchematic(options: Parameters<typeof generator>[1]): ReturnType<ReturnType<typeof convertNxGenerator>>;
9
10
  export default applicationSchematic;
@@ -3,6 +3,7 @@ Object.defineProperties(exports, {
3
3
  [Symbol.toStringTag]: { value: "Module" }
4
4
  });
5
5
  const require_src_generators_app_generator = require("./generator.js");
6
+ let _nx_devkit = require("@nx/devkit");
6
7
  //#region packages/nx-plugin/src/generators/app/compat.ts
7
8
  /**
8
9
  * Angular CLI schematic wrapper for the Analog application generator.
@@ -10,7 +11,9 @@ const require_src_generators_app_generator = require("./generator.js");
10
11
  * `ng generate @analogjs/platform:application` resolves through the
11
12
  * Angular schematics engine (which uses named exports, not default).
12
13
  */
13
- var applicationSchematic = (0, require("@nx/devkit").convertNxGenerator)(require_src_generators_app_generator);
14
+ function applicationSchematic(options) {
15
+ return (0, _nx_devkit.convertNxGenerator)(require_src_generators_app_generator)(options);
16
+ }
14
17
  //#endregion
15
18
  exports.applicationSchematic = applicationSchematic;
16
19
  exports.default = applicationSchematic;
@@ -1 +1 @@
1
- {"version":3,"file":"compat.js","names":[],"sources":["../../../../../../../../nx-plugin/src/generators/app/compat.ts"],"sourcesContent":["import { convertNxGenerator } from '@nx/devkit';\nimport generator from './generator';\n\n/**\n * Angular CLI schematic wrapper for the Analog application generator.\n * Referenced by `generators.json#schematics.application.factory` so that\n * `ng generate @analogjs/platform:application` resolves through the\n * Angular schematics engine (which uses named exports, not default).\n */\nexport const applicationSchematic: ReturnType<typeof convertNxGenerator> =\n convertNxGenerator(generator) as ReturnType<typeof convertNxGenerator>;\nexport default applicationSchematic;\n"],"mappings":";;;;;;;;;;;;AASA,IAAa,wBAAA,uBACX,CAAA,CAAA,mBAAA,CAAmB,oCAAS"}
1
+ {"version":3,"file":"compat.js","names":[],"sources":["../../../../../../../../nx-plugin/src/generators/app/compat.ts"],"sourcesContent":["import { convertNxGenerator } from '@nx/devkit';\nimport generator from './generator';\n\n/**\n * Angular CLI schematic wrapper for the Analog application generator.\n * Referenced by `generators.json#schematics.application.factory` so that\n * `ng generate @analogjs/platform:application` resolves through the\n * Angular schematics engine (which uses named exports, not default).\n */\nexport function applicationSchematic(\n options: Parameters<typeof generator>[1],\n): ReturnType<ReturnType<typeof convertNxGenerator>> {\n return convertNxGenerator(generator)(options);\n}\nexport default applicationSchematic;\n"],"mappings":";;;;;;;;;;;;;AASA,SAAgB,qBACd,SACmD;CACnD,QAAA,GAAO,WAAA,mBAAA,CAAmB,oCAAS,CAAC,CAAC,OAAO;AAC9C"}
@@ -2,6 +2,7 @@ const require_version_utils = require("../../utils/version-utils.js");
2
2
  const require_add_home_page = require("./lib/add-home-page.js");
3
3
  const require_minimum_supported_versions = require("./versions/minimum-supported-versions.js");
4
4
  const require_add_angular_app = require("./lib/add-angular-app.js");
5
+ const require_versions = require("../../utils/versions/versions.js");
5
6
  const require_src_generators_init_generator = require("../init/generator.js");
6
7
  const require_add_files = require("./lib/add-files.js");
7
8
  const require_add_agent_context = require("./lib/add-agent-context.js");
@@ -41,7 +42,10 @@ function normalizeOptions(tree, options) {
41
42
  async function appGenerator(tree, options) {
42
43
  const nxVersion = require_version_utils.getInstalledPackageVersion(tree, "nx");
43
44
  if (nxVersion && require_minimum_supported_versions.belowMinimumSupportedNxVersion(nxVersion)) throw new Error(_nx_devkit.stripIndents`Nx v${require_minimum_supported_versions.MINIMUM_SUPPORTED_NX_VERSION} or newer is required to install Analog`);
44
- if (options.linter === "oxlint" && !nxVersion) throw new Error(_nx_devkit.stripIndents`The oxlint linter is only supported in Nx workspaces`);
45
+ if (options.linter === "oxlint") {
46
+ if (!nxVersion) throw new Error(_nx_devkit.stripIndents`The oxlint linter is only supported in Nx workspaces`);
47
+ if (require_minimum_supported_versions.belowMinimumSupportedOxlintNxVersion(nxVersion)) throw new Error(_nx_devkit.stripIndents`Nx v${require_minimum_supported_versions.MINIMUM_SUPPORTED_OXLINT_NX_VERSION} or newer is required to use the oxlint linter`);
48
+ }
45
49
  const normalizedOptions = normalizeOptions(tree, options);
46
50
  if (nxVersion) await require_add_angular_app.addAngularApp(tree, normalizedOptions);
47
51
  else {
@@ -62,10 +66,11 @@ async function appGenerator(tree, options) {
62
66
  require_add_files.addFiles(tree, normalizedOptions, majorAngularVersion);
63
67
  (0, _nx_devkit.addDependenciesToPackageJson)(tree, {
64
68
  "front-matter": "^4.0.2",
69
+ h3: require_versions.H3,
65
70
  marked: "^18.0.0",
66
71
  mermaid: "^10.2.4",
67
72
  prismjs: "^1.29.0"
68
- }, {});
73
+ }, { "@analogjs/vite-plugin-nitro": require_versions.ANALOG_JS_VITE_PLUGIN_NITRO });
69
74
  (0, _nx_devkit.updateJson)(tree, "/package.json", (json) => {
70
75
  json.dependencies["@angular/platform-server"] = `~${angularVersion}`;
71
76
  json.overrides = {
@@ -1 +1 @@
1
- {"version":3,"file":"generator.js","names":[],"sources":["../../../../../../../../nx-plugin/src/generators/app/generator.ts"],"sourcesContent":["import {\n formatFiles,\n getWorkspaceLayout,\n installPackagesTask,\n names,\n offsetFromRoot as determineOffsetFromRoot,\n stripIndents,\n Tree,\n addDependenciesToPackageJson,\n updateJson,\n} from '@nx/devkit';\nimport { wrapAngularDevkitSchematic } from '@nx/devkit/ngcli-adapter';\nimport { AnalogNxApplicationGeneratorOptions } from './schema';\nimport { major, coerce } from 'semver';\nimport { getInstalledPackageVersion } from '../../utils/version-utils';\nimport { addHomePage } from './lib/add-home-page';\nimport {\n belowMinimumSupportedNxVersion,\n MINIMUM_SUPPORTED_NX_VERSION,\n} from './versions/minimum-supported-versions';\nimport { addAngularApp } from './lib/add-angular-app';\nimport setupAnalogGenerator from '../init/generator';\nimport { addFiles } from './lib/add-files';\nimport { addAgentContext } from './lib/add-agent-context';\nimport { addTailwindConfig } from './lib/add-tailwind-config';\nimport { cleanupFiles } from './lib/cleanup-files';\nimport { addAnalogProjectConfig } from './lib/add-analog-project-config';\nimport { updateIndex } from './lib/update-index-html';\n\nexport interface NormalizedOptions\n extends AnalogNxApplicationGeneratorOptions, ReturnType<typeof names> {\n projectName: string;\n projectRoot: string;\n projectDirectory: string;\n parsedTags: string[];\n offsetFromRoot: string;\n appsDir: string;\n nxPackageNamespace: string;\n isNx: boolean;\n}\n\nfunction normalizeOptions(\n tree: Tree,\n options: AnalogNxApplicationGeneratorOptions,\n): NormalizedOptions {\n const isNx = tree.exists('/nx.json');\n const appsDir = isNx ? getWorkspaceLayout(tree).appsDir : 'projects';\n const allNames = names(options.analogAppName);\n const projectDirectory = allNames.fileName;\n const projectName = projectDirectory.replace(new RegExp('/', 'g'), '-');\n const projectRoot = `${appsDir}/${projectDirectory}`;\n const parsedTags = options.tags\n ? options.tags.split(',').map((s) => s.trim())\n : [];\n const offsetFromRoot = determineOffsetFromRoot(projectRoot);\n const nxPackageNamespace = '@nx';\n const addTailwind = options.addTailwind ?? true;\n\n return {\n ...options,\n ...allNames,\n projectName,\n projectRoot,\n projectDirectory,\n parsedTags,\n offsetFromRoot,\n appsDir,\n nxPackageNamespace,\n addTailwind,\n isNx,\n };\n}\n\nasync function appGenerator(\n tree: Tree,\n options: AnalogNxApplicationGeneratorOptions,\n): Promise<() => void> {\n const nxVersion = getInstalledPackageVersion(tree, 'nx');\n\n if (nxVersion && belowMinimumSupportedNxVersion(nxVersion)) {\n throw new Error(\n stripIndents`Nx v${MINIMUM_SUPPORTED_NX_VERSION} or newer is required to install Analog`,\n );\n }\n\n if (options.linter === 'oxlint' && !nxVersion) {\n throw new Error(\n stripIndents`The oxlint linter is only supported in Nx workspaces`,\n );\n }\n\n const normalizedOptions = normalizeOptions(tree, options);\n\n if (nxVersion) {\n await addAngularApp(tree, normalizedOptions);\n } else {\n const angularAppSchematic = wrapAngularDevkitSchematic(\n '@schematics/angular',\n 'application',\n );\n await angularAppSchematic(tree, {\n projectRoot: normalizedOptions.projectRoot,\n name: normalizedOptions.analogAppName,\n });\n addAnalogProjectConfig(\n tree,\n normalizedOptions.projectRoot,\n normalizedOptions.projectName,\n normalizedOptions.parsedTags,\n normalizedOptions.name,\n normalizedOptions.appsDir,\n normalizedOptions.nxPackageNamespace,\n );\n }\n\n await setupAnalogGenerator(tree, {\n project: normalizedOptions.analogAppName,\n vitest: true,\n });\n\n const angularVersion = getInstalledPackageVersion(tree, '@angular/core');\n const coercedAngularVersion = coerce(angularVersion ?? '');\n if (!coercedAngularVersion) {\n throw new Error('Could not determine installed Angular version.');\n }\n const majorAngularVersion = major(coercedAngularVersion);\n addFiles(tree, normalizedOptions, majorAngularVersion);\n addDependenciesToPackageJson(\n tree,\n {\n 'front-matter': '^4.0.2',\n marked: '^18.0.0',\n mermaid: '^10.2.4',\n prismjs: '^1.29.0',\n },\n {},\n );\n\n updateJson<{\n dependencies: Record<string, string>;\n overrides?: Record<string, unknown>;\n }>(tree, '/package.json', (json) => {\n json.dependencies['@angular/platform-server'] = `~${angularVersion}`;\n json.overrides = {\n ...json.overrides,\n vite: '$vite',\n vitest: '$vitest',\n };\n\n return json;\n });\n\n updateIndex(tree, normalizedOptions.analogAppName);\n\n if (normalizedOptions.addTailwind) {\n await addTailwindConfig(tree, normalizedOptions.projectName);\n }\n\n addHomePage(tree, normalizedOptions, majorAngularVersion);\n\n if (!normalizedOptions.skipAgentContext) {\n addAgentContext(tree, normalizedOptions.projectRoot);\n }\n\n cleanupFiles(tree, normalizedOptions);\n\n if (!normalizedOptions.skipFormat) {\n await formatFiles(tree);\n }\n\n return () => {\n installPackagesTask(tree);\n };\n}\n\nexport default appGenerator;\n"],"mappings":";;;;;;;;;;;;;;;AAyCA,SAAS,iBACP,MACA,SACmB;CACnB,MAAM,O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,kBAAkB;EAC3B,QAAQ;CACV,CAAC;CAED,MAAM,iBAAiB,sBAAA,2BAA2B,MAAM,eAAe;CACvE,MAAM,yBAAA,GAAwB,OAAA,OAAA,CAAO,kBAAkB,EAAE;CACzD,IAAI,CAAC,uBACH,MAAM,IAAI,MAAM,gDAAgD;CAElE,MAAM,uBAAA,GAAsB,OAAA,MAAA,CAAM,qBAAqB;CACvD,kBAAA,SAAS,MAAM,mBAAmB,mBAAmB;CACrD,CAAA,GAAA,WAAA,6BAAA,CACE,MACA;EACE,gBAAgB;EAChB,QAAQ;EACR,SAAS;EACT,SAAS;CACX,GACA,CAAC,CACH;CAEA,CAAA,GAAA,WAAA,WAAA,CAGG,MAAM,kBAAkB,SAAS;EAClC,KAAK,aAAa,8BAA8B,IAAI;EACpD,KAAK,YAAY;GACf,GAAG,KAAK;GACR,MAAM;GACN,QAAQ;EACV;EAEA,OAAO;CACT,CAAC;CAED,0BAAA,YAAY,MAAM,kBAAkB,aAAa;CAEjD,IAAI,kBAAkB,aACpB,MAAM,4BAAA,kBAAkB,MAAM,kBAAkB,WAAW;CAG7D,sBAAA,YAAY,MAAM,mBAAmB,mBAAmB;CAExD,IAAI,CAAC,kBAAkB,kBACrB,0BAAA,gBAAgB,MAAM,kBAAkB,WAAW;CAGrD,sBAAA,aAAa,MAAM,iBAAiB;CAEpC,IAAI,CAAC,kBAAkB,YACrB,OAAA,GAAM,WAAA,YAAA,CAAY,IAAI;CAGxB,aAAa;EACX,CAAA,GAAA,WAAA,oBAAA,CAAoB,IAAI;CAC1B;AACF"}
1
+ {"version":3,"file":"generator.js","names":[],"sources":["../../../../../../../../nx-plugin/src/generators/app/generator.ts"],"sourcesContent":["import {\n formatFiles,\n getWorkspaceLayout,\n installPackagesTask,\n names,\n offsetFromRoot as determineOffsetFromRoot,\n stripIndents,\n Tree,\n addDependenciesToPackageJson,\n updateJson,\n} from '@nx/devkit';\nimport { wrapAngularDevkitSchematic } from '@nx/devkit/ngcli-adapter';\nimport { AnalogNxApplicationGeneratorOptions } from './schema';\nimport { major, coerce } from 'semver';\nimport { getInstalledPackageVersion } from '../../utils/version-utils';\nimport { addHomePage } from './lib/add-home-page';\nimport {\n belowMinimumSupportedNxVersion,\n belowMinimumSupportedOxlintNxVersion,\n MINIMUM_SUPPORTED_NX_VERSION,\n MINIMUM_SUPPORTED_OXLINT_NX_VERSION,\n} from './versions/minimum-supported-versions';\nimport { addAngularApp } from './lib/add-angular-app';\nimport setupAnalogGenerator from '../init/generator';\nimport { addFiles } from './lib/add-files';\nimport { addAgentContext } from './lib/add-agent-context';\nimport { addTailwindConfig } from './lib/add-tailwind-config';\nimport { cleanupFiles } from './lib/cleanup-files';\nimport { addAnalogProjectConfig } from './lib/add-analog-project-config';\nimport { updateIndex } from './lib/update-index-html';\nimport { ANALOG_JS_VITE_PLUGIN_NITRO, H3 } from '../../utils/versions/versions';\n\nexport interface NormalizedOptions\n extends AnalogNxApplicationGeneratorOptions, ReturnType<typeof names> {\n projectName: string;\n projectRoot: string;\n projectDirectory: string;\n parsedTags: string[];\n offsetFromRoot: string;\n appsDir: string;\n nxPackageNamespace: string;\n isNx: boolean;\n}\n\nfunction normalizeOptions(\n tree: Tree,\n options: AnalogNxApplicationGeneratorOptions,\n): NormalizedOptions {\n const isNx = tree.exists('/nx.json');\n const appsDir = isNx ? getWorkspaceLayout(tree).appsDir : 'projects';\n const allNames = names(options.analogAppName);\n const projectDirectory = allNames.fileName;\n const projectName = projectDirectory.replace(new RegExp('/', 'g'), '-');\n const projectRoot = `${appsDir}/${projectDirectory}`;\n const parsedTags = options.tags\n ? options.tags.split(',').map((s) => s.trim())\n : [];\n const offsetFromRoot = determineOffsetFromRoot(projectRoot);\n const nxPackageNamespace = '@nx';\n const addTailwind = options.addTailwind ?? true;\n\n return {\n ...options,\n ...allNames,\n projectName,\n projectRoot,\n projectDirectory,\n parsedTags,\n offsetFromRoot,\n appsDir,\n nxPackageNamespace,\n addTailwind,\n isNx,\n };\n}\n\nasync function appGenerator(\n tree: Tree,\n options: AnalogNxApplicationGeneratorOptions,\n): Promise<() => void> {\n const nxVersion = getInstalledPackageVersion(tree, 'nx');\n\n if (nxVersion && belowMinimumSupportedNxVersion(nxVersion)) {\n throw new Error(\n stripIndents`Nx v${MINIMUM_SUPPORTED_NX_VERSION} or newer is required to install Analog`,\n );\n }\n\n if (options.linter === 'oxlint') {\n if (!nxVersion) {\n throw new Error(\n stripIndents`The oxlint linter is only supported in Nx workspaces`,\n );\n }\n if (belowMinimumSupportedOxlintNxVersion(nxVersion)) {\n throw new Error(\n stripIndents`Nx v${MINIMUM_SUPPORTED_OXLINT_NX_VERSION} or newer is required to use the oxlint linter`,\n );\n }\n }\n\n const normalizedOptions = normalizeOptions(tree, options);\n\n if (nxVersion) {\n await addAngularApp(tree, normalizedOptions);\n } else {\n const angularAppSchematic = wrapAngularDevkitSchematic(\n '@schematics/angular',\n 'application',\n );\n await angularAppSchematic(tree, {\n projectRoot: normalizedOptions.projectRoot,\n name: normalizedOptions.analogAppName,\n });\n addAnalogProjectConfig(\n tree,\n normalizedOptions.projectRoot,\n normalizedOptions.projectName,\n normalizedOptions.parsedTags,\n normalizedOptions.name,\n normalizedOptions.appsDir,\n normalizedOptions.nxPackageNamespace,\n );\n }\n\n await setupAnalogGenerator(tree, {\n project: normalizedOptions.analogAppName,\n vitest: true,\n });\n\n const angularVersion = getInstalledPackageVersion(tree, '@angular/core');\n const coercedAngularVersion = coerce(angularVersion ?? '');\n if (!coercedAngularVersion) {\n throw new Error('Could not determine installed Angular version.');\n }\n const majorAngularVersion = major(coercedAngularVersion);\n addFiles(tree, normalizedOptions, majorAngularVersion);\n addDependenciesToPackageJson(\n tree,\n {\n 'front-matter': '^4.0.2',\n h3: H3,\n marked: '^18.0.0',\n mermaid: '^10.2.4',\n prismjs: '^1.29.0',\n },\n { '@analogjs/vite-plugin-nitro': ANALOG_JS_VITE_PLUGIN_NITRO },\n );\n\n updateJson<{\n dependencies: Record<string, string>;\n overrides?: Record<string, unknown>;\n }>(tree, '/package.json', (json) => {\n json.dependencies['@angular/platform-server'] = `~${angularVersion}`;\n json.overrides = {\n ...json.overrides,\n vite: '$vite',\n vitest: '$vitest',\n };\n\n return json;\n });\n\n updateIndex(tree, normalizedOptions.analogAppName);\n\n if (normalizedOptions.addTailwind) {\n await addTailwindConfig(tree, normalizedOptions.projectName);\n }\n\n addHomePage(tree, normalizedOptions, majorAngularVersion);\n\n if (!normalizedOptions.skipAgentContext) {\n addAgentContext(tree, normalizedOptions.projectRoot);\n }\n\n cleanupFiles(tree, normalizedOptions);\n\n if (!normalizedOptions.skipFormat) {\n await formatFiles(tree);\n }\n\n return () => {\n installPackagesTask(tree);\n };\n}\n\nexport default appGenerator;\n"],"mappings":";;;;;;;;;;;;;;;;AA4CA,SAAS,iBACP,MACA,SACmB;CACnB,MAAM,OAAO,KAAK,OAAO,UAAU;CACnC,MAAM,UAAU,QAAA,GAAO,WAAA,mBAAA,CAAmB,IAAI,CAAC,CAAC,UAAU;CAC1D,MAAM,YAAA,GAAW,WAAA,MAAA,CAAM,QAAQ,aAAa;CAC5C,MAAM,mBAAmB,SAAS;CAClC,MAAM,cAAc,iBAAiB,wBAAQ,IAAI,OAAO,KAAK,GAAG,GAAG,GAAG;CACtE,MAAM,cAAc,GAAG,QAAQ,GAAG;CAClC,MAAM,aAAa,QAAQ,OACvB,QAAQ,KAAK,MAAM,GAAG,CAAC,CAAC,KAAK,MAAM,EAAE,KAAK,CAAC,IAC3C,CAAC;CACL,MAAM,kBAAA,GAAiB,WAAA,eAAA,CAAwB,WAAW;CAC1D,MAAM,qBAAqB;CAC3B,MAAM,cAAc,QAAQ,eAAe;CAE3C,OAAO;EACL,GAAG;EACH,GAAG;EACH;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;CACF;AACF;AAEA,eAAe,aACb,MACA,SACqB;CACrB,MAAM,YAAY,sBAAA,2BAA2B,MAAM,IAAI;CAEvD,IAAI,aAAa,mCAAA,+BAA+B,SAAS,GACvD,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,OAAO;CACT,CAAC;CAED,0BAAA,YAAY,MAAM,kBAAkB,aAAa;CAEjD,IAAI,kBAAkB,aACpB,MAAM,4BAAA,kBAAkB,MAAM,kBAAkB,WAAW;CAG7D,sBAAA,YAAY,MAAM,mBAAmB,mBAAmB;CAExD,IAAI,CAAC,kBAAkB,kBACrB,0BAAA,gBAAgB,MAAM,kBAAkB,WAAW;CAGrD,sBAAA,aAAa,MAAM,iBAAiB;CAEpC,IAAI,CAAC,kBAAkB,YACrB,OAAA,GAAM,WAAA,YAAA,CAAY,IAAI;CAGxB,aAAa;EACX,CAAA,GAAA,WAAA,oBAAA,CAAoB,IAAI;CAC1B;AACF"}
@@ -1,7 +1,6 @@
1
1
  const require_tailwind_dependencies = require("../versions/tailwind-dependencies.js");
2
2
  let _nx_devkit = require("@nx/devkit");
3
3
  let semver = require("semver");
4
- let _nx_devkit_internal = require("@nx/devkit/internal");
5
4
  //#region packages/nx-plugin/src/generators/app/lib/add-tailwind-helpers.ts
6
5
  function normalizeOptions(options) {
7
6
  return {
@@ -13,7 +12,8 @@ function detectTailwindInstalledVersion(tree) {
13
12
  const { dependencies, devDependencies } = (0, _nx_devkit.readJson)(tree, "package.json");
14
13
  const tailwindVersion = dependencies?.tailwindcss ?? devDependencies?.tailwindcss;
15
14
  if (!tailwindVersion) return;
16
- const version = (0, _nx_devkit_internal.checkAndCleanWithSemver)("tailwindcss", tailwindVersion);
15
+ const version = (0, semver.coerce)(tailwindVersion);
16
+ if (!version) throw new Error(`The Tailwind CSS version "${tailwindVersion}" is not a valid version.`);
17
17
  if ((0, semver.lt)(version, "4.0.0")) throw new Error(`The Tailwind CSS version "${tailwindVersion}" is not supported. Please upgrade to v4.0.0 or higher.`);
18
18
  return (0, semver.lt)(version, "5.0.0") ? "4" : "5";
19
19
  }