@nativescript/vite 8.0.0-alpha.1 → 8.0.0-alpha.11

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 (220) hide show
  1. package/configuration/angular.d.ts +1 -1
  2. package/configuration/angular.js +486 -140
  3. package/configuration/angular.js.map +1 -1
  4. package/configuration/base.js +159 -29
  5. package/configuration/base.js.map +1 -1
  6. package/configuration/javascript.js +3 -3
  7. package/configuration/javascript.js.map +1 -1
  8. package/configuration/solid.js +27 -0
  9. package/configuration/solid.js.map +1 -1
  10. package/configuration/typescript.js +4 -4
  11. package/configuration/typescript.js.map +1 -1
  12. package/helpers/angular/angular-linker.js +38 -42
  13. package/helpers/angular/angular-linker.js.map +1 -1
  14. package/helpers/angular/inject-component-hmr-registration.d.ts +112 -0
  15. package/helpers/angular/inject-component-hmr-registration.js +359 -0
  16. package/helpers/angular/inject-component-hmr-registration.js.map +1 -0
  17. package/helpers/angular/inline-decorator-component-templates.d.ts +3 -0
  18. package/helpers/angular/inline-decorator-component-templates.js +400 -0
  19. package/helpers/angular/inline-decorator-component-templates.js.map +1 -0
  20. package/helpers/angular/shared-linker.d.ts +7 -0
  21. package/helpers/angular/shared-linker.js +37 -1
  22. package/helpers/angular/shared-linker.js.map +1 -1
  23. package/helpers/angular/synthesize-decorator-ctor-parameters.d.ts +1 -0
  24. package/helpers/angular/synthesize-decorator-ctor-parameters.js +256 -0
  25. package/helpers/angular/synthesize-decorator-ctor-parameters.js.map +1 -0
  26. package/helpers/angular/synthesize-injectable-factories.d.ts +3 -0
  27. package/helpers/angular/synthesize-injectable-factories.js +414 -0
  28. package/helpers/angular/synthesize-injectable-factories.js.map +1 -0
  29. package/helpers/angular/util.d.ts +1 -0
  30. package/helpers/angular/util.js +88 -0
  31. package/helpers/angular/util.js.map +1 -1
  32. package/helpers/commonjs-plugins.d.ts +5 -2
  33. package/helpers/commonjs-plugins.js +126 -0
  34. package/helpers/commonjs-plugins.js.map +1 -1
  35. package/helpers/config-as-json.js +10 -0
  36. package/helpers/config-as-json.js.map +1 -1
  37. package/helpers/esbuild-platform-resolver.js +5 -5
  38. package/helpers/esbuild-platform-resolver.js.map +1 -1
  39. package/helpers/external-configs.d.ts +9 -1
  40. package/helpers/external-configs.js +31 -6
  41. package/helpers/external-configs.js.map +1 -1
  42. package/helpers/global-defines.d.ts +51 -0
  43. package/helpers/global-defines.js +77 -0
  44. package/helpers/global-defines.js.map +1 -1
  45. package/helpers/import-meta-path.d.ts +4 -0
  46. package/helpers/import-meta-path.js +5 -0
  47. package/helpers/import-meta-path.js.map +1 -0
  48. package/helpers/import-specifier.d.ts +1 -0
  49. package/helpers/import-specifier.js +18 -0
  50. package/helpers/import-specifier.js.map +1 -0
  51. package/helpers/logging.d.ts +1 -0
  52. package/helpers/logging.js +63 -3
  53. package/helpers/logging.js.map +1 -1
  54. package/helpers/main-entry.d.ts +5 -2
  55. package/helpers/main-entry.js +375 -116
  56. package/helpers/main-entry.js.map +1 -1
  57. package/helpers/nativeclass-transform.js +8 -127
  58. package/helpers/nativeclass-transform.js.map +1 -1
  59. package/helpers/nativeclass-transformer-plugin.d.ts +19 -1
  60. package/helpers/nativeclass-transformer-plugin.js +318 -36
  61. package/helpers/nativeclass-transformer-plugin.js.map +1 -1
  62. package/helpers/ns-core-url.d.ts +83 -0
  63. package/helpers/ns-core-url.js +167 -0
  64. package/helpers/ns-core-url.js.map +1 -0
  65. package/helpers/prelink-angular.js +1 -4
  66. package/helpers/prelink-angular.js.map +1 -1
  67. package/helpers/project.d.ts +35 -0
  68. package/helpers/project.js +120 -2
  69. package/helpers/project.js.map +1 -1
  70. package/helpers/ts-config-paths.js +50 -2
  71. package/helpers/ts-config-paths.js.map +1 -1
  72. package/helpers/workers.d.ts +20 -19
  73. package/helpers/workers.js +620 -3
  74. package/helpers/workers.js.map +1 -1
  75. package/hmr/client/css-handler.js +60 -19
  76. package/hmr/client/css-handler.js.map +1 -1
  77. package/hmr/client/hmr-pending-overlay.d.ts +27 -0
  78. package/hmr/client/hmr-pending-overlay.js +50 -0
  79. package/hmr/client/hmr-pending-overlay.js.map +1 -0
  80. package/hmr/client/index.js +767 -24
  81. package/hmr/client/index.js.map +1 -1
  82. package/hmr/client/utils.d.ts +5 -0
  83. package/hmr/client/utils.js +283 -12
  84. package/hmr/client/utils.js.map +1 -1
  85. package/hmr/entry-runtime.d.ts +10 -0
  86. package/hmr/entry-runtime.js +330 -42
  87. package/hmr/entry-runtime.js.map +1 -1
  88. package/hmr/frameworks/angular/client/index.d.ts +3 -1
  89. package/hmr/frameworks/angular/client/index.js +821 -25
  90. package/hmr/frameworks/angular/client/index.js.map +1 -1
  91. package/hmr/frameworks/angular/server/linker.js +37 -6
  92. package/hmr/frameworks/angular/server/linker.js.map +1 -1
  93. package/hmr/frameworks/angular/server/strategy.js +30 -6
  94. package/hmr/frameworks/angular/server/strategy.js.map +1 -1
  95. package/hmr/frameworks/typescript/server/strategy.js +8 -2
  96. package/hmr/frameworks/typescript/server/strategy.js.map +1 -1
  97. package/hmr/frameworks/vue/client/index.js +18 -42
  98. package/hmr/frameworks/vue/client/index.js.map +1 -1
  99. package/hmr/helpers/ast-normalizer.js +22 -10
  100. package/hmr/helpers/ast-normalizer.js.map +1 -1
  101. package/hmr/helpers/cjs-named-exports.d.ts +23 -0
  102. package/hmr/helpers/cjs-named-exports.js +152 -0
  103. package/hmr/helpers/cjs-named-exports.js.map +1 -0
  104. package/hmr/server/constants.d.ts +1 -0
  105. package/hmr/server/constants.js +14 -3
  106. package/hmr/server/constants.js.map +1 -1
  107. package/hmr/server/core-sanitize.d.ts +49 -2
  108. package/hmr/server/core-sanitize.js +267 -24
  109. package/hmr/server/core-sanitize.js.map +1 -1
  110. package/hmr/server/import-map.d.ts +65 -0
  111. package/hmr/server/import-map.js +222 -0
  112. package/hmr/server/import-map.js.map +1 -0
  113. package/hmr/server/index.d.ts +2 -1
  114. package/hmr/server/index.js.map +1 -1
  115. package/hmr/server/ns-core-cjs-shape.d.ts +204 -0
  116. package/hmr/server/ns-core-cjs-shape.js +271 -0
  117. package/hmr/server/ns-core-cjs-shape.js.map +1 -0
  118. package/hmr/server/perf-instrumentation.d.ts +114 -0
  119. package/hmr/server/perf-instrumentation.js +195 -0
  120. package/hmr/server/perf-instrumentation.js.map +1 -0
  121. package/hmr/server/runtime-graph-filter.d.ts +5 -0
  122. package/hmr/server/runtime-graph-filter.js +21 -0
  123. package/hmr/server/runtime-graph-filter.js.map +1 -0
  124. package/hmr/server/shared-transform-request.d.ts +12 -0
  125. package/hmr/server/shared-transform-request.js +144 -0
  126. package/hmr/server/shared-transform-request.js.map +1 -0
  127. package/hmr/server/vite-plugin.d.ts +21 -1
  128. package/hmr/server/vite-plugin.js +461 -22
  129. package/hmr/server/vite-plugin.js.map +1 -1
  130. package/hmr/server/websocket-angular-entry.d.ts +2 -0
  131. package/hmr/server/websocket-angular-entry.js +68 -0
  132. package/hmr/server/websocket-angular-entry.js.map +1 -0
  133. package/hmr/server/websocket-angular-hot-update.d.ts +78 -0
  134. package/hmr/server/websocket-angular-hot-update.js +413 -0
  135. package/hmr/server/websocket-angular-hot-update.js.map +1 -0
  136. package/hmr/server/websocket-core-bridge.d.ts +21 -0
  137. package/hmr/server/websocket-core-bridge.js +357 -0
  138. package/hmr/server/websocket-core-bridge.js.map +1 -0
  139. package/hmr/server/websocket-graph-upsert.d.ts +21 -0
  140. package/hmr/server/websocket-graph-upsert.js +33 -0
  141. package/hmr/server/websocket-graph-upsert.js.map +1 -0
  142. package/hmr/server/websocket-hmr-pending.d.ts +43 -0
  143. package/hmr/server/websocket-hmr-pending.js +55 -0
  144. package/hmr/server/websocket-hmr-pending.js.map +1 -0
  145. package/hmr/server/websocket-module-bindings.d.ts +6 -0
  146. package/hmr/server/websocket-module-bindings.js +471 -0
  147. package/hmr/server/websocket-module-bindings.js.map +1 -0
  148. package/hmr/server/websocket-module-specifiers.d.ts +101 -0
  149. package/hmr/server/websocket-module-specifiers.js +820 -0
  150. package/hmr/server/websocket-module-specifiers.js.map +1 -0
  151. package/hmr/server/websocket-ns-m-finalize.d.ts +22 -0
  152. package/hmr/server/websocket-ns-m-finalize.js +88 -0
  153. package/hmr/server/websocket-ns-m-finalize.js.map +1 -0
  154. package/hmr/server/websocket-ns-m-paths.d.ts +3 -0
  155. package/hmr/server/websocket-ns-m-paths.js +92 -0
  156. package/hmr/server/websocket-ns-m-paths.js.map +1 -0
  157. package/hmr/server/websocket-ns-m-request.d.ts +45 -0
  158. package/hmr/server/websocket-ns-m-request.js +196 -0
  159. package/hmr/server/websocket-ns-m-request.js.map +1 -0
  160. package/hmr/server/websocket-runtime-compat.d.ts +19 -0
  161. package/hmr/server/websocket-runtime-compat.js +287 -0
  162. package/hmr/server/websocket-runtime-compat.js.map +1 -0
  163. package/hmr/server/websocket-served-module-helpers.d.ts +36 -0
  164. package/hmr/server/websocket-served-module-helpers.js +631 -0
  165. package/hmr/server/websocket-served-module-helpers.js.map +1 -0
  166. package/hmr/server/websocket-txn.d.ts +6 -0
  167. package/hmr/server/websocket-txn.js +45 -0
  168. package/hmr/server/websocket-txn.js.map +1 -0
  169. package/hmr/server/websocket-vendor-unifier.d.ts +10 -0
  170. package/hmr/server/websocket-vendor-unifier.js +51 -0
  171. package/hmr/server/websocket-vendor-unifier.js.map +1 -0
  172. package/hmr/server/websocket-vue-sfc.d.ts +27 -0
  173. package/hmr/server/websocket-vue-sfc.js +1069 -0
  174. package/hmr/server/websocket-vue-sfc.js.map +1 -0
  175. package/hmr/server/websocket.d.ts +26 -3
  176. package/hmr/server/websocket.js +2492 -798
  177. package/hmr/server/websocket.js.map +1 -1
  178. package/hmr/shared/package-classifier.d.ts +9 -0
  179. package/hmr/shared/package-classifier.js +58 -0
  180. package/hmr/shared/package-classifier.js.map +1 -0
  181. package/hmr/shared/runtime/boot-timeline.d.ts +17 -0
  182. package/hmr/shared/runtime/boot-timeline.js +51 -0
  183. package/hmr/shared/runtime/boot-timeline.js.map +1 -0
  184. package/hmr/shared/runtime/browser-runtime-contract.d.ts +64 -0
  185. package/hmr/shared/runtime/browser-runtime-contract.js +54 -0
  186. package/hmr/shared/runtime/browser-runtime-contract.js.map +1 -0
  187. package/hmr/shared/runtime/dev-overlay.d.ts +85 -0
  188. package/hmr/shared/runtime/dev-overlay.js +1236 -0
  189. package/hmr/shared/runtime/dev-overlay.js.map +1 -0
  190. package/hmr/shared/runtime/http-only-boot.d.ts +1 -0
  191. package/hmr/shared/runtime/http-only-boot.js +53 -6
  192. package/hmr/shared/runtime/http-only-boot.js.map +1 -1
  193. package/hmr/shared/runtime/module-provenance.d.ts +1 -0
  194. package/hmr/shared/runtime/module-provenance.js +63 -0
  195. package/hmr/shared/runtime/module-provenance.js.map +1 -0
  196. package/hmr/shared/runtime/platform-polyfills.d.ts +26 -0
  197. package/hmr/shared/runtime/platform-polyfills.js +122 -0
  198. package/hmr/shared/runtime/platform-polyfills.js.map +1 -0
  199. package/hmr/shared/runtime/root-placeholder.d.ts +1 -0
  200. package/hmr/shared/runtime/root-placeholder.js +552 -82
  201. package/hmr/shared/runtime/root-placeholder.js.map +1 -1
  202. package/hmr/shared/runtime/session-bootstrap.d.ts +1 -0
  203. package/hmr/shared/runtime/session-bootstrap.js +195 -0
  204. package/hmr/shared/runtime/session-bootstrap.js.map +1 -0
  205. package/hmr/shared/runtime/vendor-bootstrap.js +52 -15
  206. package/hmr/shared/runtime/vendor-bootstrap.js.map +1 -1
  207. package/hmr/shared/vendor/manifest.d.ts +37 -0
  208. package/hmr/shared/vendor/manifest.js +677 -57
  209. package/hmr/shared/vendor/manifest.js.map +1 -1
  210. package/hmr/shared/vendor/registry.js +104 -7
  211. package/hmr/shared/vendor/registry.js.map +1 -1
  212. package/index.d.ts +1 -0
  213. package/index.js +5 -0
  214. package/index.js.map +1 -1
  215. package/package.json +14 -2
  216. package/runtime/core-aliases-early.js +94 -67
  217. package/runtime/core-aliases-early.js.map +1 -1
  218. package/shims/solid-jsx-runtime.d.ts +7 -0
  219. package/shims/solid-jsx-runtime.js +17 -0
  220. package/shims/solid-jsx-runtime.js.map +1 -0
