@nativescript/vite 8.0.0-alpha.0 → 8.0.0-alpha.10

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 (222) 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 -41
  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 +7 -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 +365 -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 -31
  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/preserve-imports.js +2 -17
  68. package/helpers/preserve-imports.js.map +1 -1
  69. package/helpers/project.d.ts +35 -0
  70. package/helpers/project.js +120 -2
  71. package/helpers/project.js.map +1 -1
  72. package/helpers/ts-config-paths.js +50 -2
  73. package/helpers/ts-config-paths.js.map +1 -1
  74. package/helpers/workers.d.ts +20 -19
  75. package/helpers/workers.js +620 -3
  76. package/helpers/workers.js.map +1 -1
  77. package/hmr/client/css-handler.js +60 -19
  78. package/hmr/client/css-handler.js.map +1 -1
  79. package/hmr/client/hmr-pending-overlay.d.ts +27 -0
  80. package/hmr/client/hmr-pending-overlay.js +50 -0
  81. package/hmr/client/hmr-pending-overlay.js.map +1 -0
  82. package/hmr/client/index.js +597 -24
  83. package/hmr/client/index.js.map +1 -1
  84. package/hmr/client/utils.d.ts +5 -0
  85. package/hmr/client/utils.js +212 -21
  86. package/hmr/client/utils.js.map +1 -1
  87. package/hmr/entry-runtime.d.ts +10 -0
  88. package/hmr/entry-runtime.js +330 -42
  89. package/hmr/entry-runtime.js.map +1 -1
  90. package/hmr/frameworks/angular/client/index.d.ts +3 -1
  91. package/hmr/frameworks/angular/client/index.js +821 -25
  92. package/hmr/frameworks/angular/client/index.js.map +1 -1
  93. package/hmr/frameworks/angular/server/linker.js +37 -6
  94. package/hmr/frameworks/angular/server/linker.js.map +1 -1
  95. package/hmr/frameworks/angular/server/strategy.js +30 -6
  96. package/hmr/frameworks/angular/server/strategy.js.map +1 -1
  97. package/hmr/frameworks/typescript/server/strategy.js +8 -2
  98. package/hmr/frameworks/typescript/server/strategy.js.map +1 -1
  99. package/hmr/frameworks/vue/client/index.js +18 -42
  100. package/hmr/frameworks/vue/client/index.js.map +1 -1
  101. package/hmr/helpers/ast-normalizer.js +22 -10
  102. package/hmr/helpers/ast-normalizer.js.map +1 -1
  103. package/hmr/helpers/cjs-named-exports.d.ts +23 -0
  104. package/hmr/helpers/cjs-named-exports.js +152 -0
  105. package/hmr/helpers/cjs-named-exports.js.map +1 -0
  106. package/hmr/server/constants.d.ts +1 -0
  107. package/hmr/server/constants.js +14 -3
  108. package/hmr/server/constants.js.map +1 -1
  109. package/hmr/server/core-sanitize.d.ts +49 -2
  110. package/hmr/server/core-sanitize.js +267 -24
  111. package/hmr/server/core-sanitize.js.map +1 -1
  112. package/hmr/server/import-map.d.ts +65 -0
  113. package/hmr/server/import-map.js +222 -0
  114. package/hmr/server/import-map.js.map +1 -0
  115. package/hmr/server/index.d.ts +2 -1
  116. package/hmr/server/index.js.map +1 -1
  117. package/hmr/server/ns-core-cjs-shape.d.ts +204 -0
  118. package/hmr/server/ns-core-cjs-shape.js +271 -0
  119. package/hmr/server/ns-core-cjs-shape.js.map +1 -0
  120. package/hmr/server/perf-instrumentation.d.ts +114 -0
  121. package/hmr/server/perf-instrumentation.js +195 -0
  122. package/hmr/server/perf-instrumentation.js.map +1 -0
  123. package/hmr/server/runtime-graph-filter.d.ts +5 -0
  124. package/hmr/server/runtime-graph-filter.js +21 -0
  125. package/hmr/server/runtime-graph-filter.js.map +1 -0
  126. package/hmr/server/shared-transform-request.d.ts +12 -0
  127. package/hmr/server/shared-transform-request.js +144 -0
  128. package/hmr/server/shared-transform-request.js.map +1 -0
  129. package/hmr/server/vite-plugin.d.ts +21 -1
  130. package/hmr/server/vite-plugin.js +461 -22
  131. package/hmr/server/vite-plugin.js.map +1 -1
  132. package/hmr/server/websocket-angular-entry.d.ts +2 -0
  133. package/hmr/server/websocket-angular-entry.js +68 -0
  134. package/hmr/server/websocket-angular-entry.js.map +1 -0
  135. package/hmr/server/websocket-angular-hot-update.d.ts +78 -0
  136. package/hmr/server/websocket-angular-hot-update.js +413 -0
  137. package/hmr/server/websocket-angular-hot-update.js.map +1 -0
  138. package/hmr/server/websocket-core-bridge.d.ts +21 -0
  139. package/hmr/server/websocket-core-bridge.js +357 -0
  140. package/hmr/server/websocket-core-bridge.js.map +1 -0
  141. package/hmr/server/websocket-graph-upsert.d.ts +21 -0
  142. package/hmr/server/websocket-graph-upsert.js +33 -0
  143. package/hmr/server/websocket-graph-upsert.js.map +1 -0
  144. package/hmr/server/websocket-hmr-pending.d.ts +43 -0
  145. package/hmr/server/websocket-hmr-pending.js +55 -0
  146. package/hmr/server/websocket-hmr-pending.js.map +1 -0
  147. package/hmr/server/websocket-module-bindings.d.ts +6 -0
  148. package/hmr/server/websocket-module-bindings.js +471 -0
  149. package/hmr/server/websocket-module-bindings.js.map +1 -0
  150. package/hmr/server/websocket-module-specifiers.d.ts +101 -0
  151. package/hmr/server/websocket-module-specifiers.js +820 -0
  152. package/hmr/server/websocket-module-specifiers.js.map +1 -0
  153. package/hmr/server/websocket-ns-m-finalize.d.ts +22 -0
  154. package/hmr/server/websocket-ns-m-finalize.js +88 -0
  155. package/hmr/server/websocket-ns-m-finalize.js.map +1 -0
  156. package/hmr/server/websocket-ns-m-paths.d.ts +3 -0
  157. package/hmr/server/websocket-ns-m-paths.js +92 -0
  158. package/hmr/server/websocket-ns-m-paths.js.map +1 -0
  159. package/hmr/server/websocket-ns-m-request.d.ts +45 -0
  160. package/hmr/server/websocket-ns-m-request.js +196 -0
  161. package/hmr/server/websocket-ns-m-request.js.map +1 -0
  162. package/hmr/server/websocket-runtime-compat.d.ts +19 -0
  163. package/hmr/server/websocket-runtime-compat.js +287 -0
  164. package/hmr/server/websocket-runtime-compat.js.map +1 -0
  165. package/hmr/server/websocket-served-module-helpers.d.ts +36 -0
  166. package/hmr/server/websocket-served-module-helpers.js +631 -0
  167. package/hmr/server/websocket-served-module-helpers.js.map +1 -0
  168. package/hmr/server/websocket-txn.d.ts +6 -0
  169. package/hmr/server/websocket-txn.js +45 -0
  170. package/hmr/server/websocket-txn.js.map +1 -0
  171. package/hmr/server/websocket-vendor-unifier.d.ts +10 -0
  172. package/hmr/server/websocket-vendor-unifier.js +51 -0
  173. package/hmr/server/websocket-vendor-unifier.js.map +1 -0
  174. package/hmr/server/websocket-vue-sfc.d.ts +27 -0
  175. package/hmr/server/websocket-vue-sfc.js +1069 -0
  176. package/hmr/server/websocket-vue-sfc.js.map +1 -0
  177. package/hmr/server/websocket.d.ts +26 -3
  178. package/hmr/server/websocket.js +2233 -796
  179. package/hmr/server/websocket.js.map +1 -1
  180. package/hmr/shared/package-classifier.d.ts +9 -0
  181. package/hmr/shared/package-classifier.js +58 -0
  182. package/hmr/shared/package-classifier.js.map +1 -0
  183. package/hmr/shared/runtime/boot-timeline.d.ts +17 -0
  184. package/hmr/shared/runtime/boot-timeline.js +51 -0
  185. package/hmr/shared/runtime/boot-timeline.js.map +1 -0
  186. package/hmr/shared/runtime/browser-runtime-contract.d.ts +64 -0
  187. package/hmr/shared/runtime/browser-runtime-contract.js +54 -0
  188. package/hmr/shared/runtime/browser-runtime-contract.js.map +1 -0
  189. package/hmr/shared/runtime/dev-overlay.d.ts +85 -0
  190. package/hmr/shared/runtime/dev-overlay.js +1236 -0
  191. package/hmr/shared/runtime/dev-overlay.js.map +1 -0
  192. package/hmr/shared/runtime/http-only-boot.d.ts +1 -0
  193. package/hmr/shared/runtime/http-only-boot.js +53 -6
  194. package/hmr/shared/runtime/http-only-boot.js.map +1 -1
  195. package/hmr/shared/runtime/module-provenance.d.ts +1 -0
  196. package/hmr/shared/runtime/module-provenance.js +63 -0
  197. package/hmr/shared/runtime/module-provenance.js.map +1 -0
  198. package/hmr/shared/runtime/platform-polyfills.d.ts +26 -0
  199. package/hmr/shared/runtime/platform-polyfills.js +122 -0
  200. package/hmr/shared/runtime/platform-polyfills.js.map +1 -0
  201. package/hmr/shared/runtime/root-placeholder.d.ts +1 -0
  202. package/hmr/shared/runtime/root-placeholder.js +552 -82
  203. package/hmr/shared/runtime/root-placeholder.js.map +1 -1
  204. package/hmr/shared/runtime/session-bootstrap.d.ts +1 -0
  205. package/hmr/shared/runtime/session-bootstrap.js +195 -0
  206. package/hmr/shared/runtime/session-bootstrap.js.map +1 -0
  207. package/hmr/shared/runtime/vendor-bootstrap.js +52 -15
  208. package/hmr/shared/runtime/vendor-bootstrap.js.map +1 -1
  209. package/hmr/shared/vendor/manifest.d.ts +37 -0
  210. package/hmr/shared/vendor/manifest.js +677 -57
  211. package/hmr/shared/vendor/manifest.js.map +1 -1
  212. package/hmr/shared/vendor/registry.js +104 -7
  213. package/hmr/shared/vendor/registry.js.map +1 -1
  214. package/index.d.ts +1 -0
  215. package/index.js +5 -0
  216. package/index.js.map +1 -1
  217. package/package.json +14 -2
  218. package/runtime/core-aliases-early.js +94 -67
  219. package/runtime/core-aliases-early.js.map +1 -1
  220. package/shims/solid-jsx-runtime.d.ts +7 -0
  221. package/shims/solid-jsx-runtime.js +17 -0
  222. package/shims/solid-jsx-runtime.js.map +1 -0
