@nativescript/vite 8.0.0-alpha.0 → 8.0.0-alpha.10
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/configuration/angular.d.ts +1 -1
- package/configuration/angular.js +486 -140
- package/configuration/angular.js.map +1 -1
- package/configuration/base.js +159 -41
- package/configuration/base.js.map +1 -1
- package/configuration/javascript.js +3 -3
- package/configuration/javascript.js.map +1 -1
- package/configuration/solid.js +7 -0
- package/configuration/solid.js.map +1 -1
- package/configuration/typescript.js +4 -4
- package/configuration/typescript.js.map +1 -1
- package/helpers/angular/angular-linker.js +38 -42
- package/helpers/angular/angular-linker.js.map +1 -1
- package/helpers/angular/inject-component-hmr-registration.d.ts +112 -0
- package/helpers/angular/inject-component-hmr-registration.js +359 -0
- package/helpers/angular/inject-component-hmr-registration.js.map +1 -0
- package/helpers/angular/inline-decorator-component-templates.d.ts +3 -0
- package/helpers/angular/inline-decorator-component-templates.js +400 -0
- package/helpers/angular/inline-decorator-component-templates.js.map +1 -0
- package/helpers/angular/shared-linker.d.ts +7 -0
- package/helpers/angular/shared-linker.js +37 -1
- package/helpers/angular/shared-linker.js.map +1 -1
- package/helpers/angular/synthesize-decorator-ctor-parameters.d.ts +1 -0
- package/helpers/angular/synthesize-decorator-ctor-parameters.js +256 -0
- package/helpers/angular/synthesize-decorator-ctor-parameters.js.map +1 -0
- package/helpers/angular/synthesize-injectable-factories.d.ts +3 -0
- package/helpers/angular/synthesize-injectable-factories.js +414 -0
- package/helpers/angular/synthesize-injectable-factories.js.map +1 -0
- package/helpers/angular/util.d.ts +1 -0
- package/helpers/angular/util.js +88 -0
- package/helpers/angular/util.js.map +1 -1
- package/helpers/commonjs-plugins.d.ts +5 -2
- package/helpers/commonjs-plugins.js +126 -0
- package/helpers/commonjs-plugins.js.map +1 -1
- package/helpers/config-as-json.js +10 -0
- package/helpers/config-as-json.js.map +1 -1
- package/helpers/esbuild-platform-resolver.js +5 -5
- package/helpers/esbuild-platform-resolver.js.map +1 -1
- package/helpers/external-configs.d.ts +9 -1
- package/helpers/external-configs.js +31 -6
- package/helpers/external-configs.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/import-meta-path.d.ts +4 -0
- package/helpers/import-meta-path.js +5 -0
- package/helpers/import-meta-path.js.map +1 -0
- package/helpers/import-specifier.d.ts +1 -0
- package/helpers/import-specifier.js +18 -0
- package/helpers/import-specifier.js.map +1 -0
- package/helpers/logging.d.ts +1 -0
- package/helpers/logging.js +63 -3
- package/helpers/logging.js.map +1 -1
- package/helpers/main-entry.d.ts +5 -2
- package/helpers/main-entry.js +365 -116
- package/helpers/main-entry.js.map +1 -1
- package/helpers/nativeclass-transform.js +8 -127
- package/helpers/nativeclass-transform.js.map +1 -1
- package/helpers/nativeclass-transformer-plugin.d.ts +19 -1
- package/helpers/nativeclass-transformer-plugin.js +318 -31
- package/helpers/nativeclass-transformer-plugin.js.map +1 -1
- package/helpers/ns-core-url.d.ts +83 -0
- package/helpers/ns-core-url.js +167 -0
- package/helpers/ns-core-url.js.map +1 -0
- package/helpers/prelink-angular.js +1 -4
- package/helpers/prelink-angular.js.map +1 -1
- package/helpers/preserve-imports.js +2 -17
- package/helpers/preserve-imports.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/ts-config-paths.js +50 -2
- package/helpers/ts-config-paths.js.map +1 -1
- package/helpers/workers.d.ts +20 -19
- package/helpers/workers.js +620 -3
- package/helpers/workers.js.map +1 -1
- package/hmr/client/css-handler.js +60 -19
- package/hmr/client/css-handler.js.map +1 -1
- 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 +597 -24
- package/hmr/client/index.js.map +1 -1
- package/hmr/client/utils.d.ts +5 -0
- package/hmr/client/utils.js +212 -21
- package/hmr/client/utils.js.map +1 -1
- package/hmr/entry-runtime.d.ts +10 -0
- package/hmr/entry-runtime.js +330 -42
- package/hmr/entry-runtime.js.map +1 -1
- package/hmr/frameworks/angular/client/index.d.ts +3 -1
- package/hmr/frameworks/angular/client/index.js +821 -25
- package/hmr/frameworks/angular/client/index.js.map +1 -1
- package/hmr/frameworks/angular/server/linker.js +37 -6
- package/hmr/frameworks/angular/server/linker.js.map +1 -1
- package/hmr/frameworks/angular/server/strategy.js +30 -6
- package/hmr/frameworks/angular/server/strategy.js.map +1 -1
- package/hmr/frameworks/typescript/server/strategy.js +8 -2
- package/hmr/frameworks/typescript/server/strategy.js.map +1 -1
- package/hmr/frameworks/vue/client/index.js +18 -42
- package/hmr/frameworks/vue/client/index.js.map +1 -1
- package/hmr/helpers/ast-normalizer.js +22 -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/server/constants.d.ts +1 -0
- package/hmr/server/constants.js +14 -3
- package/hmr/server/constants.js.map +1 -1
- package/hmr/server/core-sanitize.d.ts +49 -2
- package/hmr/server/core-sanitize.js +267 -24
- package/hmr/server/core-sanitize.js.map +1 -1
- package/hmr/server/import-map.d.ts +65 -0
- package/hmr/server/import-map.js +222 -0
- package/hmr/server/import-map.js.map +1 -0
- package/hmr/server/index.d.ts +2 -1
- 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/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/runtime-graph-filter.d.ts +5 -0
- package/hmr/server/runtime-graph-filter.js +21 -0
- package/hmr/server/runtime-graph-filter.js.map +1 -0
- package/hmr/server/shared-transform-request.d.ts +12 -0
- package/hmr/server/shared-transform-request.js +144 -0
- package/hmr/server/shared-transform-request.js.map +1 -0
- package/hmr/server/vite-plugin.d.ts +21 -1
- package/hmr/server/vite-plugin.js +461 -22
- package/hmr/server/vite-plugin.js.map +1 -1
- package/hmr/server/websocket-angular-entry.d.ts +2 -0
- package/hmr/server/websocket-angular-entry.js +68 -0
- package/hmr/server/websocket-angular-entry.js.map +1 -0
- package/hmr/server/websocket-angular-hot-update.d.ts +78 -0
- package/hmr/server/websocket-angular-hot-update.js +413 -0
- package/hmr/server/websocket-angular-hot-update.js.map +1 -0
- package/hmr/server/websocket-core-bridge.d.ts +21 -0
- package/hmr/server/websocket-core-bridge.js +357 -0
- package/hmr/server/websocket-core-bridge.js.map +1 -0
- package/hmr/server/websocket-graph-upsert.d.ts +21 -0
- package/hmr/server/websocket-graph-upsert.js +33 -0
- package/hmr/server/websocket-graph-upsert.js.map +1 -0
- package/hmr/server/websocket-hmr-pending.d.ts +43 -0
- package/hmr/server/websocket-hmr-pending.js +55 -0
- package/hmr/server/websocket-hmr-pending.js.map +1 -0
- package/hmr/server/websocket-module-bindings.d.ts +6 -0
- package/hmr/server/websocket-module-bindings.js +471 -0
- package/hmr/server/websocket-module-bindings.js.map +1 -0
- package/hmr/server/websocket-module-specifiers.d.ts +101 -0
- package/hmr/server/websocket-module-specifiers.js +820 -0
- package/hmr/server/websocket-module-specifiers.js.map +1 -0
- package/hmr/server/websocket-ns-m-finalize.d.ts +22 -0
- package/hmr/server/websocket-ns-m-finalize.js +88 -0
- package/hmr/server/websocket-ns-m-finalize.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-runtime-compat.d.ts +19 -0
- package/hmr/server/websocket-runtime-compat.js +287 -0
- package/hmr/server/websocket-runtime-compat.js.map +1 -0
- package/hmr/server/websocket-served-module-helpers.d.ts +36 -0
- package/hmr/server/websocket-served-module-helpers.js +631 -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 +45 -0
- package/hmr/server/websocket-txn.js.map +1 -0
- package/hmr/server/websocket-vendor-unifier.d.ts +10 -0
- package/hmr/server/websocket-vendor-unifier.js +51 -0
- package/hmr/server/websocket-vendor-unifier.js.map +1 -0
- package/hmr/server/websocket-vue-sfc.d.ts +27 -0
- package/hmr/server/websocket-vue-sfc.js +1069 -0
- package/hmr/server/websocket-vue-sfc.js.map +1 -0
- package/hmr/server/websocket.d.ts +26 -3
- package/hmr/server/websocket.js +2233 -796
- package/hmr/server/websocket.js.map +1 -1
- package/hmr/shared/package-classifier.d.ts +9 -0
- package/hmr/shared/package-classifier.js +58 -0
- package/hmr/shared/package-classifier.js.map +1 -0
- package/hmr/shared/runtime/boot-timeline.d.ts +17 -0
- package/hmr/shared/runtime/boot-timeline.js +51 -0
- package/hmr/shared/runtime/boot-timeline.js.map +1 -0
- package/hmr/shared/runtime/browser-runtime-contract.d.ts +64 -0
- package/hmr/shared/runtime/browser-runtime-contract.js +54 -0
- package/hmr/shared/runtime/browser-runtime-contract.js.map +1 -0
- package/hmr/shared/runtime/dev-overlay.d.ts +85 -0
- package/hmr/shared/runtime/dev-overlay.js +1236 -0
- package/hmr/shared/runtime/dev-overlay.js.map +1 -0
- package/hmr/shared/runtime/http-only-boot.d.ts +1 -0
- package/hmr/shared/runtime/http-only-boot.js +53 -6
- package/hmr/shared/runtime/http-only-boot.js.map +1 -1
- package/hmr/shared/runtime/module-provenance.d.ts +1 -0
- package/hmr/shared/runtime/module-provenance.js +63 -0
- package/hmr/shared/runtime/module-provenance.js.map +1 -0
- package/hmr/shared/runtime/platform-polyfills.d.ts +26 -0
- package/hmr/shared/runtime/platform-polyfills.js +122 -0
- package/hmr/shared/runtime/platform-polyfills.js.map +1 -0
- package/hmr/shared/runtime/root-placeholder.d.ts +1 -0
- package/hmr/shared/runtime/root-placeholder.js +552 -82
- package/hmr/shared/runtime/root-placeholder.js.map +1 -1
- package/hmr/shared/runtime/session-bootstrap.d.ts +1 -0
- package/hmr/shared/runtime/session-bootstrap.js +195 -0
- package/hmr/shared/runtime/session-bootstrap.js.map +1 -0
- package/hmr/shared/runtime/vendor-bootstrap.js +52 -15
- package/hmr/shared/runtime/vendor-bootstrap.js.map +1 -1
- package/hmr/shared/vendor/manifest.d.ts +37 -0
- package/hmr/shared/vendor/manifest.js +677 -57
- package/hmr/shared/vendor/manifest.js.map +1 -1
- package/hmr/shared/vendor/registry.js +104 -7
- package/hmr/shared/vendor/registry.js.map +1 -1
- package/index.d.ts +1 -0
- package/index.js +5 -0
- package/index.js.map +1 -1
- package/package.json +14 -2
- package/runtime/core-aliases-early.js +94 -67
- package/runtime/core-aliases-early.js.map +1 -1
- package/shims/solid-jsx-runtime.d.ts +7 -0
- package/shims/solid-jsx-runtime.js +17 -0
- package/shims/solid-jsx-runtime.js.map +1 -0
|
@@ -0,0 +1,820 @@
|
|
|
1
|
+
import { existsSync, readFileSync, realpathSync } from 'fs';
|
|
2
|
+
import * as path from 'path';
|
|
3
|
+
import * as PAT from './constants.js';
|
|
4
|
+
import { getVendorManifest, resolveVendorSpecifier } from '../shared/vendor/registry.js';
|
|
5
|
+
import { getProjectRootPath } from '../../helpers/project.js';
|
|
6
|
+
import { extractRootPackageName, getPackageRuntimeInfo } from '../shared/package-classifier.js';
|
|
7
|
+
const ESM_FRAMEWORK_PACKAGE_ROOTS = new Set(['@nativescript/angular', 'nativescript-angular']);
|
|
8
|
+
const BUILD_TIME_ONLY_PACKAGE_ROOTS = new Set(['@nativescript/vite', '@nativescript/webpack', '@nativescript/android', '@nativescript/ios', '@nativescript/visionos', 'vite', 'webpack', 'esbuild', 'typescript', 'ts-node', 'prettier']);
|
|
9
|
+
const BUILD_TIME_ONLY_PACKAGE_PREFIXES = ['@vitejs/', '@rollup/', '@babel/', '@angular-devkit/', '@angular/build', '@analogjs/', 'vite-plugin-'];
|
|
10
|
+
const EXPLICIT_RUNTIME_PLUGIN_SCRIPT_EXT_RE = /(?:\.(?:ios|android|visionos))?\.(?:ts|tsx|js|jsx|mjs|mts|cts)$/i;
|
|
11
|
+
function hasExplicitRuntimePluginScriptExtension(segment) {
|
|
12
|
+
return EXPLICIT_RUNTIME_PLUGIN_SCRIPT_EXT_RE.test(segment);
|
|
13
|
+
}
|
|
14
|
+
export function extractVitePrebundleId(spec) {
|
|
15
|
+
const m = spec.match(/\.vite\/deps\/([^?]+?)\.[mc]?js/);
|
|
16
|
+
if (m)
|
|
17
|
+
return m[1];
|
|
18
|
+
const m2 = spec.match(/__x00__([^?]+?)\.[mc]?js/);
|
|
19
|
+
if (m2)
|
|
20
|
+
return m2[1];
|
|
21
|
+
return null;
|
|
22
|
+
}
|
|
23
|
+
export function getFlattenedManifestMap(manifest) {
|
|
24
|
+
const map = new Map();
|
|
25
|
+
const mods = Object.keys(manifest.modules || {});
|
|
26
|
+
for (const canonical of mods) {
|
|
27
|
+
const flat = canonical.replace(/\./g, '__').replace(/\//g, '_');
|
|
28
|
+
map.set(flat, canonical);
|
|
29
|
+
const alias = manifest.aliases?.[canonical];
|
|
30
|
+
if (alias) {
|
|
31
|
+
const aliasFlat = String(alias).replace(/\./g, '__').replace(/\//g, '_');
|
|
32
|
+
map.set(aliasFlat, canonical);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
return map;
|
|
36
|
+
}
|
|
37
|
+
export function normalizeNativeScriptCoreSpecifier(spec) {
|
|
38
|
+
let normalized = spec.replace(/@nativescript[_-]core/gi, '@nativescript/core').replace(/@nativescript\/core\/index\.js$/i, '@nativescript/core/index.js');
|
|
39
|
+
if (normalized.startsWith('/node_modules/')) {
|
|
40
|
+
const idx = normalized.toLowerCase().indexOf('@nativescript/core');
|
|
41
|
+
if (idx !== -1) {
|
|
42
|
+
normalized = normalized.slice(idx);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
if (normalized.toLowerCase().startsWith('@nativescript/core')) {
|
|
46
|
+
normalized = normalized.replace(/\?[^"'`]*$/, '');
|
|
47
|
+
}
|
|
48
|
+
return normalized;
|
|
49
|
+
}
|
|
50
|
+
export function normalizeNodeModulesSpecifier(spec) {
|
|
51
|
+
if (!spec) {
|
|
52
|
+
return null;
|
|
53
|
+
}
|
|
54
|
+
let normalized = spec.replace(/\\/g, '/');
|
|
55
|
+
const idx = normalized.lastIndexOf('/node_modules/');
|
|
56
|
+
if (idx === -1) {
|
|
57
|
+
return null;
|
|
58
|
+
}
|
|
59
|
+
let subPath = normalized.slice(idx + '/node_modules/'.length);
|
|
60
|
+
if (!subPath) {
|
|
61
|
+
return null;
|
|
62
|
+
}
|
|
63
|
+
subPath = subPath.replace(PAT.QUERY_PATTERN, '');
|
|
64
|
+
if (!subPath) {
|
|
65
|
+
return null;
|
|
66
|
+
}
|
|
67
|
+
if (subPath.startsWith('.vite/')) {
|
|
68
|
+
return null;
|
|
69
|
+
}
|
|
70
|
+
return subPath.startsWith('/') ? subPath.slice(1) : subPath;
|
|
71
|
+
}
|
|
72
|
+
export function isEsmFrameworkPackageSpecifier(spec) {
|
|
73
|
+
if (!spec)
|
|
74
|
+
return false;
|
|
75
|
+
const cleaned = spec.replace(PAT.QUERY_PATTERN, '');
|
|
76
|
+
const normalized = normalizeNodeModulesSpecifier(cleaned) || cleaned.replace(/^\/+/, '');
|
|
77
|
+
const root = extractRootPackageName(normalized);
|
|
78
|
+
return ESM_FRAMEWORK_PACKAGE_ROOTS.has(root);
|
|
79
|
+
}
|
|
80
|
+
export function isCoreGlobalsReference(spec) {
|
|
81
|
+
return /@nativescript(?:[\/_-])core(?:[\/_-])globals/.test(spec || '');
|
|
82
|
+
}
|
|
83
|
+
export function isNativeScriptCoreModule(spec) {
|
|
84
|
+
return /^(?:@nativescript[\/_-]core|@nativescript\/core)(?:\b|\/)/i.test(spec || '');
|
|
85
|
+
}
|
|
86
|
+
export function isNativeScriptPluginModule(spec) {
|
|
87
|
+
return /^@nativescript\//i.test(spec || '') && !isNativeScriptCoreModule(spec || '');
|
|
88
|
+
}
|
|
89
|
+
function isBuildTimeOnlyPackageRoot(root) {
|
|
90
|
+
if (!root)
|
|
91
|
+
return false;
|
|
92
|
+
if (BUILD_TIME_ONLY_PACKAGE_ROOTS.has(root))
|
|
93
|
+
return true;
|
|
94
|
+
return BUILD_TIME_ONLY_PACKAGE_PREFIXES.some((prefix) => root.startsWith(prefix));
|
|
95
|
+
}
|
|
96
|
+
function isAllowedNativeScriptViteDeviceSubpath(spec) {
|
|
97
|
+
const cleaned = spec.replace(PAT.QUERY_PATTERN, '');
|
|
98
|
+
const normalized = normalizeNodeModulesSpecifier(cleaned) || cleaned.replace(/^\/+/, '');
|
|
99
|
+
const pkgName = extractRootPackageName(normalized) || normalized;
|
|
100
|
+
if (pkgName !== '@nativescript/vite') {
|
|
101
|
+
return true;
|
|
102
|
+
}
|
|
103
|
+
const subpath = normalized.slice(pkgName.length).replace(/^\/+/, '');
|
|
104
|
+
if (!subpath) {
|
|
105
|
+
return false;
|
|
106
|
+
}
|
|
107
|
+
return subpath === 'hmr/entry-runtime.js' || subpath.startsWith('hmr/client/') || /^hmr\/frameworks\/[^/]+\/client\//.test(subpath) || subpath.startsWith('hmr/shared/runtime/') || subpath.startsWith('shims/') || subpath === 'runtime/core-aliases-early.js' || subpath === 'polyfills/module.js';
|
|
108
|
+
}
|
|
109
|
+
export function getBlockedDeviceNodeModulesReason(spec) {
|
|
110
|
+
if (!spec)
|
|
111
|
+
return null;
|
|
112
|
+
const cleaned = spec.replace(PAT.QUERY_PATTERN, '');
|
|
113
|
+
const normalized = normalizeNodeModulesSpecifier(cleaned) || cleaned.replace(/^\/+/, '');
|
|
114
|
+
const pkgName = extractRootPackageName(normalized) || normalized;
|
|
115
|
+
if (!pkgName) {
|
|
116
|
+
return null;
|
|
117
|
+
}
|
|
118
|
+
if (pkgName === '@nativescript/vite') {
|
|
119
|
+
if (isAllowedNativeScriptViteDeviceSubpath(normalized)) {
|
|
120
|
+
return null;
|
|
121
|
+
}
|
|
122
|
+
const subpath = normalized.slice(pkgName.length).replace(/^\/+/, '');
|
|
123
|
+
return subpath ? `build-time NativeScript Vite module is not device-loadable: ${pkgName}/${subpath}` : 'build-time NativeScript Vite package root is not device-loadable';
|
|
124
|
+
}
|
|
125
|
+
if (isBuildTimeOnlyPackageRoot(pkgName)) {
|
|
126
|
+
return `build-time package is not device-loadable: ${pkgName}`;
|
|
127
|
+
}
|
|
128
|
+
return null;
|
|
129
|
+
}
|
|
130
|
+
export function isLikelyNativeScriptRuntimePluginSpecifier(spec, projectRoot = getProjectRootPath()) {
|
|
131
|
+
if (!spec)
|
|
132
|
+
return false;
|
|
133
|
+
const s = spec.replace(PAT.QUERY_PATTERN, '');
|
|
134
|
+
if (/^(?:\.|\/|https?:\/\/)/i.test(s))
|
|
135
|
+
return false;
|
|
136
|
+
if (s.startsWith('@@/'))
|
|
137
|
+
return false;
|
|
138
|
+
if (s.startsWith('~/'))
|
|
139
|
+
return false;
|
|
140
|
+
if (s.startsWith('@/'))
|
|
141
|
+
return false;
|
|
142
|
+
if (/\.vue(?:\?|$)/i.test(s))
|
|
143
|
+
return false;
|
|
144
|
+
const root = extractRootPackageName(s) || s;
|
|
145
|
+
if (!root)
|
|
146
|
+
return false;
|
|
147
|
+
if (isNativeScriptCoreModule(root))
|
|
148
|
+
return false;
|
|
149
|
+
if (ESM_FRAMEWORK_PACKAGE_ROOTS.has(root))
|
|
150
|
+
return false;
|
|
151
|
+
if (/^(?:vue|nativescript-vue)(?:\b|\/)/i.test(root))
|
|
152
|
+
return false;
|
|
153
|
+
if (isBuildTimeOnlyPackageRoot(root))
|
|
154
|
+
return false;
|
|
155
|
+
if (getPackageRuntimeInfo(root, projectRoot).hasNativeScriptMetadata)
|
|
156
|
+
return true;
|
|
157
|
+
if (/^@nativescript\//i.test(root))
|
|
158
|
+
return true;
|
|
159
|
+
if (/^(?:@nativescript-community|@nstudio|@mleleux)\//i.test(root))
|
|
160
|
+
return true;
|
|
161
|
+
return /(?:^|\/)nativescript(?:$|[-_])/i.test(root);
|
|
162
|
+
}
|
|
163
|
+
export function isLikelyNativeScriptPluginSpecifier(spec, projectRoot = getProjectRootPath()) {
|
|
164
|
+
if (!spec)
|
|
165
|
+
return false;
|
|
166
|
+
const s = spec.replace(PAT.QUERY_PATTERN, '');
|
|
167
|
+
if (/^(?:\.|\/|https?:\/\/)/i.test(s))
|
|
168
|
+
return false;
|
|
169
|
+
if (s.startsWith('@@/'))
|
|
170
|
+
return false;
|
|
171
|
+
if (s.startsWith('~/'))
|
|
172
|
+
return false;
|
|
173
|
+
if (s.startsWith('@/'))
|
|
174
|
+
return false;
|
|
175
|
+
if (/\.vue(?:\?|$)/i.test(s))
|
|
176
|
+
return false;
|
|
177
|
+
if (/^@nativescript\/core(\b|\/)/i.test(s))
|
|
178
|
+
return false;
|
|
179
|
+
if (isEsmFrameworkPackageSpecifier(s))
|
|
180
|
+
return false;
|
|
181
|
+
if (/^(?:vue|nativescript-vue)(?:\b|\/)/i.test(s))
|
|
182
|
+
return false;
|
|
183
|
+
const root = extractRootPackageName(s) || s;
|
|
184
|
+
if (isBuildTimeOnlyPackageRoot(root))
|
|
185
|
+
return false;
|
|
186
|
+
if (getPackageRuntimeInfo(root, projectRoot).hasNativeScriptMetadata)
|
|
187
|
+
return true;
|
|
188
|
+
return true;
|
|
189
|
+
}
|
|
190
|
+
export function tryReadRawExplicitJavaScriptModule(spec, projectRoot) {
|
|
191
|
+
if (!spec || !spec.startsWith('/'))
|
|
192
|
+
return null;
|
|
193
|
+
if (spec.startsWith('/@id/') || spec.startsWith('/@fs/'))
|
|
194
|
+
return null;
|
|
195
|
+
if (!/\.js$/i.test(spec) || /\.(?:mjs|cjs)$/i.test(spec))
|
|
196
|
+
return null;
|
|
197
|
+
try {
|
|
198
|
+
const nodeModulesSpecifier = normalizeNodeModulesSpecifier(spec);
|
|
199
|
+
if (nodeModulesSpecifier) {
|
|
200
|
+
const pkgName = extractRootPackageName(nodeModulesSpecifier);
|
|
201
|
+
if (isLikelyNativeScriptRuntimePluginSpecifier(pkgName, projectRoot)) {
|
|
202
|
+
return null;
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
catch { }
|
|
207
|
+
// source-map-js ships as CJS with relative require() calls that need
|
|
208
|
+
// ESM conversion via sourceMapJsCompatPlugin. Force Vite transforms.
|
|
209
|
+
if (/\/node_modules\/source-map-js\//.test(spec))
|
|
210
|
+
return null;
|
|
211
|
+
const root = path.resolve(projectRoot);
|
|
212
|
+
const absPath = path.resolve(root, `.${spec}`);
|
|
213
|
+
if (!absPath.startsWith(root + path.sep) && absPath !== root)
|
|
214
|
+
return null;
|
|
215
|
+
try {
|
|
216
|
+
const code = existsSync(absPath) ? readFileSync(absPath, 'utf-8') : null;
|
|
217
|
+
if (code != null) {
|
|
218
|
+
const usesNodeModuleInterop = /(?:from\s*['"](?:node:)?module['"]|import\s*\{[^}]*\bcreateRequire\b[^}]*\}\s*from\s*['"](?:node:)?module['"]|\bcreateRequire\s*\()/m.test(code);
|
|
219
|
+
if (usesNodeModuleInterop) {
|
|
220
|
+
return null;
|
|
221
|
+
}
|
|
222
|
+
// For node_modules files that use CJS require() with relative
|
|
223
|
+
// specifiers, defer to Vite transforms so the ESM conversion
|
|
224
|
+
// plugins (e.g. sourceMapJsCompatPlugin) can run. Raw reads
|
|
225
|
+
// leave `require('./x')` intact, which then hits NS's native
|
|
226
|
+
// file-based require and fails on HTTP URLs.
|
|
227
|
+
if (/\/node_modules\//.test(spec) && /\brequire\s*\(\s*['"]\.{1,2}\//.test(code)) {
|
|
228
|
+
return null;
|
|
229
|
+
}
|
|
230
|
+
return { code, resolvedId: spec };
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
catch { }
|
|
234
|
+
return null;
|
|
235
|
+
}
|
|
236
|
+
export function stripDecoratedServePrefixes(spec) {
|
|
237
|
+
let cleanedSpec = spec || '';
|
|
238
|
+
let bootTaggedRequest = false;
|
|
239
|
+
let forcedVer = null;
|
|
240
|
+
try {
|
|
241
|
+
let changed = true;
|
|
242
|
+
while (changed) {
|
|
243
|
+
changed = false;
|
|
244
|
+
const bootMatch = cleanedSpec.match(/^\/?__ns_boot__\/[^\/]+(\/.*)?$/);
|
|
245
|
+
if (bootMatch) {
|
|
246
|
+
bootTaggedRequest = true;
|
|
247
|
+
cleanedSpec = bootMatch[1] || '/';
|
|
248
|
+
changed = true;
|
|
249
|
+
}
|
|
250
|
+
const hmrMatch = cleanedSpec.match(/^\/?__ns_hmr__\/([^\/]+)(\/.*)?$/);
|
|
251
|
+
if (hmrMatch) {
|
|
252
|
+
const tag = hmrMatch[1] || '';
|
|
253
|
+
if (tag) {
|
|
254
|
+
forcedVer = tag;
|
|
255
|
+
}
|
|
256
|
+
cleanedSpec = hmrMatch[2] || '/';
|
|
257
|
+
changed = true;
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
catch { }
|
|
262
|
+
return { cleanedSpec, bootTaggedRequest, forcedVer };
|
|
263
|
+
}
|
|
264
|
+
export function resolveVendorFromCandidate(specifier) {
|
|
265
|
+
if (!specifier) {
|
|
266
|
+
return null;
|
|
267
|
+
}
|
|
268
|
+
const manifest = getVendorManifest();
|
|
269
|
+
if (!manifest) {
|
|
270
|
+
return null;
|
|
271
|
+
}
|
|
272
|
+
const cleaned = specifier.replace(PAT.QUERY_PATTERN, '');
|
|
273
|
+
const direct = resolveVendorSpecifier(cleaned);
|
|
274
|
+
if (direct) {
|
|
275
|
+
return direct;
|
|
276
|
+
}
|
|
277
|
+
const flattenedId = extractVitePrebundleId(cleaned);
|
|
278
|
+
if (flattenedId) {
|
|
279
|
+
const flattenedMap = getFlattenedManifestMap(manifest);
|
|
280
|
+
const flatMatch = flattenedMap.get(flattenedId);
|
|
281
|
+
if (flatMatch) {
|
|
282
|
+
return flatMatch;
|
|
283
|
+
}
|
|
284
|
+
for (const [flatKey, canonical] of flattenedMap.entries()) {
|
|
285
|
+
if (flattenedId === flatKey) {
|
|
286
|
+
return canonical;
|
|
287
|
+
}
|
|
288
|
+
if (flattenedId.startsWith(`${flatKey}_`)) {
|
|
289
|
+
const flatSuffix = flattenedId.slice(flatKey.length + 1);
|
|
290
|
+
const subpath = flatSuffix.replace(/_/g, '/');
|
|
291
|
+
if (isFileDistSubpath(subpath)) {
|
|
292
|
+
return canonical;
|
|
293
|
+
}
|
|
294
|
+
const aliasKey = `${canonical}/${subpath.split('/')[0]}`;
|
|
295
|
+
if (manifest.aliases?.[aliasKey] && manifest.modules[manifest.aliases[aliasKey]]) {
|
|
296
|
+
return manifest.aliases[aliasKey];
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
const guessedId = flattenedId.replace(/__/g, '.').replace(/_/g, '/');
|
|
301
|
+
if (guessedId && guessedId !== flattenedId) {
|
|
302
|
+
const guessedCanonical = resolveVendorSpecifier(guessedId);
|
|
303
|
+
if (guessedCanonical) {
|
|
304
|
+
return guessedCanonical;
|
|
305
|
+
}
|
|
306
|
+
const prefix = findVendorPrefix(guessedId, manifest);
|
|
307
|
+
if (prefix) {
|
|
308
|
+
return prefix;
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
const normalizedCore = normalizeNativeScriptCoreSpecifier(cleaned);
|
|
313
|
+
if (normalizedCore !== cleaned) {
|
|
314
|
+
const nsCanonical = resolveVendorSpecifier(normalizedCore);
|
|
315
|
+
if (nsCanonical) {
|
|
316
|
+
return nsCanonical;
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
const nodeModulesSpecifier = normalizeNodeModulesSpecifier(cleaned);
|
|
320
|
+
if (nodeModulesSpecifier) {
|
|
321
|
+
const canonical = resolveVendorSpecifier(nodeModulesSpecifier);
|
|
322
|
+
if (canonical) {
|
|
323
|
+
return canonical;
|
|
324
|
+
}
|
|
325
|
+
const prefix = findVendorPrefix(nodeModulesSpecifier, manifest);
|
|
326
|
+
if (prefix) {
|
|
327
|
+
return prefix;
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
const prefix = findVendorPrefix(cleaned, manifest);
|
|
331
|
+
if (prefix) {
|
|
332
|
+
return prefix;
|
|
333
|
+
}
|
|
334
|
+
return null;
|
|
335
|
+
}
|
|
336
|
+
/**
|
|
337
|
+
* Resolve a candidate URL ('/node_modules/...', '/@fs/...', or an
|
|
338
|
+
* absolute fs path) to a real file on disk under one of the allowed
|
|
339
|
+
* roots, returning the absolute fs path or `null`.
|
|
340
|
+
*
|
|
341
|
+
* `workspaceRoot` is consulted ONLY when the candidate cannot be
|
|
342
|
+
* resolved under `projectRoot` — this keeps the existing app-local
|
|
343
|
+
* behaviour identical and adds a fallback for monorepos where
|
|
344
|
+
* `node_modules/` is hoisted above the app dir (Nx, Rush, Turborepo,
|
|
345
|
+
* etc.). Without this fallback, every `/ns/m/node_modules/<hoisted-pkg>`
|
|
346
|
+
* request to the dev server's bridge fails with a "transform miss"
|
|
347
|
+
* 404 even though the file is right there at the workspace root.
|
|
348
|
+
*/
|
|
349
|
+
export function resolveCandidateFilePath(candidate, projectRoot, workspaceRoot) {
|
|
350
|
+
const cleaned = candidate.replace(PAT.QUERY_PATTERN, '');
|
|
351
|
+
if (!cleaned)
|
|
352
|
+
return null;
|
|
353
|
+
const tryUnderRoot = (root) => {
|
|
354
|
+
const resolvedRoot = path.resolve(root);
|
|
355
|
+
let absPath = null;
|
|
356
|
+
if (cleaned.startsWith('/@fs/')) {
|
|
357
|
+
absPath = cleaned.slice('/@fs'.length);
|
|
358
|
+
}
|
|
359
|
+
else if (cleaned.includes('/node_modules/')) {
|
|
360
|
+
absPath = path.resolve(resolvedRoot, `.${cleaned}`);
|
|
361
|
+
}
|
|
362
|
+
else if (/^(?:[A-Za-z]:)?\//.test(cleaned)) {
|
|
363
|
+
absPath = path.resolve(cleaned);
|
|
364
|
+
}
|
|
365
|
+
if (!absPath) {
|
|
366
|
+
return null;
|
|
367
|
+
}
|
|
368
|
+
const rel = path.relative(resolvedRoot, absPath);
|
|
369
|
+
if (!rel || rel.startsWith('..') || path.isAbsolute(rel)) {
|
|
370
|
+
return null;
|
|
371
|
+
}
|
|
372
|
+
return existsSync(absPath) ? absPath : null;
|
|
373
|
+
};
|
|
374
|
+
const fromProjectRoot = tryUnderRoot(projectRoot);
|
|
375
|
+
if (fromProjectRoot)
|
|
376
|
+
return fromProjectRoot;
|
|
377
|
+
if (workspaceRoot) {
|
|
378
|
+
const resolvedProject = path.resolve(projectRoot);
|
|
379
|
+
const resolvedWorkspace = path.resolve(workspaceRoot);
|
|
380
|
+
if (resolvedWorkspace !== resolvedProject) {
|
|
381
|
+
return tryUnderRoot(resolvedWorkspace);
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
return null;
|
|
385
|
+
}
|
|
386
|
+
/**
|
|
387
|
+
* Rewrite a `/@fs/<abs-path>` URL into a `/ns/m/<rel>` URL so the chain
|
|
388
|
+
* stays inside our HMR pipeline.
|
|
389
|
+
*
|
|
390
|
+
* Vite's transform output emits `/@fs/<abs-path>` for any module whose
|
|
391
|
+
* resolved id lives outside the configured `root` — including hoisted
|
|
392
|
+
* `node_modules/<pkg>/...` entries and workspace libraries in monorepos
|
|
393
|
+
* (Nx, Rush, Turborepo, pnpm/yarn/npm workspaces, etc.). If we leave
|
|
394
|
+
* those URLs untouched, the device fetches them through Vite's standard
|
|
395
|
+
* middleware which does NOT apply our CJS/UMD-wrapping pipeline; UMD
|
|
396
|
+
* modules like papaparse then crash because top-level `this` is
|
|
397
|
+
* `undefined` in ESM context (the `(function(root, factory) { ... })(this,
|
|
398
|
+
* function moduleFactory() { ... })` IIFE passes `undefined` as `root`
|
|
399
|
+
* and the third branch tries to do `undefined.Papa = factory()`).
|
|
400
|
+
*
|
|
401
|
+
* The conversion preserves any `?...` / `#...` suffix and tries roots in
|
|
402
|
+
* this order:
|
|
403
|
+
* 1. `projectRoot` — app-local files; mirrors the URL shape we already
|
|
404
|
+
* emit for relative imports under the app's own dir.
|
|
405
|
+
* 2. `workspaceRoot` — hoisted `node_modules` and monorepo workspace
|
|
406
|
+
* libs. The `/ns/m/` handler resolves these via its
|
|
407
|
+
* `buildFsCandidate` fallback that probes both roots.
|
|
408
|
+
*
|
|
409
|
+
* Returns `null` when the absolute path is outside both roots; the
|
|
410
|
+
* caller should then leave the original `/@fs/` URL alone (defensive).
|
|
411
|
+
*/
|
|
412
|
+
export function rewriteFsAbsoluteToNsM(spec, projectRoot, workspaceRoot) {
|
|
413
|
+
if (!spec || !spec.startsWith('/@fs/'))
|
|
414
|
+
return null;
|
|
415
|
+
const queryStart = spec.search(/[?#]/);
|
|
416
|
+
const cleanSpec = queryStart !== -1 ? spec.slice(0, queryStart) : spec;
|
|
417
|
+
const querySuffix = queryStart !== -1 ? spec.slice(queryStart) : '';
|
|
418
|
+
// /@fs/<abs-path> — strip the prefix to recover the absolute path.
|
|
419
|
+
// On posix this is "/Users/...". On Windows Vite emits "/@fs/C:/..."
|
|
420
|
+
// where the path retains its drive letter.
|
|
421
|
+
const absPath = cleanSpec.slice('/@fs'.length);
|
|
422
|
+
if (!absPath.startsWith('/'))
|
|
423
|
+
return null;
|
|
424
|
+
const toPosix = (value) => value.replace(/\\/g, '/');
|
|
425
|
+
const stripTrailing = (value) => value.replace(/\/+$/, '');
|
|
426
|
+
const projectRootPosix = stripTrailing(toPosix(path.resolve(projectRoot)));
|
|
427
|
+
const workspaceRootPosix = workspaceRoot ? stripTrailing(toPosix(path.resolve(workspaceRoot))) : null;
|
|
428
|
+
const tryRoot = (root) => {
|
|
429
|
+
if (!root)
|
|
430
|
+
return null;
|
|
431
|
+
if (absPath === root)
|
|
432
|
+
return '';
|
|
433
|
+
if (absPath.startsWith(`${root}/`)) {
|
|
434
|
+
return absPath.slice(root.length + 1);
|
|
435
|
+
}
|
|
436
|
+
return null;
|
|
437
|
+
};
|
|
438
|
+
// App-local first so URLs match the existing `/ns/m/<projectRel>` shape.
|
|
439
|
+
let rel = tryRoot(projectRootPosix);
|
|
440
|
+
if (rel === null && workspaceRootPosix && workspaceRootPosix !== projectRootPosix) {
|
|
441
|
+
rel = tryRoot(workspaceRootPosix);
|
|
442
|
+
}
|
|
443
|
+
if (rel === null)
|
|
444
|
+
return null;
|
|
445
|
+
return rel === '' ? `/ns/m${querySuffix}` : `/ns/m/${rel}${querySuffix}`;
|
|
446
|
+
}
|
|
447
|
+
/**
|
|
448
|
+
* Filter `candidates` (variations of `spec` with different extensions /
|
|
449
|
+
* `index.*`) down to those that exist on disk under `projectRoot` or
|
|
450
|
+
* `workspaceRoot`. Workspace-root-only matches are rewritten to their
|
|
451
|
+
* `/@fs/<abs-path>` form so the downstream `transformRequest` call can
|
|
452
|
+
* load them directly without having to go through Vite's bare-specifier
|
|
453
|
+
* resolver — which is gated by the package's `package.json#exports`
|
|
454
|
+
* field and refuses internal sub-paths even when the file is on disk
|
|
455
|
+
* (e.g. `css-tree/lib/syntax/index.js`).
|
|
456
|
+
*
|
|
457
|
+
* Candidates whose real path (after symlink resolution) lives OUTSIDE
|
|
458
|
+
* any `node_modules` directory are also rewritten to `/@fs/<real-path>`.
|
|
459
|
+
* Vite's built-in esbuild transform plugin excludes `node_modules` paths
|
|
460
|
+
* from TS->JS conversion, so a workspace TypeScript package re-exposed
|
|
461
|
+
* via `node_modules/<scope>/<pkg>` (a common monorepo pattern: e.g.
|
|
462
|
+
* `node_modules/@blackout/plugins -> ../../plugins/src`) would otherwise
|
|
463
|
+
* be served as raw TypeScript and fail at the device with `Missing
|
|
464
|
+
* initializer in const declaration` on type annotations like
|
|
465
|
+
* `export const X: string = '...'`. Routing through the realpath makes
|
|
466
|
+
* Vite see a non-`node_modules` path and the TS transform applies.
|
|
467
|
+
*
|
|
468
|
+
* App-local candidates whose real path is also app-local are returned
|
|
469
|
+
* unchanged so existing behaviour is preserved bit-for-bit.
|
|
470
|
+
*/
|
|
471
|
+
export function filterExistingNodeModulesTransformCandidates(spec, candidates, projectRoot, workspaceRoot) {
|
|
472
|
+
const cleanedSpec = spec.replace(PAT.QUERY_PATTERN, '');
|
|
473
|
+
if (!cleanedSpec.includes('/node_modules/')) {
|
|
474
|
+
return candidates;
|
|
475
|
+
}
|
|
476
|
+
const resolvedProjectRoot = path.resolve(projectRoot);
|
|
477
|
+
const resolvedWorkspaceRoot = workspaceRoot ? path.resolve(workspaceRoot) : null;
|
|
478
|
+
const hasDistinctWorkspaceRoot = !!resolvedWorkspaceRoot && resolvedWorkspaceRoot !== resolvedProjectRoot;
|
|
479
|
+
// The bridge's caller composes `candidates` from both the explicit
|
|
480
|
+
// spec and a fan-out of extension/index variants, which routinely
|
|
481
|
+
// produces the same URL twice (e.g. `/foo/index.js` is both the
|
|
482
|
+
// explicit spec and a `${baseNoExt}.js` variant). Dedup so we don't
|
|
483
|
+
// invoke `transformRequest()` twice for the same path.
|
|
484
|
+
const seen = new Set();
|
|
485
|
+
const result = [];
|
|
486
|
+
for (const candidate of candidates) {
|
|
487
|
+
const resolved = resolveCandidateFilePath(candidate, resolvedProjectRoot, hasDistinctWorkspaceRoot ? resolvedWorkspaceRoot : null);
|
|
488
|
+
if (!resolved)
|
|
489
|
+
continue;
|
|
490
|
+
const cleanedCandidate = candidate.replace(PAT.QUERY_PATTERN, '');
|
|
491
|
+
const querySuffix = candidate.length > cleanedCandidate.length ? candidate.slice(cleanedCandidate.length) : '';
|
|
492
|
+
// Detect "node_modules entry that symlinks to non-node_modules
|
|
493
|
+
// source". This is the canonical NativeScript monorepo pattern for
|
|
494
|
+
// workspace packages re-exposed under `node_modules/<scope>/<pkg>`
|
|
495
|
+
// so the runtime resolver finds them via standard Node resolution.
|
|
496
|
+
// Without this rewrite Vite serves the raw `.ts` source and the
|
|
497
|
+
// device chokes on type annotations.
|
|
498
|
+
let mapped = null;
|
|
499
|
+
try {
|
|
500
|
+
const realResolved = realpathSync(resolved);
|
|
501
|
+
if (realResolved !== resolved) {
|
|
502
|
+
const realIsInsideNodeModules = realResolved.split(path.sep).includes('node_modules');
|
|
503
|
+
if (!realIsInsideNodeModules) {
|
|
504
|
+
mapped = `/@fs${realResolved.replace(/\\/g, '/')}${querySuffix}`;
|
|
505
|
+
}
|
|
506
|
+
}
|
|
507
|
+
}
|
|
508
|
+
catch {
|
|
509
|
+
// realpath may fail on broken or circular symlinks. Fall
|
|
510
|
+
// through to the existing project/workspace logic.
|
|
511
|
+
}
|
|
512
|
+
if (mapped === null) {
|
|
513
|
+
if (!hasDistinctWorkspaceRoot) {
|
|
514
|
+
mapped = candidate;
|
|
515
|
+
}
|
|
516
|
+
else {
|
|
517
|
+
const relFromProject = path.relative(resolvedProjectRoot, resolved);
|
|
518
|
+
const insideProjectRoot = relFromProject !== '' && !relFromProject.startsWith('..') && !path.isAbsolute(relFromProject);
|
|
519
|
+
if (insideProjectRoot) {
|
|
520
|
+
mapped = candidate;
|
|
521
|
+
}
|
|
522
|
+
else {
|
|
523
|
+
// Hoisted `node_modules/<pkg>/...` file lives above projectRoot.
|
|
524
|
+
// Rewrite the URL to its fs-anchored form so Vite reads it directly
|
|
525
|
+
// instead of bouncing through bare-specifier resolution that the
|
|
526
|
+
// hoisted package's `exports` field may refuse.
|
|
527
|
+
mapped = `/@fs${resolved.replace(/\\/g, '/')}${querySuffix}`;
|
|
528
|
+
}
|
|
529
|
+
}
|
|
530
|
+
}
|
|
531
|
+
if (seen.has(mapped))
|
|
532
|
+
continue;
|
|
533
|
+
seen.add(mapped);
|
|
534
|
+
result.push(mapped);
|
|
535
|
+
}
|
|
536
|
+
return result;
|
|
537
|
+
}
|
|
538
|
+
function findVendorPrefix(specifier, manifest) {
|
|
539
|
+
const { modules, aliases } = manifest;
|
|
540
|
+
const keys = Object.keys(modules || {});
|
|
541
|
+
for (const key of keys) {
|
|
542
|
+
if (specifier === key) {
|
|
543
|
+
return key;
|
|
544
|
+
}
|
|
545
|
+
if (specifier.startsWith(`${key}/`)) {
|
|
546
|
+
const subpath = specifier.slice(key.length + 1);
|
|
547
|
+
if (isFileDistSubpath(subpath)) {
|
|
548
|
+
return key;
|
|
549
|
+
}
|
|
550
|
+
const aliasKey = `${key}/${subpath.split('/')[0]}`;
|
|
551
|
+
if (aliases?.[aliasKey] && modules[aliases[aliasKey]]) {
|
|
552
|
+
return aliases[aliasKey];
|
|
553
|
+
}
|
|
554
|
+
continue;
|
|
555
|
+
}
|
|
556
|
+
}
|
|
557
|
+
return null;
|
|
558
|
+
}
|
|
559
|
+
export function viteDepsPathToBareSpecifier(depPath) {
|
|
560
|
+
const manifest = getVendorManifest();
|
|
561
|
+
if (!manifest)
|
|
562
|
+
return null;
|
|
563
|
+
const flatId = extractVitePrebundleId(`.vite/deps/${depPath}`);
|
|
564
|
+
if (!flatId)
|
|
565
|
+
return null;
|
|
566
|
+
const flatMap = getFlattenedManifestMap(manifest);
|
|
567
|
+
if (flatMap.has(flatId)) {
|
|
568
|
+
return flatMap.get(flatId);
|
|
569
|
+
}
|
|
570
|
+
let bestKey = '';
|
|
571
|
+
let bestCanonical = '';
|
|
572
|
+
for (const [flatKey, canonical] of flatMap.entries()) {
|
|
573
|
+
if (flatId.startsWith(`${flatKey}_`) && flatKey.length > bestKey.length) {
|
|
574
|
+
bestKey = flatKey;
|
|
575
|
+
bestCanonical = canonical;
|
|
576
|
+
}
|
|
577
|
+
}
|
|
578
|
+
if (bestKey && bestCanonical) {
|
|
579
|
+
const flatSuffix = flatId.slice(bestKey.length + 1);
|
|
580
|
+
const subpath = flatSuffix.replace(/_/g, '/');
|
|
581
|
+
return `${bestCanonical}/${subpath}`;
|
|
582
|
+
}
|
|
583
|
+
return null;
|
|
584
|
+
}
|
|
585
|
+
function isFileDistSubpath(subpath) {
|
|
586
|
+
const firstSegment = subpath.split('/')[0];
|
|
587
|
+
const FILE_DIST_DIRS = new Set(['dist', 'src', 'lib', 'build', 'esm', 'cjs', 'es', 'umd', 'module', 'bundle', 'output', '_esm', '_cjs']);
|
|
588
|
+
if (FILE_DIST_DIRS.has(firstSegment)) {
|
|
589
|
+
return true;
|
|
590
|
+
}
|
|
591
|
+
if (!subpath.includes('/') && /\.[a-zA-Z0-9]+$/.test(subpath)) {
|
|
592
|
+
return true;
|
|
593
|
+
}
|
|
594
|
+
return false;
|
|
595
|
+
}
|
|
596
|
+
const nodeModulesPackageBoundaryCache = new Map();
|
|
597
|
+
export function resolveNodeModulesPackageBoundary(nodeModulesSpec, projectRoot) {
|
|
598
|
+
const normalized = String(nodeModulesSpec || '')
|
|
599
|
+
.replace(PAT.QUERY_PATTERN, '')
|
|
600
|
+
.replace(/^\/+/, '');
|
|
601
|
+
const resolvedProjectRoot = path.resolve(projectRoot || getProjectRootPath());
|
|
602
|
+
const cacheKey = `${resolvedProjectRoot}::${normalized}`;
|
|
603
|
+
const cached = nodeModulesPackageBoundaryCache.get(cacheKey);
|
|
604
|
+
if (cached) {
|
|
605
|
+
return cached;
|
|
606
|
+
}
|
|
607
|
+
const rootPackageName = extractRootPackageName(normalized) || normalized;
|
|
608
|
+
let packageName = rootPackageName;
|
|
609
|
+
if (packageName && normalized.startsWith(`${packageName}/`)) {
|
|
610
|
+
const segments = normalized.split('/');
|
|
611
|
+
const rootSegmentCount = rootPackageName.startsWith('@') ? 2 : 1;
|
|
612
|
+
for (let end = segments.length; end > rootSegmentCount; end--) {
|
|
613
|
+
const candidate = segments.slice(0, end).join('/');
|
|
614
|
+
if (!candidate || candidate === rootPackageName) {
|
|
615
|
+
continue;
|
|
616
|
+
}
|
|
617
|
+
const candidatePackageJson = path.join(resolvedProjectRoot, 'node_modules', ...candidate.split('/'), 'package.json');
|
|
618
|
+
if (existsSync(candidatePackageJson)) {
|
|
619
|
+
packageName = candidate;
|
|
620
|
+
break;
|
|
621
|
+
}
|
|
622
|
+
}
|
|
623
|
+
}
|
|
624
|
+
const subpath = normalized === packageName ? '' : normalized.slice(packageName.length).replace(/^\/+/, '');
|
|
625
|
+
const resolved = { packageName, subpath };
|
|
626
|
+
nodeModulesPackageBoundaryCache.set(cacheKey, resolved);
|
|
627
|
+
return resolved;
|
|
628
|
+
}
|
|
629
|
+
const exportsReverseMapCache = new Map();
|
|
630
|
+
function resolveExportConditionValue(conditions) {
|
|
631
|
+
if (typeof conditions === 'string')
|
|
632
|
+
return conditions;
|
|
633
|
+
if (typeof conditions !== 'object' || conditions === null)
|
|
634
|
+
return null;
|
|
635
|
+
const obj = conditions;
|
|
636
|
+
for (const key of ['esm2022', 'esm', 'esm2015', 'import', 'module', 'default']) {
|
|
637
|
+
if (key in obj) {
|
|
638
|
+
const result = resolveExportConditionValue(obj[key]);
|
|
639
|
+
if (result)
|
|
640
|
+
return result;
|
|
641
|
+
}
|
|
642
|
+
}
|
|
643
|
+
for (const val of Object.values(obj)) {
|
|
644
|
+
if (typeof val === 'string')
|
|
645
|
+
return val;
|
|
646
|
+
}
|
|
647
|
+
return null;
|
|
648
|
+
}
|
|
649
|
+
function getExportsReverseMap(pkgName, projectRoot) {
|
|
650
|
+
const cached = exportsReverseMapCache.get(pkgName);
|
|
651
|
+
if (cached)
|
|
652
|
+
return cached;
|
|
653
|
+
const map = new Map();
|
|
654
|
+
try {
|
|
655
|
+
const pkgJsonPath = path.join(projectRoot, 'node_modules', pkgName, 'package.json');
|
|
656
|
+
const pkgJson = JSON.parse(readFileSync(pkgJsonPath, 'utf-8'));
|
|
657
|
+
if (pkgJson.exports && typeof pkgJson.exports === 'object') {
|
|
658
|
+
for (const [entryPoint, conditions] of Object.entries(pkgJson.exports)) {
|
|
659
|
+
if (entryPoint.includes('*') || entryPoint.endsWith('.json'))
|
|
660
|
+
continue;
|
|
661
|
+
const resolvedPath = resolveExportConditionValue(conditions);
|
|
662
|
+
if (resolvedPath && typeof resolvedPath === 'string') {
|
|
663
|
+
const normalized = resolvedPath.replace(/^\.\//, '');
|
|
664
|
+
const bareSpec = entryPoint === '.' ? pkgName : `${pkgName}/${entryPoint.replace(/^\.\//, '')}`;
|
|
665
|
+
map.set(normalized, bareSpec);
|
|
666
|
+
}
|
|
667
|
+
}
|
|
668
|
+
}
|
|
669
|
+
if (map.size === 0) {
|
|
670
|
+
for (const field of ['module', 'main']) {
|
|
671
|
+
const value = pkgJson[field];
|
|
672
|
+
if (value && typeof value === 'string') {
|
|
673
|
+
const normalized = value.replace(/^\.\//, '');
|
|
674
|
+
map.set(normalized, pkgName);
|
|
675
|
+
const withoutExt = normalized.replace(/\.[^.]+$/, '');
|
|
676
|
+
if (withoutExt !== normalized) {
|
|
677
|
+
map.set(withoutExt, pkgName);
|
|
678
|
+
}
|
|
679
|
+
break;
|
|
680
|
+
}
|
|
681
|
+
}
|
|
682
|
+
}
|
|
683
|
+
}
|
|
684
|
+
catch { }
|
|
685
|
+
exportsReverseMapCache.set(pkgName, map);
|
|
686
|
+
return map;
|
|
687
|
+
}
|
|
688
|
+
function getPackageMainFieldInfo(pkgName, projectRoot) {
|
|
689
|
+
const info = getPackageRuntimeInfo(pkgName, projectRoot);
|
|
690
|
+
return {
|
|
691
|
+
hasExports: info.hasExports,
|
|
692
|
+
mainEntries: info.mainEntries,
|
|
693
|
+
};
|
|
694
|
+
}
|
|
695
|
+
export function resolveInternalRuntimePluginBareSpecifier(spec, projectRoot) {
|
|
696
|
+
if (!spec) {
|
|
697
|
+
return null;
|
|
698
|
+
}
|
|
699
|
+
const cleaned = spec.replace(PAT.QUERY_PATTERN, '');
|
|
700
|
+
const normalized = normalizeNodeModulesSpecifier(cleaned) || cleaned.replace(/^\/+/, '');
|
|
701
|
+
if (!normalized) {
|
|
702
|
+
return null;
|
|
703
|
+
}
|
|
704
|
+
const rootPackageName = extractRootPackageName(normalized);
|
|
705
|
+
if (!rootPackageName || !isLikelyNativeScriptRuntimePluginSpecifier(rootPackageName, projectRoot)) {
|
|
706
|
+
return null;
|
|
707
|
+
}
|
|
708
|
+
const { packageName, subpath } = resolveNodeModulesPackageBoundary(normalized, projectRoot);
|
|
709
|
+
if (!subpath || packageName !== rootPackageName) {
|
|
710
|
+
return null;
|
|
711
|
+
}
|
|
712
|
+
if (!subpath.includes('/')) {
|
|
713
|
+
return null;
|
|
714
|
+
}
|
|
715
|
+
const reverseMap = getExportsReverseMap(packageName, projectRoot);
|
|
716
|
+
const originalSpec = reverseMap.get(subpath);
|
|
717
|
+
if (originalSpec && originalSpec !== packageName) {
|
|
718
|
+
return null;
|
|
719
|
+
}
|
|
720
|
+
const packageMainInfo = getPackageMainFieldInfo(packageName, projectRoot);
|
|
721
|
+
if (!packageMainInfo.hasExports && packageMainInfo.mainEntries.has(subpath)) {
|
|
722
|
+
return packageName;
|
|
723
|
+
}
|
|
724
|
+
return normalized;
|
|
725
|
+
}
|
|
726
|
+
export function shouldPreserveBareRuntimePluginSubpathImport(spec, projectRoot) {
|
|
727
|
+
if (!spec) {
|
|
728
|
+
return false;
|
|
729
|
+
}
|
|
730
|
+
const cleaned = spec.replace(PAT.QUERY_PATTERN, '');
|
|
731
|
+
if (!cleaned || /^(?:\.|\/|https?:\/\/)/i.test(cleaned)) {
|
|
732
|
+
return false;
|
|
733
|
+
}
|
|
734
|
+
if (normalizeNodeModulesSpecifier(cleaned)) {
|
|
735
|
+
return false;
|
|
736
|
+
}
|
|
737
|
+
const normalized = cleaned.replace(/^\/+/, '');
|
|
738
|
+
const rootPackageName = extractRootPackageName(normalized);
|
|
739
|
+
if (!rootPackageName || !isLikelyNativeScriptRuntimePluginSpecifier(rootPackageName, projectRoot)) {
|
|
740
|
+
return false;
|
|
741
|
+
}
|
|
742
|
+
const { packageName, subpath } = resolveNodeModulesPackageBoundary(normalized, projectRoot);
|
|
743
|
+
if (!subpath || packageName !== rootPackageName) {
|
|
744
|
+
return false;
|
|
745
|
+
}
|
|
746
|
+
const lastSegment = subpath.split('/').pop() || '';
|
|
747
|
+
if (hasExplicitRuntimePluginScriptExtension(lastSegment)) {
|
|
748
|
+
return false;
|
|
749
|
+
}
|
|
750
|
+
if (!subpath.includes('/')) {
|
|
751
|
+
const packageBaseName = packageName.split('/').pop() || '';
|
|
752
|
+
const withoutPlatform = lastSegment.replace(/\.(ios|android|visionos)$/i, '');
|
|
753
|
+
if (withoutPlatform === 'index' || withoutPlatform === packageBaseName || withoutPlatform.startsWith(`${packageBaseName}.`)) {
|
|
754
|
+
return false;
|
|
755
|
+
}
|
|
756
|
+
}
|
|
757
|
+
const reverseMap = getExportsReverseMap(packageName, projectRoot);
|
|
758
|
+
const originalSpec = reverseMap.get(subpath);
|
|
759
|
+
if (originalSpec && originalSpec !== packageName) {
|
|
760
|
+
return false;
|
|
761
|
+
}
|
|
762
|
+
return true;
|
|
763
|
+
}
|
|
764
|
+
export function resolveVendorRouting(nodeModulesSpec, projectRoot) {
|
|
765
|
+
const rootPackageName = extractRootPackageName(nodeModulesSpec);
|
|
766
|
+
const { packageName: pkgName, subpath } = resolveNodeModulesPackageBoundary(nodeModulesSpec, projectRoot);
|
|
767
|
+
const pkgBaseName = pkgName.split('/').pop() || '';
|
|
768
|
+
const isRootLevelMainEntry = (() => {
|
|
769
|
+
if (!subpath || subpath.includes('/')) {
|
|
770
|
+
return false;
|
|
771
|
+
}
|
|
772
|
+
const withoutExt = subpath.replace(/\.[^.]+$/, '');
|
|
773
|
+
const withoutPlatform = withoutExt.replace(/\.(ios|android|visionos)$/i, '');
|
|
774
|
+
return withoutPlatform === 'index' || withoutPlatform === pkgBaseName;
|
|
775
|
+
})();
|
|
776
|
+
if (rootPackageName && pkgName !== rootPackageName) {
|
|
777
|
+
return { route: 'http' };
|
|
778
|
+
}
|
|
779
|
+
if (isLikelyNativeScriptRuntimePluginSpecifier(pkgName, projectRoot) && (!subpath || isRootLevelMainEntry)) {
|
|
780
|
+
return { route: 'vendor', bareSpec: pkgName };
|
|
781
|
+
}
|
|
782
|
+
if (isLikelyNativeScriptRuntimePluginSpecifier(pkgName, projectRoot) && subpath.includes('/')) {
|
|
783
|
+
const exactBareSpecifier = resolveInternalRuntimePluginBareSpecifier(nodeModulesSpec, projectRoot);
|
|
784
|
+
if (exactBareSpecifier) {
|
|
785
|
+
return { route: 'vendor', bareSpec: exactBareSpecifier };
|
|
786
|
+
}
|
|
787
|
+
}
|
|
788
|
+
const manifest = getVendorManifest();
|
|
789
|
+
if (!manifest?.modules?.[pkgName]) {
|
|
790
|
+
return null;
|
|
791
|
+
}
|
|
792
|
+
if (/\.(ios|android|visionos)\.(js|ts|mjs|mts)$/i.test(nodeModulesSpec) && isLikelyNativeScriptRuntimePluginSpecifier(pkgName, projectRoot) && isRootLevelMainEntry) {
|
|
793
|
+
return { route: 'vendor', bareSpec: pkgName };
|
|
794
|
+
}
|
|
795
|
+
if (/\.(ios|android|visionos)\.(js|ts|mjs|mts)$/.test(nodeModulesSpec)) {
|
|
796
|
+
return { route: 'http' };
|
|
797
|
+
}
|
|
798
|
+
if (!subpath) {
|
|
799
|
+
return { route: 'vendor', bareSpec: pkgName };
|
|
800
|
+
}
|
|
801
|
+
const reverseMap = getExportsReverseMap(pkgName, projectRoot);
|
|
802
|
+
const originalSpec = reverseMap.get(subpath);
|
|
803
|
+
if (originalSpec && originalSpec !== pkgName) {
|
|
804
|
+
return { route: 'http' };
|
|
805
|
+
}
|
|
806
|
+
if (subpath) {
|
|
807
|
+
const packageMainInfo = getPackageMainFieldInfo(pkgName, projectRoot);
|
|
808
|
+
if (!packageMainInfo.hasExports && packageMainInfo.mainEntries.has(subpath)) {
|
|
809
|
+
return { route: 'vendor', bareSpec: pkgName };
|
|
810
|
+
}
|
|
811
|
+
}
|
|
812
|
+
if (!subpath.includes('/')) {
|
|
813
|
+
const lastSegment = subpath.replace(/\.[^.]+$/, '');
|
|
814
|
+
if (lastSegment === 'index' || lastSegment === pkgBaseName || lastSegment.startsWith(pkgBaseName + '.')) {
|
|
815
|
+
return { route: 'vendor', bareSpec: pkgName };
|
|
816
|
+
}
|
|
817
|
+
}
|
|
818
|
+
return { route: 'http' };
|
|
819
|
+
}
|
|
820
|
+
//# sourceMappingURL=websocket-module-specifiers.js.map
|