@nativescript/vite 8.0.0-alpha.3 → 8.0.0-alpha.31
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/configuration/angular.d.ts +34 -1
- package/configuration/angular.js +373 -163
- package/configuration/angular.js.map +1 -1
- package/configuration/base.js +184 -14
- package/configuration/base.js.map +1 -1
- package/configuration/javascript.js +5 -72
- package/configuration/javascript.js.map +1 -1
- package/configuration/solid.js +27 -1
- package/configuration/solid.js.map +1 -1
- package/configuration/typescript.js +5 -75
- 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/config-as-json.js +10 -0
- package/helpers/config-as-json.js.map +1 -1
- package/helpers/dev-host.d.ts +341 -0
- package/helpers/dev-host.js +617 -0
- package/helpers/dev-host.js.map +1 -0
- package/helpers/esbuild-platform-resolver.js +4 -1
- package/helpers/esbuild-platform-resolver.js.map +1 -1
- package/helpers/global-defines.d.ts +51 -0
- package/helpers/global-defines.js +77 -0
- 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.d.ts +1 -0
- package/helpers/logging.js +63 -3
- package/helpers/logging.js.map +1 -1
- package/helpers/main-entry.d.ts +2 -1
- package/helpers/main-entry.js +430 -47
- 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.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 +8 -3
- 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 +88 -0
- package/helpers/ns-core-url.js +191 -0
- package/helpers/ns-core-url.js.map +1 -0
- package/helpers/package-platform-aliases.js +4 -3
- 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/project.d.ts +35 -0
- package/helpers/project.js +120 -2
- package/helpers/project.js.map +1 -1
- package/helpers/resolver.js +17 -2
- package/helpers/resolver.js.map +1 -1
- package/helpers/ts-config-paths.d.ts +14 -0
- package/helpers/ts-config-paths.js +89 -8
- package/helpers/ts-config-paths.js.map +1 -1
- package/helpers/typescript-check.d.ts +2 -1
- package/helpers/typescript-check.js.map +1 -1
- 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 +1 -0
- package/hmr/client/css-handler.js +33 -20
- 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 +73 -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 +27 -0
- package/hmr/client/hmr-pending-overlay.js +50 -0
- package/hmr/client/hmr-pending-overlay.js.map +1 -0
- package/hmr/client/index.js +459 -164
- package/hmr/client/index.js.map +1 -1
- package/hmr/client/utils.d.ts +6 -1
- package/hmr/client/utils.js +184 -8
- package/hmr/client/utils.js.map +1 -1
- package/hmr/entry-runtime.d.ts +2 -1
- package/hmr/entry-runtime.js +252 -65
- 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.d.ts +1 -0
- package/hmr/frameworks/angular/client/index.js +778 -20
- 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 +448 -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 +17 -11
- package/hmr/frameworks/angular/server/websocket-angular-hot-update.js +336 -0
- package/hmr/frameworks/angular/server/websocket-angular-hot-update.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/server/strategy.js +360 -16
- package/hmr/frameworks/solid/server/strategy.js.map +1 -1
- package/hmr/frameworks/typescript/server/strategy.js +28 -14
- package/hmr/frameworks/typescript/server/strategy.js.map +1 -1
- package/hmr/frameworks/vue/client/index.js +30 -199
- package/hmr/frameworks/vue/client/index.js.map +1 -1
- package/hmr/frameworks/vue/client/strategy.d.ts +7 -0
- package/hmr/frameworks/vue/client/strategy.js +83 -0
- package/hmr/frameworks/vue/client/strategy.js.map +1 -0
- package/hmr/frameworks/vue/client/vue-sfc-update-overlay.d.ts +82 -0
- package/hmr/frameworks/vue/client/vue-sfc-update-overlay.js +133 -0
- package/hmr/frameworks/vue/client/vue-sfc-update-overlay.js.map +1 -0
- package/hmr/frameworks/vue/server/sfc-route-assemble.d.ts +7 -0
- package/hmr/frameworks/vue/server/sfc-route-assemble.js +706 -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 +457 -0
- package/hmr/frameworks/vue/server/sfc-route-serve.js.map +1 -0
- package/hmr/frameworks/vue/server/sfc-route-shared.d.ts +19 -0
- package/hmr/frameworks/vue/server/sfc-route-shared.js +14 -0
- package/hmr/frameworks/vue/server/sfc-route-shared.js.map +1 -0
- package/hmr/frameworks/vue/server/strategy.js +244 -0
- 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.js +52 -5
- 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/server/constants.js +13 -4
- package/hmr/server/constants.js.map +1 -1
- package/hmr/server/core-sanitize.d.ts +90 -7
- package/hmr/server/core-sanitize.js +211 -56
- package/hmr/server/core-sanitize.js.map +1 -1
- package/hmr/server/device-transform-helpers.d.ts +24 -0
- package/hmr/server/device-transform-helpers.js +327 -0
- package/hmr/server/device-transform-helpers.js.map +1 -0
- package/hmr/server/framework-strategy.d.ts +95 -11
- package/hmr/server/hmr-module-graph.d.ts +37 -0
- package/hmr/server/hmr-module-graph.js +214 -0
- package/hmr/server/hmr-module-graph.js.map +1 -0
- package/hmr/server/import-map.d.ts +11 -2
- package/hmr/server/import-map.js +59 -40
- 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 +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-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 +35 -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 +195 -0
- package/hmr/server/perf-instrumentation.js.map +1 -0
- package/hmr/server/process-code-for-device.d.ts +15 -0
- package/hmr/server/process-code-for-device.js +654 -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 +604 -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 +12 -0
- package/hmr/server/server-origin.js +66 -0
- package/hmr/server/server-origin.js.map +1 -0
- package/hmr/server/shared-transform-request.js +12 -5
- package/hmr/server/shared-transform-request.js.map +1 -1
- package/hmr/server/transform-cache-invalidation.d.ts +11 -0
- package/hmr/server/transform-cache-invalidation.js +84 -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.js +60 -42
- package/hmr/server/vite-plugin.js.map +1 -1
- package/hmr/server/websocket-core-bridge.d.ts +41 -6
- package/hmr/server/websocket-core-bridge.js +72 -75
- 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-graph-upsert.d.ts +15 -0
- package/hmr/server/websocket-graph-upsert.js +20 -0
- package/hmr/server/websocket-graph-upsert.js.map +1 -1
- package/hmr/server/websocket-hmr-pending.d.ts +37 -0
- package/hmr/server/websocket-hmr-pending.js +55 -0
- package/hmr/server/websocket-hmr-pending.js.map +1 -0
- package/hmr/server/websocket-hot-update.d.ts +77 -0
- package/hmr/server/websocket-hot-update.js +330 -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 +46 -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 +202 -19
- package/hmr/server/websocket-module-specifiers.js.map +1 -1
- package/hmr/server/websocket-ns-core.d.ts +21 -0
- package/hmr/server/websocket-ns-core.js +306 -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 +150 -0
- package/hmr/server/websocket-ns-entry.js.map +1 -0
- package/hmr/server/websocket-ns-m-paths.d.ts +3 -0
- package/hmr/server/websocket-ns-m-paths.js +92 -0
- package/hmr/server/websocket-ns-m-paths.js.map +1 -0
- package/hmr/server/websocket-ns-m-request.d.ts +45 -0
- package/hmr/server/websocket-ns-m-request.js +196 -0
- package/hmr/server/websocket-ns-m-request.js.map +1 -0
- package/hmr/server/websocket-ns-m.d.ts +33 -0
- package/hmr/server/websocket-ns-m.js +748 -0
- package/hmr/server/websocket-ns-m.js.map +1 -0
- package/hmr/server/websocket-served-module-helpers.d.ts +39 -0
- package/hmr/server/websocket-served-module-helpers.js +654 -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 +39 -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 +8 -39
- package/hmr/server/websocket.js +602 -6049
- package/hmr/server/websocket.js.map +1 -1
- package/hmr/shared/ns-globals.d.ts +118 -0
- package/hmr/shared/ns-globals.js +27 -0
- package/hmr/shared/ns-globals.js.map +1 -0
- package/hmr/shared/protocol.d.ts +136 -0
- package/hmr/shared/protocol.js +28 -0
- package/hmr/shared/protocol.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 +40 -0
- package/hmr/shared/runtime/boot-progress.js +128 -0
- package/hmr/shared/runtime/boot-progress.js.map +1 -0
- package/hmr/shared/runtime/boot-timeline.d.ts +18 -0
- package/hmr/shared/runtime/boot-timeline.js +52 -0
- package/hmr/shared/runtime/boot-timeline.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.d.ts +75 -26
- package/hmr/shared/runtime/dev-overlay.js +990 -260
- package/hmr/shared/runtime/dev-overlay.js.map +1 -1
- package/hmr/shared/runtime/module-provenance.js +1 -4
- 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 +310 -0
- package/hmr/shared/runtime/root-placeholder-view.js.map +1 -0
- package/hmr/shared/runtime/root-placeholder.js +352 -194
- package/hmr/shared/runtime/root-placeholder.js.map +1 -1
- package/hmr/shared/runtime/session-bootstrap.js +164 -1
- package/hmr/shared/runtime/session-bootstrap.js.map +1 -1
- package/hmr/shared/runtime/vendor-bootstrap.js +1 -9
- 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 +512 -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 +3 -2
- 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 +102 -741
- package/hmr/shared/vendor/manifest.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 +16 -0
- package/hmr/shared/vendor/vendor-esbuild-plugins.js +203 -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 +55 -11
- package/runtime/core-aliases-early.js +17 -41
- package/runtime/core-aliases-early.js.map +1 -1
- 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 +0 -239
- package/hmr/server/websocket-angular-hot-update.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,109 @@
|
|
|
1
|
+
import { runAngularLinker } from './shared-linker.js';
|
|
2
|
+
import { containsRealNgDeclare } from './util.js';
|
|
3
|
+
function normalizeAngularLinkerId(id) {
|
|
4
|
+
return id.split('?', 1)[0].replace(/\\/g, '/');
|
|
5
|
+
}
|
|
6
|
+
function isDebug() {
|
|
7
|
+
return process.env.VITE_DEBUG_LOGS === 'true' || process.env.VITE_DEBUG_LOGS === '1';
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Vite plugin to run the Angular linker (Babel) over partial-compiled Angular
|
|
11
|
+
* libraries inside node_modules (e.g. @angular/*, @nativescript/angular),
|
|
12
|
+
* converting ɵɵngDeclare* calls to ɵɵdefine* so the runtime doesn't need JIT.
|
|
13
|
+
*/
|
|
14
|
+
export function angularLinkerVitePlugin(projectRoot) {
|
|
15
|
+
// Base filter: Angular framework libraries + NativeScript Angular + its polyfills bundle.
|
|
16
|
+
const FILTER = /node_modules\/(?:@angular|@nativescript\/angular)\/.*\.[mc]?js$|nativescript-angular-polyfills\.mjs$/;
|
|
17
|
+
// Extended filter: ANY node_modules .js/.mjs file — catches Angular ecosystem
|
|
18
|
+
// packages (ngrx, etc.) carrying ɵɵngDeclare* partials. Vite 8 watch rebuilds
|
|
19
|
+
// may skip chunk-level linker fallbacks for cached chunks, so link at transform.
|
|
20
|
+
const NODE_MODULES_FILTER = /node_modules\/.*\.[mc]?js$/;
|
|
21
|
+
// NS_STRICT_NG_LINK_ALL=1 aggressively links any JS/ESM file with a real
|
|
22
|
+
// ɵɵngDeclare* call site so no partials survive into the device bundle.
|
|
23
|
+
const strictAll = process.env.NS_STRICT_NG_LINK_ALL === '1' || process.env.NS_STRICT_NG_LINK_ALL === 'true';
|
|
24
|
+
return {
|
|
25
|
+
name: 'ns-angular-linker-vite',
|
|
26
|
+
enforce: 'pre',
|
|
27
|
+
async load(id) {
|
|
28
|
+
const cleanId = normalizeAngularLinkerId(id);
|
|
29
|
+
if (!strictAll && !FILTER.test(cleanId)) {
|
|
30
|
+
if (!NODE_MODULES_FILTER.test(cleanId))
|
|
31
|
+
return null;
|
|
32
|
+
try {
|
|
33
|
+
const fs = await import('node:fs/promises');
|
|
34
|
+
const peek = await fs.readFile(cleanId, 'utf8');
|
|
35
|
+
if (!peek || !containsRealNgDeclare(peek))
|
|
36
|
+
return null;
|
|
37
|
+
}
|
|
38
|
+
catch {
|
|
39
|
+
return null;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
try {
|
|
43
|
+
const fs = await import('node:fs/promises');
|
|
44
|
+
const code = await fs.readFile(cleanId, 'utf8');
|
|
45
|
+
if (!code)
|
|
46
|
+
return null;
|
|
47
|
+
if (strictAll && !FILTER.test(cleanId) && !containsRealNgDeclare(code))
|
|
48
|
+
return null;
|
|
49
|
+
const linked = await runAngularLinker(code, { filename: cleanId, projectRoot });
|
|
50
|
+
if (linked) {
|
|
51
|
+
if (isDebug())
|
|
52
|
+
console.log('[ns-angular-linker][vite-load] linked', cleanId);
|
|
53
|
+
return { code: linked, map: null };
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
catch { }
|
|
57
|
+
return null;
|
|
58
|
+
},
|
|
59
|
+
async transform(code, id) {
|
|
60
|
+
const cleanId = normalizeAngularLinkerId(id);
|
|
61
|
+
if (!strictAll && !FILTER.test(cleanId)) {
|
|
62
|
+
if (!NODE_MODULES_FILTER.test(cleanId) || !code || !containsRealNgDeclare(code))
|
|
63
|
+
return null;
|
|
64
|
+
}
|
|
65
|
+
if (!code)
|
|
66
|
+
return null;
|
|
67
|
+
if (strictAll && !FILTER.test(cleanId) && !containsRealNgDeclare(code))
|
|
68
|
+
return null;
|
|
69
|
+
try {
|
|
70
|
+
const linked = await runAngularLinker(code, { filename: cleanId, projectRoot, freshPlugin: true });
|
|
71
|
+
if (linked) {
|
|
72
|
+
if (isDebug())
|
|
73
|
+
console.log('[ns-angular-linker][vite] linked', cleanId);
|
|
74
|
+
return { code: linked, map: null };
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
catch { }
|
|
78
|
+
return null;
|
|
79
|
+
},
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Post-phase linker: catches any ɵɵngDeclare* introduced by downstream
|
|
84
|
+
* transforms (e.g. optimizer) including project source, after other plugins run.
|
|
85
|
+
*/
|
|
86
|
+
export function angularLinkerVitePluginPost(projectRoot) {
|
|
87
|
+
return {
|
|
88
|
+
name: 'ns-angular-linker-vite-post',
|
|
89
|
+
enforce: 'post',
|
|
90
|
+
async transform(code, id) {
|
|
91
|
+
if (!/\.(m?js)(\?|$)/.test(id))
|
|
92
|
+
return null;
|
|
93
|
+
if (!code || !containsRealNgDeclare(code))
|
|
94
|
+
return null;
|
|
95
|
+
try {
|
|
96
|
+
const filename = id.split('?', 1)[0];
|
|
97
|
+
const linked = await runAngularLinker(code, { filename, projectRoot });
|
|
98
|
+
if (linked) {
|
|
99
|
+
if (isDebug())
|
|
100
|
+
console.log('[ns-angular-linker][vite-post] linked', filename);
|
|
101
|
+
return { code: linked, map: null };
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
catch { }
|
|
105
|
+
return null;
|
|
106
|
+
},
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
//# sourceMappingURL=angular-linker.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"angular-linker.js","sourceRoot":"","sources":["../../../../../../../packages/vite/hmr/frameworks/angular/build/angular-linker.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,EAAE,qBAAqB,EAAE,MAAM,WAAW,CAAC;AAElD,SAAS,wBAAwB,CAAC,EAAU;IAC3C,OAAO,EAAE,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;AAChD,CAAC;AAED,SAAS,OAAO;IACf,OAAO,OAAO,CAAC,GAAG,CAAC,eAAe,KAAK,MAAM,IAAI,OAAO,CAAC,GAAG,CAAC,eAAe,KAAK,GAAG,CAAC;AACtF,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,uBAAuB,CAAC,WAAoB;IAC3D,0FAA0F;IAC1F,MAAM,MAAM,GAAG,sGAAsG,CAAC;IACtH,8EAA8E;IAC9E,8EAA8E;IAC9E,iFAAiF;IACjF,MAAM,mBAAmB,GAAG,4BAA4B,CAAC;IACzD,yEAAyE;IACzE,wEAAwE;IACxE,MAAM,SAAS,GAAG,OAAO,CAAC,GAAG,CAAC,qBAAqB,KAAK,GAAG,IAAI,OAAO,CAAC,GAAG,CAAC,qBAAqB,KAAK,MAA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N,IAAI,EAAE,6BAA6B;QACnC,OAAO,EAAE,MAAM;QACf,KAAK,CAAC,SAAS,CAAC,IAAI,EAAE,EAAE;YACvB,IAAI,CAAC,gBAAgB,CAAC,IAAI,CAAC,EAAE,CAAC;gBAAE,OAAO,IAAI,CAAC;YAC5C,IAAI,CAAC,IAAI,IAAI,CAAC,qBAAqB,CAAC,IAAI,CAAC;gBAAE,OAAO,IAAI,CAAC;YACvD,IAAI,CAAC;gBACJ,MAAM,QAAQ,GAAG,EAAE,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;gBACrC,MAAM,MAAM,GAAG,MAAM,gBAAgB,CAAC,IAAI,EAAE,EAAE,QAAQ,EAAE,WAAW,EAAE,CAAC,CAAC;gBACvE,IAAI,MAAM,EAAE,CAAC;oBACZ,IAAI,OAAO,EAAE;wBAAE,OAAO,CAAC,GAAG,CAAC,uCAAuC,EAAE,QAAQ,CAAC,CAAC;oBAC9E,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,EAAE,IAAI,EAAE,CAAC;gBACpC,CAAC;YACF,CAAC;YAAC,MAAM,CAAC,CAAA,CAAC;YACV,OAAO,IAAI,CAAC;QACb,CAAC;KACD,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Vite-side helper that injects HMR self-registration calls into the
|
|
3
|
+
* compiled output of user `.ts` files that declare `@Component`-
|
|
4
|
+
* decorated classes.
|
|
5
|
+
*
|
|
6
|
+
* After an HMR reboot, the global `__NS_HMR_REGISTER_COMPONENT__` hook
|
|
7
|
+
* (installed by `@nativescript/angular`) records each fresh class
|
|
8
|
+
* keyed by source name. HMR helpers (modal restore, route replay) read
|
|
9
|
+
* the registry to re-attach to the live class. See
|
|
10
|
+
* `hmr-class-registry.ts` for the runtime side of the contract.
|
|
11
|
+
*
|
|
12
|
+
* The helper exposes two phases used by complementary Vite plugins:
|
|
13
|
+
* 1. `findComponentClassNames(rawTs)` — scans the user's raw TS
|
|
14
|
+
* source for `@Component`-decorated classes. Used by an
|
|
15
|
+
* `enforce: 'pre'` plugin to discover names BEFORE the Analog
|
|
16
|
+
* Angular plugin compiles the file. The discovery has to happen
|
|
17
|
+
* on raw TS because the Angular plugin rewrites the `@Component`
|
|
18
|
+
* decorator into static metadata calls (`ɵsetClassMetadata`,
|
|
19
|
+
* `ɵɵdefineComponent`) and removes the textual `@Component(...)`
|
|
20
|
+
* pattern.
|
|
21
|
+
* 2. `appendComponentHmrRegistration(compiledCode, names)` — appends
|
|
22
|
+
* the registration snippet to the END of compiled JS produced by
|
|
23
|
+
* the Analog Angular plugin. Used by an `enforce: 'post'` plugin.
|
|
24
|
+
* Appending here is the only reliable insertion point because:
|
|
25
|
+
* - Class declarations are evaluated and bound by then.
|
|
26
|
+
* - Angular's static metadata (`ɵcmp`/`ɵfac`) has finished
|
|
27
|
+
* attaching, so the registered class identity already
|
|
28
|
+
* carries the up-to-date component definition.
|
|
29
|
+
* - The Analog Angular plugin's `transform` discards anything
|
|
30
|
+
* appended before its compilation step (it returns code
|
|
31
|
+
* regenerated from its own `outputFiles` cache, not the
|
|
32
|
+
* input passed in). Verified directly in the plugin chain.
|
|
33
|
+
* - Source-map line offsets for the original module body are
|
|
34
|
+
* preserved (we only append).
|
|
35
|
+
*
|
|
36
|
+
* The legacy `injectComponentHmrRegistration(rawTs)` helper is kept
|
|
37
|
+
* for backward compatibility — it appends to raw TS in a single call —
|
|
38
|
+
* but is no longer the path used by the live HMR pipeline (its output
|
|
39
|
+
* is silently dropped by the Angular plugin for `@Component` files).
|
|
40
|
+
*
|
|
41
|
+
* The helpers are dev-only: production builds skip the Vite plugins
|
|
42
|
+
* (`apply: 'serve'`), and the runtime hook short-circuits when
|
|
43
|
+
* `isAngularHmrEnabled()` is false.
|
|
44
|
+
*/
|
|
45
|
+
/**
|
|
46
|
+
* Marker comment placed immediately before the appended registration
|
|
47
|
+
* block. Plugins can scan for this string to make their work
|
|
48
|
+
* idempotent across re-transforms (the Vite cache may replay the
|
|
49
|
+
* transform pipeline on cached modules).
|
|
50
|
+
*/
|
|
51
|
+
export declare const INJECTION_MARKER = "/* @nativescript/vite ns-hmr-register */";
|
|
52
|
+
export interface InjectComponentHmrRegistrationOptions {
|
|
53
|
+
/**
|
|
54
|
+
* Optional override of the global hook name. Defaults to
|
|
55
|
+
* `__NS_HMR_REGISTER_COMPONENT__`. Exposed for tests; production
|
|
56
|
+
* callers should keep the default.
|
|
57
|
+
*/
|
|
58
|
+
hookName?: string;
|
|
59
|
+
}
|
|
60
|
+
export interface InjectComponentHmrRegistrationResult {
|
|
61
|
+
/** New code, or `null` if no transformation is needed. */
|
|
62
|
+
code: string | null;
|
|
63
|
+
/** Names of `@Component` classes detected in the file. */
|
|
64
|
+
componentNames: string[];
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Build the trailing snippet that registers each component class with
|
|
68
|
+
* the global HMR hook. Pure string construction — exposed so the post-
|
|
69
|
+
* Angular plugin can append it to compiled output without re-scanning
|
|
70
|
+
* for class names (the pre plugin already scanned the raw TS source).
|
|
71
|
+
*
|
|
72
|
+
* Returns an empty string when `componentNames` is empty so callers
|
|
73
|
+
* can concatenate unconditionally.
|
|
74
|
+
*/
|
|
75
|
+
export declare function buildComponentHmrRegistrationSuffix(componentNames: string[], options?: InjectComponentHmrRegistrationOptions): string;
|
|
76
|
+
/**
|
|
77
|
+
* Append the registration snippet to a piece of code (typically the
|
|
78
|
+
* compiled output from `@analogjs/vite-plugin-angular`) using a list
|
|
79
|
+
* of component names previously discovered in the raw TS source.
|
|
80
|
+
*
|
|
81
|
+
* Returns `{ code: null, componentNames: [] }` if `componentNames`
|
|
82
|
+
* is empty or if the code already contains the injection marker
|
|
83
|
+
* (idempotent re-transform case).
|
|
84
|
+
*/
|
|
85
|
+
export declare function appendComponentHmrRegistration(code: string, componentNames: string[], options?: InjectComponentHmrRegistrationOptions): InjectComponentHmrRegistrationResult;
|
|
86
|
+
/**
|
|
87
|
+
* Legacy helper: scan raw TypeScript source for `@Component` classes
|
|
88
|
+
* and append registration calls. Retained for tests and for any
|
|
89
|
+
* caller running outside the post-Angular plugin chain.
|
|
90
|
+
*
|
|
91
|
+
* NOTE: For files compiled by `@analogjs/vite-plugin-angular`, this
|
|
92
|
+
* helper's output is discarded — the Angular plugin replaces the
|
|
93
|
+
* input code with the regenerated compiled output from its internal
|
|
94
|
+
* `outputFiles` cache. Use `findComponentClassNames(rawTs)` +
|
|
95
|
+
* `appendComponentHmrRegistration(compiledCode, names)` from a
|
|
96
|
+
* `enforce: 'post'` plugin to survive that compilation step.
|
|
97
|
+
*/
|
|
98
|
+
export declare function injectComponentHmrRegistration(code: string, options?: InjectComponentHmrRegistrationOptions): InjectComponentHmrRegistrationResult;
|
|
99
|
+
/**
|
|
100
|
+
* Walk a TS source string and collect class names declared after a
|
|
101
|
+
* `@Component(...)` decorator. Supports:
|
|
102
|
+
* - `export class Foo` and bare `class Foo`
|
|
103
|
+
* - `abstract class Foo` (rare for @Component but allowed)
|
|
104
|
+
* - Any number of additional decorators stacked between `@Component`
|
|
105
|
+
* and the class keyword (e.g. `@Component({}) @SomethingElse() ...`)
|
|
106
|
+
*
|
|
107
|
+
* Skips matches that fall inside string literals or comments. Uses a
|
|
108
|
+
* paren-matching scanner instead of regex `[\s\S]*?` so multi-line
|
|
109
|
+
* decorator arguments (templates, styles arrays) don't trip up the
|
|
110
|
+
* scanner.
|
|
111
|
+
*/
|
|
112
|
+
export declare function findComponentClassNames(code: string): string[];
|
|
@@ -0,0 +1,291 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Vite-side helper that injects HMR self-registration calls into the
|
|
3
|
+
* compiled output of user `.ts` files that declare `@Component`-
|
|
4
|
+
* decorated classes.
|
|
5
|
+
*
|
|
6
|
+
* After an HMR reboot, the global `__NS_HMR_REGISTER_COMPONENT__` hook
|
|
7
|
+
* (installed by `@nativescript/angular`) records each fresh class
|
|
8
|
+
* keyed by source name. HMR helpers (modal restore, route replay) read
|
|
9
|
+
* the registry to re-attach to the live class. See
|
|
10
|
+
* `hmr-class-registry.ts` for the runtime side of the contract.
|
|
11
|
+
*
|
|
12
|
+
* The helper exposes two phases used by complementary Vite plugins:
|
|
13
|
+
* 1. `findComponentClassNames(rawTs)` — scans the user's raw TS
|
|
14
|
+
* source for `@Component`-decorated classes. Used by an
|
|
15
|
+
* `enforce: 'pre'` plugin to discover names BEFORE the Analog
|
|
16
|
+
* Angular plugin compiles the file. The discovery has to happen
|
|
17
|
+
* on raw TS because the Angular plugin rewrites the `@Component`
|
|
18
|
+
* decorator into static metadata calls (`ɵsetClassMetadata`,
|
|
19
|
+
* `ɵɵdefineComponent`) and removes the textual `@Component(...)`
|
|
20
|
+
* pattern.
|
|
21
|
+
* 2. `appendComponentHmrRegistration(compiledCode, names)` — appends
|
|
22
|
+
* the registration snippet to the END of compiled JS produced by
|
|
23
|
+
* the Analog Angular plugin. Used by an `enforce: 'post'` plugin.
|
|
24
|
+
* Appending here is the only reliable insertion point because:
|
|
25
|
+
* - Class declarations are evaluated and bound by then.
|
|
26
|
+
* - Angular's static metadata (`ɵcmp`/`ɵfac`) has finished
|
|
27
|
+
* attaching, so the registered class identity already
|
|
28
|
+
* carries the up-to-date component definition.
|
|
29
|
+
* - The Analog Angular plugin's `transform` discards anything
|
|
30
|
+
* appended before its compilation step (it returns code
|
|
31
|
+
* regenerated from its own `outputFiles` cache, not the
|
|
32
|
+
* input passed in). Verified directly in the plugin chain.
|
|
33
|
+
* - Source-map line offsets for the original module body are
|
|
34
|
+
* preserved (we only append).
|
|
35
|
+
*
|
|
36
|
+
* The legacy `injectComponentHmrRegistration(rawTs)` helper is kept
|
|
37
|
+
* for backward compatibility — it appends to raw TS in a single call —
|
|
38
|
+
* but is no longer the path used by the live HMR pipeline (its output
|
|
39
|
+
* is silently dropped by the Angular plugin for `@Component` files).
|
|
40
|
+
*
|
|
41
|
+
* The helpers are dev-only: production builds skip the Vite plugins
|
|
42
|
+
* (`apply: 'serve'`), and the runtime hook short-circuits when
|
|
43
|
+
* `isAngularHmrEnabled()` is false.
|
|
44
|
+
*/
|
|
45
|
+
import { findMatchingDelimiter } from './js-lexer.js';
|
|
46
|
+
const COMPONENT_DECORATOR_RE = /@Component\s*\(/g;
|
|
47
|
+
/**
|
|
48
|
+
* Marker comment placed immediately before the appended registration
|
|
49
|
+
* block. Plugins can scan for this string to make their work
|
|
50
|
+
* idempotent across re-transforms (the Vite cache may replay the
|
|
51
|
+
* transform pipeline on cached modules).
|
|
52
|
+
*/
|
|
53
|
+
export const INJECTION_MARKER = '/* @nativescript/vite ns-hmr-register */';
|
|
54
|
+
/**
|
|
55
|
+
* Build the trailing snippet that registers each component class with
|
|
56
|
+
* the global HMR hook. Pure string construction — exposed so the post-
|
|
57
|
+
* Angular plugin can append it to compiled output without re-scanning
|
|
58
|
+
* for class names (the pre plugin already scanned the raw TS source).
|
|
59
|
+
*
|
|
60
|
+
* Returns an empty string when `componentNames` is empty so callers
|
|
61
|
+
* can concatenate unconditionally.
|
|
62
|
+
*/
|
|
63
|
+
export function buildComponentHmrRegistrationSuffix(componentNames, options = {}) {
|
|
64
|
+
if (!componentNames || componentNames.length === 0) {
|
|
65
|
+
return '';
|
|
66
|
+
}
|
|
67
|
+
const hookName = options.hookName ?? '__NS_HMR_REGISTER_COMPONENT__';
|
|
68
|
+
const registrationLines = componentNames.map((name) => buildRegistrationLine(hookName, name));
|
|
69
|
+
// Pad with two newlines so the appended block is visually separated
|
|
70
|
+
// from the original module body in source maps and stack traces.
|
|
71
|
+
return `\n\n${INJECTION_MARKER}\n${registrationLines.join('\n')}\n`;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Append the registration snippet to a piece of code (typically the
|
|
75
|
+
* compiled output from `@analogjs/vite-plugin-angular`) using a list
|
|
76
|
+
* of component names previously discovered in the raw TS source.
|
|
77
|
+
*
|
|
78
|
+
* Returns `{ code: null, componentNames: [] }` if `componentNames`
|
|
79
|
+
* is empty or if the code already contains the injection marker
|
|
80
|
+
* (idempotent re-transform case).
|
|
81
|
+
*/
|
|
82
|
+
export function appendComponentHmrRegistration(code, componentNames, options = {}) {
|
|
83
|
+
if (!code) {
|
|
84
|
+
return { code: null, componentNames: [] };
|
|
85
|
+
}
|
|
86
|
+
if (!componentNames || componentNames.length === 0) {
|
|
87
|
+
return { code: null, componentNames: [] };
|
|
88
|
+
}
|
|
89
|
+
if (code.includes(INJECTION_MARKER)) {
|
|
90
|
+
return { code: null, componentNames: [] };
|
|
91
|
+
}
|
|
92
|
+
const suffix = buildComponentHmrRegistrationSuffix(componentNames, options);
|
|
93
|
+
if (!suffix) {
|
|
94
|
+
return { code: null, componentNames: [] };
|
|
95
|
+
}
|
|
96
|
+
return {
|
|
97
|
+
code: code + suffix,
|
|
98
|
+
componentNames: [...componentNames],
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Legacy helper: scan raw TypeScript source for `@Component` classes
|
|
103
|
+
* and append registration calls. Retained for tests and for any
|
|
104
|
+
* caller running outside the post-Angular plugin chain.
|
|
105
|
+
*
|
|
106
|
+
* NOTE: For files compiled by `@analogjs/vite-plugin-angular`, this
|
|
107
|
+
* helper's output is discarded — the Angular plugin replaces the
|
|
108
|
+
* input code with the regenerated compiled output from its internal
|
|
109
|
+
* `outputFiles` cache. Use `findComponentClassNames(rawTs)` +
|
|
110
|
+
* `appendComponentHmrRegistration(compiledCode, names)` from a
|
|
111
|
+
* `enforce: 'post'` plugin to survive that compilation step.
|
|
112
|
+
*/
|
|
113
|
+
export function injectComponentHmrRegistration(code, options = {}) {
|
|
114
|
+
if (!code) {
|
|
115
|
+
return { code: null, componentNames: [] };
|
|
116
|
+
}
|
|
117
|
+
if (code.includes(INJECTION_MARKER)) {
|
|
118
|
+
// Already injected (re-transform case) — return original to avoid
|
|
119
|
+
// duplicating registration calls.
|
|
120
|
+
return { code: null, componentNames: [] };
|
|
121
|
+
}
|
|
122
|
+
if (!COMPONENT_DECORATOR_RE.test(code)) {
|
|
123
|
+
return { code: null, componentNames: [] };
|
|
124
|
+
}
|
|
125
|
+
// RegExp.prototype.test with `g` flag advances lastIndex; reset for the
|
|
126
|
+
// next walk in `findComponentClassNames`.
|
|
127
|
+
COMPONENT_DECORATOR_RE.lastIndex = 0;
|
|
128
|
+
const componentNames = findComponentClassNames(code);
|
|
129
|
+
if (componentNames.length === 0) {
|
|
130
|
+
return { code: null, componentNames: [] };
|
|
131
|
+
}
|
|
132
|
+
const suffix = buildComponentHmrRegistrationSuffix(componentNames, options);
|
|
133
|
+
return {
|
|
134
|
+
code: code + suffix,
|
|
135
|
+
componentNames,
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
function buildRegistrationLine(hookName, className) {
|
|
139
|
+
// Wrap each call in its own try so a failure (e.g. the class binding
|
|
140
|
+
// not in scope at module end because the user re-exported it from
|
|
141
|
+
// somewhere else) doesn't break sibling registrations.
|
|
142
|
+
// The typeof guard prevents a ReferenceError if the global hook isn't
|
|
143
|
+
// installed (production builds, non-Angular contexts, isolated unit
|
|
144
|
+
// tests). The "globalThis" reference is universal across modern JS
|
|
145
|
+
// runtimes including the NativeScript iOS/Android runtimes.
|
|
146
|
+
return `try { if (typeof globalThis !== 'undefined' && typeof globalThis.${hookName} === 'function' && typeof ${className} !== 'undefined') { globalThis.${hookName}(${JSON.stringify(className)}, ${className}, typeof import.meta !== 'undefined' && import.meta && import.meta.url ? import.meta.url : ''); } } catch (e) {}`;
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Walk a TS source string and collect class names declared after a
|
|
150
|
+
* `@Component(...)` decorator. Supports:
|
|
151
|
+
* - `export class Foo` and bare `class Foo`
|
|
152
|
+
* - `abstract class Foo` (rare for @Component but allowed)
|
|
153
|
+
* - Any number of additional decorators stacked between `@Component`
|
|
154
|
+
* and the class keyword (e.g. `@Component({}) @SomethingElse() ...`)
|
|
155
|
+
*
|
|
156
|
+
* Skips matches that fall inside string literals or comments. Uses a
|
|
157
|
+
* paren-matching scanner instead of regex `[\s\S]*?` so multi-line
|
|
158
|
+
* decorator arguments (templates, styles arrays) don't trip up the
|
|
159
|
+
* scanner.
|
|
160
|
+
*/
|
|
161
|
+
export function findComponentClassNames(code) {
|
|
162
|
+
const names = [];
|
|
163
|
+
const componentRe = /@Component\s*\(/g;
|
|
164
|
+
let match;
|
|
165
|
+
while ((match = componentRe.exec(code)) !== null) {
|
|
166
|
+
const matchStart = match.index;
|
|
167
|
+
if (isInsideStringOrComment(code, matchStart)) {
|
|
168
|
+
continue;
|
|
169
|
+
}
|
|
170
|
+
const openParenIdx = matchStart + match[0].length - 1;
|
|
171
|
+
const closeParenIdx = findMatchingDelimiter(code, openParenIdx, '(', ')');
|
|
172
|
+
if (closeParenIdx === -1) {
|
|
173
|
+
continue;
|
|
174
|
+
}
|
|
175
|
+
const className = findClassNameAfter(code, closeParenIdx + 1);
|
|
176
|
+
if (className && !names.includes(className)) {
|
|
177
|
+
names.push(className);
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
return names;
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* Starting at `position`, skip whitespace and any further decorators
|
|
184
|
+
* (`@Foo(...)`) and return the next class name encountered, or
|
|
185
|
+
* `null` if no class declaration follows.
|
|
186
|
+
*/
|
|
187
|
+
function findClassNameAfter(code, position) {
|
|
188
|
+
let i = position;
|
|
189
|
+
while (i < code.length) {
|
|
190
|
+
while (i < code.length && /\s/.test(code[i])) {
|
|
191
|
+
i++;
|
|
192
|
+
}
|
|
193
|
+
if (i >= code.length) {
|
|
194
|
+
return null;
|
|
195
|
+
}
|
|
196
|
+
if (code[i] === '@') {
|
|
197
|
+
// Another decorator stacked between @Component and class.
|
|
198
|
+
i++;
|
|
199
|
+
// Decorator name (identifier).
|
|
200
|
+
while (i < code.length && /[\w$.]/.test(code[i])) {
|
|
201
|
+
i++;
|
|
202
|
+
}
|
|
203
|
+
while (i < code.length && /\s/.test(code[i])) {
|
|
204
|
+
i++;
|
|
205
|
+
}
|
|
206
|
+
if (code[i] === '(') {
|
|
207
|
+
const decoClose = findMatchingDelimiter(code, i, '(', ')');
|
|
208
|
+
if (decoClose === -1) {
|
|
209
|
+
return null;
|
|
210
|
+
}
|
|
211
|
+
i = decoClose + 1;
|
|
212
|
+
}
|
|
213
|
+
continue;
|
|
214
|
+
}
|
|
215
|
+
const remainder = code.slice(i);
|
|
216
|
+
const classMatch = /^(?:export\s+(?:default\s+)?)?(?:abstract\s+)?class\s+([A-Za-z_$][\w$]*)/.exec(remainder);
|
|
217
|
+
if (classMatch) {
|
|
218
|
+
return classMatch[1];
|
|
219
|
+
}
|
|
220
|
+
return null;
|
|
221
|
+
}
|
|
222
|
+
return null;
|
|
223
|
+
}
|
|
224
|
+
/**
|
|
225
|
+
* True if `index` falls inside a // line comment, /* block comment, or
|
|
226
|
+
* a string/template literal. Used to filter out false positives from
|
|
227
|
+
* `@Component(` matches inside docs or stringified examples.
|
|
228
|
+
*/
|
|
229
|
+
function isInsideStringOrComment(code, index) {
|
|
230
|
+
let i = 0;
|
|
231
|
+
let quote = null;
|
|
232
|
+
let escape = false;
|
|
233
|
+
let inLineComment = false;
|
|
234
|
+
let inBlockComment = false;
|
|
235
|
+
while (i < index) {
|
|
236
|
+
const char = code[i];
|
|
237
|
+
const next = code[i + 1];
|
|
238
|
+
if (inLineComment) {
|
|
239
|
+
if (char === '\n') {
|
|
240
|
+
inLineComment = false;
|
|
241
|
+
}
|
|
242
|
+
i++;
|
|
243
|
+
continue;
|
|
244
|
+
}
|
|
245
|
+
if (inBlockComment) {
|
|
246
|
+
if (char === '*' && next === '/') {
|
|
247
|
+
inBlockComment = false;
|
|
248
|
+
i += 2;
|
|
249
|
+
continue;
|
|
250
|
+
}
|
|
251
|
+
i++;
|
|
252
|
+
continue;
|
|
253
|
+
}
|
|
254
|
+
if (quote) {
|
|
255
|
+
if (escape) {
|
|
256
|
+
escape = false;
|
|
257
|
+
i++;
|
|
258
|
+
continue;
|
|
259
|
+
}
|
|
260
|
+
if (char === '\\') {
|
|
261
|
+
escape = true;
|
|
262
|
+
i++;
|
|
263
|
+
continue;
|
|
264
|
+
}
|
|
265
|
+
if (char === quote) {
|
|
266
|
+
quote = null;
|
|
267
|
+
}
|
|
268
|
+
i++;
|
|
269
|
+
continue;
|
|
270
|
+
}
|
|
271
|
+
if (char === '/' && next === '/') {
|
|
272
|
+
inLineComment = true;
|
|
273
|
+
i += 2;
|
|
274
|
+
continue;
|
|
275
|
+
}
|
|
276
|
+
if (char === '/' && next === '*') {
|
|
277
|
+
inBlockComment = true;
|
|
278
|
+
i += 2;
|
|
279
|
+
continue;
|
|
280
|
+
}
|
|
281
|
+
if (char === '"' || char === "'" || char === '`') {
|
|
282
|
+
quote = char;
|
|
283
|
+
i++;
|
|
284
|
+
continue;
|
|
285
|
+
}
|
|
286
|
+
i++;
|
|
287
|
+
}
|
|
288
|
+
return inLineComment || inBlockComment || quote !== null;
|
|
289
|
+
}
|
|
290
|
+
// Comment-aware delimiter matcher lives in ./js-lexer.ts
|
|
291
|
+
//# sourceMappingURL=inject-component-hmr-registration.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"inject-component-hmr-registration.js","sourceRoot":"","sources":["../../../../../../../packages/vite/hmr/frameworks/angular/build/inject-component-hmr-registration.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2CG;AAEH,OAAO,EAAE,qBAAqB,EAAE,MAAM,eAAe,CAAC;AAEtD,MAAM,sBAAsB,GAAG,kBAAkB,CAAC;AAElD;;;;;GAKG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,0CAA0C,CAAC;AAkB3E;;;;;;;;GAQG;AACH,MAAM,UAAU,mCAAmC,CAAC,cAAwB,EAAE,UAAiD,EAAE;IAChI,IAAI,CAAC,cAAc,IAAI,cAAc,CAAC,MAAM,KAAK,CAAC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C;YACtB,CAAC,IAAI,CAAC,CAAC;YACP,SAAS;QACV,CAAC;QACD,IAAI,IAAI,KAAK,GAAG,IAAI,IAAI,KAAK,GAAG,IAAI,IAAI,KAAK,GAAG,EAAE,CAAC;YAClD,KAAK,GAAG,IAAI,CAAC;YACb,CAAC,EAAE,CAAC;YACJ,SAAS;QACV,CAAC;QACD,CAAC,EAAE,CAAC;IACL,CAAC;IAED,OAAO,aAAa,IAAI,cAAc,IAAI,KAAK,KAAK,IAAI,CAAC;AAC1D,CAAC;AAED,yDAAyD"}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Re-inject `/* @vite-ignore *\/` into Angular's HMR initializer dynamic
|
|
3
|
+
* imports.
|
|
4
|
+
*
|
|
5
|
+
* # Why this exists
|
|
6
|
+
*
|
|
7
|
+
* Angular's compiler (`@angular/compiler`'s `compileHmrInitializer`) emits
|
|
8
|
+
* each `@Component`-decorated class's HMR loader as:
|
|
9
|
+
*
|
|
10
|
+
* ```js
|
|
11
|
+
* function FooComponent_HmrLoad(t) {
|
|
12
|
+
* import(\/* @vite-ignore *\/ i0.ɵɵgetReplaceMetadataURL(id, t, import.meta.url))
|
|
13
|
+
* .then((m) => m.default && i0.ɵɵreplaceMetadata(FooComponent, m.default, ...));
|
|
14
|
+
* }
|
|
15
|
+
* ```
|
|
16
|
+
*
|
|
17
|
+
* The `\/* @vite-ignore *\/` annotation tells Vite "do not try to
|
|
18
|
+
* statically analyze this dynamic import" — the URL is computed at
|
|
19
|
+
* runtime by `ɵɵgetReplaceMetadataURL`, which produces something like
|
|
20
|
+
* `http://host/ns/m/<componentDir>/@ng/component?c=<id>&t=<ts>` to be
|
|
21
|
+
* resolved by Analog's `liveReloadPlugin` middleware on the dev server.
|
|
22
|
+
*
|
|
23
|
+
* Somewhere along the post-Angular transform chain — empirically the
|
|
24
|
+
* `compact: false` Babel pass driven by the Angular linker, but
|
|
25
|
+
* potentially other plugins as well — the leading-argument comment is
|
|
26
|
+
* being dropped. By the time the file lands on the device, the
|
|
27
|
+
* compiled emit reads:
|
|
28
|
+
*
|
|
29
|
+
* ```js
|
|
30
|
+
* import(i0.ɵɵgetReplaceMetadataURL(id, t, import.meta.url))
|
|
31
|
+
* ```
|
|
32
|
+
*
|
|
33
|
+
* Vite's static analyzer logs:
|
|
34
|
+
*
|
|
35
|
+
* > The above dynamic import cannot be analyzed by Vite.
|
|
36
|
+
*
|
|
37
|
+
* and rewrites the call site to route through Vite's runtime resolver,
|
|
38
|
+
* which fails on the iOS runtime because the resolver expects a
|
|
39
|
+
* statically-known module specifier. The HMR loader IIFE runs at every
|
|
40
|
+
* component module evaluation (gated by `ngDevMode`), so the failure
|
|
41
|
+
* fires at boot for the FIRST `@Component` whose module is evaluated —
|
|
42
|
+
* typically a base/utility component like `ConfirmationDialogBaseComponent`
|
|
43
|
+
* — and aborts session startup with:
|
|
44
|
+
*
|
|
45
|
+
* > TypeError at Module.ɵɵgetReplaceMetadataURL
|
|
46
|
+
*
|
|
47
|
+
* Re-inserting the annotation downstream of every other transform makes
|
|
48
|
+
* us tolerant of upstream comment-loss without depending on the linker's
|
|
49
|
+
* comment behaviour. The fix is purely additive: if the comment is still
|
|
50
|
+
* present (Angular versions that emit it differently, or future
|
|
51
|
+
* compilers that wrap the URL in an alternate helper), `appendIfMissing`
|
|
52
|
+
* leaves the import untouched.
|
|
53
|
+
*
|
|
54
|
+
* # Idempotence
|
|
55
|
+
*
|
|
56
|
+
* The helper is safe to call repeatedly on the same source — once the
|
|
57
|
+
* annotation is present, subsequent calls become a no-op match by match.
|
|
58
|
+
* Vite's transform pipeline can replay cached transforms during a
|
|
59
|
+
* single dev session, so idempotence is required, not optional.
|
|
60
|
+
*
|
|
61
|
+
* # Surface area
|
|
62
|
+
*
|
|
63
|
+
* We only touch `import()` calls whose argument expression contains
|
|
64
|
+
* `ɵɵgetReplaceMetadataURL` (matching either the literal Unicode form
|
|
65
|
+
* or the escaped `\u0275\u0275getReplaceMetadataURL`). Every other
|
|
66
|
+
* dynamic import is left alone — an over-broad sweep would suppress
|
|
67
|
+
* Vite warnings on user dynamic imports that genuinely should be
|
|
68
|
+
* statically analyzed.
|
|
69
|
+
*/
|
|
70
|
+
/**
|
|
71
|
+
* Inject `/* @vite-ignore *\/` into every `import()` whose argument
|
|
72
|
+
* references Angular's `ɵɵgetReplaceMetadataURL`. Returns the original
|
|
73
|
+
* code unchanged when no qualifying imports are found.
|
|
74
|
+
*/
|
|
75
|
+
export declare function injectAngularHmrViteIgnore(code: string): string;
|