@nativescript/vite 8.0.0-alpha.6 → 8.0.0-alpha.60

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 (463) hide show
  1. package/README.md +51 -11
  2. package/bin/cli.cjs +8 -14
  3. package/configuration/angular.d.ts +34 -1
  4. package/configuration/angular.js +376 -165
  5. package/configuration/angular.js.map +1 -1
  6. package/configuration/base.js +244 -53
  7. package/configuration/base.js.map +1 -1
  8. package/configuration/javascript.js +14 -93
  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 +51 -6
  13. package/configuration/solid.js.map +1 -1
  14. package/configuration/typescript.js +12 -93
  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-state.d.ts +8 -0
  19. package/helpers/app-css-state.js +8 -0
  20. package/helpers/app-css-state.js.map +1 -0
  21. package/helpers/bundler-context.d.ts +11 -0
  22. package/helpers/bundler-context.js +71 -0
  23. package/helpers/bundler-context.js.map +1 -0
  24. package/helpers/cli-flags.d.ts +12 -0
  25. package/helpers/cli-flags.js +34 -0
  26. package/helpers/cli-flags.js.map +1 -1
  27. package/helpers/css-platform-plugin.d.ts +14 -0
  28. package/helpers/css-platform-plugin.js +43 -25
  29. package/helpers/css-platform-plugin.js.map +1 -1
  30. package/helpers/dev-host.d.ts +360 -0
  31. package/helpers/dev-host.js +694 -0
  32. package/helpers/dev-host.js.map +1 -0
  33. package/helpers/dynamic-import-plugin.js +4 -2
  34. package/helpers/dynamic-import-plugin.js.map +1 -1
  35. package/helpers/esbuild-platform-resolver.js +4 -1
  36. package/helpers/esbuild-platform-resolver.js.map +1 -1
  37. package/helpers/external-configs.d.ts +10 -12
  38. package/helpers/external-configs.js +58 -35
  39. package/helpers/external-configs.js.map +1 -1
  40. package/helpers/global-defines.d.ts +100 -13
  41. package/helpers/global-defines.js +149 -28
  42. package/helpers/global-defines.js.map +1 -1
  43. package/helpers/hmr-scope.d.ts +26 -0
  44. package/helpers/hmr-scope.js +67 -0
  45. package/helpers/hmr-scope.js.map +1 -0
  46. package/helpers/init.js +0 -18
  47. package/helpers/init.js.map +1 -1
  48. package/helpers/logging.js +29 -1
  49. package/helpers/logging.js.map +1 -1
  50. package/helpers/main-entry.d.ts +4 -1
  51. package/helpers/main-entry.js +368 -53
  52. package/helpers/main-entry.js.map +1 -1
  53. package/helpers/nativeclass-esbuild-plugin.d.ts +2 -1
  54. package/helpers/nativeclass-esbuild-plugin.js.map +1 -1
  55. package/helpers/nativeclass-transform.js +5 -6
  56. package/helpers/nativeclass-transform.js.map +1 -1
  57. package/helpers/nativeclass-transformer-plugin.d.ts +9 -2
  58. package/helpers/nativeclass-transformer-plugin.js +157 -14
  59. package/helpers/nativeclass-transformer-plugin.js.map +1 -1
  60. package/helpers/nativescript-package-resolver.js +10 -62
  61. package/helpers/nativescript-package-resolver.js.map +1 -1
  62. package/helpers/normalize-id.d.ts +42 -0
  63. package/helpers/normalize-id.js +60 -0
  64. package/helpers/normalize-id.js.map +1 -0
  65. package/helpers/ns-core-url.d.ts +29 -7
  66. package/helpers/ns-core-url.js +69 -12
  67. package/helpers/ns-core-url.js.map +1 -1
  68. package/helpers/optimize-deps.d.ts +16 -0
  69. package/helpers/optimize-deps.js +17 -0
  70. package/helpers/optimize-deps.js.map +1 -0
  71. package/helpers/package-platform-aliases.js +34 -49
  72. package/helpers/package-platform-aliases.js.map +1 -1
  73. package/helpers/platform-types.d.ts +2 -0
  74. package/helpers/platform-types.js +2 -0
  75. package/helpers/platform-types.js.map +1 -0
  76. package/helpers/postcss-platform-config.d.ts +17 -1
  77. package/helpers/postcss-platform-config.js +20 -37
  78. package/helpers/postcss-platform-config.js.map +1 -1
  79. package/helpers/project.d.ts +35 -0
  80. package/helpers/project.js +120 -2
  81. package/helpers/project.js.map +1 -1
  82. package/helpers/resolve-main-field-platform.d.ts +20 -0
  83. package/helpers/resolve-main-field-platform.js +49 -0
  84. package/helpers/resolve-main-field-platform.js.map +1 -0
  85. package/helpers/resolver.js +17 -2
  86. package/helpers/resolver.js.map +1 -1
  87. package/helpers/theme-core-plugins.js +1 -1
  88. package/helpers/theme-core-plugins.js.map +1 -1
  89. package/helpers/ts-config-paths.d.ts +32 -0
  90. package/helpers/ts-config-paths.js +156 -27
  91. package/helpers/ts-config-paths.js.map +1 -1
  92. package/helpers/typescript-check.d.ts +2 -1
  93. package/helpers/typescript-check.js +2 -2
  94. package/helpers/typescript-check.js.map +1 -1
  95. package/helpers/ui-registration.d.ts +21 -0
  96. package/helpers/ui-registration.js +156 -0
  97. package/helpers/ui-registration.js.map +1 -0
  98. package/helpers/utils.d.ts +9 -0
  99. package/helpers/utils.js +22 -2
  100. package/helpers/utils.js.map +1 -1
  101. package/helpers/vite-package-version.d.ts +7 -0
  102. package/helpers/vite-package-version.js +44 -0
  103. package/helpers/vite-package-version.js.map +1 -0
  104. package/helpers/workers.d.ts +20 -19
  105. package/helpers/workers.js +624 -4
  106. package/helpers/workers.js.map +1 -1
  107. package/hmr/client/css-handler.d.ts +2 -1
  108. package/hmr/client/css-handler.js +50 -26
  109. package/hmr/client/css-handler.js.map +1 -1
  110. package/hmr/client/css-update-overlay.d.ts +18 -0
  111. package/hmr/client/css-update-overlay.js +27 -0
  112. package/hmr/client/css-update-overlay.js.map +1 -0
  113. package/hmr/client/framework-client-strategy.d.ts +79 -0
  114. package/hmr/client/framework-client-strategy.js +19 -0
  115. package/hmr/client/framework-client-strategy.js.map +1 -0
  116. package/hmr/client/hmr-pending-overlay.d.ts +0 -14
  117. package/hmr/client/hmr-pending-overlay.js +14 -4
  118. package/hmr/client/hmr-pending-overlay.js.map +1 -1
  119. package/hmr/client/hot-context.d.ts +67 -0
  120. package/hmr/client/hot-context.js +284 -0
  121. package/hmr/client/hot-context.js.map +1 -0
  122. package/hmr/client/index.js +922 -273
  123. package/hmr/client/index.js.map +1 -1
  124. package/hmr/client/utils.d.ts +2 -1
  125. package/hmr/client/utils.js +111 -99
  126. package/hmr/client/utils.js.map +1 -1
  127. package/hmr/entry-runtime.d.ts +2 -1
  128. package/hmr/entry-runtime.js +271 -69
  129. package/hmr/entry-runtime.js.map +1 -1
  130. package/hmr/frameworks/angular/build/angular-linker.d.ts +12 -0
  131. package/hmr/frameworks/angular/build/angular-linker.js +109 -0
  132. package/hmr/frameworks/angular/build/angular-linker.js.map +1 -0
  133. package/hmr/frameworks/angular/build/inject-component-hmr-registration.d.ts +112 -0
  134. package/hmr/frameworks/angular/build/inject-component-hmr-registration.js +291 -0
  135. package/hmr/frameworks/angular/build/inject-component-hmr-registration.js.map +1 -0
  136. package/hmr/frameworks/angular/build/inject-hmr-vite-ignore.d.ts +75 -0
  137. package/hmr/frameworks/angular/build/inject-hmr-vite-ignore.js +221 -0
  138. package/hmr/frameworks/angular/build/inject-hmr-vite-ignore.js.map +1 -0
  139. package/{helpers/angular → hmr/frameworks/angular/build}/inline-decorator-component-templates.js +1 -170
  140. package/hmr/frameworks/angular/build/inline-decorator-component-templates.js.map +1 -0
  141. package/hmr/frameworks/angular/build/js-lexer.d.ts +4 -0
  142. package/{helpers/angular/synthesize-decorator-ctor-parameters.js → hmr/frameworks/angular/build/js-lexer.js} +22 -96
  143. package/hmr/frameworks/angular/build/js-lexer.js.map +1 -0
  144. package/hmr/frameworks/angular/build/shared-linker.d.ts +39 -0
  145. package/hmr/frameworks/angular/build/shared-linker.js +128 -0
  146. package/hmr/frameworks/angular/build/shared-linker.js.map +1 -0
  147. package/hmr/frameworks/angular/build/synthesize-decorator-ctor-parameters.js +88 -0
  148. package/hmr/frameworks/angular/build/synthesize-decorator-ctor-parameters.js.map +1 -0
  149. package/{helpers/angular → hmr/frameworks/angular/build}/synthesize-injectable-factories.js +1 -174
  150. package/hmr/frameworks/angular/build/synthesize-injectable-factories.js.map +1 -0
  151. package/{helpers/angular → hmr/frameworks/angular/build}/util.d.ts +1 -0
  152. package/hmr/frameworks/angular/build/util.js +155 -0
  153. package/hmr/frameworks/angular/build/util.js.map +1 -0
  154. package/hmr/frameworks/angular/client/index.js +542 -175
  155. package/hmr/frameworks/angular/client/index.js.map +1 -1
  156. package/hmr/frameworks/angular/client/strategy.d.ts +9 -0
  157. package/hmr/frameworks/angular/client/strategy.js +19 -0
  158. package/hmr/frameworks/angular/client/strategy.js.map +1 -0
  159. package/hmr/frameworks/angular/server/angular-root-component.d.ts +79 -0
  160. package/hmr/frameworks/angular/server/angular-root-component.js +149 -0
  161. package/hmr/frameworks/angular/server/angular-root-component.js.map +1 -0
  162. package/hmr/frameworks/angular/server/linker.js +1 -4
  163. package/hmr/frameworks/angular/server/linker.js.map +1 -1
  164. package/hmr/frameworks/angular/server/strategy.js +458 -12
  165. package/hmr/frameworks/angular/server/strategy.js.map +1 -1
  166. package/hmr/{server → frameworks/angular/server}/websocket-angular-entry.js +2 -2
  167. package/hmr/frameworks/angular/server/websocket-angular-entry.js.map +1 -0
  168. package/hmr/{server → frameworks/angular/server}/websocket-angular-hot-update.d.ts +14 -11
  169. package/hmr/{server → frameworks/angular/server}/websocket-angular-hot-update.js +108 -111
  170. package/hmr/frameworks/angular/server/websocket-angular-hot-update.js.map +1 -0
  171. package/hmr/frameworks/react/server/strategy.d.ts +2 -0
  172. package/hmr/frameworks/react/server/strategy.js +230 -0
  173. package/hmr/frameworks/react/server/strategy.js.map +1 -0
  174. package/hmr/frameworks/solid/build/solid-jsx-deps.d.ts +15 -0
  175. package/hmr/frameworks/solid/build/solid-jsx-deps.js +178 -0
  176. package/hmr/frameworks/solid/build/solid-jsx-deps.js.map +1 -0
  177. package/hmr/frameworks/solid/client/app-runtime.d.ts +68 -0
  178. package/hmr/frameworks/solid/client/app-runtime.js +246 -0
  179. package/hmr/frameworks/solid/client/app-runtime.js.map +1 -0
  180. package/hmr/frameworks/solid/server/strategy.js +291 -16
  181. package/hmr/frameworks/solid/server/strategy.js.map +1 -1
  182. package/hmr/frameworks/typescript/server/strategy.js +38 -14
  183. package/hmr/frameworks/typescript/server/strategy.js.map +1 -1
  184. package/hmr/frameworks/vue/client/dep-propagation.d.ts +44 -0
  185. package/hmr/frameworks/vue/client/dep-propagation.js +148 -0
  186. package/hmr/frameworks/vue/client/dep-propagation.js.map +1 -0
  187. package/hmr/frameworks/vue/client/index.d.ts +9 -0
  188. package/hmr/frameworks/vue/client/index.js +251 -247
  189. package/hmr/frameworks/vue/client/index.js.map +1 -1
  190. package/hmr/frameworks/vue/client/strategy.d.ts +33 -0
  191. package/hmr/frameworks/vue/client/strategy.js +157 -0
  192. package/hmr/frameworks/vue/client/strategy.js.map +1 -0
  193. package/hmr/frameworks/vue/client/vue-sfc-update-overlay.d.ts +49 -0
  194. package/hmr/frameworks/vue/client/vue-sfc-update-overlay.js +142 -0
  195. package/hmr/frameworks/vue/client/vue-sfc-update-overlay.js.map +1 -0
  196. package/hmr/frameworks/vue/server/compiler.d.ts +3 -1
  197. package/hmr/frameworks/vue/server/compiler.js +3 -1
  198. package/hmr/frameworks/vue/server/compiler.js.map +1 -1
  199. package/hmr/frameworks/vue/server/sfc-route-assemble.d.ts +7 -0
  200. package/hmr/frameworks/vue/server/sfc-route-assemble.js +823 -0
  201. package/hmr/frameworks/vue/server/sfc-route-assemble.js.map +1 -0
  202. package/hmr/frameworks/vue/server/sfc-route-meta.d.ts +7 -0
  203. package/hmr/frameworks/vue/server/sfc-route-meta.js +80 -0
  204. package/hmr/frameworks/vue/server/sfc-route-meta.js.map +1 -0
  205. package/hmr/frameworks/vue/server/sfc-route-serve.d.ts +8 -0
  206. package/hmr/frameworks/vue/server/sfc-route-serve.js +462 -0
  207. package/hmr/frameworks/vue/server/sfc-route-serve.js.map +1 -0
  208. package/hmr/frameworks/vue/server/sfc-route-shared.d.ts +45 -0
  209. package/hmr/frameworks/vue/server/sfc-route-shared.js +105 -0
  210. package/hmr/frameworks/vue/server/sfc-route-shared.js.map +1 -0
  211. package/hmr/frameworks/vue/server/strategy.d.ts +35 -0
  212. package/hmr/frameworks/vue/server/strategy.js +286 -7
  213. package/hmr/frameworks/vue/server/strategy.js.map +1 -1
  214. package/hmr/frameworks/vue/server/websocket-sfc.d.ts +15 -0
  215. package/hmr/frameworks/vue/server/websocket-sfc.js +20 -0
  216. package/hmr/frameworks/vue/server/websocket-sfc.js.map +1 -0
  217. package/hmr/helpers/ast-normalizer.d.ts +3 -1
  218. package/hmr/helpers/ast-normalizer.js +77 -10
  219. package/hmr/helpers/ast-normalizer.js.map +1 -1
  220. package/hmr/helpers/cjs-named-exports.d.ts +23 -0
  221. package/hmr/helpers/cjs-named-exports.js +152 -0
  222. package/hmr/helpers/cjs-named-exports.js.map +1 -0
  223. package/hmr/helpers/package-exports.d.ts +16 -0
  224. package/hmr/helpers/package-exports.js +396 -0
  225. package/hmr/helpers/package-exports.js.map +1 -0
  226. package/hmr/helpers/vendor-rewrite.d.ts +1 -1
  227. package/hmr/helpers/vendor-rewrite.js +5 -3
  228. package/hmr/helpers/vendor-rewrite.js.map +1 -1
  229. package/hmr/server/boot-archive-route.d.ts +40 -0
  230. package/hmr/server/boot-archive-route.js +154 -0
  231. package/hmr/server/boot-archive-route.js.map +1 -0
  232. package/hmr/server/boot-closure-route.d.ts +49 -0
  233. package/hmr/server/boot-closure-route.js +144 -0
  234. package/hmr/server/boot-closure-route.js.map +1 -0
  235. package/hmr/server/boot-recording.d.ts +58 -0
  236. package/hmr/server/boot-recording.js +228 -0
  237. package/hmr/server/boot-recording.js.map +1 -0
  238. package/hmr/server/constants.js +20 -5
  239. package/hmr/server/constants.js.map +1 -1
  240. package/hmr/server/core-bundle.d.ts +140 -0
  241. package/hmr/server/core-bundle.js +614 -0
  242. package/hmr/server/core-bundle.js.map +1 -0
  243. package/hmr/server/core-sanitize.d.ts +86 -7
  244. package/hmr/server/core-sanitize.js +170 -45
  245. package/hmr/server/core-sanitize.js.map +1 -1
  246. package/hmr/server/css-device-module.d.ts +28 -0
  247. package/hmr/server/css-device-module.js +44 -0
  248. package/hmr/server/css-device-module.js.map +1 -0
  249. package/hmr/server/deps-bundle.d.ts +218 -0
  250. package/hmr/server/deps-bundle.js +984 -0
  251. package/hmr/server/deps-bundle.js.map +1 -0
  252. package/hmr/server/device-transform-helpers.d.ts +24 -0
  253. package/hmr/server/device-transform-helpers.js +408 -0
  254. package/hmr/server/device-transform-helpers.js.map +1 -0
  255. package/hmr/server/framework-strategy.d.ts +113 -11
  256. package/hmr/server/hmr-module-graph.d.ts +37 -0
  257. package/hmr/server/hmr-module-graph.js +215 -0
  258. package/hmr/server/hmr-module-graph.js.map +1 -0
  259. package/hmr/server/import-map.d.ts +13 -4
  260. package/hmr/server/import-map.js +94 -47
  261. package/hmr/server/import-map.js.map +1 -1
  262. package/hmr/server/index.js +7 -16
  263. package/hmr/server/index.js.map +1 -1
  264. package/hmr/server/ns-core-cjs-shape.d.ts +2 -4
  265. package/hmr/server/ns-core-cjs-shape.js +4 -6
  266. package/hmr/server/ns-core-cjs-shape.js.map +1 -1
  267. package/hmr/server/ns-m-response-memo.d.ts +10 -0
  268. package/hmr/server/ns-m-response-memo.js +33 -0
  269. package/hmr/server/ns-m-response-memo.js.map +1 -0
  270. package/hmr/server/ns-rt-bridge.d.ts +51 -0
  271. package/hmr/server/ns-rt-bridge.js +131 -0
  272. package/hmr/server/ns-rt-bridge.js.map +1 -0
  273. package/hmr/server/ns-rt-route.d.ts +5 -0
  274. package/hmr/server/ns-rt-route.js +39 -0
  275. package/hmr/server/ns-rt-route.js.map +1 -0
  276. package/hmr/server/perf-instrumentation.d.ts +6 -10
  277. package/hmr/server/perf-instrumentation.js +5 -6
  278. package/hmr/server/perf-instrumentation.js.map +1 -1
  279. package/hmr/server/process-code-for-device.d.ts +30 -0
  280. package/hmr/server/process-code-for-device.js +791 -0
  281. package/hmr/server/process-code-for-device.js.map +1 -0
  282. package/hmr/server/require-guard.d.ts +1 -0
  283. package/hmr/server/require-guard.js +12 -0
  284. package/hmr/server/require-guard.js.map +1 -0
  285. package/hmr/server/rewrite-imports.d.ts +2 -0
  286. package/hmr/server/rewrite-imports.js +630 -0
  287. package/hmr/server/rewrite-imports.js.map +1 -0
  288. package/hmr/server/route-helpers.d.ts +7 -0
  289. package/hmr/server/route-helpers.js +13 -0
  290. package/hmr/server/route-helpers.js.map +1 -0
  291. package/hmr/server/server-origin.d.ts +2 -0
  292. package/hmr/server/server-origin.js +83 -0
  293. package/hmr/server/server-origin.js.map +1 -0
  294. package/hmr/server/shared-transform-request.js +1 -2
  295. package/hmr/server/shared-transform-request.js.map +1 -1
  296. package/hmr/server/transform-cache-invalidation.d.ts +37 -0
  297. package/hmr/server/transform-cache-invalidation.js +156 -0
  298. package/hmr/server/transform-cache-invalidation.js.map +1 -0
  299. package/hmr/server/vendor-bare-module-shims.d.ts +4 -0
  300. package/hmr/server/vendor-bare-module-shims.js +80 -0
  301. package/hmr/server/vendor-bare-module-shims.js.map +1 -0
  302. package/hmr/server/vite-plugin.d.ts +1 -0
  303. package/hmr/server/vite-plugin.js +180 -54
  304. package/hmr/server/vite-plugin.js.map +1 -1
  305. package/hmr/server/websocket-core-bridge.d.ts +51 -4
  306. package/hmr/server/websocket-core-bridge.js +62 -54
  307. package/hmr/server/websocket-core-bridge.js.map +1 -1
  308. package/hmr/server/websocket-css-hot-update.d.ts +33 -0
  309. package/hmr/server/websocket-css-hot-update.js +65 -0
  310. package/hmr/server/websocket-css-hot-update.js.map +1 -0
  311. package/hmr/server/websocket-device-transform.d.ts +3 -0
  312. package/hmr/server/websocket-device-transform.js +7 -0
  313. package/hmr/server/websocket-device-transform.js.map +1 -0
  314. package/hmr/server/websocket-hmr-pending.d.ts +3 -9
  315. package/hmr/server/websocket-hmr-pending.js +1 -1
  316. package/hmr/server/websocket-hmr-pending.js.map +1 -1
  317. package/hmr/server/websocket-hot-update.d.ts +77 -0
  318. package/hmr/server/websocket-hot-update.js +360 -0
  319. package/hmr/server/websocket-hot-update.js.map +1 -0
  320. package/hmr/server/websocket-import-map-route.d.ts +15 -0
  321. package/hmr/server/websocket-import-map-route.js +50 -0
  322. package/hmr/server/websocket-import-map-route.js.map +1 -0
  323. package/hmr/server/websocket-module-bindings.js +3 -3
  324. package/hmr/server/websocket-module-bindings.js.map +1 -1
  325. package/hmr/server/websocket-module-specifiers.d.ts +66 -2
  326. package/hmr/server/websocket-module-specifiers.js +191 -20
  327. package/hmr/server/websocket-module-specifiers.js.map +1 -1
  328. package/hmr/server/websocket-ns-core.d.ts +34 -0
  329. package/hmr/server/websocket-ns-core.js +414 -0
  330. package/hmr/server/websocket-ns-core.js.map +1 -0
  331. package/hmr/server/websocket-ns-entry.d.ts +21 -0
  332. package/hmr/server/websocket-ns-entry.js +164 -0
  333. package/hmr/server/websocket-ns-entry.js.map +1 -0
  334. package/hmr/server/websocket-ns-m-paths.d.ts +1 -3
  335. package/hmr/server/websocket-ns-m-paths.js +25 -82
  336. package/hmr/server/websocket-ns-m-paths.js.map +1 -1
  337. package/hmr/server/websocket-ns-m-request.d.ts +11 -1
  338. package/hmr/server/websocket-ns-m-request.js +17 -9
  339. package/hmr/server/websocket-ns-m-request.js.map +1 -1
  340. package/hmr/server/websocket-ns-m.d.ts +52 -0
  341. package/hmr/server/websocket-ns-m.js +824 -0
  342. package/hmr/server/websocket-ns-m.js.map +1 -0
  343. package/hmr/server/websocket-served-module-helpers.d.ts +50 -4
  344. package/hmr/server/websocket-served-module-helpers.js +384 -86
  345. package/hmr/server/websocket-served-module-helpers.js.map +1 -1
  346. package/hmr/server/websocket-txn.js +6 -9
  347. package/hmr/server/websocket-txn.js.map +1 -1
  348. package/hmr/server/websocket-vendor-unifier.d.ts +0 -1
  349. package/hmr/server/websocket-vendor-unifier.js +4 -9
  350. package/hmr/server/websocket-vendor-unifier.js.map +1 -1
  351. package/hmr/server/websocket.d.ts +7 -39
  352. package/hmr/server/websocket.js +643 -6716
  353. package/hmr/server/websocket.js.map +1 -1
  354. package/hmr/shared/ns-globals.d.ts +108 -0
  355. package/hmr/shared/ns-globals.js +28 -0
  356. package/hmr/shared/ns-globals.js.map +1 -0
  357. package/hmr/shared/protocol.d.ts +145 -0
  358. package/hmr/shared/protocol.js +28 -0
  359. package/hmr/shared/protocol.js.map +1 -0
  360. package/hmr/shared/runtime/boot-archive-format.d.ts +16 -0
  361. package/hmr/shared/runtime/boot-archive-format.js +31 -0
  362. package/hmr/shared/runtime/boot-archive-format.js.map +1 -0
  363. package/hmr/shared/runtime/boot-complete.d.ts +14 -0
  364. package/hmr/shared/runtime/boot-complete.js +32 -0
  365. package/hmr/shared/runtime/boot-complete.js.map +1 -0
  366. package/hmr/shared/runtime/boot-placeholder-ui.d.ts +69 -0
  367. package/hmr/shared/runtime/boot-placeholder-ui.js +101 -0
  368. package/hmr/shared/runtime/boot-placeholder-ui.js.map +1 -0
  369. package/hmr/shared/runtime/boot-progress.d.ts +44 -0
  370. package/hmr/shared/runtime/boot-progress.js +134 -0
  371. package/hmr/shared/runtime/boot-progress.js.map +1 -0
  372. package/hmr/shared/runtime/boot-timeline.d.ts +2 -1
  373. package/hmr/shared/runtime/boot-timeline.js +9 -22
  374. package/hmr/shared/runtime/boot-timeline.js.map +1 -1
  375. package/hmr/shared/runtime/browser-runtime-contract.d.ts +53 -22
  376. package/hmr/shared/runtime/browser-runtime-contract.js +6 -9
  377. package/hmr/shared/runtime/browser-runtime-contract.js.map +1 -1
  378. package/hmr/shared/runtime/dev-overlay-snapshots.d.ts +31 -0
  379. package/hmr/shared/runtime/dev-overlay-snapshots.js +324 -0
  380. package/hmr/shared/runtime/dev-overlay-snapshots.js.map +1 -0
  381. package/hmr/shared/runtime/dev-overlay.d.ts +76 -30
  382. package/hmr/shared/runtime/dev-overlay.js +767 -408
  383. package/hmr/shared/runtime/dev-overlay.js.map +1 -1
  384. package/hmr/shared/runtime/global-scope.d.ts +18 -0
  385. package/hmr/shared/runtime/global-scope.js +21 -0
  386. package/hmr/shared/runtime/global-scope.js.map +1 -0
  387. package/hmr/shared/runtime/hooks.js +2 -1
  388. package/hmr/shared/runtime/hooks.js.map +1 -1
  389. package/hmr/shared/runtime/http-only-boot.js +7 -6
  390. package/hmr/shared/runtime/http-only-boot.js.map +1 -1
  391. package/hmr/shared/runtime/module-provenance.js +4 -6
  392. package/hmr/shared/runtime/module-provenance.js.map +1 -1
  393. package/hmr/shared/runtime/root-placeholder-view.d.ts +19 -0
  394. package/hmr/shared/runtime/root-placeholder-view.js +311 -0
  395. package/hmr/shared/runtime/root-placeholder-view.js.map +1 -0
  396. package/hmr/shared/runtime/root-placeholder.js +398 -204
  397. package/hmr/shared/runtime/root-placeholder.js.map +1 -1
  398. package/hmr/shared/runtime/session-bootstrap.js +255 -50
  399. package/hmr/shared/runtime/session-bootstrap.js.map +1 -1
  400. package/hmr/shared/runtime/vendor-bootstrap.js +3 -10
  401. package/hmr/shared/runtime/vendor-bootstrap.js.map +1 -1
  402. package/hmr/shared/vendor/manifest-collect.d.ts +4 -0
  403. package/hmr/shared/vendor/manifest-collect.js +549 -0
  404. package/hmr/shared/vendor/manifest-collect.js.map +1 -0
  405. package/hmr/shared/vendor/manifest-loader.d.ts +2 -1
  406. package/hmr/shared/vendor/manifest-loader.js +5 -3
  407. package/hmr/shared/vendor/manifest-loader.js.map +1 -1
  408. package/hmr/shared/vendor/manifest.d.ts +1 -7
  409. package/hmr/shared/vendor/manifest.js +125 -825
  410. package/hmr/shared/vendor/manifest.js.map +1 -1
  411. package/hmr/shared/vendor/registry.d.ts +2 -0
  412. package/hmr/shared/vendor/registry.js +14 -0
  413. package/hmr/shared/vendor/registry.js.map +1 -1
  414. package/hmr/shared/vendor/vendor-device-shim.d.ts +1 -0
  415. package/hmr/shared/vendor/vendor-device-shim.js +208 -0
  416. package/hmr/shared/vendor/vendor-device-shim.js.map +1 -0
  417. package/hmr/shared/vendor/vendor-esbuild-plugins.d.ts +38 -0
  418. package/hmr/shared/vendor/vendor-esbuild-plugins.js +296 -0
  419. package/hmr/shared/vendor/vendor-esbuild-plugins.js.map +1 -0
  420. package/hmr/vendor-bootstrap.d.ts +1 -3
  421. package/hmr/vendor-bootstrap.js +4 -6
  422. package/hmr/vendor-bootstrap.js.map +1 -1
  423. package/index.d.ts +1 -0
  424. package/index.js +5 -0
  425. package/index.js.map +1 -1
  426. package/package.json +65 -11
  427. package/runtime/core-aliases-early.js +25 -55
  428. package/runtime/core-aliases-early.js.map +1 -1
  429. package/shims/react-jsx-runtime.d.ts +4 -0
  430. package/shims/react-jsx-runtime.js +61 -0
  431. package/shims/react-jsx-runtime.js.map +1 -0
  432. package/helpers/angular/angular-linker.d.ts +0 -13
  433. package/helpers/angular/angular-linker.js +0 -194
  434. package/helpers/angular/angular-linker.js.map +0 -1
  435. package/helpers/angular/inline-decorator-component-templates.js.map +0 -1
  436. package/helpers/angular/shared-linker.d.ts +0 -11
  437. package/helpers/angular/shared-linker.js +0 -75
  438. package/helpers/angular/shared-linker.js.map +0 -1
  439. package/helpers/angular/synthesize-decorator-ctor-parameters.js.map +0 -1
  440. package/helpers/angular/synthesize-injectable-factories.js.map +0 -1
  441. package/helpers/angular/util.js +0 -67
  442. package/helpers/angular/util.js.map +0 -1
  443. package/helpers/prelink-angular.d.ts +0 -2
  444. package/helpers/prelink-angular.js +0 -117
  445. package/helpers/prelink-angular.js.map +0 -1
  446. package/hmr/server/websocket-angular-entry.js.map +0 -1
  447. package/hmr/server/websocket-angular-hot-update.js.map +0 -1
  448. package/hmr/server/websocket-ns-m-finalize.d.ts +0 -22
  449. package/hmr/server/websocket-ns-m-finalize.js +0 -88
  450. package/hmr/server/websocket-ns-m-finalize.js.map +0 -1
  451. package/hmr/server/websocket-runtime-compat.d.ts +0 -19
  452. package/hmr/server/websocket-runtime-compat.js +0 -286
  453. package/hmr/server/websocket-runtime-compat.js.map +0 -1
  454. package/hmr/server/websocket-vue-sfc.d.ts +0 -27
  455. package/hmr/server/websocket-vue-sfc.js +0 -1114
  456. package/hmr/server/websocket-vue-sfc.js.map +0 -1
  457. package/transformers/NativeClass/index.d.ts +0 -2
  458. package/transformers/NativeClass/index.js +0 -222
  459. package/transformers/NativeClass/index.js.map +0 -1
  460. /package/{helpers/angular → hmr/frameworks/angular/build}/inline-decorator-component-templates.d.ts +0 -0
  461. /package/{helpers/angular → hmr/frameworks/angular/build}/synthesize-decorator-ctor-parameters.d.ts +0 -0
  462. /package/{helpers/angular → hmr/frameworks/angular/build}/synthesize-injectable-factories.d.ts +0 -0
  463. /package/hmr/{server → frameworks/angular/server}/websocket-angular-entry.d.ts +0 -0
