@officesdk/officesdk-plugin 0.0.0-stage → 1.0.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/LICENSE +21 -0
- package/NOTICE +23 -0
- package/bin/check-package.mjs +9 -0
- package/bin/codex.mjs +63 -0
- package/bin/file-host.mjs +120 -0
- package/bin/hosts.mjs +75 -0
- package/bin/ide.mjs +70 -0
- package/bin/install.mjs +62 -0
- package/bin/workbuddy.mjs +97 -0
- package/bin/zcode.mjs +91 -0
- package/kit-manifest.json +3465 -0
- package/package.json +38 -4
- package/routes.json +95 -0
- package/runtime/download-sources.mjs +107 -0
- package/runtime/downloader.mjs +326 -0
- package/runtime/lease.mjs +88 -0
- package/runtime/office-kit.mjs +150 -0
- package/runtime/runtime.mjs +139 -0
- package/runtime/sources.mjs +85 -0
- package/runtime/tar.mjs +235 -0
- package/README.md +0 -3
package/package.json
CHANGED
|
@@ -1,6 +1,40 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@officesdk/officesdk-plugin",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "1.0.3",
|
|
4
|
+
"description": "Install OfficeSDK for the current AI agent",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"bin": {
|
|
7
|
+
"officesdk-plugin": "./bin/install.mjs"
|
|
8
|
+
},
|
|
9
|
+
"files": [
|
|
10
|
+
"bin/check-package.mjs",
|
|
11
|
+
"bin/codex.mjs",
|
|
12
|
+
"bin/file-host.mjs",
|
|
13
|
+
"bin/hosts.mjs",
|
|
14
|
+
"bin/ide.mjs",
|
|
15
|
+
"bin/install.mjs",
|
|
16
|
+
"bin/workbuddy.mjs",
|
|
17
|
+
"bin/zcode.mjs",
|
|
18
|
+
"routes.json",
|
|
19
|
+
"LICENSE",
|
|
20
|
+
"runtime",
|
|
21
|
+
"kit-manifest.json",
|
|
22
|
+
"NOTICE"
|
|
23
|
+
],
|
|
24
|
+
"license": "MIT",
|
|
25
|
+
"engines": {
|
|
26
|
+
"node": ">=22.19.0"
|
|
27
|
+
},
|
|
28
|
+
"repository": {
|
|
29
|
+
"type": "git",
|
|
30
|
+
"url": "git+https://github.com/officesdk/officesdk-plugin.git",
|
|
31
|
+
"directory": "packages/installer"
|
|
32
|
+
},
|
|
33
|
+
"publishConfig": {
|
|
34
|
+
"access": "public",
|
|
35
|
+
"registry": "https://registry.npmjs.org/"
|
|
36
|
+
},
|
|
37
|
+
"scripts": {
|
|
38
|
+
"prepack": "node bin/check-package.mjs"
|
|
39
|
+
}
|
|
40
|
+
}
|
package/routes.json
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
{
|
|
2
|
+
"dsh": {
|
|
3
|
+
"kind": "dsh-npm",
|
|
4
|
+
"package": "@officesdk/officesdk-plugin-dsh",
|
|
5
|
+
"asset": "officesdk-officesdk-plugin-dsh-1.0.3.tgz",
|
|
6
|
+
"size": 1391604,
|
|
7
|
+
"sha256": "df68ac947245375538fd59c3555e55cbe981601c883503fbf364e954e0b37653"
|
|
8
|
+
},
|
|
9
|
+
"hermes": {
|
|
10
|
+
"kind": "file-host",
|
|
11
|
+
"asset": "officesdk-hermes-1.0.3.tar.gz",
|
|
12
|
+
"sha256": "ce6ab80e4a01b08b4785c323afc5a45216b592a6ed2424a4f2d735443820ed75",
|
|
13
|
+
"size": 1831724,
|
|
14
|
+
"manifest": "package.json",
|
|
15
|
+
"name": "officesdk-plugin-hermes",
|
|
16
|
+
"platforms": [
|
|
17
|
+
"darwin-arm64"
|
|
18
|
+
]
|
|
19
|
+
},
|
|
20
|
+
"minimax": {
|
|
21
|
+
"kind": "file-host",
|
|
22
|
+
"asset": "officesdk-minimax-1.0.3.tar.gz",
|
|
23
|
+
"sha256": "a2ff69159001bb385e3b646e34991968db19e61f8e53a1b217306e16cf85cb57",
|
|
24
|
+
"size": 1147394,
|
|
25
|
+
"manifest": ".minimax-plugin/plugin.json",
|
|
26
|
+
"name": "officesdk-minimax",
|
|
27
|
+
"platforms": [
|
|
28
|
+
"darwin-arm64"
|
|
29
|
+
]
|
|
30
|
+
},
|
|
31
|
+
"zcode": {
|
|
32
|
+
"kind": "zcode-market",
|
|
33
|
+
"asset": "officesdk-zcode-1.0.3.tar.gz",
|
|
34
|
+
"size": 1570516,
|
|
35
|
+
"sha256": "7aa76b0a0447a8713b96f984c634dc974bfbbaaf19f0ae26880572933b9119f1",
|
|
36
|
+
"manifest": ".zcode-plugin/plugin.json",
|
|
37
|
+
"name": "officesdk",
|
|
38
|
+
"platforms": [
|
|
39
|
+
"darwin-arm64"
|
|
40
|
+
]
|
|
41
|
+
},
|
|
42
|
+
"codex": {
|
|
43
|
+
"kind": "codex-market",
|
|
44
|
+
"asset": "officesdk-codex-1.0.3.tar.gz",
|
|
45
|
+
"size": 1666172,
|
|
46
|
+
"sha256": "5ad1c96b63e5fd8bce792a01db61c95a63d57d0b917353d3372444e2137a3cec",
|
|
47
|
+
"manifest": ".codex-plugin/plugin.json",
|
|
48
|
+
"name": "officesdk",
|
|
49
|
+
"platforms": [
|
|
50
|
+
"darwin-arm64"
|
|
51
|
+
]
|
|
52
|
+
},
|
|
53
|
+
"workbuddy": {
|
|
54
|
+
"kind": "workbuddy-market",
|
|
55
|
+
"asset": "officesdk-workbuddy-1.0.3.tar.gz",
|
|
56
|
+
"size": 1511007,
|
|
57
|
+
"sha256": "5bbe7477c483b9a61277561847440b41a5bce1aec84d1b0a8fa41da7ada5f288",
|
|
58
|
+
"manifest": ".workbuddy-plugin/plugin.json",
|
|
59
|
+
"name": "officesdk",
|
|
60
|
+
"platforms": [
|
|
61
|
+
"darwin-arm64"
|
|
62
|
+
]
|
|
63
|
+
},
|
|
64
|
+
"antigravity": {
|
|
65
|
+
"kind": "file-host",
|
|
66
|
+
"asset": "officesdk-antigravity-1.0.3.tar.gz",
|
|
67
|
+
"size": 1527766,
|
|
68
|
+
"sha256": "52b98e7933c3547a2e7661abc72eac5b6c18909f241a49163be939246a33b42c",
|
|
69
|
+
"manifest": "plugin.json",
|
|
70
|
+
"name": "officesdk",
|
|
71
|
+
"platforms": [
|
|
72
|
+
"darwin-arm64"
|
|
73
|
+
]
|
|
74
|
+
},
|
|
75
|
+
"grok": {
|
|
76
|
+
"kind": "vsix",
|
|
77
|
+
"asset": "officesdk-ide-1.0.3-darwin-arm64.vsix",
|
|
78
|
+
"name": "officesdk.officesdk-plugin-grok",
|
|
79
|
+
"size": 1820401,
|
|
80
|
+
"sha256": "3f63bfe7946d20ce28a9d61c945423109a763cb45accf47dde2d910d423cc991",
|
|
81
|
+
"platforms": [
|
|
82
|
+
"darwin-arm64"
|
|
83
|
+
]
|
|
84
|
+
},
|
|
85
|
+
"cursor": {
|
|
86
|
+
"kind": "vsix",
|
|
87
|
+
"asset": "officesdk-ide-1.0.3-darwin-arm64.vsix",
|
|
88
|
+
"name": "officesdk.officesdk-plugin-grok",
|
|
89
|
+
"size": 1820401,
|
|
90
|
+
"sha256": "3f63bfe7946d20ce28a9d61c945423109a763cb45accf47dde2d910d423cc991",
|
|
91
|
+
"platforms": [
|
|
92
|
+
"darwin-arm64"
|
|
93
|
+
]
|
|
94
|
+
}
|
|
95
|
+
}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import { readFileSync } from 'node:fs';
|
|
2
|
+
import { join } from 'node:path';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Where downloads come from, as data (spec 261111-npm-publish-prep §6): `download-sources.json` at the package root
|
|
6
|
+
* names an ordered list of source ids per item in its one profile, `public`: the Kit from office-kit's release (`release`:
|
|
7
|
+
* the sources kit-manifest.json names, office-kit's GitHub release), the editor resources from office-kit's npm package
|
|
8
|
+
* (`npm`: kit-manifest.json `editor.npm`; the release does not carry them), each after `mirror` when OFFICESDK_KIT_MIRROR
|
|
9
|
+
* is set; its skills ship inside the package (`bundled`, spec 261113-bundle-public-skills): nothing to download.
|
|
10
|
+
*
|
|
11
|
+
* Both the Kit and the editor resources download on first use; an offline package carries both. The `public` skill
|
|
12
|
+
* source (a mirror at `publicBase`) still works when a file names it (drills).
|
|
13
|
+
*
|
|
14
|
+
* A missing or unreadable file means the defaults below. Environment variables still override (OFFICESDK_KIT_MIRROR,
|
|
15
|
+
* OFFICESDK_EDITOR_NPM, and OFFICESDK_SKILLS_BASE for `publicBase`).
|
|
16
|
+
*/
|
|
17
|
+
export const SOURCES_FILE = 'download-sources.json';
|
|
18
|
+
export const PROFILES = Object.freeze(['public']);
|
|
19
|
+
/**
|
|
20
|
+
* The editor's npm registry is its last source (the release carries no editor): it gets time to answer (15 s), to
|
|
21
|
+
* pause in the body (30 s), and three tries, as any last source does.
|
|
22
|
+
*/
|
|
23
|
+
export const NPM_DEFAULTS = Object.freeze({ connectTimeoutMs: 15_000, idleMs: 30_000, attempts: 3 });
|
|
24
|
+
export const PUBLIC_CONNECT_TIMEOUT_MS = 5000;
|
|
25
|
+
const KIT_IDS = ['mirror', 'release'];
|
|
26
|
+
const EDITOR_IDS = ['mirror', 'npm'];
|
|
27
|
+
/** `bundled`: the skills ship complete in the package; no download source is tried. `public`: a skill mirror (drills). */
|
|
28
|
+
const SKILL_IDS = ['public', 'bundled'];
|
|
29
|
+
|
|
30
|
+
export const DEFAULT_SOURCES = Object.freeze({
|
|
31
|
+
v: 1,
|
|
32
|
+
profile: 'public',
|
|
33
|
+
profiles: {
|
|
34
|
+
public: {
|
|
35
|
+
kit: ['mirror', 'release'],
|
|
36
|
+
editor: ['mirror', 'npm'],
|
|
37
|
+
skills: { sources: ['bundled'], catalog: ['bundled'] },
|
|
38
|
+
},
|
|
39
|
+
},
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
const entryOf = value => (typeof value === 'string' ? { id: value } : value && typeof value === 'object' && typeof value.id === 'string' ? value : undefined);
|
|
43
|
+
const positive = value => (Number.isFinite(value) && value > 0 ? value : undefined);
|
|
44
|
+
|
|
45
|
+
/** What is wrong with a sources document (empty when nothing); CI and the gate refuse a package whose file has problems. */
|
|
46
|
+
export function sourcesProblems(doc) {
|
|
47
|
+
const problems = [];
|
|
48
|
+
if (doc?.v !== 1) return ['download-sources.json: v must be 1'];
|
|
49
|
+
if (!PROFILES.includes(doc.profile)) problems.push(`download-sources.json: profile must be one of ${PROFILES.join(', ')}`);
|
|
50
|
+
for (const name of PROFILES) {
|
|
51
|
+
const profile = doc.profiles?.[name];
|
|
52
|
+
if (!profile) { problems.push(`download-sources.json: profiles.${name} is missing`); continue; }
|
|
53
|
+
for (const [item, allowed] of [['kit', KIT_IDS], ['editor', EDITOR_IDS]]) {
|
|
54
|
+
if (!Array.isArray(profile[item])) { problems.push(`profiles.${name}.${item} must be a list`); continue; }
|
|
55
|
+
for (const raw of profile[item]) { const entry = entryOf(raw); if (!entry || !allowed.includes(entry.id)) problems.push(`profiles.${name}.${item}: unknown source ${JSON.stringify(raw)}`); }
|
|
56
|
+
}
|
|
57
|
+
for (const list of ['sources', 'catalog']) for (const id of profile.skills?.[list] ?? []) if (!SKILL_IDS.includes(id)) problems.push(`profiles.${name}.skills.${list}: unknown source ${id}`);
|
|
58
|
+
// Skills either ship in the package or download; a profile never mixes the two.
|
|
59
|
+
const skillIds = [...profile.skills?.sources ?? [], ...profile.skills?.catalog ?? []];
|
|
60
|
+
if (skillIds.includes('bundled') && skillIds.some(id => id !== 'bundled')) problems.push(`profiles.${name}.skills: bundled cannot be mixed with download sources`);
|
|
61
|
+
const base = profile.skills?.publicBase;
|
|
62
|
+
if (base && !/^https:\/\//.test(base) && !/^http:\/\/(127\.0\.0\.1|localhost)[:/]/.test(base)) problems.push(`profiles.${name}.skills.publicBase must be https (or a loopback http address for drills)`);
|
|
63
|
+
}
|
|
64
|
+
return problems;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/** The parsed document (DEFAULT_SOURCES when the package has none or it is broken: `log` says why). */
|
|
68
|
+
export function readDownloadSources(packageRoot, log = () => {}) {
|
|
69
|
+
let doc;
|
|
70
|
+
try { doc = JSON.parse(readFileSync(join(packageRoot, SOURCES_FILE), 'utf8')); }
|
|
71
|
+
catch (error) { if (error?.code !== 'ENOENT') log('warn', `${SOURCES_FILE} is unreadable (${error?.message}); the built-in sources are used`); return DEFAULT_SOURCES; }
|
|
72
|
+
const problems = sourcesProblems(doc);
|
|
73
|
+
if (problems.length) { log('warn', `${SOURCES_FILE}: ${problems.join('; ')}; the built-in sources are used`); return DEFAULT_SOURCES; }
|
|
74
|
+
return doc;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* The selected profile, normalised: `{ name, kit: [{id,…}], editor: [{id,…}], skills: { sources, catalog, publicBase } }`.
|
|
79
|
+
* `env.OFFICESDK_SKILLS_BASE` replaces `publicBase`.
|
|
80
|
+
*/
|
|
81
|
+
export function selectProfile(doc = DEFAULT_SOURCES, env = process.env) {
|
|
82
|
+
const name = PROFILES.includes(doc?.profile) ? doc.profile : 'public';
|
|
83
|
+
const profile = doc?.profiles?.[name] ?? DEFAULT_SOURCES.profiles[name];
|
|
84
|
+
const skills = profile.skills ?? {};
|
|
85
|
+
const publicBase = (env.OFFICESDK_SKILLS_BASE || skills.publicBase || '').trim();
|
|
86
|
+
return {
|
|
87
|
+
name,
|
|
88
|
+
kit: (profile.kit ?? []).map(entryOf).filter(Boolean),
|
|
89
|
+
editor: (profile.editor ?? []).map(entryOf).filter(Boolean),
|
|
90
|
+
skills: { sources: [...skills.sources ?? []], catalog: [...skills.catalog ?? []], publicBase: publicBase.replace(/\/+$/, '') },
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/** The npm source options of an editor list entry (DEFAULT timeouts unless the file sets its own). */
|
|
95
|
+
export function npmOptions(entry = {}) {
|
|
96
|
+
return { connectTimeoutMs: positive(entry.connectTimeoutMs) ?? NPM_DEFAULTS.connectTimeoutMs, idleMs: positive(entry.idleMs) ?? NPM_DEFAULTS.idleMs, attempts: positive(entry.attempts) ?? NPM_DEFAULTS.attempts };
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/** The document a build writes for `profile` (pack-universal --sources); `publicBase` (drills) sets a public mirror. */
|
|
100
|
+
export function sourcesFor(profile = 'public', { publicBase } = {}) {
|
|
101
|
+
if (!PROFILES.includes(profile)) throw new Error(`unknown sources profile ${profile} (only public)`);
|
|
102
|
+
const doc = JSON.parse(JSON.stringify(DEFAULT_SOURCES));
|
|
103
|
+
doc.profile = profile;
|
|
104
|
+
// A drill of the old public mirror: the public profile downloads its skills from `publicBase` instead of carrying them.
|
|
105
|
+
if (publicBase) doc.profiles.public.skills = { sources: ['public'], catalog: ['public'], publicBase: publicBase.replace(/\/+$/, '') };
|
|
106
|
+
return doc;
|
|
107
|
+
}
|
|
@@ -0,0 +1,326 @@
|
|
|
1
|
+
import { createHash, randomUUID } from 'node:crypto';
|
|
2
|
+
import { EventEmitter, once } from 'node:events';
|
|
3
|
+
import { createReadStream, createWriteStream, existsSync, readFileSync, readdirSync, statSync } from 'node:fs';
|
|
4
|
+
import { mkdir, readFile, rename, rm, stat, writeFile } from 'node:fs/promises';
|
|
5
|
+
import { basename, dirname, join } from 'node:path';
|
|
6
|
+
import { waitForLease } from './lease.mjs';
|
|
7
|
+
import { SourceError, openSource } from './sources.mjs';
|
|
8
|
+
import { extractTar } from './tar.mjs';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* One downloader for everything the universal package fetches (spec 261110-universal-package §4.2, §4.5): office-kit's
|
|
12
|
+
* Kit and editor resources, and skill resources. An item is
|
|
13
|
+
*
|
|
14
|
+
* { key, dir, files, sources, archive?, strip?, outside?, bundledDir?, prepare?, label? }
|
|
15
|
+
*
|
|
16
|
+
* `dir` is where the verified files end up (written once, then never changed: a new version gets a new dir); `files` the
|
|
17
|
+
* manifest's `{ [path]: { sha256 | sha512, executable? } }`; `archive` `{ file, size, integrity }` for a `.tar.gz` whose
|
|
18
|
+
* sha512 the manifest pins (Kit, editor); without it the source streams a plain tar checked file by file.
|
|
19
|
+
* `prepare(tmpDir)` runs on the unpacked files before they go live (Kit: executable bits, quarantine, self test).
|
|
20
|
+
*
|
|
21
|
+
* Downloads run under one lease per data root (several DSH windows and profiles share it), resume from `.part` files,
|
|
22
|
+
* try each source `attempts` times with growing delays, and emit `progress` events
|
|
23
|
+
* `{ key, label, phase: 'waiting'|'downloading'|'verifying'|'unpacking'|'ready'|'failed', received?, total?, error? }`.
|
|
24
|
+
*/
|
|
25
|
+
export class DownloadError extends Error {
|
|
26
|
+
constructor(item, failures) {
|
|
27
|
+
const reasons = failures.map(failure => `${failure.source}: ${failure.message}`);
|
|
28
|
+
super(`${item.label ?? item.key} could not be downloaded (${reasons.join('; ') || 'no source'})`);
|
|
29
|
+
this.name = 'DownloadError';
|
|
30
|
+
this.code = failures.length && failures.every(failure => failure.code === 'no-token' || failure.code === 'denied') ? 'denied' : 'download-failed';
|
|
31
|
+
this.failures = failures;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export const COMPLETE = '.complete';
|
|
36
|
+
const DELAYS_MS = [2000, 8000, 30000];
|
|
37
|
+
const IDLE_MS = 60_000;
|
|
38
|
+
const RENAME_RETRIES = [100, 200, 400, 800, 1600, 2000, 2000, 2000, 2000, 2000];
|
|
39
|
+
const sleep = (ms, signal) => new Promise((resolve, reject) => {
|
|
40
|
+
if (signal?.aborted) return reject(signal.reason);
|
|
41
|
+
const timer = setTimeout(resolve, ms);
|
|
42
|
+
signal?.addEventListener('abort', () => { clearTimeout(timer); reject(signal.reason); }, { once: true });
|
|
43
|
+
});
|
|
44
|
+
const sourceName = source => source.id ?? source.kind;
|
|
45
|
+
|
|
46
|
+
/** A stable marker for an item's content: its archive sha512, else a hash of its file list. */
|
|
47
|
+
export function markerOf(item) {
|
|
48
|
+
// A skill is the same files whether its pack's sha512 is known yet or not (review R2-F1): its file list decides.
|
|
49
|
+
if (item.archive?.integrity && !String(item.key ?? '').startsWith('skill/')) return item.archive.integrity;
|
|
50
|
+
const text = JSON.stringify(Object.keys(item.files).sort().map(name => [name, item.files[name].sha512 ?? item.files[name].sha256, Boolean(item.files[name].executable)]));
|
|
51
|
+
return `files-sha256-${createHash('sha256').update(text).digest('base64')}`;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
async function hashFile(file, algorithm) {
|
|
55
|
+
const hash = createHash(algorithm);
|
|
56
|
+
for await (const chunk of createReadStream(file)) hash.update(chunk);
|
|
57
|
+
return `${algorithm}-${hash.digest('base64')}`;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/** Problems between the unpacked files and the manifest's list (missing, extra, changed, executable bit). */
|
|
61
|
+
export function fileProblems(expected, actual) {
|
|
62
|
+
const problems = [];
|
|
63
|
+
for (const [name, want] of Object.entries(expected)) {
|
|
64
|
+
const got = actual[name];
|
|
65
|
+
if (!got) { problems.push(`missing ${name}`); continue; }
|
|
66
|
+
const algorithm = want.sha512 ? 'sha512' : 'sha256';
|
|
67
|
+
if (got[algorithm] !== want[algorithm]) problems.push(`changed ${name}`);
|
|
68
|
+
if (Boolean(want.executable) !== Boolean(got.executable)) problems.push(`mode ${name}`);
|
|
69
|
+
}
|
|
70
|
+
for (const name of Object.keys(actual)) if (!Object.hasOwn(expected, name)) problems.push(`unexpected ${name}`);
|
|
71
|
+
return problems;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export class Downloader extends EventEmitter {
|
|
75
|
+
constructor({ root, open = openSource, delaysMs = DELAYS_MS, idleMs = IDLE_MS, fetchImpl, spawn, now = Date.now, lease = {}, log = () => {}, renameDelaysMs = RENAME_RETRIES }) {
|
|
76
|
+
super();
|
|
77
|
+
Object.assign(this, { root, open, delaysMs, idleMs, fetchImpl, spawn, now, leaseOptions: lease, log, renameDelaysMs });
|
|
78
|
+
this.inflight = new Map();
|
|
79
|
+
this.prepared = new Set();
|
|
80
|
+
this.via = new Map();
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
get downloads() { return join(this.root, 'downloads'); }
|
|
84
|
+
get stateFile() { return join(this.root, 'state.json'); }
|
|
85
|
+
|
|
86
|
+
/** Progress of `item`; while a download runs it names the source in use and the sources it fell back from. */
|
|
87
|
+
progress(item, fields) { this.emit('progress', { key: item.key, label: item.label, source: undefined, fallback: undefined, ...this.via.get(item.key), ...fields }); }
|
|
88
|
+
|
|
89
|
+
/** Whether `item.dir` holds this exact item: its `.complete` marker and every listed file present. Cheap: no hashing. */
|
|
90
|
+
isComplete(item) {
|
|
91
|
+
try {
|
|
92
|
+
const marker = JSON.parse(readFileSync(join(item.dir, COMPLETE), 'utf8'));
|
|
93
|
+
if (marker.marker !== markerOf(item)) return false;
|
|
94
|
+
return Object.keys(item.files).every(name => existsSync(join(item.dir, ...name.split('/'))));
|
|
95
|
+
} catch { return false; }
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* The directory holding `item`, downloading it when needed. Bundled copies (an offline package) are used in place
|
|
100
|
+
* when every listed file is there. Concurrent calls for one key share one download.
|
|
101
|
+
* Options: `signal`, `budgetMs` (give up waiting after this; the download keeps going in the background unless
|
|
102
|
+
* `signal` aborts), `firstSourceOnly`.
|
|
103
|
+
*/
|
|
104
|
+
async ensure(item, { signal, budgetMs, firstSourceOnly = false } = {}) {
|
|
105
|
+
const bundled = item.bundledDir && Object.keys(item.files).every(name => existsSync(join(item.bundledDir, ...name.split('/'))));
|
|
106
|
+
if (bundled) {
|
|
107
|
+
if (item.prepare && !this.prepared.has(item.bundledDir)) { await item.prepare(item.bundledDir, { bundled: true }); this.prepared.add(item.bundledDir); }
|
|
108
|
+
// Not touched: `lastUsed` belongs to the data directory copy, which a packaged copy leaves to age out (prune).
|
|
109
|
+
return { dir: item.bundledDir, source: 'bundled' };
|
|
110
|
+
}
|
|
111
|
+
if (this.isComplete(item)) { await this.touch(item); return { dir: item.dir, source: 'cache' }; }
|
|
112
|
+
let running = this.inflight.get(item.key);
|
|
113
|
+
if (!running) {
|
|
114
|
+
running = this.download(item, { signal: budgetMs ? undefined : signal, firstSourceOnly }).finally(() => this.inflight.delete(item.key));
|
|
115
|
+
this.inflight.set(item.key, running);
|
|
116
|
+
}
|
|
117
|
+
if (!budgetMs) return running;
|
|
118
|
+
let timer;
|
|
119
|
+
const budget = new Promise((_, reject) => { timer = setTimeout(() => reject(Object.assign(new Error(`${item.label ?? item.key} is still downloading`), { code: 'still-downloading' })), budgetMs); });
|
|
120
|
+
const aborted = signal ? new Promise((_, reject) => signal.addEventListener('abort', () => reject(signal.reason), { once: true })) : new Promise(() => {});
|
|
121
|
+
try { return await Promise.race([running, budget, aborted]); } finally { clearTimeout(timer); }
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
async download(item, { signal, firstSourceOnly }) {
|
|
125
|
+
this.progress(item, { phase: 'waiting' });
|
|
126
|
+
const lease = await waitForLease(join(this.root, '.lock'), { signal, onWait: () => this.progress(item, { phase: 'waiting' }), ...this.leaseOptions });
|
|
127
|
+
try {
|
|
128
|
+
// Another process may have finished it while this one waited.
|
|
129
|
+
if (this.isComplete(item)) { this.progress(item, { phase: 'ready' }); return { dir: item.dir, source: 'cache' }; }
|
|
130
|
+
const manual = item.archive && await this.manualCopy(item);
|
|
131
|
+
if (manual) {
|
|
132
|
+
try { await this.install(item, { kind: 'manual' }, createReadStream(manual), 'tgz', signal); await rm(manual, { force: true }); return { dir: item.dir, source: 'manual' }; }
|
|
133
|
+
catch (error) { this.log('warn', `ignored ${manual}: ${error.message}`); }
|
|
134
|
+
}
|
|
135
|
+
const failures = [];
|
|
136
|
+
const sources = firstSourceOnly ? item.sources.slice(0, 1) : item.sources;
|
|
137
|
+
const fellBack = [];
|
|
138
|
+
for (const [index, source] of sources.entries()) {
|
|
139
|
+
// A source may set its own number of tries (download-sources.json `attempts`; the editor's npm source: NPM_DEFAULTS).
|
|
140
|
+
const attempts = firstSourceOnly ? 1 : Math.max(1, Math.min(source.attempts ?? this.delaysMs.length, this.delaysMs.length));
|
|
141
|
+
this.via.set(item.key, { source: sourceName(source), ...fellBack.length && { fallback: [...fellBack] } });
|
|
142
|
+
for (let attempt = 1; attempt <= attempts; attempt++) {
|
|
143
|
+
signal?.throwIfAborted();
|
|
144
|
+
try {
|
|
145
|
+
await this.fetchFrom(item, source, signal);
|
|
146
|
+
this.progress(item, { phase: 'ready' });
|
|
147
|
+
await this.touch(item, { lastError: null, source: sourceName(source) });
|
|
148
|
+
return { dir: item.dir, source: sourceName(source) };
|
|
149
|
+
} catch (error) {
|
|
150
|
+
if (signal?.aborted) throw signal.reason;
|
|
151
|
+
failures.push({ source: sourceName(source), message: error?.message ?? String(error), code: error?.code });
|
|
152
|
+
this.log('warn', `${item.key} from ${sourceName(source)} (try ${attempt}): ${error?.message ?? error}`);
|
|
153
|
+
// `final`: the bytes were fine and another source would deliver the same (a Kit that does not start).
|
|
154
|
+
if (error?.final) { const failed = new DownloadError(item, failures); this.progress(item, { phase: 'failed', error: failed.message }); throw failed; }
|
|
155
|
+
if (error?.retry === false || attempt === attempts) break;
|
|
156
|
+
await sleep(this.delaysMs[attempt - 1], signal);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
fellBack.push(sourceName(source));
|
|
160
|
+
const next = sources[index + 1];
|
|
161
|
+
if (next) this.log('warn', `${item.key}: ${sourceName(source)} unavailable (${failures.at(-1)?.message}); falling back to ${sourceName(next)}`);
|
|
162
|
+
}
|
|
163
|
+
const error = new DownloadError(item, failures);
|
|
164
|
+
this.progress(item, { phase: 'failed', error: error.message });
|
|
165
|
+
await this.touch(item, { lastError: { at: this.now(), message: error.message } }, { used: false });
|
|
166
|
+
throw error;
|
|
167
|
+
} finally { this.via.delete(item.key); lease.release(); }
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
/** An archive the user put into downloads/ by hand (any name) with the manifest's size and sha512 (spec §5). */
|
|
171
|
+
async manualCopy(item) {
|
|
172
|
+
let names;
|
|
173
|
+
try { names = readdirSync(this.downloads); } catch { return undefined; }
|
|
174
|
+
for (const name of names) {
|
|
175
|
+
if (name.endsWith('.part') || name.endsWith('.part.json')) continue;
|
|
176
|
+
const file = join(this.downloads, name);
|
|
177
|
+
try {
|
|
178
|
+
if (statSync(file).size !== item.archive.size) continue;
|
|
179
|
+
if (await hashFile(file, 'sha512') === item.archive.integrity) return file;
|
|
180
|
+
} catch { /* unreadable: not ours */ }
|
|
181
|
+
}
|
|
182
|
+
return undefined;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
async fetchFrom(item, source, signal) {
|
|
186
|
+
// One controller per attempt: an idle body is cut off by aborting its request, not by waiting for its reader.
|
|
187
|
+
const attempt = new AbortController();
|
|
188
|
+
const requestSignal = signal ? AbortSignal.any([signal, attempt.signal]) : attempt.signal;
|
|
189
|
+
const cut = error => attempt.abort(error);
|
|
190
|
+
// Without a pinned archive the source streams the files themselves (checked one by one).
|
|
191
|
+
if (!item.archive) {
|
|
192
|
+
const opened = await this.open(source, item, { signal: requestSignal, fetchImpl: this.fetchImpl, spawn: this.spawn });
|
|
193
|
+
return this.install(item, source, this.watch(opened.body, signal, cut, source.idleMs), opened.format ?? 'tar', signal);
|
|
194
|
+
}
|
|
195
|
+
await mkdir(this.downloads, { recursive: true });
|
|
196
|
+
const part = join(this.downloads, `${basename(item.archive.file)}.part`);
|
|
197
|
+
const metaFile = `${part}.json`;
|
|
198
|
+
let meta = {};
|
|
199
|
+
try { meta = JSON.parse(await readFile(metaFile, 'utf8')); } catch {}
|
|
200
|
+
let offset = 0;
|
|
201
|
+
try { offset = meta.source === sourceName(source) && meta.integrity === item.archive.integrity && meta.etag ? (await stat(part)).size : 0; } catch {}
|
|
202
|
+
// A complete .part that already matches (a run whose later step failed, e.g. the Kit self test): no new download.
|
|
203
|
+
if (offset === item.archive.size && await hashFile(part, 'sha512').catch(() => '') === item.archive.integrity) {
|
|
204
|
+
await this.install(item, source, createReadStream(part), 'tgz', signal);
|
|
205
|
+
await rm(part, { force: true }); await rm(metaFile, { force: true });
|
|
206
|
+
return;
|
|
207
|
+
}
|
|
208
|
+
if (offset >= item.archive.size) offset = 0;
|
|
209
|
+
const opened = await this.open(source, item, { offset, etag: meta.etag, signal: requestSignal, fetchImpl: this.fetchImpl, spawn: this.spawn });
|
|
210
|
+
if (!opened.resumed) offset = 0;
|
|
211
|
+
await writeFile(metaFile, JSON.stringify({ source: sourceName(source), etag: opened.etag ?? null, integrity: item.archive.integrity }));
|
|
212
|
+
const out = createWriteStream(part, { flags: offset ? 'a' : 'w' });
|
|
213
|
+
const closed = new Promise((resolve, reject) => { out.once('close', resolve); out.once('error', reject); });
|
|
214
|
+
let received = offset;
|
|
215
|
+
try {
|
|
216
|
+
for await (const chunk of this.watch(opened.body, signal, cut, source.idleMs)) {
|
|
217
|
+
received += chunk.length;
|
|
218
|
+
if (received > item.archive.size) throw new SourceError(`${item.archive.file} is larger than ${item.archive.size} bytes`, { code: 'size' });
|
|
219
|
+
if (!out.write(chunk)) await once(out, 'drain');
|
|
220
|
+
this.progress(item, { phase: 'downloading', received, total: item.archive.size });
|
|
221
|
+
}
|
|
222
|
+
} finally { out.end(); await closed.catch(() => {}); }
|
|
223
|
+
if (received !== item.archive.size) throw new SourceError(`${item.archive.file}: got ${received} of ${item.archive.size} bytes`, { code: 'size' });
|
|
224
|
+
this.progress(item, { phase: 'verifying', received, total: item.archive.size });
|
|
225
|
+
const integrity = await hashFile(part, 'sha512');
|
|
226
|
+
if (integrity !== item.archive.integrity) {
|
|
227
|
+
await rm(part, { force: true }); await rm(metaFile, { force: true });
|
|
228
|
+
throw new SourceError(`${item.archive.file}: sha512 does not match the manifest`, { code: 'integrity' });
|
|
229
|
+
}
|
|
230
|
+
await this.install(item, source, createReadStream(part), 'tgz', signal);
|
|
231
|
+
await rm(part, { force: true }); await rm(metaFile, { force: true });
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
/** Passes the body through, failing (and cutting the request off) when no data arrives for `idleMs` (the source's own, if it sets one). */
|
|
235
|
+
async* watch(body, signal, cut = () => {}, idleMs = this.idleMs) {
|
|
236
|
+
const iterator = body[Symbol.asyncIterator]();
|
|
237
|
+
for (;;) {
|
|
238
|
+
let timer;
|
|
239
|
+
const idle = new Promise((_, reject) => { timer = setTimeout(() => { const error = new SourceError(`no data for ${idleMs / 1000} s`, { code: 'timeout' }); cut(error); reject(error); }, idleMs); });
|
|
240
|
+
let next;
|
|
241
|
+
try { next = await Promise.race([iterator.next(), idle]); }
|
|
242
|
+
catch (error) {
|
|
243
|
+
// Never awaited: a reader stuck in a pending read would hold this attempt forever.
|
|
244
|
+
iterator.return?.()?.catch?.(() => {});
|
|
245
|
+
throw signal?.aborted ? signal.reason : error;
|
|
246
|
+
} finally { clearTimeout(timer); }
|
|
247
|
+
if (next.done) return;
|
|
248
|
+
signal?.throwIfAborted();
|
|
249
|
+
yield next.value;
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
/** Unpacks into a sibling temporary directory, checks every file, prepares it, then renames it into place. */
|
|
254
|
+
async install(item, source, stream, format, signal) {
|
|
255
|
+
const parent = dirname(item.dir);
|
|
256
|
+
await mkdir(parent, { recursive: true });
|
|
257
|
+
const tmp = join(parent, `.${basename(item.dir)}.tmp-${randomUUID()}`);
|
|
258
|
+
try {
|
|
259
|
+
this.progress(item, { phase: 'unpacking' });
|
|
260
|
+
// `strip` is the archive's prefix.
|
|
261
|
+
const strip = item.strip ?? '';
|
|
262
|
+
const { files } = await extractTar(stream, tmp, { gzip: format === 'tgz', strip, outside: item.outside ?? 'reject' });
|
|
263
|
+
signal?.throwIfAborted();
|
|
264
|
+
const problems = fileProblems(item.files, files);
|
|
265
|
+
if (problems.length) throw new SourceError(`${item.label ?? item.key} does not match the manifest: ${problems.slice(0, 5).join(', ')}${problems.length > 5 ? ` and ${problems.length - 5} more` : ''}`, { code: 'integrity' });
|
|
266
|
+
if (item.prepare) await item.prepare(tmp, { bundled: false });
|
|
267
|
+
await writeFile(join(tmp, COMPLETE), JSON.stringify({ marker: markerOf(item), source: sourceName(source), at: new Date(this.now()).toISOString() }));
|
|
268
|
+
// A leftover incomplete directory (an interrupted run before this layout) is moved aside first.
|
|
269
|
+
if (existsSync(item.dir)) {
|
|
270
|
+
const aside = join(parent, `.${basename(item.dir)}.old-${randomUUID()}`);
|
|
271
|
+
await this.retryRename(item.dir, aside);
|
|
272
|
+
await rm(aside, { recursive: true, force: true }).catch(() => {});
|
|
273
|
+
}
|
|
274
|
+
await this.retryRename(tmp, item.dir);
|
|
275
|
+
} catch (error) {
|
|
276
|
+
await rm(tmp, { recursive: true, force: true }).catch(() => {});
|
|
277
|
+
throw error;
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
/** Windows: a freshly written exe is often held briefly by Defender or the indexer (EPERM/EBUSY/EACCES). */
|
|
282
|
+
async retryRename(from, to) {
|
|
283
|
+
for (let attempt = 0; ; attempt++) {
|
|
284
|
+
try { return await rename(from, to); }
|
|
285
|
+
catch (error) {
|
|
286
|
+
if (!['EPERM', 'EBUSY', 'EACCES'].includes(error?.code) || attempt >= this.renameDelaysMs.length) throw error;
|
|
287
|
+
await sleep(this.renameDelaysMs[attempt]);
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
readState() { try { return JSON.parse(readFileSync(this.stateFile, 'utf8')); } catch { return { items: {} }; } }
|
|
293
|
+
/** Records use (and the last error) per item key; best effort, never fatal. */
|
|
294
|
+
async touch(item, fields = {}, { used = true } = {}) {
|
|
295
|
+
try {
|
|
296
|
+
await mkdir(this.root, { recursive: true });
|
|
297
|
+
const state = this.readState();
|
|
298
|
+
state.items ??= {};
|
|
299
|
+
const previous = state.items[item.key] ?? {};
|
|
300
|
+
state.items[item.key] = { ...previous, dir: item.dir, ...used && { lastUsed: this.now() }, ...fields };
|
|
301
|
+
if (fields.lastError === null) delete state.items[item.key].lastError;
|
|
302
|
+
const tmp = `${this.stateFile}.${randomUUID()}.tmp`;
|
|
303
|
+
await writeFile(tmp, JSON.stringify(state, null, 2));
|
|
304
|
+
await rename(tmp, this.stateFile);
|
|
305
|
+
} catch (error) { this.log('debug', `state.json not written: ${error?.message}`); }
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
/** The last failure recorded for `key`, if any. */
|
|
309
|
+
lastError(key) { return this.readState().items?.[key]?.lastError ?? undefined; }
|
|
310
|
+
|
|
311
|
+
/**
|
|
312
|
+
* Removes item directories under `dirs` that are not kept: `keep(dir)` true, used within `maxAgeMs`, or locked.
|
|
313
|
+
* Returns the removed directories. A directory that cannot be removed (Windows: in use) is left for next time.
|
|
314
|
+
*/
|
|
315
|
+
async prune({ dirs, keep = () => false, maxAgeMs = 30 * 24 * 3600_000 }) {
|
|
316
|
+
const state = this.readState();
|
|
317
|
+
const lastUsed = new Map(Object.values(state.items ?? {}).filter(entry => entry?.dir).map(entry => [entry.dir, entry.lastUsed ?? 0]));
|
|
318
|
+
const removed = [];
|
|
319
|
+
for (const dir of dirs) {
|
|
320
|
+
if (keep(dir)) continue;
|
|
321
|
+
if (this.now() - (lastUsed.get(dir) ?? 0) < maxAgeMs) continue;
|
|
322
|
+
try { await rm(dir, { recursive: true, force: true }); removed.push(dir); } catch (error) { this.log('debug', `kept ${dir}: ${error?.message}`); }
|
|
323
|
+
}
|
|
324
|
+
return removed;
|
|
325
|
+
}
|
|
326
|
+
}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { randomUUID } from 'node:crypto';
|
|
2
|
+
import { closeSync, linkSync, mkdirSync, openSync, readFileSync, renameSync, rmSync, statSync, utimesSync, writeSync } from 'node:fs';
|
|
3
|
+
import { dirname } from 'node:path';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* A lock file held as a lease (spec 261110-universal-package §4.2 `.lock`): created with O_EXCL and holding
|
|
7
|
+
* `<pid>:<holder uuid>` (one DSH process may run several profiles' copies of the plugin, so the pid alone does not tell
|
|
8
|
+
* holders apart). The holder touches it every `renewMs`; one not touched for `staleMs` is stale whoever wrote it, and is
|
|
9
|
+
* taken over by renaming it aside and creating a new one, then reading it back to be sure the new one is ours.
|
|
10
|
+
*/
|
|
11
|
+
export const RENEW_MS = 10_000;
|
|
12
|
+
export const STALE_MS = 60_000;
|
|
13
|
+
|
|
14
|
+
export class LeaseBusy extends Error {
|
|
15
|
+
constructor(file, holder) { super(`${file} is held by ${holder}`); this.name = 'LeaseBusy'; this.code = 'busy'; this.holder = holder; }
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function create(file, mine) {
|
|
19
|
+
const fd = openSync(file, 'wx', 0o600);
|
|
20
|
+
try { writeSync(fd, mine); } finally { closeSync(fd); }
|
|
21
|
+
}
|
|
22
|
+
const read = file => { try { return readFileSync(file, 'utf8'); } catch { return undefined; } };
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Takes the lease or throws LeaseBusy. Returns `{ release, holder }`; the lease renews itself until released.
|
|
26
|
+
* `now`/`setInterval` are injectable for tests.
|
|
27
|
+
*/
|
|
28
|
+
export function acquireLease(file, { holder = randomUUID(), staleMs = STALE_MS, renewMs = RENEW_MS, now = Date.now, timers = { setInterval, clearInterval }, beforeTakeover = () => {} } = {}) {
|
|
29
|
+
mkdirSync(dirname(file), { recursive: true });
|
|
30
|
+
const mine = `${process.pid}:${holder}`;
|
|
31
|
+
try { create(file, mine); }
|
|
32
|
+
catch (error) {
|
|
33
|
+
if (error?.code !== 'EEXIST') throw error;
|
|
34
|
+
let age = 0;
|
|
35
|
+
try { age = now() - statSync(file).mtimeMs; } catch { /* vanished: try again below */ }
|
|
36
|
+
const stale = read(file);
|
|
37
|
+
if (age < staleMs && stale !== undefined) throw new LeaseBusy(file, stale);
|
|
38
|
+
// Stale: move it aside (only one taker wins the rename of this exact file), then create ours. What was moved must be
|
|
39
|
+
// the lease judged stale: another taker may have replaced it in between, and then it goes back and this one waits.
|
|
40
|
+
const aside = `${file}.stale-${randomUUID()}`;
|
|
41
|
+
beforeTakeover();
|
|
42
|
+
let moved = false;
|
|
43
|
+
try { renameSync(file, aside); moved = true; } catch { /* another taker moved it first */ }
|
|
44
|
+
if (moved) {
|
|
45
|
+
let fresh = false;
|
|
46
|
+
try { fresh = readFileSync(aside, 'utf8') !== stale || now() - statSync(aside).mtimeMs < staleMs; } catch {}
|
|
47
|
+
if (fresh) {
|
|
48
|
+
// link, not rename: never overwrite a lease someone created meanwhile.
|
|
49
|
+
try { linkSync(aside, file); } catch { /* a newer lease is there */ }
|
|
50
|
+
rmSync(aside, { force: true });
|
|
51
|
+
throw new LeaseBusy(file, read(file));
|
|
52
|
+
}
|
|
53
|
+
rmSync(aside, { force: true });
|
|
54
|
+
}
|
|
55
|
+
try { create(file, mine); } catch (again) { if (again?.code === 'EEXIST') throw new LeaseBusy(file, read(file)); throw again; }
|
|
56
|
+
}
|
|
57
|
+
if (read(file) !== mine) throw new LeaseBusy(file, read(file));
|
|
58
|
+
const timer = timers.setInterval(() => { try { if (read(file) === mine) { const t = new Date(now()); utimesSync(file, t, t); } } catch { /* the next renewal tries again */ } }, renewMs);
|
|
59
|
+
timer?.unref?.();
|
|
60
|
+
let released = false;
|
|
61
|
+
return {
|
|
62
|
+
holder: mine,
|
|
63
|
+
release() {
|
|
64
|
+
if (released) return;
|
|
65
|
+
released = true;
|
|
66
|
+
timers.clearInterval(timer);
|
|
67
|
+
if (read(file) === mine) rmSync(file, { force: true });
|
|
68
|
+
},
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/** Waits for the lease, polling every `pollMs`, until `signal` aborts or `timeoutMs` passes. */
|
|
73
|
+
export async function waitForLease(file, { signal, pollMs = 1000, timeoutMs = Infinity, onWait = () => {}, ...options } = {}) {
|
|
74
|
+
const started = Date.now();
|
|
75
|
+
for (;;) {
|
|
76
|
+
try { return acquireLease(file, options); }
|
|
77
|
+
catch (error) {
|
|
78
|
+
if (!(error instanceof LeaseBusy)) throw error;
|
|
79
|
+
if (Date.now() - started > timeoutMs) throw error;
|
|
80
|
+
onWait(error.holder);
|
|
81
|
+
}
|
|
82
|
+
signal?.throwIfAborted();
|
|
83
|
+
await new Promise((resolve, reject) => {
|
|
84
|
+
const timer = setTimeout(resolve, pollMs);
|
|
85
|
+
signal?.addEventListener('abort', () => { clearTimeout(timer); reject(signal.reason); }, { once: true });
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
}
|