@nativescript/vite 8.0.0-beta.0 → 8.0.0-rc.0

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 (577) hide show
  1. package/README.md +73 -14
  2. package/bin/cli.cjs +8 -14
  3. package/configuration/angular.d.ts +35 -2
  4. package/configuration/angular.js +541 -216
  5. package/configuration/angular.js.map +1 -1
  6. package/configuration/base.js +227 -77
  7. package/configuration/base.js.map +1 -1
  8. package/configuration/javascript.js +17 -96
  9. package/configuration/javascript.js.map +1 -1
  10. package/configuration/react.js +41 -73
  11. package/configuration/react.js.map +1 -1
  12. package/configuration/solid.js +58 -6
  13. package/configuration/solid.js.map +1 -1
  14. package/configuration/typescript.js +15 -96
  15. package/configuration/typescript.js.map +1 -1
  16. package/helpers/app-components.d.ts +2 -1
  17. package/helpers/app-components.js.map +1 -1
  18. package/helpers/app-css-refresh.d.ts +31 -0
  19. package/helpers/app-css-refresh.js +43 -0
  20. package/helpers/app-css-refresh.js.map +1 -0
  21. package/helpers/app-css-state.d.ts +17 -0
  22. package/helpers/app-css-state.js +51 -0
  23. package/helpers/app-css-state.js.map +1 -0
  24. package/helpers/bundler-context.d.ts +11 -0
  25. package/helpers/bundler-context.js +71 -0
  26. package/helpers/bundler-context.js.map +1 -0
  27. package/helpers/cli-flags.d.ts +12 -0
  28. package/helpers/cli-flags.js +34 -0
  29. package/helpers/cli-flags.js.map +1 -1
  30. package/helpers/commonjs-plugins.d.ts +5 -2
  31. package/helpers/commonjs-plugins.js +126 -0
  32. package/helpers/commonjs-plugins.js.map +1 -1
  33. package/helpers/config-as-json.js +10 -0
  34. package/helpers/config-as-json.js.map +1 -1
  35. package/helpers/css-platform-plugin.d.ts +14 -0
  36. package/helpers/css-platform-plugin.js +43 -25
  37. package/helpers/css-platform-plugin.js.map +1 -1
  38. package/helpers/dev-host.d.ts +360 -0
  39. package/helpers/dev-host.js +694 -0
  40. package/helpers/dev-host.js.map +1 -0
  41. package/helpers/dynamic-import-plugin.d.ts +2 -1
  42. package/helpers/dynamic-import-plugin.js +59 -53
  43. package/helpers/dynamic-import-plugin.js.map +1 -1
  44. package/helpers/esbuild-platform-resolver.js +9 -6
  45. package/helpers/esbuild-platform-resolver.js.map +1 -1
  46. package/helpers/external-configs.d.ts +10 -4
  47. package/helpers/external-configs.js +63 -15
  48. package/helpers/external-configs.js.map +1 -1
  49. package/helpers/flavor.d.ts +13 -0
  50. package/helpers/flavor.js +18 -1
  51. package/helpers/flavor.js.map +1 -1
  52. package/helpers/global-defines.d.ts +117 -0
  53. package/helpers/global-defines.js +209 -11
  54. package/helpers/global-defines.js.map +1 -1
  55. package/helpers/hmr-scope.d.ts +26 -0
  56. package/helpers/hmr-scope.js +67 -0
  57. package/helpers/hmr-scope.js.map +1 -0
  58. package/helpers/import-meta-path.d.ts +4 -0
  59. package/helpers/import-meta-path.js +5 -0
  60. package/helpers/import-meta-path.js.map +1 -0
  61. package/helpers/import-specifier.d.ts +1 -0
  62. package/helpers/import-specifier.js +18 -0
  63. package/helpers/import-specifier.js.map +1 -0
  64. package/helpers/init.js +6 -20
  65. package/helpers/init.js.map +1 -1
  66. package/helpers/logging.d.ts +1 -0
  67. package/helpers/logging.js +65 -4
  68. package/helpers/logging.js.map +1 -1
  69. package/helpers/main-entry.d.ts +8 -2
  70. package/helpers/main-entry.js +622 -120
  71. package/helpers/main-entry.js.map +1 -1
  72. package/helpers/nativeclass-esbuild-plugin.d.ts +2 -1
  73. package/helpers/nativeclass-esbuild-plugin.js +6 -1
  74. package/helpers/nativeclass-esbuild-plugin.js.map +1 -1
  75. package/helpers/nativeclass-transform.d.ts +13 -0
  76. package/helpers/nativeclass-transform.js +42 -131
  77. package/helpers/nativeclass-transform.js.map +1 -1
  78. package/helpers/nativeclass-transformer-plugin.d.ts +19 -1
  79. package/helpers/nativeclass-transformer-plugin.js +324 -37
  80. package/helpers/nativeclass-transformer-plugin.js.map +1 -1
  81. package/helpers/nativescript-package-resolver.js +10 -62
  82. package/helpers/nativescript-package-resolver.js.map +1 -1
  83. package/helpers/normalize-id.d.ts +42 -0
  84. package/helpers/normalize-id.js +60 -0
  85. package/helpers/normalize-id.js.map +1 -0
  86. package/helpers/ns-core-external-urls.d.ts +32 -0
  87. package/helpers/ns-core-external-urls.js +107 -0
  88. package/helpers/ns-core-external-urls.js.map +1 -0
  89. package/helpers/ns-core-url.d.ts +106 -0
  90. package/helpers/ns-core-url.js +225 -0
  91. package/helpers/ns-core-url.js.map +1 -0
  92. package/helpers/optimize-deps.d.ts +16 -0
  93. package/helpers/optimize-deps.js +17 -0
  94. package/helpers/optimize-deps.js.map +1 -0
  95. package/helpers/package-platform-aliases.js +34 -49
  96. package/helpers/package-platform-aliases.js.map +1 -1
  97. package/helpers/platform-types.d.ts +2 -0
  98. package/helpers/platform-types.js +2 -0
  99. package/helpers/platform-types.js.map +1 -0
  100. package/helpers/postcss-platform-config.d.ts +17 -1
  101. package/helpers/postcss-platform-config.js +20 -37
  102. package/helpers/postcss-platform-config.js.map +1 -1
  103. package/helpers/project.d.ts +35 -0
  104. package/helpers/project.js +120 -2
  105. package/helpers/project.js.map +1 -1
  106. package/helpers/resolve-main-field-platform.d.ts +20 -0
  107. package/helpers/resolve-main-field-platform.js +49 -0
  108. package/helpers/resolve-main-field-platform.js.map +1 -0
  109. package/helpers/resolver.js +17 -2
  110. package/helpers/resolver.js.map +1 -1
  111. package/helpers/theme-core-plugins.js +1 -1
  112. package/helpers/theme-core-plugins.js.map +1 -1
  113. package/helpers/ts-config-paths.d.ts +32 -0
  114. package/helpers/ts-config-paths.js +156 -27
  115. package/helpers/ts-config-paths.js.map +1 -1
  116. package/helpers/typescript-check.d.ts +2 -1
  117. package/helpers/typescript-check.js +4 -4
  118. package/helpers/typescript-check.js.map +1 -1
  119. package/helpers/ui-registration.d.ts +21 -0
  120. package/helpers/ui-registration.js +156 -0
  121. package/helpers/ui-registration.js.map +1 -0
  122. package/helpers/utils.d.ts +9 -0
  123. package/helpers/utils.js +22 -2
  124. package/helpers/utils.js.map +1 -1
  125. package/helpers/vite-package-version.d.ts +7 -0
  126. package/helpers/vite-package-version.js +44 -0
  127. package/helpers/vite-package-version.js.map +1 -0
  128. package/helpers/workers.d.ts +40 -19
  129. package/helpers/workers.js +312 -13
  130. package/helpers/workers.js.map +1 -1
  131. package/hmr/client/css-handler.d.ts +2 -1
  132. package/hmr/client/css-handler.js +95 -23
  133. package/hmr/client/css-handler.js.map +1 -1
  134. package/hmr/client/css-update-overlay.d.ts +18 -0
  135. package/hmr/client/css-update-overlay.js +27 -0
  136. package/hmr/client/css-update-overlay.js.map +1 -0
  137. package/hmr/client/framework-client-strategy.d.ts +87 -0
  138. package/hmr/client/framework-client-strategy.js +18 -0
  139. package/hmr/client/framework-client-strategy.js.map +1 -0
  140. package/hmr/client/hmr-pending-overlay.d.ts +13 -0
  141. package/hmr/client/hmr-pending-overlay.js +41 -0
  142. package/hmr/client/hmr-pending-overlay.js.map +1 -0
  143. package/hmr/client/hot-context.d.ts +67 -0
  144. package/hmr/client/hot-context.js +307 -0
  145. package/hmr/client/hot-context.js.map +1 -0
  146. package/hmr/client/index.d.ts +9 -1
  147. package/hmr/client/index.js +91 -1418
  148. package/hmr/client/index.js.map +1 -1
  149. package/hmr/client/overlay-driver.d.ts +10 -0
  150. package/hmr/client/overlay-driver.js +33 -0
  151. package/hmr/client/overlay-driver.js.map +1 -0
  152. package/hmr/client/protocol-dispatch.d.ts +8 -0
  153. package/hmr/client/protocol-dispatch.js +308 -0
  154. package/hmr/client/protocol-dispatch.js.map +1 -0
  155. package/hmr/client/root-reset.d.ts +15 -0
  156. package/hmr/client/root-reset.js +358 -0
  157. package/hmr/client/root-reset.js.map +1 -0
  158. package/hmr/client/strategy-loader.d.ts +24 -0
  159. package/hmr/client/strategy-loader.js +100 -0
  160. package/hmr/client/strategy-loader.js.map +1 -0
  161. package/hmr/client/update-pipeline.d.ts +27 -0
  162. package/hmr/client/update-pipeline.js +464 -0
  163. package/hmr/client/update-pipeline.js.map +1 -0
  164. package/hmr/client/utils.d.ts +14 -1
  165. package/hmr/client/utils.js +265 -54
  166. package/hmr/client/utils.js.map +1 -1
  167. package/hmr/client/ws-transport.d.ts +21 -0
  168. package/hmr/client/ws-transport.js +323 -0
  169. package/hmr/client/ws-transport.js.map +1 -0
  170. package/hmr/entry-runtime.d.ts +11 -0
  171. package/hmr/entry-runtime.js +566 -43
  172. package/hmr/entry-runtime.js.map +1 -1
  173. package/hmr/frameworks/angular/build/angular-linker.d.ts +12 -0
  174. package/hmr/frameworks/angular/build/angular-linker.js +113 -0
  175. package/hmr/frameworks/angular/build/angular-linker.js.map +1 -0
  176. package/hmr/frameworks/angular/build/inject-component-hmr-registration.d.ts +112 -0
  177. package/hmr/frameworks/angular/build/inject-component-hmr-registration.js +291 -0
  178. package/hmr/frameworks/angular/build/inject-component-hmr-registration.js.map +1 -0
  179. package/hmr/frameworks/angular/build/inject-hmr-vite-ignore.d.ts +75 -0
  180. package/hmr/frameworks/angular/build/inject-hmr-vite-ignore.js +221 -0
  181. package/hmr/frameworks/angular/build/inject-hmr-vite-ignore.js.map +1 -0
  182. package/hmr/frameworks/angular/build/inline-decorator-component-templates.d.ts +3 -0
  183. package/hmr/frameworks/angular/build/inline-decorator-component-templates.js +231 -0
  184. package/hmr/frameworks/angular/build/inline-decorator-component-templates.js.map +1 -0
  185. package/hmr/frameworks/angular/build/js-lexer.d.ts +4 -0
  186. package/hmr/frameworks/angular/build/js-lexer.js +182 -0
  187. package/hmr/frameworks/angular/build/js-lexer.js.map +1 -0
  188. package/hmr/frameworks/angular/build/linker-stats.d.ts +18 -0
  189. package/hmr/frameworks/angular/build/linker-stats.js +29 -0
  190. package/hmr/frameworks/angular/build/linker-stats.js.map +1 -0
  191. package/hmr/frameworks/angular/build/shared-linker.d.ts +39 -0
  192. package/hmr/frameworks/angular/build/shared-linker.js +128 -0
  193. package/hmr/frameworks/angular/build/shared-linker.js.map +1 -0
  194. package/hmr/frameworks/angular/build/synthesize-decorator-ctor-parameters.d.ts +1 -0
  195. package/hmr/frameworks/angular/build/synthesize-decorator-ctor-parameters.js +88 -0
  196. package/hmr/frameworks/angular/build/synthesize-decorator-ctor-parameters.js.map +1 -0
  197. package/hmr/frameworks/angular/build/synthesize-injectable-factories.d.ts +3 -0
  198. package/hmr/frameworks/angular/build/synthesize-injectable-factories.js +241 -0
  199. package/hmr/frameworks/angular/build/synthesize-injectable-factories.js.map +1 -0
  200. package/hmr/frameworks/angular/build/ts-fallback-transform.d.ts +5 -0
  201. package/hmr/frameworks/angular/build/ts-fallback-transform.js +138 -0
  202. package/hmr/frameworks/angular/build/ts-fallback-transform.js.map +1 -0
  203. package/{helpers/angular → hmr/frameworks/angular/build}/util.d.ts +1 -0
  204. package/hmr/frameworks/angular/build/util.js +155 -0
  205. package/hmr/frameworks/angular/build/util.js.map +1 -0
  206. package/hmr/frameworks/angular/build/worker-url-preserve.d.ts +5 -0
  207. package/hmr/frameworks/angular/build/worker-url-preserve.js +140 -0
  208. package/hmr/frameworks/angular/build/worker-url-preserve.js.map +1 -0
  209. package/hmr/frameworks/angular/client/index.d.ts +2 -1
  210. package/hmr/frameworks/angular/client/index.js +637 -23
  211. package/hmr/frameworks/angular/client/index.js.map +1 -1
  212. package/hmr/frameworks/angular/client/strategy.d.ts +9 -0
  213. package/hmr/frameworks/angular/client/strategy.js +19 -0
  214. package/hmr/frameworks/angular/client/strategy.js.map +1 -0
  215. package/hmr/frameworks/angular/server/angular-root-component.d.ts +79 -0
  216. package/hmr/frameworks/angular/server/angular-root-component.js +149 -0
  217. package/hmr/frameworks/angular/server/angular-root-component.js.map +1 -0
  218. package/hmr/frameworks/angular/server/linker.js +37 -6
  219. package/hmr/frameworks/angular/server/linker.js.map +1 -1
  220. package/hmr/frameworks/angular/server/ng-component-route.d.ts +43 -0
  221. package/hmr/frameworks/angular/server/ng-component-route.js +113 -0
  222. package/hmr/frameworks/angular/server/ng-component-route.js.map +1 -0
  223. package/hmr/frameworks/angular/server/strategy.js +697 -18
  224. package/hmr/frameworks/angular/server/strategy.js.map +1 -1
  225. package/hmr/frameworks/angular/server/websocket-angular-entry.d.ts +2 -0
  226. package/hmr/frameworks/angular/server/websocket-angular-entry.js +68 -0
  227. package/hmr/frameworks/angular/server/websocket-angular-entry.js.map +1 -0
  228. package/hmr/frameworks/angular/server/websocket-angular-hot-update.d.ts +94 -0
  229. package/hmr/frameworks/angular/server/websocket-angular-hot-update.js +485 -0
  230. package/hmr/frameworks/angular/server/websocket-angular-hot-update.js.map +1 -0
  231. package/hmr/frameworks/react/client/strategy.d.ts +12 -0
  232. package/hmr/frameworks/react/client/strategy.js +27 -0
  233. package/hmr/frameworks/react/client/strategy.js.map +1 -0
  234. package/hmr/frameworks/react/server/strategy.d.ts +2 -0
  235. package/hmr/frameworks/react/server/strategy.js +230 -0
  236. package/hmr/frameworks/react/server/strategy.js.map +1 -0
  237. package/hmr/frameworks/solid/build/solid-jsx-deps.d.ts +15 -0
  238. package/hmr/frameworks/solid/build/solid-jsx-deps.js +178 -0
  239. package/hmr/frameworks/solid/build/solid-jsx-deps.js.map +1 -0
  240. package/hmr/frameworks/solid/client/app-runtime.d.ts +68 -0
  241. package/hmr/frameworks/solid/client/app-runtime.js +252 -0
  242. package/hmr/frameworks/solid/client/app-runtime.js.map +1 -0
  243. package/hmr/frameworks/solid/client/strategy.d.ts +7 -0
  244. package/hmr/frameworks/solid/client/strategy.js +391 -0
  245. package/hmr/frameworks/solid/client/strategy.js.map +1 -0
  246. package/hmr/frameworks/solid/server/strategy.js +293 -16
  247. package/hmr/frameworks/solid/server/strategy.js.map +1 -1
  248. package/hmr/frameworks/typescript/client/strategy.d.ts +7 -0
  249. package/hmr/frameworks/typescript/client/strategy.js +418 -0
  250. package/hmr/frameworks/typescript/client/strategy.js.map +1 -0
  251. package/hmr/frameworks/typescript/server/strategy.js +48 -16
  252. package/hmr/frameworks/typescript/server/strategy.js.map +1 -1
  253. package/hmr/frameworks/vue/client/dep-propagation.d.ts +44 -0
  254. package/hmr/frameworks/vue/client/dep-propagation.js +148 -0
  255. package/hmr/frameworks/vue/client/dep-propagation.js.map +1 -0
  256. package/hmr/frameworks/vue/client/index.d.ts +10 -1
  257. package/hmr/frameworks/vue/client/index.js +287 -562
  258. package/hmr/frameworks/vue/client/index.js.map +1 -1
  259. package/hmr/frameworks/vue/client/navigate-app.d.ts +3 -0
  260. package/hmr/frameworks/vue/client/navigate-app.js +178 -0
  261. package/hmr/frameworks/vue/client/navigate-app.js.map +1 -0
  262. package/hmr/frameworks/vue/client/strategy.d.ts +33 -0
  263. package/hmr/frameworks/vue/client/strategy.js +152 -0
  264. package/hmr/frameworks/vue/client/strategy.js.map +1 -0
  265. package/hmr/frameworks/vue/client/vue-sfc-update-overlay.d.ts +49 -0
  266. package/hmr/frameworks/vue/client/vue-sfc-update-overlay.js +124 -0
  267. package/hmr/frameworks/vue/client/vue-sfc-update-overlay.js.map +1 -0
  268. package/hmr/frameworks/vue/server/compiler.d.ts +3 -1
  269. package/hmr/frameworks/vue/server/compiler.js +3 -1
  270. package/hmr/frameworks/vue/server/compiler.js.map +1 -1
  271. package/hmr/frameworks/vue/server/sfc-route-assemble.d.ts +7 -0
  272. package/hmr/frameworks/vue/server/sfc-route-assemble.js +823 -0
  273. package/hmr/frameworks/vue/server/sfc-route-assemble.js.map +1 -0
  274. package/hmr/frameworks/vue/server/sfc-route-meta.d.ts +7 -0
  275. package/hmr/frameworks/vue/server/sfc-route-meta.js +80 -0
  276. package/hmr/frameworks/vue/server/sfc-route-meta.js.map +1 -0
  277. package/hmr/frameworks/vue/server/sfc-route-serve.d.ts +8 -0
  278. package/hmr/frameworks/vue/server/sfc-route-serve.js +462 -0
  279. package/hmr/frameworks/vue/server/sfc-route-serve.js.map +1 -0
  280. package/hmr/frameworks/vue/server/sfc-route-shared.d.ts +45 -0
  281. package/hmr/frameworks/vue/server/sfc-route-shared.js +105 -0
  282. package/hmr/frameworks/vue/server/sfc-route-shared.js.map +1 -0
  283. package/hmr/frameworks/vue/server/strategy.d.ts +35 -0
  284. package/hmr/frameworks/vue/server/strategy.js +291 -7
  285. package/hmr/frameworks/vue/server/strategy.js.map +1 -1
  286. package/hmr/frameworks/vue/server/websocket-sfc.d.ts +15 -0
  287. package/hmr/frameworks/vue/server/websocket-sfc.js +20 -0
  288. package/hmr/frameworks/vue/server/websocket-sfc.js.map +1 -0
  289. package/hmr/helpers/ast-normalizer.d.ts +3 -1
  290. package/hmr/helpers/ast-normalizer.js +131 -24
  291. package/hmr/helpers/ast-normalizer.js.map +1 -1
  292. package/hmr/helpers/cjs-named-exports.d.ts +23 -0
  293. package/hmr/helpers/cjs-named-exports.js +152 -0
  294. package/hmr/helpers/cjs-named-exports.js.map +1 -0
  295. package/hmr/helpers/package-exports.d.ts +16 -0
  296. package/hmr/helpers/package-exports.js +396 -0
  297. package/hmr/helpers/package-exports.js.map +1 -0
  298. package/hmr/helpers/vendor-rewrite.d.ts +1 -1
  299. package/hmr/helpers/vendor-rewrite.js +5 -3
  300. package/hmr/helpers/vendor-rewrite.js.map +1 -1
  301. package/hmr/server/boot-recording.d.ts +51 -0
  302. package/hmr/server/boot-recording.js +214 -0
  303. package/hmr/server/boot-recording.js.map +1 -0
  304. package/hmr/server/constants.d.ts +1 -0
  305. package/hmr/server/constants.js +21 -4
  306. package/hmr/server/constants.js.map +1 -1
  307. package/hmr/server/content-css-update.d.ts +54 -0
  308. package/hmr/server/content-css-update.js +78 -0
  309. package/hmr/server/content-css-update.js.map +1 -0
  310. package/hmr/server/core-bundle.d.ts +140 -0
  311. package/hmr/server/core-bundle.js +614 -0
  312. package/hmr/server/core-bundle.js.map +1 -0
  313. package/hmr/server/core-sanitize.d.ts +130 -4
  314. package/hmr/server/core-sanitize.js +393 -32
  315. package/hmr/server/core-sanitize.js.map +1 -1
  316. package/hmr/server/css-connect-sync.d.ts +28 -0
  317. package/hmr/server/css-connect-sync.js +59 -0
  318. package/hmr/server/css-connect-sync.js.map +1 -0
  319. package/hmr/server/css-device-module.d.ts +28 -0
  320. package/hmr/server/css-device-module.js +44 -0
  321. package/hmr/server/css-device-module.js.map +1 -0
  322. package/hmr/server/css-update-message.d.ts +23 -0
  323. package/hmr/server/css-update-message.js +41 -0
  324. package/hmr/server/css-update-message.js.map +1 -0
  325. package/hmr/server/deps-bundle.d.ts +233 -0
  326. package/hmr/server/deps-bundle.js +1022 -0
  327. package/hmr/server/deps-bundle.js.map +1 -0
  328. package/hmr/server/device-transform-helpers.d.ts +24 -0
  329. package/hmr/server/device-transform-helpers.js +408 -0
  330. package/hmr/server/device-transform-helpers.js.map +1 -0
  331. package/hmr/server/framework-strategy.d.ts +182 -11
  332. package/hmr/server/hmr-module-graph.d.ts +37 -0
  333. package/hmr/server/hmr-module-graph.js +215 -0
  334. package/hmr/server/hmr-module-graph.js.map +1 -0
  335. package/hmr/server/import-map.d.ts +99 -0
  336. package/hmr/server/import-map.js +294 -0
  337. package/hmr/server/import-map.js.map +1 -0
  338. package/hmr/server/index.d.ts +2 -1
  339. package/hmr/server/index.js +7 -16
  340. package/hmr/server/index.js.map +1 -1
  341. package/hmr/server/node-builtins-route.d.ts +12 -0
  342. package/hmr/server/node-builtins-route.js +86 -0
  343. package/hmr/server/node-builtins-route.js.map +1 -0
  344. package/hmr/server/ns-core-cjs-shape.d.ts +204 -0
  345. package/hmr/server/ns-core-cjs-shape.js +271 -0
  346. package/hmr/server/ns-core-cjs-shape.js.map +1 -0
  347. package/hmr/server/ns-m-response-memo.d.ts +10 -0
  348. package/hmr/server/ns-m-response-memo.js +33 -0
  349. package/hmr/server/ns-m-response-memo.js.map +1 -0
  350. package/hmr/server/ns-rt-bridge.d.ts +51 -0
  351. package/hmr/server/ns-rt-bridge.js +131 -0
  352. package/hmr/server/ns-rt-bridge.js.map +1 -0
  353. package/hmr/server/ns-rt-route.d.ts +5 -0
  354. package/hmr/server/ns-rt-route.js +39 -0
  355. package/hmr/server/ns-rt-route.js.map +1 -0
  356. package/hmr/server/perf-instrumentation.d.ts +114 -0
  357. package/hmr/server/perf-instrumentation.js +197 -0
  358. package/hmr/server/perf-instrumentation.js.map +1 -0
  359. package/hmr/server/process-code-for-device.d.ts +44 -0
  360. package/hmr/server/process-code-for-device.js +834 -0
  361. package/hmr/server/process-code-for-device.js.map +1 -0
  362. package/hmr/server/require-guard.d.ts +1 -0
  363. package/hmr/server/require-guard.js +12 -0
  364. package/hmr/server/require-guard.js.map +1 -0
  365. package/hmr/server/rewrite-imports.d.ts +2 -0
  366. package/hmr/server/rewrite-imports.js +631 -0
  367. package/hmr/server/rewrite-imports.js.map +1 -0
  368. package/hmr/server/route-helpers.d.ts +7 -0
  369. package/hmr/server/route-helpers.js +13 -0
  370. package/hmr/server/route-helpers.js.map +1 -0
  371. package/hmr/server/runtime-graph-filter.d.ts +5 -0
  372. package/hmr/server/runtime-graph-filter.js +28 -0
  373. package/hmr/server/runtime-graph-filter.js.map +1 -0
  374. package/hmr/server/server-origin.d.ts +2 -0
  375. package/hmr/server/server-origin.js +88 -0
  376. package/hmr/server/server-origin.js.map +1 -0
  377. package/hmr/server/shared-transform-request.d.ts +12 -0
  378. package/hmr/server/shared-transform-request.js +143 -0
  379. package/hmr/server/shared-transform-request.js.map +1 -0
  380. package/hmr/server/socket-utils.d.ts +10 -0
  381. package/hmr/server/socket-utils.js +14 -0
  382. package/hmr/server/socket-utils.js.map +1 -0
  383. package/hmr/server/transform-cache-invalidation.d.ts +37 -0
  384. package/hmr/server/transform-cache-invalidation.js +156 -0
  385. package/hmr/server/transform-cache-invalidation.js.map +1 -0
  386. package/hmr/server/vendor-bare-module-shims.d.ts +4 -0
  387. package/hmr/server/vendor-bare-module-shims.js +80 -0
  388. package/hmr/server/vendor-bare-module-shims.js.map +1 -0
  389. package/hmr/server/vite-plugin.d.ts +22 -1
  390. package/hmr/server/vite-plugin.js +655 -58
  391. package/hmr/server/vite-plugin.js.map +1 -1
  392. package/hmr/server/websocket-core-bridge.d.ts +68 -0
  393. package/hmr/server/websocket-core-bridge.js +370 -0
  394. package/hmr/server/websocket-core-bridge.js.map +1 -0
  395. package/hmr/server/websocket-device-transform.d.ts +3 -0
  396. package/hmr/server/websocket-device-transform.js +7 -0
  397. package/hmr/server/websocket-device-transform.js.map +1 -0
  398. package/hmr/server/websocket-graph-upsert.d.ts +21 -0
  399. package/hmr/server/websocket-graph-upsert.js +33 -0
  400. package/hmr/server/websocket-graph-upsert.js.map +1 -0
  401. package/hmr/server/websocket-hmr-pending.d.ts +29 -0
  402. package/hmr/server/websocket-hmr-pending.js +33 -0
  403. package/hmr/server/websocket-hmr-pending.js.map +1 -0
  404. package/hmr/server/websocket-hot-update.d.ts +80 -0
  405. package/hmr/server/websocket-hot-update.js +295 -0
  406. package/hmr/server/websocket-hot-update.js.map +1 -0
  407. package/hmr/server/websocket-import-map-route.d.ts +15 -0
  408. package/hmr/server/websocket-import-map-route.js +51 -0
  409. package/hmr/server/websocket-import-map-route.js.map +1 -0
  410. package/hmr/server/websocket-module-bindings.d.ts +21 -0
  411. package/hmr/server/websocket-module-bindings.js +504 -0
  412. package/hmr/server/websocket-module-bindings.js.map +1 -0
  413. package/hmr/server/websocket-module-specifiers.d.ts +96 -0
  414. package/hmr/server/websocket-module-specifiers.js +819 -0
  415. package/hmr/server/websocket-module-specifiers.js.map +1 -0
  416. package/hmr/server/websocket-ns-core.d.ts +34 -0
  417. package/hmr/server/websocket-ns-core.js +414 -0
  418. package/hmr/server/websocket-ns-core.js.map +1 -0
  419. package/hmr/server/websocket-ns-entry.d.ts +21 -0
  420. package/hmr/server/websocket-ns-entry.js +163 -0
  421. package/hmr/server/websocket-ns-entry.js.map +1 -0
  422. package/hmr/server/websocket-ns-m-paths.d.ts +19 -0
  423. package/hmr/server/websocket-ns-m-paths.js +115 -0
  424. package/hmr/server/websocket-ns-m-paths.js.map +1 -0
  425. package/hmr/server/websocket-ns-m-request.d.ts +46 -0
  426. package/hmr/server/websocket-ns-m-request.js +197 -0
  427. package/hmr/server/websocket-ns-m-request.js.map +1 -0
  428. package/hmr/server/websocket-ns-m.d.ts +52 -0
  429. package/hmr/server/websocket-ns-m.js +590 -0
  430. package/hmr/server/websocket-ns-m.js.map +1 -0
  431. package/hmr/server/websocket-served-module-helpers.d.ts +89 -0
  432. package/hmr/server/websocket-served-module-helpers.js +935 -0
  433. package/hmr/server/websocket-served-module-helpers.js.map +1 -0
  434. package/hmr/server/websocket-txn.d.ts +6 -0
  435. package/hmr/server/websocket-txn.js +42 -0
  436. package/hmr/server/websocket-txn.js.map +1 -0
  437. package/hmr/server/websocket-vendor-unifier.d.ts +9 -0
  438. package/hmr/server/websocket-vendor-unifier.js +46 -0
  439. package/hmr/server/websocket-vendor-unifier.js.map +1 -0
  440. package/hmr/server/websocket.d.ts +7 -17
  441. package/hmr/server/websocket.js +723 -5376
  442. package/hmr/server/websocket.js.map +1 -1
  443. package/hmr/shared/ns-globals.d.ts +107 -0
  444. package/hmr/shared/ns-globals.js +29 -0
  445. package/hmr/shared/ns-globals.js.map +1 -0
  446. package/hmr/shared/package-classifier.d.ts +9 -0
  447. package/hmr/shared/package-classifier.js +58 -0
  448. package/hmr/shared/package-classifier.js.map +1 -0
  449. package/hmr/shared/protocol.d.ts +157 -0
  450. package/hmr/shared/protocol.js +28 -0
  451. package/hmr/shared/protocol.js.map +1 -0
  452. package/hmr/shared/runtime/boot-complete.d.ts +14 -0
  453. package/hmr/shared/runtime/boot-complete.js +32 -0
  454. package/hmr/shared/runtime/boot-complete.js.map +1 -0
  455. package/hmr/shared/runtime/boot-placeholder-ui.d.ts +69 -0
  456. package/hmr/shared/runtime/boot-placeholder-ui.js +101 -0
  457. package/hmr/shared/runtime/boot-placeholder-ui.js.map +1 -0
  458. package/hmr/shared/runtime/boot-progress.d.ts +44 -0
  459. package/hmr/shared/runtime/boot-progress.js +134 -0
  460. package/hmr/shared/runtime/boot-progress.js.map +1 -0
  461. package/hmr/shared/runtime/boot-timeline.d.ts +17 -0
  462. package/hmr/shared/runtime/boot-timeline.js +40 -0
  463. package/hmr/shared/runtime/boot-timeline.js.map +1 -0
  464. package/hmr/shared/runtime/browser-runtime-contract.d.ts +97 -0
  465. package/hmr/shared/runtime/browser-runtime-contract.js +66 -0
  466. package/hmr/shared/runtime/browser-runtime-contract.js.map +1 -0
  467. package/hmr/shared/runtime/dev-overlay-ios.d.ts +87 -0
  468. package/hmr/shared/runtime/dev-overlay-ios.js +521 -0
  469. package/hmr/shared/runtime/dev-overlay-ios.js.map +1 -0
  470. package/hmr/shared/runtime/dev-overlay-shared.d.ts +58 -0
  471. package/hmr/shared/runtime/dev-overlay-shared.js +116 -0
  472. package/hmr/shared/runtime/dev-overlay-shared.js.map +1 -0
  473. package/hmr/shared/runtime/dev-overlay-snapshots.d.ts +31 -0
  474. package/hmr/shared/runtime/dev-overlay-snapshots.js +324 -0
  475. package/hmr/shared/runtime/dev-overlay-snapshots.js.map +1 -0
  476. package/hmr/shared/runtime/dev-overlay-tree.d.ts +59 -0
  477. package/hmr/shared/runtime/dev-overlay-tree.js +712 -0
  478. package/hmr/shared/runtime/dev-overlay-tree.js.map +1 -0
  479. package/hmr/shared/runtime/dev-overlay.d.ts +39 -0
  480. package/hmr/shared/runtime/dev-overlay.js +292 -0
  481. package/hmr/shared/runtime/dev-overlay.js.map +1 -0
  482. package/hmr/shared/runtime/global-scope.d.ts +18 -0
  483. package/hmr/shared/runtime/global-scope.js +21 -0
  484. package/hmr/shared/runtime/global-scope.js.map +1 -0
  485. package/hmr/shared/runtime/hooks.js +2 -1
  486. package/hmr/shared/runtime/hooks.js.map +1 -1
  487. package/hmr/shared/runtime/launch-bridge.d.ts +9 -0
  488. package/hmr/shared/runtime/launch-bridge.js +98 -0
  489. package/hmr/shared/runtime/launch-bridge.js.map +1 -0
  490. package/hmr/shared/runtime/module-provenance.d.ts +1 -0
  491. package/hmr/shared/runtime/module-provenance.js +64 -0
  492. package/hmr/shared/runtime/module-provenance.js.map +1 -0
  493. package/hmr/shared/runtime/ns-runtime-test-double.d.ts +21 -0
  494. package/hmr/shared/runtime/ns-runtime-test-double.js +20 -0
  495. package/hmr/shared/runtime/ns-runtime-test-double.js.map +1 -0
  496. package/hmr/shared/runtime/overlay-flag.d.ts +9 -0
  497. package/hmr/shared/runtime/overlay-flag.js +34 -0
  498. package/hmr/shared/runtime/overlay-flag.js.map +1 -0
  499. package/hmr/shared/runtime/platform-polyfills.d.ts +26 -0
  500. package/hmr/shared/runtime/platform-polyfills.js +122 -0
  501. package/hmr/shared/runtime/platform-polyfills.js.map +1 -0
  502. package/hmr/shared/runtime/root-placeholder-view.d.ts +19 -0
  503. package/hmr/shared/runtime/root-placeholder-view.js +311 -0
  504. package/hmr/shared/runtime/root-placeholder-view.js.map +1 -0
  505. package/hmr/shared/runtime/root-placeholder.d.ts +1 -0
  506. package/hmr/shared/runtime/root-placeholder.js +778 -83
  507. package/hmr/shared/runtime/root-placeholder.js.map +1 -1
  508. package/hmr/shared/runtime/session-bootstrap.d.ts +1 -0
  509. package/hmr/shared/runtime/session-bootstrap.js +350 -0
  510. package/hmr/shared/runtime/session-bootstrap.js.map +1 -0
  511. package/hmr/shared/runtime/vendor-bootstrap.js +54 -16
  512. package/hmr/shared/runtime/vendor-bootstrap.js.map +1 -1
  513. package/hmr/shared/runtime/vendor-resolve.d.ts +22 -0
  514. package/hmr/shared/runtime/vendor-resolve.js +45 -0
  515. package/hmr/shared/runtime/vendor-resolve.js.map +1 -0
  516. package/hmr/shared/runtime/worker-tracking.d.ts +28 -0
  517. package/hmr/shared/runtime/worker-tracking.js +114 -0
  518. package/hmr/shared/runtime/worker-tracking.js.map +1 -0
  519. package/hmr/shared/vendor/manifest-collect.d.ts +4 -0
  520. package/hmr/shared/vendor/manifest-collect.js +909 -0
  521. package/hmr/shared/vendor/manifest-collect.js.map +1 -0
  522. package/hmr/shared/vendor/manifest-loader.d.ts +2 -1
  523. package/hmr/shared/vendor/manifest-loader.js +5 -3
  524. package/hmr/shared/vendor/manifest-loader.js.map +1 -1
  525. package/hmr/shared/vendor/manifest.d.ts +12 -0
  526. package/hmr/shared/vendor/manifest.js +341 -545
  527. package/hmr/shared/vendor/manifest.js.map +1 -1
  528. package/hmr/shared/vendor/registry.d.ts +2 -0
  529. package/hmr/shared/vendor/registry.js +118 -7
  530. package/hmr/shared/vendor/registry.js.map +1 -1
  531. package/hmr/shared/vendor/vendor-device-shim.d.ts +1 -0
  532. package/hmr/shared/vendor/vendor-device-shim.js +208 -0
  533. package/hmr/shared/vendor/vendor-device-shim.js.map +1 -0
  534. package/hmr/shared/vendor/vendor-esbuild-plugins.d.ts +107 -0
  535. package/hmr/shared/vendor/vendor-esbuild-plugins.js +540 -0
  536. package/hmr/shared/vendor/vendor-esbuild-plugins.js.map +1 -0
  537. package/index.d.ts +1 -0
  538. package/index.js +5 -0
  539. package/index.js.map +1 -1
  540. package/package.json +76 -14
  541. package/runtime/core-aliases-early.js +103 -81
  542. package/runtime/core-aliases-early.js.map +1 -1
  543. package/shims/react-jsx-runtime.d.ts +4 -0
  544. package/shims/react-jsx-runtime.js +61 -0
  545. package/shims/react-jsx-runtime.js.map +1 -0
  546. package/shims/solid-jsx-runtime.d.ts +7 -0
  547. package/shims/solid-jsx-runtime.js +17 -0
  548. package/shims/solid-jsx-runtime.js.map +1 -0
  549. package/helpers/angular/angular-linker.d.ts +0 -13
  550. package/helpers/angular/angular-linker.js +0 -189
  551. package/helpers/angular/angular-linker.js.map +0 -1
  552. package/helpers/angular/shared-linker.d.ts +0 -4
  553. package/helpers/angular/shared-linker.js +0 -39
  554. package/helpers/angular/shared-linker.js.map +0 -1
  555. package/helpers/angular/util.js +0 -67
  556. package/helpers/angular/util.js.map +0 -1
  557. package/helpers/module-runner-patch.d.ts +0 -3
  558. package/helpers/module-runner-patch.js +0 -63
  559. package/helpers/module-runner-patch.js.map +0 -1
  560. package/helpers/prelink-angular.d.ts +0 -2
  561. package/helpers/prelink-angular.js +0 -117
  562. package/helpers/prelink-angular.js.map +0 -1
  563. package/hmr/shared/runtime/http-only-boot.d.ts +0 -1
  564. package/hmr/shared/runtime/http-only-boot.js +0 -124
  565. package/hmr/shared/runtime/http-only-boot.js.map +0 -1
  566. package/hmr/vendor-bootstrap.d.ts +0 -3
  567. package/hmr/vendor-bootstrap.js +0 -32
  568. package/hmr/vendor-bootstrap.js.map +0 -1
  569. package/shims/react-reconciler-constants.d.ts +0 -14
  570. package/shims/react-reconciler-constants.js +0 -21
  571. package/shims/react-reconciler-constants.js.map +0 -1
  572. package/shims/react-reconciler.d.ts +0 -8
  573. package/shims/react-reconciler.js +0 -15
  574. package/shims/react-reconciler.js.map +0 -1
  575. package/transformers/NativeClass/index.d.ts +0 -2
  576. package/transformers/NativeClass/index.js +0 -222
  577. package/transformers/NativeClass/index.js.map +0 -1