@@ -1,12 +1,12 @@
1
1
  import * as esbuild from 'esbuild';
2
- import { readFile } from 'fs/promises';
3
2
  import path from 'path';
4
- import { readFileSync } from 'fs';
5
3
  import { createHash } from 'crypto';
6
- import { createRequire } from 'node:module';
7
- import { registerVendorManifest, clearVendorManifest, getVendorManifest } from './registry.js';
4
+ import { registerVendorManifest, clearVendorManifest, getVendorManifest, getVendorRuntimeModule } from './registry.js';
5
+ import { collectVendorModules } from './manifest-collect.js';
8
6
  import { generatePlatformPolyfills } from '../runtime/platform-polyfills.js';
9
7
  import { createNativeClassEsbuildPlugin } from '../../../helpers/nativeclass-esbuild-plugin.js';
8
+ import { getGlobalDefines } from '../../../helpers/global-defines.js';
9
+ import { createVendorEsbuildPlugin, createSolidJsxEsbuildPlugin, angularLinkerEsbuildPlugin, createUnicodeRegexEsbuildPlugin } from './vendor-esbuild-plugins.js';
10
10
  export const VENDOR_MANIFEST_ID = '@nativescript/vendor-manifest';
11
11
  export const VENDOR_MANIFEST_VIRTUAL_ID = '\0' + VENDOR_MANIFEST_ID;
