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

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 (361) hide show
  1. package/migrations/migration.json +7 -1
  2. package/package.json +28 -14
  3. package/src/index.d.ts +5 -2
  4. package/src/index.js +3 -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/json-ld-manifest-plugin.d.ts +41 -0
  52. package/src/lib/json-ld-manifest-plugin.js +84 -0
  53. package/src/lib/json-ld-manifest-plugin.js.map +1 -0
  54. package/src/lib/nitro/analog-nitro-plugin.d.ts +18 -0
  55. package/src/lib/nitro/analog-nitro-plugin.js +582 -0
  56. package/src/lib/nitro/analog-nitro-plugin.js.map +1 -0
  57. package/src/lib/nitro/angular-linker-plugin.d.ts +15 -0
  58. package/src/lib/nitro/angular-linker-plugin.js +64 -0
  59. package/src/lib/nitro/angular-linker-plugin.js.map +1 -0
  60. package/src/lib/nitro/build-sitemap.d.ts +23 -0
  61. package/src/lib/nitro/build-sitemap.js +137 -0
  62. package/src/lib/nitro/build-sitemap.js.map +1 -0
  63. package/src/lib/nitro/debug.d.ts +5 -0
  64. package/src/lib/nitro/debug.js +11 -0
  65. package/src/lib/nitro/debug.js.map +1 -0
  66. package/src/lib/nitro/get-content-files.d.ts +13 -0
  67. package/src/lib/nitro/get-content-files.js +52 -0
  68. package/src/lib/nitro/get-content-files.js.map +1 -0
  69. package/src/lib/nitro/get-page-handlers.d.ts +22 -0
  70. package/src/lib/nitro/get-page-handlers.js +33 -0
  71. package/src/lib/nitro/get-page-handlers.js.map +1 -0
  72. package/src/lib/nitro/i18n-prerender.d.ts +29 -0
  73. package/src/lib/nitro/i18n-prerender.js +61 -0
  74. package/src/lib/nitro/i18n-prerender.js.map +1 -0
  75. package/src/lib/nitro/page-endpoints-plugin.d.ts +7 -0
  76. package/src/lib/nitro/page-endpoints-plugin.js +72 -0
  77. package/src/lib/nitro/page-endpoints-plugin.js.map +1 -0
  78. package/src/lib/nitro/post-rendering-hook.d.ts +2 -0
  79. package/src/lib/nitro/post-rendering-hook.js +10 -0
  80. package/src/lib/nitro/post-rendering-hook.js.map +1 -0
  81. package/src/lib/nitro/renderers.d.ts +33 -0
  82. package/src/lib/nitro/renderers.js +22 -0
  83. package/src/lib/nitro/renderers.js.map +1 -0
  84. package/src/lib/nitro/types.d.ts +122 -0
  85. package/src/lib/nx-plugin/_virtual/_rolldown/runtime.js +23 -0
  86. package/src/lib/nx-plugin/builders.json +15 -0
  87. package/src/lib/nx-plugin/executors.json +13 -5
  88. package/src/lib/nx-plugin/generators.json +25 -0
  89. package/src/lib/nx-plugin/node_modules/.pnpm/es-toolkit@1.45.1/node_modules/es-toolkit/dist/string/camelCase.js +13 -0
  90. package/src/lib/nx-plugin/node_modules/.pnpm/es-toolkit@1.45.1/node_modules/es-toolkit/dist/string/camelCase.js.map +1 -0
  91. package/src/lib/nx-plugin/node_modules/.pnpm/es-toolkit@1.45.1/node_modules/es-toolkit/dist/string/capitalize.js +8 -0
  92. package/src/lib/nx-plugin/node_modules/.pnpm/es-toolkit@1.45.1/node_modules/es-toolkit/dist/string/capitalize.js.map +1 -0
  93. package/src/lib/nx-plugin/node_modules/.pnpm/es-toolkit@1.45.1/node_modules/es-toolkit/dist/string/words.js +9 -0
  94. package/src/lib/nx-plugin/node_modules/.pnpm/es-toolkit@1.45.1/node_modules/es-toolkit/dist/string/words.js.map +1 -0
  95. package/src/lib/nx-plugin/package.json +1 -3
  96. package/src/lib/nx-plugin/src/builders/vite/schema.json +39 -0
  97. package/src/lib/nx-plugin/src/builders/vite/vite-build.d.ts +11 -0
  98. package/src/lib/nx-plugin/src/builders/vite/vite-build.js +18 -0
  99. package/src/lib/nx-plugin/src/builders/vite/vite-build.js.map +1 -0
  100. package/src/lib/nx-plugin/src/builders/vite-dev-server/dev-server.d.ts +7 -0
  101. package/src/lib/nx-plugin/src/builders/vite-dev-server/dev-server.js +14 -0
  102. package/src/lib/nx-plugin/src/builders/vite-dev-server/dev-server.js.map +1 -0
  103. package/src/lib/nx-plugin/src/builders/vite-dev-server/schema.json +27 -0
  104. package/src/lib/nx-plugin/src/executors/vite-dev-server/compat.d.ts +1 -1
  105. package/src/lib/nx-plugin/src/executors/vite-dev-server/compat.js +4 -4
  106. package/src/lib/nx-plugin/src/executors/vite-dev-server/compat.js.map +1 -1
  107. package/src/lib/nx-plugin/src/executors/vite-dev-server/vite-dev-server.impl.d.ts +1 -1
  108. package/src/lib/nx-plugin/src/executors/vite-dev-server/vite-dev-server.impl.js +3 -3
  109. package/src/lib/nx-plugin/src/executors/vite-dev-server/vite-dev-server.impl.js.map +1 -1
  110. package/src/lib/nx-plugin/src/executors/vitest/compat.d.ts +1 -1
  111. package/src/lib/nx-plugin/src/executors/vitest/compat.js +4 -4
  112. package/src/lib/nx-plugin/src/executors/vitest/compat.js.map +1 -1
  113. package/src/lib/nx-plugin/src/executors/vitest/vitest.impl.d.ts +1 -1
  114. package/src/lib/nx-plugin/src/executors/vitest/vitest.impl.js +3 -3
  115. package/src/lib/nx-plugin/src/executors/vitest/vitest.impl.js.map +1 -1
  116. package/src/lib/nx-plugin/src/generators/app/compat.d.ts +9 -3
  117. package/src/lib/nx-plugin/src/generators/app/compat.js +15 -4
  118. package/src/lib/nx-plugin/src/generators/app/compat.js.map +1 -1
  119. package/src/lib/nx-plugin/src/generators/app/files/agents/AGENTS.md +11 -0
  120. package/src/lib/nx-plugin/src/generators/app/files/agents/CLAUDE.md +1 -0
  121. package/src/lib/nx-plugin/src/generators/app/files/root/tsconfig.base.json +3 -6
  122. package/src/lib/nx-plugin/src/generators/app/files/template-angular/src/test-setup.ts__template__ +1 -0
  123. package/src/lib/nx-plugin/src/generators/app/files/template-angular/tsconfig.app.json__template__ +1 -3
  124. package/src/lib/nx-plugin/src/generators/app/files/template-angular/tsconfig.json__template__ +2 -1
  125. package/src/lib/nx-plugin/src/generators/app/files/template-angular/vite.config.ts__template__ +7 -3
  126. package/src/lib/nx-plugin/src/generators/app/files/template-angular-v17/tsconfig.json__template__ +4 -2
  127. package/src/lib/nx-plugin/src/generators/app/files/template-angular-v17/vite.config.ts__template__ +2 -5
  128. package/src/lib/nx-plugin/src/generators/app/files/template-angular-v18/tsconfig.json__template__ +4 -2
  129. package/src/lib/nx-plugin/src/generators/app/files/template-angular-v18/vite.config.ts__template__ +3 -6
  130. package/src/lib/nx-plugin/src/generators/app/files/template-angular-v19/tsconfig.app.json__template__ +1 -3
  131. package/src/lib/nx-plugin/src/generators/app/files/template-angular-v19/tsconfig.json__template__ +4 -2
  132. package/src/lib/nx-plugin/src/generators/app/files/template-angular-v19/vite.config.ts__template__ +2 -5
  133. package/src/lib/nx-plugin/src/generators/app/generator.d.ts +11 -11
  134. package/src/lib/nx-plugin/src/generators/app/generator.js +44 -37
  135. package/src/lib/nx-plugin/src/generators/app/generator.js.map +1 -1
  136. package/src/lib/nx-plugin/src/generators/app/lib/add-agent-context.d.ts +2 -0
  137. package/src/lib/nx-plugin/src/generators/app/lib/add-agent-context.js +16 -0
  138. package/src/lib/nx-plugin/src/generators/app/lib/add-agent-context.js.map +1 -0
  139. package/src/lib/nx-plugin/src/generators/app/lib/add-analog-dependencies.d.ts +1 -1
  140. package/src/lib/nx-plugin/src/generators/app/lib/add-analog-project-config.d.ts +1 -1
  141. package/src/lib/nx-plugin/src/generators/app/lib/add-analog-project-config.js +6 -5
  142. package/src/lib/nx-plugin/src/generators/app/lib/add-analog-project-config.js.map +1 -1
  143. package/src/lib/nx-plugin/src/generators/app/lib/add-angular-app.d.ts +2 -2
  144. package/src/lib/nx-plugin/src/generators/app/lib/add-angular-app.js +8 -11
  145. package/src/lib/nx-plugin/src/generators/app/lib/add-angular-app.js.map +1 -1
  146. package/src/lib/nx-plugin/src/generators/app/lib/add-eslint.d.ts +2 -2
  147. package/src/lib/nx-plugin/src/generators/app/lib/add-files.d.ts +2 -2
  148. package/src/lib/nx-plugin/src/generators/app/lib/add-files.js +6 -5
  149. package/src/lib/nx-plugin/src/generators/app/lib/add-files.js.map +1 -1
  150. package/src/lib/nx-plugin/src/generators/app/lib/add-home-page.d.ts +2 -2
  151. package/src/lib/nx-plugin/src/generators/app/lib/add-home-page.js +6 -5
  152. package/src/lib/nx-plugin/src/generators/app/lib/add-home-page.js.map +1 -1
  153. package/src/lib/nx-plugin/src/generators/app/lib/add-tailwind-config.d.ts +7 -7
  154. package/src/lib/nx-plugin/src/generators/app/lib/add-tailwind-config.js +13 -11
  155. package/src/lib/nx-plugin/src/generators/app/lib/add-tailwind-config.js.map +1 -1
  156. package/src/lib/nx-plugin/src/generators/app/lib/add-tailwind-helpers.d.ts +4 -5
  157. package/src/lib/nx-plugin/src/generators/app/lib/add-tailwind-helpers.js +34 -40
  158. package/src/lib/nx-plugin/src/generators/app/lib/add-tailwind-helpers.js.map +1 -1
  159. package/src/lib/nx-plugin/src/generators/app/lib/add-vite-plugin.d.ts +1 -1
  160. package/src/lib/nx-plugin/src/generators/app/lib/cleanup-files.d.ts +2 -2
  161. package/src/lib/nx-plugin/src/generators/app/lib/cleanup-files.js +1 -1
  162. package/src/lib/nx-plugin/src/generators/app/lib/cleanup-files.js.map +1 -1
  163. package/src/lib/nx-plugin/src/generators/app/lib/initialize-analog-workspace.d.ts +2 -2
  164. package/src/lib/nx-plugin/src/generators/app/lib/update-index-html.d.ts +1 -1
  165. package/src/lib/nx-plugin/src/generators/app/lib/update-index-html.js +5 -4
  166. package/src/lib/nx-plugin/src/generators/app/lib/update-index-html.js.map +1 -1
  167. package/src/lib/nx-plugin/src/generators/app/schema.d.ts +3 -0
  168. package/src/lib/nx-plugin/src/generators/app/schema.json +6 -0
  169. package/src/lib/nx-plugin/src/generators/app/versions/minimum-supported-versions.d.ts +4 -2
  170. package/src/lib/nx-plugin/src/generators/app/versions/minimum-supported-versions.js +9 -6
  171. package/src/lib/nx-plugin/src/generators/app/versions/minimum-supported-versions.js.map +1 -1
  172. package/src/lib/nx-plugin/src/generators/app/versions/nx-dependencies.d.ts +0 -3
  173. package/src/lib/nx-plugin/src/generators/app/versions/nx_17_X/versions.d.ts +1 -1
  174. package/src/lib/nx-plugin/src/generators/app/versions/nx_18_X/versions.d.ts +12 -12
  175. package/src/lib/nx-plugin/src/generators/app/versions/nx_18_X/versions.js +8 -27
  176. package/src/lib/nx-plugin/src/generators/app/versions/nx_18_X/versions.js.map +1 -1
  177. package/src/lib/nx-plugin/src/generators/app/versions/tailwind-dependencies.d.ts +1 -1
  178. package/src/lib/nx-plugin/src/generators/app/versions/tailwind-dependencies.js +6 -5
  179. package/src/lib/nx-plugin/src/generators/app/versions/tailwind-dependencies.js.map +1 -1
  180. package/src/lib/nx-plugin/src/generators/app/versions.d.ts +0 -18
  181. package/src/lib/nx-plugin/src/generators/init/compat.d.ts +9 -3
  182. package/src/lib/nx-plugin/src/generators/init/compat.js +15 -4
  183. package/src/lib/nx-plugin/src/generators/init/compat.js.map +1 -1
  184. package/src/lib/nx-plugin/src/generators/init/files/vite.config.ts__template__ +2 -6
  185. package/src/lib/nx-plugin/src/generators/init/generator.d.ts +3 -3
  186. package/src/lib/nx-plugin/src/generators/init/generator.js +35 -34
  187. package/src/lib/nx-plugin/src/generators/init/generator.js.map +1 -1
  188. package/src/lib/nx-plugin/src/generators/init/lib/add-analog-dependencies.d.ts +1 -1
  189. package/src/lib/nx-plugin/src/generators/init/lib/add-analog-dependencies.js +8 -7
  190. package/src/lib/nx-plugin/src/generators/init/lib/add-analog-dependencies.js.map +1 -1
  191. package/src/lib/nx-plugin/src/generators/init/lib/update-app-tsconfig.d.ts +2 -2
  192. package/src/lib/nx-plugin/src/generators/init/lib/update-app-tsconfig.js +6 -5
  193. package/src/lib/nx-plugin/src/generators/init/lib/update-app-tsconfig.js.map +1 -1
  194. package/src/lib/nx-plugin/src/generators/init/lib/update-build-target.d.ts +2 -2
  195. package/src/lib/nx-plugin/src/generators/init/lib/update-build-target.js +15 -14
  196. package/src/lib/nx-plugin/src/generators/init/lib/update-build-target.js.map +1 -1
  197. package/src/lib/nx-plugin/src/generators/init/lib/update-git-ignore.d.ts +1 -1
  198. package/src/lib/nx-plugin/src/generators/init/lib/update-git-ignore.js +1 -1
  199. package/src/lib/nx-plugin/src/generators/init/lib/update-git-ignore.js.map +1 -1
  200. package/src/lib/nx-plugin/src/generators/init/lib/update-index-html.d.ts +2 -2
  201. package/src/lib/nx-plugin/src/generators/init/lib/update-index-html.js +7 -6
  202. package/src/lib/nx-plugin/src/generators/init/lib/update-index-html.js.map +1 -1
  203. package/src/lib/nx-plugin/src/generators/init/lib/update-main.d.ts +2 -2
  204. package/src/lib/nx-plugin/src/generators/init/lib/update-main.js +5 -4
  205. package/src/lib/nx-plugin/src/generators/init/lib/update-main.js.map +1 -1
  206. package/src/lib/nx-plugin/src/generators/init/lib/update-package-json.d.ts +2 -2
  207. package/src/lib/nx-plugin/src/generators/init/lib/update-package-json.js +9 -8
  208. package/src/lib/nx-plugin/src/generators/init/lib/update-package-json.js.map +1 -1
  209. package/src/lib/nx-plugin/src/generators/init/lib/update-serve-target.d.ts +2 -2
  210. package/src/lib/nx-plugin/src/generators/init/lib/update-serve-target.js +6 -5
  211. package/src/lib/nx-plugin/src/generators/init/lib/update-serve-target.js.map +1 -1
  212. package/src/lib/nx-plugin/src/generators/init/lib/update-test-target.d.ts +2 -2
  213. package/src/lib/nx-plugin/src/generators/init/lib/update-test-target.js +6 -5
  214. package/src/lib/nx-plugin/src/generators/init/lib/update-test-target.js.map +1 -1
  215. package/src/lib/nx-plugin/src/generators/init/lib/update-test-tsconfig.d.ts +2 -2
  216. package/src/lib/nx-plugin/src/generators/init/lib/update-test-tsconfig.js +6 -5
  217. package/src/lib/nx-plugin/src/generators/init/lib/update-test-tsconfig.js.map +1 -1
  218. package/src/lib/nx-plugin/src/generators/init/test-files/src/test-setup.ts__template__ +1 -0
  219. package/src/lib/nx-plugin/src/generators/page/__snapshots__/generator.spec.ts.snap +0 -7
  220. package/src/lib/nx-plugin/src/generators/page/compat.d.ts +9 -0
  221. package/src/lib/nx-plugin/src/generators/page/compat.js +19 -0
  222. package/src/lib/nx-plugin/src/generators/page/compat.js.map +1 -0
  223. package/src/lib/nx-plugin/src/generators/page/files/__fileName__.page.ts__template__ +0 -1
  224. package/src/lib/nx-plugin/src/generators/page/generator.d.ts +3 -4
  225. package/src/lib/nx-plugin/src/generators/page/generator.js +14 -13
  226. package/src/lib/nx-plugin/src/generators/page/generator.js.map +1 -1
  227. package/src/lib/nx-plugin/src/generators/preset/__snapshots__/generator.spec.ts.snap +9 -7
  228. package/src/lib/nx-plugin/src/generators/preset/generator.d.ts +3 -3
  229. package/src/lib/nx-plugin/src/generators/preset/generator.js +24 -7
  230. package/src/lib/nx-plugin/src/generators/preset/generator.js.map +1 -1
  231. package/src/lib/nx-plugin/src/generators/preset/schema.d.ts +1 -0
  232. package/src/lib/nx-plugin/src/generators/preset/schema.json +6 -0
  233. package/src/lib/nx-plugin/src/generators/setup-vitest/compat.d.ts +9 -3
  234. package/src/lib/nx-plugin/src/generators/setup-vitest/compat.js +15 -4
  235. package/src/lib/nx-plugin/src/generators/setup-vitest/compat.js.map +1 -1
  236. package/src/lib/nx-plugin/src/generators/setup-vitest/files/src/test-setup.ts__template__ +1 -0
  237. package/src/lib/nx-plugin/src/generators/setup-vitest/files/vite.config.mts__template__ +0 -6
  238. package/src/lib/nx-plugin/src/generators/setup-vitest/generator.d.ts +3 -3
  239. package/src/lib/nx-plugin/src/generators/setup-vitest/generator.js +19 -21
  240. package/src/lib/nx-plugin/src/generators/setup-vitest/generator.js.map +1 -1
  241. package/src/lib/nx-plugin/src/generators/setup-vitest/lib/add-analog-dependencies.d.ts +1 -1
  242. package/src/lib/nx-plugin/src/generators/setup-vitest/lib/add-analog-dependencies.js +5 -4
  243. package/src/lib/nx-plugin/src/generators/setup-vitest/lib/add-analog-dependencies.js.map +1 -1
  244. package/src/lib/nx-plugin/src/generators/setup-vitest/lib/update-test-target.d.ts +2 -2
  245. package/src/lib/nx-plugin/src/generators/setup-vitest/lib/update-test-target.js +6 -5
  246. package/src/lib/nx-plugin/src/generators/setup-vitest/lib/update-test-target.js.map +1 -1
  247. package/src/lib/nx-plugin/src/generators/setup-vitest/lib/update-tsconfig.d.ts +2 -2
  248. package/src/lib/nx-plugin/src/generators/setup-vitest/lib/update-tsconfig.js +6 -5
  249. package/src/lib/nx-plugin/src/generators/setup-vitest/lib/update-tsconfig.js.map +1 -1
  250. package/src/lib/nx-plugin/src/utils/version-utils.d.ts +1 -1
  251. package/src/lib/nx-plugin/src/utils/version-utils.js +9 -8
  252. package/src/lib/nx-plugin/src/utils/version-utils.js.map +1 -1
  253. package/src/lib/nx-plugin/src/utils/versions/dependencies.js +33 -32
  254. package/src/lib/nx-plugin/src/utils/versions/dependencies.js.map +1 -1
  255. package/src/lib/nx-plugin/src/utils/versions/dev-dependencies.js +40 -39
  256. package/src/lib/nx-plugin/src/utils/versions/dev-dependencies.js.map +1 -1
  257. package/src/lib/nx-plugin/src/utils/versions/ng_17_X/versions.d.ts +1 -1
  258. package/src/lib/nx-plugin/src/utils/versions/ng_17_X/versions.js +16 -2
  259. package/src/lib/nx-plugin/src/utils/versions/ng_17_X/versions.js.map +1 -1
  260. package/src/lib/nx-plugin/src/utils/versions/ng_18_X/versions.d.ts +1 -1
  261. package/src/lib/nx-plugin/src/utils/versions/ng_18_X/versions.js +16 -2
  262. package/src/lib/nx-plugin/src/utils/versions/ng_18_X/versions.js.map +1 -1
  263. package/src/lib/nx-plugin/src/utils/versions/ng_19_X/versions.d.ts +9 -8
  264. package/src/lib/nx-plugin/src/utils/versions/ng_19_X/versions.js +27 -10
  265. package/src/lib/nx-plugin/src/utils/versions/ng_19_X/versions.js.map +1 -1
  266. package/src/lib/options.d.ts +165 -84
  267. package/src/lib/platform-plugin.d.ts +2 -2
  268. package/src/lib/platform-plugin.js +20 -34
  269. package/src/lib/platform-plugin.js.map +1 -1
  270. package/src/lib/route-file-discovery.d.ts +23 -0
  271. package/src/lib/route-file-discovery.js +114 -0
  272. package/src/lib/route-file-discovery.js.map +1 -0
  273. package/src/lib/route-generation-plugin.d.ts +3 -0
  274. package/src/lib/route-generation-plugin.js +45 -0
  275. package/src/lib/route-generation-plugin.js.map +1 -0
  276. package/src/lib/route-idiom-diagnostics.d.ts +13 -0
  277. package/src/lib/route-idiom-diagnostics.js +160 -0
  278. package/src/lib/route-idiom-diagnostics.js.map +1 -0
  279. package/src/lib/route-manifest.d.ts +122 -0
  280. package/src/lib/route-manifest.js +431 -0
  281. package/src/lib/route-manifest.js.map +1 -0
  282. package/src/lib/router-plugin.d.ts +19 -19
  283. package/src/lib/router-plugin.js +127 -33
  284. package/src/lib/router-plugin.js.map +1 -1
  285. package/src/lib/server-fn-client-transform.d.ts +26 -0
  286. package/src/lib/server-fn-client-transform.js +97 -0
  287. package/src/lib/server-fn-client-transform.js.map +1 -0
  288. package/src/lib/server-fn-id.d.ts +25 -0
  289. package/src/lib/server-fn-id.js +37 -0
  290. package/src/lib/server-fn-id.js.map +1 -0
  291. package/src/lib/ssr/defer-streaming-plugin.d.ts +65 -0
  292. package/src/lib/ssr/inject-html-plugin.d.ts +1 -1
  293. package/src/lib/ssr/inject-html-plugin.js.map +1 -1
  294. package/src/lib/ssr/ssr-build-plugin.d.ts +24 -16
  295. package/src/lib/ssr/ssr-build-plugin.js +2 -18
  296. package/src/lib/ssr/ssr-build-plugin.js.map +1 -1
  297. package/src/lib/typed-routes-plugin.d.ts +50 -0
  298. package/src/lib/typed-routes-plugin.js +234 -0
  299. package/src/lib/typed-routes-plugin.js.map +1 -0
  300. package/src/lib/utils/debug-harness.d.ts +23 -0
  301. package/src/lib/utils/debug-harness.js +88 -0
  302. package/src/lib/utils/debug-harness.js.map +1 -0
  303. package/src/lib/utils/debug-log-file.d.ts +5 -0
  304. package/src/lib/utils/debug-log-file.js +56 -0
  305. package/src/lib/utils/debug-log-file.js.map +1 -0
  306. package/src/lib/utils/debug.d.ts +20 -0
  307. package/src/lib/utils/debug.js +24 -0
  308. package/src/lib/utils/debug.js.map +1 -0
  309. package/src/lib/utils/rolldown.d.ts +2 -2
  310. package/src/lib/utils/rolldown.js.map +1 -1
  311. package/src/server-mode-plugin.d.ts +11 -5
  312. package/src/server-mode-plugin.js +16 -6
  313. package/src/server-mode-plugin.js.map +1 -1
  314. package/src/lib/nx-plugin/src/executors/vite/compat.d.ts +0 -3
  315. package/src/lib/nx-plugin/src/executors/vite/compat.js +0 -8
  316. package/src/lib/nx-plugin/src/executors/vite/compat.js.map +0 -1
  317. package/src/lib/nx-plugin/src/executors/vite/schema.d.ts +0 -2
  318. package/src/lib/nx-plugin/src/executors/vite/schema.json +0 -147
  319. package/src/lib/nx-plugin/src/executors/vite/vite.impl.d.ts +0 -2
  320. package/src/lib/nx-plugin/src/executors/vite/vite.impl.js +0 -7
  321. package/src/lib/nx-plugin/src/executors/vite/vite.impl.js.map +0 -1
  322. package/src/lib/nx-plugin/src/generators/app/files/tailwind/v4/.postcssrc.json +0 -5
  323. package/src/lib/nx-plugin/src/generators/app/files/tailwind/v4/tailwind.config.ts__template__ +0 -14
  324. package/src/lib/nx-plugin/src/generators/app/files/template-angular-v15/index.html__template__ +0 -15
  325. package/src/lib/nx-plugin/src/generators/app/files/template-angular-v15/src/app/app.component.spec.ts__template__ +0 -17
  326. package/src/lib/nx-plugin/src/generators/app/files/template-angular-v15/src/app/app.component.ts__template__ +0 -10
  327. package/src/lib/nx-plugin/src/generators/app/files/template-angular-v15/src/favicon.ico__template__ +0 -0
  328. package/src/lib/nx-plugin/src/generators/app/files/template-angular-v15/src/main.providers.ts__template__ +0 -5
  329. package/src/lib/nx-plugin/src/generators/app/files/template-angular-v15/src/main.server.ts__template__ +0 -23
  330. package/src/lib/nx-plugin/src/generators/app/files/template-angular-v15/src/main.ts__template__ +0 -11
  331. package/src/lib/nx-plugin/src/generators/app/files/template-angular-v15/src/public/assets/.gitkeep__template__ +0 -0
  332. package/src/lib/nx-plugin/src/generators/app/files/template-angular-v15/src/public/assets/analog.svg__template__ +0 -1
  333. package/src/lib/nx-plugin/src/generators/app/files/template-angular-v15/src/public/assets/vite.svg__template__ +0 -1
  334. package/src/lib/nx-plugin/src/generators/app/files/template-angular-v15/src/server/routes/v1/hello.ts__template__ +0 -3
  335. package/src/lib/nx-plugin/src/generators/app/files/template-angular-v15/src/styles.css__template__ +0 -4
  336. package/src/lib/nx-plugin/src/generators/app/files/template-angular-v15/src/test-setup.ts__template__ +0 -12
  337. package/src/lib/nx-plugin/src/generators/app/files/template-angular-v15/src/vite-env.d.ts__template__ +0 -1
  338. package/src/lib/nx-plugin/src/generators/app/files/template-angular-v15/tsconfig.app.json__template__ +0 -16
  339. package/src/lib/nx-plugin/src/generators/app/files/template-angular-v15/tsconfig.editor.json__template__ +0 -7
  340. package/src/lib/nx-plugin/src/generators/app/files/template-angular-v15/tsconfig.json__template__ +0 -32
  341. package/src/lib/nx-plugin/src/generators/app/files/template-angular-v15/tsconfig.spec.json__template__ +0 -14
  342. package/src/lib/nx-plugin/src/generators/app/files/template-angular-v15/vite.config.ts__template__ +0 -61
  343. package/src/lib/nx-plugin/src/generators/app/lib/add-analog-dependencies.js +0 -14
  344. package/src/lib/nx-plugin/src/generators/app/lib/add-analog-dependencies.js.map +0 -1
  345. package/src/lib/nx-plugin/src/generators/app/lib/add-eslint.js +0 -15
  346. package/src/lib/nx-plugin/src/generators/app/lib/add-eslint.js.map +0 -1
  347. package/src/lib/nx-plugin/src/generators/app/lib/add-vite-plugin.js +0 -11
  348. package/src/lib/nx-plugin/src/generators/app/lib/add-vite-plugin.js.map +0 -1
  349. package/src/lib/nx-plugin/src/generators/app/lib/initialize-analog-workspace.js +0 -64
  350. package/src/lib/nx-plugin/src/generators/app/lib/initialize-analog-workspace.js.map +0 -1
  351. package/src/lib/nx-plugin/src/generators/app/versions/dependencies.js +0 -37
  352. package/src/lib/nx-plugin/src/generators/app/versions/dependencies.js.map +0 -1
  353. package/src/lib/nx-plugin/src/generators/app/versions/dev-dependencies.js +0 -45
  354. package/src/lib/nx-plugin/src/generators/app/versions/dev-dependencies.js.map +0 -1
  355. package/src/lib/nx-plugin/src/generators/app/versions/nx-dependencies.js +0 -27
  356. package/src/lib/nx-plugin/src/generators/app/versions/nx-dependencies.js.map +0 -1
  357. package/src/lib/nx-plugin/src/generators/app/versions/nx_17_X/versions.js +0 -30
  358. package/src/lib/nx-plugin/src/generators/app/versions/nx_17_X/versions.js.map +0 -1
  359. package/src/lib/nx-plugin/src/generators/app/versions.js +0 -29
  360. package/src/lib/nx-plugin/src/generators/app/versions.js.map +0 -1
  361. package/src/lib/nx-plugin/src/index.d.ts +0 -0
