@nativescript/vite 8.0.0-beta.0 → 8.0.0-dev.0
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 +89 -14
- package/bin/cli.cjs +8 -14
- package/configuration/angular.d.ts +35 -2
- package/configuration/angular.js +541 -216
- package/configuration/angular.js.map +1 -1
- package/configuration/base.js +228 -78
- package/configuration/base.js.map +1 -1
- package/configuration/javascript.js +17 -96
- package/configuration/javascript.js.map +1 -1
- package/configuration/react.js +41 -73
- package/configuration/react.js.map +1 -1
- package/configuration/solid.js +58 -6
- package/configuration/solid.js.map +1 -1
- package/configuration/typescript.js +15 -96
- package/configuration/typescript.js.map +1 -1
- package/framework.d.ts +22 -0
- package/framework.js +18 -0
- package/framework.js.map +1 -0
- package/helpers/app-components.d.ts +2 -1
- package/helpers/app-components.js.map +1 -1
- package/helpers/app-css-refresh.d.ts +31 -0
- package/helpers/app-css-refresh.js +43 -0
- package/helpers/app-css-refresh.js.map +1 -0
- package/helpers/app-css-state.d.ts +17 -0
- package/helpers/app-css-state.js +51 -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/cli-flags.d.ts +12 -0
- package/helpers/cli-flags.js +34 -0
- package/helpers/cli-flags.js.map +1 -1
- package/helpers/commonjs-plugins.d.ts +5 -2
- package/helpers/commonjs-plugins.js +126 -0
- package/helpers/commonjs-plugins.js.map +1 -1
- package/helpers/config-as-json.js +10 -0
- package/helpers/config-as-json.js.map +1 -1
- package/helpers/css-platform-plugin.d.ts +14 -0
- package/helpers/css-platform-plugin.js +43 -25
- package/helpers/css-platform-plugin.js.map +1 -1
- package/helpers/dev-host.d.ts +360 -0
- package/helpers/dev-host.js +694 -0
- package/helpers/dev-host.js.map +1 -0
- package/helpers/dynamic-import-plugin.d.ts +2 -1
- package/helpers/dynamic-import-plugin.js +59 -53
- package/helpers/dynamic-import-plugin.js.map +1 -1
- package/helpers/esbuild-platform-resolver.js +9 -6
- package/helpers/esbuild-platform-resolver.js.map +1 -1
- package/helpers/external-configs.d.ts +10 -4
- package/helpers/external-configs.js +63 -15
- package/helpers/external-configs.js.map +1 -1
- package/helpers/flavor.d.ts +31 -0
- package/helpers/flavor.js +53 -2
- package/helpers/flavor.js.map +1 -1
- package/helpers/global-defines.d.ts +118 -0
- package/helpers/global-defines.js +214 -11
- 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/import-meta-path.d.ts +4 -0
- package/helpers/import-meta-path.js +5 -0
- package/helpers/import-meta-path.js.map +1 -0
- package/helpers/import-specifier.d.ts +1 -0
- package/helpers/import-specifier.js +18 -0
- package/helpers/import-specifier.js.map +1 -0
- package/helpers/init.js +24 -26
- package/helpers/init.js.map +1 -1
- package/helpers/logging.d.ts +12 -1
- package/helpers/logging.js +81 -5
- package/helpers/logging.js.map +1 -1
- package/helpers/main-entry.d.ts +8 -2
- package/helpers/main-entry.js +622 -120
- package/helpers/main-entry.js.map +1 -1
- package/helpers/nativeclass-esbuild-plugin.d.ts +2 -1
- package/helpers/nativeclass-esbuild-plugin.js +6 -1
- package/helpers/nativeclass-esbuild-plugin.js.map +1 -1
- package/helpers/nativeclass-transform.d.ts +13 -0
- package/helpers/nativeclass-transform.js +42 -131
- package/helpers/nativeclass-transform.js.map +1 -1
- package/helpers/nativeclass-transformer-plugin.d.ts +19 -1
- package/helpers/nativeclass-transformer-plugin.js +324 -37
- package/helpers/nativeclass-transformer-plugin.js.map +1 -1
- package/helpers/nativescript-package-resolver.js +10 -62
- 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-external-urls.d.ts +32 -0
- package/helpers/ns-core-external-urls.js +107 -0
- package/helpers/ns-core-external-urls.js.map +1 -0
- package/helpers/ns-core-url.d.ts +106 -0
- package/helpers/ns-core-url.js +225 -0
- package/helpers/ns-core-url.js.map +1 -0
- package/helpers/optimize-deps.d.ts +16 -0
- package/helpers/optimize-deps.js +17 -0
- package/helpers/optimize-deps.js.map +1 -0
- package/helpers/package-platform-aliases.js +34 -49
- 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/postcss-platform-config.d.ts +17 -1
- package/helpers/postcss-platform-config.js +20 -37
- package/helpers/postcss-platform-config.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/resolve-main-field-platform.d.ts +20 -0
- package/helpers/resolve-main-field-platform.js +49 -0
- package/helpers/resolve-main-field-platform.js.map +1 -0
- package/helpers/resolver.js +17 -2
- package/helpers/resolver.js.map +1 -1
- package/helpers/theme-core-plugins.js +1 -1
- package/helpers/theme-core-plugins.js.map +1 -1
- package/helpers/ts-config-paths.d.ts +32 -0
- package/helpers/ts-config-paths.js +156 -27
- package/helpers/ts-config-paths.js.map +1 -1
- package/helpers/typescript-check.d.ts +3 -3
- package/helpers/typescript-check.js +4 -4
- package/helpers/typescript-check.js.map +1 -1
- package/helpers/ui-registration.d.ts +21 -0
- package/helpers/ui-registration.js +156 -0
- package/helpers/ui-registration.js.map +1 -0
- package/helpers/utils.d.ts +9 -0
- package/helpers/utils.js +22 -2
- package/helpers/utils.js.map +1 -1
- package/helpers/vite-package-version.d.ts +7 -0
- package/helpers/vite-package-version.js +44 -0
- package/helpers/vite-package-version.js.map +1 -0
- package/helpers/workers.d.ts +40 -19
- package/helpers/workers.js +312 -13
- package/helpers/workers.js.map +1 -1
- package/hmr/client/css-handler.d.ts +2 -1
- package/hmr/client/css-handler.js +95 -23
- 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/framework-client-strategy.d.ts +117 -0
- package/hmr/client/framework-client-strategy.js +18 -0
- package/hmr/client/framework-client-strategy.js.map +1 -0
- package/hmr/client/framework.d.ts +31 -0
- package/hmr/client/framework.js +17 -0
- package/hmr/client/framework.js.map +1 -0
- package/hmr/client/hmr-pending-overlay.d.ts +13 -0
- package/hmr/client/hmr-pending-overlay.js +41 -0
- package/hmr/client/hmr-pending-overlay.js.map +1 -0
- package/hmr/client/hot-context.d.ts +89 -0
- package/hmr/client/hot-context.js +404 -0
- package/hmr/client/hot-context.js.map +1 -0
- package/hmr/client/index.d.ts +9 -1
- package/hmr/client/index.js +91 -1418
- package/hmr/client/index.js.map +1 -1
- package/hmr/client/overlay-driver.d.ts +10 -0
- package/hmr/client/overlay-driver.js +33 -0
- package/hmr/client/overlay-driver.js.map +1 -0
- package/hmr/client/protocol-dispatch.d.ts +8 -0
- package/hmr/client/protocol-dispatch.js +308 -0
- package/hmr/client/protocol-dispatch.js.map +1 -0
- package/hmr/client/root-reset.d.ts +15 -0
- package/hmr/client/root-reset.js +358 -0
- package/hmr/client/root-reset.js.map +1 -0
- package/hmr/client/strategy-loader.d.ts +24 -0
- package/hmr/client/strategy-loader.js +136 -0
- package/hmr/client/strategy-loader.js.map +1 -0
- package/hmr/client/update-pipeline.d.ts +27 -0
- package/hmr/client/update-pipeline.js +489 -0
- package/hmr/client/update-pipeline.js.map +1 -0
- package/hmr/client/utils.d.ts +14 -1
- package/hmr/client/utils.js +265 -54
- package/hmr/client/utils.js.map +1 -1
- package/hmr/client/ws-transport.d.ts +21 -0
- package/hmr/client/ws-transport.js +323 -0
- package/hmr/client/ws-transport.js.map +1 -0
- package/hmr/entry-runtime.d.ts +11 -0
- package/hmr/entry-runtime.js +566 -43
- package/hmr/entry-runtime.js.map +1 -1
- package/hmr/framework-flavors.d.ts +59 -0
- package/hmr/framework-flavors.js +108 -0
- package/hmr/framework-flavors.js.map +1 -0
- package/hmr/frameworks/angular/build/angular-linker.d.ts +12 -0
- package/hmr/frameworks/angular/build/angular-linker.js +113 -0
- package/hmr/frameworks/angular/build/angular-linker.js.map +1 -0
- package/hmr/frameworks/angular/build/inject-component-hmr-registration.d.ts +112 -0
- package/hmr/frameworks/angular/build/inject-component-hmr-registration.js +291 -0
- package/hmr/frameworks/angular/build/inject-component-hmr-registration.js.map +1 -0
- package/hmr/frameworks/angular/build/inject-hmr-vite-ignore.d.ts +75 -0
- package/hmr/frameworks/angular/build/inject-hmr-vite-ignore.js +221 -0
- package/hmr/frameworks/angular/build/inject-hmr-vite-ignore.js.map +1 -0
- package/hmr/frameworks/angular/build/inline-decorator-component-templates.d.ts +3 -0
- package/hmr/frameworks/angular/build/inline-decorator-component-templates.js +231 -0
- package/hmr/frameworks/angular/build/inline-decorator-component-templates.js.map +1 -0
- package/hmr/frameworks/angular/build/js-lexer.d.ts +4 -0
- package/hmr/frameworks/angular/build/js-lexer.js +182 -0
- package/hmr/frameworks/angular/build/js-lexer.js.map +1 -0
- package/hmr/frameworks/angular/build/linker-stats.d.ts +18 -0
- package/hmr/frameworks/angular/build/linker-stats.js +29 -0
- package/hmr/frameworks/angular/build/linker-stats.js.map +1 -0
- package/hmr/frameworks/angular/build/shared-linker.d.ts +39 -0
- package/hmr/frameworks/angular/build/shared-linker.js +128 -0
- package/hmr/frameworks/angular/build/shared-linker.js.map +1 -0
- package/hmr/frameworks/angular/build/synthesize-decorator-ctor-parameters.d.ts +1 -0
- package/hmr/frameworks/angular/build/synthesize-decorator-ctor-parameters.js +88 -0
- package/hmr/frameworks/angular/build/synthesize-decorator-ctor-parameters.js.map +1 -0
- package/hmr/frameworks/angular/build/synthesize-injectable-factories.d.ts +3 -0
- package/hmr/frameworks/angular/build/synthesize-injectable-factories.js +241 -0
- package/hmr/frameworks/angular/build/synthesize-injectable-factories.js.map +1 -0
- package/hmr/frameworks/angular/build/ts-fallback-transform.d.ts +5 -0
- package/hmr/frameworks/angular/build/ts-fallback-transform.js +138 -0
- package/hmr/frameworks/angular/build/ts-fallback-transform.js.map +1 -0
- package/{helpers/angular → hmr/frameworks/angular/build}/util.d.ts +1 -0
- package/hmr/frameworks/angular/build/util.js +155 -0
- package/hmr/frameworks/angular/build/util.js.map +1 -0
- package/hmr/frameworks/angular/build/worker-url-preserve.d.ts +5 -0
- package/hmr/frameworks/angular/build/worker-url-preserve.js +140 -0
- package/hmr/frameworks/angular/build/worker-url-preserve.js.map +1 -0
- package/hmr/frameworks/angular/client/index.d.ts +2 -1
- package/hmr/frameworks/angular/client/index.js +637 -23
- package/hmr/frameworks/angular/client/index.js.map +1 -1
- package/hmr/frameworks/angular/client/strategy.d.ts +9 -0
- package/hmr/frameworks/angular/client/strategy.js +19 -0
- package/hmr/frameworks/angular/client/strategy.js.map +1 -0
- package/hmr/frameworks/angular/server/angular-root-component.d.ts +79 -0
- package/hmr/frameworks/angular/server/angular-root-component.js +149 -0
- package/hmr/frameworks/angular/server/angular-root-component.js.map +1 -0
- package/hmr/frameworks/angular/server/linker.js +37 -6
- package/hmr/frameworks/angular/server/linker.js.map +1 -1
- package/hmr/frameworks/angular/server/ng-component-route.d.ts +43 -0
- package/hmr/frameworks/angular/server/ng-component-route.js +113 -0
- package/hmr/frameworks/angular/server/ng-component-route.js.map +1 -0
- package/hmr/frameworks/angular/server/strategy.js +697 -18
- package/hmr/frameworks/angular/server/strategy.js.map +1 -1
- package/hmr/frameworks/angular/server/websocket-angular-entry.d.ts +2 -0
- package/hmr/frameworks/angular/server/websocket-angular-entry.js +68 -0
- package/hmr/frameworks/angular/server/websocket-angular-entry.js.map +1 -0
- package/hmr/frameworks/angular/server/websocket-angular-hot-update.d.ts +94 -0
- package/hmr/frameworks/angular/server/websocket-angular-hot-update.js +485 -0
- package/hmr/frameworks/angular/server/websocket-angular-hot-update.js.map +1 -0
- package/hmr/frameworks/react/client/strategy.d.ts +12 -0
- package/hmr/frameworks/react/client/strategy.js +27 -0
- package/hmr/frameworks/react/client/strategy.js.map +1 -0
- package/hmr/frameworks/react/server/strategy.d.ts +2 -0
- package/hmr/frameworks/react/server/strategy.js +230 -0
- package/hmr/frameworks/react/server/strategy.js.map +1 -0
- package/hmr/frameworks/solid/build/solid-jsx-deps.d.ts +15 -0
- package/hmr/frameworks/solid/build/solid-jsx-deps.js +178 -0
- package/hmr/frameworks/solid/build/solid-jsx-deps.js.map +1 -0
- package/hmr/frameworks/solid/client/app-runtime.d.ts +68 -0
- package/hmr/frameworks/solid/client/app-runtime.js +252 -0
- package/hmr/frameworks/solid/client/app-runtime.js.map +1 -0
- package/hmr/frameworks/solid/client/strategy.d.ts +7 -0
- package/hmr/frameworks/solid/client/strategy.js +391 -0
- package/hmr/frameworks/solid/client/strategy.js.map +1 -0
- package/hmr/frameworks/solid/server/strategy.js +293 -16
- package/hmr/frameworks/solid/server/strategy.js.map +1 -1
- package/hmr/frameworks/typescript/client/strategy.d.ts +7 -0
- package/hmr/frameworks/typescript/client/strategy.js +418 -0
- package/hmr/frameworks/typescript/client/strategy.js.map +1 -0
- package/hmr/frameworks/typescript/server/strategy.js +48 -16
- package/hmr/frameworks/typescript/server/strategy.js.map +1 -1
- package/hmr/frameworks/vue/client/dep-propagation.d.ts +44 -0
- package/hmr/frameworks/vue/client/dep-propagation.js +148 -0
- package/hmr/frameworks/vue/client/dep-propagation.js.map +1 -0
- package/hmr/frameworks/vue/client/index.d.ts +10 -1
- package/hmr/frameworks/vue/client/index.js +287 -562
- package/hmr/frameworks/vue/client/index.js.map +1 -1
- package/hmr/frameworks/vue/client/navigate-app.d.ts +3 -0
- package/hmr/frameworks/vue/client/navigate-app.js +178 -0
- package/hmr/frameworks/vue/client/navigate-app.js.map +1 -0
- package/hmr/frameworks/vue/client/strategy.d.ts +33 -0
- package/hmr/frameworks/vue/client/strategy.js +152 -0
- package/hmr/frameworks/vue/client/strategy.js.map +1 -0
- package/hmr/frameworks/vue/client/vue-sfc-update-overlay.d.ts +49 -0
- package/hmr/frameworks/vue/client/vue-sfc-update-overlay.js +124 -0
- package/hmr/frameworks/vue/client/vue-sfc-update-overlay.js.map +1 -0
- package/hmr/frameworks/vue/server/compiler.d.ts +3 -1
- package/hmr/frameworks/vue/server/compiler.js +3 -1
- package/hmr/frameworks/vue/server/compiler.js.map +1 -1
- package/hmr/frameworks/vue/server/sfc-route-assemble.d.ts +7 -0
- package/hmr/frameworks/vue/server/sfc-route-assemble.js +823 -0
- package/hmr/frameworks/vue/server/sfc-route-assemble.js.map +1 -0
- package/hmr/frameworks/vue/server/sfc-route-meta.d.ts +7 -0
- package/hmr/frameworks/vue/server/sfc-route-meta.js +80 -0
- package/hmr/frameworks/vue/server/sfc-route-meta.js.map +1 -0
- package/hmr/frameworks/vue/server/sfc-route-serve.d.ts +8 -0
- package/hmr/frameworks/vue/server/sfc-route-serve.js +462 -0
- package/hmr/frameworks/vue/server/sfc-route-serve.js.map +1 -0
- package/hmr/frameworks/vue/server/sfc-route-shared.d.ts +45 -0
- package/hmr/frameworks/vue/server/sfc-route-shared.js +105 -0
- package/hmr/frameworks/vue/server/sfc-route-shared.js.map +1 -0
- package/hmr/frameworks/vue/server/strategy.d.ts +35 -0
- package/hmr/frameworks/vue/server/strategy.js +291 -7
- package/hmr/frameworks/vue/server/strategy.js.map +1 -1
- package/hmr/frameworks/vue/server/websocket-sfc.d.ts +15 -0
- package/hmr/frameworks/vue/server/websocket-sfc.js +20 -0
- package/hmr/frameworks/vue/server/websocket-sfc.js.map +1 -0
- package/hmr/helpers/ast-normalizer.d.ts +3 -1
- package/hmr/helpers/ast-normalizer.js +131 -24
- 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/helpers/vendor-rewrite.d.ts +1 -1
- package/hmr/helpers/vendor-rewrite.js +5 -3
- package/hmr/helpers/vendor-rewrite.js.map +1 -1
- package/hmr/server/boot-recording.d.ts +51 -0
- package/hmr/server/boot-recording.js +214 -0
- package/hmr/server/boot-recording.js.map +1 -0
- package/hmr/server/constants.d.ts +1 -0
- package/hmr/server/constants.js +21 -4
- package/hmr/server/constants.js.map +1 -1
- package/hmr/server/content-css-update.d.ts +54 -0
- package/hmr/server/content-css-update.js +78 -0
- package/hmr/server/content-css-update.js.map +1 -0
- package/hmr/server/core-bundle.d.ts +140 -0
- package/hmr/server/core-bundle.js +614 -0
- package/hmr/server/core-bundle.js.map +1 -0
- package/hmr/server/core-sanitize.d.ts +130 -4
- package/hmr/server/core-sanitize.js +393 -32
- package/hmr/server/core-sanitize.js.map +1 -1
- package/hmr/server/css-connect-sync.d.ts +28 -0
- package/hmr/server/css-connect-sync.js +59 -0
- package/hmr/server/css-connect-sync.js.map +1 -0
- package/hmr/server/css-device-module.d.ts +28 -0
- package/hmr/server/css-device-module.js +44 -0
- package/hmr/server/css-device-module.js.map +1 -0
- package/hmr/server/css-update-message.d.ts +23 -0
- package/hmr/server/css-update-message.js +41 -0
- package/hmr/server/css-update-message.js.map +1 -0
- package/hmr/server/deps-bundle.d.ts +233 -0
- package/hmr/server/deps-bundle.js +1022 -0
- package/hmr/server/deps-bundle.js.map +1 -0
- package/hmr/server/device-transform-helpers.d.ts +24 -0
- package/hmr/server/device-transform-helpers.js +408 -0
- package/hmr/server/device-transform-helpers.js.map +1 -0
- package/hmr/server/framework-strategy.d.ts +182 -11
- package/hmr/server/hmr-module-graph.d.ts +37 -0
- package/hmr/server/hmr-module-graph.js +215 -0
- package/hmr/server/hmr-module-graph.js.map +1 -0
- package/hmr/server/import-map.d.ts +99 -0
- package/hmr/server/import-map.js +294 -0
- package/hmr/server/import-map.js.map +1 -0
- package/hmr/server/index.d.ts +2 -1
- package/hmr/server/index.js +7 -16
- package/hmr/server/index.js.map +1 -1
- package/hmr/server/node-builtins-route.d.ts +12 -0
- package/hmr/server/node-builtins-route.js +86 -0
- package/hmr/server/node-builtins-route.js.map +1 -0
- 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-m-response-memo.d.ts +10 -0
- package/hmr/server/ns-m-response-memo.js +33 -0
- package/hmr/server/ns-m-response-memo.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 +39 -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 +197 -0
- package/hmr/server/perf-instrumentation.js.map +1 -0
- package/hmr/server/process-code-for-device.d.ts +54 -0
- package/hmr/server/process-code-for-device.js +832 -0
- package/hmr/server/process-code-for-device.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/rewrite-imports.d.ts +2 -0
- package/hmr/server/rewrite-imports.js +631 -0
- package/hmr/server/rewrite-imports.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/runtime-graph-filter.d.ts +5 -0
- package/hmr/server/runtime-graph-filter.js +28 -0
- package/hmr/server/runtime-graph-filter.js.map +1 -0
- package/hmr/server/server-origin.d.ts +2 -0
- package/hmr/server/server-origin.js +88 -0
- package/hmr/server/server-origin.js.map +1 -0
- package/hmr/server/shared-transform-request.d.ts +12 -0
- package/hmr/server/shared-transform-request.js +143 -0
- package/hmr/server/shared-transform-request.js.map +1 -0
- package/hmr/server/socket-utils.d.ts +10 -0
- package/hmr/server/socket-utils.js +14 -0
- package/hmr/server/socket-utils.js.map +1 -0
- package/hmr/server/transform-cache-invalidation.d.ts +37 -0
- package/hmr/server/transform-cache-invalidation.js +156 -0
- package/hmr/server/transform-cache-invalidation.js.map +1 -0
- 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.d.ts +22 -1
- package/hmr/server/vite-plugin.js +655 -58
- package/hmr/server/vite-plugin.js.map +1 -1
- package/hmr/server/websocket-core-bridge.d.ts +68 -0
- package/hmr/server/websocket-core-bridge.js +370 -0
- package/hmr/server/websocket-core-bridge.js.map +1 -0
- package/hmr/server/websocket-device-transform.d.ts +3 -0
- package/hmr/server/websocket-device-transform.js +7 -0
- package/hmr/server/websocket-device-transform.js.map +1 -0
- package/hmr/server/websocket-graph-upsert.d.ts +21 -0
- package/hmr/server/websocket-graph-upsert.js +33 -0
- package/hmr/server/websocket-graph-upsert.js.map +1 -0
- package/hmr/server/websocket-hmr-pending.d.ts +29 -0
- package/hmr/server/websocket-hmr-pending.js +33 -0
- package/hmr/server/websocket-hmr-pending.js.map +1 -0
- package/hmr/server/websocket-hot-update.d.ts +80 -0
- package/hmr/server/websocket-hot-update.js +299 -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 +51 -0
- package/hmr/server/websocket-import-map-route.js.map +1 -0
- package/hmr/server/websocket-module-bindings.d.ts +21 -0
- package/hmr/server/websocket-module-bindings.js +504 -0
- package/hmr/server/websocket-module-bindings.js.map +1 -0
- package/hmr/server/websocket-module-specifiers.d.ts +98 -0
- package/hmr/server/websocket-module-specifiers.js +832 -0
- package/hmr/server/websocket-module-specifiers.js.map +1 -0
- package/hmr/server/websocket-ns-core.d.ts +34 -0
- package/hmr/server/websocket-ns-core.js +414 -0
- package/hmr/server/websocket-ns-core.js.map +1 -0
- package/hmr/server/websocket-ns-entry.d.ts +21 -0
- package/hmr/server/websocket-ns-entry.js +163 -0
- package/hmr/server/websocket-ns-entry.js.map +1 -0
- package/hmr/server/websocket-ns-m-paths.d.ts +19 -0
- package/hmr/server/websocket-ns-m-paths.js +115 -0
- package/hmr/server/websocket-ns-m-paths.js.map +1 -0
- package/hmr/server/websocket-ns-m-request.d.ts +46 -0
- package/hmr/server/websocket-ns-m-request.js +197 -0
- package/hmr/server/websocket-ns-m-request.js.map +1 -0
- package/hmr/server/websocket-ns-m.d.ts +52 -0
- package/hmr/server/websocket-ns-m.js +592 -0
- package/hmr/server/websocket-ns-m.js.map +1 -0
- package/hmr/server/websocket-served-module-helpers.d.ts +98 -0
- package/hmr/server/websocket-served-module-helpers.js +948 -0
- package/hmr/server/websocket-served-module-helpers.js.map +1 -0
- package/hmr/server/websocket-txn.d.ts +6 -0
- package/hmr/server/websocket-txn.js +42 -0
- package/hmr/server/websocket-txn.js.map +1 -0
- package/hmr/server/websocket-vendor-unifier.d.ts +9 -0
- package/hmr/server/websocket-vendor-unifier.js +46 -0
- package/hmr/server/websocket-vendor-unifier.js.map +1 -0
- package/hmr/server/websocket.d.ts +6 -17
- package/hmr/server/websocket.js +723 -5376
- package/hmr/server/websocket.js.map +1 -1
- package/hmr/shared/ns-globals.d.ts +108 -0
- package/hmr/shared/ns-globals.js +29 -0
- package/hmr/shared/ns-globals.js.map +1 -0
- package/hmr/shared/package-classifier.d.ts +9 -0
- package/hmr/shared/package-classifier.js +58 -0
- package/hmr/shared/package-classifier.js.map +1 -0
- package/hmr/shared/protocol.d.ts +157 -0
- package/hmr/shared/protocol.js +28 -0
- package/hmr/shared/protocol.js.map +1 -0
- package/hmr/shared/runtime/boot-complete.d.ts +14 -0
- package/hmr/shared/runtime/boot-complete.js +32 -0
- package/hmr/shared/runtime/boot-complete.js.map +1 -0
- 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 +44 -0
- package/hmr/shared/runtime/boot-progress.js +134 -0
- package/hmr/shared/runtime/boot-progress.js.map +1 -0
- package/hmr/shared/runtime/boot-timeline.d.ts +17 -0
- package/hmr/shared/runtime/boot-timeline.js +40 -0
- package/hmr/shared/runtime/boot-timeline.js.map +1 -0
- package/hmr/shared/runtime/browser-runtime-contract.d.ts +97 -0
- package/hmr/shared/runtime/browser-runtime-contract.js +66 -0
- package/hmr/shared/runtime/browser-runtime-contract.js.map +1 -0
- package/hmr/shared/runtime/dev-overlay-ios.d.ts +87 -0
- package/hmr/shared/runtime/dev-overlay-ios.js +521 -0
- package/hmr/shared/runtime/dev-overlay-ios.js.map +1 -0
- package/hmr/shared/runtime/dev-overlay-shared.d.ts +58 -0
- package/hmr/shared/runtime/dev-overlay-shared.js +116 -0
- package/hmr/shared/runtime/dev-overlay-shared.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-tree.d.ts +59 -0
- package/hmr/shared/runtime/dev-overlay-tree.js +712 -0
- package/hmr/shared/runtime/dev-overlay-tree.js.map +1 -0
- package/hmr/shared/runtime/dev-overlay.d.ts +39 -0
- package/hmr/shared/runtime/dev-overlay.js +292 -0
- package/hmr/shared/runtime/dev-overlay.js.map +1 -0
- package/hmr/shared/runtime/global-scope.d.ts +18 -0
- package/hmr/shared/runtime/global-scope.js +21 -0
- package/hmr/shared/runtime/global-scope.js.map +1 -0
- package/hmr/shared/runtime/hooks.js +2 -1
- package/hmr/shared/runtime/hooks.js.map +1 -1
- package/hmr/shared/runtime/launch-bridge.d.ts +9 -0
- package/hmr/shared/runtime/launch-bridge.js +98 -0
- package/hmr/shared/runtime/launch-bridge.js.map +1 -0
- package/hmr/shared/runtime/module-provenance.d.ts +1 -0
- package/hmr/shared/runtime/module-provenance.js +64 -0
- package/hmr/shared/runtime/module-provenance.js.map +1 -0
- package/hmr/shared/runtime/ns-runtime-test-double.d.ts +21 -0
- package/hmr/shared/runtime/ns-runtime-test-double.js +20 -0
- package/hmr/shared/runtime/ns-runtime-test-double.js.map +1 -0
- package/hmr/shared/runtime/overlay-flag.d.ts +9 -0
- package/hmr/shared/runtime/overlay-flag.js +34 -0
- package/hmr/shared/runtime/overlay-flag.js.map +1 -0
- package/hmr/shared/runtime/platform-polyfills.d.ts +26 -0
- package/hmr/shared/runtime/platform-polyfills.js +122 -0
- package/hmr/shared/runtime/platform-polyfills.js.map +1 -0
- package/hmr/shared/runtime/root-placeholder-view.d.ts +19 -0
- package/hmr/shared/runtime/root-placeholder-view.js +311 -0
- package/hmr/shared/runtime/root-placeholder-view.js.map +1 -0
- package/hmr/shared/runtime/root-placeholder.d.ts +1 -0
- package/hmr/shared/runtime/root-placeholder.js +778 -83
- package/hmr/shared/runtime/root-placeholder.js.map +1 -1
- package/hmr/shared/runtime/session-bootstrap.d.ts +1 -0
- package/hmr/shared/runtime/session-bootstrap.js +350 -0
- package/hmr/shared/runtime/session-bootstrap.js.map +1 -0
- package/hmr/shared/runtime/vendor-bootstrap.js +54 -16
- package/hmr/shared/runtime/vendor-bootstrap.js.map +1 -1
- package/hmr/shared/runtime/vendor-resolve.d.ts +22 -0
- package/hmr/shared/runtime/vendor-resolve.js +45 -0
- package/hmr/shared/runtime/vendor-resolve.js.map +1 -0
- package/hmr/shared/runtime/worker-tracking.d.ts +28 -0
- package/hmr/shared/runtime/worker-tracking.js +114 -0
- package/hmr/shared/runtime/worker-tracking.js.map +1 -0
- package/hmr/shared/vendor/manifest-collect.d.ts +4 -0
- package/hmr/shared/vendor/manifest-collect.js +909 -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 +5 -3
- package/hmr/shared/vendor/manifest-loader.js.map +1 -1
- package/hmr/shared/vendor/manifest.d.ts +12 -0
- package/hmr/shared/vendor/manifest.js +341 -545
- package/hmr/shared/vendor/manifest.js.map +1 -1
- package/hmr/shared/vendor/registry.d.ts +2 -0
- package/hmr/shared/vendor/registry.js +118 -7
- package/hmr/shared/vendor/registry.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 +107 -0
- package/hmr/shared/vendor/vendor-esbuild-plugins.js +540 -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 +83 -14
- package/runtime/core-aliases-early.js +103 -81
- package/runtime/core-aliases-early.js.map +1 -1
- package/shims/react-jsx-runtime.d.ts +4 -0
- package/shims/react-jsx-runtime.js +61 -0
- package/shims/react-jsx-runtime.js.map +1 -0
- package/shims/solid-jsx-runtime.d.ts +7 -0
- package/shims/solid-jsx-runtime.js +17 -0
- package/shims/solid-jsx-runtime.js.map +1 -0
- package/helpers/angular/angular-linker.d.ts +0 -13
- package/helpers/angular/angular-linker.js +0 -189
- package/helpers/angular/angular-linker.js.map +0 -1
- package/helpers/angular/shared-linker.d.ts +0 -4
- package/helpers/angular/shared-linker.js +0 -39
- package/helpers/angular/shared-linker.js.map +0 -1
- package/helpers/angular/util.js +0 -67
- package/helpers/angular/util.js.map +0 -1
- package/helpers/module-runner-patch.d.ts +0 -3
- package/helpers/module-runner-patch.js +0 -63
- package/helpers/module-runner-patch.js.map +0 -1
- package/helpers/prelink-angular.d.ts +0 -2
- package/helpers/prelink-angular.js +0 -117
- package/helpers/prelink-angular.js.map +0 -1
- package/hmr/shared/runtime/http-only-boot.d.ts +0 -1
- package/hmr/shared/runtime/http-only-boot.js +0 -124
- package/hmr/shared/runtime/http-only-boot.js.map +0 -1
- package/hmr/vendor-bootstrap.d.ts +0 -3
- package/hmr/vendor-bootstrap.js +0 -32
- package/hmr/vendor-bootstrap.js.map +0 -1
- package/shims/react-reconciler-constants.d.ts +0 -14
- package/shims/react-reconciler-constants.js +0 -21
- package/shims/react-reconciler-constants.js.map +0 -1
- package/shims/react-reconciler.d.ts +0 -8
- package/shims/react-reconciler.js +0 -15
- package/shims/react-reconciler.js.map +0 -1
- package/transformers/NativeClass/index.d.ts +0 -2
- package/transformers/NativeClass/index.js +0 -222
- package/transformers/NativeClass/index.js.map +0 -1
|
@@ -0,0 +1,1022 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* THE single node_modules payload for dev-session device serving.
|
|
3
|
+
*
|
|
4
|
+
* DEFAULT MODE
|
|
5
|
+
* ------------
|
|
6
|
+
* All node_modules code a session needs evaluates from ONE ESM payload served
|
|
7
|
+
* at `GET /ns/deps-bundle.mjs`. Its entry set is the union of:
|
|
8
|
+
* - the vendor collection (direct NativeScript-plugin/framework deps from
|
|
9
|
+
* package.json — available on the very first boot, no recording needed),
|
|
10
|
+
* - the persisted boot recording (every deep `/ns/m/node_modules/...` file a
|
|
11
|
+
* previous cold boot actually fetched — rxjs internals, Angular fesm
|
|
12
|
+
* files, community plugin subpaths).
|
|
13
|
+
*
|
|
14
|
+
* The canonical `/ns/m/node_modules/...` URL space is preserved — those
|
|
15
|
+
* routes serve THIN SHIMS that statically import the bundle and re-export the
|
|
16
|
+
* requested module's namespace from the `globalThis.__NS_DEPS_MODULES__`
|
|
17
|
+
* registry the bundle populates. Because every shim's only dependency is the
|
|
18
|
+
* one bundle URL, V8 evaluates the dependency closure exactly once — module
|
|
19
|
+
* identity stays keyed by canonical URL, with ONE big prefetchable payload
|
|
20
|
+
* instead of a deep serial fetch chain.
|
|
21
|
+
*
|
|
22
|
+
* The vendor registry is a VIEW over this bundle: the session bootstrap's
|
|
23
|
+
* `/@nativescript/vendor.mjs` import serves a thin module (see
|
|
24
|
+
* `buildDepsVendorRuntimeModule`) that imports this bundle and exposes
|
|
25
|
+
* package-root namespaces from the deps registry, so the JS-side sync
|
|
26
|
+
* resolution chain (`__nsVendorRegistry` → require shim) resolves into the
|
|
27
|
+
* SAME realm as every shim. No second node_modules payload ever evaluates.
|
|
28
|
+
*
|
|
29
|
+
* REALM RULES
|
|
30
|
+
* -----------
|
|
31
|
+
* - `@nativescript/core[/*]` stays EXTERNAL as a bare specifier: the device
|
|
32
|
+
* import map routes it to the `/ns/core` bridge, so bundled dep code joins
|
|
33
|
+
* the live core realm.
|
|
34
|
+
* - Dynamic `import()` targets inside dep code are externalized back to
|
|
35
|
+
* their canonical `/ns/m/node_modules/...` URL, preserving lazy evaluation
|
|
36
|
+
* and per-URL identity for modules the boot never touched.
|
|
37
|
+
* - `@nativescript/vite` client modules stay per-module (dev tooling loads
|
|
38
|
+
* independently of the app dependency closure).
|
|
39
|
+
* - Everything else resolvable is internalized — platform-suffix resolution
|
|
40
|
+
* (`index.ios.js`) backs up esbuild's resolver — and EVERY bundled input
|
|
41
|
+
* file is registered, so any `/ns/m` URL minted for a bundled file
|
|
42
|
+
* resolves to the single bundle instance. Bare externals are emitted only
|
|
43
|
+
* for specs with no on-disk resolution at all: anything resolvable would
|
|
44
|
+
* otherwise round-trip through a shim of this bundle mid-evaluation (ESM
|
|
45
|
+
* cycle: the shim body runs before the registry is populated and throws).
|
|
46
|
+
*
|
|
47
|
+
* FALLBACK
|
|
48
|
+
* --------
|
|
49
|
+
* A failed esbuild build logs once and falls back to per-module serving plus
|
|
50
|
+
* the standalone vendor bundle for the session. Opt out entirely with
|
|
51
|
+
* `NS_DEPS_PER_MODULE=1` (patch-package workflows editing node_modules).
|
|
52
|
+
*/
|
|
53
|
+
import { existsSync, mkdirSync, readdirSync, readFileSync, realpathSync, statSync, unlinkSync, writeFileSync } from 'node:fs';
|
|
54
|
+
import * as path from 'node:path';
|
|
55
|
+
import { createHash } from 'node:crypto';
|
|
56
|
+
import * as esbuild from 'esbuild';
|
|
57
|
+
import { resolvePlatform } from '../../helpers/cli-flags.js';
|
|
58
|
+
import { getGlobalDefines } from '../../helpers/global-defines.js';
|
|
59
|
+
import { getProjectFlavor } from '../../helpers/flavor.js';
|
|
60
|
+
import { getMonorepoWorkspaceRoot } from '../../helpers/project.js';
|
|
61
|
+
import { createNativeClassEsbuildPlugin } from '../../helpers/nativeclass-esbuild-plugin.js';
|
|
62
|
+
import { resolveVerboseFlag } from '../../helpers/logging.js';
|
|
63
|
+
import { getVitePackageVersion } from '../../helpers/vite-package-version.js';
|
|
64
|
+
import { createNodeBuiltinPolyfillEsbuildPlugin, createSolidJsxEsbuildPlugin, createUnicodeRegexEsbuildPlugin, createVendorEsbuildPlugin, createWebpackLoaderStubEsbuildPlugin, createOptionalDependencyStubEsbuildPlugin, createNativeAddonStubEsbuildPlugin } from '../shared/vendor/vendor-esbuild-plugins.js';
|
|
65
|
+
import { getVendorManifest, setVendorRuntimeModuleProvider } from '../shared/vendor/registry.js';
|
|
66
|
+
import { collectVendorModules } from '../shared/vendor/manifest-collect.js';
|
|
67
|
+
import { generatePlatformPolyfills } from '../shared/runtime/platform-polyfills.js';
|
|
68
|
+
import { getAngularLinkerFactory, runAngularLinker } from '../frameworks/angular/build/shared-linker.js';
|
|
69
|
+
import { getBlockedDeviceNodeModulesReason, isFlavorClientPackageSpecifier, resolveCandidateFilePath } from './websocket-module-specifiers.js';
|
|
70
|
+
import { extractDirectExportedNames, JS_IDENTIFIER_RE, parseExportSpecList } from './websocket-core-bridge.js';
|
|
71
|
+
import { hasExistingDefaultExport } from './ns-core-cjs-shape.js';
|
|
72
|
+
import { loadPersistedBootRecording } from './boot-recording.js';
|
|
73
|
+
import { setDeviceModuleHeaders } from './route-helpers.js';
|
|
74
|
+
export const DEPS_BUNDLE_PATH = '/ns/deps-bundle.mjs';
|
|
75
|
+
/**
|
|
76
|
+
* Per-module node_modules serving mode (vs the default single-eval deps
|
|
77
|
+
* bundle). `NS_DEPS_PER_MODULE=1|true` forces per-module serving — the right
|
|
78
|
+
* mode when hand-editing files inside node_modules (patch-package workflows).
|
|
79
|
+
*/
|
|
80
|
+
export function isDepsPerModuleServingEnabled(env = process.env) {
|
|
81
|
+
const v = env.NS_DEPS_PER_MODULE;
|
|
82
|
+
return v === '1' || v === 'true';
|
|
83
|
+
}
|
|
84
|
+
// ============================================================================
|
|
85
|
+
// Entry resolution — recorded `/ns/m/node_modules/...` paths → physical files
|
|
86
|
+
// ============================================================================
|
|
87
|
+
const SCRIPT_EXT_RE = /\.(ts|tsx|js|jsx|mjs|mts|cts)$/i;
|
|
88
|
+
const NON_BUNDLEABLE_EXT_RE = /\.(css|scss|sass|less|json|html|vue|svelte)$/i;
|
|
89
|
+
/** Registry key for a physical file: substring from the LAST node_modules segment. */
|
|
90
|
+
export function depsRegistryKeyForFile(absPath) {
|
|
91
|
+
const posix = absPath.replace(/\\/g, '/');
|
|
92
|
+
const idx = posix.lastIndexOf('/node_modules/');
|
|
93
|
+
if (idx === -1)
|
|
94
|
+
return null;
|
|
95
|
+
return posix.slice(idx + 1);
|
|
96
|
+
}
|
|
97
|
+
function platformResolveExtensions(platform) {
|
|
98
|
+
if (platform === 'android') {
|
|
99
|
+
return ['.android.tsx', '.tsx', '.android.jsx', '.jsx', '.android.ts', '.ts', '.android.js', '.js', '.mjs', '.cjs', '.json'];
|
|
100
|
+
}
|
|
101
|
+
return ['.ios.tsx', '.visionos.tsx', '.tsx', '.ios.jsx', '.visionos.jsx', '.jsx', '.ios.ts', '.visionos.ts', '.ts', '.ios.js', '.visionos.js', '.js', '.mjs', '.cjs', '.json'];
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Same extension/index fan-out the /ns/m route uses for a served spec,
|
|
105
|
+
* platform-suffixed variants first (`canvas` → `canvas.ios.js` before
|
|
106
|
+
* `canvas.js`, `Paywall` → `Paywall/index.ios.js`) so shim lookup lands on
|
|
107
|
+
* the same file the per-module pipeline would serve.
|
|
108
|
+
*/
|
|
109
|
+
export function buildDepsCandidateSpecs(spec, platform) {
|
|
110
|
+
const hasExt = SCRIPT_EXT_RE.test(spec);
|
|
111
|
+
const baseNoExt = hasExt ? spec.replace(SCRIPT_EXT_RE, '') : spec;
|
|
112
|
+
const exts = platformResolveExtensions(platform);
|
|
113
|
+
return [...(hasExt ? [spec] : []), ...exts.map((ext) => baseNoExt + ext), ...exts.map((ext) => baseNoExt + '/index' + ext)];
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Resolve a package ROOT spec (`/node_modules/<pkg>`) to its entry file via
|
|
117
|
+
* the package's own `exports['.']`/`module`/`main`, honoring platform
|
|
118
|
+
* suffix variants NativeScript plugins commonly ship (`index.ios.js`).
|
|
119
|
+
*/
|
|
120
|
+
function resolvePackageRootEntry(spec, roots, platform) {
|
|
121
|
+
const pkgSub = spec.replace(/^\/node_modules\//, '');
|
|
122
|
+
if (!pkgSub || pkgSub.includes('/node_modules/'))
|
|
123
|
+
return null;
|
|
124
|
+
const parts = pkgSub.split('/');
|
|
125
|
+
const isScoped = pkgSub.startsWith('@');
|
|
126
|
+
if (parts.length !== (isScoped ? 2 : 1))
|
|
127
|
+
return null;
|
|
128
|
+
for (const root of roots) {
|
|
129
|
+
const pkgDir = path.join(root, 'node_modules', ...parts);
|
|
130
|
+
const pkgJsonPath = path.join(pkgDir, 'package.json');
|
|
131
|
+
if (!existsSync(pkgJsonPath))
|
|
132
|
+
continue;
|
|
133
|
+
let pkg;
|
|
134
|
+
try {
|
|
135
|
+
pkg = JSON.parse(readFileSync(pkgJsonPath, 'utf-8'));
|
|
136
|
+
}
|
|
137
|
+
catch {
|
|
138
|
+
continue;
|
|
139
|
+
}
|
|
140
|
+
const candidates = [];
|
|
141
|
+
const visitExports = (node) => {
|
|
142
|
+
if (!node)
|
|
143
|
+
return;
|
|
144
|
+
if (typeof node === 'string') {
|
|
145
|
+
candidates.push(node);
|
|
146
|
+
return;
|
|
147
|
+
}
|
|
148
|
+
if (typeof node === 'object' && !Array.isArray(node)) {
|
|
149
|
+
// Prefer client/ESM conditions in the order esbuild would.
|
|
150
|
+
for (const cond of ['module', 'import', 'browser', 'default', 'require']) {
|
|
151
|
+
if (node[cond] !== undefined)
|
|
152
|
+
visitExports(node[cond]);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
};
|
|
156
|
+
visitExports(pkg.exports?.['.'] ?? (typeof pkg.exports === 'string' ? pkg.exports : undefined));
|
|
157
|
+
if (typeof pkg.module === 'string')
|
|
158
|
+
candidates.push(pkg.module);
|
|
159
|
+
if (typeof pkg.main === 'string')
|
|
160
|
+
candidates.push(pkg.main);
|
|
161
|
+
candidates.push('index');
|
|
162
|
+
for (const cand of candidates) {
|
|
163
|
+
const abs = path.resolve(pkgDir, cand);
|
|
164
|
+
if (!abs.startsWith(pkgDir + path.sep))
|
|
165
|
+
continue;
|
|
166
|
+
if (existsSync(abs) && statSync(abs).isFile())
|
|
167
|
+
return abs;
|
|
168
|
+
const base = abs.replace(SCRIPT_EXT_RE, '');
|
|
169
|
+
for (const ext of platformResolveExtensions(platform)) {
|
|
170
|
+
if (existsSync(base + ext))
|
|
171
|
+
return base + ext;
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
return null;
|
|
176
|
+
}
|
|
177
|
+
/** `/node_modules/<pkg>` or `/node_modules/@scope/<pkg>` with no subpath. */
|
|
178
|
+
function isPackageRootSpec(spec) {
|
|
179
|
+
const pkgSub = spec.replace(/^\/node_modules\//, '');
|
|
180
|
+
if (!pkgSub || pkgSub === spec || pkgSub.includes('/node_modules/'))
|
|
181
|
+
return false;
|
|
182
|
+
return pkgSub.split('/').length === (pkgSub.startsWith('@') ? 2 : 1);
|
|
183
|
+
}
|
|
184
|
+
function resolveSpecToFile(spec, projectRoot, workspaceRoot, platform) {
|
|
185
|
+
const roots = [projectRoot, ...(workspaceRoot && path.resolve(workspaceRoot) !== path.resolve(projectRoot) ? [workspaceRoot] : [])];
|
|
186
|
+
// Package roots honor the declared entry (exports/module/main) FIRST —
|
|
187
|
+
// matching esbuild's resolution of bare imports inside the bundle. The
|
|
188
|
+
// index fan-out would otherwise pick stray root files like a shipped
|
|
189
|
+
// `index.ts` source whose relative imports aren't in the npm package
|
|
190
|
+
// (solid-navigation shape), minting a broken or second realm.
|
|
191
|
+
if (isPackageRootSpec(spec)) {
|
|
192
|
+
const entry = resolvePackageRootEntry(spec, roots, platform);
|
|
193
|
+
if (entry)
|
|
194
|
+
return entry;
|
|
195
|
+
}
|
|
196
|
+
for (const candidate of buildDepsCandidateSpecs(spec, platform)) {
|
|
197
|
+
const abs = resolveCandidateFilePath(candidate, projectRoot, workspaceRoot);
|
|
198
|
+
if (abs)
|
|
199
|
+
return abs;
|
|
200
|
+
}
|
|
201
|
+
return isPackageRootSpec(spec) ? null : resolvePackageRootEntry(spec, roots, platform);
|
|
202
|
+
}
|
|
203
|
+
// Never bundled: `@nativescript/core` belongs to the /ns/core bridge realm,
|
|
204
|
+
// and `@nativescript/vite` IS the dev tooling — its device-served client
|
|
205
|
+
// modules (hot registry, session bootstrap, framework strategies) must load
|
|
206
|
+
// independently of the app dependency closure, not as consumers of it.
|
|
207
|
+
// Bundling them would make the HMR client's evaluation depend on the entire
|
|
208
|
+
// deps payload (and deadlock the session bootstrap's client evict/re-import).
|
|
209
|
+
const NEVER_BUNDLED_SPEC_RE = /^\/node_modules\/@nativescript\/(?:core|vite)(?:\/|$)/;
|
|
210
|
+
const NEVER_BUNDLED_KEY_RE = /^node_modules\/@nativescript\/(?:core|vite)\//;
|
|
211
|
+
/**
|
|
212
|
+
* Map recorded boot paths to bundle entries. Skips: non-node_modules paths,
|
|
213
|
+
* blocked packages, the never-bundled `@nativescript/core` + `@nativescript/vite`
|
|
214
|
+
* realms, non-script assets, symlinked workspace-source packages, and files
|
|
215
|
+
* that cannot be resolved on disk (they stay per-module).
|
|
216
|
+
*/
|
|
217
|
+
export function resolveDepsEntriesFromRecording(recordedPaths, projectRoot, workspaceRoot, platform) {
|
|
218
|
+
const entries = [];
|
|
219
|
+
const seenKeys = new Set();
|
|
220
|
+
for (const recorded of recordedPaths) {
|
|
221
|
+
if (typeof recorded !== 'string' || !recorded.startsWith('/ns/m/node_modules/'))
|
|
222
|
+
continue;
|
|
223
|
+
const spec = recorded.slice('/ns/m'.length).replace(/[?#].*$/, '');
|
|
224
|
+
if (NON_BUNDLEABLE_EXT_RE.test(spec))
|
|
225
|
+
continue;
|
|
226
|
+
if (NEVER_BUNDLED_SPEC_RE.test(spec))
|
|
227
|
+
continue;
|
|
228
|
+
if (getBlockedDeviceNodeModulesReason(spec))
|
|
229
|
+
continue;
|
|
230
|
+
const absPath = resolveSpecToFile(spec, projectRoot, workspaceRoot, platform);
|
|
231
|
+
if (!absPath || NON_BUNDLEABLE_EXT_RE.test(absPath))
|
|
232
|
+
continue;
|
|
233
|
+
// Symlinked node_modules entries pointing at workspace source are app
|
|
234
|
+
// code in disguise — leave them to the Vite pipeline (same policy as
|
|
235
|
+
// filterExistingNodeModulesTransformCandidates).
|
|
236
|
+
try {
|
|
237
|
+
const real = realpathSync(absPath);
|
|
238
|
+
if (real !== absPath && !real.split(path.sep).includes('node_modules'))
|
|
239
|
+
continue;
|
|
240
|
+
}
|
|
241
|
+
catch {
|
|
242
|
+
continue;
|
|
243
|
+
}
|
|
244
|
+
const key = depsRegistryKeyForFile(absPath);
|
|
245
|
+
if (!key || seenKeys.has(key))
|
|
246
|
+
continue;
|
|
247
|
+
seenKeys.add(key);
|
|
248
|
+
entries.push({ spec, key, absPath });
|
|
249
|
+
}
|
|
250
|
+
return entries;
|
|
251
|
+
}
|
|
252
|
+
/**
|
|
253
|
+
* Seed bundle entries from the vendor collection (direct NativeScript-plugin
|
|
254
|
+
* and framework deps from package.json). This makes the bundle exist on the
|
|
255
|
+
* very first boot — no recording needed — and produces the specifier→key map
|
|
256
|
+
* that backs `__nsVendorRegistry` (see buildDepsVendorRuntimeModule), so the
|
|
257
|
+
* JS-side sync resolution chain resolves into THIS bundle's realm.
|
|
258
|
+
*/
|
|
259
|
+
export function resolveDepsEntriesFromVendorCollection(projectRoot, workspaceRoot, platform, flavor) {
|
|
260
|
+
const entries = [];
|
|
261
|
+
const vendorSpecToKey = new Map();
|
|
262
|
+
let collectedSpecs;
|
|
263
|
+
try {
|
|
264
|
+
collectedSpecs = collectVendorModules(projectRoot, platform, flavor).entries;
|
|
265
|
+
}
|
|
266
|
+
catch {
|
|
267
|
+
return { entries, vendorSpecToKey };
|
|
268
|
+
}
|
|
269
|
+
const seenKeys = new Set();
|
|
270
|
+
for (const bare of collectedSpecs) {
|
|
271
|
+
const spec = `/node_modules/${bare}`;
|
|
272
|
+
if (NEVER_BUNDLED_SPEC_RE.test(spec))
|
|
273
|
+
continue;
|
|
274
|
+
if (getBlockedDeviceNodeModulesReason(spec))
|
|
275
|
+
continue;
|
|
276
|
+
// Solid pins its runtime to dist/dev.js everywhere (see the routing
|
|
277
|
+
// plugin); the seed must land on the same file or the registry entry
|
|
278
|
+
// would mint a second solid realm.
|
|
279
|
+
const resolveTarget = flavor === 'solid' && bare === 'solid-js' ? '/node_modules/solid-js/dist/dev.js' : spec;
|
|
280
|
+
const absPath = resolveSpecToFile(resolveTarget, projectRoot, workspaceRoot, platform);
|
|
281
|
+
if (!absPath || NON_BUNDLEABLE_EXT_RE.test(absPath))
|
|
282
|
+
continue;
|
|
283
|
+
try {
|
|
284
|
+
const real = realpathSync(absPath);
|
|
285
|
+
if (real !== absPath && !real.split(path.sep).includes('node_modules'))
|
|
286
|
+
continue;
|
|
287
|
+
}
|
|
288
|
+
catch {
|
|
289
|
+
continue;
|
|
290
|
+
}
|
|
291
|
+
const key = depsRegistryKeyForFile(absPath);
|
|
292
|
+
if (!key)
|
|
293
|
+
continue;
|
|
294
|
+
vendorSpecToKey.set(bare, key);
|
|
295
|
+
if (seenKeys.has(key))
|
|
296
|
+
continue;
|
|
297
|
+
seenKeys.add(key);
|
|
298
|
+
entries.push({ spec, key, absPath });
|
|
299
|
+
}
|
|
300
|
+
return { entries, vendorSpecToKey };
|
|
301
|
+
}
|
|
302
|
+
// ============================================================================
|
|
303
|
+
// Bundle generation — two esbuild passes
|
|
304
|
+
// ============================================================================
|
|
305
|
+
/**
|
|
306
|
+
* Synthetic esbuild entry: evaluate the dep closure once and expose every
|
|
307
|
+
* bundled file's live namespace through `globalThis.__NS_DEPS_MODULES__`,
|
|
308
|
+
* keyed by node_modules-relative file path.
|
|
309
|
+
*/
|
|
310
|
+
export function buildDepsBundleEntryCode(files) {
|
|
311
|
+
const lines = [];
|
|
312
|
+
files.forEach(({ absPath }, i) => {
|
|
313
|
+
lines.push(`import * as __ns_dep_${i}__ from ${JSON.stringify(absPath)};`);
|
|
314
|
+
});
|
|
315
|
+
lines.push('');
|
|
316
|
+
lines.push('const __nsDepsReg = (globalThis.__NS_DEPS_MODULES__ || (globalThis.__NS_DEPS_MODULES__ = Object.create(null)));');
|
|
317
|
+
files.forEach(({ key }, i) => {
|
|
318
|
+
lines.push(`__nsDepsReg[${JSON.stringify(key)}] = __ns_dep_${i}__;`);
|
|
319
|
+
});
|
|
320
|
+
lines.push('export {};');
|
|
321
|
+
lines.push('');
|
|
322
|
+
return lines.join('\n');
|
|
323
|
+
}
|
|
324
|
+
// Node built-ins the device runtime cannot resolve — externalized exactly like
|
|
325
|
+
// the core and vendor bundle builds.
|
|
326
|
+
const NODE_BUILTINS = ['assert', 'async_hooks', 'buffer', 'child_process', 'cluster', 'console', 'constants', 'crypto', 'dgram', 'diagnostics_channel', 'dns', 'domain', 'events', 'fs', 'fs/promises', 'http', 'http2', 'https', 'inspector', 'module', 'net', 'os', 'path', 'path/posix', 'path/win32', 'perf_hooks', 'process', 'punycode', 'querystring', 'readline', 'repl', 'stream', 'stream/web', 'stream/promises', 'string_decoder', 'sys', 'timers', 'timers/promises', 'tls', 'trace_events', 'tty', 'url', 'util', 'v8', 'vm', 'wasi', 'worker_threads', 'zlib'];
|
|
327
|
+
const NODE_EXTERNALS = [...NODE_BUILTINS, ...NODE_BUILTINS.map((b) => `node:${b}`)];
|
|
328
|
+
const NODE_BUILTIN_SET = new Set(NODE_EXTERNALS);
|
|
329
|
+
/**
|
|
330
|
+
* Import routing inside the deps bundle, mirroring per-module
|
|
331
|
+
* `rewriteImports` topology. The single-realm rules:
|
|
332
|
+
* - `@nativescript/core[/*]` → external bare (device import map → /ns/core).
|
|
333
|
+
* - Dynamic `import()` targets → external `/ns/m/node_modules/...` URL:
|
|
334
|
+
* evaluation stays lazy and the target keeps its per-URL identity (a shim
|
|
335
|
+
* when the target is itself bundled; dynamic imports run after the bundle
|
|
336
|
+
* finishes evaluating, so the shim's registry read cannot race it).
|
|
337
|
+
* - `@nativescript/vite` client modules stay per-module (see
|
|
338
|
+
* NEVER_BUNDLED_SPEC_RE) → external canonical /ns/m URL.
|
|
339
|
+
* - Solid flavor: bare `solid-js` pins to `solid-js/dist/dev.js` INSIDE the
|
|
340
|
+
* bundle — the same file `rewriteImports` routes every importer to — so
|
|
341
|
+
* the bundle can never carry a second solid realm.
|
|
342
|
+
* - Everything else internalizes. Bare specs esbuild cannot resolve get
|
|
343
|
+
* platform-aware resolution (`index.ios.js`-style entries esbuild's
|
|
344
|
+
* resolver misses); only specs with no on-disk resolution at all stay
|
|
345
|
+
* external bare. Anything resolvable MUST internalize: this bundle is the
|
|
346
|
+
* only node_modules realm, so an external bare spec would resolve
|
|
347
|
+
* on-device through the import map back into a shim of this bundle — an
|
|
348
|
+
* evaluation cycle (the shim's registry read runs before the bundle body
|
|
349
|
+
* finishes and throws). Pass 2 registers every internalized file, keeping
|
|
350
|
+
* per-URL identity for all of them.
|
|
351
|
+
*/
|
|
352
|
+
function createDepsImportRoutingPlugin(projectRoot, workspaceRoot, platform, flavor) {
|
|
353
|
+
return {
|
|
354
|
+
name: 'ns-deps-import-routing',
|
|
355
|
+
setup(build) {
|
|
356
|
+
build.onResolve({ filter: /.*/ }, async (args) => {
|
|
357
|
+
if (args.pluginData?.nsDepsRoutingProbe)
|
|
358
|
+
return undefined;
|
|
359
|
+
if (args.kind === 'entry-point')
|
|
360
|
+
return undefined;
|
|
361
|
+
const spec = args.path;
|
|
362
|
+
const probeResolve = (target) => build.resolve(target, {
|
|
363
|
+
resolveDir: args.resolveDir,
|
|
364
|
+
kind: args.kind,
|
|
365
|
+
importer: args.importer,
|
|
366
|
+
pluginData: { nsDepsRoutingProbe: true },
|
|
367
|
+
});
|
|
368
|
+
if (args.kind === 'dynamic-import') {
|
|
369
|
+
if (spec.startsWith('/ns/') || /^https?:\/\//.test(spec))
|
|
370
|
+
return { path: spec, external: true };
|
|
371
|
+
const probe = await probeResolve(spec);
|
|
372
|
+
if (probe.errors.length > 0 || !probe.path || probe.external)
|
|
373
|
+
return probe;
|
|
374
|
+
const key = depsRegistryKeyForFile(probe.path);
|
|
375
|
+
if (!key)
|
|
376
|
+
return probe;
|
|
377
|
+
return { path: `/ns/m/${key.replace(SCRIPT_EXT_RE, '')}`, external: true };
|
|
378
|
+
}
|
|
379
|
+
if (spec.startsWith('.') || spec.startsWith('/') || /^[A-Za-z]:[\\/]/.test(spec))
|
|
380
|
+
return undefined;
|
|
381
|
+
if (NODE_BUILTIN_SET.has(spec))
|
|
382
|
+
return undefined;
|
|
383
|
+
if (/^@nativescript\/core(?:\/|$)/.test(spec)) {
|
|
384
|
+
return { path: spec, external: true };
|
|
385
|
+
}
|
|
386
|
+
if (/^@nativescript\/vite(?:\/|$)/.test(spec) || isFlavorClientPackageSpecifier(spec)) {
|
|
387
|
+
return { path: `/ns/m/node_modules/${spec.replace(SCRIPT_EXT_RE, '')}`, external: true };
|
|
388
|
+
}
|
|
389
|
+
if (flavor === 'solid' && spec === 'solid-js') {
|
|
390
|
+
const pinned = await probeResolve('solid-js/dist/dev.js');
|
|
391
|
+
if (!pinned.errors.length && pinned.path)
|
|
392
|
+
return pinned;
|
|
393
|
+
}
|
|
394
|
+
const probe = await probeResolve(spec);
|
|
395
|
+
if (probe.errors.length > 0 || !probe.path) {
|
|
396
|
+
const resolved = resolveSpecToFile(`/node_modules/${spec}`, projectRoot, workspaceRoot, platform);
|
|
397
|
+
if (resolved)
|
|
398
|
+
return { path: resolved };
|
|
399
|
+
return { path: spec, external: true };
|
|
400
|
+
}
|
|
401
|
+
return probe;
|
|
402
|
+
});
|
|
403
|
+
},
|
|
404
|
+
};
|
|
405
|
+
}
|
|
406
|
+
/**
|
|
407
|
+
* Angular partial-declaration linker for the deps bundle. Broader than the
|
|
408
|
+
* vendor build's `@angular/`-scoped pass: recorded closures include partial-
|
|
409
|
+
* compiled LIBRARY fesm files (e.g. nativescript-fonticon/angular) that the
|
|
410
|
+
* per-module pipeline links at serve time, so the bundle must link any
|
|
411
|
+
* node_modules file carrying `ɵɵngDeclare`.
|
|
412
|
+
*/
|
|
413
|
+
function createDepsAngularLinkerPlugin(projectRoot) {
|
|
414
|
+
return {
|
|
415
|
+
name: 'ns-deps-angular-linker',
|
|
416
|
+
async setup(build) {
|
|
417
|
+
const { babel, createLinker } = await getAngularLinkerFactory(projectRoot);
|
|
418
|
+
if (!babel || !createLinker)
|
|
419
|
+
return;
|
|
420
|
+
build.onLoad({ filter: /node_modules[\\/].*\.[mc]?js$/ }, async (args) => {
|
|
421
|
+
let source;
|
|
422
|
+
try {
|
|
423
|
+
source = readFileSync(args.path, 'utf8');
|
|
424
|
+
}
|
|
425
|
+
catch {
|
|
426
|
+
return undefined;
|
|
427
|
+
}
|
|
428
|
+
if (!source.includes('\u0275\u0275ngDeclare'))
|
|
429
|
+
return undefined;
|
|
430
|
+
try {
|
|
431
|
+
const linked = await runAngularLinker(source, { filename: args.path, projectRoot, freshPlugin: true });
|
|
432
|
+
return { contents: linked || source, loader: 'js' };
|
|
433
|
+
}
|
|
434
|
+
catch {
|
|
435
|
+
return { contents: source, loader: 'js' };
|
|
436
|
+
}
|
|
437
|
+
});
|
|
438
|
+
},
|
|
439
|
+
};
|
|
440
|
+
}
|
|
441
|
+
// ============================================================================
|
|
442
|
+
// Disk cache — same shape as the core bundle cache (node_modules/.ns-vite).
|
|
443
|
+
// The key covers the lockfile (dependency identity), the full entry set
|
|
444
|
+
// (recorded + vendor-seeded), defines, and the vite package version. Opt out
|
|
445
|
+
// with `NS_DEPS_BUNDLE_NO_DISK_CACHE=1`.
|
|
446
|
+
// ============================================================================
|
|
447
|
+
const DEPS_BUNDLE_DISK_CACHE_SCHEMA = 4;
|
|
448
|
+
function isDepsBundleDiskCacheDisabled(env = process.env) {
|
|
449
|
+
const v = env.NS_DEPS_BUNDLE_NO_DISK_CACHE;
|
|
450
|
+
return v === '1' || v === 'true';
|
|
451
|
+
}
|
|
452
|
+
function lockfileFingerprint(projectRoot) {
|
|
453
|
+
for (const name of ['package-lock.json', 'pnpm-lock.yaml', 'yarn.lock', 'bun.lock', 'bun.lockb']) {
|
|
454
|
+
const file = path.join(projectRoot, name);
|
|
455
|
+
try {
|
|
456
|
+
const st = statSync(file);
|
|
457
|
+
return `${name}:${st.mtimeMs}:${st.size}`;
|
|
458
|
+
}
|
|
459
|
+
catch { }
|
|
460
|
+
}
|
|
461
|
+
return 'none';
|
|
462
|
+
}
|
|
463
|
+
export function computeDepsBundleCacheKey(input) {
|
|
464
|
+
const payload = JSON.stringify({
|
|
465
|
+
schema: DEPS_BUNDLE_DISK_CACHE_SCHEMA,
|
|
466
|
+
platform: input.platform,
|
|
467
|
+
mode: input.mode,
|
|
468
|
+
flavor: input.flavor,
|
|
469
|
+
defines: input.defines,
|
|
470
|
+
entryKeys: input.entryKeys,
|
|
471
|
+
lockfile: input.lockfile,
|
|
472
|
+
vitePackageVersion: input.vitePackageVersion,
|
|
473
|
+
});
|
|
474
|
+
return createHash('sha1').update(payload).digest('hex');
|
|
475
|
+
}
|
|
476
|
+
function depsBundleCacheDir(projectRoot) {
|
|
477
|
+
return path.join(projectRoot, 'node_modules', '.ns-vite');
|
|
478
|
+
}
|
|
479
|
+
function depsBundleCacheFileBase(platform, key) {
|
|
480
|
+
return `deps-bundle-${platform}-${key.slice(0, 12)}`;
|
|
481
|
+
}
|
|
482
|
+
export function tryLoadDepsBundleFromDisk(projectRoot, platform, key) {
|
|
483
|
+
try {
|
|
484
|
+
const dir = depsBundleCacheDir(projectRoot);
|
|
485
|
+
const base = depsBundleCacheFileBase(platform, key);
|
|
486
|
+
const metaPath = path.join(dir, `${base}.json`);
|
|
487
|
+
const codePath = path.join(dir, `${base}.mjs`);
|
|
488
|
+
if (!existsSync(metaPath) || !existsSync(codePath))
|
|
489
|
+
return null;
|
|
490
|
+
const meta = JSON.parse(readFileSync(metaPath, 'utf-8'));
|
|
491
|
+
if (!meta || meta.schema !== DEPS_BUNDLE_DISK_CACHE_SCHEMA || meta.key !== key)
|
|
492
|
+
return null;
|
|
493
|
+
if (!Array.isArray(meta.keys) || typeof meta.specToKey !== 'object' || typeof meta.keyToFile !== 'object' || typeof meta.vendorSpecToKey !== 'object')
|
|
494
|
+
return null;
|
|
495
|
+
const code = readFileSync(codePath, 'utf-8');
|
|
496
|
+
const hash = createHash('sha1').update(code).digest('hex');
|
|
497
|
+
if (hash !== meta.hash)
|
|
498
|
+
return null;
|
|
499
|
+
return {
|
|
500
|
+
code,
|
|
501
|
+
keys: new Set(meta.keys.filter((k) => typeof k === 'string')),
|
|
502
|
+
specToKey: new Map(Object.entries(meta.specToKey)),
|
|
503
|
+
keyToFile: new Map(Object.entries(meta.keyToFile)),
|
|
504
|
+
vendorSpecToKey: new Map(Object.entries(meta.vendorSpecToKey)),
|
|
505
|
+
hash,
|
|
506
|
+
builtAt: typeof meta.builtAt === 'number' ? meta.builtAt : Date.now(),
|
|
507
|
+
buildMs: typeof meta.buildMs === 'number' ? meta.buildMs : 0,
|
|
508
|
+
};
|
|
509
|
+
}
|
|
510
|
+
catch {
|
|
511
|
+
return null;
|
|
512
|
+
}
|
|
513
|
+
}
|
|
514
|
+
export function saveDepsBundleToDisk(projectRoot, platform, key, state, verbose) {
|
|
515
|
+
try {
|
|
516
|
+
const dir = depsBundleCacheDir(projectRoot);
|
|
517
|
+
mkdirSync(dir, { recursive: true });
|
|
518
|
+
const base = depsBundleCacheFileBase(platform, key);
|
|
519
|
+
try {
|
|
520
|
+
for (const name of readdirSync(dir)) {
|
|
521
|
+
if (name.startsWith(`deps-bundle-${platform}-`) && !name.startsWith(base)) {
|
|
522
|
+
unlinkSync(path.join(dir, name));
|
|
523
|
+
}
|
|
524
|
+
}
|
|
525
|
+
}
|
|
526
|
+
catch { }
|
|
527
|
+
writeFileSync(path.join(dir, `${base}.mjs`), state.code);
|
|
528
|
+
writeFileSync(path.join(dir, `${base}.json`), JSON.stringify({
|
|
529
|
+
schema: DEPS_BUNDLE_DISK_CACHE_SCHEMA,
|
|
530
|
+
key,
|
|
531
|
+
hash: state.hash,
|
|
532
|
+
builtAt: state.builtAt,
|
|
533
|
+
buildMs: state.buildMs,
|
|
534
|
+
keys: Array.from(state.keys),
|
|
535
|
+
specToKey: Object.fromEntries(state.specToKey),
|
|
536
|
+
keyToFile: Object.fromEntries(state.keyToFile),
|
|
537
|
+
vendorSpecToKey: Object.fromEntries(state.vendorSpecToKey),
|
|
538
|
+
}));
|
|
539
|
+
}
|
|
540
|
+
catch (error) {
|
|
541
|
+
if (verbose) {
|
|
542
|
+
console.warn(`[ns-deps-bundle] disk cache write failed (non-fatal): ${error?.message || error}`);
|
|
543
|
+
}
|
|
544
|
+
}
|
|
545
|
+
}
|
|
546
|
+
export async function generateDepsBundle(options) {
|
|
547
|
+
const { projectRoot, platform, mode, flavor, verbose } = options;
|
|
548
|
+
const t0 = Date.now();
|
|
549
|
+
const workspaceRoot = getMonorepoWorkspaceRoot(projectRoot);
|
|
550
|
+
const recordedEntries = resolveDepsEntriesFromRecording(options.recordedPaths, projectRoot, workspaceRoot, String(platform));
|
|
551
|
+
const vendorSeed = resolveDepsEntriesFromVendorCollection(projectRoot, workspaceRoot, String(platform), flavor);
|
|
552
|
+
// Union: recorded deep files + vendor-collected package roots. Recorded
|
|
553
|
+
// entries win on key collisions so their served-spec mapping is preserved;
|
|
554
|
+
// vendorSpecToKey still points every vendor specifier at its bundled key.
|
|
555
|
+
const entries = [...recordedEntries];
|
|
556
|
+
const mergedKeys = new Set(recordedEntries.map((e) => e.key));
|
|
557
|
+
for (const entry of vendorSeed.entries) {
|
|
558
|
+
if (mergedKeys.has(entry.key))
|
|
559
|
+
continue;
|
|
560
|
+
mergedKeys.add(entry.key);
|
|
561
|
+
entries.push(entry);
|
|
562
|
+
}
|
|
563
|
+
if (!entries.length)
|
|
564
|
+
return null;
|
|
565
|
+
const defines = (() => {
|
|
566
|
+
const raw = getGlobalDefines({
|
|
567
|
+
platform: String(platform),
|
|
568
|
+
targetMode: mode === 'development' ? 'development' : 'production',
|
|
569
|
+
verbose: !!verbose,
|
|
570
|
+
flavor: flavor ?? '',
|
|
571
|
+
isCI: !!process.env.CI,
|
|
572
|
+
});
|
|
573
|
+
const out = {};
|
|
574
|
+
for (const [key, value] of Object.entries(raw)) {
|
|
575
|
+
out[key] = typeof value === 'string' ? value : JSON.stringify(value);
|
|
576
|
+
}
|
|
577
|
+
out['process.env.NODE_ENV'] = JSON.stringify(mode === 'development' ? 'development' : 'production');
|
|
578
|
+
// webpack-HMR idiom carried by ESM-published packages (e.g.
|
|
579
|
+
// @nativescript/canvas-polyfill's `if (module.hot) ...` at module top
|
|
580
|
+
// level). In the single-eval ESM bundle a FREE `module` reference is a
|
|
581
|
+
// ReferenceError the moment the bundle evaluates. esbuild's define only
|
|
582
|
+
// substitutes free references, so CJS-wrapped code (where `module` is a
|
|
583
|
+
// bound variable) is untouched.
|
|
584
|
+
out['module.hot'] = 'undefined';
|
|
585
|
+
return out;
|
|
586
|
+
})();
|
|
587
|
+
const diskCacheDisabled = isDepsBundleDiskCacheDisabled();
|
|
588
|
+
let cacheKey = null;
|
|
589
|
+
if (!diskCacheDisabled) {
|
|
590
|
+
cacheKey = computeDepsBundleCacheKey({
|
|
591
|
+
platform: String(platform),
|
|
592
|
+
mode: String(mode),
|
|
593
|
+
flavor: flavor ?? '',
|
|
594
|
+
defines,
|
|
595
|
+
entryKeys: entries.map((e) => e.key).sort(),
|
|
596
|
+
lockfile: lockfileFingerprint(projectRoot),
|
|
597
|
+
vitePackageVersion: getVitePackageVersion(),
|
|
598
|
+
});
|
|
599
|
+
const cached = tryLoadDepsBundleFromDisk(projectRoot, String(platform), cacheKey);
|
|
600
|
+
if (cached) {
|
|
601
|
+
if (verbose) {
|
|
602
|
+
console.log(`[ns-deps-bundle] loaded from disk cache: ${cached.keys.size} modules, ${(cached.code.length / 1024).toFixed(0)}kb in ${Date.now() - t0}ms (hash ${cached.hash.slice(0, 8)}, key ${cacheKey.slice(0, 12)})`);
|
|
603
|
+
}
|
|
604
|
+
return cached;
|
|
605
|
+
}
|
|
606
|
+
}
|
|
607
|
+
// createWebpackLoaderStubEsbuildPlugin runs first: legacy `loader!./x`
|
|
608
|
+
// specifiers (dead NS 6/7 webpack branches in plugins) must be stubbed
|
|
609
|
+
// before any resolver sees them — one such specifier anywhere in the dep
|
|
610
|
+
// closure would otherwise hard-fail the whole bundle.
|
|
611
|
+
// createNodeBuiltinPolyfillEsbuildPlugin bundles installed npm polyfills
|
|
612
|
+
// (buffer, events, ...) that would otherwise leak as bare builtin externals
|
|
613
|
+
// the device cannot resolve.
|
|
614
|
+
const buildPlugins = () => [
|
|
615
|
+
createWebpackLoaderStubEsbuildPlugin(),
|
|
616
|
+
createNodeBuiltinPolyfillEsbuildPlugin(projectRoot, NODE_BUILTINS),
|
|
617
|
+
createNativeClassEsbuildPlugin(platform),
|
|
618
|
+
createVendorEsbuildPlugin(projectRoot),
|
|
619
|
+
createDepsImportRoutingPlugin(projectRoot, workspaceRoot, String(platform), flavor),
|
|
620
|
+
...(flavor === 'angular' ? [createDepsAngularLinkerPlugin(projectRoot)] : []),
|
|
621
|
+
...(flavor === 'solid' ? [createSolidJsxEsbuildPlugin(projectRoot)] : []),
|
|
622
|
+
createUnicodeRegexEsbuildPlugin(projectRoot),
|
|
623
|
+
createOptionalDependencyStubEsbuildPlugin(projectRoot),
|
|
624
|
+
createNativeAddonStubEsbuildPlugin(),
|
|
625
|
+
];
|
|
626
|
+
const sharedBuildOptions = {
|
|
627
|
+
platform: 'neutral',
|
|
628
|
+
format: 'esm',
|
|
629
|
+
bundle: true,
|
|
630
|
+
target: 'es2019',
|
|
631
|
+
// Keep every module body — dep packages rely on registration side
|
|
632
|
+
// effects the same way core does.
|
|
633
|
+
treeShaking: false,
|
|
634
|
+
sourcemap: false,
|
|
635
|
+
write: false,
|
|
636
|
+
logLevel: 'silent',
|
|
637
|
+
legalComments: 'eof',
|
|
638
|
+
conditions: ['module', 'react-native', 'import', 'browser', 'default'],
|
|
639
|
+
mainFields: ['module', 'browser', 'main'],
|
|
640
|
+
resolveExtensions: platformResolveExtensions(String(platform)),
|
|
641
|
+
absWorkingDir: projectRoot,
|
|
642
|
+
loader: { '.css': 'text', '.json': 'json' },
|
|
643
|
+
define: defines,
|
|
644
|
+
external: NODE_EXTERNALS,
|
|
645
|
+
};
|
|
646
|
+
// Pass 1: discover the full static input closure of the entries. Pass 2
|
|
647
|
+
// registers EVERY input, so any /ns/m URL that later resolves to a bundled
|
|
648
|
+
// file serves a shim into the single bundle realm.
|
|
649
|
+
const entryKeySet = new Set(entries.map((e) => e.key));
|
|
650
|
+
const discovery = await esbuild.build({
|
|
651
|
+
...sharedBuildOptions,
|
|
652
|
+
stdin: {
|
|
653
|
+
contents: entries.map((e) => `import ${JSON.stringify(e.absPath)};`).join('\n'),
|
|
654
|
+
resolveDir: projectRoot,
|
|
655
|
+
sourcefile: 'ns-deps-bundle-discovery.ts',
|
|
656
|
+
loader: 'ts',
|
|
657
|
+
},
|
|
658
|
+
metafile: true,
|
|
659
|
+
plugins: buildPlugins(),
|
|
660
|
+
});
|
|
661
|
+
const files = entries.map(({ key, absPath }) => ({ key, absPath }));
|
|
662
|
+
for (const input of Object.keys(discovery.metafile?.inputs ?? {})) {
|
|
663
|
+
if (input === '<stdin>' || input.includes(':') || !input.includes('node_modules/'))
|
|
664
|
+
continue;
|
|
665
|
+
const absPath = path.resolve(projectRoot, input);
|
|
666
|
+
if (!existsSync(absPath))
|
|
667
|
+
continue;
|
|
668
|
+
const key = depsRegistryKeyForFile(absPath);
|
|
669
|
+
if (!key || entryKeySet.has(key) || NEVER_BUNDLED_KEY_RE.test(key))
|
|
670
|
+
continue;
|
|
671
|
+
entryKeySet.add(key);
|
|
672
|
+
files.push({ key, absPath });
|
|
673
|
+
}
|
|
674
|
+
const buildResult = await esbuild.build({
|
|
675
|
+
...sharedBuildOptions,
|
|
676
|
+
stdin: {
|
|
677
|
+
contents: buildDepsBundleEntryCode(files),
|
|
678
|
+
resolveDir: projectRoot,
|
|
679
|
+
sourcefile: 'ns-deps-bundle-entry.ts',
|
|
680
|
+
loader: 'ts',
|
|
681
|
+
},
|
|
682
|
+
plugins: buildPlugins(),
|
|
683
|
+
});
|
|
684
|
+
if (!buildResult.outputFiles?.length) {
|
|
685
|
+
throw new Error('deps bundle generation produced no output');
|
|
686
|
+
}
|
|
687
|
+
// Platform polyfills (self, AbortController, ...) run before any dep module
|
|
688
|
+
// body — this bundle is the first node_modules code a session evaluates.
|
|
689
|
+
const code = ['/* /ns/deps-bundle.mjs — single-eval node_modules dep closure (dev bundle mode) */', generatePlatformPolyfills(), buildResult.outputFiles[0].text].join('\n');
|
|
690
|
+
const hash = createHash('sha1').update(code).digest('hex');
|
|
691
|
+
const state = {
|
|
692
|
+
code,
|
|
693
|
+
keys: new Set(files.map((f) => f.key)),
|
|
694
|
+
specToKey: new Map(entries.map((e) => [e.spec, e.key])),
|
|
695
|
+
keyToFile: new Map(files.map((f) => [f.key, f.absPath])),
|
|
696
|
+
vendorSpecToKey: vendorSeed.vendorSpecToKey,
|
|
697
|
+
hash,
|
|
698
|
+
builtAt: Date.now(),
|
|
699
|
+
buildMs: Date.now() - t0,
|
|
700
|
+
};
|
|
701
|
+
if (verbose) {
|
|
702
|
+
console.log(`[ns-deps-bundle] built ${files.length} modules (${recordedEntries.length} recorded + ${vendorSeed.entries.length} vendor-seeded), ${(code.length / 1024).toFixed(0)}kb in ${state.buildMs}ms (hash ${hash.slice(0, 8)})`);
|
|
703
|
+
}
|
|
704
|
+
if (!diskCacheDisabled && cacheKey) {
|
|
705
|
+
saveDepsBundleToDisk(projectRoot, String(platform), cacheKey, state, verbose);
|
|
706
|
+
}
|
|
707
|
+
return state;
|
|
708
|
+
}
|
|
709
|
+
const ESM_SYNTAX_RE = /^[ \t]*(?:import[\s{"'*]|export[\s{*])/m;
|
|
710
|
+
function resolveLocalReExportTarget(spec, importerPath, platform) {
|
|
711
|
+
const base = path.resolve(path.dirname(importerPath), spec);
|
|
712
|
+
if (existsSync(base) && statSync(base).isFile())
|
|
713
|
+
return base;
|
|
714
|
+
for (const ext of platformResolveExtensions(platform)) {
|
|
715
|
+
for (const candidate of [base + ext, base + '/index' + ext]) {
|
|
716
|
+
if (existsSync(candidate) && statSync(candidate).isFile())
|
|
717
|
+
return candidate;
|
|
718
|
+
}
|
|
719
|
+
}
|
|
720
|
+
return null;
|
|
721
|
+
}
|
|
722
|
+
// Static CJS export-name discovery: `exports.NAME = ...` and
|
|
723
|
+
// `Object.defineProperty(exports, "NAME", ...)` assignments (transpiled-to-CJS
|
|
724
|
+
// packages like downsample). UMD factories (`module.exports = fn()`) expose no
|
|
725
|
+
// static names — those are flagged `opaqueCjs` so the shim path can still
|
|
726
|
+
// serve their (default-only) namespace instead of re-evaluating them
|
|
727
|
+
// per-module.
|
|
728
|
+
const CJS_EXPORT_ASSIGN_RE = /\bexports\.([$_\p{ID_Start}][$\p{ID_Continue}]*)\s*=/gu;
|
|
729
|
+
const CJS_DEFINE_PROPERTY_RE = /\bObject\.defineProperty\(\s*exports\s*,\s*["']([$_\p{ID_Start}][$\p{ID_Continue}]*)["']/gu;
|
|
730
|
+
function collectCjsExportInfo(code) {
|
|
731
|
+
const names = new Set();
|
|
732
|
+
let match;
|
|
733
|
+
while ((match = CJS_EXPORT_ASSIGN_RE.exec(code)) !== null)
|
|
734
|
+
names.add(match[1]);
|
|
735
|
+
while ((match = CJS_DEFINE_PROPERTY_RE.exec(code)) !== null)
|
|
736
|
+
names.add(match[1]);
|
|
737
|
+
names.delete('__esModule');
|
|
738
|
+
if (names.size === 0)
|
|
739
|
+
return { names: null, hasDefault: false, opaqueCjs: true };
|
|
740
|
+
const hasDefault = names.delete('default');
|
|
741
|
+
return { names: Array.from(names).sort(), hasDefault };
|
|
742
|
+
}
|
|
743
|
+
/**
|
|
744
|
+
* Static export-name discovery for a node_modules file. ESM: direct exports
|
|
745
|
+
* plus recursion through RELATIVE `export * from` chains (the shape deep
|
|
746
|
+
* package barrels like rxjs's index take). CJS: `exports.NAME` assignment
|
|
747
|
+
* scanning (esbuild's interop exposes those names on the bundled namespace at
|
|
748
|
+
* runtime). Returns `names: null` for files whose export surface is not
|
|
749
|
+
* statically enumerable — with two DIFFERENT consequences downstream:
|
|
750
|
+
* CJS/UMD files additionally carry `opaqueCjs: true` and still get a
|
|
751
|
+
* default-only shim (their bundled namespace has nothing but `default`);
|
|
752
|
+
* ESM files with a bare `export * from 'pkg'` or an unresolvable relative
|
|
753
|
+
* `export *` target keep per-module serving, where the transform pipeline
|
|
754
|
+
* resolves the star through the import map.
|
|
755
|
+
*/
|
|
756
|
+
export function collectDepsModuleExportInfo(absPath, platform, seen = new Set()) {
|
|
757
|
+
if (seen.has(absPath))
|
|
758
|
+
return { names: [], hasDefault: false };
|
|
759
|
+
seen.add(absPath);
|
|
760
|
+
let code = '';
|
|
761
|
+
try {
|
|
762
|
+
code = readFileSync(absPath, 'utf8');
|
|
763
|
+
}
|
|
764
|
+
catch {
|
|
765
|
+
return { names: null, hasDefault: false };
|
|
766
|
+
}
|
|
767
|
+
if (!ESM_SYNTAX_RE.test(code))
|
|
768
|
+
return collectCjsExportInfo(code);
|
|
769
|
+
const names = new Set(extractDirectExportedNames(code));
|
|
770
|
+
let match;
|
|
771
|
+
const starAsRe = /\bexport\s+\*\s+as\s+([$_\p{ID_Start}][$\p{ID_Continue}]*)\s+from\s+["'][^"']+["']/gu;
|
|
772
|
+
while ((match = starAsRe.exec(code)) !== null) {
|
|
773
|
+
names.add(match[1]);
|
|
774
|
+
}
|
|
775
|
+
const braceRe = /\bexport\s*\{([^}]+)\}/g;
|
|
776
|
+
while ((match = braceRe.exec(code)) !== null) {
|
|
777
|
+
for (const { exportedName } of parseExportSpecList(match[1])) {
|
|
778
|
+
names.add(exportedName);
|
|
779
|
+
}
|
|
780
|
+
}
|
|
781
|
+
const starRe = /^[ \t]*export\s+\*\s+from\s+["']([^"']+)["']/gm;
|
|
782
|
+
while ((match = starRe.exec(code)) !== null) {
|
|
783
|
+
const spec = match[1];
|
|
784
|
+
if (!spec.startsWith('.'))
|
|
785
|
+
return { names: null, hasDefault: false };
|
|
786
|
+
const target = resolveLocalReExportTarget(spec, absPath, platform);
|
|
787
|
+
if (!target)
|
|
788
|
+
return { names: null, hasDefault: false };
|
|
789
|
+
const child = collectDepsModuleExportInfo(target, platform, seen);
|
|
790
|
+
if (child.names === null)
|
|
791
|
+
return { names: null, hasDefault: false };
|
|
792
|
+
for (const name of child.names)
|
|
793
|
+
names.add(name);
|
|
794
|
+
}
|
|
795
|
+
names.delete('default');
|
|
796
|
+
return { names: Array.from(names).sort(), hasDefault: hasExistingDefaultExport(code) };
|
|
797
|
+
}
|
|
798
|
+
const RESERVED_EXPORT_NAMES = new Set(['default', 'break', 'case', 'catch', 'class', 'const', 'continue', 'debugger', 'delete', 'do', 'else', 'enum', 'export', 'extends', 'false', 'finally', 'for', 'function', 'if', 'import', 'in', 'instanceof', 'new', 'null', 'return', 'super', 'switch', 'this', 'throw', 'true', 'try', 'typeof', 'var', 'void', 'while', 'with', 'let', 'static', 'yield', 'await', 'eval', 'arguments', '__ns_dep_ns__']);
|
|
799
|
+
/**
|
|
800
|
+
* Shim served at `/ns/m/node_modules/...` for a bundled module. The static
|
|
801
|
+
* bundle import guarantees the registry is populated before the body reads it
|
|
802
|
+
* (ESM deps evaluate first). Modules without their own `export default` keep
|
|
803
|
+
* the self-namespace default so "default import + destructure" consumers work
|
|
804
|
+
* (same contract as the /ns/core bundle shims).
|
|
805
|
+
*/
|
|
806
|
+
export function buildDepsShimCode(key, exportNames, hasOwnDefaultExport) {
|
|
807
|
+
// JS_IDENTIFIER_RE (not ASCII \w): Angular exports `ɵɵdefineInjectable`-style
|
|
808
|
+
// names — dropping them here breaks every `import * as i0` consumer.
|
|
809
|
+
const names = Array.from(new Set(exportNames)).filter((n) => JS_IDENTIFIER_RE.test(n) && !RESERVED_EXPORT_NAMES.has(n));
|
|
810
|
+
const lines = [];
|
|
811
|
+
lines.push(`/* ns-deps bridge (bundle mode) — ${key} */`);
|
|
812
|
+
lines.push(`import ${JSON.stringify(DEPS_BUNDLE_PATH)};`);
|
|
813
|
+
lines.push(`const __ns_dep_ns__ = (globalThis.__NS_DEPS_MODULES__ || {})[${JSON.stringify(key)}];`);
|
|
814
|
+
lines.push(`if (!__ns_dep_ns__) { throw new Error(${JSON.stringify(`[ns-deps] deps bundle registry missing '${key}' — restart the dev server or set NS_DEPS_PER_MODULE=1`)}); }`);
|
|
815
|
+
for (const name of names) {
|
|
816
|
+
lines.push(`export const ${name} = __ns_dep_ns__.${name};`);
|
|
817
|
+
}
|
|
818
|
+
if (hasOwnDefaultExport) {
|
|
819
|
+
lines.push(`export default __ns_dep_ns__.default;`);
|
|
820
|
+
}
|
|
821
|
+
else {
|
|
822
|
+
lines.push(`export default __ns_dep_ns__;`);
|
|
823
|
+
}
|
|
824
|
+
lines.push('');
|
|
825
|
+
return lines.join('\n');
|
|
826
|
+
}
|
|
827
|
+
/**
|
|
828
|
+
* The dev-session `/@nativescript/vendor.mjs` module, backed by the deps
|
|
829
|
+
* bundle. The session bootstrap imports it and hands `__nsVendorModuleMap` +
|
|
830
|
+
* `vendorManifest` to `installVendorBootstrap`, which populates
|
|
831
|
+
* `__nsVendorRegistry` — the JS-side sync resolution chain (client HMR
|
|
832
|
+
* helpers, the require shim for CJS interop) then resolves package roots
|
|
833
|
+
* into the SAME realm as every `/ns/m` shim. Map entries are emitted for
|
|
834
|
+
* both the collected specifier and its manifest-canonical alias so lookups
|
|
835
|
+
* hit either form. `@nativescript/core` is the one non-deps entry: a bare
|
|
836
|
+
* import the device import map routes to the `/ns/core` bridge realm.
|
|
837
|
+
*/
|
|
838
|
+
export function buildDepsVendorRuntimeModule(vendorSpecToKey, manifest) {
|
|
839
|
+
const aliases = manifest?.aliases ?? {};
|
|
840
|
+
const emit = new Map();
|
|
841
|
+
for (const [spec, key] of vendorSpecToKey) {
|
|
842
|
+
emit.set(spec, key);
|
|
843
|
+
const canonical = aliases[spec];
|
|
844
|
+
if (canonical && !emit.has(canonical))
|
|
845
|
+
emit.set(canonical, key);
|
|
846
|
+
}
|
|
847
|
+
const includeCore = !!manifest?.modules?.['@nativescript/core'];
|
|
848
|
+
const lines = [];
|
|
849
|
+
lines.push('/* /@nativescript/vendor.mjs — deps-backed vendor view (dev bundle mode) */');
|
|
850
|
+
lines.push(`import ${JSON.stringify(DEPS_BUNDLE_PATH)};`);
|
|
851
|
+
if (includeCore) {
|
|
852
|
+
lines.push(`import * as __ns_core__ from "@nativescript/core";`);
|
|
853
|
+
}
|
|
854
|
+
lines.push('const __nsDepsReg = globalThis.__NS_DEPS_MODULES__ || {};');
|
|
855
|
+
lines.push('export const __nsVendorModuleMap = {');
|
|
856
|
+
if (includeCore) {
|
|
857
|
+
lines.push(` ${JSON.stringify('@nativescript/core')}: __ns_core__,`);
|
|
858
|
+
}
|
|
859
|
+
for (const [spec, key] of emit) {
|
|
860
|
+
lines.push(` ${JSON.stringify(spec)}: __nsDepsReg[${JSON.stringify(key)}],`);
|
|
861
|
+
}
|
|
862
|
+
lines.push('};');
|
|
863
|
+
lines.push(`export const vendorManifest = ${JSON.stringify(manifest ?? {})};`);
|
|
864
|
+
lines.push('export default vendorManifest;');
|
|
865
|
+
lines.push('');
|
|
866
|
+
return lines.join('\n');
|
|
867
|
+
}
|
|
868
|
+
export function createDepsBundleService(options) {
|
|
869
|
+
let state = null;
|
|
870
|
+
let failed = false;
|
|
871
|
+
let servingDisabled = false;
|
|
872
|
+
let building = null;
|
|
873
|
+
const workspaceRoot = getMonorepoWorkspaceRoot(options.projectRoot);
|
|
874
|
+
const shimCache = new Map();
|
|
875
|
+
const ensureBuilt = async () => {
|
|
876
|
+
if (state)
|
|
877
|
+
return state;
|
|
878
|
+
if (failed)
|
|
879
|
+
return null;
|
|
880
|
+
if (!building) {
|
|
881
|
+
// No recording is fine: the vendor collection seeds first-boot entries.
|
|
882
|
+
const recordedPaths = options.getRecordedPaths() ?? [];
|
|
883
|
+
building = generateDepsBundle({ ...options, recordedPaths })
|
|
884
|
+
.then((built) => {
|
|
885
|
+
state = built;
|
|
886
|
+
return built;
|
|
887
|
+
})
|
|
888
|
+
.catch((error) => {
|
|
889
|
+
failed = true;
|
|
890
|
+
console.warn(`[ns-deps-bundle] bundle build FAILED — falling back to per-module node_modules serving for this session. Set NS_DEPS_PER_MODULE=1 to silence. Error: ${error?.message || error}`);
|
|
891
|
+
return null;
|
|
892
|
+
});
|
|
893
|
+
}
|
|
894
|
+
return building;
|
|
895
|
+
};
|
|
896
|
+
const keyForSpec = (spec) => {
|
|
897
|
+
if (!state)
|
|
898
|
+
return null;
|
|
899
|
+
const direct = state.specToKey.get(spec);
|
|
900
|
+
if (direct)
|
|
901
|
+
return direct;
|
|
902
|
+
const absPath = resolveSpecToFile(spec, options.projectRoot, workspaceRoot, String(options.platform));
|
|
903
|
+
if (!absPath)
|
|
904
|
+
return null;
|
|
905
|
+
const key = depsRegistryKeyForFile(absPath);
|
|
906
|
+
return key && state.keys.has(key) ? key : null;
|
|
907
|
+
};
|
|
908
|
+
return {
|
|
909
|
+
ensureBuilt,
|
|
910
|
+
getState: () => state,
|
|
911
|
+
hasFailed: () => failed,
|
|
912
|
+
getShimForSpec(spec) {
|
|
913
|
+
if (!state || servingDisabled)
|
|
914
|
+
return null;
|
|
915
|
+
if (!spec.includes('/node_modules/'))
|
|
916
|
+
return null;
|
|
917
|
+
const cached = shimCache.get(spec);
|
|
918
|
+
if (cached !== undefined)
|
|
919
|
+
return cached;
|
|
920
|
+
let shim = null;
|
|
921
|
+
const key = keyForSpec(spec);
|
|
922
|
+
if (key) {
|
|
923
|
+
const file = state.keyToFile.get(key);
|
|
924
|
+
const info = file ? collectDepsModuleExportInfo(file, String(options.platform)) : { names: null, hasDefault: false };
|
|
925
|
+
if (info.names !== null) {
|
|
926
|
+
shim = buildDepsShimCode(key, info.names, info.hasDefault);
|
|
927
|
+
}
|
|
928
|
+
else if (info.opaqueCjs) {
|
|
929
|
+
// Statically opaque CJS/UMD (e.g. moment-timezone): the bundled
|
|
930
|
+
// namespace is `{ default: module.exports }` and nothing else, so
|
|
931
|
+
// a default-only shim is the COMPLETE surface. Serving the shim
|
|
932
|
+
// (not the per-module transform) keeps the single bundle
|
|
933
|
+
// evaluation — patch-style packages that mutate another package
|
|
934
|
+
// at eval time break if evaluated a second time.
|
|
935
|
+
shim = buildDepsShimCode(key, [], true);
|
|
936
|
+
}
|
|
937
|
+
}
|
|
938
|
+
shimCache.set(spec, shim);
|
|
939
|
+
return shim;
|
|
940
|
+
},
|
|
941
|
+
disableServingForSession(reason) {
|
|
942
|
+
if (servingDisabled)
|
|
943
|
+
return;
|
|
944
|
+
servingDisabled = true;
|
|
945
|
+
console.warn(`[ns-deps-bundle] shim serving disabled for this session (${reason}) — restart the dev server to rebuild the deps bundle.`);
|
|
946
|
+
},
|
|
947
|
+
isServingDisabled: () => servingDisabled,
|
|
948
|
+
};
|
|
949
|
+
}
|
|
950
|
+
let sharedService = null;
|
|
951
|
+
let sharedServiceResolved = false;
|
|
952
|
+
/**
|
|
953
|
+
* Process-wide deps bundle service derived from the dev server's config + CLI
|
|
954
|
+
* flags (one dev server per process, like the core bundle service). Returns
|
|
955
|
+
* null when per-module serving is forced via `NS_DEPS_PER_MODULE=1`. The
|
|
956
|
+
* recording source is the persisted boot recording — the in-session recorder
|
|
957
|
+
* starts from the same file, and mid-session recordings apply on the next
|
|
958
|
+
* dev-server start.
|
|
959
|
+
*/
|
|
960
|
+
export function getSharedDepsBundleService(server) {
|
|
961
|
+
if (sharedServiceResolved)
|
|
962
|
+
return sharedService;
|
|
963
|
+
sharedServiceResolved = true;
|
|
964
|
+
if (isDepsPerModuleServingEnabled())
|
|
965
|
+
return null;
|
|
966
|
+
// Platform/flavor resolution matches createBootRecorderFromEnv exactly so
|
|
967
|
+
// the service reads the same recording file the recorder writes.
|
|
968
|
+
const platform = resolvePlatform() || 'ios';
|
|
969
|
+
const flavor = getProjectFlavor();
|
|
970
|
+
const projectRoot = server.config?.root || process.cwd();
|
|
971
|
+
sharedService = createDepsBundleService({
|
|
972
|
+
projectRoot,
|
|
973
|
+
platform,
|
|
974
|
+
mode: server.config?.mode === 'development' ? 'development' : 'production',
|
|
975
|
+
flavor,
|
|
976
|
+
verbose: resolveVerboseFlag(),
|
|
977
|
+
getRecordedPaths: () => loadPersistedBootRecording(projectRoot, platform, flavor),
|
|
978
|
+
});
|
|
979
|
+
// ONE node_modules payload: back /@nativescript/vendor.mjs with this bundle
|
|
980
|
+
// (see buildDepsVendorRuntimeModule). A null return — not built yet, build
|
|
981
|
+
// failed, or dependency set changed mid-session — falls back to the
|
|
982
|
+
// standalone vendor bundle build in vendorManifestPlugin.
|
|
983
|
+
setVendorRuntimeModuleProvider(() => {
|
|
984
|
+
const st = sharedService?.getState();
|
|
985
|
+
if (!st || sharedService.isServingDisabled())
|
|
986
|
+
return null;
|
|
987
|
+
return buildDepsVendorRuntimeModule(st.vendorSpecToKey, getVendorManifest());
|
|
988
|
+
});
|
|
989
|
+
return sharedService;
|
|
990
|
+
}
|
|
991
|
+
/** Test seam: drop the shared service so specs can mount fresh. */
|
|
992
|
+
export function resetSharedDepsBundleServiceForTests() {
|
|
993
|
+
sharedService = null;
|
|
994
|
+
sharedServiceResolved = false;
|
|
995
|
+
setVendorRuntimeModuleProvider(null);
|
|
996
|
+
}
|
|
997
|
+
/** GET /ns/deps-bundle.mjs — the single-eval dep closure payload. */
|
|
998
|
+
export function registerDepsBundleRoute(server, service) {
|
|
999
|
+
server.middlewares.use(async (req, res, next) => {
|
|
1000
|
+
try {
|
|
1001
|
+
const urlObj = new URL(req.url || '', 'http://localhost');
|
|
1002
|
+
if (urlObj.pathname !== DEPS_BUNDLE_PATH)
|
|
1003
|
+
return next();
|
|
1004
|
+
const state = await service.ensureBuilt();
|
|
1005
|
+
if (!state) {
|
|
1006
|
+
res.statusCode = 503;
|
|
1007
|
+
res.setHeader('Access-Control-Allow-Origin', '*');
|
|
1008
|
+
res.setHeader('Content-Type', 'application/json');
|
|
1009
|
+
res.end(JSON.stringify({ error: 'deps-bundle-unavailable' }));
|
|
1010
|
+
return;
|
|
1011
|
+
}
|
|
1012
|
+
setDeviceModuleHeaders(res);
|
|
1013
|
+
res.statusCode = 200;
|
|
1014
|
+
res.end(state.code);
|
|
1015
|
+
}
|
|
1016
|
+
catch (e) {
|
|
1017
|
+
console.warn('[ns-deps-bundle] serve failed:', e?.message);
|
|
1018
|
+
next();
|
|
1019
|
+
}
|
|
1020
|
+
});
|
|
1021
|
+
}
|
|
1022
|
+
//# sourceMappingURL=deps-bundle.js.map
|