@@ -0,0 +1,152 @@
1
+ // Runtime-enumerated CommonJS named exports for the HMR `/ns/m` pipeline.
2
+ //
3
+ // Why this exists:
4
+ // V8's HTTP-imported ES module loader (the device's `http-esm` mode) requires
5
+ // named exports to be declared statically at parse time. Many real-world npm
6
+ // packages do not declare their public surface statically — the canonical
7
+ // example is lodash:
8
+ //
9
+ // (freeModule.exports = _)._ = _;
10
+ //
11
+ // At parse time there are zero `exports.foo = ...` or
12
+ // `Object.defineProperty(exports, 'foo', ...)` patterns. Lodash builds its
13
+ // public surface dynamically inside an IIFE and attaches every method to a
14
+ // function object that is then assigned to `module.exports`. Neither a
15
+ // regex nor an AST can statically determine that lodash exposes
16
+ // `capitalize`, `chunk`, `debounce`, etc.
17
+ //
18
+ // The only correct way to enumerate this kind of CJS module's public
19
+ // surface is to actually load it in the dev server's Node context and ask
20
+ // `Object.keys(...)`. This is exactly what esbuild and Vite do at build
21
+ // time when they pre-bundle CJS deps for an ESM consumer; this helper
22
+ // brings the same strategy to the HMR served-module pipeline so that
23
+ // `import { capitalize } from 'lodash'` succeeds even when lodash is not
24
+ // pre-bundled by Vite.
25
+ //
26
+ // Safety:
27
+ // - Only call this for modules under `node_modules` (we never execute user
28
+ // source code via this path).
29
+ // - Wrap in try/catch — some npm packages throw at load time (missing peer
30
+ // deps, browser-only globals, side effects). On any failure we return an
31
+ // empty list and the caller falls back to whatever it could detect
32
+ // statically.
33
+ // - Cache by absolute path so a second HMR request for the same module is
34
+ // free.
35
+ import { createRequire } from 'node:module';
36
+ import * as path from 'node:path';
37
+ import * as fs from 'node:fs';
38
+ const cache = new Map();
39
+ const RESERVED = new Set(['default', '__esModule']);
40
+ // `Object.getOwnPropertyNames` on a function exposes these implementation
41
+ // details — they are not real exports.
42
+ const FUNCTION_INTERNAL = new Set(['length', 'name', 'prototype', 'arguments', 'caller']);
43
+ const VALID_IDENT = /^[A-Za-z_$][\w$]*$/;
44
+ export function clearCjsNamedExportsCache(filePath) {
45
+ if (!filePath) {
46
+ cache.clear();
47
+ }
48
+ else {
49
+ cache.delete(filePath);
50
+ }
51
+ }
52
+ export function getCjsNamedExportsCacheSize() {
53
+ return cache.size;
54
+ }
55
+ /**
56
+ * Normalize a path that may have come from a Vite-resolved id (e.g.
57
+ * `/@fs/Users/.../node_modules/foo/index.js?import`) into a plain
58
+ * absolute filesystem path that `createRequire` can load.
59
+ *
60
+ * Returns null if the path does not look like an absolute filesystem
61
+ * path that exists on disk.
62
+ */
63
+ export function normalizeAbsolutePathForRequire(input) {
64
+ if (!input)
65
+ return null;
66
+ let s = String(input).replace(/[?#].*$/, '');
67
+ // Vite serves absolute paths as `/@fs/<absolute>`; strip the prefix.
68
+ if (s.startsWith('/@fs/')) {
69
+ s = s.slice('/@fs'.length);
70
+ }
71
+ if (!path.isAbsolute(s))
72
+ return null;
73
+ try {
74
+ if (!fs.statSync(s).isFile())
75
+ return null;
76
+ }
77
+ catch {
78
+ return null;
79
+ }
80
+ return s;
81
+ }
82
+ /**
83
+ * Enumerate the named exports of a CommonJS module by loading it in the
84
+ * dev server's Node context.
85
+ *
86
+ * Returns an empty array if the module can't be loaded, isn't in
87
+ * node_modules, or doesn't expose any enumerable string-keyed properties
88
+ * that look like JS identifiers.
89
+ *
90
+ * Results are cached by absolute path. Pass `clearCjsNamedExportsCache()`
91
+ * if you need to invalidate (e.g. between tests).
92
+ */
93
+ export function getCjsNamedExports(absolutePath) {
94
+ const normalized = normalizeAbsolutePathForRequire(absolutePath);
95
+ if (!normalized)
96
+ return [];
97
+ // Only enumerate node_modules paths — never execute user source via this code path.
98
+ if (!/(?:^|\/)node_modules\//.test(normalized))
99
+ return [];
100
+ const cached = cache.get(normalized);
101
+ if (cached !== undefined)
102
+ return cached || [];
103
+ let names = null;
104
+ try {
105
+ // `createRequire` needs a path that itself exists; the file we are
106
+ // enumerating is a fine anchor. The cwd of the require base is its
107
+ // parent directory, which matters for nested workspace resolution.
108
+ const req = createRequire(normalized);
109
+ const mod = req(normalized);
110
+ const collected = new Set();
111
+ const isFn = typeof mod === 'function';
112
+ if (mod && (typeof mod === 'object' || isFn)) {
113
+ // `Object.keys` returns enumerable own props — covers most CJS modules
114
+ // where named exports are real properties on the exports object.
115
+ try {
116
+ for (const k of Object.keys(mod)) {
117
+ if (!RESERVED.has(k) && VALID_IDENT.test(k))
118
+ collected.add(k);
119
+ }
120
+ }
121
+ catch {
122
+ /* exotic proxy etc. */
123
+ }
124
+ // `Object.getOwnPropertyNames` covers non-enumerable own props too.
125
+ // Lodash attaches a few methods that aren't enumerable; more importantly
126
+ // some packages mark exports non-enumerable on purpose.
127
+ try {
128
+ for (const k of Object.getOwnPropertyNames(mod)) {
129
+ if (RESERVED.has(k) || !VALID_IDENT.test(k))
130
+ continue;
131
+ if (isFn && FUNCTION_INTERNAL.has(k))
132
+ continue;
133
+ collected.add(k);
134
+ }
135
+ }
136
+ catch {
137
+ /* exotic */
138
+ }
139
+ names = Array.from(collected);
140
+ }
141
+ else {
142
+ // Primitive default export (e.g. `module.exports = 'hello'`). No named exports possible.
143
+ names = [];
144
+ }
145
+ }
146
+ catch {
147
+ names = null;
148
+ }
149
+ cache.set(normalized, names);
150
+ return names || [];
151
+ }
152
+ //# sourceMappingURL=cjs-named-exports.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cjs-named-exports.js","sourceRoot":"","sources":["../../../../../packages/vite/hmr/helpers/cjs-named-exports.ts"],"names":[],"mappings":"AAAA,0EAA0E;AAC1E,EAAE;AACF,mBAAmB;AACnB,8EAA8E;AAC9E,6EAA6E;AAC7E,0EAA0E;AAC1E,qBAAqB;AACrB,EAAE;AACF,oCAAoC;AACpC,EAAE;AACF,sDAAsD;AACtD,2EAA2E;AAC3E,2EAA2E;AAC3E,uEAAuE;AACvE,gEAAgE;AAChE,0CAA0C;AAC1C,EAAE;AACF,qEAAqE;AACrE,0EAA0E;AAC1E,wEAAwE;AACxE,sEAAsE;AACt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AAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC;oBAClC,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,WAAW,CAAC,IAAI,CAAC,CAAC,CAAC;wBAAE,SAAS,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;gBAC/D,CAAC;YACF,CAAC;YAAC,MAAM,CAAC;gBACR,uBAAuB;YACxB,CAAC;YACD,oEAAoE;YACpE,yEAAyE;YACzE,wDAAwD;YACxD,IAAI,CAAC;gBACJ,KAAK,MAAM,CAAC,IAAI,MAAM,CAAC,mBAAmB,CAAC,GAAG,CAAC,EAAE,CAAC;oBACjD,IAAI,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC,CAAC;wBAAE,SAAS;oBACtD,IAAI,IAAI,IAAI,iBAAiB,CAAC,GAAG,CAAC,CAAC,CAAC;wBAAE,SAAS;oBAC/C,SAAS,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;gBAClB,CAAC;YACF,CAAC;YAAC,MAAM,CAAC;gBACR,YAAY;YACb,CAAC;YACD,KAAK,GAAG,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;QAC/B,CAAC;aAAM,CAAC;YACP,yFAAyF;YACzF,KAAK,GAAG,EAAE,CAAC;QACZ,CAAC;IACF,CAAC;IAAC,MAAM,CAAC;QACR,KAAK,GAAG,IAAI,CAAC;IACd,CAAC;IAED,KAAK,CAAC,GAAG,CAAC,UAAU,EAAE,KAAK,CAAC,CAAC;IAC7B,OAAO,KAAK,IAAI,EAAE,CAAC;AACpB,CAAC"}
@@ -4,6 +4,7 @@ export declare const IMPORT_PATTERN_1: RegExp;
4
4
  export declare const IMPORT_PATTERN_2: RegExp;
5
5
  export declare const EXPORT_PATTERN: RegExp;
6
6
  export declare const IMPORT_PATTERN_3: RegExp;
7
+ export declare const IMPORT_PATTERN_SIDE_EFFECT: RegExp;
7
8
  export declare const VUE_FILE_PATTERN: RegExp;
8
9
  export declare const VUE_FILE_IMPORT: RegExp;
9
10
  export declare const VITE_CLIENT_IMPORT: RegExp;
@@ -5,13 +5,24 @@ export const QUERY_PATTERN = /\?.*$/;
5
5
  // Detect whether Vite's variable dynamic import helper is already inlined
6
6
  export const VARIABLE_DYNAMIC_IMPORT_HELPER_PATTERN = /__variableDynamicImportRuntimeHelper\s*=/;
7
7
  // Import/export matchers (static and dynamic)
8
- export const IMPORT_PATTERN_1 = /(?:^|\n)(\s*import\s+[^'";]*?\s+from\s+["'])([^"']+)(["'];?)/g;
9
- export const IMPORT_PATTERN_2 = /(?:^|\n)(\s*export\s+[^'";]*?\s+from\s+["'])([^"']+)(["'];?)/g;
8
+ //
9
+ // Each pattern's first capture group includes the optional leading anchor
10
+ // (`^|\n`) so the replacement function preserves the line break that would
11
+ // otherwise be silently consumed by the regex engine. Without this, two
12
+ // concatenated patterns like:
13
+ // `})();\nexport * from "a"\nexport * from "b"`
14
+ // would collapse to:
15
+ // `})();export * from "a"export * from "b"`
16
+ // because each `(?:^|\n)` ate a newline that no replacement string put back.
17
+ export const IMPORT_PATTERN_1 = /((?:^|\n)\s*import\s+[^'";]*?\s+from\s+["'])([^"']+)(["'];?)/g;
18
+ export const IMPORT_PATTERN_2 = /((?:^|\n)\s*export\s+[^'";]*?\s+from\s+["'])([^"']+)(["'];?)/g;
10
19
  export const EXPORT_PATTERN = IMPORT_PATTERN_2;
11
20
  export const IMPORT_PATTERN_3 = /(import\(\s*["'])([^"']+)(["']\s*\))/g;
21
+ // Side-effect imports: import "spec" / import 'spec' (no `from`, no bindings)
22
+ export const IMPORT_PATTERN_SIDE_EFFECT = /((?:^|\n)\s*import\s+["'])([^"']+)(["'];?)/g;
12
23
  // Vue-specific patterns
13
24
  export const VUE_FILE_PATTERN = /\.vue(?:\?[^"']*)?$/;
14
- export const VUE_FILE_IMPORT = /(?:^|\n)(\s*import\s+[^'";]*?\s+from\s+["'])([^"']+\.vue(?:\?[^"']*)?)(["'];?)/g;
25
+ export const VUE_FILE_IMPORT = /((?:^|\n)\s*import\s+[^'";]*?\s+from\s+["'])([^"']+\.vue(?:\?[^"']*)?)(["'];?)/g;
15
26
  // Vite/HMR noise cleanup
16
27
  export const VITE_CLIENT_IMPORT = /(?:^|\n)\s*import\s+['"](?:\/@vite\/client|@vite\/client)['"];?/g;
17
28
  // Strip Vite's injected `import.meta.hot = __vite__createHotContext(...)` assignment.
@@ -1 +1 @@
1
- {"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../../../packages/vite/hmr/server/constants.ts"],"names":[],"mappings":"AAAA,oEAAoE;AACpE,qGAAqG;AAErG,uBAAuB;AACvB,MAAM,CAAC,MAAM,aAAa,GAAG,OAAO,CAAC;AAErC,0EAA0E;AAC1E,MAAM,CAAC,MAAM,sCAAsC,GAAG,0CAA0C,CAAC;AAEjG,8CAA8C;AAC9C,MAAM,CAAC,MAAM,gBAAgB,GAAG,+DAA+D,CAAC;AAChG,MAAM,CAAC,MAAM,gBAAgB,GAAG,+DAA+D,CAAC;AAChG,MAAM,CAAC,MAAM,cAAc,GAAG,gBAAgB,CAAC;AAC/C,MAAM,CAAC,MAAM,gBAAgB,GAAG,uCAAuC,CAAC;AAExE,wBAAwB;AACxB,MAAM,CAAC,MAAM,gBAAgB,GAAG,qBAAqB,CAAC;AACtD,MAAM,CAAC,MAAM,eAAe,GAAG,iFAAiF,CAAC;AAEjH,yBAAyB;AACzB,MAAM,CAAC,MAAM,kBAAkB,GAAG,kEAAkE,CAAC;AACrG,sFAAsF;AACtF,wFAAwF;AACxF,2CAA2C;AAC3C,MAAM,CAAC,MAAM,0BAA0B,GAAG,sCAAsC,CAAC;AACjF,MAAM,CAAC,MAAM,qBAAqB,GAAG,+DAA+D,CAAC;AAErG,uEAAuE;AACvE,MAAM,CAAC,MAAM,iBAAiB,GAAG,kEAAkE,CAAC;AACpG,MAAM,CAAC,MAAM,qBAAqB,GAAG,sEAAsE,CAAC;AAC5G,MAAM,CAAC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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
  */
@@ -30,3 +30,50 @@ export declare function fixDanglingCoreFrom(code: string): string;
30
30
  * into the unified '/ns/core' bridge before fast-fail assertions.
31
31
  */
32
32
  export declare function normalizeAnyCoreSpecToBridge(code: string): string;
33
+ /**
34
+ * Minimal specifier rewriter for deep subpath core modules.
35
+ *
36
+ * Takes Vite's correctly-transformed ESM output and ONLY rewrites the
37
+ * specifier strings inside import/export clauses. Does NOT:
38
+ * - Inject global defines
39
+ * - Run AST normalization
40
+ * - Convert named imports to default + destructure
41
+ * - Mangle newlines or code structure
42
+ *
43
+ * This replaces the heavy 5-pass pipeline (processCodeForDevice →
44
+ * rewriteImports → deduplicateLinkerImports → CJS wrapping → etc.)
45
+ * for deep subpath core modules where Vite already produces correct ESM.
46
+ */
47
+ export declare function rewriteSpecifiersForDevice(code: string, origin: string, ver: number): string;
48
+ /**
49
+ * Determine whether a `/ns/core` bridge URL points to a real subpath module.
50
+ *
51
+ * Any `/ns/core/<sub>` module now serves real ESM content with real named
52
+ * exports via Vite's transform pipeline, except for package-main aliases like
53
+ * `/ns/core/index`, which should be treated like the main `/ns/core`
54
+ * bridge and destructured from its default export.
55
+ * The main proxy bridge (`/ns/core`) still only exports a default Proxy and
56
+ * requires named imports to be destructured from it.
57
+ *
58
+ * This check is used in all named-import-to-default destructuring passes to
59
+ * skip rewriting for real subpath modules — they have named exports that work
60
+ * natively without conversion.
61
+ *
62
+ * Accepts both the canonical path form (`/ns/core/<sub>`) and the legacy
63
+ * query form (`/ns/core?p=<sub>`) for back-compat; every emitter has been
64
+ * migrated to the path form but external code may still carry the old URL.
65
+ */
66
+ export declare function isDeepCoreSubpath(url: string): boolean;
67
+ /**
68
+ * Synthesize a `default` export for an ESM module that only has named/star
69
+ * exports. Utility function — not currently called from the core bridge
70
+ * handler since `ensureDestructureCoreImports` now skips deep subpaths.
71
+ *
72
+ * Handles all three @nativescript/core patterns:
73
+ * 1. Direct declarations: export class X, export function Y, export const Z
74
+ * 2. Named re-exports: export { A, B } from '/path'
75
+ * 3. Star re-exports: export * from '/path'
76
+ *
77
+ * Returns the code unchanged if it already has a default export or CJS exports.
78
+ */
79
+ 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;
@@ -63,7 +59,9 @@ export function fixDanglingCoreFrom(code) {
63
59
  code = code.replace(/;\s*import\s+/g, ';\nimport ');
64
60
  // Multi-line form: import { ...\n ...\n} from\nimport "<core-url>";[tail]
65
61
  // 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) => {
62
+ // Accepts canonical path form (/ns/core/<sub>), legacy query form
63
+ // (/ns/core?p=<sub>), and versioned-path form (/ns/core/<ver>/<sub>).
64
+ code = code.replace(/(^|\n|;)\s*import\s*\{([\s\S]*?)\}\s*from\s*\n\s*import\s+["']((?:https?:\/\/[^"']+)?\/ns\/core(?:\/[^"']*)?(?:\?p=[^"']+)?)["'];?(.*)/g, (_m, pre, named, url, tail) => {
67
65
  const prefix = pre ? (String(pre).endsWith(';') ? String(pre) + '\n' : String(pre)) : '';
68
66
  const tailNorm = (tail || '').replace(/^\s*;?\s*/, '').trim();
69
67
  return prefix + `import {${named}} from "${url}";` + (tailNorm ? `\n${tailNorm}` : '');
@@ -77,7 +75,7 @@ export function fixDanglingCoreFrom(code) {
77
75
  const next = lines[i + 1];
78
76
  // Support when the next line starts with the core import followed by another ';import ...'
79
77
  // 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);
78
+ const m2 = /^\s*import\s+["']((?:https?:\/\/[^"']+)?\/ns\/core(?:\/[^"']*)?(?:\?p=[^"']+)?)["'];?(.*)$/.exec(next);
81
79
  if (m2) {
82
80
  const url = m2[1];
83
81
  const tail = m2[2] || '';
@@ -109,26 +107,271 @@ export function normalizeAnyCoreSpecToBridge(code) {
109
107
  return code;
110
108
  try {
111
109
  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
- };
110
+ const toCoreBridgeUrl = (sub) => buildCoreUrlPath(sub);
119
111
  // Static: import ... from "...@nativescript/core[/sub]..."
120
- out = out.replace(/from\s+["'][^"']*@nativescript[\/_-]core([^"']*)["']/g, (_m, sub) => `from "/ns/core${toQp(sub)}"`);
112
+ out = out.replace(/from\s+["'][^"']*@nativescript[\/_-]core([^"']*)["']/g, (_m, sub) => `from "${toCoreBridgeUrl(sub)}"`);
121
113
  // 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)}";`);
114
+ out = out.replace(/(^|\n)\s*import\s+["'][^"']*@nativescript[\/_-]core([^"']*)["'];?/gm, (full, pfx, sub) => `${pfx}import "${toCoreBridgeUrl(sub)}";`);
123
115
  // Dynamic: import("...@nativescript/core[/sub]...")
124
- out = out.replace(/import\(\s*["'][^"']*@nativescript[\/_-]core([^"']*)["']\s*\)/g, (_m, sub) => `import("/ns/core${toQp(sub)}")`);
116
+ out = out.replace(/import\(\s*["'][^"']*@nativescript[\/_-]core([^"']*)["']\s*\)/g, (_m, sub) => `import("${toCoreBridgeUrl(sub)}")`);
125
117
  // 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}"`);
118
+ // Normalize to a valid specifier: "from '/ns/core...'". Accepts both
119
+ // canonical path form (/ns/core/<sub>) and legacy ?p= form.
120
+ out = out.replace(/from\s+import\s+["']((?:https?:\/\/[^"']+)?\/ns\/core(?:\/[^"']*)?(?:\?p=[^"']+)?)['"]/g, (_m, url) => `from "${url}"`);
128
121
  return out;
129
122
  }
130
123
  catch {
131
124
  return code;
132
125
  }
133
126
  }
127
+ /**
128
+ * Rewrite a single import/export specifier for device consumption.
129
+ *
130
+ * Converts Vite-resolved root-relative paths to URLs the device can fetch:
131
+ * /node_modules/@nativescript/core/x/y → /ns/core/x/y (canonical)
132
+ * /node_modules/other-pkg/x.js → {origin}/ns/m/node_modules/other-pkg/x.js
133
+ * /src/app/foo.ts → {origin}/ns/m/src/app/foo.ts
134
+ * already /ns/... or http://... → unchanged
135
+ */
136
+ function rewriteSpec(spec, origin, ver) {
137
+ void ver;
138
+ // Strip Vite cache-busting query params for bridge URLs
139
+ const cleanSpec = spec.split('?')[0];
140
+ // @nativescript/core anywhere in the path → core bridge.
141
+ // Delegated to the ONE canonical URL generator to guarantee that
142
+ // every emitter — this function, the ns-core-external-urls plugin,
143
+ // main-entry's coreSpec, and the runtime import map — produces
144
+ // byte-identical URLs for the same logical module. Mixed forms
145
+ // (query `?p=`, versioned, `.js` suffix) would otherwise produce
146
+ // distinct iOS HTTP ESM cache entries for the same file,
147
+ // re-evaluating register() side effects and crashing on "Cannot
148
+ // redefine property".
149
+ const coreIdx = cleanSpec.indexOf('@nativescript/core');
150
+ if (coreIdx !== -1) {
151
+ const after = cleanSpec.substring(coreIdx + '@nativescript/core'.length);
152
+ return buildCoreUrlPath(after);
153
+ }
154
+ // Already a bridge, vendor, or HTTP URL → leave unchanged
155
+ if (spec.startsWith('/ns/') || spec.startsWith('http://') || spec.startsWith('https://') || spec.startsWith('ns-vendor://')) {
156
+ return spec;
157
+ }
158
+ // Leave relative specifiers for Vite/rolldown to resolve (they do not
159
+ // appear after Vite transform but the guard is free)
160
+ if (spec.startsWith('./') || spec.startsWith('../')) {
161
+ return spec;
162
+ }
163
+ // Root-relative paths → HTTP URL through /ns/m/ handler
164
+ if (spec.startsWith('/')) {
165
+ return `${origin}/ns/m${spec}`;
166
+ }
167
+ // Bare package specifier (e.g. `source-map-js/lib/source-map-generator.js`)
168
+ // → HTTP URL through /ns/m/node_modules/ handler. Under HMR bundle-build,
169
+ // @nativescript/core subpath modules served by this bridge (e.g.
170
+ // /ns/core?p=inspector_modules) may reference other npm packages with bare
171
+ // specifiers in their transformed output — specifically, the CommonJS
172
+ // compat transformer for source-map-js rewrites `require('./lib/source-
173
+ // map-generator')` into `import from 'source-map-js/lib/source-map-
174
+ // generator.js'`, a bare specifier that iOS's ESM loader cannot resolve at
175
+ // module-instantiation time (the runtime import map isn't installed yet).
176
+ // Converting to /ns/m/node_modules/<spec> makes iOS fetch the package over
177
+ // HTTP, which Vite serves through the same pipeline that already handles
178
+ // every other node_modules subpath import in the app.
179
+ return `${origin}/ns/m/node_modules/${spec}`;
180
+ }
181
+ /**
182
+ * Minimal specifier rewriter for deep subpath core modules.
183
+ *
184
+ * Takes Vite's correctly-transformed ESM output and ONLY rewrites the
185
+ * specifier strings inside import/export clauses. Does NOT:
186
+ * - Inject global defines
187
+ * - Run AST normalization
188
+ * - Convert named imports to default + destructure
189
+ * - Mangle newlines or code structure
190
+ *
191
+ * This replaces the heavy 5-pass pipeline (processCodeForDevice →
192
+ * rewriteImports → deduplicateLinkerImports → CJS wrapping → etc.)
193
+ * for deep subpath core modules where Vite already produces correct ESM.
194
+ */
195
+ export function rewriteSpecifiersForDevice(code, origin, ver) {
196
+ if (!code)
197
+ return code;
198
+ let result = code;
199
+ // Pattern 1: from "specifier" — covers all static import/export forms
200
+ // import { X } from "spec"
201
+ // import X from "spec"
202
+ // import * as X from "spec"
203
+ // export { X } from "spec"
204
+ // export * from "spec"
205
+ //
206
+ // The lookbehind guard below ensures we only match `from` at the start of
207
+ // its ESM-keyword context, not `from` appearing INSIDE a string literal
208
+ // (e.g. `if (time === 'from') { … }` in @nativescript/core's
209
+ // css-animation-parser). Without this guard the regex spans from the
210
+ // `from` inside the string to the NEXT quote elsewhere in the file,
211
+ // corrupting both tokens.
212
+ result = result.replace(/(?<![a-zA-Z0-9_$'"`])(from\s+)(["'])([^"']+)\2/g, (_m, pre, q, spec) => {
213
+ return `${pre}${q}${rewriteSpec(spec, origin, ver)}${q}`;
214
+ });
215
+ // Pattern 2: import("specifier") — dynamic imports
216
+ result = result.replace(/(import\s*\(\s*)(["'])([^"']+)\2(\s*\))/g, (_m, pre, q, spec, post) => {
217
+ return `${pre}${q}${rewriteSpec(spec, origin, ver)}${q}${post}`;
218
+ });
219
+ // Pattern 3: import "specifier" — side-effect imports (no from clause)
220
+ // Anchored after start-of-string, newline, or semicolon to avoid false matches.
221
+ // The `^` alternative is critical: when a transformed module's body begins
222
+ // with a side-effect import (no preceding `;` or `\n`), the legacy
223
+ // `[;\n]`-only anchor missed it and the URL leaked to the device unmodified.
224
+ // Concrete failure mode: `/ns/core/inspector_modules` whose first body line
225
+ // `import '/@fs/.../@nativescript/core/globals/index.js';` was served raw,
226
+ // producing a `__DEV__ is not defined` ReferenceError in `platform-check.js`
227
+ // because `/@fs/` URLs bypass the `/ns/core` bridge's define-injection.
228
+ result = result.replace(/(^|[;\n])(\s*import\s+)(["'])([^"']+)\3/g, (_m, lead, pre, q, spec) => {
229
+ // Skip if it looks like an identifier rather than a path
230
+ if (!/[/.@]/.test(spec))
231
+ return _m;
232
+ return `${lead}${pre}${q}${rewriteSpec(spec, origin, ver)}${q}`;
233
+ });
234
+ return result;
235
+ }
236
+ /**
237
+ * Determine whether a `/ns/core` bridge URL points to a real subpath module.
238
+ *
239
+ * Any `/ns/core/<sub>` module now serves real ESM content with real named
240
+ * exports via Vite's transform pipeline, except for package-main aliases like
241
+ * `/ns/core/index`, which should be treated like the main `/ns/core`
242
+ * bridge and destructured from its default export.
243
+ * The main proxy bridge (`/ns/core`) still only exports a default Proxy and
244
+ * requires named imports to be destructured from it.
245
+ *
246
+ * This check is used in all named-import-to-default destructuring passes to
247
+ * skip rewriting for real subpath modules — they have named exports that work
248
+ * natively without conversion.
249
+ *
250
+ * Accepts both the canonical path form (`/ns/core/<sub>`) and the legacy
251
+ * query form (`/ns/core?p=<sub>`) for back-compat; every emitter has been
252
+ * migrated to the path form but external code may still carry the old URL.
253
+ */
254
+ export function isDeepCoreSubpath(url) {
255
+ if (!url || typeof url !== 'string')
256
+ return false;
257
+ // Legacy query form
258
+ const query = url.match(/\?p=([^&'"#]+)/);
259
+ if (query) {
260
+ const sub = String(query[1] || '').replace(/^\/+/, '');
261
+ if (!sub || sub === 'index' || sub === 'index.js')
262
+ return false;
263
+ return true;
264
+ }
265
+ // Canonical path form — extract the subpath segment following /ns/core/.
266
+ const path = url.match(/\/ns\/core\/([^?#]+)/);
267
+ if (!path)
268
+ return false;
269
+ const sub = String(path[1] || '').replace(/^\/+|\/+$/g, '');
270
+ if (!sub || sub === 'index' || sub === 'index.js')
271
+ return false;
272
+ return true;
273
+ }
274
+ /**
275
+ * Synthesize a `default` export for an ESM module that only has named/star
276
+ * exports. Utility function — not currently called from the core bridge
277
+ * handler since `ensureDestructureCoreImports` now skips deep subpaths.
278
+ *
279
+ * Handles all three @nativescript/core patterns:
280
+ * 1. Direct declarations: export class X, export function Y, export const Z
281
+ * 2. Named re-exports: export { A, B } from '/path'
282
+ * 3. Star re-exports: export * from '/path'
283
+ *
284
+ * Returns the code unchanged if it already has a default export or CJS exports.
285
+ */
286
+ export function synthesizeDefaultExport(moduleCode) {
287
+ if (!moduleCode || typeof moduleCode !== 'string')
288
+ return moduleCode;
289
+ const hasExportDefault = /\bexport\s+default\b/.test(moduleCode) || /export\s*\{\s*default\s*(?:as\s*default)?\s*\}/.test(moduleCode);
290
+ if (hasExportDefault)
291
+ return moduleCode;
292
+ const hasCjsExports = /\bmodule\s*\.\s*exports\b/.test(moduleCode) || /\bexports\s*\.\s*\w/.test(moduleCode);
293
+ if (hasCjsExports)
294
+ return moduleCode;
295
+ try {
296
+ const bindings = []; // [localName, exportedName]
297
+ const extraImports = [];
298
+ const starSpreads = [];
299
+ let sIdx = 0;
300
+ let m;
301
+ // export { A, b as B } [from 'src'] — handles both local and re-exports
302
+ const reBraces = /\bexport\s*\{([^}]+)\}\s*(?:from\s*["']([^"']+)["'])?/g;
303
+ while ((m = reBraces.exec(moduleCode)) !== null) {
304
+ const specList = m[1];
305
+ const fromSrc = m[2]; // undefined for local exports
306
+ const specs = specList
307
+ .split(',')
308
+ .map((s) => s.trim())
309
+ .filter(Boolean);
310
+ for (const spec of specs) {
311
+ const parts = spec.split(/\s+as\s+/);
312
+ const srcName = parts[0].trim();
313
+ const expName = parts.length > 1 ? parts[1].trim() : srcName;
314
+ if (!expName || expName === 'default')
315
+ continue;
316
+ // For re-exports, the local name is the exported name (from the import we add below)
317
+ // For local exports, the local name is srcName (already in scope)
318
+ bindings.push(fromSrc ? [expName, expName] : [srcName, expName]);
319
+ }
320
+ if (fromSrc) {
321
+ const importSpecs = specs
322
+ .map((spec) => {
323
+ const parts = spec.split(/\s+as\s+/);
324
+ const srcName = parts[0].trim();
325
+ const expName = parts.length > 1 ? parts[1].trim() : srcName;
326
+ if (!expName || expName === 'default')
327
+ return '';
328
+ return parts.length > 1 ? `${srcName} as ${expName}` : expName;
329
+ })
330
+ .filter(Boolean);
331
+ if (importSpecs.length) {
332
+ extraImports.push(`import { ${importSpecs.join(', ')} } from ${JSON.stringify(fromSrc)};`);
333
+ }
334
+ }
335
+ }
336
+ // export const/let/var X
337
+ const reDecl = /\bexport\s+(?:const|let|var)\s+([A-Za-z_$][\w$]*)/g;
338
+ while ((m = reDecl.exec(moduleCode)) !== null) {
339
+ bindings.push([m[1], m[1]]);
340
+ }
341
+ // export [async] function[*]/class X
342
+ const reFunc = /\bexport\s+(?:async\s+)?(?:function\s*\*?|class)\s+([A-Za-z_$][\w$]*)/g;
343
+ while ((m = reFunc.exec(moduleCode)) !== null) {
344
+ bindings.push([m[1], m[1]]);
345
+ }
346
+ // export * as X from 'src' (namespace re-export)
347
+ const reStarAs = /\bexport\s*\*\s*as\s+([A-Za-z_$][\w$]*)\s+from\s*["']([^"']+)["']/g;
348
+ while ((m = reStarAs.exec(moduleCode)) !== null) {
349
+ extraImports.push(`import * as ${m[1]} from ${JSON.stringify(m[2])};`);
350
+ bindings.push([m[1], m[1]]);
351
+ }
352
+ // export * from 'src' (bare star re-export, NOT 'export * as')
353
+ const reStarBare = /\bexport\s*\*\s*(?!as\s)from\s*["']([^"']+)["']/g;
354
+ while ((m = reStarBare.exec(moduleCode)) !== null) {
355
+ const v = `__ns_star_${sIdx++}`;
356
+ extraImports.push(`import * as ${v} from ${JSON.stringify(m[1])};`);
357
+ starSpreads.push(`...${v}`);
358
+ }
359
+ if (bindings.length > 0 || starSpreads.length > 0) {
360
+ const entries = [...starSpreads];
361
+ const seen = new Set();
362
+ for (const [local, exported] of bindings) {
363
+ if (seen.has(exported))
364
+ continue;
365
+ seen.add(exported);
366
+ entries.push(local === exported ? exported : `${JSON.stringify(exported)}: ${local}`);
367
+ }
368
+ const prefix = extraImports.length ? extraImports.join('\n') + '\n' : '';
369
+ return prefix + moduleCode + `\nvar __ns_default_export = { ${entries.join(', ')} };\nexport { __ns_default_export as default };\n`;
370
+ }
371
+ return moduleCode;
372
+ }
373
+ catch {
374
+ return moduleCode;
375
+ }
376
+ }
134
377
  //# sourceMappingURL=core-sanitize.js.map