@@ -1,44 +1,331 @@
1
+ import ts from 'typescript';
1
2
  import { transformNativeClassSource } from './nativeclass-transform.js';
3
+ /**
4
+ * Look for `NativeClass` either as a bare identifier or as a `NativeClass(...)` call expression
5
+ * inside a `__decorate` array element. Returns true if the element is a NativeClass marker.
6
+ */
7
+ function isNativeClassDecoratorElement(el) {
8
+ if (ts.isIdentifier(el) && el.text === 'NativeClass')
9
+ return true;
10
+ if (ts.isCallExpression(el) && ts.isIdentifier(el.expression) && el.expression.text === 'NativeClass')
11
+ return true;
12
+ return false;
13
+ }
14
+ /**
15
+ * Walk the AST and collect every `__decorate([..., NativeClass(), ...], X)` (or
16
+ * `__decorate*` variants) where the array contains a NativeClass marker.
17
+ *
18
+ * For each such call we record the target class name (so it can be downleveled
19
+ * later) and produce a textual edit that strips ONLY the `NativeClass` element.
20
+ * If `NativeClass` was the only element, the whole `__decorate(...)` call is
21
+ * replaced with its target identifier so the surrounding assignment becomes a
22
+ * harmless self-assign (`X = X`) and `NativeClass` no longer appears in the
23
+ * served output.
24
+ *
25
+ * Using AST instead of regex lets us tolerate any number of additional
26
+ * decorators in the array (e.g. `__metadata("design:paramtypes", [])`), which
27
+ * Angular's compiler always emits when a class has a constructor.
28
+ */
29
+ function collectNativeClassDecorateEdits(code, sf) {
30
+ const edits = [];
31
+ const classNames = new Set();
32
+ const visit = (node) => {
33
+ if (ts.isCallExpression(node)) {
34
+ const callee = node.expression;
35
+ const calleeName = ts.isIdentifier(callee) ? callee.text : ts.isPropertyAccessExpression(callee) && ts.isIdentifier(callee.expression) && ts.isIdentifier(callee.name) ? `${callee.expression.text}.${callee.name.text}` : undefined;
36
+ if (calleeName && /^__decorate/.test(calleeName) && node.arguments.length >= 2) {
37
+ const firstArg = node.arguments[0];
38
+ const secondArg = node.arguments[1];
39
+ if (ts.isArrayLiteralExpression(firstArg) && ts.isIdentifier(secondArg)) {
40
+ const remaining = firstArg.elements.filter((el) => !isNativeClassDecoratorElement(el));
41
+ if (remaining.length !== firstArg.elements.length) {
42
+ classNames.add(secondArg.text);
43
+ const callStart = node.getStart(sf);
44
+ const callEnd = node.getEnd();
45
+ if (remaining.length === 0) {
46
+ // Replace `__decorate([NativeClass()], X)` with `X` so the surrounding
47
+ // assignment (`X = __decorate(...)`) becomes `X = X` — a no-op the runtime
48
+ // will skip without errors.
49
+ edits.push({ start: callStart, end: callEnd, text: secondArg.text });
50
+ }
51
+ else {
52
+ const remainingText = remaining.map((el) => code.slice(el.getStart(sf), el.getEnd())).join(', ');
53
+ const followingArgs = node.arguments.slice(1);
54
+ const argsText = `[${remainingText}]` + (followingArgs.length ? ', ' + followingArgs.map((a) => code.slice(a.getStart(sf), a.getEnd())).join(', ') : '');
55
+ edits.push({ start: callStart, end: callEnd, text: `${calleeName}(${argsText})` });
56
+ }
57
+ }
58
+ }
59
+ }
60
+ }
61
+ ts.forEachChild(node, visit);
62
+ };
63
+ visit(sf);
64
+ return { edits, classNames };
65
+ }
66
+ /**
67
+ * Strip `__extends` from any tslib named import that may already exist in the
68
+ * served file. The NativeScript iOS V8 runtime registers a NATIVE-aware
69
+ * `__extends` on `globalThis` (see ClassBuilder.mm `RegisterNativeTypeScriptExtendsFunction`)
70
+ * which performs ObjC class registration when the parent is a native wrapper
71
+ * (e.g. `NSObject`). Importing `__extends` from tslib shadows that global with
72
+ * tslib's plain implementation, which never registers the class as a native
73
+ * subclass — leading to `Cannot read properties of undefined (reading '__extended')`
74
+ * when `_super.call(this)` runs. We must let `__extends` fall through to the
75
+ * runtime global, so any pre-existing tslib `__extends` named import is removed
76
+ * from this file's `tslib` import.
77
+ */
78
+ function stripExtendsImportFromTslib(code) {
79
+ if (!/\b__extends\b/.test(code))
80
+ return code;
81
+ let sf;
82
+ try {
83
+ sf = ts.createSourceFile('extends-import-check.js', code, ts.ScriptTarget.Latest, true, ts.ScriptKind.JS);
84
+ }
85
+ catch {
86
+ return code;
87
+ }
88
+ const edits = [];
89
+ for (const stmt of sf.statements) {
90
+ if (!ts.isImportDeclaration(stmt))
91
+ continue;
92
+ const spec = stmt.moduleSpecifier;
93
+ if (!ts.isStringLiteral(spec))
94
+ continue;
95
+ // Match any tslib variant ("tslib", "tslib/...", or absolute paths to tslib).
96
+ if (!/(?:^|\/)tslib(?:\/|$)|(?:^|[/\\])tslib[/\\]/.test(spec.text))
97
+ continue;
98
+ const clause = stmt.importClause;
99
+ if (!clause || !clause.namedBindings || !ts.isNamedImports(clause.namedBindings))
100
+ continue;
101
+ const named = clause.namedBindings;
102
+ const remaining = named.elements.filter((el) => (el.propertyName?.text ?? el.name.text) !== '__extends');
103
+ if (remaining.length === named.elements.length)
104
+ continue;
105
+ if (remaining.length === 0 && !clause.name) {
106
+ // The whole import would become empty — drop the entire statement.
107
+ edits.push({ start: stmt.getFullStart(), end: stmt.getEnd(), text: '' });
108
+ continue;
109
+ }
110
+ const remainingText = remaining.map((el) => code.slice(el.getStart(sf), el.getEnd())).join(', ');
111
+ edits.push({ start: named.getStart(sf), end: named.getEnd(), text: `{ ${remainingText} }` });
112
+ }
113
+ if (!edits.length)
114
+ return code;
115
+ let output = code;
116
+ for (const e of edits.sort((a, b) => b.start - a.start)) {
117
+ output = output.slice(0, e.start) + e.text + output.slice(e.end);
118
+ }
119
+ return output;
120
+ }
121
+ /**
122
+ * Post-phase cleanup for NativeClass decorators.
123
+ * Strips `NativeClass` from any `__decorate([...], X)` call (regardless of what
124
+ * other decorators / metadata appear in the array) and downlevels ES6 classes
125
+ * to ES5 so the NativeScript runtime can detect native class inheritance via
126
+ * `__extends`.
127
+ *
128
+ * The pre-phase plugin runs before Vite's TS pipeline and produces ES5 directly,
129
+ * but downstream plugins (notably the Angular plugin) re-compile from the
130
+ * original TypeScript source and overwrite the pre-phase output. This post-phase
131
+ * pass catches those survivors. It's the safety net, not the primary path.
132
+ *
133
+ * Exported separately for testability.
134
+ */
135
+ export function postCleanupNativeClass(code, bareId, verbose = false) {
136
+ if (!code)
137
+ return null;
138
+ if (!code.includes('__decorate') || !code.includes('NativeClass'))
139
+ return null;
140
+ let sf;
141
+ try {
142
+ sf = ts.createSourceFile(bareId + '.js', code, ts.ScriptTarget.Latest, true, ts.ScriptKind.JS);
143
+ }
144
+ catch {
145
+ return null;
146
+ }
147
+ const { edits: decorateEdits, classNames: classNamesToDownlevel } = collectNativeClassDecorateEdits(code, sf);
148
+ if (!classNamesToDownlevel.size)
149
+ return null;
150
+ // Apply decorator-stripping edits first so the AST we re-parse for Phase 2 is consistent.
151
+ let output = code;
152
+ for (const e of decorateEdits.sort((a, b) => b.start - a.start)) {
153
+ output = output.slice(0, e.start) + e.text + output.slice(e.end);
154
+ }
155
+ // Phase 2: Downlevel any ES6 class expression that extends a native base.
156
+ // Angular's re-compilation typically emits:
157
+ // var AppDelegate = class AppDelegate extends UIResponder { ... };
158
+ // or with _1 alias:
159
+ // var PDFViewDelegateImpl = PDFViewDelegateImpl_1 = class PDFViewDelegateImpl extends NSObject { ... };
160
+ // We rewrite each into ES5 with __extends so the NativeScript runtime can detect
161
+ // native class inheritance and register ObjC/Java classes.
162
+ let downleveledAtLeastOne = false;
163
+ for (const className of Array.from(classNamesToDownlevel)) {
164
+ try {
165
+ // Use TypeScript AST to find and extract the class expression reliably
166
+ const sf = ts.createSourceFile(bareId + '.js', output, ts.ScriptTarget.Latest, true, ts.ScriptKind.JS);
167
+ let classNode;
168
+ let baseName = '';
169
+ let varDeclStart = -1;
170
+ let varDeclEnd = -1;
171
+ let aliasName = ''; // e.g. PDFViewDelegateImpl_1
172
+ const findClass = (node) => {
173
+ if (classNode)
174
+ return;
175
+ // Match: var X = class X extends Y { ... }
176
+ // or: var X = X_1 = class X extends Y { ... }
177
+ if (ts.isVariableStatement(node)) {
178
+ for (const decl of node.declarationList.declarations) {
179
+ if (ts.isIdentifier(decl.name) && decl.name.text === className && decl.initializer) {
180
+ let classExpr = decl.initializer;
181
+ // Handle alias: X = X_1 = class X extends Y { ... }
182
+ if (ts.isBinaryExpression(classExpr) && classExpr.operatorToken.kind === ts.SyntaxKind.EqualsToken) {
183
+ if (ts.isIdentifier(classExpr.left)) {
184
+ aliasName = classExpr.left.text;
185
+ }
186
+ classExpr = classExpr.right;
187
+ }
188
+ if (ts.isClassExpression(classExpr) && classExpr.heritageClauses?.length) {
189
+ const extendsClause = classExpr.heritageClauses.find((h) => h.token === ts.SyntaxKind.ExtendsKeyword);
190
+ if (extendsClause?.types[0]) {
191
+ baseName = output.slice(extendsClause.types[0].expression.getStart(sf), extendsClause.types[0].expression.getEnd());
192
+ classNode = classExpr;
193
+ varDeclStart = node.getStart(sf);
194
+ varDeclEnd = node.getEnd();
195
+ }
196
+ }
197
+ }
198
+ }
199
+ }
200
+ ts.forEachChild(node, findClass);
201
+ };
202
+ findClass(sf);
203
+ if (!classNode || !baseName)
204
+ continue;
205
+ // Extract just the class as a declaration for ts.transpileModule
206
+ const classText = output.slice(classNode.getStart(sf), classNode.getEnd());
207
+ // Convert class expression to declaration for proper downlevel
208
+ const classAsDecl = classText.replace(/^class\b/, `class`);
209
+ const toDownlevel = `class ${className} extends ${baseName} ${classAsDecl.slice(classAsDecl.indexOf('{'))}`;
210
+ const downleveled = ts
211
+ .transpileModule(toDownlevel, {
212
+ compilerOptions: {
213
+ module: ts.ModuleKind.ESNext,
214
+ target: ts.ScriptTarget.ES5,
215
+ experimentalDecorators: true,
216
+ emitDecoratorMetadata: false,
217
+ noEmitHelpers: true,
218
+ useDefineForClassFields: false,
219
+ },
220
+ })
221
+ .outputText.replace(/enumerable:\s*false/g, 'enumerable: true')
222
+ .replace(/export \{\};?\s*$/m, '')
223
+ .trim();
224
+ // The downleveled output is a var statement: var ClassName = (function(_super) { ... })(Base);
225
+ // Build the replacement, preserving any alias assignment
226
+ let replacement = downleveled;
227
+ if (aliasName) {
228
+ // Original was: var X = X_1 = class X extends Y {...};
229
+ // Downlevel produces: var X = (function(_super){...})(Y);
230
+ // We need: var X = X_1 = (function(_super){...})(Y);
231
+ replacement = replacement.replace(`var ${className} =`, `var ${className} = ${aliasName} =`);
232
+ }
233
+ output = output.slice(0, varDeclStart) + replacement + output.slice(varDeclEnd);
234
+ downleveledAtLeastOne = true;
235
+ if (verbose) {
236
+ console.log(`[ns-nativeclass-post] Downleveled ES6 class "${className}" to ES5 with __extends in ${bareId}`);
237
+ }
238
+ }
239
+ catch (e) {
240
+ if (verbose) {
241
+ console.warn(`[ns-nativeclass-post] Failed to downlevel class "${className}" in ${bareId}:`, e);
242
+ }
243
+ // If downleveling fails, the decorator is at least stripped
244
+ }
245
+ }
246
+ // If we downleveled at least one class, the output now references __extends.
247
+ // We MUST NOT import __extends from tslib here: the NativeScript iOS V8 runtime
248
+ // installs a native-aware `__extends` on `globalThis` that handles native class
249
+ // registration when the parent is a native wrapper (e.g. NSObject). Importing
250
+ // tslib's __extends would shadow that global with a plain implementation that
251
+ // never registers the class as a native subclass, leading to
252
+ // `Cannot read properties of undefined (reading '__extended')` when
253
+ // `_super.call(this)` runs. Let the bare `__extends(...)` reference fall
254
+ // through to the runtime global.
255
+ if (downleveledAtLeastOne) {
256
+ output = stripExtendsImportFromTslib(output);
257
+ }
258
+ if (output !== code) {
259
+ if (verbose) {
260
+ console.log(`[ns-nativeclass-post] Cleaned __decorate NativeClass from ${bareId}`);
261
+ }
262
+ return { code: output, map: null };
263
+ }
264
+ return null;
265
+ }
2
266
  /**
3
267
  * Wraps NativeClass TS transformer into a Vite plugin.
4
268
  */
