@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
package/helpers/main-entry.js
CHANGED
|
@@ -2,10 +2,14 @@ import { getPackageJson, getProjectFilePath, getProjectRootPath } from './projec
|
|
|
2
2
|
import fs from 'fs';
|
|
3
3
|
import path from 'path';
|
|
4
4
|
import { preprocessCSS } from 'vite';
|
|
5
|
+
import { parse as parseCssToAst } from 'css';
|
|
5
6
|
import { getProjectFlavor } from './flavor.js';
|
|
6
7
|
import { getProjectAppPath, getProjectAppRelativePath, getProjectAppVirtualPath } from './utils.js';
|
|
7
8
|
import { getResolvedAppComponents } from './app-components.js';
|
|
8
9
|
import { toStaticImportSpecifier } from './import-specifier.js';
|
|
10
|
+
import { buildCoreUrl } from './ns-core-url.js';
|
|
11
|
+
import { resolveDeviceReachableOrigin } from './dev-host.js';
|
|
12
|
+
import { setAppCssState } from './app-css-state.js';
|
|
9
13
|
// Switched to runtime modules to avoid fragile string injection and enable TS checks
|
|
10
14
|
const projectRoot = getProjectRootPath();
|
|
11
15
|
const appRootDir = getProjectAppPath();
|
|
@@ -51,6 +55,35 @@ const APP_CSS_RESOLVED = '\0' + APP_CSS_VIRTUAL_ID;
|
|
|
51
55
|
// polyfill is installed during module evaluation (before zone.js patches run).
|
|
52
56
|
const XHR_POLYFILL_VIRTUAL_ID = 'virtual:ns-xhr-polyfill';
|
|
53
57
|
const XHR_POLYFILL_RESOLVED = '\0' + XHR_POLYFILL_VIRTUAL_ID;
|
|
58
|
+
// Virtual module that seeds compile-time defines (`__APPLE__`, `__IOS__`,
|
|
59
|
+
// `__DEV__`, etc.) on `globalThis` BEFORE any other module evaluates.
|
|
60
|
+
//
|
|
61
|
+
// Why this exists. The per-module shim that `processCodeForDevice` injects
|
|
62
|
+
// at the top of every served module reads these values from `globalThis`:
|
|
63
|
+
// const __APPLE__ = globalThis.__APPLE__ !== undefined
|
|
64
|
+
// ? globalThis.__APPLE__
|
|
65
|
+
// : (__IOS__ || __VISIONOS__);
|
|
66
|
+
// `const` evaluates ONCE at module instantiation. So every module needs
|
|
67
|
+
// `globalThis.__APPLE__` to already be set when it instantiates — otherwise
|
|
68
|
+
// it locks in `false` for the lifetime of the module.
|
|
69
|
+
//
|
|
70
|
+
// In ESM, all `import` statements hoist to the top of the module's
|
|
71
|
+
// evaluation phase: imports run in DFS post-order BEFORE the importing
|
|
72
|
+
// module's body. If we put the seed assignments inline in the entry's
|
|
73
|
+
// body (e.g. `globalThis.__APPLE__ = true`), they run AFTER every module
|
|
74
|
+
// transitively imported via `bundle-entry-points` (which reaches the
|
|
75
|
+
// user's `main.ts` → `app.module.ts` → services → util files). Those
|
|
76
|
+
// utility modules then snapshot `globalThis.__APPLE__ = undefined` and
|
|
77
|
+
// fall through to the `false` branch — landing iOS code in the
|
|
78
|
+
// `else { /* Android */ }` branch and crashing on `Utils.android.*`.
|
|
79
|
+
//
|
|
80
|
+
// The fix is to import this virtual module FIRST in the entry. As a leaf
|
|
81
|
+
// in the dependency graph it evaluates before every sibling import, so
|
|
82
|
+
// its body assignments happen before any user module instantiates and
|
|
83
|
+
// reads `globalThis.__*`. This is the architecturally-correct way to
|
|
84
|
+
// make values available to other modules across the import graph in ESM.
|
|
85
|
+
const DEFINES_SEED_VIRTUAL_ID = 'virtual:ns-defines-seed';
|
|
86
|
+
const DEFINES_SEED_RESOLVED = '\0' + DEFINES_SEED_VIRTUAL_ID;
|
|
54
87
|
export function mainEntryPlugin(opts) {
|
|
55
88
|
let resolvedConfig;
|
|
56
89
|
return {
|
|
@@ -58,6 +91,93 @@ export function mainEntryPlugin(opts) {
|
|
|
58
91
|
configResolved(config) {
|
|
59
92
|
resolvedConfig = config;
|
|
60
93
|
},
|
|
94
|
+
// Warm chokidar with `app.css`'s @import dependency tree at
|
|
95
|
+
// server startup. Without this, the FIRST save to a workspace
|
|
96
|
+
// `@import` dep (e.g. `<repo>/libs/.../index.css`) is silently
|
|
97
|
+
// dropped: nothing in the cold-boot path causes the dev server
|
|
98
|
+
// to transform `app.css`, so `vite:css` never registers
|
|
99
|
+
// `@import`-resolved deps with the watcher. Eagerly resolving
|
|
100
|
+
// them here breaks the chicken-and-egg.
|
|
101
|
+
//
|
|
102
|
+
// We ALSO stash the resolved dep set on the server itself so
|
|
103
|
+
// the HMR websocket handler can recognize when a non-CSS edit
|
|
104
|
+
// (e.g. a `.html` template or `.ts` file scanned by Tailwind's
|
|
105
|
+
// content config) should trigger a fresh `app.css` fetch. The
|
|
106
|
+
// `preprocessCSS` deps include every file PostCSS reported as
|
|
107
|
+
// a `dependency` message — for Tailwind 3 with content globs,
|
|
108
|
+
// Vite's `compileCSS` expands the `dir-dependency` glob into
|
|
109
|
+
// the individual file paths, so we get the full content set.
|
|
110
|
+
//
|
|
111
|
+
// `app.css` is NEVER a real Vite module in NS HMR (the virtual
|
|
112
|
+
// `:ns-app-css` module re-runs `preprocessCSS` in its load
|
|
113
|
+
// hook), so the standard moduleGraph `addWatchFile` →
|
|
114
|
+
// `_addedImports` → file-only-entry-importer chain doesn't
|
|
115
|
+
// populate, and `ctx.modules` for a content-file edit never
|
|
116
|
+
// links back to a CSS module. The dep set fills that gap.
|
|
117
|
+
configureServer(server) {
|
|
118
|
+
if (server.config.command !== 'serve')
|
|
119
|
+
return;
|
|
120
|
+
const appCssPath = path.resolve(projectRoot, getProjectAppRelativePath('app.css'));
|
|
121
|
+
if (!fs.existsSync(appCssPath))
|
|
122
|
+
return;
|
|
123
|
+
const normalizeFsPath = (p) => path.resolve(p).replace(/\\/g, '/');
|
|
124
|
+
const normalizedAppCssPath = normalizeFsPath(appCssPath);
|
|
125
|
+
const watchedDeps = new Set([normalizedAppCssPath]);
|
|
126
|
+
const refreshDeps = async () => {
|
|
127
|
+
try {
|
|
128
|
+
const code = fs.readFileSync(appCssPath, 'utf-8');
|
|
129
|
+
const result = await preprocessCSS(code, appCssPath, server.config);
|
|
130
|
+
server.watcher.add(appCssPath);
|
|
131
|
+
const next = new Set([normalizedAppCssPath]);
|
|
132
|
+
for (const dep of result?.deps ?? []) {
|
|
133
|
+
if (typeof dep === 'string' && dep) {
|
|
134
|
+
server.watcher.add(dep);
|
|
135
|
+
next.add(normalizeFsPath(dep));
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
// Atomic-ish replace: clear + repopulate the existing
|
|
139
|
+
// Set so any concurrent reader sees a consistent view
|
|
140
|
+
// when iterating with `.has()`.
|
|
141
|
+
watchedDeps.clear();
|
|
142
|
+
for (const f of next)
|
|
143
|
+
watchedDeps.add(f);
|
|
144
|
+
}
|
|
145
|
+
catch { }
|
|
146
|
+
};
|
|
147
|
+
setAppCssState(server, { path: normalizedAppCssPath, deps: watchedDeps });
|
|
148
|
+
refreshDeps();
|
|
149
|
+
// Re-scan when `app.css` itself or a Tailwind config file
|
|
150
|
+
// changes — Tailwind's content list and utility definitions
|
|
151
|
+
// can both shift, so the dep set has to follow. Debounced
|
|
152
|
+
// because watcher events for the same edit can fire in
|
|
153
|
+
// quick succession (chokidar's atomic save handling).
|
|
154
|
+
let pendingRefresh = null;
|
|
155
|
+
const scheduleRefresh = () => {
|
|
156
|
+
if (pendingRefresh)
|
|
157
|
+
clearTimeout(pendingRefresh);
|
|
158
|
+
pendingRefresh = setTimeout(() => {
|
|
159
|
+
pendingRefresh = null;
|
|
160
|
+
refreshDeps();
|
|
161
|
+
}, 50);
|
|
162
|
+
};
|
|
163
|
+
const isAppCssOrTailwindConfig = (file) => {
|
|
164
|
+
const normalized = normalizeFsPath(file);
|
|
165
|
+
if (normalized === normalizedAppCssPath)
|
|
166
|
+
return true;
|
|
167
|
+
return /\/tailwind\.config\.[mc]?[jt]s$/.test(normalized);
|
|
168
|
+
};
|
|
169
|
+
server.watcher.on('change', (file) => {
|
|
170
|
+
if (isAppCssOrTailwindConfig(file))
|
|
171
|
+
scheduleRefresh();
|
|
172
|
+
});
|
|
173
|
+
// `add`/`unlink` cover Tailwind's content set growing or
|
|
174
|
+
// shrinking — new template files, deleted partials, etc.
|
|
175
|
+
// Re-running `preprocessCSS` is the safest way to keep the
|
|
176
|
+
// glob expansion accurate without re-implementing the
|
|
177
|
+
// match.
|
|
178
|
+
server.watcher.on('add', scheduleRefresh);
|
|
179
|
+
server.watcher.on('unlink', scheduleRefresh);
|
|
180
|
+
},
|
|
61
181
|
resolveId(id) {
|
|
62
182
|
if (id === VIRTUAL_ID)
|
|
63
183
|
return RESOLVED;
|
|
@@ -65,19 +185,111 @@ export function mainEntryPlugin(opts) {
|
|
|
65
185
|
return APP_CSS_RESOLVED;
|
|
66
186
|
if (id === XHR_POLYFILL_VIRTUAL_ID)
|
|
67
187
|
return XHR_POLYFILL_RESOLVED;
|
|
188
|
+
if (id === DEFINES_SEED_VIRTUAL_ID)
|
|
189
|
+
return DEFINES_SEED_RESOLVED;
|
|
68
190
|
return null;
|
|
69
191
|
},
|
|
70
192
|
async load(id) {
|
|
71
|
-
//
|
|
72
|
-
//
|
|
73
|
-
//
|
|
74
|
-
//
|
|
193
|
+
// Compute the dev server origin for HMR mode. Under HMR we emit
|
|
194
|
+
// `@nativescript/core*` imports as FULL HTTP URLs so iOS's ESM loader
|
|
195
|
+
// can fetch them directly during bundle.mjs module instantiation —
|
|
196
|
+
// the import map isn't installed yet at that phase. For non-HMR
|
|
197
|
+
// builds, we keep bare specifiers so production bundlers inline core
|
|
198
|
+
// the normal way.
|
|
199
|
+
//
|
|
200
|
+
// Routes through `resolveDeviceReachableOrigin` so the URL baked
|
|
201
|
+
// into the bundle is something the DEVICE can reach: wildcard
|
|
202
|
+
// binds (`0.0.0.0`) and Android loopback get remapped to a real
|
|
203
|
+
// LAN IP (preferred) or the platform's reachable fallback
|
|
204
|
+
// (`10.0.2.2` for the Android emulator). Without this, Android
|
|
205
|
+
// crashes at boot trying to fetch `http://0.0.0.0:5173/ns/core/xhr`.
|
|
206
|
+
const getBootOrigin = () => {
|
|
207
|
+
if (!opts.hmrActive)
|
|
208
|
+
return null;
|
|
209
|
+
try {
|
|
210
|
+
const { origin } = resolveDeviceReachableOrigin({
|
|
211
|
+
host: resolvedConfig.server.host,
|
|
212
|
+
platform: opts.platform,
|
|
213
|
+
protocol: resolvedConfig.server.https || opts.useHttps ? 'https' : 'http',
|
|
214
|
+
port: Number(resolvedConfig.server.port || 5173),
|
|
215
|
+
});
|
|
216
|
+
return origin;
|
|
217
|
+
}
|
|
218
|
+
catch {
|
|
219
|
+
return null;
|
|
220
|
+
}
|
|
221
|
+
};
|
|
222
|
+
// Return a spec string for @nativescript/core or a subpath that is
|
|
223
|
+
// guaranteed to resolve at iOS module-instantiation time. Under HMR
|
|
224
|
+
// this is always a full HTTP URL into the /ns/core bridge (no
|
|
225
|
+
// import-map dependency). Under non-HMR it's the bare specifier for
|
|
226
|
+
// the bundler to handle.
|
|
227
|
+
//
|
|
228
|
+
// Under HMR, delegates to buildCoreUrl() — the ONE canonical URL
|
|
229
|
+
// generator. Every URL emitter in the build/runtime pipeline (this
|
|
230
|
+
// function, ns-core-external-urls, rewriteSpec, runtime import map)
|
|
231
|
+
// uses the same function so iOS's HTTP ESM cache sees byte-identical
|
|
232
|
+
// URLs.
|
|
233
|
+
const coreSpec = (subpath) => {
|
|
234
|
+
const origin = getBootOrigin();
|
|
235
|
+
if (origin) {
|
|
236
|
+
return buildCoreUrl(origin, subpath);
|
|
237
|
+
}
|
|
238
|
+
const sub = subpath ? String(subpath).replace(/^\/+/, '') : '';
|
|
239
|
+
return sub ? `@nativescript/core/${sub}` : '@nativescript/core';
|
|
240
|
+
};
|
|
241
|
+
// Virtual module that processes app.css through PostCSS/Tailwind and emits a
|
|
242
|
+
// JS module that BOTH applies the CSS as a side-effect AND exports the raw
|
|
243
|
+
// CSS string as default.
|
|
244
|
+
//
|
|
245
|
+
// Background: Vite's default `?inline` CSS handling collides with
|
|
246
|
+
// @analogjs/vite-plugin-angular's load hook in Vite 8 (it converts ?inline
|
|
247
|
+
// CSS to JS without setting moduleType:'js', so vite:css still tries to run
|
|
248
|
+
// PostCSS on the JS output). This virtual module sidesteps that.
|
|
249
|
+
//
|
|
250
|
+
// We still export the raw CSS string as default so the entry can seed
|
|
251
|
+
// `globalThis.__NS_HMR_APP_CSS__` for HMR's HTTP-core-realm replay path.
|
|
252
|
+
//
|
|
253
|
+
// We always pre-parse with rework `css` and either:
|
|
254
|
+
// - non-HMR: call `addTaggedAdditionalCSS(astJson, 'app.css')` directly
|
|
255
|
+
// so the bundled `style-scope` realm gets the styles before any view
|
|
256
|
+
// is created.
|
|
257
|
+
// - HMR: stash the AST on `globalThis.__NS_HMR_APP_CSS_AST__` so
|
|
258
|
+
// `installHttpCoreCssSupport` can apply it via the SAME AST path
|
|
259
|
+
// in the HTTP-core realm. Without this, the HTTP path would fall
|
|
260
|
+
// back to applying the raw text via `cssTreeParse` at runtime,
|
|
261
|
+
// which has produced subtle behavioral mismatches with the rework
|
|
262
|
+
// AST (e.g. `.text-sm { line-height: 20 }` rendering with extra
|
|
263
|
+
// line spacing under HMR but not under the no-HMR rolldown
|
|
264
|
+
// bundle, even though both bundles serialize the identical
|
|
265
|
+
// declaration). Pre-parsing once at build time and shipping the
|
|
266
|
+
// AST to BOTH paths keeps cold-boot rendering identical between
|
|
267
|
+
// the two modes. Live HMR edits still arrive as raw text via the
|
|
268
|
+
// dev-server WebSocket, so `installHttpCoreCssSupport` keeps the
|
|
269
|
+
// raw-text fallback for that case.
|
|
75
270
|
if (id === APP_CSS_RESOLVED) {
|
|
76
271
|
const appCssPath = path.resolve(projectRoot, getProjectAppRelativePath('app.css'));
|
|
77
272
|
const code = fs.readFileSync(appCssPath, 'utf-8');
|
|
78
273
|
const result = await preprocessCSS(code, appCssPath, resolvedConfig);
|
|
274
|
+
const ast = parseCssToAst(result.code, { silent: true });
|
|
275
|
+
// `css` emits `position` metadata on every AST node. NS doesn't
|
|
276
|
+
// use it, and stripping it ~halves the inlined JSON size — same
|
|
277
|
+
// thing webpack's css2json-loader does.
|
|
278
|
+
const astJson = JSON.stringify(ast, (key, value) => (key === 'position' ? undefined : value));
|
|
279
|
+
const lines = [];
|
|
280
|
+
if (opts.hmrActive) {
|
|
281
|
+
// Stash AST on globalThis BEFORE the entry seeds
|
|
282
|
+
// `__NS_HMR_APP_CSS__` from this module's default export, so
|
|
283
|
+
// `installHttpCoreCssSupport` can prefer the AST and match
|
|
284
|
+
// the no-HMR application path exactly.
|
|
285
|
+
lines.push(`try { (globalThis).__NS_HMR_APP_CSS_AST__ = ${astJson}; } catch {}`);
|
|
286
|
+
}
|
|
287
|
+
else {
|
|
288
|
+
lines.push(`import { addTaggedAdditionalCSS } from ${JSON.stringify(coreSpec('ui/styling/style-scope'))};`, `addTaggedAdditionalCSS(${astJson}, 'app.css');`);
|
|
289
|
+
}
|
|
290
|
+
lines.push(`export default ${JSON.stringify(result.code)};`);
|
|
79
291
|
return {
|
|
80
|
-
code:
|
|
292
|
+
code: lines.join('\n'),
|
|
81
293
|
moduleType: 'js',
|
|
82
294
|
};
|
|
83
295
|
}
|
|
@@ -85,42 +297,192 @@ export function mainEntryPlugin(opts) {
|
|
|
85
297
|
// guaranteeing XMLHttpRequest is on globalThis before zone.js or any other code accesses it.
|
|
86
298
|
if (id === XHR_POLYFILL_RESOLVED) {
|
|
87
299
|
return {
|
|
88
|
-
code: [
|
|
300
|
+
code: [`import * as xhrImpl from ${JSON.stringify(coreSpec('xhr'))};`, "var polyfills = ['XMLHttpRequest','FormData','Blob','File','FileReader'];", 'for (var i = 0; i < polyfills.length; i++) {', ' var n = polyfills[i];', ' if (!(n in globalThis) && xhrImpl[n]) globalThis[n] = xhrImpl[n];', '}'].join('\n'),
|
|
301
|
+
moduleType: 'js',
|
|
302
|
+
};
|
|
303
|
+
}
|
|
304
|
+
// Virtual module that seeds compile-time defines on globalThis.
|
|
305
|
+
// Imported FIRST in the entry so it evaluates as a leaf before
|
|
306
|
+
// any other module — including the `bundle-entry-points` chain
|
|
307
|
+
// that transitively reaches the user's app code. See the
|
|
308
|
+
// DEFINES_SEED_VIRTUAL_ID comment at the top of this file.
|
|
309
|
+
if (id === DEFINES_SEED_RESOLVED) {
|
|
310
|
+
const isApple = opts.platform === 'ios' || opts.platform === 'visionos';
|
|
311
|
+
const seedLines = [
|
|
312
|
+
`globalThis.__DEV__ = ${opts.isDevMode ? 'true' : 'false'};`,
|
|
313
|
+
`globalThis.__ANDROID__ = ${opts.platform === 'android' ? 'true' : 'false'};`,
|
|
314
|
+
`globalThis.__IOS__ = ${opts.platform === 'ios' ? 'true' : 'false'};`,
|
|
315
|
+
`globalThis.__VISIONOS__ = ${opts.platform === 'visionos' ? 'true' : 'false'};`,
|
|
316
|
+
`globalThis.__APPLE__ = ${isApple ? 'true' : 'false'};`,
|
|
317
|
+
'globalThis.__COMMONJS__ = false;',
|
|
318
|
+
'globalThis.__NS_WEBPACK__ = false;',
|
|
319
|
+
`globalThis.__NS_ENV_VERBOSE__ = ${opts.verbose ? 'true' : 'false'};`,
|
|
320
|
+
// Seed the runtime flavor so the HMR client (which is loaded from
|
|
321
|
+
// node_modules and therefore NOT processed by Vite's `define`
|
|
322
|
+
// substitution) can resolve `TARGET_FLAVOR` reliably. Without
|
|
323
|
+
// this, `resolveTargetFlavor()` in `hmr/client/index.ts` only
|
|
324
|
+
// detects 'angular' (via __reboot_ng_modules__) and 'vue' (via
|
|
325
|
+
// __VUE_HMR_RUNTIME__), and 'solid' / 'typescript' fall through
|
|
326
|
+
// to undefined — so any flavor-specific switch case in
|
|
327
|
+
// `processQueue` (Solid component boundary discovery, route-loader
|
|
328
|
+
// patching, overlay stage transitions) silently never fires.
|
|
329
|
+
`globalThis.__NS_TARGET_FLAVOR__ = ${JSON.stringify(flavor)};`,
|
|
330
|
+
'globalThis.__UI_USE_XML_PARSER__ = true;',
|
|
331
|
+
'globalThis.__UI_USE_EXTERNAL_RENDERER__ = false;',
|
|
332
|
+
"globalThis.__CSS_PARSER__ = 'css-tree';",
|
|
333
|
+
'globalThis.__TEST__ = false;',
|
|
334
|
+
];
|
|
335
|
+
return {
|
|
336
|
+
code: seedLines.join('\n') + '\n',
|
|
89
337
|
moduleType: 'js',
|
|
90
338
|
};
|
|
91
339
|
}
|
|
92
340
|
if (id !== RESOLVED)
|
|
93
341
|
return null;
|
|
342
|
+
let imports = '';
|
|
343
|
+
// Under HMR: import the defines-seed virtual module FIRST so its
|
|
344
|
+
// body — which sets `globalThis.__APPLE__`, `__IOS__`, `__DEV__`,
|
|
345
|
+
// etc. — evaluates as a leaf in the dependency graph BEFORE any
|
|
346
|
+
// other module instantiates. Per-module shims injected by
|
|
347
|
+
// `processCodeForDevice` read these from globalThis and snapshot
|
|
348
|
+
// them at instantiation time, so they MUST be set first.
|
|
349
|
+
//
|
|
350
|
+
// Under non-HMR: Vite's `define` config handles substitution
|
|
351
|
+
// statically at build time — no runtime seeding needed.
|
|
352
|
+
if (opts.hmrActive) {
|
|
353
|
+
imports += `import '${DEFINES_SEED_VIRTUAL_ID}';\n`;
|
|
354
|
+
}
|
|
94
355
|
// consistent verbose flag to easily reference below
|
|
95
|
-
|
|
96
|
-
// Ensure any CommonJS-style tooling requires (e.g. from Babel or
|
|
97
|
-
// build-time libraries that may be accidentally bundled) do
|
|
98
|
-
// to resolve Node built-ins like 'fs' or 'path' on
|
|
99
|
-
// are not used at runtime for NativeScript
|
|
100
|
-
// empty object from a
|
|
101
|
-
|
|
356
|
+
imports += "const __nsVerboseLog = typeof __NS_ENV_VERBOSE__ !== 'undefined' && __NS_ENV_VERBOSE__;\n";
|
|
357
|
+
// Ensure any CommonJS-style tooling requires (e.g. from Babel or
|
|
358
|
+
// other build-time libraries that may be accidentally bundled) do
|
|
359
|
+
// not attempt to resolve Node built-ins like 'fs' or 'path' on
|
|
360
|
+
// device. These modules are not used at runtime for NativeScript
|
|
361
|
+
// apps, so we safely return an empty object from a shim.
|
|
362
|
+
//
|
|
363
|
+
// IMPORTANT: Under HMR, vendor packages call the real NativeScript
|
|
364
|
+
// CommonJS require() with `@nativescript/core/<sub>` specifiers
|
|
365
|
+
// (e.g. `require('@nativescript/core/ui/core/view').View` in
|
|
366
|
+
// `@nativescript-community/gesturehandler`). If we overwrite
|
|
367
|
+
// globalThis.require with a blanket stub, every such call returns
|
|
368
|
+
// `{}` and any property access on the result (e.g. `.View`) is
|
|
369
|
+
// `undefined`, cascading into `TypeError: Cannot read properties
|
|
370
|
+
// of undefined (reading 'prototype')` inside `applyMixins` when
|
|
371
|
+
// vendor install() hooks run.
|
|
372
|
+
//
|
|
373
|
+
// Instead, install a DELEGATING shim:
|
|
374
|
+
// - If the specifier is a Node built-in (fs, path, os, …) or
|
|
375
|
+
// a webpack-only runtime hook (require.context), return a
|
|
376
|
+
// safe empty stub.
|
|
377
|
+
// - Otherwise, delegate to the preserved original
|
|
378
|
+
// `globalThis.require` (NativeScript's native CJS loader),
|
|
379
|
+
// which routes `@nativescript/core*` through the HTTP bridge
|
|
380
|
+
// or, for already-HTTP-loaded modules, through the
|
|
381
|
+
// `globalThis.__NS_CORE_MODULES__` registry populated by the
|
|
382
|
+
// `/ns/core` bridge preamble.
|
|
383
|
+
imports += "try { if (typeof globalThis !== 'undefined') {\n";
|
|
384
|
+
imports += " var __nsOrigRequire = typeof globalThis.require === 'function' ? globalThis.require : null;\n";
|
|
385
|
+
imports += ' var __nsNodeBuiltins = { fs: 1, path: 1, os: 1, url: 1, crypto: 1, util: 1, stream: 1, events: 1, buffer: 1, http: 1, https: 1, net: 1, tls: 1, dns: 1, child_process: 1, module: 1, zlib: 1, querystring: 1, assert: 1, constants: 1, vm: 1 };\n';
|
|
386
|
+
// Mirror helpers/ns-core-url.ts normalizeCoreSub() inline so the
|
|
387
|
+
// lookup against __NS_CORE_MODULES__ uses the same keys the
|
|
388
|
+
// /ns/core handler registers under.
|
|
389
|
+
imports += ' var __nsNormSub = function (s) {\n';
|
|
390
|
+
imports += " if (!s) return '';\n";
|
|
391
|
+
imports += " var t = String(s).split('?')[0].split('#')[0].trim();\n";
|
|
392
|
+
imports += " t = t.replace(/^\\/+/, '').replace(/\\/+$/, '');\n";
|
|
393
|
+
imports += " t = t.replace(/\\.(?:mjs|cjs|js)$/, '');\n";
|
|
394
|
+
imports += " if (t.length >= 6 && t.substring(t.length - 6) === '/index') t = t.substring(0, t.length - 6);\n";
|
|
395
|
+
imports += " if (!t || t === 'index') return '';\n";
|
|
396
|
+
imports += ' return t;\n';
|
|
397
|
+
imports += ' };\n';
|
|
398
|
+
// Invariant D: CJS/ESM interop shape helper.
|
|
399
|
+
//
|
|
400
|
+
// Install a global, idempotent shape function that converts
|
|
401
|
+
// ESM Module Namespace Objects (which have [[Prototype]] = null
|
|
402
|
+
// per spec §9.4.6) into plain Objects that inherit from
|
|
403
|
+
// Object.prototype. CJS consumers — especially zone.js's
|
|
404
|
+
// patchMethod() — call `hasOwnProperty`, `toString`, etc. on
|
|
405
|
+
// their require() result; a null-proto namespace throws
|
|
406
|
+
// "X is not a function" on the first such call.
|
|
407
|
+
//
|
|
408
|
+
// Properties:
|
|
409
|
+
// - Recursive: @nativescript/core re-exports Utils/Http/Trace
|
|
410
|
+
// as nested namespaces (`export * as Utils from './utils'`),
|
|
411
|
+
// each also null-proto. Shallow wrapping leaves those.
|
|
412
|
+
// - Identity-preserving via a WeakMap cache keyed on the
|
|
413
|
+
// underlying namespace. zone.js MUTATES its target (stashes
|
|
414
|
+
// delegate symbols, overwrites methods); a fresh copy per
|
|
415
|
+
// require() would lose those mutations on the next lookup.
|
|
416
|
+
// - Installed ONCE on globalThis so the /ns/core handler's
|
|
417
|
+
// registration footer, the vendor shim's createRequire, and
|
|
418
|
+
// any other consumer share the same cache and see
|
|
419
|
+
// mutation-consistent shapes.
|
|
420
|
+
imports += ' var __nsShapeCache = globalThis.__NS_CJS_SHAPE_CACHE__ || (globalThis.__NS_CJS_SHAPE_CACHE__ = new WeakMap());\n';
|
|
421
|
+
imports += ' var __nsShapeCjs = globalThis.__NS_CJS_SHAPE__ || (globalThis.__NS_CJS_SHAPE__ = function __nsShape(obj) {\n';
|
|
422
|
+
imports += " if (!obj || typeof obj !== 'object') return obj;\n";
|
|
423
|
+
imports += ' var proto = Object.getPrototypeOf(obj);\n';
|
|
424
|
+
imports += ' var isNsModule = false;\n';
|
|
425
|
+
imports += " try { isNsModule = obj[Symbol.toStringTag] === 'Module'; } catch (e) {}\n";
|
|
426
|
+
imports += ' if (proto !== null && !isNsModule) return obj;\n';
|
|
427
|
+
imports += ' if (__nsShapeCache.has(obj)) return __nsShapeCache.get(obj);\n';
|
|
428
|
+
imports += ' var out = {};\n';
|
|
429
|
+
imports += ' __nsShapeCache.set(obj, out);\n';
|
|
430
|
+
imports += ' try {\n';
|
|
431
|
+
imports += ' var keys = Object.keys(obj);\n';
|
|
432
|
+
imports += ' for (var i = 0; i < keys.length; i++) {\n';
|
|
433
|
+
imports += ' var k = keys[i];\n';
|
|
434
|
+
imports += ' try { out[k] = __nsShape(obj[k]); } catch (e) {}\n';
|
|
435
|
+
imports += ' }\n';
|
|
436
|
+
imports += ' } catch (e) {}\n';
|
|
437
|
+
imports += ' return out;\n';
|
|
438
|
+
imports += ' });\n';
|
|
439
|
+
imports += ' var _nsReq = function (id) {\n';
|
|
440
|
+
imports += ' try {\n';
|
|
441
|
+
imports += " var n = String(id || '');\n";
|
|
442
|
+
imports += " var stripped = n.indexOf('node:') === 0 ? n.slice(5) : n;\n";
|
|
443
|
+
imports += ' if (__nsNodeBuiltins[stripped]) return {};\n';
|
|
444
|
+
imports += " if (n === '@nativescript/core' || n.indexOf('@nativescript/core/') === 0) {\n";
|
|
445
|
+
imports += ' var table = globalThis.__NS_CORE_MODULES__;\n';
|
|
446
|
+
imports += ' if (table) {\n';
|
|
447
|
+
// Table entries are ALREADY shaped (the /ns/core footer stores
|
|
448
|
+
// the shape, not the raw namespace). But we pass through
|
|
449
|
+
// __nsShapeCjs anyway — it's a no-op on already-shaped values
|
|
450
|
+
// (fast path: `proto !== null && !isNsModule` returns obj as-is)
|
|
451
|
+
// and guards against future changes to how the registry is
|
|
452
|
+
// populated (e.g., by direct assignment from test code).
|
|
453
|
+
imports += ' if (table[n]) return __nsShapeCjs(table[n]);\n';
|
|
454
|
+
imports += " var rawSub = n === '@nativescript/core' ? '' : n.slice('@nativescript/core/'.length);\n";
|
|
455
|
+
imports += ' var normSub = __nsNormSub(rawSub);\n';
|
|
456
|
+
imports += " var bareKey = normSub ? '@nativescript/core/' + normSub : '@nativescript/core';\n";
|
|
457
|
+
imports += ' if (table[bareKey]) return __nsShapeCjs(table[bareKey]);\n';
|
|
458
|
+
imports += ' if (table[normSub]) return __nsShapeCjs(table[normSub]);\n';
|
|
459
|
+
imports += ' }\n';
|
|
460
|
+
imports += ' }\n';
|
|
461
|
+
// Fallback to native require (NativeScript CJS loader via HTTP
|
|
462
|
+
// bridge). Shape the result too — the native loader may return
|
|
463
|
+
// a raw ESM namespace for core subpaths served before the /ns/core
|
|
464
|
+
// footer runs.
|
|
465
|
+
imports += ' if (__nsOrigRequire) return __nsShapeCjs(__nsOrigRequire(id));\n';
|
|
466
|
+
imports += ' } catch (e) {}\n';
|
|
467
|
+
imports += ' return {};\n';
|
|
468
|
+
imports += ' };\n';
|
|
469
|
+
imports += ' _nsReq.context = function () { var _c = { keys: function () { return []; } }; _c.__esModule = true; return _c; };\n';
|
|
470
|
+
imports += ' if (__nsOrigRequire) { try { _nsReq.resolve = __nsOrigRequire.resolve ? __nsOrigRequire.resolve.bind(__nsOrigRequire) : function (id) { return id; }; } catch (e) {} }\n';
|
|
471
|
+
imports += ' globalThis.require = _nsReq;\n';
|
|
472
|
+
imports += ' globalThis.__nsOrigRequire = __nsOrigRequire;\n';
|
|
473
|
+
imports += '} } catch {}\n';
|
|
102
474
|
// Banner diagnostics for visibility at runtime
|
|
103
475
|
if (opts.verbose) {
|
|
104
476
|
imports += `console.info('[ns-entry] begin', { platform: ${JSON.stringify(opts.platform)}, dev: ${JSON.stringify(opts.isDevMode)}, hmr: ${JSON.stringify(opts.hmrActive)}, verbose: ${JSON.stringify(opts.verbose)}, mainEntry: ${JSON.stringify(mainEntry)}, mainRel: ${JSON.stringify(mainEntryRelPosix)}, time: new Date().toISOString() });\n`;
|
|
105
477
|
}
|
|
106
478
|
if (opts.hmrActive) {
|
|
107
|
-
//
|
|
108
|
-
//
|
|
109
|
-
//
|
|
110
|
-
//
|
|
111
|
-
//
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
imports += `globalThis.__IOS__ = ${opts.platform === 'ios' ? 'true' : 'false'};\n`;
|
|
115
|
-
imports += `globalThis.__VISIONOS__ = ${opts.platform === 'visionos' ? 'true' : 'false'};\n`;
|
|
116
|
-
imports += `globalThis.__APPLE__ = ${opts.platform === 'ios' || opts.platform === 'visionos' ? 'true' : 'false'};\n`;
|
|
117
|
-
imports += `globalThis.__COMMONJS__ = false;\n`;
|
|
118
|
-
imports += `globalThis.__NS_WEBPACK__ = false;\n`;
|
|
119
|
-
imports += `globalThis.__NS_ENV_VERBOSE__ = ${opts.verbose ? 'true' : 'false'};\n`;
|
|
120
|
-
imports += `globalThis.__UI_USE_XML_PARSER__ = true;\n`;
|
|
121
|
-
imports += `globalThis.__UI_USE_EXTERNAL_RENDERER__ = false;\n`;
|
|
122
|
-
imports += `globalThis.__CSS_PARSER__ = 'css-tree';\n`;
|
|
123
|
-
imports += `globalThis.__TEST__ = false;\n`;
|
|
479
|
+
// NOTE: globalThis defines (`__APPLE__`, `__IOS__`, `__DEV__`,
|
|
480
|
+
// etc.) are seeded by the `virtual:ns-defines-seed` import at
|
|
481
|
+
// the very top of this entry — see the import on line ~192.
|
|
482
|
+
// They MUST run as a leaf module ahead of any other graph
|
|
483
|
+
// node, so we can't seed them inline here (ESM imports hoist
|
|
484
|
+
// past inline body code, so any module reachable through
|
|
485
|
+
// `bundle-entry-points` would otherwise see undefined).
|
|
124
486
|
imports += "import { installModuleProvenanceRecorder } from '@nativescript/vite/hmr/shared/runtime/module-provenance.js';\n";
|
|
125
487
|
imports += 'installModuleProvenanceRecorder(__nsVerboseLog);\n';
|
|
126
488
|
}
|
|
@@ -128,14 +490,16 @@ export function mainEntryPlugin(opts) {
|
|
|
128
490
|
// Install XHR polyfill FIRST — its virtual module body runs during import evaluation,
|
|
129
491
|
// before any subsequent import (like zone.js) can reference XMLHttpRequest.
|
|
130
492
|
imports += `import '${XHR_POLYFILL_VIRTUAL_ID}';\n`;
|
|
131
|
-
// Load globals early
|
|
132
|
-
|
|
493
|
+
// Load globals early. Under HMR we use a full HTTP URL so iOS's
|
|
494
|
+
// ESM loader can fetch it directly at module-instantiation time —
|
|
495
|
+
// the import map isn't installed yet at that phase.
|
|
496
|
+
imports += `import ${JSON.stringify(coreSpec('globals/index'))};\n`;
|
|
133
497
|
if (opts.verbose) {
|
|
134
498
|
imports += `console.info('[ns-entry] core globals loaded');\n`;
|
|
135
499
|
}
|
|
136
500
|
// Seed the real NativeScript Application singleton before any early HMR/placeholder
|
|
137
501
|
// code runs. Dynamic discovery is too late for iOS placeholder startup.
|
|
138
|
-
imports +=
|
|
502
|
+
imports += `import { Application as __nsEarlyApplication } from ${JSON.stringify(coreSpec('application'))};\n`;
|
|
139
503
|
imports += `try { if (__nsEarlyApplication && (typeof __nsEarlyApplication.run === 'function' || typeof __nsEarlyApplication.on === 'function' || typeof __nsEarlyApplication.resetRootView === 'function')) { globalThis.Application = __nsEarlyApplication; } } catch {}\n`;
|
|
140
504
|
if (opts.verbose) {
|
|
141
505
|
imports += `console.info('[ns-entry] early Application seeded', { hasRun: typeof globalThis.Application?.run === 'function', hasOn: typeof globalThis.Application?.on === 'function', hasResetRootView: typeof globalThis.Application?.resetRootView === 'function' });\n`;
|
|
@@ -171,7 +535,7 @@ export function mainEntryPlugin(opts) {
|
|
|
171
535
|
}
|
|
172
536
|
}
|
|
173
537
|
// Load NS bundle entry points after early hook
|
|
174
|
-
imports +=
|
|
538
|
+
imports += `import ${JSON.stringify(coreSpec('bundle-entry-points'))};\n`;
|
|
175
539
|
if (opts.verbose) {
|
|
176
540
|
imports += `console.info('[ns-entry] bundle-entry-points loaded');\n`;
|
|
177
541
|
}
|
|
@@ -238,19 +602,30 @@ export function mainEntryPlugin(opts) {
|
|
|
238
602
|
// Import Application statically if needed for CSS or Android activity defer
|
|
239
603
|
if (hasAppCss || needsAndroidActivityDefer) {
|
|
240
604
|
if (hasAppCss) {
|
|
241
|
-
|
|
605
|
+
// The virtual module's body either:
|
|
606
|
+
// - non-HMR: calls `addTaggedAdditionalCSS(ast, 'app.css')`
|
|
607
|
+
// as an import-time side-effect, landing CSS in NS's
|
|
608
|
+
// selector tables before any view is created.
|
|
609
|
+
// - HMR: stashes the rework AST on
|
|
610
|
+
// `globalThis.__NS_HMR_APP_CSS_AST__` so
|
|
611
|
+
// `installHttpCoreCssSupport` can apply it via the SAME
|
|
612
|
+
// AST path in the HTTP-core realm. The default export
|
|
613
|
+
// is the raw CSS string, also seeded onto
|
|
614
|
+
// `globalThis.__NS_HMR_APP_CSS__` here as a
|
|
615
|
+
// raw-text fallback (used for live HMR edits via the
|
|
616
|
+
// dev-server WebSocket).
|
|
617
|
+
imports += `// Apply global CSS before app bootstrap (AST under non-HMR; AST stashed for HMR cold boot)\n`;
|
|
242
618
|
imports += `import appCssContent from '${APP_CSS_VIRTUAL_ID}';\n`;
|
|
243
619
|
if (opts.hmrActive) {
|
|
244
620
|
imports += `try { globalThis.__NS_HMR_APP_CSS__ = appCssContent; } catch {}\n`;
|
|
245
621
|
}
|
|
246
|
-
}
|
|
247
|
-
imports += `import { Application } from '@nativescript/core';\n`;
|
|
248
|
-
if (hasAppCss) {
|
|
249
|
-
imports += `if (appCssContent) { try { Application.addCss(appCssContent); } catch (error) { console.error('Error applying CSS:', error); } }\n`;
|
|
250
622
|
if (opts.verbose) {
|
|
251
|
-
imports += `console.info('[ns-entry] app.css applied');\n`;
|
|
623
|
+
imports += `console.info('[ns-entry] app.css applied as AST');\n`;
|
|
252
624
|
}
|
|
253
625
|
}
|
|
626
|
+
if (needsAndroidActivityDefer) {
|
|
627
|
+
imports += `import { Application } from ${JSON.stringify(coreSpec())};\n`;
|
|
628
|
+
}
|
|
254
629
|
}
|
|
255
630
|
// ---- Deferred Android activity import (non-HMR only) ----
|
|
256
631
|
// Uses the statically imported Application to avoid mixing dynamic and static imports
|
|
@@ -278,15 +653,23 @@ export function mainEntryPlugin(opts) {
|
|
|
278
653
|
if (opts.verbose) {
|
|
279
654
|
imports += `console.info('[ns-entry] including deterministic dev session bootstrap', { platform: ${JSON.stringify(opts.platform)}, mainRel: ${JSON.stringify(mainEntryRelPosix)} });\n`;
|
|
280
655
|
}
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
656
|
+
// Same device-reachable origin as `getBootOrigin()` so the
|
|
657
|
+
// session-descriptor URL and every `/ns/core/*` URL baked
|
|
658
|
+
// into bundle.mjs come from one canonical source. Without
|
|
659
|
+
// this, Android's `bundle.mjs` would hit `0.0.0.0:5173` for
|
|
660
|
+
// both endpoints (server.host's wildcard bind) and fail at
|
|
661
|
+
// boot before any user code runs.
|
|
662
|
+
const { origin: bootOrigin } = resolveDeviceReachableOrigin({
|
|
663
|
+
host: resolvedConfig.server.host,
|
|
664
|
+
platform: opts.platform,
|
|
665
|
+
protocol: resolvedConfig.server.https || opts.useHttps ? 'https' : 'http',
|
|
666
|
+
port: Number(resolvedConfig.server.port || 5173),
|
|
667
|
+
});
|
|
668
|
+
const sessionUrl = bootOrigin + '/__ns_dev__/session';
|
|
286
669
|
imports += "import { startBrowserRuntimeSession } from '@nativescript/vite/hmr/shared/runtime/session-bootstrap.js';\n";
|
|
287
670
|
imports += `startBrowserRuntimeSession(${JSON.stringify(sessionUrl)}, __nsVerboseLog).catch((error) => {\n`;
|
|
288
671
|
imports += ` try { globalThis.__NS_ENTRY_ERROR__ = { phase: 'deterministic-dev-session', message: String(error && (error.message || error)), stack: error && error.stack ? String(error.stack) : '' }; } catch {}\n`;
|
|
289
|
-
imports += `
|
|
672
|
+
imports += ` console.error('[ns-entry] deterministic dev session bootstrap failed', error && error.stack ? error.stack : error);\n`;
|
|
290
673
|
imports += `});\n`;
|
|
291
674
|
if (opts.verbose) {
|
|
292
675
|
imports += `console.info('[ns-entry] deterministic dev session bootstrap appended');\n`;
|
|
@@ -300,7 +683,7 @@ export function mainEntryPlugin(opts) {
|
|
|
300
683
|
}
|
|
301
684
|
if (opts.isDevMode) {
|
|
302
685
|
// debug tools support
|
|
303
|
-
imports +=
|
|
686
|
+
imports += `import ${JSON.stringify(coreSpec('inspector_modules'))};\n`;
|
|
304
687
|
if (opts.verbose) {
|
|
305
688
|
imports += "console.info('[ns-entry] inspector modules imported');\n";
|
|
306
689
|
}
|