dsh-tg-bridge 1.31.0 → 1.31.1
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/control/release.mjs +23 -4
- package/package.json +1 -1
package/control/release.mjs
CHANGED
|
@@ -153,15 +153,34 @@ export function newestModuleMtime(root) {
|
|
|
153
153
|
return newest;
|
|
154
154
|
}
|
|
155
155
|
|
|
156
|
-
/**
|
|
156
|
+
/**
|
|
157
|
+
* Latest published version of an npm package, or '' when npm is unreachable.
|
|
158
|
+
*
|
|
159
|
+
* The answer is memoised for a minute, for two reasons that both showed up as
|
|
160
|
+
* bugs. The first is honesty: `/update` and `/version` are the same card, and
|
|
161
|
+
* when the network was slow enough for one `npm view` to time out and the other
|
|
162
|
+
* to answer, the two spellings of one command disagreed about the same fact.
|
|
163
|
+
* The second is cost: `npm view` blocks the process for up to 45 seconds, and a
|
|
164
|
+
* second card inside that minute should not pay it again. A stale minute is
|
|
165
|
+
* nothing to a release check; two answers to one question is not.
|
|
166
|
+
*/
|
|
167
|
+
const LATEST_TTL_MS = 60 * 1000;
|
|
168
|
+
const latestCache = new Map();
|
|
169
|
+
|
|
157
170
|
export function npmLatest(name) {
|
|
171
|
+
const key = String(name);
|
|
172
|
+
const hit = latestCache.get(key);
|
|
173
|
+
if (hit && Date.now() - hit.at < LATEST_TTL_MS) return hit.value;
|
|
174
|
+
let value = '';
|
|
158
175
|
try {
|
|
159
|
-
const r = spawnSync('npm', ['view',
|
|
176
|
+
const r = spawnSync('npm', ['view', key, 'version'], { encoding: 'utf8', shell: true, timeout: 45000, windowsHide: true });
|
|
160
177
|
const out = String(r.stdout || '').trim().split(/\s+/).pop() || '';
|
|
161
|
-
|
|
178
|
+
value = r.status === 0 && /^\d/.test(out) ? out : '';
|
|
162
179
|
} catch {
|
|
163
|
-
|
|
180
|
+
value = '';
|
|
164
181
|
}
|
|
182
|
+
latestCache.set(key, { value, at: Date.now() });
|
|
183
|
+
return value;
|
|
165
184
|
}
|
|
166
185
|
|
|
167
186
|
/**
|
package/package.json
CHANGED