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