@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
@@ -8,8 +8,8 @@
8
8
  * "@nativescript/core/index.js";
9
9
  * This trips the sanitizer's local-core-path detector and breaks HTTP ESM loading.
10
10
  *
11
- * This helper safely maps those literals to:
12
- * import "/ns/core?p=index.js";
11
+ * This helper safely maps those literals to the canonical path form:
12
+ * import "/ns/core/<sub>"; // subpath form, no version, no ?p=
13
13
  * or, without subpath:
14
14
  * import "/ns/core";
15
15
  */
@@ -19,14 +19,140 @@ export declare function normalizeStrayCoreStringLiterals(code: string): string;
19
19
  * following side-effect import of the core bridge.
20
20
  *
21
21
  * Example:
22
- * import { A, B } from\nimport "/ns/core?p=index.js";
22
+ * import { A, B } from\nimport "/ns/core/index";
23
23
  * becomes
24
- * import { A, B } from "/ns/core?p=index.js";
24
+ * import { A, B } from "/ns/core/index";
25
25
  */
26
26
  export declare function fixDanglingCoreFrom(code: string): string;
27
+ /**
28
+ * Run the full "rescue any stray @nativescript/core references" pass over the
29
+ * code in one call. This is the canonical entry point for NS-M served modules
30
+ * (and any other consumer that wants the safety net). The three sub-passes
31
+ * cover progressively rarer pipeline accidents:
32
+ *
33
+ * 1. `normalizeStrayCoreStringLiterals` — turns naked `"@nativescript/core/foo";`
34
+ * string literals (produced by some upstream transforms that bare-stringify
35
+ * side-effect imports) back into proper `import "/ns/core/foo";`.
36
+ * 2. `fixDanglingCoreFrom` — merges multi-line accidents where a `from`
37
+ * clause got separated from its specifier across newlines.
38
+ * 3. `normalizeAnyCoreSpecToBridge` — final regex sweep that catches any
39
+ * remaining `from "...@nativescript/core[/sub]..."` references that escaped
40
+ * both the AST normalizer and the import rewriter.
41
+ *
42
+ * Centralising the passes here ensures every NS-M emitter applies the same
43
+ * safety net in the same order; drift between call sites re-introduces the
44
+ * realm-split bug.
45
+ *
46
+ * Returns the (possibly) rewritten code; never throws.
47
+ */
48
+ export declare function sanitizeStrayCoreReferences(code: string): string;
27
49
  /**
28
50
  * Fallback: normalize ANY import spec that references '@nativescript/core' (including
29
51
  * absolute/relative or resolved forms like '/node_modules/@nativescript/core/index.js?v=...')
30
52
  * into the unified '/ns/core' bridge before fast-fail assertions.
31
53
  */
32
54
  export declare function normalizeAnyCoreSpecToBridge(code: string): string;
