@nativescript/vite 8.0.0-alpha.9 → 8.0.0-rc.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 +73 -14
- package/bin/cli.cjs +8 -14
- package/configuration/angular.d.ts +34 -1
- package/configuration/angular.js +196 -217
- package/configuration/angular.js.map +1 -1
- package/configuration/base.js +151 -103
- package/configuration/base.js.map +1 -1
- package/configuration/javascript.js +14 -93
- package/configuration/javascript.js.map +1 -1
- package/configuration/react.js +41 -73
- package/configuration/react.js.map +1 -1
- package/configuration/solid.js +51 -6
- package/configuration/solid.js.map +1 -1
- package/configuration/typescript.js +11 -92
- package/configuration/typescript.js.map +1 -1
- 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/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 +4 -1
- package/helpers/esbuild-platform-resolver.js.map +1 -1
- package/helpers/external-configs.d.ts +10 -12
- package/helpers/external-configs.js +58 -35
- package/helpers/external-configs.js.map +1 -1
- package/helpers/flavor.d.ts +13 -0
- package/helpers/flavor.js +18 -1
- package/helpers/flavor.js.map +1 -1
- package/helpers/global-defines.d.ts +99 -33
- package/helpers/global-defines.js +187 -66
- 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 +6 -20
- package/helpers/init.js.map +1 -1
- package/helpers/logging.js +29 -1
- package/helpers/logging.js.map +1 -1
- package/helpers/main-entry.d.ts +4 -1
- package/helpers/main-entry.js +293 -40
- 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 +37 -7
- package/helpers/nativeclass-transform.js.map +1 -1
- package/helpers/nativeclass-transformer-plugin.js +8 -3
- 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 +26 -3
- package/helpers/ns-core-url.js +66 -8
- package/helpers/ns-core-url.js.map +1 -1
- 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/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 +143 -62
- package/helpers/ts-config-paths.js.map +1 -1
- package/helpers/typescript-check.d.ts +2 -1
- 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 +33 -0
- package/helpers/workers.js +237 -10
- package/helpers/workers.js.map +1 -1
- package/hmr/client/css-handler.d.ts +2 -1
- package/hmr/client/css-handler.js +63 -32
- 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 +87 -0
- package/hmr/client/framework-client-strategy.js +18 -0
- package/hmr/client/framework-client-strategy.js.map +1 -0
- package/hmr/client/hmr-pending-overlay.d.ts +0 -14
- package/hmr/client/hmr-pending-overlay.js +2 -11
- package/hmr/client/hmr-pending-overlay.js.map +1 -1
- package/hmr/client/hot-context.d.ts +67 -0
- package/hmr/client/hot-context.js +307 -0
- package/hmr/client/hot-context.js.map +1 -0
- package/hmr/client/index.d.ts +9 -1
- package/hmr/client/index.js +70 -1970
- 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 +100 -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 +464 -0
- package/hmr/client/update-pipeline.js.map +1 -0
- package/hmr/client/utils.d.ts +9 -1
- package/hmr/client/utils.js +117 -97
- 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 +2 -1
- package/hmr/entry-runtime.js +279 -44
- package/hmr/entry-runtime.js.map +1 -1
- 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/{helpers/angular → hmr/frameworks/angular/build}/inject-component-hmr-registration.js +2 -70
- 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/{helpers/angular → hmr/frameworks/angular/build}/inline-decorator-component-templates.js +1 -170
- 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/{helpers/angular/synthesize-decorator-ctor-parameters.js → hmr/frameworks/angular/build/js-lexer.js} +22 -96
- 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.js +88 -0
- package/hmr/frameworks/angular/build/synthesize-decorator-ctor-parameters.js.map +1 -0
- package/{helpers/angular → hmr/frameworks/angular/build}/synthesize-injectable-factories.js +1 -174
- 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/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 +0 -1
- package/hmr/frameworks/angular/client/index.js +360 -194
- 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/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 +668 -13
- package/hmr/frameworks/angular/server/strategy.js.map +1 -1
- package/hmr/{server → frameworks/angular/server}/websocket-angular-entry.js +2 -2
- package/hmr/frameworks/angular/server/websocket-angular-entry.js.map +1 -0
- package/hmr/{server → frameworks/angular/server}/websocket-angular-hot-update.d.ts +27 -11
- package/hmr/{server → frameworks/angular/server}/websocket-angular-hot-update.js +179 -107
- 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 +40 -14
- 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 +270 -521
- 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 +109 -14
- package/hmr/helpers/ast-normalizer.js.map +1 -1
- 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.js +7 -1
- 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 +86 -7
- package/hmr/server/core-sanitize.js +155 -37
- 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 +57 -23
- package/hmr/server/import-map.js +142 -70
- package/hmr/server/import-map.js.map +1 -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-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 +1 -1
- package/hmr/server/perf-instrumentation.js +3 -1
- package/hmr/server/perf-instrumentation.js.map +1 -1
- package/hmr/server/process-code-for-device.d.ts +44 -0
- package/hmr/server/process-code-for-device.js +834 -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.js +8 -1
- package/hmr/server/runtime-graph-filter.js.map +1 -1
- 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.js +1 -2
- package/hmr/server/shared-transform-request.js.map +1 -1
- 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 +1 -0
- package/hmr/server/vite-plugin.js +211 -53
- package/hmr/server/vite-plugin.js.map +1 -1
- package/hmr/server/websocket-core-bridge.d.ts +51 -4
- package/hmr/server/websocket-core-bridge.js +62 -49
- package/hmr/server/websocket-core-bridge.js.map +1 -1
- 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-hmr-pending.d.ts +2 -16
- package/hmr/server/websocket-hmr-pending.js +0 -22
- package/hmr/server/websocket-hmr-pending.js.map +1 -1
- package/hmr/server/websocket-hot-update.d.ts +80 -0
- package/hmr/server/websocket-hot-update.js +295 -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 +15 -0
- package/hmr/server/websocket-module-bindings.js +36 -3
- package/hmr/server/websocket-module-bindings.js.map +1 -1
- package/hmr/server/websocket-module-specifiers.d.ts +0 -5
- package/hmr/server/websocket-module-specifiers.js +29 -30
- package/hmr/server/websocket-module-specifiers.js.map +1 -1
- 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 -3
- package/hmr/server/websocket-ns-m-paths.js +98 -75
- package/hmr/server/websocket-ns-m-paths.js.map +1 -1
- package/hmr/server/websocket-ns-m-request.d.ts +2 -1
- package/hmr/server/websocket-ns-m-request.js +3 -2
- package/hmr/server/websocket-ns-m-request.js.map +1 -1
- package/hmr/server/websocket-ns-m.d.ts +52 -0
- package/hmr/server/websocket-ns-m.js +590 -0
- package/hmr/server/websocket-ns-m.js.map +1 -0
- package/hmr/server/websocket-served-module-helpers.d.ts +56 -3
- package/hmr/server/websocket-served-module-helpers.js +444 -140
- package/hmr/server/websocket-served-module-helpers.js.map +1 -1
- package/hmr/server/websocket-txn.js +6 -9
- package/hmr/server/websocket-txn.js.map +1 -1
- package/hmr/server/websocket-vendor-unifier.d.ts +0 -1
- package/hmr/server/websocket-vendor-unifier.js +4 -9
- package/hmr/server/websocket-vendor-unifier.js.map +1 -1
- package/hmr/server/websocket.d.ts +7 -40
- package/hmr/server/websocket.js +661 -6751
- package/hmr/server/websocket.js.map +1 -1
- package/hmr/shared/ns-globals.d.ts +107 -0
- package/hmr/shared/ns-globals.js +29 -0
- package/hmr/shared/ns-globals.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 +1 -1
- package/hmr/shared/runtime/boot-timeline.js +8 -19
- package/hmr/shared/runtime/boot-timeline.js.map +1 -1
- package/hmr/shared/runtime/browser-runtime-contract.d.ts +58 -25
- package/hmr/shared/runtime/browser-runtime-contract.js +21 -9
- package/hmr/shared/runtime/browser-runtime-contract.js.map +1 -1
- 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 +23 -69
- package/hmr/shared/runtime/dev-overlay.js +67 -1011
- package/hmr/shared/runtime/dev-overlay.js.map +1 -1
- 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.js +3 -2
- package/hmr/shared/runtime/module-provenance.js.map +1 -1
- 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/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.js +382 -157
- package/hmr/shared/runtime/root-placeholder.js.map +1 -1
- package/hmr/shared/runtime/session-bootstrap.js +209 -54
- package/hmr/shared/runtime/session-bootstrap.js.map +1 -1
- package/hmr/shared/runtime/vendor-bootstrap.js +2 -1
- 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 +10 -35
- package/hmr/shared/vendor/manifest.js +154 -978
- package/hmr/shared/vendor/manifest.js.map +1 -1
- package/hmr/shared/vendor/registry.d.ts +2 -0
- package/hmr/shared/vendor/registry.js +14 -0
- 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/package.json +63 -13
- package/runtime/core-aliases-early.js +11 -16
- 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/helpers/angular/angular-linker.d.ts +0 -13
- package/helpers/angular/angular-linker.js +0 -185
- package/helpers/angular/angular-linker.js.map +0 -1
- package/helpers/angular/inject-component-hmr-registration.js.map +0 -1
- package/helpers/angular/inline-decorator-component-templates.js.map +0 -1
- package/helpers/angular/shared-linker.d.ts +0 -11
- package/helpers/angular/shared-linker.js +0 -75
- package/helpers/angular/shared-linker.js.map +0 -1
- package/helpers/angular/synthesize-decorator-ctor-parameters.js.map +0 -1
- package/helpers/angular/synthesize-injectable-factories.js.map +0 -1
- 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 -114
- package/helpers/prelink-angular.js.map +0 -1
- package/hmr/server/websocket-angular-entry.js.map +0 -1
- package/hmr/server/websocket-angular-hot-update.js.map +0 -1
- package/hmr/server/websocket-ns-m-finalize.d.ts +0 -22
- package/hmr/server/websocket-ns-m-finalize.js +0 -88
- package/hmr/server/websocket-ns-m-finalize.js.map +0 -1
- package/hmr/server/websocket-runtime-compat.d.ts +0 -19
- package/hmr/server/websocket-runtime-compat.js +0 -287
- package/hmr/server/websocket-runtime-compat.js.map +0 -1
- package/hmr/server/websocket-vue-sfc.d.ts +0 -27
- package/hmr/server/websocket-vue-sfc.js +0 -1069
- package/hmr/server/websocket-vue-sfc.js.map +0 -1
- package/hmr/shared/runtime/http-only-boot.d.ts +0 -2
- package/hmr/shared/runtime/http-only-boot.js +0 -171
- 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
- /package/{helpers/angular → hmr/frameworks/angular/build}/inject-component-hmr-registration.d.ts +0 -0
- /package/{helpers/angular → hmr/frameworks/angular/build}/inline-decorator-component-templates.d.ts +0 -0
- /package/{helpers/angular → hmr/frameworks/angular/build}/synthesize-decorator-ctor-parameters.d.ts +0 -0
- /package/{helpers/angular → hmr/frameworks/angular/build}/synthesize-injectable-factories.d.ts +0 -0
- /package/{helpers/angular → hmr/frameworks/angular/build}/util.d.ts +0 -0
- /package/{helpers/angular → hmr/frameworks/angular/build}/util.js +0 -0
- /package/hmr/{server → frameworks/angular/server}/websocket-angular-entry.d.ts +0 -0
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
import * as esbuild from 'esbuild';
|
|
2
|
-
import { readFile } from 'fs/promises';
|
|
3
2
|
import path from 'path';
|
|
4
|
-
import fs, { readFileSync } from 'fs';
|
|
5
3
|
import { createHash } from 'crypto';
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
4
|
+
import { registerVendorManifest, clearVendorManifest, getVendorManifest, getVendorRuntimeModule } from './registry.js';
|
|
5
|
+
import { collectVendorModules } from './manifest-collect.js';
|
|
8
6
|
import { generatePlatformPolyfills } from '../runtime/platform-polyfills.js';
|
|
9
7
|
import { createNativeClassEsbuildPlugin } from '../../../helpers/nativeclass-esbuild-plugin.js';
|
|
10
8
|
import { getGlobalDefines } from '../../../helpers/global-defines.js';
|
|
9
|
+
import { createVendorEsbuildPlugin, createSolidJsxEsbuildPlugin, angularLinkerEsbuildPlugin, createUnicodeRegexEsbuildPlugin, createWebpackLoaderStubEsbuildPlugin, createNodeBuiltinPolyfillEsbuildPlugin, createOptionalDependencyStubEsbuildPlugin, createNativeAddonStubEsbuildPlugin } from './vendor-esbuild-plugins.js';
|
|
11
10
|
export const VENDOR_MANIFEST_ID = '@nativescript/vendor-manifest';
|
|
12
11
|
export const VENDOR_MANIFEST_VIRTUAL_ID = '\0' + VENDOR_MANIFEST_ID;
|
|
13
12
|
export const VENDOR_BUNDLE_ID = '@nativescript/vendor';
|
|
@@ -16,105 +15,6 @@ export const SERVER_VENDOR_PATH = '/@nativescript/vendor.mjs';
|
|
|
16
15
|
export const SERVER_MANIFEST_PATH = '/@nativescript/vendor-manifest.json';
|
|
17
16
|
export const DEFAULT_VENDOR_FILENAME = 'ns-vendor.mjs';
|
|
18
17
|
export const DEFAULT_MANIFEST_FILENAME = 'ns-vendor-manifest.json';
|
|
19
|
-
// Do not force-include @nativescript/core in the dev vendor bundle.
|
|
20
|
-
// Keeping core out of vendor avoids duplicate side-effect registrations (e.g.,
|
|
21
|
-
// com.tns.FragmentClass, com.tns.NativeScriptActivity) across bundle.mjs and vendor.
|
|
22
|
-
// Force runtime-sensitive packages onto the vendor path so they do not drift
|
|
23
|
-
// between startup bundle, HTTP-wrapped CommonJS, and base-require semantics
|
|
24
|
-
// during HMR sessions.
|
|
25
|
-
const ALWAYS_INCLUDE = new Set(['stacktrace-js']);
|
|
26
|
-
const ALWAYS_EXCLUDE = new Set([
|
|
27
|
-
'@nativescript/android',
|
|
28
|
-
'@nativescript/ios',
|
|
29
|
-
'@nativescript/types',
|
|
30
|
-
'@nativescript/webpack',
|
|
31
|
-
// Angular browser animations are not used in NativeScript; excluding reduces
|
|
32
|
-
// memory pressure and avoids bringing partial declarations into vendor.
|
|
33
|
-
'@angular/animations',
|
|
34
|
-
'@angular/platform-browser/animations',
|
|
35
|
-
// Not needed at runtime with linked partials; reduce vendor size/memory.
|
|
36
|
-
'@angular/platform-browser-dynamic',
|
|
37
|
-
// Native add-on helpers pulled by ws or others; exclude in NS dev vendor
|
|
38
|
-
'bufferutil',
|
|
39
|
-
'utf-8-validate',
|
|
40
|
-
'node-gyp-build',
|
|
41
|
-
'bufferutil',
|
|
42
|
-
'utf-8-validate',
|
|
43
|
-
'node-gyp-build',
|
|
44
|
-
// All @babel/* and babel-* packages are build-time tools, never runtime deps.
|
|
45
|
-
// They get pulled in as peer deps of packages like @nativescript-community/solid-js
|
|
46
|
-
// but should never be in the vendor bundle (they require 'fs', 'path', etc.).
|
|
47
|
-
'@babel/core',
|
|
48
|
-
'@babel/helper-plugin-utils',
|
|
49
|
-
'@babel/generator',
|
|
50
|
-
'@babel/helper-string-parser',
|
|
51
|
-
'@babel/helper-validator-identifier',
|
|
52
|
-
'@babel/parser',
|
|
53
|
-
'@babel/plugin-syntax-typescript',
|
|
54
|
-
'@babel/plugin-transform-typescript',
|
|
55
|
-
'@babel/preset-typescript',
|
|
56
|
-
'@babel/preset-env',
|
|
57
|
-
'@babel/types',
|
|
58
|
-
'babel-preset-solid',
|
|
59
|
-
'babel-plugin-jsx-dom-expressions',
|
|
60
|
-
// Heavy dependency not needed in vendor dev bundle; fetch via HTTP loader instead
|
|
61
|
-
'rxjs',
|
|
62
|
-
'nativescript',
|
|
63
|
-
'typescript',
|
|
64
|
-
'ts-node',
|
|
65
|
-
'vue-tsc',
|
|
66
|
-
'ws',
|
|
67
|
-
'@types/node',
|
|
68
|
-
'nativescript-theme-core',
|
|
69
|
-
// Build-time tools that get pulled in as transitive dependencies but should
|
|
70
|
-
// never be in the device vendor bundle (they require Node built-ins like fs,
|
|
71
|
-
// path, child_process, etc.). Now that we collect transitive runtime deps,
|
|
72
|
-
// these need explicit exclusion.
|
|
73
|
-
'esbuild',
|
|
74
|
-
'prettier',
|
|
75
|
-
'acorn',
|
|
76
|
-
'recast',
|
|
77
|
-
'source-map',
|
|
78
|
-
'source-map-js',
|
|
79
|
-
'tsx',
|
|
80
|
-
'diff',
|
|
81
|
-
'esprima',
|
|
82
|
-
// TanStack build-time router tooling (code generation, file-based routing)
|
|
83
|
-
'@tanstack/router-plugin',
|
|
84
|
-
'@tanstack/router-generator',
|
|
85
|
-
'@tanstack/router-utils',
|
|
86
|
-
'@tanstack/virtual-file-routes',
|
|
87
|
-
// File system / glob utilities — build-time only, require Node fs
|
|
88
|
-
'fdir',
|
|
89
|
-
'picomatch',
|
|
90
|
-
'tinyglobby',
|
|
91
|
-
// SSR-only library (bot detection) — not needed on device
|
|
92
|
-
'isbot',
|
|
93
|
-
// Type-only packages with no runtime JavaScript
|
|
94
|
-
'csstype',
|
|
95
|
-
// NativeScript CLI hook system — build-time only, requires Node os/path
|
|
96
|
-
'@nativescript/hook',
|
|
97
|
-
// Test runner uses webpack's require.context API which doesn't exist in Vite.
|
|
98
|
-
// Including it in the vendor bundle causes __require.context crashes at runtime.
|
|
99
|
-
'@nativescript/unit-test-runner',
|
|
100
|
-
'nativescript-unit-test-runner',
|
|
101
|
-
// CSS build tools — postcss, tailwindcss, and related tooling are exclusively
|
|
102
|
-
// build-time processors. They require Node APIs (process, fs, path) and must
|
|
103
|
-
// never run on device. esbuild bundles their transitive deps (picocolors,
|
|
104
|
-
// nanoid, etc.) which reference `process` and crash at runtime.
|
|
105
|
-
'tailwindcss',
|
|
106
|
-
'@nativescript/tailwind',
|
|
107
|
-
'postcss',
|
|
108
|
-
'autoprefixer',
|
|
109
|
-
'postcss-import',
|
|
110
|
-
'postcss-url',
|
|
111
|
-
'postcss-nested',
|
|
112
|
-
'picocolors',
|
|
113
|
-
'nanoid',
|
|
114
|
-
// Server-side SDKs that require Node networking APIs (net, tls, dns, crypto).
|
|
115
|
-
// These are backend tools, not device-side.
|
|
116
|
-
'mongodb',
|
|
117
|
-
]);
|
|
118
18
|
const INDEX_ALIAS_SUFFIXES = ['/index', '/index.js', '/index.android.js', '/index.ios.js', '/index.visionos.js'];
|
|
119
19
|
export function vendorManifestPlugin(options) {
|
|
120
20
|
let cachedResult = null;
|
|
@@ -158,15 +58,47 @@ export function vendorManifestPlugin(options) {
|
|
|
158
58
|
cachedResult = null;
|
|
159
59
|
clearVendorManifest();
|
|
160
60
|
};
|
|
61
|
+
// Manifest registration without the esbuild payload build. The dev serve
|
|
62
|
+
// process only needs the manifest (module ids + aliases) for the import
|
|
63
|
+
// map and vendor-routing decisions — the payload itself is deps-backed
|
|
64
|
+
// (see getVendorRuntimeModule). The full build stays lazy, reached only
|
|
65
|
+
// through the fallback serving path or the build-process virtual modules.
|
|
66
|
+
const ensureManifestRegistered = () => {
|
|
67
|
+
if (getVendorManifest())
|
|
68
|
+
return;
|
|
69
|
+
const collected = collectVendorModules(options.projectRoot, options.platform, options.flavor);
|
|
70
|
+
const hash = createHash('sha1').update(JSON.stringify(collected.entries)).digest('hex');
|
|
71
|
+
registerVendorManifest(buildManifest(collected.entries, hash));
|
|
72
|
+
};
|
|
161
73
|
const respondWithVendor = async (_server, req, res) => {
|
|
162
74
|
try {
|
|
163
|
-
const result = await ensureResult('server');
|
|
164
75
|
if (req.url === SERVER_VENDOR_PATH) {
|
|
76
|
+
// ONE node_modules payload: when the deps bundle is active, the
|
|
77
|
+
// vendor module is a thin view over /ns/deps-bundle.mjs.
|
|
78
|
+
const depsBacked = getVendorRuntimeModule();
|
|
79
|
+
if (depsBacked !== null) {
|
|
80
|
+
res.setHeader('Content-Type', 'application/javascript');
|
|
81
|
+
res.end(depsBacked);
|
|
82
|
+
return true;
|
|
83
|
+
}
|
|
84
|
+
// No deps bundle (build failed or NS_DEPS_PER_MODULE=1): serve a
|
|
85
|
+
// view over the SAME `/ns/m/node_modules/<pkg>` URLs the import
|
|
86
|
+
// map targets, so the registry and import-side resolution share
|
|
87
|
+
// one realm. Never a second standalone payload — that realm
|
|
88
|
+
// split is exactly what the deps bundle design forbids.
|
|
89
|
+
ensureManifestRegistered();
|
|
165
90
|
res.setHeader('Content-Type', 'application/javascript');
|
|
166
|
-
res.end(
|
|
91
|
+
res.end(createHttpVendorRuntimeModule(getVendorManifest()));
|
|
167
92
|
return true;
|
|
168
93
|
}
|
|
169
94
|
if (req.url === SERVER_MANIFEST_PATH) {
|
|
95
|
+
const registered = getVendorManifest();
|
|
96
|
+
if (registered) {
|
|
97
|
+
res.setHeader('Content-Type', 'application/json');
|
|
98
|
+
res.end(JSON.stringify(registered, null, 2));
|
|
99
|
+
return true;
|
|
100
|
+
}
|
|
101
|
+
const result = await ensureResult('server');
|
|
170
102
|
res.setHeader('Content-Type', 'application/json');
|
|
171
103
|
res.end(JSON.stringify(result.manifest, null, 2));
|
|
172
104
|
return true;
|
|
@@ -185,7 +117,12 @@ export function vendorManifestPlugin(options) {
|
|
|
185
117
|
enforce: 'pre',
|
|
186
118
|
configResolved() { },
|
|
187
119
|
async configureServer(server) {
|
|
188
|
-
|
|
120
|
+
try {
|
|
121
|
+
ensureManifestRegistered();
|
|
122
|
+
}
|
|
123
|
+
catch (error) {
|
|
124
|
+
console.error('[vendor] failed to register vendor manifest at server start', error);
|
|
125
|
+
}
|
|
189
126
|
server.middlewares.use(async (req, res, next) => {
|
|
190
127
|
if (req.url === SERVER_VENDOR_PATH || req.url === SERVER_MANIFEST_PATH) {
|
|
191
128
|
const handled = await respondWithVendor(server, req, res);
|
|
@@ -203,9 +140,12 @@ export function vendorManifestPlugin(options) {
|
|
|
203
140
|
return;
|
|
204
141
|
}
|
|
205
142
|
resetCache();
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
}
|
|
143
|
+
try {
|
|
144
|
+
ensureManifestRegistered();
|
|
145
|
+
}
|
|
146
|
+
catch (error) {
|
|
147
|
+
console.error('[vendor] failed to regenerate vendor manifest', error);
|
|
148
|
+
}
|
|
209
149
|
});
|
|
210
150
|
},
|
|
211
151
|
async buildStart() {
|
|
@@ -290,10 +230,52 @@ async function generateVendorBundle(options) {
|
|
|
290
230
|
}));
|
|
291
231
|
},
|
|
292
232
|
};
|
|
233
|
+
// Externalize the `solid-js` root specifier for the Solid flavor so
|
|
234
|
+
// vendor-bundled packages (e.g. `@nativescript-community/solid-js`,
|
|
235
|
+
// `solid-navigation`, transitively `solid-js/universal` and
|
|
236
|
+
// `solid-js/store`) don't bake their own copy of solid-js into
|
|
237
|
+
// vendor.mjs. The dev server's import map (see `import-map.ts`)
|
|
238
|
+
// redirects bare `solid-js` to the same `/ns/m/node_modules/solid-js/...`
|
|
239
|
+
// URL that Vite's alias produces for user code and `@solid-refresh`,
|
|
240
|
+
// so V8 dedupes the three import paths down to a single module
|
|
241
|
+
// instance — one `Owner` module-local, one reactive graph, one
|
|
242
|
+
// `$DEVCOMP`/`$PROXY` symbol identity across the whole app.
|
|
243
|
+
//
|
|
244
|
+
// Important: scope this to the EXACT bare `solid-js` specifier. Subpaths
|
|
245
|
+
// like `solid-js/store`, `solid-js/universal`, `solid-js/web` stay
|
|
246
|
+
// bundleable so vendor packages that import them keep working out of
|
|
247
|
+
// the box; those subpaths still go through the unified solid-js
|
|
248
|
+
// runtime via their own `import 'solid-js'` statements (which we just
|
|
249
|
+
// externalized).
|
|
250
|
+
const nsSolidJsExternalPlugin = {
|
|
251
|
+
name: 'ns-solid-js-external',
|
|
252
|
+
setup(build) {
|
|
253
|
+
build.onResolve({ filter: /^solid-js$/ }, (args) => ({
|
|
254
|
+
path: args.path,
|
|
255
|
+
external: true,
|
|
256
|
+
}));
|
|
257
|
+
},
|
|
258
|
+
};
|
|
293
259
|
const plugins = [
|
|
294
260
|
// Mark @nativescript/core external BEFORE other plugins so esbuild never
|
|
295
261
|
// tries to read/transform core's source files. See comment above.
|
|
296
262
|
nsCoreExternalPlugin,
|
|
263
|
+
// Stub legacy webpack-loader-prefixed requires (dead NS 6/7 branches in
|
|
264
|
+
// plugins) BEFORE resolution — a single `loader!./x` specifier would
|
|
265
|
+
// otherwise hard-fail the whole bundle. See the plugin for details.
|
|
266
|
+
createWebpackLoaderStubEsbuildPlugin(),
|
|
267
|
+
createOptionalDependencyStubEsbuildPlugin(options.projectRoot),
|
|
268
|
+
// Stub compiled `.node` addons (fsevents & co.) — unloadable by esbuild and
|
|
269
|
+
// unrunnable on device; a throwing stub preserves optional-dep semantics.
|
|
270
|
+
createNativeAddonStubEsbuildPlugin(),
|
|
271
|
+
// Bundle installed npm polyfills for node-builtin names (buffer, events,
|
|
272
|
+
// ...) instead of leaving bare externals the device cannot resolve.
|
|
273
|
+
createNodeBuiltinPolyfillEsbuildPlugin(projectRoot),
|
|
274
|
+
// For the Solid flavor, externalize `solid-js` so vendor.mjs and the
|
|
275
|
+
// HTTP-served `@solid-refresh` / user code converge on one runtime
|
|
276
|
+
// realm. See `nsSolidJsExternalPlugin`'s definition for the full
|
|
277
|
+
// duplicate-instance rationale.
|
|
278
|
+
...(flavor === 'solid' ? [nsSolidJsExternalPlugin] : []),
|
|
297
279
|
// Apply NativeClass transformer to convert @NativeClass decorated classes to ES5 IIFE pattern.
|
|
298
280
|
// This MUST run before other plugins to ensure proper transformation.
|
|
299
281
|
createNativeClassEsbuildPlugin(platform),
|
|
@@ -315,6 +297,12 @@ async function generateVendorBundle(options) {
|
|
|
315
297
|
if (flavor === 'solid') {
|
|
316
298
|
plugins.push(createSolidJsxEsbuildPlugin(projectRoot));
|
|
317
299
|
}
|
|
300
|
+
// Registered last so the framework-specific passes above own their files
|
|
301
|
+
// first (esbuild stops at the first onLoad that returns a result). Applies
|
|
302
|
+
// to every flavor: any vendored dependency (e.g. highlight.js) may ship
|
|
303
|
+
// `\p{…}` regexes that NativeScript's non-ICU V8 cannot compile, which would
|
|
304
|
+
// otherwise abort the entire vendor.mjs compile. See the plugin for details.
|
|
305
|
+
plugins.push(createUnicodeRegexEsbuildPlugin(projectRoot));
|
|
318
306
|
const buildResult = await esbuild.build({
|
|
319
307
|
stdin: {
|
|
320
308
|
contents: entryCode,
|
|
@@ -377,6 +365,10 @@ async function generateVendorBundle(options) {
|
|
|
377
365
|
// Belt-and-suspenders: keep the original NODE_ENV define explicit so
|
|
378
366
|
// future changes to `getGlobalDefines()` can't silently drop it.
|
|
379
367
|
out['process.env.NODE_ENV'] = JSON.stringify(mode);
|
|
368
|
+
// webpack-HMR idiom carried by ESM-published packages — a FREE
|
|
369
|
+
// `module.hot` reference is a ReferenceError in the ESM bundle the
|
|
370
|
+
// moment it evaluates (see the matching define in deps-bundle.ts).
|
|
371
|
+
out['module.hot'] = 'undefined';
|
|
380
372
|
return out;
|
|
381
373
|
})(),
|
|
382
374
|
plugins,
|
|
@@ -500,410 +492,71 @@ async function generateVendorBundle(options) {
|
|
|
500
492
|
entries: collected.entries,
|
|
501
493
|
};
|
|
502
494
|
}
|
|
503
|
-
function collectVendorModules(projectRoot, platform, flavor) {
|
|
504
|
-
const packageJsonPath = path.resolve(projectRoot, 'package.json');
|
|
505
|
-
const pkg = JSON.parse(readFileSync(packageJsonPath, 'utf-8'));
|
|
506
|
-
const projectRequire = createRequire(packageJsonPath);
|
|
507
|
-
const debug = process.env.VITE_DEBUG_LOGS === 'true' || process.env.VITE_DEBUG_LOGS === '1';
|
|
508
|
-
const vendor = new Set();
|
|
509
|
-
const visited = new Set();
|
|
510
|
-
const queue = [];
|
|
511
|
-
// Local-source deps (file: pointing to a directory, link:, workspace:) are
|
|
512
|
-
// app code, not pre-packaged libraries. esbuild's vendor pipeline has none
|
|
513
|
-
// of the user's tsconfig path aliases or other Vite plugin resolvers, so
|
|
514
|
-
// any aliased import inside their source will fail with "Could not
|
|
515
|
-
// resolve". We collect their names here so that peer-dep traversal can
|
|
516
|
-
// also skip them.
|
|
517
|
-
const localSourceNames = new Set();
|
|
518
|
-
const isPackageRootSpecifier = (name) => {
|
|
519
|
-
if (!name)
|
|
520
|
-
return false;
|
|
521
|
-
if (name.startsWith('@')) {
|
|
522
|
-
// Scoped: @scope/name is root; anything deeper is subpath
|
|
523
|
-
const parts = name.split('/');
|
|
524
|
-
return parts.length === 2;
|
|
525
|
-
}
|
|
526
|
-
// Unscoped: no slash means root; any slash means subpath
|
|
527
|
-
return !name.includes('/');
|
|
528
|
-
};
|
|
529
|
-
const isAngularFlavor = flavor === 'angular';
|
|
530
|
-
const addCandidate = (name) => {
|
|
531
|
-
if (!name || shouldSkipDependency(name)) {
|
|
532
|
-
return;
|
|
533
|
-
}
|
|
534
|
-
// Avoid pulling Angular compiler/runtime into the dev vendor bundle when
|
|
535
|
-
// the current project flavor is not Angular (for example, solid). This
|
|
536
|
-
// prevents esbuild from trying to bundle @angular/compiler and its Babel
|
|
537
|
-
// toolchain, which requires Node built-ins like fs/path/url.
|
|
538
|
-
if (!isAngularFlavor && (name === '@angular/compiler' || name.startsWith('@angular/'))) {
|
|
539
|
-
return;
|
|
540
|
-
}
|
|
541
|
-
// Skip already-visited packages to avoid redundant queue processing
|
|
542
|
-
if (visited.has(name)) {
|
|
543
|
-
return;
|
|
544
|
-
}
|
|
545
|
-
visited.add(name);
|
|
546
|
-
vendor.add(name);
|
|
547
|
-
const isRoot = isPackageRootSpecifier(name);
|
|
548
|
-
// Only traverse deps for package roots; subpaths should not attempt package.json resolution
|
|
549
|
-
if (isRoot) {
|
|
550
|
-
queue.push(name);
|
|
551
|
-
}
|
|
552
|
-
};
|
|
553
|
-
const addDeps = (deps) => {
|
|
554
|
-
if (!deps) {
|
|
555
|
-
return;
|
|
556
|
-
}
|
|
557
|
-
for (const [name, spec] of Object.entries(deps)) {
|
|
558
|
-
if (isUnvendorableLocalSource(name, spec, projectRequire, platform)) {
|
|
559
|
-
// Defer to the regular Vite/Rolldown pipeline (HTTP-served in
|
|
560
|
-
// dev, bundled in production) where the
|
|
561
|
-
// ns-tsconfig-paths-resolver and the rest of the plugin chain
|
|
562
|
-
// can handle aliased imports. Local .tgz file: refs ARE proper
|
|
563
|
-
// packaged libraries and DO stay in vendor; so do file:
|
|
564
|
-
// directory refs that point at packages with compiled JS
|
|
565
|
-
// entry points (a common NativeScript monorepo pattern that
|
|
566
|
-
// hoists installs and re-exposes them from the app's
|
|
567
|
-
// package.json via `file:../../node_modules/<name>`).
|
|
568
|
-
localSourceNames.add(name);
|
|
569
|
-
if (debug) {
|
|
570
|
-
console.log(`[vendor] skipping local source dependency ${name} (spec: ${String(spec)})`);
|
|
571
|
-
}
|
|
572
|
-
continue;
|
|
573
|
-
}
|
|
574
|
-
addCandidate(name);
|
|
575
|
-
}
|
|
576
|
-
};
|
|
577
|
-
addDeps(pkg.dependencies);
|
|
578
|
-
addDeps(pkg.optionalDependencies);
|
|
579
|
-
for (const name of ALWAYS_INCLUDE) {
|
|
580
|
-
// Some force-included packages are only present transitively in apps that
|
|
581
|
-
// actually use them. Skip missing packages quietly so unrelated projects do
|
|
582
|
-
// not fail vendor collection just because the policy list names them.
|
|
583
|
-
if (canResolveDependencyPackageJson(name, projectRequire)) {
|
|
584
|
-
addCandidate(name);
|
|
585
|
-
}
|
|
586
|
-
}
|
|
587
|
-
// Ensure Android Activity proxy is present for SBG scanning in dev/HMR
|
|
588
|
-
// and non-HMR builds alike: explicitly include the side-effect module
|
|
589
|
-
// that registers `com.tns.NativeScriptActivity`.
|
|
590
|
-
if (platform === 'android') {
|
|
591
|
-
addCandidate('@nativescript/core/ui/frame/activity.android');
|
|
592
|
-
}
|
|
593
|
-
if (pkg.dependencies?.['nativescript-vue'] && pkg.devDependencies?.vue) {
|
|
594
|
-
addCandidate('vue');
|
|
595
|
-
}
|
|
596
|
-
// Angular framework packages are intentionally NOT added to vendor. They are
|
|
597
|
-
// served via HTTP only so every importer resolves to a single module realm.
|
|
598
|
-
// See shouldSkipDependency() for the full rationale. RxJS is also left out of
|
|
599
|
-
// vendor (large, and not required in the vendor bundle for dev HMR).
|
|
600
|
-
if (pkg.dependencies?.['react-nativescript']) {
|
|
601
|
-
if (pkg.dependencies?.react) {
|
|
602
|
-
addCandidate('react');
|
|
603
|
-
}
|
|
604
|
-
if (pkg.dependencies?.['react-dom']) {
|
|
605
|
-
addCandidate('react-dom');
|
|
606
|
-
}
|
|
607
|
-
}
|
|
608
|
-
// SolidJS / TanStack Router: when @nativescript/tanstack-router is a dependency,
|
|
609
|
-
// its runtime deps (@tanstack/solid-router, @tanstack/router-core, @tanstack/history)
|
|
610
|
-
// MUST be in the vendor bundle. These packages:
|
|
611
|
-
// 1. Use browser APIs (window.dispatchEvent) that don't exist in NativeScript — they
|
|
612
|
-
// must be bundled where the NativeScript wrapper intercepts those calls
|
|
613
|
-
// 2. Contain JSX source that needs Solid compilation (dist/source/*.jsx) — the HTTP
|
|
614
|
-
// fallback can't compile node_modules JSX since vite-plugin-solid skips it
|
|
615
|
-
// 3. Import solid-js internally — loading via HTTP creates a separate solid-js instance
|
|
616
|
-
// esbuild uses the 'import' condition (not 'solid'), resolving to pre-compiled
|
|
617
|
-
// dist/esm/*.js which avoids all three issues.
|
|
618
|
-
if (pkg.dependencies?.['@nativescript/tanstack-router']) {
|
|
619
|
-
addCandidate('@tanstack/solid-router');
|
|
620
|
-
addCandidate('@tanstack/router-core');
|
|
621
|
-
addCandidate('@tanstack/history');
|
|
622
|
-
}
|
|
623
|
-
parseEnvList(process.env.NS_VENDOR_INCLUDE).forEach(addCandidate);
|
|
624
|
-
const projectDeps = {
|
|
625
|
-
dependencies: new Set(Object.keys(pkg.dependencies ?? {})),
|
|
626
|
-
optional: new Set(Object.keys(pkg.optionalDependencies ?? {})),
|
|
627
|
-
dev: new Set(Object.keys(pkg.devDependencies ?? {})),
|
|
628
|
-
};
|
|
629
|
-
while (queue.length) {
|
|
630
|
-
const specifier = queue.shift();
|
|
631
|
-
const dependencyPkg = readDependencyPackageJson(specifier, projectRequire);
|
|
632
|
-
if (!dependencyPkg) {
|
|
633
|
-
continue;
|
|
634
|
-
}
|
|
635
|
-
const peerDependencies = Object.keys(dependencyPkg.peerDependencies ?? {});
|
|
636
|
-
for (const peer of peerDependencies) {
|
|
637
|
-
if (shouldSkipDependency(peer) || localSourceNames.has(peer)) {
|
|
638
|
-
continue;
|
|
639
|
-
}
|
|
640
|
-
if (projectDeps.dependencies.has(peer) || projectDeps.optional.has(peer) || projectDeps.dev.has(peer)) {
|
|
641
|
-
addCandidate(peer);
|
|
642
|
-
}
|
|
643
|
-
}
|
|
644
|
-
// NOTE: We intentionally do NOT collect transitive runtime dependencies
|
|
645
|
-
// here. The import map + runtime specifier normalization handles non-vendor
|
|
646
|
-
// packages by routing them through HTTP to the Vite dev server. This avoids
|
|
647
|
-
// the fragility of trying to esbuild-bundle every transitive dep (which can
|
|
648
|
-
// fail due to Node built-ins, type-only packages, duplicate module instances,
|
|
649
|
-
// etc.). Only direct project dependencies go into the vendor bundle.
|
|
650
|
-
}
|
|
651
|
-
parseEnvList(process.env.NS_VENDOR_EXCLUDE).forEach((name) => {
|
|
652
|
-
vendor.delete(name);
|
|
653
|
-
});
|
|
654
|
-
return {
|
|
655
|
-
entries: Array.from(vendor).sort(),
|
|
656
|
-
};
|
|
657
|
-
}
|
|
658
|
-
function shouldSkipDependency(name) {
|
|
659
|
-
if (!name) {
|
|
660
|
-
return true;
|
|
661
|
-
}
|
|
662
|
-
if (ALWAYS_EXCLUDE.has(name)) {
|
|
663
|
-
return true;
|
|
664
|
-
}
|
|
665
|
-
// Angular framework packages must only be served via the HTTP path so every
|
|
666
|
-
// importer resolves to a single module realm. When these packages are present
|
|
667
|
-
// in the vendor bundle AND imported by app modules via HTTP subpath, every
|
|
668
|
-
// @Component/@Injectable gets defined twice (once per realm), producing NG0912
|
|
669
|
-
// selector collisions, cross-realm `instanceof` failures, and dual class
|
|
670
|
-
// identities throughout Angular's DI container. HTTP-only is the single-realm
|
|
671
|
-
// invariant for user-level framework code.
|
|
672
|
-
if (name === '@nativescript/angular' || name === 'nativescript-angular' || name.startsWith('@angular/')) {
|
|
673
|
-
return true;
|
|
674
|
-
}
|
|
675
|
-
// All Babel packages are build tools — never bundle into device runtime.
|
|
676
|
-
// They require Node built-ins (fs, path, url) that don't exist on device.
|
|
677
|
-
if (name.startsWith('@babel/') || name.startsWith('babel-')) {
|
|
678
|
-
return true;
|
|
679
|
-
}
|
|
680
|
-
// Dev tools and type-only packages — not needed on device
|
|
681
|
-
if (name.startsWith('@solid-devtools/')) {
|
|
682
|
-
return true;
|
|
683
|
-
}
|
|
684
|
-
if (name.startsWith('@types/')) {
|
|
685
|
-
return true;
|
|
686
|
-
}
|
|
687
|
-
// PostCSS ecosystem — all build-time CSS processing
|
|
688
|
-
if (name === 'postcss' || name.startsWith('postcss-')) {
|
|
689
|
-
return true;
|
|
690
|
-
}
|
|
691
|
-
// Tailwind ecosystem — build-time only CSS framework
|
|
692
|
-
if (name.includes('tailwind')) {
|
|
693
|
-
return true;
|
|
694
|
-
}
|
|
695
|
-
// Test runners and frameworks — never needed on device
|
|
696
|
-
if (name.includes('test-runner') || name.includes('unit-test')) {
|
|
697
|
-
return true;
|
|
698
|
-
}
|
|
699
|
-
// Linters and formatters — build-time tools
|
|
700
|
-
if (name.includes('eslint') || name.includes('stylelint')) {
|
|
701
|
-
return true;
|
|
702
|
-
}
|
|
703
|
-
if (name.startsWith('.')) {
|
|
704
|
-
return true;
|
|
705
|
-
}
|
|
706
|
-
if (name.startsWith('file:')) {
|
|
707
|
-
return true;
|
|
708
|
-
}
|
|
709
|
-
if (name.startsWith('workspace:')) {
|
|
710
|
-
return true;
|
|
711
|
-
}
|
|
712
|
-
if (name.startsWith('link:')) {
|
|
713
|
-
return true;
|
|
714
|
-
}
|
|
715
|
-
return false;
|
|
716
|
-
}
|
|
717
|
-
const COMPILED_JS_ENTRY_EXTENSIONS = ['.js', '.mjs', '.cjs'];
|
|
718
|
-
const COMPILED_JS_ENTRY_REGEX = /\.(?:c|m)?jsx?$/;
|
|
719
|
-
function compiledJsExtensionsForPlatform(platform) {
|
|
720
|
-
const exts = [...COMPILED_JS_ENTRY_EXTENSIONS];
|
|
721
|
-
switch (platform) {
|
|
722
|
-
case 'android':
|
|
723
|
-
exts.push('.android.js');
|
|
724
|
-
break;
|
|
725
|
-
case 'ios':
|
|
726
|
-
exts.push('.ios.js', '.visionos.js');
|
|
727
|
-
break;
|
|
728
|
-
case 'visionos':
|
|
729
|
-
exts.push('.visionos.js', '.ios.js');
|
|
730
|
-
break;
|
|
731
|
-
}
|
|
732
|
-
return exts;
|
|
733
|
-
}
|
|
734
|
-
/**
|
|
735
|
-
* Determine whether a `package.json` dependency must be excluded from the
|
|
736
|
-
* HMR vendor bundle because esbuild's standalone vendor pipeline can't
|
|
737
|
-
* resolve its source.
|
|
738
|
-
*
|
|
739
|
-
* The HMR vendor bundle is generated by a standalone esbuild build that
|
|
740
|
-
* has none of the Vite plugin chain (most notably
|
|
741
|
-
* `ns-tsconfig-paths-resolver`), so any aliased import inside the
|
|
742
|
-
* package's **source** files will fail with "Could not resolve" and abort
|
|
743
|
-
* the whole bundle.
|
|
744
|
-
*
|
|
745
|
-
* Skip:
|
|
746
|
-
* - `link:` and `workspace:` refs (always app-side source).
|
|
747
|
-
* - `file:` refs to a directory whose installed package only ships
|
|
748
|
-
* TypeScript/JSX source (no compiled `.js`/`.mjs`/`.cjs` entry).
|
|
749
|
-
*
|
|
750
|
-
* Keep (return false):
|
|
751
|
-
* - Regular semver / git / url specs (normal third-party libraries).
|
|
752
|
-
* - Local `.tgz` file refs (pre-packaged libraries extracted at install).
|
|
753
|
-
* - `file:` directory refs that resolve to a package with a compiled JS
|
|
754
|
-
* entry — a common NativeScript monorepo convention where the app's
|
|
755
|
-
* `package.json` redirects to `../../node_modules/<name>` to avoid
|
|
756
|
-
* duplicate installs while letting the NativeScript CLI discover
|
|
757
|
-
* plugins from the app directory.
|
|
758
|
-
*/
|
|
759
|
-
export function isUnvendorableLocalSource(name, spec, projectRequire, platform) {
|
|
760
|
-
if (typeof spec !== 'string')
|
|
761
|
-
return false;
|
|
762
|
-
if (spec.startsWith('link:') || spec.startsWith('workspace:'))
|
|
763
|
-
return true;
|
|
764
|
-
if (!spec.startsWith('file:'))
|
|
765
|
-
return false;
|
|
766
|
-
// Tarballs are already pre-packaged libraries — install extracts them
|
|
767
|
-
// into a normal node_modules entry.
|
|
768
|
-
if (/\.t(?:ar\.)?gz(?:[?#].*)?$/.test(spec))
|
|
769
|
-
return false;
|
|
770
|
-
// Directory file: refs need a deeper check: peek at the installed
|
|
771
|
-
// package.json and ask "does this ship compiled JS?". If yes, vendor
|
|
772
|
-
// it. If no (TS source only), defer to the regular Vite pipeline.
|
|
773
|
-
return !packageHasCompiledJsEntry(name, projectRequire, platform);
|
|
774
|
-
}
|
|
775
|
-
function packageHasCompiledJsEntry(name, projectRequire, platform) {
|
|
776
|
-
let pkgJsonPath;
|
|
777
|
-
try {
|
|
778
|
-
pkgJsonPath = projectRequire.resolve(`${name}/package.json`);
|
|
779
|
-
}
|
|
780
|
-
catch {
|
|
781
|
-
return false;
|
|
782
|
-
}
|
|
783
|
-
let pkg;
|
|
784
|
-
try {
|
|
785
|
-
pkg = JSON.parse(readFileSync(pkgJsonPath, 'utf-8'));
|
|
786
|
-
}
|
|
787
|
-
catch {
|
|
788
|
-
return false;
|
|
789
|
-
}
|
|
790
|
-
const pkgDir = path.dirname(pkgJsonPath);
|
|
791
|
-
const candidates = [];
|
|
792
|
-
const pushCandidate = (value) => {
|
|
793
|
-
if (typeof value === 'string' && value)
|
|
794
|
-
candidates.push(value);
|
|
795
|
-
};
|
|
796
|
-
pushCandidate(pkg.module);
|
|
797
|
-
pushCandidate(pkg.main);
|
|
798
|
-
// Recursively flatten conditional `exports` maps to surface concrete
|
|
799
|
-
// file paths. We only need `string` leaves; anything else (function-
|
|
800
|
-
// based exports, etc.) doesn't apply to esbuild's resolution.
|
|
801
|
-
const visitExports = (node) => {
|
|
802
|
-
if (!node)
|
|
803
|
-
return;
|
|
804
|
-
if (typeof node === 'string') {
|
|
805
|
-
pushCandidate(node);
|
|
806
|
-
return;
|
|
807
|
-
}
|
|
808
|
-
if (Array.isArray(node)) {
|
|
809
|
-
for (const item of node)
|
|
810
|
-
visitExports(item);
|
|
811
|
-
return;
|
|
812
|
-
}
|
|
813
|
-
if (typeof node === 'object') {
|
|
814
|
-
for (const value of Object.values(node))
|
|
815
|
-
visitExports(value);
|
|
816
|
-
}
|
|
817
|
-
};
|
|
818
|
-
visitExports(pkg.exports);
|
|
819
|
-
if (candidates.length === 0) {
|
|
820
|
-
// node's default lookup falls back to `index.js`.
|
|
821
|
-
candidates.push('index');
|
|
822
|
-
}
|
|
823
|
-
const extensionsToTry = compiledJsExtensionsForPlatform(platform);
|
|
824
|
-
for (const cand of candidates) {
|
|
825
|
-
const abs = path.resolve(pkgDir, cand);
|
|
826
|
-
const ext = path.extname(cand);
|
|
827
|
-
if (COMPILED_JS_ENTRY_REGEX.test(cand)) {
|
|
828
|
-
// Explicit JS extension. If the file exists, vendor it. If not
|
|
829
|
-
// (a NativeScript plugin commonly declares `main: "index.js"`
|
|
830
|
-
// but ships only platform variants like `index.ios.js`), try
|
|
831
|
-
// the platform-specific variants which esbuild's
|
|
832
|
-
// `resolveExtensions` will pick up at bundle time.
|
|
833
|
-
if (fs.existsSync(abs))
|
|
834
|
-
return true;
|
|
835
|
-
const baseAbs = abs.slice(0, -ext.length);
|
|
836
|
-
for (const e of extensionsToTry) {
|
|
837
|
-
if (fs.existsSync(baseAbs + e))
|
|
838
|
-
return true;
|
|
839
|
-
}
|
|
840
|
-
continue;
|
|
841
|
-
}
|
|
842
|
-
if (!ext) {
|
|
843
|
-
// Extensionless main — try plain JS variants AND the
|
|
844
|
-
// platform-specific variants NativeScript plugins commonly use
|
|
845
|
-
// (`index.ios.js`, `index.android.js`, `index.visionos.js`).
|
|
846
|
-
for (const e of extensionsToTry) {
|
|
847
|
-
if (fs.existsSync(abs + e))
|
|
848
|
-
return true;
|
|
849
|
-
}
|
|
850
|
-
continue;
|
|
851
|
-
}
|
|
852
|
-
// A non-JS extension (typically `.ts`/`.tsx`) means the package
|
|
853
|
-
// only ships TS source — esbuild's vendor pipeline can't resolve
|
|
854
|
-
// any tsconfig-aliased imports inside it.
|
|
855
|
-
}
|
|
856
|
-
return false;
|
|
857
|
-
}
|
|
858
|
-
export const __test_collectVendorModules = collectVendorModules;
|
|
859
|
-
export const __test_createVendorBundleRuntimeModule = createVendorBundleRuntimeModule;
|
|
860
|
-
export const __test_isUnvendorableLocalSource = isUnvendorableLocalSource;
|
|
861
|
-
export const __test_packageHasCompiledJsEntry = packageHasCompiledJsEntry;
|
|
862
|
-
function canResolveDependencyPackageJson(specifier, projectRequire) {
|
|
863
|
-
try {
|
|
864
|
-
projectRequire.resolve(`${specifier}/package.json`);
|
|
865
|
-
return true;
|
|
866
|
-
}
|
|
867
|
-
catch {
|
|
868
|
-
return false;
|
|
869
|
-
}
|
|
870
|
-
}
|
|
871
|
-
function readDependencyPackageJson(specifier, projectRequire) {
|
|
872
|
-
try {
|
|
873
|
-
const packageJsonPath = projectRequire.resolve(`${specifier}/package.json`);
|
|
874
|
-
return JSON.parse(readFileSync(packageJsonPath, 'utf-8'));
|
|
875
|
-
}
|
|
876
|
-
catch (error) {
|
|
877
|
-
if (process.env.VITE_DEBUG_LOGS) {
|
|
878
|
-
console.warn(`[vendor] unable to resolve ${specifier} package.json`, error);
|
|
879
|
-
}
|
|
880
|
-
return null;
|
|
881
|
-
}
|
|
882
|
-
}
|
|
883
|
-
function parseEnvList(value) {
|
|
884
|
-
if (!value) {
|
|
885
|
-
return [];
|
|
886
|
-
}
|
|
887
|
-
return value
|
|
888
|
-
.split(',')
|
|
889
|
-
.map((token) => token.trim())
|
|
890
|
-
.filter(Boolean);
|
|
891
|
-
}
|
|
892
495
|
function createVendorEntry(entries) {
|
|
893
496
|
if (!entries.length) {
|
|
894
497
|
return `export const __nsVendorModuleMap = {};
|
|
895
498
|
`;
|
|
896
499
|
}
|
|
897
|
-
|
|
500
|
+
// Emit a side-effect-only import FIRST for each entry, then the namespace
|
|
501
|
+
// import we actually expose through `__nsVendorModuleMap`. Per the ESM
|
|
502
|
+
// spec, `import "pkg";` (no clause) guarantees module body evaluation, and
|
|
503
|
+
// esbuild treats these as DCE-immune even when the package declares
|
|
504
|
+
// `"sideEffects": false`. Without this, packages whose top-level
|
|
505
|
+
// statements install runtime patches (e.g. `@nativescript-community/text`
|
|
506
|
+
// monkey-patching `TextBase.prototype.setTextDecorationAndTransform` via
|
|
507
|
+
// `overrideSpanAndFormattedString()` invoked from
|
|
508
|
+
// `@nativescript-community/ui-label/index-common.js` line 12) can have
|
|
509
|
+
// their bodies elided by esbuild — exports stay resolvable via the
|
|
510
|
+
// namespace, but the runtime patches never fire, producing line-height /
|
|
511
|
+
// letter-spacing / formatted-text rendering divergence between HMR
|
|
512
|
+
// (vendor.mjs via HTTP) and no-HMR (single Rolldown bundle that inlines
|
|
513
|
+
// everything anyway). This affects any NS plugin that relies on top-level
|
|
514
|
+
// side-effects to wire up renderer behavior.
|
|
515
|
+
const sideEffectImports = entries.map((specifier) => `import ${JSON.stringify(specifier)};`).join('\n');
|
|
516
|
+
const namespaceImports = entries.map((specifier, index) => `import * as __nsVendor_${index} from ${JSON.stringify(specifier)};`).join('\n');
|
|
898
517
|
const modules = entries.map((specifier, index) => `${JSON.stringify(specifier)}: __nsVendor_${index}`).join(',\n ');
|
|
899
|
-
return `${
|
|
518
|
+
return `${sideEffectImports}\n\n${namespaceImports}\n\nexport const __nsVendorModuleMap = {\n ${modules}\n};\n`;
|
|
900
519
|
}
|
|
901
|
-
function createVendorBundleRuntimeModule(result) {
|
|
520
|
+
export function createVendorBundleRuntimeModule(result) {
|
|
902
521
|
return `${result.code}
|
|
903
522
|
export const vendorManifest = ${JSON.stringify(result.manifest)};
|
|
904
523
|
export default vendorManifest;
|
|
905
524
|
`;
|
|
906
525
|
}
|
|
526
|
+
/**
|
|
527
|
+
* Dev-session `/@nativescript/vendor.mjs` for sessions WITHOUT a deps bundle
|
|
528
|
+
* (esbuild failure or `NS_DEPS_PER_MODULE=1`): a thin view whose namespace
|
|
529
|
+
* imports go through the same `/ns/m/node_modules/<pkg>` URLs the device
|
|
530
|
+
* import map targets. Per-module serving keys module identity by URL, so the
|
|
531
|
+
* registry entries `installVendorBootstrap` creates from this map are the
|
|
532
|
+
* SAME instances import-side resolution produces — one realm, no standalone
|
|
533
|
+
* vendor payload. `@nativescript/core` stays a bare import (import map →
|
|
534
|
+
* `/ns/core` bridge realm).
|
|
535
|
+
*/
|
|
536
|
+
export function createHttpVendorRuntimeModule(manifest) {
|
|
537
|
+
const specs = Object.keys(manifest?.modules ?? {}).filter((spec) => spec !== '@nativescript/core' && !spec.startsWith('@nativescript/core/'));
|
|
538
|
+
const includeCore = !!manifest?.modules?.['@nativescript/core'];
|
|
539
|
+
const lines = [];
|
|
540
|
+
lines.push('/* /@nativescript/vendor.mjs — HTTP-backed vendor view (per-module mode) */');
|
|
541
|
+
if (includeCore) {
|
|
542
|
+
lines.push(`import * as __ns_core__ from "@nativescript/core";`);
|
|
543
|
+
}
|
|
544
|
+
specs.forEach((spec, index) => {
|
|
545
|
+
lines.push(`import * as __nsVendor_${index} from ${JSON.stringify(`/ns/m/node_modules/${spec}`)};`);
|
|
546
|
+
});
|
|
547
|
+
lines.push('export const __nsVendorModuleMap = {');
|
|
548
|
+
if (includeCore) {
|
|
549
|
+
lines.push(` ${JSON.stringify('@nativescript/core')}: __ns_core__,`);
|
|
550
|
+
}
|
|
551
|
+
specs.forEach((spec, index) => {
|
|
552
|
+
lines.push(` ${JSON.stringify(spec)}: __nsVendor_${index},`);
|
|
553
|
+
});
|
|
554
|
+
lines.push('};');
|
|
555
|
+
lines.push(`export const vendorManifest = ${JSON.stringify(manifest ?? {})};`);
|
|
556
|
+
lines.push('export default vendorManifest;');
|
|
557
|
+
lines.push('');
|
|
558
|
+
return lines.join('\n');
|
|
559
|
+
}
|
|
907
560
|
function resolveExtensionsForPlatform(platform) {
|
|
908
561
|
const base = ['.tsx', '.jsx', '.ts', '.js', '.mjs', '.cjs', '.json'];
|
|
909
562
|
const extensions = new Set(base);
|
|
@@ -961,483 +614,6 @@ function createSbgVendorAssetCode(platform) {
|
|
|
961
614
|
lines.push('export const __nsVendorModuleMap = {};\nexport default {};\n');
|
|
962
615
|
return lines.join('\n');
|
|
963
616
|
}
|
|
964
|
-
function createVendorEsbuildPlugin(projectRoot) {
|
|
965
|
-
return {
|
|
966
|
-
name: 'ns-vendor-resolver',
|
|
967
|
-
setup(build) {
|
|
968
|
-
const debug = process.env.VITE_DEBUG_LOGS === 'true' || process.env.VITE_DEBUG_LOGS === '1';
|
|
969
|
-
build.onResolve({ filter: /^~\/package\.json$/ }, () => ({
|
|
970
|
-
path: path.resolve(projectRoot, 'package.json'),
|
|
971
|
-
}));
|
|
972
|
-
build.onResolve({ filter: /^module$/ }, () => ({
|
|
973
|
-
path: 'ns-vendor-module-shim',
|
|
974
|
-
namespace: 'ns-vendor',
|
|
975
|
-
}));
|
|
976
|
-
build.onLoad({ filter: /^ns-vendor-module-shim$/, namespace: 'ns-vendor' }, () => ({
|
|
977
|
-
contents: vendorModuleShim,
|
|
978
|
-
loader: 'js',
|
|
979
|
-
}));
|
|
980
|
-
// Stub Angular animations in vendor to avoid bundling browser-only code.
|
|
981
|
-
// Provide named exports expected by @nativescript/angular to satisfy esbuild.
|
|
982
|
-
const PB_ANIMATIONS_ID = 'ns-animations-pb-shim';
|
|
983
|
-
const ANIMATIONS_BROWSER_ID = 'ns-animations-browser-shim';
|
|
984
|
-
const ANIMATIONS_ID = 'ns-animations-noop';
|
|
985
|
-
// @angular/platform-browser/animations -> provide concrete named stubs
|
|
986
|
-
build.onResolve({ filter: /^@angular\/platform-browser\/animations(?:\/.*)?$/ }, (args) => {
|
|
987
|
-
if (debug) {
|
|
988
|
-
console.log('[vendor] map', args.path, '->', PB_ANIMATIONS_ID);
|
|
989
|
-
}
|
|
990
|
-
return { path: PB_ANIMATIONS_ID, namespace: 'ns-vendor' };
|
|
991
|
-
});
|
|
992
|
-
build.onLoad({ filter: new RegExp(`^${PB_ANIMATIONS_ID}$`), namespace: 'ns-vendor' }, () => ({
|
|
993
|
-
contents: [
|
|
994
|
-
'export default {};',
|
|
995
|
-
// Commonly imported symbols by @nativescript/angular
|
|
996
|
-
'export class AnimationBuilder {};',
|
|
997
|
-
'export const \u0275BrowserAnimationBuilder = class {};',
|
|
998
|
-
'export const \u0275AnimationEngine = class {};',
|
|
999
|
-
'export const \u0275AnimationRendererFactory = class {};',
|
|
1000
|
-
'export const \u0275WebAnimationsStyleNormalizer = class {};',
|
|
1001
|
-
// Typical platform-browser/animations APIs exported; safe no-ops
|
|
1002
|
-
'export class BrowserAnimationsModule {};',
|
|
1003
|
-
'export class NoopAnimationsModule {};',
|
|
1004
|
-
'export const provideAnimations = (..._args) => [];',
|
|
1005
|
-
'export const provideNoopAnimations = (..._args) => [];',
|
|
1006
|
-
// Marker used by some Angular internals
|
|
1007
|
-
'export const ANIMATION_MODULE_TYPE = void 0;',
|
|
1008
|
-
].join('\n'),
|
|
1009
|
-
loader: 'js',
|
|
1010
|
-
}));
|
|
1011
|
-
// @angular/animations/browser -> provide ɵ* engine/renderer/style normalizer stubs
|
|
1012
|
-
build.onResolve({ filter: /^@angular\/animations\/browser(?:\/.*)?$/ }, (args) => {
|
|
1013
|
-
if (debug) {
|
|
1014
|
-
console.log('[vendor] map', args.path, '->', ANIMATIONS_BROWSER_ID);
|
|
1015
|
-
}
|
|
1016
|
-
return { path: ANIMATIONS_BROWSER_ID, namespace: 'ns-vendor' };
|
|
1017
|
-
});
|
|
1018
|
-
build.onLoad({ filter: new RegExp(`^${ANIMATIONS_BROWSER_ID}$`), namespace: 'ns-vendor' }, () => ({
|
|
1019
|
-
contents: [
|
|
1020
|
-
'export default {};',
|
|
1021
|
-
'export class AnimationDriver {};',
|
|
1022
|
-
'export const \u0275AnimationRendererFactory = class {};',
|
|
1023
|
-
'export const \u0275AnimationStyleNormalizer = class {};',
|
|
1024
|
-
'export const \u0275WebAnimationsStyleNormalizer = class {};',
|
|
1025
|
-
'export const \u0275AnimationEngine = class {};',
|
|
1026
|
-
// Convenience alias if any consumers import non-ɵ name
|
|
1027
|
-
'export const AnimationStyleNormalizer = \u0275AnimationStyleNormalizer;',
|
|
1028
|
-
].join('\n'),
|
|
1029
|
-
loader: 'js',
|
|
1030
|
-
}));
|
|
1031
|
-
// @angular/animations -> broad no-op surface
|
|
1032
|
-
build.onResolve(
|
|
1033
|
-
// Keep generic mapping for @angular/animations base; /browser is handled above
|
|
1034
|
-
{ filter: /^@angular\/animations(?:$|\/)$/ }, (args) => {
|
|
1035
|
-
if (debug) {
|
|
1036
|
-
console.log('[vendor] map', args.path, '->', ANIMATIONS_ID);
|
|
1037
|
-
}
|
|
1038
|
-
return { path: ANIMATIONS_ID, namespace: 'ns-vendor' };
|
|
1039
|
-
});
|
|
1040
|
-
build.onLoad({ filter: new RegExp(`^${ANIMATIONS_ID}$`), namespace: 'ns-vendor' }, () => ({
|
|
1041
|
-
contents: [
|
|
1042
|
-
'export default {};',
|
|
1043
|
-
// Provide names sometimes (incorrectly) imported from @angular/animations by wrappers
|
|
1044
|
-
'export class AnimationBuilder {};',
|
|
1045
|
-
'export const \u0275BrowserAnimationBuilder = class {};',
|
|
1046
|
-
'export const \u0275AnimationEngine = class {};',
|
|
1047
|
-
'export const \u0275AnimationRendererFactory = class {};',
|
|
1048
|
-
'export const \u0275WebAnimationsStyleNormalizer = class {};',
|
|
1049
|
-
'export const ANIMATION_MODULE_TYPE = void 0;',
|
|
1050
|
-
// Export a few common tokens as harmless stubs
|
|
1051
|
-
'export const animate = (..._a) => ({});',
|
|
1052
|
-
'export const state = (..._a) => ({});',
|
|
1053
|
-
'export const style = (..._a) => ({});',
|
|
1054
|
-
'export const transition = (..._a) => ({});',
|
|
1055
|
-
'export const trigger = (..._a) => ({});',
|
|
1056
|
-
'export const sequence = (..._a) => ({});',
|
|
1057
|
-
'export const group = (..._a) => ({});',
|
|
1058
|
-
'export const query = (..._a) => ({});',
|
|
1059
|
-
'export const stagger = (..._a) => ({});',
|
|
1060
|
-
'export const keyframes = (..._a) => ({});',
|
|
1061
|
-
].join('\n'),
|
|
1062
|
-
loader: 'js',
|
|
1063
|
-
}));
|
|
1064
|
-
},
|
|
1065
|
-
};
|
|
1066
|
-
}
|
|
1067
|
-
/**
|
|
1068
|
-
* esbuild plugin to compile .jsx/.tsx files from Solid packages through
|
|
1069
|
-
* babel-preset-solid. Without this, esbuild uses its default React JSX
|
|
1070
|
-
* transform, producing React.createElement calls that crash at runtime.
|
|
1071
|
-
*
|
|
1072
|
-
* Only applied to files inside node_modules that have .jsx or .tsx extension.
|
|
1073
|
-
*/
|
|
1074
|
-
function createSolidJsxEsbuildPlugin(projectRoot) {
|
|
1075
|
-
// Lazy-load Babel and the Solid preset so they're only required when
|
|
1076
|
-
// the Solid flavor is active.
|
|
1077
|
-
let babel;
|
|
1078
|
-
let solidPreset;
|
|
1079
|
-
return {
|
|
1080
|
-
name: 'ns-vendor-solid-jsx',
|
|
1081
|
-
setup(build) {
|
|
1082
|
-
// Intercept .jsx and .tsx files from node_modules
|
|
1083
|
-
build.onLoad({ filter: /node_modules\/.*\.[jt]sx$/ }, async (args) => {
|
|
1084
|
-
try {
|
|
1085
|
-
if (!babel) {
|
|
1086
|
-
babel = await import('@babel/core');
|
|
1087
|
-
// babel-preset-solid is the standard Solid JSX transform
|
|
1088
|
-
solidPreset = (await import('babel-preset-solid')).default;
|
|
1089
|
-
}
|
|
1090
|
-
const source = await readFile(args.path, 'utf-8');
|
|
1091
|
-
const result = await babel.transformAsync(source, {
|
|
1092
|
-
filename: args.path,
|
|
1093
|
-
presets: [
|
|
1094
|
-
[
|
|
1095
|
-
solidPreset,
|
|
1096
|
-
{
|
|
1097
|
-
generate: 'universal',
|
|
1098
|
-
hydratable: false,
|
|
1099
|
-
moduleName: '@nativescript-community/solid-js',
|
|
1100
|
-
},
|
|
1101
|
-
],
|
|
1102
|
-
],
|
|
1103
|
-
parserOpts: {
|
|
1104
|
-
plugins: ['jsx', ...(args.path.endsWith('.tsx') ? ['typescript'] : [])],
|
|
1105
|
-
},
|
|
1106
|
-
ast: false,
|
|
1107
|
-
sourceMaps: false,
|
|
1108
|
-
configFile: false,
|
|
1109
|
-
babelrc: false,
|
|
1110
|
-
});
|
|
1111
|
-
if (result?.code) {
|
|
1112
|
-
return { contents: result.code, loader: 'js' };
|
|
1113
|
-
}
|
|
1114
|
-
}
|
|
1115
|
-
catch (e) {
|
|
1116
|
-
console.warn(`[ns-vendor-solid-jsx] failed to transform ${args.path}:`, e?.message || e);
|
|
1117
|
-
}
|
|
1118
|
-
// Fall through to esbuild's default handling
|
|
1119
|
-
return undefined;
|
|
1120
|
-
});
|
|
1121
|
-
},
|
|
1122
|
-
};
|
|
1123
|
-
}
|
|
1124
|
-
/**
|
|
1125
|
-
* Minimal esbuild plugin to run Angular linker (Babel) over partial-compiled
|
|
1126
|
-
* Angular packages in node_modules. This converts ɵɵngDeclare* calls into
|
|
1127
|
-
* ɵɵdefine* so runtime doesn't require the JIT compiler.
|
|
1128
|
-
*/
|
|
1129
|
-
function angularLinkerEsbuildPlugin(projectRoot) {
|
|
1130
|
-
// Lazily resolve Babel and Angular linker from the project to avoid hard deps
|
|
1131
|
-
let babel = null;
|
|
1132
|
-
let createLinker = null;
|
|
1133
|
-
let angularFileSystem = null;
|
|
1134
|
-
async function ensureDeps() {
|
|
1135
|
-
if (babel && createLinker)
|
|
1136
|
-
return;
|
|
1137
|
-
try {
|
|
1138
|
-
const req = createRequire(projectRoot + '/package.json');
|
|
1139
|
-
// Resolve from the application project first
|
|
1140
|
-
const babelPath = req.resolve('@babel/core');
|
|
1141
|
-
const linkerPath = req.resolve('@angular/compiler-cli/linker/babel');
|
|
1142
|
-
babel = (await import(babelPath));
|
|
1143
|
-
const linkerMod = await import(linkerPath);
|
|
1144
|
-
createLinker = linkerMod.createLinkerPlugin || linkerMod.createEs2015LinkerPlugin || null;
|
|
1145
|
-
}
|
|
1146
|
-
catch {
|
|
1147
|
-
// As a fallback, try local resolution (hoisted installs)
|
|
1148
|
-
try {
|
|
1149
|
-
babel = (await import('@babel/core'));
|
|
1150
|
-
}
|
|
1151
|
-
catch { }
|
|
1152
|
-
try {
|
|
1153
|
-
const linkerMod = await import('@angular/compiler-cli/linker/babel');
|
|
1154
|
-
createLinker = linkerMod.createLinkerPlugin || linkerMod.createEs2015LinkerPlugin || null;
|
|
1155
|
-
}
|
|
1156
|
-
catch { }
|
|
1157
|
-
}
|
|
1158
|
-
// Angular 21+ requires a fileSystem for the linker plugin
|
|
1159
|
-
if (!angularFileSystem) {
|
|
1160
|
-
try {
|
|
1161
|
-
const req = createRequire(projectRoot + '/package.json');
|
|
1162
|
-
const cliPath = req.resolve('@angular/compiler-cli');
|
|
1163
|
-
const cliMod = await import(cliPath);
|
|
1164
|
-
if (cliMod.NodeJSFileSystem) {
|
|
1165
|
-
angularFileSystem = new cliMod.NodeJSFileSystem();
|
|
1166
|
-
}
|
|
1167
|
-
}
|
|
1168
|
-
catch { }
|
|
1169
|
-
if (!angularFileSystem) {
|
|
1170
|
-
try {
|
|
1171
|
-
const cliMod = await import('@angular/compiler-cli');
|
|
1172
|
-
if (cliMod.NodeJSFileSystem) {
|
|
1173
|
-
angularFileSystem = new cliMod.NodeJSFileSystem();
|
|
1174
|
-
}
|
|
1175
|
-
}
|
|
1176
|
-
catch { }
|
|
1177
|
-
}
|
|
1178
|
-
if (!angularFileSystem) {
|
|
1179
|
-
// Minimal fallback
|
|
1180
|
-
const nodePath = await import('node:path');
|
|
1181
|
-
const nodeFs = await import('node:fs');
|
|
1182
|
-
angularFileSystem = {
|
|
1183
|
-
resolve: (...paths) => nodePath.resolve(...paths),
|
|
1184
|
-
dirname: (p) => nodePath.dirname(p),
|
|
1185
|
-
join: (...paths) => nodePath.join(...paths),
|
|
1186
|
-
isRooted: (p) => nodePath.isAbsolute(p),
|
|
1187
|
-
exists: (p) => nodeFs.existsSync(p),
|
|
1188
|
-
readFile: (p) => nodeFs.readFileSync(p, 'utf8'),
|
|
1189
|
-
};
|
|
1190
|
-
}
|
|
1191
|
-
}
|
|
1192
|
-
}
|
|
1193
|
-
// Restrict to Angular framework packages to minimize esbuild memory usage.
|
|
1194
|
-
const FILTER = /node_modules\/(?:@angular|@nativescript\/angular)\/.*\.[mc]?js$/;
|
|
1195
|
-
return {
|
|
1196
|
-
name: 'ns-angular-linker',
|
|
1197
|
-
async setup(build) {
|
|
1198
|
-
const debug = process.env.VITE_DEBUG_LOGS === 'true' || process.env.VITE_DEBUG_LOGS === '1';
|
|
1199
|
-
await ensureDeps();
|
|
1200
|
-
if (!babel || !createLinker) {
|
|
1201
|
-
// Nothing to do if deps unavailable
|
|
1202
|
-
return;
|
|
1203
|
-
}
|
|
1204
|
-
build.onLoad({ filter: FILTER }, async (args) => {
|
|
1205
|
-
try {
|
|
1206
|
-
const source = await readFile(args.path, 'utf8');
|
|
1207
|
-
// Fast-path: only run linker when partial declarations are present
|
|
1208
|
-
if (!(source.includes('\u0275\u0275ngDeclare') || source.includes('ɵɵngDeclare'))) {
|
|
1209
|
-
return { contents: source, loader: 'js' };
|
|
1210
|
-
}
|
|
1211
|
-
const plugin = createLinker({
|
|
1212
|
-
sourceMapping: false,
|
|
1213
|
-
fileSystem: angularFileSystem,
|
|
1214
|
-
});
|
|
1215
|
-
if (debug) {
|
|
1216
|
-
console.log('[ns-angular-linker][vendor] linking', args.path);
|
|
1217
|
-
}
|
|
1218
|
-
const result = await babel.transformAsync(source, {
|
|
1219
|
-
filename: args.path,
|
|
1220
|
-
configFile: false,
|
|
1221
|
-
babelrc: false,
|
|
1222
|
-
sourceMaps: false,
|
|
1223
|
-
compact: false,
|
|
1224
|
-
plugins: [plugin],
|
|
1225
|
-
});
|
|
1226
|
-
return {
|
|
1227
|
-
contents: (result && result.code) || source,
|
|
1228
|
-
loader: 'js',
|
|
1229
|
-
};
|
|
1230
|
-
}
|
|
1231
|
-
catch (e) {
|
|
1232
|
-
// On any failure, return original source to avoid breaking the build
|
|
1233
|
-
return { contents: await readFile(args.path, 'utf8'), loader: 'js' };
|
|
1234
|
-
}
|
|
1235
|
-
});
|
|
1236
|
-
},
|
|
1237
|
-
};
|
|
1238
|
-
}
|
|
1239
|
-
const vendorModuleShim = `
|
|
1240
|
-
const g = globalThis;
|
|
1241
|
-
const BACKSLASH = String.fromCharCode(92);
|
|
1242
|
-
|
|
1243
|
-
function toForwardSlashes(input) {
|
|
1244
|
-
return String(input ?? '').split(BACKSLASH).join('/');
|
|
1245
|
-
}
|
|
1246
|
-
|
|
1247
|
-
function getNativeScriptRequire() {
|
|
1248
|
-
const nsRequire = typeof g.require === "function" ? g.require : null;
|
|
1249
|
-
if (nsRequire) {
|
|
1250
|
-
return nsRequire;
|
|
1251
|
-
}
|
|
1252
|
-
const legacy = g.__nsRequire;
|
|
1253
|
-
if (typeof legacy === "function") {
|
|
1254
|
-
return legacy;
|
|
1255
|
-
}
|
|
1256
|
-
return null;
|
|
1257
|
-
}
|
|
1258
|
-
|
|
1259
|
-
function getDocumentsPath() {
|
|
1260
|
-
const cached = g.__NS_DOCUMENTS_PATH__;
|
|
1261
|
-
if (typeof cached === "string" && cached.length) {
|
|
1262
|
-
return toForwardSlashes(cached);
|
|
1263
|
-
}
|
|
1264
|
-
try {
|
|
1265
|
-
const core = g.require ? g.require("@nativescript/core") : null;
|
|
1266
|
-
const docsFolder = core?.knownFolders?.documents?.();
|
|
1267
|
-
const docPath = docsFolder?.path;
|
|
1268
|
-
if (docPath) {
|
|
1269
|
-
const normalized = toForwardSlashes(docPath);
|
|
1270
|
-
g.__NS_DOCUMENTS_PATH__ = normalized;
|
|
1271
|
-
return normalized;
|
|
1272
|
-
}
|
|
1273
|
-
} catch (_err) {
|
|
1274
|
-
// ignore - fallback to raw specifier
|
|
1275
|
-
}
|
|
1276
|
-
return null;
|
|
1277
|
-
}
|
|
1278
|
-
|
|
1279
|
-
function collapseSegments(input) {
|
|
1280
|
-
const segments = [];
|
|
1281
|
-
const parts = input.split('/');
|
|
1282
|
-
for (const part of parts) {
|
|
1283
|
-
if (!part || part === ".") {
|
|
1284
|
-
continue;
|
|
1285
|
-
}
|
|
1286
|
-
if (part === "..") {
|
|
1287
|
-
if (segments.length && segments[segments.length - 1] !== "..") {
|
|
1288
|
-
segments.pop();
|
|
1289
|
-
continue;
|
|
1290
|
-
}
|
|
1291
|
-
}
|
|
1292
|
-
segments.push(part);
|
|
1293
|
-
}
|
|
1294
|
-
const leadingSlash = input.startsWith('/');
|
|
1295
|
-
return (leadingSlash ? '/' : '') + segments.join('/');
|
|
1296
|
-
}
|
|
1297
|
-
|
|
1298
|
-
function normalizeSpecifier(spec) {
|
|
1299
|
-
let value = String(spec ?? "");
|
|
1300
|
-
value = toForwardSlashes(value);
|
|
1301
|
-
const docsPath = getDocumentsPath();
|
|
1302
|
-
if (value.startsWith("__NSDOC__/")) {
|
|
1303
|
-
if (docsPath) {
|
|
1304
|
-
value = docsPath + '/' + value.slice("__NSDOC__/".length);
|
|
1305
|
-
} else {
|
|
1306
|
-
value = value.slice("__NSDOC__/".length);
|
|
1307
|
-
}
|
|
1308
|
-
}
|
|
1309
|
-
if (value.startsWith("~/") && docsPath) {
|
|
1310
|
-
value = docsPath + '/' + value.slice(2);
|
|
1311
|
-
}
|
|
1312
|
-
if (value.startsWith("file://")) {
|
|
1313
|
-
const stripped = value.slice("file://".length);
|
|
1314
|
-
value = stripped.startsWith('/') ? stripped : '/' + stripped;
|
|
1315
|
-
}
|
|
1316
|
-
if (value.includes("/../") || value.includes("/./")) {
|
|
1317
|
-
value = collapseSegments(value);
|
|
1318
|
-
}
|
|
1319
|
-
return value;
|
|
1320
|
-
}
|
|
1321
|
-
|
|
1322
|
-
function normalizeCoreSubLocal(s) {
|
|
1323
|
-
if (!s) return "";
|
|
1324
|
-
let t = String(s).split("?")[0].split("#")[0].trim();
|
|
1325
|
-
t = t.replace(/^\\/+/, "").replace(/\\/+$/, "");
|
|
1326
|
-
t = t.replace(/\\.(?:mjs|cjs|js)$/, "");
|
|
1327
|
-
if (t.length >= 6 && t.substring(t.length - 6) === "/index") {
|
|
1328
|
-
t = t.substring(0, t.length - 6);
|
|
1329
|
-
}
|
|
1330
|
-
if (!t || t === "index") return "";
|
|
1331
|
-
return t;
|
|
1332
|
-
}
|
|
1333
|
-
|
|
1334
|
-
// Invariant D: shape ESM namespaces before returning to CJS callers.
|
|
1335
|
-
//
|
|
1336
|
-
// The /ns/core handler's registration footer (see websocket.ts) and the
|
|
1337
|
-
// main-entry require shim (see helpers/main-entry.ts) both install the
|
|
1338
|
-
// shape function on globalThis. In practice, entries stored in
|
|
1339
|
-
// __NS_CORE_MODULES__ are ALREADY shaped, so this pass-through is a
|
|
1340
|
-
// fast no-op (the shape function's fast path returns obj as-is when it
|
|
1341
|
-
// already has Object.prototype). We call it anyway as defense-in-depth
|
|
1342
|
-
// against future callers that might populate the registry without
|
|
1343
|
-
// shaping.
|
|
1344
|
-
function shapeForCjs(value) {
|
|
1345
|
-
if (!value || typeof value !== "object") return value;
|
|
1346
|
-
const shape = g.__NS_CJS_SHAPE__;
|
|
1347
|
-
if (typeof shape === "function") {
|
|
1348
|
-
try { return shape(value); } catch (e) {}
|
|
1349
|
-
}
|
|
1350
|
-
return value;
|
|
1351
|
-
}
|
|
1352
|
-
|
|
1353
|
-
function resolveCoreFromRegistry(normalizedId) {
|
|
1354
|
-
if (
|
|
1355
|
-
normalizedId !== "@nativescript/core" &&
|
|
1356
|
-
normalizedId.indexOf("@nativescript/core/") !== 0
|
|
1357
|
-
) {
|
|
1358
|
-
return null;
|
|
1359
|
-
}
|
|
1360
|
-
const table = g.__NS_CORE_MODULES__;
|
|
1361
|
-
if (!table) return null;
|
|
1362
|
-
if (table[normalizedId]) return shapeForCjs(table[normalizedId]);
|
|
1363
|
-
const rawSub =
|
|
1364
|
-
normalizedId === "@nativescript/core"
|
|
1365
|
-
? ""
|
|
1366
|
-
: normalizedId.slice("@nativescript/core/".length);
|
|
1367
|
-
const normSub = normalizeCoreSubLocal(rawSub);
|
|
1368
|
-
const bareKey = normSub ? "@nativescript/core/" + normSub : "@nativescript/core";
|
|
1369
|
-
if (table[bareKey]) return shapeForCjs(table[bareKey]);
|
|
1370
|
-
if (normSub && table[normSub]) return shapeForCjs(table[normSub]);
|
|
1371
|
-
if (!normSub && table[""]) return shapeForCjs(table[""]);
|
|
1372
|
-
return null;
|
|
1373
|
-
}
|
|
1374
|
-
|
|
1375
|
-
export function createRequire(_url) {
|
|
1376
|
-
const nsRequire = getNativeScriptRequire();
|
|
1377
|
-
if (!nsRequire) {
|
|
1378
|
-
return function (id) {
|
|
1379
|
-
// Even without nsRequire, the @nativescript/core registry populated by
|
|
1380
|
-
// the /ns/core bridge may already have the module — return it so
|
|
1381
|
-
// vendor install() hooks that run against the HMR-served core don't
|
|
1382
|
-
// crash at module-instantiation time.
|
|
1383
|
-
const fromRegistry = resolveCoreFromRegistry(normalizeSpecifier(id));
|
|
1384
|
-
if (fromRegistry) return fromRegistry;
|
|
1385
|
-
throw new Error("NativeScript require() is not available in this context");
|
|
1386
|
-
};
|
|
1387
|
-
}
|
|
1388
|
-
const req = function (id) {
|
|
1389
|
-
const normalizedId = normalizeSpecifier(id);
|
|
1390
|
-
// Invariant C: @nativescript/core and its subpaths are served ONCE via
|
|
1391
|
-
// the /ns/core HTTP bridge, which self-registers each module's ESM
|
|
1392
|
-
// namespace on globalThis.__NS_CORE_MODULES__. CommonJS require() from
|
|
1393
|
-
// vendor packages (e.g. \`require('@nativescript/core/ui/core/view').View\`
|
|
1394
|
-
// in @nativescript-community/gesturehandler, or \`require('@nativescript/core').View\`
|
|
1395
|
-
// in @nativescript-community/ui-material-core) MUST resolve to that
|
|
1396
|
-
// same namespace; otherwise we re-trigger class identity splits and
|
|
1397
|
-
// applyMixins() crashes with "Cannot read properties of undefined".
|
|
1398
|
-
const fromRegistry = resolveCoreFromRegistry(normalizedId);
|
|
1399
|
-
if (fromRegistry) return fromRegistry;
|
|
1400
|
-
if (
|
|
1401
|
-
normalizedId.includes("../data/patch.json") ||
|
|
1402
|
-
normalizedId.includes("css-tree/lib/data/patch.json")
|
|
1403
|
-
) {
|
|
1404
|
-
return {
|
|
1405
|
-
atrules: {},
|
|
1406
|
-
properties: {},
|
|
1407
|
-
types: {},
|
|
1408
|
-
};
|
|
1409
|
-
}
|
|
1410
|
-
if (normalizedId.includes("mdn-data/")) {
|
|
1411
|
-
return {};
|
|
1412
|
-
}
|
|
1413
|
-
if (
|
|
1414
|
-
normalizedId.endsWith("/package.json") ||
|
|
1415
|
-
normalizedId.includes("../package.json")
|
|
1416
|
-
) {
|
|
1417
|
-
return { version: "0.0.0" };
|
|
1418
|
-
}
|
|
1419
|
-
if (normalizedId.endsWith(".json")) {
|
|
1420
|
-
return {};
|
|
1421
|
-
}
|
|
1422
|
-
// Shape the native require result too. The NativeScript CJS loader
|
|
1423
|
-
// may serve an @nativescript/core subpath over HTTP before the
|
|
1424
|
-
// /ns/core footer has run (e.g., during initial boot). In that
|
|
1425
|
-
// window, the result is a raw ESM namespace with null [[Prototype]]
|
|
1426
|
-
// and zone.js/vendor install() hooks crash on hasOwnProperty.
|
|
1427
|
-
return shapeForCjs(nsRequire(normalizedId));
|
|
1428
|
-
};
|
|
1429
|
-
req.resolve = nsRequire.resolve
|
|
1430
|
-
? function (id) {
|
|
1431
|
-
return nsRequire.resolve(id);
|
|
1432
|
-
}
|
|
1433
|
-
: function (id) {
|
|
1434
|
-
return id;
|
|
1435
|
-
};
|
|
1436
|
-
return req;
|
|
1437
|
-
}
|
|
1438
|
-
|
|
1439
|
-
export default { createRequire };
|
|
1440
|
-
`;
|
|
1441
617
|
function stripIndexSuffix(specifier) {
|
|
1442
618
|
return specifier.replace(/\/(?:(?:index)(?:\.[^.\/]+)?)$/, '');
|
|
1443
619
|
}
|