12
12
  export const VENDOR_BUNDLE_ID = '@nativescript/vendor';
@@ -15,105 +15,6 @@ export const SERVER_VENDOR_PATH = '/@nativescript/vendor.mjs';
15
15
  export const SERVER_MANIFEST_PATH = '/@nativescript/vendor-manifest.json';
16
16
  export const DEFAULT_VENDOR_FILENAME = 'ns-vendor.mjs';
17
17
  export const DEFAULT_MANIFEST_FILENAME = 'ns-vendor-manifest.json';
18
- // Do not force-include @nativescript/core in the dev vendor bundle.
19
- // Keeping core out of vendor avoids duplicate side-effect registrations (e.g.,
20
- // com.tns.FragmentClass, com.tns.NativeScriptActivity) across bundle.mjs and vendor.
21
- // Force runtime-sensitive packages onto the vendor path so they do not drift
22
- // between startup bundle, HTTP-wrapped CommonJS, and base-require semantics
23
- // during HMR sessions.
24
- const ALWAYS_INCLUDE = new Set(['stacktrace-js']);
25
- const ALWAYS_EXCLUDE = new Set([
26
- '@nativescript/android',
27
- '@nativescript/ios',
28
- '@nativescript/types',
29
- '@nativescript/webpack',
30
- // Angular browser animations are not used in NativeScript; excluding reduces
31
- // memory pressure and avoids bringing partial declarations into vendor.
32
- '@angular/animations',
33
- '@angular/platform-browser/animations',
34
- // Not needed at runtime with linked partials; reduce vendor size/memory.
35
- '@angular/platform-browser-dynamic',
36
- // Native add-on helpers pulled by ws or others; exclude in NS dev vendor
37
- 'bufferutil',
38
- 'utf-8-validate',
39
- 'node-gyp-build',
40
- 'bufferutil',
41
- 'utf-8-validate',
42
- 'node-gyp-build',
43
- // All @babel/* and babel-* packages are build-time tools, never runtime deps.
44
- // They get pulled in as peer deps of packages like @nativescript-community/solid-js
45
- // but should never be in the vendor bundle (they require 'fs', 'path', etc.).
46
- '@babel/core',
47
- '@babel/helper-plugin-utils',
48
- '@babel/generator',
49
- '@babel/helper-string-parser',
50
- '@babel/helper-validator-identifier',
51
- '@babel/parser',
52
- '@babel/plugin-syntax-typescript',
53
- '@babel/plugin-transform-typescript',
54
- '@babel/preset-typescript',
55
- '@babel/preset-env',
56
- '@babel/types',
57
- 'babel-preset-solid',
58
- 'babel-plugin-jsx-dom-expressions',
59
- // Heavy dependency not needed in vendor dev bundle; fetch via HTTP loader instead
60
- 'rxjs',
61
- 'nativescript',
62
- 'typescript',
63
- 'ts-node',
64
- 'vue-tsc',
65
- 'ws',
66
- '@types/node',
67
- 'nativescript-theme-core',
68
- // Build-time tools that get pulled in as transitive dependencies but should
69
- // never be in the device vendor bundle (they require Node built-ins like fs,
70
- // path, child_process, etc.). Now that we collect transitive runtime deps,
71
- // these need explicit exclusion.
72
- 'esbuild',
73
- 'prettier',
74
- 'acorn',
75
- 'recast',
76
- 'source-map',
77
- 'source-map-js',
78
- 'tsx',
79
- 'diff',
80
- 'esprima',
81
- // TanStack build-time router tooling (code generation, file-based routing)
82
- '@tanstack/router-plugin',
83
- '@tanstack/router-generator',
84
- '@tanstack/router-utils',
85
- '@tanstack/virtual-file-routes',
86
- // File system / glob utilities — build-time only, require Node fs
87
- 'fdir',
88
- 'picomatch',
89
- 'tinyglobby',
90
- // SSR-only library (bot detection) — not needed on device
91
- 'isbot',
92
- // Type-only packages with no runtime JavaScript
93
- 'csstype',
94
- // NativeScript CLI hook system — build-time only, requires Node os/path
95
- '@nativescript/hook',
96
- // Test runner uses webpack's require.context API which doesn't exist in Vite.
97
- // Including it in the vendor bundle causes __require.context crashes at runtime.
98
- '@nativescript/unit-test-runner',
99
- 'nativescript-unit-test-runner',
100
- // CSS build tools — postcss, tailwindcss, and related tooling are exclusively
101
- // build-time processors. They require Node APIs (process, fs, path) and must
102
- // never run on device. esbuild bundles their transitive deps (picocolors,
103
- // nanoid, etc.) which reference `process` and crash at runtime.
104
- 'tailwindcss',
105
- '@nativescript/tailwind',
106
- 'postcss',
107
- 'autoprefixer',
108
- 'postcss-import',
109
- 'postcss-url',
110
- 'postcss-nested',
111
- 'picocolors',
112
- 'nanoid',
113
- // Server-side SDKs that require Node networking APIs (net, tls, dns, crypto).
114
- // These are backend tools, not device-side.
115
- 'mongodb',
116
- ]);
117
18
  const INDEX_ALIAS_SUFFIXES = ['/index', '/index.js', '/index.android.js', '/index.ios.js', '/index.visionos.js'];