55
+ /**
56
+ * Description of the URL the bridge is currently serving, used to resolve
57
+ * relative import specifiers (`./x`, `../x`) into absolute `/ns/core/<sub>`
58
+ * URLs.
59
+ *
60
+ * Why this exists: Vite's `vite:import-analysis` pass usually rewrites every
61
+ * relative specifier to an absolute (`/@fs/...` or `/node_modules/...`) ID
62
+ * before code reaches us, but for files under `node_modules` some transform
63
+ * paths leave relatives untouched. When the device fetches such a module at
64
+ * `http://host/ns/core/utils/layout-helper` (no trailing slash, no `/index`)
65
+ * V8/iOS apply RFC 3986 URL resolution and treat `layout-helper` as the
66
+ * *file*, so `./layout-helper-common` becomes
67
+ * `http://host/ns/core/utils/layout-helper-common` — a sibling that does not
68
+ * exist (the real file lives at `…/layout-helper/layout-helper-common`).
69
+ *
70
+ * Passing a `RelativeBase` lets `rewriteSpec` resolve these specifiers
71
+ * server-side and emit canonical absolute `/ns/core/<resolved>` URLs, so the
72
+ * device never has to guess. When omitted, `rewriteSpec` falls back to the
73
+ * pre-existing behaviour of leaving relatives alone.
74
+ */
75
+ export type RelativeBase = {
76
+ /**
77
+ * Sub-path of the served module, without the leading `/ns/core/`. May be
78
+ * the empty string for the package main (`/ns/core` itself).
79
+ */
80
+ sub: string;
81
+ /**
82
+ * `true` when the served file is a directory-index (e.g.
83
+ * `…/utils/layout-helper/index.android.ts`); in that case `sub` already
84
+ * names the *directory*, and `./x` resolves to `<sub>/x`.
85
+ *
86
+ * `false` for plain file modules (e.g. `…/utils/native-helper.ts`); the
87
+ * resolution base is the parent directory of `sub`, so `./x` resolves to
88
+ * `<sub-parent>/x`.
89
+ */
90
+ isDirectoryIndex: boolean;
91
+ };
92
+ /**
93
+ * Detect whether a resolved module path is a directory-index file. Matches
94
+ * `index.<platform?>.<ext>` shapes used across @nativescript/core (e.g.
95
+ * `index.js`, `index.android.ts`, `index.ios.mjs`).
96
+ */
97
+ export declare function isDirectoryIndexFilename(modulePath: string): boolean;
98
+ /**
99
+ * Resolve a relative specifier (`./x`, `../x`) into a canonical
100
+ * @nativescript/core sub-path, given the base described by `relBase`.
101
+ *
102
+ * `…/index.<platform>.<ext>` files mean `sub` IS the directory (so `./x` →
103
+ * `<sub>/x`); plain files mean the resolution base is `sub`'s parent.
104
+ *
105
+ * Returned sub-path is sanitised by `buildCoreUrlPath`'s convention: trailing
106
+ * `.(m)?(j|t)s` extensions are stripped so callers can directly emit
107
+ * `/ns/core/<resolved>` without producing a non-canonical URL that the
108
+ * bridge would 301-redirect later.
109
+ */
110
+ export declare function resolveRelativeCoreSub(spec: string, relBase: RelativeBase): string | null;
111
+ /**
112
+ * Minimal specifier rewriter for deep subpath core modules.
113
+ *
114
+ * Takes Vite's correctly-transformed ESM output and ONLY rewrites the
115
+ * specifier strings inside import/export clauses. Does NOT:
116
+ * - Inject global defines
117
+ * - Run AST normalization
118
+ * - Convert named imports to default + destructure
119
+ * - Mangle newlines or code structure
120
+ *
121
+ * This replaces the heavy 5-pass pipeline (processCodeForDevice →
122
+ * rewriteImports → deduplicateLinkerImports → CJS wrapping → etc.)
123
+ * for deep subpath core modules where Vite already produces correct ESM.
124
+ *
125
+ * When `relBase` is supplied, relative specifiers (`./x`, `../x`) are
126
+ * resolved server-side into canonical `/ns/core/<resolved>` URLs so the
127
+ * device never has to guess where a directory-index file's siblings live.
128
+ * See `RelativeBase` and `rewriteSpec` for the full rationale.
129
+ */
130
+ export declare function rewriteSpecifiersForDevice(code: string, origin: string, ver: number, relBase?: RelativeBase): string;
131
+ /**
132
+ * Determine whether a `/ns/core` bridge URL points to a real subpath module.
133
+ *
134
+ * Any `/ns/core/<sub>` module now serves real ESM content with real named
135
+ * exports via Vite's transform pipeline, except for package-main aliases like
136
+ * `/ns/core/index`, which should be treated like the main `/ns/core`
137
+ * bridge and destructured from its default export.
138
+ * The main proxy bridge (`/ns/core`) still only exports a default Proxy and
139
+ * requires named imports to be destructured from it.
140
+ *
141
+ * This check is used in all named-import-to-default destructuring passes to
142
+ * skip rewriting for real subpath modules — they have named exports that work
143
+ * natively without conversion.
144
+ */
145
+ export declare function isDeepCoreSubpath(url: string): boolean;
146
+ /**
147
+ * Synthesize a `default` export for an ESM module that only has named/star
148
+ * exports. Utility function — not currently called from the core bridge
149
+ * handler since `ensureDestructureCoreImports` now skips deep subpaths.
150
+ *
151
+ * Handles all three @nativescript/core patterns:
152
+ * 1. Direct declarations: export class X, export function Y, export const Z
153
+ * 2. Named re-exports: export { A, B } from '/path'
154
+ * 3. Star re-exports: export * from '/path'
155
+ *
156
+ * Returns the code unchanged if it already has a default export or CJS exports.
157
+ */
158
+ export declare function synthesizeDefaultExport(moduleCode: string): string;
@@ -1,3 +1,4 @@
1
+ import { buildCoreUrlPath } from '../../helpers/ns-core-url.js';
1
2
  /**
2
3
  * Rewrites stray string-literal side-effect lines that reference @nativescript/core
3
4
  * into proper ESM import statements targeting the unified /ns/core bridge.
@@ -8,8 +9,8 @@
8
9
  * "@nativescript/core/index.js";
9
10
  * This trips the sanitizer's local-core-path detector and breaks HTTP ESM loading.
10
11
  *
11
- * This helper safely maps those literals to:
12
- * import "/ns/core?p=index.js";
12
+ * This helper safely maps those literals to the canonical path form:
13
+ * import "/ns/core/<sub>"; // subpath form, no version, no ?p=
13
14
  * or, without subpath:
14
15
  * import "/ns/core";
15
16
  */
