(id: string)
| 36 | return null; |
| 37 | }, |
| 38 | load(id: string) { |
| 39 | if (id !== RESOLVED) return null; |
| 40 | |
| 41 | // consistent verbose flag to easily reference below |
| 42 | let imports = "const __nsVerboseLog = typeof __NS_ENV_VERBOSE__ !== 'undefined' && __NS_ENV_VERBOSE__;\n"; |
| 43 | |
| 44 | // Ensure any CommonJS-style tooling requires (e.g. from Babel or other |
| 45 | // build-time libraries that may be accidentally bundled) do not attempt |
| 46 | // to resolve Node built-ins like 'fs' or 'path' on device. These modules |
| 47 | // are not used at runtime for NativeScript apps, so we safely return an |
| 48 | // empty object from a global require shim when present. |
| 49 | imports += "try { if (typeof globalThis !== 'undefined') { globalThis.require = function () { return {}; }; } } catch {}\n"; |
| 50 | |
| 51 | // Banner diagnostics for visibility at runtime |
| 52 | if (opts.verbose) { |
| 53 | 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`; |
| 54 | } |
| 55 | |
| 56 | if (opts.hmrActive) { |
| 57 | // ---- Vendor manifest bootstrap ---- |
| 58 | // Use single self-contained vendor module to avoid extra imports affecting chunking |
| 59 | imports += "import vendorManifest, { __nsVendorModuleMap } from '@nativescript/vendor';\n"; |
| 60 | imports += "import { installVendorBootstrap } from '@nativescript/vite/hmr/shared/runtime/vendor-bootstrap.js';\n"; |
| 61 | if (opts.verbose) { |
| 62 | imports += `console.info('[ns-entry] vendor manifest imported', { keys: Object.keys(vendorManifest||{}).length, hasMap: typeof __nsVendorModuleMap === 'object' });\n`; |
| 63 | } |
| 64 | imports += 'installVendorBootstrap(vendorManifest, __nsVendorModuleMap, __nsVerboseLog);\n'; |
| 65 | if (opts.verbose) { |
| 66 | imports += `console.info('[ns-entry] vendor bootstrap installed');\n`; |
| 67 | } |
| 68 | } |
| 69 | |
| 70 | // ---- Core runtime globals (always-needed) ---- |
| 71 | // Load globals early |
| 72 | imports += "import '@nativescript/core/globals/index';\n"; |
| 73 | if (opts.verbose) { |
| 74 | imports += `console.info('[ns-entry] core globals loaded');\n`; |
| 75 | } |
| 76 | |
| 77 | /** |
| 78 | * Ensure the canonical @nativescript/core classes are available on globalThis |
| 79 | * before any other framework modules execute (like bundle-entry-points) to avoid duplicate realms |
| 80 | * and lifecycle registration using an uninitialized Application instance. |
| 81 | * We do this for both HMR and non-HMR builds to guarantee stable bootstrap. |
| 82 | */ |
| 83 | imports += "import { installCoreAliasesEarly } from '@nativescript/vite/runtime/core-aliases-early.js';\n"; |
| 84 | imports += 'installCoreAliasesEarly(__nsVerboseLog);\n'; |
| 85 | |
| 86 | if (opts.hmrActive) { |
| 87 | // Placeholder root for HMR to show prior to http loaded es modules take over |
| 88 | if (opts.verbose) { |
| 89 | imports += `console.info('[ns-entry] installing placeholder...');\n`; |
| 90 | } |
| 91 | imports += "import { installRootPlaceholder } from '@nativescript/vite/hmr/shared/runtime/root-placeholder.js';\n"; |
| 92 | imports += 'installRootPlaceholder(__nsVerboseLog);\n'; |
| 93 | if (opts.verbose) { |
| 94 | imports += `console.info('[ns-entry] placeholder installed');\n`; |
| 95 | } |
nothing calls this directly
no test coverage detected