@analogjs/platform 3.0.0-alpha.9 → 3.0.0-alpha.91

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 (355) hide show
  1. package/migrations/migration.json +7 -1
  2. package/package.json +28 -14
  3. package/src/index.d.ts +4 -2
  4. package/src/index.js +2 -1
  5. package/src/index.js.map +1 -1
  6. package/src/lib/analog-integration-plugin.d.ts +9 -0
  7. package/src/lib/analog-integration-plugin.js +22 -0
  8. package/src/lib/analog-integration-plugin.js.map +1 -0
  9. package/src/lib/clear-client-page-endpoint.d.ts +2 -2
  10. package/src/lib/clear-client-page-endpoint.js +27 -5
  11. package/src/lib/clear-client-page-endpoint.js.map +1 -1
  12. package/src/lib/content/marked/index.d.ts +5 -5
  13. package/src/lib/content/marked/index.js.map +1 -1
  14. package/src/lib/content/marked/marked-content-highlighter.d.ts +2 -2
  15. package/src/lib/content/marked/marked-content-highlighter.js.map +1 -1
  16. package/src/lib/content/marked/marked-setup.service.d.ts +8 -8
  17. package/src/lib/content/marked/marked-setup.service.js +7 -5
  18. package/src/lib/content/marked/marked-setup.service.js.map +1 -1
  19. package/src/lib/content/prism/angular.js.map +1 -1
  20. package/src/lib/content/prism/index.d.ts +1 -1
  21. package/src/lib/content/prism/index.js.map +1 -1
  22. package/src/lib/content/prism/options.d.ts +1 -1
  23. package/src/lib/content/prism/prism-highlighter.d.ts +5 -5
  24. package/src/lib/content/prism/prism-highlighter.js.map +1 -1
  25. package/src/lib/content/shiki/index.d.ts +3 -3
  26. package/src/lib/content/shiki/index.js +9 -6
  27. package/src/lib/content/shiki/index.js.map +1 -1
  28. package/src/lib/content/shiki/options.d.ts +8 -7
  29. package/src/lib/content/shiki/shiki-highlighter.d.ts +14 -13
  30. package/src/lib/content/shiki/shiki-highlighter.js +7 -4
  31. package/src/lib/content/shiki/shiki-highlighter.js.map +1 -1
  32. package/src/lib/content/utils/escape-html.d.ts +7 -0
  33. package/src/lib/content/utils/escape-html.js +16 -0
  34. package/src/lib/content/utils/escape-html.js.map +1 -0
  35. package/src/lib/content-plugin.d.ts +19 -19
  36. package/src/lib/content-plugin.js +34 -9
  37. package/src/lib/content-plugin.js.map +1 -1
  38. package/src/lib/deps-plugin.d.ts +2 -2
  39. package/src/lib/deps-plugin.js +24 -11
  40. package/src/lib/deps-plugin.js.map +1 -1
  41. package/src/lib/discover-library-routes.d.ts +19 -0
  42. package/src/lib/discover-library-routes.js +72 -0
  43. package/src/lib/discover-library-routes.js.map +1 -0
  44. package/src/lib/i18n-component-registry-plugin.d.ts +17 -0
  45. package/src/lib/i18n-component-registry-plugin.js +100 -0
  46. package/src/lib/i18n-component-registry-plugin.js.map +1 -0
  47. package/src/lib/i18n-extract-plugin.d.ts +33 -0
  48. package/src/lib/inject-server-fn-ids.d.ts +17 -0
  49. package/src/lib/inject-server-fn-ids.js +94 -0
  50. package/src/lib/inject-server-fn-ids.js.map +1 -0
  51. package/src/lib/nitro/analog-nitro-plugin.d.ts +18 -0
  52. package/src/lib/nitro/analog-nitro-plugin.js +582 -0
  53. package/src/lib/nitro/analog-nitro-plugin.js.map +1 -0
  54. package/src/lib/nitro/angular-linker-plugin.d.ts +15 -0
  55. package/src/lib/nitro/angular-linker-plugin.js +64 -0
  56. package/src/lib/nitro/angular-linker-plugin.js.map +1 -0
  57. package/src/lib/nitro/build-sitemap.d.ts +23 -0
  58. package/src/lib/nitro/build-sitemap.js +137 -0
  59. package/src/lib/nitro/build-sitemap.js.map +1 -0
  60. package/src/lib/nitro/debug.d.ts +5 -0
  61. package/src/lib/nitro/debug.js +11 -0
  62. package/src/lib/nitro/debug.js.map +1 -0
  63. package/src/lib/nitro/get-content-files.d.ts +13 -0
  64. package/src/lib/nitro/get-content-files.js +52 -0
  65. package/src/lib/nitro/get-content-files.js.map +1 -0
  66. package/src/lib/nitro/get-page-handlers.d.ts +22 -0
  67. package/src/lib/nitro/get-page-handlers.js +33 -0
  68. package/src/lib/nitro/get-page-handlers.js.map +1 -0
  69. package/src/lib/nitro/i18n-prerender.d.ts +29 -0
  70. package/src/lib/nitro/i18n-prerender.js +61 -0
  71. package/src/lib/nitro/i18n-prerender.js.map +1 -0
  72. package/src/lib/nitro/page-endpoints-plugin.d.ts +7 -0
  73. package/src/lib/nitro/page-endpoints-plugin.js +72 -0
  74. package/src/lib/nitro/page-endpoints-plugin.js.map +1 -0
  75. package/src/lib/nitro/post-rendering-hook.d.ts +2 -0
  76. package/src/lib/nitro/post-rendering-hook.js +10 -0
  77. package/src/lib/nitro/post-rendering-hook.js.map +1 -0
  78. package/src/lib/nitro/renderers.d.ts +33 -0
  79. package/src/lib/nitro/renderers.js +22 -0
  80. package/src/lib/nitro/renderers.js.map +1 -0
  81. package/src/lib/nitro/types.d.ts +122 -0
  82. package/src/lib/nx-plugin/_virtual/_rolldown/runtime.js +23 -0
  83. package/src/lib/nx-plugin/builders.json +15 -0
  84. package/src/lib/nx-plugin/executors.json +13 -5
  85. package/src/lib/nx-plugin/generators.json +25 -0
  86. package/src/lib/nx-plugin/node_modules/.pnpm/es-toolkit@1.45.1/node_modules/es-toolkit/dist/string/camelCase.js +13 -0
  87. package/src/lib/nx-plugin/node_modules/.pnpm/es-toolkit@1.45.1/node_modules/es-toolkit/dist/string/camelCase.js.map +1 -0
  88. package/src/lib/nx-plugin/node_modules/.pnpm/es-toolkit@1.45.1/node_modules/es-toolkit/dist/string/capitalize.js +8 -0
  89. package/src/lib/nx-plugin/node_modules/.pnpm/es-toolkit@1.45.1/node_modules/es-toolkit/dist/string/capitalize.js.map +1 -0
  90. package/src/lib/nx-plugin/node_modules/.pnpm/es-toolkit@1.45.1/node_modules/es-toolkit/dist/string/words.js +9 -0
  91. package/src/lib/nx-plugin/node_modules/.pnpm/es-toolkit@1.45.1/node_modules/es-toolkit/dist/string/words.js.map +1 -0
  92. package/src/lib/nx-plugin/package.json +1 -3
  93. package/src/lib/nx-plugin/src/builders/vite/schema.json +39 -0
  94. package/src/lib/nx-plugin/src/builders/vite/vite-build.d.ts +11 -0
  95. package/src/lib/nx-plugin/src/builders/vite/vite-build.js +18 -0
  96. package/src/lib/nx-plugin/src/builders/vite/vite-build.js.map +1 -0
  97. package/src/lib/nx-plugin/src/builders/vite-dev-server/dev-server.d.ts +7 -0
  98. package/src/lib/nx-plugin/src/builders/vite-dev-server/dev-server.js +14 -0
  99. package/src/lib/nx-plugin/src/builders/vite-dev-server/dev-server.js.map +1 -0
  100. package/src/lib/nx-plugin/src/builders/vite-dev-server/schema.json +27 -0
  101. package/src/lib/nx-plugin/src/executors/vite-dev-server/compat.d.ts +1 -1
  102. package/src/lib/nx-plugin/src/executors/vite-dev-server/compat.js +4 -4
  103. package/src/lib/nx-plugin/src/executors/vite-dev-server/compat.js.map +1 -1
  104. package/src/lib/nx-plugin/src/executors/vite-dev-server/vite-dev-server.impl.d.ts +1 -1
  105. package/src/lib/nx-plugin/src/executors/vite-dev-server/vite-dev-server.impl.js +3 -3
  106. package/src/lib/nx-plugin/src/executors/vite-dev-server/vite-dev-server.impl.js.map +1 -1
  107. package/src/lib/nx-plugin/src/executors/vitest/compat.d.ts +1 -1
  108. package/src/lib/nx-plugin/src/executors/vitest/compat.js +4 -4
  109. package/src/lib/nx-plugin/src/executors/vitest/compat.js.map +1 -1
  110. package/src/lib/nx-plugin/src/executors/vitest/vitest.impl.d.ts +1 -1
  111. package/src/lib/nx-plugin/src/executors/vitest/vitest.impl.js +3 -3
  112. package/src/lib/nx-plugin/src/executors/vitest/vitest.impl.js.map +1 -1
  113. package/src/lib/nx-plugin/src/generators/app/compat.d.ts +9 -3
  114. package/src/lib/nx-plugin/src/generators/app/compat.js +15 -4
  115. package/src/lib/nx-plugin/src/generators/app/compat.js.map +1 -1
  116. package/src/lib/nx-plugin/src/generators/app/files/agents/AGENTS.md +11 -0
  117. package/src/lib/nx-plugin/src/generators/app/files/agents/CLAUDE.md +1 -0
  118. package/src/lib/nx-plugin/src/generators/app/files/root/tsconfig.base.json +3 -6
  119. package/src/lib/nx-plugin/src/generators/app/files/template-angular/src/test-setup.ts__template__ +1 -0
  120. package/src/lib/nx-plugin/src/generators/app/files/template-angular/tsconfig.app.json__template__ +1 -3
  121. package/src/lib/nx-plugin/src/generators/app/files/template-angular/tsconfig.json__template__ +2 -1
  122. package/src/lib/nx-plugin/src/generators/app/files/template-angular/vite.config.ts__template__ +7 -3
  123. package/src/lib/nx-plugin/src/generators/app/files/template-angular-v17/tsconfig.json__template__ +4 -2
  124. package/src/lib/nx-plugin/src/generators/app/files/template-angular-v17/vite.config.ts__template__ +2 -5
  125. package/src/lib/nx-plugin/src/generators/app/files/template-angular-v18/tsconfig.json__template__ +4 -2
  126. package/src/lib/nx-plugin/src/generators/app/files/template-angular-v18/vite.config.ts__template__ +3 -6
  127. package/src/lib/nx-plugin/src/generators/app/files/template-angular-v19/tsconfig.app.json__template__ +1 -3
  128. package/src/lib/nx-plugin/src/generators/app/files/template-angular-v19/tsconfig.json__template__ +4 -2
  129. package/src/lib/nx-plugin/src/generators/app/files/template-angular-v19/vite.config.ts__template__ +2 -5
  130. package/src/lib/nx-plugin/src/generators/app/generator.d.ts +11 -11
  131. package/src/lib/nx-plugin/src/generators/app/generator.js +44 -37
  132. package/src/lib/nx-plugin/src/generators/app/generator.js.map +1 -1
  133. package/src/lib/nx-plugin/src/generators/app/lib/add-agent-context.d.ts +2 -0
  134. package/src/lib/nx-plugin/src/generators/app/lib/add-agent-context.js +16 -0
  135. package/src/lib/nx-plugin/src/generators/app/lib/add-agent-context.js.map +1 -0
  136. package/src/lib/nx-plugin/src/generators/app/lib/add-analog-dependencies.d.ts +1 -1
  137. package/src/lib/nx-plugin/src/generators/app/lib/add-analog-project-config.d.ts +1 -1
  138. package/src/lib/nx-plugin/src/generators/app/lib/add-analog-project-config.js +6 -5
  139. package/src/lib/nx-plugin/src/generators/app/lib/add-analog-project-config.js.map +1 -1
  140. package/src/lib/nx-plugin/src/generators/app/lib/add-angular-app.d.ts +2 -2
  141. package/src/lib/nx-plugin/src/generators/app/lib/add-angular-app.js +8 -11
  142. package/src/lib/nx-plugin/src/generators/app/lib/add-angular-app.js.map +1 -1
  143. package/src/lib/nx-plugin/src/generators/app/lib/add-eslint.d.ts +2 -2
  144. package/src/lib/nx-plugin/src/generators/app/lib/add-files.d.ts +2 -2
  145. package/src/lib/nx-plugin/src/generators/app/lib/add-files.js +6 -5
  146. package/src/lib/nx-plugin/src/generators/app/lib/add-files.js.map +1 -1
  147. package/src/lib/nx-plugin/src/generators/app/lib/add-home-page.d.ts +2 -2
  148. package/src/lib/nx-plugin/src/generators/app/lib/add-home-page.js +6 -5
  149. package/src/lib/nx-plugin/src/generators/app/lib/add-home-page.js.map +1 -1
  150. package/src/lib/nx-plugin/src/generators/app/lib/add-tailwind-config.d.ts +7 -7
  151. package/src/lib/nx-plugin/src/generators/app/lib/add-tailwind-config.js +13 -11
  152. package/src/lib/nx-plugin/src/generators/app/lib/add-tailwind-config.js.map +1 -1
  153. package/src/lib/nx-plugin/src/generators/app/lib/add-tailwind-helpers.d.ts +4 -5
  154. package/src/lib/nx-plugin/src/generators/app/lib/add-tailwind-helpers.js +34 -40
  155. package/src/lib/nx-plugin/src/generators/app/lib/add-tailwind-helpers.js.map +1 -1
  156. package/src/lib/nx-plugin/src/generators/app/lib/add-vite-plugin.d.ts +1 -1
  157. package/src/lib/nx-plugin/src/generators/app/lib/cleanup-files.d.ts +2 -2
  158. package/src/lib/nx-plugin/src/generators/app/lib/cleanup-files.js +1 -1
  159. package/src/lib/nx-plugin/src/generators/app/lib/cleanup-files.js.map +1 -1
  160. package/src/lib/nx-plugin/src/generators/app/lib/initialize-analog-workspace.d.ts +2 -2
  161. package/src/lib/nx-plugin/src/generators/app/lib/update-index-html.d.ts +1 -1
  162. package/src/lib/nx-plugin/src/generators/app/lib/update-index-html.js +5 -4
  163. package/src/lib/nx-plugin/src/generators/app/lib/update-index-html.js.map +1 -1
  164. package/src/lib/nx-plugin/src/generators/app/schema.d.ts +3 -0
  165. package/src/lib/nx-plugin/src/generators/app/schema.json +6 -0
  166. package/src/lib/nx-plugin/src/generators/app/versions/minimum-supported-versions.d.ts +4 -2
  167. package/src/lib/nx-plugin/src/generators/app/versions/minimum-supported-versions.js +9 -6
  168. package/src/lib/nx-plugin/src/generators/app/versions/minimum-supported-versions.js.map +1 -1
  169. package/src/lib/nx-plugin/src/generators/app/versions/nx-dependencies.d.ts +0 -3
  170. package/src/lib/nx-plugin/src/generators/app/versions/nx_17_X/versions.d.ts +1 -1
  171. package/src/lib/nx-plugin/src/generators/app/versions/nx_18_X/versions.d.ts +12 -12
  172. package/src/lib/nx-plugin/src/generators/app/versions/nx_18_X/versions.js +8 -27
  173. package/src/lib/nx-plugin/src/generators/app/versions/nx_18_X/versions.js.map +1 -1
  174. package/src/lib/nx-plugin/src/generators/app/versions/tailwind-dependencies.d.ts +1 -1
  175. package/src/lib/nx-plugin/src/generators/app/versions/tailwind-dependencies.js +6 -5
  176. package/src/lib/nx-plugin/src/generators/app/versions/tailwind-dependencies.js.map +1 -1
  177. package/src/lib/nx-plugin/src/generators/app/versions.d.ts +0 -18
  178. package/src/lib/nx-plugin/src/generators/init/compat.d.ts +9 -3
  179. package/src/lib/nx-plugin/src/generators/init/compat.js +15 -4
  180. package/src/lib/nx-plugin/src/generators/init/compat.js.map +1 -1
  181. package/src/lib/nx-plugin/src/generators/init/files/vite.config.ts__template__ +2 -6
  182. package/src/lib/nx-plugin/src/generators/init/generator.d.ts +3 -3
  183. package/src/lib/nx-plugin/src/generators/init/generator.js +35 -34
  184. package/src/lib/nx-plugin/src/generators/init/generator.js.map +1 -1
  185. package/src/lib/nx-plugin/src/generators/init/lib/add-analog-dependencies.d.ts +1 -1
  186. package/src/lib/nx-plugin/src/generators/init/lib/add-analog-dependencies.js +8 -7
  187. package/src/lib/nx-plugin/src/generators/init/lib/add-analog-dependencies.js.map +1 -1
  188. package/src/lib/nx-plugin/src/generators/init/lib/update-app-tsconfig.d.ts +2 -2
  189. package/src/lib/nx-plugin/src/generators/init/lib/update-app-tsconfig.js +6 -5
  190. package/src/lib/nx-plugin/src/generators/init/lib/update-app-tsconfig.js.map +1 -1
  191. package/src/lib/nx-plugin/src/generators/init/lib/update-build-target.d.ts +2 -2
  192. package/src/lib/nx-plugin/src/generators/init/lib/update-build-target.js +15 -14
  193. package/src/lib/nx-plugin/src/generators/init/lib/update-build-target.js.map +1 -1
  194. package/src/lib/nx-plugin/src/generators/init/lib/update-git-ignore.d.ts +1 -1
  195. package/src/lib/nx-plugin/src/generators/init/lib/update-git-ignore.js +1 -1
  196. package/src/lib/nx-plugin/src/generators/init/lib/update-git-ignore.js.map +1 -1
  197. package/src/lib/nx-plugin/src/generators/init/lib/update-index-html.d.ts +2 -2
  198. package/src/lib/nx-plugin/src/generators/init/lib/update-index-html.js +7 -6
  199. package/src/lib/nx-plugin/src/generators/init/lib/update-index-html.js.map +1 -1
  200. package/src/lib/nx-plugin/src/generators/init/lib/update-main.d.ts +2 -2
  201. package/src/lib/nx-plugin/src/generators/init/lib/update-main.js +5 -4
  202. package/src/lib/nx-plugin/src/generators/init/lib/update-main.js.map +1 -1
  203. package/src/lib/nx-plugin/src/generators/init/lib/update-package-json.d.ts +2 -2
  204. package/src/lib/nx-plugin/src/generators/init/lib/update-package-json.js +9 -8
  205. package/src/lib/nx-plugin/src/generators/init/lib/update-package-json.js.map +1 -1
  206. package/src/lib/nx-plugin/src/generators/init/lib/update-serve-target.d.ts +2 -2
  207. package/src/lib/nx-plugin/src/generators/init/lib/update-serve-target.js +6 -5
  208. package/src/lib/nx-plugin/src/generators/init/lib/update-serve-target.js.map +1 -1
  209. package/src/lib/nx-plugin/src/generators/init/lib/update-test-target.d.ts +2 -2
  210. package/src/lib/nx-plugin/src/generators/init/lib/update-test-target.js +6 -5
  211. package/src/lib/nx-plugin/src/generators/init/lib/update-test-target.js.map +1 -1
  212. package/src/lib/nx-plugin/src/generators/init/lib/update-test-tsconfig.d.ts +2 -2
  213. package/src/lib/nx-plugin/src/generators/init/lib/update-test-tsconfig.js +6 -5
  214. package/src/lib/nx-plugin/src/generators/init/lib/update-test-tsconfig.js.map +1 -1
  215. package/src/lib/nx-plugin/src/generators/init/test-files/src/test-setup.ts__template__ +1 -0
  216. package/src/lib/nx-plugin/src/generators/page/__snapshots__/generator.spec.ts.snap +0 -7
  217. package/src/lib/nx-plugin/src/generators/page/compat.d.ts +9 -0
  218. package/src/lib/nx-plugin/src/generators/page/compat.js +19 -0
  219. package/src/lib/nx-plugin/src/generators/page/compat.js.map +1 -0
  220. package/src/lib/nx-plugin/src/generators/page/files/__fileName__.page.ts__template__ +0 -1
  221. package/src/lib/nx-plugin/src/generators/page/generator.d.ts +3 -4
  222. package/src/lib/nx-plugin/src/generators/page/generator.js +14 -13
  223. package/src/lib/nx-plugin/src/generators/page/generator.js.map +1 -1
  224. package/src/lib/nx-plugin/src/generators/preset/__snapshots__/generator.spec.ts.snap +9 -7
  225. package/src/lib/nx-plugin/src/generators/preset/generator.d.ts +3 -3
  226. package/src/lib/nx-plugin/src/generators/preset/generator.js +24 -7
  227. package/src/lib/nx-plugin/src/generators/preset/generator.js.map +1 -1
  228. package/src/lib/nx-plugin/src/generators/preset/schema.d.ts +1 -0
  229. package/src/lib/nx-plugin/src/generators/preset/schema.json +6 -0
  230. package/src/lib/nx-plugin/src/generators/setup-vitest/compat.d.ts +9 -3
  231. package/src/lib/nx-plugin/src/generators/setup-vitest/compat.js +15 -4
  232. package/src/lib/nx-plugin/src/generators/setup-vitest/compat.js.map +1 -1
  233. package/src/lib/nx-plugin/src/generators/setup-vitest/files/src/test-setup.ts__template__ +1 -0
  234. package/src/lib/nx-plugin/src/generators/setup-vitest/files/vite.config.mts__template__ +0 -6
  235. package/src/lib/nx-plugin/src/generators/setup-vitest/generator.d.ts +3 -3
  236. package/src/lib/nx-plugin/src/generators/setup-vitest/generator.js +19 -21
  237. package/src/lib/nx-plugin/src/generators/setup-vitest/generator.js.map +1 -1
  238. package/src/lib/nx-plugin/src/generators/setup-vitest/lib/add-analog-dependencies.d.ts +1 -1
  239. package/src/lib/nx-plugin/src/generators/setup-vitest/lib/add-analog-dependencies.js +5 -4
  240. package/src/lib/nx-plugin/src/generators/setup-vitest/lib/add-analog-dependencies.js.map +1 -1
  241. package/src/lib/nx-plugin/src/generators/setup-vitest/lib/update-test-target.d.ts +2 -2
  242. package/src/lib/nx-plugin/src/generators/setup-vitest/lib/update-test-target.js +6 -5
  243. package/src/lib/nx-plugin/src/generators/setup-vitest/lib/update-test-target.js.map +1 -1
  244. package/src/lib/nx-plugin/src/generators/setup-vitest/lib/update-tsconfig.d.ts +2 -2
  245. package/src/lib/nx-plugin/src/generators/setup-vitest/lib/update-tsconfig.js +6 -5
  246. package/src/lib/nx-plugin/src/generators/setup-vitest/lib/update-tsconfig.js.map +1 -1
  247. package/src/lib/nx-plugin/src/utils/version-utils.d.ts +1 -1
  248. package/src/lib/nx-plugin/src/utils/version-utils.js +9 -8
  249. package/src/lib/nx-plugin/src/utils/version-utils.js.map +1 -1
  250. package/src/lib/nx-plugin/src/utils/versions/dependencies.js +33 -32
  251. package/src/lib/nx-plugin/src/utils/versions/dependencies.js.map +1 -1
  252. package/src/lib/nx-plugin/src/utils/versions/dev-dependencies.js +40 -39
  253. package/src/lib/nx-plugin/src/utils/versions/dev-dependencies.js.map +1 -1
  254. package/src/lib/nx-plugin/src/utils/versions/ng_17_X/versions.d.ts +1 -1
  255. package/src/lib/nx-plugin/src/utils/versions/ng_17_X/versions.js +16 -2
  256. package/src/lib/nx-plugin/src/utils/versions/ng_17_X/versions.js.map +1 -1
  257. package/src/lib/nx-plugin/src/utils/versions/ng_18_X/versions.d.ts +1 -1
  258. package/src/lib/nx-plugin/src/utils/versions/ng_18_X/versions.js +16 -2
  259. package/src/lib/nx-plugin/src/utils/versions/ng_18_X/versions.js.map +1 -1
  260. package/src/lib/nx-plugin/src/utils/versions/ng_19_X/versions.d.ts +9 -8
  261. package/src/lib/nx-plugin/src/utils/versions/ng_19_X/versions.js +27 -10
  262. package/src/lib/nx-plugin/src/utils/versions/ng_19_X/versions.js.map +1 -1
  263. package/src/lib/options.d.ts +117 -84
  264. package/src/lib/platform-plugin.d.ts +2 -2
  265. package/src/lib/platform-plugin.js +25 -34
  266. package/src/lib/platform-plugin.js.map +1 -1
  267. package/src/lib/route-file-discovery.d.ts +25 -0
  268. package/src/lib/route-file-discovery.js +125 -0
  269. package/src/lib/route-file-discovery.js.map +1 -0
  270. package/src/lib/route-idiom-diagnostics.d.ts +13 -0
  271. package/src/lib/route-idiom-diagnostics.js +160 -0
  272. package/src/lib/route-idiom-diagnostics.js.map +1 -0
  273. package/src/lib/route-manifest.d.ts +118 -0
  274. package/src/lib/route-manifest.js +300 -0
  275. package/src/lib/route-manifest.js.map +1 -0
  276. package/src/lib/router-plugin.d.ts +19 -19
  277. package/src/lib/router-plugin.js +127 -33
  278. package/src/lib/router-plugin.js.map +1 -1
  279. package/src/lib/server-fn-client-transform.d.ts +26 -0
  280. package/src/lib/server-fn-client-transform.js +97 -0
  281. package/src/lib/server-fn-client-transform.js.map +1 -0
  282. package/src/lib/server-fn-id.d.ts +25 -0
  283. package/src/lib/server-fn-id.js +37 -0
  284. package/src/lib/server-fn-id.js.map +1 -0
  285. package/src/lib/ssr/defer-streaming-plugin.d.ts +65 -0
  286. package/src/lib/ssr/inject-html-plugin.d.ts +1 -1
  287. package/src/lib/ssr/inject-html-plugin.js.map +1 -1
  288. package/src/lib/ssr/ssr-build-plugin.d.ts +24 -16
  289. package/src/lib/ssr/ssr-build-plugin.js +2 -18
  290. package/src/lib/ssr/ssr-build-plugin.js.map +1 -1
  291. package/src/lib/typed-routes-plugin.d.ts +13 -0
  292. package/src/lib/typed-routes-plugin.js +119 -0
  293. package/src/lib/typed-routes-plugin.js.map +1 -0
  294. package/src/lib/utils/debug-harness.d.ts +23 -0
  295. package/src/lib/utils/debug-harness.js +88 -0
  296. package/src/lib/utils/debug-harness.js.map +1 -0
  297. package/src/lib/utils/debug-log-file.d.ts +5 -0
  298. package/src/lib/utils/debug-log-file.js +56 -0
  299. package/src/lib/utils/debug-log-file.js.map +1 -0
  300. package/src/lib/utils/debug.d.ts +20 -0
  301. package/src/lib/utils/debug.js +21 -0
  302. package/src/lib/utils/debug.js.map +1 -0
  303. package/src/lib/utils/rolldown.d.ts +2 -2
  304. package/src/lib/utils/rolldown.js.map +1 -1
  305. package/src/server-mode-plugin.d.ts +11 -5
  306. package/src/server-mode-plugin.js +16 -6
  307. package/src/server-mode-plugin.js.map +1 -1
  308. package/src/lib/nx-plugin/src/executors/vite/compat.d.ts +0 -3
  309. package/src/lib/nx-plugin/src/executors/vite/compat.js +0 -8
  310. package/src/lib/nx-plugin/src/executors/vite/compat.js.map +0 -1
  311. package/src/lib/nx-plugin/src/executors/vite/schema.d.ts +0 -2
  312. package/src/lib/nx-plugin/src/executors/vite/schema.json +0 -147
  313. package/src/lib/nx-plugin/src/executors/vite/vite.impl.d.ts +0 -2
  314. package/src/lib/nx-plugin/src/executors/vite/vite.impl.js +0 -7
  315. package/src/lib/nx-plugin/src/executors/vite/vite.impl.js.map +0 -1
  316. package/src/lib/nx-plugin/src/generators/app/files/tailwind/v4/.postcssrc.json +0 -5
  317. package/src/lib/nx-plugin/src/generators/app/files/tailwind/v4/tailwind.config.ts__template__ +0 -14
  318. package/src/lib/nx-plugin/src/generators/app/files/template-angular-v15/index.html__template__ +0 -15
  319. package/src/lib/nx-plugin/src/generators/app/files/template-angular-v15/src/app/app.component.spec.ts__template__ +0 -17
  320. package/src/lib/nx-plugin/src/generators/app/files/template-angular-v15/src/app/app.component.ts__template__ +0 -10
  321. package/src/lib/nx-plugin/src/generators/app/files/template-angular-v15/src/favicon.ico__template__ +0 -0
  322. package/src/lib/nx-plugin/src/generators/app/files/template-angular-v15/src/main.providers.ts__template__ +0 -5
  323. package/src/lib/nx-plugin/src/generators/app/files/template-angular-v15/src/main.server.ts__template__ +0 -23
  324. package/src/lib/nx-plugin/src/generators/app/files/template-angular-v15/src/main.ts__template__ +0 -11
  325. package/src/lib/nx-plugin/src/generators/app/files/template-angular-v15/src/public/assets/.gitkeep__template__ +0 -0
  326. package/src/lib/nx-plugin/src/generators/app/files/template-angular-v15/src/public/assets/analog.svg__template__ +0 -1
  327. package/src/lib/nx-plugin/src/generators/app/files/template-angular-v15/src/public/assets/vite.svg__template__ +0 -1
  328. package/src/lib/nx-plugin/src/generators/app/files/template-angular-v15/src/server/routes/v1/hello.ts__template__ +0 -3
  329. package/src/lib/nx-plugin/src/generators/app/files/template-angular-v15/src/styles.css__template__ +0 -4
  330. package/src/lib/nx-plugin/src/generators/app/files/template-angular-v15/src/test-setup.ts__template__ +0 -12
  331. package/src/lib/nx-plugin/src/generators/app/files/template-angular-v15/src/vite-env.d.ts__template__ +0 -1
  332. package/src/lib/nx-plugin/src/generators/app/files/template-angular-v15/tsconfig.app.json__template__ +0 -16
  333. package/src/lib/nx-plugin/src/generators/app/files/template-angular-v15/tsconfig.editor.json__template__ +0 -7
  334. package/src/lib/nx-plugin/src/generators/app/files/template-angular-v15/tsconfig.json__template__ +0 -32
  335. package/src/lib/nx-plugin/src/generators/app/files/template-angular-v15/tsconfig.spec.json__template__ +0 -14
  336. package/src/lib/nx-plugin/src/generators/app/files/template-angular-v15/vite.config.ts__template__ +0 -61
  337. package/src/lib/nx-plugin/src/generators/app/lib/add-analog-dependencies.js +0 -14
  338. package/src/lib/nx-plugin/src/generators/app/lib/add-analog-dependencies.js.map +0 -1
  339. package/src/lib/nx-plugin/src/generators/app/lib/add-eslint.js +0 -15
  340. package/src/lib/nx-plugin/src/generators/app/lib/add-eslint.js.map +0 -1
  341. package/src/lib/nx-plugin/src/generators/app/lib/add-vite-plugin.js +0 -11
  342. package/src/lib/nx-plugin/src/generators/app/lib/add-vite-plugin.js.map +0 -1
  343. package/src/lib/nx-plugin/src/generators/app/lib/initialize-analog-workspace.js +0 -64
  344. package/src/lib/nx-plugin/src/generators/app/lib/initialize-analog-workspace.js.map +0 -1
  345. package/src/lib/nx-plugin/src/generators/app/versions/dependencies.js +0 -37
  346. package/src/lib/nx-plugin/src/generators/app/versions/dependencies.js.map +0 -1
  347. package/src/lib/nx-plugin/src/generators/app/versions/dev-dependencies.js +0 -45
  348. package/src/lib/nx-plugin/src/generators/app/versions/dev-dependencies.js.map +0 -1
  349. package/src/lib/nx-plugin/src/generators/app/versions/nx-dependencies.js +0 -27
  350. package/src/lib/nx-plugin/src/generators/app/versions/nx-dependencies.js.map +0 -1
  351. package/src/lib/nx-plugin/src/generators/app/versions/nx_17_X/versions.js +0 -30
  352. package/src/lib/nx-plugin/src/generators/app/versions/nx_17_X/versions.js.map +0 -1
  353. package/src/lib/nx-plugin/src/generators/app/versions.js +0 -29
  354. package/src/lib/nx-plugin/src/generators/app/versions.js.map +0 -1
  355. package/src/lib/nx-plugin/src/index.d.ts +0 -0