@@ -18,26 +19,21 @@ export function normalizeStrayCoreStringLiterals(code) {
18
19
  return code;
19
20
  try {
20
21
  let out = code;
22
+ const toCoreBridgeUrl = (sub) => buildCoreUrlPath(sub);
21
23
  // Normalize any concatenated imports on the same line to start on a new line
22
24
  // e.g. `...;import x from` -> `...;\nimport x from`
23
25
  out = out.replace(/;\s*import\s+/g, ';\nimport ');
24
26
  // Case 1: inline literal followed by another import on SAME line
25
27
  // Example: "@nativescript/core/index.js";import { x } from "...";
26
28
  out = out.replace(/(["']@nativescript\/core([^"']*)["'];)(\s*import\s+)/g, (_m, _lit, sub, after) => {
27
- const qp = String(sub || '')
28
- .trim()
29
- .replace(/^\//, '');
30
- const url = qp ? `/ns/core?p=${qp}` : '/ns/core';
29
+ const url = toCoreBridgeUrl(sub);
31
30
  return `import "${url}";${after}`;
32
31
  });
33
32
  // Case 2: standalone literal on its own line (not a JSON key) — must be end-of-line
34
33
  // Guard with EOL so we don't rewrite JSON keys like "@nativescript/core": "alpha"
35
34
  const reLine = /(^|\n)([\t ]*)["']@nativescript\/core([^"']*)["']\s*;?\s*(?=$|\n)/g;
36
35
  out = out.replace(reLine, (_full, prefix, indent, sub) => {
37
- const qp = String(sub || '')
38
- .trim()
39
- .replace(/^\//, '');
40
- const url = qp ? `/ns/core?p=${qp}` : '/ns/core';
36
+ const url = toCoreBridgeUrl(sub);
41
37
  return `${prefix}${indent}import "${url}";`;
42
38
  });
43
39
  return out;
@@ -51,19 +47,18 @@ export function normalizeStrayCoreStringLiterals(code) {
51
47
  * following side-effect import of the core bridge.
52
48
  *
53
49
  * Example:
54
- * import { A, B } from\nimport "/ns/core?p=index.js";
50
+ * import { A, B } from\nimport "/ns/core/index";
55
51
  * becomes
56
- * import { A, B } from "/ns/core?p=index.js";
52
+ * import { A, B } from "/ns/core/index";
57
53
  */
58
54
  export function fixDanglingCoreFrom(code) {
59
55
  if (!code || typeof code !== 'string')
60
56
  return code;
61
57
  try {
62
- // Also normalize any concatenated imports before processing
63
58
  code = code.replace(/;\s*import\s+/g, ';\nimport ');
64
59
  // Multi-line form: import { ...\n ...\n} from\nimport "<core-url>";[tail]
65
60
  // Merge into: import { ... } from "<core-url>";\n[tail]
66
- code = code.replace(/(^|\n|;)\s*import\s*\{([\s\S]*?)\}\s*from\s*\n\s*import\s+["']((?:https?:\/\/[^"']+)?\/ns\/core(?:\/\d+)?(?:\?p=[^"']+)?)["'];?(.*)/g, (_m, pre, named, url, tail) => {
61
+ code = code.replace(/(^|\n|;)\s*import\s*\{([\s\S]*?)\}\s*from\s*\n\s*import\s+["']((?:https?:\/\/[^"']+)?\/ns\/core(?:\/[^"']*)?)["'];?(.*)/g, (_m, pre, named, url, tail) => {
67
62
  const prefix = pre ? (String(pre).endsWith(';') ? String(pre) + '\n' : String(pre)) : '';
68
63
  const tailNorm = (tail || '').replace(/^\s*;?\s*/, '').trim();
69
64
  return prefix + `import {${named}} from "${url}";` + (tailNorm ? `\n${tailNorm}` : '');
@@ -75,19 +70,16 @@ export function fixDanglingCoreFrom(code) {
75
70
  const m = /^\s*import\s*\{[^}]+\}\s*from\s*$/.exec(ln);
76
71
  if (m && i + 1 < lines.length) {
77
72
  const next = lines[i + 1];
78
- // Support when the next line starts with the core import followed by another ';import ...'
79
- // Capture the core import URL and any trailing content after it (another import concatenated)
80
- const m2 = /^\s*import\s+["']((?:https?:\/\/[^"']+)?\/ns\/core(?:\/\d+)?(?:\?p=[^"']+)?)["'];?(.*)$/.exec(next);
73
+ const m2 = /^\s*import\s+["']((?:https?:\/\/[^"']+)?\/ns\/core(?:\/[^"']*)?)["'];?(.*)$/.exec(next);
81
74
  if (m2) {
82
75
  const url = m2[1];
83
76
  const tail = m2[2] || '';
84
77
  out.push(ln + ' ' + `"${url}";`);
85
- // If there is a tail like ';import { ... } from "..."', normalize it onto a new line
86
78
  const tailNorm = tail.replace(/^\s*;?\s*/, '');
87
79
  if (tailNorm.trim().length > 0) {
88
80
  out.push(tailNorm);
89
81
  }
90
- i++; // consume the next line
82
+ i++;
91
83
  continue;
92
84
  }
93
85
  }
@@ -99,6 +91,45 @@ export function fixDanglingCoreFrom(code) {
99
91
  return code;
100
92
  }
101
93
  }
94
+ /**
95
+ * Run the full "rescue any stray @nativescript/core references" pass over the
96
+ * code in one call. This is the canonical entry point for NS-M served modules
97
+ * (and any other consumer that wants the safety net). The three sub-passes
98
+ * cover progressively rarer pipeline accidents:
99
+ *
100
+ * 1. `normalizeStrayCoreStringLiterals` — turns naked `"@nativescript/core/foo";`
101
+ * string literals (produced by some upstream transforms that bare-stringify
102
+ * side-effect imports) back into proper `import "/ns/core/foo";`.
103
+ * 2. `fixDanglingCoreFrom` — merges multi-line accidents where a `from`
104
+ * clause got separated from its specifier across newlines.
105
+ * 3. `normalizeAnyCoreSpecToBridge` — final regex sweep that catches any
106
+ * remaining `from "...@nativescript/core[/sub]..."` references that escaped
107
+ * both the AST normalizer and the import rewriter.
108
+ *
109
+ * Centralising the passes here ensures every NS-M emitter applies the same
110
+ * safety net in the same order; drift between call sites re-introduces the
111
+ * realm-split bug.
112
+ *
113
+ * Returns the (possibly) rewritten code; never throws.
114
+ */
115
+ export function sanitizeStrayCoreReferences(code) {
116
+ if (!code || typeof code !== 'string')
117
+ return code;
118
+ let out = code;
119
+ try {
120
+ out = normalizeStrayCoreStringLiterals(out);
121
+ }
122
+ catch { }
123
+ try {
124
+ out = fixDanglingCoreFrom(out);
125
+ }
126
+ catch { }
127
+ try {
128
+ out = normalizeAnyCoreSpecToBridge(out);
129
+ }
130
+ catch { }
131
+ return out;
132
+ }
102
133
  /**
103
134
  * Fallback: normalize ANY import spec that references '@nativescript/core' (including
104
135
  * absolute/relative or resolved forms like '/node_modules/@nativescript/core/index.js?v=...')
@@ -109,26 +140,356 @@ export function normalizeAnyCoreSpecToBridge(code) {
109
140
  return code;
110
141
  try {
111
142
  let out = code;
112
- const toQp = (sub) => {
113
- const s = String(sub || '')
114
- .split('?')[0]
115
- .trim()
116
- .replace(/^\//, '');
117
- return s ? `?p=${s}` : '';
118
- };
143
+ const toCoreBridgeUrl = (sub) => buildCoreUrlPath(sub);
119
144
  // Static: import ... from "...@nativescript/core[/sub]..."
120
- out = out.replace(/from\s+["'][^"']*@nativescript[\/_-]core([^"']*)["']/g, (_m, sub) => `from "/ns/core${toQp(sub)}"`);
145
+ out = out.replace(/from\s+["'][^"']*@nativescript[\/_-]core([^"']*)["']/g, (_m, sub) => `from "${toCoreBridgeUrl(sub)}"`);
121
146
  // Side-effect: import "...@nativescript/core[/sub]..."
122
- out = out.replace(/(^|\n)\s*import\s+["'][^"']*@nativescript[\/_-]core([^"']*)["'];?/gm, (full, pfx, sub) => `${pfx}import "/ns/core${toQp(sub)}";`);
147
+ out = out.replace(/(^|\n)\s*import\s+["'][^"']*@nativescript[\/_-]core([^"']*)["'];?/gm, (full, pfx, sub) => `${pfx}import "${toCoreBridgeUrl(sub)}";`);
123
148
  // Dynamic: import("...@nativescript/core[/sub]...")
124
- out = out.replace(/import\(\s*["'][^"']*@nativescript[\/_-]core([^"']*)["']\s*\)/g, (_m, sub) => `import("/ns/core${toQp(sub)}")`);
125
- // Repair glitch where a previous pass split/merged lines into: "from import '/ns/core...'"
126
- // Normalize to a valid specifier: "from '/ns/core...'"
127
- out = out.replace(/from\s+import\s+["']((?:https?:\/\/[^"']+)?\/ns\/core(?:\/[0-9]+)?(?:\?p=[^"']+)?)['"]/g, (_m, url) => `from "${url}"`);
149
+ out = out.replace(/import\(\s*["'][^"']*@nativescript[\/_-]core([^"']*)["']\s*\)/g, (_m, sub) => `import("${toCoreBridgeUrl(sub)}")`);
150
+ // Repair glitch where a previous pass split/merged lines into:
151
+ // "from import '/ns/core...'". Normalize to a valid specifier:
152
+ // "from '/ns/core...'".
153
+ out = out.replace(/from\s+import\s+["']((?:https?:\/\/[^"']+)?\/ns\/core(?:\/[^"']*)?)['"]/g, (_m, url) => `from "${url}"`);
128
154
  return out;
129
155
  }
130
156
  catch {
131
157
  return code;
132
158
  }
133
159
  }
160
+ /**
161
+ * Detect whether a resolved module path is a directory-index file. Matches
162
+ * `index.<platform?>.<ext>` shapes used across @nativescript/core (e.g.
163
+ * `index.js`, `index.android.ts`, `index.ios.mjs`).
164
+ */
165
+ export function isDirectoryIndexFilename(modulePath) {
166
+ if (!modulePath || typeof modulePath !== 'string')
167
+ return false;
168
+ const cleaned = modulePath.split(/[?#]/)[0];
169
+ const base = cleaned.replace(/\\/g, '/').split('/').pop() || '';
170
+ return /^index(?:\.(?:android|ios|visionos))?\.(?:m?[jt]s)$/i.test(base);
171
+ }
172
+ /**
173
+ * Resolve a relative specifier (`./x`, `../x`) into a canonical
174
+ * @nativescript/core sub-path, given the base described by `relBase`.
175
+ *
176
+ * `…/index.<platform>.<ext>` files mean `sub` IS the directory (so `./x` →
177
+ * `<sub>/x`); plain files mean the resolution base is `sub`'s parent.
178
+ *
179
+ * Returned sub-path is sanitised by `buildCoreUrlPath`'s convention: trailing
180
+ * `.(m)?(j|t)s` extensions are stripped so callers can directly emit
181
+ * `/ns/core/<resolved>` without producing a non-canonical URL that the
182
+ * bridge would 301-redirect later.
183
+ */
184
+ export function resolveRelativeCoreSub(spec, relBase) {
185
+ if (!spec || (!spec.startsWith('./') && !spec.startsWith('../')))
186
+ return null;
187
+ const cleanSpec = spec.split(/[?#]/)[0];
188
+ const stripExt = (s) => s.replace(/\.(?:m?[jt]s)$/i, '');
189
+ const splitSeg = (s) => s.split('/').filter((p) => p.length > 0);
190
+ const baseSub = String(relBase?.sub || '').replace(/^\/+|\/+$/g, '');
191
+ const dirParts = relBase?.isDirectoryIndex ? splitSeg(baseSub) : splitSeg(baseSub).slice(0, -1);
192
+ const relParts = cleanSpec.split('/');
193
+ for (const part of relParts) {
194
+ if (part === '' || part === '.')
195
+ continue;
196
+ if (part === '..') {
197
+ if (dirParts.length === 0)
198
+ return null;
199
+ dirParts.pop();
200
+ continue;
201
+ }
202
+ dirParts.push(part);
203
+ }
204
+ const joined = dirParts.join('/');
205
+ return stripExt(joined);
206
+ }
207
+ /**
208
+ * Rewrite a single import/export specifier for device consumption.
209
+ *
210
+ * Converts Vite-resolved root-relative paths to URLs the device can fetch:
211
+ * /node_modules/@nativescript/core/x/y → /ns/core/x/y (canonical)
212
+ * /node_modules/other-pkg/x.js → {origin}/ns/m/node_modules/other-pkg/x.js
213
+ * /src/app/foo.ts → {origin}/ns/m/src/app/foo.ts
214
+ * already /ns/... or http://... → unchanged
215
+ *
216
+ * When `relBase` is supplied AND `spec` is a relative path (`./x` or `../x`),
217
+ * the relative specifier is resolved to an absolute `/ns/core/<resolved>`
218
+ * URL using `resolveRelativeCoreSub`. Without `relBase`, relatives are
219
+ * returned unchanged (legacy behaviour for non-core call sites).
220
+ */
221
+ function rewriteSpec(spec, origin, ver, relBase) {
222
+ void ver;
223
+ // Strip Vite cache-busting query params for bridge URLs
224
+ const cleanSpec = spec.split('?')[0];
225
+ // @nativescript/core anywhere in the path → core bridge.
226
+ // Delegated to the ONE canonical URL generator to guarantee that
227
+ // every emitter — this function, the ns-core-external-urls plugin,
228
+ // main-entry's coreSpec, and the runtime import map — produces
229
+ // byte-identical URLs for the same logical module. Mixed forms
230
+ // (query `?p=`, versioned, `.js` suffix) would otherwise produce
231
+ // distinct iOS HTTP ESM cache entries for the same file,
232
+ // re-evaluating register() side effects and crashing on "Cannot
233
+ // redefine property".
234
+ const coreIdx = cleanSpec.indexOf('@nativescript/core');
235
+ if (coreIdx !== -1) {
236
+ const after = cleanSpec.substring(coreIdx + '@nativescript/core'.length);
237
+ return buildCoreUrlPath(after);
238
+ }
239
+ // Already-canonicalised bridge URLs deserve a second look — a
240
+ // `/ns/core/<sub>` URL with a stale platform suffix (`.ios`),
241
+ // trailing `/index`, or `.js` extension would survive this pass
242
+ // but be 301-redirected by the bridge handler at runtime, costing
243
+ // an extra round-trip and risking double-evaluation if iOS caches
244
+ // both spellings. Run any `/ns/core/...` (or full-origin variant)
245
+ // back through `buildCoreUrlPath` so the rewriter is the
246
+ // single point that produces canonical core URLs for the device.
247
+ const coreBridgePathOnly = cleanSpec.match(/^\/ns\/core(?:\/[^?#]*)?$/);
248
+ if (coreBridgePathOnly) {
249
+ const sub = cleanSpec.replace(/^\/ns\/core\/?/, '');
250
+ return buildCoreUrlPath(sub);
251
+ }
252
+ const coreBridgeWithOrigin = cleanSpec.match(/^https?:\/\/[^/]+\/ns\/core(?:\/[^?#]*)?$/);
253
+ if (coreBridgeWithOrigin) {
254
+ const sub = cleanSpec.replace(/^https?:\/\/[^/]+\/ns\/core\/?/, '');
255
+ const canonicalPath = buildCoreUrlPath(sub);
256
+ const originPrefix = cleanSpec.replace(/\/ns\/core(?:\/.*)?$/, '');
257
+ return `${originPrefix}${canonicalPath}`;
258
+ }
259
+ // Already a bridge or HTTP URL → leave unchanged
260
+ if (spec.startsWith('/ns/') || spec.startsWith('http://') || spec.startsWith('https://')) {
261
+ return spec;
262
+ }
263
+ // Relative specifiers (`./x`, `../x`).
264
+ //
265
+ // Vite's import-analysis usually rewrites these to absolute IDs, but
266
+ // for files under `node_modules` it sometimes leaves them in place.
267
+ // When that happens AND the served URL has no trailing slash AND is
268
+ // itself a directory-index file (e.g. `…/layout-helper/index.android.ts`
269
+ // served at `/ns/core/utils/layout-helper`), V8's URL resolver treats
270
+ // `layout-helper` as the file and points `./layout-helper-common` at the
271
+ // non-existent sibling `/ns/core/utils/layout-helper-common`. Vite then
272
+ // 500s with "Failed to load url … Does the file exist?" and the
273
+ // dependent module never finishes evaluating.
274
+ //
275
+ // When `relBase` is supplied we resolve the specifier server-side and
276
+ // emit a canonical absolute `/ns/core/<resolved>` URL so the device
277
+ // cannot guess wrong. Falling back to the unchanged relative path
278
+ // preserves legacy behaviour for callers that don't (yet) thread
279
+ // `relBase` through.
280
+ if (spec.startsWith('./') || spec.startsWith('../')) {
281
+ if (relBase) {
282
+ const resolvedSub = resolveRelativeCoreSub(spec, relBase);
283
+ if (resolvedSub !== null) {
284
+ return buildCoreUrlPath(resolvedSub);
285
+ }
286
+ }
287
+ return spec;
288
+ }
289
+ // Root-relative paths → HTTP URL through /ns/m/ handler
290
+ if (spec.startsWith('/')) {
291
+ return `${origin}/ns/m${spec}`;
292
+ }
293
+ // Bare package specifier (e.g. `source-map-js/lib/source-map-generator.js`)
294
+ // → HTTP URL through /ns/m/node_modules/ handler. Under HMR bundle-build,
295
+ // @nativescript/core subpath modules served by this bridge (e.g.
296
+ // /ns/core?p=inspector_modules) may reference other npm packages with bare
297
+ // specifiers in their transformed output — specifically, the CommonJS
298
+ // compat transformer for source-map-js rewrites `require('./lib/source-
299
+ // map-generator')` into `import from 'source-map-js/lib/source-map-
300
+ // generator.js'`, a bare specifier that iOS's ESM loader cannot resolve at
301
+ // module-instantiation time (the runtime import map isn't installed yet).
302
+ // Converting to /ns/m/node_modules/<spec> makes iOS fetch the package over
303
+ // HTTP, which Vite serves through the same pipeline that already handles
304
+ // every other node_modules subpath import in the app.
305
+ return `${origin}/ns/m/node_modules/${spec}`;
306
+ }
307
+ /**
308
+ * Minimal specifier rewriter for deep subpath core modules.
309
+ *
310
+ * Takes Vite's correctly-transformed ESM output and ONLY rewrites the
311
+ * specifier strings inside import/export clauses. Does NOT:
312
+ * - Inject global defines
313
+ * - Run AST normalization
314
+ * - Convert named imports to default + destructure
315
+ * - Mangle newlines or code structure
316
+ *
317
+ * This replaces the heavy 5-pass pipeline (processCodeForDevice →
318
+ * rewriteImports → deduplicateLinkerImports → CJS wrapping → etc.)
319
+ * for deep subpath core modules where Vite already produces correct ESM.
320
+ *
321
+ * When `relBase` is supplied, relative specifiers (`./x`, `../x`) are
322
+ * resolved server-side into canonical `/ns/core/<resolved>` URLs so the
323
+ * device never has to guess where a directory-index file's siblings live.
324
+ * See `RelativeBase` and `rewriteSpec` for the full rationale.
325
+ */
326
+ export function rewriteSpecifiersForDevice(code, origin, ver, relBase) {
327
+ if (!code)
328
+ return code;
329
+ let result = code;
330
+ // Pattern 1: from "specifier" — covers all static import/export forms
331
+ // import { X } from "spec"
332
+ // import X from "spec"
333
+ // import * as X from "spec"
334
+ // export { X } from "spec"
335
+ // export * from "spec"
336
+ //
337
+ // The lookbehind guard below ensures we only match `from` at the start of
338
+ // its ESM-keyword context, not `from` appearing INSIDE a string literal
339
+ // (e.g. `if (time === 'from') { … }` in @nativescript/core's
340
+ // css-animation-parser). Without this guard the regex spans from the
341
+ // `from` inside the string to the NEXT quote elsewhere in the file,
342
+ // corrupting both tokens.
343
+ result = result.replace(/(?<![a-zA-Z0-9_$'"`])(from\s+)(["'])([^"']+)\2/g, (_m, pre, q, spec) => {
344
+ return `${pre}${q}${rewriteSpec(spec, origin, ver, relBase)}${q}`;
345
+ });
346
+ // Pattern 2: import("specifier") — dynamic imports
347
+ result = result.replace(/(import\s*\(\s*)(["'])([^"']+)\2(\s*\))/g, (_m, pre, q, spec, post) => {
348
+ return `${pre}${q}${rewriteSpec(spec, origin, ver, relBase)}${q}${post}`;
349
+ });
350
+ // Pattern 3: import "specifier" — side-effect imports (no from clause)
351
+ // Anchored after start-of-string, newline, or semicolon to avoid false matches.
352
+ // The `^` alternative is critical: when a transformed module's body begins
353
+ // with a side-effect import (no preceding `;` or `\n`), the legacy
354
+ // `[;\n]`-only anchor missed it and the URL leaked to the device unmodified.
355
+ // Concrete failure mode: `/ns/core/inspector_modules` whose first body line
356
+ // `import '/@fs/.../@nativescript/core/globals/index.js';` was served raw,
357
+ // producing a `__DEV__ is not defined` ReferenceError in `platform-check.js`
358
+ // because `/@fs/` URLs bypass the `/ns/core` bridge's define-injection.
359
+ result = result.replace(/(^|[;\n])(\s*import\s+)(["'])([^"']+)\3/g, (_m, lead, pre, q, spec) => {
360
+ // Skip if it looks like an identifier rather than a path
361
+ if (!/[/.@]/.test(spec))
362
+ return _m;
363
+ return `${lead}${pre}${q}${rewriteSpec(spec, origin, ver, relBase)}${q}`;
364
+ });
365
+ return result;
366
+ }
367
+ /**
368
+ * Determine whether a `/ns/core` bridge URL points to a real subpath module.
369
+ *
370
+ * Any `/ns/core/<sub>` module now serves real ESM content with real named
371
+ * exports via Vite's transform pipeline, except for package-main aliases like
372
+ * `/ns/core/index`, which should be treated like the main `/ns/core`
373
+ * bridge and destructured from its default export.
374
+ * The main proxy bridge (`/ns/core`) still only exports a default Proxy and
375
+ * requires named imports to be destructured from it.
376
+ *
377
+ * This check is used in all named-import-to-default destructuring passes to
378
+ * skip rewriting for real subpath modules — they have named exports that work
379
+ * natively without conversion.
380
+ */
381
+ export function isDeepCoreSubpath(url) {
382
+ if (!url || typeof url !== 'string')
383
+ return false;
384
+ const path = url.match(/\/ns\/core\/([^?#]+)/);
385
+ if (!path)
386
+ return false;
387
+ const sub = String(path[1] || '').replace(/^\/+|\/+$/g, '');
388
+ if (!sub || sub === 'index' || sub === 'index.js')
389
+ return false;
390
+ return true;
391
+ }
392
+ /**
393
+ * Synthesize a `default` export for an ESM module that only has named/star
394
+ * exports. Utility function — not currently called from the core bridge
395
+ * handler since `ensureDestructureCoreImports` now skips deep subpaths.
396
+ *
397
+ * Handles all three @nativescript/core patterns:
398
+ * 1. Direct declarations: export class X, export function Y, export const Z
399
+ * 2. Named re-exports: export { A, B } from '/path'
400
+ * 3. Star re-exports: export * from '/path'
401
+ *
402
+ * Returns the code unchanged if it already has a default export or CJS exports.
403
+ */
404
+ export function synthesizeDefaultExport(moduleCode) {
405
+ if (!moduleCode || typeof moduleCode !== 'string')
406
+ return moduleCode;
407
+ const hasExportDefault = /\bexport\s+default\b/.test(moduleCode) || /export\s*\{\s*default\s*(?:as\s*default)?\s*\}/.test(moduleCode);
408
+ if (hasExportDefault)
409
+ return moduleCode;
410
+ const hasCjsExports = /\bmodule\s*\.\s*exports\b/.test(moduleCode) || /\bexports\s*\.\s*\w/.test(moduleCode);
411
+ if (hasCjsExports)
412
+ return moduleCode;
413
+ try {
414
+ const bindings = []; // [localName, exportedName]
415
+ const extraImports = [];
416
+ const starSpreads = [];
417
+ let sIdx = 0;
418
+ let m;
419
+ // export { A, b as B } [from 'src'] — handles both local and re-exports
420
+ const reBraces = /\bexport\s*\{([^}]+)\}\s*(?:from\s*["']([^"']+)["'])?/g;
421
+ while ((m = reBraces.exec(moduleCode)) !== null) {
422
+ const specList = m[1];
423
+ const fromSrc = m[2]; // undefined for local exports
424
+ const specs = specList
425
+ .split(',')
426
+ .map((s) => s.trim())
427
+ .filter(Boolean);
428
+ for (const spec of specs) {
429
+ const parts = spec.split(/\s+as\s+/);
430
+ const srcName = parts[0].trim();
431
+ const expName = parts.length > 1 ? parts[1].trim() : srcName;
432
+ if (!expName || expName === 'default')
433
+ continue;
434
+ // For re-exports, the local name is the exported name (from the import we add below)
435
+ // For local exports, the local name is srcName (already in scope)
436
+ bindings.push(fromSrc ? [expName, expName] : [srcName, expName]);
437
+ }
438
+ if (fromSrc) {
439
+ const importSpecs = specs
440
+ .map((spec) => {
441
+ const parts = spec.split(/\s+as\s+/);
442
+ const srcName = parts[0].trim();
443
+ const expName = parts.length > 1 ? parts[1].trim() : srcName;
444
+ if (!expName || expName === 'default')
445
+ return '';
446
+ return parts.length > 1 ? `${srcName} as ${expName}` : expName;
447
+ })
448
+ .filter(Boolean);
449
+ if (importSpecs.length) {
450
+ extraImports.push(`import { ${importSpecs.join(', ')} } from ${JSON.stringify(fromSrc)};`);
451
+ }
452
+ }
453
+ }
454
+ // export const/let/var X
455
+ const reDecl = /\bexport\s+(?:const|let|var)\s+([A-Za-z_$][\w$]*)/g;
456
+ while ((m = reDecl.exec(moduleCode)) !== null) {
457
+ bindings.push([m[1], m[1]]);
458
+ }
459
+ // export [async] function[*]/class X
460
+ const reFunc = /\bexport\s+(?:async\s+)?(?:function\s*\*?|class)\s+([A-Za-z_$][\w$]*)/g;
461
+ while ((m = reFunc.exec(moduleCode)) !== null) {
462
+ bindings.push([m[1], m[1]]);
463
+ }
464
+ // export * as X from 'src' (namespace re-export)
465
+ const reStarAs = /\bexport\s*\*\s*as\s+([A-Za-z_$][\w$]*)\s+from\s*["']([^"']+)["']/g;
466
+ while ((m = reStarAs.exec(moduleCode)) !== null) {
467
+ extraImports.push(`import * as ${m[1]} from ${JSON.stringify(m[2])};`);
468
+ bindings.push([m[1], m[1]]);
469
+ }
470
+ // export * from 'src' (bare star re-export, NOT 'export * as')
471
+ const reStarBare = /\bexport\s*\*\s*(?!as\s)from\s*["']([^"']+)["']/g;
472
+ while ((m = reStarBare.exec(moduleCode)) !== null) {
473
+ const v = `__ns_star_${sIdx++}`;
474
+ extraImports.push(`import * as ${v} from ${JSON.stringify(m[1])};`);
475
+ starSpreads.push(`...${v}`);
476
+ }
477
+ if (bindings.length > 0 || starSpreads.length > 0) {
478
+ const entries = [...starSpreads];
479
+ const seen = new Set();
480
+ for (const [local, exported] of bindings) {
481
+ if (seen.has(exported))
482
+ continue;
483
+ seen.add(exported);
484
+ entries.push(local === exported ? exported : `${JSON.stringify(exported)}: ${local}`);
485
+ }
486
+ const prefix = extraImports.length ? extraImports.join('\n') + '\n' : '';
487
+ return prefix + moduleCode + `\nvar __ns_default_export = { ${entries.join(', ')} };\nexport { __ns_default_export as default };\n`;
488
+ }
489
+ return moduleCode;
490
+ }
491
+ catch {
492
+ return moduleCode;
493
+ }
494
+ }
134
495
  //# sourceMappingURL=core-sanitize.js.map