@nativescript/vite 8.0.0-alpha.3 → 8.0.0-alpha.30
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.
- package/README.md +51 -11
- package/configuration/angular.d.ts +34 -1
- package/configuration/angular.js +369 -159
- package/configuration/angular.js.map +1 -1
- package/configuration/base.js +184 -14
- package/configuration/base.js.map +1 -1
- package/configuration/javascript.js +5 -72
- package/configuration/javascript.js.map +1 -1
- package/configuration/solid.js +27 -1
- package/configuration/solid.js.map +1 -1
- package/configuration/typescript.js +5 -75
- package/configuration/typescript.js.map +1 -1
- package/helpers/angular/angular-linker.d.ts +5 -6
- package/helpers/angular/angular-linker.js +36 -121
- package/helpers/angular/angular-linker.js.map +1 -1
- package/helpers/angular/inject-component-hmr-registration.d.ts +112 -0
- package/helpers/angular/inject-component-hmr-registration.js +291 -0
- package/helpers/angular/inject-component-hmr-registration.js.map +1 -0
- package/helpers/angular/inject-hmr-vite-ignore.d.ts +75 -0
- package/helpers/angular/inject-hmr-vite-ignore.js +221 -0
- package/helpers/angular/inject-hmr-vite-ignore.js.map +1 -0
- package/helpers/angular/inline-decorator-component-templates.js +1 -170
- package/helpers/angular/inline-decorator-component-templates.js.map +1 -1
- package/helpers/angular/js-lexer.d.ts +4 -0
- package/helpers/angular/js-lexer.js +182 -0
- package/helpers/angular/js-lexer.js.map +1 -0
- package/helpers/angular/shared-linker.d.ts +31 -3
- package/helpers/angular/shared-linker.js +67 -14
- package/helpers/angular/shared-linker.js.map +1 -1
- package/helpers/angular/synthesize-decorator-ctor-parameters.js +2 -170
- package/helpers/angular/synthesize-decorator-ctor-parameters.js.map +1 -1
- package/helpers/angular/synthesize-injectable-factories.js +1 -174
- package/helpers/angular/synthesize-injectable-factories.js.map +1 -1
- package/helpers/angular/util.d.ts +1 -0
- package/helpers/angular/util.js +88 -0
- package/helpers/angular/util.js.map +1 -1
- package/helpers/app-components.d.ts +2 -1
- package/helpers/app-components.js.map +1 -1
- package/helpers/app-css-state.d.ts +8 -0
- package/helpers/app-css-state.js +8 -0
- package/helpers/app-css-state.js.map +1 -0
- package/helpers/bundler-context.d.ts +11 -0
- package/helpers/bundler-context.js +71 -0
- package/helpers/bundler-context.js.map +1 -0
- package/helpers/config-as-json.js +10 -0
- package/helpers/config-as-json.js.map +1 -1
- package/helpers/dev-host.d.ts +341 -0
- package/helpers/dev-host.js +617 -0
- package/helpers/dev-host.js.map +1 -0
- package/helpers/esbuild-platform-resolver.js +4 -1
- package/helpers/esbuild-platform-resolver.js.map +1 -1
- package/helpers/global-defines.d.ts +51 -0
- package/helpers/global-defines.js +77 -0
- package/helpers/global-defines.js.map +1 -1
- package/helpers/hmr-scope.d.ts +26 -0
- package/helpers/hmr-scope.js +67 -0
- package/helpers/hmr-scope.js.map +1 -0
- package/helpers/init.js +0 -18
- package/helpers/init.js.map +1 -1
- package/helpers/logging.d.ts +1 -0
- package/helpers/logging.js +63 -3
- package/helpers/logging.js.map +1 -1
- package/helpers/main-entry.d.ts +2 -1
- package/helpers/main-entry.js +430 -47
- package/helpers/main-entry.js.map +1 -1
- package/helpers/nativeclass-esbuild-plugin.d.ts +2 -1
- package/helpers/nativeclass-esbuild-plugin.js.map +1 -1
- package/helpers/nativeclass-transform.js.map +1 -1
- package/helpers/nativeclass-transformer-plugin.d.ts +9 -2
- package/helpers/nativeclass-transformer-plugin.js +157 -14
- package/helpers/nativeclass-transformer-plugin.js.map +1 -1
- package/helpers/nativescript-package-resolver.js +8 -3
- package/helpers/nativescript-package-resolver.js.map +1 -1
- package/helpers/normalize-id.d.ts +42 -0
- package/helpers/normalize-id.js +60 -0
- package/helpers/normalize-id.js.map +1 -0
- package/helpers/ns-core-url.d.ts +88 -0
- package/helpers/ns-core-url.js +191 -0
- package/helpers/ns-core-url.js.map +1 -0
- package/helpers/package-platform-aliases.js +4 -3
- package/helpers/package-platform-aliases.js.map +1 -1
- package/helpers/platform-types.d.ts +2 -0
- package/helpers/platform-types.js +2 -0
- package/helpers/platform-types.js.map +1 -0
- package/helpers/prelink-angular.js +12 -33
- package/helpers/prelink-angular.js.map +1 -1
- package/helpers/project.d.ts +35 -0
- package/helpers/project.js +120 -2
- package/helpers/project.js.map +1 -1
- package/helpers/resolver.js +17 -2
- package/helpers/resolver.js.map +1 -1
- package/helpers/solid-jsx-deps.d.ts +15 -0
- package/helpers/solid-jsx-deps.js +178 -0
- package/helpers/solid-jsx-deps.js.map +1 -0
- package/helpers/ts-config-paths.d.ts +14 -0
- package/helpers/ts-config-paths.js +89 -8
- package/helpers/ts-config-paths.js.map +1 -1
- package/helpers/typescript-check.d.ts +2 -1
- package/helpers/typescript-check.js.map +1 -1
- package/helpers/workers.d.ts +20 -19
- package/helpers/workers.js +624 -4
- package/helpers/workers.js.map +1 -1
- package/hmr/client/css-handler.d.ts +1 -0
- package/hmr/client/css-handler.js +33 -20
- package/hmr/client/css-handler.js.map +1 -1
- package/hmr/client/css-update-overlay.d.ts +18 -0
- package/hmr/client/css-update-overlay.js +27 -0
- package/hmr/client/css-update-overlay.js.map +1 -0
- package/hmr/client/hmr-pending-overlay.d.ts +27 -0
- package/hmr/client/hmr-pending-overlay.js +50 -0
- package/hmr/client/hmr-pending-overlay.js.map +1 -0
- package/hmr/client/index.js +419 -15
- package/hmr/client/index.js.map +1 -1
- package/hmr/client/utils.d.ts +6 -1
- package/hmr/client/utils.js +184 -8
- package/hmr/client/utils.js.map +1 -1
- package/hmr/client/vue-sfc-update-overlay.d.ts +82 -0
- package/hmr/client/vue-sfc-update-overlay.js +133 -0
- package/hmr/client/vue-sfc-update-overlay.js.map +1 -0
- package/hmr/entry-runtime.d.ts +2 -1
- package/hmr/entry-runtime.js +252 -65
- package/hmr/entry-runtime.js.map +1 -1
- package/hmr/frameworks/angular/client/index.d.ts +1 -0
- package/hmr/frameworks/angular/client/index.js +778 -20
- package/hmr/frameworks/angular/client/index.js.map +1 -1
- package/hmr/frameworks/angular/server/linker.js +1 -4
- package/hmr/frameworks/angular/server/linker.js.map +1 -1
- package/hmr/frameworks/angular/server/strategy.js +13 -15
- package/hmr/frameworks/angular/server/strategy.js.map +1 -1
- package/hmr/frameworks/solid/server/strategy.js +3 -18
- package/hmr/frameworks/solid/server/strategy.js.map +1 -1
- package/hmr/frameworks/typescript/server/strategy.js +2 -15
- package/hmr/frameworks/typescript/server/strategy.js.map +1 -1
- package/hmr/frameworks/vue/client/index.js +30 -199
- package/hmr/frameworks/vue/client/index.js.map +1 -1
- package/hmr/helpers/ast-normalizer.js +52 -5
- package/hmr/helpers/ast-normalizer.js.map +1 -1
- package/hmr/helpers/cjs-named-exports.d.ts +23 -0
- package/hmr/helpers/cjs-named-exports.js +152 -0
- package/hmr/helpers/cjs-named-exports.js.map +1 -0
- package/hmr/helpers/package-exports.d.ts +16 -0
- package/hmr/helpers/package-exports.js +396 -0
- package/hmr/helpers/package-exports.js.map +1 -0
- package/hmr/server/angular-root-component.d.ts +79 -0
- package/hmr/server/angular-root-component.js +149 -0
- package/hmr/server/angular-root-component.js.map +1 -0
- package/hmr/server/constants.js +13 -4
- package/hmr/server/constants.js.map +1 -1
- package/hmr/server/core-sanitize.d.ts +90 -7
- package/hmr/server/core-sanitize.js +211 -56
- package/hmr/server/core-sanitize.js.map +1 -1
- package/hmr/server/framework-strategy.d.ts +9 -19
- package/hmr/server/hmr-module-graph.d.ts +37 -0
- package/hmr/server/hmr-module-graph.js +214 -0
- package/hmr/server/hmr-module-graph.js.map +1 -0
- package/hmr/server/import-map.js +60 -8
- package/hmr/server/import-map.js.map +1 -1
- package/hmr/server/index.js +1 -0
- package/hmr/server/index.js.map +1 -1
- package/hmr/server/ns-core-cjs-shape.d.ts +204 -0
- package/hmr/server/ns-core-cjs-shape.js +271 -0
- package/hmr/server/ns-core-cjs-shape.js.map +1 -0
- package/hmr/server/ns-rt-bridge.d.ts +51 -0
- package/hmr/server/ns-rt-bridge.js +131 -0
- package/hmr/server/ns-rt-bridge.js.map +1 -0
- package/hmr/server/ns-rt-route.d.ts +5 -0
- package/hmr/server/ns-rt-route.js +35 -0
- package/hmr/server/ns-rt-route.js.map +1 -0
- package/hmr/server/perf-instrumentation.d.ts +114 -0
- package/hmr/server/perf-instrumentation.js +195 -0
- package/hmr/server/perf-instrumentation.js.map +1 -0
- package/hmr/server/require-guard.d.ts +1 -0
- package/hmr/server/require-guard.js +12 -0
- package/hmr/server/require-guard.js.map +1 -0
- package/hmr/server/route-helpers.d.ts +7 -0
- package/hmr/server/route-helpers.js +13 -0
- package/hmr/server/route-helpers.js.map +1 -0
- package/hmr/server/server-origin.d.ts +12 -0
- package/hmr/server/server-origin.js +66 -0
- package/hmr/server/server-origin.js.map +1 -0
- package/hmr/server/shared-transform-request.js +12 -5
- package/hmr/server/shared-transform-request.js.map +1 -1
- package/hmr/server/vendor-bare-module-shims.d.ts +4 -0
- package/hmr/server/vendor-bare-module-shims.js +80 -0
- package/hmr/server/vendor-bare-module-shims.js.map +1 -0
- package/hmr/server/vite-plugin.js +60 -42
- package/hmr/server/vite-plugin.js.map +1 -1
- package/hmr/server/websocket-angular-entry.js +1 -1
- package/hmr/server/websocket-angular-entry.js.map +1 -1
- package/hmr/server/websocket-angular-hot-update.d.ts +17 -0
- package/hmr/server/websocket-angular-hot-update.js +176 -2
- package/hmr/server/websocket-angular-hot-update.js.map +1 -1
- package/hmr/server/websocket-core-bridge.d.ts +41 -6
- package/hmr/server/websocket-core-bridge.js +72 -75
- package/hmr/server/websocket-core-bridge.js.map +1 -1
- package/hmr/server/websocket-css-hot-update.d.ts +33 -0
- package/hmr/server/websocket-css-hot-update.js +65 -0
- package/hmr/server/websocket-css-hot-update.js.map +1 -0
- package/hmr/server/websocket-device-transform.d.ts +21 -0
- package/hmr/server/websocket-device-transform.js +1570 -0
- package/hmr/server/websocket-device-transform.js.map +1 -0
- package/hmr/server/websocket-graph-upsert.d.ts +15 -0
- package/hmr/server/websocket-graph-upsert.js +20 -0
- package/hmr/server/websocket-graph-upsert.js.map +1 -1
- package/hmr/server/websocket-hmr-pending.d.ts +43 -0
- package/hmr/server/websocket-hmr-pending.js +55 -0
- package/hmr/server/websocket-hmr-pending.js.map +1 -0
- package/hmr/server/websocket-hot-update.d.ts +51 -0
- package/hmr/server/websocket-hot-update.js +1160 -0
- package/hmr/server/websocket-hot-update.js.map +1 -0
- package/hmr/server/websocket-import-map-route.d.ts +15 -0
- package/hmr/server/websocket-import-map-route.js +44 -0
- package/hmr/server/websocket-import-map-route.js.map +1 -0
- package/hmr/server/websocket-module-bindings.js +3 -3
- package/hmr/server/websocket-module-bindings.js.map +1 -1
- package/hmr/server/websocket-module-specifiers.d.ts +66 -2
- package/hmr/server/websocket-module-specifiers.js +202 -19
- package/hmr/server/websocket-module-specifiers.js.map +1 -1
- package/hmr/server/websocket-ns-core.d.ts +21 -0
- package/hmr/server/websocket-ns-core.js +305 -0
- package/hmr/server/websocket-ns-core.js.map +1 -0
- package/hmr/server/websocket-ns-entry.d.ts +22 -0
- package/hmr/server/websocket-ns-entry.js +150 -0
- package/hmr/server/websocket-ns-entry.js.map +1 -0
- package/hmr/server/websocket-ns-m-paths.d.ts +3 -0
- package/hmr/server/websocket-ns-m-paths.js +92 -0
- package/hmr/server/websocket-ns-m-paths.js.map +1 -0
- package/hmr/server/websocket-ns-m-request.d.ts +45 -0
- package/hmr/server/websocket-ns-m-request.js +196 -0
- package/hmr/server/websocket-ns-m-request.js.map +1 -0
- package/hmr/server/websocket-ns-m.d.ts +34 -0
- package/hmr/server/websocket-ns-m.js +853 -0
- package/hmr/server/websocket-ns-m.js.map +1 -0
- package/hmr/server/websocket-served-module-helpers.d.ts +39 -0
- package/hmr/server/websocket-served-module-helpers.js +654 -0
- package/hmr/server/websocket-served-module-helpers.js.map +1 -0
- package/hmr/server/websocket-sfc.d.ts +24 -0
- package/hmr/server/websocket-sfc.js +1223 -0
- package/hmr/server/websocket-sfc.js.map +1 -0
- package/hmr/server/websocket-txn.d.ts +6 -0
- package/hmr/server/websocket-txn.js +39 -0
- package/hmr/server/websocket-txn.js.map +1 -0
- package/hmr/server/websocket-vendor-unifier.d.ts +10 -0
- package/hmr/server/websocket-vendor-unifier.js +45 -0
- package/hmr/server/websocket-vendor-unifier.js.map +1 -0
- package/hmr/server/websocket.d.ts +0 -30
- package/hmr/server/websocket.js +599 -6038
- package/hmr/server/websocket.js.map +1 -1
- package/hmr/shared/runtime/boot-placeholder-ui.d.ts +69 -0
- package/hmr/shared/runtime/boot-placeholder-ui.js +101 -0
- package/hmr/shared/runtime/boot-placeholder-ui.js.map +1 -0
- package/hmr/shared/runtime/boot-progress.d.ts +40 -0
- package/hmr/shared/runtime/boot-progress.js +128 -0
- package/hmr/shared/runtime/boot-progress.js.map +1 -0
- package/hmr/shared/runtime/boot-timeline.d.ts +18 -0
- package/hmr/shared/runtime/boot-timeline.js +52 -0
- package/hmr/shared/runtime/boot-timeline.js.map +1 -0
- package/hmr/shared/runtime/dev-overlay-snapshots.d.ts +31 -0
- package/hmr/shared/runtime/dev-overlay-snapshots.js +324 -0
- package/hmr/shared/runtime/dev-overlay-snapshots.js.map +1 -0
- package/hmr/shared/runtime/dev-overlay.d.ts +75 -26
- package/hmr/shared/runtime/dev-overlay.js +990 -260
- package/hmr/shared/runtime/dev-overlay.js.map +1 -1
- package/hmr/shared/runtime/module-provenance.js +1 -4
- package/hmr/shared/runtime/module-provenance.js.map +1 -1
- package/hmr/shared/runtime/root-placeholder-view.d.ts +19 -0
- package/hmr/shared/runtime/root-placeholder-view.js +310 -0
- package/hmr/shared/runtime/root-placeholder-view.js.map +1 -0
- package/hmr/shared/runtime/root-placeholder.js +352 -194
- package/hmr/shared/runtime/root-placeholder.js.map +1 -1
- package/hmr/shared/runtime/session-bootstrap.js +164 -1
- package/hmr/shared/runtime/session-bootstrap.js.map +1 -1
- package/hmr/shared/runtime/vendor-bootstrap.js +1 -9
- package/hmr/shared/runtime/vendor-bootstrap.js.map +1 -1
- package/hmr/shared/vendor/manifest-collect.d.ts +32 -0
- package/hmr/shared/vendor/manifest-collect.js +512 -0
- package/hmr/shared/vendor/manifest-collect.js.map +1 -0
- package/hmr/shared/vendor/manifest-loader.d.ts +2 -1
- package/hmr/shared/vendor/manifest-loader.js +3 -2
- package/hmr/shared/vendor/manifest-loader.js.map +1 -1
- package/hmr/shared/vendor/manifest.d.ts +1 -5
- package/hmr/shared/vendor/manifest.js +102 -739
- package/hmr/shared/vendor/manifest.js.map +1 -1
- package/hmr/shared/vendor/vendor-device-shim.d.ts +1 -0
- package/hmr/shared/vendor/vendor-device-shim.js +208 -0
- package/hmr/shared/vendor/vendor-device-shim.js.map +1 -0
- package/hmr/shared/vendor/vendor-esbuild-plugins.d.ts +16 -0
- package/hmr/shared/vendor/vendor-esbuild-plugins.js +203 -0
- package/hmr/shared/vendor/vendor-esbuild-plugins.js.map +1 -0
- package/index.d.ts +1 -0
- package/index.js +5 -0
- package/index.js.map +1 -1
- package/package.json +55 -11
- package/runtime/core-aliases-early.js +17 -41
- package/runtime/core-aliases-early.js.map +1 -1
|
@@ -0,0 +1,271 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CJS/ESM interop shape.
|
|
3
|
+
*
|
|
4
|
+
* PROBLEM
|
|
5
|
+
* -------
|
|
6
|
+
* ESM Module Namespace Objects (ECMA §9.4.6) have [[Prototype]] = null.
|
|
7
|
+
* They do NOT inherit Object.prototype — no `hasOwnProperty`, no `toString`,
|
|
8
|
+
* no `isPrototypeOf`. CJS consumers (most notably zone.js's `patchMethod`)
|
|
9
|
+
* assume their require() result is a plain object that has those methods:
|
|
10
|
+
*
|
|
11
|
+
* let proto = target;
|
|
12
|
+
* while (proto && !proto.hasOwnProperty(name)) // ← crashes on null-proto
|
|
13
|
+
* proto = Object.getPrototypeOf(proto);
|
|
14
|
+
*
|
|
15
|
+
* `@nativescript/core/index.js` re-exports several sub-modules as namespaces:
|
|
16
|
+
*
|
|
17
|
+
* export * as Utils from './utils';
|
|
18
|
+
* export * as Http from './http';
|
|
19
|
+
* export * as Connectivity from './connectivity';
|
|
20
|
+
* export * as ApplicationSettings from './application-settings';
|
|
21
|
+
*
|
|
22
|
+
* When bundle.mjs does `import { Utils } from '@nativescript/core'`, `Utils`
|
|
23
|
+
* binds to that null-proto sub-namespace. zone.js then does
|
|
24
|
+
* `patchMethod(Utils, 'mainThreadify', …)` and crashes.
|
|
25
|
+
*
|
|
26
|
+
* WHY globalThis.require shims ALONE DON'T FIX THIS
|
|
27
|
+
* -------------------------------------------------
|
|
28
|
+
* ESM imports never pass through `globalThis.require`. They go through the
|
|
29
|
+
* host's ESM linker (V8 on iOS). Shimming `require` only intercepts the CJS
|
|
30
|
+
* path (vendor packages that use `require('@nativescript/core')`); direct
|
|
31
|
+
* ESM imports of `Utils` still see the raw null-proto namespace.
|
|
32
|
+
*
|
|
33
|
+
* THE FIX
|
|
34
|
+
* -------
|
|
35
|
+
* Rewrite `export * as X from 'Y'` at the /ns/core bridge response level:
|
|
36
|
+
*
|
|
37
|
+
* // before
|
|
38
|
+
* export * as Utils from './utils';
|
|
39
|
+
*
|
|
40
|
+
* // after
|
|
41
|
+
* import * as __ns_re_Utils__ from './utils';
|
|
42
|
+
* export const Utils = __NS_CJS_SHAPE__(__ns_re_Utils__);
|
|
43
|
+
*
|
|
44
|
+
* Now `Utils` is a plain Object (inherits Object.prototype). Zone.js's
|
|
45
|
+
* `patchMethod(Utils, ...)` succeeds. The shape function is recursive —
|
|
46
|
+
* nested namespaces get the same treatment — and identity-preserving
|
|
47
|
+
* (WeakMap-cached) so mutations stick across lookups.
|
|
48
|
+
*
|
|
49
|
+
* WHY THE SHAPE INSTALL MUST RUN IN MODULE BODY (NOT FOOTER)
|
|
50
|
+
* ---------------------------------------------------------
|
|
51
|
+
* `export const Utils = __NS_CJS_SHAPE__(__ns_re_Utils__)` is body code. It
|
|
52
|
+
* executes during module evaluation, BEFORE the registration footer. So the
|
|
53
|
+
* shape function must be installed as a body-level statement that runs
|
|
54
|
+
* before the rewritten body — we can't rely on the footer's install.
|
|
55
|
+
*
|
|
56
|
+
* Each served /ns/core module independently installs the shape function via
|
|
57
|
+
* an idempotent `|| (globalThis.__NS_CJS_SHAPE__ = ...)` assignment. The
|
|
58
|
+
* first module to evaluate wins; subsequent evaluations are no-ops. This
|
|
59
|
+
* also handles dependency-before-importer order (depth-first ESM eval):
|
|
60
|
+
* `/ns/core/utils` evaluates before `/ns/core` main, so the shape helper
|
|
61
|
+
* is in place whenever any body needs it.
|
|
62
|
+
*/
|
|
63
|
+
/**
|
|
64
|
+
* Body-code statements that idempotently install `globalThis.__NS_CJS_SHAPE__`
|
|
65
|
+
* and `globalThis.__NS_CJS_SHAPE_CACHE__`. Must execute BEFORE any transformed
|
|
66
|
+
* `export const X = __NS_CJS_SHAPE__(...)` statement in the same module.
|
|
67
|
+
*
|
|
68
|
+
* Properties:
|
|
69
|
+
* - Recursive: traverses nested namespaces so `Utils.Something` is also
|
|
70
|
+
* a plain Object (if that sub-namespace is itself null-proto).
|
|
71
|
+
* - Identity-preserving: WeakMap keyed on the underlying ESM namespace.
|
|
72
|
+
* zone.js mutates its patch target; a fresh copy per call would lose
|
|
73
|
+
* mutations. Every lookup of the same namespace returns the same
|
|
74
|
+
* shaped object.
|
|
75
|
+
* - Cycle-safe: records the output in the cache BEFORE recursing into
|
|
76
|
+
* children. Handles `core ↔ platform` style cycles.
|
|
77
|
+
* - TDZ-safe: wraps each property read in try/catch. Some exports
|
|
78
|
+
* (Angular zone.js with early-access patterns) are still in their
|
|
79
|
+
* temporal dead zone when the namespace is first snapshotted. A thrown
|
|
80
|
+
* property read is skipped rather than failing the whole shape.
|
|
81
|
+
*/
|
|
82
|
+
export function buildShapeInstallHeader() {
|
|
83
|
+
return [
|
|
84
|
+
`/* Invariant D: CJS/ESM interop shape installer */`,
|
|
85
|
+
`try { if (typeof globalThis !== 'undefined') {`,
|
|
86
|
+
` const __nsShapeCache = globalThis.__NS_CJS_SHAPE_CACHE__ || (globalThis.__NS_CJS_SHAPE_CACHE__ = new WeakMap());`,
|
|
87
|
+
` if (typeof globalThis.__NS_CJS_SHAPE__ !== 'function') {`,
|
|
88
|
+
` globalThis.__NS_CJS_SHAPE__ = function __nsShape(obj) {`,
|
|
89
|
+
` if (!obj || typeof obj !== 'object') return obj;`,
|
|
90
|
+
` let isNsModule = false;`,
|
|
91
|
+
` try { isNsModule = obj[Symbol.toStringTag] === 'Module'; } catch (e) {}`,
|
|
92
|
+
` const proto = Object.getPrototypeOf(obj);`,
|
|
93
|
+
` if (proto !== null && !isNsModule) return obj;`,
|
|
94
|
+
` if (__nsShapeCache.has(obj)) return __nsShapeCache.get(obj);`,
|
|
95
|
+
` const out = {};`,
|
|
96
|
+
` __nsShapeCache.set(obj, out);`,
|
|
97
|
+
` try {`,
|
|
98
|
+
` const keys = Object.keys(obj);`,
|
|
99
|
+
` for (let i = 0; i < keys.length; i++) {`,
|
|
100
|
+
` const k = keys[i];`,
|
|
101
|
+
` try { out[k] = __nsShape(obj[k]); } catch (e) { /* TDZ / unreadable */ }`,
|
|
102
|
+
` }`,
|
|
103
|
+
` } catch (e) {}`,
|
|
104
|
+
` return out;`,
|
|
105
|
+
` };`,
|
|
106
|
+
` }`,
|
|
107
|
+
`} } catch (e) { console.warn('[ns-core] shape installer failed:', (e && e.message) || e); }`,
|
|
108
|
+
].join('\n');
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Rewrite namespace re-exports from CJS-incompatible ESM namespace form into
|
|
112
|
+
* shape-aware const exports. Handles the two forms Vite/esbuild may emit:
|
|
113
|
+
*
|
|
114
|
+
* (1) Original ES2020 syntax preserved unchanged:
|
|
115
|
+
* export * as X from 'Y';
|
|
116
|
+
*
|
|
117
|
+
* (2) Transpiled form esbuild emits when targeting older ES:
|
|
118
|
+
* import * as _foo from 'Y';
|
|
119
|
+
* export { _foo as X };
|
|
120
|
+
*
|
|
121
|
+
* Both become:
|
|
122
|
+
* import * as __ns_re_X__ from 'Y';
|
|
123
|
+
* export const X = __NS_CJS_SHAPE__(__ns_re_X__);
|
|
124
|
+
*
|
|
125
|
+
* Notes on the transform:
|
|
126
|
+
* - The internal binding uses a derived name (`__ns_re_<X>__`) so
|
|
127
|
+
* collisions with user bindings are extremely unlikely. Core doesn't
|
|
128
|
+
* declare identifiers matching that shape.
|
|
129
|
+
* - `__NS_CJS_SHAPE__` is read from globalThis with a defensive fallback
|
|
130
|
+
* (identity function) in case installation failed or runs in an
|
|
131
|
+
* environment where it hasn't been initialized yet. This makes the
|
|
132
|
+
* transform safe to apply to modules that don't always go through the
|
|
133
|
+
* /ns/core handler's headers.
|
|
134
|
+
* - We do NOT shape `export *` (star re-exports without alias). Those
|
|
135
|
+
* spread individual named exports — they don't create a nested
|
|
136
|
+
* namespace and aren't affected by the null-proto issue.
|
|
137
|
+
* - We do NOT shape `export { x } from 'y'` forms. Those copy individual
|
|
138
|
+
* named exports directly; the consumer never sees the namespace.
|
|
139
|
+
*
|
|
140
|
+
* The regex is intentionally precise. It matches only the `export * as X from
|
|
141
|
+
* 'Y'` syntactic form (and its transpiled equivalent) — no accidental matches
|
|
142
|
+
* in string literals or comments because those can't start a top-level
|
|
143
|
+
* statement with `export`.
|
|
144
|
+
*/
|
|
145
|
+
export function rewriteNamespaceReExportsForShape(code) {
|
|
146
|
+
const shapeExpr = `(typeof globalThis.__NS_CJS_SHAPE__ === 'function' ? globalThis.__NS_CJS_SHAPE__ : function (x) { return x; })`;
|
|
147
|
+
// Form (1): export * as X from 'Y'; (ES2020 aggregate re-export)
|
|
148
|
+
let out = code.replace(/(^|\n)(\s*)export\s+\*\s+as\s+([A-Za-z_$][\w$]*)\s+from\s+(['"`])([^'"`\n]+)\4\s*;?/g, (_match, prefix, indent, name, quote, spec) => {
|
|
149
|
+
const internal = `__ns_re_${name}__`;
|
|
150
|
+
return `${prefix}${indent}import * as ${internal} from ${quote}${spec}${quote};\n${indent}export const ${name} = ${shapeExpr}(${internal});`;
|
|
151
|
+
});
|
|
152
|
+
// Form (2): import * as _x from 'Y'; export { _x as X };
|
|
153
|
+
// This pattern appears when esbuild targets older ES. We detect the pair
|
|
154
|
+
// by matching the import and its paired export on the same or adjacent
|
|
155
|
+
// lines. Rather than try to join two regex passes, we transform the
|
|
156
|
+
// `export { _x as X }` branch by replacing the `_x` in the export with a
|
|
157
|
+
// shape-wrapped const. Keeping the import intact is safe because the
|
|
158
|
+
// local binding is still needed for the shape call.
|
|
159
|
+
out = out.replace(/export\s*\{\s*([A-Za-z_$][\w$]*)\s+as\s+([A-Za-z_$][\w$]*)\s*\}\s*;?/g, (match, localName, exportName) => {
|
|
160
|
+
// Only transform if the local name looks like an esbuild-generated
|
|
161
|
+
// namespace binding (leading underscore) AND the export name is a
|
|
162
|
+
// PascalCase identifier. This avoids touching user re-exports.
|
|
163
|
+
if (!/^_/.test(localName))
|
|
164
|
+
return match;
|
|
165
|
+
if (!/^[A-Z]/.test(exportName))
|
|
166
|
+
return match;
|
|
167
|
+
return `export const ${exportName} = ${shapeExpr}(${localName});`;
|
|
168
|
+
});
|
|
169
|
+
return out;
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* Convenience: returns true if the given code appears to contain at least one
|
|
173
|
+
* namespace re-export that would benefit from the shape transform. Used to
|
|
174
|
+
* skip the regex replace for modules that don't need it (keeps the response
|
|
175
|
+
* identical for most submodules, which just have plain `export * from` or
|
|
176
|
+
* named exports).
|
|
177
|
+
*/
|
|
178
|
+
export function hasNamespaceReExport(code) {
|
|
179
|
+
return /export\s+\*\s+as\s+[A-Za-z_$][\w$]*\s+from\s+['"`]/.test(code);
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* Default-export bridge footer.
|
|
183
|
+
*
|
|
184
|
+
* BACKGROUND
|
|
185
|
+
* ----------
|
|
186
|
+
* Upstream consumer rewrites in the /ns/m handler convert
|
|
187
|
+
* `import { X } from '@nativescript/core'` into
|
|
188
|
+
* `import __ns_core_ns from '/ns/core'; const { X } = __ns_core_ns;`
|
|
189
|
+
* — a DEFAULT import followed by destructuring. The inline comment on that
|
|
190
|
+
* rewrite says explicitly: "This makes `import { Frame } from
|
|
191
|
+
* '@nativescript/core'` work even if the bridge provides only a default
|
|
192
|
+
* export."
|
|
193
|
+
*
|
|
194
|
+
* The original `@nativescript/core/index.js` has no `export default` — all
|
|
195
|
+
* named exports. Without this footer, consumers of the transformed import
|
|
196
|
+
* fail at ESM link time:
|
|
197
|
+
*
|
|
198
|
+
* SyntaxError: The requested module '/ns/core/<ver>' does not
|
|
199
|
+
* provide an export named 'default'
|
|
200
|
+
*
|
|
201
|
+
* THE FIX
|
|
202
|
+
* -------
|
|
203
|
+
* Emit `export default __ns_core_self_ns__;` at the end of the served
|
|
204
|
+
* module body. `__ns_core_self_ns__` is the namespace import the server
|
|
205
|
+
* already emits at the top of every /ns/core response for self-
|
|
206
|
+
* registration purposes. ESM spec guarantees a module re-entering itself
|
|
207
|
+
* during evaluation returns the in-progress namespace — so no extra
|
|
208
|
+
* evaluation occurs, and the default binding receives an object whose
|
|
209
|
+
* properties are every named export of the same module.
|
|
210
|
+
*
|
|
211
|
+
* CONSUMER MATRIX AFTER THIS FIX
|
|
212
|
+
* ------------------------------
|
|
213
|
+
* • `import X from '/ns/core'` (default) → X = self namespace
|
|
214
|
+
* • `import * as X from '/ns/core'` → X = self namespace + X.default = self
|
|
215
|
+
* • `import { X } from '/ns/core'` (named) → individual named binding (untouched)
|
|
216
|
+
* • `const { X } = <default-import>` → destructure from self namespace
|
|
217
|
+
* • `require('@nativescript/core')` (CJS) → shaped self via registry
|
|
218
|
+
*
|
|
219
|
+
* SKIP CONDITIONS
|
|
220
|
+
* ---------------
|
|
221
|
+
* Returns empty string when the source already declares a default export
|
|
222
|
+
* (some deep subpaths do — e.g. a file that does `export default MyClass`
|
|
223
|
+
* would SyntaxError on a duplicate). The consumer rewrite is also gated
|
|
224
|
+
* on `isDeepCoreSubpath`, so those paths don't normally hit the default-
|
|
225
|
+
* import pattern anyway.
|
|
226
|
+
*
|
|
227
|
+
* WHY THE DEFAULT ISN'T SHAPED
|
|
228
|
+
* ----------------------------
|
|
229
|
+
* The default is the raw null-proto MNO. This is intentional:
|
|
230
|
+
*
|
|
231
|
+
* 1. All current default-import consumers either destructure or do
|
|
232
|
+
* property access. Neither requires Object.prototype in the chain.
|
|
233
|
+
* 2. Shaping the default inside the module body would require calling
|
|
234
|
+
* __NS_CJS_SHAPE__ on a namespace whose own `default` slot is still
|
|
235
|
+
* being initialized — temporal dead zone hazard.
|
|
236
|
+
* 3. CJS consumers that need `.hasOwnProperty` go through the registry
|
|
237
|
+
* (shaped at registration), not through the default import.
|
|
238
|
+
*
|
|
239
|
+
* If a future consumer surfaces that calls `.hasOwnProperty` on the
|
|
240
|
+
* default, we can revisit. The current rule-of-least-surprise is:
|
|
241
|
+
* shape at the CJS boundary, not at the ESM boundary.
|
|
242
|
+
*/
|
|
243
|
+
export function buildDefaultExportFooter(rewrittenCode) {
|
|
244
|
+
if (hasExistingDefaultExport(rewrittenCode))
|
|
245
|
+
return '';
|
|
246
|
+
return ['/* Default-export bridge for /ns/core consumers */', 'export default __ns_core_self_ns__;'].join('\n');
|
|
247
|
+
}
|
|
248
|
+
/**
|
|
249
|
+
* Detects whether a module body already declares a default export in any of
|
|
250
|
+
* the syntactic forms the ESM spec allows. Mirrors the logic in
|
|
251
|
+
* `websocket-core-bridge.ts:hasModuleDefaultExport` — kept here so the
|
|
252
|
+
* default-export bridge helper is self-contained and unit-testable.
|
|
253
|
+
*
|
|
254
|
+
* Handles:
|
|
255
|
+
* - `export default <expr>;`
|
|
256
|
+
* - `export default function|class ...`
|
|
257
|
+
* - `export { x as default };`
|
|
258
|
+
* - `export { default };` (implicit `default as default`)
|
|
259
|
+
* - `export { default as default };`
|
|
260
|
+
* - `export { foo, default };`
|
|
261
|
+
*/
|
|
262
|
+
export function hasExistingDefaultExport(code) {
|
|
263
|
+
if (!code || typeof code !== 'string')
|
|
264
|
+
return false;
|
|
265
|
+
if (/\bexport\s+default\b/.test(code))
|
|
266
|
+
return true;
|
|
267
|
+
if (/\bexport\s*\{[^}]*\bdefault\b[^}]*\}/.test(code))
|
|
268
|
+
return true;
|
|
269
|
+
return false;
|
|
270
|
+
}
|
|
271
|
+
//# sourceMappingURL=ns-core-cjs-shape.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ns-core-cjs-shape.js","sourceRoot":"","sources":["../../../../../packages/vite/hmr/server/ns-core-cjs-shape.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6DG;AAEH;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,UAAU,uBAAuB;IACtC,OAAO;QACN,oDAAoD;QACpD,gDAAgD;QAChD,oHAAoH;QACpH,4DAA4D;QAC5D,6DAA6D;QAC7D,wDAAwD;QACxD,+BAA+B;QAC/B,+EAA+E;QAC/E,iDAAiD;QACjD,sDAAsD;QACtD,oEAAoE;QACpE,uBAAuB;QACvB,qCAAqC;QACrC,aAAa;QACb,wCAAwC;QACxC,iDAAiD;QACjD,8BAA8B;QAC9B,oFAAoF;QACpF,WAAW;QACX,sBAAsB;QACtB,mBAAmB;QACnB,QAAQ;QACR,KAAK;QACL,6FAA6F;KAC7F,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AACd,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AACH,MAAM,UAAU,iCAAiC,CAAC,IAAY;IAC7D,MAAM,SAAS,GAAG,gHAAgH,CAAC;IAEnI,kEAAkE;IAClE,IAAI,GAAG,GAAG,IAAI,CAAC,OAAO,CAAC,sFAAsF,EAAE,CAAC,MAAM,EAAE,MAAc,EAAE,MAAc,EAAE,IAAY,EAAE,KAAa,EAAE,IAAY,EAAE,EAAE;QACpM,MAAM,QAAQ,GAAG,WAAW,IAAI,IAAI,CAAC;QACrC,OAAO,GAAG,MAAM,GAAG,MAAM,eAAe,QAAQ,SAAS,KAAK,GAAG,IAAI,GAAG,KAAK,MAAM,MAAM,gBAAgB,IAAI,MAAM,SAAS,IAAI,QAAQ,IAAI,CAAC;IAC9I,CAAC,CAAC,CAAC;IAEH,yDAAyD;IACzD,yEAAyE;IACzE,uEAAuE;IACvE,oEAAoE;IACpE,yEAAyE;IACzE,qEAAqE;IACrE,oDAAoD;IACpD,GAAG,GAAG,GAAG,CAAC,OAAO,CAAC,uEAAuE,EAAE,CAAC,KAAK,EAAE,SAAiB,EAAE,UAAkB,EAAE,EAAE;QAC3I,mEAAmE;QACnE,kEAAkE;QAClE,+DAA+D;QAC/D,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC;YAAE,OAAO,KAAK,CAAC;QACxC,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,UAAU,CAAC;YAAE,OAAO,KAAK,CAAC;QAC7C,OAAO,gBAAgB,UAAU,MAAM,SAAS,IAAI,SAAS,IAAI,CAAC;IACnE,CAAC,CAAC,CAAC;IAEH,OAAO,GAAG,CAAC;AACZ,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,oBAAoB,CAAC,IAAY;IAChD,OAAO,oDAAoD,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AACxE,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6DG;AACH,MAAM,UAAU,wBAAwB,CAAC,aAAqB;IAC7D,IAAI,wBAAwB,CAAC,aAAa,CAAC;QAAE,OAAO,EAAE,CAAC;IACvD,OAAO,CAAC,oDAAoD,EAAE,qCAAqC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AACjH,CAAC;AAED;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,wBAAwB,CAAC,IAAY;IACpD,IAAI,CAAC,IAAI,IAAI,OAAO,IAAI,KAAK,QAAQ;QAAE,OAAO,KAAK,CAAC;IACpD,IAAI,sBAAsB,CAAC,IAAI,CAAC,IAAI,CAAC;QAAE,OAAO,IAAI,CAAC;IACnD,IAAI,sCAAsC,CAAC,IAAI,CAAC,IAAI,CAAC;QAAE,OAAO,IAAI,CAAC;IACnE,OAAO,KAAK,CAAC;AACd,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,IAAI,CAAC,IAAI,CAAC,sBAAsB,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC;YAC3H,WAAW,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QACvB,CAAC;IACF,CAAC;IACD,MAAM,gBAAgB,GAAG,KAAK,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC,IAAI,EAAE,CAAC;IAExD,MAAM,kBAAkB,GAAG,gBAAgB,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,gBAAgB,CAAC,kBAAkB,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC5G,MAAM,cAAc,GAAG,gBAAgB,CAAC,MAAM,CAAC,CAAC,aAAa,EAAE,eAAe,EAAE,YAAY,EAAE,mBAAmB,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAE/H,MAAM,IAAI,GACT,sFAAsF;QACtF,sFAAsF;QACtF,uFAAuF;QACvF,uFAAuF;QACvF,yFAAyF;QACzF,wDAAwD;QACxD,+IAA+I;QAC/I,uEAAuE;QACvE,sEAAsE;QACtE,sEAAsE;QACtE,uEAAuE;QACvE,qEAAqE;QACrE,qIAAqI;QACrI,yBAAyB;QACzB,qDAAqD;QACrD,oHAAoH;QACpH,2BAA2B;QAC3B,2BAA2B;QAC3B,gGAAgG;QAChG,8OAA8O;QAC9O,wBAAwB;QACxB,0CAA0C;QAC1C,oBAAoB;QACpB,qKAAqK;QACrK,2IAA2I;QAC3I,kDAAkD;QAClD,uBAAuB;QACvB,uBAAuB;QACvB,gBAAgB;QAChB,KAAK;QACL,sEAAsE;QACtE,oEAAoE;QACpE,iEAAiE;QACjE,oEAAoE;QACpE,qEAAqE;QACrE,gDAAgD;QAChD,SAAS;QACT,kEAAkE;QAClE,gBAAgB;QAChB,yMAAyM;QACzM,iBAAiB;QACjB,uDAAuD;QACvD,mDAAmD;QACnD,mIAAmI;QACnI,SAAS;QACT,OAAO;QACP,cAAc;QACd,0CAA0C;QAC1C,wEAAwE;QACxE,kBAAkB;QAClB,IAAI;QACJ,qEAAqE;QACrE,sEAAsE;QACtE,iEAAiE;QACjE,gCAAgC;QAChC,kpCAAkpC;QAClpC,02BAA02B;QAC12B,yXAAyX;QACzX,6EAA6E;QAC7E,8DAA8D;QAC9D,8CAA8C;QAC9C,uDAAuD;QACvD,kDAAkD;QAClD,iCAAiC;QACjC,+GAA+G;QAC/G,mGAAmG;QACnG,MAAM;QACN,oBAAoB,cAAc,OAAO,CAAC;IAE3C,OAAO,OAAO,CAAC,mBAAmB,GAAG,IAAI,CAAC;AAC3C,CAAC;AAED;;;;;;;;;;GAUG;AACH,MAAM,UAAU,wBAAwB,CAAC,WAAmB;IAC3D,MAAM,GAAG,GAAG,IAAI,GAAG,EAAU,CAAC;IAC9B,MAAM,KAAK,GAAG,uBAAuB,CAAC,kBAAkB,EAAE,WAAW,CAAC,CAAC;IACvE,KAAK,MAAM,CAAC,IAAI,KAAK,CAAC,KAAK,EAAE,CAAC;QAC7B,IAAI,OAAO,CAAC,KAAK,QAAQ,IAAI,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC;YAAE,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;IAC3D,CAAC;IACD,OAAO,GAAG,CAAC;AACZ,CAAC"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { getProjectRootPath } from '../../helpers/project.js';
|
|
2
|
+
import { buildNsRtBridgeModule, discoverNsvBridgeExports } from './ns-rt-bridge.js';
|
|
3
|
+
import { REQUIRE_GUARD_SNIPPET } from './require-guard.js';
|
|
4
|
+
import { setDeviceModuleHeaders } from './route-helpers.js';
|
|
5
|
+
// ESM runtime bridge for NativeScript-Vue: `GET /ns/rt[/<ver>]`.
|
|
6
|
+
//
|
|
7
|
+
// Serves a single authoritative source of Vue helpers bound to the
|
|
8
|
+
// NativeScript renderer. The bridge lazily resolves helpers from the vendor
|
|
9
|
+
// registry on first evaluation (it does not statically import `vue`), then
|
|
10
|
+
// re-exports them so SFCs can call them during module evaluation. The shared
|
|
11
|
+
// `buildNsRtBridgeModule` owns the body (preamble, passthroughs, HMR shims,
|
|
12
|
+
// polyfills, default export); discovery is the only source of truth for which
|
|
13
|
+
// vendor symbols are forwarded.
|
|
14
|
+
export function registerNsRtBridgeRoute(server, options) {
|
|
15
|
+
server.middlewares.use(async (req, res, next) => {
|
|
16
|
+
try {
|
|
17
|
+
const urlObj = new URL(req.url || '', 'http://localhost');
|
|
18
|
+
// Accept only /ns/rt and /ns/rt/<ver> for cache-busting semantics
|
|
19
|
+
if (!(urlObj.pathname === '/ns/rt' || /^\/ns\/rt\/[\d]+$/.test(urlObj.pathname)))
|
|
20
|
+
return next();
|
|
21
|
+
setDeviceModuleHeaders(res);
|
|
22
|
+
const rtVerSeg = urlObj.pathname.replace(/^\/ns\/rt\/?/, '');
|
|
23
|
+
const rtVer = /^[0-9]+$/.test(rtVerSeg) ? rtVerSeg : String(options.getGraphVersion() || 0);
|
|
24
|
+
const vendorExports = discoverNsvBridgeExports(getProjectRootPath());
|
|
25
|
+
const code = buildNsRtBridgeModule({ rtVer, requireGuardSnippet: REQUIRE_GUARD_SNIPPET, vendorExports });
|
|
26
|
+
res.statusCode = 200;
|
|
27
|
+
res.end(code);
|
|
28
|
+
}
|
|
29
|
+
catch {
|
|
30
|
+
res.statusCode = 500;
|
|
31
|
+
res.end('export {}\n');
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
//# sourceMappingURL=ns-rt-route.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ns-rt-route.js","sourceRoot":"","sources":["../../../../../packages/vite/hmr/server/ns-rt-route.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AAC9D,OAAO,EAAE,qBAAqB,EAAE,wBAAwB,EAAE,MAAM,mBAAmB,CAAC;AACpF,OAAO,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAC;AAC3D,OAAO,EAAE,sBAAsB,EAAE,MAAM,oBAAoB,CAAC;AAQ5D,iEAAiE;AACjE,EAAE;AACF,mEAAmE;AACnE,4EAA4E;AAC5E,2EAA2E;AAC3E,6EAA6E;AAC7E,4EAA4E;AAC5E,8EAA8E;AAC9E,gCAAgC;AAChC,MAAM,UAAU,uBAAuB,CAAC,MAAqB,EAAE,OAAyB;IACvF,MAAM,CAAC,WAAW,CAAC,GAAG,CAAC,KAAK,EAAE,GAAG,EAAE,GAAG,EAAE,IAAI,EAAE,EAAE;QAC/C,IAAI,CAAC;YACJ,MAAM,MAAM,GAAG,IAAI,GAAG,CAAC,GAAG,CAAC,GAAG,IAAI,EAAE,EAAE,kBAAkB,CAAC,CAAC;YAC1D,kEAAkE;YAClE,IAAI,CAAC,CAAC,MAAM,CAAC,QAAQ,KAAK,QAAQ,IAAI,mBAAmB,CAAC,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;gBAAE,OAAO,IAAI,EAAE,CAAC;YAChG,sBAAsB,CAAC,GAAG,CAAC,CAAC;YAC5B,MAAM,QAAQ,GAAG,MAAM,CAAC,QAAQ,CAAC,OAAO,CAAC,cAAc,EAAE,EAAE,CAAC,CAAC;YAC7D,MAAM,KAAK,GAAG,UAAU,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,eAAe,EAAE,IAAI,CAAC,CAAC,CAAC;YAC5F,MAAM,aAAa,GAAG,wBAAwB,CAAC,kBAAkB,EAAE,CAAC,CAAC;YACrE,MAAM,IAAI,GAAG,qBAAqB,CAAC,EAAE,KAAK,EAAE,mBAAmB,EAAE,qBAAqB,EAAE,aAAa,EAAE,CAAC,CAAC;YACzG,GAAG,CAAC,UAAU,GAAG,GAAG,CAAC;YACrB,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QACf,CAAC;QAAC,MAAM,CAAC;YACR,GAAG,CAAC,UAAU,GAAG,GAAG,CAAC;YACrB,GAAG,CAAC,GAAG,CAAC,aAAa,CAAC,CAAC;QACxB,CAAC;IACF,CAAC,CAAC,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
export type ServerStartupBannerInput = {
|
|
2
|
+
version: string;
|
|
3
|
+
transformConcurrency: number;
|
|
4
|
+
transformCacheMs: number;
|
|
5
|
+
lazyInitialGraph: boolean;
|
|
6
|
+
graphVersion: number;
|
|
7
|
+
};
|
|
8
|
+
export declare function formatServerStartupBanner(input: ServerStartupBannerInput): string;
|
|
9
|
+
/**
|
|
10
|
+
* Classify a URL path into a coarse route category. Any pathname that
|
|
11
|
+
* doesn't match a known NativeScript dev route is reported as `other`;
|
|
12
|
+
* callers are expected to filter their own irrelevant routes before
|
|
13
|
+
* calling `record()`.
|
|
14
|
+
*/
|
|
15
|
+
export declare function classifyBootRoute(pathname: string): BootRouteCategory;
|
|
16
|
+
export type BootRouteCategory = 'ns/m' | 'ns/rt' | 'ns/core' | 'ns/vendor' | 'ns/import-map' | 'ns/boot' | 'ns/hmr' | 'ns/other' | 'other';
|
|
17
|
+
export type ColdBootRequestCounter = {
|
|
18
|
+
record: (url: string) => RecordHandle;
|
|
19
|
+
finalize: () => void;
|
|
20
|
+
getState: () => ColdBootCounterState;
|
|
21
|
+
};
|
|
22
|
+
export type RecordHandle = {
|
|
23
|
+
finish: () => void;
|
|
24
|
+
};
|
|
25
|
+
export type ColdBootCounterState = {
|
|
26
|
+
active: boolean;
|
|
27
|
+
count: number;
|
|
28
|
+
inFlight: number;
|
|
29
|
+
maxConcurrent: number;
|
|
30
|
+
startedAt: number | null;
|
|
31
|
+
firstRequestUrl: string | null;
|
|
32
|
+
perRoute: Partial<Record<BootRouteCategory, number>>;
|
|
33
|
+
};
|
|
34
|
+
export type ColdBootCounterOptions = {
|
|
35
|
+
/**
|
|
36
|
+
* Emit a rolling summary every N requests (default 100). Lower the
|
|
37
|
+
* threshold in tests to keep them snappy. Set to 0 to disable rolling
|
|
38
|
+
* summaries; a final summary still fires from `finalize()`.
|
|
39
|
+
*/
|
|
40
|
+
summaryEvery?: number;
|
|
41
|
+
/**
|
|
42
|
+
* Cold-boot window closes when no new requests arrive within this
|
|
43
|
+
* idle window (default 5000ms). The HMR edit loop reuses the same
|
|
44
|
+
* handler, but it never bursts as heavily as cold boot. Raise this
|
|
45
|
+
* via `NS_VITE_HMR_BOOT_TRACE_IDLE_MS` when profiling a slow boot
|
|
46
|
+
* so inter-wave pauses don't close the counter prematurely.
|
|
47
|
+
*/
|
|
48
|
+
idleWindowMs?: number;
|
|
49
|
+
/** Defaults to `Date.now`; tests inject a deterministic clock. */
|
|
50
|
+
now?: () => number;
|
|
51
|
+
/** Defaults to `setTimeout`; tests can inject a fake timer. */
|
|
52
|
+
setTimer?: (handler: () => void, ms: number) => unknown;
|
|
53
|
+
/** Defaults to `clearTimeout`; tests can inject a fake timer. */
|
|
54
|
+
clearTimer?: (handle: unknown) => void;
|
|
55
|
+
/** Logger called for every summary line (rolling + final). */
|
|
56
|
+
log: (line: string) => void;
|
|
57
|
+
};
|
|
58
|
+
export declare function createColdBootRequestCounter(options: ColdBootCounterOptions): ColdBootRequestCounter;
|
|
59
|
+
export type PopulateInitialGraphSummary = {
|
|
60
|
+
moduleCount: number;
|
|
61
|
+
durationMs: number;
|
|
62
|
+
graphVersion: number;
|
|
63
|
+
bumpedVersion: boolean;
|
|
64
|
+
};
|
|
65
|
+
export declare function formatPopulateInitialGraphSummary(input: PopulateInitialGraphSummary): string;
|
|
66
|
+
export type HmrUpdateKind = 'ts' | 'html' | 'css' | 'vue' | 'tsx' | 'jsx' | 'js' | 'mjs' | 'unknown';
|
|
67
|
+
/**
|
|
68
|
+
* Classify a file's HMR update kind by extension. Used by the server-side
|
|
69
|
+
* update summary so a quick log line tells us which pipeline ran. Returns
|
|
70
|
+
* `'unknown'` for anything that doesn't match a known dev-time extension —
|
|
71
|
+
* the caller decides whether to log it or skip it entirely.
|
|
72
|
+
*/
|
|
73
|
+
export declare function classifyHmrUpdateKind(file: string): HmrUpdateKind;
|
|
74
|
+
export type HmrUpdateSummary = {
|
|
75
|
+
/** Project-relative or absolute path of the file that triggered HMR. */
|
|
76
|
+
file: string;
|
|
77
|
+
/** File classification. */
|
|
78
|
+
kind: HmrUpdateKind;
|
|
79
|
+
/** Time spent waiting for `populateInitialGraph` to complete (ms). */
|
|
80
|
+
awaitMs: number;
|
|
81
|
+
/** Time spent in framework-specific work (graph updates, invalidation). */
|
|
82
|
+
frameworkMs: number;
|
|
83
|
+
/** Time spent broadcasting the WebSocket message. */
|
|
84
|
+
broadcastMs: number;
|
|
85
|
+
/** End-to-end handler time. */
|
|
86
|
+
totalMs: number;
|
|
87
|
+
/** Number of modules invalidated by the update. */
|
|
88
|
+
invalidated: number;
|
|
89
|
+
/** Number of HMR clients the message was sent to. */
|
|
90
|
+
recipients: number;
|
|
91
|
+
/**
|
|
92
|
+
* Angular-only narrowing decision: whether transitive-importer
|
|
93
|
+
* invalidation was narrowed because the changed file lacks Angular
|
|
94
|
+
* semantic decorators (`@Component`/`@Directive`/`@Pipe`/`@Injectable`/
|
|
95
|
+
* `@NgModule`). `true` means narrow (importers preserved, ESM live
|
|
96
|
+
* bindings carry the change). `false` means broad (importers also
|
|
97
|
+
* invalidated). `null`/`undefined` means the field is not applicable
|
|
98
|
+
* to this update (e.g. CSS, non-Angular flavor) and the field is
|
|
99
|
+
* omitted from the summary line entirely.
|
|
100
|
+
*/
|
|
101
|
+
narrowed?: boolean | null;
|
|
102
|
+
};
|
|
103
|
+
/**
|
|
104
|
+
* Single-line summary for the server side of an HMR update. Always-on so
|
|
105
|
+
* a 6-second `.ts` save is immediately visible without flipping verbose.
|
|
106
|
+
* Format:
|
|
107
|
+
* [hmr-ws][update] kind=ts file=/src/foo.ts await=12ms framework=180ms broadcast=2ms total=194ms invalidated=23 recipients=1
|
|
108
|
+
*
|
|
109
|
+
* For Angular `.ts` updates, `narrowed=yes|no` is appended so the
|
|
110
|
+
* narrowing decision is immediately visible without flipping verbose:
|
|
111
|
+
* [hmr-ws][update] kind=ts file=/src/app/foo.constants.ts ... invalidated=1 recipients=1 narrowed=yes
|
|
112
|
+
* [hmr-ws][update] kind=ts file=/src/app/foo.component.ts ... invalidated=132 recipients=1 narrowed=no
|
|
113
|
+
*/
|
|
114
|
+
export declare function formatHmrUpdateSummary(input: HmrUpdateSummary): string;
|