@nativescript/vite 8.0.0-alpha.2 → 8.0.0-alpha.3
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.d.ts +21 -74
- package/hmr/server/websocket.js +455 -1386
- 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,239 @@
|
|
|
1
|
+
import { getProjectAppVirtualPath } from '../../helpers/utils.js';
|
|
2
|
+
import { isRuntimeGraphExcludedPath, normalizeRuntimeGraphPath } from './runtime-graph-filter.js';
|
|
3
|
+
const APP_VIRTUAL_WITH_SLASH = `${getProjectAppVirtualPath()}/`;
|
|
4
|
+
export function canonicalizeTransformRequestCacheKey(url, projectRoot) {
|
|
5
|
+
if (!url)
|
|
6
|
+
return url;
|
|
7
|
+
const [rawPath, rawQuery = ''] = url.split('?', 2);
|
|
8
|
+
let normalizedPath = rawPath;
|
|
9
|
+
const root = projectRoot ? projectRoot.replace(/\\/g, '/') : '';
|
|
10
|
+
if (normalizedPath.startsWith('/@fs/')) {
|
|
11
|
+
const fsPath = normalizedPath.slice('/@fs'.length).replace(/\\/g, '/');
|
|
12
|
+
if (root && fsPath.startsWith(root)) {
|
|
13
|
+
const rel = fsPath.slice(root.length);
|
|
14
|
+
normalizedPath = rel.startsWith('/') ? rel : `/${rel}`;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
else if (root && normalizedPath.replace(/\\/g, '/').startsWith(root)) {
|
|
18
|
+
const rel = normalizedPath.replace(/\\/g, '/').slice(root.length);
|
|
19
|
+
normalizedPath = rel.startsWith('/') ? rel : `/${rel}`;
|
|
20
|
+
}
|
|
21
|
+
if (!rawQuery) {
|
|
22
|
+
return normalizedPath;
|
|
23
|
+
}
|
|
24
|
+
const params = new URLSearchParams(rawQuery);
|
|
25
|
+
params.delete('t');
|
|
26
|
+
params.delete('v');
|
|
27
|
+
const kept = Array.from(params.entries()).sort(([leftKey, leftValue], [rightKey, rightValue]) => {
|
|
28
|
+
if (leftKey === rightKey) {
|
|
29
|
+
return leftValue.localeCompare(rightValue);
|
|
30
|
+
}
|
|
31
|
+
return leftKey.localeCompare(rightKey);
|
|
32
|
+
});
|
|
33
|
+
if (!kept.length) {
|
|
34
|
+
return normalizedPath;
|
|
35
|
+
}
|
|
36
|
+
const normalizedQuery = new URLSearchParams();
|
|
37
|
+
for (const [key, value] of kept) {
|
|
38
|
+
normalizedQuery.append(key, value);
|
|
39
|
+
}
|
|
40
|
+
return `${normalizedPath}?${normalizedQuery.toString()}`;
|
|
41
|
+
}
|
|
42
|
+
export function collectGraphUpdateModulesForHotUpdate(options) {
|
|
43
|
+
const targets = new Map();
|
|
44
|
+
const addTarget = (mod) => {
|
|
45
|
+
const id = mod?.id?.replace(/\?.*$/, '');
|
|
46
|
+
if (!id)
|
|
47
|
+
return;
|
|
48
|
+
if (isRuntimeGraphExcludedPath(id))
|
|
49
|
+
return;
|
|
50
|
+
if (!targets.has(id)) {
|
|
51
|
+
targets.set(id, mod);
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
if (options.flavor === 'angular' && /\.(html|htm)$/i.test(options.file)) {
|
|
55
|
+
for (const mod of options.modules || []) {
|
|
56
|
+
for (const importer of mod?.importers || []) {
|
|
57
|
+
const importerId = importer?.id || '';
|
|
58
|
+
if (/\.[cm]?[jt]sx?(?:$|\?)/i.test(importerId)) {
|
|
59
|
+
addTarget(importer);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
if (!targets.size) {
|
|
64
|
+
addTarget(options.getModuleById(options.file.replace(/\.(html|htm)$/i, '.ts')));
|
|
65
|
+
addTarget(options.getModuleById(options.file.replace(/\.(html|htm)$/i, '.js')));
|
|
66
|
+
}
|
|
67
|
+
return Array.from(targets.values());
|
|
68
|
+
}
|
|
69
|
+
if (!options.file.endsWith('.vue')) {
|
|
70
|
+
addTarget(options.getModuleById(options.file) || options.getModuleById(options.file + '?vue'));
|
|
71
|
+
}
|
|
72
|
+
return Array.from(targets.values());
|
|
73
|
+
}
|
|
74
|
+
export function collectAngularHotUpdateRoots(options) {
|
|
75
|
+
const roots = [];
|
|
76
|
+
const seenIds = new Set();
|
|
77
|
+
const seenObjects = new Set();
|
|
78
|
+
const addRoot = (mod) => {
|
|
79
|
+
if (!mod) {
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
if (mod.id) {
|
|
83
|
+
if (isRuntimeGraphExcludedPath(mod.id)) {
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
if (seenIds.has(mod.id)) {
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
seenIds.add(mod.id);
|
|
90
|
+
roots.push(mod);
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
if (seenObjects.has(mod)) {
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
seenObjects.add(mod);
|
|
97
|
+
roots.push(mod);
|
|
98
|
+
};
|
|
99
|
+
if (/\.(html|htm)$/i.test(options.file)) {
|
|
100
|
+
for (const mod of collectGraphUpdateModulesForHotUpdate({
|
|
101
|
+
file: options.file,
|
|
102
|
+
flavor: 'angular',
|
|
103
|
+
modules: options.modules,
|
|
104
|
+
getModuleById: options.getModuleById,
|
|
105
|
+
})) {
|
|
106
|
+
addRoot(mod);
|
|
107
|
+
}
|
|
108
|
+
return roots;
|
|
109
|
+
}
|
|
110
|
+
if (!/\.(m|c)?ts$/i.test(options.file)) {
|
|
111
|
+
return roots;
|
|
112
|
+
}
|
|
113
|
+
for (const mod of options.modules || []) {
|
|
114
|
+
addRoot(mod);
|
|
115
|
+
}
|
|
116
|
+
for (const mod of options.getModulesByFile?.(options.file) || []) {
|
|
117
|
+
addRoot(mod);
|
|
118
|
+
}
|
|
119
|
+
if (!roots.length) {
|
|
120
|
+
addRoot(options.getModuleById(options.file));
|
|
121
|
+
}
|
|
122
|
+
return roots;
|
|
123
|
+
}
|
|
124
|
+
export function collectAngularTransitiveImportersForInvalidation(options) {
|
|
125
|
+
const visited = new Set();
|
|
126
|
+
const collected = new Map();
|
|
127
|
+
const isExcluded = options.isExcluded ?? ((id) => id.includes('/node_modules/') || isRuntimeGraphExcludedPath(id));
|
|
128
|
+
const maxDepth = Math.max(1, Math.floor(options.maxDepth ?? 16));
|
|
129
|
+
const normalizeId = (value) => normalizeRuntimeGraphPath(value ?? '');
|
|
130
|
+
const walk = (mod, depth) => {
|
|
131
|
+
if (!mod || visited.has(mod)) {
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
visited.add(mod);
|
|
135
|
+
if (depth >= maxDepth) {
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
138
|
+
const importers = mod.importers;
|
|
139
|
+
if (!importers) {
|
|
140
|
+
return;
|
|
141
|
+
}
|
|
142
|
+
for (const importer of importers) {
|
|
143
|
+
if (!importer)
|
|
144
|
+
continue;
|
|
145
|
+
const importerId = normalizeId(importer.id);
|
|
146
|
+
if (!importerId) {
|
|
147
|
+
walk(importer, depth + 1);
|
|
148
|
+
continue;
|
|
149
|
+
}
|
|
150
|
+
if (isExcluded(importerId)) {
|
|
151
|
+
continue;
|
|
152
|
+
}
|
|
153
|
+
if (!collected.has(importerId)) {
|
|
154
|
+
collected.set(importerId, importer);
|
|
155
|
+
}
|
|
156
|
+
walk(importer, depth + 1);
|
|
157
|
+
}
|
|
158
|
+
};
|
|
159
|
+
for (const mod of options.modules || []) {
|
|
160
|
+
walk(mod, 0);
|
|
161
|
+
}
|
|
162
|
+
return Array.from(collected.values());
|
|
163
|
+
}
|
|
164
|
+
export function shouldInvalidateAngularTransitiveImporters(options) {
|
|
165
|
+
if (options.flavor !== 'angular') {
|
|
166
|
+
return false;
|
|
167
|
+
}
|
|
168
|
+
return /\.(?:html|htm|(m|c)?[jt]sx?)$/i.test(options.file);
|
|
169
|
+
}
|
|
170
|
+
function isExtensionlessAngularAppTransformCandidate(id) {
|
|
171
|
+
return id.startsWith(APP_VIRTUAL_WITH_SLASH) && /\.(?:[mc]?[jt]sx?)$/i.test(id);
|
|
172
|
+
}
|
|
173
|
+
function addAngularTransformCacheInvalidationUrl(targets, rawId, projectRoot) {
|
|
174
|
+
const id = String(rawId || '');
|
|
175
|
+
if (!id) {
|
|
176
|
+
return;
|
|
177
|
+
}
|
|
178
|
+
const cacheKey = projectRoot ? canonicalizeTransformRequestCacheKey(id, projectRoot) : id;
|
|
179
|
+
targets.add(cacheKey);
|
|
180
|
+
const normalizedId = cacheKey.replace(/\?.*$/, '');
|
|
181
|
+
if (!isExtensionlessAngularAppTransformCandidate(normalizedId)) {
|
|
182
|
+
return;
|
|
183
|
+
}
|
|
184
|
+
targets.add(normalizedId.replace(/\.(?:[mc]?[jt]sx?)$/i, ''));
|
|
185
|
+
}
|
|
186
|
+
export function collectAngularTransformCacheInvalidationUrls(options) {
|
|
187
|
+
const urls = new Set();
|
|
188
|
+
if (options.isTs) {
|
|
189
|
+
addAngularTransformCacheInvalidationUrl(urls, options.file, options.projectRoot);
|
|
190
|
+
}
|
|
191
|
+
for (const mod of options.hotUpdateRoots || []) {
|
|
192
|
+
addAngularTransformCacheInvalidationUrl(urls, mod?.id, options.projectRoot);
|
|
193
|
+
}
|
|
194
|
+
for (const mod of options.transitiveImporters || []) {
|
|
195
|
+
addAngularTransformCacheInvalidationUrl(urls, mod?.id, options.projectRoot);
|
|
196
|
+
}
|
|
197
|
+
return Array.from(urls);
|
|
198
|
+
}
|
|
199
|
+
export function shouldSuppressDefaultViteHotUpdate(options) {
|
|
200
|
+
if (options.flavor !== 'angular') {
|
|
201
|
+
return false;
|
|
202
|
+
}
|
|
203
|
+
return /\.(html|htm|ts)$/i.test(options.file);
|
|
204
|
+
}
|
|
205
|
+
export function normalizeHotReloadMatchPath(raw, root) {
|
|
206
|
+
let normalized = String(raw || '')
|
|
207
|
+
.split('?')[0]
|
|
208
|
+
.replace(/\\/g, '/')
|
|
209
|
+
.replace(/^file:\/\//, '');
|
|
210
|
+
if (root) {
|
|
211
|
+
const rootNormalized = root.replace(/\\/g, '/');
|
|
212
|
+
if (normalized.startsWith(rootNormalized)) {
|
|
213
|
+
normalized = normalized.slice(rootNormalized.length);
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
if (!normalized.startsWith('/')) {
|
|
217
|
+
normalized = `/${normalized}`;
|
|
218
|
+
}
|
|
219
|
+
return normalized;
|
|
220
|
+
}
|
|
221
|
+
export function shouldSuppressViteFullReloadPayload(options) {
|
|
222
|
+
const { payload, pendingEntries, root } = options;
|
|
223
|
+
const now = options.now ?? Date.now();
|
|
224
|
+
if (!payload || payload.type !== 'full-reload') {
|
|
225
|
+
return false;
|
|
226
|
+
}
|
|
227
|
+
const payloadPath = typeof payload.path === 'string' && payload.path !== '*' ? normalizeHotReloadMatchPath(payload.path, root) : null;
|
|
228
|
+
const payloadTriggeredBy = typeof payload.triggeredBy === 'string' ? normalizeHotReloadMatchPath(payload.triggeredBy, root) : null;
|
|
229
|
+
for (const entry of pendingEntries) {
|
|
230
|
+
if (!entry || entry.expiresAt <= now) {
|
|
231
|
+
continue;
|
|
232
|
+
}
|
|
233
|
+
if (payloadTriggeredBy === entry.absPath || payloadTriggeredBy === entry.relPath || payloadPath === entry.relPath || payloadPath === entry.absPath) {
|
|
234
|
+
return true;
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
return false;
|
|
238
|
+
}
|
|
239
|
+
//# sourceMappingURL=websocket-angular-hot-update.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"websocket-angular-hot-update.js","sourceRoot":"","sources":["../../../../../packages/vite/hmr/server/websocket-angular-hot-update.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,wBAAwB,EAAE,MAAM,wBAAwB,CAAC;AAClE,OAAO,EAAE,0BAA0B,EAAE,yBAAyB,EAAE,MAAM,2BAA2B,CAAC;AAElG,MAAM,sBAAsB,GAAG,GAAG,wBAAwB,EAAE,GAAG,CAAC;AAQhE,MAAM,UAAU,oCAAoC,CAAC,GAAW,EAAE,WAAmB;IACpF,IAAI,CAAC,GAAG;QAAE,OA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GAAG,EAAE,CAAC;IAEtC,IAAI,CAAC,OAAO,IAAI,OAAO,CAAC,IAAI,KAAK,aAAa,EAAE,CAAC;QAChD,OAAO,KAAK,CAAC;IACd,CAAC;IAED,MAAM,WAAW,GAAG,OAAO,OAAO,CAAC,IAAI,KAAK,QAAQ,IAAI,OAAO,CAAC,IAAI,KAAK,GAAG,CAAC,CAAC,CAAC,2BAA2B,CAAC,OAAO,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;IACtI,MAAM,kBAAkB,GAAG,OAAO,OAAO,CAAC,WAAW,KAAK,QAAQ,CAAC,CAAC,CAAC,2BAA2B,CAAC,OAAO,CAAC,WAAW,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;IAEnI,KAAK,MAAM,KAAK,IAAI,cAAc,EAAE,CAAC;QACpC,IAAI,CAAC,KAAK,IAAI,KAAK,CAAC,SAAS,IAAI,GAAG,EAAE,CAAC;YACtC,SAAS;QACV,CAAC;QAED,IAAI,kBAAkB,KAAK,KAAK,CAAC,OAAO,IAAI,kBAAkB,KAAK,KAAK,CAAC,OAAO,IAAI,WAAW,KAAK,KAAK,CAAC,OAAO,IAAI,WAAW,KAAK,KAAK,CAAC,OAAO,EAAE,CAAC;YACpJ,OAAO,IAAI,CAAC;QACb,CAAC;IACF,CAAC;IAED,OAAO,KAAK,CAAC;AACd,CAAC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export type CoreExportOrigin = {
|
|
2
|
+
moduleId: string;
|
|
3
|
+
mode: 'named' | 'module';
|
|
4
|
+
importedName?: string;
|
|
5
|
+
canonicalSubpath?: string;
|
|
6
|
+
};
|
|
7
|
+
export type ParsedCoreBridgeRequest = {
|
|
8
|
+
hasExplicitVersion: boolean;
|
|
9
|
+
ver: string;
|
|
10
|
+
sub: string;
|
|
11
|
+
normalizedSub: string | null;
|
|
12
|
+
key: string;
|
|
13
|
+
};
|
|
14
|
+
export declare function extractDirectExportedNames(code: string): string[];
|
|
15
|
+
export declare function resolveRuntimeCoreModulePath(normalizedSubpath: string, resolveModuleId: (moduleId: string) => Promise<string | null> | string | null): Promise<string | null>;
|
|
16
|
+
export declare function collectStaticExportNamesFromFile(modulePath: string, seen?: Set<string>): string[];
|
|
17
|
+
export declare function collectStaticExportOriginsFromFile(modulePath: string, rootEntryPath?: string, seen?: Set<string>): Record<string, CoreExportOrigin[]>;
|
|
18
|
+
export declare function normalizeCoreExportOriginsForRuntime(exportOrigins: Record<string, CoreExportOrigin[]>, resolveModuleId: (moduleId: string) => Promise<string | null> | string | null, rootModulePath: string): Promise<Record<string, CoreExportOrigin[]>>;
|
|
19
|
+
export declare function ensureVersionedCoreImports(code: string, _origin: string, ver: number): string;
|
|
20
|
+
export declare function hasModuleDefaultExport(moduleCode: string): boolean;
|
|
21
|
+
export declare function buildVersionedCoreSubpathAliasModule(sub: string, ver: number | string, namedExports?: string[], hasDefaultExport?: boolean): string;
|
|
22
|
+
export declare function buildVersionedCoreMainBridgeModule(key: string, ver: number | string, namedExports?: string[], exportOrigins?: Record<string, CoreExportOrigin[]>): string;
|
|
23
|
+
export declare function parseCoreBridgeRequest(pathname: string, searchParams: URLSearchParams, currentGraphVersion: number): ParsedCoreBridgeRequest | null;
|
|
@@ -0,0 +1,360 @@
|
|
|
1
|
+
import { existsSync, readFileSync, statSync } from 'node:fs';
|
|
2
|
+
import * as path from 'node:path';
|
|
3
|
+
const REQUIRE_GUARD_SNIPPET = `// [guard] install require('http(s)://') detector\n(()=>{try{var g=globalThis;if(g.__NS_REQUIRE_GUARD_INSTALLED__){}else{var mk=function(o,l){return function(){try{var s=arguments[0];if(typeof s==='string'&&/^(?:https?:)\\/\\//.test(s)){var e=new Error('[ns-hmr][require-guard] require of URL: '+s+' via '+l);try{console.error(e.message+'\\n'+(e.stack||''));}catch(e2){}try{g.__NS_REQUIRE_GUARD_LAST__={spec:s,stack:e.stack,label:l,ts:Date.now()};}catch(e3){}}}catch(e1){}return o.apply(this, arguments);};};if(typeof g.require==='function'&&!g.require.__NS_REQ_GUARDED__){var o1=g.require;g.require=mk(o1,'require');g.require.__NS_REQ_GUARDED__=true;}if(typeof g.__nsRequire==='function'&&!g.__nsRequire.__NS_REQ_GUARDED__){var o2=g.__nsRequire;g.__nsRequire=mk(o2,'__nsRequire');g.__nsRequire.__NS_REQ_GUARDED__=true;}g.__NS_REQUIRE_GUARD_INSTALLED__=true;}}catch(e){}})();\n`;
|
|
4
|
+
export function extractDirectExportedNames(code) {
|
|
5
|
+
const names = new Set();
|
|
6
|
+
const declRe = /\bexport\s+(?:async\s+)?(?:function|class)\s+([A-Za-z_$][\w$]*)/g;
|
|
7
|
+
let match;
|
|
8
|
+
while ((match = declRe.exec(code)) !== null) {
|
|
9
|
+
names.add(match[1]);
|
|
10
|
+
}
|
|
11
|
+
const namespaceRe = /\bexport\s+namespace\s+([A-Za-z_$][\w$]*)/g;
|
|
12
|
+
while ((match = namespaceRe.exec(code)) !== null) {
|
|
13
|
+
names.add(match[1]);
|
|
14
|
+
}
|
|
15
|
+
const varRe = /\bexport\s+(?:const|let|var)\s+([^=;{]+)/g;
|
|
16
|
+
while ((match = varRe.exec(code)) !== null) {
|
|
17
|
+
const decl = match[1].trim();
|
|
18
|
+
if (decl.startsWith('{')) {
|
|
19
|
+
const inner = decl.replace(/^\{|\}$/g, '');
|
|
20
|
+
for (const part of inner.split(',')) {
|
|
21
|
+
const name = part.split(':')[0].trim();
|
|
22
|
+
if (/^[A-Za-z_$][\w$]*$/.test(name))
|
|
23
|
+
names.add(name);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
const name = decl.split(/[\s,=]/)[0].trim();
|
|
28
|
+
if (/^[A-Za-z_$][\w$]*$/.test(name))
|
|
29
|
+
names.add(name);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
const directBraceRe = /\bexport\s*\{([^}]+)\}(?!\s*from)/g;
|
|
33
|
+
while ((match = directBraceRe.exec(code)) !== null) {
|
|
34
|
+
for (const part of match[1].split(',')) {
|
|
35
|
+
const trimmed = part.trim();
|
|
36
|
+
const asMatch = trimmed.match(/(\S+)\s+as\s+(\S+)/);
|
|
37
|
+
const name = asMatch ? asMatch[2] : trimmed.split(/\s/)[0];
|
|
38
|
+
if (name && /^[A-Za-z_$][\w$]*$/.test(name) && name !== 'default') {
|
|
39
|
+
names.add(name);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
return Array.from(names);
|
|
44
|
+
}
|
|
45
|
+
function parseExportSpecList(specList) {
|
|
46
|
+
return String(specList || '')
|
|
47
|
+
.split(',')
|
|
48
|
+
.map((part) => part.trim())
|
|
49
|
+
.filter(Boolean)
|
|
50
|
+
.map((part) => {
|
|
51
|
+
const asMatch = part.match(/(\S+)\s+as\s+(\S+)/i);
|
|
52
|
+
if (asMatch) {
|
|
53
|
+
return { importedName: asMatch[1].trim(), exportedName: asMatch[2].trim() };
|
|
54
|
+
}
|
|
55
|
+
const name = part.split(/\s/)[0]?.trim() || '';
|
|
56
|
+
return { importedName: name, exportedName: name };
|
|
57
|
+
})
|
|
58
|
+
.filter(({ exportedName, importedName }) => /^[A-Za-z_$][\w$]*$/.test(exportedName) && exportedName !== 'default' && /^[A-Za-z_$][\w$]*$/.test(importedName));
|
|
59
|
+
}
|
|
60
|
+
function runtimeModuleIdForFile(modulePath, rootEntryPath) {
|
|
61
|
+
const cleanedPath = String(modulePath || '').replace(/[?#].*$/, '');
|
|
62
|
+
const cleanedRoot = String(rootEntryPath || '').replace(/[?#].*$/, '');
|
|
63
|
+
if (!cleanedPath || !cleanedRoot)
|
|
64
|
+
return null;
|
|
65
|
+
const rootDir = path.dirname(cleanedRoot);
|
|
66
|
+
let rel = path.relative(rootDir, cleanedPath).replace(/\\/g, '/');
|
|
67
|
+
if (!rel || rel === 'index.ts' || rel === 'index.js' || rel === 'index.mjs') {
|
|
68
|
+
return '@nativescript/core';
|
|
69
|
+
}
|
|
70
|
+
rel = rel.replace(/\.(?:ts|js|mjs)$/, '');
|
|
71
|
+
rel = rel.replace(/\/index$/, '');
|
|
72
|
+
return `@nativescript/core/${rel}`;
|
|
73
|
+
}
|
|
74
|
+
function runtimeModuleIdFromLocalSpecifier(spec, currentModuleId) {
|
|
75
|
+
if (!spec.startsWith('.'))
|
|
76
|
+
return spec || null;
|
|
77
|
+
const base = currentModuleId.replace(/^@nativescript\/core(?:\/|$)/, '');
|
|
78
|
+
const baseDir = base ? `/${base}` : '/';
|
|
79
|
+
let rel = path.posix.normalize(path.posix.join(baseDir, spec)).replace(/^\/+/, '');
|
|
80
|
+
rel = rel.replace(/\.(?:ts|js|mjs)$/, '');
|
|
81
|
+
rel = rel.replace(/\/index$/, '');
|
|
82
|
+
return rel ? `@nativescript/core/${rel}` : '@nativescript/core';
|
|
83
|
+
}
|
|
84
|
+
function canonicalCoreSubpathForFile(modulePath, rootEntryPath) {
|
|
85
|
+
const cleanedPath = String(modulePath || '').replace(/[?#].*$/, '');
|
|
86
|
+
const cleanedRoot = String(rootEntryPath || '').replace(/[?#].*$/, '');
|
|
87
|
+
if (!cleanedPath || !cleanedRoot)
|
|
88
|
+
return null;
|
|
89
|
+
const rootDir = path.dirname(cleanedRoot);
|
|
90
|
+
let rel = path.relative(rootDir, cleanedPath).replace(/\\/g, '/');
|
|
91
|
+
if (!rel || rel === 'index.ts' || rel === 'index.js' || rel === 'index.mjs') {
|
|
92
|
+
return null;
|
|
93
|
+
}
|
|
94
|
+
rel = rel.replace(/\.(?:ts|js|mjs)$/, '.js');
|
|
95
|
+
return rel;
|
|
96
|
+
}
|
|
97
|
+
function canonicalCoreSubpathFromLocalSpecifier(spec, currentCanonicalSubpath) {
|
|
98
|
+
if (!spec.startsWith('.'))
|
|
99
|
+
return null;
|
|
100
|
+
const baseDir = currentCanonicalSubpath ? path.posix.dirname(currentCanonicalSubpath) : '.';
|
|
101
|
+
let rel = path.posix.normalize(path.posix.join(baseDir, spec)).replace(/^\.?\/?/, '');
|
|
102
|
+
if (!rel)
|
|
103
|
+
return null;
|
|
104
|
+
if (/\.(?:ts|js|mjs)$/i.test(rel)) {
|
|
105
|
+
return rel.replace(/\.(?:ts|js|mjs)$/i, '.js');
|
|
106
|
+
}
|
|
107
|
+
return `${rel.replace(/\/+$/, '')}/index.js`;
|
|
108
|
+
}
|
|
109
|
+
export async function resolveRuntimeCoreModulePath(normalizedSubpath, resolveModuleId) {
|
|
110
|
+
const cleanedSubpath = String(normalizedSubpath || '').replace(/^\/+/, '');
|
|
111
|
+
const candidates = [];
|
|
112
|
+
if (!cleanedSubpath || cleanedSubpath === 'index.js') {
|
|
113
|
+
candidates.push('@nativescript/core');
|
|
114
|
+
}
|
|
115
|
+
else {
|
|
116
|
+
if (/\/index\.js$/i.test(cleanedSubpath)) {
|
|
117
|
+
const packageSubpath = cleanedSubpath.replace(/\/index\.js$/i, '');
|
|
118
|
+
if (packageSubpath) {
|
|
119
|
+
candidates.push(`@nativescript/core/${packageSubpath}`);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
candidates.push(`@nativescript/core/${cleanedSubpath}`);
|
|
123
|
+
}
|
|
124
|
+
for (const candidate of candidates) {
|
|
125
|
+
try {
|
|
126
|
+
const resolved = await resolveModuleId(candidate);
|
|
127
|
+
if (resolved) {
|
|
128
|
+
return String(resolved).replace(/[?#].*$/, '');
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
catch { }
|
|
132
|
+
}
|
|
133
|
+
return null;
|
|
134
|
+
}
|
|
135
|
+
function appendCoreExportOrigin(map, exportedName, origin) {
|
|
136
|
+
if (!/^[A-Za-z_$][\w$]*$/.test(exportedName) || exportedName === 'default')
|
|
137
|
+
return;
|
|
138
|
+
const existing = map[exportedName] || (map[exportedName] = []);
|
|
139
|
+
if (existing.some((entry) => entry.moduleId === origin.moduleId && entry.mode === origin.mode && entry.importedName === origin.importedName)) {
|
|
140
|
+
return;
|
|
141
|
+
}
|
|
142
|
+
existing.push(origin);
|
|
143
|
+
}
|
|
144
|
+
function resolveLocalExportTarget(spec, importerId) {
|
|
145
|
+
const importerPath = String(importerId || '').replace(/[?#].*$/, '');
|
|
146
|
+
if (!importerPath)
|
|
147
|
+
return null;
|
|
148
|
+
const importerDir = path.dirname(importerPath);
|
|
149
|
+
const candidates = [path.resolve(importerDir, spec), path.resolve(importerDir, `${spec}.ts`), path.resolve(importerDir, `${spec}.js`), path.resolve(importerDir, `${spec}.mjs`), path.resolve(importerDir, spec, 'index.ts'), path.resolve(importerDir, spec, 'index.js'), path.resolve(importerDir, spec, 'index.mjs')];
|
|
150
|
+
for (const candidate of candidates) {
|
|
151
|
+
if (existsSync(candidate) && !statSync(candidate).isDirectory()) {
|
|
152
|
+
return candidate;
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
return null;
|
|
156
|
+
}
|
|
157
|
+
export function collectStaticExportNamesFromFile(modulePath, seen = new Set()) {
|
|
158
|
+
return Object.keys(collectStaticExportOriginsFromFile(modulePath, modulePath, seen));
|
|
159
|
+
}
|
|
160
|
+
export function collectStaticExportOriginsFromFile(modulePath, rootEntryPath = modulePath, seen = new Set()) {
|
|
161
|
+
const cleanedPath = String(modulePath || '').replace(/[?#].*$/, '');
|
|
162
|
+
const cleanedRoot = String(rootEntryPath || '').replace(/[?#].*$/, '');
|
|
163
|
+
if (!cleanedPath || !cleanedRoot || seen.has(cleanedPath) || !existsSync(cleanedPath)) {
|
|
164
|
+
return {};
|
|
165
|
+
}
|
|
166
|
+
seen.add(cleanedPath);
|
|
167
|
+
let code = '';
|
|
168
|
+
try {
|
|
169
|
+
code = readFileSync(cleanedPath, 'utf8');
|
|
170
|
+
}
|
|
171
|
+
catch {
|
|
172
|
+
return {};
|
|
173
|
+
}
|
|
174
|
+
const currentModuleId = runtimeModuleIdForFile(cleanedPath, cleanedRoot) || '@nativescript/core';
|
|
175
|
+
const currentCanonicalSubpath = canonicalCoreSubpathForFile(cleanedPath, cleanedRoot);
|
|
176
|
+
const origins = {};
|
|
177
|
+
for (const name of extractDirectExportedNames(code)) {
|
|
178
|
+
appendCoreExportOrigin(origins, name, { moduleId: currentModuleId, mode: 'named', importedName: name, canonicalSubpath: currentCanonicalSubpath || undefined });
|
|
179
|
+
}
|
|
180
|
+
const starAsRe = /\bexport\s+\*\s+as\s+([A-Za-z_$][\w$]*)\s+from\s+["']([^"']+)["']/g;
|
|
181
|
+
let match;
|
|
182
|
+
while ((match = starAsRe.exec(code)) !== null) {
|
|
183
|
+
const exportedName = match[1];
|
|
184
|
+
const spec = match[2];
|
|
185
|
+
const resolvedTarget = spec.startsWith('.') ? resolveLocalExportTarget(spec, cleanedPath) : null;
|
|
186
|
+
const moduleId = resolvedTarget ? runtimeModuleIdForFile(resolvedTarget, cleanedRoot) : spec.startsWith('.') ? runtimeModuleIdFromLocalSpecifier(spec, currentModuleId) : spec;
|
|
187
|
+
const canonicalSubpath = resolvedTarget ? canonicalCoreSubpathForFile(resolvedTarget, cleanedRoot) : spec.startsWith('.') ? canonicalCoreSubpathFromLocalSpecifier(spec, currentCanonicalSubpath) : undefined;
|
|
188
|
+
if (!moduleId)
|
|
189
|
+
continue;
|
|
190
|
+
appendCoreExportOrigin(origins, exportedName, { moduleId, mode: 'module', canonicalSubpath: canonicalSubpath || undefined });
|
|
191
|
+
}
|
|
192
|
+
const namedReExportRe = /\bexport\s*\{([^}]+)\}\s*from\s*["']([^"']+)["']/g;
|
|
193
|
+
while ((match = namedReExportRe.exec(code)) !== null) {
|
|
194
|
+
const specList = match[1];
|
|
195
|
+
const spec = match[2];
|
|
196
|
+
const resolvedTarget = spec.startsWith('.') ? resolveLocalExportTarget(spec, cleanedPath) : null;
|
|
197
|
+
const moduleId = resolvedTarget ? runtimeModuleIdForFile(resolvedTarget, cleanedRoot) : spec.startsWith('.') ? runtimeModuleIdFromLocalSpecifier(spec, currentModuleId) : spec;
|
|
198
|
+
const canonicalSubpath = resolvedTarget ? canonicalCoreSubpathForFile(resolvedTarget, cleanedRoot) : spec.startsWith('.') ? canonicalCoreSubpathFromLocalSpecifier(spec, currentCanonicalSubpath) : undefined;
|
|
199
|
+
if (!moduleId)
|
|
200
|
+
continue;
|
|
201
|
+
for (const { exportedName, importedName } of parseExportSpecList(specList)) {
|
|
202
|
+
appendCoreExportOrigin(origins, exportedName, { moduleId, mode: 'named', importedName, canonicalSubpath: canonicalSubpath || undefined });
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
const directBraceRe = /\bexport\s*\{([^}]+)\}(?!\s*from)/g;
|
|
206
|
+
while ((match = directBraceRe.exec(code)) !== null) {
|
|
207
|
+
for (const { exportedName, importedName } of parseExportSpecList(match[1])) {
|
|
208
|
+
appendCoreExportOrigin(origins, exportedName, { moduleId: currentModuleId, mode: 'named', importedName, canonicalSubpath: currentCanonicalSubpath || undefined });
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
const starRe = /^[ \t]*export\s+\*\s+from\s+["']([^"']+)["'];?[ \t]*$/gm;
|
|
212
|
+
while ((match = starRe.exec(code)) !== null) {
|
|
213
|
+
const spec = match[1];
|
|
214
|
+
if (!spec.startsWith('.'))
|
|
215
|
+
continue;
|
|
216
|
+
const resolvedTarget = resolveLocalExportTarget(spec, cleanedPath);
|
|
217
|
+
const moduleId = resolvedTarget ? runtimeModuleIdForFile(resolvedTarget, cleanedRoot) : runtimeModuleIdFromLocalSpecifier(spec, currentModuleId);
|
|
218
|
+
const canonicalSubpath = resolvedTarget ? canonicalCoreSubpathForFile(resolvedTarget, cleanedRoot) : canonicalCoreSubpathFromLocalSpecifier(spec, currentCanonicalSubpath);
|
|
219
|
+
if (!resolvedTarget)
|
|
220
|
+
continue;
|
|
221
|
+
const childOrigins = collectStaticExportOriginsFromFile(resolvedTarget, cleanedRoot, seen);
|
|
222
|
+
for (const [exportedName, entries] of Object.entries(childOrigins)) {
|
|
223
|
+
if (moduleId) {
|
|
224
|
+
appendCoreExportOrigin(origins, exportedName, { moduleId, mode: 'named', importedName: exportedName, canonicalSubpath: canonicalSubpath || undefined });
|
|
225
|
+
}
|
|
226
|
+
for (const entry of entries) {
|
|
227
|
+
appendCoreExportOrigin(origins, exportedName, entry);
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
return origins;
|
|
232
|
+
}
|
|
233
|
+
export async function normalizeCoreExportOriginsForRuntime(exportOrigins, resolveModuleId, rootModulePath) {
|
|
234
|
+
const cleanedRoot = String(rootModulePath || '').replace(/[?#].*$/, '');
|
|
235
|
+
if (!cleanedRoot || !exportOrigins || typeof exportOrigins !== 'object') {
|
|
236
|
+
return exportOrigins;
|
|
237
|
+
}
|
|
238
|
+
const resolutionCache = new Map();
|
|
239
|
+
const normalizedOrigins = {};
|
|
240
|
+
for (const [exportedName, entries] of Object.entries(exportOrigins)) {
|
|
241
|
+
normalizedOrigins[exportedName] = await Promise.all((entries || []).map(async (entry) => {
|
|
242
|
+
if (!entry?.moduleId || !entry.moduleId.startsWith('@nativescript/core')) {
|
|
243
|
+
return entry;
|
|
244
|
+
}
|
|
245
|
+
let resolvedPath = resolutionCache.get(entry.moduleId);
|
|
246
|
+
if (resolvedPath === undefined) {
|
|
247
|
+
try {
|
|
248
|
+
resolvedPath = (await resolveModuleId(entry.moduleId)) || null;
|
|
249
|
+
}
|
|
250
|
+
catch {
|
|
251
|
+
resolvedPath = null;
|
|
252
|
+
}
|
|
253
|
+
resolvedPath = resolvedPath ? String(resolvedPath).replace(/[?#].*$/, '') : null;
|
|
254
|
+
resolutionCache.set(entry.moduleId, resolvedPath);
|
|
255
|
+
}
|
|
256
|
+
if (!resolvedPath) {
|
|
257
|
+
return entry;
|
|
258
|
+
}
|
|
259
|
+
const canonicalSubpath = canonicalCoreSubpathForFile(resolvedPath, cleanedRoot);
|
|
260
|
+
if (!canonicalSubpath || canonicalSubpath === entry.canonicalSubpath) {
|
|
261
|
+
return entry;
|
|
262
|
+
}
|
|
263
|
+
return { ...entry, canonicalSubpath };
|
|
264
|
+
}));
|
|
265
|
+
}
|
|
266
|
+
return normalizedOrigins;
|
|
267
|
+
}
|
|
268
|
+
export function ensureVersionedCoreImports(code, _origin, ver) {
|
|
269
|
+
try {
|
|
270
|
+
code = code.replace(/(["'])(?:https?:\/\/[^"']+)?\/ns\/core(?:\/[\d]+)?(\?p=[^"']+)?\1/g, (_m, q, qp) => `${q}/ns/core/${ver}${qp || ''}${q}`);
|
|
271
|
+
code = code.replace(/import\(\s*(["'])(?:https?:\/\/[^"']+)?\/ns\/core(?:\/[\d]+)?(\?p=[^"']+)?\1\s*\)/g, (_m, q, qp) => `import(${q}/ns/core/${ver}${qp || ''}${q})`);
|
|
272
|
+
}
|
|
273
|
+
catch { }
|
|
274
|
+
return code;
|
|
275
|
+
}
|
|
276
|
+
export function hasModuleDefaultExport(moduleCode) {
|
|
277
|
+
if (!moduleCode || typeof moduleCode !== 'string')
|
|
278
|
+
return false;
|
|
279
|
+
return /\bexport\s+default\b/.test(moduleCode) || /\bexport\s*\{[^}]*\bdefault\b[^}]*\}/.test(moduleCode);
|
|
280
|
+
}
|
|
281
|
+
export function buildVersionedCoreSubpathAliasModule(sub, ver, namedExports = [], hasDefaultExport = false) {
|
|
282
|
+
const normalizedSub = (sub || '').replace(/^\/+/, '');
|
|
283
|
+
const canonicalUrl = `/ns/core/${ver}?p=${normalizedSub}`;
|
|
284
|
+
const filteredExports = Array.from(new Set(namedExports)).filter((name) => /^[A-Za-z_$][A-Za-z0-9_$]*$/.test(name) && name !== 'default' && name !== '__esModule');
|
|
285
|
+
const exportLines = filteredExports.length ? `export { ${filteredExports.join(', ')} } from ${JSON.stringify(canonicalUrl)};\n` : `export * from ${JSON.stringify(canonicalUrl)};\n`;
|
|
286
|
+
if (hasDefaultExport) {
|
|
287
|
+
return `export { default } from ${JSON.stringify(canonicalUrl)};\n` + exportLines;
|
|
288
|
+
}
|
|
289
|
+
return `import * as __ns_core_alias from ${JSON.stringify(canonicalUrl)};\n` + `export default __ns_core_alias;\n` + exportLines;
|
|
290
|
+
}
|
|
291
|
+
export function buildVersionedCoreMainBridgeModule(key, ver, namedExports = [], exportOrigins = {}) {
|
|
292
|
+
const filteredExports = Array.from(new Set(namedExports)).filter((name) => /^[A-Za-z_$][A-Za-z0-9_$]*$/.test(name) && name !== 'default' && name !== '__esModule');
|
|
293
|
+
const namedExportDeclarations = filteredExports.length ? filteredExports.map((name) => `const ${name} = __getCoreExport(${JSON.stringify(name)});`).join('\n') + '\n' : '';
|
|
294
|
+
const namedExportObjectLiteral = filteredExports.length ? `{ ${filteredExports.join(', ')} }` : '{}';
|
|
295
|
+
const namedExportStatement = filteredExports.length ? `export { ${filteredExports.join(', ')} };\n` : '';
|
|
296
|
+
const serializedExportOrigins = JSON.stringify(exportOrigins);
|
|
297
|
+
const staticOriginImports = new Map();
|
|
298
|
+
const staticOriginImportLines = [];
|
|
299
|
+
let staticOriginCounter = 0;
|
|
300
|
+
for (const entries of Object.values(exportOrigins)) {
|
|
301
|
+
for (const entry of entries) {
|
|
302
|
+
if (!entry.canonicalSubpath)
|
|
303
|
+
continue;
|
|
304
|
+
if (staticOriginImports.has(entry.canonicalSubpath))
|
|
305
|
+
continue;
|
|
306
|
+
const localName = `__ns_core_origin_${staticOriginCounter++}`;
|
|
307
|
+
staticOriginImports.set(entry.canonicalSubpath, localName);
|
|
308
|
+
staticOriginImportLines.push(`import * as ${localName} from ${JSON.stringify(`/ns/core/${ver}?p=${entry.canonicalSubpath}`)};`);
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
const staticOriginModulesLiteral = staticOriginImports.size
|
|
312
|
+
? `{ ${Array.from(staticOriginImports.entries())
|
|
313
|
+
.map(([subpath, localName]) => `${JSON.stringify(subpath)}: ${localName}`)
|
|
314
|
+
.join(', ')} }`
|
|
315
|
+
: '{}';
|
|
316
|
+
return ((staticOriginImportLines.length ? `${staticOriginImportLines.join('\n')}\n` : '') +
|
|
317
|
+
REQUIRE_GUARD_SNIPPET +
|
|
318
|
+
`// [ns-core-bridge][v${ver}] HTTP-only ESM bridge\n` +
|
|
319
|
+
`const g = globalThis;\n` +
|
|
320
|
+
`const reg = (g.__nsVendorRegistry ||= new Map());\n` +
|
|
321
|
+
`const __unwrapNsModule = (mod) => {\n if (!mod) return null;\n try { if ((typeof mod === 'object' || typeof mod === 'function') && Object.prototype.hasOwnProperty.call(mod, 'default')) { const keys = Object.keys(mod).filter((entry) => entry !== '__esModule'); if (!keys.length || (keys.length === 1 && keys[0] === 'default')) return mod.default; } } catch {}\n return mod;\n};\n` +
|
|
322
|
+
`const __resolveNsModule = (moduleId) => {\n try { if (typeof g.moduleExists === 'function' && g.moduleExists(moduleId) && typeof g.loadModule === 'function') { const mod = g.loadModule(moduleId); if (mod) return __unwrapNsModule(mod); } } catch {}\n try { if (reg && reg.get) { const mod = reg.get(moduleId); if (mod) return __unwrapNsModule(mod); } } catch {}\n try { const req = g.__nsVendorRequire || g.__nsRequire || g.require; if (typeof req === 'function') { const mod = req(moduleId); if (mod) return __unwrapNsModule(mod); } } catch {}\n try { const nr = g.__nativeRequire; if (typeof nr === 'function') { const mod = nr(moduleId, '/'); if (mod) return __unwrapNsModule(mod); } } catch {}\n return null;\n};\n` +
|
|
323
|
+
`const __pickApplicationApi = (candidate) => {\n if (!candidate) return null;\n const candidates = [candidate, candidate.Application, candidate.app, candidate.application];\n for (const entry of candidates) { if (entry && (typeof entry.run === 'function' || typeof entry.on === 'function' || typeof entry.resetRootView === 'function')) return entry; }\n return null;\n};\n` +
|
|
324
|
+
`let __nsPrimaryCoreReady = false;\nlet __nsPrimaryCore = null;\nconst __getPrimaryCore = () => { if (!__nsPrimaryCoreReady) { __nsPrimaryCore = __resolveNsModule(${JSON.stringify(key)}) || __resolveNsModule('@nativescript/core') || null; __nsPrimaryCoreReady = true; } return __nsPrimaryCore; };\n` +
|
|
325
|
+
`let __nsCoreUiReady = false;\nlet __nsCoreUi = null;\nconst __getCoreUi = () => { if (!__nsCoreUiReady) { __nsCoreUi = __resolveNsModule('@nativescript/core/ui') || null; __nsCoreUiReady = true; } return __nsCoreUi; };\n` +
|
|
326
|
+
`const __nsCoreExportOrigins = ${serializedExportOrigins};\nconst __nsCoreOriginModules = ${staticOriginModulesLiteral};\n` +
|
|
327
|
+
`const __resolveFromExportOrigins = (name) => { const entries = __nsCoreExportOrigins && __nsCoreExportOrigins[name]; if (!entries || !entries.length) return undefined; for (const entry of entries) { try { const mod = (entry.canonicalSubpath && __nsCoreOriginModules[entry.canonicalSubpath]) || __resolveNsModule(entry.moduleId); if (!mod) continue; if (entry.mode === 'module') return mod; const importedName = entry.importedName || name; if (importedName === 'Application') { const picked = __pickApplicationApi(mod); if (picked) return picked; } if (mod && mod[importedName] !== undefined) return mod[importedName]; } catch {} } return undefined; };\n` +
|
|
328
|
+
`const __getCoreExport = (name) => { if (name === 'Application' && g.Application && (typeof g.Application.run === 'function' || typeof g.Application.on === 'function' || typeof g.Application.resetRootView === 'function')) return g.Application; if (name === 'Application') { const appModule = __resolveNsModule('@nativescript/core/application'); const pickedApp = __pickApplicationApi(appModule); if (pickedApp) return pickedApp; } const primary = __getPrimaryCore(); if (name === 'Application') { const pickedPrimary = __pickApplicationApi(primary); if (pickedPrimary) return pickedPrimary; } try { if (primary && primary[name] !== undefined) return primary[name]; } catch {} const ui = __getCoreUi(); try { if (ui && ui[name] !== undefined) return ui[name]; } catch {} const viaOrigins = __resolveFromExportOrigins(name); if (viaOrigins !== undefined) return viaOrigins; try { const v = g[name]; if (v !== undefined) return v; } catch {} return undefined; };\n` +
|
|
329
|
+
namedExportDeclarations +
|
|
330
|
+
`const __nsNamedCore = ${namedExportObjectLiteral};\n` +
|
|
331
|
+
`const __core = new Proxy(__nsNamedCore, { get(_t, p){ if (p === 'default') return __core; if (p === Symbol.toStringTag) return 'Module'; try { if (typeof p === 'string' && Object.prototype.hasOwnProperty.call(__nsNamedCore, p)) { const value = __nsNamedCore[p]; if (value !== undefined) return value; } } catch {} return __getCoreExport(p); } });\n` +
|
|
332
|
+
namedExportStatement +
|
|
333
|
+
`export default __core;\n`);
|
|
334
|
+
}
|
|
335
|
+
export function parseCoreBridgeRequest(pathname, searchParams, currentGraphVersion) {
|
|
336
|
+
if (!pathname)
|
|
337
|
+
return null;
|
|
338
|
+
if (!(pathname === '/ns/core' || pathname === '/ns/core/' || pathname.startsWith('/ns/core/'))) {
|
|
339
|
+
return null;
|
|
340
|
+
}
|
|
341
|
+
if (/^\/ns\/core\/\d+(?:\/.*)$/.test(pathname)) {
|
|
342
|
+
return null;
|
|
343
|
+
}
|
|
344
|
+
const afterCore = pathname.replace(/^\/ns\/core\/?/, '');
|
|
345
|
+
if (afterCore.startsWith('/')) {
|
|
346
|
+
return null;
|
|
347
|
+
}
|
|
348
|
+
const hasExplicitVersion = /^\d+$/.test(afterCore);
|
|
349
|
+
const ver = hasExplicitVersion ? afterCore : String(currentGraphVersion || 0);
|
|
350
|
+
const sub = searchParams.get('p') || (afterCore && !hasExplicitVersion ? afterCore : '');
|
|
351
|
+
const normalizedSub = sub ? sub.replace(/^\/+/, '') : null;
|
|
352
|
+
return {
|
|
353
|
+
hasExplicitVersion,
|
|
354
|
+
ver,
|
|
355
|
+
sub: normalizedSub || '',
|
|
356
|
+
normalizedSub,
|
|
357
|
+
key: normalizedSub ? `@nativescript/core/${normalizedSub}` : '@nativescript/core',
|
|
358
|
+
};
|
|
359
|
+
}
|
|
360
|
+
//# sourceMappingURL=websocket-core-bridge.js.map
|