@kubohiroya/sb3-toolchain 0.10.0 → 0.12.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/CHANGELOG.md +22 -0
- package/README.ja.md +17 -1
- package/README.md +17 -1
- package/dist/archive.d.ts +1 -0
- package/dist/archive.js +16 -0
- package/dist/archive.js.map +1 -0
- package/dist/assert.d.ts +2 -0
- package/dist/assert.js +11 -0
- package/dist/assert.js.map +1 -0
- package/dist/bin.d.ts +1 -0
- package/dist/bin.js +12 -0
- package/dist/bin.js.map +1 -0
- package/dist/build.d.ts +23 -0
- package/dist/build.js +111 -0
- package/dist/build.js.map +1 -0
- package/dist/cli.d.ts +87 -0
- package/dist/cli.js +544 -0
- package/dist/cli.js.map +1 -0
- package/dist/constants.d.ts +2 -0
- package/dist/constants.js +7 -0
- package/dist/constants.js.map +1 -0
- package/dist/extension-api-manifest.d.ts +46 -0
- package/dist/extension-api-manifest.js +211 -0
- package/dist/extension-api-manifest.js.map +1 -0
- package/dist/extension-bundle-archive.d.ts +36 -0
- package/dist/extension-bundle-archive.js +302 -0
- package/dist/extension-bundle-archive.js.map +1 -0
- package/dist/extension-bundle-configuration.d.ts +55 -0
- package/dist/extension-bundle-configuration.js +200 -0
- package/dist/extension-bundle-configuration.js.map +1 -0
- package/dist/extension-bundle.d.ts +39 -0
- package/dist/extension-bundle.js +580 -0
- package/dist/extension-bundle.js.map +1 -0
- package/dist/extension-dependencies.d.ts +18 -0
- package/dist/extension-dependencies.js +59 -0
- package/dist/extension-dependencies.js.map +1 -0
- package/dist/extension-id-migration.d.ts +83 -0
- package/dist/extension-id-migration.js +292 -0
- package/dist/extension-id-migration.js.map +1 -0
- package/dist/extension-sync.d.ts +111 -0
- package/dist/extension-sync.js +463 -0
- package/dist/extension-sync.js.map +1 -0
- package/dist/import.d.ts +39 -0
- package/dist/import.js +244 -0
- package/dist/import.js.map +1 -0
- package/dist/index.d.ts +31 -0
- package/dist/index.js +18 -0
- package/dist/npm-extension-source.d.ts +13 -0
- package/dist/npm-extension-source.js +63 -0
- package/dist/npm-extension-source.js.map +1 -0
- package/dist/output-safety.d.ts +29 -0
- package/dist/output-safety.js +213 -0
- package/dist/output-safety.js.map +1 -0
- package/dist/project-asset-additions.d.ts +29 -0
- package/dist/project-asset-additions.js +412 -0
- package/dist/project-asset-additions.js.map +1 -0
- package/dist/release-snapshot.d.ts +75 -0
- package/dist/release-snapshot.js +177 -0
- package/dist/release-snapshot.js.map +1 -0
- package/dist/source.d.ts +41 -0
- package/dist/source.js +282 -0
- package/dist/source.js.map +1 -0
- package/dist/turbowarp-clean-up.d.ts +18 -0
- package/dist/turbowarp-clean-up.js +266 -0
- package/dist/turbowarp-clean-up.js.map +1 -0
- package/dist/types.d.ts +80 -0
- package/package.json +29 -21
- package/bin/sb3-toolchain.mjs +0 -9
- package/src/archive.js +0 -35
- package/src/build.js +0 -188
- package/src/cli.js +0 -748
- package/src/constants.js +0 -4
- package/src/extension-api-manifest.js +0 -336
- package/src/extension-bundle-archive.js +0 -422
- package/src/extension-bundle-configuration.js +0 -265
- package/src/extension-bundle.js +0 -695
- package/src/extension-dependencies.js +0 -114
- package/src/extension-id-migration.js +0 -496
- package/src/extension-sync.js +0 -754
- package/src/import.js +0 -397
- package/src/index.js +0 -75
- package/src/npm-extension-source.js +0 -111
- package/src/output-safety.js +0 -322
- package/src/project-asset-additions.js +0 -560
- package/src/release-snapshot.js +0 -247
- package/src/source.js +0 -468
- package/src/turbowarp-clean-up.js +0 -295
|
@@ -0,0 +1,463 @@
|
|
|
1
|
+
import { assert, errorMessage } from "./assert.js";
|
|
2
|
+
import { assertNoInterruptedRollback, compareDirectories, pathExists, replaceDirectoryTransactionally } from "./output-safety.js";
|
|
3
|
+
import { compareExtensionApiManifests, defaultExtensionApiManifestSizeLimit, extensionApiManifestIntegrity, formatExtensionApiCompatibilityChanges, parseExtensionApiManifest, validateExtensionApiManifestSourceMetadata, validateManagedExtensionApiManifest } from "./extension-api-manifest.js";
|
|
4
|
+
import { extensionHeaderId, extensionIntegrity, validateExtensionSourceMetadata, validateManagedExtensionContents } from "./extension-dependencies.js";
|
|
5
|
+
import { createDeterministicSb3, inspectSb3SourceForExtensionSync, validateSb3Source } from "./source.js";
|
|
6
|
+
import { rewriteExtensionIdDocuments, validateNewExtensionId } from "./extension-id-migration.js";
|
|
7
|
+
import { readNpmExtensionSource } from "./npm-extension-source.js";
|
|
8
|
+
import path from "node:path";
|
|
9
|
+
import { cp, lstat, mkdtemp, readFile, rm, writeFile } from "node:fs/promises";
|
|
10
|
+
//#region src/extension-sync.ts
|
|
11
|
+
var defaultExtensionArtifactSizeLimit = 5242880;
|
|
12
|
+
var githubApiResponseSizeLimit = 1048576;
|
|
13
|
+
function assertFetch(fetchImplementation) {
|
|
14
|
+
assert(typeof fetchImplementation === "function", "A Fetch API implementation is required for GitHub extension operations.");
|
|
15
|
+
return fetchImplementation;
|
|
16
|
+
}
|
|
17
|
+
function githubHeaders(accept) {
|
|
18
|
+
return {
|
|
19
|
+
Accept: accept,
|
|
20
|
+
"User-Agent": "sb3-toolchain",
|
|
21
|
+
"X-GitHub-Api-Version": "2022-11-28"
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
function rawArtifactUrl(source, commit, artifactPath = source.artifact) {
|
|
25
|
+
const artifact = artifactPath.split("/").map((segment) => encodeURIComponent(segment)).join("/");
|
|
26
|
+
return `https://raw.githubusercontent.com/${source.repository}/${commit}/${artifact}`;
|
|
27
|
+
}
|
|
28
|
+
async function downloadExtensionApiManifest(extension, commit, fetchImplementation, maximumManifestBytes, expectedId = extension.id) {
|
|
29
|
+
const metadata = validateExtensionApiManifestSourceMetadata(extension);
|
|
30
|
+
if (!metadata) return null;
|
|
31
|
+
const contents = await fetchBytes(fetchImplementation, rawArtifactUrl(extension.source, commit, metadata.artifact), maximumManifestBytes, `GitHub extension API manifest download for ${extension.id}`, "application/json");
|
|
32
|
+
return {
|
|
33
|
+
contents,
|
|
34
|
+
manifest: parseExtensionApiManifest(contents, { expectedId })
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
function githubCommitUrl(source) {
|
|
38
|
+
return `https://api.github.com/repos/${source.repository}/commits/` + encodeURIComponent(source.ref);
|
|
39
|
+
}
|
|
40
|
+
async function readLimitedResponse(response, maximumBytes, description) {
|
|
41
|
+
const contentLength = response.headers?.get?.("content-length");
|
|
42
|
+
if (contentLength !== null && contentLength !== void 0) {
|
|
43
|
+
const parsedLength = Number(contentLength);
|
|
44
|
+
assert(Number.isSafeInteger(parsedLength) && parsedLength >= 0, `${description} returned an invalid Content-Length.`);
|
|
45
|
+
assert(parsedLength <= maximumBytes, `${description} exceeds the ${maximumBytes}-byte limit.`);
|
|
46
|
+
}
|
|
47
|
+
if (!response.body?.getReader) {
|
|
48
|
+
const contents = Buffer.from(await response.arrayBuffer());
|
|
49
|
+
assert(contents.length <= maximumBytes, `${description} exceeds the ${maximumBytes}-byte limit.`);
|
|
50
|
+
return contents;
|
|
51
|
+
}
|
|
52
|
+
const reader = response.body.getReader();
|
|
53
|
+
const chunks = [];
|
|
54
|
+
let totalLength = 0;
|
|
55
|
+
try {
|
|
56
|
+
while (true) {
|
|
57
|
+
const { done, value } = await reader.read();
|
|
58
|
+
if (done) break;
|
|
59
|
+
totalLength += value.byteLength;
|
|
60
|
+
assert(totalLength <= maximumBytes, `${description} exceeds the ${maximumBytes}-byte limit.`);
|
|
61
|
+
chunks.push(Buffer.from(value));
|
|
62
|
+
}
|
|
63
|
+
} catch (error) {
|
|
64
|
+
await reader.cancel(error).catch(() => {});
|
|
65
|
+
throw error;
|
|
66
|
+
}
|
|
67
|
+
return Buffer.concat(chunks, totalLength);
|
|
68
|
+
}
|
|
69
|
+
async function fetchBytes(fetchImplementation, url, maximumBytes, description, accept) {
|
|
70
|
+
const parsedUrl = new URL(url);
|
|
71
|
+
assert(parsedUrl.protocol === "https:", `${description} requires HTTPS.`);
|
|
72
|
+
let response;
|
|
73
|
+
try {
|
|
74
|
+
response = await fetchImplementation(url, {
|
|
75
|
+
headers: githubHeaders(accept),
|
|
76
|
+
redirect: "error"
|
|
77
|
+
});
|
|
78
|
+
} catch (error) {
|
|
79
|
+
throw new Error(`${description} request failed: ${errorMessage(error)}`, { cause: error });
|
|
80
|
+
}
|
|
81
|
+
assert(response && typeof response === "object", `${description} request returned an invalid response.`);
|
|
82
|
+
assert(response.redirected !== true && (!response.url || new URL(response.url).href === parsedUrl.href), `${description} refused a redirected response.`);
|
|
83
|
+
assert(response.ok, `${description} request failed with HTTP ${response.status ?? "(unknown)"}.`);
|
|
84
|
+
return readLimitedResponse(response, maximumBytes, description);
|
|
85
|
+
}
|
|
86
|
+
async function resolveGithubCommit(extension, fetchImplementation) {
|
|
87
|
+
const source = extension.source;
|
|
88
|
+
if (/^[a-f0-9]{40}$/u.test(source.ref)) return source.ref;
|
|
89
|
+
const contents = await fetchBytes(fetchImplementation, githubCommitUrl(source), githubApiResponseSizeLimit, `GitHub ref lookup for ${extension.id}`, "application/vnd.github+json");
|
|
90
|
+
let response;
|
|
91
|
+
try {
|
|
92
|
+
response = JSON.parse(contents.toString("utf8"));
|
|
93
|
+
} catch (error) {
|
|
94
|
+
throw new Error(`GitHub ref lookup for ${extension.id} returned invalid JSON.`, { cause: error });
|
|
95
|
+
}
|
|
96
|
+
assert(typeof response?.sha === "string" && /^[a-f0-9]{40}$/u.test(response.sha), `GitHub ref lookup for ${extension.id} returned an invalid commit SHA.`);
|
|
97
|
+
return response.sha;
|
|
98
|
+
}
|
|
99
|
+
async function downloadExtension(extension, commit, fetchImplementation, maximumArtifactBytes, expectedId = extension.id) {
|
|
100
|
+
const contents = await fetchBytes(fetchImplementation, rawArtifactUrl(extension.source, commit), maximumArtifactBytes, `GitHub artifact download for ${extension.id}`, "application/javascript, text/javascript;q=0.9, */*;q=0.1");
|
|
101
|
+
const actualId = extensionHeaderId(contents);
|
|
102
|
+
assert(actualId === expectedId, `Downloaded extension header ID mismatch for ${extension.id}: expected ${expectedId}, got ${actualId ?? "(missing)"}`);
|
|
103
|
+
return contents;
|
|
104
|
+
}
|
|
105
|
+
function managedExtensions(source) {
|
|
106
|
+
return source.extensions.filter((extension) => extension.source !== void 0);
|
|
107
|
+
}
|
|
108
|
+
async function inspectExtensionSource(sourceDirectory, { willReplace = false } = {}) {
|
|
109
|
+
const resolvedSourceDirectory = path.resolve(sourceDirectory);
|
|
110
|
+
if (willReplace) {
|
|
111
|
+
assert(resolvedSourceDirectory !== path.parse(resolvedSourceDirectory).root, "Refusing to replace a filesystem root during extension synchronization.");
|
|
112
|
+
assert(!await pathExists(path.join(resolvedSourceDirectory, ".git")), "Refusing to replace a Git repository root during extension synchronization.");
|
|
113
|
+
}
|
|
114
|
+
const stats = await lstat(resolvedSourceDirectory);
|
|
115
|
+
assert(stats.isDirectory() && !stats.isSymbolicLink(), `SB3 source must be a directory, not a file or symbolic link: ${resolvedSourceDirectory}`);
|
|
116
|
+
if (willReplace) await assertNoInterruptedRollback(resolvedSourceDirectory);
|
|
117
|
+
return inspectSb3SourceForExtensionSync(resolvedSourceDirectory);
|
|
118
|
+
}
|
|
119
|
+
async function installCandidate({ candidateDirectory, confirmReplace, initialSourceFingerprint, sourceDirectory, yes }) {
|
|
120
|
+
const comparison = await compareDirectories(sourceDirectory, candidateDirectory);
|
|
121
|
+
assert(comparison.existingFingerprint === initialSourceFingerprint, "SB3 source changed while extension artifacts were being fetched; refusing to replace it.");
|
|
122
|
+
if (comparison.identical) {
|
|
123
|
+
await rm(candidateDirectory, {
|
|
124
|
+
recursive: true,
|
|
125
|
+
force: true
|
|
126
|
+
});
|
|
127
|
+
return {
|
|
128
|
+
changed: false,
|
|
129
|
+
comparison,
|
|
130
|
+
rollbackCleanupWarning: null
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
const context = {
|
|
134
|
+
comparison,
|
|
135
|
+
sourceDirectory
|
|
136
|
+
};
|
|
137
|
+
if (!yes) {
|
|
138
|
+
assert(typeof confirmReplace === "function", `Managed extension files differ in ${sourceDirectory}. Non-interactive replacement requires --yes.`);
|
|
139
|
+
assert(await confirmReplace(context), "Extension synchronization cancelled; the existing source was not changed.");
|
|
140
|
+
}
|
|
141
|
+
const latestComparison = await compareDirectories(sourceDirectory, candidateDirectory);
|
|
142
|
+
assert(latestComparison.existingFingerprint === comparison.existingFingerprint && latestComparison.candidateFingerprint === comparison.candidateFingerprint, "SB3 source or extension candidate changed during synchronization; refusing to replace it.");
|
|
143
|
+
return {
|
|
144
|
+
changed: true,
|
|
145
|
+
comparison,
|
|
146
|
+
...await replaceDirectoryTransactionally(candidateDirectory, sourceDirectory)
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
async function updateCandidate({ allowBreakingApi, apiManifestArtifact, confirmReplace, fetchImplementation, maximumArtifactBytes, maximumManifestBytes, migrateToId, mode, selectedExtensionId, sourceArtifact, sourceDirectory, yes }) {
|
|
150
|
+
assert(Number.isSafeInteger(maximumArtifactBytes) && maximumArtifactBytes > 0, "maximumArtifactBytes must be a positive integer.");
|
|
151
|
+
assert(Number.isSafeInteger(maximumManifestBytes) && maximumManifestBytes > 0, "maximumManifestBytes must be a positive integer.");
|
|
152
|
+
assert(!allowBreakingApi || yes, "--allow-breaking-api requires --yes.");
|
|
153
|
+
const source = await inspectExtensionSource(sourceDirectory, { willReplace: true });
|
|
154
|
+
const initialComparison = await compareDirectories(source.resolvedSourceDirectory, source.resolvedSourceDirectory);
|
|
155
|
+
assert(initialComparison.identical && initialComparison.existingFingerprint === initialComparison.candidateFingerprint, "SB3 source changed while its initial state was being inspected.");
|
|
156
|
+
const managed = managedExtensions(source);
|
|
157
|
+
assert(managed.length > 0, "No managed embedded extensions were found.");
|
|
158
|
+
if (selectedExtensionId !== void 0) assert(managed.some((extension) => extension.id === selectedExtensionId), `Managed extension was not found: ${selectedExtensionId}`);
|
|
159
|
+
const selected = managed.filter((extension) => selectedExtensionId === void 0 || extension.id === selectedExtensionId);
|
|
160
|
+
if (migrateToId !== void 0) {
|
|
161
|
+
assert(mode === "update", "Extension ID migration is only available during update.");
|
|
162
|
+
assert(selectedExtensionId !== void 0, "Extension ID migration requires an explicit existing extension ID.");
|
|
163
|
+
validateNewExtensionId(migrateToId);
|
|
164
|
+
assert(selected.every((extension) => extension.source?.provider === "github"), "Extension ID migration is not supported for npm-managed extensions.");
|
|
165
|
+
}
|
|
166
|
+
assert(sourceArtifact === void 0 || migrateToId !== void 0, "A replacement artifact path requires an extension ID migration.");
|
|
167
|
+
assert(apiManifestArtifact === void 0 || migrateToId !== void 0, "A replacement API manifest artifact path requires an extension ID migration.");
|
|
168
|
+
if (migrateToId !== void 0) {
|
|
169
|
+
const extensionManifest = JSON.parse(await readFile(path.join(source.resolvedSourceDirectory, source.sourceManifest.embeddedExtensions), "utf8"));
|
|
170
|
+
assert(selectedExtensionId !== void 0, "Extension ID migration requires an extension ID.");
|
|
171
|
+
rewriteExtensionIdDocuments({
|
|
172
|
+
apiManifestArtifact,
|
|
173
|
+
extensionManifest,
|
|
174
|
+
newId: migrateToId,
|
|
175
|
+
oldId: selectedExtensionId,
|
|
176
|
+
project: source.project,
|
|
177
|
+
sourceArtifact
|
|
178
|
+
});
|
|
179
|
+
}
|
|
180
|
+
const downloads = await Promise.all(selected.map(async (extension) => {
|
|
181
|
+
let effectiveExtension = extension;
|
|
182
|
+
if (sourceArtifact !== void 0 || apiManifestArtifact !== void 0) {
|
|
183
|
+
const effectiveSource = { ...extension.source };
|
|
184
|
+
if (sourceArtifact !== void 0) effectiveSource.artifact = sourceArtifact;
|
|
185
|
+
if (apiManifestArtifact !== void 0) {
|
|
186
|
+
assert(effectiveSource.apiManifest, `Extension ${extension.id} has no managed API manifest metadata.`);
|
|
187
|
+
effectiveSource.apiManifest = {
|
|
188
|
+
...effectiveSource.apiManifest,
|
|
189
|
+
artifact: apiManifestArtifact
|
|
190
|
+
};
|
|
191
|
+
}
|
|
192
|
+
effectiveExtension = {
|
|
193
|
+
...extension,
|
|
194
|
+
source: effectiveSource
|
|
195
|
+
};
|
|
196
|
+
}
|
|
197
|
+
validateExtensionSourceMetadata(effectiveExtension);
|
|
198
|
+
if (effectiveExtension.source?.provider === "npm") {
|
|
199
|
+
const npmSource = await readNpmExtensionSource(effectiveExtension, source.resolvedSourceDirectory, {
|
|
200
|
+
allowVersionMismatch: mode === "update",
|
|
201
|
+
maximumArtifactBytes,
|
|
202
|
+
maximumManifestBytes
|
|
203
|
+
});
|
|
204
|
+
const apiManifestDownload = npmSource.apiManifestContents ? {
|
|
205
|
+
contents: npmSource.apiManifestContents,
|
|
206
|
+
manifest: parseExtensionApiManifest(npmSource.apiManifestContents, { expectedId: extension.id })
|
|
207
|
+
} : null;
|
|
208
|
+
let compatibilityChanges = [];
|
|
209
|
+
if (mode === "sync") {
|
|
210
|
+
validateManagedExtensionContents(extension, npmSource.contents);
|
|
211
|
+
if (apiManifestDownload) validateManagedExtensionApiManifest(extension, apiManifestDownload.contents);
|
|
212
|
+
} else if (apiManifestDownload) {
|
|
213
|
+
const installedApiManifestContents = source.extensionApiManifestContents.get(extension.id);
|
|
214
|
+
assert(installedApiManifestContents, `Managed extension API manifest is missing for ${extension.id}.`);
|
|
215
|
+
const installedApiManifest = validateManagedExtensionApiManifest(extension, installedApiManifestContents)?.manifest;
|
|
216
|
+
assert(installedApiManifest, `Managed extension API manifest is invalid: ${extension.id}`);
|
|
217
|
+
compatibilityChanges = compareExtensionApiManifests(installedApiManifest, apiManifestDownload.manifest);
|
|
218
|
+
}
|
|
219
|
+
return {
|
|
220
|
+
apiManifestDownload,
|
|
221
|
+
commit: null,
|
|
222
|
+
compatibilityChanges,
|
|
223
|
+
contents: npmSource.contents,
|
|
224
|
+
effectiveExtension,
|
|
225
|
+
extension,
|
|
226
|
+
npmVersion: npmSource.version
|
|
227
|
+
};
|
|
228
|
+
}
|
|
229
|
+
const githubFetch = assertFetch(fetchImplementation);
|
|
230
|
+
const commit = mode === "sync" ? extension.source.resolvedCommit : await resolveGithubCommit(extension, githubFetch);
|
|
231
|
+
const expectedId = migrateToId ?? extension.id;
|
|
232
|
+
const [contents, apiManifestDownload] = await Promise.all([downloadExtension(effectiveExtension, commit, githubFetch, maximumArtifactBytes, expectedId), downloadExtensionApiManifest(effectiveExtension, commit, githubFetch, maximumManifestBytes, expectedId)]);
|
|
233
|
+
let compatibilityChanges = [];
|
|
234
|
+
if (mode === "sync") {
|
|
235
|
+
validateManagedExtensionContents(extension, contents);
|
|
236
|
+
if (apiManifestDownload) validateManagedExtensionApiManifest(extension, apiManifestDownload.contents);
|
|
237
|
+
} else if (apiManifestDownload) {
|
|
238
|
+
const installedApiManifestContents = source.extensionApiManifestContents.get(extension.id);
|
|
239
|
+
assert(installedApiManifestContents, `Managed extension API manifest is missing for ${extension.id}.`);
|
|
240
|
+
const installedApiManifest = validateManagedExtensionApiManifest(extension, installedApiManifestContents)?.manifest;
|
|
241
|
+
assert(installedApiManifest, `Managed extension API manifest is invalid: ${extension.id}`);
|
|
242
|
+
compatibilityChanges = compareExtensionApiManifests(installedApiManifest, apiManifestDownload.manifest);
|
|
243
|
+
}
|
|
244
|
+
return {
|
|
245
|
+
apiManifestDownload,
|
|
246
|
+
commit,
|
|
247
|
+
compatibilityChanges,
|
|
248
|
+
contents,
|
|
249
|
+
effectiveExtension,
|
|
250
|
+
extension
|
|
251
|
+
};
|
|
252
|
+
}));
|
|
253
|
+
const breakingApiChanges = downloads.flatMap((download) => download.compatibilityChanges.filter((change) => change.breaking).map((change) => ({
|
|
254
|
+
...change,
|
|
255
|
+
extensionId: download.extension.id
|
|
256
|
+
})));
|
|
257
|
+
if (breakingApiChanges.length > 0 && !allowBreakingApi) {
|
|
258
|
+
const details = downloads.filter((download) => download.compatibilityChanges.some((change) => change.breaking)).map((download) => formatExtensionApiCompatibilityChanges(download.extension.id, download.compatibilityChanges.filter((change) => change.breaking))).join("\n");
|
|
259
|
+
throw new Error(`Extension API update contains ${breakingApiChanges.length} breaking change(s). Review the reported paths, then use --allow-breaking-api with --yes to apply.
|
|
260
|
+
` + details);
|
|
261
|
+
}
|
|
262
|
+
const parentDirectory = path.dirname(source.resolvedSourceDirectory);
|
|
263
|
+
const candidateDirectory = await mkdtemp(path.join(parentDirectory, `.${path.basename(source.resolvedSourceDirectory)}.extensions-`));
|
|
264
|
+
let installed = false;
|
|
265
|
+
try {
|
|
266
|
+
await cp(source.resolvedSourceDirectory, candidateDirectory, {
|
|
267
|
+
preserveTimestamps: true,
|
|
268
|
+
recursive: true,
|
|
269
|
+
verbatimSymlinks: true
|
|
270
|
+
});
|
|
271
|
+
const manifestPath = path.join(candidateDirectory, source.sourceManifest.embeddedExtensions);
|
|
272
|
+
const manifest = JSON.parse(await readFile(manifestPath, "utf8"));
|
|
273
|
+
const projectPath = path.join(candidateDirectory, source.sourceManifest.project);
|
|
274
|
+
const entriesById = new Map(manifest.extensions.map((entry) => [entry.id, entry]));
|
|
275
|
+
let manifestChanged = false;
|
|
276
|
+
let migration;
|
|
277
|
+
for (const { apiManifestDownload, commit, contents, effectiveExtension, extension, npmVersion } of downloads) {
|
|
278
|
+
if (migrateToId !== void 0) {
|
|
279
|
+
const project = JSON.parse(await readFile(projectPath, "utf8"));
|
|
280
|
+
migration = rewriteExtensionIdDocuments({
|
|
281
|
+
apiManifestArtifact,
|
|
282
|
+
extensionManifest: manifest,
|
|
283
|
+
newId: migrateToId,
|
|
284
|
+
oldId: extension.id,
|
|
285
|
+
project,
|
|
286
|
+
sourceArtifact: effectiveExtension.source?.artifact
|
|
287
|
+
});
|
|
288
|
+
const migratedSource = migration.extensionManifest.extensions[migration.extensionIndex].source;
|
|
289
|
+
assert(migratedSource, `Migrated extension has no source metadata: ${extension.id}`);
|
|
290
|
+
migratedSource.resolvedCommit = commit ?? void 0;
|
|
291
|
+
migratedSource.integrity = extensionIntegrity(contents);
|
|
292
|
+
if (apiManifestDownload && migratedSource.apiManifest) migratedSource.apiManifest.integrity = extensionApiManifestIntegrity(apiManifestDownload.contents);
|
|
293
|
+
const writes = [
|
|
294
|
+
writeFile(projectPath, `${JSON.stringify(migration.project, null, 2)}\n`),
|
|
295
|
+
writeFile(manifestPath, `${JSON.stringify(migration.extensionManifest, null, 2)}\n`),
|
|
296
|
+
writeFile(path.join(candidateDirectory, migration.newPath), contents)
|
|
297
|
+
];
|
|
298
|
+
if (apiManifestDownload && migration.newApiManifestPath) writes.push(writeFile(path.join(candidateDirectory, migration.newApiManifestPath), apiManifestDownload.contents));
|
|
299
|
+
await Promise.all(writes);
|
|
300
|
+
await rm(path.join(candidateDirectory, migration.oldPath));
|
|
301
|
+
if (migration.oldApiManifestPath) await rm(path.join(candidateDirectory, migration.oldApiManifestPath));
|
|
302
|
+
continue;
|
|
303
|
+
}
|
|
304
|
+
await writeFile(path.join(candidateDirectory, extension.path), contents);
|
|
305
|
+
if (apiManifestDownload) {
|
|
306
|
+
const apiManifestPath = extension.source?.apiManifest?.path;
|
|
307
|
+
assert(apiManifestPath, `Managed extension API manifest path is missing: ${extension.id}`);
|
|
308
|
+
await writeFile(path.join(candidateDirectory, apiManifestPath), apiManifestDownload.contents);
|
|
309
|
+
}
|
|
310
|
+
if (mode === "update") {
|
|
311
|
+
const candidateExtension = entriesById.get(extension.id);
|
|
312
|
+
assert(candidateExtension, `Extension manifest entry disappeared: ${extension.id}`);
|
|
313
|
+
const candidateSource = candidateExtension.source;
|
|
314
|
+
assert(candidateSource, `Extension manifest entry has no source: ${extension.id}`);
|
|
315
|
+
const integrity = extensionIntegrity(contents);
|
|
316
|
+
manifestChanged = manifestChanged || candidateSource.integrity !== integrity;
|
|
317
|
+
if (candidateSource.provider === "npm") {
|
|
318
|
+
manifestChanged = manifestChanged || candidateSource.version !== npmVersion;
|
|
319
|
+
candidateSource.version = npmVersion;
|
|
320
|
+
} else {
|
|
321
|
+
manifestChanged = manifestChanged || candidateSource.resolvedCommit !== commit;
|
|
322
|
+
candidateSource.resolvedCommit = commit ?? void 0;
|
|
323
|
+
}
|
|
324
|
+
candidateSource.integrity = integrity;
|
|
325
|
+
if (apiManifestDownload && candidateSource.apiManifest) {
|
|
326
|
+
const apiManifestIntegrity = extensionApiManifestIntegrity(apiManifestDownload.contents);
|
|
327
|
+
manifestChanged = manifestChanged || candidateSource.apiManifest.integrity !== apiManifestIntegrity;
|
|
328
|
+
candidateSource.apiManifest.integrity = apiManifestIntegrity;
|
|
329
|
+
candidateSource.apiManifest.formatVersion = apiManifestDownload.manifest.formatVersion;
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
if (manifestChanged && migrateToId === void 0) await writeFile(manifestPath, `${JSON.stringify(manifest, null, 2)}\n`);
|
|
334
|
+
if (migration) await createDeterministicSb3(candidateDirectory);
|
|
335
|
+
else await validateSb3Source(candidateDirectory);
|
|
336
|
+
const result = await installCandidate({
|
|
337
|
+
candidateDirectory,
|
|
338
|
+
confirmReplace,
|
|
339
|
+
initialSourceFingerprint: initialComparison.existingFingerprint,
|
|
340
|
+
sourceDirectory: source.resolvedSourceDirectory,
|
|
341
|
+
yes
|
|
342
|
+
});
|
|
343
|
+
installed = true;
|
|
344
|
+
return {
|
|
345
|
+
...result,
|
|
346
|
+
apiCompatibility: downloads.filter(({ apiManifestDownload }) => apiManifestDownload !== null).map(({ compatibilityChanges, extension }) => ({
|
|
347
|
+
changes: compatibilityChanges,
|
|
348
|
+
id: migrateToId ?? extension.id,
|
|
349
|
+
previousId: migrateToId === void 0 ? void 0 : extension.id
|
|
350
|
+
})),
|
|
351
|
+
extensions: downloads.map(({ commit, extension, npmVersion }) => {
|
|
352
|
+
const extensionSource = extension.source;
|
|
353
|
+
return extensionSource?.provider === "npm" ? {
|
|
354
|
+
id: extension.id,
|
|
355
|
+
package: extensionSource.package,
|
|
356
|
+
version: npmVersion
|
|
357
|
+
} : {
|
|
358
|
+
id: migrateToId ?? extension.id,
|
|
359
|
+
previousId: migrateToId === void 0 ? void 0 : extension.id,
|
|
360
|
+
resolvedCommit: commit
|
|
361
|
+
};
|
|
362
|
+
}),
|
|
363
|
+
migration: migration === void 0 ? null : {
|
|
364
|
+
counts: migration.counts,
|
|
365
|
+
fromId: selectedExtensionId,
|
|
366
|
+
toId: migrateToId,
|
|
367
|
+
totalChanges: migration.totalChanges,
|
|
368
|
+
unclassifiedReferences: migration.unclassifiedReferences
|
|
369
|
+
},
|
|
370
|
+
mode,
|
|
371
|
+
sourceDirectory: source.resolvedSourceDirectory
|
|
372
|
+
};
|
|
373
|
+
} finally {
|
|
374
|
+
if (!installed) await rm(candidateDirectory, {
|
|
375
|
+
recursive: true,
|
|
376
|
+
force: true
|
|
377
|
+
});
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
async function extensionStatus(sourceDirectory, { fetch: fetchImplementation = globalThis.fetch } = {}) {
|
|
381
|
+
const source = await inspectExtensionSource(sourceDirectory);
|
|
382
|
+
return Promise.all(managedExtensions(source).map(async (extension) => {
|
|
383
|
+
const extensionSource = extension.source;
|
|
384
|
+
assert(extensionSource, `Managed extension has no source metadata: ${extension.id}`);
|
|
385
|
+
let local = "valid";
|
|
386
|
+
try {
|
|
387
|
+
const contents = source.extensionContents.get(extension.id);
|
|
388
|
+
assert(contents, `Managed extension contents are missing: ${extension.id}`);
|
|
389
|
+
validateManagedExtensionContents(extension, contents);
|
|
390
|
+
if (extensionSource.apiManifest) {
|
|
391
|
+
const apiManifestContents = source.extensionApiManifestContents.get(extension.id);
|
|
392
|
+
assert(apiManifestContents, `Managed extension API manifest is missing: ${extension.id}`);
|
|
393
|
+
validateManagedExtensionApiManifest(extension, apiManifestContents);
|
|
394
|
+
}
|
|
395
|
+
} catch {
|
|
396
|
+
local = "modified";
|
|
397
|
+
}
|
|
398
|
+
if (extensionSource.provider === "npm") {
|
|
399
|
+
const npmSource = await readNpmExtensionSource(extension, source.resolvedSourceDirectory, {
|
|
400
|
+
allowVersionMismatch: true,
|
|
401
|
+
maximumArtifactBytes: defaultExtensionArtifactSizeLimit,
|
|
402
|
+
maximumManifestBytes: defaultExtensionApiManifestSizeLimit
|
|
403
|
+
});
|
|
404
|
+
if (npmSource.version === extensionSource.version) {
|
|
405
|
+
validateManagedExtensionContents(extension, npmSource.contents);
|
|
406
|
+
if (npmSource.apiManifestContents) validateManagedExtensionApiManifest(extension, npmSource.apiManifestContents);
|
|
407
|
+
}
|
|
408
|
+
return {
|
|
409
|
+
id: extension.id,
|
|
410
|
+
installedVersion: npmSource.version,
|
|
411
|
+
local,
|
|
412
|
+
package: extensionSource.package,
|
|
413
|
+
state: npmSource.version === extensionSource.version ? "current" : "update-available",
|
|
414
|
+
version: extensionSource.version
|
|
415
|
+
};
|
|
416
|
+
}
|
|
417
|
+
const remoteCommit = await resolveGithubCommit(extension, assertFetch(fetchImplementation));
|
|
418
|
+
return {
|
|
419
|
+
id: extension.id,
|
|
420
|
+
local,
|
|
421
|
+
ref: extensionSource.ref,
|
|
422
|
+
remoteCommit,
|
|
423
|
+
resolvedCommit: extensionSource.resolvedCommit,
|
|
424
|
+
state: remoteCommit === extensionSource.resolvedCommit ? "current" : "update-available"
|
|
425
|
+
};
|
|
426
|
+
}));
|
|
427
|
+
}
|
|
428
|
+
async function syncExtensions({ confirmReplace, fetch: fetchImplementation = globalThis.fetch, maximumArtifactBytes = defaultExtensionArtifactSizeLimit, maximumManifestBytes = defaultExtensionApiManifestSizeLimit, sourceDirectory, yes = false }) {
|
|
429
|
+
return updateCandidate({
|
|
430
|
+
allowBreakingApi: false,
|
|
431
|
+
apiManifestArtifact: void 0,
|
|
432
|
+
confirmReplace,
|
|
433
|
+
fetchImplementation,
|
|
434
|
+
maximumArtifactBytes,
|
|
435
|
+
maximumManifestBytes,
|
|
436
|
+
migrateToId: void 0,
|
|
437
|
+
mode: "sync",
|
|
438
|
+
selectedExtensionId: void 0,
|
|
439
|
+
sourceArtifact: void 0,
|
|
440
|
+
sourceDirectory,
|
|
441
|
+
yes
|
|
442
|
+
});
|
|
443
|
+
}
|
|
444
|
+
async function updateExtensions({ allowBreakingApi = false, apiManifestArtifact, confirmReplace, extensionId, fetch: fetchImplementation = globalThis.fetch, maximumArtifactBytes = defaultExtensionArtifactSizeLimit, maximumManifestBytes = defaultExtensionApiManifestSizeLimit, migrateToId, sourceArtifact, sourceDirectory, yes = false }) {
|
|
445
|
+
return updateCandidate({
|
|
446
|
+
allowBreakingApi,
|
|
447
|
+
apiManifestArtifact,
|
|
448
|
+
confirmReplace,
|
|
449
|
+
fetchImplementation,
|
|
450
|
+
maximumArtifactBytes,
|
|
451
|
+
maximumManifestBytes,
|
|
452
|
+
migrateToId,
|
|
453
|
+
mode: "update",
|
|
454
|
+
selectedExtensionId: extensionId,
|
|
455
|
+
sourceArtifact,
|
|
456
|
+
sourceDirectory,
|
|
457
|
+
yes
|
|
458
|
+
});
|
|
459
|
+
}
|
|
460
|
+
//#endregion
|
|
461
|
+
export { defaultExtensionArtifactSizeLimit, extensionStatus, syncExtensions, updateExtensions };
|
|
462
|
+
|
|
463
|
+
//# sourceMappingURL=extension-sync.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"extension-sync.js","names":[],"sources":["../src/extension-sync.ts"],"sourcesContent":["// SPDX-License-Identifier: MPL-2.0\n\nimport {cp, lstat, mkdtemp, readFile, rm, writeFile} from 'node:fs/promises';\nimport path from 'node:path';\n\nimport {assert, errorMessage} from './assert';\nimport {\n compareExtensionApiManifests,\n defaultExtensionApiManifestSizeLimit,\n extensionApiManifestIntegrity,\n formatExtensionApiCompatibilityChanges,\n parseExtensionApiManifest,\n validateExtensionApiManifestSourceMetadata,\n validateManagedExtensionApiManifest,\n} from './extension-api-manifest';\nimport type {ExtensionApiCompatibilityChange, ExtensionApiManifest} from './extension-api-manifest';\nimport {\n extensionHeaderId,\n extensionIntegrity,\n validateExtensionSourceMetadata,\n validateManagedExtensionContents,\n} from './extension-dependencies';\nimport {rewriteExtensionIdDocuments, validateNewExtensionId} from './extension-id-migration';\nimport type {RewriteExtensionIdDocumentsResult} from './extension-id-migration';\nimport {readNpmExtensionSource} from './npm-extension-source';\nimport {\n assertNoInterruptedRollback,\n compareDirectories,\n pathExists,\n replaceDirectoryTransactionally,\n} from './output-safety';\nimport type {DirectoryComparison} from './output-safety';\nimport {\n createDeterministicSb3,\n inspectSb3SourceForExtensionSync,\n validateSb3Source,\n} from './source';\nimport type {InspectedSb3Source} from './source';\nimport type {\n EmbeddedExtension,\n EmbeddedExtensionManifest,\n ExtensionSource,\n GitHubExtensionSource,\n ProjectJson,\n} from './types';\n\nexport const defaultExtensionArtifactSizeLimit = 5 * 1024 * 1024;\nconst githubApiResponseSizeLimit = 1024 * 1024;\n\nexport type FetchImplementation = typeof globalThis.fetch;\n\nexport type ExtensionSyncMode = 'sync' | 'update';\n\n/** The candidate manifest is edited in place as a JSON document before it is written back. */\ninterface MutableExtensionSource {\n apiManifest?: {artifact: string; formatVersion: number; integrity: string; path: string};\n artifact: string;\n integrity: string;\n package?: string;\n provider: string;\n ref?: string;\n resolvedCommit?: string;\n version?: string;\n}\n\ninterface MutableManifestExtension {\n id: string;\n path: string;\n source?: MutableExtensionSource;\n [key: string]: unknown;\n}\n\ninterface MutableExtensionManifest {\n extensions: MutableManifestExtension[];\n [key: string]: unknown;\n}\n\ninterface ApiManifestDownload {\n contents: Buffer;\n manifest: ExtensionApiManifest;\n}\n\ninterface ExtensionDownload {\n apiManifestDownload: ApiManifestDownload | null;\n commit: string | null;\n compatibilityChanges: ExtensionApiCompatibilityChange[];\n contents: Buffer;\n effectiveExtension: EmbeddedExtension;\n extension: EmbeddedExtension;\n npmVersion?: string;\n}\n\nexport interface ExtensionSyncConfirmContext {\n comparison: DirectoryComparison;\n sourceDirectory: string;\n}\n\ninterface UpdateCandidateInput {\n allowBreakingApi: boolean;\n apiManifestArtifact: string | undefined;\n confirmReplace?: (context: ExtensionSyncConfirmContext) => boolean | Promise<boolean>;\n fetchImplementation?: FetchImplementation;\n maximumArtifactBytes: number;\n maximumManifestBytes: number;\n migrateToId: string | undefined;\n mode: ExtensionSyncMode;\n selectedExtensionId: string | undefined;\n sourceArtifact: string | undefined;\n sourceDirectory: string;\n yes: boolean;\n}\n\nexport interface SyncExtensionsOptions {\n confirmReplace?: (context: ExtensionSyncConfirmContext) => boolean | Promise<boolean>;\n fetch?: FetchImplementation;\n maximumArtifactBytes?: number;\n maximumManifestBytes?: number;\n sourceDirectory: string;\n yes?: boolean;\n}\n\nexport interface UpdateExtensionsOptions extends SyncExtensionsOptions {\n allowBreakingApi?: boolean;\n apiManifestArtifact?: string;\n extensionId?: string;\n migrateToId?: string;\n sourceArtifact?: string;\n}\n\nfunction assertFetch(fetchImplementation: FetchImplementation | undefined): FetchImplementation {\n assert(\n typeof fetchImplementation === 'function',\n 'A Fetch API implementation is required for GitHub extension operations.',\n );\n return fetchImplementation;\n}\n\nfunction githubHeaders(accept: string): Record<string, string> {\n return {\n Accept: accept,\n 'User-Agent': 'sb3-toolchain',\n 'X-GitHub-Api-Version': '2022-11-28',\n };\n}\n\nfunction rawArtifactUrl(\n source: GitHubExtensionSource,\n commit: string,\n artifactPath: string = source.artifact,\n): string {\n const artifact = artifactPath\n .split('/')\n .map((segment) => encodeURIComponent(segment))\n .join('/');\n return `https://raw.githubusercontent.com/${source.repository}/${commit}/${artifact}`;\n}\n\nasync function downloadExtensionApiManifest(\n extension: EmbeddedExtension,\n commit: string,\n fetchImplementation: FetchImplementation,\n maximumManifestBytes: number,\n expectedId: string = extension.id,\n): Promise<ApiManifestDownload | null> {\n const metadata = validateExtensionApiManifestSourceMetadata(extension);\n if (!metadata) return null;\n const contents = await fetchBytes(\n fetchImplementation,\n rawArtifactUrl(extension.source as GitHubExtensionSource, commit, metadata.artifact),\n maximumManifestBytes,\n `GitHub extension API manifest download for ${extension.id}`,\n 'application/json',\n );\n const manifest = parseExtensionApiManifest(contents, {expectedId});\n return {contents, manifest};\n}\n\nfunction githubCommitUrl(source: GitHubExtensionSource): string {\n return (\n `https://api.github.com/repos/${source.repository}/commits/` + encodeURIComponent(source.ref)\n );\n}\n\nasync function readLimitedResponse(\n response: Response,\n maximumBytes: number,\n description: string,\n): Promise<Buffer> {\n const contentLength = response.headers?.get?.('content-length');\n if (contentLength !== null && contentLength !== undefined) {\n const parsedLength = Number(contentLength);\n assert(\n Number.isSafeInteger(parsedLength) && parsedLength >= 0,\n `${description} returned an invalid Content-Length.`,\n );\n assert(parsedLength <= maximumBytes, `${description} exceeds the ${maximumBytes}-byte limit.`);\n }\n\n if (!response.body?.getReader) {\n const contents = Buffer.from(await response.arrayBuffer());\n assert(\n contents.length <= maximumBytes,\n `${description} exceeds the ${maximumBytes}-byte limit.`,\n );\n return contents;\n }\n\n const reader = response.body.getReader();\n const chunks: Buffer[] = [];\n let totalLength = 0;\n try {\n while (true) {\n const {done, value} = await reader.read();\n if (done) break;\n totalLength += value.byteLength;\n assert(totalLength <= maximumBytes, `${description} exceeds the ${maximumBytes}-byte limit.`);\n chunks.push(Buffer.from(value));\n }\n } catch (error) {\n await reader.cancel(error).catch(() => {});\n throw error;\n }\n return Buffer.concat(chunks, totalLength);\n}\n\nasync function fetchBytes(\n fetchImplementation: FetchImplementation,\n url: string,\n maximumBytes: number,\n description: string,\n accept: string,\n): Promise<Buffer> {\n const parsedUrl = new URL(url);\n assert(parsedUrl.protocol === 'https:', `${description} requires HTTPS.`);\n let response: Response;\n try {\n response = await fetchImplementation(url, {\n headers: githubHeaders(accept),\n redirect: 'error',\n });\n } catch (error) {\n throw new Error(`${description} request failed: ${errorMessage(error)}`, {cause: error});\n }\n assert(\n response && typeof response === 'object',\n `${description} request returned an invalid response.`,\n );\n assert(\n response.redirected !== true &&\n (!response.url || new URL(response.url).href === parsedUrl.href),\n `${description} refused a redirected response.`,\n );\n assert(response.ok, `${description} request failed with HTTP ${response.status ?? '(unknown)'}.`);\n return readLimitedResponse(response, maximumBytes, description);\n}\n\nasync function resolveGithubCommit(\n extension: EmbeddedExtension,\n fetchImplementation: FetchImplementation,\n): Promise<string> {\n const source = extension.source as GitHubExtensionSource;\n if (/^[a-f0-9]{40}$/u.test(source.ref)) {\n return source.ref;\n }\n const contents = await fetchBytes(\n fetchImplementation,\n githubCommitUrl(source),\n githubApiResponseSizeLimit,\n `GitHub ref lookup for ${extension.id}`,\n 'application/vnd.github+json',\n );\n let response: {sha?: unknown} | null;\n try {\n response = JSON.parse(contents.toString('utf8'));\n } catch (error) {\n throw new Error(`GitHub ref lookup for ${extension.id} returned invalid JSON.`, {cause: error});\n }\n assert(\n typeof response?.sha === 'string' && /^[a-f0-9]{40}$/u.test(response.sha),\n `GitHub ref lookup for ${extension.id} returned an invalid commit SHA.`,\n );\n return response.sha as string;\n}\n\nasync function downloadExtension(\n extension: EmbeddedExtension,\n commit: string,\n fetchImplementation: FetchImplementation,\n maximumArtifactBytes: number,\n expectedId: string = extension.id,\n): Promise<Buffer> {\n const contents = await fetchBytes(\n fetchImplementation,\n rawArtifactUrl(extension.source as GitHubExtensionSource, commit),\n maximumArtifactBytes,\n `GitHub artifact download for ${extension.id}`,\n 'application/javascript, text/javascript;q=0.9, */*;q=0.1',\n );\n const actualId = extensionHeaderId(contents);\n assert(\n actualId === expectedId,\n `Downloaded extension header ID mismatch for ${extension.id}: ` +\n `expected ${expectedId}, got ${actualId ?? '(missing)'}`,\n );\n return contents;\n}\n\nfunction managedExtensions(source: InspectedSb3Source): EmbeddedExtension[] {\n return source.extensions.filter((extension) => extension.source !== undefined);\n}\n\nasync function inspectExtensionSource(\n sourceDirectory: string,\n {willReplace = false}: {willReplace?: boolean} = {},\n): Promise<InspectedSb3Source> {\n const resolvedSourceDirectory = path.resolve(sourceDirectory);\n if (willReplace) {\n assert(\n resolvedSourceDirectory !== path.parse(resolvedSourceDirectory).root,\n 'Refusing to replace a filesystem root during extension synchronization.',\n );\n assert(\n !(await pathExists(path.join(resolvedSourceDirectory, '.git'))),\n 'Refusing to replace a Git repository root during extension synchronization.',\n );\n }\n const stats = await lstat(resolvedSourceDirectory);\n assert(\n stats.isDirectory() && !stats.isSymbolicLink(),\n `SB3 source must be a directory, not a file or symbolic link: ${resolvedSourceDirectory}`,\n );\n if (willReplace) {\n await assertNoInterruptedRollback(resolvedSourceDirectory);\n }\n return inspectSb3SourceForExtensionSync(resolvedSourceDirectory);\n}\n\nasync function installCandidate({\n candidateDirectory,\n confirmReplace,\n initialSourceFingerprint,\n sourceDirectory,\n yes,\n}: {\n candidateDirectory: string;\n confirmReplace?: (context: ExtensionSyncConfirmContext) => boolean | Promise<boolean>;\n initialSourceFingerprint: string;\n sourceDirectory: string;\n yes: boolean;\n}): Promise<{\n changed: boolean;\n comparison: DirectoryComparison;\n rollbackCleanupWarning: string | null;\n}> {\n const comparison = await compareDirectories(sourceDirectory, candidateDirectory);\n assert(\n comparison.existingFingerprint === initialSourceFingerprint,\n 'SB3 source changed while extension artifacts were being fetched; refusing to replace it.',\n );\n if (comparison.identical) {\n await rm(candidateDirectory, {recursive: true, force: true});\n return {changed: false, comparison, rollbackCleanupWarning: null};\n }\n\n const context = {comparison, sourceDirectory};\n if (!yes) {\n assert(\n typeof confirmReplace === 'function',\n `Managed extension files differ in ${sourceDirectory}. ` +\n 'Non-interactive replacement requires --yes.',\n );\n assert(\n await confirmReplace(context),\n 'Extension synchronization cancelled; the existing source was not changed.',\n );\n }\n\n const latestComparison = await compareDirectories(sourceDirectory, candidateDirectory);\n assert(\n latestComparison.existingFingerprint === comparison.existingFingerprint &&\n latestComparison.candidateFingerprint === comparison.candidateFingerprint,\n 'SB3 source or extension candidate changed during synchronization; refusing to replace it.',\n );\n const replacement = await replaceDirectoryTransactionally(candidateDirectory, sourceDirectory);\n return {changed: true, comparison, ...replacement};\n}\n\nasync function updateCandidate({\n allowBreakingApi,\n apiManifestArtifact,\n confirmReplace,\n fetchImplementation,\n maximumArtifactBytes,\n maximumManifestBytes,\n migrateToId,\n mode,\n selectedExtensionId,\n sourceArtifact,\n sourceDirectory,\n yes,\n}: UpdateCandidateInput) {\n assert(\n Number.isSafeInteger(maximumArtifactBytes) && maximumArtifactBytes > 0,\n 'maximumArtifactBytes must be a positive integer.',\n );\n assert(\n Number.isSafeInteger(maximumManifestBytes) && maximumManifestBytes > 0,\n 'maximumManifestBytes must be a positive integer.',\n );\n assert(!allowBreakingApi || yes, '--allow-breaking-api requires --yes.');\n const source = await inspectExtensionSource(sourceDirectory, {willReplace: true});\n const initialComparison = await compareDirectories(\n source.resolvedSourceDirectory,\n source.resolvedSourceDirectory,\n );\n assert(\n initialComparison.identical &&\n initialComparison.existingFingerprint === initialComparison.candidateFingerprint,\n 'SB3 source changed while its initial state was being inspected.',\n );\n const managed = managedExtensions(source);\n assert(managed.length > 0, 'No managed embedded extensions were found.');\n if (selectedExtensionId !== undefined) {\n assert(\n managed.some((extension) => extension.id === selectedExtensionId),\n `Managed extension was not found: ${selectedExtensionId}`,\n );\n }\n const selected = managed.filter(\n (extension) => selectedExtensionId === undefined || extension.id === selectedExtensionId,\n );\n if (migrateToId !== undefined) {\n assert(mode === 'update', 'Extension ID migration is only available during update.');\n assert(\n selectedExtensionId !== undefined,\n 'Extension ID migration requires an explicit existing extension ID.',\n );\n validateNewExtensionId(migrateToId);\n assert(\n selected.every((extension) => extension.source?.provider === 'github'),\n 'Extension ID migration is not supported for npm-managed extensions.',\n );\n }\n assert(\n sourceArtifact === undefined || migrateToId !== undefined,\n 'A replacement artifact path requires an extension ID migration.',\n );\n assert(\n apiManifestArtifact === undefined || migrateToId !== undefined,\n 'A replacement API manifest artifact path requires an extension ID migration.',\n );\n if (migrateToId !== undefined) {\n const extensionManifest = JSON.parse(\n await readFile(\n path.join(source.resolvedSourceDirectory, source.sourceManifest.embeddedExtensions),\n 'utf8',\n ),\n ) as EmbeddedExtensionManifest;\n assert(selectedExtensionId !== undefined, 'Extension ID migration requires an extension ID.');\n rewriteExtensionIdDocuments({\n apiManifestArtifact,\n extensionManifest,\n newId: migrateToId,\n oldId: selectedExtensionId,\n project: source.project,\n sourceArtifact,\n });\n }\n\n const downloads: ExtensionDownload[] = await Promise.all(\n selected.map(async (extension): Promise<ExtensionDownload> => {\n let effectiveExtension = extension;\n if (sourceArtifact !== undefined || apiManifestArtifact !== undefined) {\n const effectiveSource = {...extension.source} as ExtensionSource;\n if (sourceArtifact !== undefined) effectiveSource.artifact = sourceArtifact;\n if (apiManifestArtifact !== undefined) {\n assert(\n effectiveSource.apiManifest,\n `Extension ${extension.id} has no managed API manifest metadata.`,\n );\n effectiveSource.apiManifest = {\n ...effectiveSource.apiManifest,\n artifact: apiManifestArtifact,\n };\n }\n effectiveExtension = {...extension, source: effectiveSource};\n }\n validateExtensionSourceMetadata(effectiveExtension);\n if (effectiveExtension.source?.provider === 'npm') {\n const npmSource = await readNpmExtensionSource(\n effectiveExtension,\n source.resolvedSourceDirectory,\n {\n allowVersionMismatch: mode === 'update',\n maximumArtifactBytes,\n maximumManifestBytes,\n },\n );\n const apiManifestDownload = npmSource.apiManifestContents\n ? {\n contents: npmSource.apiManifestContents,\n manifest: parseExtensionApiManifest(npmSource.apiManifestContents, {\n expectedId: extension.id,\n }),\n }\n : null;\n let compatibilityChanges: ExtensionApiCompatibilityChange[] = [];\n if (mode === 'sync') {\n validateManagedExtensionContents(extension, npmSource.contents);\n if (apiManifestDownload) {\n validateManagedExtensionApiManifest(extension, apiManifestDownload.contents);\n }\n } else if (apiManifestDownload) {\n const installedApiManifestContents = source.extensionApiManifestContents.get(\n extension.id,\n );\n assert(\n installedApiManifestContents,\n `Managed extension API manifest is missing for ${extension.id}.`,\n );\n const installedApiManifest = validateManagedExtensionApiManifest(\n extension,\n installedApiManifestContents,\n )?.manifest;\n assert(\n installedApiManifest,\n `Managed extension API manifest is invalid: ${extension.id}`,\n );\n compatibilityChanges = compareExtensionApiManifests(\n installedApiManifest,\n apiManifestDownload.manifest,\n );\n }\n return {\n apiManifestDownload,\n commit: null,\n compatibilityChanges,\n contents: npmSource.contents,\n effectiveExtension,\n extension,\n npmVersion: npmSource.version,\n };\n }\n const githubFetch = assertFetch(fetchImplementation);\n const commit =\n mode === 'sync'\n ? (extension.source as GitHubExtensionSource).resolvedCommit\n : await resolveGithubCommit(extension, githubFetch);\n const expectedId = migrateToId ?? extension.id;\n const [contents, apiManifestDownload] = await Promise.all([\n downloadExtension(\n effectiveExtension,\n commit,\n githubFetch,\n maximumArtifactBytes,\n expectedId,\n ),\n downloadExtensionApiManifest(\n effectiveExtension,\n commit,\n githubFetch,\n maximumManifestBytes,\n expectedId,\n ),\n ]);\n let compatibilityChanges: ExtensionApiCompatibilityChange[] = [];\n if (mode === 'sync') {\n validateManagedExtensionContents(extension, contents);\n if (apiManifestDownload) {\n validateManagedExtensionApiManifest(extension, apiManifestDownload.contents);\n }\n } else if (apiManifestDownload) {\n const installedApiManifestContents = source.extensionApiManifestContents.get(extension.id);\n assert(\n installedApiManifestContents,\n `Managed extension API manifest is missing for ${extension.id}.`,\n );\n const installedApiManifest = validateManagedExtensionApiManifest(\n extension,\n installedApiManifestContents,\n )?.manifest;\n assert(installedApiManifest, `Managed extension API manifest is invalid: ${extension.id}`);\n compatibilityChanges = compareExtensionApiManifests(\n installedApiManifest,\n apiManifestDownload.manifest,\n );\n }\n return {\n apiManifestDownload,\n commit,\n compatibilityChanges,\n contents,\n effectiveExtension,\n extension,\n };\n }),\n );\n const breakingApiChanges = downloads.flatMap((download) =>\n download.compatibilityChanges\n .filter((change) => change.breaking)\n .map((change) => ({...change, extensionId: download.extension.id})),\n );\n if (breakingApiChanges.length > 0 && !allowBreakingApi) {\n const details = downloads\n .filter((download) => download.compatibilityChanges.some((change) => change.breaking))\n .map((download) =>\n formatExtensionApiCompatibilityChanges(\n download.extension.id,\n download.compatibilityChanges.filter((change) => change.breaking),\n ),\n )\n .join('\\n');\n throw new Error(\n `Extension API update contains ${breakingApiChanges.length} breaking change(s). ` +\n 'Review the reported paths, then use --allow-breaking-api with --yes to apply.\\n' +\n details,\n );\n }\n\n const parentDirectory = path.dirname(source.resolvedSourceDirectory);\n const candidateDirectory = await mkdtemp(\n path.join(parentDirectory, `.${path.basename(source.resolvedSourceDirectory)}.extensions-`),\n );\n let installed = false;\n try {\n await cp(source.resolvedSourceDirectory, candidateDirectory, {\n preserveTimestamps: true,\n recursive: true,\n verbatimSymlinks: true,\n });\n const manifestPath = path.join(candidateDirectory, source.sourceManifest.embeddedExtensions);\n const manifest = JSON.parse(await readFile(manifestPath, 'utf8')) as MutableExtensionManifest;\n const projectPath = path.join(candidateDirectory, source.sourceManifest.project);\n const entriesById = new Map(manifest.extensions.map((entry) => [entry.id, entry]));\n let manifestChanged = false;\n let migration: RewriteExtensionIdDocumentsResult | undefined;\n for (const {\n apiManifestDownload,\n commit,\n contents,\n effectiveExtension,\n extension,\n npmVersion,\n } of downloads) {\n if (migrateToId !== undefined) {\n const project = JSON.parse(await readFile(projectPath, 'utf8')) as ProjectJson;\n migration = rewriteExtensionIdDocuments({\n apiManifestArtifact,\n extensionManifest: manifest as unknown as EmbeddedExtensionManifest,\n newId: migrateToId,\n oldId: extension.id,\n project,\n sourceArtifact: effectiveExtension.source?.artifact,\n });\n const migratedExtension = migration.extensionManifest.extensions[\n migration.extensionIndex\n ] as unknown as MutableManifestExtension;\n const migratedSource = migratedExtension.source;\n assert(migratedSource, `Migrated extension has no source metadata: ${extension.id}`);\n migratedSource.resolvedCommit = commit ?? undefined;\n migratedSource.integrity = extensionIntegrity(contents);\n if (apiManifestDownload && migratedSource.apiManifest) {\n migratedSource.apiManifest.integrity = extensionApiManifestIntegrity(\n apiManifestDownload.contents,\n );\n }\n const writes = [\n writeFile(projectPath, `${JSON.stringify(migration.project, null, 2)}\\n`),\n writeFile(manifestPath, `${JSON.stringify(migration.extensionManifest, null, 2)}\\n`),\n writeFile(path.join(candidateDirectory, migration.newPath), contents),\n ];\n if (apiManifestDownload && migration.newApiManifestPath) {\n writes.push(\n writeFile(\n path.join(candidateDirectory, migration.newApiManifestPath),\n apiManifestDownload.contents,\n ),\n );\n }\n await Promise.all(writes);\n await rm(path.join(candidateDirectory, migration.oldPath));\n if (migration.oldApiManifestPath) {\n await rm(path.join(candidateDirectory, migration.oldApiManifestPath));\n }\n continue;\n }\n await writeFile(path.join(candidateDirectory, extension.path), contents);\n if (apiManifestDownload) {\n const apiManifestPath = extension.source?.apiManifest?.path;\n assert(apiManifestPath, `Managed extension API manifest path is missing: ${extension.id}`);\n await writeFile(\n path.join(candidateDirectory, apiManifestPath),\n apiManifestDownload.contents,\n );\n }\n if (mode === 'update') {\n const candidateExtension = entriesById.get(extension.id);\n assert(candidateExtension, `Extension manifest entry disappeared: ${extension.id}`);\n const candidateSource = candidateExtension.source;\n assert(candidateSource, `Extension manifest entry has no source: ${extension.id}`);\n const integrity = extensionIntegrity(contents);\n manifestChanged = manifestChanged || candidateSource.integrity !== integrity;\n if (candidateSource.provider === 'npm') {\n manifestChanged = manifestChanged || candidateSource.version !== npmVersion;\n candidateSource.version = npmVersion;\n } else {\n manifestChanged = manifestChanged || candidateSource.resolvedCommit !== commit;\n candidateSource.resolvedCommit = commit ?? undefined;\n }\n candidateSource.integrity = integrity;\n if (apiManifestDownload && candidateSource.apiManifest) {\n const apiManifestIntegrity = extensionApiManifestIntegrity(apiManifestDownload.contents);\n manifestChanged =\n manifestChanged || candidateSource.apiManifest.integrity !== apiManifestIntegrity;\n candidateSource.apiManifest.integrity = apiManifestIntegrity;\n candidateSource.apiManifest.formatVersion = apiManifestDownload.manifest.formatVersion;\n }\n }\n }\n if (manifestChanged && migrateToId === undefined) {\n await writeFile(manifestPath, `${JSON.stringify(manifest, null, 2)}\\n`);\n }\n if (migration) {\n await createDeterministicSb3(candidateDirectory);\n } else {\n await validateSb3Source(candidateDirectory);\n }\n const result = await installCandidate({\n candidateDirectory,\n confirmReplace,\n initialSourceFingerprint: initialComparison.existingFingerprint,\n sourceDirectory: source.resolvedSourceDirectory,\n yes,\n });\n installed = true;\n return {\n ...result,\n apiCompatibility: downloads\n .filter(({apiManifestDownload}) => apiManifestDownload !== null)\n .map(({compatibilityChanges, extension}) => ({\n changes: compatibilityChanges,\n id: migrateToId ?? extension.id,\n previousId: migrateToId === undefined ? undefined : extension.id,\n })),\n extensions: downloads.map(({commit, extension, npmVersion}) => {\n const extensionSource = extension.source;\n return extensionSource?.provider === 'npm'\n ? {\n id: extension.id,\n package: extensionSource.package,\n version: npmVersion,\n }\n : {\n id: migrateToId ?? extension.id,\n previousId: migrateToId === undefined ? undefined : extension.id,\n resolvedCommit: commit,\n };\n }),\n migration:\n migration === undefined\n ? null\n : {\n counts: migration.counts,\n fromId: selectedExtensionId,\n toId: migrateToId,\n totalChanges: migration.totalChanges,\n unclassifiedReferences: migration.unclassifiedReferences,\n },\n mode,\n sourceDirectory: source.resolvedSourceDirectory,\n };\n } finally {\n if (!installed) {\n await rm(candidateDirectory, {recursive: true, force: true});\n }\n }\n}\n\nexport async function extensionStatus(\n sourceDirectory: string,\n {fetch: fetchImplementation = globalThis.fetch}: {fetch?: FetchImplementation} = {},\n) {\n const source = await inspectExtensionSource(sourceDirectory);\n return Promise.all(\n managedExtensions(source).map(async (extension) => {\n const extensionSource = extension.source;\n assert(extensionSource, `Managed extension has no source metadata: ${extension.id}`);\n let local = 'valid';\n try {\n const contents = source.extensionContents.get(extension.id);\n assert(contents, `Managed extension contents are missing: ${extension.id}`);\n validateManagedExtensionContents(extension, contents);\n if (extensionSource.apiManifest) {\n const apiManifestContents = source.extensionApiManifestContents.get(extension.id);\n assert(apiManifestContents, `Managed extension API manifest is missing: ${extension.id}`);\n validateManagedExtensionApiManifest(extension, apiManifestContents);\n }\n } catch {\n local = 'modified';\n }\n if (extensionSource.provider === 'npm') {\n const npmSource = await readNpmExtensionSource(extension, source.resolvedSourceDirectory, {\n allowVersionMismatch: true,\n maximumArtifactBytes: defaultExtensionArtifactSizeLimit,\n maximumManifestBytes: defaultExtensionApiManifestSizeLimit,\n });\n if (npmSource.version === extensionSource.version) {\n validateManagedExtensionContents(extension, npmSource.contents);\n if (npmSource.apiManifestContents) {\n validateManagedExtensionApiManifest(extension, npmSource.apiManifestContents);\n }\n }\n return {\n id: extension.id,\n installedVersion: npmSource.version,\n local,\n package: extensionSource.package,\n state: npmSource.version === extensionSource.version ? 'current' : 'update-available',\n version: extensionSource.version,\n };\n }\n const remoteCommit = await resolveGithubCommit(extension, assertFetch(fetchImplementation));\n return {\n id: extension.id,\n local,\n ref: extensionSource.ref,\n remoteCommit,\n resolvedCommit: extensionSource.resolvedCommit,\n state: remoteCommit === extensionSource.resolvedCommit ? 'current' : 'update-available',\n };\n }),\n );\n}\n\nexport async function syncExtensions({\n confirmReplace,\n fetch: fetchImplementation = globalThis.fetch,\n maximumArtifactBytes = defaultExtensionArtifactSizeLimit,\n maximumManifestBytes = defaultExtensionApiManifestSizeLimit,\n sourceDirectory,\n yes = false,\n}: SyncExtensionsOptions) {\n return updateCandidate({\n allowBreakingApi: false,\n apiManifestArtifact: undefined,\n confirmReplace,\n fetchImplementation,\n maximumArtifactBytes,\n maximumManifestBytes,\n migrateToId: undefined,\n mode: 'sync',\n selectedExtensionId: undefined,\n sourceArtifact: undefined,\n sourceDirectory,\n yes,\n });\n}\n\nexport async function updateExtensions({\n allowBreakingApi = false,\n apiManifestArtifact,\n confirmReplace,\n extensionId,\n fetch: fetchImplementation = globalThis.fetch,\n maximumArtifactBytes = defaultExtensionArtifactSizeLimit,\n maximumManifestBytes = defaultExtensionApiManifestSizeLimit,\n migrateToId,\n sourceArtifact,\n sourceDirectory,\n yes = false,\n}: UpdateExtensionsOptions) {\n return updateCandidate({\n allowBreakingApi,\n apiManifestArtifact,\n confirmReplace,\n fetchImplementation,\n maximumArtifactBytes,\n maximumManifestBytes,\n migrateToId,\n mode: 'update',\n selectedExtensionId: extensionId,\n sourceArtifact,\n sourceDirectory,\n yes,\n });\n}\n"],"mappings":";;;;;;;;;;AA8CA,IAAa,oCAAoC;AACjD,IAAM,6BAA6B;AAkFnC,SAAS,YAAY,qBAA2E;CAC9F,OACE,OAAO,wBAAwB,YAC/B,yEACF;CACA,OAAO;AACT;AAEA,SAAS,cAAc,QAAwC;CAC7D,OAAO;EACL,QAAQ;EACR,cAAc;EACd,wBAAwB;CAC1B;AACF;AAEA,SAAS,eACP,QACA,QACA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CAAC;EAC1F,OAAO;GACL,IAAI,UAAU;GACd;GACA,KAAK,gBAAgB;GACrB;GACA,gBAAgB,gBAAgB;GAChC,OAAO,iBAAiB,gBAAgB,iBAAiB,YAAY;EACvE;CACF,CAAC,CACH;AACF;AAEA,eAAsB,eAAe,EACnC,gBACA,OAAO,sBAAsB,WAAW,OACxC,uBAAuB,mCACvB,uBAAuB,sCACvB,iBACA,MAAM,SACkB;CACxB,OAAO,gBAAgB;EACrB,kBAAkB;EAClB,qBAAqB,KAAA;EACrB;EACA;EACA;EACA;EACA,aAAa,KAAA;EACb,MAAM;EACN,qBAAqB,KAAA;EACrB,gBAAgB,KAAA;EAChB;EACA;CACF,CAAC;AACH;AAEA,eAAsB,iBAAiB,EACrC,mBAAmB,OACnB,qBACA,gBACA,aACA,OAAO,sBAAsB,WAAW,OACxC,uBAAuB,mCACvB,uBAAuB,sCACvB,aACA,gBACA,iBACA,MAAM,SACoB;CAC1B,OAAO,gBAAgB;EACrB;EACA;EACA;EACA;EACA;EACA;EACA;EACA,MAAM;EACN,qBAAqB;EACrB;EACA;EACA;CACF,CAAC;AACH"}
|
package/dist/import.d.ts
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { DirectoryComparison, GitOutputState } from './output-safety';
|
|
2
|
+
import { ExtensionEncoding } from './types';
|
|
3
|
+
export { validateOutputDirectoryPath } from './output-safety';
|
|
4
|
+
export interface DecodedExtensionDataUrl {
|
|
5
|
+
encoding: ExtensionEncoding;
|
|
6
|
+
mediaType: string;
|
|
7
|
+
parameters: string[];
|
|
8
|
+
source: Buffer;
|
|
9
|
+
}
|
|
10
|
+
export interface OutputReplacementContext {
|
|
11
|
+
comparison: DirectoryComparison;
|
|
12
|
+
discardLocalChanges: boolean;
|
|
13
|
+
gitState: GitOutputState;
|
|
14
|
+
outputDirectory: string;
|
|
15
|
+
}
|
|
16
|
+
export interface ImportSb3Options {
|
|
17
|
+
confirmReplace?: (context: OutputReplacementContext) => boolean | Promise<boolean>;
|
|
18
|
+
discardLocalChanges?: boolean;
|
|
19
|
+
inputPath: string;
|
|
20
|
+
outputDirectory: string;
|
|
21
|
+
protectedRoot?: string;
|
|
22
|
+
yes?: boolean;
|
|
23
|
+
}
|
|
24
|
+
export interface ImportSb3Result {
|
|
25
|
+
archiveEntryCount: number;
|
|
26
|
+
assetCount: number;
|
|
27
|
+
changed: boolean;
|
|
28
|
+
differenceCounts: {
|
|
29
|
+
added: number;
|
|
30
|
+
modified: number;
|
|
31
|
+
removed: number;
|
|
32
|
+
} | null;
|
|
33
|
+
embeddedExtensionCount: number;
|
|
34
|
+
inputPath: string;
|
|
35
|
+
outputDirectory: string;
|
|
36
|
+
rollbackCleanupWarning: string | null;
|
|
37
|
+
}
|
|
38
|
+
export declare function decodeExtensionDataUrl(dataUrl: unknown): DecodedExtensionDataUrl;
|
|
39
|
+
export declare function importSb3({ inputPath, outputDirectory, protectedRoot, discardLocalChanges, yes, confirmReplace, }: ImportSb3Options): Promise<ImportSb3Result>;
|