118
19
  export function vendorManifestPlugin(options) {
119
20
  let cachedResult = null;
@@ -157,15 +58,42 @@ export function vendorManifestPlugin(options) {
157
58
  cachedResult = null;
158
59
  clearVendorManifest();
159
60
  };
61
+ // Manifest registration without the esbuild payload build. The dev serve
62
+ // process only needs the manifest (module ids + aliases) for the import
63
+ // map and vendor-routing decisions — the payload itself is deps-backed
64
+ // (see getVendorRuntimeModule). The full build stays lazy, reached only
65
+ // through the fallback serving path or the build-process virtual modules.
66
+ const ensureManifestRegistered = () => {
67
+ if (getVendorManifest())
68
+ return;
69
+ const collected = collectVendorModules(options.projectRoot, options.platform, options.flavor);
70
+ const hash = createHash('sha1').update(JSON.stringify(collected.entries)).digest('hex');
71
+ registerVendorManifest(buildManifest(collected.entries, hash));
72
+ };
160
73
  const respondWithVendor = async (_server, req, res) => {
161
74
  try {
162
- const result = await ensureResult('server');
163
75
  if (req.url === SERVER_VENDOR_PATH) {
76
+ // ONE node_modules payload: when the deps bundle is active, the
77
+ // vendor module is a thin view over /ns/deps-bundle.mjs.
78
+ const depsBacked = getVendorRuntimeModule();
79
+ if (depsBacked !== null) {
80
+ res.setHeader('Content-Type', 'application/javascript');
81
+ res.end(depsBacked);
82
+ return true;
83
+ }
84
+ const result = await ensureResult('server');
164
85
  res.setHeader('Content-Type', 'application/javascript');
165
86
  res.end(createVendorBundleRuntimeModule(result));
166
87
  return true;
167
88
  }
168
89
  if (req.url === SERVER_MANIFEST_PATH) {
90
+ const registered = getVendorManifest();
91
+ if (registered) {
92
+ res.setHeader('Content-Type', 'application/json');
93
+ res.end(JSON.stringify(registered, null, 2));
94
+ return true;
95
+ }
96
+ const result = await ensureResult('server');
169
97
  res.setHeader('Content-Type', 'application/json');
170
98
  res.end(JSON.stringify(result.manifest, null, 2));
171
99
  return true;
@@ -184,7 +112,12 @@ export function vendorManifestPlugin(options) {
184
112
  enforce: 'pre',
185
113
  configResolved() { },
186
114
  async configureServer(server) {
187
- await ensureResult('server-start');
115
+ try {
116
+ ensureManifestRegistered();
117
+ }
118
+ catch (error) {
119
+ console.error('[vendor] failed to register vendor manifest at server start', error);
120
+ }
188
121
  server.middlewares.use(async (req, res, next) => {
189
122
  if (req.url === SERVER_VENDOR_PATH || req.url === SERVER_MANIFEST_PATH) {
190
123
  const handled = await respondWithVendor(server, req, res);
@@ -202,9 +135,12 @@ export function vendorManifestPlugin(options) {
202
135
  return;
203
136
  }
204
137
  resetCache();
205
- ensureResult('package.json change').catch((error) => {
206
- console.error('[vendor] failed to regenerate vendor bundle', error);
207
- });
138
+ try {
139
+ ensureManifestRegistered();
140
+ }
141
+ catch (error) {
142
+ console.error('[vendor] failed to regenerate vendor manifest', error);
143
+ }
208
144
  });
209
145
  },
210
146
  async buildStart() {
@@ -289,10 +225,41 @@ async function generateVendorBundle(options) {
289
225
  }));
290
226
  },
291
227
  };
228
+ // Externalize the `solid-js` root specifier for the Solid flavor so
229
+ // vendor-bundled packages (e.g. `@nativescript-community/solid-js`,
230
+ // `solid-navigation`, transitively `solid-js/universal` and
231
+ // `solid-js/store`) don't bake their own copy of solid-js into
232
+ // vendor.mjs. The dev server's import map (see `import-map.ts`)
233
+ // redirects bare `solid-js` to the same `/ns/m/node_modules/solid-js/...`
234
+ // URL that Vite's alias produces for user code and `@solid-refresh`,
235
+ // so V8 dedupes the three import paths down to a single module
236
+ // instance — one `Owner` module-local, one reactive graph, one
237
+ // `$DEVCOMP`/`$PROXY` symbol identity across the whole app.
238
+ //
239
+ // Important: scope this to the EXACT bare `solid-js` specifier. Subpaths
240
+ // like `solid-js/store`, `solid-js/universal`, `solid-js/web` stay
241
+ // bundleable so vendor packages that import them keep working out of
242
+ // the box; those subpaths still go through the unified solid-js
243
+ // runtime via their own `import 'solid-js'` statements (which we just
244
+ // externalized).
245
+ const nsSolidJsExternalPlugin = {
246
+ name: 'ns-solid-js-external',
247
+ setup(build) {
248
+ build.onResolve({ filter: /^solid-js$/ }, (args) => ({
249
+ path: args.path,
250
+ external: true,
251
+ }));
252
+ },
253
+ };
292
254
  const plugins = [
293
255
  // Mark @nativescript/core external BEFORE other plugins so esbuild never
294
256
  // tries to read/transform core's source files. See comment above.
295
257
  nsCoreExternalPlugin,
258
+ // For the Solid flavor, externalize `solid-js` so vendor.mjs and the
259
+ // HTTP-served `@solid-refresh` / user code converge on one runtime
260
+ // realm. See `nsSolidJsExternalPlugin`'s definition for the full
261
+ // duplicate-instance rationale.
262
+ ...(flavor === 'solid' ? [nsSolidJsExternalPlugin] : []),
296
263
  // Apply NativeClass transformer to convert @NativeClass decorated classes to ES5 IIFE pattern.
297
264
  // This MUST run before other plugins to ensure proper transformation.
298
265
  createNativeClassEsbuildPlugin(platform),
@@ -314,6 +281,12 @@ async function generateVendorBundle(options) {
314
281
  if (flavor === 'solid') {
315
282
  plugins.push(createSolidJsxEsbuildPlugin(projectRoot));
316
283
  }
284
+ // Registered last so the framework-specific passes above own their files
285
+ // first (esbuild stops at the first onLoad that returns a result). Applies
286
+ // to every flavor: any vendored dependency (e.g. highlight.js) may ship
287
+ // `\p{…}` regexes that NativeScript's non-ICU V8 cannot compile, which would
288
+ // otherwise abort the entire vendor.mjs compile. See the plugin for details.
289
+ plugins.push(createUnicodeRegexEsbuildPlugin(projectRoot));
317
290
  const buildResult = await esbuild.build({
318
291
  stdin: {
319
292
  contents: entryCode,
@@ -353,9 +326,31 @@ async function generateVendorBundle(options) {
353
326
  '.css': 'text',
354
327
  '.json': 'json',
355
328
  },
356
- define: {
357
- 'process.env.NODE_ENV': JSON.stringify(mode),
358
- },
329
+ // Mirror Vite's main-bundle DefinePlugin in the vendor esbuild build.
330
+ //
331
+ // esbuild's `define` requires every value to be a JS expression
332
+ // expressed as a string (the same constraint Vite normalises away).
333
+ // `getGlobalDefines()` returns a few raw `boolean` values for
334
+ // historical reasons (e.g. `__COMMONJS__: false`,
335
+ // `__UI_USE_XML_PARSER__: true`), so coerce any non-string entries
336
+ // through `JSON.stringify` before handing the table to esbuild.
337
+ define: (() => {
338
+ const raw = getGlobalDefines({
339
+ platform,
340
+ targetMode: mode,
341
+ verbose: !!options.verbose,
342
+ flavor: flavor ?? '',
343
+ isCI: !!process.env.CI,
344
+ });
345
+ const out = {};
346
+ for (const [key, value] of Object.entries(raw)) {
347
+ out[key] = typeof value === 'string' ? value : JSON.stringify(value);
348
+ }
349
+ // Belt-and-suspenders: keep the original NODE_ENV define explicit so
350
+ // future changes to `getGlobalDefines()` can't silently drop it.
351
+ out['process.env.NODE_ENV'] = JSON.stringify(mode);
352
+ return out;
353
+ })(),
359
354
  plugins,
360
355
  // Externalize ALL Node built-in modules. The vendor bundle runs on the
361
356
  // NativeScript device runtime, not Node, so any Node API reference must
@@ -477,238 +472,32 @@ async function generateVendorBundle(options) {
477
472
  entries: collected.entries,
478
473
  };
479
474
  }
480
- function collectVendorModules(projectRoot, platform, flavor) {
481
- const packageJsonPath = path.resolve(projectRoot, 'package.json');
482
- const pkg = JSON.parse(readFileSync(packageJsonPath, 'utf-8'));
483
- const projectRequire = createRequire(packageJsonPath);
484
- const vendor = new Set();
485
- const visited = new Set();
486
- const queue = [];
487
- const isPackageRootSpecifier = (name) => {
488
- if (!name)
489
- return false;
490
- if (name.startsWith('@')) {
491
- // Scoped: @scope/name is root; anything deeper is subpath
492
- const parts = name.split('/');
493
- return parts.length === 2;
494
- }
495
- // Unscoped: no slash means root; any slash means subpath
496
- return !name.includes('/');
497
- };
498
- const isAngularFlavor = flavor === 'angular';
499
- const addCandidate = (name) => {
500
- if (!name || shouldSkipDependency(name)) {
501
- return;
502
- }
503
- // Avoid pulling Angular compiler/runtime into the dev vendor bundle when
504
- // the current project flavor is not Angular (for example, solid). This
505
- // prevents esbuild from trying to bundle @angular/compiler and its Babel
506
- // toolchain, which requires Node built-ins like fs/path/url.
507
- if (!isAngularFlavor && (name === '@angular/compiler' || name.startsWith('@angular/'))) {
508
- return;
509
- }
510
- // Skip already-visited packages to avoid redundant queue processing
511
- if (visited.has(name)) {
512
- return;
513
- }
514
- visited.add(name);
515
- vendor.add(name);
516
- const isRoot = isPackageRootSpecifier(name);
517
- // Only traverse deps for package roots; subpaths should not attempt package.json resolution
518
- if (isRoot) {
519
- queue.push(name);
520
- }
521
- };
522
- const addDeps = (deps) => {
523
- if (!deps) {
524
- return;
525
- }
526
- for (const name of Object.keys(deps)) {
527
- addCandidate(name);
528
- }
529
- };
530
- addDeps(pkg.dependencies);
531
- addDeps(pkg.optionalDependencies);
532
- for (const name of ALWAYS_INCLUDE) {
533
- // Some force-included packages are only present transitively in apps that
534
- // actually use them. Skip missing packages quietly so unrelated projects do
535
- // not fail vendor collection just because the policy list names them.
536
- if (canResolveDependencyPackageJson(name, projectRequire)) {
537
- addCandidate(name);
538
- }
539
- }
540
- // Ensure Android Activity proxy is present for SBG scanning in dev/HMR
541
- // and non-HMR builds alike: explicitly include the side-effect module
542
- // that registers `com.tns.NativeScriptActivity`.
543
- if (platform === 'android') {
544
- addCandidate('@nativescript/core/ui/frame/activity.android');
545
- }
546
- if (pkg.dependencies?.['nativescript-vue'] && pkg.devDependencies?.vue) {
547
- addCandidate('vue');
548
- }
549
- // Angular framework packages are intentionally NOT added to vendor. They are
550
- // served via HTTP only so every importer resolves to a single module realm.
551
- // See shouldSkipDependency() for the full rationale. RxJS is also left out of
552
- // vendor (large, and not required in the vendor bundle for dev HMR).
553
- if (pkg.dependencies?.['react-nativescript']) {
554
- if (pkg.dependencies?.react) {
555
- addCandidate('react');
556
- }
557
- if (pkg.dependencies?.['react-dom']) {
558
- addCandidate('react-dom');
559
- }
560
- }
561
- // SolidJS / TanStack Router: when @nativescript/tanstack-router is a dependency,
562
- // its runtime deps (@tanstack/solid-router, @tanstack/router-core, @tanstack/history)
563
- // MUST be in the vendor bundle. These packages:
564
- // 1. Use browser APIs (window.dispatchEvent) that don't exist in NativeScript — they
565
- // must be bundled where the NativeScript wrapper intercepts those calls
566
- // 2. Contain JSX source that needs Solid compilation (dist/source/*.jsx) — the HTTP
567
- // fallback can't compile node_modules JSX since vite-plugin-solid skips it
568
- // 3. Import solid-js internally — loading via HTTP creates a separate solid-js instance
569
- // esbuild uses the 'import' condition (not 'solid'), resolving to pre-compiled
570
- // dist/esm/*.js which avoids all three issues.
571
- if (pkg.dependencies?.['@nativescript/tanstack-router']) {
572
- addCandidate('@tanstack/solid-router');
573
- addCandidate('@tanstack/router-core');
574
- addCandidate('@tanstack/history');
575
- }
576
- parseEnvList(process.env.NS_VENDOR_INCLUDE).forEach(addCandidate);
577
- const projectDeps = {
578
- dependencies: new Set(Object.keys(pkg.dependencies ?? {})),
579
- optional: new Set(Object.keys(pkg.optionalDependencies ?? {})),
580
- dev: new Set(Object.keys(pkg.devDependencies ?? {})),
581
- };
582
- while (queue.length) {
583
- const specifier = queue.shift();
584
- const dependencyPkg = readDependencyPackageJson(specifier, projectRequire);
585
- if (!dependencyPkg) {
586
- continue;
587
- }
588
- const peerDependencies = Object.keys(dependencyPkg.peerDependencies ?? {});
589
- for (const peer of peerDependencies) {
590
- if (shouldSkipDependency(peer)) {
591
- continue;
592
- }
593
- if (projectDeps.dependencies.has(peer) || projectDeps.optional.has(peer) || projectDeps.dev.has(peer)) {
594
- addCandidate(peer);
595
- }
596
- }
597
- // NOTE: We intentionally do NOT collect transitive runtime dependencies
598
- // here. The import map + runtime specifier normalization handles non-vendor
599
- // packages by routing them through HTTP to the Vite dev server. This avoids
600
- // the fragility of trying to esbuild-bundle every transitive dep (which can
601
- // fail due to Node built-ins, type-only packages, duplicate module instances,
602
- // etc.). Only direct project dependencies go into the vendor bundle.
603
- }
604
- parseEnvList(process.env.NS_VENDOR_EXCLUDE).forEach((name) => {
605
- vendor.delete(name);
606
- });
607
- return {
608
- entries: Array.from(vendor).sort(),
609
- };
610
- }
611
- function shouldSkipDependency(name) {
612
- if (!name) {
613
- return true;
614
- }
615
- if (ALWAYS_EXCLUDE.has(name)) {
616
- return true;
617
- }
618
- // Angular framework packages must only be served via the HTTP path so every
619
- // importer resolves to a single module realm. When these packages are present
620
- // in the vendor bundle AND imported by app modules via HTTP subpath, every
621
- // @Component/@Injectable gets defined twice (once per realm), producing NG0912
622
- // selector collisions, cross-realm `instanceof` failures, and dual class
623
- // identities throughout Angular's DI container. HTTP-only is the single-realm
624
- // invariant for user-level framework code.
625
- if (name === '@nativescript/angular' || name === 'nativescript-angular' || name.startsWith('@angular/')) {
626
- return true;
627
- }
628
- // All Babel packages are build tools — never bundle into device runtime.
629
- // They require Node built-ins (fs, path, url) that don't exist on device.
630
- if (name.startsWith('@babel/') || name.startsWith('babel-')) {
631
- return true;
632
- }
633
- // Dev tools and type-only packages — not needed on device
634
- if (name.startsWith('@solid-devtools/')) {
635
- return true;
636
- }
637
- if (name.startsWith('@types/')) {
638
- return true;
639
- }
640
- // PostCSS ecosystem — all build-time CSS processing
641
- if (name === 'postcss' || name.startsWith('postcss-')) {
642
- return true;
643
- }
644
- // Tailwind ecosystem — build-time only CSS framework
645
- if (name.includes('tailwind')) {
646
- return true;
647
- }
648
- // Test runners and frameworks — never needed on device
649
- if (name.includes('test-runner') || name.includes('unit-test')) {
650
- return true;
651
- }
652
- // Linters and formatters — build-time tools
653
- if (name.includes('eslint') || name.includes('stylelint')) {
654
- return true;
655
- }
656
- if (name.startsWith('.')) {
657
- return true;
658
- }
659
- if (name.startsWith('file:')) {
660
- return true;
661
- }
662
- if (name.startsWith('workspace:')) {
663
- return true;
664
- }
665
- if (name.startsWith('link:')) {
666
- return true;
667
- }
668
- return false;
669
- }
670
- export const __test_collectVendorModules = collectVendorModules;
671
- export const __test_createVendorBundleRuntimeModule = createVendorBundleRuntimeModule;
672
- function canResolveDependencyPackageJson(specifier, projectRequire) {
673
- try {
674
- projectRequire.resolve(`${specifier}/package.json`);
675
- return true;
676
- }
677
- catch {
678
- return false;
679
- }
680
- }
681
- function readDependencyPackageJson(specifier, projectRequire) {
682
- try {
683
- const packageJsonPath = projectRequire.resolve(`${specifier}/package.json`);
684
- return JSON.parse(readFileSync(packageJsonPath, 'utf-8'));
685
- }
686
- catch (error) {
687
- if (process.env.VITE_DEBUG_LOGS) {
688
- console.warn(`[vendor] unable to resolve ${specifier} package.json`, error);
689
- }
690
- return null;
691
- }
692
- }
693
- function parseEnvList(value) {
694
- if (!value) {
695
- return [];
696
- }
697
- return value
698
- .split(',')
699
- .map((token) => token.trim())
700
- .filter(Boolean);
701
- }
702
475
  function createVendorEntry(entries) {
703
476
  if (!entries.length) {
704
477
  return `export const __nsVendorModuleMap = {};
705
478
  `;
706
479
  }
707
- const imports = entries.map((specifier, index) => `import * as __nsVendor_${index} from ${JSON.stringify(specifier)};`).join('\n');
480
+ // Emit a side-effect-only import FIRST for each entry, then the namespace
481
+ // import we actually expose through `__nsVendorModuleMap`. Per the ESM
482
+ // spec, `import "pkg";` (no clause) guarantees module body evaluation, and
483
+ // esbuild treats these as DCE-immune even when the package declares
484
+ // `"sideEffects": false`. Without this, packages whose top-level
485
+ // statements install runtime patches (e.g. `@nativescript-community/text`
486
+ // monkey-patching `TextBase.prototype.setTextDecorationAndTransform` via
487
+ // `overrideSpanAndFormattedString()` invoked from
488
+ // `@nativescript-community/ui-label/index-common.js` line 12) can have
489
+ // their bodies elided by esbuild — exports stay resolvable via the
490
+ // namespace, but the runtime patches never fire, producing line-height /
491
+ // letter-spacing / formatted-text rendering divergence between HMR
492
+ // (vendor.mjs via HTTP) and no-HMR (single Rolldown bundle that inlines
493
+ // everything anyway). This affects any NS plugin that relies on top-level
494
+ // side-effects to wire up renderer behavior.
495
+ const sideEffectImports = entries.map((specifier) => `import ${JSON.stringify(specifier)};`).join('\n');
496
+ const namespaceImports = entries.map((specifier, index) => `import * as __nsVendor_${index} from ${JSON.stringify(specifier)};`).join('\n');
708
497
  const modules = entries.map((specifier, index) => `${JSON.stringify(specifier)}: __nsVendor_${index}`).join(',\n ');
709
- return `${imports}\n\nexport const __nsVendorModuleMap = {\n ${modules}\n};\n`;
498
+ return `${sideEffectImports}\n\n${namespaceImports}\n\nexport const __nsVendorModuleMap = {\n ${modules}\n};\n`;
710
499
  }
711
- function createVendorBundleRuntimeModule(result) {
500
+ export function createVendorBundleRuntimeModule(result) {
712
501
  return `${result.code}
713
502
  export const vendorManifest = ${JSON.stringify(result.manifest)};
714
503
  export default vendorManifest;
@@ -771,495 +560,6 @@ function createSbgVendorAssetCode(platform) {
771
560
  lines.push('export const __nsVendorModuleMap = {};\nexport default {};\n');
772
561
  return lines.join('\n');
773
562
  }
774
- function createVendorEsbuildPlugin(projectRoot) {
775
- return {
776
- name: 'ns-vendor-resolver',
777
- setup(build) {
778
- const debug = process.env.VITE_DEBUG_LOGS === 'true' || process.env.VITE_DEBUG_LOGS === '1';
779
- build.onResolve({ filter: /^~\/package\.json$/ }, () => ({
780
- path: path.resolve(projectRoot, 'package.json'),
781
- }));
782
- build.onResolve({ filter: /^module$/ }, () => ({
783
- path: 'ns-vendor-module-shim',
784
- namespace: 'ns-vendor',
785
- }));
786
- build.onLoad({ filter: /^ns-vendor-module-shim$/, namespace: 'ns-vendor' }, () => ({
787
- contents: vendorModuleShim,
788
- loader: 'js',
789
- }));
790
- // Stub Angular animations in vendor to avoid bundling browser-only code.
791
- // Provide named exports expected by @nativescript/angular to satisfy esbuild.
792
- const PB_ANIMATIONS_ID = 'ns-animations-pb-shim';
793
- const ANIMATIONS_BROWSER_ID = 'ns-animations-browser-shim';
794
- const ANIMATIONS_ID = 'ns-animations-noop';
795
- // @angular/platform-browser/animations -> provide concrete named stubs
796
- build.onResolve({ filter: /^@angular\/platform-browser\/animations(?:\/.*)?$/ }, (args) => {
797
- if (debug) {
798
- try {
799
- console.log('[vendor] map', args.path, '->', PB_ANIMATIONS_ID);
800
- }
801
- catch { }
802
- }
803
- return { path: PB_ANIMATIONS_ID, namespace: 'ns-vendor' };
804
- });
805
- build.onLoad({ filter: new RegExp(`^${PB_ANIMATIONS_ID}$`), namespace: 'ns-vendor' }, () => ({
806
- contents: [
807
- 'export default {};',
808
- // Commonly imported symbols by @nativescript/angular
809
- 'export class AnimationBuilder {};',
810
- 'export const \u0275BrowserAnimationBuilder = class {};',
811
- 'export const \u0275AnimationEngine = class {};',
812
- 'export const \u0275AnimationRendererFactory = class {};',
813
- 'export const \u0275WebAnimationsStyleNormalizer = class {};',
814
- // Typical platform-browser/animations APIs exported; safe no-ops
815
- 'export class BrowserAnimationsModule {};',
816
- 'export class NoopAnimationsModule {};',
817
- 'export const provideAnimations = (..._args) => [];',
818
- 'export const provideNoopAnimations = (..._args) => [];',
819
- // Marker used by some Angular internals
820
- 'export const ANIMATION_MODULE_TYPE = void 0;',
821
- ].join('\n'),
822
- loader: 'js',
823
- }));
824
- // @angular/animations/browser -> provide ɵ* engine/renderer/style normalizer stubs
825
- build.onResolve({ filter: /^@angular\/animations\/browser(?:\/.*)?$/ }, (args) => {
826
- if (debug) {
827
- try {
828
- console.log('[vendor] map', args.path, '->', ANIMATIONS_BROWSER_ID);
829
- }
830
- catch { }
831
- }
832
- return { path: ANIMATIONS_BROWSER_ID, namespace: 'ns-vendor' };
833
- });
834
- build.onLoad({ filter: new RegExp(`^${ANIMATIONS_BROWSER_ID}$`), namespace: 'ns-vendor' }, () => ({
835
- contents: [
836
- 'export default {};',
837
- 'export class AnimationDriver {};',
838
- 'export const \u0275AnimationRendererFactory = class {};',
839
- 'export const \u0275AnimationStyleNormalizer = class {};',
840
- 'export const \u0275WebAnimationsStyleNormalizer = class {};',
841
- 'export const \u0275AnimationEngine = class {};',
842
- // Convenience alias if any consumers import non-ɵ name
843
- 'export const AnimationStyleNormalizer = \u0275AnimationStyleNormalizer;',
844
- ].join('\n'),
845
- loader: 'js',
846
- }));
847
- // @angular/animations -> broad no-op surface
848
- build.onResolve(
849
- // Keep generic mapping for @angular/animations base; /browser is handled above
850
- { filter: /^@angular\/animations(?:$|\/)$/ }, (args) => {
851
- if (debug) {
852
- try {
853
- console.log('[vendor] map', args.path, '->', ANIMATIONS_ID);
854
- }
855
- catch { }
856
- }
857
- return { path: ANIMATIONS_ID, namespace: 'ns-vendor' };
858
- });
859
- build.onLoad({ filter: new RegExp(`^${ANIMATIONS_ID}$`), namespace: 'ns-vendor' }, () => ({
860
- contents: [
861
- 'export default {};',
862
- // Provide names sometimes (incorrectly) imported from @angular/animations by wrappers
863
- 'export class AnimationBuilder {};',
864
- 'export const \u0275BrowserAnimationBuilder = class {};',
865
- 'export const \u0275AnimationEngine = class {};',
866
- 'export const \u0275AnimationRendererFactory = class {};',
867
- 'export const \u0275WebAnimationsStyleNormalizer = class {};',
868
- 'export const ANIMATION_MODULE_TYPE = void 0;',
869
- // Export a few common tokens as harmless stubs
870
- 'export const animate = (..._a) => ({});',
871
- 'export const state = (..._a) => ({});',
872
- 'export const style = (..._a) => ({});',
873
- 'export const transition = (..._a) => ({});',
874
- 'export const trigger = (..._a) => ({});',
875
- 'export const sequence = (..._a) => ({});',
876
- 'export const group = (..._a) => ({});',
877
- 'export const query = (..._a) => ({});',
878
- 'export const stagger = (..._a) => ({});',
879
- 'export const keyframes = (..._a) => ({});',
880
- ].join('\n'),
881
- loader: 'js',
882
- }));
883
- },
884
- };
885
- }
886
- /**
887
- * esbuild plugin to compile .jsx/.tsx files from Solid packages through
888
- * babel-preset-solid. Without this, esbuild uses its default React JSX
889
- * transform, producing React.createElement calls that crash at runtime.
890
- *
891
- * Only applied to files inside node_modules that have .jsx or .tsx extension.
892
- */
893
- function createSolidJsxEsbuildPlugin(projectRoot) {
894
- // Lazy-load Babel and the Solid preset so they're only required when
895
- // the Solid flavor is active.
896
- let babel;
897
- let solidPreset;
898
- return {
899
- name: 'ns-vendor-solid-jsx',
900
- setup(build) {
901
- // Intercept .jsx and .tsx files from node_modules
902
- build.onLoad({ filter: /node_modules\/.*\.[jt]sx$/ }, async (args) => {
903
- try {
904
- if (!babel) {
905
- babel = await import('@babel/core');
906
- // babel-preset-solid is the standard Solid JSX transform
907
- solidPreset = (await import('babel-preset-solid')).default;
908
- }
909
- const source = await readFile(args.path, 'utf-8');
910
- const result = await babel.transformAsync(source, {
911
- filename: args.path,
912
- presets: [
913
- [
914
- solidPreset,
915
- {
916
- generate: 'universal',
917
- hydratable: false,
918
- moduleName: '@nativescript-community/solid-js',
919
- },
920
- ],
921
- ],
922
- parserOpts: {
923
- plugins: ['jsx', ...(args.path.endsWith('.tsx') ? ['typescript'] : [])],
924
- },
925
- ast: false,
926
- sourceMaps: false,
927
- configFile: false,
928
- babelrc: false,
929
- });
930
- if (result?.code) {
931
- return { contents: result.code, loader: 'js' };
932
- }
933
- }
934
- catch (e) {
935
- console.warn(`[ns-vendor-solid-jsx] failed to transform ${args.path}:`, e?.message || e);
936
- }
937
- // Fall through to esbuild's default handling
938
- return undefined;
939
- });
940
- },
941
- };
942
- }
943
- /**
944
- * Minimal esbuild plugin to run Angular linker (Babel) over partial-compiled
945
- * Angular packages in node_modules. This converts ɵɵngDeclare* calls into
946
- * ɵɵdefine* so runtime doesn't require the JIT compiler.
947
- */
948
- function angularLinkerEsbuildPlugin(projectRoot) {
949
- // Lazily resolve Babel and Angular linker from the project to avoid hard deps
950
- let babel = null;
951
- let createLinker = null;
952
- let angularFileSystem = null;
953
- async function ensureDeps() {
954
- if (babel && createLinker)
955
- return;
956
- try {
957
- const req = createRequire(projectRoot + '/package.json');
958
- // Resolve from the application project first
959
- const babelPath = req.resolve('@babel/core');
960
- const linkerPath = req.resolve('@angular/compiler-cli/linker/babel');
961
- babel = (await import(babelPath));
962
- const linkerMod = await import(linkerPath);
963
- createLinker = linkerMod.createLinkerPlugin || linkerMod.createEs2015LinkerPlugin || null;
964
- }
965
- catch {
966
- // As a fallback, try local resolution (hoisted installs)
967
- try {
968
- babel = (await import('@babel/core'));
969
- }
970
- catch { }
971
- try {
972
- const linkerMod = await import('@angular/compiler-cli/linker/babel');
973
- createLinker = linkerMod.createLinkerPlugin || linkerMod.createEs2015LinkerPlugin || null;
974
- }
975
- catch { }
976
- }
977
- // Angular 21+ requires a fileSystem for the linker plugin
978
- if (!angularFileSystem) {
979
- try {
980
- const req = createRequire(projectRoot + '/package.json');
981
- const cliPath = req.resolve('@angular/compiler-cli');
982
- const cliMod = await import(cliPath);
983
- if (cliMod.NodeJSFileSystem) {
984
- angularFileSystem = new cliMod.NodeJSFileSystem();
985
- }
986
- }
987
- catch { }
988
- if (!angularFileSystem) {
989
- try {
990
- const cliMod = await import('@angular/compiler-cli');
991
- if (cliMod.NodeJSFileSystem) {
992
- angularFileSystem = new cliMod.NodeJSFileSystem();
993
- }
994
- }
995
- catch { }
996
- }
997
- if (!angularFileSystem) {
998
- // Minimal fallback
999
- const nodePath = await import('node:path');
1000
- const nodeFs = await import('node:fs');
1001
- angularFileSystem = {
1002
- resolve: (...paths) => nodePath.resolve(...paths),
1003
- dirname: (p) => nodePath.dirname(p),
1004
- join: (...paths) => nodePath.join(...paths),
1005
- isRooted: (p) => nodePath.isAbsolute(p),
1006
- exists: (p) => nodeFs.existsSync(p),
1007
- readFile: (p) => nodeFs.readFileSync(p, 'utf8'),
1008
- };
1009
- }
1010
- }
1011
- }
1012
- // Restrict to Angular framework packages to minimize esbuild memory usage.
1013
- const FILTER = /node_modules\/(?:@angular|@nativescript\/angular)\/.*\.[mc]?js$/;
1014
- return {
1015
- name: 'ns-angular-linker',
1016
- async setup(build) {
1017
- const debug = process.env.VITE_DEBUG_LOGS === 'true' || process.env.VITE_DEBUG_LOGS === '1';
1018
- await ensureDeps();
1019
- if (!babel || !createLinker) {
1020
- // Nothing to do if deps unavailable
1021
- return;
1022
- }
1023
- build.onLoad({ filter: FILTER }, async (args) => {
1024
- try {
1025
- const source = await readFile(args.path, 'utf8');
1026
- // Fast-path: only run linker when partial declarations are present
1027
- if (!(source.includes('\u0275\u0275ngDeclare') || source.includes('ɵɵngDeclare'))) {
1028
- return { contents: source, loader: 'js' };
1029
- }
1030
- const plugin = createLinker({
1031
- sourceMapping: false,
1032
- fileSystem: angularFileSystem,
1033
- });
1034
- if (debug) {
1035
- try {
1036
- console.log('[ns-angular-linker][vendor] linking', args.path);
1037
- }
1038
- catch { }
1039
- }
1040
- const result = await babel.transformAsync(source, {
1041
- filename: args.path,
1042
- configFile: false,
1043
- babelrc: false,
1044
- sourceMaps: false,
1045
- compact: false,
1046
- plugins: [plugin],
1047
- });
1048
- return {
1049
- contents: (result && result.code) || source,
1050
- loader: 'js',
1051
- };
1052
- }
1053
- catch (e) {
1054
- // On any failure, return original source to avoid breaking the build
1055
- return { contents: await readFile(args.path, 'utf8'), loader: 'js' };
1056
- }
1057
- });
1058
- },
1059
- };
1060
- }
1061
- const vendorModuleShim = `
1062
- const g = globalThis;
1063
- const BACKSLASH = String.fromCharCode(92);
1064
-
1065
- function toForwardSlashes(input) {
1066
- return String(input ?? '').split(BACKSLASH).join('/');
1067
- }
1068
-
1069
- function getNativeScriptRequire() {
1070
- const nsRequire = typeof g.require === "function" ? g.require : null;
1071
- if (nsRequire) {
1072
- return nsRequire;
1073
- }
1074
- const legacy = g.__nsRequire;
1075
- if (typeof legacy === "function") {
1076
- return legacy;
1077
- }
1078
- return null;
1079
- }
1080
-
1081
- function getDocumentsPath() {
1082
- const cached = g.__NS_DOCUMENTS_PATH__;
1083
- if (typeof cached === "string" && cached.length) {
1084
- return toForwardSlashes(cached);
1085
- }
1086
- try {
1087
- const core = g.require ? g.require("@nativescript/core") : null;
1088
- const docsFolder = core?.knownFolders?.documents?.();
1089
- const docPath = docsFolder?.path;
1090
- if (docPath) {
1091
- const normalized = toForwardSlashes(docPath);
1092
- g.__NS_DOCUMENTS_PATH__ = normalized;
1093
- return normalized;
1094
- }
1095
- } catch (_err) {
1096
- // ignore - fallback to raw specifier
1097
- }
1098
- return null;
1099
- }
1100
-
1101
- function collapseSegments(input) {
1102
- const segments = [];
1103
- const parts = input.split('/');
1104
- for (const part of parts) {
1105
- if (!part || part === ".") {
1106
- continue;
1107
- }
1108
- if (part === "..") {
1109
- if (segments.length && segments[segments.length - 1] !== "..") {
1110
- segments.pop();
1111
- continue;
1112
- }
1113
- }
1114
- segments.push(part);
1115
- }
1116
- const leadingSlash = input.startsWith('/');
1117
- return (leadingSlash ? '/' : '') + segments.join('/');
1118
- }
1119
-
1120
- function normalizeSpecifier(spec) {
1121
- let value = String(spec ?? "");
1122
- value = toForwardSlashes(value);
1123
- const docsPath = getDocumentsPath();
1124
- if (value.startsWith("__NSDOC__/")) {
1125
- if (docsPath) {
1126
- value = docsPath + '/' + value.slice("__NSDOC__/".length);
1127
- } else {
1128
- value = value.slice("__NSDOC__/".length);
1129
- }
1130
- }
1131
- if (value.startsWith("~/") && docsPath) {
1132
- value = docsPath + '/' + value.slice(2);
1133
- }
1134
- if (value.startsWith("file://")) {
1135
- const stripped = value.slice("file://".length);
1136
- value = stripped.startsWith('/') ? stripped : '/' + stripped;
1137
- }
1138
- if (value.includes("/../") || value.includes("/./")) {
1139
- value = collapseSegments(value);
1140
- }
1141
- return value;
1142
- }
1143
-
1144
- function normalizeCoreSubLocal(s) {
1145
- if (!s) return "";
1146
- let t = String(s).split("?")[0].split("#")[0].trim();
1147
- t = t.replace(/^\\/+/, "").replace(/\\/+$/, "");
1148
- t = t.replace(/\\.(?:mjs|cjs|js)$/, "");
1149
- if (t.length >= 6 && t.substring(t.length - 6) === "/index") {
1150
- t = t.substring(0, t.length - 6);
1151
- }
1152
- if (!t || t === "index") return "";
1153
- return t;
1154
- }
1155
-
1156
- // Invariant D: shape ESM namespaces before returning to CJS callers.
1157
- //
1158
- // The /ns/core handler's registration footer (see websocket.ts) and the
1159
- // main-entry require shim (see helpers/main-entry.ts) both install the
1160
- // shape function on globalThis. In practice, entries stored in
1161
- // __NS_CORE_MODULES__ are ALREADY shaped, so this pass-through is a
1162
- // fast no-op (the shape function's fast path returns obj as-is when it
1163
- // already has Object.prototype). We call it anyway as defense-in-depth
1164
- // against future callers that might populate the registry without
1165
- // shaping.
1166
- function shapeForCjs(value) {
1167
- if (!value || typeof value !== "object") return value;
1168
- const shape = g.__NS_CJS_SHAPE__;
1169
- if (typeof shape === "function") {
1170
- try { return shape(value); } catch (e) {}
1171
- }
1172
- return value;
1173
- }
1174
-
1175
- function resolveCoreFromRegistry(normalizedId) {
1176
- if (
1177
- normalizedId !== "@nativescript/core" &&
1178
- normalizedId.indexOf("@nativescript/core/") !== 0
1179
- ) {
1180
- return null;
1181
- }
1182
- const table = g.__NS_CORE_MODULES__;
1183
- if (!table) return null;
1184
- if (table[normalizedId]) return shapeForCjs(table[normalizedId]);
1185
- const rawSub =
1186
- normalizedId === "@nativescript/core"
1187
- ? ""
1188
- : normalizedId.slice("@nativescript/core/".length);
1189
- const normSub = normalizeCoreSubLocal(rawSub);
1190
- const bareKey = normSub ? "@nativescript/core/" + normSub : "@nativescript/core";
1191
- if (table[bareKey]) return shapeForCjs(table[bareKey]);
1192
- if (normSub && table[normSub]) return shapeForCjs(table[normSub]);
1193
- if (!normSub && table[""]) return shapeForCjs(table[""]);
1194
- return null;
1195
- }
1196
-
1197
- export function createRequire(_url) {
1198
- const nsRequire = getNativeScriptRequire();
1199
- if (!nsRequire) {
1200
- return function (id) {
1201
- // Even without nsRequire, the @nativescript/core registry populated by
1202
- // the /ns/core bridge may already have the module — return it so
1203
- // vendor install() hooks that run against the HMR-served core don't
1204
- // crash at module-instantiation time.
1205
- const fromRegistry = resolveCoreFromRegistry(normalizeSpecifier(id));
1206
- if (fromRegistry) return fromRegistry;
1207
- throw new Error("NativeScript require() is not available in this context");
1208
- };
1209
- }
1210
- const req = function (id) {
1211
- const normalizedId = normalizeSpecifier(id);
1212
- // Invariant C: @nativescript/core and its subpaths are served ONCE via
1213
- // the /ns/core HTTP bridge, which self-registers each module's ESM
1214
- // namespace on globalThis.__NS_CORE_MODULES__. CommonJS require() from
1215
- // vendor packages (e.g. \`require('@nativescript/core/ui/core/view').View\`
1216
- // in @nativescript-community/gesturehandler, or \`require('@nativescript/core').View\`
1217
- // in @nativescript-community/ui-material-core) MUST resolve to that
1218
- // same namespace; otherwise we re-trigger class identity splits and
1219
- // applyMixins() crashes with "Cannot read properties of undefined".
1220
- const fromRegistry = resolveCoreFromRegistry(normalizedId);
1221
- if (fromRegistry) return fromRegistry;
1222
- if (
1223
- normalizedId.includes("../data/patch.json") ||
1224
- normalizedId.includes("css-tree/lib/data/patch.json")
1225
- ) {
1226
- return {
1227
- atrules: {},
1228
- properties: {},
1229
- types: {},
1230
- };
1231
- }
1232
- if (normalizedId.includes("mdn-data/")) {
1233
- return {};
1234
- }
1235
- if (
1236
- normalizedId.endsWith("/package.json") ||
1237
- normalizedId.includes("../package.json")
1238
- ) {
1239
- return { version: "0.0.0" };
1240
- }
1241
- if (normalizedId.endsWith(".json")) {
1242
- return {};
1243
- }
1244
- // Shape the native require result too. The NativeScript CJS loader
1245
- // may serve an @nativescript/core subpath over HTTP before the
1246
- // /ns/core footer has run (e.g., during initial boot). In that
1247
- // window, the result is a raw ESM namespace with null [[Prototype]]
1248
- // and zone.js/vendor install() hooks crash on hasOwnProperty.
1249
- return shapeForCjs(nsRequire(normalizedId));
1250
- };
1251
- req.resolve = nsRequire.resolve
1252
- ? function (id) {
1253
- return nsRequire.resolve(id);
1254
- }
1255
- : function (id) {
1256
- return id;
1257
- };
1258
- return req;
1259
- }
1260
-
1261
- export default { createRequire };
1262
- `;
1263
563
  function stripIndexSuffix(specifier) {
1264
564
  return specifier.replace(/\/(?:(?:index)(?:\.[^.\/]+)?)$/, '');
1265
565
  }