@oclif/plugin-update 4.7.44 → 4.7.46
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 +1 -1
- package/dist/update.js +52 -21
- package/oclif.manifest.json +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -81,7 +81,7 @@ EXAMPLES
|
|
|
81
81
|
$ oclif-example update --available
|
|
82
82
|
```
|
|
83
83
|
|
|
84
|
-
_See code: [src/commands/update.ts](https://github.com/oclif/plugin-update/blob/4.7.
|
|
84
|
+
_See code: [src/commands/update.ts](https://github.com/oclif/plugin-update/blob/4.7.46/src/commands/update.ts)_
|
|
85
85
|
<!-- commandsstop -->
|
|
86
86
|
|
|
87
87
|
# Contributing
|
package/dist/update.js
CHANGED
|
@@ -8,7 +8,7 @@ import { mkdir, readdir, readFile, rm, stat, symlink, utimes, writeFile } from '
|
|
|
8
8
|
import { basename, dirname, join } from 'node:path';
|
|
9
9
|
import { ProxyAgent } from 'proxy-agent';
|
|
10
10
|
import { Extractor } from './tar.js';
|
|
11
|
-
import { ls
|
|
11
|
+
import { ls } from './util.js';
|
|
12
12
|
const debug = makeDebug('oclif:update');
|
|
13
13
|
const filesize = (n) => {
|
|
14
14
|
const [num, suffix] = fileSize(n, { output: 'array' });
|
|
@@ -144,8 +144,12 @@ get_script_dir () {
|
|
|
144
144
|
DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
|
|
145
145
|
echo "$DIR"
|
|
146
146
|
}
|
|
147
|
-
|
|
148
|
-
|
|
147
|
+
|
|
148
|
+
# Ensure everything is read at once before execution to avoid race conditions when updating versions
|
|
149
|
+
{
|
|
150
|
+
DIR=$(get_script_dir)
|
|
151
|
+
${binPathEnvVar}="\$DIR/${bin}" ${redirectedEnvVar}=1 "$DIR/../${version}/bin/${bin}" "$@"
|
|
152
|
+
}; exit
|
|
149
153
|
`;
|
|
150
154
|
/* eslint-enable no-useless-escape */
|
|
151
155
|
await writeFile(dst, body, { mode: 0o755 });
|
|
@@ -283,25 +287,52 @@ const s3VersionManifestKey = ({ config, hash, version }) => {
|
|
|
283
287
|
const s3SubDir = composeS3SubDir(config);
|
|
284
288
|
return join(s3SubDir, 'versions', version, hash, `${bin}-v${version}-${hash}-${determinePlatform(config)}-${arch}-buildmanifest`);
|
|
285
289
|
};
|
|
286
|
-
//
|
|
287
|
-
|
|
288
|
-
|
|
290
|
+
// When autoupdating, wait until the CLI isn't active (lastrun mtime > 1 hour old).
|
|
291
|
+
//
|
|
292
|
+
// IMPORTANT: every CLI invocation touches lastrun before this function runs, so
|
|
293
|
+
// while the user is actively using the CLI, `lastrun + 1hr` keeps shifting
|
|
294
|
+
// forward and this wait never naturally resolves. The previous implementation
|
|
295
|
+
// recursed forever in that scenario, leaving each spawned autoupdate child
|
|
296
|
+
// pinned in memory as a full node process for the entire active session. When
|
|
297
|
+
// combined with the race documented in hooks/init.ts (which could spawn
|
|
298
|
+
// multiple such children per debounce window), the leaked children compounded
|
|
299
|
+
// until OOM on machines doing heavy CLI setup.
|
|
300
|
+
//
|
|
301
|
+
// Fix: cap the wait at a sensible wall-clock max. If the user is still active
|
|
302
|
+
// after that, abandon this autoupdate run — the next CLI invocation will fire
|
|
303
|
+
// a new one when it's again "needed".
|
|
304
|
+
const MAX_DEBOUNCE_WAIT_MS = 6 * 60 * 60 * 1000; // 6 hours
|
|
305
|
+
const DEBOUNCE_POLL_INTERVAL_MS = 60 * 1000; // 1 minute
|
|
306
|
+
const debounce = (cacheDir) => {
|
|
289
307
|
const lastrunfile = join(cacheDir, 'lastrun');
|
|
290
|
-
const
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
const
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
308
|
+
const startedAt = Date.now();
|
|
309
|
+
let announced = false;
|
|
310
|
+
return new Promise((resolve) => {
|
|
311
|
+
const check = async () => {
|
|
312
|
+
const m = await mtime(lastrunfile);
|
|
313
|
+
m.setHours(m.getHours() + 1);
|
|
314
|
+
if (m <= new Date()) {
|
|
315
|
+
ux.stdout('time to update');
|
|
316
|
+
resolve();
|
|
317
|
+
return;
|
|
318
|
+
}
|
|
319
|
+
if (Date.now() - startedAt >= MAX_DEBOUNCE_WAIT_MS) {
|
|
320
|
+
ux.stdout('autoupdate: debounce wait exceeded; abandoning this run');
|
|
321
|
+
resolve();
|
|
322
|
+
return;
|
|
323
|
+
}
|
|
324
|
+
const msg = `waiting until ${m.toISOString()} to update`;
|
|
325
|
+
if (announced) {
|
|
326
|
+
debug(msg);
|
|
327
|
+
}
|
|
328
|
+
else {
|
|
329
|
+
ux.stdout(msg);
|
|
330
|
+
announced = true;
|
|
331
|
+
}
|
|
332
|
+
setTimeout(check, DEBOUNCE_POLL_INTERVAL_MS);
|
|
333
|
+
};
|
|
334
|
+
check();
|
|
335
|
+
});
|
|
305
336
|
};
|
|
306
337
|
const setChannel = async (channel, dataDir) => writeFile(join(dataDir, 'channel'), channel, 'utf8');
|
|
307
338
|
const fetchChannelManifest = async (channel, config) => {
|
package/oclif.manifest.json
CHANGED