@nativescript/vite 8.0.0-alpha.6 → 8.0.0-alpha.60
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 +376 -165
- package/configuration/angular.js.map +1 -1
- package/configuration/base.js +244 -53
- 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-state.d.ts +8 -0
- package/helpers/app-css-state.js +8 -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 +4 -2
- 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/global-defines.d.ts +100 -13
- package/helpers/global-defines.js +149 -28
- 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 +368 -53
- package/helpers/main-entry.js.map +1 -1
- package/helpers/nativeclass-esbuild-plugin.d.ts +2 -1
- package/helpers/nativeclass-esbuild-plugin.js.map +1 -1
- package/helpers/nativeclass-transform.js +5 -6
- package/helpers/nativeclass-transform.js.map +1 -1
- package/helpers/nativeclass-transformer-plugin.d.ts +9 -2
- package/helpers/nativeclass-transformer-plugin.js +157 -14
- 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-url.d.ts +29 -7
- package/helpers/ns-core-url.js +69 -12
- 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 +2 -2
- 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 +20 -19
- package/helpers/workers.js +624 -4
- package/helpers/workers.js.map +1 -1
- package/hmr/client/css-handler.d.ts +2 -1
- package/hmr/client/css-handler.js +50 -26
- 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 +79 -0
- package/hmr/client/framework-client-strategy.js +19 -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 +14 -4
- 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 +284 -0
- package/hmr/client/hot-context.js.map +1 -0
- package/hmr/client/index.js +922 -273
- package/hmr/client/index.js.map +1 -1
- package/hmr/client/utils.d.ts +2 -1
- package/hmr/client/utils.js +111 -99
- package/hmr/client/utils.js.map +1 -1
- package/hmr/entry-runtime.d.ts +2 -1
- package/hmr/entry-runtime.js +271 -69
- 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 +109 -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/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/{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/client/index.js +542 -175
- 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/strategy.js +458 -12
- 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 +14 -11
- package/hmr/{server → frameworks/angular/server}/websocket-angular-hot-update.js +108 -111
- package/hmr/frameworks/angular/server/websocket-angular-hot-update.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 +246 -0
- package/hmr/frameworks/solid/client/app-runtime.js.map +1 -0
- package/hmr/frameworks/solid/server/strategy.js +291 -16
- package/hmr/frameworks/solid/server/strategy.js.map +1 -1
- package/hmr/frameworks/typescript/server/strategy.js +38 -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 +9 -0
- package/hmr/frameworks/vue/client/index.js +251 -247
- package/hmr/frameworks/vue/client/index.js.map +1 -1
- package/hmr/frameworks/vue/client/strategy.d.ts +33 -0
- package/hmr/frameworks/vue/client/strategy.js +157 -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 +142 -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 +286 -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 +77 -10
- 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-archive-route.d.ts +40 -0
- package/hmr/server/boot-archive-route.js +154 -0
- package/hmr/server/boot-archive-route.js.map +1 -0
- package/hmr/server/boot-closure-route.d.ts +49 -0
- package/hmr/server/boot-closure-route.js +144 -0
- package/hmr/server/boot-closure-route.js.map +1 -0
- package/hmr/server/boot-recording.d.ts +58 -0
- package/hmr/server/boot-recording.js +228 -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/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 +170 -45
- package/hmr/server/core-sanitize.js.map +1 -1
- 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/deps-bundle.d.ts +218 -0
- package/hmr/server/deps-bundle.js +984 -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 +113 -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 +13 -4
- package/hmr/server/import-map.js +94 -47
- 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/ns-core-cjs-shape.d.ts +2 -4
- package/hmr/server/ns-core-cjs-shape.js +4 -6
- 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 +6 -10
- package/hmr/server/perf-instrumentation.js +5 -6
- package/hmr/server/perf-instrumentation.js.map +1 -1
- package/hmr/server/process-code-for-device.d.ts +30 -0
- package/hmr/server/process-code-for-device.js +791 -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 +630 -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/server-origin.d.ts +2 -0
- package/hmr/server/server-origin.js +83 -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/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 +180 -54
- 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 -54
- package/hmr/server/websocket-core-bridge.js.map +1 -1
- package/hmr/server/websocket-css-hot-update.d.ts +33 -0
- package/hmr/server/websocket-css-hot-update.js +65 -0
- package/hmr/server/websocket-css-hot-update.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-hmr-pending.d.ts +3 -9
- package/hmr/server/websocket-hmr-pending.js +1 -1
- package/hmr/server/websocket-hmr-pending.js.map +1 -1
- package/hmr/server/websocket-hot-update.d.ts +77 -0
- package/hmr/server/websocket-hot-update.js +360 -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 +50 -0
- package/hmr/server/websocket-import-map-route.js.map +1 -0
- package/hmr/server/websocket-module-bindings.js +3 -3
- package/hmr/server/websocket-module-bindings.js.map +1 -1
- package/hmr/server/websocket-module-specifiers.d.ts +66 -2
- package/hmr/server/websocket-module-specifiers.js +191 -20
- 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 +1 -3
- package/hmr/server/websocket-ns-m-paths.js +25 -82
- package/hmr/server/websocket-ns-m-paths.js.map +1 -1
- package/hmr/server/websocket-ns-m-request.d.ts +11 -1
- package/hmr/server/websocket-ns-m-request.js +17 -9
- 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 +824 -0
- package/hmr/server/websocket-ns-m.js.map +1 -0
- package/hmr/server/websocket-served-module-helpers.d.ts +50 -4
- package/hmr/server/websocket-served-module-helpers.js +384 -86
- 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 -39
- package/hmr/server/websocket.js +643 -6716
- package/hmr/server/websocket.js.map +1 -1
- package/hmr/shared/ns-globals.d.ts +108 -0
- package/hmr/shared/ns-globals.js +28 -0
- package/hmr/shared/ns-globals.js.map +1 -0
- package/hmr/shared/protocol.d.ts +145 -0
- package/hmr/shared/protocol.js +28 -0
- package/hmr/shared/protocol.js.map +1 -0
- package/hmr/shared/runtime/boot-archive-format.d.ts +16 -0
- package/hmr/shared/runtime/boot-archive-format.js +31 -0
- package/hmr/shared/runtime/boot-archive-format.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 +2 -1
- package/hmr/shared/runtime/boot-timeline.js +9 -22
- package/hmr/shared/runtime/boot-timeline.js.map +1 -1
- package/hmr/shared/runtime/browser-runtime-contract.d.ts +53 -22
- package/hmr/shared/runtime/browser-runtime-contract.js +6 -9
- package/hmr/shared/runtime/browser-runtime-contract.js.map +1 -1
- 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.d.ts +76 -30
- package/hmr/shared/runtime/dev-overlay.js +767 -408
- 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/http-only-boot.js +7 -6
- package/hmr/shared/runtime/http-only-boot.js.map +1 -1
- package/hmr/shared/runtime/module-provenance.js +4 -6
- package/hmr/shared/runtime/module-provenance.js.map +1 -1
- 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 +398 -204
- package/hmr/shared/runtime/root-placeholder.js.map +1 -1
- package/hmr/shared/runtime/session-bootstrap.js +255 -50
- 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/vendor/manifest-collect.d.ts +4 -0
- package/hmr/shared/vendor/manifest-collect.js +549 -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 +1 -7
- package/hmr/shared/vendor/manifest.js +125 -825
- 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 +38 -0
- package/hmr/shared/vendor/vendor-esbuild-plugins.js +296 -0
- package/hmr/shared/vendor/vendor-esbuild-plugins.js.map +1 -0
- package/hmr/vendor-bootstrap.d.ts +1 -3
- package/hmr/vendor-bootstrap.js +4 -6
- package/hmr/vendor-bootstrap.js.map +1 -1
- package/index.d.ts +1 -0
- package/index.js +5 -0
- package/index.js.map +1 -1
- package/package.json +65 -11
- package/runtime/core-aliases-early.js +25 -55
- 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/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 -286
- 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/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
|
@@ -0,0 +1,824 @@
|
|
|
1
|
+
import * as path from 'path';
|
|
2
|
+
import { parse as babelParse } from '@babel/parser';
|
|
3
|
+
import traverse from '@babel/traverse';
|
|
4
|
+
import { sanitizeStrayCoreReferences } from './core-sanitize.js';
|
|
5
|
+
import { getMonorepoWorkspaceRoot } from '../../helpers/project.js';
|
|
6
|
+
import { isRuntimeGraphExcludedPath } from './runtime-graph-filter.js';
|
|
7
|
+
import { buildPiniaVendorShim, buildVueVendorShim } from './vendor-bare-module-shims.js';
|
|
8
|
+
import { canonicalizeNsMImportPath } from './websocket-ns-m-paths.js';
|
|
9
|
+
import { setDeviceModuleHeaders } from './route-helpers.js';
|
|
10
|
+
import { CSS_MODULE_RE, buildCssRegisterSnippetFromVar, normalizeCssForDevice } from './css-device-module.js';
|
|
11
|
+
import { filterExistingNodeModulesTransformCandidates, getBlockedDeviceNodeModulesReason, resolveCandidateFilePath, stripDecoratedServePrefixes, tryReadRawExplicitJavaScriptModule } from './websocket-module-specifiers.js';
|
|
12
|
+
import { assertNoOptimizedArtifacts, buildBootProgressSnippet, canonicalizeRtImports, classifyServedModule, dedupeRtNamedImportsAgainstDestructures, deduplicateLinkerImports, ensureDestructureCoreImports, ensureGuardPlainDynamicImports, ensureVariableDynamicImportHelper, expandStarExports, hoistTopLevelStaticImports, MODULE_IMPORT_ANALYSIS_PLUGINS, wrapCommonJsModuleForDevice } from './websocket-served-module-helpers.js';
|
|
13
|
+
import { cleanCode, collectImportDependencies, processCodeForDevice, rewriteImports } from './websocket-device-transform.js';
|
|
14
|
+
import { REQUIRE_GUARD_SNIPPET } from './require-guard.js';
|
|
15
|
+
import { getServerOrigin } from './server-origin.js';
|
|
16
|
+
import { createNsMResponseMemo } from './ns-m-response-memo.js';
|
|
17
|
+
import { getSharedDepsBundleService, registerDepsBundleRoute } from './deps-bundle.js';
|
|
18
|
+
const babelTraverse = traverse?.default || traverse;
|
|
19
|
+
// Minimal valid ESM body for "no component update available": the iOS HTTP
|
|
20
|
+
// ESM loader (`LoadHttpModuleForUrl`) rejects empty bodies even on HTTP 200,
|
|
21
|
+
// so an actual empty response would crash the component's `_HmrLoad` import.
|
|
22
|
+
const NG_COMPONENT_NO_UPDATE_STUB = '// [ns:m] no Angular component update for this request — substituted with valid empty module to satisfy iOS HTTP loader (rejects empty bodies)\nexport {};\n';
|
|
23
|
+
/**
|
|
24
|
+
* Registers the `/ns/m/*` device module server: the HTTP endpoint every
|
|
25
|
+
* NativeScript device uses to fetch app/source modules (and AnalogJS Angular
|
|
26
|
+
* `/@ng/component` live-reload requests) as device-ready ESM. This is the
|
|
27
|
+
* single hottest route in the HMR server.
|
|
28
|
+
*/
|
|
29
|
+
export function registerNsModuleServerRoute(server, options) {
|
|
30
|
+
// Final-response memo: repeat serves of an unchanged module (app restarts,
|
|
31
|
+
// the boot-archive build, kickstart waves) skip the whole post-processing
|
|
32
|
+
// pipeline. Keyed by a hash of Vite's transform output, so HMR edits
|
|
33
|
+
// invalidate implicitly. `NS_VITE_HMR_DISABLE_NSM_MEMO=1` opts out.
|
|
34
|
+
const memoDisabled = process.env.NS_VITE_HMR_DISABLE_NSM_MEMO === '1' || process.env.NS_VITE_HMR_DISABLE_NSM_MEMO === 'true';
|
|
35
|
+
const responseMemo = createNsMResponseMemo();
|
|
36
|
+
// Deps bundle (see deps-bundle.ts): once a boot recording exists, the
|
|
37
|
+
// recorded node_modules closure is served as ONE esbuild payload and the
|
|
38
|
+
// canonical /ns/m/node_modules/... URLs become thin registry shims.
|
|
39
|
+
const depsBundle = options.depsBundle !== undefined ? options.depsBundle : getSharedDepsBundleService(server);
|
|
40
|
+
if (depsBundle) {
|
|
41
|
+
registerDepsBundleRoute(server, depsBundle);
|
|
42
|
+
}
|
|
43
|
+
server.middlewares.use(async (req, res, next) => {
|
|
44
|
+
try {
|
|
45
|
+
const urlObj = new URL(req.url || '', 'http://localhost');
|
|
46
|
+
if (!urlObj.pathname.startsWith('/ns/m'))
|
|
47
|
+
return next();
|
|
48
|
+
// Closure deps injected by createHmrWebSocketPlugin (see websocket.ts).
|
|
49
|
+
const verbose = options.verbose;
|
|
50
|
+
const APP_VIRTUAL_WITH_SLASH = options.appVirtualWithSlash;
|
|
51
|
+
const sfcFileMap = options.sfcFileMap;
|
|
52
|
+
const depFileMap = options.depFileMap;
|
|
53
|
+
const sharedTransformRequest = options.sharedTransformRequest;
|
|
54
|
+
const ensureInitialGraphPopulationStarted = options.ensureInitialGraphPopulationStarted;
|
|
55
|
+
const strategy = options.getStrategy();
|
|
56
|
+
// Delegate AnalogJS Angular component live-reload endpoints.
|
|
57
|
+
//
|
|
58
|
+
// Angular 21's `ɵɵgetReplaceMetadataURL` (in @angular/core
|
|
59
|
+
// _debug_node-chunk.mjs) builds the metadata-replacement URL as
|
|
60
|
+
// `new URL('./@ng/component?c=<id>&t=<ts>', import.meta.url).href`.
|
|
61
|
+
// Because `import.meta.url` for a NS-served module is
|
|
62
|
+
// `http://host:port/ns/m/<project-relative>/component.ts`, the
|
|
63
|
+
// resolved metadata URL ends up *nested* under the component's
|
|
64
|
+
// directory: `/ns/m/<dir>/@ng/component?c=...&t=...`.
|
|
65
|
+
//
|
|
66
|
+
// AnalogJS's `liveReloadPlugin` registers a middleware that matches
|
|
67
|
+
// `/@ng/component` anywhere in `req.url` and returns either an empty
|
|
68
|
+
// module body (no HMR update available) or the metadata-replacement
|
|
69
|
+
// code (after a save invalidates the file). Without this delegation
|
|
70
|
+
// the NS `/ns/m/` middleware would treat the path as a file lookup,
|
|
71
|
+
// fail to resolve `@ng/component` against disk, and respond with
|
|
72
|
+
// 404 — which surfaces as `HTTP fetch/compile failed` at the
|
|
73
|
+
// component's own `_HmrLoad(Date.now())` call on initial boot and
|
|
74
|
+
// blocks Angular component bootstrapping.
|
|
75
|
+
//
|
|
76
|
+
// Calling `next()` here lets AnalogJS's middleware (or any other
|
|
77
|
+
// middleware later in the chain) handle the request. Analog's
|
|
78
|
+
// middleware reads only the `?c=` query string and is pathname-
|
|
79
|
+
// agnostic, so we don't need to rewrite `req.url` for it to work.
|
|
80
|
+
//
|
|
81
|
+
// HOWEVER: AnalogJS responds with an EMPTY body (`res.end('')`)
|
|
82
|
+
// for non-invalidated component IDs (initial boot, before any
|
|
83
|
+
// file save). The iOS HTTP ESM loader's
|
|
84
|
+
// `LoadHttpModuleForUrl` (ModuleInternalCallbacks.mm) treats an
|
|
85
|
+
// empty body as a fetch failure (`body.empty() → reject`), even
|
|
86
|
+
// when the HTTP status is 200 OK. That bubbles up as
|
|
87
|
+
// `HTTP fetch/compile failed` at the device's `__ns_import(...)`
|
|
88
|
+
// inside each component's `_HmrLoad(Date.now())` and crashes
|
|
89
|
+
// Angular's component bootstrap. To make Analog's empty
|
|
90
|
+
// "no-update" response acceptable to the iOS loader, we wrap
|
|
91
|
+
// `res.write` / `res.end` and substitute a minimal valid ESM
|
|
92
|
+
// module body (`export {}`) when downstream writes nothing.
|
|
93
|
+
// Non-empty bodies (real HMR update payloads after a save)
|
|
94
|
+
// pass through unchanged.
|
|
95
|
+
if (urlObj.pathname.includes('/@ng/component')) {
|
|
96
|
+
// Boot-fetch gate: every compiled component runs
|
|
97
|
+
// `<Class>_HmrLoad(Date.now())` on evaluation, so every cold
|
|
98
|
+
// boot hits this route for every component. Analog serves a
|
|
99
|
+
// REAL metadata-replacement payload whenever the component's
|
|
100
|
+
// module was invalidated at any point in the dev server's
|
|
101
|
+
// lifetime (Vite's `lastInvalidationTimestamp` never resets),
|
|
102
|
+
// and a boot-time `ɵɵreplaceMetadata` on the root component
|
|
103
|
+
// tears down the PageRouterOutlet frame — the "relaunch after
|
|
104
|
+
// an HMR edit → white screen" failure. Only fetches echoing a
|
|
105
|
+
// forwarded `angular:component-update` broadcast's exact
|
|
106
|
+
// `(id, t)` pair may reach Analog; a fresh boot already
|
|
107
|
+
// evaluates the latest transformed source and never needs a
|
|
108
|
+
// replacement payload.
|
|
109
|
+
const isLiveUpdateFetch = options.isLiveAngularComponentUpdateFetch;
|
|
110
|
+
if (isLiveUpdateFetch) {
|
|
111
|
+
const componentId = urlObj.searchParams.get('c') || '';
|
|
112
|
+
const timestampRaw = urlObj.searchParams.get('t');
|
|
113
|
+
// `Number(null)` is 0 — require an actual `t` param.
|
|
114
|
+
const timestamp = timestampRaw ? Number(timestampRaw) : NaN;
|
|
115
|
+
if (!componentId || !Number.isFinite(timestamp) || !isLiveUpdateFetch(componentId, timestamp)) {
|
|
116
|
+
res.statusCode = 200;
|
|
117
|
+
res.setHeader('Content-Type', 'text/javascript');
|
|
118
|
+
res.setHeader('Cache-Control', 'no-cache');
|
|
119
|
+
res.end(NG_COMPONENT_NO_UPDATE_STUB);
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
const chunks = [];
|
|
124
|
+
const origEnd = res.end.bind(res);
|
|
125
|
+
let ended = false;
|
|
126
|
+
const captureChunk = (chunk) => {
|
|
127
|
+
if (chunk == null)
|
|
128
|
+
return;
|
|
129
|
+
if (typeof chunk === 'string') {
|
|
130
|
+
chunks.push(chunk);
|
|
131
|
+
}
|
|
132
|
+
else if (Buffer.isBuffer(chunk)) {
|
|
133
|
+
chunks.push(chunk.toString('utf8'));
|
|
134
|
+
}
|
|
135
|
+
else {
|
|
136
|
+
chunks.push(String(chunk));
|
|
137
|
+
}
|
|
138
|
+
};
|
|
139
|
+
res.write = function (chunk, ..._args) {
|
|
140
|
+
captureChunk(chunk);
|
|
141
|
+
return true;
|
|
142
|
+
};
|
|
143
|
+
res.end = function (chunk, ..._args) {
|
|
144
|
+
if (ended)
|
|
145
|
+
return true;
|
|
146
|
+
ended = true;
|
|
147
|
+
captureChunk(chunk);
|
|
148
|
+
let body = chunks.join('');
|
|
149
|
+
if (body.length === 0) {
|
|
150
|
+
body = NG_COMPONENT_NO_UPDATE_STUB;
|
|
151
|
+
}
|
|
152
|
+
try {
|
|
153
|
+
res.setHeader('Content-Length', Buffer.byteLength(body, 'utf8'));
|
|
154
|
+
}
|
|
155
|
+
catch { }
|
|
156
|
+
return origEnd(body);
|
|
157
|
+
};
|
|
158
|
+
return next();
|
|
159
|
+
}
|
|
160
|
+
// graphVersion starts at 1 and stays stable during cold boot (see
|
|
161
|
+
// `upsertGraphModule`'s bumpVersion option and the inline comment
|
|
162
|
+
// at the graphVersion declaration), so the initial population can
|
|
163
|
+
// run in the background without blocking the first response.
|
|
164
|
+
// `handleHotUpdate` awaits the same promise so the first HMR
|
|
165
|
+
// event still sees a fully populated graph.
|
|
166
|
+
ensureInitialGraphPopulationStarted(server);
|
|
167
|
+
// Cold-boot counting lives in the leading boot-trace middleware
|
|
168
|
+
// (see `configureServer` — it records the request and tracks
|
|
169
|
+
// finish() via res.on('close'/'finish')), not here: recording in
|
|
170
|
+
// this handler would miss the round-trip timing and per-route
|
|
171
|
+
// breakdowns.
|
|
172
|
+
setDeviceModuleHeaders(res);
|
|
173
|
+
// Support both query (?path=/abs) and path-style (/ns/m/abs)
|
|
174
|
+
let spec = urlObj.searchParams.get('path') || '';
|
|
175
|
+
if (!spec) {
|
|
176
|
+
const base = '/ns/m';
|
|
177
|
+
const rest = urlObj.pathname.slice(base.length);
|
|
178
|
+
if (rest && rest !== '/')
|
|
179
|
+
spec = rest;
|
|
180
|
+
}
|
|
181
|
+
// Special-case stub for anomalous '@' imports emitted as '/__invalid_at__.mjs'
|
|
182
|
+
if (spec === '/__invalid_at__.mjs' || spec === '__invalid_at__.mjs') {
|
|
183
|
+
res.statusCode = 200;
|
|
184
|
+
res.end("// invalid '@' import stub\nexport {}\n");
|
|
185
|
+
return;
|
|
186
|
+
}
|
|
187
|
+
if (!spec) {
|
|
188
|
+
res.statusCode = 200;
|
|
189
|
+
res.end('export {}\n');
|
|
190
|
+
return;
|
|
191
|
+
}
|
|
192
|
+
const serverRoot = (server.config?.root || process.cwd());
|
|
193
|
+
const monorepoWorkspaceRoot = getMonorepoWorkspaceRoot(serverRoot);
|
|
194
|
+
spec = spec.replace(/[?#].*$/, '');
|
|
195
|
+
// Tolerate LEGACY path-based boot/HMR prefixes from stale cached
|
|
196
|
+
// device code (`/ns/m/__ns_boot__/b1/…`, `/ns/m/__ns_hmr__/<tag>/…`).
|
|
197
|
+
// Current servers never emit them — freshness is eviction-driven.
|
|
198
|
+
try {
|
|
199
|
+
spec = stripDecoratedServePrefixes(spec).cleanedSpec;
|
|
200
|
+
}
|
|
201
|
+
catch { }
|
|
202
|
+
// Normalize absolute filesystem paths back to project-relative ids (e.g. /src/app.ts)
|
|
203
|
+
try {
|
|
204
|
+
const toPosix = (p) => p.replace(/\\/g, '/');
|
|
205
|
+
const rootPosix = toPosix(serverRoot);
|
|
206
|
+
const specPosix = toPosix(spec);
|
|
207
|
+
// If spec is an absolute path under the project root, convert to '/'+relative
|
|
208
|
+
const isAbsFs = /^\//.test(specPosix) || /^[A-Za-z]:\//.test(spec); // posix or win drive
|
|
209
|
+
if (isAbsFs) {
|
|
210
|
+
let rel = specPosix.startsWith(rootPosix) ? specPosix.slice(rootPosix.length) : require('path').posix.relative(rootPosix, specPosix);
|
|
211
|
+
if (!rel.startsWith('..')) {
|
|
212
|
+
if (!rel.startsWith('/'))
|
|
213
|
+
rel = '/' + rel;
|
|
214
|
+
// Ensure leading '/src' style when path maps into src
|
|
215
|
+
spec = rel;
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
catch { }
|
|
220
|
+
// Serve Vite virtual modules (/@id/ prefix). These are internal
|
|
221
|
+
// virtual modules (e.g., \0nsvite:nsconfig-json for ~/package.json)
|
|
222
|
+
// that don't exist on disk. Decode the ID and load via plugin container.
|
|
223
|
+
if (spec.startsWith('/@id/')) {
|
|
224
|
+
try {
|
|
225
|
+
// First try Vite's transform pipeline directly
|
|
226
|
+
const vr = await sharedTransformRequest(spec);
|
|
227
|
+
if (vr?.code) {
|
|
228
|
+
res.statusCode = 200;
|
|
229
|
+
res.end(vr.code);
|
|
230
|
+
return;
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
catch { }
|
|
234
|
+
try {
|
|
235
|
+
// Fallback: decode the virtual module ID (__x00__ → \0) and
|
|
236
|
+
// load through the plugin container directly
|
|
237
|
+
const rawId = spec.slice('/@id/'.length).replace(/__x00__/g, '\0');
|
|
238
|
+
const loadResult = await server.pluginContainer.load(rawId);
|
|
239
|
+
if (loadResult) {
|
|
240
|
+
const code = typeof loadResult === 'string' ? loadResult : loadResult.code;
|
|
241
|
+
if (code) {
|
|
242
|
+
res.statusCode = 200;
|
|
243
|
+
res.end(code);
|
|
244
|
+
return;
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
catch { }
|
|
249
|
+
}
|
|
250
|
+
if (spec.startsWith('@/'))
|
|
251
|
+
spec = APP_VIRTUAL_WITH_SLASH + spec.slice(2);
|
|
252
|
+
if (spec.startsWith('./'))
|
|
253
|
+
spec = spec.slice(1);
|
|
254
|
+
const blockedNodeModulesReason = getBlockedDeviceNodeModulesReason(spec);
|
|
255
|
+
if (blockedNodeModulesReason) {
|
|
256
|
+
res.statusCode = 404;
|
|
257
|
+
res.end(`// [ns:m] blocked device import\nthrow new Error(${JSON.stringify(`[ns/m] ${blockedNodeModulesReason}`)});\nexport {};\n`);
|
|
258
|
+
return;
|
|
259
|
+
}
|
|
260
|
+
if (!spec.startsWith('/'))
|
|
261
|
+
spec = '/' + spec;
|
|
262
|
+
// Deps-bundle shim short-circuit: a bundled node_modules module is
|
|
263
|
+
// served as a thin registry shim (see deps-bundle.ts) — the whole
|
|
264
|
+
// transform pipeline below is skipped. Non-bundled specs (no
|
|
265
|
+
// recording yet, CJS files, build failure) fall through unchanged.
|
|
266
|
+
if (depsBundle && spec.includes('/node_modules/')) {
|
|
267
|
+
const shim = depsBundle.getShimForSpec(spec);
|
|
268
|
+
if (shim) {
|
|
269
|
+
res.statusCode = 200;
|
|
270
|
+
res.end(shim);
|
|
271
|
+
return;
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
// A JS/TS `import './x.css'` reaches the device as a module request;
|
|
275
|
+
// Vite's default CSS module needs a DOM, so it's a no-op on NativeScript.
|
|
276
|
+
// Compile via `?inline` (full postcss/sass/@import, no DOM side effect),
|
|
277
|
+
// register the result under the file's root-relative tag (matches the
|
|
278
|
+
// `.css` live-edit tag so edits replace, not stack), and re-export the
|
|
279
|
+
// string for `import css from './x.css'`. `app.css` has its own path.
|
|
280
|
+
if (CSS_MODULE_RE.test(spec)) {
|
|
281
|
+
try {
|
|
282
|
+
const inlineRes = await sharedTransformRequest(`${spec}?inline`);
|
|
283
|
+
const inlineCode = inlineRes?.code || '';
|
|
284
|
+
// `?inline` output is `export default "<compiled css>"`.
|
|
285
|
+
const m = inlineCode.match(/export\s+default\s+("(?:[^"\\]|\\.)*")\s*;?/s);
|
|
286
|
+
if (m) {
|
|
287
|
+
let css = '';
|
|
288
|
+
try {
|
|
289
|
+
css = JSON.parse(m[1]);
|
|
290
|
+
}
|
|
291
|
+
catch { }
|
|
292
|
+
css = normalizeCssForDevice(css);
|
|
293
|
+
const out = `// [ns:m][css] ${spec}\n` + `const __ns_css_text__ = ${JSON.stringify(css)};\n` + buildCssRegisterSnippetFromVar(spec, '__ns_css_text__') + `export default __ns_css_text__;\n`;
|
|
294
|
+
res.statusCode = 200;
|
|
295
|
+
res.end(out);
|
|
296
|
+
return;
|
|
297
|
+
}
|
|
298
|
+
if (verbose)
|
|
299
|
+
console.warn('[ns:m][css] unexpected ?inline output shape for', spec);
|
|
300
|
+
}
|
|
301
|
+
catch (cssErr) {
|
|
302
|
+
if (verbose)
|
|
303
|
+
console.warn('[ns:m][css] inline compile failed', spec, cssErr?.message);
|
|
304
|
+
}
|
|
305
|
+
// Fall through to default handling if inline compile produced nothing.
|
|
306
|
+
}
|
|
307
|
+
const hasExt = /\.(ts|tsx|js|jsx|mjs|mts|cts|vue)$/i.test(spec);
|
|
308
|
+
const baseNoExt = hasExt ? spec.replace(/\.(ts|tsx|js|jsx|mjs|mts|cts)$/i, '') : spec;
|
|
309
|
+
const candidates = [...(hasExt ? [spec] : []), baseNoExt + '.ts', baseNoExt + '.js', baseNoExt + '.tsx', baseNoExt + '.jsx', baseNoExt + '.mjs', baseNoExt + '.mts', baseNoExt + '.cts', baseNoExt + '.vue', baseNoExt + '/index.ts', baseNoExt + '/index.js', baseNoExt + '/index.tsx', baseNoExt + '/index.jsx', baseNoExt + '/index.mjs'];
|
|
310
|
+
const transformCandidates = filterExistingNodeModulesTransformCandidates(spec, candidates, serverRoot, monorepoWorkspaceRoot);
|
|
311
|
+
let transformed = null;
|
|
312
|
+
let resolvedCandidate = null;
|
|
313
|
+
const rawExplicitModule = tryReadRawExplicitJavaScriptModule(spec, serverRoot);
|
|
314
|
+
if (rawExplicitModule) {
|
|
315
|
+
transformed = { code: rawExplicitModule.code };
|
|
316
|
+
resolvedCandidate = rawExplicitModule.resolvedId;
|
|
317
|
+
}
|
|
318
|
+
// Queue and dedupe transformRequest calls so heavy app graphs do not
|
|
319
|
+
// overwhelm Vite with concurrent work. Slow-transform warnings start only
|
|
320
|
+
// when the transform actually begins executing, and requests stay pending
|
|
321
|
+
// until Vite returns a real result.
|
|
322
|
+
const transformWithTimeout = (url, timeoutMs = 120000) => {
|
|
323
|
+
return sharedTransformRequest(url, timeoutMs);
|
|
324
|
+
};
|
|
325
|
+
if (!transformed?.code) {
|
|
326
|
+
for (const cand of transformCandidates) {
|
|
327
|
+
try {
|
|
328
|
+
const r = await transformWithTimeout(cand);
|
|
329
|
+
if (r?.code) {
|
|
330
|
+
transformed = r;
|
|
331
|
+
resolvedCandidate = cand;
|
|
332
|
+
break;
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
catch { }
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
// Fallback 1: ask Vite to resolve the id, then transform the resolved id (handles aliases and virtual ids)
|
|
339
|
+
if (!transformed?.code) {
|
|
340
|
+
try {
|
|
341
|
+
const rid = await server.pluginContainer?.resolveId?.(spec, undefined);
|
|
342
|
+
const ridStr = typeof rid === 'string' ? rid : rid?.id || null;
|
|
343
|
+
if (ridStr) {
|
|
344
|
+
const r = await transformWithTimeout(ridStr);
|
|
345
|
+
if (r?.code) {
|
|
346
|
+
transformed = r;
|
|
347
|
+
resolvedCandidate = ridStr;
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
catch { }
|
|
352
|
+
}
|
|
353
|
+
// Fallback 1b: if spec is a /node_modules/ path, extract bare specifier
|
|
354
|
+
// and try resolveId with that. This handles package.json "exports" field
|
|
355
|
+
// resolution (e.g., solid-js/jsx-runtime → solid-js/dist/solid.js).
|
|
356
|
+
if (!transformed?.code && spec.includes('/node_modules/')) {
|
|
357
|
+
try {
|
|
358
|
+
const nmIdx = spec.lastIndexOf('/node_modules/');
|
|
359
|
+
const bare = spec.slice(nmIdx + '/node_modules/'.length);
|
|
360
|
+
if (bare && !bare.startsWith('.')) {
|
|
361
|
+
const rid = await server.pluginContainer?.resolveId?.(bare, undefined);
|
|
362
|
+
const ridStr = typeof rid === 'string' ? rid : rid?.id || null;
|
|
363
|
+
if (ridStr) {
|
|
364
|
+
const r = await sharedTransformRequest(ridStr);
|
|
365
|
+
if (r?.code) {
|
|
366
|
+
transformed = r;
|
|
367
|
+
resolvedCandidate = ridStr;
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
catch { }
|
|
373
|
+
}
|
|
374
|
+
// Fallback 2: try /@fs absolute path under project root (Vite file system alias).
|
|
375
|
+
// In a monorepo with hoisted node_modules the file may live above
|
|
376
|
+
// `serverRoot`, so try the workspace root next.
|
|
377
|
+
if (!transformed?.code) {
|
|
378
|
+
try {
|
|
379
|
+
const toPosix = (p) => p.replace(/\\/g, '/');
|
|
380
|
+
const rootsToTry = [serverRoot, ...(monorepoWorkspaceRoot && path.resolve(monorepoWorkspaceRoot) !== path.resolve(serverRoot) ? [monorepoWorkspaceRoot] : [])];
|
|
381
|
+
for (const root of rootsToTry) {
|
|
382
|
+
const rootPosix = toPosix(root).replace(/\/$/, '');
|
|
383
|
+
const absPosix = `${rootPosix}${spec.startsWith('/') ? '' : '/'}${spec}`;
|
|
384
|
+
const fsId = `/@fs${absPosix}`;
|
|
385
|
+
if (resolveCandidateFilePath(fsId, serverRoot, monorepoWorkspaceRoot)) {
|
|
386
|
+
const r = await transformWithTimeout(fsId);
|
|
387
|
+
if (r?.code) {
|
|
388
|
+
transformed = r;
|
|
389
|
+
resolvedCandidate = fsId;
|
|
390
|
+
break;
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
catch { }
|
|
396
|
+
}
|
|
397
|
+
// Fallback 3: try adding ?import to hint Vite's transform pipeline
|
|
398
|
+
if (!transformed?.code) {
|
|
399
|
+
for (const cand of transformCandidates) {
|
|
400
|
+
try {
|
|
401
|
+
const r = await transformWithTimeout(`${cand}${cand.includes('?') ? '&' : '?'}import`);
|
|
402
|
+
if (r?.code) {
|
|
403
|
+
transformed = r;
|
|
404
|
+
resolvedCandidate = `${cand}?import`;
|
|
405
|
+
break;
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
catch { }
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
// Solid HMR: patch the served `@solid-refresh` runtime so $$refreshESM
|
|
412
|
+
// applies registry updates inline on module re-evaluation. The full
|
|
413
|
+
// patch (and its server-side diagnostics) lives in the Solid strategy's
|
|
414
|
+
// `transformNodeModule` hook; every other flavor leaves the hook
|
|
415
|
+
// undefined, so this is a no-op for them.
|
|
416
|
+
try {
|
|
417
|
+
if (transformed?.code && strategy?.transformNodeModule) {
|
|
418
|
+
const patched = strategy.transformNodeModule(transformed.code, resolvedCandidate || spec || '', verbose);
|
|
419
|
+
if (patched !== transformed.code) {
|
|
420
|
+
// Work on a copy to avoid mutating Vite's cached TransformResult
|
|
421
|
+
transformed = { ...transformed, code: patched };
|
|
422
|
+
}
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
catch { }
|
|
426
|
+
// NOTE: Path-based cache busting for /ns/m/* imports is applied in the
|
|
427
|
+
// finalize step below (after rewriteImports adds the /ns/m/ prefix).
|
|
428
|
+
// The block here only handles TypeScript-specific graph population.
|
|
429
|
+
try {
|
|
430
|
+
if (transformed?.code) {
|
|
431
|
+
const code = transformed.code;
|
|
432
|
+
// TypeScript-specific graph population: when TS flavor is active
|
|
433
|
+
// and this is an application module under the virtual app root,
|
|
434
|
+
// upsert it into the HMR graph so ns:hmr-full-graph is non-empty.
|
|
435
|
+
try {
|
|
436
|
+
if (strategy?.flavor === 'typescript' || strategy?.flavor === 'react') {
|
|
437
|
+
const id = (resolvedCandidate || spec).replace(/[?#].*$/, '');
|
|
438
|
+
// Only track app modules (under APP_VIRTUAL_WITH_SLASH) and ts/js/tsx/jsx/mjs.
|
|
439
|
+
const isApp = id.startsWith(APP_VIRTUAL_WITH_SLASH) || id.startsWith('/app/');
|
|
440
|
+
if (isApp && /\.(ts|tsx|js|jsx|mjs|mts|cts)$/i.test(id) && !isRuntimeGraphExcludedPath(id)) {
|
|
441
|
+
const deps = Array.from(collectImportDependencies(code, id));
|
|
442
|
+
if (verbose) {
|
|
443
|
+
console.log('[hmr-ws][ts-graph] candidate', { id, depsCount: deps.length });
|
|
444
|
+
}
|
|
445
|
+
// Serve-time warm-up: no live edit happened, so don't bump
|
|
446
|
+
// graphVersion.
|
|
447
|
+
options.upsertGraphModule(id, code, deps, { bumpVersion: false });
|
|
448
|
+
}
|
|
449
|
+
}
|
|
450
|
+
}
|
|
451
|
+
catch { }
|
|
452
|
+
}
|
|
453
|
+
}
|
|
454
|
+
catch { }
|
|
455
|
+
// If transformRequest failed, handle bare-module vendor shims for 'vue' and 'pinia'
|
|
456
|
+
if (!transformed?.code) {
|
|
457
|
+
const bare = spec.startsWith('/') ? spec.slice(1) : spec;
|
|
458
|
+
const isBare = bare && !bare.includes('/') && !/\.(ts|tsx|js|jsx|mjs|mts|cts|vue)$/i.test(bare);
|
|
459
|
+
if (isBare && (bare === 'vue' || bare === 'nativescript-vue' || bare === 'pinia')) {
|
|
460
|
+
const pkg = bare;
|
|
461
|
+
let code = '';
|
|
462
|
+
if (pkg === 'vue' || pkg === 'nativescript-vue') {
|
|
463
|
+
code = buildVueVendorShim(pkg);
|
|
464
|
+
}
|
|
465
|
+
else if (pkg === 'pinia') {
|
|
466
|
+
code = buildPiniaVendorShim();
|
|
467
|
+
}
|
|
468
|
+
res.statusCode = 200;
|
|
469
|
+
res.end(code || 'export {}\n');
|
|
470
|
+
return;
|
|
471
|
+
}
|
|
472
|
+
// Generic bare module resolution via Vite plugin container
|
|
473
|
+
if (isBare) {
|
|
474
|
+
try {
|
|
475
|
+
const resolved = await server.pluginContainer?.resolveId?.(spec, undefined);
|
|
476
|
+
const resolvedId = typeof resolved === 'string' ? resolved : resolved?.id || null;
|
|
477
|
+
if (resolvedId) {
|
|
478
|
+
const r = await server.transformRequest(resolvedId);
|
|
479
|
+
if (r?.code) {
|
|
480
|
+
transformed = r;
|
|
481
|
+
resolvedCandidate = resolvedId;
|
|
482
|
+
}
|
|
483
|
+
}
|
|
484
|
+
}
|
|
485
|
+
catch { }
|
|
486
|
+
}
|
|
487
|
+
if (!transformed?.code) {
|
|
488
|
+
// Emit a module that throws with context for easier on-device debugging
|
|
489
|
+
try {
|
|
490
|
+
const tried = Array.from(new Set(transformCandidates.length > 0 ? transformCandidates : candidates)).slice(0, 12);
|
|
491
|
+
const out = `// [ns:m] transform miss path=${spec} tried=${tried.length}\n` + `throw new Error(${JSON.stringify(`[ns/m] transform failed for ${spec} (tried ${tried.length} candidates).`)});\nexport {};\n`;
|
|
492
|
+
res.statusCode = 404;
|
|
493
|
+
res.end(out);
|
|
494
|
+
return;
|
|
495
|
+
}
|
|
496
|
+
catch {
|
|
497
|
+
res.statusCode = 404;
|
|
498
|
+
res.end('export {}\n');
|
|
499
|
+
return;
|
|
500
|
+
}
|
|
501
|
+
}
|
|
502
|
+
}
|
|
503
|
+
// Final-response memo (see ns-m-response-memo.ts): identical
|
|
504
|
+
// (spec, transform output, context) → identical served body, so repeat
|
|
505
|
+
// serves skip the post-processing pipeline. The graph version in the
|
|
506
|
+
// context conservatively invalidates on any live edit — star-export
|
|
507
|
+
// expansion and the link-check read other modules, so this module's
|
|
508
|
+
// own transform hash is not sufficient.
|
|
509
|
+
const memoContext = `${strategy?.flavor || ''}|${getServerOrigin(server)}|${options.getGraphVersion()}|${resolvedCandidate || ''}`;
|
|
510
|
+
const memoKey = memoDisabled ? null : responseMemo.buildKey(spec, transformed.code, memoContext);
|
|
511
|
+
if (memoKey) {
|
|
512
|
+
const memoized = responseMemo.get(memoKey);
|
|
513
|
+
if (memoized !== undefined) {
|
|
514
|
+
res.statusCode = 200;
|
|
515
|
+
res.end(memoized);
|
|
516
|
+
return;
|
|
517
|
+
}
|
|
518
|
+
}
|
|
519
|
+
let code = transformed.code;
|
|
520
|
+
// Prepend guard to capture any URL-based require attempts
|
|
521
|
+
code = REQUIRE_GUARD_SNIPPET + code;
|
|
522
|
+
code = cleanCode(code, strategy);
|
|
523
|
+
// Library code (node_modules, monorepo core source, dist vite package)
|
|
524
|
+
// must skip the app-source passes inside processCodeForDevice (AST
|
|
525
|
+
// normalization, /ns/rt helper-alias injection). One classification
|
|
526
|
+
// point — see classifyServedModule for the full case list.
|
|
527
|
+
const isNodeMod = classifyServedModule(resolvedCandidate || spec) === 'library';
|
|
528
|
+
code = processCodeForDevice(code, false, true, isNodeMod, resolvedCandidate || spec);
|
|
529
|
+
// import.meta.hot is JS-owned: cleanCode() strips Vite's browser
|
|
530
|
+
// __vite__createHotContext assignment and processCodeForDevice
|
|
531
|
+
// injects the NS hot-context prelude (globalThis.__NS_HOT_REGISTRY__,
|
|
532
|
+
// installed by the /__ns_dev__/client bootstrap) for app modules.
|
|
533
|
+
const projectRoot = server.config?.root || process.cwd();
|
|
534
|
+
const serverOrigin = getServerOrigin(server);
|
|
535
|
+
// Served-module import rewrite, routed through the active framework
|
|
536
|
+
// strategy. Angular overrides with its register-only entry pass
|
|
537
|
+
// (`rewriteServedModule`); every other flavor falls through to the shared
|
|
538
|
+
// `rewriteImports` default.
|
|
539
|
+
const servedModuleCtx = {
|
|
540
|
+
moduleId: resolvedCandidate || spec,
|
|
541
|
+
sfcFileMap,
|
|
542
|
+
depFileMap,
|
|
543
|
+
projectRoot,
|
|
544
|
+
serverOrigin,
|
|
545
|
+
verbose: !!verbose,
|
|
546
|
+
};
|
|
547
|
+
code = strategy?.rewriteServedModule ? strategy.rewriteServedModule(code, servedModuleCtx) : rewriteImports(code, servedModuleCtx.moduleId, sfcFileMap, depFileMap, projectRoot, !!verbose, undefined, serverOrigin, true);
|
|
548
|
+
// Expand `export * from "url"` into explicit named re-exports.
|
|
549
|
+
// NativeScript's HTTP ESM loader may not propagate star-re-exports across
|
|
550
|
+
// HTTP module boundaries (the namespace object gets direct exports but
|
|
551
|
+
// misses re-exported names). By expanding to `export { a, b } from "url"`,
|
|
552
|
+
// the engine sees explicit named exports and resolves them correctly.
|
|
553
|
+
try {
|
|
554
|
+
code = await expandStarExports(code, server, server.config?.root || process.cwd(), verbose, sharedTransformRequest, resolvedCandidate || spec);
|
|
555
|
+
}
|
|
556
|
+
catch (e) {
|
|
557
|
+
if (verbose)
|
|
558
|
+
console.warn('[ns/m] export* expansion failed:', e?.message);
|
|
559
|
+
}
|
|
560
|
+
// Dedupe any /ns/rt named imports that duplicate destructured bindings off default /ns/rt
|
|
561
|
+
try {
|
|
562
|
+
code = dedupeRtNamedImportsAgainstDestructures(code);
|
|
563
|
+
}
|
|
564
|
+
catch { }
|
|
565
|
+
code = ensureVariableDynamicImportHelper(code);
|
|
566
|
+
// Final safety: guard any plain dynamic import(...) occurrences to reroute anomalous '@' specs
|
|
567
|
+
try {
|
|
568
|
+
code = ensureGuardPlainDynamicImports(code);
|
|
569
|
+
}
|
|
570
|
+
catch { }
|
|
571
|
+
// Extra hardening before the fast-fail assertion: run the
|
|
572
|
+
// consolidated stray-core-reference safety net. If any
|
|
573
|
+
// rewrite occurred, leave a diagnostic marker so the
|
|
574
|
+
// pipeline review log explains why the served code carries
|
|
575
|
+
// it.
|
|
576
|
+
try {
|
|
577
|
+
const __before = code;
|
|
578
|
+
code = sanitizeStrayCoreReferences(code);
|
|
579
|
+
if (code !== __before) {
|
|
580
|
+
code = `// [hmr-sanitize] core-literal->bridge\n` + code;
|
|
581
|
+
}
|
|
582
|
+
}
|
|
583
|
+
catch { }
|
|
584
|
+
// Final pass: deduplicate/resolve any bare-specifier imports that slipped
|
|
585
|
+
// through the pipeline (e.g., extracted from JSDoc comments by import-splitting
|
|
586
|
+
// regexes, or injected by the Angular linker on already-resolved code).
|
|
587
|
+
try {
|
|
588
|
+
code = deduplicateLinkerImports(code);
|
|
589
|
+
}
|
|
590
|
+
catch { }
|
|
591
|
+
// CJS/UMD wrapping: if a module uses module.exports but has no ESM export default,
|
|
592
|
+
// wrap it with CJS shims so the device HTTP ESM loader can consume it.
|
|
593
|
+
// This handles npm packages that use CommonJS but aren't pre-bundled by Vite.
|
|
594
|
+
//
|
|
595
|
+
// Key constraints this must handle:
|
|
596
|
+
// - CJS modules often declare local vars with the same names as their exports
|
|
597
|
+
// (e.g. `function createLTTB() {...}; exports.createLTTB = createLTTB;`)
|
|
598
|
+
// so `export var { createLTTB }` would cause a duplicate declaration.
|
|
599
|
+
// - UMD modules reference `this` at top level (undefined in ESM) but
|
|
600
|
+
// typically fall back to `self` or `globalThis`.
|
|
601
|
+
// - `module`, `exports` must be shims since they don't exist in ESM.
|
|
602
|
+
try {
|
|
603
|
+
code = wrapCommonJsModuleForDevice(code, resolvedCandidate || null);
|
|
604
|
+
}
|
|
605
|
+
catch { }
|
|
606
|
+
try {
|
|
607
|
+
assertNoOptimizedArtifacts(code, `NS M ${resolvedCandidate || spec}`);
|
|
608
|
+
}
|
|
609
|
+
catch (e) {
|
|
610
|
+
res.statusCode = 500;
|
|
611
|
+
return void res.end(`throw new Error(${JSON.stringify(e?.message || String(e))});\nexport {};`);
|
|
612
|
+
}
|
|
613
|
+
// Defensive export normalization: if a module defines `routes` and only exports it named,
|
|
614
|
+
// add a default export alias so both `import { routes }` and `import routes` work.
|
|
615
|
+
try {
|
|
616
|
+
if (!/\bexport\s+default\b/.test(code)) {
|
|
617
|
+
const hasNamedRoutes = /\bexport\s*\{\s*routes\s*\}/.test(code);
|
|
618
|
+
const hasConstRoutes = /\bconst\s+routes\s*=/.test(code) || /\bvar\s+routes\s*=/.test(code) || /\blet\s+routes\s*=/.test(code);
|
|
619
|
+
if (hasNamedRoutes && hasConstRoutes) {
|
|
620
|
+
code += `\nexport default routes;\n`;
|
|
621
|
+
}
|
|
622
|
+
}
|
|
623
|
+
}
|
|
624
|
+
catch { }
|
|
625
|
+
// Every emitted endpoint URL is CANONICAL (unversioned).
|
|
626
|
+
//
|
|
627
|
+
// Module identity is literally the URL — a versioned
|
|
628
|
+
// `/ns/rt/<ver>` / `/ns/core/<ver>` / `/ns/sfc/<ver>` would
|
|
629
|
+
// create a second module realm. `canonicalizeRtImports` and the
|
|
630
|
+
// strategy's `canonicalizeFrameworkImports` collapse any
|
|
631
|
+
// versioned form (stale cached device code) back to the single
|
|
632
|
+
// canonical URL.
|
|
633
|
+
try {
|
|
634
|
+
code = canonicalizeRtImports(code, getServerOrigin(server));
|
|
635
|
+
code = strategy.canonicalizeFrameworkImports?.(code, getServerOrigin(server)) ?? code;
|
|
636
|
+
}
|
|
637
|
+
catch { }
|
|
638
|
+
// `/ns/m` URL finalize step.
|
|
639
|
+
//
|
|
640
|
+
// `canonicalizeNsMImportPath` strips any `__ns_hmr__/<tag>/`
|
|
641
|
+
// and `__ns_boot__/b1/` segments so every emitted URL is the
|
|
642
|
+
// canonical stable form (cache busting is driven by
|
|
643
|
+
// `__NS_DEV__.invalidateModules` + the runtime's eviction nonce, not
|
|
644
|
+
// URL decoration).
|
|
645
|
+
try {
|
|
646
|
+
const origin = getServerOrigin(server);
|
|
647
|
+
const rewritePath = (p) => canonicalizeNsMImportPath(p);
|
|
648
|
+
// /ns/m URL forms — all collapse to canonical stable
|
|
649
|
+
// URLs via the `rewriteNsMImportPathForHmr` rewriter.
|
|
650
|
+
// 1) Static imports: import ... from "/ns/m/..."
|
|
651
|
+
code = code.replace(/(from\s*["'])(\/ns\/m\/[^"'?]+)(["'])/g, (_m, a, p, b) => `${a}${rewritePath(p)}${b}`);
|
|
652
|
+
// 2) Side-effect imports: import "/ns/m/..."
|
|
653
|
+
code = code.replace(/(import\s*(?!\()\s*["'])(\/ns\/m\/[^"'?]+)(["'])/g, (_m, a, p, b) => `${a}${rewritePath(p)}${b}`);
|
|
654
|
+
// 3) Dynamic imports: import("/ns/m/...")
|
|
655
|
+
code = code.replace(/(import\(\s*["'])(\/ns\/m\/[^"'?]+)(["']\s*\))/g, (_m, a, p, b) => `${a}${rewritePath(p)}${b}`);
|
|
656
|
+
// 4) new URL("/ns/m/...", import.meta.url)
|
|
657
|
+
code = code.replace(/(new\s+URL\(\s*["'])(\/ns\/m\/[^"'?]+)(["']\s*,\s*import\.meta\.url\s*\))/g, (_m, a, p, b) => `${a}${rewritePath(p)}${b}`);
|
|
658
|
+
// 5) __ns_import(new URL('/ns/m/...', import.meta.url).href)
|
|
659
|
+
code = code.replace(/(new\s+URL\(\s*["'])(\/ns\/m\/[^"'?]+)(["']\s*,\s*import\.meta\.url\s*\)\.href)/g, (_m, a, p, b) => `${a}${rewritePath(p)}${b}`);
|
|
660
|
+
// 6) Force absolute HTTP for new URL('/ns/m/...', import.meta.url).href → canonical stable URL.
|
|
661
|
+
try {
|
|
662
|
+
code = code.replace(/new\s+URL\(\s*["'](\/ns\/m\/[^"'?]+)(?:\?[^"']*)?["']\s*,\s*import\.meta\.url\s*\)\.href/g, (_m, p1) => `${JSON.stringify(`${origin}${rewritePath(p1)}`)}`);
|
|
663
|
+
}
|
|
664
|
+
catch { }
|
|
665
|
+
// 7) SFC URLs (Vue) — canonical, like everything else. Freshness
|
|
666
|
+
// is driven by the Vue client evicting the SFC artifact URL set.
|
|
667
|
+
try {
|
|
668
|
+
code = code.replace(/new\s+URL\(\s*["']\/ns\/sfc(\/[^"'?]+)(?:\?[^"']*)?["']\s*,\s*import\.meta\.url\s*\)\.href/g, (_m, p1) => `${JSON.stringify(`${origin}/ns/sfc${p1}`)}`);
|
|
669
|
+
}
|
|
670
|
+
catch { }
|
|
671
|
+
}
|
|
672
|
+
catch { }
|
|
673
|
+
// Final guard: eliminate any lingering named imports from /ns/core to avoid
|
|
674
|
+
// evaluation-time "does not provide an export named ..." in the device runtime.
|
|
675
|
+
try {
|
|
676
|
+
code = ensureDestructureCoreImports(code);
|
|
677
|
+
}
|
|
678
|
+
catch { }
|
|
679
|
+
// Boot-time module graph progress: while the app is still replacing
|
|
680
|
+
// the placeholder, emit lightweight progress updates as /ns/m app
|
|
681
|
+
// modules begin evaluating. The snippet is SELF-GATING (it no-ops
|
|
682
|
+
// once `__NS_HMR_BOOT_COMPLETE__` flips) so it is injected
|
|
683
|
+
// unconditionally — no boot-tagged URL needed. node_modules are
|
|
684
|
+
// deliberately skipped (the heartbeat's wall-clock axis covers
|
|
685
|
+
// vendor stretches; see startBootImportHeartbeat).
|
|
686
|
+
try {
|
|
687
|
+
if (!isNodeMod) {
|
|
688
|
+
const bootModuleLabel = String(spec || '').replace(/\\/g, '/');
|
|
689
|
+
const bootProgressSnippet = buildBootProgressSnippet(bootModuleLabel);
|
|
690
|
+
code = bootProgressSnippet + code;
|
|
691
|
+
code = hoistTopLevelStaticImports(code);
|
|
692
|
+
}
|
|
693
|
+
}
|
|
694
|
+
catch { }
|
|
695
|
+
// Dev-only: link-check static imports to surface missing bindings early
|
|
696
|
+
try {
|
|
697
|
+
const devCheck = process.env.NODE_ENV !== 'production';
|
|
698
|
+
if (devCheck) {
|
|
699
|
+
const ast = babelParse(code, {
|
|
700
|
+
sourceType: 'module',
|
|
701
|
+
plugins: MODULE_IMPORT_ANALYSIS_PLUGINS,
|
|
702
|
+
});
|
|
703
|
+
const imports = [];
|
|
704
|
+
babelTraverse(ast, {
|
|
705
|
+
ImportDeclaration(p) {
|
|
706
|
+
const src = p.node.source.value;
|
|
707
|
+
if (typeof src !== 'string')
|
|
708
|
+
return;
|
|
709
|
+
const wantsDefault = p.node.specifiers.some((s) => s.type === 'ImportDefaultSpecifier');
|
|
710
|
+
imports.push({ src, wantsDefault });
|
|
711
|
+
},
|
|
712
|
+
});
|
|
713
|
+
// Resolve and verify each static import that asks for default
|
|
714
|
+
for (const imp of imports) {
|
|
715
|
+
if (!imp.wantsDefault)
|
|
716
|
+
continue;
|
|
717
|
+
// Only check our served endpoints and app modules
|
|
718
|
+
if (/^https?:\/\/[^\s]+\/ns\//.test(imp.src) || /^https?:\/\/[^\s]+\/.+/.test(imp.src)) {
|
|
719
|
+
const u = new URL(imp.src, 'http://localhost');
|
|
720
|
+
// Fetch target module's sanitized code using server.transformRequest or by routing through our own endpoints heuristically
|
|
721
|
+
let targetCode = '';
|
|
722
|
+
try {
|
|
723
|
+
if (u.pathname.startsWith('/ns/asm')) {
|
|
724
|
+
// Reconstruct: call our own assembler handler to get code (preferred)
|
|
725
|
+
const target = await server.transformRequest(imp.src.replace(/^https?:\/\/[^/]+/, ''));
|
|
726
|
+
targetCode = target?.code || '';
|
|
727
|
+
}
|
|
728
|
+
else if (u.pathname.startsWith('/ns/sfc')) {
|
|
729
|
+
// Delegator re-exports default from /ns/asm — skip; assembler will be checked when imported by upstream
|
|
730
|
+
continue;
|
|
731
|
+
}
|
|
732
|
+
else if (u.pathname.startsWith('/ns/m')) {
|
|
733
|
+
// Resolve to local project path and transform with same candidate logic as /ns/m handler
|
|
734
|
+
let local = u.pathname.replace(/^\/ns\/m/, '');
|
|
735
|
+
try {
|
|
736
|
+
// Normalize project-relative path
|
|
737
|
+
if (local.startsWith('@/'))
|
|
738
|
+
local = APP_VIRTUAL_WITH_SLASH + local.slice(2);
|
|
739
|
+
if (local.startsWith('./'))
|
|
740
|
+
local = local.slice(1);
|
|
741
|
+
if (!local.startsWith('/'))
|
|
742
|
+
local = '/' + local;
|
|
743
|
+
const hasExt = /(\.ts|\.tsx|\.js|\.jsx|\.mjs|\.mts|\.cts|\.vue)$/i.test(local);
|
|
744
|
+
const baseNoExt = hasExt ? local.replace(/\.(ts|tsx|js|jsx|mjs|mts|cts)$/i, '') : local;
|
|
745
|
+
const cands = [...(hasExt ? [local] : []), baseNoExt + '.ts', baseNoExt + '.js', baseNoExt + '.tsx', baseNoExt + '.jsx', baseNoExt + '.mjs', baseNoExt + '.mts', baseNoExt + '.cts', baseNoExt + '.vue', baseNoExt + '/index.ts', baseNoExt + '/index.js', baseNoExt + '/index.tsx', baseNoExt + '/index.jsx', baseNoExt + '/index.mjs'];
|
|
746
|
+
let t = null;
|
|
747
|
+
for (const cand of cands) {
|
|
748
|
+
try {
|
|
749
|
+
const r = await server.transformRequest(cand);
|
|
750
|
+
if (r?.code) {
|
|
751
|
+
t = r;
|
|
752
|
+
break;
|
|
753
|
+
}
|
|
754
|
+
}
|
|
755
|
+
catch { }
|
|
756
|
+
if (t?.code)
|
|
757
|
+
break;
|
|
758
|
+
}
|
|
759
|
+
if (!t?.code) {
|
|
760
|
+
try {
|
|
761
|
+
const rid = await server.pluginContainer?.resolveId?.(local, undefined);
|
|
762
|
+
const ridStr = typeof rid === 'string' ? rid : rid?.id || null;
|
|
763
|
+
if (ridStr) {
|
|
764
|
+
const r2 = await server.transformRequest(ridStr);
|
|
765
|
+
if (r2?.code)
|
|
766
|
+
t = r2;
|
|
767
|
+
}
|
|
768
|
+
}
|
|
769
|
+
catch { }
|
|
770
|
+
}
|
|
771
|
+
targetCode = t?.code || '';
|
|
772
|
+
}
|
|
773
|
+
catch { }
|
|
774
|
+
}
|
|
775
|
+
else if (u.pathname.startsWith('/ns/rt') || u.pathname.startsWith('/ns/core')) {
|
|
776
|
+
// Bridges export named/default as needed; skip default check
|
|
777
|
+
continue;
|
|
778
|
+
}
|
|
779
|
+
}
|
|
780
|
+
catch { }
|
|
781
|
+
if (!targetCode)
|
|
782
|
+
continue;
|
|
783
|
+
const hasDefault = /\bexport\s+default\b/.test(targetCode) || /export\s*\{\s*default\s*(?:as\s*default)?\s*\}/.test(targetCode);
|
|
784
|
+
if (!hasDefault) {
|
|
785
|
+
// CJS/UMD modules won't have `export default` — they get CJS-wrapped
|
|
786
|
+
// by the serving pipeline. Only warn, don't fatally block the importer.
|
|
787
|
+
const hasCjsPattern = /\bmodule\s*\.\s*exports\b/.test(targetCode) || /\bexports\s*\.\s*\w/.test(targetCode);
|
|
788
|
+
if (hasCjsPattern) {
|
|
789
|
+
if (verbose) {
|
|
790
|
+
console.warn(`[ns:m][link-check] CJS module without export default: ${u.pathname} (will be CJS-wrapped at serve time)`);
|
|
791
|
+
}
|
|
792
|
+
continue;
|
|
793
|
+
}
|
|
794
|
+
const msg = `[link-check] Missing default export in ${u.pathname}${u.search} (imported by ${resolvedCandidate || spec})`;
|
|
795
|
+
// Emit a module that throws to surface the exact offender
|
|
796
|
+
res.statusCode = 200;
|
|
797
|
+
res.end(`throw new Error(${JSON.stringify(msg)});\nexport {};`);
|
|
798
|
+
return;
|
|
799
|
+
}
|
|
800
|
+
}
|
|
801
|
+
}
|
|
802
|
+
}
|
|
803
|
+
}
|
|
804
|
+
catch (eLC) {
|
|
805
|
+
if (verbose) {
|
|
806
|
+
console.warn('[ns:m][link-check] failed', eLC?.message || eLC);
|
|
807
|
+
}
|
|
808
|
+
}
|
|
809
|
+
// Only fully successful serves are memoized — every early-return
|
|
810
|
+
// above (link-check throw module, 404 stubs, 500s) stays uncached.
|
|
811
|
+
if (memoKey) {
|
|
812
|
+
responseMemo.set(memoKey, code);
|
|
813
|
+
}
|
|
814
|
+
res.statusCode = 200;
|
|
815
|
+
res.end(code);
|
|
816
|
+
}
|
|
817
|
+
catch (e) {
|
|
818
|
+
console.warn('[sfc-asm] error serving', req.url, e && e.message ? e.message : e);
|
|
819
|
+
res.statusCode = 500;
|
|
820
|
+
res.end('export {}\n');
|
|
821
|
+
}
|
|
822
|
+
});
|
|
823
|
+
}
|
|
824
|
+
//# sourceMappingURL=websocket-ns-m.js.map
|