@nativescript/vite 8.0.0-alpha.7 → 8.0.0-alpha.70
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +51 -11
- package/bin/cli.cjs +8 -14
- package/configuration/angular.d.ts +34 -1
- package/configuration/angular.js +293 -172
- package/configuration/angular.js.map +1 -1
- package/configuration/base.js +177 -110
- 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 +12 -93
- 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.js +9 -4
- 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 +17 -0
- package/helpers/flavor.js.map +1 -1
- package/helpers/global-defines.d.ts +101 -33
- package/helpers/global-defines.js +187 -64
- package/helpers/global-defines.js.map +1 -1
- package/helpers/hmr-scope.d.ts +26 -0
- package/helpers/hmr-scope.js +67 -0
- package/helpers/hmr-scope.js.map +1 -0
- package/helpers/init.js +0 -18
- package/helpers/init.js.map +1 -1
- package/helpers/logging.js +29 -1
- package/helpers/logging.js.map +1 -1
- package/helpers/main-entry.d.ts +4 -1
- package/helpers/main-entry.js +366 -47
- 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.d.ts +9 -2
- package/helpers/nativeclass-transformer-plugin.js +163 -15
- 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/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 +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 +40 -19
- package/helpers/workers.js +324 -13
- 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 +83 -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 +282 -71
- 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/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/{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/{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 +0 -1
- package/hmr/frameworks/angular/client/index.js +459 -223
- 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 +1 -4
- 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 +677 -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 +28 -11
- package/hmr/{server → frameworks/angular/server}/websocket-angular-hot-update.js +191 -105
- 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 +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 +109 -14
- 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.js +20 -5
- 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 +164 -39
- 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 +51 -19
- package/hmr/server/import-map.js +136 -66
- 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-core-cjs-shape.js +1 -1
- package/hmr/server/ns-core-cjs-shape.js.map +1 -1
- 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 +227 -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 +38 -5
- package/hmr/server/websocket-module-bindings.js.map +1 -1
- package/hmr/server/websocket-module-specifiers.d.ts +66 -7
- package/hmr/server/websocket-module-specifiers.js +219 -49
- 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 +164 -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 +13 -2
- package/hmr/server/websocket-ns-m-request.js +20 -11
- 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 +57 -4
- package/hmr/server/websocket-served-module-helpers.js +462 -141
- 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 +653 -6734
- package/hmr/server/websocket.js.map +1 -1
- package/hmr/shared/ns-globals.d.ts +106 -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 +43 -24
- 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 -1023
- 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 +4 -6
- 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 +401 -206
- package/hmr/shared/runtime/root-placeholder.js.map +1 -1
- package/hmr/shared/runtime/session-bootstrap.js +203 -58
- package/hmr/shared/runtime/session-bootstrap.js.map +1 -1
- package/hmr/shared/runtime/vendor-bootstrap.js +3 -10
- 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/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 -7
- package/hmr/shared/vendor/manifest.js +180 -826
- 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/index.d.ts +1 -0
- package/index.js +5 -0
- package/index.js.map +1 -1
- package/package.json +65 -13
- package/runtime/core-aliases-early.js +28 -57
- 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 -194
- package/helpers/angular/angular-linker.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 +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/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 -1114
- 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}/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/hmr/{server → frameworks/angular/server}/websocket-angular-entry.d.ts +0 -0
|
@@ -1,9 +1,99 @@
|
|
|
1
1
|
import { parse as babelParse } from '@babel/parser';
|
|
2
2
|
import * as t from '@babel/types';
|
|
3
|
+
import { existsSync, readFileSync } from 'fs';
|
|
4
|
+
import * as path from 'path';
|
|
3
5
|
import * as PAT from './constants.js';
|
|
4
6
|
import { isDeepCoreSubpath } from './core-sanitize.js';
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
+
import { getCjsNamedExports } from '../helpers/cjs-named-exports.js';
|
|
8
|
+
import { getMonorepoWorkspaceRoot } from '../../helpers/project.js';
|
|
9
|
+
import { extractDirectExportedNames, parseExportSpecList } from './websocket-core-bridge.js';
|
|
10
|
+
import { resolveCandidateFilePath } from './websocket-module-specifiers.js';
|
|
11
|
+
let cachedWorkspaceCoreRoot;
|
|
12
|
+
/**
|
|
13
|
+
* Absolute root of @nativescript/core when it is consumed from monorepo
|
|
14
|
+
* source (`<workspace>/packages/core` in the NativeScript repo) rather than
|
|
15
|
+
* node_modules. Returns null for standalone apps.
|
|
16
|
+
*/
|
|
17
|
+
export function getWorkspaceCoreSourceRoot() {
|
|
18
|
+
if (cachedWorkspaceCoreRoot !== undefined)
|
|
19
|
+
return cachedWorkspaceCoreRoot;
|
|
20
|
+
cachedWorkspaceCoreRoot = null;
|
|
21
|
+
try {
|
|
22
|
+
const wsRoot = getMonorepoWorkspaceRoot();
|
|
23
|
+
if (wsRoot) {
|
|
24
|
+
const pkgPath = path.join(wsRoot, 'packages/core/package.json');
|
|
25
|
+
if (existsSync(pkgPath)) {
|
|
26
|
+
const pkg = JSON.parse(readFileSync(pkgPath, 'utf-8'));
|
|
27
|
+
if (pkg?.name === '@nativescript/core') {
|
|
28
|
+
cachedWorkspaceCoreRoot = path.resolve(wsRoot, 'packages/core').replace(/\\/g, '/');
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
catch { }
|
|
34
|
+
return cachedWorkspaceCoreRoot;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* True when a served module path points into @nativescript/core consumed from
|
|
38
|
+
* monorepo source. These modules are library code: the app-source HMR passes
|
|
39
|
+
* (AST normalization, /ns/rt underscore-helper alias injection) must NOT run
|
|
40
|
+
* on them — they exist for compiled app/SFC output, and on core sources they
|
|
41
|
+
* misread internals (e.g. `ClassInfo._getBase`) as Vue template helpers and
|
|
42
|
+
* inject destructures that shadow real bindings or TDZ-crash on the circular
|
|
43
|
+
* /ns/rt dependency. In standalone apps core lives under node_modules and is
|
|
44
|
+
* already excluded by the node_modules check.
|
|
45
|
+
*/
|
|
46
|
+
export function isWorkspaceCoreModulePath(p) {
|
|
47
|
+
if (!p)
|
|
48
|
+
return false;
|
|
49
|
+
const coreRoot = getWorkspaceCoreSourceRoot();
|
|
50
|
+
if (!coreRoot)
|
|
51
|
+
return false;
|
|
52
|
+
const normalized = String(p).split('?')[0].replace(/\\/g, '/');
|
|
53
|
+
return normalized.includes(coreRoot + '/') || /(^|\/)packages\/core\//.test(normalized);
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* True when a served module path points into the @nativescript/vite package
|
|
57
|
+
* routed via its monorepo build output (`dist/packages/vite/...`). Apps that
|
|
58
|
+
* consume the package via `file:../../dist/packages/vite` get a node_modules
|
|
59
|
+
* SYMLINK, and require.resolve follows it to the real dist path — so the
|
|
60
|
+
* served URL carries no `node_modules/` segment and escapes the node_modules
|
|
61
|
+
* library check. Like core source, this is library code: the app-source HMR
|
|
62
|
+
* passes (AST normalization, /ns/rt alias injection) must not run on it —
|
|
63
|
+
* e.g. the HMR client bundle already carries its own `__ns_rt_ns_re` import,
|
|
64
|
+
* and a second injected one is a duplicate-declaration SyntaxError on device.
|
|
65
|
+
*/
|
|
66
|
+
export function isWorkspaceVitePackageModulePath(p) {
|
|
67
|
+
if (!p)
|
|
68
|
+
return false;
|
|
69
|
+
const normalized = String(p).split('?')[0].replace(/\\/g, '/');
|
|
70
|
+
return /(^|\/)dist\/packages\/vite\//.test(normalized);
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Single classification point for the /ns/m served-module pipeline. The
|
|
74
|
+
* app-source passes inside processCodeForDevice (AST normalization, /ns/rt
|
|
75
|
+
* underscore-helper alias injection) must run ONLY on 'app' modules; 'library'
|
|
76
|
+
* code is served as-is plus import rewriting. Three things count as library:
|
|
77
|
+
* - anything under node_modules
|
|
78
|
+
* - @nativescript/core consumed from monorepo source (packages/core)
|
|
79
|
+
* - the @nativescript/vite package served from its dist build output
|
|
80
|
+
* (file:../../dist/packages/vite symlinks resolve to the real dist path,
|
|
81
|
+
* so no node_modules segment appears in the URL)
|
|
82
|
+
* Add the next workspace-library case HERE, not at a call site.
|
|
83
|
+
*/
|
|
84
|
+
export function classifyServedModule(p) {
|
|
85
|
+
if (!p)
|
|
86
|
+
return 'app';
|
|
87
|
+
const normalized = String(p).split('?')[0].replace(/\\/g, '/');
|
|
88
|
+
if (/(?:^|\/)node_modules\//.test(normalized))
|
|
89
|
+
return 'library';
|
|
90
|
+
if (isWorkspaceCoreModulePath(normalized))
|
|
91
|
+
return 'library';
|
|
92
|
+
if (isWorkspaceVitePackageModulePath(normalized))
|
|
93
|
+
return 'library';
|
|
94
|
+
return 'app';
|
|
95
|
+
}
|
|
96
|
+
export const MODULE_IMPORT_ANALYSIS_PLUGINS = ['typescript', 'jsx', 'importMeta', 'topLevelAwait', 'classProperties', 'classPrivateProperties', 'classPrivateMethods', 'decorators-legacy'];
|
|
7
97
|
export function collectTopLevelImportRecords(code) {
|
|
8
98
|
if (!code || typeof code !== 'string' || !/\bimport\b/.test(code)) {
|
|
9
99
|
return [];
|
|
@@ -63,19 +153,50 @@ export function hoistTopLevelStaticImports(code) {
|
|
|
63
153
|
}
|
|
64
154
|
return `${hoisted.join('\n')}\n${stripped.replace(/^\s*\n+/, '')}`;
|
|
65
155
|
}
|
|
156
|
+
// Boot-progress instrumentation snippet (server-side string-only).
|
|
157
|
+
//
|
|
158
|
+
// Injected at the top of every `__ns_boot__/b1`-tagged module the dev
|
|
159
|
+
// server serves during cold boot. The snippet is FULLY SYNCHRONOUS —
|
|
160
|
+
// even one conditional top-level `await` would mark the module async
|
|
161
|
+
// in V8, propagating an async-promise chain through the entire boot
|
|
162
|
+
// graph and tripping the iOS 10 s top-level-await deadline (see
|
|
163
|
+
// `ModuleInternal.mm::pumpAsyncProgress`). It just bumps the
|
|
164
|
+
// `__NS_HMR_BOOT_MODULE_COUNT__` / `__NS_HMR_BOOT_LAST_MODULE__`
|
|
165
|
+
// globals; the 250 ms heartbeat in `session-bootstrap.ts` owns
|
|
166
|
+
// `setBootStage` and runs `boot-progress.ts::computeBootImportProgress`
|
|
167
|
+
// against those counters plus elapsed wall-clock to drive the bar.
|
|
168
|
+
// The iOS runtime's `MaybePumpJSThreadDuringBoot` keeps the JS-thread
|
|
169
|
+
// CFRunLoop ticking between sync fetches so the heartbeat can fire
|
|
170
|
+
// during the otherwise-blocking cold-boot module walk.
|
|
171
|
+
//
|
|
172
|
+
// Regression-tested by `websocket-integrity.spec.ts` (snippet stays
|
|
173
|
+
// fully synchronous + propagates exactly via the boot-tag prefix).
|
|
66
174
|
export function buildBootProgressSnippet(bootModuleLabel) {
|
|
67
175
|
const normalizedLabel = JSON.stringify(String(bootModuleLabel || '').replace(/\\/g, '/'));
|
|
68
|
-
return [
|
|
69
|
-
`const __nsBootGlobal=globalThis;`,
|
|
70
|
-
`try{if(!__nsBootGlobal.__NS_HMR_BOOT_COMPLETE__){const __nsBootApi=__nsBootGlobal.__NS_HMR_DEV_OVERLAY__;if(__nsBootApi&&typeof __nsBootApi.setBootStage==='function'){const __nsBootCount=(__nsBootGlobal.__NS_HMR_BOOT_MODULE_COUNT__=Number(__nsBootGlobal.__NS_HMR_BOOT_MODULE_COUNT__||0)+1);__nsBootGlobal.__NS_HMR_BOOT_LAST_MODULE__=${normalizedLabel};const __nsBootNow=Date.now();const __nsBootLast=Number(__nsBootGlobal.__NS_HMR_BOOT_LAST_PROGRESS_AT__||0);if(__nsBootCount<=8||__nsBootCount%6===0||__nsBootNow-__nsBootLast>90){__nsBootGlobal.__NS_HMR_BOOT_LAST_PROGRESS_AT__=__nsBootNow;const __nsBootProgress=Math.min(94,82+Math.min(10,Math.round((Math.log(__nsBootCount+1)/Math.LN2)*2)));__nsBootApi.setBootStage('importing-main',{detail:'Evaluated '+__nsBootCount+' modules\\n'+__nsBootGlobal.__NS_HMR_BOOT_LAST_MODULE__,attempt:Number(__nsBootGlobal.__NS_HMR_BOOT_MAIN_ATTEMPT__||1),attempts:Number(__nsBootGlobal.__NS_HMR_BOOT_MAIN_ATTEMPTS__||6),progress:__nsBootProgress});}}}}catch(__nsBootErr){}`,
|
|
71
|
-
`if(!__nsBootGlobal.__NS_HMR_BOOT_COMPLETE__){const __nsBootCount=Number(__nsBootGlobal.__NS_HMR_BOOT_MODULE_COUNT__||0);if(__nsBootCount<=24||__nsBootCount%8===0){await new Promise((resolve)=>setTimeout(resolve,0));}}`,
|
|
72
|
-
'',
|
|
73
|
-
].join('\n');
|
|
176
|
+
return [`const __nsBootGlobal=globalThis;`, `try{if(!__nsBootGlobal.__NS_HMR_BOOT_COMPLETE__){__nsBootGlobal.__NS_HMR_BOOT_MODULE_COUNT__=Number(__nsBootGlobal.__NS_HMR_BOOT_MODULE_COUNT__||0)+1;__nsBootGlobal.__NS_HMR_BOOT_LAST_MODULE__=${normalizedLabel};}}catch(__nsBootErr){}`, ''].join('\n');
|
|
74
177
|
}
|
|
75
178
|
export function stripCoreGlobalsImports(code) {
|
|
76
179
|
const pattern = /^\s*(?:import\s+(?:[^'"\n]*from\s+)?|export\s+\*\s+from\s+)["'][^"']*(?:@nativescript(?:[/_-])core(?:[\/_-])globals|@nativescript_core_globals)[^"']*["'];?\s*$/gm;
|
|
77
180
|
return code.replace(pattern, '');
|
|
78
181
|
}
|
|
182
|
+
// The ONE device-side implementation of Vite's variable-dynamic-import
|
|
183
|
+
// helper. Injected by `ensureVariableDynamicImportHelper` and by
|
|
184
|
+
// `stripViteDynamicImportVirtual` when it removes the `/@id/__x00__vite`
|
|
185
|
+
// virtual that normally provides it — both paths must emit the same shim.
|
|
186
|
+
const VARIABLE_DYNAMIC_IMPORT_HELPER_SOURCE = `const __variableDynamicImportRuntimeHelper = (map, request, importMode) => {\n` +
|
|
187
|
+
` try { if (request === '@') { return import(new URL('/ns/m/__invalid_at__.mjs', import.meta.url).href); } } catch {}\n` +
|
|
188
|
+
` const loader = map && (map[request] || map[request?.replace(/\\\\/g, "/")]);\n` +
|
|
189
|
+
` if (!loader) {\n` +
|
|
190
|
+
` const error = new Error("Cannot dynamically import: " + request);\n` +
|
|
191
|
+
` error.code = 'ERR_MODULE_NOT_FOUND';\n` +
|
|
192
|
+
` return Promise.reject(error);\n` +
|
|
193
|
+
` }\n` +
|
|
194
|
+
` try {\n` +
|
|
195
|
+
` return loader(importMode);\n` +
|
|
196
|
+
` } catch (err) {\n` +
|
|
197
|
+
` return Promise.reject(err);\n` +
|
|
198
|
+
` }\n` +
|
|
199
|
+
`};\n`;
|
|
79
200
|
export function ensureVariableDynamicImportHelper(code) {
|
|
80
201
|
if (!code.includes('__variableDynamicImportRuntimeHelper')) {
|
|
81
202
|
return code;
|
|
@@ -83,23 +204,9 @@ export function ensureVariableDynamicImportHelper(code) {
|
|
|
83
204
|
if (PAT.VARIABLE_DYNAMIC_IMPORT_HELPER_PATTERN.test(code)) {
|
|
84
205
|
return code;
|
|
85
206
|
}
|
|
86
|
-
|
|
87
|
-
` try { if (request === '@') { return import(new URL('/ns/m/__invalid_at__.mjs', import.meta.url).href); } } catch {}\n` +
|
|
88
|
-
` const loader = map && (map[request] || map[request?.replace(/\\\\/g, "/")]);\n` +
|
|
89
|
-
` if (!loader) {\n` +
|
|
90
|
-
` const error = new Error("Cannot dynamically import: " + request);\n` +
|
|
91
|
-
` error.code = 'ERR_MODULE_NOT_FOUND';\n` +
|
|
92
|
-
` return Promise.reject(error);\n` +
|
|
93
|
-
` }\n` +
|
|
94
|
-
` try {\n` +
|
|
95
|
-
` return loader(importMode);\n` +
|
|
96
|
-
` } catch (err) {\n` +
|
|
97
|
-
` return Promise.reject(err);\n` +
|
|
98
|
-
` }\n` +
|
|
99
|
-
`};\n`;
|
|
100
|
-
return `${helper}${code}`;
|
|
207
|
+
return `${VARIABLE_DYNAMIC_IMPORT_HELPER_SOURCE}${code}`;
|
|
101
208
|
}
|
|
102
|
-
export function ensureGuardPlainDynamicImports(code
|
|
209
|
+
export function ensureGuardPlainDynamicImports(code) {
|
|
103
210
|
try {
|
|
104
211
|
if (!code || !/\bimport\s*\(/.test(code))
|
|
105
212
|
return code;
|
|
@@ -128,7 +235,7 @@ export function ensureGuardPlainDynamicImports(code, _origin) {
|
|
|
128
235
|
// * The runtime canonicalizes any URL shape (boot prefix, hmr prefix,
|
|
129
236
|
// stable) to a single key via `CanonicalizeHttpUrlKey`.
|
|
130
237
|
// * The Angular client receives an explicit eviction set in
|
|
131
|
-
// `ns:angular-update` and calls `
|
|
238
|
+
// `ns:angular-update` and calls ns:runtime `invalidateModules` before
|
|
132
239
|
// re-importing the entry, so V8 only refetches modules that
|
|
133
240
|
// actually changed.
|
|
134
241
|
// * The dynamic-import helper no longer needs to busy-construct
|
|
@@ -176,40 +283,207 @@ export function ensureDynamicHmrImportHelper(code) {
|
|
|
176
283
|
return code;
|
|
177
284
|
}
|
|
178
285
|
}
|
|
179
|
-
|
|
180
|
-
|
|
286
|
+
/**
|
|
287
|
+
* Star-export expansion must be TRANSITIVE.
|
|
288
|
+
*
|
|
289
|
+
* The expansion below replaces `export * from "url"` with an explicit named
|
|
290
|
+
* list, so any name missing from that list is silently dropped from the
|
|
291
|
+
* importer's export surface — the device then fails at link time with
|
|
292
|
+
* "does not provide an export named '<name>'". Real packages routinely chain
|
|
293
|
+
* star re-exports (`index.ios.js → export * from './canvas'` →
|
|
294
|
+
* `canvas.ios.js → export * from './canvas.common'`), so the name set for a
|
|
295
|
+
* star target is the union of its direct exports, its named re-exports, and
|
|
296
|
+
* — recursively — every nested `export * from` chain, cycles included.
|
|
297
|
+
*
|
|
298
|
+
* This mirrors `collectStaticExportOriginsFromFile` in
|
|
299
|
+
* `websocket-core-bridge.ts`, which solved the identical problem for the
|
|
300
|
+
* /ns/core bridge (see its `Application` comment). That walker reads files
|
|
301
|
+
* from disk; this one works on Vite-transformed code via the shared
|
|
302
|
+
* transformer, because star targets here are served URLs (aliases, /@fs
|
|
303
|
+
* paths, platform-extension resolution already applied by Vite's resolver).
|
|
304
|
+
* If you change export-name semantics in one walker, check the other.
|
|
305
|
+
*/
|
|
306
|
+
const STAR_EXPANSION_MAX_DEPTH = 64;
|
|
307
|
+
/**
|
|
308
|
+
* Normalize a star-export target (served URL or nested transformed
|
|
309
|
+
* specifier) into a root-relative path feedable to Vite's transform
|
|
310
|
+
* pipeline. Returns null for specifiers that cannot be walked (bare ids,
|
|
311
|
+
* relative specs with no parent context).
|
|
312
|
+
*/
|
|
313
|
+
function normalizeStarExportTargetPath(spec, parentVitePath) {
|
|
314
|
+
let p = String(spec || '').trim();
|
|
315
|
+
if (!p)
|
|
316
|
+
return null;
|
|
317
|
+
p = p.replace(/^https?:\/\/[^/]+/, '');
|
|
318
|
+
p = p.replace(/[?#].*$/, '');
|
|
319
|
+
p = p.replace(/^\/ns\/m\//, '/');
|
|
320
|
+
p = p.replace(/^\/__ns_boot__\/[^/]+/, '');
|
|
321
|
+
p = p.replace(/\/__ns_hmr__\/[^/]+/, '');
|
|
322
|
+
if (p.startsWith('.')) {
|
|
323
|
+
// Vite's import analysis normally rewrites nested specifiers to
|
|
324
|
+
// root-relative URLs; resolve any relative stragglers against the
|
|
325
|
+
// parent module's directory.
|
|
326
|
+
const parent = String(parentVitePath || '')
|
|
327
|
+
.replace(/\\/g, '/')
|
|
328
|
+
.replace(/[?#].*$/, '');
|
|
329
|
+
if (!parent.startsWith('/'))
|
|
330
|
+
return null;
|
|
331
|
+
p = path.posix.normalize(path.posix.join(path.posix.dirname(parent), p));
|
|
332
|
+
}
|
|
333
|
+
return p.startsWith('/') ? p : null;
|
|
334
|
+
}
|
|
335
|
+
// One of three deliberately-separate export scanners; each answers a
|
|
336
|
+
// different question and merging them would couple unrelated contracts:
|
|
337
|
+
// - `extractDirectExportedNames` (websocket-core-bridge.ts): direct lexical
|
|
338
|
+
// exports only — the shared primitive both other scanners build on.
|
|
339
|
+
// - `scanModuleExportSurface` (here): direct exports PLUS re-export lists
|
|
340
|
+
// and `export * from` sources, because star expansion must know both what
|
|
341
|
+
// a module claims and where the rest comes from.
|
|
342
|
+
// - `extractExportMetadata` (below): does a module have a default export
|
|
343
|
+
// and which named ones — shape-only, for SFC route metadata.
|
|
344
|
+
function scanModuleExportSurface(code) {
|
|
345
|
+
const ownNames = new Set(extractDirectExportedNames(code));
|
|
346
|
+
for (const m of code.matchAll(/\bexport\s+\*\s+as\s+([A-Za-z_$][\w$]*)\s+from\s*["'][^"']+["']/g)) {
|
|
347
|
+
ownNames.add(m[1]);
|
|
348
|
+
}
|
|
349
|
+
for (const m of code.matchAll(/\bexport\s*\{([^}]+)\}\s*from\s*["'][^"']+["']/g)) {
|
|
350
|
+
for (const { exportedName } of parseExportSpecList(m[1])) {
|
|
351
|
+
ownNames.add(exportedName);
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
const starSources = [];
|
|
355
|
+
// Tolerate trailing comments/code on the line (see the identical fix in
|
|
356
|
+
// websocket-core-bridge.ts: a strict `$` anchor silently skipped
|
|
357
|
+
// `export * from './layouts'; // barrel export` lines).
|
|
358
|
+
for (const m of code.matchAll(/^[ \t]*export\s+\*\s+from\s+["']([^"']+)["'][^\n]*$/gm)) {
|
|
359
|
+
starSources.push(m[1]);
|
|
360
|
+
}
|
|
361
|
+
return { ownNames, starSources };
|
|
362
|
+
}
|
|
363
|
+
/**
|
|
364
|
+
* Recursively collect the full export-name set of a star-export target,
|
|
365
|
+
* following nested `export * from` chains. Cycle-safe via the DFS `stack`
|
|
366
|
+
* set (a revisited module contributes nothing new at that point — its names
|
|
367
|
+
* are already being collected by the outer visit, matching spec
|
|
368
|
+
* GetExportedNames semantics). Returns null when the target itself cannot
|
|
369
|
+
* be transformed; partial failures deeper in the chain are reported through
|
|
370
|
+
* `diagnostics` while still returning every name that could be collected.
|
|
371
|
+
*/
|
|
372
|
+
async function collectStarTargetExportNames(vitePath, transformer, stack, depth, diagnostics) {
|
|
373
|
+
if (stack.has(vitePath))
|
|
374
|
+
return new Set();
|
|
375
|
+
if (depth > STAR_EXPANSION_MAX_DEPTH) {
|
|
376
|
+
diagnostics.push(`star-export chain deeper than ${STAR_EXPANSION_MAX_DEPTH} at ${vitePath}`);
|
|
377
|
+
return null;
|
|
378
|
+
}
|
|
379
|
+
let targetCode;
|
|
380
|
+
try {
|
|
381
|
+
targetCode = (await transformer(vitePath))?.code ?? undefined;
|
|
382
|
+
}
|
|
383
|
+
catch { }
|
|
384
|
+
if (!targetCode) {
|
|
385
|
+
diagnostics.push(`unresolvable star-export target ${vitePath}`);
|
|
386
|
+
return null;
|
|
387
|
+
}
|
|
388
|
+
const surface = scanModuleExportSurface(targetCode);
|
|
389
|
+
const names = new Set(surface.ownNames);
|
|
390
|
+
stack.add(vitePath);
|
|
391
|
+
try {
|
|
392
|
+
for (const spec of surface.starSources) {
|
|
393
|
+
const childPath = normalizeStarExportTargetPath(spec, vitePath);
|
|
394
|
+
if (!childPath) {
|
|
395
|
+
diagnostics.push(`unwalkable nested star-export specifier ${JSON.stringify(spec)} in ${vitePath}`);
|
|
396
|
+
continue;
|
|
397
|
+
}
|
|
398
|
+
const childNames = await collectStarTargetExportNames(childPath, transformer, stack, depth + 1, diagnostics);
|
|
399
|
+
if (!childNames)
|
|
400
|
+
continue;
|
|
401
|
+
for (const n of childNames)
|
|
402
|
+
names.add(n);
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
finally {
|
|
406
|
+
stack.delete(vitePath);
|
|
407
|
+
}
|
|
408
|
+
// `export *` never re-exports default.
|
|
409
|
+
names.delete('default');
|
|
410
|
+
return names;
|
|
181
411
|
}
|
|
182
|
-
export async function expandStarExports(code, server,
|
|
183
|
-
const STAR_RE = /^[ \t]*
|
|
412
|
+
export async function expandStarExports(code, server, projectRoot, verbose, sharedTransformer, importerId) {
|
|
413
|
+
const STAR_RE = /^[ \t]*export\s+\*\s+from\s+["']([^"']+)["'];?(?=[ \t]*(?:\/\/[^\n]*)?$)/gm;
|
|
184
414
|
let match;
|
|
185
415
|
const replacements = [];
|
|
186
416
|
while ((match = STAR_RE.exec(code)) !== null) {
|
|
187
|
-
const url = match[
|
|
417
|
+
const url = match[1];
|
|
188
418
|
if (!url.includes('/node_modules/'))
|
|
189
419
|
continue;
|
|
190
|
-
replacements.push({ full: match[0], url
|
|
420
|
+
replacements.push({ full: match[0], url });
|
|
191
421
|
}
|
|
192
422
|
if (!replacements.length)
|
|
193
423
|
return code;
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
424
|
+
// Names already exported lexically by the importing module. Per spec,
|
|
425
|
+
// lexical exports shadow star-exported names — re-emitting them in an
|
|
426
|
+
// explicit list would be a duplicate-export SyntaxError on device.
|
|
427
|
+
const claimed = new Set(scanModuleExportSurface(code).ownNames);
|
|
428
|
+
// Resolve each star-export target in parallel through the shared runner
|
|
429
|
+
// (when provided) so they share the /ns/m TTL cache and concurrency gate.
|
|
430
|
+
const baseTransformer = sharedTransformer ?? ((url) => server.transformRequest(url));
|
|
431
|
+
// A bare `/node_modules/<pkg>/...` URL is NOT transformable on its own:
|
|
432
|
+
// Vite's bare-specifier resolver is gated by the package's
|
|
433
|
+
// `package.json#exports` and refuses internal sub-paths even when the file
|
|
434
|
+
// is on disk (e.g. `css-tree/lib/version.js`, `css-what/dist/esm/types.js`),
|
|
435
|
+
// and in a monorepo the package is hoisted ABOVE the app's `root` so the
|
|
436
|
+
// path doesn't exist relative to it at all. Either way the transform
|
|
437
|
+
// returns nothing and the star target is mis-reported as "unresolvable",
|
|
438
|
+
// silently dropping its names from the importer's export surface. Mirror the
|
|
439
|
+
// main /ns/m route (`filterExistingNodeModulesTransformCandidates`): resolve
|
|
440
|
+
// the path to a concrete file under the project or workspace root and feed
|
|
441
|
+
// the `/@fs/<abs>` form to Vite, which bypasses the `exports` gate. Falls
|
|
442
|
+
// back to the raw URL for anything that doesn't resolve to a real file.
|
|
443
|
+
const workspaceRoot = projectRoot ? getMonorepoWorkspaceRoot(projectRoot) : null;
|
|
444
|
+
const transformer = (url) => {
|
|
445
|
+
if (projectRoot && url.includes('/node_modules/')) {
|
|
446
|
+
const abs = resolveCandidateFilePath(url, projectRoot, workspaceRoot);
|
|
447
|
+
if (abs) {
|
|
448
|
+
// Posix-normalize and guarantee a leading slash so Windows drive
|
|
449
|
+
// letters produce the `/@fs/C:/...` form Vite expects.
|
|
450
|
+
const absPosix = abs.replace(/\\/g, '/');
|
|
451
|
+
return baseTransformer(`/@fs${absPosix.startsWith('/') ? '' : '/'}${absPosix}`);
|
|
210
452
|
}
|
|
211
453
|
}
|
|
212
|
-
|
|
454
|
+
return baseTransformer(url);
|
|
455
|
+
};
|
|
456
|
+
const resolved = await Promise.all(replacements.map(async (rep) => {
|
|
457
|
+
const diagnostics = [];
|
|
458
|
+
const vitePath = normalizeStarExportTargetPath(rep.url, null);
|
|
459
|
+
if (!vitePath) {
|
|
460
|
+
diagnostics.push(`unwalkable star-export URL ${rep.url}`);
|
|
461
|
+
return { rep, names: null, diagnostics };
|
|
462
|
+
}
|
|
463
|
+
const names = await collectStarTargetExportNames(vitePath, transformer, new Set(), 0, diagnostics);
|
|
464
|
+
if (verbose && names) {
|
|
465
|
+
console.log(`[ns/m] expanded export* -> ${names.size} names from ${vitePath}${diagnostics.length ? ' (partial)' : ''}`);
|
|
466
|
+
}
|
|
467
|
+
return { rep, names, diagnostics };
|
|
468
|
+
}));
|
|
469
|
+
for (const entry of resolved) {
|
|
470
|
+
if (entry.diagnostics.length) {
|
|
471
|
+
// Always-on: an incomplete expansion silently narrows the importer's
|
|
472
|
+
// export surface, which surfaces on device as a link-time
|
|
473
|
+
// "does not provide an export named ..." with no server-side trace.
|
|
474
|
+
console.warn(`[ns/m][export*] incomplete star-export expansion${importerId ? ` in ${importerId}` : ''} for ${entry.rep.url}: ${entry.diagnostics.join('; ')}`);
|
|
475
|
+
}
|
|
476
|
+
if (!entry.names)
|
|
477
|
+
continue;
|
|
478
|
+
// First star wins for names provided by multiple siblings; duplicates
|
|
479
|
+
// would be a SyntaxError, and spec-ambiguous names have no good answer.
|
|
480
|
+
const emit = Array.from(entry.names).filter((n) => !claimed.has(n));
|
|
481
|
+
for (const n of emit)
|
|
482
|
+
claimed.add(n);
|
|
483
|
+
// An empty list still keeps the dependency edge (side effects,
|
|
484
|
+
// evaluation order) via a side-effect import.
|
|
485
|
+
const explicit = emit.length ? `export { ${emit.join(', ')} } from ${JSON.stringify(entry.rep.url)};` : `import ${JSON.stringify(entry.rep.url)};`;
|
|
486
|
+
code = code.replace(entry.rep.full, explicit);
|
|
213
487
|
}
|
|
214
488
|
return code;
|
|
215
489
|
}
|
|
@@ -232,11 +506,17 @@ export function repairImportEqualsAssignments(code) {
|
|
|
232
506
|
catch { }
|
|
233
507
|
return code;
|
|
234
508
|
}
|
|
235
|
-
|
|
236
|
-
|
|
509
|
+
// Canonicalize `/ns/rt` imports: collapse any versioned form
|
|
510
|
+
// (`/ns/rt/<n>`, `/@ns/rt/<n>`) to the single unversioned `/ns/rt` URL.
|
|
511
|
+
// One canonical URL per bridge module — the runtime treats the literal
|
|
512
|
+
// URL as module identity, so emitting `/ns/rt/<ver>` would mint a new
|
|
513
|
+
// module realm per graph version. (The GET route still ACCEPTS the
|
|
514
|
+
// versioned form for stale in-flight code; see ns-rt-route.ts.)
|
|
515
|
+
export function canonicalizeRtImports(code, origin) {
|
|
516
|
+
if (!code || !origin)
|
|
237
517
|
return code;
|
|
238
|
-
code = code.replace(/(from\s+["'])(?:https?:\/\/[^"']+)?\/(?:\@ns|ns)\/rt(?:\/[\d]+)?(["'])/g, (_m, p1, p3) => `${p1}/ns/rt
|
|
239
|
-
code = code.replace(/(import\(\s*["'])(?:https?:\/\/[^"']+)?\/(?:\@ns|ns)\/rt(?:\/[\d]+)?(["']\s*\))/g, (_m, p1, p3) => `${p1}/ns/rt
|
|
518
|
+
code = code.replace(/(from\s+["'])(?:https?:\/\/[^"']+)?\/(?:\@ns|ns)\/rt(?:\/[\d]+)?(["'])/g, (_m, p1, p3) => `${p1}/ns/rt${p3}`);
|
|
519
|
+
code = code.replace(/(import\(\s*["'])(?:https?:\/\/[^"']+)?\/(?:\@ns|ns)\/rt(?:\/[\d]+)?(["']\s*\))/g, (_m, p1, p3) => `${p1}/ns/rt${p3}`);
|
|
240
520
|
return code;
|
|
241
521
|
}
|
|
242
522
|
export function stripViteDynamicImportVirtual(code) {
|
|
@@ -244,19 +524,27 @@ export function stripViteDynamicImportVirtual(code) {
|
|
|
244
524
|
return code;
|
|
245
525
|
}
|
|
246
526
|
const original = code;
|
|
247
|
-
|
|
527
|
+
// Statement-scoped, NOT line-anchored: Vite 8 emits its injected imports
|
|
528
|
+
// concatenated on ONE line with the module's original first line, e.g.
|
|
529
|
+
// import …"/@vite/client";import …"/@id/__x00__vite/dynamic-import-helper.js";/**
|
|
530
|
+
// A `^…$`-anchored replace would delete the whole line — including the
|
|
531
|
+
// module's leading `/**`, leaving an orphaned JSDoc body that is a
|
|
532
|
+
// SyntaxError ("Unexpected token '*'") on device.
|
|
533
|
+
code = code.replace(/import\s+[^;'"\n]*['"][^'"\n]*\/@id\/__x00__vite\/dynamic-import-helper[^'"\n]*['"]\s*;?/g, '');
|
|
248
534
|
if (/\/@id\/__x00__vite\/dynamic-import-helper/.test(code)) {
|
|
249
535
|
code = code.replace(/\/@id\/__x00__vite\/dynamic-import-helper[^"'`)]*/g, '/__NS_UNUSED_DYNAMIC_IMPORT_HELPER__');
|
|
250
536
|
}
|
|
251
537
|
if (!/__variableDynamicImportRuntimeHelper/.test(code)) {
|
|
252
|
-
|
|
253
|
-
code = inline + code;
|
|
538
|
+
code = VARIABLE_DYNAMIC_IMPORT_HELPER_SOURCE + code;
|
|
254
539
|
}
|
|
255
540
|
if (code !== original) {
|
|
256
541
|
code = `// [hmr-sanitize] removed virtual dynamic-import-helper\n${code}`;
|
|
257
542
|
}
|
|
258
543
|
return code;
|
|
259
544
|
}
|
|
545
|
+
// Shape-only scanner (see the scanner taxonomy above scanModuleExportSurface):
|
|
546
|
+
// answers "does this module export a default, and which named exports?" for
|
|
547
|
+
// the Vue SFC route metadata. It intentionally ignores re-export sources.
|
|
260
548
|
export function extractExportMetadata(code) {
|
|
261
549
|
const named = new Set();
|
|
262
550
|
let hasDefault = /\bexport\s+default\b/.test(code);
|
|
@@ -288,76 +576,106 @@ export function extractExportMetadata(code) {
|
|
|
288
576
|
named.delete('default');
|
|
289
577
|
return { hasDefault, named: Array.from(named) };
|
|
290
578
|
}
|
|
579
|
+
/**
|
|
580
|
+
* Defensive export normalization for route-config modules: if a served module
|
|
581
|
+
* defines `routes` and only exports it named, append a default-export alias so
|
|
582
|
+
* both `import { routes }` and `import routes` resolve. Backing implementation
|
|
583
|
+
* for `FrameworkServerStrategy.normalizeServedExports` (Vue/Solid/TS).
|
|
584
|
+
*/
|
|
585
|
+
export function ensureRoutesDefaultExport(code) {
|
|
586
|
+
if (/\bexport\s+default\b/.test(code))
|
|
587
|
+
return code;
|
|
588
|
+
const hasNamedRoutes = /\bexport\s*\{\s*routes\s*\}/.test(code);
|
|
589
|
+
const hasConstRoutes = /\bconst\s+routes\s*=/.test(code) || /\bvar\s+routes\s*=/.test(code) || /\blet\s+routes\s*=/.test(code);
|
|
590
|
+
if (hasNamedRoutes && hasConstRoutes) {
|
|
591
|
+
return code + `\nexport default routes;\n`;
|
|
592
|
+
}
|
|
593
|
+
return code;
|
|
594
|
+
}
|
|
291
595
|
function shouldAllowLocalCoreSanitizerPaths(contextLabel) {
|
|
292
|
-
|
|
596
|
+
// The @nativescript/vite HMR runtime (client + framework strategies)
|
|
597
|
+
// legitimately references local core paths in strings — allow it whether it
|
|
598
|
+
// is served from node_modules or from the monorepo dist output
|
|
599
|
+
// (`file:../../dist/packages/vite` symlinks resolve to the real dist path,
|
|
600
|
+
// so no node_modules segment appears in the served URL).
|
|
601
|
+
return /\b(?:node_modules\/@nativescript\/vite|dist\/packages\/vite)\/hmr\/(?:client|frameworks)\//.test(contextLabel);
|
|
293
602
|
}
|
|
294
603
|
export function assertNoOptimizedArtifacts(code, contextLabel) {
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
offenders.push(`${i + 1}: ${line.substring(0, 200)}`);
|
|
305
|
-
break;
|
|
306
|
-
}
|
|
307
|
-
}
|
|
308
|
-
if (localCore.test(line)) {
|
|
309
|
-
const trimmed = line.trimStart();
|
|
310
|
-
if (trimmed.startsWith('//') || trimmed.startsWith('/*') || trimmed.startsWith('*')) {
|
|
311
|
-
continue;
|
|
312
|
-
}
|
|
313
|
-
if (shouldAllowLocalCoreSanitizerPaths(contextLabel)) {
|
|
314
|
-
continue;
|
|
315
|
-
}
|
|
316
|
-
offenders.push(`${i + 1}: ${line.substring(0, 200)} [local-core-path]`);
|
|
317
|
-
}
|
|
318
|
-
if (offenders.length >= 10)
|
|
604
|
+
const offenders = [];
|
|
605
|
+
const lines = code.split('\n');
|
|
606
|
+
const tests = [/\b__VITE_PLUGIN__\b/, /\b__VITE_PRELOAD__\b/];
|
|
607
|
+
const localCore = /(^|[^\w@])(?:\.\.?\/|\/)??@nativescript[\/_-]core\//i;
|
|
608
|
+
for (let i = 0; i < lines.length; i++) {
|
|
609
|
+
const line = lines[i];
|
|
610
|
+
for (const re of tests) {
|
|
611
|
+
if (re.test(line)) {
|
|
612
|
+
offenders.push(`${i + 1}: ${line.substring(0, 200)}`);
|
|
319
613
|
break;
|
|
614
|
+
}
|
|
320
615
|
}
|
|
321
|
-
if (
|
|
322
|
-
const
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
616
|
+
if (localCore.test(line)) {
|
|
617
|
+
const trimmed = line.trimStart();
|
|
618
|
+
if (trimmed.startsWith('//') || trimmed.startsWith('/*') || trimmed.startsWith('*')) {
|
|
619
|
+
continue;
|
|
620
|
+
}
|
|
621
|
+
if (shouldAllowLocalCoreSanitizerPaths(contextLabel)) {
|
|
622
|
+
continue;
|
|
623
|
+
}
|
|
624
|
+
// Only module-resolution contexts (import/export/require) leak to the
|
|
625
|
+
// device ESM loader. A core path appearing as plain runtime string data
|
|
626
|
+
// — e.g. component-builder's `const CORE_UI_BARREL = '@nativescript/core/ui'`
|
|
627
|
+
// passed to `global.loadModule()`, which reads the bundler module
|
|
628
|
+
// registry, not the ESM loader — is legitimate and must not fail serving.
|
|
629
|
+
if (!/(?:\bimport\b|\bexport\b|\bfrom\s*["']|\brequire\s*\()/.test(line)) {
|
|
630
|
+
continue;
|
|
631
|
+
}
|
|
632
|
+
offenders.push(`${i + 1}: ${line.substring(0, 200)} [local-core-path]`);
|
|
327
633
|
}
|
|
328
|
-
|
|
329
|
-
|
|
634
|
+
if (offenders.length >= 10)
|
|
635
|
+
break;
|
|
636
|
+
}
|
|
637
|
+
if (offenders.length) {
|
|
638
|
+
const msg = `[sanitize-fail] Optimized deps/virtual id artifacts detected in ${contextLabel}. These cannot be evaluated by the device HTTP ESM loader. Offending lines (first ${Math.min(5, offenders.length)} shown):\n` + offenders.slice(0, 5).join('\n');
|
|
639
|
+
const error = new Error(msg);
|
|
640
|
+
error.code = 'NS_SANITIZE_FAIL';
|
|
641
|
+
error.offenders = offenders;
|
|
330
642
|
throw error;
|
|
331
643
|
}
|
|
332
644
|
}
|
|
333
|
-
|
|
645
|
+
/** Convert an import spec list (`A, B as C`) into a destructure pattern (`A, B: C`). */
|
|
646
|
+
function toDestructurePattern(specList) {
|
|
647
|
+
return specList
|
|
648
|
+
.split(',')
|
|
649
|
+
.map((s) => s.trim())
|
|
650
|
+
.filter(Boolean)
|
|
651
|
+
.map((seg) => {
|
|
652
|
+
const match = seg.split(/\s+as\s+/i);
|
|
653
|
+
return match.length === 2 ? `${match[0].trim()}: ${match[1].trim()}` : seg;
|
|
654
|
+
})
|
|
655
|
+
.join(', ');
|
|
656
|
+
}
|
|
657
|
+
// Rewrite named imports from a bridge URL (`/ns/core`, `/ns/rt`) into a
|
|
658
|
+
// default import plus `const {}` destructure. The bridge modules export a
|
|
659
|
+
// default namespace object, so a named import that survives to the device
|
|
660
|
+
// fails at link time ("does not provide an export named ...").
|
|
661
|
+
function destructureBridgeImports(code, opts) {
|
|
334
662
|
try {
|
|
335
663
|
let result = code;
|
|
336
|
-
let
|
|
337
|
-
const
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
.
|
|
341
|
-
|
|
342
|
-
const
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
.join(', ');
|
|
346
|
-
const reNamed = /(^|\n)\s*import\s*\{([^}]+)\}\s*from\s*["']((?:https?:\/\/[^"']+)?\/ns\/core(?:\/[\d]+)?(?:\?p=[^"']+)?)['"];?\s*/gm;
|
|
347
|
-
result = result.replace(reNamed, (_full, prefix, specList, src) => {
|
|
348
|
-
if (isDeepCoreSubpath(src))
|
|
349
|
-
return _full;
|
|
350
|
-
const tempName = `__ns_core_ns_re${coreImportCounter > 0 ? `_${coreImportCounter}` : ''}`;
|
|
351
|
-
coreImportCounter++;
|
|
352
|
-
const decl = `const { ${toDestructure(specList)} } = ${tempName};`;
|
|
353
|
-
return `${prefix}import ${tempName} from ${JSON.stringify(src)};\n${decl}\n`;
|
|
664
|
+
let counter = 0;
|
|
665
|
+
const srcPattern = `((?:https?:\\/\\/[^"']+)?${opts.pathPattern})`;
|
|
666
|
+
const reNamed = new RegExp(`(^|\\n)\\s*import\\s*\\{([^}]+)\\}\\s*from\\s*["']${srcPattern}['"];?\\s*`, 'gm');
|
|
667
|
+
result = result.replace(reNamed, (full, prefix, specList, src) => {
|
|
668
|
+
if (opts.shouldSkip?.(src))
|
|
669
|
+
return full;
|
|
670
|
+
const tempName = opts.numberRepeats && counter > 0 ? `${opts.tempName}_${counter}` : opts.tempName;
|
|
671
|
+
counter++;
|
|
672
|
+
return `${prefix}import ${tempName} from ${JSON.stringify(src)};\nconst { ${toDestructurePattern(specList)} } = ${tempName};\n`;
|
|
354
673
|
});
|
|
355
|
-
const reMixed =
|
|
356
|
-
result = result.replace(reMixed, (
|
|
357
|
-
if (
|
|
358
|
-
return
|
|
359
|
-
|
|
360
|
-
return `${prefix}import ${defName} from ${JSON.stringify(src)};\n${decl}\n`;
|
|
674
|
+
const reMixed = new RegExp(`(^|\\n)\\s*import\\s+([A-Za-z_$][\\w$]*)\\s*,\\s*\\{([^}]+)\\}\\s*from\\s*["']${srcPattern}['"];?\\s*`, 'gm');
|
|
675
|
+
result = result.replace(reMixed, (full, prefix, defName, specList, src) => {
|
|
676
|
+
if (opts.shouldSkip?.(src))
|
|
677
|
+
return full;
|
|
678
|
+
return `${prefix}import ${defName} from ${JSON.stringify(src)};\nconst { ${toDestructurePattern(specList)} } = ${defName};\n`;
|
|
361
679
|
});
|
|
362
680
|
return result;
|
|
363
681
|
}
|
|
@@ -365,34 +683,21 @@ export function ensureDestructureCoreImports(code) {
|
|
|
365
683
|
return code;
|
|
366
684
|
}
|
|
367
685
|
}
|
|
686
|
+
export function ensureDestructureCoreImports(code) {
|
|
687
|
+
return destructureBridgeImports(code, {
|
|
688
|
+
pathPattern: String.raw `\/ns\/core(?:\/[^"']+)?`,
|
|
689
|
+
tempName: '__ns_core_ns_re',
|
|
690
|
+
numberRepeats: true,
|
|
691
|
+
// Deep core subpaths keep their named-import form (see core-sanitize.ts).
|
|
692
|
+
shouldSkip: isDeepCoreSubpath,
|
|
693
|
+
});
|
|
694
|
+
}
|
|
368
695
|
export function ensureDestructureRtImports(code) {
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
.filter(Boolean)
|
|
375
|
-
.map((seg) => {
|
|
376
|
-
const match = seg.split(/\s+as\s+/i);
|
|
377
|
-
return match.length === 2 ? `${match[0].trim()}: ${match[1].trim()}` : seg;
|
|
378
|
-
})
|
|
379
|
-
.join(', ');
|
|
380
|
-
const reNamed = /(^|\n)\s*import\s*\{([^}]+)\}\s*from\s*["']((?:https?:\/\/[^"']+)?\/ns\/rt(?:\/[\d]+)?)['"];?\s*/gm;
|
|
381
|
-
result = result.replace(reNamed, (_full, prefix, specList, src) => {
|
|
382
|
-
const tempName = `__ns_rt_ns_re`;
|
|
383
|
-
const decl = `const { ${toDestructure(specList)} } = ${tempName};`;
|
|
384
|
-
return `${prefix}import ${tempName} from ${JSON.stringify(src)};\n${decl}\n`;
|
|
385
|
-
});
|
|
386
|
-
const reMixed = /(^|\n)\s*import\s+([A-Za-z_$][\w$]*)\s*,\s*\{([^}]+)\}\s*from\s*["']((?:https?:\/\/[^"']+)?\/ns\/rt(?:\/[\d]+)?)['"];?\s*/gm;
|
|
387
|
-
result = result.replace(reMixed, (_full, prefix, defName, specList, src) => {
|
|
388
|
-
const decl = `const { ${toDestructure(specList)} } = ${defName};`;
|
|
389
|
-
return `${prefix}import ${defName} from ${JSON.stringify(src)};\n${decl}\n`;
|
|
390
|
-
});
|
|
391
|
-
return result;
|
|
392
|
-
}
|
|
393
|
-
catch {
|
|
394
|
-
return code;
|
|
395
|
-
}
|
|
696
|
+
return destructureBridgeImports(code, {
|
|
697
|
+
pathPattern: String.raw `\/ns\/rt(?:\/[\d]+)?`,
|
|
698
|
+
tempName: '__ns_rt_ns_re',
|
|
699
|
+
numberRepeats: false,
|
|
700
|
+
});
|
|
396
701
|
}
|
|
397
702
|
export function dedupeRtNamedImportsAgainstDestructures(code) {
|
|
398
703
|
try {
|
|
@@ -537,7 +842,7 @@ export function deduplicateLinkerImports(code) {
|
|
|
537
842
|
return code;
|
|
538
843
|
}
|
|
539
844
|
}
|
|
540
|
-
export function wrapCommonJsModuleForDevice(code) {
|
|
845
|
+
export function wrapCommonJsModuleForDevice(code, absolutePath) {
|
|
541
846
|
if (!code)
|
|
542
847
|
return code;
|
|
543
848
|
try {
|
|
@@ -563,6 +868,22 @@ export function wrapCommonJsModuleForDevice(code) {
|
|
|
563
868
|
namedExports.add(name);
|
|
564
869
|
}
|
|
565
870
|
}
|
|
871
|
+
// Static enumeration only sees `exports.foo = ...` and `Object.defineProperty(exports, 'foo', ...)`.
|
|
872
|
+
// Real-world packages like lodash attach their entire surface to a function inside an IIFE and
|
|
873
|
+
// then `module.exports = thatFunction`. Static analysis returns zero in that case. To handle
|
|
874
|
+
// these modules we ALSO load the package in the dev-server's Node context (only when we have a
|
|
875
|
+
// node_modules path) and merge the runtime keys. See `helpers/cjs-named-exports.ts` for the
|
|
876
|
+
// reasoning and safety boundaries.
|
|
877
|
+
if (absolutePath) {
|
|
878
|
+
try {
|
|
879
|
+
for (const n of getCjsNamedExports(absolutePath)) {
|
|
880
|
+
namedExports.add(n);
|
|
881
|
+
}
|
|
882
|
+
}
|
|
883
|
+
catch {
|
|
884
|
+
/* fall through to whatever we caught statically */
|
|
885
|
+
}
|
|
886
|
+
}
|
|
566
887
|
let suffix = `\nvar __cjs_mod = module.exports;\nexport default __cjs_mod;\n`;
|
|
567
888
|
if (namedExports.size) {
|
|
568
889
|
const entries = Array.from(namedExports);
|