@@ -1 +1 @@
1
- {"version":3,"file":"router-plugin.js","names":[],"sources":["../../../../../packages/platform/src/lib/router-plugin.ts"],"sourcesContent":["import { normalizePath, Plugin, UserConfig, ViteDevServer } from 'vite';\nimport { globSync } from 'tinyglobby';\nimport { resolve } from 'node:path';\n\nimport { Options } from './options.js';\n\n/**\n * Router plugin that handles route file discovery and hot module replacement.\n *\n * This plugin provides three main functionalities:\n * 1. Route invalidation when files are added/deleted (HMR workaround)\n * 2. Dynamic route file discovery and import generation\n * 3. Content route file discovery for markdown and Analog content\n *\n * @param options Configuration options for the router plugin\n * @returns Array of Vite plugins for route handling\n *\n * IMPORTANT: This plugin uses tinyglobby for file discovery.\n * Key behavior with { dot: true, absolute: true }:\n * - Returns absolute paths for ALL discovered files\n * - Path normalization is required to match expected output format\n * - Files within project root must use relative paths in object keys\n * - Files outside project root keep absolute paths in object keys\n */\nexport function routerPlugin(options?: Options): Plugin[] {\n const workspaceRoot = normalizePath(options?.workspaceRoot ?? process.cwd());\n let config: UserConfig;\n let root: string;\n const isRouteLikeFile = (path: string) =>\n path.includes(`routes`) ||\n path.includes(`pages`) ||\n path.includes('content');\n const invalidateFileModules = (server: ViteDevServer, path: string) => {\n const normalizedPath = normalizePath(path);\n // A newly added page can be discovered before its final contents settle.\n // Invalidate the page module itself so later edits don't keep serving the\n // first incomplete transform from Vite's module graph.\n const fileModules =\n server.moduleGraph.getModulesByFile?.(normalizedPath) ??\n server.moduleGraph.fileToModulesMap.get(normalizedPath);\n\n fileModules?.forEach((mod) => {\n server.moduleGraph.invalidateModule(mod);\n\n mod.importers.forEach((imp) => {\n server.moduleGraph.invalidateModule(imp);\n });\n });\n };\n\n return [\n {\n name: 'analogjs-router-invalidate-routes',\n configureServer(server) {\n /**\n * Invalidates route modules when files are added or deleted.\n * This is a workaround for Vite's HMR limitations with dynamic imports.\n *\n * @param path The file path that was added or deleted\n */\n function invalidateRoutes(path: string) {\n if (!isRouteLikeFile(path)) {\n return;\n }\n\n invalidateFileModules(server, path);\n\n server.moduleGraph.fileToModulesMap.forEach((mods) => {\n mods.forEach((mod) => {\n if (mod.id?.includes('analogjs') && mod.id?.includes('fesm')) {\n server.moduleGraph.invalidateModule(mod);\n\n mod.importers.forEach((imp) => {\n server.moduleGraph.invalidateModule(imp);\n });\n }\n });\n });\n\n server.ws.send({\n type: 'full-reload',\n });\n }\n\n server.watcher.on('add', invalidateRoutes);\n server.watcher.on('change', invalidateRoutes);\n server.watcher.on('unlink', invalidateRoutes);\n },\n },\n {\n name: 'analog-glob-routes',\n // enforce: 'post' ensures this transform runs AFTER the Angular compiler\n // plugin, which replaces module content with its own compiled output.\n // Without this, the Angular plugin would overwrite the route replacements.\n enforce: 'post',\n config(_config) {\n config = _config;\n root = normalizePath(resolve(workspaceRoot, config.root || '.') || '.');\n },\n /**\n * Transforms code to replace ANALOG_ROUTE_FILES and ANALOG_CONTENT_ROUTE_FILES\n * placeholders with actual dynamic imports of discovered route and content files.\n *\n * @param code The source code to transform\n * @returns Transformed code with dynamic imports or undefined if no transformation needed\n */\n // Vite 8 / Rolldown filtered transform: the `filter.code` substring\n // pre-filter lets the bundler skip modules that don't contain the\n // marker. 'ANALOG_ROUTE_FILES' also matches 'ANALOG_CONTENT_ROUTE_FILES'\n // (substring), so a single filter covers both placeholders.\n transform: {\n filter: {\n code: 'ANALOG_ROUTE_FILES',\n },\n handler(code) {\n if (\n code.includes('ANALOG_ROUTE_FILES') ||\n code.includes('ANALOG_CONTENT_ROUTE_FILES')\n ) {\n // Discover route files using tinyglobby\n // NOTE: { absolute: true } returns absolute paths for ALL files\n const routeFiles: string[] = globSync(\n [\n `${root}/app/routes/**/*.ts`,\n `${root}/src/app/routes/**/*.ts`,\n `${root}/src/app/pages/**/*.page.ts`,\n ...(options?.additionalPagesDirs || []).map(\n (glob) => `${workspaceRoot}${glob}/**/*.page.ts`,\n ),\n ],\n { dot: true, absolute: true },\n );\n\n // Discover content files using tinyglobby\n const contentRouteFiles: string[] = globSync(\n [\n `${root}/src/app/routes/**/*.md`,\n `${root}/src/app/pages/**/*.md`,\n `${root}/src/content/**/*.md`,\n ...(options?.additionalContentDirs || []).map(\n (glob) => `${workspaceRoot}${glob}/**/*.md`,\n ),\n ],\n { dot: true, absolute: true },\n );\n\n let result = code.replace(\n 'ANALOG_ROUTE_FILES = {};',\n `\n ANALOG_ROUTE_FILES = {${routeFiles.map((module) => {\n // CRITICAL: tinyglobby returns absolute paths, but we need relative paths for project files\n // to match expected output format. Library files keep absolute paths.\n const key = module.startsWith(root)\n ? module.replace(root, '')\n : module;\n return `\"${key}\": () => import('${module}')`;\n })}};\n `,\n );\n\n result = result.replace(\n 'ANALOG_CONTENT_ROUTE_FILES = {};',\n `\n ANALOG_CONTENT_ROUTE_FILES = {${contentRouteFiles.map((module) => {\n // Same path normalization as route files\n const key = module.startsWith(root)\n ? module.replace(root, '')\n : module;\n return `\"${key}\": () => import('${module}?analog-content-file=true').then(m => m.default)`;\n })}};\n `,\n );\n\n return {\n code: result,\n map: { mappings: '' },\n };\n }\n\n return;\n },\n },\n },\n {\n name: 'analog-glob-endpoints',\n // enforce: 'post' ensures this transform runs AFTER the Angular compiler\n // plugin, which replaces module content with its own compiled output.\n // Without this, the Angular plugin would overwrite the endpoint replacements.\n enforce: 'post',\n /**\n * Transforms code to replace ANALOG_PAGE_ENDPOINTS placeholder\n * with actual dynamic imports of discovered server endpoint files.\n *\n * @param code The source code to transform\n * @returns Transformed code with dynamic imports or undefined if no transformation needed\n */\n transform: {\n filter: {\n code: 'ANALOG_PAGE_ENDPOINTS',\n },\n handler(code) {\n if (code.includes('ANALOG_PAGE_ENDPOINTS')) {\n // Discover server endpoint files using tinyglobby\n const endpointFiles: string[] = globSync(\n [\n `${root}/src/app/pages/**/*.server.ts`,\n ...(options?.additionalPagesDirs || []).map(\n (glob) => `${workspaceRoot}${glob}/**/*.server.ts`,\n ),\n ],\n { dot: true, absolute: true },\n );\n\n const result = code.replace(\n 'ANALOG_PAGE_ENDPOINTS = {};',\n `\n ANALOG_PAGE_ENDPOINTS = {${endpointFiles.map((module) => {\n // Same path normalization for consistency\n const key = module.startsWith(root)\n ? module.replace(root, '')\n : module;\n return `\"${key}\": () => import('${module}')`;\n })}};\n `,\n );\n\n return {\n code: result,\n map: { mappings: '' },\n };\n }\n\n return;\n },\n },\n },\n ];\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAwBA,SAAgB,aAAa,SAA6B;CACxD,MAAM,gBAAgB,cAAc,SAAS,iBAAiB,QAAQ,KAAK,CAAC;CAC5E,IAAI;CACJ,IAAI;CACJ,MAAM,mBAAmB,SACvB,KAAK,SAAS,SAAS,IACvB,KAAK,SAAS,QAAQ,IACtB,KAAK,SAAS,UAAU;CAC1B,MAAM,yBAAyB,QAAuB,SAAiB;EACrE,MAAM,iBAAiB,cAAc,KAAK;AAQ1C,GAHE,OAAO,YAAY,mBAAmB,eAAe,IACrD,OAAO,YAAY,iBAAiB,IAAI,eAAe,GAE5C,SAAS,QAAQ;AAC5B,UAAO,YAAY,iBAAiB,IAAI;AAExC,OAAI,UAAU,SAAS,QAAQ;AAC7B,WAAO,YAAY,iBAAiB,IAAI;KACxC;IACF;;AAGJ,QAAO;EACL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QAChB,4BACA;sCACwB,WAAW,KAAK,WAAW;AAMjD,cAAO,IAHK,OAAO,WAAW,KAAK,GAC/B,OAAO,QAAQ,MAAM,GAAG,GACxB,OACW,mBAAmB,OAAO;QACzC,CAAC;cAEJ;AAED,eAAS,OAAO,QACd,oCACA;4CAC8B,kBAAkB,KAAK,WAAW;AAKhE,cAAO,IAHK,OAAO,WAAW,KAAK,GAC/B,OAAO,QAAQ,MAAM,GAAG,GACxB,OACW,mBAAmB,OAAO;QACzC,CAAC;cAEF;AAED,aAAO;OACL,MAAM;OACN,KAAK,EAAE,UAAU,IAAI;OACtB;;;IAKN;GACF;EACD;GACE,MAAM;GAIN,SAAS;GAQT,WAAW;IACT,QAAQ,EACN,MAAM,yBACP;IACD,QAAQ,MAAM;AACZ,SAAI,KAAK,SAAS,wBAAwB,EAAE;MAE1C,MAAM,gBAA0B,SAC9B,CACE,GAAG,KAAK,gCACR,IAAI,SAAS,uBAAuB,EAAE,EAAE,KACrC,SAAS,GAAG,gBAAgB,KAAK,iBACnC,CACF,EACD;OAAE,KAAK;OAAM,UAAU;OAAM,CAC9B;AAeD,aAAO;OACL,MAda,KAAK,QAClB,+BACA;yCAC2B,cAAc,KAAK,WAAW;AAKvD,eAAO,IAHK,OAAO,WAAW,KAAK,GAC/B,OAAO,QAAQ,MAAM,GAAG,GACxB,OACW,mBAAmB,OAAO;SACzC,CAAC;cAEJ;OAIC,KAAK,EAAE,UAAU,IAAI;OACtB;;;IAKN;GACF;EACF"}
1
+ {"version":3,"file":"router-plugin.js","names":[],"sources":["../../../src/lib/router-plugin.ts"],"sourcesContent":["import { normalizePath, Plugin, UserConfig, ViteDevServer } from 'vite';\nimport { globSync } from 'tinyglobby';\nimport { readFileSync } from 'node:fs';\nimport { isAbsolute, relative, resolve } from 'node:path';\n\nimport { Options } from './options.js';\nimport {\n analyzeAnalogRouteFile,\n formatAnalogRouteIdiomDiagnostic,\n} from './route-idiom-diagnostics.js';\n\n/**\n * Router plugin that handles route file discovery and hot module replacement.\n *\n * This plugin provides three main functionalities:\n * 1. Route invalidation when files are added/deleted (HMR workaround)\n * 2. Dynamic route file discovery and import generation\n * 3. Content route file discovery for markdown and Analog content\n *\n * @param options Configuration options for the router plugin\n * @returns Array of Vite plugins for route handling\n *\n * IMPORTANT: This plugin uses tinyglobby for file discovery.\n * Key behavior with { dot: true, absolute: true }:\n * - Returns absolute paths for ALL discovered files\n * - Path normalization is required to match expected output format\n * - Files within project root must use relative paths in object keys\n * - Files outside project root keep absolute paths in object keys\n */\nexport function routerPlugin(options?: Options): Plugin[] {\n const workspaceRoot = normalizePath(\n options?.workspaceRoot ?? process.env['NX_WORKSPACE_ROOT'] ?? process.cwd(),\n );\n let config: UserConfig;\n let root: string;\n // Option dirs are workspace-relative, often written with a leading `/`.\n // Normalize them once into absolute workspace paths so watcher events,\n // glob patterns, and key generation all compare against the same shape.\n const normalizeWatchedDir = (dir: string) => {\n const normalizedDir = normalizePath(\n dir.startsWith(`${workspaceRoot}/`) || dir === workspaceRoot\n ? dir\n : dir.startsWith('/')\n ? `${workspaceRoot}${dir}`\n : resolve(workspaceRoot, dir),\n );\n return normalizedDir.endsWith('/')\n ? normalizedDir.slice(0, -1)\n : normalizedDir;\n };\n // Computed eagerly — these depend only on `options` and `workspaceRoot`,\n // both of which are fixed at construction time.\n const additionalPagesDirs = (options?.additionalPagesDirs || []).map((dir) =>\n normalizeWatchedDir(dir),\n );\n const additionalContentDirs = (options?.additionalContentDirs || []).map(\n (dir) => normalizeWatchedDir(dir),\n );\n // Returns every directory that can contain route-like files. The root-\n // relative entries are only available after the Vite `config` hook sets\n // `root`. The short-form fallbacks (`/app/routes`, etc.) let watcher\n // events match before `config` runs — they cover the common convention\n // where paths start with these prefixes.\n const getRouteLikeDirs = () => [\n ...(root\n ? [\n normalizeWatchedDir(`${root}/app/routes`),\n normalizeWatchedDir(`${root}/src/app/routes`),\n normalizeWatchedDir(`${root}/src/app/pages`),\n normalizeWatchedDir(`${root}/src/content`),\n ]\n : []),\n '/app/routes',\n '/src/app/routes',\n '/src/app/pages',\n '/src/content',\n ...additionalPagesDirs,\n ...additionalContentDirs,\n ];\n // These lists are used repeatedly by transform hooks during serve. Keeping\n // them warm avoids a full glob on every route/content invalidation.\n let routeFilesCache: string[] | undefined;\n let pageRouteFilesCache: string[] | undefined;\n let contentRouteFilesCache: string[] | undefined;\n let endpointFilesCache: string[] | undefined;\n const routeDiagnosticCache = new Map<string, string>();\n const isRouteLikeFile = (path: string) => {\n // Watcher paths from chokidar are already absolute — `normalizePath`\n // (forward-slash only) is sufficient; `resolve()` would be a no-op.\n const normalizedPath = normalizePath(path);\n\n return getRouteLikeDirs().some(\n (dir) => normalizedPath === dir || normalizedPath.startsWith(`${dir}/`),\n );\n };\n const discoverRouteFiles = () => {\n routeFilesCache ??= globSync(\n [\n `${root}/app/routes/**/*.ts`,\n `${root}/src/app/routes/**/*.ts`,\n `${root}/src/app/pages/**/*.page.ts`,\n ...additionalPagesDirs.map((dir) => `${dir}/**/*.page.ts`),\n ],\n { dot: true, absolute: true },\n );\n\n return routeFilesCache;\n };\n const discoverContentRouteFiles = () => {\n contentRouteFilesCache ??= globSync(\n [\n `${root}/src/app/routes/**/*.md`,\n `${root}/src/app/pages/**/*.md`,\n `${root}/src/content/**/*.md`,\n ...additionalContentDirs.map((dir) => `${dir}/**/*.md`),\n ],\n { dot: true, absolute: true },\n );\n\n return contentRouteFilesCache;\n };\n const discoverEndpointFiles = () => {\n endpointFilesCache ??= globSync(\n [\n `${root}/src/app/pages/**/*.server.ts`,\n ...additionalPagesDirs.map((dir) => `${dir}/**/*.server.ts`),\n ],\n { dot: true, absolute: true },\n );\n\n return endpointFilesCache;\n };\n const discoverPageRouteFiles = () => {\n pageRouteFilesCache ??= discoverRouteFiles().filter((file) =>\n file.endsWith('.page.ts'),\n );\n\n return pageRouteFilesCache;\n };\n const invalidateDiscoveryCaches = () => {\n routeFilesCache = undefined;\n pageRouteFilesCache = undefined;\n contentRouteFilesCache = undefined;\n endpointFilesCache = undefined;\n };\n const reportRouteDiagnostics = (path: string) => {\n if (!path.endsWith('.page.ts')) {\n return;\n }\n\n try {\n const code = readFileSync(path, 'utf-8');\n const routeFiles = discoverPageRouteFiles();\n const diagnostics = analyzeAnalogRouteFile({\n filename: path,\n code,\n routeFiles,\n });\n\n const rendered = diagnostics.map((diagnostic) =>\n formatAnalogRouteIdiomDiagnostic(diagnostic, path, workspaceRoot),\n );\n const fingerprint = rendered.join('\\n\\n');\n\n if (!fingerprint) {\n routeDiagnosticCache.delete(path);\n return;\n }\n\n if (routeDiagnosticCache.get(path) === fingerprint) {\n return;\n }\n\n routeDiagnosticCache.set(path, fingerprint);\n rendered.forEach((message) => console.warn(message));\n } catch {\n routeDiagnosticCache.delete(path);\n }\n };\n const getModuleKey = (module: string) => {\n // Before config sets `root`, fall back to workspace-relative keys.\n if (!root) {\n return `/${normalizePath(relative(workspaceRoot, module))}`;\n }\n\n const relToRoot = normalizePath(relative(root, module));\n // Use true path containment instead of a raw prefix check so siblings like\n // `/apps/my-app-tools/...` are not mistaken for files inside `/apps/my-app`.\n const isInRoot = !relToRoot.startsWith('..') && !isAbsolute(relToRoot);\n\n if (isInRoot) {\n return `/${relToRoot}`;\n }\n\n return `/${normalizePath(relative(workspaceRoot, module))}`;\n };\n const invalidateFileModules = (server: ViteDevServer, path: string) => {\n const normalizedPath = normalizePath(path);\n // A newly added page can be discovered before its final contents settle.\n // Invalidate the page module itself so later edits don't keep serving the\n // first incomplete transform from Vite's module graph.\n const fileModules =\n server.moduleGraph.getModulesByFile?.(normalizedPath) ??\n server.moduleGraph.fileToModulesMap.get(normalizedPath);\n\n fileModules?.forEach((mod) => {\n server.moduleGraph.invalidateModule(mod);\n\n mod.importers.forEach((imp) => {\n server.moduleGraph.invalidateModule(imp);\n });\n });\n };\n\n return [\n {\n name: 'analogjs-router-invalidate-routes',\n configureServer(server) {\n /**\n * Invalidates route modules when files are added or deleted.\n * This is a workaround for Vite's HMR limitations with dynamic imports.\n *\n * @param path The file path that was added or deleted\n */\n function invalidateRoutes(\n path: string,\n event: 'add' | 'change' | 'unlink',\n ) {\n if (!isRouteLikeFile(path)) {\n return;\n }\n\n // Add/remove changes the route graph shape, so the discovery caches\n // must be rebuilt. Plain edits can keep using the current file set.\n if (event !== 'change') {\n invalidateDiscoveryCaches();\n }\n\n if (event === 'change') {\n reportRouteDiagnostics(path);\n } else if (event === 'unlink') {\n routeDiagnosticCache.delete(path);\n discoverPageRouteFiles().forEach((file) =>\n reportRouteDiagnostics(file),\n );\n } else {\n discoverPageRouteFiles().forEach((file) =>\n reportRouteDiagnostics(file),\n );\n }\n\n invalidateFileModules(server, path);\n\n // For an in-place edit we only need module invalidation. Keeping the\n // app alive here lets Angular/Vite attempt the narrower HMR path.\n if (event === 'change') {\n return;\n }\n\n server.moduleGraph.fileToModulesMap.forEach((mods) => {\n mods.forEach((mod) => {\n if (mod.id?.includes('analogjs') && mod.id?.includes('fesm')) {\n server.moduleGraph.invalidateModule(mod);\n\n mod.importers.forEach((imp) => {\n server.moduleGraph.invalidateModule(imp);\n });\n }\n });\n });\n\n server.ws.send('analog:debug-full-reload', {\n plugin: 'platform:router-plugin',\n reason: 'route-graph-shape-changed',\n event,\n path,\n });\n server.ws.send({\n type: 'full-reload',\n });\n }\n\n server.watcher.on('add', (path) => invalidateRoutes(path, 'add'));\n server.watcher.on('change', (path) => invalidateRoutes(path, 'change'));\n server.watcher.on('unlink', (path) => invalidateRoutes(path, 'unlink'));\n\n // Vite's watcher only covers the app root by default.\n // additionalPagesDirs / additionalContentDirs live outside the\n // root (e.g. libs/shared/feature in a monorepo), so file\n // add/rename/delete events are never fired for them. Explicitly\n // add these directories to chokidar so route invalidation works.\n for (const dir of [...additionalPagesDirs, ...additionalContentDirs]) {\n server.watcher.add(dir);\n }\n\n discoverPageRouteFiles().forEach((file) =>\n reportRouteDiagnostics(file),\n );\n },\n },\n {\n name: 'analog-glob-routes',\n // enforce: 'post' ensures this transform runs AFTER the Angular compiler\n // plugin, which replaces module content with its own compiled output.\n // Without this, the Angular plugin would overwrite the route replacements.\n enforce: 'post',\n config(_config) {\n config = _config;\n root = normalizePath(resolve(workspaceRoot, config.root || '.') || '.');\n },\n /**\n * Transforms code to replace ANALOG_ROUTE_FILES and ANALOG_CONTENT_ROUTE_FILES\n * placeholders with actual dynamic imports of discovered route and content files.\n *\n * @param code The source code to transform\n * @returns Transformed code with dynamic imports or undefined if no transformation needed\n */\n // Vite 8 / Rolldown filtered transform: the `filter.code` substring\n // pre-filter lets the bundler skip modules that don't contain the\n // marker. '_ROUTE_FILES' is a common substring of both\n // 'ANALOG_ROUTE_FILES' and 'ANALOG_CONTENT_ROUTE_FILES'.\n //\n // IMPORTANT: Do NOT change this to 'ANALOG_ROUTE_FILES' — that is NOT\n // a substring of 'ANALOG_CONTENT_ROUTE_FILES' (they diverge at\n // position 7: 'ANALOG_C...' vs 'ANALOG_R...'). When tsconfig path\n // aliases resolve @analogjs/router and @analogjs/router/content to\n // separate source files, each variable lives in its own module and\n // the filter must match both independently.\n transform: {\n filter: {\n code: '_ROUTE_FILES',\n },\n handler(code) {\n if (\n code.includes('ANALOG_ROUTE_FILES') ||\n code.includes('ANALOG_CONTENT_ROUTE_FILES')\n ) {\n // Discover route files using tinyglobby\n // NOTE: { absolute: true } returns absolute paths for ALL files\n const routeFiles = discoverRouteFiles();\n\n // Discover content files using tinyglobby\n const contentRouteFiles = discoverContentRouteFiles();\n\n let result = code.replace(\n 'ANALOG_ROUTE_FILES = {};',\n `\n ANALOG_ROUTE_FILES = {${routeFiles.map((module) => {\n // Keys are app-root-relative for in-app files,\n // workspace-relative for library files (additionalPagesDirs).\n // import() keeps absolute paths for Vite's module resolution.\n const key = getModuleKey(module);\n return `\"${key}\": () => import('${module}')`;\n })}};\n `,\n );\n\n result = result.replace(\n 'ANALOG_CONTENT_ROUTE_FILES = {};',\n `\n ANALOG_CONTENT_ROUTE_FILES = {${contentRouteFiles.map((module) => {\n const key = getModuleKey(module);\n return `\"${key}\": () => import('${module}?analog-content-file=true').then(m => m.default)`;\n })}};\n `,\n );\n\n result = result.replace(\n 'ANALOG_CONTENT_FILE_COUNT = 0',\n `ANALOG_CONTENT_FILE_COUNT = ${contentRouteFiles.length}`,\n );\n\n return {\n code: result,\n map: { mappings: '' },\n };\n }\n\n return;\n },\n },\n },\n {\n name: 'analog-glob-endpoints',\n // enforce: 'post' ensures this transform runs AFTER the Angular compiler\n // plugin, which replaces module content with its own compiled output.\n // Without this, the Angular plugin would overwrite the endpoint replacements.\n enforce: 'post',\n /**\n * Transforms code to replace ANALOG_PAGE_ENDPOINTS placeholder\n * with actual dynamic imports of discovered server endpoint files.\n *\n * @param code The source code to transform\n * @returns Transformed code with dynamic imports or undefined if no transformation needed\n */\n transform: {\n filter: {\n code: 'ANALOG_PAGE_ENDPOINTS',\n },\n handler(code) {\n if (code.includes('ANALOG_PAGE_ENDPOINTS')) {\n // Discover server endpoint files using tinyglobby\n const endpointFiles = discoverEndpointFiles();\n\n const result = code.replace(\n 'ANALOG_PAGE_ENDPOINTS = {};',\n `\n ANALOG_PAGE_ENDPOINTS = {${endpointFiles.map((module) => {\n const key = getModuleKey(module);\n return `\"${key}\": () => import('${module}')`;\n })}};\n `,\n );\n\n return {\n code: result,\n map: { mappings: '' },\n };\n }\n\n return;\n },\n },\n },\n ];\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AA6BA,SAAgB,aAAa,SAA6B;CACxD,MAAM,gBAAgB,cACpB,SAAS,iBAAiB,QAAQ,IAAI,wBAAwB,QAAQ,KAAK,CAC5E;CACD,IAAI;CACJ,IAAI;CAIJ,MAAM,uBAAuB,QAAgB;EAC3C,MAAM,gBAAgB,cACpB,IAAI,WAAW,GAAG,cAAc,GAAG,IAAI,QAAQ,gBAC3C,MACA,IAAI,WAAW,IAAI,GACjB,GAAG,gBAAgB,QACnB,QAAQ,eAAe,IAAI,CAClC;AACD,SAAO,cAAc,SAAS,IAAI,GAC9B,cAAc,MAAM,GAA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AO,QAAQ,IAAI,IAAI,IAAI;;GAoBzE,WAAW;IACT,QAAQ,EACN,MAAM,gBACP;IACD,QAAQ,MAAM;AACZ,SACE,KAAK,SAAS,qBAAqB,IACnC,KAAK,SAAS,6BAA6B,EAC3C;MAGA,MAAM,aAAa,oBAAoB;MAGvC,MAAM,oBAAoB,2BAA2B;MAErD,IAAI,SAAS,KAAK,QAChB,4BACA;sCACwB,WAAW,KAAK,WAAW;AAKjD,cAAO,IADK,aAAa,OAAO,CACjB,mBAAmB,OAAO;QACzC,CAAC;cAEJ;AAED,eAAS,OAAO,QACd,oCACA;4CAC8B,kBAAkB,KAAK,WAAW;AAEhE,cAAO,IADK,aAAa,OAAO,CACjB,mBAAmB,OAAO;QACzC,CAAC;cAEF;AAED,eAAS,OAAO,QACd,iCACA,+BAA+B,kBAAkB,SAClD;AAED,aAAO;OACL,MAAM;OACN,KAAK,EAAE,UAAU,IAAI;OACtB;;;IAKN;GACF;EACD;GACE,MAAM;GAIN,SAAS;GAQT,WAAW;IACT,QAAQ,EACN,MAAM,yBACP;IACD,QAAQ,MAAM;AACZ,SAAI,KAAK,SAAS,wBAAwB,EAAE;MAE1C,MAAM,gBAAgB,uBAAuB;AAY7C,aAAO;OACL,MAXa,KAAK,QAClB,+BACA;yCAC2B,cAAc,KAAK,WAAW;AAEvD,eAAO,IADK,aAAa,OAAO,CACjB,mBAAmB,OAAO;SACzC,CAAC;cAEJ;OAIC,KAAK,EAAE,UAAU,IAAI;OACtB;;;IAKN;GACF;EACF"}
@@ -0,0 +1,26 @@
1
+ /**
2
+ * Client-build scrub + proxy generation for server functions.
3
+ *
4
+ * On the client build a `*.server.ts` module must not carry server handler
5
+ * bodies (which `inject()` server services, read the request, hit the database).
6
+ * But the client still imports the named `serverFn` exports to dispatch them.
7
+ * This transform regenerates the module so each `export const NAME = serverFn(
8
+ * config, handler)` becomes a call to the client-safe `createServerFnRef`
9
+ * factory — keeping the `{ id, url, method }` metadata `injectServerFn` needs,
10
+ * dropping the handler and every server-only import. Because the regenerated
11
+ * module references nothing else, the server code tree-shakes away entirely.
12
+ *
13
+ * Returns the new module source, or `null` when the module defines no server
14
+ * function (the caller falls back to the page-endpoint scrub for those).
15
+ */
16
+ export interface ServerFnProxy {
17
+ name: string;
18
+ id: string;
19
+ method: "GET" | "POST";
20
+ }
21
+ export interface ScrubResult {
22
+ code: string;
23
+ proxies: ServerFnProxy[];
24
+ hadDefaultExport: boolean;
25
+ }
26
+ export declare function scrubServerFnModule(code: string, fileId?: string): ScrubResult | null;
@@ -0,0 +1,97 @@
1
+ import { deriveServerFnId } from "./server-fn-id.js";
2
+ import { parseSync } from "oxc-parser";
3
+ //#region packages/platform/src/lib/server-fn-client-transform.ts
4
+ var SERVER_FN_SOURCE = "@analogjs/router/server";
5
+ function scrubServerFnModule(code, fileId = "file.ts") {
6
+ if (!code.includes("serverFn")) return null;
7
+ const { program } = parseSync(fileId, code);
8
+ const body = program.body;
9
+ const serverFnLocalNames = collectServerFnLocalNames(body);
10
+ const hadDefaultExport = body.some((node) => node.type === "ExportDefaultDeclaration");
11
+ const proxies = [];
12
+ for (const node of body) {
13
+ if (node.type !== "ExportNamedDeclaration" || node.declaration?.type !== "VariableDeclaration") continue;
14
+ for (const declarator of node.declaration.declarations) {
15
+ if (declarator.id?.type !== "Identifier" || declarator.init?.type !== "CallExpression" || declarator.init.callee?.type !== "Identifier" || !serverFnLocalNames.has(declarator.init.callee.name)) continue;
16
+ proxies.push(toProxy(declarator.id.name, declarator.init.arguments ?? [], fileId));
17
+ }
18
+ }
19
+ const callCount = countServerFnCalls(program, serverFnLocalNames);
20
+ if (callCount > proxies.length) throw new Error(`[analog] ${fileId}: found ${callCount} serverFn call(s) but could only rewrite ${proxies.length} for the client build. Server functions must be declared as a directly exported const — \`export const name = serverFn(…)\` — so the handler can be stripped from the browser bundle.`);
21
+ if (proxies.length === 0) return null;
22
+ const lines = [
23
+ `import { createServerFnRef } from '@analogjs/router';`,
24
+ "",
25
+ ...proxies.map((p) => `export const ${p.name} = createServerFnRef({ id: ${JSON.stringify(p.id)}, method: ${JSON.stringify(p.method)} });`)
26
+ ];
27
+ if (hadDefaultExport) lines.push("", "export default undefined;");
28
+ return {
29
+ code: lines.join("\n") + "\n",
30
+ proxies,
31
+ hadDefaultExport
32
+ };
33
+ }
34
+ /** Local identifier(s) `serverFn` is imported under from `@analogjs/router/server`. */
35
+ function collectServerFnLocalNames(body) {
36
+ const names = /* @__PURE__ */ new Set();
37
+ for (const node of body) {
38
+ if (node.type !== "ImportDeclaration" || node.source?.value !== SERVER_FN_SOURCE) continue;
39
+ for (const spec of node.specifiers ?? []) if (spec.type === "ImportSpecifier" && spec.imported?.name === "serverFn") names.add(spec.local.name);
40
+ }
41
+ if (names.size === 0) names.add("serverFn");
42
+ return names;
43
+ }
44
+ function toProxy(name, args, fileId) {
45
+ const method = methodForCall(name, args, fileId);
46
+ return {
47
+ name,
48
+ id: deriveServerFnId(fileId, name),
49
+ method
50
+ };
51
+ }
52
+ /**
53
+ * Resolve the HTTP method from the call shape, matching the runtime overloads:
54
+ * `serverFn(handler)` ⇒ GET, `serverFn(schema, handler)` ⇒ POST,
55
+ * `serverFn(config, handler)` ⇒ config-driven.
56
+ */
57
+ function methodForCall(name, args, fileId) {
58
+ const arg0 = args[0];
59
+ if (isFunctionNode(arg0)) return "GET";
60
+ if (arg0?.type === "ObjectExpression") {
61
+ let method;
62
+ let hasInput = false;
63
+ for (const prop of arg0.properties ?? []) {
64
+ if (prop.type !== "Property") continue;
65
+ const key = prop.key?.type === "Identifier" ? prop.key.name : prop.key?.value;
66
+ if (key === "method" && isStringLiteral(prop.value)) method = prop.value.value;
67
+ else if (key === "input") hasInput = true;
68
+ }
69
+ if (method === "GET" && hasInput) throw new Error(`[analog] serverFn "${name}" in ${fileId} declares method: 'GET' with an input schema; GET carries no body. Use POST or drop the input.`);
70
+ return method ?? (hasInput ? "POST" : "GET");
71
+ }
72
+ if (arg0 && args.length >= 2) return "POST";
73
+ throw new Error(`[analog] serverFn "${name}" in ${fileId} must be called as serverFn(handler), serverFn(schema, handler), or serverFn(config, handler).`);
74
+ }
75
+ function isFunctionNode(node) {
76
+ return node?.type === "ArrowFunctionExpression" || node?.type === "FunctionExpression";
77
+ }
78
+ function isStringLiteral(node) {
79
+ return node?.type === "Literal" && typeof node.value === "string";
80
+ }
81
+ /** Every `serverFn(...)` call anywhere in the module, not just exported ones. */
82
+ function countServerFnCalls(node, names) {
83
+ if (!node || typeof node !== "object") return 0;
84
+ if (Array.isArray(node)) return node.reduce((total, child) => total + countServerFnCalls(child, names), 0);
85
+ const record = node;
86
+ let count = 0;
87
+ if (record.type === "CallExpression") {
88
+ const callee = record["callee"];
89
+ if (callee?.type === "Identifier" && callee.name && names.has(callee.name)) count += 1;
90
+ }
91
+ for (const key of Object.keys(record)) count += countServerFnCalls(record[key], names);
92
+ return count;
93
+ }
94
+ //#endregion
95
+ export { scrubServerFnModule };
96
+
97
+ //# sourceMappingURL=server-fn-client-transform.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"server-fn-client-transform.js","names":[],"sources":["../../../src/lib/server-fn-client-transform.ts"],"sourcesContent":["import { parseSync } from 'oxc-parser';\n// Light subpath (no vite/nitro barrel): the built scrub is loaded outside a\n// build too, so it must not pull the plugin graph in.\nimport { deriveServerFnId } from './server-fn-id.js';\n\n/**\n * Client-build scrub + proxy generation for server functions.\n *\n * On the client build a `*.server.ts` module must not carry server handler\n * bodies (which `inject()` server services, read the request, hit the database).\n * But the client still imports the named `serverFn` exports to dispatch them.\n * This transform regenerates the module so each `export const NAME = serverFn(\n * config, handler)` becomes a call to the client-safe `createServerFnRef`\n * factory — keeping the `{ id, url, method }` metadata `injectServerFn` needs,\n * dropping the handler and every server-only import. Because the regenerated\n * module references nothing else, the server code tree-shakes away entirely.\n *\n * Returns the new module source, or `null` when the module defines no server\n * function (the caller falls back to the page-endpoint scrub for those).\n */\nexport interface ServerFnProxy {\n name: string;\n id: string;\n method: 'GET' | 'POST';\n}\n\nexport interface ScrubResult {\n code: string;\n proxies: ServerFnProxy[];\n hadDefaultExport: boolean;\n}\n\nconst SERVER_FN_SOURCE = '@analogjs/router/server';\n\nexport function scrubServerFnModule(\n code: string,\n fileId = 'file.ts',\n): ScrubResult | null {\n // Cheap bail-out before parsing: no `serverFn` token, nothing to do.\n if (!code.includes('serverFn')) {\n return null;\n }\n\n const { program } = parseSync(fileId, code);\n const body = (program as { body: any[] }).body;\n\n const serverFnLocalNames = collectServerFnLocalNames(body);\n const hadDefaultExport = body.some(\n (node) => node.type === 'ExportDefaultDeclaration',\n );\n\n const proxies: ServerFnProxy[] = [];\n for (const node of body) {\n if (\n node.type !== 'ExportNamedDeclaration' ||\n node.declaration?.type !== 'VariableDeclaration'\n ) {\n continue;\n }\n for (const declarator of node.declaration.declarations) {\n if (\n declarator.id?.type !== 'Identifier' ||\n declarator.init?.type !== 'CallExpression' ||\n declarator.init.callee?.type !== 'Identifier' ||\n !serverFnLocalNames.has(declarator.init.callee.name)\n ) {\n continue;\n }\n proxies.push(\n toProxy(declarator.id.name, declarator.init.arguments ?? [], fileId),\n );\n }\n }\n\n // Every `serverFn(...)` call in the module must have become a proxy. If one\n // did not, the module uses a shape this transform cannot rewrite (e.g.\n // `const fn = serverFn(...); export { fn };`) and returning `null` would leave\n // it untouched — shipping the handler and its server imports to the browser.\n // Fail the build instead: a scrub that silently opts out is a code leak.\n const callCount = countServerFnCalls(program, serverFnLocalNames);\n if (callCount > proxies.length) {\n throw new Error(\n `[analog] ${fileId}: found ${callCount} serverFn call(s) but could only rewrite ${proxies.length} for the client build. ` +\n `Server functions must be declared as a directly exported const — \\`export const name = serverFn(…)\\` — so the handler can be stripped from the browser bundle.`,\n );\n }\n\n if (proxies.length === 0) {\n return null;\n }\n\n const lines = [\n `import { createServerFnRef } from '@analogjs/router';`,\n '',\n ...proxies.map(\n (p) =>\n `export const ${p.name} = createServerFnRef({ id: ${JSON.stringify(\n p.id,\n )}, method: ${JSON.stringify(p.method)} });`,\n ),\n ];\n // A file that is also a page endpoint keeps the load-shim the router expects.\n if (hadDefaultExport) {\n lines.push('', 'export default undefined;');\n }\n\n return { code: lines.join('\\n') + '\\n', proxies, hadDefaultExport };\n}\n\n/** Local identifier(s) `serverFn` is imported under from `@analogjs/router/server`. */\nfunction collectServerFnLocalNames(body: any[]): Set<string> {\n const names = new Set<string>();\n for (const node of body) {\n if (\n node.type !== 'ImportDeclaration' ||\n node.source?.value !== SERVER_FN_SOURCE\n ) {\n continue;\n }\n for (const spec of node.specifiers ?? []) {\n if (\n spec.type === 'ImportSpecifier' &&\n spec.imported?.name === 'serverFn'\n ) {\n names.add(spec.local.name);\n }\n }\n }\n // Fallback: if the module never imported it (unusual), still match the\n // conventional name so a mis-resolved import doesn't leak server code.\n if (names.size === 0) {\n names.add('serverFn');\n }\n return names;\n}\n\nfunction toProxy(name: string, args: any[], fileId: string): ServerFnProxy {\n const method = methodForCall(name, args, fileId);\n // The id is derived, never read from source — same algorithm the server\n // registration uses, so client proxy and server route always match.\n return { name, id: deriveServerFnId(fileId, name), method };\n}\n\n/**\n * Resolve the HTTP method from the call shape, matching the runtime overloads:\n * `serverFn(handler)` ⇒ GET, `serverFn(schema, handler)` ⇒ POST,\n * `serverFn(config, handler)` ⇒ config-driven.\n */\nfunction methodForCall(\n name: string,\n args: any[],\n fileId: string,\n): 'GET' | 'POST' {\n const arg0 = args[0];\n\n // serverFn(handler) — input-less GET.\n if (isFunctionNode(arg0)) return 'GET';\n\n // serverFn(config, handler) — read method/input off the object.\n if (arg0?.type === 'ObjectExpression') {\n let method: 'GET' | 'POST' | undefined;\n let hasInput = false;\n for (const prop of arg0.properties ?? []) {\n if (prop.type !== 'Property') continue;\n const key =\n prop.key?.type === 'Identifier' ? prop.key.name : prop.key?.value;\n if (key === 'method' && isStringLiteral(prop.value)) {\n method = prop.value.value as 'GET' | 'POST';\n } else if (key === 'input') {\n hasInput = true;\n }\n }\n if (method === 'GET' && hasInput) {\n throw new Error(\n `[analog] serverFn \"${name}\" in ${fileId} declares method: 'GET' with an input schema; GET carries no body. Use POST or drop the input.`,\n );\n }\n return method ?? (hasInput ? 'POST' : 'GET');\n }\n\n // serverFn(schema, handler) — a schema ⇒ POST + input.\n if (arg0 && args.length >= 2) return 'POST';\n\n throw new Error(\n `[analog] serverFn \"${name}\" in ${fileId} must be called as serverFn(handler), serverFn(schema, handler), or serverFn(config, handler).`,\n );\n}\n\nfunction isFunctionNode(node: any): boolean {\n return (\n node?.type === 'ArrowFunctionExpression' ||\n node?.type === 'FunctionExpression'\n );\n}\n\nfunction isStringLiteral(\n node: any,\n): node is { type: 'Literal'; value: string } {\n return node?.type === 'Literal' && typeof node.value === 'string';\n}\n\n/** Every `serverFn(...)` call anywhere in the module, not just exported ones. */\nfunction countServerFnCalls(node: unknown, names: Set<string>): number {\n if (!node || typeof node !== 'object') {\n return 0;\n }\n if (Array.isArray(node)) {\n return node.reduce(\n (total, child) => total + countServerFnCalls(child, names),\n 0,\n );\n }\n\n const record = node as Record<string, unknown> & { type?: string };\n let count = 0;\n if (record.type === 'CallExpression') {\n const callee = record['callee'] as { type?: string; name?: string };\n if (\n callee?.type === 'Identifier' &&\n callee.name &&\n names.has(callee.name)\n ) {\n count += 1;\n }\n }\n for (const key of Object.keys(record)) {\n count += countServerFnCalls(record[key], names);\n }\n return count;\n}\n"],"mappings":";;;AAgCA,IAAM,mBAAmB;AAEzB,SAAgB,oBACd,MACA,SAAS,WACW;AAEpB,KAAI,CAAC,KAAK,SAAS,WAAW,CAC5B,QAAO;CAGT,MAAM,EAAE,YAAY,UAAU,QAAQ,KAAK;CAC3C,MAAM,OAAQ,QAA4B;CAE1C,MAAM,qBAAqB,0BAA0B,KAAK;CAC1D,MAAM,mBAAmB,KAAK,MAC3B,SAAS,KAAK,SAAS,2BACzB;CAED,MAAM,UAA2B,EAAE;AACnC,MAAK,MAAM,QAAQ,MAAM;AACvB,MACE,KAAK,SAAS,4BACd,KAAK,aAAa,SAAS,sBAE3B;AAEF,OAA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 @@
1
+ /**
2
+ * Server-function ids are derived, never author-chosen, for security:
3
+ *
4
+ * - **Collision-free.** `hash(fileId + exportName)` is unique per file+export, so
5
+ * two functions can never share a route and hijack each other's dispatch — a
6
+ * real risk with hand-picked ids where two authors independently pick `getUser`.
7
+ * - **Non-enumerable.** The public route is an opaque digest, not a guessable
8
+ * verb like `/_analog/fn/deleteAccount`, shrinking the discoverable surface.
9
+ * - **Not author-controlled.** Authors cannot expose a meaningful or duplicate
10
+ * route by accident; the id is a pure function of location.
11
+ *
12
+ * Both build transforms (server registration + client proxy) MUST derive the
13
+ * same id, so this is the single source of truth for the algorithm and the
14
+ * `fileId` must be the **project-root-relative** POSIX path — identical across
15
+ * the client, SSR, and Nitro builds regardless of absolute checkout location.
16
+ */
17
+ /** Project-root-relative POSIX module path used as the stable hash input. */
18
+ export declare function serverFnFileId(absPath: string, projectRoot: string): string;
19
+ /**
20
+ * Derives the opaque, collision-free id for a server function from its
21
+ * project-root-relative file id and export name. 16 hex chars (64 bits) is far
22
+ * beyond birthday-collision range for any realistic function count while keeping
23
+ * the route short.
24
+ */
25
+ export declare function deriveServerFnId(fileId: string, exportName: string): string;
@@ -0,0 +1,37 @@
1
+ import { relative } from "node:path";
2
+ import { createHash } from "node:crypto";
3
+ //#region packages/platform/src/lib/server-fn-id.ts
4
+ var toPosix = (p) => p.replace(/\\/g, "/");
5
+ /**
6
+ * Server-function ids are derived, never author-chosen, for security:
7
+ *
8
+ * - **Collision-free.** `hash(fileId + exportName)` is unique per file+export, so
9
+ * two functions can never share a route and hijack each other's dispatch — a
10
+ * real risk with hand-picked ids where two authors independently pick `getUser`.
11
+ * - **Non-enumerable.** The public route is an opaque digest, not a guessable
12
+ * verb like `/_analog/fn/deleteAccount`, shrinking the discoverable surface.
13
+ * - **Not author-controlled.** Authors cannot expose a meaningful or duplicate
14
+ * route by accident; the id is a pure function of location.
15
+ *
16
+ * Both build transforms (server registration + client proxy) MUST derive the
17
+ * same id, so this is the single source of truth for the algorithm and the
18
+ * `fileId` must be the **project-root-relative** POSIX path — identical across
19
+ * the client, SSR, and Nitro builds regardless of absolute checkout location.
20
+ */
21
+ /** Project-root-relative POSIX module path used as the stable hash input. */
22
+ function serverFnFileId(absPath, projectRoot) {
23
+ return toPosix(relative(projectRoot, absPath));
24
+ }
25
+ /**
26
+ * Derives the opaque, collision-free id for a server function from its
27
+ * project-root-relative file id and export name. 16 hex chars (64 bits) is far
28
+ * beyond birthday-collision range for any realistic function count while keeping
29
+ * the route short.
30
+ */
31
+ function deriveServerFnId(fileId, exportName) {
32
+ return createHash("sha256").update(`${fileId}#${exportName}`).digest("hex").slice(0, 16);
33
+ }
34
+ //#endregion
35
+ export { deriveServerFnId, serverFnFileId };
36
+
37
+ //# sourceMappingURL=server-fn-id.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"server-fn-id.js","names":[],"sources":["../../../src/lib/server-fn-id.ts"],"sourcesContent":["import { createHash } from 'node:crypto';\nimport { relative } from 'node:path';\n\n// Intentionally dependency-light (node built-ins only): this module is loaded by\n// the client scrub, so it must not drag in vite/nitro. POSIX-normalize inline.\nconst toPosix = (p: string): string => p.replace(/\\\\/g, '/');\n\n/**\n * Server-function ids are derived, never author-chosen, for security:\n *\n * - **Collision-free.** `hash(fileId + exportName)` is unique per file+export, so\n * two functions can never share a route and hijack each other's dispatch — a\n * real risk with hand-picked ids where two authors independently pick `getUser`.\n * - **Non-enumerable.** The public route is an opaque digest, not a guessable\n * verb like `/_analog/fn/deleteAccount`, shrinking the discoverable surface.\n * - **Not author-controlled.** Authors cannot expose a meaningful or duplicate\n * route by accident; the id is a pure function of location.\n *\n * Both build transforms (server registration + client proxy) MUST derive the\n * same id, so this is the single source of truth for the algorithm and the\n * `fileId` must be the **project-root-relative** POSIX path — identical across\n * the client, SSR, and Nitro builds regardless of absolute checkout location.\n */\n\n/** Project-root-relative POSIX module path used as the stable hash input. */\nexport function serverFnFileId(absPath: string, projectRoot: string): string {\n return toPosix(relative(projectRoot, absPath));\n}\n\n/**\n * Derives the opaque, collision-free id for a server function from its\n * project-root-relative file id and export name. 16 hex chars (64 bits) is far\n * beyond birthday-collision range for any realistic function count while keeping\n * the route short.\n */\nexport function deriveServerFnId(fileId: string, exportName: string): string {\n return createHash('sha256')\n .update(`${fileId}#${exportName}`)\n .digest('hex')\n .slice(0, 16);\n}\n"],"mappings":";;;AAKA,IAAM,WAAW,MAAsB,EAAE,QAAQ,OAAO,IAAI;;;;;;;;;;;;;;;;;;AAoB5D,SAAgB,eAAe,SAAiB,aAA6B;AAC3E,QAAO,QAAQ,SAAS,aAAa,QAAQ,CAAC;;;;;;;;AAShD,SAAgB,iBAAiB,QAAgB,YAA4B;AAC3E,QAAO,WAAW,SAAS,CACxB,OAAO,GAAG,OAAO,GAAG,aAAa,CACjC,OAAO,MAAM,CACb,MAAM,GAAG,GAAG"}
@@ -0,0 +1,65 @@
1
+ import type { Plugin } from "vite";
2
+ /**
3
+ * Minimum Angular major whose compiled `@angular/core` FESM matches the
4
+ * streaming patch anchors. Incremental hydration is a stable public API from
5
+ * v20 (`withIncrementalHydration`, `@publicApi 20.0`), but v20's FESM inlines
6
+ * the injection anchor's `DeferBlockStateEnd` profiler event to its numeric
7
+ * ordinal, whereas v21+ keeps the symbolic `ProfilerEvent.DeferBlockStateEnd`
8
+ * form the anchor matches on. Keying on the literal ordinal would be fragile
9
+ * (enum values shift between versions), so v21 is the floor.
10
+ */
11
+ export declare const MIN_STREAMING_ANGULAR_MAJOR = 21;
12
+ /**
13
+ * Whether the streaming SSR patch can be applied to the installed Angular.
14
+ * A `null` major (version undetectable) returns `true`: don't block on a failed
15
+ * detection — the plugin's anchor-drift detection catches a real mismatch at
16
+ * build time and falls back to buffered rendering.
17
+ */
18
+ export declare function streamingSupportedOnAngular(major: number | null): boolean;
19
+ /**
20
+ * Pure transform that injects the streaming-SSR per-block resolution hook into
21
+ * `@angular/core`'s compiled output. It is the same class of transform as
22
+ * `i18nDefRegistryPlugin` in ./ssr-build-plugin — a string patch of Angular's
23
+ * bundle applied only to SSR builds. Exported separately so it can be unit
24
+ * tested against a bundle string.
25
+ *
26
+ * Two edits, both keyed on single-occurrence anchors in the module that holds
27
+ * the defer runtime:
28
+ * 1. Inside `applyDeferBlockState`, fire `globalThis.__analogSsrDeferCapture`
29
+ * when a `@defer` block reaches `Complete` on the server, passing the
30
+ * block's live `lContainer` — this is the per-block resolution signal a
31
+ * streaming renderer consumes.
32
+ * 2. Expose `collectNativeNodesInLContainer` via `globalThis.__analogSsrInternals`
33
+ * so the renderer can serialize a block's subtree.
34
+ *
35
+ * Returns `null` when the module is not the one carrying the defer runtime, so
36
+ * it is a no-op on every other Angular module.
37
+ */
38
+ export declare function injectDeferStreamingHook(code: string): string | null;
39
+ /**
40
+ * Classify an `@angular/core` module for the streaming patch. The patch anchors
41
+ * on internal symbol names, so when Angular changes those the transform would
42
+ * otherwise become a silent no-op and streaming would degrade to buffered with
43
+ * no signal. This distinguishes "not the target module" (skip quietly) from
44
+ * "this IS the `@defer` runtime module but the anchors drifted" (worth warning).
45
+ */
46
+ export declare function inspectAngularCoreModule(code: string): {
47
+ kind: "not-target";
48
+ } | {
49
+ kind: "patchable";
50
+ } | {
51
+ kind: "drifted";
52
+ reason: string;
53
+ };
54
+ /**
55
+ * Vite plugin that applies {@link injectDeferStreamingHook} to `@angular/core`
56
+ * during SSR builds, so `@analogjs/router`'s `renderStream` can flush `@defer`
57
+ * blocks as they resolve on the server — without hand-patching node_modules.
58
+ *
59
+ * Only active for SSR. Mirrors the enforce/filter/ssr-gate shape of
60
+ * `i18nDefRegistryPlugin`. If the `@defer` runtime module is found but its
61
+ * anchors have drifted (Angular changed internals), or if it is never
62
+ * encountered at all, the plugin warns rather than silently producing a build
63
+ * that falls back to buffered rendering.
64
+ */
65
+ export declare function deferStreamingPlugin(): Plugin;
@@ -1,2 +1,2 @@
1
- import { Plugin } from 'vite';
1
+ import { Plugin } from "vite";
2
2
  export declare function injectHTMLPlugin(): Plugin[];
@@ -1 +1 @@
1
- {"version":3,"file":"inject-html-plugin.js","names":[],"sources":["../../../../../../packages/platform/src/lib/ssr/inject-html-plugin.ts"],"sourcesContent":["import { VERSION } from '@angular/compiler-cli';\nimport { Plugin } from 'vite';\nimport { readFile } from 'node:fs/promises';\nimport { createRequire } from 'node:module';\n\nconst require = createRequire(import.meta.url);\n\nfunction eventReplayPlugin(): Plugin {\n return {\n name: 'analogjs-event-replay-plugin',\n async transformIndexHtml() {\n const eventReplayScript = await readFile(\n require.resolve('@angular/core/event-dispatch-contract.min.js'),\n 'utf-8',\n );\n\n return [\n {\n tag: 'script',\n attrs: {\n type: 'text/javascript',\n id: 'ng-event-dispatch-contract',\n },\n children: eventReplayScript,\n injectTo: 'body',\n },\n ];\n },\n };\n}\n\nexport function injectHTMLPlugin(): Plugin[] {\n const hasEventReplay = Number(VERSION.major) >= 18;\n\n return hasEventReplay ? [eventReplayPlugin()] : [];\n}\n"],"mappings":";;;;AAKA,IAAM,UAAU,cAAc,OAAO,KAAK,IAAI;AAE9C,SAAS,oBAA4B;AACnC,QAAO;EACL,MAAM;EACN,MAAM,qBAAqB;AAMzB,UAAO,CACL;IACE,KAAK;IACL,OAAO;KACL,MAAM;KACN,IAAI;KACL;IACD,UAZsB,MAAM,SAC9B,QAAQ,QAAQ,+CAA+C,EAC/D,QACD;IAUG,UAAU;IACX,CACF;;EAEJ;;AAGH,SAAgB,mBAA6B;AAG3C,QAFuB,OAAO,QAAQ,MAAM,IAAI,KAExB,CAAC,mBAAmB,CAAC,GAAG,EAAE"}
1
+ {"version":3,"file":"inject-html-plugin.js","names":[],"sources":["../../../../src/lib/ssr/inject-html-plugin.ts"],"sourcesContent":["import { VERSION } from '@angular/compiler-cli';\nimport { Plugin } from 'vite';\nimport { readFile } from 'node:fs/promises';\nimport { createRequire } from 'node:module';\n\nconst require = createRequire(import.meta.url);\n\nfunction eventReplayPlugin(): Plugin {\n return {\n name: 'analogjs-event-replay-plugin',\n async transformIndexHtml() {\n const eventReplayScript = await readFile(\n require.resolve('@angular/core/event-dispatch-contract.min.js'),\n 'utf-8',\n );\n\n return [\n {\n tag: 'script',\n attrs: {\n type: 'text/javascript',\n id: 'ng-event-dispatch-contract',\n },\n children: eventReplayScript,\n injectTo: 'body',\n },\n ];\n },\n };\n}\n\nexport function injectHTMLPlugin(): Plugin[] {\n const hasEventReplay = Number(VERSION.major) >= 18;\n\n return hasEventReplay ? [eventReplayPlugin()] : [];\n}\n"],"mappings":";;;;AAKA,IAAM,UAAU,cAAc,OAAO,KAAK,IAAI;AAE9C,SAAS,oBAA4B;AACnC,QAAO;EACL,MAAM;EACN,MAAM,qBAAqB;AAMzB,UAAO,CACL;IACE,KAAK;IACL,OAAO;KACL,MAAM;KACN,IAAI;KACL;IACD,UAZsB,MAAM,SAC9B,QAAQ,QAAQ,+CAA+C,EAC/D,QACD;IAUG,UAAU;IACX,CACF;;EAEJ;;AAGH,SAAgB,mBAA6B;AAG3C,QAFuB,OAAO,QAAQ,MAAM,IAAI,KAExB,CAAC,mBAAmB,CAAC,GAAG,EAAE"}
@@ -1,18 +1,26 @@
1
- import * as vite from 'vite';
1
+ import * as vite from "vite";
2
2
  /**
3
- * SSR build patches for Angular platform-server, Zone.js, and Domino.
4
- *
5
- * Returns an array of Vite plugins because under Vite 8+ (Rolldown) we
6
- * append Rolldown's built-in `replacePlugin` for an AST-safe
7
- * `global → globalThis` rewrite that avoids false positives inside string
8
- * literals and comments.
9
- *
10
- * **Why each patch exists:**
11
- * - zone-node: removes a `const global = globalThis` alias that shadows the
12
- * real global in strict mode.
13
- * - platform-server: rewrites `xhr2.XMLHttpRequest` for CJS/ESM compat and
14
- * replaces bare `global` references with `globalThis`.
15
- * - xhr2: strips Node-specific `os`/`process` references for SSR bundling.
16
- * - domino/sloppy.js: replaces `with()` statements that are illegal in ESM.
17
- */
3
+ * SSR build patches for Angular platform-server, Zone.js, and Domino.
4
+ *
5
+ * **Why each patch exists:**
6
+ * - zone-node: removes a `const global = globalThis` alias that shadows the
7
+ * real global in strict mode.
8
+ * - platform-server: rewrites `xhr2.XMLHttpRequest` for CJS/ESM compat and
9
+ * replaces bare `global` references with `globalThis`.
10
+ * - xhr2: strips Node-specific `os`/`process` references for SSR bundling.
11
+ * - domino/sloppy.js: replaces `with()` statements that are illegal in ESM.
12
+ */
18
13
  export declare function ssrBuildPlugin(): vite.Plugin[];
14
+ /**
15
+ * Vite plugin that patches `@angular/core`'s `getComponentId()` to
16
+ * mirror every compiled component definition to a global Set, bypassing
17
+ * the `ngServerMode` guard that normally prevents registration on the
18
+ * server. The set lives at `globalThis.__ngComponentDefs` and is read by
19
+ * `@analogjs/router`'s SSR render function to null cached `tView`
20
+ * objects between requests so that `$localize` tagged templates in
21
+ * `consts()` re-evaluate with the freshly loaded translations.
22
+ *
23
+ * Only active when the platform's `i18n` option is configured.
24
+ * Only transforms `@angular/core` modules in SSR builds.
25
+ */
26
+ export declare function i18nDefRegistryPlugin(): Plugin;
@@ -1,14 +1,8 @@
1
1
  import * as vite from "vite";
2
- import { createRequire } from "node:module";
3
2
  //#region packages/platform/src/lib/ssr/ssr-build-plugin.ts
4
3
  /**
5
4
  * SSR build patches for Angular platform-server, Zone.js, and Domino.
6
5
  *
7
- * Returns an array of Vite plugins because under Vite 8+ (Rolldown) we
8
- * append Rolldown's built-in `replacePlugin` for an AST-safe
9
- * `global → globalThis` rewrite that avoids false positives inside string
10
- * literals and comments.
11
- *
12
6
  * **Why each patch exists:**
13
7
  * - zone-node: removes a `const global = globalThis` alias that shadows the
14
8
  * real global in strict mode.
@@ -18,7 +12,7 @@ import { createRequire } from "node:module";
18
12
  * - domino/sloppy.js: replaces `with()` statements that are illegal in ESM.
19
13
  */
20
14
  function ssrBuildPlugin() {
21
- const plugins = [{
15
+ return [{
22
16
  name: "analogjs-ssr-build-plugin",
23
17
  apply: "build",
24
18
  config() {
@@ -30,7 +24,7 @@ function ssrBuildPlugin() {
30
24
  if (id.includes("zone-node") && code.includes("const global = globalThis;")) return { code: code.replace("const global = globalThis;", "") };
31
25
  if (id.includes("platform-server")) {
32
26
  let result = code.replace("new xhr2.XMLHttpRequest", "new (xhr2.default.XMLHttpRequest || xhr2.default)");
33
- if (!vite.rolldownVersion) result = result.replaceAll("global.", "globalThis.").replaceAll("global,", "globalThis,").replaceAll(" global[", " globalThis[");
27
+ result = result.replaceAll("global.", "globalThis.").replaceAll("global,", "globalThis,").replaceAll(" global[", " globalThis[");
34
28
  return { code: result };
35
29
  }
36
30
  if (id.includes(vite.normalizePath("xhr2.js"))) return { code: code.replace("os.type()", `''`).replace("os.arch()", `''`).replace("process.versions.node", `'node'`).replace("process.versions.v8", `'v8'`) };
@@ -38,16 +32,6 @@ function ssrBuildPlugin() {
38
32
  }
39
33
  }
40
34
  }];
41
- if (vite.rolldownVersion) {
42
- const require = createRequire(import.meta.url);
43
- const { replacePlugin } = require("rolldown/plugins");
44
- const { withFilter } = require("rolldown/filter");
45
- plugins.push(withFilter(replacePlugin({ global: "globalThis" }, {
46
- preventAssignment: true,
47
- objectGuards: true
48
- }), { transform: { id: /platform-server/ } }));
49
- }
50
- return plugins;
51
35
  }
52
36
  //#endregion
53
37
  export { ssrBuildPlugin };
@@ -1 +1 @@
1
- {"version":3,"file":"ssr-build-plugin.js","names":[],"sources":["../../../../../../packages/platform/src/lib/ssr/ssr-build-plugin.ts"],"sourcesContent":["import { createRequire } from 'node:module';\nimport * as vite from 'vite';\n\n/**\n * SSR build patches for Angular platform-server, Zone.js, and Domino.\n *\n * Returns an array of Vite plugins because under Vite 8+ (Rolldown) we\n * append Rolldown's built-in `replacePlugin` for an AST-safe\n * `global → globalThis` rewrite that avoids false positives inside string\n * literals and comments.\n *\n * **Why each patch exists:**\n * - zone-node: removes a `const global = globalThis` alias that shadows the\n * real global in strict mode.\n * - platform-server: rewrites `xhr2.XMLHttpRequest` for CJS/ESM compat and\n * replaces bare `global` references with `globalThis`.\n * - xhr2: strips Node-specific `os`/`process` references for SSR bundling.\n * - domino/sloppy.js: replaces `with()` statements that are illegal in ESM.\n */\nexport function ssrBuildPlugin(): vite.Plugin[] {\n const plugins: vite.Plugin[] = [\n {\n name: 'analogjs-ssr-build-plugin',\n apply: 'build',\n config() {\n return {\n ssr: {\n noExternal: ['xhr2'],\n },\n };\n },\n transform: {\n filter: {\n id: /zone-node|platform-server|xhr2\\.js|domino\\/lib\\/sloppy\\.js/,\n },\n handler(code, id) {\n if (\n id.includes('zone-node') &&\n code.includes('const global = globalThis;')\n ) {\n return {\n code: code.replace('const global = globalThis;', ''),\n };\n }\n\n if (id.includes('platform-server')) {\n let result = code.replace(\n 'new xhr2.XMLHttpRequest',\n 'new (xhr2.default.XMLHttpRequest || xhr2.default)',\n );\n\n // Under Vite 8+ the appended `replacePlugin` handles\n // global → globalThis via AST-aware replacement (scoped to\n // platform-server by `withFilter`). For Vite ≤7 we fall back\n // to text-based replaceAll — imprecise but sufficient for the\n // known occurrences in @angular/platform-server bundles.\n if (!vite.rolldownVersion) {\n result = result\n .replaceAll('global.', 'globalThis.')\n .replaceAll('global,', 'globalThis,')\n .replaceAll(' global[', ' globalThis[');\n }\n\n return { code: result };\n }\n\n if (id.includes(vite.normalizePath('xhr2.js'))) {\n return {\n code: code\n .replace('os.type()', `''`)\n .replace('os.arch()', `''`)\n .replace('process.versions.node', `'node'`)\n .replace('process.versions.v8', `'v8'`),\n };\n }\n\n if (id.includes(vite.normalizePath('domino/lib/sloppy.js'))) {\n return {\n code: code.replace(/with\\(/gi, 'if('),\n };\n }\n\n return;\n },\n },\n },\n ];\n\n // Under Vite 8+ (Rolldown), append Rolldown's built-in `replacePlugin`\n // for AST-aware `global → globalThis` rewriting scoped to platform-server.\n //\n // `createRequire` is used instead of dynamic `import()` because this code\n // runs synchronously during plugin construction (not inside an async hook).\n // Rolldown is guaranteed to be installed when `vite.rolldownVersion` is truthy.\n if (vite.rolldownVersion) {\n const require = createRequire(import.meta.url);\n const { replacePlugin } =\n require('rolldown/plugins') as typeof import('rolldown/plugins');\n const { withFilter } =\n require('rolldown/filter') as typeof import('rolldown/filter');\n\n plugins.push(\n withFilter(\n replacePlugin(\n { global: 'globalThis' },\n { preventAssignment: true, objectGuards: true },\n ),\n { transform: { id: /platform-server/ } },\n ) as unknown as vite.Plugin,\n );\n }\n\n return plugins;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAmBA,SAAgB,iBAAgC;CAC9C,MAAM,UAAyB,CAC7B;EACE,MAAM;EACN,OAAO;EACP,SAAS;AACP,UAAO,EACL,KAAK,EACH,YAAY,CAAC,OAAO,EACrB,EACF;;EAEH,WAAW;GACT,QAAQ,EACN,IAAI,8DACL;GACD,QAAQ,MAAM,IAAI;AAChB,QACE,GAAG,SAAS,YAAY,IACxB,KAAK,SAAS,6BAA6B,CAE3C,QAAO,EACL,MAAM,KAAK,QAAQ,8BAA8B,GAAG,EACrD;AAGH,QAAI,GAAG,SAAS,kBAAkB,EAAE;KAClC,IAAI,SAAS,KAAK,QAChB,2BACA,oDACD;AAOD,SAAI,CAAC,KAAK,gBACR,UAAS,OACN,WAAW,WAAW,cAAc,CACpC,WAAW,WAAW,cAAc,CACpC,WAAW,YAAY,eAAe;AAG3C,YAAO,EAAE,MAAM,QAAQ;;AAGzB,QAAI,GAAG,SAAS,KAAK,cAAc,UAAU,CAAC,CAC5C,QAAO,EACL,MAAM,KACH,QAAQ,aAAa,KAAK,CAC1B,QAAQ,aAAa,KAAK,CAC1B,QAAQ,yBAAyB,SAAS,CAC1C,QAAQ,uBAAuB,OAAO,EAC1C;AAGH,QAAI,GAAG,SAAS,KAAK,cAAc,uBAAuB,CAAC,CACzD,QAAO,EACL,MAAM,KAAK,QAAQ,YAAY,MAAM,EACtC;;GAKN;EACF,CACF;AAQD,KAAI,KAAK,iBAAiB;EACxB,MAAM,UAAU,cAAc,OAAO,KAAK,IAAI;EAC9C,MAAM,EAAE,kBACN,QAAQ,mBAAmB;EAC7B,MAAM,EAAE,eACN,QAAQ,kBAAkB;AAE5B,UAAQ,KACN,WACE,cACE,EAAE,QAAQ,cAAc,EACxB;GAAE,mBAAmB;GAAM,cAAc;GAAM,CAChD,EACD,EAAE,WAAW,EAAE,IAAI,mBAAmB,EAAE,CACzC,CACF;;AAGH,QAAO"}
1
+ {"version":3,"file":"ssr-build-plugin.js","names":[],"sources":["../../../../src/lib/ssr/ssr-build-plugin.ts"],"sourcesContent":["import * as vite from 'vite';\n\n/**\n * SSR build patches for Angular platform-server, Zone.js, and Domino.\n *\n * **Why each patch exists:**\n * - zone-node: removes a `const global = globalThis` alias that shadows the\n * real global in strict mode.\n * - platform-server: rewrites `xhr2.XMLHttpRequest` for CJS/ESM compat and\n * replaces bare `global` references with `globalThis`.\n * - xhr2: strips Node-specific `os`/`process` references for SSR bundling.\n * - domino/sloppy.js: replaces `with()` statements that are illegal in ESM.\n */\nexport function ssrBuildPlugin(): vite.Plugin[] {\n const plugins: vite.Plugin[] = [\n {\n name: 'analogjs-ssr-build-plugin',\n apply: 'build',\n config() {\n return {\n ssr: {\n noExternal: ['xhr2'],\n },\n };\n },\n transform: {\n filter: {\n id: /zone-node|platform-server|xhr2\\.js|domino\\/lib\\/sloppy\\.js/,\n },\n handler(code, id) {\n if (\n id.includes('zone-node') &&\n code.includes('const global = globalThis;')\n ) {\n return {\n code: code.replace('const global = globalThis;', ''),\n };\n }\n\n if (id.includes('platform-server')) {\n let result = code.replace(\n 'new xhr2.XMLHttpRequest',\n 'new (xhr2.default.XMLHttpRequest || xhr2.default)',\n );\n\n // Narrowly scoped text replacement of the bare `global`\n // identifier. Matching `global.`, `global,` and ` global[`\n // targets the known occurrences in the @angular/platform-server\n // bundle while leaving strings, comments and asset paths that\n // merely contain the word `global` untouched (see #2426).\n result = result\n .replaceAll('global.', 'globalThis.')\n .replaceAll('global,', 'globalThis,')\n .replaceAll(' global[', ' globalThis[');\n\n return { code: result };\n }\n\n if (id.includes(vite.normalizePath('xhr2.js'))) {\n return {\n code: code\n .replace('os.type()', `''`)\n .replace('os.arch()', `''`)\n .replace('process.versions.node', `'node'`)\n .replace('process.versions.v8', `'v8'`),\n };\n }\n\n if (id.includes(vite.normalizePath('domino/lib/sloppy.js'))) {\n return {\n code: code.replace(/with\\(/gi, 'if('),\n };\n }\n\n return;\n },\n },\n },\n ];\n\n return plugins;\n}\n\n/**\n * Vite plugin that patches `@angular/core`'s `getComponentId()` to\n * mirror every compiled component definition to a global Set, bypassing\n * the `ngServerMode` guard that normally prevents registration on the\n * server. The set lives at `globalThis.__ngComponentDefs` and is read by\n * `@analogjs/router`'s SSR render function to null cached `tView`\n * objects between requests so that `$localize` tagged templates in\n * `consts()` re-evaluate with the freshly loaded translations.\n *\n * Only active when the platform's `i18n` option is configured.\n * Only transforms `@angular/core` modules in SSR builds.\n */\nexport function i18nDefRegistryPlugin(): Plugin {\n const DETECT_MARKER = 'GENERATED_COMP_IDS.set(compId, componentDef.type);';\n const RETURN_STMT = 'return compId;\\n}';\n\n return {\n name: 'analogjs-i18n-def-registry',\n enforce: 'post',\n\n transform: {\n filter: {\n id: /\\/@angular\\/core\\//,\n },\n handler(code, id, options) {\n if (!options?.ssr) return;\n if (!code.includes(DETECT_MARKER)) return;\n\n return {\n code: code.replace(\n RETURN_STMT,\n '(globalThis.__ngComponentDefs ??= new Set()).add(componentDef);\\n' +\n RETURN_STMT,\n ),\n };\n },\n },\n };\n}\n"],"mappings":";;;;;;;;;;;;;AAaA,SAAgB,iBAAgC;AAmE9C,QAlE+B,CAC7B;EACE,MAAM;EACN,OAAO;EACP,SAAS;AACP,UAAO,EACL,KAAK,EACH,YAAY,CAAC,OAAO,EACrB,EACF;;EAEH,WAAW;GACT,QAAQ,EACN,IAAI,8DACL;GACD,QAAQ,MAAM,IAAI;AAChB,QACE,GAAG,SAAS,YAAY,IACxB,KAAK,SAAS,6BAA6B,CAE3C,QAAO,EACL,MAAM,KAAK,QAAQ,8BAA8B,GAAG,EACrD;AAGH,QAAI,GAAG,SAAS,kBAAkB,EAAE;KAClC,IAAI,SAAS,KAAK,QAChB,2BACA,oDACD;AAOD,cAAS,OACN,WAAW,WAAW,cAAc,CACpC,WAAW,WAAW,cAAc,CACpC,WAAW,YAAY,eAAe;AAEzC,YAAO,EAAE,MAAM,QAAQ;;AAGzB,QAAI,GAAG,SAAS,KAAK,cAAc,UAAU,CAAC,CAC5C,QAAO,EACL,MAAM,KACH,QAAQ,aAAa,KAAK,CAC1B,QAAQ,aAAa,KAAK,CAC1B,QAAQ,yBAAyB,SAAS,CAC1C,QAAQ,uBAAuB,OAAO,EAC1C;AAGH,QAAI,GAAG,SAAS,KAAK,cAAc,uBAAuB,CAAC,CACzD,QAAO,EACL,MAAM,KAAK,QAAQ,YAAY,MAAM,EACtC;;GAKN;EACF,CACF"}
@@ -0,0 +1,13 @@
1
+ import { type Plugin } from "vite";
2
+ export interface TypedRoutingOptions {
3
+ /** Generated declaration path (.d.ts), relative to the app root. */
4
+ outFile?: string;
5
+ /** Fail builds when a checked-in route table is stale. Defaults to true. */
6
+ verifyOnBuild?: boolean;
7
+ }
8
+ export interface TypedRoutesPluginOptions extends TypedRoutingOptions {
9
+ workspaceRoot?: string;
10
+ additionalPagesDirs?: string[];
11
+ additionalContentDirs?: string[];
12
+ }
13
+ export declare function typedRoutes(options?: TypedRoutesPluginOptions): Plugin;