@kubohiroya/sb3-toolchain 0.1.0
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 +373 -0
- package/README.md +187 -0
- package/bin/sb3-toolchain.mjs +9 -0
- package/docs/extension-id-migration.md +59 -0
- package/docs/source-format-v1.md +119 -0
- package/package.json +62 -0
- package/src/archive.js +35 -0
- package/src/build.js +151 -0
- package/src/cli.js +465 -0
- package/src/constants.js +4 -0
- package/src/extension-dependencies.js +86 -0
- package/src/extension-id-migration.js +425 -0
- package/src/extension-sync.js +496 -0
- package/src/import.js +381 -0
- package/src/index.js +34 -0
- package/src/output-safety.js +322 -0
- package/src/source.js +386 -0
|
@@ -0,0 +1,496 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MPL-2.0
|
|
2
|
+
|
|
3
|
+
import {cp, lstat, mkdtemp, readFile, rm, writeFile} from 'node:fs/promises';
|
|
4
|
+
import path from 'node:path';
|
|
5
|
+
|
|
6
|
+
import {
|
|
7
|
+
extensionHeaderId,
|
|
8
|
+
extensionIntegrity,
|
|
9
|
+
validateExtensionSourceMetadata,
|
|
10
|
+
validateManagedExtensionContents,
|
|
11
|
+
} from './extension-dependencies.js';
|
|
12
|
+
import {rewriteExtensionIdDocuments, validateNewExtensionId} from './extension-id-migration.js';
|
|
13
|
+
import {
|
|
14
|
+
assertNoInterruptedRollback,
|
|
15
|
+
compareDirectories,
|
|
16
|
+
pathExists,
|
|
17
|
+
replaceDirectoryTransactionally,
|
|
18
|
+
} from './output-safety.js';
|
|
19
|
+
import {
|
|
20
|
+
createDeterministicSb3,
|
|
21
|
+
inspectSb3SourceForExtensionSync,
|
|
22
|
+
validateSb3Source,
|
|
23
|
+
} from './source.js';
|
|
24
|
+
|
|
25
|
+
export const defaultExtensionArtifactSizeLimit = 5 * 1024 * 1024;
|
|
26
|
+
const githubApiResponseSizeLimit = 1024 * 1024;
|
|
27
|
+
|
|
28
|
+
function assert(condition, message) {
|
|
29
|
+
if (!condition) {
|
|
30
|
+
throw new Error(message);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function assertFetch(fetchImplementation) {
|
|
35
|
+
assert(
|
|
36
|
+
typeof fetchImplementation === 'function',
|
|
37
|
+
'A Fetch API implementation is required for GitHub extension operations.',
|
|
38
|
+
);
|
|
39
|
+
return fetchImplementation;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function githubHeaders(accept) {
|
|
43
|
+
return {
|
|
44
|
+
Accept: accept,
|
|
45
|
+
'User-Agent': 'sb3-toolchain',
|
|
46
|
+
'X-GitHub-Api-Version': '2022-11-28',
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function rawArtifactUrl(source, commit) {
|
|
51
|
+
const artifact = source.artifact
|
|
52
|
+
.split('/')
|
|
53
|
+
.map((segment) => encodeURIComponent(segment))
|
|
54
|
+
.join('/');
|
|
55
|
+
return `https://raw.githubusercontent.com/${source.repository}/${commit}/${artifact}`;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function githubCommitUrl(source) {
|
|
59
|
+
return (
|
|
60
|
+
`https://api.github.com/repos/${source.repository}/commits/` + encodeURIComponent(source.ref)
|
|
61
|
+
);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
async function readLimitedResponse(response, maximumBytes, description) {
|
|
65
|
+
const contentLength = response.headers?.get?.('content-length');
|
|
66
|
+
if (contentLength !== null && contentLength !== undefined) {
|
|
67
|
+
const parsedLength = Number(contentLength);
|
|
68
|
+
assert(
|
|
69
|
+
Number.isSafeInteger(parsedLength) && parsedLength >= 0,
|
|
70
|
+
`${description} returned an invalid Content-Length.`,
|
|
71
|
+
);
|
|
72
|
+
assert(parsedLength <= maximumBytes, `${description} exceeds the ${maximumBytes}-byte limit.`);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
if (!response.body?.getReader) {
|
|
76
|
+
const contents = Buffer.from(await response.arrayBuffer());
|
|
77
|
+
assert(
|
|
78
|
+
contents.length <= maximumBytes,
|
|
79
|
+
`${description} exceeds the ${maximumBytes}-byte limit.`,
|
|
80
|
+
);
|
|
81
|
+
return contents;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
const reader = response.body.getReader();
|
|
85
|
+
const chunks = [];
|
|
86
|
+
let totalLength = 0;
|
|
87
|
+
try {
|
|
88
|
+
while (true) {
|
|
89
|
+
const {done, value} = await reader.read();
|
|
90
|
+
if (done) break;
|
|
91
|
+
totalLength += value.byteLength;
|
|
92
|
+
assert(totalLength <= maximumBytes, `${description} exceeds the ${maximumBytes}-byte limit.`);
|
|
93
|
+
chunks.push(Buffer.from(value));
|
|
94
|
+
}
|
|
95
|
+
} catch (error) {
|
|
96
|
+
await reader.cancel(error).catch(() => {});
|
|
97
|
+
throw error;
|
|
98
|
+
}
|
|
99
|
+
return Buffer.concat(chunks, totalLength);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
async function fetchBytes(fetchImplementation, url, maximumBytes, description, accept) {
|
|
103
|
+
const parsedUrl = new URL(url);
|
|
104
|
+
assert(parsedUrl.protocol === 'https:', `${description} requires HTTPS.`);
|
|
105
|
+
let response;
|
|
106
|
+
try {
|
|
107
|
+
response = await fetchImplementation(url, {
|
|
108
|
+
headers: githubHeaders(accept),
|
|
109
|
+
redirect: 'error',
|
|
110
|
+
});
|
|
111
|
+
} catch (error) {
|
|
112
|
+
throw new Error(`${description} request failed: ${error.message}`, {cause: error});
|
|
113
|
+
}
|
|
114
|
+
assert(
|
|
115
|
+
response && typeof response === 'object',
|
|
116
|
+
`${description} request returned an invalid response.`,
|
|
117
|
+
);
|
|
118
|
+
assert(
|
|
119
|
+
response.redirected !== true &&
|
|
120
|
+
(!response.url || new URL(response.url).href === parsedUrl.href),
|
|
121
|
+
`${description} refused a redirected response.`,
|
|
122
|
+
);
|
|
123
|
+
assert(response.ok, `${description} request failed with HTTP ${response.status ?? '(unknown)'}.`);
|
|
124
|
+
return readLimitedResponse(response, maximumBytes, description);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
async function resolveGithubCommit(extension, fetchImplementation) {
|
|
128
|
+
const source = extension.source;
|
|
129
|
+
if (/^[a-f0-9]{40}$/u.test(source.ref)) {
|
|
130
|
+
return source.ref;
|
|
131
|
+
}
|
|
132
|
+
const contents = await fetchBytes(
|
|
133
|
+
fetchImplementation,
|
|
134
|
+
githubCommitUrl(source),
|
|
135
|
+
githubApiResponseSizeLimit,
|
|
136
|
+
`GitHub ref lookup for ${extension.id}`,
|
|
137
|
+
'application/vnd.github+json',
|
|
138
|
+
);
|
|
139
|
+
let response;
|
|
140
|
+
try {
|
|
141
|
+
response = JSON.parse(contents.toString('utf8'));
|
|
142
|
+
} catch (error) {
|
|
143
|
+
throw new Error(`GitHub ref lookup for ${extension.id} returned invalid JSON.`, {cause: error});
|
|
144
|
+
}
|
|
145
|
+
assert(
|
|
146
|
+
typeof response?.sha === 'string' && /^[a-f0-9]{40}$/u.test(response.sha),
|
|
147
|
+
`GitHub ref lookup for ${extension.id} returned an invalid commit SHA.`,
|
|
148
|
+
);
|
|
149
|
+
return response.sha;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
async function downloadExtension(
|
|
153
|
+
extension,
|
|
154
|
+
commit,
|
|
155
|
+
fetchImplementation,
|
|
156
|
+
maximumArtifactBytes,
|
|
157
|
+
expectedId = extension.id,
|
|
158
|
+
) {
|
|
159
|
+
const contents = await fetchBytes(
|
|
160
|
+
fetchImplementation,
|
|
161
|
+
rawArtifactUrl(extension.source, commit),
|
|
162
|
+
maximumArtifactBytes,
|
|
163
|
+
`GitHub artifact download for ${extension.id}`,
|
|
164
|
+
'application/javascript, text/javascript;q=0.9, */*;q=0.1',
|
|
165
|
+
);
|
|
166
|
+
const actualId = extensionHeaderId(contents);
|
|
167
|
+
assert(
|
|
168
|
+
actualId === expectedId,
|
|
169
|
+
`Downloaded extension header ID mismatch for ${extension.id}: ` +
|
|
170
|
+
`expected ${expectedId}, got ${actualId ?? '(missing)'}`,
|
|
171
|
+
);
|
|
172
|
+
return contents;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
function managedExtensions(source) {
|
|
176
|
+
return source.extensions.filter((extension) => extension.source !== undefined);
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
async function inspectExtensionSource(sourceDirectory, {willReplace = false} = {}) {
|
|
180
|
+
const resolvedSourceDirectory = path.resolve(sourceDirectory);
|
|
181
|
+
if (willReplace) {
|
|
182
|
+
assert(
|
|
183
|
+
resolvedSourceDirectory !== path.parse(resolvedSourceDirectory).root,
|
|
184
|
+
'Refusing to replace a filesystem root during extension synchronization.',
|
|
185
|
+
);
|
|
186
|
+
assert(
|
|
187
|
+
!(await pathExists(path.join(resolvedSourceDirectory, '.git'))),
|
|
188
|
+
'Refusing to replace a Git repository root during extension synchronization.',
|
|
189
|
+
);
|
|
190
|
+
}
|
|
191
|
+
const stats = await lstat(resolvedSourceDirectory);
|
|
192
|
+
assert(
|
|
193
|
+
stats.isDirectory() && !stats.isSymbolicLink(),
|
|
194
|
+
`SB3 source must be a directory, not a file or symbolic link: ${resolvedSourceDirectory}`,
|
|
195
|
+
);
|
|
196
|
+
if (willReplace) {
|
|
197
|
+
await assertNoInterruptedRollback(resolvedSourceDirectory);
|
|
198
|
+
}
|
|
199
|
+
return inspectSb3SourceForExtensionSync(resolvedSourceDirectory);
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
async function installCandidate({
|
|
203
|
+
candidateDirectory,
|
|
204
|
+
confirmReplace,
|
|
205
|
+
initialSourceFingerprint,
|
|
206
|
+
sourceDirectory,
|
|
207
|
+
yes,
|
|
208
|
+
}) {
|
|
209
|
+
const comparison = await compareDirectories(sourceDirectory, candidateDirectory);
|
|
210
|
+
assert(
|
|
211
|
+
comparison.existingFingerprint === initialSourceFingerprint,
|
|
212
|
+
'SB3 source changed while extension artifacts were being fetched; refusing to replace it.',
|
|
213
|
+
);
|
|
214
|
+
if (comparison.identical) {
|
|
215
|
+
await rm(candidateDirectory, {recursive: true, force: true});
|
|
216
|
+
return {changed: false, comparison, rollbackCleanupWarning: null};
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
const context = {comparison, sourceDirectory};
|
|
220
|
+
if (!yes) {
|
|
221
|
+
assert(
|
|
222
|
+
typeof confirmReplace === 'function',
|
|
223
|
+
`Managed extension files differ in ${sourceDirectory}. ` +
|
|
224
|
+
'Non-interactive replacement requires --yes.',
|
|
225
|
+
);
|
|
226
|
+
assert(
|
|
227
|
+
await confirmReplace(context),
|
|
228
|
+
'Extension synchronization cancelled; the existing source was not changed.',
|
|
229
|
+
);
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
const latestComparison = await compareDirectories(sourceDirectory, candidateDirectory);
|
|
233
|
+
assert(
|
|
234
|
+
latestComparison.existingFingerprint === comparison.existingFingerprint &&
|
|
235
|
+
latestComparison.candidateFingerprint === comparison.candidateFingerprint,
|
|
236
|
+
'SB3 source or extension candidate changed during synchronization; refusing to replace it.',
|
|
237
|
+
);
|
|
238
|
+
const replacement = await replaceDirectoryTransactionally(candidateDirectory, sourceDirectory);
|
|
239
|
+
return {changed: true, comparison, ...replacement};
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
async function updateCandidate({
|
|
243
|
+
confirmReplace,
|
|
244
|
+
fetchImplementation,
|
|
245
|
+
maximumArtifactBytes,
|
|
246
|
+
migrateToId,
|
|
247
|
+
mode,
|
|
248
|
+
selectedExtensionId,
|
|
249
|
+
sourceArtifact,
|
|
250
|
+
sourceDirectory,
|
|
251
|
+
yes,
|
|
252
|
+
}) {
|
|
253
|
+
assert(
|
|
254
|
+
Number.isSafeInteger(maximumArtifactBytes) && maximumArtifactBytes > 0,
|
|
255
|
+
'maximumArtifactBytes must be a positive integer.',
|
|
256
|
+
);
|
|
257
|
+
const source = await inspectExtensionSource(sourceDirectory, {willReplace: true});
|
|
258
|
+
const initialComparison = await compareDirectories(
|
|
259
|
+
source.resolvedSourceDirectory,
|
|
260
|
+
source.resolvedSourceDirectory,
|
|
261
|
+
);
|
|
262
|
+
assert(
|
|
263
|
+
initialComparison.identical &&
|
|
264
|
+
initialComparison.existingFingerprint === initialComparison.candidateFingerprint,
|
|
265
|
+
'SB3 source changed while its initial state was being inspected.',
|
|
266
|
+
);
|
|
267
|
+
const managed = managedExtensions(source);
|
|
268
|
+
assert(managed.length > 0, 'No managed embedded extensions were found.');
|
|
269
|
+
if (selectedExtensionId !== undefined) {
|
|
270
|
+
assert(
|
|
271
|
+
managed.some((extension) => extension.id === selectedExtensionId),
|
|
272
|
+
`Managed extension was not found: ${selectedExtensionId}`,
|
|
273
|
+
);
|
|
274
|
+
}
|
|
275
|
+
if (migrateToId !== undefined) {
|
|
276
|
+
assert(mode === 'update', 'Extension ID migration is only available during update.');
|
|
277
|
+
assert(
|
|
278
|
+
selectedExtensionId !== undefined,
|
|
279
|
+
'Extension ID migration requires an explicit existing extension ID.',
|
|
280
|
+
);
|
|
281
|
+
validateNewExtensionId(migrateToId);
|
|
282
|
+
}
|
|
283
|
+
assert(
|
|
284
|
+
sourceArtifact === undefined || migrateToId !== undefined,
|
|
285
|
+
'A replacement artifact path requires an extension ID migration.',
|
|
286
|
+
);
|
|
287
|
+
const selected = managed.filter(
|
|
288
|
+
(extension) => selectedExtensionId === undefined || extension.id === selectedExtensionId,
|
|
289
|
+
);
|
|
290
|
+
if (migrateToId !== undefined) {
|
|
291
|
+
const extensionManifest = JSON.parse(
|
|
292
|
+
await readFile(
|
|
293
|
+
path.join(source.resolvedSourceDirectory, source.sourceManifest.embeddedExtensions),
|
|
294
|
+
'utf8',
|
|
295
|
+
),
|
|
296
|
+
);
|
|
297
|
+
rewriteExtensionIdDocuments({
|
|
298
|
+
extensionManifest,
|
|
299
|
+
newId: migrateToId,
|
|
300
|
+
oldId: selectedExtensionId,
|
|
301
|
+
project: source.project,
|
|
302
|
+
sourceArtifact,
|
|
303
|
+
});
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
const downloads = await Promise.all(
|
|
307
|
+
selected.map(async (extension) => {
|
|
308
|
+
const effectiveExtension =
|
|
309
|
+
sourceArtifact === undefined
|
|
310
|
+
? extension
|
|
311
|
+
: {
|
|
312
|
+
...extension,
|
|
313
|
+
source: {...extension.source, artifact: sourceArtifact},
|
|
314
|
+
};
|
|
315
|
+
validateExtensionSourceMetadata(effectiveExtension);
|
|
316
|
+
const commit =
|
|
317
|
+
mode === 'sync'
|
|
318
|
+
? extension.source.resolvedCommit
|
|
319
|
+
: await resolveGithubCommit(extension, fetchImplementation);
|
|
320
|
+
const contents = await downloadExtension(
|
|
321
|
+
effectiveExtension,
|
|
322
|
+
commit,
|
|
323
|
+
fetchImplementation,
|
|
324
|
+
maximumArtifactBytes,
|
|
325
|
+
migrateToId ?? extension.id,
|
|
326
|
+
);
|
|
327
|
+
if (mode === 'sync') {
|
|
328
|
+
validateManagedExtensionContents(extension, contents);
|
|
329
|
+
}
|
|
330
|
+
return {commit, contents, effectiveExtension, extension};
|
|
331
|
+
}),
|
|
332
|
+
);
|
|
333
|
+
|
|
334
|
+
const parentDirectory = path.dirname(source.resolvedSourceDirectory);
|
|
335
|
+
const candidateDirectory = await mkdtemp(
|
|
336
|
+
path.join(parentDirectory, `.${path.basename(source.resolvedSourceDirectory)}.extensions-`),
|
|
337
|
+
);
|
|
338
|
+
let installed = false;
|
|
339
|
+
try {
|
|
340
|
+
await cp(source.resolvedSourceDirectory, candidateDirectory, {
|
|
341
|
+
preserveTimestamps: true,
|
|
342
|
+
recursive: true,
|
|
343
|
+
verbatimSymlinks: true,
|
|
344
|
+
});
|
|
345
|
+
const manifestPath = path.join(candidateDirectory, source.sourceManifest.embeddedExtensions);
|
|
346
|
+
const manifest = JSON.parse(await readFile(manifestPath, 'utf8'));
|
|
347
|
+
const projectPath = path.join(candidateDirectory, source.sourceManifest.project);
|
|
348
|
+
const entriesById = new Map(manifest.extensions.map((extension) => [extension.id, extension]));
|
|
349
|
+
let manifestChanged = false;
|
|
350
|
+
let migration;
|
|
351
|
+
for (const {commit, contents, effectiveExtension, extension} of downloads) {
|
|
352
|
+
if (migrateToId !== undefined) {
|
|
353
|
+
const project = JSON.parse(await readFile(projectPath, 'utf8'));
|
|
354
|
+
migration = rewriteExtensionIdDocuments({
|
|
355
|
+
extensionManifest: manifest,
|
|
356
|
+
newId: migrateToId,
|
|
357
|
+
oldId: extension.id,
|
|
358
|
+
project,
|
|
359
|
+
sourceArtifact: effectiveExtension.source.artifact,
|
|
360
|
+
});
|
|
361
|
+
const migratedExtension = migration.extensionManifest.extensions[migration.extensionIndex];
|
|
362
|
+
migratedExtension.source.resolvedCommit = commit;
|
|
363
|
+
migratedExtension.source.integrity = extensionIntegrity(contents);
|
|
364
|
+
await Promise.all([
|
|
365
|
+
writeFile(projectPath, `${JSON.stringify(migration.project, null, 2)}\n`),
|
|
366
|
+
writeFile(manifestPath, `${JSON.stringify(migration.extensionManifest, null, 2)}\n`),
|
|
367
|
+
writeFile(path.join(candidateDirectory, migration.newPath), contents),
|
|
368
|
+
]);
|
|
369
|
+
await rm(path.join(candidateDirectory, migration.oldPath));
|
|
370
|
+
continue;
|
|
371
|
+
}
|
|
372
|
+
await writeFile(path.join(candidateDirectory, extension.path), contents);
|
|
373
|
+
if (mode === 'update') {
|
|
374
|
+
const candidateExtension = entriesById.get(extension.id);
|
|
375
|
+
assert(candidateExtension, `Extension manifest entry disappeared: ${extension.id}`);
|
|
376
|
+
const integrity = extensionIntegrity(contents);
|
|
377
|
+
manifestChanged =
|
|
378
|
+
manifestChanged ||
|
|
379
|
+
candidateExtension.source.resolvedCommit !== commit ||
|
|
380
|
+
candidateExtension.source.integrity !== integrity;
|
|
381
|
+
candidateExtension.source.resolvedCommit = commit;
|
|
382
|
+
candidateExtension.source.integrity = integrity;
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
if (manifestChanged && migrateToId === undefined) {
|
|
386
|
+
await writeFile(manifestPath, `${JSON.stringify(manifest, null, 2)}\n`);
|
|
387
|
+
}
|
|
388
|
+
if (migration) {
|
|
389
|
+
await createDeterministicSb3(candidateDirectory);
|
|
390
|
+
} else {
|
|
391
|
+
await validateSb3Source(candidateDirectory);
|
|
392
|
+
}
|
|
393
|
+
const result = await installCandidate({
|
|
394
|
+
candidateDirectory,
|
|
395
|
+
confirmReplace,
|
|
396
|
+
initialSourceFingerprint: initialComparison.existingFingerprint,
|
|
397
|
+
sourceDirectory: source.resolvedSourceDirectory,
|
|
398
|
+
yes,
|
|
399
|
+
});
|
|
400
|
+
installed = true;
|
|
401
|
+
return {
|
|
402
|
+
...result,
|
|
403
|
+
extensions: downloads.map(({commit, extension}) => ({
|
|
404
|
+
id: migrateToId ?? extension.id,
|
|
405
|
+
previousId: migrateToId === undefined ? undefined : extension.id,
|
|
406
|
+
resolvedCommit: commit,
|
|
407
|
+
})),
|
|
408
|
+
migration:
|
|
409
|
+
migration === undefined
|
|
410
|
+
? null
|
|
411
|
+
: {
|
|
412
|
+
counts: migration.counts,
|
|
413
|
+
fromId: selectedExtensionId,
|
|
414
|
+
toId: migrateToId,
|
|
415
|
+
totalChanges: migration.totalChanges,
|
|
416
|
+
unclassifiedReferences: migration.unclassifiedReferences,
|
|
417
|
+
},
|
|
418
|
+
mode,
|
|
419
|
+
sourceDirectory: source.resolvedSourceDirectory,
|
|
420
|
+
};
|
|
421
|
+
} finally {
|
|
422
|
+
if (!installed) {
|
|
423
|
+
await rm(candidateDirectory, {recursive: true, force: true});
|
|
424
|
+
}
|
|
425
|
+
}
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
export async function extensionStatus(
|
|
429
|
+
sourceDirectory,
|
|
430
|
+
{fetch: fetchImplementation = globalThis.fetch} = {},
|
|
431
|
+
) {
|
|
432
|
+
const source = await inspectExtensionSource(sourceDirectory);
|
|
433
|
+
const fetchFunction = assertFetch(fetchImplementation);
|
|
434
|
+
return Promise.all(
|
|
435
|
+
managedExtensions(source).map(async (extension) => {
|
|
436
|
+
const remoteCommit = await resolveGithubCommit(extension, fetchFunction);
|
|
437
|
+
let local = 'valid';
|
|
438
|
+
try {
|
|
439
|
+
validateManagedExtensionContents(extension, source.extensionContents.get(extension.id));
|
|
440
|
+
} catch {
|
|
441
|
+
local = 'modified';
|
|
442
|
+
}
|
|
443
|
+
return {
|
|
444
|
+
id: extension.id,
|
|
445
|
+
local,
|
|
446
|
+
ref: extension.source.ref,
|
|
447
|
+
remoteCommit,
|
|
448
|
+
resolvedCommit: extension.source.resolvedCommit,
|
|
449
|
+
state: remoteCommit === extension.source.resolvedCommit ? 'current' : 'update-available',
|
|
450
|
+
};
|
|
451
|
+
}),
|
|
452
|
+
);
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
export async function syncExtensions({
|
|
456
|
+
confirmReplace,
|
|
457
|
+
fetch: fetchImplementation = globalThis.fetch,
|
|
458
|
+
maximumArtifactBytes = defaultExtensionArtifactSizeLimit,
|
|
459
|
+
sourceDirectory,
|
|
460
|
+
yes = false,
|
|
461
|
+
}) {
|
|
462
|
+
return updateCandidate({
|
|
463
|
+
confirmReplace,
|
|
464
|
+
fetchImplementation: assertFetch(fetchImplementation),
|
|
465
|
+
maximumArtifactBytes,
|
|
466
|
+
migrateToId: undefined,
|
|
467
|
+
mode: 'sync',
|
|
468
|
+
selectedExtensionId: undefined,
|
|
469
|
+
sourceArtifact: undefined,
|
|
470
|
+
sourceDirectory,
|
|
471
|
+
yes,
|
|
472
|
+
});
|
|
473
|
+
}
|
|
474
|
+
|
|
475
|
+
export async function updateExtensions({
|
|
476
|
+
confirmReplace,
|
|
477
|
+
extensionId,
|
|
478
|
+
fetch: fetchImplementation = globalThis.fetch,
|
|
479
|
+
maximumArtifactBytes = defaultExtensionArtifactSizeLimit,
|
|
480
|
+
migrateToId,
|
|
481
|
+
sourceArtifact,
|
|
482
|
+
sourceDirectory,
|
|
483
|
+
yes = false,
|
|
484
|
+
}) {
|
|
485
|
+
return updateCandidate({
|
|
486
|
+
confirmReplace,
|
|
487
|
+
fetchImplementation: assertFetch(fetchImplementation),
|
|
488
|
+
maximumArtifactBytes,
|
|
489
|
+
migrateToId,
|
|
490
|
+
mode: 'update',
|
|
491
|
+
selectedExtensionId: extensionId,
|
|
492
|
+
sourceArtifact,
|
|
493
|
+
sourceDirectory,
|
|
494
|
+
yes,
|
|
495
|
+
});
|
|
496
|
+
}
|