@@ -0,0 +1,935 @@
1
+ import { parse as babelParse } from '@babel/parser';
2
+ import * as t from '@babel/types';
3
+ import { existsSync, readFileSync } from 'fs';
4
+ import * as path from 'path';
5
+ import * as PAT from './constants.js';
6
+ import { isDeepCoreSubpath } from './core-sanitize.js';
7
+ import { getCjsNamedExports } from '../helpers/cjs-named-exports.js';
8
+ import { getMonorepoWorkspaceRoot } from '../../helpers/project.js';
9
+ import { extractDirectExportedNames, parseExportSpecList } from './websocket-core-bridge.js';
10
+ import { resolveCandidateFilePath } from './websocket-module-specifiers.js';
11
+ let cachedWorkspaceCoreRoot;
12
+ /**
13
+ * Absolute root of @nativescript/core when it is consumed from monorepo
14
+ * source (`<workspace>/packages/core` in the NativeScript repo) rather than
15
+ * node_modules. Returns null for standalone apps.
16
+ */
17
+ export function getWorkspaceCoreSourceRoot() {
18
+ if (cachedWorkspaceCoreRoot !== undefined)
19
+ return cachedWorkspaceCoreRoot;
20
+ cachedWorkspaceCoreRoot = null;
21
+ try {
22
+ const wsRoot = getMonorepoWorkspaceRoot();
23
+ if (wsRoot) {
24
+ const pkgPath = path.join(wsRoot, 'packages/core/package.json');
25
+ if (existsSync(pkgPath)) {
26
+ const pkg = JSON.parse(readFileSync(pkgPath, 'utf-8'));
27
+ if (pkg?.name === '@nativescript/core') {
28
+ cachedWorkspaceCoreRoot = path.resolve(wsRoot, 'packages/core').replace(/\\/g, '/');
29
+ }
30
+ }
31
+ }
32
+ }
33
+ catch { }
34
+ return cachedWorkspaceCoreRoot;
35
+ }
36
+ /**
37
+ * True when a served module path points into @nativescript/core consumed from
38
+ * monorepo source. These modules are library code: the app-source HMR passes
39
+ * (AST normalization, /ns/rt underscore-helper alias injection) must NOT run
40
+ * on them — they exist for compiled app/SFC output, and on core sources they
41
+ * misread internals (e.g. `ClassInfo._getBase`) as Vue template helpers and
42
+ * inject destructures that shadow real bindings or TDZ-crash on the circular
43
+ * /ns/rt dependency. In standalone apps core lives under node_modules and is
44
+ * already excluded by the node_modules check.
45
+ */
46
+ export function isWorkspaceCoreModulePath(p) {
47
+ if (!p)
48
+ return false;
49
+ const coreRoot = getWorkspaceCoreSourceRoot();
50
+ if (!coreRoot)
51
+ return false;
52
+ const normalized = String(p).split('?')[0].replace(/\\/g, '/');
53
+ return normalized.includes(coreRoot + '/') || /(^|\/)packages\/core\//.test(normalized);
54
+ }
55
+ /**
56
+ * True when a served module path points into the @nativescript/vite package
57
+ * routed via its monorepo build output (`dist/packages/vite/...`). Apps that
58
+ * consume the package via `file:../../dist/packages/vite` get a node_modules
59
+ * SYMLINK, and require.resolve follows it to the real dist path — so the
60
+ * served URL carries no `node_modules/` segment and escapes the node_modules
61
+ * library check. Like core source, this is library code: the app-source HMR
62
+ * passes (AST normalization, /ns/rt alias injection) must not run on it —
63
+ * e.g. the HMR client bundle already carries its own `__ns_rt_ns_re` import,
64
+ * and a second injected one is a duplicate-declaration SyntaxError on device.
65
+ */
66
+ export function isWorkspaceVitePackageModulePath(p) {
67
+ if (!p)
68
+ return false;
69
+ const normalized = String(p).split('?')[0].replace(/\\/g, '/');
70
+ return /(^|\/)dist\/packages\/vite\//.test(normalized);
71
+ }
72
+ /**
73
+ * Single classification point for the /ns/m served-module pipeline. The
74
+ * app-source passes inside processCodeForDevice (AST normalization, /ns/rt
75
+ * underscore-helper alias injection) must run ONLY on 'app' modules; 'library'
76
+ * code is served as-is plus import rewriting. Three things count as library:
77
+ * - anything under node_modules
78
+ * - @nativescript/core consumed from monorepo source (packages/core)
79
+ * - the @nativescript/vite package served from its dist build output
80
+ * (file:../../dist/packages/vite symlinks resolve to the real dist path,
81
+ * so no node_modules segment appears in the URL)
82
+ * Add the next workspace-library case HERE, not at a call site.
83
+ */
84
+ export function classifyServedModule(p) {
85
+ if (!p)
86
+ return 'app';
87
+ const normalized = String(p).split('?')[0].replace(/\\/g, '/');
88
+ if (/(?:^|\/)node_modules\//.test(normalized))
89
+ return 'library';
90
+ if (isWorkspaceCoreModulePath(normalized))
91
+ return 'library';
92
+ if (isWorkspaceVitePackageModulePath(normalized))
93
+ return 'library';
94
+ return 'app';
95
+ }
96
+ export const MODULE_IMPORT_ANALYSIS_PLUGINS = ['typescript', 'jsx', 'importMeta', 'topLevelAwait', 'classProperties', 'classPrivateProperties', 'classPrivateMethods', 'decorators-legacy'];
97
+ export function collectTopLevelImportRecords(code) {
98
+ if (!code || typeof code !== 'string' || !/\bimport\b/.test(code)) {
99
+ return [];
100
+ }
101
+ try {
102
+ const ast = babelParse(code, {
103
+ sourceType: 'module',
104
+ plugins: MODULE_IMPORT_ANALYSIS_PLUGINS,
105
+ });
106
+ const body = ast?.program?.body;
107
+ if (!Array.isArray(body)) {
108
+ return [];
109
+ }
110
+ return body
111
+ .filter((node) => t.isImportDeclaration(node) && typeof node.start === 'number' && typeof node.end === 'number' && typeof node.source?.value === 'string')
112
+ .map((node) => ({
113
+ start: node.start,
114
+ end: node.end,
115
+ text: code.slice(node.start, node.end),
116
+ source: node.source.value,
117
+ hasOnlyNamedSpecifiers: Array.isArray(node.specifiers) && node.specifiers.length > 0 && node.specifiers.every((spec) => t.isImportSpecifier(spec)),
118
+ namedBindings: Array.isArray(node.specifiers)
119
+ ? node.specifiers
120
+ .filter((spec) => t.isImportSpecifier(spec) && typeof spec.start === 'number' && typeof spec.end === 'number')
121
+ .map((spec) => ({
122
+ importedName: t.isIdentifier(spec.imported) ? spec.imported.name : String(spec.imported?.value || ''),
123
+ text: code.slice(spec.start, spec.end),
124
+ }))
125
+ : [],
126
+ }));
127
+ }
128
+ catch {
129
+ return [];
130
+ }
131
+ }
132
+ export function hoistTopLevelStaticImports(code) {
133
+ const imports = collectTopLevelImportRecords(code);
134
+ if (!imports.length) {
135
+ return code;
136
+ }
137
+ let stripped = code;
138
+ for (const imp of [...imports].sort((left, right) => right.start - left.start)) {
139
+ stripped = stripped.slice(0, imp.start) + stripped.slice(imp.end);
140
+ }
141
+ const hoisted = [];
142
+ const seen = new Set();
143
+ for (const imp of imports) {
144
+ const text = imp.text.trim();
145
+ if (!text || seen.has(text)) {
146
+ continue;
147
+ }
148
+ seen.add(text);
149
+ hoisted.push(text);
150
+ }
151
+ if (!hoisted.length) {
152
+ return stripped;
153
+ }
154
+ return `${hoisted.join('\n')}\n${stripped.replace(/^\s*\n+/, '')}`;
155
+ }
156
+ // Boot-progress instrumentation snippet (server-side string-only).
157
+ //
158
+ // Injected at the top of every `__ns_boot__/b1`-tagged module the dev
159
+ // server serves during cold boot. The snippet is FULLY SYNCHRONOUS —
160
+ // even one conditional top-level `await` would mark the module async
161
+ // in V8, propagating an async-promise chain through the entire boot
162
+ // graph and tripping the iOS 10 s top-level-await deadline (see
163
+ // `ModuleInternal.mm::pumpAsyncProgress`). It just bumps the
164
+ // `__NS_HMR_BOOT_MODULE_COUNT__` / `__NS_HMR_BOOT_LAST_MODULE__`
165
+ // globals; the 250 ms heartbeat in `session-bootstrap.ts` owns
166
+ // `setBootStage` and runs `boot-progress.ts::computeBootImportProgress`
167
+ // against those counters plus elapsed wall-clock to drive the bar.
168
+ // The iOS runtime's `MaybePumpJSThreadDuringBoot` keeps the JS-thread
169
+ // CFRunLoop ticking between sync fetches so the heartbeat can fire
170
+ // during the otherwise-blocking cold-boot module walk.
171
+ //
172
+ // Regression-tested by `websocket-integrity.spec.ts` (snippet stays
173
+ // fully synchronous + propagates exactly via the boot-tag prefix).
174
+ export function buildBootProgressSnippet(bootModuleLabel) {
175
+ const normalizedLabel = JSON.stringify(String(bootModuleLabel || '').replace(/\\/g, '/'));
176
+ return [`const __nsBootGlobal=globalThis;`, `try{if(!__nsBootGlobal.__NS_HMR_BOOT_COMPLETE__){__nsBootGlobal.__NS_HMR_BOOT_MODULE_COUNT__=Number(__nsBootGlobal.__NS_HMR_BOOT_MODULE_COUNT__||0)+1;__nsBootGlobal.__NS_HMR_BOOT_LAST_MODULE__=${normalizedLabel};}}catch(__nsBootErr){}`, ''].join('\n');
177
+ }
178
+ export function stripCoreGlobalsImports(code) {
179
+ const pattern = /^\s*(?:import\s+(?:[^'"\n]*from\s+)?|export\s+\*\s+from\s+)["'][^"']*(?:@nativescript(?:[/_-])core(?:[\/_-])globals|@nativescript_core_globals)[^"']*["'];?\s*$/gm;
180
+ return code.replace(pattern, '');
181
+ }
182
+ // The ONE device-side implementation of Vite's variable-dynamic-import
183
+ // helper. Injected by `ensureVariableDynamicImportHelper` and by
184
+ // `stripViteDynamicImportVirtual` when it removes the `/@id/__x00__vite`
185
+ // virtual that normally provides it — both paths must emit the same shim.
186
+ const VARIABLE_DYNAMIC_IMPORT_HELPER_SOURCE = `const __variableDynamicImportRuntimeHelper = (map, request, importMode) => {\n` +
187
+ ` try { if (request === '@') { return import(new URL('/ns/m/__invalid_at__.mjs', import.meta.url).href); } } catch {}\n` +
188
+ ` const loader = map && (map[request] || map[request?.replace(/\\\\/g, "/")]);\n` +
189
+ ` if (!loader) {\n` +
190
+ ` const error = new Error("Cannot dynamically import: " + request);\n` +
191
+ ` error.code = 'ERR_MODULE_NOT_FOUND';\n` +
192
+ ` return Promise.reject(error);\n` +
193
+ ` }\n` +
194
+ ` try {\n` +
195
+ ` return loader(importMode);\n` +
196
+ ` } catch (err) {\n` +
197
+ ` return Promise.reject(err);\n` +
198
+ ` }\n` +
199
+ `};\n`;
200
+ export function ensureVariableDynamicImportHelper(code) {
201
+ if (!code.includes('__variableDynamicImportRuntimeHelper')) {
202
+ return code;
203
+ }
204
+ if (PAT.VARIABLE_DYNAMIC_IMPORT_HELPER_PATTERN.test(code)) {
205
+ return code;
206
+ }
207
+ return `${VARIABLE_DYNAMIC_IMPORT_HELPER_SOURCE}${code}`;
208
+ }
209
+ export function ensureGuardPlainDynamicImports(code) {
210
+ try {
211
+ if (!code || !/\bimport\s*\(/.test(code))
212
+ return code;
213
+ const wrapper = `const __ns_import = (s) => { try { if (s === '@') { return import(new URL('/ns/m/__invalid_at__.mjs', import.meta.url).href); } } catch {} return import(s); }\n`;
214
+ const replaced = code.replace(/(^|[^\.\w$])import\s*\(/g, (_m, p1) => `${p1}__ns_import(`);
215
+ if (replaced !== code) {
216
+ return wrapper + replaced;
217
+ }
218
+ return code;
219
+ }
220
+ catch {
221
+ return code;
222
+ }
223
+ }
224
+ // Stable URL helper for dynamic imports.
225
+ //
226
+ // Older versions of the helper synthesized
227
+ // `/ns/m/__ns_hmr__/<tag>/<rest>` URLs from
228
+ // `globalThis.__NS_HMR_GRAPH_VERSION__` and an importer-derived tag.
229
+ // That tag flowed straight into V8's `g_moduleRegistry` cache key — so
230
+ // a `graphVersion` bump on every save effectively flushed the whole
231
+ // module graph (HMR latency was dominated by Vite re-transforming the
232
+ // unchanged closure on every save).
233
+ //
234
+ // The current contract inverts that:
235
+ // * The runtime canonicalizes any URL shape (boot prefix, hmr prefix,
236
+ // stable) to a single key via `CanonicalizeHttpUrlKey`.
237
+ // * The Angular client receives an explicit eviction set in
238
+ // `ns:angular-update` and calls ns:module `invalidateModules` before
239
+ // re-importing the entry, so V8 only refetches modules that
240
+ // actually changed.
241
+ // * The dynamic-import helper no longer needs to busy-construct
242
+ // versioned URLs. Boot prefix preservation still matters at COLD
243
+ // boot because the server-side handler routes `/__ns_boot__/b1/`
244
+ // paths to the boot-progress instrumentation snippet — but the
245
+ // prefix is read from `import.meta.url`, never synthesized from
246
+ // `__NS_HMR_GRAPH_VERSION__`.
247
+ //
248
+ // The helper is intentionally tiny:
249
+ // 1. `@` and falsy specs route to `/ns/m/__invalid_at__.mjs` (existing
250
+ // defensive sentinel for misencoded imports).
251
+ // 2. `/ns/m/...` specs that don't yet have a boot prefix get one
252
+ // added when the caller is itself a boot-tagged module. This
253
+ // keeps the boot-progress instrumentation flowing through the
254
+ // transitive cold-boot graph during cold-boot sequences. Once HMR
255
+ // takes over (`__NS_HMR_BOOT_COMPLETE__` is set on the global), no
256
+ // prefix is added — the runtime canonicalizer collapses any
257
+ // historical prefix to the same key.
258
+ // 3. Everything else is a pass-through `import(spec)`.
259
+ export function ensureDynamicHmrImportHelper(code) {
260
+ try {
261
+ if (!code.includes('__nsDynamicHmrImport('))
262
+ return code;
263
+ if (code.includes('const __nsDynamicHmrImport ='))
264
+ return code;
265
+ const helper = 'const __nsDynamicHmrImport = (spec) => {\n' +
266
+ " const __nsm = '/ns' + '/m';\n" +
267
+ " try { if (!spec || spec === '@') { return import(new URL(__nsm + '/__invalid_at__.mjs', import.meta.url).href); } } catch {}\n" +
268
+ ' try {\n' +
269
+ " if (typeof spec !== 'string' || !spec.startsWith(__nsm + '/')) return import(spec);\n" +
270
+ ' const g = globalThis;\n' +
271
+ " const inBoot = !g.__NS_HMR_BOOT_COMPLETE__ && typeof import.meta !== 'undefined' && import.meta && typeof import.meta.url === 'string' && import.meta.url.includes('/__ns_boot__/b1/');\n" +
272
+ " const noBootPrefixYet = !spec.startsWith(__nsm + '/__ns_boot__/');\n" +
273
+ " const isAppModule = !spec.startsWith(__nsm + '/node_modules/');\n" +
274
+ " const finalSpec = inBoot && noBootPrefixYet && isAppModule ? __nsm + '/__ns_boot__/b1' + spec.slice(__nsm.length) : spec;\n" +
275
+ " const origin = typeof g.__NS_HTTP_ORIGIN__ === 'string' && /^https?:\\/\\//.test(g.__NS_HTTP_ORIGIN__) ? g.__NS_HTTP_ORIGIN__ : '';\n" +
276
+ ' return import(origin ? origin + finalSpec : new URL(finalSpec, import.meta.url).href);\n' +
277
+ ' } catch {}\n' +
278
+ ' return import(spec);\n' +
279
+ '};\n';
280
+ return helper + code;
281
+ }
282
+ catch {
283
+ return code;
284
+ }
285
+ }
286
+ /**
287
+ * Star-export expansion must be TRANSITIVE.
288
+ *
289
+ * The expansion below replaces `export * from "url"` with an explicit named
290
+ * list, so any name missing from that list is silently dropped from the
291
+ * importer's export surface — the device then fails at link time with
292
+ * "does not provide an export named '<name>'". Real packages routinely chain
293
+ * star re-exports (`index.ios.js → export * from './canvas'` →
294
+ * `canvas.ios.js → export * from './canvas.common'`), so the name set for a
295
+ * star target is the union of its direct exports, its named re-exports, and
296
+ * — recursively — every nested `export * from` chain, cycles included.
297
+ *
298
+ * This mirrors `collectStaticExportOriginsFromFile` in
299
+ * `websocket-core-bridge.ts`, which solved the identical problem for the
300
+ * /ns/core bridge (see its `Application` comment). That walker reads files
301
+ * from disk; this one works on Vite-transformed code via the shared
302
+ * transformer, because star targets here are served URLs (aliases, /@fs
303
+ * paths, platform-extension resolution already applied by Vite's resolver).
304
+ * If you change export-name semantics in one walker, check the other.
305
+ */
306
+ const STAR_EXPANSION_MAX_DEPTH = 64;
307
+ /**
308
+ * Normalize a star-export target (served URL or nested transformed
309
+ * specifier) into a root-relative path feedable to Vite's transform
310
+ * pipeline. Returns null for specifiers that cannot be walked (bare ids,
311
+ * relative specs with no parent context).
312
+ */
313
+ function normalizeStarExportTargetPath(spec, parentVitePath) {
314
+ let p = String(spec || '').trim();
315
+ if (!p)
316
+ return null;
317
+ p = p.replace(/^https?:\/\/[^/]+/, '');
318
+ p = p.replace(/[?#].*$/, '');
319
+ p = p.replace(/^\/ns\/m\//, '/');
320
+ p = p.replace(/^\/__ns_boot__\/[^/]+/, '');
321
+ p = p.replace(/\/__ns_hmr__\/[^/]+/, '');
322
+ if (p.startsWith('.')) {
323
+ // Vite's import analysis normally rewrites nested specifiers to
324
+ // root-relative URLs; resolve any relative stragglers against the
325
+ // parent module's directory.
326
+ const parent = String(parentVitePath || '')
327
+ .replace(/\\/g, '/')
328
+ .replace(/[?#].*$/, '');
329
+ if (!parent.startsWith('/'))
330
+ return null;
331
+ p = path.posix.normalize(path.posix.join(path.posix.dirname(parent), p));
332
+ }
333
+ return p.startsWith('/') ? p : null;
334
+ }
335
+ // One of three deliberately-separate export scanners; each answers a
336
+ // different question and merging them would couple unrelated contracts:
337
+ // - `extractDirectExportedNames` (websocket-core-bridge.ts): direct lexical
338
+ // exports only — the shared primitive both other scanners build on.
339
+ // - `scanModuleExportSurface` (here): direct exports PLUS re-export lists
340
+ // and `export * from` sources, because star expansion must know both what
341
+ // a module claims and where the rest comes from.
342
+ // - `extractExportMetadata` (below): does a module have a default export
343
+ // and which named ones — shape-only, for SFC route metadata.
344
+ function scanModuleExportSurface(code) {
345
+ const ownNames = new Set(extractDirectExportedNames(code));
346
+ for (const m of code.matchAll(/\bexport\s+\*\s+as\s+([A-Za-z_$][\w$]*)\s+from\s*["'][^"']+["']/g)) {
347
+ ownNames.add(m[1]);
348
+ }
349
+ for (const m of code.matchAll(/\bexport\s*\{([^}]+)\}\s*from\s*["'][^"']+["']/g)) {
350
+ for (const { exportedName } of parseExportSpecList(m[1])) {
351
+ ownNames.add(exportedName);
352
+ }
353
+ }
354
+ const starSources = [];
355
+ // Tolerate trailing comments/code on the line (see the identical fix in
356
+ // websocket-core-bridge.ts: a strict `$` anchor silently skipped
357
+ // `export * from './layouts'; // barrel export` lines).
358
+ for (const m of code.matchAll(/^[ \t]*export\s+\*\s+from\s+["']([^"']+)["'][^\n]*$/gm)) {
359
+ starSources.push(m[1]);
360
+ }
361
+ return { ownNames, starSources };
362
+ }
363
+ /**
364
+ * Recursively collect the full export-name set of a star-export target,
365
+ * following nested `export * from` chains. Cycle-safe via the DFS `stack`
366
+ * set (a revisited module contributes nothing new at that point — its names
367
+ * are already being collected by the outer visit, matching spec
368
+ * GetExportedNames semantics). Returns null when the target itself cannot
369
+ * be transformed; partial failures deeper in the chain are reported through
370
+ * `diagnostics` while still returning every name that could be collected.
371
+ */
372
+ async function collectStarTargetExportNames(vitePath, transformer, stack, depth, diagnostics) {
373
+ if (stack.has(vitePath))
374
+ return new Set();
375
+ if (depth > STAR_EXPANSION_MAX_DEPTH) {
376
+ diagnostics.push(`star-export chain deeper than ${STAR_EXPANSION_MAX_DEPTH} at ${vitePath}`);
377
+ return null;
378
+ }
379
+ let targetCode;
380
+ try {
381
+ targetCode = (await transformer(vitePath))?.code ?? undefined;
382
+ }
383
+ catch { }
384
+ if (!targetCode) {
385
+ diagnostics.push(`unresolvable star-export target ${vitePath}`);
386
+ return null;
387
+ }
388
+ const surface = scanModuleExportSurface(targetCode);
389
+ const names = new Set(surface.ownNames);
390
+ stack.add(vitePath);
391
+ try {
392
+ for (const spec of surface.starSources) {
393
+ const childPath = normalizeStarExportTargetPath(spec, vitePath);
394
+ if (!childPath) {
395
+ diagnostics.push(`unwalkable nested star-export specifier ${JSON.stringify(spec)} in ${vitePath}`);
396
+ continue;
397
+ }
398
+ const childNames = await collectStarTargetExportNames(childPath, transformer, stack, depth + 1, diagnostics);
399
+ if (!childNames)
400
+ continue;
401
+ for (const n of childNames)
402
+ names.add(n);
403
+ }
404
+ }
405
+ finally {
406
+ stack.delete(vitePath);
407
+ }
408
+ // `export *` never re-exports default.
409
+ names.delete('default');
410
+ return names;
411
+ }
412
+ export async function expandStarExports(code, server, projectRoot, verbose, sharedTransformer, importerId) {
413
+ const STAR_RE = /^[ \t]*export\s+\*\s+from\s+["']([^"']+)["'];?(?=[ \t]*(?:\/\/[^\n]*)?$)/gm;
414
+ let match;
415
+ const replacements = [];
416
+ while ((match = STAR_RE.exec(code)) !== null) {
417
+ const url = match[1];
418
+ if (!url.includes('/node_modules/'))
419
+ continue;
420
+ replacements.push({ full: match[0], url });
421
+ }
422
+ if (!replacements.length)
423
+ return code;
424
+ // Names already exported lexically by the importing module. Per spec,
425
+ // lexical exports shadow star-exported names — re-emitting them in an
426
+ // explicit list would be a duplicate-export SyntaxError on device.
427
+ const claimed = new Set(scanModuleExportSurface(code).ownNames);
428
+ // Resolve each star-export target in parallel through the shared runner
429
+ // (when provided) so they share the /ns/m TTL cache and concurrency gate.
430
+ const baseTransformer = sharedTransformer ?? ((url) => server.transformRequest(url));
431
+ // A bare `/node_modules/<pkg>/...` URL is NOT transformable on its own:
432
+ // Vite's bare-specifier resolver is gated by the package's
433
+ // `package.json#exports` and refuses internal sub-paths even when the file
434
+ // is on disk (e.g. `css-tree/lib/version.js`, `css-what/dist/esm/types.js`),
435
+ // and in a monorepo the package is hoisted ABOVE the app's `root` so the
436
+ // path doesn't exist relative to it at all. Either way the transform
437
+ // returns nothing and the star target is mis-reported as "unresolvable",
438
+ // silently dropping its names from the importer's export surface. Mirror the
439
+ // main /ns/m route (`filterExistingNodeModulesTransformCandidates`): resolve
440
+ // the path to a concrete file under the project or workspace root and feed
441
+ // the `/@fs/<abs>` form to Vite, which bypasses the `exports` gate. Falls
442
+ // back to the raw URL for anything that doesn't resolve to a real file.
443
+ const workspaceRoot = projectRoot ? getMonorepoWorkspaceRoot(projectRoot) : null;
444
+ const transformer = (url) => {
445
+ if (projectRoot && url.includes('/node_modules/')) {
446
+ const abs = resolveCandidateFilePath(url, projectRoot, workspaceRoot);
447
+ if (abs) {
448
+ // Posix-normalize and guarantee a leading slash so Windows drive
449
+ // letters produce the `/@fs/C:/...` form Vite expects.
450
+ const absPosix = abs.replace(/\\/g, '/');
451
+ return baseTransformer(`/@fs${absPosix.startsWith('/') ? '' : '/'}${absPosix}`);
452
+ }
453
+ }
454
+ return baseTransformer(url);
455
+ };
456
+ const resolved = await Promise.all(replacements.map(async (rep) => {
457
+ const diagnostics = [];
458
+ const vitePath = normalizeStarExportTargetPath(rep.url, null);
459
+ if (!vitePath) {
460
+ diagnostics.push(`unwalkable star-export URL ${rep.url}`);
461
+ return { rep, names: null, diagnostics };
462
+ }
463
+ const names = await collectStarTargetExportNames(vitePath, transformer, new Set(), 0, diagnostics);
464
+ if (verbose && names) {
465
+ console.log(`[ns/m] expanded export* -> ${names.size} names from ${vitePath}${diagnostics.length ? ' (partial)' : ''}`);
466
+ }
467
+ return { rep, names, diagnostics };
468
+ }));
469
+ for (const entry of resolved) {
470
+ if (entry.diagnostics.length) {
471
+ // Always-on: an incomplete expansion silently narrows the importer's
472
+ // export surface, which surfaces on device as a link-time
473
+ // "does not provide an export named ..." with no server-side trace.
474
+ console.warn(`[ns/m][export*] incomplete star-export expansion${importerId ? ` in ${importerId}` : ''} for ${entry.rep.url}: ${entry.diagnostics.join('; ')}`);
475
+ }
476
+ if (!entry.names)
477
+ continue;
478
+ // First star wins for names provided by multiple siblings; duplicates
479
+ // would be a SyntaxError, and spec-ambiguous names have no good answer.
480
+ const emit = Array.from(entry.names).filter((n) => !claimed.has(n));
481
+ for (const n of emit)
482
+ claimed.add(n);
483
+ // An empty list still keeps the dependency edge (side effects,
484
+ // evaluation order) via a side-effect import.
485
+ const explicit = emit.length ? `export { ${emit.join(', ')} } from ${JSON.stringify(entry.rep.url)};` : `import ${JSON.stringify(entry.rep.url)};`;
486
+ code = code.replace(entry.rep.full, explicit);
487
+ }
488
+ return code;
489
+ }
490
+ export function repairImportEqualsAssignments(code) {
491
+ try {
492
+ if (!code || typeof code !== 'string')
493
+ return code;
494
+ code = code.replace(/(^|\n)\s*import\s*\{([^}]+)\}\s*=\s*([^;]+);?/g, (_m, p1, specList, rhs) => {
495
+ const cleaned = String(specList)
496
+ .split(',')
497
+ .map((s) => s.trim())
498
+ .filter(Boolean)
499
+ .map((seg) => seg.replace(/\s+as\s+/i, ': '))
500
+ .join(', ');
501
+ return `${p1}const { ${cleaned} } = ${rhs};`;
502
+ });
503
+ code = code.replace(/(^|\n)\s*import\s*\*\s*as\s*([A-Za-z_$][\w$]*)\s*=\s*([^;]+);?/g, (_m, p1, ns, rhs) => `${p1}const ${ns} = (${rhs});`);
504
+ code = code.replace(/(^|\n)\s*import\s+([A-Za-z_$][\w$]*)\s*=\s*([^;]+);?/g, (_m, p1, id, rhs) => `${p1}const ${id} = ${rhs};`);
505
+ }
506
+ catch { }
507
+ return code;
508
+ }
509
+ // Canonicalize `/ns/rt` imports: collapse any versioned form
510
+ // (`/ns/rt/<n>`, `/@ns/rt/<n>`) to the single unversioned `/ns/rt` URL.
511
+ // One canonical URL per bridge module — the runtime treats the literal
512
+ // URL as module identity, so emitting `/ns/rt/<ver>` would mint a new
513
+ // module realm per graph version. (The GET route still ACCEPTS the
514
+ // versioned form for stale in-flight code; see ns-rt-route.ts.)
515
+ export function canonicalizeRtImports(code, origin) {
516
+ if (!code || !origin)
517
+ return code;
518
+ code = code.replace(/(from\s+["'])(?:https?:\/\/[^"']+)?\/(?:\@ns|ns)\/rt(?:\/[\d]+)?(["'])/g, (_m, p1, p3) => `${p1}/ns/rt${p3}`);
519
+ code = code.replace(/(import\(\s*["'])(?:https?:\/\/[^"']+)?\/(?:\@ns|ns)\/rt(?:\/[\d]+)?(["']\s*\))/g, (_m, p1, p3) => `${p1}/ns/rt${p3}`);
520
+ return code;
521
+ }
522
+ export function stripViteDynamicImportVirtual(code) {
523
+ if (!/\/@id\/__x00__vite\/dynamic-import-helper/.test(code)) {
524
+ return code;
525
+ }
526
+ const original = code;
527
+ // Statement-scoped, NOT line-anchored: Vite 8 emits its injected imports
528
+ // concatenated on ONE line with the module's original first line, e.g.
529
+ // import …"/@vite/client";import …"/@id/__x00__vite/dynamic-import-helper.js";/**
530
+ // A `^…$`-anchored replace would delete the whole line — including the
531
+ // module's leading `/**`, leaving an orphaned JSDoc body that is a
532
+ // SyntaxError ("Unexpected token '*'") on device.
533
+ code = code.replace(/import\s+[^;'"\n]*['"][^'"\n]*\/@id\/__x00__vite\/dynamic-import-helper[^'"\n]*['"]\s*;?/g, '');
534
+ if (/\/@id\/__x00__vite\/dynamic-import-helper/.test(code)) {
535
+ code = code.replace(/\/@id\/__x00__vite\/dynamic-import-helper[^"'`)]*/g, '/__NS_UNUSED_DYNAMIC_IMPORT_HELPER__');
536
+ }
537
+ if (!/__variableDynamicImportRuntimeHelper/.test(code)) {
538
+ code = VARIABLE_DYNAMIC_IMPORT_HELPER_SOURCE + code;
539
+ }
540
+ if (code !== original) {
541
+ code = `// [hmr-sanitize] removed virtual dynamic-import-helper\n${code}`;
542
+ }
543
+ return code;
544
+ }
545
+ // Shape-only scanner (see the scanner taxonomy above scanModuleExportSurface):
546
+ // answers "does this module export a default, and which named exports?" for
547
+ // the Vue SFC route metadata. It intentionally ignores re-export sources.
548
+ export function extractExportMetadata(code) {
549
+ const named = new Set();
550
+ let hasDefault = /\bexport\s+default\b/.test(code);
551
+ try {
552
+ for (const match of code.matchAll(/\bexport\s+(?:const|let|var|function|class)\s+([A-Za-z_$][A-Za-z0-9_$]*)/g)) {
553
+ if (match[1])
554
+ named.add(match[1]);
555
+ }
556
+ for (const match of code.matchAll(/\bexport\s*\{([^}]+)\}/g)) {
557
+ const inner = (match[1] || '')
558
+ .split(',')
559
+ .map((s) => s.trim())
560
+ .filter(Boolean);
561
+ for (const seg of inner) {
562
+ const direct = seg.match(/^([A-Za-z_$][A-Za-z0-9_$]*)(?:\s+as\s+([A-Za-z_$][A-Za-z0-9_$]*))?$/);
563
+ if (!direct)
564
+ continue;
565
+ const base = direct[1];
566
+ const alias = direct[2];
567
+ if (base === 'default') {
568
+ hasDefault = true;
569
+ continue;
570
+ }
571
+ named.add(alias || base);
572
+ }
573
+ }
574
+ }
575
+ catch { }
576
+ named.delete('default');
577
+ return { hasDefault, named: Array.from(named) };
578
+ }
579
+ /**
580
+ * Defensive export normalization for route-config modules: if a served module
581
+ * defines `routes` and only exports it named, append a default-export alias so
582
+ * both `import { routes }` and `import routes` resolve. Backing implementation
583
+ * for `FrameworkServerStrategy.normalizeServedExports` (Vue/Solid/TS).
584
+ */
585
+ export function ensureRoutesDefaultExport(code) {
586
+ if (/\bexport\s+default\b/.test(code))
587
+ return code;
588
+ const hasNamedRoutes = /\bexport\s*\{\s*routes\s*\}/.test(code);
589
+ const hasConstRoutes = /\bconst\s+routes\s*=/.test(code) || /\bvar\s+routes\s*=/.test(code) || /\blet\s+routes\s*=/.test(code);
590
+ if (hasNamedRoutes && hasConstRoutes) {
591
+ return code + `\nexport default routes;\n`;
592
+ }
593
+ return code;
594
+ }
595
+ function shouldAllowLocalCoreSanitizerPaths(contextLabel) {
596
+ // The @nativescript/vite HMR runtime (client + framework strategies)
597
+ // legitimately references local core paths in strings — allow it whether it
598
+ // is served from node_modules or from the monorepo dist output
599
+ // (`file:../../dist/packages/vite` symlinks resolve to the real dist path,
600
+ // so no node_modules segment appears in the served URL).
601
+ return /\b(?:node_modules\/@nativescript\/vite|dist\/packages\/vite)\/hmr\/(?:client|frameworks)\//.test(contextLabel);
602
+ }
603
+ export function assertNoOptimizedArtifacts(code, contextLabel) {
604
+ const offenders = [];
605
+ const lines = code.split('\n');
606
+ const tests = [/\b__VITE_PLUGIN__\b/, /\b__VITE_PRELOAD__\b/];
607
+ const localCore = /(^|[^\w@])(?:\.\.?\/|\/)??@nativescript[\/_-]core\//i;
608
+ for (let i = 0; i < lines.length; i++) {
609
+ const line = lines[i];
610
+ for (const re of tests) {
611
+ if (re.test(line)) {
612
+ offenders.push(`${i + 1}: ${line.substring(0, 200)}`);
613
+ break;
614
+ }
615
+ }
616
+ if (localCore.test(line)) {
617
+ const trimmed = line.trimStart();
618
+ if (trimmed.startsWith('//') || trimmed.startsWith('/*') || trimmed.startsWith('*')) {
619
+ continue;
620
+ }
621
+ if (shouldAllowLocalCoreSanitizerPaths(contextLabel)) {
622
+ continue;
623
+ }
624
+ // Only module-resolution contexts (import/export/require) leak to the
625
+ // device ESM loader. A core path appearing as plain runtime string data
626
+ // — e.g. component-builder's `const CORE_UI_BARREL = '@nativescript/core/ui'`
627
+ // passed to `global.loadModule()`, which reads the bundler module
628
+ // registry, not the ESM loader — is legitimate and must not fail serving.
629
+ if (!/(?:\bimport\b|\bexport\b|\bfrom\s*["']|\brequire\s*\()/.test(line)) {
630
+ continue;
631
+ }
632
+ offenders.push(`${i + 1}: ${line.substring(0, 200)} [local-core-path]`);
633
+ }
634
+ if (offenders.length >= 10)
635
+ break;
636
+ }
637
+ if (offenders.length) {
638
+ const msg = `[sanitize-fail] Optimized deps/virtual id artifacts detected in ${contextLabel}. These cannot be evaluated by the device HTTP ESM loader. Offending lines (first ${Math.min(5, offenders.length)} shown):\n` + offenders.slice(0, 5).join('\n');
639
+ const error = new Error(msg);
640
+ error.code = 'NS_SANITIZE_FAIL';
641
+ error.offenders = offenders;
642
+ throw error;
643
+ }
644
+ }
645
+ /** Convert an import spec list (`A, B as C`) into a destructure pattern (`A, B: C`). */
646
+ function toDestructurePattern(specList) {
647
+ return specList
648
+ .split(',')
649
+ .map((s) => s.trim())
650
+ .filter(Boolean)
651
+ .map((seg) => {
652
+ const match = seg.split(/\s+as\s+/i);
653
+ return match.length === 2 ? `${match[0].trim()}: ${match[1].trim()}` : seg;
654
+ })
655
+ .join(', ');
656
+ }
657
+ // Rewrite named imports from a bridge URL (`/ns/core`, `/ns/rt`) into a
658
+ // default import plus `const {}` destructure. The bridge modules export a
659
+ // default namespace object, so a named import that survives to the device
660
+ // fails at link time ("does not provide an export named ...").
661
+ function destructureBridgeImports(code, opts) {
662
+ try {
663
+ let result = code;
664
+ let counter = 0;
665
+ const srcPattern = `((?:https?:\\/\\/[^"']+)?${opts.pathPattern})`;
666
+ const reNamed = new RegExp(`(^|\\n)\\s*import\\s*\\{([^}]+)\\}\\s*from\\s*["']${srcPattern}['"];?\\s*`, 'gm');
667
+ result = result.replace(reNamed, (full, prefix, specList, src) => {
668
+ if (opts.shouldSkip?.(src))
669
+ return full;
670
+ const tempName = opts.numberRepeats && counter > 0 ? `${opts.tempName}_${counter}` : opts.tempName;
671
+ counter++;
672
+ return `${prefix}import ${tempName} from ${JSON.stringify(src)};\nconst { ${toDestructurePattern(specList)} } = ${tempName};\n`;
673
+ });
674
+ const reMixed = new RegExp(`(^|\\n)\\s*import\\s+([A-Za-z_$][\\w$]*)\\s*,\\s*\\{([^}]+)\\}\\s*from\\s*["']${srcPattern}['"];?\\s*`, 'gm');
675
+ result = result.replace(reMixed, (full, prefix, defName, specList, src) => {
676
+ if (opts.shouldSkip?.(src))
677
+ return full;
678
+ return `${prefix}import ${defName} from ${JSON.stringify(src)};\nconst { ${toDestructurePattern(specList)} } = ${defName};\n`;
679
+ });
680
+ return result;
681
+ }
682
+ catch {
683
+ return code;
684
+ }
685
+ }
686
+ export function ensureDestructureCoreImports(code) {
687
+ return destructureBridgeImports(code, {
688
+ pathPattern: String.raw `\/ns\/core(?:\/[^"']+)?`,
689
+ tempName: '__ns_core_ns_re',
690
+ numberRepeats: true,
691
+ // Deep core subpaths keep their named-import form (see core-sanitize.ts).
692
+ shouldSkip: isDeepCoreSubpath,
693
+ });
694
+ }
695
+ export function ensureDestructureRtImports(code) {
696
+ return destructureBridgeImports(code, {
697
+ pathPattern: String.raw `\/ns\/rt(?:\/[\d]+)?`,
698
+ tempName: '__ns_rt_ns_re',
699
+ numberRepeats: false,
700
+ });
701
+ }
702
+ export function dedupeRtNamedImportsAgainstDestructures(code) {
703
+ try {
704
+ let result = code;
705
+ const rtDestructureRE = /(^|\n)\s*const\s*\{([^}]+)\}\s*=\s*(__ns_rt_ns(?:\d+|_re))\s*;?/gm;
706
+ const rtBound = new Set();
707
+ let match;
708
+ while ((match = rtDestructureRE.exec(result)) !== null) {
709
+ const specList = String(match[2] || '');
710
+ specList
711
+ .split(',')
712
+ .map((s) => s.trim())
713
+ .filter(Boolean)
714
+ .forEach((seg) => {
715
+ const bind = seg.includes(':') ? seg.split(':')[1].trim() : seg;
716
+ if (bind)
717
+ rtBound.add(bind);
718
+ });
719
+ }
720
+ if (!rtBound.size)
721
+ return result;
722
+ const rtNamedImportRE = /(^|\n)\s*import\s*\{([^}]+)\}\s*from\s*["']((?:https?:\/\/[^"']+)?\/ns\/rt(?:\/[\d]+)?)['"];?\s*/gm;
723
+ const edits = [];
724
+ while ((match = rtNamedImportRE.exec(result)) !== null) {
725
+ const full = match[0];
726
+ const prefix = match[1] || '';
727
+ const specList = String(match[2] || '');
728
+ const src = match[3];
729
+ const kept = [];
730
+ specList
731
+ .split(',')
732
+ .map((s) => s.trim())
733
+ .filter(Boolean)
734
+ .forEach((seg) => {
735
+ const importedName = seg.split(/\s+as\s+/i)[0].trim();
736
+ if (!rtBound.has(importedName))
737
+ kept.push(seg);
738
+ });
739
+ let replacement = '';
740
+ if (kept.length) {
741
+ replacement = `${prefix}import { ${kept.join(', ')} } from ${JSON.stringify(src)};`;
742
+ }
743
+ else {
744
+ replacement = prefix || '';
745
+ }
746
+ edits.push({
747
+ start: rtNamedImportRE.lastIndex - full.length,
748
+ end: rtNamedImportRE.lastIndex,
749
+ text: replacement,
750
+ });
751
+ }
752
+ if (edits.length) {
753
+ edits
754
+ .sort((a, b) => b.start - a.start)
755
+ .forEach((edit) => {
756
+ result = result.slice(0, edit.start) + edit.text + result.slice(edit.end);
757
+ });
758
+ }
759
+ return result;
760
+ }
761
+ catch {
762
+ return code;
763
+ }
764
+ }
765
+ export function deduplicateLinkerImports(code) {
766
+ if (!code)
767
+ return code;
768
+ try {
769
+ const imports = collectTopLevelImportRecords(code);
770
+ if (!imports.length) {
771
+ return code;
772
+ }
773
+ const pkgUrlMap = new Map();
774
+ const pkgBindings = new Map();
775
+ for (const imp of imports) {
776
+ const url = imp.source;
777
+ if (!/^https?:\/\//.test(url) && !url.startsWith('/')) {
778
+ continue;
779
+ }
780
+ const nmIdx = url.lastIndexOf('/node_modules/');
781
+ if (nmIdx === -1)
782
+ continue;
783
+ const afterNm = url.substring(nmIdx + '/node_modules/'.length);
784
+ const parts = afterNm.split('/');
785
+ const pkg = parts[0].startsWith('@') ? parts.slice(0, 2).join('/') : parts[0];
786
+ if (!pkgUrlMap.has(pkg))
787
+ pkgUrlMap.set(pkg, url);
788
+ if (imp.namedBindings.length) {
789
+ if (!pkgBindings.has(pkg))
790
+ pkgBindings.set(pkg, new Set());
791
+ for (const binding of imp.namedBindings) {
792
+ if (binding.importedName)
793
+ pkgBindings.get(pkg).add(binding.importedName);
794
+ }
795
+ }
796
+ }
797
+ if (pkgUrlMap.size === 0)
798
+ return code;
799
+ const edits = [];
800
+ for (const imp of imports) {
801
+ if (!imp.hasOnlyNamedSpecifiers) {
802
+ continue;
803
+ }
804
+ const specifier = imp.source;
805
+ if (specifier.startsWith('/') || specifier.startsWith('.') || specifier.startsWith('http')) {
806
+ continue;
807
+ }
808
+ const parts = specifier.split('/');
809
+ const pkg = specifier.startsWith('@') ? parts.slice(0, 2).join('/') : parts[0];
810
+ const url = pkgUrlMap.get(pkg);
811
+ if (!url) {
812
+ continue;
813
+ }
814
+ const existing = pkgBindings.get(pkg) || new Set();
815
+ const newBindings = imp.namedBindings.filter((binding) => !existing.has(binding.importedName));
816
+ if (newBindings.length === 0) {
817
+ edits.push({ start: imp.start, end: imp.end, text: '' });
818
+ continue;
819
+ }
820
+ if (newBindings.length === imp.namedBindings.length) {
821
+ continue;
822
+ }
823
+ for (const binding of newBindings) {
824
+ existing.add(binding.importedName);
825
+ }
826
+ edits.push({
827
+ start: imp.start,
828
+ end: imp.end,
829
+ text: `import { ${newBindings.map((binding) => binding.text).join(', ')} } from ${JSON.stringify(url)};`,
830
+ });
831
+ }
832
+ if (!edits.length) {
833
+ return code;
834
+ }
835
+ let next = code;
836
+ for (const edit of edits.sort((left, right) => right.start - left.start)) {
837
+ next = next.slice(0, edit.start) + edit.text + next.slice(edit.end);
838
+ }
839
+ return next;
840
+ }
841
+ catch {
842
+ return code;
843
+ }
844
+ }
845
+ export function wrapCommonJsModuleForDevice(code, absolutePath) {
846
+ if (!code)
847
+ return code;
848
+ try {
849
+ const hasExportDefault = /\bexport\s+default\b/.test(code) || /export\s*\{\s*default\s*(?:as\s*default)?\s*\}/.test(code);
850
+ const hasNamedExports = /\bexport\s+(?:const|let|var|function|class|async)\b/.test(code) || /\bexport\s*\{/.test(code);
851
+ const hasCjsExports = /\bmodule\s*\.\s*exports\b/.test(code) || /\bexports\s*\.\s*\w/.test(code);
852
+ if (hasExportDefault || hasNamedExports || !hasCjsExports) {
853
+ return code;
854
+ }
855
+ const namedExports = new Set();
856
+ const exportsRe = /\bexports\s*\.\s*([A-Za-z_$][\w$]*)\s*=/g;
857
+ let match;
858
+ while ((match = exportsRe.exec(code)) !== null) {
859
+ const name = match[1];
860
+ if (name !== '__esModule' && name !== 'default') {
861
+ namedExports.add(name);
862
+ }
863
+ }
864
+ const defPropRe = /Object\s*\.\s*defineProperty\s*\(\s*exports\s*,\s*['"]([^'"]+)['"]/g;
865
+ while ((match = defPropRe.exec(code)) !== null) {
866
+ const name = match[1];
867
+ if (name !== '__esModule' && name !== 'default') {
868
+ namedExports.add(name);
869
+ }
870
+ }
871
+ // Static enumeration only sees `exports.foo = ...` and `Object.defineProperty(exports, 'foo', ...)`.
872
+ // Real-world packages like lodash attach their entire surface to a function inside an IIFE and
873
+ // then `module.exports = thatFunction`. Static analysis returns zero in that case. To handle
874
+ // these modules we ALSO load the package in the dev-server's Node context (only when we have a
875
+ // node_modules path) and merge the runtime keys. See `helpers/cjs-named-exports.ts` for the
876
+ // reasoning and safety boundaries.
877
+ if (absolutePath) {
878
+ try {
879
+ for (const n of getCjsNamedExports(absolutePath)) {
880
+ namedExports.add(n);
881
+ }
882
+ }
883
+ catch {
884
+ /* fall through to whatever we caught statically */
885
+ }
886
+ }
887
+ let suffix = `\nvar __cjs_mod = module.exports;\nexport default __cjs_mod;\n`;
888
+ if (namedExports.size) {
889
+ const entries = Array.from(namedExports);
890
+ const temps = entries.map((name, i) => `var __cjs_e${i} = __cjs_mod[${JSON.stringify(name)}];`);
891
+ const reExports = entries.map((name, i) => `__cjs_e${i} as ${name}`);
892
+ suffix += `${temps.join(' ')}\nexport { ${reExports.join(', ')} };\n`;
893
+ }
894
+ const prelude = `var module = { exports: {} }; var exports = module.exports;\n` +
895
+ `var __ns_cjs_require_base = (typeof globalThis.__nsBaseRequire === 'function' ? globalThis.__nsBaseRequire : (typeof globalThis.__nsRequire === 'function' ? globalThis.__nsRequire : (typeof globalThis.require === 'function' ? globalThis.require : undefined)));\n` +
896
+ `var __ns_cjs_require_kind = (typeof globalThis.__nsBaseRequire === 'function' ? 'base-require' : (typeof globalThis.__nsRequire === 'function' ? 'vendor-require' : 'global-require'));\n` +
897
+ `var require = function(spec) {\n` +
898
+ ` if (!__ns_cjs_require_base) { throw new Error('require is not defined'); }\n` +
899
+ // Resolve relative specifiers against the HTTP-served module's URL
900
+ // before delegating to NS's runtime require. Keeps ./sibling and
901
+ // ../parent requires routable through the HTTP ESM loader rather
902
+ // than NS's filesystem-based require.
903
+ ` var __nsResolvedSpec = spec;\n` +
904
+ ` try {\n` +
905
+ ` if (typeof spec === 'string' && (spec.indexOf('./') === 0 || spec.indexOf('../') === 0)) {\n` +
906
+ ` var __nsParentUrl = (typeof import.meta !== 'undefined' && import.meta && typeof import.meta.url === 'string') ? import.meta.url : null;\n` +
907
+ ` if (__nsParentUrl) {\n` +
908
+ ` var __nsResolvedUrl = new URL(spec, __nsParentUrl);\n` +
909
+ ` if (!/\\.[A-Za-z0-9]+$/.test(__nsResolvedUrl.pathname.split('/').pop() || '')) {\n` +
910
+ ` __nsResolvedUrl.pathname = __nsResolvedUrl.pathname.replace(/\\/+$/, '') + '.js';\n` +
911
+ ` }\n` +
912
+ ` __nsResolvedSpec = __nsResolvedUrl.href;\n` +
913
+ ` }\n` +
914
+ ` }\n` +
915
+ ` } catch (e) {}\n` +
916
+ ` try { var __nsRecord = globalThis.__NS_RECORD_MODULE_PROVENANCE__; if (typeof __nsRecord === 'function') { __nsRecord(String(__nsResolvedSpec), { kind: __ns_cjs_require_kind, specifier: String(spec), url: __nsResolvedSpec !== spec ? __nsResolvedSpec : undefined, via: 'cjs-wrapper', parent: (typeof import.meta !== 'undefined' && import.meta && import.meta.url) ? import.meta.url : undefined }); } } catch (e) {}\n` +
917
+ ` var mod = __ns_cjs_require_base(__nsResolvedSpec);\n` +
918
+ ` try {\n` +
919
+ ` if (mod && (typeof mod === 'object' || typeof mod === 'function') && mod.default !== undefined) {\n` +
920
+ ` var keys = [];\n` +
921
+ ` try { keys = Object.keys(mod); } catch (e) {}\n` +
922
+ ` var defaultOnly = keys.length === 1 && keys[0] === 'default';\n` +
923
+ ` var esModuleOnly = keys.length === 2 && keys.indexOf('default') !== -1 && keys.indexOf('__esModule') !== -1;\n` +
924
+ ` if (mod.__esModule || defaultOnly || esModuleOnly) { return mod.default; }\n` +
925
+ ` }\n` +
926
+ ` } catch (e) {}\n` +
927
+ ` return mod;\n` +
928
+ `};\n`;
929
+ return `${prelude}${code}${suffix}`;
930
+ }
931
+ catch {
932
+ return code;
933
+ }
934
+ }
935
+ //# sourceMappingURL=websocket-served-module-helpers.js.map