inup 1.5.5 → 1.5.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +24 -10
- package/dist/cli.js +20 -22
- package/dist/config/constants.js +4 -2
- package/dist/config/package-meta.js +10 -0
- package/dist/config/project-config.js +6 -1
- package/dist/core/package-detector.js +8 -4
- package/dist/core/upgrade-runner.js +7 -10
- package/dist/core/upgrader.js +6 -8
- package/dist/features/changelog/clients/github-client.js +5 -6
- package/dist/features/changelog/services/changelog-service.js +2 -4
- package/dist/features/changelog/services/package-metadata-service.js +6 -11
- package/dist/features/changelog/services/release-notes-service.js +4 -2
- package/dist/features/debug/services/performance-tracker.js +6 -8
- package/dist/index.js +1 -2
- package/dist/interactive-ui.js +13 -606
- package/dist/services/background-audit.js +3 -5
- package/dist/services/cache-manager.js +5 -7
- package/dist/services/http/inflight.js +22 -0
- package/dist/services/http/retry.js +30 -0
- package/dist/services/jsdelivr/client.js +191 -0
- package/dist/services/jsdelivr/manifest.js +136 -0
- package/dist/services/jsdelivr-registry.js +6 -392
- package/dist/services/npm-registry.js +12 -81
- package/dist/services/persistent-cache.js +8 -13
- package/dist/types/domain.js +3 -0
- package/dist/types/streaming.js +3 -0
- package/dist/types/ui.js +3 -0
- package/dist/types.js +17 -0
- package/dist/ui/controllers/package-info-modal-controller.js +22 -31
- package/dist/ui/controllers/vulnerability-audit-controller.js +17 -8
- package/dist/ui/index.js +3 -0
- package/dist/ui/input-handler.js +58 -75
- package/dist/ui/keymap.js +208 -0
- package/dist/ui/modal/package-info-sections/release-notes.js +161 -0
- package/dist/ui/modal/package-info-sections/sections.js +150 -0
- package/dist/ui/modal/package-info-sections/text.js +75 -0
- package/dist/ui/modal/package-info-sections.js +15 -369
- package/dist/ui/modal/package-info.js +1 -1
- package/dist/ui/renderer/help-modal.js +75 -0
- package/dist/ui/renderer/index.js +2 -5
- package/dist/ui/renderer/package-list/interface.js +184 -0
- package/dist/ui/renderer/package-list/rows.js +172 -0
- package/dist/ui/renderer/package-list.js +15 -455
- package/dist/ui/session/action-dispatcher.js +233 -0
- package/dist/ui/session/index.js +13 -0
- package/dist/ui/session/interactive-session.js +280 -0
- package/dist/ui/session/selection-state-builder.js +144 -0
- package/dist/ui/state/filter-manager.js +17 -6
- package/dist/ui/state/modal-manager.js +35 -0
- package/dist/ui/state/navigation-manager.js +33 -4
- package/dist/ui/state/state-manager.js +68 -3
- package/dist/ui/state/theme-manager.js +1 -0
- package/dist/ui/themes-colors.js +4 -1
- package/dist/ui/themes.js +11 -19
- package/dist/ui/utils/cursor.js +3 -4
- package/dist/ui/utils/index.js +6 -1
- package/dist/ui/utils/text.js +3 -2
- package/dist/ui/utils/version.js +60 -86
- package/dist/utils/config.js +13 -1
- package/dist/utils/filesystem/io.js +87 -0
- package/dist/utils/filesystem/paths.js +19 -0
- package/dist/utils/filesystem/scan.js +205 -0
- package/dist/utils/filesystem.js +17 -335
- package/dist/utils/version.js +31 -1
- package/package.json +6 -5
|
@@ -3,13 +3,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.packageCache = exports.CacheManager = void 0;
|
|
4
4
|
const config_1 = require("../config");
|
|
5
5
|
const persistent_cache_1 = require("./persistent-cache");
|
|
6
|
-
|
|
7
|
-
* Unified cache manager that handles both in-memory and persistent disk caching.
|
|
8
|
-
* Consolidates caching logic used across registry services.
|
|
9
|
-
*/
|
|
6
|
+
// Single TTL policy for both memory and disk.
|
|
10
7
|
class CacheManager {
|
|
8
|
+
memoryCache = new Map();
|
|
9
|
+
ttl;
|
|
11
10
|
constructor(ttl = config_1.CACHE_TTL) {
|
|
12
|
-
this.memoryCache = new Map();
|
|
13
11
|
this.ttl = ttl;
|
|
14
12
|
}
|
|
15
13
|
/**
|
|
@@ -24,11 +22,11 @@ class CacheManager {
|
|
|
24
22
|
}
|
|
25
23
|
// Check persistent disk cache (survives restarts)
|
|
26
24
|
const diskCached = persistent_cache_1.persistentCache.get(key);
|
|
27
|
-
if (diskCached) {
|
|
25
|
+
if (diskCached && Date.now() - diskCached.timestamp < this.ttl) {
|
|
28
26
|
// Populate in-memory cache for subsequent accesses
|
|
29
27
|
this.memoryCache.set(key, {
|
|
30
28
|
data: diskCached,
|
|
31
|
-
timestamp:
|
|
29
|
+
timestamp: diskCached.timestamp,
|
|
32
30
|
});
|
|
33
31
|
return diskCached;
|
|
34
32
|
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.InflightMap = void 0;
|
|
4
|
+
class InflightMap {
|
|
5
|
+
map = new Map();
|
|
6
|
+
async dedupe(key, fn) {
|
|
7
|
+
const existing = this.map.get(key);
|
|
8
|
+
if (existing) {
|
|
9
|
+
return await existing;
|
|
10
|
+
}
|
|
11
|
+
const promise = fn().finally(() => {
|
|
12
|
+
this.map.delete(key);
|
|
13
|
+
});
|
|
14
|
+
this.map.set(key, promise);
|
|
15
|
+
return await promise;
|
|
16
|
+
}
|
|
17
|
+
clear() {
|
|
18
|
+
this.map.clear();
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
exports.InflightMap = InflightMap;
|
|
22
|
+
//# sourceMappingURL=inflight.js.map
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isTransientNetworkError = exports.isRetryableStatus = exports.sleep = void 0;
|
|
4
|
+
const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
5
|
+
exports.sleep = sleep;
|
|
6
|
+
const isRetryableStatus = (statusCode) => statusCode === 408 || statusCode === 429 || statusCode >= 500;
|
|
7
|
+
exports.isRetryableStatus = isRetryableStatus;
|
|
8
|
+
const isTransientNetworkError = (error) => {
|
|
9
|
+
if (!(error instanceof Error)) {
|
|
10
|
+
return false;
|
|
11
|
+
}
|
|
12
|
+
const maybeCode = error.code;
|
|
13
|
+
return (error.name === 'AbortError' ||
|
|
14
|
+
error.name === 'HeadersTimeoutError' ||
|
|
15
|
+
error.name === 'BodyTimeoutError' ||
|
|
16
|
+
error.name === 'ConnectTimeoutError' ||
|
|
17
|
+
error.name === 'SocketError' ||
|
|
18
|
+
maybeCode === 'UND_ERR_HEADERS_TIMEOUT' ||
|
|
19
|
+
maybeCode === 'UND_ERR_BODY_TIMEOUT' ||
|
|
20
|
+
maybeCode === 'UND_ERR_CONNECT_TIMEOUT' ||
|
|
21
|
+
maybeCode === 'UND_ERR_SOCKET' ||
|
|
22
|
+
maybeCode === 'ENOTFOUND' ||
|
|
23
|
+
maybeCode === 'EAI_AGAIN' ||
|
|
24
|
+
maybeCode === 'ECONNRESET' ||
|
|
25
|
+
maybeCode === 'ECONNREFUSED' ||
|
|
26
|
+
maybeCode === 'ETIMEDOUT' ||
|
|
27
|
+
maybeCode === 'EPIPE');
|
|
28
|
+
};
|
|
29
|
+
exports.isTransientNetworkError = isTransientNetworkError;
|
|
30
|
+
//# sourceMappingURL=retry.js.map
|
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.jsdelivrPool = exports.RETRY_TIMEOUTS = void 0;
|
|
4
|
+
exports.fetchPackageManifestFromJsdelivr = fetchPackageManifestFromJsdelivr;
|
|
5
|
+
exports.fetchPackageManifestFromNpmRegistry = fetchPackageManifestFromNpmRegistry;
|
|
6
|
+
const undici_1 = require("undici");
|
|
7
|
+
const config_1 = require("../../config");
|
|
8
|
+
const utils_1 = require("../../utils");
|
|
9
|
+
const retry_1 = require("../http/retry");
|
|
10
|
+
const DEFAULT_JSDELIVR_RETRY_TIMEOUT_MS = 2000;
|
|
11
|
+
const DEFAULT_JSDELIVR_POOL_TIMEOUT_MS = 60000;
|
|
12
|
+
const MIN_JSDELIVR_CONNECT_TIMEOUT_MS = 500;
|
|
13
|
+
const toPositiveInteger = (value) => {
|
|
14
|
+
if (!Number.isFinite(value) || value <= 0) {
|
|
15
|
+
return null;
|
|
16
|
+
}
|
|
17
|
+
const normalized = Math.floor(value);
|
|
18
|
+
return normalized > 0 ? normalized : null;
|
|
19
|
+
};
|
|
20
|
+
exports.RETRY_TIMEOUTS = (() => {
|
|
21
|
+
const configured = Array.from(new Set(config_1.JSDELIVR_RETRY_TIMEOUTS.map(toPositiveInteger).filter((value) => value !== null))).sort((a, b) => a - b);
|
|
22
|
+
return configured.length > 0 ? configured : [DEFAULT_JSDELIVR_RETRY_TIMEOUT_MS];
|
|
23
|
+
})();
|
|
24
|
+
const RETRY_DELAYS = config_1.JSDELIVR_RETRY_DELAYS.map(toPositiveInteger).filter((value) => value !== null);
|
|
25
|
+
const MAX_RETRY_AFTER_DELAY_MS = exports.RETRY_TIMEOUTS[exports.RETRY_TIMEOUTS.length - 1];
|
|
26
|
+
const RETRY_AFTER_HEADER = 'retry-after';
|
|
27
|
+
const parseRetryAfterMs = (value) => {
|
|
28
|
+
const trimmed = value.trim();
|
|
29
|
+
if (!trimmed) {
|
|
30
|
+
return null;
|
|
31
|
+
}
|
|
32
|
+
const seconds = Number(trimmed);
|
|
33
|
+
if (Number.isFinite(seconds)) {
|
|
34
|
+
if (seconds <= 0) {
|
|
35
|
+
return null;
|
|
36
|
+
}
|
|
37
|
+
const delayMs = Math.floor(seconds * 1000);
|
|
38
|
+
return delayMs > 0 ? delayMs : null;
|
|
39
|
+
}
|
|
40
|
+
const dateMs = Date.parse(trimmed);
|
|
41
|
+
if (Number.isNaN(dateMs)) {
|
|
42
|
+
return null;
|
|
43
|
+
}
|
|
44
|
+
const delayMs = dateMs - Date.now();
|
|
45
|
+
return delayMs > 0 ? delayMs : null;
|
|
46
|
+
};
|
|
47
|
+
const getHeaderValue = (headers, name) => {
|
|
48
|
+
if (!headers) {
|
|
49
|
+
return null;
|
|
50
|
+
}
|
|
51
|
+
const direct = headers[name];
|
|
52
|
+
if (typeof direct === 'string') {
|
|
53
|
+
return direct;
|
|
54
|
+
}
|
|
55
|
+
if (Array.isArray(direct)) {
|
|
56
|
+
return direct.find((value) => typeof value === 'string') ?? null;
|
|
57
|
+
}
|
|
58
|
+
const headerEntry = Object.entries(headers).find(([headerName]) => headerName.toLowerCase() === name);
|
|
59
|
+
if (!headerEntry) {
|
|
60
|
+
return null;
|
|
61
|
+
}
|
|
62
|
+
const [, rawValue] = headerEntry;
|
|
63
|
+
if (typeof rawValue === 'string') {
|
|
64
|
+
return rawValue;
|
|
65
|
+
}
|
|
66
|
+
if (Array.isArray(rawValue)) {
|
|
67
|
+
return rawValue.find((value) => typeof value === 'string') ?? null;
|
|
68
|
+
}
|
|
69
|
+
return null;
|
|
70
|
+
};
|
|
71
|
+
const getRetryAfterDelay = (headers) => {
|
|
72
|
+
const retryAfterValue = getHeaderValue(headers, RETRY_AFTER_HEADER);
|
|
73
|
+
if (!retryAfterValue) {
|
|
74
|
+
return null;
|
|
75
|
+
}
|
|
76
|
+
const parsedDelay = parseRetryAfterMs(retryAfterValue);
|
|
77
|
+
if (parsedDelay === null) {
|
|
78
|
+
return null;
|
|
79
|
+
}
|
|
80
|
+
return Math.min(parsedDelay, MAX_RETRY_AFTER_DELAY_MS);
|
|
81
|
+
};
|
|
82
|
+
const getRetryDelay = (attempt, headers) => {
|
|
83
|
+
const configuredDelay = RETRY_DELAYS.length === 0 ? 0 : RETRY_DELAYS[Math.min(attempt, RETRY_DELAYS.length - 1)];
|
|
84
|
+
const retryAfterDelay = getRetryAfterDelay(headers);
|
|
85
|
+
return retryAfterDelay === null ? configuredDelay : Math.max(configuredDelay, retryAfterDelay);
|
|
86
|
+
};
|
|
87
|
+
// Keep connection setup bounded by retry budget so fallback stays responsive.
|
|
88
|
+
const JSDELIVR_CONNECT_TIMEOUT_MS = Math.max(exports.RETRY_TIMEOUTS[0], MIN_JSDELIVR_CONNECT_TIMEOUT_MS);
|
|
89
|
+
const JSDELIVR_POOL_TIMEOUT_MS = toPositiveInteger(config_1.JSDELIVR_POOL_TIMEOUT) ?? DEFAULT_JSDELIVR_POOL_TIMEOUT_MS;
|
|
90
|
+
const JSDELIVR_CONNECTIONS = toPositiveInteger(config_1.MAX_CONCURRENT_REQUESTS) ?? 1;
|
|
91
|
+
// Create a persistent connection pool for jsDelivr CDN with optimal settings
|
|
92
|
+
// This enables connection reuse and HTTP/1.1 keep-alive for blazing fast requests
|
|
93
|
+
exports.jsdelivrPool = new undici_1.Pool('https://cdn.jsdelivr.net', {
|
|
94
|
+
connections: JSDELIVR_CONNECTIONS,
|
|
95
|
+
pipelining: 10,
|
|
96
|
+
keepAliveTimeout: JSDELIVR_POOL_TIMEOUT_MS,
|
|
97
|
+
keepAliveMaxTimeout: JSDELIVR_POOL_TIMEOUT_MS,
|
|
98
|
+
connectTimeout: JSDELIVR_CONNECT_TIMEOUT_MS,
|
|
99
|
+
});
|
|
100
|
+
const consumeBodySafely = async (body) => {
|
|
101
|
+
try {
|
|
102
|
+
await body.text();
|
|
103
|
+
}
|
|
104
|
+
catch {
|
|
105
|
+
// Ignore body read errors on non-200 responses because request will be retried/fallback.
|
|
106
|
+
}
|
|
107
|
+
};
|
|
108
|
+
async function fetchPackageManifestFromJsdelivr(packageName, versionTag) {
|
|
109
|
+
const url = `${config_1.JSDELIVR_CDN_URL}/${encodeURIComponent(packageName)}@${versionTag}/package.json`;
|
|
110
|
+
for (let attempt = 0; attempt < exports.RETRY_TIMEOUTS.length; attempt++) {
|
|
111
|
+
const timeout = exports.RETRY_TIMEOUTS[attempt];
|
|
112
|
+
const tReq = Date.now();
|
|
113
|
+
try {
|
|
114
|
+
const { statusCode, headers, body } = await (0, undici_1.request)(url, {
|
|
115
|
+
dispatcher: exports.jsdelivrPool,
|
|
116
|
+
method: 'GET',
|
|
117
|
+
headers: {
|
|
118
|
+
accept: 'application/json',
|
|
119
|
+
},
|
|
120
|
+
headersTimeout: timeout,
|
|
121
|
+
bodyTimeout: timeout,
|
|
122
|
+
});
|
|
123
|
+
if (statusCode !== 200) {
|
|
124
|
+
// Consume body to prevent memory leaks
|
|
125
|
+
await consumeBodySafely(body);
|
|
126
|
+
if ((0, retry_1.isRetryableStatus)(statusCode) && attempt < exports.RETRY_TIMEOUTS.length - 1) {
|
|
127
|
+
const delay = getRetryDelay(attempt, headers);
|
|
128
|
+
utils_1.debugLog.warn('jsdelivr', `${packageName}@${versionTag} HTTP ${statusCode}, retry ${attempt + 1} in ${delay}ms`);
|
|
129
|
+
if (delay > 0) {
|
|
130
|
+
await (0, retry_1.sleep)(delay);
|
|
131
|
+
}
|
|
132
|
+
continue;
|
|
133
|
+
}
|
|
134
|
+
utils_1.debugLog.warn('jsdelivr', `${packageName}@${versionTag} HTTP ${statusCode}, no more retries`);
|
|
135
|
+
return null;
|
|
136
|
+
}
|
|
137
|
+
const text = await body.text();
|
|
138
|
+
const data = JSON.parse(text);
|
|
139
|
+
if (!data || typeof data !== 'object' || Array.isArray(data)) {
|
|
140
|
+
return null;
|
|
141
|
+
}
|
|
142
|
+
utils_1.debugLog.perf('jsdelivr', `fetch manifest ${packageName}@${versionTag}`, tReq);
|
|
143
|
+
return data;
|
|
144
|
+
}
|
|
145
|
+
catch (error) {
|
|
146
|
+
if ((0, retry_1.isTransientNetworkError)(error) && attempt < exports.RETRY_TIMEOUTS.length - 1) {
|
|
147
|
+
const delay = getRetryDelay(attempt);
|
|
148
|
+
utils_1.debugLog.warn('jsdelivr', `${packageName}@${versionTag} transient error on attempt ${attempt + 1}, retry in ${delay}ms`, error);
|
|
149
|
+
if (delay > 0) {
|
|
150
|
+
await (0, retry_1.sleep)(delay);
|
|
151
|
+
}
|
|
152
|
+
continue;
|
|
153
|
+
}
|
|
154
|
+
if (!(0, retry_1.isTransientNetworkError)(error)) {
|
|
155
|
+
// Unexpected errors are logged for observability.
|
|
156
|
+
console.error(`jsDelivr fetch failed for ${packageName}@${versionTag} on attempt ${attempt + 1}/${exports.RETRY_TIMEOUTS.length}`, error);
|
|
157
|
+
utils_1.debugLog.error('jsdelivr', `unexpected error for ${packageName}@${versionTag} attempt ${attempt + 1}`, error);
|
|
158
|
+
}
|
|
159
|
+
else {
|
|
160
|
+
utils_1.debugLog.warn('jsdelivr', `${packageName}@${versionTag} exhausted retries`, error);
|
|
161
|
+
}
|
|
162
|
+
return null;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
return null;
|
|
166
|
+
}
|
|
167
|
+
async function fetchPackageManifestFromNpmRegistry(packageName, version) {
|
|
168
|
+
const controller = new AbortController();
|
|
169
|
+
const timeoutId = setTimeout(() => controller.abort(), config_1.REQUEST_TIMEOUT);
|
|
170
|
+
try {
|
|
171
|
+
const response = await fetch(`${config_1.NPM_REGISTRY_URL}/${encodeURIComponent(packageName)}/${encodeURIComponent(version)}`, {
|
|
172
|
+
method: 'GET',
|
|
173
|
+
headers: {
|
|
174
|
+
accept: 'application/json',
|
|
175
|
+
},
|
|
176
|
+
signal: controller.signal,
|
|
177
|
+
});
|
|
178
|
+
if (!response.ok) {
|
|
179
|
+
return null;
|
|
180
|
+
}
|
|
181
|
+
return (await response.json());
|
|
182
|
+
}
|
|
183
|
+
catch (error) {
|
|
184
|
+
utils_1.debugLog.warn('npm-registry', `exact manifest fallback failed for ${packageName}@${version}`, error);
|
|
185
|
+
return null;
|
|
186
|
+
}
|
|
187
|
+
finally {
|
|
188
|
+
clearTimeout(timeoutId);
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
//# sourceMappingURL=client.js.map
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.fetchExactPackageManifest = fetchExactPackageManifest;
|
|
37
|
+
exports.getAllPackageDataFromJsdelivr = getAllPackageDataFromJsdelivr;
|
|
38
|
+
exports.closeJsdelivrPool = closeJsdelivrPool;
|
|
39
|
+
exports.clearExactManifestCache = clearExactManifestCache;
|
|
40
|
+
const semver = __importStar(require("semver"));
|
|
41
|
+
const utils_1 = require("../../utils");
|
|
42
|
+
const version_1 = require("../../utils/version");
|
|
43
|
+
const inflight_1 = require("../http/inflight");
|
|
44
|
+
const client_1 = require("./client");
|
|
45
|
+
const EXACT_VERSION_PATTERN = /^[0-9]+\.[0-9]+\.[0-9]+(?:-[0-9A-Za-z.-]+)?(?:\+[0-9A-Za-z.-]+)?$/;
|
|
46
|
+
const sortVersionsDescending = (versions) => {
|
|
47
|
+
const uniqueVersions = [];
|
|
48
|
+
const seenVersions = new Set();
|
|
49
|
+
for (const version of versions) {
|
|
50
|
+
const identity = (0, version_1.versionIdentity)(version);
|
|
51
|
+
if (!seenVersions.has(identity)) {
|
|
52
|
+
seenVersions.add(identity);
|
|
53
|
+
uniqueVersions.push(version);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
return uniqueVersions.sort((a, b) => {
|
|
57
|
+
const comparableA = (0, version_1.toComparableVersion)(a);
|
|
58
|
+
const comparableB = (0, version_1.toComparableVersion)(b);
|
|
59
|
+
if (comparableA && comparableB) {
|
|
60
|
+
return semver.rcompare(comparableA, comparableB);
|
|
61
|
+
}
|
|
62
|
+
if (comparableA) {
|
|
63
|
+
return -1;
|
|
64
|
+
}
|
|
65
|
+
if (comparableB) {
|
|
66
|
+
return 1;
|
|
67
|
+
}
|
|
68
|
+
return b.localeCompare(a);
|
|
69
|
+
});
|
|
70
|
+
};
|
|
71
|
+
const inFlightManifests = new inflight_1.InflightMap();
|
|
72
|
+
async function fetchExactPackageManifest(packageName, version) {
|
|
73
|
+
const normalizedVersion = version.trim();
|
|
74
|
+
if (!EXACT_VERSION_PATTERN.test(normalizedVersion) || !semver.valid(normalizedVersion)) {
|
|
75
|
+
utils_1.debugLog.warn('jsdelivr', `skipping non-exact version lookup for ${packageName}@${version}`);
|
|
76
|
+
return null;
|
|
77
|
+
}
|
|
78
|
+
const cacheKey = `${packageName}@${normalizedVersion}`;
|
|
79
|
+
return inFlightManifests.dedupe(cacheKey, async () => {
|
|
80
|
+
const jsdelivrManifest = await (0, client_1.fetchPackageManifestFromJsdelivr)(packageName, normalizedVersion);
|
|
81
|
+
if (jsdelivrManifest) {
|
|
82
|
+
return jsdelivrManifest;
|
|
83
|
+
}
|
|
84
|
+
return await (0, client_1.fetchPackageManifestFromNpmRegistry)(packageName, normalizedVersion);
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
async function getAllPackageDataFromJsdelivr(packageNames, currentVersions, onProgress) {
|
|
88
|
+
const packageData = new Map();
|
|
89
|
+
if (packageNames.length === 0) {
|
|
90
|
+
return packageData;
|
|
91
|
+
}
|
|
92
|
+
const total = packageNames.length;
|
|
93
|
+
let completedCount = 0;
|
|
94
|
+
const inFlightLookups = new inflight_1.InflightMap();
|
|
95
|
+
const fetchPackageData = async (packageName, currentVersion) => {
|
|
96
|
+
const latestManifest = await (0, client_1.fetchPackageManifestFromJsdelivr)(packageName, 'latest');
|
|
97
|
+
const latestVersion = typeof latestManifest?.version === 'string' ? latestManifest.version.trim() : '';
|
|
98
|
+
if (!latestVersion) {
|
|
99
|
+
return null;
|
|
100
|
+
}
|
|
101
|
+
const majorVersion = (0, version_1.extractMajorVersion)(currentVersion);
|
|
102
|
+
const latestMajorVersion = (0, version_1.extractMajorVersion)(latestVersion);
|
|
103
|
+
const shouldFetchMajorVersion = Boolean(majorVersion && (latestMajorVersion === null || latestMajorVersion !== majorVersion));
|
|
104
|
+
const majorManifest = shouldFetchMajorVersion
|
|
105
|
+
? await (0, client_1.fetchPackageManifestFromJsdelivr)(packageName, majorVersion)
|
|
106
|
+
: null;
|
|
107
|
+
const majorResolvedVersion = typeof majorManifest?.version === 'string' ? majorManifest.version.trim() : '';
|
|
108
|
+
const sortedVersions = sortVersionsDescending([latestVersion, majorResolvedVersion].filter(Boolean));
|
|
109
|
+
const allVersions = sortedVersions[0] === latestVersion
|
|
110
|
+
? sortedVersions
|
|
111
|
+
: [latestVersion, ...sortedVersions.filter((version) => version !== latestVersion)];
|
|
112
|
+
return { latestVersion, allVersions };
|
|
113
|
+
};
|
|
114
|
+
const getPackageData = (packageName, currentVersion) => inFlightLookups.dedupe(packageName, () => fetchPackageData(packageName, currentVersion));
|
|
115
|
+
await Promise.all(packageNames.map(async (packageName) => {
|
|
116
|
+
try {
|
|
117
|
+
const result = await getPackageData(packageName, currentVersions?.get(packageName));
|
|
118
|
+
if (result) {
|
|
119
|
+
packageData.set(packageName, result);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
finally {
|
|
123
|
+
completedCount++;
|
|
124
|
+
onProgress?.(packageName, completedCount, total);
|
|
125
|
+
}
|
|
126
|
+
}));
|
|
127
|
+
return packageData;
|
|
128
|
+
}
|
|
129
|
+
async function closeJsdelivrPool() {
|
|
130
|
+
const { jsdelivrPool } = await Promise.resolve().then(() => __importStar(require('./client')));
|
|
131
|
+
await jsdelivrPool.close();
|
|
132
|
+
}
|
|
133
|
+
function clearExactManifestCache() {
|
|
134
|
+
inFlightManifests.clear();
|
|
135
|
+
}
|
|
136
|
+
//# sourceMappingURL=manifest.js.map
|