@nativescript/vite 8.0.0-beta.0 → 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 +35 -2
- package/configuration/angular.js +541 -216
- package/configuration/angular.js.map +1 -1
- package/configuration/base.js +227 -77
- package/configuration/base.js.map +1 -1
- package/configuration/javascript.js +17 -96
- package/configuration/javascript.js.map +1 -1
- package/configuration/react.js +41 -73
- package/configuration/react.js.map +1 -1
- package/configuration/solid.js +58 -6
- package/configuration/solid.js.map +1 -1
- package/configuration/typescript.js +15 -96
- package/configuration/typescript.js.map +1 -1
- package/helpers/app-components.d.ts +2 -1
- package/helpers/app-components.js.map +1 -1
- package/helpers/app-css-refresh.d.ts +31 -0
- package/helpers/app-css-refresh.js +43 -0
- package/helpers/app-css-refresh.js.map +1 -0
- package/helpers/app-css-state.d.ts +17 -0
- package/helpers/app-css-state.js +51 -0
- package/helpers/app-css-state.js.map +1 -0
- package/helpers/bundler-context.d.ts +11 -0
- package/helpers/bundler-context.js +71 -0
- package/helpers/bundler-context.js.map +1 -0
- package/helpers/cli-flags.d.ts +12 -0
- package/helpers/cli-flags.js +34 -0
- package/helpers/cli-flags.js.map +1 -1
- package/helpers/commonjs-plugins.d.ts +5 -2
- package/helpers/commonjs-plugins.js +126 -0
- package/helpers/commonjs-plugins.js.map +1 -1
- package/helpers/config-as-json.js +10 -0
- package/helpers/config-as-json.js.map +1 -1
- package/helpers/css-platform-plugin.d.ts +14 -0
- package/helpers/css-platform-plugin.js +43 -25
- package/helpers/css-platform-plugin.js.map +1 -1
- package/helpers/dev-host.d.ts +360 -0
- package/helpers/dev-host.js +694 -0
- package/helpers/dev-host.js.map +1 -0
- package/helpers/dynamic-import-plugin.d.ts +2 -1
- package/helpers/dynamic-import-plugin.js +59 -53
- package/helpers/dynamic-import-plugin.js.map +1 -1
- package/helpers/esbuild-platform-resolver.js +9 -6
- package/helpers/esbuild-platform-resolver.js.map +1 -1
- package/helpers/external-configs.d.ts +10 -4
- package/helpers/external-configs.js +63 -15
- package/helpers/external-configs.js.map +1 -1
- package/helpers/flavor.d.ts +13 -0
- package/helpers/flavor.js +18 -1
- package/helpers/flavor.js.map +1 -1
- package/helpers/global-defines.d.ts +117 -0
- package/helpers/global-defines.js +209 -11
- package/helpers/global-defines.js.map +1 -1
- package/helpers/hmr-scope.d.ts +26 -0
- package/helpers/hmr-scope.js +67 -0
- package/helpers/hmr-scope.js.map +1 -0
- package/helpers/import-meta-path.d.ts +4 -0
- package/helpers/import-meta-path.js +5 -0
- package/helpers/import-meta-path.js.map +1 -0
- package/helpers/import-specifier.d.ts +1 -0
- package/helpers/import-specifier.js +18 -0
- package/helpers/import-specifier.js.map +1 -0
- package/helpers/init.js +6 -20
- package/helpers/init.js.map +1 -1
- package/helpers/logging.d.ts +1 -0
- package/helpers/logging.js +65 -4
- package/helpers/logging.js.map +1 -1
- package/helpers/main-entry.d.ts +8 -2
- package/helpers/main-entry.js +622 -120
- package/helpers/main-entry.js.map +1 -1
- package/helpers/nativeclass-esbuild-plugin.d.ts +2 -1
- package/helpers/nativeclass-esbuild-plugin.js +6 -1
- package/helpers/nativeclass-esbuild-plugin.js.map +1 -1
- package/helpers/nativeclass-transform.d.ts +13 -0
- package/helpers/nativeclass-transform.js +42 -131
- package/helpers/nativeclass-transform.js.map +1 -1
- package/helpers/nativeclass-transformer-plugin.d.ts +19 -1
- package/helpers/nativeclass-transformer-plugin.js +324 -37
- package/helpers/nativeclass-transformer-plugin.js.map +1 -1
- package/helpers/nativescript-package-resolver.js +10 -62
- package/helpers/nativescript-package-resolver.js.map +1 -1
- package/helpers/normalize-id.d.ts +42 -0
- package/helpers/normalize-id.js +60 -0
- package/helpers/normalize-id.js.map +1 -0
- package/helpers/ns-core-external-urls.d.ts +32 -0
- package/helpers/ns-core-external-urls.js +107 -0
- package/helpers/ns-core-external-urls.js.map +1 -0
- package/helpers/ns-core-url.d.ts +106 -0
- package/helpers/ns-core-url.js +225 -0
- package/helpers/ns-core-url.js.map +1 -0
- package/helpers/optimize-deps.d.ts +16 -0
- package/helpers/optimize-deps.js +17 -0
- package/helpers/optimize-deps.js.map +1 -0
- package/helpers/package-platform-aliases.js +34 -49
- package/helpers/package-platform-aliases.js.map +1 -1
- package/helpers/platform-types.d.ts +2 -0
- package/helpers/platform-types.js +2 -0
- package/helpers/platform-types.js.map +1 -0
- package/helpers/postcss-platform-config.d.ts +17 -1
- package/helpers/postcss-platform-config.js +20 -37
- package/helpers/postcss-platform-config.js.map +1 -1
- package/helpers/project.d.ts +35 -0
- package/helpers/project.js +120 -2
- package/helpers/project.js.map +1 -1
- package/helpers/resolve-main-field-platform.d.ts +20 -0
- package/helpers/resolve-main-field-platform.js +49 -0
- package/helpers/resolve-main-field-platform.js.map +1 -0
- package/helpers/resolver.js +17 -2
- package/helpers/resolver.js.map +1 -1
- package/helpers/theme-core-plugins.js +1 -1
- package/helpers/theme-core-plugins.js.map +1 -1
- package/helpers/ts-config-paths.d.ts +32 -0
- package/helpers/ts-config-paths.js +156 -27
- package/helpers/ts-config-paths.js.map +1 -1
- package/helpers/typescript-check.d.ts +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 +312 -13
- package/helpers/workers.js.map +1 -1
- package/hmr/client/css-handler.d.ts +2 -1
- package/hmr/client/css-handler.js +95 -23
- package/hmr/client/css-handler.js.map +1 -1
- package/hmr/client/css-update-overlay.d.ts +18 -0
- package/hmr/client/css-update-overlay.js +27 -0
- package/hmr/client/css-update-overlay.js.map +1 -0
- package/hmr/client/framework-client-strategy.d.ts +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 +13 -0
- package/hmr/client/hmr-pending-overlay.js +41 -0
- package/hmr/client/hmr-pending-overlay.js.map +1 -0
- package/hmr/client/hot-context.d.ts +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 +91 -1418
- package/hmr/client/index.js.map +1 -1
- package/hmr/client/overlay-driver.d.ts +10 -0
- package/hmr/client/overlay-driver.js +33 -0
- package/hmr/client/overlay-driver.js.map +1 -0
- package/hmr/client/protocol-dispatch.d.ts +8 -0
- package/hmr/client/protocol-dispatch.js +308 -0
- package/hmr/client/protocol-dispatch.js.map +1 -0
- package/hmr/client/root-reset.d.ts +15 -0
- package/hmr/client/root-reset.js +358 -0
- package/hmr/client/root-reset.js.map +1 -0
- package/hmr/client/strategy-loader.d.ts +24 -0
- package/hmr/client/strategy-loader.js +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 +14 -1
- package/hmr/client/utils.js +265 -54
- package/hmr/client/utils.js.map +1 -1
- package/hmr/client/ws-transport.d.ts +21 -0
- package/hmr/client/ws-transport.js +323 -0
- package/hmr/client/ws-transport.js.map +1 -0
- package/hmr/entry-runtime.d.ts +11 -0
- package/hmr/entry-runtime.js +566 -43
- package/hmr/entry-runtime.js.map +1 -1
- package/hmr/frameworks/angular/build/angular-linker.d.ts +12 -0
- package/hmr/frameworks/angular/build/angular-linker.js +113 -0
- package/hmr/frameworks/angular/build/angular-linker.js.map +1 -0
- package/hmr/frameworks/angular/build/inject-component-hmr-registration.d.ts +112 -0
- package/hmr/frameworks/angular/build/inject-component-hmr-registration.js +291 -0
- package/hmr/frameworks/angular/build/inject-component-hmr-registration.js.map +1 -0
- package/hmr/frameworks/angular/build/inject-hmr-vite-ignore.d.ts +75 -0
- package/hmr/frameworks/angular/build/inject-hmr-vite-ignore.js +221 -0
- package/hmr/frameworks/angular/build/inject-hmr-vite-ignore.js.map +1 -0
- package/hmr/frameworks/angular/build/inline-decorator-component-templates.d.ts +3 -0
- package/hmr/frameworks/angular/build/inline-decorator-component-templates.js +231 -0
- package/hmr/frameworks/angular/build/inline-decorator-component-templates.js.map +1 -0
- package/hmr/frameworks/angular/build/js-lexer.d.ts +4 -0
- package/hmr/frameworks/angular/build/js-lexer.js +182 -0
- package/hmr/frameworks/angular/build/js-lexer.js.map +1 -0
- package/hmr/frameworks/angular/build/linker-stats.d.ts +18 -0
- package/hmr/frameworks/angular/build/linker-stats.js +29 -0
- package/hmr/frameworks/angular/build/linker-stats.js.map +1 -0
- package/hmr/frameworks/angular/build/shared-linker.d.ts +39 -0
- package/hmr/frameworks/angular/build/shared-linker.js +128 -0
- package/hmr/frameworks/angular/build/shared-linker.js.map +1 -0
- package/hmr/frameworks/angular/build/synthesize-decorator-ctor-parameters.d.ts +1 -0
- package/hmr/frameworks/angular/build/synthesize-decorator-ctor-parameters.js +88 -0
- package/hmr/frameworks/angular/build/synthesize-decorator-ctor-parameters.js.map +1 -0
- package/hmr/frameworks/angular/build/synthesize-injectable-factories.d.ts +3 -0
- package/hmr/frameworks/angular/build/synthesize-injectable-factories.js +241 -0
- package/hmr/frameworks/angular/build/synthesize-injectable-factories.js.map +1 -0
- package/hmr/frameworks/angular/build/ts-fallback-transform.d.ts +5 -0
- package/hmr/frameworks/angular/build/ts-fallback-transform.js +138 -0
- package/hmr/frameworks/angular/build/ts-fallback-transform.js.map +1 -0
- package/{helpers/angular → hmr/frameworks/angular/build}/util.d.ts +1 -0
- package/hmr/frameworks/angular/build/util.js +155 -0
- package/hmr/frameworks/angular/build/util.js.map +1 -0
- package/hmr/frameworks/angular/build/worker-url-preserve.d.ts +5 -0
- package/hmr/frameworks/angular/build/worker-url-preserve.js +140 -0
- package/hmr/frameworks/angular/build/worker-url-preserve.js.map +1 -0
- package/hmr/frameworks/angular/client/index.d.ts +2 -1
- package/hmr/frameworks/angular/client/index.js +637 -23
- package/hmr/frameworks/angular/client/index.js.map +1 -1
- package/hmr/frameworks/angular/client/strategy.d.ts +9 -0
- package/hmr/frameworks/angular/client/strategy.js +19 -0
- package/hmr/frameworks/angular/client/strategy.js.map +1 -0
- package/hmr/frameworks/angular/server/angular-root-component.d.ts +79 -0
- package/hmr/frameworks/angular/server/angular-root-component.js +149 -0
- package/hmr/frameworks/angular/server/angular-root-component.js.map +1 -0
- package/hmr/frameworks/angular/server/linker.js +37 -6
- package/hmr/frameworks/angular/server/linker.js.map +1 -1
- package/hmr/frameworks/angular/server/ng-component-route.d.ts +43 -0
- package/hmr/frameworks/angular/server/ng-component-route.js +113 -0
- package/hmr/frameworks/angular/server/ng-component-route.js.map +1 -0
- package/hmr/frameworks/angular/server/strategy.js +697 -18
- package/hmr/frameworks/angular/server/strategy.js.map +1 -1
- package/hmr/frameworks/angular/server/websocket-angular-entry.d.ts +2 -0
- package/hmr/frameworks/angular/server/websocket-angular-entry.js +68 -0
- package/hmr/frameworks/angular/server/websocket-angular-entry.js.map +1 -0
- package/hmr/frameworks/angular/server/websocket-angular-hot-update.d.ts +94 -0
- package/hmr/frameworks/angular/server/websocket-angular-hot-update.js +485 -0
- package/hmr/frameworks/angular/server/websocket-angular-hot-update.js.map +1 -0
- package/hmr/frameworks/react/client/strategy.d.ts +12 -0
- package/hmr/frameworks/react/client/strategy.js +27 -0
- package/hmr/frameworks/react/client/strategy.js.map +1 -0
- package/hmr/frameworks/react/server/strategy.d.ts +2 -0
- package/hmr/frameworks/react/server/strategy.js +230 -0
- package/hmr/frameworks/react/server/strategy.js.map +1 -0
- package/hmr/frameworks/solid/build/solid-jsx-deps.d.ts +15 -0
- package/hmr/frameworks/solid/build/solid-jsx-deps.js +178 -0
- package/hmr/frameworks/solid/build/solid-jsx-deps.js.map +1 -0
- package/hmr/frameworks/solid/client/app-runtime.d.ts +68 -0
- package/hmr/frameworks/solid/client/app-runtime.js +252 -0
- package/hmr/frameworks/solid/client/app-runtime.js.map +1 -0
- package/hmr/frameworks/solid/client/strategy.d.ts +7 -0
- package/hmr/frameworks/solid/client/strategy.js +391 -0
- package/hmr/frameworks/solid/client/strategy.js.map +1 -0
- package/hmr/frameworks/solid/server/strategy.js +293 -16
- package/hmr/frameworks/solid/server/strategy.js.map +1 -1
- package/hmr/frameworks/typescript/client/strategy.d.ts +7 -0
- package/hmr/frameworks/typescript/client/strategy.js +418 -0
- package/hmr/frameworks/typescript/client/strategy.js.map +1 -0
- package/hmr/frameworks/typescript/server/strategy.js +48 -16
- package/hmr/frameworks/typescript/server/strategy.js.map +1 -1
- package/hmr/frameworks/vue/client/dep-propagation.d.ts +44 -0
- package/hmr/frameworks/vue/client/dep-propagation.js +148 -0
- package/hmr/frameworks/vue/client/dep-propagation.js.map +1 -0
- package/hmr/frameworks/vue/client/index.d.ts +10 -1
- package/hmr/frameworks/vue/client/index.js +287 -562
- package/hmr/frameworks/vue/client/index.js.map +1 -1
- package/hmr/frameworks/vue/client/navigate-app.d.ts +3 -0
- package/hmr/frameworks/vue/client/navigate-app.js +178 -0
- package/hmr/frameworks/vue/client/navigate-app.js.map +1 -0
- package/hmr/frameworks/vue/client/strategy.d.ts +33 -0
- package/hmr/frameworks/vue/client/strategy.js +152 -0
- package/hmr/frameworks/vue/client/strategy.js.map +1 -0
- package/hmr/frameworks/vue/client/vue-sfc-update-overlay.d.ts +49 -0
- package/hmr/frameworks/vue/client/vue-sfc-update-overlay.js +124 -0
- package/hmr/frameworks/vue/client/vue-sfc-update-overlay.js.map +1 -0
- package/hmr/frameworks/vue/server/compiler.d.ts +3 -1
- package/hmr/frameworks/vue/server/compiler.js +3 -1
- package/hmr/frameworks/vue/server/compiler.js.map +1 -1
- package/hmr/frameworks/vue/server/sfc-route-assemble.d.ts +7 -0
- package/hmr/frameworks/vue/server/sfc-route-assemble.js +823 -0
- package/hmr/frameworks/vue/server/sfc-route-assemble.js.map +1 -0
- package/hmr/frameworks/vue/server/sfc-route-meta.d.ts +7 -0
- package/hmr/frameworks/vue/server/sfc-route-meta.js +80 -0
- package/hmr/frameworks/vue/server/sfc-route-meta.js.map +1 -0
- package/hmr/frameworks/vue/server/sfc-route-serve.d.ts +8 -0
- package/hmr/frameworks/vue/server/sfc-route-serve.js +462 -0
- package/hmr/frameworks/vue/server/sfc-route-serve.js.map +1 -0
- package/hmr/frameworks/vue/server/sfc-route-shared.d.ts +45 -0
- package/hmr/frameworks/vue/server/sfc-route-shared.js +105 -0
- package/hmr/frameworks/vue/server/sfc-route-shared.js.map +1 -0
- package/hmr/frameworks/vue/server/strategy.d.ts +35 -0
- package/hmr/frameworks/vue/server/strategy.js +291 -7
- package/hmr/frameworks/vue/server/strategy.js.map +1 -1
- package/hmr/frameworks/vue/server/websocket-sfc.d.ts +15 -0
- package/hmr/frameworks/vue/server/websocket-sfc.js +20 -0
- package/hmr/frameworks/vue/server/websocket-sfc.js.map +1 -0
- package/hmr/helpers/ast-normalizer.d.ts +3 -1
- package/hmr/helpers/ast-normalizer.js +131 -24
- package/hmr/helpers/ast-normalizer.js.map +1 -1
- package/hmr/helpers/cjs-named-exports.d.ts +23 -0
- package/hmr/helpers/cjs-named-exports.js +152 -0
- package/hmr/helpers/cjs-named-exports.js.map +1 -0
- package/hmr/helpers/package-exports.d.ts +16 -0
- package/hmr/helpers/package-exports.js +396 -0
- package/hmr/helpers/package-exports.js.map +1 -0
- package/hmr/helpers/vendor-rewrite.d.ts +1 -1
- package/hmr/helpers/vendor-rewrite.js +5 -3
- package/hmr/helpers/vendor-rewrite.js.map +1 -1
- package/hmr/server/boot-recording.d.ts +51 -0
- package/hmr/server/boot-recording.js +214 -0
- package/hmr/server/boot-recording.js.map +1 -0
- package/hmr/server/constants.d.ts +1 -0
- package/hmr/server/constants.js +21 -4
- package/hmr/server/constants.js.map +1 -1
- package/hmr/server/content-css-update.d.ts +54 -0
- package/hmr/server/content-css-update.js +78 -0
- package/hmr/server/content-css-update.js.map +1 -0
- package/hmr/server/core-bundle.d.ts +140 -0
- package/hmr/server/core-bundle.js +614 -0
- package/hmr/server/core-bundle.js.map +1 -0
- package/hmr/server/core-sanitize.d.ts +130 -4
- package/hmr/server/core-sanitize.js +393 -32
- package/hmr/server/core-sanitize.js.map +1 -1
- package/hmr/server/css-connect-sync.d.ts +28 -0
- package/hmr/server/css-connect-sync.js +59 -0
- package/hmr/server/css-connect-sync.js.map +1 -0
- package/hmr/server/css-device-module.d.ts +28 -0
- package/hmr/server/css-device-module.js +44 -0
- package/hmr/server/css-device-module.js.map +1 -0
- package/hmr/server/css-update-message.d.ts +23 -0
- package/hmr/server/css-update-message.js +41 -0
- package/hmr/server/css-update-message.js.map +1 -0
- package/hmr/server/deps-bundle.d.ts +233 -0
- package/hmr/server/deps-bundle.js +1022 -0
- package/hmr/server/deps-bundle.js.map +1 -0
- package/hmr/server/device-transform-helpers.d.ts +24 -0
- package/hmr/server/device-transform-helpers.js +408 -0
- package/hmr/server/device-transform-helpers.js.map +1 -0
- package/hmr/server/framework-strategy.d.ts +182 -11
- package/hmr/server/hmr-module-graph.d.ts +37 -0
- package/hmr/server/hmr-module-graph.js +215 -0
- package/hmr/server/hmr-module-graph.js.map +1 -0
- package/hmr/server/import-map.d.ts +99 -0
- package/hmr/server/import-map.js +294 -0
- package/hmr/server/import-map.js.map +1 -0
- package/hmr/server/index.d.ts +2 -1
- package/hmr/server/index.js +7 -16
- package/hmr/server/index.js.map +1 -1
- package/hmr/server/node-builtins-route.d.ts +12 -0
- package/hmr/server/node-builtins-route.js +86 -0
- package/hmr/server/node-builtins-route.js.map +1 -0
- package/hmr/server/ns-core-cjs-shape.d.ts +204 -0
- package/hmr/server/ns-core-cjs-shape.js +271 -0
- package/hmr/server/ns-core-cjs-shape.js.map +1 -0
- package/hmr/server/ns-m-response-memo.d.ts +10 -0
- package/hmr/server/ns-m-response-memo.js +33 -0
- package/hmr/server/ns-m-response-memo.js.map +1 -0
- package/hmr/server/ns-rt-bridge.d.ts +51 -0
- package/hmr/server/ns-rt-bridge.js +131 -0
- package/hmr/server/ns-rt-bridge.js.map +1 -0
- package/hmr/server/ns-rt-route.d.ts +5 -0
- package/hmr/server/ns-rt-route.js +39 -0
- package/hmr/server/ns-rt-route.js.map +1 -0
- package/hmr/server/perf-instrumentation.d.ts +114 -0
- package/hmr/server/perf-instrumentation.js +197 -0
- package/hmr/server/perf-instrumentation.js.map +1 -0
- package/hmr/server/process-code-for-device.d.ts +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.d.ts +5 -0
- package/hmr/server/runtime-graph-filter.js +28 -0
- package/hmr/server/runtime-graph-filter.js.map +1 -0
- package/hmr/server/server-origin.d.ts +2 -0
- package/hmr/server/server-origin.js +88 -0
- package/hmr/server/server-origin.js.map +1 -0
- package/hmr/server/shared-transform-request.d.ts +12 -0
- package/hmr/server/shared-transform-request.js +143 -0
- package/hmr/server/shared-transform-request.js.map +1 -0
- package/hmr/server/socket-utils.d.ts +10 -0
- package/hmr/server/socket-utils.js +14 -0
- package/hmr/server/socket-utils.js.map +1 -0
- package/hmr/server/transform-cache-invalidation.d.ts +37 -0
- package/hmr/server/transform-cache-invalidation.js +156 -0
- package/hmr/server/transform-cache-invalidation.js.map +1 -0
- package/hmr/server/vendor-bare-module-shims.d.ts +4 -0
- package/hmr/server/vendor-bare-module-shims.js +80 -0
- package/hmr/server/vendor-bare-module-shims.js.map +1 -0
- package/hmr/server/vite-plugin.d.ts +22 -1
- package/hmr/server/vite-plugin.js +655 -58
- package/hmr/server/vite-plugin.js.map +1 -1
- package/hmr/server/websocket-core-bridge.d.ts +68 -0
- package/hmr/server/websocket-core-bridge.js +370 -0
- package/hmr/server/websocket-core-bridge.js.map +1 -0
- package/hmr/server/websocket-device-transform.d.ts +3 -0
- package/hmr/server/websocket-device-transform.js +7 -0
- package/hmr/server/websocket-device-transform.js.map +1 -0
- package/hmr/server/websocket-graph-upsert.d.ts +21 -0
- package/hmr/server/websocket-graph-upsert.js +33 -0
- package/hmr/server/websocket-graph-upsert.js.map +1 -0
- package/hmr/server/websocket-hmr-pending.d.ts +29 -0
- package/hmr/server/websocket-hmr-pending.js +33 -0
- package/hmr/server/websocket-hmr-pending.js.map +1 -0
- package/hmr/server/websocket-hot-update.d.ts +80 -0
- package/hmr/server/websocket-hot-update.js +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 +21 -0
- package/hmr/server/websocket-module-bindings.js +504 -0
- package/hmr/server/websocket-module-bindings.js.map +1 -0
- package/hmr/server/websocket-module-specifiers.d.ts +96 -0
- package/hmr/server/websocket-module-specifiers.js +819 -0
- package/hmr/server/websocket-module-specifiers.js.map +1 -0
- package/hmr/server/websocket-ns-core.d.ts +34 -0
- package/hmr/server/websocket-ns-core.js +414 -0
- package/hmr/server/websocket-ns-core.js.map +1 -0
- package/hmr/server/websocket-ns-entry.d.ts +21 -0
- package/hmr/server/websocket-ns-entry.js +163 -0
- package/hmr/server/websocket-ns-entry.js.map +1 -0
- package/hmr/server/websocket-ns-m-paths.d.ts +19 -0
- package/hmr/server/websocket-ns-m-paths.js +115 -0
- package/hmr/server/websocket-ns-m-paths.js.map +1 -0
- package/hmr/server/websocket-ns-m-request.d.ts +46 -0
- package/hmr/server/websocket-ns-m-request.js +197 -0
- package/hmr/server/websocket-ns-m-request.js.map +1 -0
- package/hmr/server/websocket-ns-m.d.ts +52 -0
- package/hmr/server/websocket-ns-m.js +590 -0
- package/hmr/server/websocket-ns-m.js.map +1 -0
- package/hmr/server/websocket-served-module-helpers.d.ts +89 -0
- package/hmr/server/websocket-served-module-helpers.js +935 -0
- package/hmr/server/websocket-served-module-helpers.js.map +1 -0
- package/hmr/server/websocket-txn.d.ts +6 -0
- package/hmr/server/websocket-txn.js +42 -0
- package/hmr/server/websocket-txn.js.map +1 -0
- package/hmr/server/websocket-vendor-unifier.d.ts +9 -0
- package/hmr/server/websocket-vendor-unifier.js +46 -0
- package/hmr/server/websocket-vendor-unifier.js.map +1 -0
- package/hmr/server/websocket.d.ts +7 -17
- package/hmr/server/websocket.js +723 -5376
- 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/package-classifier.d.ts +9 -0
- package/hmr/shared/package-classifier.js +58 -0
- package/hmr/shared/package-classifier.js.map +1 -0
- package/hmr/shared/protocol.d.ts +157 -0
- package/hmr/shared/protocol.js +28 -0
- package/hmr/shared/protocol.js.map +1 -0
- package/hmr/shared/runtime/boot-complete.d.ts +14 -0
- package/hmr/shared/runtime/boot-complete.js +32 -0
- package/hmr/shared/runtime/boot-complete.js.map +1 -0
- package/hmr/shared/runtime/boot-placeholder-ui.d.ts +69 -0
- package/hmr/shared/runtime/boot-placeholder-ui.js +101 -0
- package/hmr/shared/runtime/boot-placeholder-ui.js.map +1 -0
- package/hmr/shared/runtime/boot-progress.d.ts +44 -0
- package/hmr/shared/runtime/boot-progress.js +134 -0
- package/hmr/shared/runtime/boot-progress.js.map +1 -0
- package/hmr/shared/runtime/boot-timeline.d.ts +17 -0
- package/hmr/shared/runtime/boot-timeline.js +40 -0
- package/hmr/shared/runtime/boot-timeline.js.map +1 -0
- package/hmr/shared/runtime/browser-runtime-contract.d.ts +97 -0
- package/hmr/shared/runtime/browser-runtime-contract.js +66 -0
- package/hmr/shared/runtime/browser-runtime-contract.js.map +1 -0
- package/hmr/shared/runtime/dev-overlay-ios.d.ts +87 -0
- package/hmr/shared/runtime/dev-overlay-ios.js +521 -0
- package/hmr/shared/runtime/dev-overlay-ios.js.map +1 -0
- package/hmr/shared/runtime/dev-overlay-shared.d.ts +58 -0
- package/hmr/shared/runtime/dev-overlay-shared.js +116 -0
- package/hmr/shared/runtime/dev-overlay-shared.js.map +1 -0
- package/hmr/shared/runtime/dev-overlay-snapshots.d.ts +31 -0
- package/hmr/shared/runtime/dev-overlay-snapshots.js +324 -0
- package/hmr/shared/runtime/dev-overlay-snapshots.js.map +1 -0
- package/hmr/shared/runtime/dev-overlay-tree.d.ts +59 -0
- package/hmr/shared/runtime/dev-overlay-tree.js +712 -0
- package/hmr/shared/runtime/dev-overlay-tree.js.map +1 -0
- package/hmr/shared/runtime/dev-overlay.d.ts +39 -0
- package/hmr/shared/runtime/dev-overlay.js +292 -0
- package/hmr/shared/runtime/dev-overlay.js.map +1 -0
- package/hmr/shared/runtime/global-scope.d.ts +18 -0
- package/hmr/shared/runtime/global-scope.js +21 -0
- package/hmr/shared/runtime/global-scope.js.map +1 -0
- package/hmr/shared/runtime/hooks.js +2 -1
- package/hmr/shared/runtime/hooks.js.map +1 -1
- package/hmr/shared/runtime/launch-bridge.d.ts +9 -0
- package/hmr/shared/runtime/launch-bridge.js +98 -0
- package/hmr/shared/runtime/launch-bridge.js.map +1 -0
- package/hmr/shared/runtime/module-provenance.d.ts +1 -0
- package/hmr/shared/runtime/module-provenance.js +64 -0
- package/hmr/shared/runtime/module-provenance.js.map +1 -0
- package/hmr/shared/runtime/ns-runtime-test-double.d.ts +21 -0
- package/hmr/shared/runtime/ns-runtime-test-double.js +20 -0
- package/hmr/shared/runtime/ns-runtime-test-double.js.map +1 -0
- package/hmr/shared/runtime/overlay-flag.d.ts +9 -0
- package/hmr/shared/runtime/overlay-flag.js +34 -0
- package/hmr/shared/runtime/overlay-flag.js.map +1 -0
- package/hmr/shared/runtime/platform-polyfills.d.ts +26 -0
- package/hmr/shared/runtime/platform-polyfills.js +122 -0
- package/hmr/shared/runtime/platform-polyfills.js.map +1 -0
- package/hmr/shared/runtime/root-placeholder-view.d.ts +19 -0
- package/hmr/shared/runtime/root-placeholder-view.js +311 -0
- package/hmr/shared/runtime/root-placeholder-view.js.map +1 -0
- package/hmr/shared/runtime/root-placeholder.d.ts +1 -0
- package/hmr/shared/runtime/root-placeholder.js +778 -83
- package/hmr/shared/runtime/root-placeholder.js.map +1 -1
- package/hmr/shared/runtime/session-bootstrap.d.ts +1 -0
- package/hmr/shared/runtime/session-bootstrap.js +350 -0
- package/hmr/shared/runtime/session-bootstrap.js.map +1 -0
- package/hmr/shared/runtime/vendor-bootstrap.js +54 -16
- package/hmr/shared/runtime/vendor-bootstrap.js.map +1 -1
- package/hmr/shared/runtime/vendor-resolve.d.ts +22 -0
- package/hmr/shared/runtime/vendor-resolve.js +45 -0
- package/hmr/shared/runtime/vendor-resolve.js.map +1 -0
- package/hmr/shared/runtime/worker-tracking.d.ts +28 -0
- package/hmr/shared/runtime/worker-tracking.js +114 -0
- package/hmr/shared/runtime/worker-tracking.js.map +1 -0
- package/hmr/shared/vendor/manifest-collect.d.ts +4 -0
- package/hmr/shared/vendor/manifest-collect.js +909 -0
- package/hmr/shared/vendor/manifest-collect.js.map +1 -0
- package/hmr/shared/vendor/manifest-loader.d.ts +2 -1
- package/hmr/shared/vendor/manifest-loader.js +5 -3
- package/hmr/shared/vendor/manifest-loader.js.map +1 -1
- package/hmr/shared/vendor/manifest.d.ts +12 -0
- package/hmr/shared/vendor/manifest.js +341 -545
- package/hmr/shared/vendor/manifest.js.map +1 -1
- package/hmr/shared/vendor/registry.d.ts +2 -0
- package/hmr/shared/vendor/registry.js +118 -7
- package/hmr/shared/vendor/registry.js.map +1 -1
- package/hmr/shared/vendor/vendor-device-shim.d.ts +1 -0
- package/hmr/shared/vendor/vendor-device-shim.js +208 -0
- package/hmr/shared/vendor/vendor-device-shim.js.map +1 -0
- package/hmr/shared/vendor/vendor-esbuild-plugins.d.ts +107 -0
- package/hmr/shared/vendor/vendor-esbuild-plugins.js +540 -0
- package/hmr/shared/vendor/vendor-esbuild-plugins.js.map +1 -0
- package/index.d.ts +1 -0
- package/index.js +5 -0
- package/index.js.map +1 -1
- package/package.json +76 -14
- package/runtime/core-aliases-early.js +103 -81
- package/runtime/core-aliases-early.js.map +1 -1
- package/shims/react-jsx-runtime.d.ts +4 -0
- package/shims/react-jsx-runtime.js +61 -0
- package/shims/react-jsx-runtime.js.map +1 -0
- package/shims/solid-jsx-runtime.d.ts +7 -0
- package/shims/solid-jsx-runtime.js +17 -0
- package/shims/solid-jsx-runtime.js.map +1 -0
- package/helpers/angular/angular-linker.d.ts +0 -13
- package/helpers/angular/angular-linker.js +0 -189
- package/helpers/angular/angular-linker.js.map +0 -1
- package/helpers/angular/shared-linker.d.ts +0 -4
- package/helpers/angular/shared-linker.js +0 -39
- package/helpers/angular/shared-linker.js.map +0 -1
- package/helpers/angular/util.js +0 -67
- package/helpers/angular/util.js.map +0 -1
- package/helpers/module-runner-patch.d.ts +0 -3
- package/helpers/module-runner-patch.js +0 -63
- package/helpers/module-runner-patch.js.map +0 -1
- package/helpers/prelink-angular.d.ts +0 -2
- package/helpers/prelink-angular.js +0 -117
- package/helpers/prelink-angular.js.map +0 -1
- package/hmr/shared/runtime/http-only-boot.d.ts +0 -1
- package/hmr/shared/runtime/http-only-boot.js +0 -124
- package/hmr/shared/runtime/http-only-boot.js.map +0 -1
- package/hmr/vendor-bootstrap.d.ts +0 -3
- package/hmr/vendor-bootstrap.js +0 -32
- package/hmr/vendor-bootstrap.js.map +0 -1
- package/shims/react-reconciler-constants.d.ts +0 -14
- package/shims/react-reconciler-constants.js +0 -21
- package/shims/react-reconciler-constants.js.map +0 -1
- package/shims/react-reconciler.d.ts +0 -8
- package/shims/react-reconciler.js +0 -15
- package/shims/react-reconciler.js.map +0 -1
- package/transformers/NativeClass/index.d.ts +0 -2
- package/transformers/NativeClass/index.js +0 -222
- package/transformers/NativeClass/index.js.map +0 -1
|
@@ -8,8 +8,8 @@
|
|
|
8
8
|
* "@nativescript/core/index.js";
|
|
9
9
|
* This trips the sanitizer's local-core-path detector and breaks HTTP ESM loading.
|
|
10
10
|
*
|
|
11
|
-
* This helper safely maps those literals to:
|
|
12
|
-
* import "/ns/core?p=
|
|
11
|
+
* This helper safely maps those literals to the canonical path form:
|
|
12
|
+
* import "/ns/core/<sub>"; // subpath form, no version, no ?p=
|
|
13
13
|
* or, without subpath:
|
|
14
14
|
* import "/ns/core";
|
|
15
15
|
*/
|
|
@@ -19,14 +19,140 @@ export declare function normalizeStrayCoreStringLiterals(code: string): string;
|
|
|
19
19
|
* following side-effect import of the core bridge.
|
|
20
20
|
*
|
|
21
21
|
* Example:
|
|
22
|
-
* import { A, B } from\nimport "/ns/core
|
|
22
|
+
* import { A, B } from\nimport "/ns/core/index";
|
|
23
23
|
* becomes
|
|
24
|
-
* import { A, B } from "/ns/core
|
|
24
|
+
* import { A, B } from "/ns/core/index";
|
|
25
25
|
*/
|
|
26
26
|
export declare function fixDanglingCoreFrom(code: string): string;
|
|
27
|
+
/**
|
|
28
|
+
* Run the full "rescue any stray @nativescript/core references" pass over the
|
|
29
|
+
* code in one call. This is the canonical entry point for NS-M served modules
|
|
30
|
+
* (and any other consumer that wants the safety net). The three sub-passes
|
|
31
|
+
* cover progressively rarer pipeline accidents:
|
|
32
|
+
*
|
|
33
|
+
* 1. `normalizeStrayCoreStringLiterals` — turns naked `"@nativescript/core/foo";`
|
|
34
|
+
* string literals (produced by some upstream transforms that bare-stringify
|
|
35
|
+
* side-effect imports) back into proper `import "/ns/core/foo";`.
|
|
36
|
+
* 2. `fixDanglingCoreFrom` — merges multi-line accidents where a `from`
|
|
37
|
+
* clause got separated from its specifier across newlines.
|
|
38
|
+
* 3. `normalizeAnyCoreSpecToBridge` — final regex sweep that catches any
|
|
39
|
+
* remaining `from "...@nativescript/core[/sub]..."` references that escaped
|
|
40
|
+
* both the AST normalizer and the import rewriter.
|
|
41
|
+
*
|
|
42
|
+
* Centralising the passes here ensures every NS-M emitter applies the same
|
|
43
|
+
* safety net in the same order; drift between call sites re-introduces the
|
|
44
|
+
* realm-split bug.
|
|
45
|
+
*
|
|
46
|
+
* Returns the (possibly) rewritten code; never throws.
|
|
47
|
+
*/
|
|
48
|
+
export declare function sanitizeStrayCoreReferences(code: string): string;
|
|
27
49
|
/**
|
|
28
50
|
* Fallback: normalize ANY import spec that references '@nativescript/core' (including
|
|
29
51
|
* absolute/relative or resolved forms like '/node_modules/@nativescript/core/index.js?v=...')
|
|
30
52
|
* into the unified '/ns/core' bridge before fast-fail assertions.
|
|
31
53
|
*/
|
|
32
54
|
export declare function normalizeAnyCoreSpecToBridge(code: string): string;
|
|
55
|
+
/**
|
|
56
|
+
* Description of the URL the bridge is currently serving, used to resolve
|
|
57
|
+
* relative import specifiers (`./x`, `../x`) into absolute `/ns/core/<sub>`
|
|
58
|
+
* URLs.
|
|
59
|
+
*
|
|
60
|
+
* Why this exists: Vite's `vite:import-analysis` pass usually rewrites every
|
|
61
|
+
* relative specifier to an absolute (`/@fs/...` or `/node_modules/...`) ID
|
|
62
|
+
* before code reaches us, but for files under `node_modules` some transform
|
|
63
|
+
* paths leave relatives untouched. When the device fetches such a module at
|
|
64
|
+
* `http://host/ns/core/utils/layout-helper` (no trailing slash, no `/index`)
|
|
65
|
+
* V8/iOS apply RFC 3986 URL resolution and treat `layout-helper` as the
|
|
66
|
+
* *file*, so `./layout-helper-common` becomes
|
|
67
|
+
* `http://host/ns/core/utils/layout-helper-common` — a sibling that does not
|
|
68
|
+
* exist (the real file lives at `…/layout-helper/layout-helper-common`).
|
|
69
|
+
*
|
|
70
|
+
* Passing a `RelativeBase` lets `rewriteSpec` resolve these specifiers
|
|
71
|
+
* server-side and emit canonical absolute `/ns/core/<resolved>` URLs, so the
|
|
72
|
+
* device never has to guess. When omitted, `rewriteSpec` falls back to the
|
|
73
|
+
* pre-existing behaviour of leaving relatives alone.
|
|
74
|
+
*/
|
|
75
|
+
export type RelativeBase = {
|
|
76
|
+
/**
|
|
77
|
+
* Sub-path of the served module, without the leading `/ns/core/`. May be
|
|
78
|
+
* the empty string for the package main (`/ns/core` itself).
|
|
79
|
+
*/
|
|
80
|
+
sub: string;
|
|
81
|
+
/**
|
|
82
|
+
* `true` when the served file is a directory-index (e.g.
|
|
83
|
+
* `…/utils/layout-helper/index.android.ts`); in that case `sub` already
|
|
84
|
+
* names the *directory*, and `./x` resolves to `<sub>/x`.
|
|
85
|
+
*
|
|
86
|
+
* `false` for plain file modules (e.g. `…/utils/native-helper.ts`); the
|
|
87
|
+
* resolution base is the parent directory of `sub`, so `./x` resolves to
|
|
88
|
+
* `<sub-parent>/x`.
|
|
89
|
+
*/
|
|
90
|
+
isDirectoryIndex: boolean;
|
|
91
|
+
};
|
|
92
|
+
/**
|
|
93
|
+
* Detect whether a resolved module path is a directory-index file. Matches
|
|
94
|
+
* `index.<platform?>.<ext>` shapes used across @nativescript/core (e.g.
|
|
95
|
+
* `index.js`, `index.android.ts`, `index.ios.mjs`).
|
|
96
|
+
*/
|
|
97
|
+
export declare function isDirectoryIndexFilename(modulePath: string): boolean;
|
|
98
|
+
/**
|
|
99
|
+
* Resolve a relative specifier (`./x`, `../x`) into a canonical
|
|
100
|
+
* @nativescript/core sub-path, given the base described by `relBase`.
|
|
101
|
+
*
|
|
102
|
+
* `…/index.<platform>.<ext>` files mean `sub` IS the directory (so `./x` →
|
|
103
|
+
* `<sub>/x`); plain files mean the resolution base is `sub`'s parent.
|
|
104
|
+
*
|
|
105
|
+
* Returned sub-path is sanitised by `buildCoreUrlPath`'s convention: trailing
|
|
106
|
+
* `.(m)?(j|t)s` extensions are stripped so callers can directly emit
|
|
107
|
+
* `/ns/core/<resolved>` without producing a non-canonical URL that the
|
|
108
|
+
* bridge would 301-redirect later.
|
|
109
|
+
*/
|
|
110
|
+
export declare function resolveRelativeCoreSub(spec: string, relBase: RelativeBase): string | null;
|
|
111
|
+
/**
|
|
112
|
+
* Minimal specifier rewriter for deep subpath core modules.
|
|
113
|
+
*
|
|
114
|
+
* Takes Vite's correctly-transformed ESM output and ONLY rewrites the
|
|
115
|
+
* specifier strings inside import/export clauses. Does NOT:
|
|
116
|
+
* - Inject global defines
|
|
117
|
+
* - Run AST normalization
|
|
118
|
+
* - Convert named imports to default + destructure
|
|
119
|
+
* - Mangle newlines or code structure
|
|
120
|
+
*
|
|
121
|
+
* This replaces the heavy 5-pass pipeline (processCodeForDevice →
|
|
122
|
+
* rewriteImports → deduplicateLinkerImports → CJS wrapping → etc.)
|
|
123
|
+
* for deep subpath core modules where Vite already produces correct ESM.
|
|
124
|
+
*
|
|
125
|
+
* When `relBase` is supplied, relative specifiers (`./x`, `../x`) are
|
|
126
|
+
* resolved server-side into canonical `/ns/core/<resolved>` URLs so the
|
|
127
|
+
* device never has to guess where a directory-index file's siblings live.
|
|
128
|
+
* See `RelativeBase` and `rewriteSpec` for the full rationale.
|
|
129
|
+
*/
|
|
130
|
+
export declare function rewriteSpecifiersForDevice(code: string, origin: string, ver: number, relBase?: RelativeBase): string;
|
|
131
|
+
/**
|
|
132
|
+
* Determine whether a `/ns/core` bridge URL points to a real subpath module.
|
|
133
|
+
*
|
|
134
|
+
* Any `/ns/core/<sub>` module now serves real ESM content with real named
|
|
135
|
+
* exports via Vite's transform pipeline, except for package-main aliases like
|
|
136
|
+
* `/ns/core/index`, which should be treated like the main `/ns/core`
|
|
137
|
+
* bridge and destructured from its default export.
|
|
138
|
+
* The main proxy bridge (`/ns/core`) still only exports a default Proxy and
|
|
139
|
+
* requires named imports to be destructured from it.
|
|
140
|
+
*
|
|
141
|
+
* This check is used in all named-import-to-default destructuring passes to
|
|
142
|
+
* skip rewriting for real subpath modules — they have named exports that work
|
|
143
|
+
* natively without conversion.
|
|
144
|
+
*/
|
|
145
|
+
export declare function isDeepCoreSubpath(url: string): boolean;
|
|
146
|
+
/**
|
|
147
|
+
* Synthesize a `default` export for an ESM module that only has named/star
|
|
148
|
+
* exports. Utility function — not currently called from the core bridge
|
|
149
|
+
* handler since `ensureDestructureCoreImports` now skips deep subpaths.
|
|
150
|
+
*
|
|
151
|
+
* Handles all three @nativescript/core patterns:
|
|
152
|
+
* 1. Direct declarations: export class X, export function Y, export const Z
|
|
153
|
+
* 2. Named re-exports: export { A, B } from '/path'
|
|
154
|
+
* 3. Star re-exports: export * from '/path'
|
|
155
|
+
*
|
|
156
|
+
* Returns the code unchanged if it already has a default export or CJS exports.
|
|
157
|
+
*/
|
|
158
|
+
export declare function synthesizeDefaultExport(moduleCode: string): string;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { buildCoreUrlPath } from '../../helpers/ns-core-url.js';
|
|
1
2
|
/**
|
|
2
3
|
* Rewrites stray string-literal side-effect lines that reference @nativescript/core
|
|
3
4
|
* into proper ESM import statements targeting the unified /ns/core bridge.
|
|
@@ -8,8 +9,8 @@
|
|
|
8
9
|
* "@nativescript/core/index.js";
|
|
9
10
|
* This trips the sanitizer's local-core-path detector and breaks HTTP ESM loading.
|
|
10
11
|
*
|
|
11
|
-
* This helper safely maps those literals to:
|
|
12
|
-
* import "/ns/core?p=
|
|
12
|
+
* This helper safely maps those literals to the canonical path form:
|
|
13
|
+
* import "/ns/core/<sub>"; // subpath form, no version, no ?p=
|
|
13
14
|
* or, without subpath:
|
|
14
15
|
* import "/ns/core";
|
|
15
16
|
*/
|
|
@@ -18,26 +19,21 @@ export function normalizeStrayCoreStringLiterals(code) {
|
|
|
18
19
|
return code;
|
|
19
20
|
try {
|
|
20
21
|
let out = code;
|
|
22
|
+
const toCoreBridgeUrl = (sub) => buildCoreUrlPath(sub);
|
|
21
23
|
// Normalize any concatenated imports on the same line to start on a new line
|
|
22
24
|
// e.g. `...;import x from` -> `...;\nimport x from`
|
|
23
25
|
out = out.replace(/;\s*import\s+/g, ';\nimport ');
|
|
24
26
|
// Case 1: inline literal followed by another import on SAME line
|
|
25
27
|
// Example: "@nativescript/core/index.js";import { x } from "...";
|
|
26
28
|
out = out.replace(/(["']@nativescript\/core([^"']*)["'];)(\s*import\s+)/g, (_m, _lit, sub, after) => {
|
|
27
|
-
const
|
|
28
|
-
.trim()
|
|
29
|
-
.replace(/^\//, '');
|
|
30
|
-
const url = qp ? `/ns/core?p=${qp}` : '/ns/core';
|
|
29
|
+
const url = toCoreBridgeUrl(sub);
|
|
31
30
|
return `import "${url}";${after}`;
|
|
32
31
|
});
|
|
33
32
|
// Case 2: standalone literal on its own line (not a JSON key) — must be end-of-line
|
|
34
33
|
// Guard with EOL so we don't rewrite JSON keys like "@nativescript/core": "alpha"
|
|
35
34
|
const reLine = /(^|\n)([\t ]*)["']@nativescript\/core([^"']*)["']\s*;?\s*(?=$|\n)/g;
|
|
36
35
|
out = out.replace(reLine, (_full, prefix, indent, sub) => {
|
|
37
|
-
const
|
|
38
|
-
.trim()
|
|
39
|
-
.replace(/^\//, '');
|
|
40
|
-
const url = qp ? `/ns/core?p=${qp}` : '/ns/core';
|
|
36
|
+
const url = toCoreBridgeUrl(sub);
|
|
41
37
|
return `${prefix}${indent}import "${url}";`;
|
|
42
38
|
});
|
|
43
39
|
return out;
|
|
@@ -51,19 +47,18 @@ export function normalizeStrayCoreStringLiterals(code) {
|
|
|
51
47
|
* following side-effect import of the core bridge.
|
|
52
48
|
*
|
|
53
49
|
* Example:
|
|
54
|
-
* import { A, B } from\nimport "/ns/core
|
|
50
|
+
* import { A, B } from\nimport "/ns/core/index";
|
|
55
51
|
* becomes
|
|
56
|
-
* import { A, B } from "/ns/core
|
|
52
|
+
* import { A, B } from "/ns/core/index";
|
|
57
53
|
*/
|
|
58
54
|
export function fixDanglingCoreFrom(code) {
|
|
59
55
|
if (!code || typeof code !== 'string')
|
|
60
56
|
return code;
|
|
61
57
|
try {
|
|
62
|
-
// Also normalize any concatenated imports before processing
|
|
63
58
|
code = code.replace(/;\s*import\s+/g, ';\nimport ');
|
|
64
59
|
// Multi-line form: import { ...\n ...\n} from\nimport "<core-url>";[tail]
|
|
65
60
|
// Merge into: import { ... } from "<core-url>";\n[tail]
|
|
66
|
-
code = code.replace(/(^|\n|;)\s*import\s*\{([\s\S]*?)\}\s*from\s*\n\s*import\s+["']((?:https?:\/\/[^"']+)?\/ns\/core(
|
|
61
|
+
code = code.replace(/(^|\n|;)\s*import\s*\{([\s\S]*?)\}\s*from\s*\n\s*import\s+["']((?:https?:\/\/[^"']+)?\/ns\/core(?:\/[^"']*)?)["'];?(.*)/g, (_m, pre, named, url, tail) => {
|
|
67
62
|
const prefix = pre ? (String(pre).endsWith(';') ? String(pre) + '\n' : String(pre)) : '';
|
|
68
63
|
const tailNorm = (tail || '').replace(/^\s*;?\s*/, '').trim();
|
|
69
64
|
return prefix + `import {${named}} from "${url}";` + (tailNorm ? `\n${tailNorm}` : '');
|
|
@@ -75,19 +70,16 @@ export function fixDanglingCoreFrom(code) {
|
|
|
75
70
|
const m = /^\s*import\s*\{[^}]+\}\s*from\s*$/.exec(ln);
|
|
76
71
|
if (m && i + 1 < lines.length) {
|
|
77
72
|
const next = lines[i + 1];
|
|
78
|
-
|
|
79
|
-
// Capture the core import URL and any trailing content after it (another import concatenated)
|
|
80
|
-
const m2 = /^\s*import\s+["']((?:https?:\/\/[^"']+)?\/ns\/core(?:\/\d+)?(?:\?p=[^"']+)?)["'];?(.*)$/.exec(next);
|
|
73
|
+
const m2 = /^\s*import\s+["']((?:https?:\/\/[^"']+)?\/ns\/core(?:\/[^"']*)?)["'];?(.*)$/.exec(next);
|
|
81
74
|
if (m2) {
|
|
82
75
|
const url = m2[1];
|
|
83
76
|
const tail = m2[2] || '';
|
|
84
77
|
out.push(ln + ' ' + `"${url}";`);
|
|
85
|
-
// If there is a tail like ';import { ... } from "..."', normalize it onto a new line
|
|
86
78
|
const tailNorm = tail.replace(/^\s*;?\s*/, '');
|
|
87
79
|
if (tailNorm.trim().length > 0) {
|
|
88
80
|
out.push(tailNorm);
|
|
89
81
|
}
|
|
90
|
-
i++;
|
|
82
|
+
i++;
|
|
91
83
|
continue;
|
|
92
84
|
}
|
|
93
85
|
}
|
|
@@ -99,6 +91,45 @@ export function fixDanglingCoreFrom(code) {
|
|
|
99
91
|
return code;
|
|
100
92
|
}
|
|
101
93
|
}
|
|
94
|
+
/**
|
|
95
|
+
* Run the full "rescue any stray @nativescript/core references" pass over the
|
|
96
|
+
* code in one call. This is the canonical entry point for NS-M served modules
|
|
97
|
+
* (and any other consumer that wants the safety net). The three sub-passes
|
|
98
|
+
* cover progressively rarer pipeline accidents:
|
|
99
|
+
*
|
|
100
|
+
* 1. `normalizeStrayCoreStringLiterals` — turns naked `"@nativescript/core/foo";`
|
|
101
|
+
* string literals (produced by some upstream transforms that bare-stringify
|
|
102
|
+
* side-effect imports) back into proper `import "/ns/core/foo";`.
|
|
103
|
+
* 2. `fixDanglingCoreFrom` — merges multi-line accidents where a `from`
|
|
104
|
+
* clause got separated from its specifier across newlines.
|
|
105
|
+
* 3. `normalizeAnyCoreSpecToBridge` — final regex sweep that catches any
|
|
106
|
+
* remaining `from "...@nativescript/core[/sub]..."` references that escaped
|
|
107
|
+
* both the AST normalizer and the import rewriter.
|
|
108
|
+
*
|
|
109
|
+
* Centralising the passes here ensures every NS-M emitter applies the same
|
|
110
|
+
* safety net in the same order; drift between call sites re-introduces the
|
|
111
|
+
* realm-split bug.
|
|
112
|
+
*
|
|
113
|
+
* Returns the (possibly) rewritten code; never throws.
|
|
114
|
+
*/
|
|
115
|
+
export function sanitizeStrayCoreReferences(code) {
|
|
116
|
+
if (!code || typeof code !== 'string')
|
|
117
|
+
return code;
|
|
118
|
+
let out = code;
|
|
119
|
+
try {
|
|
120
|
+
out = normalizeStrayCoreStringLiterals(out);
|
|
121
|
+
}
|
|
122
|
+
catch { }
|
|
123
|
+
try {
|
|
124
|
+
out = fixDanglingCoreFrom(out);
|
|
125
|
+
}
|
|
126
|
+
catch { }
|
|
127
|
+
try {
|
|
128
|
+
out = normalizeAnyCoreSpecToBridge(out);
|
|
129
|
+
}
|
|
130
|
+
catch { }
|
|
131
|
+
return out;
|
|
132
|
+
}
|
|
102
133
|
/**
|
|
103
134
|
* Fallback: normalize ANY import spec that references '@nativescript/core' (including
|
|
104
135
|
* absolute/relative or resolved forms like '/node_modules/@nativescript/core/index.js?v=...')
|
|
@@ -109,26 +140,356 @@ export function normalizeAnyCoreSpecToBridge(code) {
|
|
|
109
140
|
return code;
|
|
110
141
|
try {
|
|
111
142
|
let out = code;
|
|
112
|
-
const
|
|
113
|
-
const s = String(sub || '')
|
|
114
|
-
.split('?')[0]
|
|
115
|
-
.trim()
|
|
116
|
-
.replace(/^\//, '');
|
|
117
|
-
return s ? `?p=${s}` : '';
|
|
118
|
-
};
|
|
143
|
+
const toCoreBridgeUrl = (sub) => buildCoreUrlPath(sub);
|
|
119
144
|
// Static: import ... from "...@nativescript/core[/sub]..."
|
|
120
|
-
out = out.replace(/from\s+["'][^"']*@nativescript[\/_-]core([^"']*)["']/g, (_m, sub) => `from "
|
|
145
|
+
out = out.replace(/from\s+["'][^"']*@nativescript[\/_-]core([^"']*)["']/g, (_m, sub) => `from "${toCoreBridgeUrl(sub)}"`);
|
|
121
146
|
// Side-effect: import "...@nativescript/core[/sub]..."
|
|
122
|
-
out = out.replace(/(^|\n)\s*import\s+["'][^"']*@nativescript[\/_-]core([^"']*)["'];?/gm, (full, pfx, sub) => `${pfx}import "
|
|
147
|
+
out = out.replace(/(^|\n)\s*import\s+["'][^"']*@nativescript[\/_-]core([^"']*)["'];?/gm, (full, pfx, sub) => `${pfx}import "${toCoreBridgeUrl(sub)}";`);
|
|
123
148
|
// Dynamic: import("...@nativescript/core[/sub]...")
|
|
124
|
-
out = out.replace(/import\(\s*["'][^"']*@nativescript[\/_-]core([^"']*)["']\s*\)/g, (_m, sub) => `import("
|
|
125
|
-
// Repair glitch where a previous pass split/merged lines into:
|
|
126
|
-
//
|
|
127
|
-
|
|
149
|
+
out = out.replace(/import\(\s*["'][^"']*@nativescript[\/_-]core([^"']*)["']\s*\)/g, (_m, sub) => `import("${toCoreBridgeUrl(sub)}")`);
|
|
150
|
+
// Repair glitch where a previous pass split/merged lines into:
|
|
151
|
+
// "from import '/ns/core...'". Normalize to a valid specifier:
|
|
152
|
+
// "from '/ns/core...'".
|
|
153
|
+
out = out.replace(/from\s+import\s+["']((?:https?:\/\/[^"']+)?\/ns\/core(?:\/[^"']*)?)['"]/g, (_m, url) => `from "${url}"`);
|
|
128
154
|
return out;
|
|
129
155
|
}
|
|
130
156
|
catch {
|
|
131
157
|
return code;
|
|
132
158
|
}
|
|
133
159
|
}
|
|
160
|
+
/**
|
|
161
|
+
* Detect whether a resolved module path is a directory-index file. Matches
|
|
162
|
+
* `index.<platform?>.<ext>` shapes used across @nativescript/core (e.g.
|
|
163
|
+
* `index.js`, `index.android.ts`, `index.ios.mjs`).
|
|
164
|
+
*/
|
|
165
|
+
export function isDirectoryIndexFilename(modulePath) {
|
|
166
|
+
if (!modulePath || typeof modulePath !== 'string')
|
|
167
|
+
return false;
|
|
168
|
+
const cleaned = modulePath.split(/[?#]/)[0];
|
|
169
|
+
const base = cleaned.replace(/\\/g, '/').split('/').pop() || '';
|
|
170
|
+
return /^index(?:\.(?:android|ios|visionos))?\.(?:m?[jt]s)$/i.test(base);
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* Resolve a relative specifier (`./x`, `../x`) into a canonical
|
|
174
|
+
* @nativescript/core sub-path, given the base described by `relBase`.
|
|
175
|
+
*
|
|
176
|
+
* `…/index.<platform>.<ext>` files mean `sub` IS the directory (so `./x` →
|
|
177
|
+
* `<sub>/x`); plain files mean the resolution base is `sub`'s parent.
|
|
178
|
+
*
|
|
179
|
+
* Returned sub-path is sanitised by `buildCoreUrlPath`'s convention: trailing
|
|
180
|
+
* `.(m)?(j|t)s` extensions are stripped so callers can directly emit
|
|
181
|
+
* `/ns/core/<resolved>` without producing a non-canonical URL that the
|
|
182
|
+
* bridge would 301-redirect later.
|
|
183
|
+
*/
|
|
184
|
+
export function resolveRelativeCoreSub(spec, relBase) {
|
|
185
|
+
if (!spec || (!spec.startsWith('./') && !spec.startsWith('../')))
|
|
186
|
+
return null;
|
|
187
|
+
const cleanSpec = spec.split(/[?#]/)[0];
|
|
188
|
+
const stripExt = (s) => s.replace(/\.(?:m?[jt]s)$/i, '');
|
|
189
|
+
const splitSeg = (s) => s.split('/').filter((p) => p.length > 0);
|
|
190
|
+
const baseSub = String(relBase?.sub || '').replace(/^\/+|\/+$/g, '');
|
|
191
|
+
const dirParts = relBase?.isDirectoryIndex ? splitSeg(baseSub) : splitSeg(baseSub).slice(0, -1);
|
|
192
|
+
const relParts = cleanSpec.split('/');
|
|
193
|
+
for (const part of relParts) {
|
|
194
|
+
if (part === '' || part === '.')
|
|
195
|
+
continue;
|
|
196
|
+
if (part === '..') {
|
|
197
|
+
if (dirParts.length === 0)
|
|
198
|
+
return null;
|
|
199
|
+
dirParts.pop();
|
|
200
|
+
continue;
|
|
201
|
+
}
|
|
202
|
+
dirParts.push(part);
|
|
203
|
+
}
|
|
204
|
+
const joined = dirParts.join('/');
|
|
205
|
+
return stripExt(joined);
|
|
206
|
+
}
|
|
207
|
+
/**
|
|
208
|
+
* Rewrite a single import/export specifier for device consumption.
|
|
209
|
+
*
|
|
210
|
+
* Converts Vite-resolved root-relative paths to URLs the device can fetch:
|
|
211
|
+
* /node_modules/@nativescript/core/x/y → /ns/core/x/y (canonical)
|
|
212
|
+
* /node_modules/other-pkg/x.js → {origin}/ns/m/node_modules/other-pkg/x.js
|
|
213
|
+
* /src/app/foo.ts → {origin}/ns/m/src/app/foo.ts
|
|
214
|
+
* already /ns/... or http://... → unchanged
|
|
215
|
+
*
|
|
216
|
+
* When `relBase` is supplied AND `spec` is a relative path (`./x` or `../x`),
|
|
217
|
+
* the relative specifier is resolved to an absolute `/ns/core/<resolved>`
|
|
218
|
+
* URL using `resolveRelativeCoreSub`. Without `relBase`, relatives are
|
|
219
|
+
* returned unchanged (legacy behaviour for non-core call sites).
|
|
220
|
+
*/
|
|
221
|
+
function rewriteSpec(spec, origin, ver, relBase) {
|
|
222
|
+
void ver;
|
|
223
|
+
// Strip Vite cache-busting query params for bridge URLs
|
|
224
|
+
const cleanSpec = spec.split('?')[0];
|
|
225
|
+
// @nativescript/core anywhere in the path → core bridge.
|
|
226
|
+
// Delegated to the ONE canonical URL generator to guarantee that
|
|
227
|
+
// every emitter — this function, the ns-core-external-urls plugin,
|
|
228
|
+
// main-entry's coreSpec, and the runtime import map — produces
|
|
229
|
+
// byte-identical URLs for the same logical module. Mixed forms
|
|
230
|
+
// (query `?p=`, versioned, `.js` suffix) would otherwise produce
|
|
231
|
+
// distinct iOS HTTP ESM cache entries for the same file,
|
|
232
|
+
// re-evaluating register() side effects and crashing on "Cannot
|
|
233
|
+
// redefine property".
|
|
234
|
+
const coreIdx = cleanSpec.indexOf('@nativescript/core');
|
|
235
|
+
if (coreIdx !== -1) {
|
|
236
|
+
const after = cleanSpec.substring(coreIdx + '@nativescript/core'.length);
|
|
237
|
+
return buildCoreUrlPath(after);
|
|
238
|
+
}
|
|
239
|
+
// Already-canonicalised bridge URLs deserve a second look — a
|
|
240
|
+
// `/ns/core/<sub>` URL with a stale platform suffix (`.ios`),
|
|
241
|
+
// trailing `/index`, or `.js` extension would survive this pass
|
|
242
|
+
// but be 301-redirected by the bridge handler at runtime, costing
|
|
243
|
+
// an extra round-trip and risking double-evaluation if iOS caches
|
|
244
|
+
// both spellings. Run any `/ns/core/...` (or full-origin variant)
|
|
245
|
+
// back through `buildCoreUrlPath` so the rewriter is the
|
|
246
|
+
// single point that produces canonical core URLs for the device.
|
|
247
|
+
const coreBridgePathOnly = cleanSpec.match(/^\/ns\/core(?:\/[^?#]*)?$/);
|
|
248
|
+
if (coreBridgePathOnly) {
|
|
249
|
+
const sub = cleanSpec.replace(/^\/ns\/core\/?/, '');
|
|
250
|
+
return buildCoreUrlPath(sub);
|
|
251
|
+
}
|
|
252
|
+
const coreBridgeWithOrigin = cleanSpec.match(/^https?:\/\/[^/]+\/ns\/core(?:\/[^?#]*)?$/);
|
|
253
|
+
if (coreBridgeWithOrigin) {
|
|
254
|
+
const sub = cleanSpec.replace(/^https?:\/\/[^/]+\/ns\/core\/?/, '');
|
|
255
|
+
const canonicalPath = buildCoreUrlPath(sub);
|
|
256
|
+
const originPrefix = cleanSpec.replace(/\/ns\/core(?:\/.*)?$/, '');
|
|
257
|
+
return `${originPrefix}${canonicalPath}`;
|
|
258
|
+
}
|
|
259
|
+
// Already a bridge or HTTP URL → leave unchanged
|
|
260
|
+
if (spec.startsWith('/ns/') || spec.startsWith('http://') || spec.startsWith('https://')) {
|
|
261
|
+
return spec;
|
|
262
|
+
}
|
|
263
|
+
// Relative specifiers (`./x`, `../x`).
|
|
264
|
+
//
|
|
265
|
+
// Vite's import-analysis usually rewrites these to absolute IDs, but
|
|
266
|
+
// for files under `node_modules` it sometimes leaves them in place.
|
|
267
|
+
// When that happens AND the served URL has no trailing slash AND is
|
|
268
|
+
// itself a directory-index file (e.g. `…/layout-helper/index.android.ts`
|
|
269
|
+
// served at `/ns/core/utils/layout-helper`), V8's URL resolver treats
|
|
270
|
+
// `layout-helper` as the file and points `./layout-helper-common` at the
|
|
271
|
+
// non-existent sibling `/ns/core/utils/layout-helper-common`. Vite then
|
|
272
|
+
// 500s with "Failed to load url … Does the file exist?" and the
|
|
273
|
+
// dependent module never finishes evaluating.
|
|
274
|
+
//
|
|
275
|
+
// When `relBase` is supplied we resolve the specifier server-side and
|
|
276
|
+
// emit a canonical absolute `/ns/core/<resolved>` URL so the device
|
|
277
|
+
// cannot guess wrong. Falling back to the unchanged relative path
|
|
278
|
+
// preserves legacy behaviour for callers that don't (yet) thread
|
|
279
|
+
// `relBase` through.
|
|
280
|
+
if (spec.startsWith('./') || spec.startsWith('../')) {
|
|
281
|
+
if (relBase) {
|
|
282
|
+
const resolvedSub = resolveRelativeCoreSub(spec, relBase);
|
|
283
|
+
if (resolvedSub !== null) {
|
|
284
|
+
return buildCoreUrlPath(resolvedSub);
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
return spec;
|
|
288
|
+
}
|
|
289
|
+
// Root-relative paths → HTTP URL through /ns/m/ handler
|
|
290
|
+
if (spec.startsWith('/')) {
|
|
291
|
+
return `${origin}/ns/m${spec}`;
|
|
292
|
+
}
|
|
293
|
+
// Bare package specifier (e.g. `source-map-js/lib/source-map-generator.js`)
|
|
294
|
+
// → HTTP URL through /ns/m/node_modules/ handler. Under HMR bundle-build,
|
|
295
|
+
// @nativescript/core subpath modules served by this bridge (e.g.
|
|
296
|
+
// /ns/core?p=inspector_modules) may reference other npm packages with bare
|
|
297
|
+
// specifiers in their transformed output — specifically, the CommonJS
|
|
298
|
+
// compat transformer for source-map-js rewrites `require('./lib/source-
|
|
299
|
+
// map-generator')` into `import from 'source-map-js/lib/source-map-
|
|
300
|
+
// generator.js'`, a bare specifier that iOS's ESM loader cannot resolve at
|
|
301
|
+
// module-instantiation time (the runtime import map isn't installed yet).
|
|
302
|
+
// Converting to /ns/m/node_modules/<spec> makes iOS fetch the package over
|
|
303
|
+
// HTTP, which Vite serves through the same pipeline that already handles
|
|
304
|
+
// every other node_modules subpath import in the app.
|
|
305
|
+
return `${origin}/ns/m/node_modules/${spec}`;
|
|
306
|
+
}
|
|
307
|
+
/**
|
|
308
|
+
* Minimal specifier rewriter for deep subpath core modules.
|
|
309
|
+
*
|
|
310
|
+
* Takes Vite's correctly-transformed ESM output and ONLY rewrites the
|
|
311
|
+
* specifier strings inside import/export clauses. Does NOT:
|
|
312
|
+
* - Inject global defines
|
|
313
|
+
* - Run AST normalization
|
|
314
|
+
* - Convert named imports to default + destructure
|
|
315
|
+
* - Mangle newlines or code structure
|
|
316
|
+
*
|
|
317
|
+
* This replaces the heavy 5-pass pipeline (processCodeForDevice →
|
|
318
|
+
* rewriteImports → deduplicateLinkerImports → CJS wrapping → etc.)
|
|
319
|
+
* for deep subpath core modules where Vite already produces correct ESM.
|
|
320
|
+
*
|
|
321
|
+
* When `relBase` is supplied, relative specifiers (`./x`, `../x`) are
|
|
322
|
+
* resolved server-side into canonical `/ns/core/<resolved>` URLs so the
|
|
323
|
+
* device never has to guess where a directory-index file's siblings live.
|
|
324
|
+
* See `RelativeBase` and `rewriteSpec` for the full rationale.
|
|
325
|
+
*/
|
|
326
|
+
export function rewriteSpecifiersForDevice(code, origin, ver, relBase) {
|
|
327
|
+
if (!code)
|
|
328
|
+
return code;
|
|
329
|
+
let result = code;
|
|
330
|
+
// Pattern 1: from "specifier" — covers all static import/export forms
|
|
331
|
+
// import { X } from "spec"
|
|
332
|
+
// import X from "spec"
|
|
333
|
+
// import * as X from "spec"
|
|
334
|
+
// export { X } from "spec"
|
|
335
|
+
// export * from "spec"
|
|
336
|
+
//
|
|
337
|
+
// The lookbehind guard below ensures we only match `from` at the start of
|
|
338
|
+
// its ESM-keyword context, not `from` appearing INSIDE a string literal
|
|
339
|
+
// (e.g. `if (time === 'from') { … }` in @nativescript/core's
|
|
340
|
+
// css-animation-parser). Without this guard the regex spans from the
|
|
341
|
+
// `from` inside the string to the NEXT quote elsewhere in the file,
|
|
342
|
+
// corrupting both tokens.
|
|
343
|
+
result = result.replace(/(?<![a-zA-Z0-9_$'"`])(from\s+)(["'])([^"']+)\2/g, (_m, pre, q, spec) => {
|
|
344
|
+
return `${pre}${q}${rewriteSpec(spec, origin, ver, relBase)}${q}`;
|
|
345
|
+
});
|
|
346
|
+
// Pattern 2: import("specifier") — dynamic imports
|
|
347
|
+
result = result.replace(/(import\s*\(\s*)(["'])([^"']+)\2(\s*\))/g, (_m, pre, q, spec, post) => {
|
|
348
|
+
return `${pre}${q}${rewriteSpec(spec, origin, ver, relBase)}${q}${post}`;
|
|
349
|
+
});
|
|
350
|
+
// Pattern 3: import "specifier" — side-effect imports (no from clause)
|
|
351
|
+
// Anchored after start-of-string, newline, or semicolon to avoid false matches.
|
|
352
|
+
// The `^` alternative is critical: when a transformed module's body begins
|
|
353
|
+
// with a side-effect import (no preceding `;` or `\n`), the legacy
|
|
354
|
+
// `[;\n]`-only anchor missed it and the URL leaked to the device unmodified.
|
|
355
|
+
// Concrete failure mode: `/ns/core/inspector_modules` whose first body line
|
|
356
|
+
// `import '/@fs/.../@nativescript/core/globals/index.js';` was served raw,
|
|
357
|
+
// producing a `__DEV__ is not defined` ReferenceError in `platform-check.js`
|
|
358
|
+
// because `/@fs/` URLs bypass the `/ns/core` bridge's define-injection.
|
|
359
|
+
result = result.replace(/(^|[;\n])(\s*import\s+)(["'])([^"']+)\3/g, (_m, lead, pre, q, spec) => {
|
|
360
|
+
// Skip if it looks like an identifier rather than a path
|
|
361
|
+
if (!/[/.@]/.test(spec))
|
|
362
|
+
return _m;
|
|
363
|
+
return `${lead}${pre}${q}${rewriteSpec(spec, origin, ver, relBase)}${q}`;
|
|
364
|
+
});
|
|
365
|
+
return result;
|
|
366
|
+
}
|
|
367
|
+
/**
|
|
368
|
+
* Determine whether a `/ns/core` bridge URL points to a real subpath module.
|
|
369
|
+
*
|
|
370
|
+
* Any `/ns/core/<sub>` module now serves real ESM content with real named
|
|
371
|
+
* exports via Vite's transform pipeline, except for package-main aliases like
|
|
372
|
+
* `/ns/core/index`, which should be treated like the main `/ns/core`
|
|
373
|
+
* bridge and destructured from its default export.
|
|
374
|
+
* The main proxy bridge (`/ns/core`) still only exports a default Proxy and
|
|
375
|
+
* requires named imports to be destructured from it.
|
|
376
|
+
*
|
|
377
|
+
* This check is used in all named-import-to-default destructuring passes to
|
|
378
|
+
* skip rewriting for real subpath modules — they have named exports that work
|
|
379
|
+
* natively without conversion.
|
|
380
|
+
*/
|
|
381
|
+
export function isDeepCoreSubpath(url) {
|
|
382
|
+
if (!url || typeof url !== 'string')
|
|
383
|
+
return false;
|
|
384
|
+
const path = url.match(/\/ns\/core\/([^?#]+)/);
|
|
385
|
+
if (!path)
|
|
386
|
+
return false;
|
|
387
|
+
const sub = String(path[1] || '').replace(/^\/+|\/+$/g, '');
|
|
388
|
+
if (!sub || sub === 'index' || sub === 'index.js')
|
|
389
|
+
return false;
|
|
390
|
+
return true;
|
|
391
|
+
}
|
|
392
|
+
/**
|
|
393
|
+
* Synthesize a `default` export for an ESM module that only has named/star
|
|
394
|
+
* exports. Utility function — not currently called from the core bridge
|
|
395
|
+
* handler since `ensureDestructureCoreImports` now skips deep subpaths.
|
|
396
|
+
*
|
|
397
|
+
* Handles all three @nativescript/core patterns:
|
|
398
|
+
* 1. Direct declarations: export class X, export function Y, export const Z
|
|
399
|
+
* 2. Named re-exports: export { A, B } from '/path'
|
|
400
|
+
* 3. Star re-exports: export * from '/path'
|
|
401
|
+
*
|
|
402
|
+
* Returns the code unchanged if it already has a default export or CJS exports.
|
|
403
|
+
*/
|
|
404
|
+
export function synthesizeDefaultExport(moduleCode) {
|
|
405
|
+
if (!moduleCode || typeof moduleCode !== 'string')
|
|
406
|
+
return moduleCode;
|
|
407
|
+
const hasExportDefault = /\bexport\s+default\b/.test(moduleCode) || /export\s*\{\s*default\s*(?:as\s*default)?\s*\}/.test(moduleCode);
|
|
408
|
+
if (hasExportDefault)
|
|
409
|
+
return moduleCode;
|
|
410
|
+
const hasCjsExports = /\bmodule\s*\.\s*exports\b/.test(moduleCode) || /\bexports\s*\.\s*\w/.test(moduleCode);
|
|
411
|
+
if (hasCjsExports)
|
|
412
|
+
return moduleCode;
|
|
413
|
+
try {
|
|
414
|
+
const bindings = []; // [localName, exportedName]
|
|
415
|
+
const extraImports = [];
|
|
416
|
+
const starSpreads = [];
|
|
417
|
+
let sIdx = 0;
|
|
418
|
+
let m;
|
|
419
|
+
// export { A, b as B } [from 'src'] — handles both local and re-exports
|
|
420
|
+
const reBraces = /\bexport\s*\{([^}]+)\}\s*(?:from\s*["']([^"']+)["'])?/g;
|
|
421
|
+
while ((m = reBraces.exec(moduleCode)) !== null) {
|
|
422
|
+
const specList = m[1];
|
|
423
|
+
const fromSrc = m[2]; // undefined for local exports
|
|
424
|
+
const specs = specList
|
|
425
|
+
.split(',')
|
|
426
|
+
.map((s) => s.trim())
|
|
427
|
+
.filter(Boolean);
|
|
428
|
+
for (const spec of specs) {
|
|
429
|
+
const parts = spec.split(/\s+as\s+/);
|
|
430
|
+
const srcName = parts[0].trim();
|
|
431
|
+
const expName = parts.length > 1 ? parts[1].trim() : srcName;
|
|
432
|
+
if (!expName || expName === 'default')
|
|
433
|
+
continue;
|
|
434
|
+
// For re-exports, the local name is the exported name (from the import we add below)
|
|
435
|
+
// For local exports, the local name is srcName (already in scope)
|
|
436
|
+
bindings.push(fromSrc ? [expName, expName] : [srcName, expName]);
|
|
437
|
+
}
|
|
438
|
+
if (fromSrc) {
|
|
439
|
+
const importSpecs = specs
|
|
440
|
+
.map((spec) => {
|
|
441
|
+
const parts = spec.split(/\s+as\s+/);
|
|
442
|
+
const srcName = parts[0].trim();
|
|
443
|
+
const expName = parts.length > 1 ? parts[1].trim() : srcName;
|
|
444
|
+
if (!expName || expName === 'default')
|
|
445
|
+
return '';
|
|
446
|
+
return parts.length > 1 ? `${srcName} as ${expName}` : expName;
|
|
447
|
+
})
|
|
448
|
+
.filter(Boolean);
|
|
449
|
+
if (importSpecs.length) {
|
|
450
|
+
extraImports.push(`import { ${importSpecs.join(', ')} } from ${JSON.stringify(fromSrc)};`);
|
|
451
|
+
}
|
|
452
|
+
}
|
|
453
|
+
}
|
|
454
|
+
// export const/let/var X
|
|
455
|
+
const reDecl = /\bexport\s+(?:const|let|var)\s+([A-Za-z_$][\w$]*)/g;
|
|
456
|
+
while ((m = reDecl.exec(moduleCode)) !== null) {
|
|
457
|
+
bindings.push([m[1], m[1]]);
|
|
458
|
+
}
|
|
459
|
+
// export [async] function[*]/class X
|
|
460
|
+
const reFunc = /\bexport\s+(?:async\s+)?(?:function\s*\*?|class)\s+([A-Za-z_$][\w$]*)/g;
|
|
461
|
+
while ((m = reFunc.exec(moduleCode)) !== null) {
|
|
462
|
+
bindings.push([m[1], m[1]]);
|
|
463
|
+
}
|
|
464
|
+
// export * as X from 'src' (namespace re-export)
|
|
465
|
+
const reStarAs = /\bexport\s*\*\s*as\s+([A-Za-z_$][\w$]*)\s+from\s*["']([^"']+)["']/g;
|
|
466
|
+
while ((m = reStarAs.exec(moduleCode)) !== null) {
|
|
467
|
+
extraImports.push(`import * as ${m[1]} from ${JSON.stringify(m[2])};`);
|
|
468
|
+
bindings.push([m[1], m[1]]);
|
|
469
|
+
}
|
|
470
|
+
// export * from 'src' (bare star re-export, NOT 'export * as')
|
|
471
|
+
const reStarBare = /\bexport\s*\*\s*(?!as\s)from\s*["']([^"']+)["']/g;
|
|
472
|
+
while ((m = reStarBare.exec(moduleCode)) !== null) {
|
|
473
|
+
const v = `__ns_star_${sIdx++}`;
|
|
474
|
+
extraImports.push(`import * as ${v} from ${JSON.stringify(m[1])};`);
|
|
475
|
+
starSpreads.push(`...${v}`);
|
|
476
|
+
}
|
|
477
|
+
if (bindings.length > 0 || starSpreads.length > 0) {
|
|
478
|
+
const entries = [...starSpreads];
|
|
479
|
+
const seen = new Set();
|
|
480
|
+
for (const [local, exported] of bindings) {
|
|
481
|
+
if (seen.has(exported))
|
|
482
|
+
continue;
|
|
483
|
+
seen.add(exported);
|
|
484
|
+
entries.push(local === exported ? exported : `${JSON.stringify(exported)}: ${local}`);
|
|
485
|
+
}
|
|
486
|
+
const prefix = extraImports.length ? extraImports.join('\n') + '\n' : '';
|
|
487
|
+
return prefix + moduleCode + `\nvar __ns_default_export = { ${entries.join(', ')} };\nexport { __ns_default_export as default };\n`;
|
|
488
|
+
}
|
|
489
|
+
return moduleCode;
|
|
490
|
+
}
|
|
491
|
+
catch {
|
|
492
|
+
return moduleCode;
|
|
493
|
+
}
|
|
494
|
+
}
|
|
134
495
|
//# sourceMappingURL=core-sanitize.js.map
|