@nativescript/vite 8.0.0-alpha.2 → 8.0.0-alpha.4
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.js +45 -8
- package/configuration/angular.js.map +1 -1
- package/configuration/base.js +1 -1
- package/configuration/base.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/main-entry.d.ts +1 -0
- package/helpers/main-entry.js +26 -85
- package/helpers/main-entry.js.map +1 -1
- package/hmr/client/index.js +72 -19
- package/hmr/client/index.js.map +1 -1
- package/hmr/client/utils.js +57 -6
- package/hmr/client/utils.js.map +1 -1
- package/hmr/entry-runtime.js +1 -1
- package/hmr/entry-runtime.js.map +1 -1
- package/hmr/frameworks/angular/client/index.d.ts +2 -1
- package/hmr/frameworks/angular/client/index.js +51 -2
- package/hmr/frameworks/angular/client/index.js.map +1 -1
- package/hmr/frameworks/angular/server/strategy.js +20 -5
- 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/server/core-sanitize.d.ts +3 -2
- package/hmr/server/core-sanitize.js +34 -17
- package/hmr/server/core-sanitize.js.map +1 -1
- package/hmr/server/import-map.js +20 -14
- package/hmr/server/import-map.js.map +1 -1
- package/hmr/server/index.d.ts +2 -1
- package/hmr/server/index.js.map +1 -1
- 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 +137 -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 +443 -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 +61 -0
- package/hmr/server/websocket-angular-hot-update.js +239 -0
- package/hmr/server/websocket-angular-hot-update.js.map +1 -0
- package/hmr/server/websocket-core-bridge.d.ts +23 -0
- package/hmr/server/websocket-core-bridge.js +360 -0
- package/hmr/server/websocket-core-bridge.js.map +1 -0
- package/hmr/server/websocket-graph-upsert.d.ts +6 -0
- package/hmr/server/websocket-graph-upsert.js +13 -0
- package/hmr/server/websocket-graph-upsert.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 +37 -0
- package/hmr/server/websocket-module-specifiers.js +637 -0
- package/hmr/server/websocket-module-specifiers.js.map +1 -0
- package/hmr/server/websocket-ns-m-finalize.d.ts +32 -0
- package/hmr/server/websocket-ns-m-finalize.js +73 -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 +47 -0
- package/hmr/server/websocket-ns-m-paths.js.map +1 -0
- package/hmr/server/websocket-ns-m-request.d.ts +35 -0
- package/hmr/server/websocket-ns-m-request.js +203 -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 +286 -0
- package/hmr/server/websocket-runtime-compat.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 +35 -0
- package/hmr/server/websocket-vue-sfc.js +1116 -0
- package/hmr/server/websocket-vue-sfc.js.map +1 -0
- package/hmr/server/websocket.d.ts +21 -74
- package/hmr/server/websocket.js +578 -3439
- 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/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 +1 -1
- package/hmr/shared/runtime/dev-overlay.js +23 -12
- package/hmr/shared/runtime/dev-overlay.js.map +1 -1
- package/hmr/shared/runtime/root-placeholder.d.ts +1 -0
- package/hmr/shared/runtime/root-placeholder.js +430 -52
- 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 +146 -0
- package/hmr/shared/runtime/session-bootstrap.js.map +1 -0
- package/hmr/shared/vendor/manifest.d.ts +2 -0
- package/hmr/shared/vendor/manifest.js +24 -10
- package/hmr/shared/vendor/manifest.js.map +1 -1
- package/package.json +7 -1
- package/runtime/core-aliases-early.js +83 -32
- package/runtime/core-aliases-early.js.map +1 -1
|
@@ -0,0 +1,637 @@
|
|
|
1
|
+
import { existsSync, readFileSync } 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
|
+
const root = path.resolve(projectRoot);
|
|
208
|
+
const absPath = path.resolve(root, `.${spec}`);
|
|
209
|
+
if (!absPath.startsWith(root + path.sep) && absPath !== root)
|
|
210
|
+
return null;
|
|
211
|
+
try {
|
|
212
|
+
const code = existsSync(absPath) ? readFileSync(absPath, 'utf-8') : null;
|
|
213
|
+
if (code != null) {
|
|
214
|
+
const usesNodeModuleInterop = /(?:from\s*['"](?:node:)?module['"]|import\s*\{[^}]*\bcreateRequire\b[^}]*\}\s*from\s*['"](?:node:)?module['"]|\bcreateRequire\s*\()/m.test(code);
|
|
215
|
+
if (usesNodeModuleInterop) {
|
|
216
|
+
return null;
|
|
217
|
+
}
|
|
218
|
+
return { code, resolvedId: spec };
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
catch { }
|
|
222
|
+
return null;
|
|
223
|
+
}
|
|
224
|
+
export function stripDecoratedServePrefixes(spec) {
|
|
225
|
+
let cleanedSpec = spec || '';
|
|
226
|
+
let bootTaggedRequest = false;
|
|
227
|
+
let forcedVer = null;
|
|
228
|
+
try {
|
|
229
|
+
let changed = true;
|
|
230
|
+
while (changed) {
|
|
231
|
+
changed = false;
|
|
232
|
+
const bootMatch = cleanedSpec.match(/^\/?__ns_boot__\/[^\/]+(\/.*)?$/);
|
|
233
|
+
if (bootMatch) {
|
|
234
|
+
bootTaggedRequest = true;
|
|
235
|
+
cleanedSpec = bootMatch[1] || '/';
|
|
236
|
+
changed = true;
|
|
237
|
+
}
|
|
238
|
+
const hmrMatch = cleanedSpec.match(/^\/?__ns_hmr__\/([^\/]+)(\/.*)?$/);
|
|
239
|
+
if (hmrMatch) {
|
|
240
|
+
const tag = hmrMatch[1] || '';
|
|
241
|
+
if (tag) {
|
|
242
|
+
forcedVer = tag;
|
|
243
|
+
}
|
|
244
|
+
cleanedSpec = hmrMatch[2] || '/';
|
|
245
|
+
changed = true;
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
catch { }
|
|
250
|
+
return { cleanedSpec, bootTaggedRequest, forcedVer };
|
|
251
|
+
}
|
|
252
|
+
export function resolveVendorFromCandidate(specifier) {
|
|
253
|
+
if (!specifier) {
|
|
254
|
+
return null;
|
|
255
|
+
}
|
|
256
|
+
const manifest = getVendorManifest();
|
|
257
|
+
if (!manifest) {
|
|
258
|
+
return null;
|
|
259
|
+
}
|
|
260
|
+
const cleaned = specifier.replace(PAT.QUERY_PATTERN, '');
|
|
261
|
+
const direct = resolveVendorSpecifier(cleaned);
|
|
262
|
+
if (direct) {
|
|
263
|
+
return direct;
|
|
264
|
+
}
|
|
265
|
+
const flattenedId = extractVitePrebundleId(cleaned);
|
|
266
|
+
if (flattenedId) {
|
|
267
|
+
const flattenedMap = getFlattenedManifestMap(manifest);
|
|
268
|
+
const flatMatch = flattenedMap.get(flattenedId);
|
|
269
|
+
if (flatMatch) {
|
|
270
|
+
return flatMatch;
|
|
271
|
+
}
|
|
272
|
+
for (const [flatKey, canonical] of flattenedMap.entries()) {
|
|
273
|
+
if (flattenedId === flatKey) {
|
|
274
|
+
return canonical;
|
|
275
|
+
}
|
|
276
|
+
if (flattenedId.startsWith(`${flatKey}_`)) {
|
|
277
|
+
const flatSuffix = flattenedId.slice(flatKey.length + 1);
|
|
278
|
+
const subpath = flatSuffix.replace(/_/g, '/');
|
|
279
|
+
if (isFileDistSubpath(subpath)) {
|
|
280
|
+
return canonical;
|
|
281
|
+
}
|
|
282
|
+
const aliasKey = `${canonical}/${subpath.split('/')[0]}`;
|
|
283
|
+
if (manifest.aliases?.[aliasKey] && manifest.modules[manifest.aliases[aliasKey]]) {
|
|
284
|
+
return manifest.aliases[aliasKey];
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
const guessedId = flattenedId.replace(/__/g, '.').replace(/_/g, '/');
|
|
289
|
+
if (guessedId && guessedId !== flattenedId) {
|
|
290
|
+
const guessedCanonical = resolveVendorSpecifier(guessedId);
|
|
291
|
+
if (guessedCanonical) {
|
|
292
|
+
return guessedCanonical;
|
|
293
|
+
}
|
|
294
|
+
const prefix = findVendorPrefix(guessedId, manifest);
|
|
295
|
+
if (prefix) {
|
|
296
|
+
return prefix;
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
const normalizedCore = normalizeNativeScriptCoreSpecifier(cleaned);
|
|
301
|
+
if (normalizedCore !== cleaned) {
|
|
302
|
+
const nsCanonical = resolveVendorSpecifier(normalizedCore);
|
|
303
|
+
if (nsCanonical) {
|
|
304
|
+
return nsCanonical;
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
const nodeModulesSpecifier = normalizeNodeModulesSpecifier(cleaned);
|
|
308
|
+
if (nodeModulesSpecifier) {
|
|
309
|
+
const canonical = resolveVendorSpecifier(nodeModulesSpecifier);
|
|
310
|
+
if (canonical) {
|
|
311
|
+
return canonical;
|
|
312
|
+
}
|
|
313
|
+
const prefix = findVendorPrefix(nodeModulesSpecifier, manifest);
|
|
314
|
+
if (prefix) {
|
|
315
|
+
return prefix;
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
const prefix = findVendorPrefix(cleaned, manifest);
|
|
319
|
+
if (prefix) {
|
|
320
|
+
return prefix;
|
|
321
|
+
}
|
|
322
|
+
return null;
|
|
323
|
+
}
|
|
324
|
+
export function resolveCandidateFilePath(candidate, projectRoot) {
|
|
325
|
+
const cleaned = candidate.replace(PAT.QUERY_PATTERN, '');
|
|
326
|
+
if (!cleaned)
|
|
327
|
+
return null;
|
|
328
|
+
const root = path.resolve(projectRoot);
|
|
329
|
+
let absPath = null;
|
|
330
|
+
if (cleaned.startsWith('/@fs/')) {
|
|
331
|
+
absPath = cleaned.slice('/@fs'.length);
|
|
332
|
+
}
|
|
333
|
+
else if (cleaned.includes('/node_modules/')) {
|
|
334
|
+
absPath = path.resolve(root, `.${cleaned}`);
|
|
335
|
+
}
|
|
336
|
+
else if (/^(?:[A-Za-z]:)?\//.test(cleaned)) {
|
|
337
|
+
absPath = path.resolve(cleaned);
|
|
338
|
+
}
|
|
339
|
+
if (!absPath) {
|
|
340
|
+
return null;
|
|
341
|
+
}
|
|
342
|
+
const rel = path.relative(root, absPath);
|
|
343
|
+
if (!rel || rel.startsWith('..') || path.isAbsolute(rel)) {
|
|
344
|
+
return null;
|
|
345
|
+
}
|
|
346
|
+
return existsSync(absPath) ? absPath : null;
|
|
347
|
+
}
|
|
348
|
+
export function filterExistingNodeModulesTransformCandidates(spec, candidates, projectRoot) {
|
|
349
|
+
const cleanedSpec = spec.replace(PAT.QUERY_PATTERN, '');
|
|
350
|
+
if (!cleanedSpec.includes('/node_modules/')) {
|
|
351
|
+
return candidates;
|
|
352
|
+
}
|
|
353
|
+
return candidates.filter((candidate) => !!resolveCandidateFilePath(candidate, projectRoot));
|
|
354
|
+
}
|
|
355
|
+
function findVendorPrefix(specifier, manifest) {
|
|
356
|
+
const { modules, aliases } = manifest;
|
|
357
|
+
const keys = Object.keys(modules || {});
|
|
358
|
+
for (const key of keys) {
|
|
359
|
+
if (specifier === key) {
|
|
360
|
+
return key;
|
|
361
|
+
}
|
|
362
|
+
if (specifier.startsWith(`${key}/`)) {
|
|
363
|
+
const subpath = specifier.slice(key.length + 1);
|
|
364
|
+
if (isFileDistSubpath(subpath)) {
|
|
365
|
+
return key;
|
|
366
|
+
}
|
|
367
|
+
const aliasKey = `${key}/${subpath.split('/')[0]}`;
|
|
368
|
+
if (aliases?.[aliasKey] && modules[aliases[aliasKey]]) {
|
|
369
|
+
return aliases[aliasKey];
|
|
370
|
+
}
|
|
371
|
+
continue;
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
return null;
|
|
375
|
+
}
|
|
376
|
+
export function viteDepsPathToBareSpecifier(depPath) {
|
|
377
|
+
const manifest = getVendorManifest();
|
|
378
|
+
if (!manifest)
|
|
379
|
+
return null;
|
|
380
|
+
const flatId = extractVitePrebundleId(`.vite/deps/${depPath}`);
|
|
381
|
+
if (!flatId)
|
|
382
|
+
return null;
|
|
383
|
+
const flatMap = getFlattenedManifestMap(manifest);
|
|
384
|
+
if (flatMap.has(flatId)) {
|
|
385
|
+
return flatMap.get(flatId);
|
|
386
|
+
}
|
|
387
|
+
let bestKey = '';
|
|
388
|
+
let bestCanonical = '';
|
|
389
|
+
for (const [flatKey, canonical] of flatMap.entries()) {
|
|
390
|
+
if (flatId.startsWith(`${flatKey}_`) && flatKey.length > bestKey.length) {
|
|
391
|
+
bestKey = flatKey;
|
|
392
|
+
bestCanonical = canonical;
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
if (bestKey && bestCanonical) {
|
|
396
|
+
const flatSuffix = flatId.slice(bestKey.length + 1);
|
|
397
|
+
const subpath = flatSuffix.replace(/_/g, '/');
|
|
398
|
+
return `${bestCanonical}/${subpath}`;
|
|
399
|
+
}
|
|
400
|
+
return null;
|
|
401
|
+
}
|
|
402
|
+
function isFileDistSubpath(subpath) {
|
|
403
|
+
const firstSegment = subpath.split('/')[0];
|
|
404
|
+
const FILE_DIST_DIRS = new Set(['dist', 'src', 'lib', 'build', 'esm', 'cjs', 'es', 'umd', 'module', 'bundle', 'output', '_esm', '_cjs']);
|
|
405
|
+
if (FILE_DIST_DIRS.has(firstSegment)) {
|
|
406
|
+
return true;
|
|
407
|
+
}
|
|
408
|
+
if (!subpath.includes('/') && /\.[a-zA-Z0-9]+$/.test(subpath)) {
|
|
409
|
+
return true;
|
|
410
|
+
}
|
|
411
|
+
return false;
|
|
412
|
+
}
|
|
413
|
+
const nodeModulesPackageBoundaryCache = new Map();
|
|
414
|
+
export function resolveNodeModulesPackageBoundary(nodeModulesSpec, projectRoot) {
|
|
415
|
+
const normalized = String(nodeModulesSpec || '')
|
|
416
|
+
.replace(PAT.QUERY_PATTERN, '')
|
|
417
|
+
.replace(/^\/+/, '');
|
|
418
|
+
const resolvedProjectRoot = path.resolve(projectRoot || getProjectRootPath());
|
|
419
|
+
const cacheKey = `${resolvedProjectRoot}::${normalized}`;
|
|
420
|
+
const cached = nodeModulesPackageBoundaryCache.get(cacheKey);
|
|
421
|
+
if (cached) {
|
|
422
|
+
return cached;
|
|
423
|
+
}
|
|
424
|
+
const rootPackageName = extractRootPackageName(normalized) || normalized;
|
|
425
|
+
let packageName = rootPackageName;
|
|
426
|
+
if (packageName && normalized.startsWith(`${packageName}/`)) {
|
|
427
|
+
const segments = normalized.split('/');
|
|
428
|
+
const rootSegmentCount = rootPackageName.startsWith('@') ? 2 : 1;
|
|
429
|
+
for (let end = segments.length; end > rootSegmentCount; end--) {
|
|
430
|
+
const candidate = segments.slice(0, end).join('/');
|
|
431
|
+
if (!candidate || candidate === rootPackageName) {
|
|
432
|
+
continue;
|
|
433
|
+
}
|
|
434
|
+
const candidatePackageJson = path.join(resolvedProjectRoot, 'node_modules', ...candidate.split('/'), 'package.json');
|
|
435
|
+
if (existsSync(candidatePackageJson)) {
|
|
436
|
+
packageName = candidate;
|
|
437
|
+
break;
|
|
438
|
+
}
|
|
439
|
+
}
|
|
440
|
+
}
|
|
441
|
+
const subpath = normalized === packageName ? '' : normalized.slice(packageName.length).replace(/^\/+/, '');
|
|
442
|
+
const resolved = { packageName, subpath };
|
|
443
|
+
nodeModulesPackageBoundaryCache.set(cacheKey, resolved);
|
|
444
|
+
return resolved;
|
|
445
|
+
}
|
|
446
|
+
const exportsReverseMapCache = new Map();
|
|
447
|
+
function resolveExportConditionValue(conditions) {
|
|
448
|
+
if (typeof conditions === 'string')
|
|
449
|
+
return conditions;
|
|
450
|
+
if (typeof conditions !== 'object' || conditions === null)
|
|
451
|
+
return null;
|
|
452
|
+
const obj = conditions;
|
|
453
|
+
for (const key of ['esm2022', 'esm', 'esm2015', 'import', 'module', 'default']) {
|
|
454
|
+
if (key in obj) {
|
|
455
|
+
const result = resolveExportConditionValue(obj[key]);
|
|
456
|
+
if (result)
|
|
457
|
+
return result;
|
|
458
|
+
}
|
|
459
|
+
}
|
|
460
|
+
for (const val of Object.values(obj)) {
|
|
461
|
+
if (typeof val === 'string')
|
|
462
|
+
return val;
|
|
463
|
+
}
|
|
464
|
+
return null;
|
|
465
|
+
}
|
|
466
|
+
function getExportsReverseMap(pkgName, projectRoot) {
|
|
467
|
+
const cached = exportsReverseMapCache.get(pkgName);
|
|
468
|
+
if (cached)
|
|
469
|
+
return cached;
|
|
470
|
+
const map = new Map();
|
|
471
|
+
try {
|
|
472
|
+
const pkgJsonPath = path.join(projectRoot, 'node_modules', pkgName, 'package.json');
|
|
473
|
+
const pkgJson = JSON.parse(readFileSync(pkgJsonPath, 'utf-8'));
|
|
474
|
+
if (pkgJson.exports && typeof pkgJson.exports === 'object') {
|
|
475
|
+
for (const [entryPoint, conditions] of Object.entries(pkgJson.exports)) {
|
|
476
|
+
if (entryPoint.includes('*') || entryPoint.endsWith('.json'))
|
|
477
|
+
continue;
|
|
478
|
+
const resolvedPath = resolveExportConditionValue(conditions);
|
|
479
|
+
if (resolvedPath && typeof resolvedPath === 'string') {
|
|
480
|
+
const normalized = resolvedPath.replace(/^\.\//, '');
|
|
481
|
+
const bareSpec = entryPoint === '.' ? pkgName : `${pkgName}/${entryPoint.replace(/^\.\//, '')}`;
|
|
482
|
+
map.set(normalized, bareSpec);
|
|
483
|
+
}
|
|
484
|
+
}
|
|
485
|
+
}
|
|
486
|
+
if (map.size === 0) {
|
|
487
|
+
for (const field of ['module', 'main']) {
|
|
488
|
+
const value = pkgJson[field];
|
|
489
|
+
if (value && typeof value === 'string') {
|
|
490
|
+
const normalized = value.replace(/^\.\//, '');
|
|
491
|
+
map.set(normalized, pkgName);
|
|
492
|
+
const withoutExt = normalized.replace(/\.[^.]+$/, '');
|
|
493
|
+
if (withoutExt !== normalized) {
|
|
494
|
+
map.set(withoutExt, pkgName);
|
|
495
|
+
}
|
|
496
|
+
break;
|
|
497
|
+
}
|
|
498
|
+
}
|
|
499
|
+
}
|
|
500
|
+
}
|
|
501
|
+
catch { }
|
|
502
|
+
exportsReverseMapCache.set(pkgName, map);
|
|
503
|
+
return map;
|
|
504
|
+
}
|
|
505
|
+
function getPackageMainFieldInfo(pkgName, projectRoot) {
|
|
506
|
+
const info = getPackageRuntimeInfo(pkgName, projectRoot);
|
|
507
|
+
return {
|
|
508
|
+
hasExports: info.hasExports,
|
|
509
|
+
mainEntries: info.mainEntries,
|
|
510
|
+
};
|
|
511
|
+
}
|
|
512
|
+
export function resolveInternalRuntimePluginBareSpecifier(spec, projectRoot) {
|
|
513
|
+
if (!spec) {
|
|
514
|
+
return null;
|
|
515
|
+
}
|
|
516
|
+
const cleaned = spec.replace(PAT.QUERY_PATTERN, '');
|
|
517
|
+
const normalized = normalizeNodeModulesSpecifier(cleaned) || cleaned.replace(/^\/+/, '');
|
|
518
|
+
if (!normalized) {
|
|
519
|
+
return null;
|
|
520
|
+
}
|
|
521
|
+
const rootPackageName = extractRootPackageName(normalized);
|
|
522
|
+
if (!rootPackageName || !isLikelyNativeScriptRuntimePluginSpecifier(rootPackageName, projectRoot)) {
|
|
523
|
+
return null;
|
|
524
|
+
}
|
|
525
|
+
const { packageName, subpath } = resolveNodeModulesPackageBoundary(normalized, projectRoot);
|
|
526
|
+
if (!subpath || packageName !== rootPackageName) {
|
|
527
|
+
return null;
|
|
528
|
+
}
|
|
529
|
+
if (!subpath.includes('/')) {
|
|
530
|
+
return null;
|
|
531
|
+
}
|
|
532
|
+
const reverseMap = getExportsReverseMap(packageName, projectRoot);
|
|
533
|
+
const originalSpec = reverseMap.get(subpath);
|
|
534
|
+
if (originalSpec && originalSpec !== packageName) {
|
|
535
|
+
return null;
|
|
536
|
+
}
|
|
537
|
+
const packageMainInfo = getPackageMainFieldInfo(packageName, projectRoot);
|
|
538
|
+
if (!packageMainInfo.hasExports && packageMainInfo.mainEntries.has(subpath)) {
|
|
539
|
+
return packageName;
|
|
540
|
+
}
|
|
541
|
+
return normalized;
|
|
542
|
+
}
|
|
543
|
+
export function shouldPreserveBareRuntimePluginSubpathImport(spec, projectRoot) {
|
|
544
|
+
if (!spec) {
|
|
545
|
+
return false;
|
|
546
|
+
}
|
|
547
|
+
const cleaned = spec.replace(PAT.QUERY_PATTERN, '');
|
|
548
|
+
if (!cleaned || /^(?:\.|\/|https?:\/\/)/i.test(cleaned)) {
|
|
549
|
+
return false;
|
|
550
|
+
}
|
|
551
|
+
if (normalizeNodeModulesSpecifier(cleaned)) {
|
|
552
|
+
return false;
|
|
553
|
+
}
|
|
554
|
+
const normalized = cleaned.replace(/^\/+/, '');
|
|
555
|
+
const rootPackageName = extractRootPackageName(normalized);
|
|
556
|
+
if (!rootPackageName || !isLikelyNativeScriptRuntimePluginSpecifier(rootPackageName, projectRoot)) {
|
|
557
|
+
return false;
|
|
558
|
+
}
|
|
559
|
+
const { packageName, subpath } = resolveNodeModulesPackageBoundary(normalized, projectRoot);
|
|
560
|
+
if (!subpath || packageName !== rootPackageName) {
|
|
561
|
+
return false;
|
|
562
|
+
}
|
|
563
|
+
const lastSegment = subpath.split('/').pop() || '';
|
|
564
|
+
if (hasExplicitRuntimePluginScriptExtension(lastSegment)) {
|
|
565
|
+
return false;
|
|
566
|
+
}
|
|
567
|
+
if (!subpath.includes('/')) {
|
|
568
|
+
const packageBaseName = packageName.split('/').pop() || '';
|
|
569
|
+
const withoutPlatform = lastSegment.replace(/\.(ios|android|visionos)$/i, '');
|
|
570
|
+
if (withoutPlatform === 'index' || withoutPlatform === packageBaseName || withoutPlatform.startsWith(`${packageBaseName}.`)) {
|
|
571
|
+
return false;
|
|
572
|
+
}
|
|
573
|
+
}
|
|
574
|
+
const reverseMap = getExportsReverseMap(packageName, projectRoot);
|
|
575
|
+
const originalSpec = reverseMap.get(subpath);
|
|
576
|
+
if (originalSpec && originalSpec !== packageName) {
|
|
577
|
+
return false;
|
|
578
|
+
}
|
|
579
|
+
return true;
|
|
580
|
+
}
|
|
581
|
+
export function resolveVendorRouting(nodeModulesSpec, projectRoot) {
|
|
582
|
+
const rootPackageName = extractRootPackageName(nodeModulesSpec);
|
|
583
|
+
const { packageName: pkgName, subpath } = resolveNodeModulesPackageBoundary(nodeModulesSpec, projectRoot);
|
|
584
|
+
const pkgBaseName = pkgName.split('/').pop() || '';
|
|
585
|
+
const isRootLevelMainEntry = (() => {
|
|
586
|
+
if (!subpath || subpath.includes('/')) {
|
|
587
|
+
return false;
|
|
588
|
+
}
|
|
589
|
+
const withoutExt = subpath.replace(/\.[^.]+$/, '');
|
|
590
|
+
const withoutPlatform = withoutExt.replace(/\.(ios|android|visionos)$/i, '');
|
|
591
|
+
return withoutPlatform === 'index' || withoutPlatform === pkgBaseName;
|
|
592
|
+
})();
|
|
593
|
+
if (rootPackageName && pkgName !== rootPackageName) {
|
|
594
|
+
return { route: 'http' };
|
|
595
|
+
}
|
|
596
|
+
if (isLikelyNativeScriptRuntimePluginSpecifier(pkgName, projectRoot) && (!subpath || isRootLevelMainEntry)) {
|
|
597
|
+
return { route: 'vendor', bareSpec: pkgName };
|
|
598
|
+
}
|
|
599
|
+
if (isLikelyNativeScriptRuntimePluginSpecifier(pkgName, projectRoot) && subpath.includes('/')) {
|
|
600
|
+
const exactBareSpecifier = resolveInternalRuntimePluginBareSpecifier(nodeModulesSpec, projectRoot);
|
|
601
|
+
if (exactBareSpecifier) {
|
|
602
|
+
return { route: 'vendor', bareSpec: exactBareSpecifier };
|
|
603
|
+
}
|
|
604
|
+
}
|
|
605
|
+
const manifest = getVendorManifest();
|
|
606
|
+
if (!manifest?.modules?.[pkgName]) {
|
|
607
|
+
return null;
|
|
608
|
+
}
|
|
609
|
+
if (/\.(ios|android|visionos)\.(js|ts|mjs|mts)$/i.test(nodeModulesSpec) && isLikelyNativeScriptRuntimePluginSpecifier(pkgName, projectRoot) && isRootLevelMainEntry) {
|
|
610
|
+
return { route: 'vendor', bareSpec: pkgName };
|
|
611
|
+
}
|
|
612
|
+
if (/\.(ios|android|visionos)\.(js|ts|mjs|mts)$/.test(nodeModulesSpec)) {
|
|
613
|
+
return { route: 'http' };
|
|
614
|
+
}
|
|
615
|
+
if (!subpath) {
|
|
616
|
+
return { route: 'vendor', bareSpec: pkgName };
|
|
617
|
+
}
|
|
618
|
+
const reverseMap = getExportsReverseMap(pkgName, projectRoot);
|
|
619
|
+
const originalSpec = reverseMap.get(subpath);
|
|
620
|
+
if (originalSpec && originalSpec !== pkgName) {
|
|
621
|
+
return { route: 'http' };
|
|
622
|
+
}
|
|
623
|
+
if (subpath) {
|
|
624
|
+
const packageMainInfo = getPackageMainFieldInfo(pkgName, projectRoot);
|
|
625
|
+
if (!packageMainInfo.hasExports && packageMainInfo.mainEntries.has(subpath)) {
|
|
626
|
+
return { route: 'vendor', bareSpec: pkgName };
|
|
627
|
+
}
|
|
628
|
+
}
|
|
629
|
+
if (!subpath.includes('/')) {
|
|
630
|
+
const lastSegment = subpath.replace(/\.[^.]+$/, '');
|
|
631
|
+
if (lastSegment === 'index' || lastSegment === pkgBaseName || lastSegment.startsWith(pkgBaseName + '.')) {
|
|
632
|
+
return { route: 'vendor', bareSpec: pkgName };
|
|
633
|
+
}
|
|
634
|
+
}
|
|
635
|
+
return { route: 'http' };
|
|
636
|
+
}
|
|
637
|
+
//# sourceMappingURL=websocket-module-specifiers.js.map
|