@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.
@@ -18,6 +18,7 @@ import * as path from 'path';
18
18
  import { createHash } from 'crypto';
19
19
  import * as PAT from './constants.js';
20
20
  import { getVendorManifest, resolveVendorSpecifier } from '../shared/vendor/registry.js';
21
+ import { buildNsRtBridgeModule, discoverNsvBridgeExports } from './ns-rt-bridge.js';
21
22
  import { getMonorepoWorkspaceRoot, getPackageJson, getProjectFilePath, getProjectRootPath } from '../../helpers/project.js';
22
23
  import { loadPrebuiltVendorManifest } from '../shared/vendor/manifest-loader.js';
23
24
  import '../vendor-bootstrap.js';
@@ -4210,167 +4211,15 @@ export const piniaSymbol = p.piniaSymbol;
4210
4211
  res.setHeader('Expires', '0');
4211
4212
  const rtVerSeg = urlObj.pathname.replace(/^\/ns\/rt\/?/, '');
4212
4213
  const rtVer = /^[0-9]+$/.test(rtVerSeg) ? rtVerSeg : String(graphVersion || 0);
4213
- const origin = getServerOrigin(server);
4214
- let code = `// [ns-rt][v2.3] NativeScript-Vue runtime bridge (module-scoped cache, no globals)\n` +
4215
- `const __origin = ((typeof globalThis !== 'undefined' && globalThis && globalThis.__NS_HTTP_ORIGIN__) || (new URL(import.meta.url)).origin);\n` +
4216
- // Always target the canonical, unversioned `/ns/core` URL the
4217
- // runtime import map maps bare `@nativescript/core` to the same
4218
- // URL, so vendor `require('@nativescript/core')` and this dynamic
4219
- // import end up at one iOS HTTP-ESM module record (and one class
4220
- // identity realm).
4221
- `let __ns_core_bridge = null; try { import(__origin + "/ns/core").then(m => { __ns_core_bridge = m; }).catch(() => {}); } catch {}\n` +
4222
- `const g = globalThis;\n` +
4223
- `const reg = (g.__nsVendorRegistry ||= new Map());\n` +
4224
- `const req = reg && reg.get ? (g.__nsVendorRequire || g.__nsRequire || g.require) : (g.__nsRequire || g.require);\n` +
4225
- `let __cached_rt = null;\n` +
4226
- `let __cached_vm = null;\n` +
4227
- `const __RT_REALM_TAG = (globalThis.__NS_RT_REALM__ ||= Math.random().toString(36).slice(2));\n` +
4228
- // One-shot evaluation marker to confirm the bridge is executed on
4229
- // device. Gated on __NS_ENV_VERBOSE__ so it stays silent unless
4230
- // the developer opts in via NS_VITE_VERBOSE / VITE_DEBUG_LOGS.
4231
- `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` +
4232
- `function __ensure(){\n` +
4233
- ` if (__cached_rt) return __cached_rt;\n` +
4234
- ` let vm = null;\n` +
4235
- ` try { vm = reg && reg.has && reg.has('nativescript-vue') ? reg.get('nativescript-vue') : (typeof req==='function' ? req('nativescript-vue') : null); } catch {}\n` +
4236
- ` if (!vm) { try { vm = reg && reg.has && reg.has('vue') ? reg.get('vue') : (typeof req==='function' ? req('vue') : null); } catch {} }\n` +
4237
- ` const rt = (vm && (vm.default ?? vm)) || {};\n` +
4238
- ` __cached_vm = vm;\n` +
4239
- ` __cached_rt = rt;\n` +
4240
- ` return rt;\n` +
4241
- `}\n` +
4242
- `// Soft-globals for @nativescript/core when missing (dev-only safety)\n` +
4243
- `try {\n` +
4244
- ` const dev = typeof __DEV__ !== 'undefined' ? __DEV__ : true;\n` +
4245
- ` if (dev) {\n` +
4246
- ` 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` +
4247
- ` if (ns) {\n` +
4248
- ` if (!g.Frame && ns.Frame) g.Frame = ns.Frame;\n` +
4249
- ` if (!g.Page && ns.Page) g.Page = ns.Page;\n` +
4250
- ` if (!g.Application && (ns.Application||ns.app||ns.application)) g.Application = (ns.Application||ns.app||ns.application);\n` +
4251
- ` }\n` +
4252
- ` }\n` +
4253
- `} catch {}\n` +
4254
- `const __get = (k) => { const rt = __ensure(); const v = rt && rt[k]; if (typeof v !== 'function' && v === undefined) { throw new Error('[ns-rt] missing export '+k); } return v; };\n` +
4255
- `export const __realm = __RT_REALM_TAG;\n` +
4256
- `export const defineComponent = (...a) => (__get('defineComponent'))(...a);\n` +
4257
- `export const resolveComponent = (...a) => (__ensure().resolveComponent)(...a);\n` +
4258
- `export const createVNode = (...a) => (__ensure().createVNode)(...a);\n` +
4259
- `export const createTextVNode = (...a) => (__ensure().createTextVNode)(...a);\n` +
4260
- `export const createCommentVNode = (...a) => (__ensure().createCommentVNode)(...a);\n` +
4261
- `export const Fragment = (__ensure().Fragment);\n` +
4262
- `export const Teleport = (__ensure().Teleport);\n` +
4263
- `export const Transition = (__ensure().Transition);\n` +
4264
- `export const TransitionGroup = (__ensure().TransitionGroup);\n` +
4265
- `export const KeepAlive = (__ensure().KeepAlive);\n` +
4266
- `export const Suspense = (__ensure().Suspense);\n` +
4267
- `export const withCtx = (...a) => (__ensure().withCtx)(...a);\n` +
4268
- `export const openBlock = (...a) => (__ensure().openBlock)(...a);\n` +
4269
- `export const createBlock = (...a) => (__ensure().createBlock)(...a);\n` +
4270
- `export const createElementVNode = (...a) => (__ensure().createElementVNode)(...a);\n` +
4271
- `export const createElementBlock = (...a) => (__ensure().createElementBlock)(...a);\n` +
4272
- `export const renderSlot = (...a) => (__ensure().renderSlot)(...a);\n` +
4273
- `export const mergeProps = (...a) => (__ensure().mergeProps)(...a);\n` +
4274
- `export const toHandlers = (...a) => (__ensure().toHandlers)(...a);\n` +
4275
- `export const renderList = (...a) => (__ensure().renderList)(...a);\n` +
4276
- `export const normalizeProps = (...a) => (__ensure().normalizeProps)(...a);\n` +
4277
- `export const guardReactiveProps = (...a) => (__ensure().guardReactiveProps)(...a);\n` +
4278
- `export const normalizeClass = (...a) => (__ensure().normalizeClass)(...a);\n` +
4279
- `export const normalizeStyle = (...a) => (__ensure().normalizeStyle)(...a);\n` +
4280
- `export const toDisplayString = (...a) => (__ensure().toDisplayString)(...a);\n` +
4281
- `export const withDirectives = (...a) => (__ensure().withDirectives)(...a);\n` +
4282
- `export const resolveDirective = (...a) => (__ensure().resolveDirective)(...a);\n` +
4283
- `export const withModifiers = (...a) => (__ensure().withModifiers)(...a);\n` +
4284
- `export const withKeys = (...a) => (__ensure().withKeys)(...a);\n` +
4285
- `export const resolveDynamicComponent = (...a) => (__ensure().resolveDynamicComponent)(...a);\n` +
4286
- `export const isVNode = (...a) => (__ensure().isVNode)(...a);\n` +
4287
- `export const cloneVNode = (...a) => (__ensure().cloneVNode)(...a);\n` +
4288
- `export const isRef = (...a) => (__ensure().isRef)(...a);\n` +
4289
- `export const ref = (...a) => (__ensure().ref)(...a);\n` +
4290
- `export const shallowRef = (...a) => (__ensure().shallowRef)(...a);\n` +
4291
- `export const unref = (...a) => (__ensure().unref)(...a);\n` +
4292
- `export const computed = (...a) => (__ensure().computed)(...a);\n` +
4293
- `export const reactive = (...a) => (__ensure().reactive)(...a);\n` +
4294
- `export const readonly = (...a) => (__ensure().readonly)(...a);\n` +
4295
- `export const isReactive = (...a) => (__ensure().isReactive)(...a);\n` +
4296
- `export const isReadonly = (...a) => (__ensure().isReadonly)(...a);\n` +
4297
- `export const toRaw = (...a) => (__ensure().toRaw)(...a);\n` +
4298
- `export const markRaw = (...a) => (__ensure().markRaw)(...a);\n` +
4299
- `export const shallowReactive = (...a) => (__ensure().shallowReactive)(...a);\n` +
4300
- `export const shallowReadonly = (...a) => (__ensure().shallowReadonly)(...a);\n` +
4301
- `export const watch = (...a) => (__ensure().watch)(...a);\n` +
4302
- `export const watchEffect = (...a) => (__ensure().watchEffect)(...a);\n` +
4303
- `export const watchPostEffect = (...a) => (__ensure().watchPostEffect)(...a);\n` +
4304
- `export const watchSyncEffect = (...a) => (__ensure().watchSyncEffect)(...a);\n` +
4305
- `export const onBeforeMount = (...a) => (__ensure().onBeforeMount)(...a);\n` +
4306
- `export const onMounted = (...a) => (__ensure().onMounted)(...a);\n` +
4307
- `export const onBeforeUpdate = (...a) => (__ensure().onBeforeUpdate)(...a);\n` +
4308
- `export const onUpdated = (...a) => (__ensure().onUpdated)(...a);\n` +
4309
- `export const onBeforeUnmount = (...a) => (__ensure().onBeforeUnmount)(...a);\n` +
4310
- `export const onUnmounted = (...a) => (__ensure().onUnmounted)(...a);\n` +
4311
- `export const onActivated = (...a) => (__ensure().onActivated)(...a);\n` +
4312
- `export const onDeactivated = (...a) => (__ensure().onDeactivated)(...a);\n` +
4313
- `export const onErrorCaptured = (...a) => (__ensure().onErrorCaptured)(...a);\n` +
4314
- `export const onRenderTracked = (...a) => (__ensure().onRenderTracked)(...a);\n` +
4315
- `export const onRenderTriggered = (...a) => (__ensure().onRenderTriggered)(...a);\n` +
4316
- `export const nextTick = (...a) => (__ensure().nextTick)(...a);\n` +
4317
- `export const h = (...a) => (__ensure().h)(...a);\n` +
4318
- `export const provide = (...a) => (__ensure().provide)(...a);\n` +
4319
- `export const inject = (...a) => (__ensure().inject)(...a);\n` +
4320
- `export const vShow = (__ensure().vShow);\n` +
4321
- `export const createApp = (...a) => (__ensure().createApp)(...a);\n` +
4322
- `export const registerElement = (...a) => (__ensure().registerElement)(...a);\n` +
4323
- `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` +
4324
- `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` +
4325
- `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` +
4326
- // Vite client helpers re-exported through the runtime bridge.
4327
- //
4328
- // Vite's `vite:import-analysis` plugin rewrites unresolvable dynamic
4329
- // imports (where the URL is not a static string literal) as
4330
- // `__vite__injectQuery(<expr>, 'import')` and prepends an import
4331
- // from `/@vite/client`. The /* @vite-ignore */ comment only
4332
- // suppresses the warning, not the rewrite — Vite gates the rewrite
4333
- // on `urlIsStringRE`, not `hasViteIgnoreRE`.
4334
- //
4335
- // In NativeScript dev, the AST normalizer (packages/vite/hmr/helpers/
4336
- // ast-normalizer.ts) correctly strips the /@vite/client import (the
4337
- // browser-only client module is not loadable on-device), then sees
4338
- // the unbound `__vite__injectQuery` identifier and synthesizes
4339
- // `const { vite__injectQuery: __vite__injectQuery } = __ns_rt_ns_1`
4340
- // from this bridge. Without this export the destructure binds to
4341
- // undefined and Angular 21's component HMR loader (and any other
4342
- // caller of dynamic-import-with-non-literal-URL) fails with
4343
- // `__vite__injectQuery is not a function` at module evaluation.
4344
- //
4345
- // This polyfill mirrors Vite 8's `__vite__injectQuery` in
4346
- // node_modules/vite/dist/node/chunks/node.js — for relative or
4347
- // absolute-path URLs it appends `?<queryToInject>` (preserving
4348
- // existing search/hash); for already-absolute URLs (http(s):, etc.)
4349
- // it returns the URL unchanged. Angular's `ɵɵgetReplaceMetadataURL`
4350
- // returns absolute HTTP URLs, so this acts as a passthrough at
4351
- // runtime, matching Vite's web behavior.
4352
- `export const vite__injectQuery = (url, queryToInject) => {\n` +
4353
- ` if (typeof url !== 'string') return url;\n` +
4354
- ` if (url[0] !== '.' && url[0] !== '/') return url;\n` +
4355
- ` const pathname = url.replace(/[?#].*$/, '');\n` +
4356
- ` let search = '', hash = '';\n` +
4357
- ` try { const u = new URL(url, 'http://vite.dev'); search = u.search || ''; hash = u.hash || ''; } catch {}\n` +
4358
- ` return pathname + '?' + queryToInject + (search ? '&' + search.slice(1) : '') + (hash || '');\n` +
4359
- `};\n` +
4360
- `export default {\n` +
4361
- ` defineComponent, resolveComponent, createVNode, createTextVNode, createCommentVNode,\n` +
4362
- ` Fragment, Teleport, Transition, TransitionGroup, KeepAlive, Suspense, withCtx, openBlock,\n` +
4363
- ` createBlock, createElementVNode, createElementBlock, renderSlot, mergeProps, toHandlers,\n` +
4364
- ` renderList, normalizeProps, guardReactiveProps, normalizeClass, normalizeStyle, toDisplayString,\n` +
4365
- ` withDirectives, resolveDirective, withModifiers, withKeys, resolveDynamicComponent,\n` +
4366
- ` isVNode, cloneVNode, isRef, ref, shallowRef, unref, computed, reactive, readonly, isReactive, isReadonly, toRaw, markRaw, shallowReactive, shallowReadonly,\n` +
4367
- ` watch, watchEffect, watchPostEffect, watchSyncEffect, onBeforeMount, onMounted, onBeforeUpdate, onUpdated,\n` +
4368
- ` onBeforeUnmount, onUnmounted, onActivated, onDeactivated, onErrorCaptured, onRenderTracked, onRenderTriggered, nextTick, h, provide, inject, vShow, createApp, registerElement,\n` +
4369
- ` $navigateTo, $navigateBack, $showModal,\n` +
4370
- ` vite__injectQuery\n` +
4371
- `};\n`;
4372
- // Prepend guard and ship (harmless, keeps diagnostics consistent)
4373
- code = REQUIRE_GUARD_SNIPPET + code;
4214
+ // Single-realm bridge: discover every export `nativescript-vue`
4215
+ // (plus its `@vue/runtime-core` re-export chain) publishes so
4216
+ // the bridge never silently drops a symbol. `discoverNsvBridgeExports`
4217
+ // returns the union of static discovery and the curated baseline,
4218
+ // with the baseline acting as the floor if discovery fails. The
4219
+ // shared builder owns the bridge body (preamble, passthroughs,
4220
+ // HMR shims, polyfills, default export) there's no inline copy.
4221
+ const vendorExports = discoverNsvBridgeExports(getProjectRootPath());
4222
+ const code = buildNsRtBridgeModule({ rtVer, requireGuardSnippet: REQUIRE_GUARD_SNIPPET, vendorExports });
4374
4223
  res.statusCode = 200;
4375
4224
  res.end(code);
4376
4225
  }