@@ -1,21 +1,21 @@
1
- import { Plugin } from 'vite';
2
- import { Options } from './options.js';
1
+ import { Plugin } from "vite";
2
+ import { Options } from "./options.js";
3
3
  /**
4
- * Router plugin that handles route file discovery and hot module replacement.
5
- *
6
- * This plugin provides three main functionalities:
7
- * 1. Route invalidation when files are added/deleted (HMR workaround)
8
- * 2. Dynamic route file discovery and import generation
9
- * 3. Content route file discovery for markdown and Analog content
10
- *
11
- * @param options Configuration options for the router plugin
12
- * @returns Array of Vite plugins for route handling
13
- *
14
- * IMPORTANT: This plugin uses tinyglobby for file discovery.
15
- * Key behavior with { dot: true, absolute: true }:
16
- * - Returns absolute paths for ALL discovered files
17
- * - Path normalization is required to match expected output format
18
- * - Files within project root must use relative paths in object keys
19
- * - Files outside project root keep absolute paths in object keys
20
- */
4
+ * Router plugin that handles route file discovery and hot module replacement.
5
+ *
6
+ * This plugin provides three main functionalities:
7
+ * 1. Route invalidation when files are added/deleted (HMR workaround)
8
+ * 2. Dynamic route file discovery and import generation
9
+ * 3. Content route file discovery for markdown and Analog content
10
+ *
11
+ * @param options Configuration options for the router plugin
12
+ * @returns Array of Vite plugins for route handling
13
+ *
14
+ * IMPORTANT: This plugin uses tinyglobby for file discovery.
15
+ * Key behavior with { dot: true, absolute: true }:
16
+ * - Returns absolute paths for ALL discovered files
17
+ * - Path normalization is required to match expected output format
18
+ * - Files within project root must use relative paths in object keys
19
+ * - Files outside project root keep absolute paths in object keys
20
+ */
21
21
  export declare function routerPlugin(options?: Options): Plugin[];
