@nativescript/vite 8.0.0-alpha.16 → 8.0.0-alpha.17

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.
@@ -0,0 +1,396 @@
1
+ // Static export-surface enumerator for the single-realm HTTP-ESM bridge.
2
+ //
3
+ // The HMR runtime serves canonical bridge specifiers (e.g. `/ns/rt` for
4
+ // `nativescript-vue`) that fan out to the device's vendor registry so that
5
+ // app code, plugins, and the vendor bundle itself share one module record
6
+ // per package. The bridge module must therefore re-export every public
7
+ // symbol the underlying package offers — otherwise consumers fall back to
8
+ // `undefined` for any export the bridge author forgot to enumerate, and the
9
+ // failure only surfaces at the call site (often deep inside a UI event
10
+ // handler) as `TypeError: <name> is not a function`.
11
+ //
12
+ // Hand-curated re-export lists are the source of that bug class. This
13
+ // helper replaces them with a deterministic walk of the package's static
14
+ // ESM export graph:
15
+ //
16
+ // 1. Resolve the package's `main` entry from the project's `node_modules`.
17
+ // 2. Parse with Babel and collect every named export — both inline
18
+ // (`export const x = …`, `export function y() {}`, `export { z }`) and
19
+ // re-exported (`export { a, b as c } from './foo'`).
20
+ // 3. Recurse into `export * from <spec>`, following both relative paths
21
+ // and bare package specifiers (so `export * from '@vue/runtime-core'`
22
+ // contributes the full Vue runtime API too).
23
+ // 4. Cache the result by `${projectRoot}::${packageId}` — the walk
24
+ // touches dozens of files for `nativescript-vue` and we want one walk
25
+ // per dev session, not per request.
26
+ //
27
+ // The walker is intentionally permissive: parse errors and unresolvable
28
+ // specifiers are swallowed (continue with what we have). The caller decides
29
+ // what to do if the surface comes back empty (typically: fall back to a
30
+ // known-good baseline list rather than emit a stub bridge).
31
+ import { parse as babelParse } from '@babel/parser';
32
+ import { readFileSync, existsSync, realpathSync } from 'fs';
33
+ import path from 'path';
34
+ import { createRequire } from 'node:module';
35
+ const cache = new Map();
36
+ /**
37
+ * Clear the cache. Tests use this to assert determinism; production code
38
+ * never needs it (the cache is intentionally process-lifetime).
39
+ */
40
+ export function __clearPackageExportsCache() {
41
+ cache.clear();
42
+ }
43
+ export function enumeratePackageExports(packageId, projectRoot) {
44
+ const root = path.resolve(projectRoot || process.cwd());
45
+ const cacheKey = `${root}::${packageId}`;
46
+ const cached = cache.get(cacheKey);
47
+ if (cached)
48
+ return cached;
49
+ const result = {
50
+ names: new Set(),
51
+ hasDefault: false,
52
+ entry: '',
53
+ visitedFiles: [],
54
+ };
55
+ const rootRequire = createRequireFromDir(root);
56
+ const entry = resolvePackageEsmEntry(packageId, rootRequire);
57
+ if (!entry) {
58
+ cache.set(cacheKey, result);
59
+ return result;
60
+ }
61
+ result.entry = entry;
62
+ const visited = new Set();
63
+ const queue = [entry];
64
+ while (queue.length) {
65
+ const file = queue.shift();
66
+ const real = safeRealpath(file);
67
+ if (visited.has(real))
68
+ continue;
69
+ visited.add(real);
70
+ result.visitedFiles.push(real);
71
+ const source = readFileSafe(real);
72
+ if (source === null)
73
+ continue;
74
+ const program = parseModule(source);
75
+ if (!program)
76
+ continue;
77
+ const dir = path.dirname(real);
78
+ const localRequire = createRequireFromFile(real);
79
+ for (const node of program.body) {
80
+ collectExportsFromNode(node, result, (spec) => {
81
+ const next = resolveSpec(spec, dir, localRequire);
82
+ if (next)
83
+ queue.push(next);
84
+ });
85
+ }
86
+ }
87
+ cache.set(cacheKey, result);
88
+ return result;
89
+ }
90
+ function collectExportsFromNode(node, out, queueReExportSource) {
91
+ if (node.type === 'ExportNamedDeclaration') {
92
+ // `export const x = …`, `export function y() {}`, `export class Z {}`
93
+ const decl = node.declaration;
94
+ if (decl) {
95
+ if (decl.declarations) {
96
+ for (const d of decl.declarations) {
97
+ addId(out.names, d?.id);
98
+ }
99
+ }
100
+ else if (decl.id?.name) {
101
+ out.names.add(decl.id.name);
102
+ }
103
+ }
104
+ // `export { a, b as c }` and `export { a } from './foo'`
105
+ for (const spec of (node.specifiers || [])) {
106
+ const exportedName = spec?.exported?.name ?? spec?.exported?.value;
107
+ if (exportedName === 'default') {
108
+ out.hasDefault = true;
109
+ }
110
+ else if (exportedName) {
111
+ out.names.add(String(exportedName));
112
+ }
113
+ }
114
+ // `export … from <source>` — we already captured the explicit names above,
115
+ // but we still need to recurse if there's a `*` re-export hiding inside
116
+ // (Babel models that as `ExportAllDeclaration`, handled below). Nothing to do here.
117
+ }
118
+ else if (node.type === 'ExportAllDeclaration') {
119
+ // `export * from <source>` — recurse.
120
+ // `export * as ns from <source>` adds a named binding `ns` instead of fanning out.
121
+ const src = node.source?.value;
122
+ const asName = node.exported?.name;
123
+ if (asName) {
124
+ if (asName !== 'default')
125
+ out.names.add(String(asName));
126
+ }
127
+ else if (src) {
128
+ queueReExportSource(src);
129
+ }
130
+ }
131
+ else if (node.type === 'ExportDefaultDeclaration') {
132
+ out.hasDefault = true;
133
+ }
134
+ }
135
+ function addId(names, idNode) {
136
+ if (!idNode)
137
+ return;
138
+ if (idNode.type === 'Identifier' && idNode.name) {
139
+ names.add(idNode.name);
140
+ return;
141
+ }
142
+ if (idNode.type === 'ObjectPattern') {
143
+ for (const prop of idNode.properties || []) {
144
+ if (prop.type === 'ObjectProperty')
145
+ addId(names, prop.value);
146
+ else if (prop.type === 'RestElement')
147
+ addId(names, prop.argument);
148
+ }
149
+ return;
150
+ }
151
+ if (idNode.type === 'ArrayPattern') {
152
+ for (const el of idNode.elements || [])
153
+ addId(names, el);
154
+ return;
155
+ }
156
+ if (idNode.type === 'AssignmentPattern') {
157
+ addId(names, idNode.left);
158
+ }
159
+ }
160
+ function parseModule(source) {
161
+ try {
162
+ const ast = babelParse(source, {
163
+ sourceType: 'module',
164
+ plugins: ['typescript', 'jsx', 'importMeta', 'topLevelAwait', 'decorators-legacy', 'classProperties', 'classPrivateProperties', 'classPrivateMethods'],
165
+ errorRecovery: true,
166
+ allowReturnOutsideFunction: true,
167
+ allowUndeclaredExports: true,
168
+ });
169
+ return ast.program;
170
+ }
171
+ catch {
172
+ return null;
173
+ }
174
+ }
175
+ function resolveSpec(spec, dir, localRequire) {
176
+ if (!spec)
177
+ return null;
178
+ if (spec.startsWith('.')) {
179
+ return resolveRelative(dir, spec);
180
+ }
181
+ if (spec.startsWith('/')) {
182
+ return existsSync(spec) ? spec : null;
183
+ }
184
+ // Bare specifier (e.g. `@vue/runtime-core` from inside `nativescript-vue`).
185
+ // `createRequire.resolve()` is CJS-first and follows the package's `main`
186
+ // field, which for dual-format packages like `@vue/runtime-core` points at
187
+ // a CommonJS shim (`module.exports = require('./dist/…cjs.js')`) — parsing
188
+ // that as ESM yields zero exports and we silently drop the entire
189
+ // re-export chain. Use the ESM-aware resolver instead so we land on the
190
+ // actual `dist/…esm-bundler.js` advertised by `exports[".module"]` /
191
+ // `module`, where `export { ref, computed, … }` lives.
192
+ if (localRequire) {
193
+ return resolvePackageEsmEntry(spec, localRequire);
194
+ }
195
+ return null;
196
+ }
197
+ /**
198
+ * Resolve a bare specifier to its ESM entry file by consulting the package's
199
+ * own `package.json` ESM hints — in priority order:
200
+ *
201
+ * 1. `exports[<sub>].module` (Vue, modern dual-format packages)
202
+ * 2. `exports[<sub>].import`
203
+ * 3. `exports[<sub>]` shorthand (string form)
204
+ * 4. top-level `module` field (older dual-format convention)
205
+ * 5. top-level `main` (last resort; may be CJS — we'll parse what we get)
206
+ *
207
+ * `<sub>` is either `"."` (root entry) or `"./relative/subpath"`. Anything not
208
+ * declared in `exports` falls back to plain CJS resolution.
209
+ *
210
+ * Returns the absolute file path, or `null` if the package can't be located.
211
+ */
212
+ function resolvePackageEsmEntry(spec, localRequire) {
213
+ const { packageName, subpath } = splitBareSpec(spec);
214
+ if (!packageName)
215
+ return null;
216
+ // Locate the package's `package.json` from the calling file's vantage point.
217
+ // Node ≥ 18.6 has `require.resolve('<pkg>/package.json')` working for almost
218
+ // every layout (including pnpm hoisted/nested), provided the package
219
+ // declares `package.json` reachable (it is, by default). If the package
220
+ // opts out of exposing it via `exports`, fall back to walking up from any
221
+ // resolvable entry.
222
+ let pkgJsonPath = safeResolve(localRequire, `${packageName}/package.json`);
223
+ if (!pkgJsonPath) {
224
+ const someEntry = safeResolve(localRequire, spec);
225
+ if (someEntry)
226
+ pkgJsonPath = findPackageJsonUpward(someEntry, packageName);
227
+ }
228
+ if (!pkgJsonPath)
229
+ return null;
230
+ const pkgDir = path.dirname(pkgJsonPath);
231
+ const pkg = readJsonSafe(pkgJsonPath);
232
+ if (!pkg)
233
+ return null;
234
+ const subKey = subpath ? `./${subpath}` : '.';
235
+ const esmRelative = pickEsmEntryFromManifest(pkg, subKey);
236
+ if (esmRelative) {
237
+ const resolved = resolveRelativeInsidePackage(pkgDir, esmRelative);
238
+ if (resolved)
239
+ return resolved;
240
+ }
241
+ // Last-resort fallback: ordinary CJS resolution. Parsing may yield zero
242
+ // exports (the file is genuinely CJS) — that's acceptable; the caller
243
+ // treats an empty contribution as "this package adds nothing" rather than
244
+ // erroring out.
245
+ return safeResolve(localRequire, spec);
246
+ }
247
+ function splitBareSpec(spec) {
248
+ if (spec.startsWith('@')) {
249
+ const parts = spec.split('/');
250
+ if (parts.length < 2)
251
+ return { packageName: '', subpath: '' };
252
+ return { packageName: `${parts[0]}/${parts[1]}`, subpath: parts.slice(2).join('/') };
253
+ }
254
+ const slash = spec.indexOf('/');
255
+ if (slash === -1)
256
+ return { packageName: spec, subpath: '' };
257
+ return { packageName: spec.slice(0, slash), subpath: spec.slice(slash + 1) };
258
+ }
259
+ function readJsonSafe(file) {
260
+ try {
261
+ return JSON.parse(readFileSync(file, 'utf-8'));
262
+ }
263
+ catch {
264
+ return null;
265
+ }
266
+ }
267
+ function pickEsmEntryFromManifest(pkg, subKey) {
268
+ const exportsField = pkg?.exports;
269
+ if (exportsField && typeof exportsField === 'object') {
270
+ const entry = exportsField[subKey];
271
+ const fromConditional = pickEsmFromConditionalExports(entry);
272
+ if (fromConditional)
273
+ return fromConditional;
274
+ }
275
+ // `exports` as a bare string only applies to the `.` subpath.
276
+ if (typeof exportsField === 'string' && subKey === '.')
277
+ return exportsField;
278
+ if (subKey === '.') {
279
+ if (typeof pkg?.module === 'string')
280
+ return pkg.module;
281
+ if (typeof pkg?.main === 'string')
282
+ return pkg.main;
283
+ // CommonJS-only packages frequently omit `main`; Node defaults to `index.js`.
284
+ return 'index.js';
285
+ }
286
+ // Subpath without an `exports` mapping: caller falls through to CJS resolution.
287
+ return null;
288
+ }
289
+ function pickEsmFromConditionalExports(entry) {
290
+ if (!entry)
291
+ return null;
292
+ if (typeof entry === 'string')
293
+ return entry;
294
+ if (typeof entry !== 'object')
295
+ return null;
296
+ // Prefer `module` (the de-facto "ESM bundler" condition that Vue, lit,
297
+ // preact etc. ship), then `import`, then `default`. Skip `node`/`require`
298
+ // because those usually point at the CJS shim we're explicitly avoiding.
299
+ for (const key of ['module', 'import', 'default']) {
300
+ const value = entry[key];
301
+ if (typeof value === 'string')
302
+ return value;
303
+ if (value && typeof value === 'object') {
304
+ const nested = pickEsmFromConditionalExports(value);
305
+ if (nested)
306
+ return nested;
307
+ }
308
+ }
309
+ return null;
310
+ }
311
+ function resolveRelativeInsidePackage(pkgDir, rel) {
312
+ const trimmed = rel.replace(/^\.\//, '');
313
+ const candidates = [trimmed, `${trimmed}.js`, `${trimmed}.mjs`, `${trimmed}.cjs`, `${trimmed}/index.js`, `${trimmed}/index.mjs`];
314
+ for (const c of candidates) {
315
+ const p = path.join(pkgDir, c);
316
+ if (existsSync(p))
317
+ return safeRealpath(p);
318
+ }
319
+ return null;
320
+ }
321
+ function findPackageJsonUpward(startFile, expectedName) {
322
+ let dir = path.dirname(startFile);
323
+ const root = path.parse(dir).root;
324
+ while (dir && dir !== root) {
325
+ const candidate = path.join(dir, 'package.json');
326
+ if (existsSync(candidate)) {
327
+ const pkg = readJsonSafe(candidate);
328
+ if (pkg?.name === expectedName)
329
+ return candidate;
330
+ }
331
+ const next = path.dirname(dir);
332
+ if (next === dir)
333
+ break;
334
+ dir = next;
335
+ }
336
+ return null;
337
+ }
338
+ function resolveRelative(dir, spec) {
339
+ const base = path.resolve(dir, spec);
340
+ const candidates = ['', '.js', '.mjs', '.cjs', '/index.js', '/index.mjs', '/index.cjs'];
341
+ for (const ext of candidates) {
342
+ const p = base + ext;
343
+ try {
344
+ if (existsSync(p)) {
345
+ const real = safeRealpath(p);
346
+ // Skip directories returned by `existsSync` without an index file fallback.
347
+ try {
348
+ const stat = readFileSafe(real);
349
+ if (stat !== null)
350
+ return real;
351
+ }
352
+ catch { }
353
+ }
354
+ }
355
+ catch { }
356
+ }
357
+ return null;
358
+ }
359
+ function safeResolve(req, spec) {
360
+ try {
361
+ return req.resolve(spec);
362
+ }
363
+ catch {
364
+ return null;
365
+ }
366
+ }
367
+ function createRequireFromDir(dir) {
368
+ // `createRequire` wants a file path; we pass a synthetic file under the
369
+ // dir so resolution starts there.
370
+ return createRequire(path.join(dir, 'package.json'));
371
+ }
372
+ function createRequireFromFile(file) {
373
+ try {
374
+ return createRequire(file);
375
+ }
376
+ catch {
377
+ return null;
378
+ }
379
+ }
380
+ function safeRealpath(file) {
381
+ try {
382
+ return realpathSync(file);
383
+ }
384
+ catch {
385
+ return file;
386
+ }
387
+ }
388
+ function readFileSafe(file) {
389
+ try {
390
+ return readFileSync(file, 'utf-8');
391
+ }
392
+ catch {
393
+ return null;
394
+ }
395
+ }
396
+ //# sourceMappingURL=package-exports.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"package-exports.js","sourceRoot":"","sources":["../../../../../packages/vite/hmr/helpers/package-exports.ts"],"names":[],"mappings":"AAAA,yEAAyE;AACzE,EAAE;AACF,wEAAwE;AACxE,2EAA2E;AAC3E,0EAA0E;AAC1E,uEAAuE;AACvE,0EAA0E;AAC1E,4EAA4E;AAC5E,uEAAuE;AACvE,qDAAqD;AACrD,EAAE;AACF,sEAAsE;AACtE,yEAAyE;AACzE,oBAAoB;AACpB,EAAE;AACF,6EAA6E;AAC7E,qEAAqE;AACrE,4EAA4E;AAC5E,0DAA0D;AAC1D,0EAA0E;AAC1E,2EAA2E;AAC3E,kDAAkD;AAClD,qEAAqE;AACrE,2EAA2E;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,CAAC;QACR,OAAO,IAAI,CAAC;IACb,CAAC;AACF,CAAC;AAED,SAAS,YAAY,CAAC,IAAY;IACjC,IAAI,CAAC;QACJ,OAAO,YAAY,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;IACpC,CAAC;IAAC,MAAM,CAAC;QACR,OAAO,IAAI,CAAC;IACb,CAAC;AACF,CAAC"}
@@ -0,0 +1,51 @@
1
+ export interface NsRtBridgeOptions {
2
+ /** Version segment from `/ns/rt/<ver>`. Retained for the URL dispatcher; the bridge body intentionally ignores it. */
3
+ rtVer: string;
4
+ /** Prologue installed verbatim before the bridge body (typically the require URL guard). */
5
+ requireGuardSnippet: string;
6
+ /**
7
+ * The discovered ESM export names of the underlying vendor package
8
+ * (`nativescript-vue`, including its `@vue/runtime-core` re-export
9
+ * chain). Each name becomes `export const <name> = (__ensure().<name>);` —
10
+ * a single canonical specifier (`/ns/rt`) forwards *every* symbol the
11
+ * vendor publishes.
12
+ *
13
+ * Required: discovery is the only source of truth. There is no hand-curated
14
+ * fallback — if discovery cannot see the package, the bridge serves no
15
+ * passthroughs and the call site is expected to surface that as a config
16
+ * error rather than silently degrade.
17
+ */
18
+ vendorExports: Iterable<string>;
19
+ }
20
+ /**
21
+ * Build the `/ns/rt` runtime bridge module text.
22
+ *
23
+ * Single-realm policy: every named export the vendor package publishes
24
+ * appears as `export const X = (__ensure().X);` — a constant binding, not a
25
+ * function wrapper. Constant bindings preserve identity for Vue's Symbol
26
+ * markers (`Fragment`, `Teleport`, …) AND work transparently for functions
27
+ * (`ref`, `createApp`, …) since the user code calls the underlying value
28
+ * directly. Calling `__ensure()` at module evaluation time is safe because
29
+ * the vendor bundle is registered earlier in the boot graph (vendor.mjs →
30
+ * `__nsVendorRegistry`), and the bridge resolves the same `nativescript-vue`
31
+ * record everyone else uses.
32
+ *
33
+ * HMR-specific shims (`$navigateTo`, `$navigateBack`, `$showModal`) and the
34
+ * Vite client polyfill (`vite__injectQuery`) are emitted as overrides that
35
+ * replace the would-be passthrough — those exports route through the HMR
36
+ * navigator instead of the vendor's native version, so the bridge must
37
+ * provide the override, not the discovered original.
38
+ */
39
+ export declare function buildNsRtBridgeModule(options: NsRtBridgeOptions): string;
40
+ /**
41
+ * Resolve the set of names the bridge should re-export for `nativescript-vue`
42
+ * given a project root. Static discovery via `enumeratePackageExports` is the
43
+ * only source — there is no curated fallback. If `nativescript-vue` is not
44
+ * resolvable from `projectRoot`, the returned set is empty and the bridge
45
+ * built from it will not emit passthroughs; the caller should treat that as
46
+ * the misconfiguration it is rather than mask it with a stale baseline.
47
+ *
48
+ * Caching lives inside `enumeratePackageExports`, so repeated calls in a dev
49
+ * session are effectively free.
50
+ */
51
+ export declare function discoverNsvBridgeExports(projectRoot: string): Set<string>;
@@ -0,0 +1,131 @@
1
+ import { enumeratePackageExports } from '../helpers/package-exports.js';
2
+ // Exports the bridge replaces with HMR-routed implementations — discovery
3
+ // must not emit a plain passthrough for these names or the override would be
4
+ // shadowed and navigation would silently fall back to the vendor's native
5
+ // version (which doesn't know about the HMR app navigator).
6
+ const NSV_SHIM_OVERRIDES = new Set(['$navigateTo', '$navigateBack', '$showModal', 'vite__injectQuery']);
7
+ // Bridge-internal identifiers that would clash with the emitted preamble if
8
+ // the vendor package happens to publish a colliding name.
9
+ const RESERVED_BRIDGE_LOCALS = new Set(['__realm', '__cached_rt', '__cached_vm', '__ensure', '__get', 'default']);
10
+ const IDENT_RE = /^[A-Za-z_$][A-Za-z0-9_$]*$/;
11
+ /**
12
+ * Build the `/ns/rt` runtime bridge module text.
13
+ *
14
+ * Single-realm policy: every named export the vendor package publishes
15
+ * appears as `export const X = (__ensure().X);` — a constant binding, not a
16
+ * function wrapper. Constant bindings preserve identity for Vue's Symbol
17
+ * markers (`Fragment`, `Teleport`, …) AND work transparently for functions
18
+ * (`ref`, `createApp`, …) since the user code calls the underlying value
19
+ * directly. Calling `__ensure()` at module evaluation time is safe because
20
+ * the vendor bundle is registered earlier in the boot graph (vendor.mjs →
21
+ * `__nsVendorRegistry`), and the bridge resolves the same `nativescript-vue`
22
+ * record everyone else uses.
23
+ *
24
+ * HMR-specific shims (`$navigateTo`, `$navigateBack`, `$showModal`) and the
25
+ * Vite client polyfill (`vite__injectQuery`) are emitted as overrides that
26
+ * replace the would-be passthrough — those exports route through the HMR
27
+ * navigator instead of the vendor's native version, so the bridge must
28
+ * provide the override, not the discovered original.
29
+ */
30
+ export function buildNsRtBridgeModule(options) {
31
+ // Sort for stable output — useful for diffing the served bridge across requests.
32
+ const passthrough = new Set();
33
+ for (const name of options.vendorExports) {
34
+ if (typeof name === 'string' && IDENT_RE.test(name) && !NSV_SHIM_OVERRIDES.has(name) && !RESERVED_BRIDGE_LOCALS.has(name)) {
35
+ passthrough.add(name);
36
+ }
37
+ }
38
+ const passthroughNames = Array.from(passthrough).sort();
39
+ const passthroughExports = passthroughNames.map((n) => `export const ${n} = (__ensure().${n});`).join('\n');
40
+ const defaultListing = passthroughNames.concat(['$navigateTo', '$navigateBack', '$showModal', 'vite__injectQuery']).join(', ');
41
+ const code = `// [ns-rt][v2.4] NativeScript-Vue runtime bridge (module-scoped cache, no globals)\n` +
42
+ `// Single-realm policy: every export is a constant binding off the vendor module's\n` +
43
+ `// canonical instance, so app code, plugins, and the vendor bundle itself share one\n` +
44
+ `// module record. The set of exports below is derived from the package's static ESM\n` +
45
+ `// shape (see hmr/helpers/package-exports.ts), not a hand-curated list, so any symbol\n` +
46
+ `// the vendor publishes flows through automatically.\n` +
47
+ `const __origin = ((typeof globalThis !== 'undefined' && globalThis && globalThis.__NS_HTTP_ORIGIN__) || (new URL(import.meta.url)).origin);\n` +
48
+ // Use the canonical, unversioned `/ns/core` URL so this dynamic import
49
+ // shares an iOS HTTP-ESM module record (and therefore a single class-
50
+ // identity realm) with vendor `require('@nativescript/core')` lookups
51
+ // resolved via the runtime import map, plus every app-side import that
52
+ // goes through the core bridge. The `rtVer` is intentionally unused.
53
+ `let __ns_core_bridge = null; try { import(__origin + "/ns/core").then(m => { __ns_core_bridge = m; }).catch(() => {}); } catch {}\n` +
54
+ `const g = globalThis;\n` +
55
+ `const reg = (g.__nsVendorRegistry ||= new Map());\n` +
56
+ `const req = reg && reg.get ? (g.__nsVendorRequire || g.__nsRequire || g.require) : (g.__nsRequire || g.require);\n` +
57
+ `let __cached_rt = null;\n` +
58
+ `let __cached_vm = null;\n` +
59
+ `const __RT_REALM_TAG = (globalThis.__NS_RT_REALM__ ||= Math.random().toString(36).slice(2));\n` +
60
+ `try { if (!(globalThis.__NS_RT_ONCE__ && globalThis.__NS_RT_ONCE__.eval)) { (globalThis.__NS_RT_ONCE__ ||= {}).eval = true; if (globalThis.__NS_ENV_VERBOSE__) console.log('[ns-rt] evaluated', { rtRealm: __RT_REALM_TAG }); } } catch {}\n` +
61
+ `function __ensure(){\n` +
62
+ ` if (__cached_rt) return __cached_rt;\n` +
63
+ ` let vm = null;\n` +
64
+ ` try { vm = reg && reg.has && reg.has('nativescript-vue') ? reg.get('nativescript-vue') : (typeof req==='function' ? req('nativescript-vue') : null); } catch {}\n` +
65
+ ` if (!vm) { try { vm = reg && reg.has && reg.has('vue') ? reg.get('vue') : (typeof req==='function' ? req('vue') : null); } catch {} }\n` +
66
+ ` const rt = (vm && (vm.default ?? vm)) || {};\n` +
67
+ ` __cached_vm = vm;\n` +
68
+ ` __cached_rt = rt;\n` +
69
+ ` return rt;\n` +
70
+ `}\n` +
71
+ // Soft-globals for @nativescript/core when missing (dev-only safety).
72
+ // This stays even with the auto-derived passthrough because Frame /
73
+ // Page / Application aren't `nativescript-vue` exports — they're
74
+ // hoisted onto `globalThis` so the navigation shims (and any legacy
75
+ // `global.Frame.topmost()`-style call site inside the vendor bundle)
76
+ // see the same identities served by `/ns/core`.
77
+ `try {\n` +
78
+ ` const dev = typeof __DEV__ !== 'undefined' ? __DEV__ : true;\n` +
79
+ ` if (dev) {\n` +
80
+ ` const ns = (__ns_core_bridge && (__ns_core_bridge.__esModule && __ns_core_bridge.default ? __ns_core_bridge.default : (__ns_core_bridge.default || __ns_core_bridge))) || __ns_core_bridge || {};\n` +
81
+ ` if (ns) {\n` +
82
+ ` if (!g.Frame && ns.Frame) g.Frame = ns.Frame;\n` +
83
+ ` if (!g.Page && ns.Page) g.Page = ns.Page;\n` +
84
+ ` if (!g.Application && (ns.Application||ns.app||ns.application)) g.Application = (ns.Application||ns.app||ns.application);\n` +
85
+ ` }\n` +
86
+ ` }\n` +
87
+ `} catch {}\n` +
88
+ `export const __realm = __RT_REALM_TAG;\n` +
89
+ // Auto-emitted passthrough exports. Discovery-driven, sorted, dedupe'd.
90
+ passthroughExports +
91
+ `\n` +
92
+ // HMR-routed navigation helpers (replace the would-be passthroughs).
93
+ // These run through `globalThis.__nsNavigateUsingApp` etc. instead of
94
+ // the vendor's native navigation, so HMR can re-route navigation
95
+ // targets after module updates.
96
+ `export const $navigateTo = (...a) => { const vm = (__cached_vm || (void __ensure(), __cached_vm)); const rt = __ensure(); try { if (!(g && g.Frame)) { const ns = (__ns_core_bridge && (__ns_core_bridge.__esModule && __ns_core_bridge.default ? __ns_core_bridge.default : (__ns_core_bridge.default || __ns_core_bridge))) || __ns_core_bridge || {}; if (ns) { if (!g.Frame && ns.Frame) g.Frame = ns.Frame; if (!g.Page && ns.Page) g.Page = ns.Page; if (!g.Application && (ns.Application||ns.app||ns.application)) g.Application = (ns.Application||ns.app||ns.application); } } } catch {} try { const hmrRealm = (g && g.__NS_HMR_REALM__) || 'unknown'; const hasTop = !!(g && g.Frame && g.Frame.topmost && g.Frame.topmost()); const top = hasTop ? g.Frame.topmost() : null; const ctor = top && top.constructor && top.constructor.name; } catch {} if (g && typeof g.__nsNavigateUsingApp === 'function') { try { return g.__nsNavigateUsingApp(...a); } catch (e) { console.error('[ns-rt] $navigateTo app navigator error', e); throw e; } } console.error('[ns-rt] $navigateTo unavailable: app navigator missing'); throw new Error('$navigateTo unavailable: app navigator missing'); } ;\n` +
97
+ `export const $navigateBack = (...a) => { const vm = (__cached_vm || (void __ensure(), __cached_vm)); const rt = __ensure(); const impl = (vm && (vm.$navigateBack || (vm.default && vm.default.$navigateBack))) || (rt && (rt.$navigateBack || (rt.runtimeHelpers && rt.runtimeHelpers.navigateBack))); let res; try { const via = (impl && (impl === (vm && vm.$navigateBack) || impl === (vm && vm.default && vm.default.$navigateBack))) ? 'vm' : (impl ? 'rt' : 'none'); } catch {} try { if (typeof impl === 'function') res = impl(...a); } catch {} try { const top = (g && g.Frame && g.Frame.topmost && g.Frame.topmost()); if (!res && top && top.canGoBack && top.canGoBack()) { res = top.goBack(); } } catch {} try { const hook = g && (g.__NS_HMR_ON_NAVIGATE_BACK || g.__NS_HMR_ON_BACK || g.__nsAttemptBackRemount); if (typeof hook === 'function') hook(); } catch {} return res; }\n` +
98
+ `export const $showModal = (...a) => { const vm = (__cached_vm || (void __ensure(), __cached_vm)); const rt = __ensure(); const impl = (vm && (vm.$showModal || (vm.default && vm.default.$showModal))) || (rt && (rt.$showModal || (rt.runtimeHelpers && rt.runtimeHelpers.showModal))); try { if (typeof impl === 'function') return impl(...a); } catch (e) { } return undefined; }\n` +
99
+ // Vite client polyfill — see the comment in websocket.ts for full rationale.
100
+ `export const vite__injectQuery = (url, queryToInject) => {\n` +
101
+ ` if (typeof url !== 'string') return url;\n` +
102
+ ` if (url[0] !== '.' && url[0] !== '/') return url;\n` +
103
+ ` const pathname = url.replace(/[?#].*$/, '');\n` +
104
+ ` let search = '', hash = '';\n` +
105
+ ` try { const u = new URL(url, 'http://vite.dev'); search = u.search || ''; hash = u.hash || ''; } catch {}\n` +
106
+ ` return pathname + '?' + queryToInject + (search ? '&' + search.slice(1) : '') + (hash || '');\n` +
107
+ `};\n` +
108
+ `export default { ${defaultListing} };\n`;
109
+ return options.requireGuardSnippet + code;
110
+ }
111
+ /**
112
+ * Resolve the set of names the bridge should re-export for `nativescript-vue`
113
+ * given a project root. Static discovery via `enumeratePackageExports` is the
114
+ * only source — there is no curated fallback. If `nativescript-vue` is not
115
+ * resolvable from `projectRoot`, the returned set is empty and the bridge
116
+ * built from it will not emit passthroughs; the caller should treat that as
117
+ * the misconfiguration it is rather than mask it with a stale baseline.
118
+ *
119
+ * Caching lives inside `enumeratePackageExports`, so repeated calls in a dev
120
+ * session are effectively free.
121
+ */
122
+ export function discoverNsvBridgeExports(projectRoot) {
123
+ const out = new Set();
124
+ const shape = enumeratePackageExports('nativescript-vue', projectRoot);
125
+ for (const n of shape.names) {
126
+ if (typeof n === 'string' && IDENT_RE.test(n))
127
+ out.add(n);
128
+ }
129
+ return out;
130
+ }
131
+ //# sourceMappingURL=ns-rt-bridge.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ns-rt-bridge.js","sourceRoot":"","sources":["../../../../../packages/vite/hmr/server/ns-rt-bridge.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,uBAAuB,EAAE,MAAM,+BAA+B,CAAC;AAExE,0EAA0E;AAC1E,6EAA6E;AAC7E,0EAA0E;AAC1E,4DAA4D;AAC5D,MAAM,kBAAkB,GAAwB,IAAI,GAAG,CAAC,CAAC,aAAa,EAAE,eAAe,EAAE,YAAY,EAAE,mBAAmB,CAAC,CAAC,CAAC;AAE7H,4EAA4E;AAC5E,0DAA0D;AAC1D,MAAM,sBAAsB,GAAwB,IAAI,GAAG,CAAC,CAAC,SAAS,EAAE,aAAa,EAAE,aAAa,EAAE,UAAU,EAAE,OAAO,EAAE,SAAS,CAAC,CAAC,CAAC;AAEvI,MAAM,QAAQ,GAAG,4BAA4B,CAAC;AAsB9C;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,UAAU,qBAAqB,CAAC,OAA0B;IAC/D,iFAAiF;IACjF,MAAM,WAAW,GAAG,IAAI,GAAG,EAAU,CAAC;IACtC,KAAK,MAAM,IAAI,IAAI,OAAO,CAAC,aAAa,EAAE,CAAC;QAC1C,IAAI,OAAO,IAAI,KAAK,QAAQ,IAAI,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,kBAAkB,CAAC,GAAG,CAAC,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