5
269
  export function createNativeClassTransformerPlugin() {
6
270
  const verbose = !!process.env.NS_DEBUG_NATIVECLASS;
7
- return {
8
- name: 'ns-nativeclass-transformer',
9
- enforce: 'pre',
10
- async transform(code, id) {
11
- if (!code)
12
- return null;
13
- const bareId = id.split('?')[0];
14
- const isTSFile = /\.(ts|tsx)$/.test(bareId);
15
- const isJSFile = /\.(js|mjs|cjs)$/.test(bareId);
16
- const isVueTSBlock = !isTSFile && /[?&]lang\.(ts|tsx)\b/.test(id);
17
- if (!isTSFile && !isVueTSBlock && !isJSFile)
18
- return null;
19
- // Check if this file has @NativeClass BEFORE transforming (for debug)
20
- const hasNativeClass = code.includes('@NativeClass') || code.includes('NativeClass');
21
- if (verbose && hasNativeClass) {
22
- console.log(`[ns-nativeclass] Processing file with NativeClass: ${bareId}`);
23
- }
24
- const res = transformNativeClassSource(code, bareId);
25
- // Verify the transform removed NativeClass
26
- if (verbose && hasNativeClass) {
27
- if (res) {
28
- const stillHas = /\bNativeClass\b/.test(res.code);
29
- if (stillHas) {
30
- console.warn(`[ns-nativeclass] WARNING: NativeClass still present after transform in ${bareId}`);
271
+ return [
272
+ {
273
+ name: 'ns-nativeclass-transformer',
274
+ enforce: 'pre',
275
+ async transform(code, id) {
276
+ if (!code)
277
+ return null;
278
+ const bareId = id.split('?')[0];
279
+ const isTSFile = /\.(ts|tsx)$/.test(bareId);
280
+ const isJSFile = /\.(js|mjs|cjs)$/.test(bareId);
281
+ const isVueTSBlock = !isTSFile && /[?&]lang\.(ts|tsx)\b/.test(id);
282
+ if (!isTSFile && !isVueTSBlock && !isJSFile)
283
+ return null;
284
+ const hasDecoratorSyntax = code.includes('@NativeClass');
285
+ const hasNativeClassIdentifier = code.includes('NativeClass');
286
+ const hasDecorateCall = isJSFile && code.includes('__decorate');
287
+ // Most modules never contain NativeClass decorations.
288
+ // Skip the heavier TS-based helper unless the source has one of the patterns it can actually rewrite.
289
+ if (!hasDecoratorSyntax && !hasNativeClassIdentifier && !hasDecorateCall) {
290
+ return null;
291
+ }
292
+ if (verbose && (hasDecoratorSyntax || hasNativeClassIdentifier)) {
293
+ console.log(`[ns-nativeclass] Processing file with NativeClass: ${bareId}`);
294
+ }
295
+ const res = transformNativeClassSource(code, bareId);
296
+ if (verbose && (hasDecoratorSyntax || hasNativeClassIdentifier)) {
297
+ if (res) {
298
+ const stillHas = /\bNativeClass\b/.test(res.code);
299
+ if (stillHas) {
300
+ console.warn(`[ns-nativeclass] WARNING: NativeClass still present after transform in ${bareId}`);
301
+ }
302
+ else {
303
+ console.log(`[ns-nativeclass] Successfully transformed ${bareId}`);
304
+ }
31
305
  }
32
306
  else {
33
- console.log(`[ns-nativeclass] Successfully transformed ${bareId}`);
307
+ console.log(`[ns-nativeclass] Transform returned null for ${bareId} (may be skipped due to platform filter)`);
34
308
  }
35
309
  }
36
- else {
37
- console.log(`[ns-nativeclass] Transform returned null for ${bareId} (may be skipped due to platform filter)`);
38
- }
39
- }
40
- return res; // may be null if no @NativeClass present
310
+ return res;
311
+ },
41
312
  },
42
- };
313
+ // Post-phase cleanup: the Angular plugin (normal phase) may re-compile TypeScript from its
314
+ // own compilation pipeline, re-introducing __decorate([NativeClass()], ...) after the pre-phase
315
+ // transformer already stripped @NativeClass. This post-phase pass catches those survivors.
316
+ // In addition to stripping the decorator, we must also downlevel any ES6 class that was
317
+ // decorated with NativeClass to ES5 (using __extends) so the NativeScript runtime can
318
+ // detect native class inheritance and register ObjC classes.
319
+ {
320
+ name: 'ns-nativeclass-post-cleanup',
321
+ enforce: 'post',
322
+ transform(code, id) {
323
+ const bareId = id.split('?')[0];
324
+ if (!/\.(ts|tsx|js|mjs)$/.test(bareId))
325
+ return null;
326
+ return postCleanupNativeClass(code, bareId, verbose);
327
+ },
328
+ },
329
+ ];
43
330
  }
44
331
  //# sourceMappingURL=nativeclass-transformer-plugin.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"nativeclass-transformer-plugin.js","sourceRoot":"","sources":["../../../../packages/vite/helpers/nativeclass-transformer-plugin.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,0BAA0B,EAAE,MAAM,4BAA4B,CAAC;AAExE;;GAEG;AACH,MAAM,UAAU,kCAAkC;IACjD,MAAM,OAAO,GAAG,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,oBAAoB,CAAC;IAEnD,OAAO;QACN,IAAI,EAAE,4BAA4B;QAClC,OAAO,EAAE,KAAK;QACd,KAAK,CAAC,SA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A0C,CAAC,CAAC;gBAC/G,CAAC;YACF,CAAC;YAED,OAAO,GAAG,CAAC,CAAC,yCAAyC;QACtD,CAAC;KACD,CAAC;AACH,CAAC"}
1
+ {"version":3,"file":"nativeclass-transformer-plugin.js","sourceRoot":"","sources":["../../../../packages/vite/helpers/nativeclass-transformer-plugin.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,YAAY,CAAC;AAC5B,OAAO,EAAE,0BAA0B,EAAE,MAAM,4BAA4B,CAAC;AAExE;;;GAGG;AACH,SAAS,6BAA6B,CAAC,EAAiB;IACvD,IAAI,EAAE,CAAC,YAAY,CAAC,EAAE,CAAC,IAAI,EAAE,CAAC,IAAI,KAAK,aAAa;QAAE,OAAO,IAAI,CAAC;IAClE,IAAI,EAAE,CAAC,gBAAgB,CAAC,EAAE,CAAC,IAAI,EAAE,CAAC,YAAY,CAAC,EAAE,CAAC,UAAU,CAAC,IAAI,EAAE,CAAC,UAAU,CAAC,IAAI,KAAK,aAAa;QAAE,OAAO,IAAI,CAAC;IACnH,OAAO,KAAK,CAAC;AACd,CAAC;AAED;;;;;;;;;;;;;;GAcG;AACH,SAAS,+BAA+B,CAAC,IAAY,EAAE,EAAiB;IACvE,MAAM,KAAK,GAAwD,EAAE,CAAC;IACtE,MAAM,UAAU,GAAG,IAAI,GAAG,EAAU,CAAC;IAErC,MAAM,KAAK,GAAG,CAAC,IAAa,EAAQ,EAAE;QACrC,IAAI,EAAE,CAAC,gBAAgB,CAAC,IAAI,CAAC,EAAE,CAAC;YAC/B,MAAM,MAAM,GAAG,IAAI,CAAC,UAAU,CAAC;YAC/B,MAAM,UAAU,GAAG,EAAE,CAAC,YAAY,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,0BAA0B,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC,YAAY,CAAC,MAAM,CAAC,UAAU,CAAC,IAAI,EAAE,CAAC,YAAY,CAAC,M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AsB,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;YACtD,CAAC;SACD;KACD,CAAC;AACH,CAAC"}
@@ -0,0 +1,83 @@
1
+ /**
2
+ * Single canonical URL generator for `@nativescript/core` under HMR.
3
+ *
4
+ * Every public-facing reference to `@nativescript/core[/sub]` resolves to
5
+ * exactly one URL string — byte-for-byte identical across every emitter
6
+ * (bundle entry, external-urls plugin, rewriter, import map, runtime
7
+ * require). There is no ambiguity about `?p=` vs path, `.js` vs
8
+ * extensionless, versioned vs unversioned.
9
+ *
10
+ * This module is the ONE site that constructs those URLs. Every caller in
11
+ * the repo should use `buildCoreUrl()` (or `buildCoreUrlPath()` when origin
12
+ * is not known yet). A single violation of canonical form produces a
13
+ * distinct iOS HTTP ESM cache entry for the same file — re-evaluating the
14
+ * module body, re-running `CssAnimationProperty.register(...)` side
15
+ * effects, and crashing with `Cannot redefine property`.
16
+ */
17
+ /**
18
+ * Normalize a user-provided subpath into the canonical form used by the
19
+ * /ns/core bridge. Strips:
20
+ * - Query and hash (`?v=…`, `#…`)
21
+ * - Leading / trailing slashes
22
+ * - Trailing `.js`/`.mjs`/`.cjs` extension (platform-suffixed forms are
23
+ * preserved: `.ios.js` → `.ios`)
24
+ * - Trailing `/index` segment (package-main sibling: `globals/index` →
25
+ * `globals`; `ui/core/view/index` → `ui/core/view`)
26
+ * - Canonical index forms (`index`, `index.js`, empty) → empty string
27
+ *
28
+ * Returns empty string for the main module (`@nativescript/core` itself).
29
+ */
30
+ export declare function normalizeCoreSub(sub?: string | null): string;
31
+ /**
32
+ * Canonical PATH (no origin) for a core module.
33
+ * Used by middleware/redirects where we don't have the dev-server origin.
34
+ *
35
+ * '' → '/ns/core'
36
+ * 'application' → '/ns/core/application'
37
+ * 'ui/core/view' → '/ns/core/ui/core/view'
38
+ * 'globals/index' → '/ns/core/globals'
39
+ */
40
+ export declare function buildCoreUrlPath(sub?: string | null): string;
41
+ /**
42
+ * Canonical FULL URL for a core module.
43
+ *
44
+ * origin='http://localhost:5173', sub='application'
45
+ * → 'http://localhost:5173/ns/core/application'
46
+ *
47
+ * Throws if origin is empty — callers that may not have origin should use
48
+ * `buildCoreUrlPath()` instead.
49
+ */
50
+ export declare function buildCoreUrl(origin: string, sub?: string | null): string;
51
+ /**
52
+ * Detect whether a URL or path references the /ns/core bridge.
53
+ * Accepts both relative `/ns/core/...` and absolute `http(s)://.../ns/core/...`.
54
+ */
55
+ export declare function isCoreBridgeUrl(input: string): boolean;
56
+ /**
57
+ * Extract the canonical sub path from a /ns/core URL.
58
+ * 'http://localhost:5173/ns/core' → ''
59
+ * 'http://localhost:5173/ns/core/application' → 'application'
60
+ * '/ns/core/ui/core/view' → 'ui/core/view'
61
+ * '/ns/core?p=foo' → 'foo' (legacy form tolerated)
62
+ * 'http://example.com/other' → null
63
+ */
64
+ export declare function extractCoreSub(input: string): string | null;
65
+ /**
66
+ * Convert a bare `@nativescript/core[/sub]` specifier or an absolute path
67
+ * pointing into `@nativescript/core`'s node_modules install into the
68
+ * canonical sub path. Returns null for anything else.
69
+ *
70
+ * '@nativescript/core' → ''
71
+ * '@nativescript/core/application' → 'application'
72
+ * '/node_modules/@nativescript/core/ui/core/view.js' → 'ui/core/view'
73
+ * '/foo/bar/baz' → null
74
+ */
75
+ export declare function specToCoreSub(spec: string): string | null;
76
+ /**
77
+ * Produce the set of "runtime module id" strings we expose in
78
+ * `globalThis.__NS_CORE_MODULES__` for a given sub. Callers of the vendor
79
+ * CJS shim may request any of these forms for the same module; we register
80
+ * all of them to the one namespace so lookups are never ambiguous.
81
+ */
82
+ export declare function moduleRegistrationKeys(sub?: string | null): string[];
83
+ export declare const CORE_SCOPE = "@nativescript/core";
@@ -0,0 +1,167 @@
1
+ /**
2
+ * Single canonical URL generator for `@nativescript/core` under HMR.
3
+ *
4
+ * Every public-facing reference to `@nativescript/core[/sub]` resolves to
5
+ * exactly one URL string — byte-for-byte identical across every emitter
6
+ * (bundle entry, external-urls plugin, rewriter, import map, runtime
7
+ * require). There is no ambiguity about `?p=` vs path, `.js` vs
8
+ * extensionless, versioned vs unversioned.
9
+ *
10
+ * This module is the ONE site that constructs those URLs. Every caller in
11
+ * the repo should use `buildCoreUrl()` (or `buildCoreUrlPath()` when origin
12
+ * is not known yet). A single violation of canonical form produces a
13
+ * distinct iOS HTTP ESM cache entry for the same file — re-evaluating the
14
+ * module body, re-running `CssAnimationProperty.register(...)` side
15
+ * effects, and crashing with `Cannot redefine property`.
16
+ */
17
+ const CORE_SCOPE_PREFIX = '@nativescript/core';
18
+ /**
19
+ * Normalize a user-provided subpath into the canonical form used by the
20
+ * /ns/core bridge. Strips:
21
+ * - Query and hash (`?v=…`, `#…`)
22
+ * - Leading / trailing slashes
23
+ * - Trailing `.js`/`.mjs`/`.cjs` extension (platform-suffixed forms are
24
+ * preserved: `.ios.js` → `.ios`)
25
+ * - Trailing `/index` segment (package-main sibling: `globals/index` →
26
+ * `globals`; `ui/core/view/index` → `ui/core/view`)
27
+ * - Canonical index forms (`index`, `index.js`, empty) → empty string
28
+ *
29
+ * Returns empty string for the main module (`@nativescript/core` itself).
30
+ */
31
+ export function normalizeCoreSub(sub) {
32
+ if (!sub)
33
+ return '';
34
+ let s = String(sub).split('?')[0].split('#')[0].trim();
35
+ s = s.replace(/^\/+/, '').replace(/\/+$/, '');
36
+ s = s.replace(/\.(?:mjs|cjs|js)$/, '');
37
+ // Strip trailing `/index` so that `globals/index` → `globals`, matching
38
+ // the bare import form that consumers spell as `@nativescript/core/globals`.
39
+ // The main module case (`index` alone) is handled below.
40
+ if (s.endsWith('/index')) {
41
+ s = s.slice(0, -'/index'.length);
42
+ }
43
+ if (!s || s === 'index')
44
+ return '';
45
+ return s;
46
+ }
47
+ /**
48
+ * Canonical PATH (no origin) for a core module.
49
+ * Used by middleware/redirects where we don't have the dev-server origin.
50
+ *
51
+ * '' → '/ns/core'
52
+ * 'application' → '/ns/core/application'
53
+ * 'ui/core/view' → '/ns/core/ui/core/view'
54
+ * 'globals/index' → '/ns/core/globals'
55
+ */
56
+ export function buildCoreUrlPath(sub) {
57
+ const s = normalizeCoreSub(sub);
58
+ return s ? `/ns/core/${s}` : '/ns/core';
59
+ }
60
+ /**
61
+ * Canonical FULL URL for a core module.
62
+ *
63
+ * origin='http://localhost:5173', sub='application'
64
+ * → 'http://localhost:5173/ns/core/application'
65
+ *
66
+ * Throws if origin is empty — callers that may not have origin should use
67
+ * `buildCoreUrlPath()` instead.
68
+ */
69
+ export function buildCoreUrl(origin, sub) {
70
+ if (!origin) {
71
+ throw new Error('[ns-core-url] buildCoreUrl requires a non-empty origin. Use buildCoreUrlPath() when origin is not yet known.');
72
+ }
73
+ const trimmedOrigin = origin.replace(/\/+$/, '');
74
+ return `${trimmedOrigin}${buildCoreUrlPath(sub)}`;
75
+ }
76
+ /**
77
+ * Detect whether a URL or path references the /ns/core bridge.
78
+ * Accepts both relative `/ns/core/...` and absolute `http(s)://.../ns/core/...`.
79
+ */
80
+ export function isCoreBridgeUrl(input) {
81
+ if (!input)
82
+ return false;
83
+ return /\/ns\/core(?:\/|$|\?)/.test(input);
84
+ }
85
+ /**
86
+ * Extract the canonical sub path from a /ns/core URL.
87
+ * 'http://localhost:5173/ns/core' → ''
88
+ * 'http://localhost:5173/ns/core/application' → 'application'
89
+ * '/ns/core/ui/core/view' → 'ui/core/view'
90
+ * '/ns/core?p=foo' → 'foo' (legacy form tolerated)
91
+ * 'http://example.com/other' → null
92
+ */
93
+ export function extractCoreSub(input) {
94
+ if (!isCoreBridgeUrl(input))
95
+ return null;
96
+ try {
97
+ const u = new URL(input, 'http://placeholder.invalid');
98
+ const pathname = u.pathname;
99
+ const pRaw = u.searchParams.get('p');
100
+ if (pRaw)
101
+ return normalizeCoreSub(pRaw);
102
+ const afterCore = pathname.replace(/^.*\/ns\/core(?:\/|$)/, '');
103
+ return normalizeCoreSub(afterCore);
104
+ }
105
+ catch {
106
+ // Fall back to literal parsing if URL constructor fails
107
+ const m = input.match(/\/ns\/core(?:\/([^?#]*))?/);
108
+ if (!m)
109
+ return null;
110
+ return normalizeCoreSub(m[1] || '');
111
+ }
112
+ }
113
+ /**
114
+ * Convert a bare `@nativescript/core[/sub]` specifier or an absolute path
115
+ * pointing into `@nativescript/core`'s node_modules install into the
116
+ * canonical sub path. Returns null for anything else.
117
+ *
118
+ * '@nativescript/core' → ''
119
+ * '@nativescript/core/application' → 'application'
120
+ * '/node_modules/@nativescript/core/ui/core/view.js' → 'ui/core/view'
121
+ * '/foo/bar/baz' → null
122
+ */
123
+ export function specToCoreSub(spec) {
124
+ if (!spec)
125
+ return null;
126
+ const cleaned = spec.split('?')[0].split('#')[0];
127
+ if (cleaned === CORE_SCOPE_PREFIX)
128
+ return '';
129
+ if (cleaned.startsWith(CORE_SCOPE_PREFIX + '/')) {
130
+ return normalizeCoreSub(cleaned.slice(CORE_SCOPE_PREFIX.length + 1));
131
+ }
132
+ const abs = cleaned.replace(/\\/g, '/').match(/\/node_modules\/@nativescript\/core\/(.+?)$/);
133
+ if (abs)
134
+ return normalizeCoreSub(abs[1]);
135
+ // Case: the path ENDS at the core root (no subpath).
136
+ if (/\/node_modules\/@nativescript\/core\/?$/.test(cleaned.replace(/\\/g, '/'))) {
137
+ return '';
138
+ }
139
+ return null;
140
+ }
141
+ /**
142
+ * Produce the set of "runtime module id" strings we expose in
143
+ * `globalThis.__NS_CORE_MODULES__` for a given sub. Callers of the vendor
144
+ * CJS shim may request any of these forms for the same module; we register
145
+ * all of them to the one namespace so lookups are never ambiguous.
146
+ */
147
+ export function moduleRegistrationKeys(sub) {
148
+ const s = normalizeCoreSub(sub);
149
+ const keys = new Set();
150
+ if (!s) {
151
+ keys.add(CORE_SCOPE_PREFIX);
152
+ keys.add('');
153
+ }
154
+ else {
155
+ keys.add(`${CORE_SCOPE_PREFIX}/${s}`);
156
+ keys.add(s);
157
+ // Tolerate `.js` tail on the key (some consumers spell it out).
158
+ keys.add(`${CORE_SCOPE_PREFIX}/${s}.js`);
159
+ keys.add(`${s}.js`);
160
+ // Tolerate `/index` / `/index.js` suffix.
161
+ keys.add(`${CORE_SCOPE_PREFIX}/${s}/index`);
162
+ keys.add(`${CORE_SCOPE_PREFIX}/${s}/index.js`);
163
+ }
164
+ return Array.from(keys);
165
+ }
166
+ export const CORE_SCOPE = CORE_SCOPE_PREFIX;
167
+ //# sourceMappingURL=ns-core-url.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ns-core-url.js","sourceRoot":"","sources":["../../../../packages/vite/helpers/ns-core-url.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,MAAM,iBAAiB,GAAG,oBAAoB,CAAC;AAE/C;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,gBAAgB,CAAC,GAAmB;IACnD,IAAI,CAAC,GAAG;QAAE,OAAO,EAAE,CAAC;IACpB,IAAI,CAAC,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;IACvD,CAAC,GAAG,CAAC,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;IAC9C,CAAC,GAAG,CAAC,CAAC,OAAO,CAAC,mBAAmB,EAAE,EAAE,CAAC,CAAC;IACvC,wEAAwE;IACxE,6EAA6E;IAC7E,yDAAyD;IACzD,IAAI,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC,EAAE,CAAC;QAC1B,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;IAClC,CAAC;IACD,IAAI,CAAC,CAAC,IAAI,CAAC,KAAK,OAAO;QAAE,OAAO,EAAE,CAAC;IACnC,OAAO,CAAC,CAAC;AACV,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,gBAAgB,CAA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