@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,631 @@
1
+ import { parse as babelParse } from '@babel/parser';
2
+ import * as t from '@babel/types';
3
+ import * as PAT from './constants.js';
4
+ import { isDeepCoreSubpath } from './core-sanitize.js';
5
+ import { getCjsNamedExports } from '../helpers/cjs-named-exports.js';
6
+ import { extractDirectExportedNames } from './websocket-core-bridge.js';
7
+ const MODULE_IMPORT_ANALYSIS_PLUGINS = ['typescript', 'jsx', 'importMeta', 'topLevelAwait', 'classProperties', 'classPrivateProperties', 'classPrivateMethods', 'decorators-legacy'];
8
+ export function collectTopLevelImportRecords(code) {
9
+ if (!code || typeof code !== 'string' || !/\bimport\b/.test(code)) {
10
+ return [];
11
+ }
12
+ try {
13
+ const ast = babelParse(code, {
14
+ sourceType: 'module',
15
+ plugins: MODULE_IMPORT_ANALYSIS_PLUGINS,
16
+ });
17
+ const body = ast?.program?.body;
18
+ if (!Array.isArray(body)) {
19
+ return [];
20
+ }
21
+ return body
22
+ .filter((node) => t.isImportDeclaration(node) && typeof node.start === 'number' && typeof node.end === 'number' && typeof node.source?.value === 'string')
23
+ .map((node) => ({
24
+ start: node.start,
25
+ end: node.end,
26
+ text: code.slice(node.start, node.end),
27
+ source: node.source.value,
28
+ hasOnlyNamedSpecifiers: Array.isArray(node.specifiers) && node.specifiers.length > 0 && node.specifiers.every((spec) => t.isImportSpecifier(spec)),
29
+ namedBindings: Array.isArray(node.specifiers)
30
+ ? node.specifiers
31
+ .filter((spec) => t.isImportSpecifier(spec) && typeof spec.start === 'number' && typeof spec.end === 'number')
32
+ .map((spec) => ({
33
+ importedName: t.isIdentifier(spec.imported) ? spec.imported.name : String(spec.imported?.value || ''),
34
+ text: code.slice(spec.start, spec.end),
35
+ }))
36
+ : [],
37
+ }));
38
+ }
39
+ catch {
40
+ return [];
41
+ }
42
+ }
43
+ export function hoistTopLevelStaticImports(code) {
44
+ const imports = collectTopLevelImportRecords(code);
45
+ if (!imports.length) {
46
+ return code;
47
+ }
48
+ let stripped = code;
49
+ for (const imp of [...imports].sort((left, right) => right.start - left.start)) {
50
+ stripped = stripped.slice(0, imp.start) + stripped.slice(imp.end);
51
+ }
52
+ const hoisted = [];
53
+ const seen = new Set();
54
+ for (const imp of imports) {
55
+ const text = imp.text.trim();
56
+ if (!text || seen.has(text)) {
57
+ continue;
58
+ }
59
+ seen.add(text);
60
+ hoisted.push(text);
61
+ }
62
+ if (!hoisted.length) {
63
+ return stripped;
64
+ }
65
+ return `${hoisted.join('\n')}\n${stripped.replace(/^\s*\n+/, '')}`;
66
+ }
67
+ export function buildBootProgressSnippet(bootModuleLabel) {
68
+ const normalizedLabel = JSON.stringify(String(bootModuleLabel || '').replace(/\\/g, '/'));
69
+ return [
70
+ `const __nsBootGlobal=globalThis;`,
71
+ `try{if(!__nsBootGlobal.__NS_HMR_BOOT_COMPLETE__){const __nsBootApi=__nsBootGlobal.__NS_HMR_DEV_OVERLAY__;if(__nsBootApi&&typeof __nsBootApi.setBootStage==='function'){const __nsBootCount=(__nsBootGlobal.__NS_HMR_BOOT_MODULE_COUNT__=Number(__nsBootGlobal.__NS_HMR_BOOT_MODULE_COUNT__||0)+1);__nsBootGlobal.__NS_HMR_BOOT_LAST_MODULE__=${normalizedLabel};const __nsBootNow=Date.now();const __nsBootLast=Number(__nsBootGlobal.__NS_HMR_BOOT_LAST_PROGRESS_AT__||0);if(__nsBootCount<=8||__nsBootCount%6===0||__nsBootNow-__nsBootLast>90){__nsBootGlobal.__NS_HMR_BOOT_LAST_PROGRESS_AT__=__nsBootNow;const __nsBootProgress=Math.min(94,82+Math.min(10,Math.round((Math.log(__nsBootCount+1)/Math.LN2)*2)));__nsBootApi.setBootStage('importing-main',{detail:'Evaluated '+__nsBootCount+' modules\\n'+__nsBootGlobal.__NS_HMR_BOOT_LAST_MODULE__,attempt:Number(__nsBootGlobal.__NS_HMR_BOOT_MAIN_ATTEMPT__||1),attempts:Number(__nsBootGlobal.__NS_HMR_BOOT_MAIN_ATTEMPTS__||6),progress:__nsBootProgress});}}}}catch(__nsBootErr){}`,
72
+ `if(!__nsBootGlobal.__NS_HMR_BOOT_COMPLETE__){const __nsBootCount=Number(__nsBootGlobal.__NS_HMR_BOOT_MODULE_COUNT__||0);if(__nsBootCount<=24||__nsBootCount%8===0){await new Promise((resolve)=>setTimeout(resolve,0));}}`,
73
+ '',
74
+ ].join('\n');
75
+ }
76
+ export function stripCoreGlobalsImports(code) {
77
+ const pattern = /^\s*(?:import\s+(?:[^'"\n]*from\s+)?|export\s+\*\s+from\s+)["'][^"']*(?:@nativescript(?:[/_-])core(?:[\/_-])globals|@nativescript_core_globals)[^"']*["'];?\s*$/gm;
78
+ return code.replace(pattern, '');
79
+ }
80
+ export function ensureVariableDynamicImportHelper(code) {
81
+ if (!code.includes('__variableDynamicImportRuntimeHelper')) {
82
+ return code;
83
+ }
84
+ if (PAT.VARIABLE_DYNAMIC_IMPORT_HELPER_PATTERN.test(code)) {
85
+ return code;
86
+ }
87
+ const helper = `const __variableDynamicImportRuntimeHelper = (map, request, importMode) => {\n` +
88
+ ` try { if (request === '@') { return import(new URL('/ns/m/__invalid_at__.mjs', import.meta.url).href); } } catch {}\n` +
89
+ ` const loader = map && (map[request] || map[request?.replace(/\\\\/g, "/")]);\n` +
90
+ ` if (!loader) {\n` +
91
+ ` const error = new Error("Cannot dynamically import: " + request);\n` +
92
+ ` error.code = 'ERR_MODULE_NOT_FOUND';\n` +
93
+ ` return Promise.reject(error);\n` +
94
+ ` }\n` +
95
+ ` try {\n` +
96
+ ` return loader(importMode);\n` +
97
+ ` } catch (err) {\n` +
98
+ ` return Promise.reject(err);\n` +
99
+ ` }\n` +
100
+ `};\n`;
101
+ return `${helper}${code}`;
102
+ }
103
+ export function ensureGuardPlainDynamicImports(code, _origin) {
104
+ try {
105
+ if (!code || !/\bimport\s*\(/.test(code))
106
+ return code;
107
+ const wrapper = `const __ns_import = (s) => { try { if (s === '@') { return import(new URL('/ns/m/__invalid_at__.mjs', import.meta.url).href); } } catch {} return import(s); }\n`;
108
+ const replaced = code.replace(/(^|[^\.\w$])import\s*\(/g, (_m, p1) => `${p1}__ns_import(`);
109
+ if (replaced !== code) {
110
+ return wrapper + replaced;
111
+ }
112
+ return code;
113
+ }
114
+ catch {
115
+ return code;
116
+ }
117
+ }
118
+ // Stable URL helper for dynamic imports.
119
+ //
120
+ // Older versions of the helper synthesized
121
+ // `/ns/m/__ns_hmr__/<tag>/<rest>` URLs from
122
+ // `globalThis.__NS_HMR_GRAPH_VERSION__` and an importer-derived tag.
123
+ // That tag flowed straight into V8's `g_moduleRegistry` cache key — so
124
+ // a `graphVersion` bump on every save effectively flushed the whole
125
+ // module graph (HMR latency was dominated by Vite re-transforming the
126
+ // unchanged closure on every save).
127
+ //
128
+ // The current contract inverts that:
129
+ // * The runtime canonicalizes any URL shape (boot prefix, hmr prefix,
130
+ // stable) to a single key via `CanonicalizeHttpUrlKey`.
131
+ // * The Angular client receives an explicit eviction set in
132
+ // `ns:angular-update` and calls `__nsInvalidateModules` before
133
+ // re-importing the entry, so V8 only refetches modules that
134
+ // actually changed.
135
+ // * The dynamic-import helper no longer needs to busy-construct
136
+ // versioned URLs. Boot prefix preservation still matters at COLD
137
+ // boot because the server-side handler routes `/__ns_boot__/b1/`
138
+ // paths to the boot-progress instrumentation snippet — but the
139
+ // prefix is read from `import.meta.url`, never synthesized from
140
+ // `__NS_HMR_GRAPH_VERSION__`.
141
+ //
142
+ // The helper is intentionally tiny:
143
+ // 1. `@` and falsy specs route to `/ns/m/__invalid_at__.mjs` (existing
144
+ // defensive sentinel for misencoded imports).
145
+ // 2. `/ns/m/...` specs that don't yet have a boot prefix get one
146
+ // added when the caller is itself a boot-tagged module. This
147
+ // keeps the boot-progress instrumentation flowing through the
148
+ // transitive cold-boot graph during cold-boot sequences. Once HMR
149
+ // takes over (`__NS_HMR_BOOT_COMPLETE__` is set on the global), no
150
+ // prefix is added — the runtime canonicalizer collapses any
151
+ // historical prefix to the same key.
152
+ // 3. Everything else is a pass-through `import(spec)`.
153
+ export function ensureDynamicHmrImportHelper(code) {
154
+ try {
155
+ if (!code.includes('__nsDynamicHmrImport('))
156
+ return code;
157
+ if (code.includes('const __nsDynamicHmrImport ='))
158
+ return code;
159
+ const helper = 'const __nsDynamicHmrImport = (spec) => {\n' +
160
+ " const __nsm = '/ns' + '/m';\n" +
161
+ " try { if (!spec || spec === '@') { return import(new URL(__nsm + '/__invalid_at__.mjs', import.meta.url).href); } } catch {}\n" +
162
+ ' try {\n' +
163
+ " if (typeof spec !== 'string' || !spec.startsWith(__nsm + '/')) return import(spec);\n" +
164
+ ' const g = globalThis;\n' +
165
+ " const inBoot = !g.__NS_HMR_BOOT_COMPLETE__ && typeof import.meta !== 'undefined' && import.meta && typeof import.meta.url === 'string' && import.meta.url.includes('/__ns_boot__/b1/');\n" +
166
+ " const noBootPrefixYet = !spec.startsWith(__nsm + '/__ns_boot__/');\n" +
167
+ " const isAppModule = !spec.startsWith(__nsm + '/node_modules/');\n" +
168
+ " const finalSpec = inBoot && noBootPrefixYet && isAppModule ? __nsm + '/__ns_boot__/b1' + spec.slice(__nsm.length) : spec;\n" +
169
+ " const origin = typeof g.__NS_HTTP_ORIGIN__ === 'string' && /^https?:\\/\\//.test(g.__NS_HTTP_ORIGIN__) ? g.__NS_HTTP_ORIGIN__ : '';\n" +
170
+ ' return import(origin ? origin + finalSpec : new URL(finalSpec, import.meta.url).href);\n' +
171
+ ' } catch {}\n' +
172
+ ' return import(spec);\n' +
173
+ '};\n';
174
+ return helper + code;
175
+ }
176
+ catch {
177
+ return code;
178
+ }
179
+ }
180
+ function extractExportedNames(code) {
181
+ return extractDirectExportedNames(code);
182
+ }
183
+ export async function expandStarExports(code, server, _projectRoot, verbose) {
184
+ const STAR_RE = /^[ \t]*(export\s+\*\s+from\s+["'])([^"']+)(["'];?)[ \t]*$/gm;
185
+ let match;
186
+ const replacements = [];
187
+ while ((match = STAR_RE.exec(code)) !== null) {
188
+ const url = match[2];
189
+ if (!url.includes('/node_modules/'))
190
+ continue;
191
+ replacements.push({ full: match[0], url, prefix: match[1], suffix: match[3] });
192
+ }
193
+ if (!replacements.length)
194
+ return code;
195
+ for (const rep of replacements) {
196
+ try {
197
+ let vitePath = rep.url.replace(/^https?:\/\/[^/]+/, '');
198
+ vitePath = vitePath.replace(/^\/ns\/m\//, '/');
199
+ vitePath = vitePath.replace(/^\/__ns_boot__\/[^/]+/, '');
200
+ vitePath = vitePath.replace(/\/__ns_hmr__\/[^/]+/, '');
201
+ const result = await server.transformRequest(vitePath);
202
+ if (!result?.code)
203
+ continue;
204
+ const names = extractExportedNames(result.code);
205
+ if (!names.length)
206
+ continue;
207
+ const explicit = `export { ${names.join(', ')} } from ${JSON.stringify(rep.url)};`;
208
+ code = code.replace(rep.full, explicit);
209
+ if (verbose) {
210
+ console.log(`[ns/m] expanded export* -> ${names.length} names from ${vitePath}`);
211
+ }
212
+ }
213
+ catch { }
214
+ }
215
+ return code;
216
+ }
217
+ export function repairImportEqualsAssignments(code) {
218
+ try {
219
+ if (!code || typeof code !== 'string')
220
+ return code;
221
+ code = code.replace(/(^|\n)\s*import\s*\{([^}]+)\}\s*=\s*([^;]+);?/g, (_m, p1, specList, rhs) => {
222
+ const cleaned = String(specList)
223
+ .split(',')
224
+ .map((s) => s.trim())
225
+ .filter(Boolean)
226
+ .map((seg) => seg.replace(/\s+as\s+/i, ': '))
227
+ .join(', ');
228
+ return `${p1}const { ${cleaned} } = ${rhs};`;
229
+ });
230
+ code = code.replace(/(^|\n)\s*import\s*\*\s*as\s*([A-Za-z_$][\w$]*)\s*=\s*([^;]+);?/g, (_m, p1, ns, rhs) => `${p1}const ${ns} = (${rhs});`);
231
+ code = code.replace(/(^|\n)\s*import\s+([A-Za-z_$][\w$]*)\s*=\s*([^;]+);?/g, (_m, p1, id, rhs) => `${p1}const ${id} = ${rhs};`);
232
+ }
233
+ catch { }
234
+ return code;
235
+ }
236
+ export function ensureVersionedRtImports(code, origin, ver) {
237
+ if (!code || !origin || !Number.isFinite(ver))
238
+ return code;
239
+ code = code.replace(/(from\s+["'])(?:https?:\/\/[^"']+)?\/(?:\@ns|ns)\/rt(?:\/[\d]+)?(["'])/g, (_m, p1, p3) => `${p1}/ns/rt/${ver}${p3}`);
240
+ code = code.replace(/(import\(\s*["'])(?:https?:\/\/[^"']+)?\/(?:\@ns|ns)\/rt(?:\/[\d]+)?(["']\s*\))/g, (_m, p1, p3) => `${p1}/ns/rt/${ver}${p3}`);
241
+ return code;
242
+ }
243
+ export function stripViteDynamicImportVirtual(code) {
244
+ if (!/\/@id\/__x00__vite\/dynamic-import-helper/.test(code)) {
245
+ return code;
246
+ }
247
+ const original = code;
248
+ code = code.replace(/^[\t ]*import[^\n]*\/@id\/__x00__vite\/dynamic-import-helper[^\n]*$/gm, '');
249
+ if (/\/@id\/__x00__vite\/dynamic-import-helper/.test(code)) {
250
+ code = code.replace(/\/@id\/__x00__vite\/dynamic-import-helper[^"'`)]*/g, '/__NS_UNUSED_DYNAMIC_IMPORT_HELPER__');
251
+ }
252
+ if (!/__variableDynamicImportRuntimeHelper/.test(code)) {
253
+ const inline = `const __variableDynamicImportRuntimeHelper = (map, request, importMode) => {\n try { if (request === '@') { return import('/ns/m/__invalid_at__.mjs'); } } catch {}\n const loader = map && (map[request] || map[request?.replace(/\\\\/g, '/')]);\n if (!loader) { const e = new Error('Cannot dynamically import: ' + request); /*@ts-ignore*/ e.code = 'ERR_MODULE_NOT_FOUND'; return Promise.reject(e); }\n try { return loader(importMode); } catch (e) { return Promise.reject(e); }\n};\n`;
254
+ code = inline + code;
255
+ }
256
+ if (code !== original) {
257
+ code = `// [hmr-sanitize] removed virtual dynamic-import-helper\n${code}`;
258
+ }
259
+ return code;
260
+ }
261
+ export function extractExportMetadata(code) {
262
+ const named = new Set();
263
+ let hasDefault = /\bexport\s+default\b/.test(code);
264
+ try {
265
+ for (const match of code.matchAll(/\bexport\s+(?:const|let|var|function|class)\s+([A-Za-z_$][A-Za-z0-9_$]*)/g)) {
266
+ if (match[1])
267
+ named.add(match[1]);
268
+ }
269
+ for (const match of code.matchAll(/\bexport\s*\{([^}]+)\}/g)) {
270
+ const inner = (match[1] || '')
271
+ .split(',')
272
+ .map((s) => s.trim())
273
+ .filter(Boolean);
274
+ for (const seg of inner) {
275
+ const direct = seg.match(/^([A-Za-z_$][A-Za-z0-9_$]*)(?:\s+as\s+([A-Za-z_$][A-Za-z0-9_$]*))?$/);
276
+ if (!direct)
277
+ continue;
278
+ const base = direct[1];
279
+ const alias = direct[2];
280
+ if (base === 'default') {
281
+ hasDefault = true;
282
+ continue;
283
+ }
284
+ named.add(alias || base);
285
+ }
286
+ }
287
+ }
288
+ catch { }
289
+ named.delete('default');
290
+ return { hasDefault, named: Array.from(named) };
291
+ }
292
+ function shouldAllowLocalCoreSanitizerPaths(contextLabel) {
293
+ return /\bnode_modules\/@nativescript\/vite\/hmr\/(?:client|frameworks)\//.test(contextLabel);
294
+ }
295
+ export function assertNoOptimizedArtifacts(code, contextLabel) {
296
+ try {
297
+ const offenders = [];
298
+ const lines = code.split('\n');
299
+ const tests = [/\b__VITE_PLUGIN__\b/, /\b__VITE_PRELOAD__\b/];
300
+ const localCore = /(^|[^\w@])(?:\.\.?\/|\/)??@nativescript[\/_-]core\//i;
301
+ for (let i = 0; i < lines.length; i++) {
302
+ const line = lines[i];
303
+ for (const re of tests) {
304
+ if (re.test(line)) {
305
+ offenders.push(`${i + 1}: ${line.substring(0, 200)}`);
306
+ break;
307
+ }
308
+ }
309
+ if (localCore.test(line)) {
310
+ const trimmed = line.trimStart();
311
+ if (trimmed.startsWith('//') || trimmed.startsWith('/*') || trimmed.startsWith('*')) {
312
+ continue;
313
+ }
314
+ if (shouldAllowLocalCoreSanitizerPaths(contextLabel)) {
315
+ continue;
316
+ }
317
+ offenders.push(`${i + 1}: ${line.substring(0, 200)} [local-core-path]`);
318
+ }
319
+ if (offenders.length >= 10)
320
+ break;
321
+ }
322
+ if (offenders.length) {
323
+ const msg = `[sanitize-fail] Optimized deps/virtual id artifacts detected in ${contextLabel}. These cannot be evaluated by the device HTTP ESM loader. Offending lines (first ${Math.min(5, offenders.length)} shown):\n` + offenders.slice(0, 5).join('\n');
324
+ const error = new Error(msg);
325
+ error.code = 'NS_SANITIZE_FAIL';
326
+ error.offenders = offenders;
327
+ throw error;
328
+ }
329
+ }
330
+ catch (error) {
331
+ throw error;
332
+ }
333
+ }
334
+ export function ensureDestructureCoreImports(code) {
335
+ try {
336
+ let result = code;
337
+ let coreImportCounter = 0;
338
+ const toDestructure = (specList) => specList
339
+ .split(',')
340
+ .map((s) => s.trim())
341
+ .filter(Boolean)
342
+ .map((seg) => {
343
+ const match = seg.split(/\s+as\s+/i);
344
+ return match.length === 2 ? `${match[0].trim()}: ${match[1].trim()}` : seg;
345
+ })
346
+ .join(', ');
347
+ const reNamed = /(^|\n)\s*import\s*\{([^}]+)\}\s*from\s*["']((?:https?:\/\/[^"']+)?\/ns\/core(?:\/[\d]+)?(?:\?p=[^"']+)?)['"];?\s*/gm;
348
+ result = result.replace(reNamed, (_full, prefix, specList, src) => {
349
+ if (isDeepCoreSubpath(src))
350
+ return _full;
351
+ const tempName = `__ns_core_ns_re${coreImportCounter > 0 ? `_${coreImportCounter}` : ''}`;
352
+ coreImportCounter++;
353
+ const decl = `const { ${toDestructure(specList)} } = ${tempName};`;
354
+ return `${prefix}import ${tempName} from ${JSON.stringify(src)};\n${decl}\n`;
355
+ });
356
+ const reMixed = /(^|\n)\s*import\s+([A-Za-z_$][\w$]*)\s*,\s*\{([^}]+)\}\s*from\s*["']((?:https?:\/\/[^"']+)?\/ns\/core(?:\/[\d]+)?(?:\?p=[^"']+)?)['"];?\s*/gm;
357
+ result = result.replace(reMixed, (_full, prefix, defName, specList, src) => {
358
+ if (isDeepCoreSubpath(src))
359
+ return _full;
360
+ const decl = `const { ${toDestructure(specList)} } = ${defName};`;
361
+ return `${prefix}import ${defName} from ${JSON.stringify(src)};\n${decl}\n`;
362
+ });
363
+ return result;
364
+ }
365
+ catch {
366
+ return code;
367
+ }
368
+ }
369
+ export function ensureDestructureRtImports(code) {
370
+ try {
371
+ let result = code;
372
+ const toDestructure = (specList) => specList
373
+ .split(',')
374
+ .map((s) => s.trim())
375
+ .filter(Boolean)
376
+ .map((seg) => {
377
+ const match = seg.split(/\s+as\s+/i);
378
+ return match.length === 2 ? `${match[0].trim()}: ${match[1].trim()}` : seg;
379
+ })
380
+ .join(', ');
381
+ const reNamed = /(^|\n)\s*import\s*\{([^}]+)\}\s*from\s*["']((?:https?:\/\/[^"']+)?\/ns\/rt(?:\/[\d]+)?)['"];?\s*/gm;
382
+ result = result.replace(reNamed, (_full, prefix, specList, src) => {
383
+ const tempName = `__ns_rt_ns_re`;
384
+ const decl = `const { ${toDestructure(specList)} } = ${tempName};`;
385
+ return `${prefix}import ${tempName} from ${JSON.stringify(src)};\n${decl}\n`;
386
+ });
387
+ const reMixed = /(^|\n)\s*import\s+([A-Za-z_$][\w$]*)\s*,\s*\{([^}]+)\}\s*from\s*["']((?:https?:\/\/[^"']+)?\/ns\/rt(?:\/[\d]+)?)['"];?\s*/gm;
388
+ result = result.replace(reMixed, (_full, prefix, defName, specList, src) => {
389
+ const decl = `const { ${toDestructure(specList)} } = ${defName};`;
390
+ return `${prefix}import ${defName} from ${JSON.stringify(src)};\n${decl}\n`;
391
+ });
392
+ return result;
393
+ }
394
+ catch {
395
+ return code;
396
+ }
397
+ }
398
+ export function dedupeRtNamedImportsAgainstDestructures(code) {
399
+ try {
400
+ let result = code;
401
+ const rtDestructureRE = /(^|\n)\s*const\s*\{([^}]+)\}\s*=\s*(__ns_rt_ns(?:\d+|_re))\s*;?/gm;
402
+ const rtBound = new Set();
403
+ let match;
404
+ while ((match = rtDestructureRE.exec(result)) !== null) {
405
+ const specList = String(match[2] || '');
406
+ specList
407
+ .split(',')
408
+ .map((s) => s.trim())
409
+ .filter(Boolean)
410
+ .forEach((seg) => {
411
+ const bind = seg.includes(':') ? seg.split(':')[1].trim() : seg;
412
+ if (bind)
413
+ rtBound.add(bind);
414
+ });
415
+ }
416
+ if (!rtBound.size)
417
+ return result;
418
+ const rtNamedImportRE = /(^|\n)\s*import\s*\{([^}]+)\}\s*from\s*["']((?:https?:\/\/[^"']+)?\/ns\/rt(?:\/[\d]+)?)['"];?\s*/gm;
419
+ const edits = [];
420
+ while ((match = rtNamedImportRE.exec(result)) !== null) {
421
+ const full = match[0];
422
+ const prefix = match[1] || '';
423
+ const specList = String(match[2] || '');
424
+ const src = match[3];
425
+ const kept = [];
426
+ specList
427
+ .split(',')
428
+ .map((s) => s.trim())
429
+ .filter(Boolean)
430
+ .forEach((seg) => {
431
+ const importedName = seg.split(/\s+as\s+/i)[0].trim();
432
+ if (!rtBound.has(importedName))
433
+ kept.push(seg);
434
+ });
435
+ let replacement = '';
436
+ if (kept.length) {
437
+ replacement = `${prefix}import { ${kept.join(', ')} } from ${JSON.stringify(src)};`;
438
+ }
439
+ else {
440
+ replacement = prefix || '';
441
+ }
442
+ edits.push({
443
+ start: rtNamedImportRE.lastIndex - full.length,
444
+ end: rtNamedImportRE.lastIndex,
445
+ text: replacement,
446
+ });
447
+ }
448
+ if (edits.length) {
449
+ edits
450
+ .sort((a, b) => b.start - a.start)
451
+ .forEach((edit) => {
452
+ result = result.slice(0, edit.start) + edit.text + result.slice(edit.end);
453
+ });
454
+ }
455
+ return result;
456
+ }
457
+ catch {
458
+ return code;
459
+ }
460
+ }
461
+ export function deduplicateLinkerImports(code) {
462
+ if (!code)
463
+ return code;
464
+ try {
465
+ const imports = collectTopLevelImportRecords(code);
466
+ if (!imports.length) {
467
+ return code;
468
+ }
469
+ const pkgUrlMap = new Map();
470
+ const pkgBindings = new Map();
471
+ for (const imp of imports) {
472
+ const url = imp.source;
473
+ if (!/^https?:\/\//.test(url) && !url.startsWith('/')) {
474
+ continue;
475
+ }
476
+ const nmIdx = url.lastIndexOf('/node_modules/');
477
+ if (nmIdx === -1)
478
+ continue;
479
+ const afterNm = url.substring(nmIdx + '/node_modules/'.length);
480
+ const parts = afterNm.split('/');
481
+ const pkg = parts[0].startsWith('@') ? parts.slice(0, 2).join('/') : parts[0];
482
+ if (!pkgUrlMap.has(pkg))
483
+ pkgUrlMap.set(pkg, url);
484
+ if (imp.namedBindings.length) {
485
+ if (!pkgBindings.has(pkg))
486
+ pkgBindings.set(pkg, new Set());
487
+ for (const binding of imp.namedBindings) {
488
+ if (binding.importedName)
489
+ pkgBindings.get(pkg).add(binding.importedName);
490
+ }
491
+ }
492
+ }
493
+ if (pkgUrlMap.size === 0)
494
+ return code;
495
+ const edits = [];
496
+ for (const imp of imports) {
497
+ if (!imp.hasOnlyNamedSpecifiers) {
498
+ continue;
499
+ }
500
+ const specifier = imp.source;
501
+ if (specifier.startsWith('/') || specifier.startsWith('.') || specifier.startsWith('http')) {
502
+ continue;
503
+ }
504
+ const parts = specifier.split('/');
505
+ const pkg = specifier.startsWith('@') ? parts.slice(0, 2).join('/') : parts[0];
506
+ const url = pkgUrlMap.get(pkg);
507
+ if (!url) {
508
+ continue;
509
+ }
510
+ const existing = pkgBindings.get(pkg) || new Set();
511
+ const newBindings = imp.namedBindings.filter((binding) => !existing.has(binding.importedName));
512
+ if (newBindings.length === 0) {
513
+ edits.push({ start: imp.start, end: imp.end, text: '' });
514
+ continue;
515
+ }
516
+ if (newBindings.length === imp.namedBindings.length) {
517
+ continue;
518
+ }
519
+ for (const binding of newBindings) {
520
+ existing.add(binding.importedName);
521
+ }
522
+ edits.push({
523
+ start: imp.start,
524
+ end: imp.end,
525
+ text: `import { ${newBindings.map((binding) => binding.text).join(', ')} } from ${JSON.stringify(url)};`,
526
+ });
527
+ }
528
+ if (!edits.length) {
529
+ return code;
530
+ }
531
+ let next = code;
532
+ for (const edit of edits.sort((left, right) => right.start - left.start)) {
533
+ next = next.slice(0, edit.start) + edit.text + next.slice(edit.end);
534
+ }
535
+ return next;
536
+ }
537
+ catch {
538
+ return code;
539
+ }
540
+ }
541
+ export function wrapCommonJsModuleForDevice(code, absolutePath) {
542
+ if (!code)
543
+ return code;
544
+ try {
545
+ const hasExportDefault = /\bexport\s+default\b/.test(code) || /export\s*\{\s*default\s*(?:as\s*default)?\s*\}/.test(code);
546
+ const hasNamedExports = /\bexport\s+(?:const|let|var|function|class|async)\b/.test(code) || /\bexport\s*\{/.test(code);
547
+ const hasCjsExports = /\bmodule\s*\.\s*exports\b/.test(code) || /\bexports\s*\.\s*\w/.test(code);
548
+ if (hasExportDefault || hasNamedExports || !hasCjsExports) {
549
+ return code;
550
+ }
551
+ const namedExports = new Set();
552
+ const exportsRe = /\bexports\s*\.\s*([A-Za-z_$][\w$]*)\s*=/g;
553
+ let match;
554
+ while ((match = exportsRe.exec(code)) !== null) {
555
+ const name = match[1];
556
+ if (name !== '__esModule' && name !== 'default') {
557
+ namedExports.add(name);
558
+ }
559
+ }
560
+ const defPropRe = /Object\s*\.\s*defineProperty\s*\(\s*exports\s*,\s*['"]([^'"]+)['"]/g;
561
+ while ((match = defPropRe.exec(code)) !== null) {
562
+ const name = match[1];
563
+ if (name !== '__esModule' && name !== 'default') {
564
+ namedExports.add(name);
565
+ }
566
+ }
567
+ // Static enumeration only sees `exports.foo = ...` and `Object.defineProperty(exports, 'foo', ...)`.
568
+ // Real-world packages like lodash attach their entire surface to a function inside an IIFE and
569
+ // then `module.exports = thatFunction`. Static analysis returns zero in that case. To handle
570
+ // these modules we ALSO load the package in the dev-server's Node context (only when we have a
571
+ // node_modules path) and merge the runtime keys. See `helpers/cjs-named-exports.ts` for the
572
+ // reasoning and safety boundaries.
573
+ if (absolutePath) {
574
+ try {
575
+ for (const n of getCjsNamedExports(absolutePath)) {
576
+ namedExports.add(n);
577
+ }
578
+ }
579
+ catch {
580
+ /* fall through to whatever we caught statically */
581
+ }
582
+ }
583
+ let suffix = `\nvar __cjs_mod = module.exports;\nexport default __cjs_mod;\n`;
584
+ if (namedExports.size) {
585
+ const entries = Array.from(namedExports);
586
+ const temps = entries.map((name, i) => `var __cjs_e${i} = __cjs_mod[${JSON.stringify(name)}];`);
587
+ const reExports = entries.map((name, i) => `__cjs_e${i} as ${name}`);
588
+ suffix += `${temps.join(' ')}\nexport { ${reExports.join(', ')} };\n`;
589
+ }
590
+ const prelude = `var module = { exports: {} }; var exports = module.exports;\n` +
591
+ `var __ns_cjs_require_base = (typeof globalThis.__nsBaseRequire === 'function' ? globalThis.__nsBaseRequire : (typeof globalThis.__nsRequire === 'function' ? globalThis.__nsRequire : (typeof globalThis.require === 'function' ? globalThis.require : undefined)));\n` +
592
+ `var __ns_cjs_require_kind = (typeof globalThis.__nsBaseRequire === 'function' ? 'base-require' : (typeof globalThis.__nsRequire === 'function' ? 'vendor-require' : 'global-require'));\n` +
593
+ `var require = function(spec) {\n` +
594
+ ` if (!__ns_cjs_require_base) { throw new Error('require is not defined'); }\n` +
595
+ // Resolve relative specifiers against the HTTP-served module's URL
596
+ // before delegating to NS's runtime require. Keeps ./sibling and
597
+ // ../parent requires routable through the HTTP ESM loader rather
598
+ // than NS's filesystem-based require.
599
+ ` var __nsResolvedSpec = spec;\n` +
600
+ ` try {\n` +
601
+ ` if (typeof spec === 'string' && (spec.indexOf('./') === 0 || spec.indexOf('../') === 0)) {\n` +
602
+ ` var __nsParentUrl = (typeof import.meta !== 'undefined' && import.meta && typeof import.meta.url === 'string') ? import.meta.url : null;\n` +
603
+ ` if (__nsParentUrl) {\n` +
604
+ ` var __nsResolvedUrl = new URL(spec, __nsParentUrl);\n` +
605
+ ` if (!/\\.[A-Za-z0-9]+$/.test(__nsResolvedUrl.pathname.split('/').pop() || '')) {\n` +
606
+ ` __nsResolvedUrl.pathname = __nsResolvedUrl.pathname.replace(/\\/+$/, '') + '.js';\n` +
607
+ ` }\n` +
608
+ ` __nsResolvedSpec = __nsResolvedUrl.href;\n` +
609
+ ` }\n` +
610
+ ` }\n` +
611
+ ` } catch (e) {}\n` +
612
+ ` try { var __nsRecord = globalThis.__NS_RECORD_MODULE_PROVENANCE__; if (typeof __nsRecord === 'function') { __nsRecord(String(__nsResolvedSpec), { kind: __ns_cjs_require_kind, specifier: String(spec), url: __nsResolvedSpec !== spec ? __nsResolvedSpec : undefined, via: 'cjs-wrapper', parent: (typeof import.meta !== 'undefined' && import.meta && import.meta.url) ? import.meta.url : undefined }); } } catch (e) {}\n` +
613
+ ` var mod = __ns_cjs_require_base(__nsResolvedSpec);\n` +
614
+ ` try {\n` +
615
+ ` if (mod && (typeof mod === 'object' || typeof mod === 'function') && mod.default !== undefined) {\n` +
616
+ ` var keys = [];\n` +
617
+ ` try { keys = Object.keys(mod); } catch (e) {}\n` +
618
+ ` var defaultOnly = keys.length === 1 && keys[0] === 'default';\n` +
619
+ ` var esModuleOnly = keys.length === 2 && keys.indexOf('default') !== -1 && keys.indexOf('__esModule') !== -1;\n` +
620
+ ` if (mod.__esModule || defaultOnly || esModuleOnly) { return mod.default; }\n` +
621
+ ` }\n` +
622
+ ` } catch (e) {}\n` +
623
+ ` return mod;\n` +
624
+ `};\n`;
625
+ return `${prelude}${code}${suffix}`;
626
+ }
627
+ catch {
628
+ return code;
629
+ }
630
+ }
631
+ //# sourceMappingURL=websocket-served-module-helpers.js.map