@@ -1,6 +1,8 @@
1
+ import { analyzeAnalogRouteFile, formatAnalogRouteIdiomDiagnostic } from "./route-idiom-diagnostics.js";
2
+ import { isAbsolute, relative, resolve } from "node:path";
3
+ import { readFileSync } from "node:fs";
1
4
  import { normalizePath } from "vite";
2
5
  import { globSync } from "tinyglobby";
3
- import { resolve } from "node:path";
4
6
  //#region packages/platform/src/lib/router-plugin.ts
5
7
  /**
6
8
  * Router plugin that handles route file discovery and hot module replacement.
@@ -21,10 +23,105 @@ import { resolve } from "node:path";
21
23
  * - Files outside project root keep absolute paths in object keys
22
24
  */
23
25
  function routerPlugin(options) {
24
- const workspaceRoot = normalizePath(options?.workspaceRoot ?? process.cwd());
26
+ const workspaceRoot = normalizePath(options?.workspaceRoot ?? process.env["NX_WORKSPACE_ROOT"] ?? process.cwd());
25
27
  let config;
26
28
  let root;
27
- const isRouteLikeFile = (path) => path.includes(`routes`) || path.includes(`pages`) || path.includes("content");
29
+ const normalizeWatchedDir = (dir) => {
30
+ const normalizedDir = normalizePath(dir.startsWith(`${workspaceRoot}/`) || dir === workspaceRoot ? dir : dir.startsWith("/") ? `${workspaceRoot}${dir}` : resolve(workspaceRoot, dir));
31
+ return normalizedDir.endsWith("/") ? normalizedDir.slice(0, -1) : normalizedDir;
32
+ };
33
+ const additionalPagesDirs = (options?.additionalPagesDirs || []).map((dir) => normalizeWatchedDir(dir));
34
+ const additionalContentDirs = (options?.additionalContentDirs || []).map((dir) => normalizeWatchedDir(dir));
35
+ const getRouteLikeDirs = () => [
36
+ ...root ? [
37
+ normalizeWatchedDir(`${root}/app/routes`),
38
+ normalizeWatchedDir(`${root}/src/app/routes`),
39
+ normalizeWatchedDir(`${root}/src/app/pages`),
40
+ normalizeWatchedDir(`${root}/src/content`)
41
+ ] : [],
42
+ "/app/routes",
43
+ "/src/app/routes",
44
+ "/src/app/pages",
45
+ "/src/content",
46
+ ...additionalPagesDirs,
47
+ ...additionalContentDirs
48
+ ];
49
+ let routeFilesCache;
50
+ let pageRouteFilesCache;
51
+ let contentRouteFilesCache;
52
+ let endpointFilesCache;
53
+ const routeDiagnosticCache = /* @__PURE__ */ new Map();
54
+ const isRouteLikeFile = (path) => {
55
+ const normalizedPath = normalizePath(path);
56
+ return getRouteLikeDirs().some((dir) => normalizedPath === dir || normalizedPath.startsWith(`${dir}/`));
57
+ };
58
+ const discoverRouteFiles = () => {
59
+ routeFilesCache ??= globSync([
60
+ `${root}/app/routes/**/*.ts`,
61
+ `${root}/src/app/routes/**/*.ts`,
62
+ `${root}/src/app/pages/**/*.page.ts`,
63
+ ...additionalPagesDirs.map((dir) => `${dir}/**/*.page.ts`)
64
+ ], {
65
+ dot: true,
66
+ absolute: true
67
+ });
68
+ return routeFilesCache;
69
+ };
70
+ const discoverContentRouteFiles = () => {
71
+ contentRouteFilesCache ??= globSync([
72
+ `${root}/src/app/routes/**/*.md`,
73
+ `${root}/src/app/pages/**/*.md`,
74
+ `${root}/src/content/**/*.md`,
75
+ ...additionalContentDirs.map((dir) => `${dir}/**/*.md`)
76
+ ], {
77
+ dot: true,
78
+ absolute: true
79
+ });
80
+ return contentRouteFilesCache;
81
+ };
82
+ const discoverEndpointFiles = () => {
83
+ endpointFilesCache ??= globSync([`${root}/src/app/pages/**/*.server.ts`, ...additionalPagesDirs.map((dir) => `${dir}/**/*.server.ts`)], {
84
+ dot: true,
85
+ absolute: true
86
+ });
87
+ return endpointFilesCache;
88
+ };
89
+ const discoverPageRouteFiles = () => {
90
+ pageRouteFilesCache ??= discoverRouteFiles().filter((file) => file.endsWith(".page.ts"));
91
+ return pageRouteFilesCache;
92
+ };
93
+ const invalidateDiscoveryCaches = () => {
94
+ routeFilesCache = void 0;
95
+ pageRouteFilesCache = void 0;
96
+ contentRouteFilesCache = void 0;
97
+ endpointFilesCache = void 0;
98
+ };
99
+ const reportRouteDiagnostics = (path) => {
100
+ if (!path.endsWith(".page.ts")) return;
101
+ try {
102
+ const rendered = analyzeAnalogRouteFile({
103
+ filename: path,
104
+ code: readFileSync(path, "utf-8"),
105
+ routeFiles: discoverPageRouteFiles()
106
+ }).map((diagnostic) => formatAnalogRouteIdiomDiagnostic(diagnostic, path, workspaceRoot));
107
+ const fingerprint = rendered.join("\n\n");
108
+ if (!fingerprint) {
109
+ routeDiagnosticCache.delete(path);
110
+ return;
111
+ }
112
+ if (routeDiagnosticCache.get(path) === fingerprint) return;
113
+ routeDiagnosticCache.set(path, fingerprint);
114
+ rendered.forEach((message) => console.warn(message));
115
+ } catch {
116
+ routeDiagnosticCache.delete(path);
117
+ }
118
+ };
119
+ const getModuleKey = (module) => {
120
+ if (!root) return `/${normalizePath(relative(workspaceRoot, module))}`;
121
+ const relToRoot = normalizePath(relative(root, module));
122
+ if (!relToRoot.startsWith("..") && !isAbsolute(relToRoot)) return `/${relToRoot}`;
123
+ return `/${normalizePath(relative(workspaceRoot, module))}`;
124
+ };
28
125
  const invalidateFileModules = (server, path) => {
29
126
  const normalizedPath = normalizePath(path);
30
127
  (server.moduleGraph.getModulesByFile?.(normalizedPath) ?? server.moduleGraph.fileToModulesMap.get(normalizedPath))?.forEach((mod) => {
@@ -44,9 +141,16 @@ function routerPlugin(options) {
44
141
  *
45
142
  * @param path The file path that was added or deleted
46
143
  */
47
- function invalidateRoutes(path) {
144
+ function invalidateRoutes(path, event) {
48
145
  if (!isRouteLikeFile(path)) return;
146
+ if (event !== "change") invalidateDiscoveryCaches();
147
+ if (event === "change") reportRouteDiagnostics(path);
148
+ else if (event === "unlink") {
149
+ routeDiagnosticCache.delete(path);
150
+ discoverPageRouteFiles().forEach((file) => reportRouteDiagnostics(file));
151
+ } else discoverPageRouteFiles().forEach((file) => reportRouteDiagnostics(file));
49
152
  invalidateFileModules(server, path);
153
+ if (event === "change") return;
50
154
  server.moduleGraph.fileToModulesMap.forEach((mods) => {
51
155
  mods.forEach((mod) => {
52
156
  if (mod.id?.includes("analogjs") && mod.id?.includes("fesm")) {
@@ -57,11 +161,19 @@ function routerPlugin(options) {
57
161
  }
58
162
  });
59
163
  });
164
+ server.ws.send("analog:debug-full-reload", {
165
+ plugin: "platform:router-plugin",
166
+ reason: "route-graph-shape-changed",
167
+ event,
168
+ path
169
+ });
60
170
  server.ws.send({ type: "full-reload" });
61
171
  }
62
- server.watcher.on("add", invalidateRoutes);
63
- server.watcher.on("change", invalidateRoutes);
64
- server.watcher.on("unlink", invalidateRoutes);
172
+ server.watcher.on("add", (path) => invalidateRoutes(path, "add"));
173
+ server.watcher.on("change", (path) => invalidateRoutes(path, "change"));
174
+ server.watcher.on("unlink", (path) => invalidateRoutes(path, "unlink"));
175
+ for (const dir of [...additionalPagesDirs, ...additionalContentDirs]) server.watcher.add(dir);
176
+ discoverPageRouteFiles().forEach((file) => reportRouteDiagnostics(file));
65
177
  }
66
178
  },
67
179
  {
@@ -72,37 +184,22 @@ function routerPlugin(options) {
72
184
  root = normalizePath(resolve(workspaceRoot, config.root || ".") || ".");
73
185
  },
74
186
  transform: {
75
- filter: { code: "ANALOG_ROUTE_FILES" },
187
+ filter: { code: "_ROUTE_FILES" },
76
188
  handler(code) {
77
189
  if (code.includes("ANALOG_ROUTE_FILES") || code.includes("ANALOG_CONTENT_ROUTE_FILES")) {
78
- const routeFiles = globSync([
79
- `${root}/app/routes/**/*.ts`,
80
- `${root}/src/app/routes/**/*.ts`,
81
- `${root}/src/app/pages/**/*.page.ts`,
82
- ...(options?.additionalPagesDirs || []).map((glob) => `${workspaceRoot}${glob}/**/*.page.ts`)
83
- ], {
84
- dot: true,
85
- absolute: true
86
- });
87
- const contentRouteFiles = globSync([
88
- `${root}/src/app/routes/**/*.md`,
89
- `${root}/src/app/pages/**/*.md`,
90
- `${root}/src/content/**/*.md`,
91
- ...(options?.additionalContentDirs || []).map((glob) => `${workspaceRoot}${glob}/**/*.md`)
92
- ], {
93
- dot: true,
94
- absolute: true
95
- });
190
+ const routeFiles = discoverRouteFiles();
191
+ const contentRouteFiles = discoverContentRouteFiles();
96
192
  let result = code.replace("ANALOG_ROUTE_FILES = {};", `
97
193
  ANALOG_ROUTE_FILES = {${routeFiles.map((module) => {
98
- return `"${module.startsWith(root) ? module.replace(root, "") : module}": () => import('${module}')`;
194
+ return `"${getModuleKey(module)}": () => import('${module}')`;
99
195
  })}};
100
196
  `);
101
197
  result = result.replace("ANALOG_CONTENT_ROUTE_FILES = {};", `
102
198
  ANALOG_CONTENT_ROUTE_FILES = {${contentRouteFiles.map((module) => {
103
- return `"${module.startsWith(root) ? module.replace(root, "") : module}": () => import('${module}?analog-content-file=true').then(m => m.default)`;
199
+ return `"${getModuleKey(module)}": () => import('${module}?analog-content-file=true').then(m => m.default)`;
104
200
  })}};
105
201
  `);
202
+ result = result.replace("ANALOG_CONTENT_FILE_COUNT = 0", `ANALOG_CONTENT_FILE_COUNT = ${contentRouteFiles.length}`);
106
203
  return {
107
204
  code: result,
108
205
  map: { mappings: "" }
@@ -118,14 +215,11 @@ function routerPlugin(options) {
118
215
  filter: { code: "ANALOG_PAGE_ENDPOINTS" },
119
216
  handler(code) {
120
217
  if (code.includes("ANALOG_PAGE_ENDPOINTS")) {
121
- const endpointFiles = globSync([`${root}/src/app/pages/**/*.server.ts`, ...(options?.additionalPagesDirs || []).map((glob) => `${workspaceRoot}${glob}/**/*.server.ts`)], {
122
- dot: true,
123
- absolute: true
124
- });
218
+ const endpointFiles = discoverEndpointFiles();
125
219
  return {
126
220
  code: code.replace("ANALOG_PAGE_ENDPOINTS = {};", `
127
221
  ANALOG_PAGE_ENDPOINTS = {${endpointFiles.map((module) => {
128
- return `"${module.startsWith(root) ? module.replace(root, "") : module}": () => import('${module}')`;
222
+ return `"${getModuleKey(module)}": () => import('${module}')`;
129
223
  })}};
130
224
  `),
131
225
  map: { mappings: "" }
@@ -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;GACE,MAAM;GACN,gBAAgB,QAAQ;;;;;;;IAOtB,SAAS,iBAAiB,MAAc;AACtC,SAAI,CAAC,gBAAgB,KAAK,CACxB;AAGF,2BAAsB,QAAQ,KAAK;AAEnC,YAAO,YAAY,iBAAiB,SAAS,SAAS;AACpD,WAAK,SAAS,QAAQ;AACpB,WAAI,IAAI,IAAI,SAAS,WAAW,IAAI,IAAI,IAAI,SAAS,OAAO,EAAE;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,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,GAAG,GAAG,GAC1B;;CAIN,MAAM,uBAAuB,SAAS,uBAAuB,EAAE,EAAE,KAAK,QACpE,oBAAoB,IAAI,CACzB;CACD,MAAM,yBAAyB,SAAS,yBAAyB,EAAE,EAAE,KAClE,QAAQ,oBAAoB,IAAI,CAClC;CAMD,MAAM,yBAAyB;EAC7B,GAAI,OACA;GACE,oBAAoB,GAAG,KAAK,aAAa;GACzC,oBAAoB,GAAG,KAAK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AW;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,OAAK,MAAM,cAAc,KAAK,YAAY,cAAc;AACtD,OACE,WAAW,IAAI,SAAS,gBACxB,WAAW,MAAM,SAAS,oBAC1B,WAAW,KAAK,QAAQ,SAAS,gBACjC,CAAC,mBAAmB,IAAI,WAAW,KAAK,OAAO,KAAK,CAEpD;AAEF,WAAQ,KACN,QAAQ,WAAW,GAAG,MAAM,WAAW,KAAK,aAAa,EAAE,EAAE,OAAO,CACrE;;;CASL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AAK,IAAI,OAAO,KAAK,KAAK;AAC9D,OAAI,QAAQ,YAAY,gBAAgB,KAAK,MAAM,CACjD,UAAS,KAAK,MAAM;YACX,QAAQ,QACjB,YAAW;;AAGf,MAAI,WAAW,SAAS,SACtB,OAAM,IAAI,MACR,sBAAsB,KAAK,OAAO,OAAO,gGAC1C;AAEH,SAAO,WAAW,WAAW,SAAS;;AAIxC,KAAI,QAAQ,KAAK,UAAU,EAAG,QAAO;AAErC,OAAM,IAAI,MACR,sBAAsB,KAAK,OAAO,OAAO,gGAC1C;;AAGH,SAAS,eAAe,MAAoB;AAC1C,QACE,MAAM,SAAS,6BACf,MAAM,SAAS;;AAInB,SAAS,gBACP,MAC4C;AAC5C,QAAO,MAAM,SAAS,aAAa,OAAO,KAAK,UAAU;;;AAI3D,SAAS,mBAAmB,MAAe,OAA4B;AACrE,KAAI,CAAC,QAAQ,OAAO,SAAS,SAC3B,QAAO;AAET,KAAI,MAAM,QAAQ,KAAK,CACrB,QAAO,KAAK,QACT,OAAO,UAAU,QAAQ,mBAAmB,OAAO,MAAM,EAC1D,EACD;CAGH,MAAM,SAAS;CACf,IAAI,QAAQ;AACZ,KAAI,OAAO,SAAS,kBAAkB;EACpC,MAAM,SAAS,OAAO;AACtB,MACE,QAAQ,SAAS,gBACjB,OAAO,QACP,MAAM,IAAI,OAAO,KAAK,CAEtB,UAAS;;AAGb,MAAK,MAAM,OAAO,OAAO,KAAK,OAAO,CACnC,UAAS,mBAAmB,OAAO,MAAM,MAAM;AAEjD,QAAO"}
@@ -0,0 +1,25 @@
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[];