@kubohiroya/sb3-toolchain 0.11.0 → 0.13.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.
Files changed (87) hide show
  1. package/CHANGELOG.md +30 -4
  2. package/README.ja.md +17 -1
  3. package/README.md +17 -1
  4. package/dist/archive.d.ts +1 -0
  5. package/dist/archive.js +16 -0
  6. package/dist/archive.js.map +1 -0
  7. package/dist/assert.d.ts +2 -0
  8. package/dist/assert.js +11 -0
  9. package/dist/assert.js.map +1 -0
  10. package/dist/bin.d.ts +1 -0
  11. package/dist/bin.js +12 -0
  12. package/dist/bin.js.map +1 -0
  13. package/dist/build.d.ts +23 -0
  14. package/dist/build.js +111 -0
  15. package/dist/build.js.map +1 -0
  16. package/dist/cli.d.ts +87 -0
  17. package/dist/cli.js +544 -0
  18. package/dist/cli.js.map +1 -0
  19. package/dist/constants.d.ts +2 -0
  20. package/dist/constants.js +7 -0
  21. package/dist/constants.js.map +1 -0
  22. package/dist/extension-api-manifest.d.ts +65 -0
  23. package/dist/extension-api-manifest.js +231 -0
  24. package/dist/extension-api-manifest.js.map +1 -0
  25. package/dist/extension-bundle-archive.d.ts +36 -0
  26. package/dist/extension-bundle-archive.js +302 -0
  27. package/dist/extension-bundle-archive.js.map +1 -0
  28. package/dist/extension-bundle-configuration.d.ts +55 -0
  29. package/dist/extension-bundle-configuration.js +200 -0
  30. package/dist/extension-bundle-configuration.js.map +1 -0
  31. package/dist/extension-bundle.d.ts +39 -0
  32. package/dist/extension-bundle.js +580 -0
  33. package/dist/extension-bundle.js.map +1 -0
  34. package/dist/extension-dependencies.d.ts +18 -0
  35. package/dist/extension-dependencies.js +59 -0
  36. package/dist/extension-dependencies.js.map +1 -0
  37. package/dist/extension-id-migration.d.ts +83 -0
  38. package/dist/extension-id-migration.js +292 -0
  39. package/dist/extension-id-migration.js.map +1 -0
  40. package/dist/extension-sync.d.ts +111 -0
  41. package/dist/extension-sync.js +463 -0
  42. package/dist/extension-sync.js.map +1 -0
  43. package/dist/import.d.ts +39 -0
  44. package/dist/import.js +244 -0
  45. package/dist/import.js.map +1 -0
  46. package/dist/index.d.ts +31 -0
  47. package/dist/index.js +18 -0
  48. package/dist/npm-extension-source.d.ts +13 -0
  49. package/dist/npm-extension-source.js +63 -0
  50. package/dist/npm-extension-source.js.map +1 -0
  51. package/dist/output-safety.d.ts +29 -0
  52. package/dist/output-safety.js +213 -0
  53. package/dist/output-safety.js.map +1 -0
  54. package/dist/project-asset-additions.d.ts +29 -0
  55. package/dist/project-asset-additions.js +412 -0
  56. package/dist/project-asset-additions.js.map +1 -0
  57. package/dist/release-snapshot.d.ts +75 -0
  58. package/dist/release-snapshot.js +177 -0
  59. package/dist/release-snapshot.js.map +1 -0
  60. package/dist/source.d.ts +41 -0
  61. package/dist/source.js +282 -0
  62. package/dist/source.js.map +1 -0
  63. package/dist/turbowarp-clean-up.d.ts +18 -0
  64. package/dist/turbowarp-clean-up.js +266 -0
  65. package/dist/turbowarp-clean-up.js.map +1 -0
  66. package/dist/types.d.ts +80 -0
  67. package/package.json +31 -20
  68. package/bin/sb3-toolchain.mjs +0 -9
  69. package/src/archive.js +0 -35
  70. package/src/build.js +0 -188
  71. package/src/cli.js +0 -748
  72. package/src/constants.js +0 -4
  73. package/src/extension-api-manifest.js +0 -336
  74. package/src/extension-bundle-archive.js +0 -422
  75. package/src/extension-bundle-configuration.js +0 -265
  76. package/src/extension-bundle.js +0 -695
  77. package/src/extension-dependencies.js +0 -114
  78. package/src/extension-id-migration.js +0 -496
  79. package/src/extension-sync.js +0 -754
  80. package/src/import.js +0 -397
  81. package/src/index.js +0 -75
  82. package/src/npm-extension-source.js +0 -111
  83. package/src/output-safety.js +0 -322
  84. package/src/project-asset-additions.js +0 -560
  85. package/src/release-snapshot.js +0 -247
  86. package/src/source.js +0 -468
  87. package/src/turbowarp-clean-up.js +0 -295
@@ -0,0 +1,412 @@
1
+ import { assert } from "./assert.js";
2
+ import path from "node:path";
3
+ import { createHash } from "node:crypto";
4
+ import { lstat, readFile, realpath } from "node:fs/promises";
5
+ import { parseBuffer } from "music-metadata";
6
+ import { isAlias, isPair, parseAllDocuments, visit } from "yaml";
7
+ //#region src/project-asset-additions.ts
8
+ var projectAssetAdditionsFormatVersion = 1;
9
+ var maximumManifestBytes = 1048576;
10
+ var forbiddenMappingKeys = /* @__PURE__ */ new Set([
11
+ "__proto__",
12
+ "constructor",
13
+ "prototype"
14
+ ]);
15
+ var lockedAssetKeys = /* @__PURE__ */ new Set([
16
+ "name",
17
+ "file",
18
+ "size",
19
+ "sha256",
20
+ "dataFormat",
21
+ "license"
22
+ ]);
23
+ var imageAssetKeys = /* @__PURE__ */ new Set([
24
+ ...lockedAssetKeys,
25
+ "kind",
26
+ "target",
27
+ "bitmapResolution",
28
+ "rotationCenterX",
29
+ "rotationCenterY"
30
+ ]);
31
+ var soundAssetKeys = /* @__PURE__ */ new Set([
32
+ ...lockedAssetKeys,
33
+ "kind",
34
+ "target",
35
+ "rate",
36
+ "sampleCount"
37
+ ]);
38
+ var imageFormats = /* @__PURE__ */ new Set([
39
+ "svg",
40
+ "png",
41
+ "jpg",
42
+ "jpeg",
43
+ "gif"
44
+ ]);
45
+ var soundFormats = /* @__PURE__ */ new Map([["wav", "audio/wav"], ["mp3", "audio/mpeg"]]);
46
+ function isRecord(value) {
47
+ return typeof value === "object" && value !== null && !Array.isArray(value);
48
+ }
49
+ function exactKeys(value, allowed, description) {
50
+ const unknown = Object.keys(value).filter((key) => !allowed.has(key));
51
+ assert(unknown.length === 0, `${description} has unknown properties: ${unknown.join(", ")}`);
52
+ }
53
+ function nonEmptyString(value, description) {
54
+ assert(typeof value === "string" && value.length > 0 && value === value.normalize("NFC") && !/[\u0000-\u001f\u007f]/u.test(value), `${description} must be a non-empty NFC string without control characters.`);
55
+ assert(!forbiddenMappingKeys.has(value), `${description} is not supported: ${value}`);
56
+ return value;
57
+ }
58
+ function finiteNumber(value, description) {
59
+ assert(typeof value === "number" && Number.isFinite(value), `${description} must be finite.`);
60
+ return value;
61
+ }
62
+ function safeInteger(value, description, minimum = 0) {
63
+ assert(typeof value === "number" && Number.isSafeInteger(value) && value >= minimum, `${description} must be a safe integer greater than or equal to ${minimum}.`);
64
+ return value;
65
+ }
66
+ function sha256(contents) {
67
+ return createHash("sha256").update(contents).digest("hex");
68
+ }
69
+ function md5(contents) {
70
+ return createHash("md5").update(contents).digest("hex");
71
+ }
72
+ function parseRestrictedYaml(source, manifestPath) {
73
+ const documents = parseAllDocuments(source, {
74
+ prettyErrors: false,
75
+ strict: true,
76
+ uniqueKeys: true,
77
+ version: "1.2"
78
+ });
79
+ const parserIssues = documents.flatMap((document) => [...document.errors, ...document.warnings]);
80
+ assert(parserIssues.length === 0, `Project asset additions manifest is not valid YAML: ${manifestPath} (${parserIssues[0]?.message})`);
81
+ assert(documents.length === 1, `Project asset additions manifest must contain exactly one YAML document: ${manifestPath}`);
82
+ let restrictedFeature;
83
+ visit(documents[0], (_key, node) => {
84
+ if (restrictedFeature) return visit.BREAK;
85
+ const yamlNode = node;
86
+ if (isAlias(node) || yamlNode?.anchor) restrictedFeature = "aliases and anchors";
87
+ else if (isPair(node) && yamlNode?.key?.value === "<<") restrictedFeature = "merge keys";
88
+ else if (yamlNode?.tag) restrictedFeature = "custom tags";
89
+ else if (isPair(node) && forbiddenMappingKeys.has(String(yamlNode?.key?.value))) restrictedFeature = `mapping key ${String(yamlNode?.key?.value)}`;
90
+ });
91
+ assert(!restrictedFeature, `Project asset additions YAML does not support ${restrictedFeature}: ${manifestPath}`);
92
+ return documents[0].toJS({ maxAliasCount: 0 });
93
+ }
94
+ async function readManifestFile(filePath) {
95
+ let stats;
96
+ try {
97
+ stats = await lstat(filePath);
98
+ } catch (error) {
99
+ throw new Error(`Project asset additions manifest is not readable: ${filePath}`, { cause: error });
100
+ }
101
+ assert(stats.isFile() && !stats.isSymbolicLink(), `Project asset additions manifest must be a regular file, not a symbolic link: ${filePath}`);
102
+ assert(stats.size <= maximumManifestBytes, `Project asset additions manifest exceeds ${maximumManifestBytes} bytes: ${filePath}`);
103
+ const source = await readFile(filePath, "utf8");
104
+ const extension = path.extname(filePath).toLowerCase();
105
+ assert(extension === ".json" || extension === ".yml" || extension === ".yaml", `Project asset additions manifest must use .json, .yml, or .yaml: ${filePath}`);
106
+ if (extension === ".json") {
107
+ let value;
108
+ try {
109
+ value = JSON.parse(source);
110
+ } catch (error) {
111
+ throw new Error(`Project asset additions manifest is not valid JSON: ${filePath}`, { cause: error });
112
+ }
113
+ parseRestrictedYaml(source, filePath);
114
+ return value;
115
+ }
116
+ return parseRestrictedYaml(source, filePath);
117
+ }
118
+ function isContained(root, candidate) {
119
+ const relative = path.relative(root, candidate);
120
+ return relative === "" || !relative.startsWith(`..${path.sep}`) && relative !== "..";
121
+ }
122
+ async function validateAllowedRoots(manifestDirectory, allowedAssetRoots) {
123
+ assert(Array.isArray(allowedAssetRoots), "allowedAssetRoots must be an array.");
124
+ const roots = [manifestDirectory, ...allowedAssetRoots].map((root) => {
125
+ assert(typeof root === "string", "Every allowed project asset root must be a string.");
126
+ return path.resolve(root);
127
+ });
128
+ const uniqueRoots = [...new Set(roots)];
129
+ return Promise.all(uniqueRoots.map(async (root) => {
130
+ const stats = await lstat(root);
131
+ assert(stats.isDirectory() && !stats.isSymbolicLink(), `Allowed project asset root must be a directory, not a symbolic link: ${root}`);
132
+ return {
133
+ lexical: root,
134
+ real: await realpath(root)
135
+ };
136
+ }));
137
+ }
138
+ async function assertNoSymlinkPath(root, candidate, description) {
139
+ const relative = path.relative(root, candidate);
140
+ assert(isContained(root, candidate), `${description} escapes its allowed root: ${candidate}`);
141
+ let current = root;
142
+ for (const segment of relative.split(path.sep).filter(Boolean)) {
143
+ current = path.join(current, segment);
144
+ const stats = await lstat(current);
145
+ assert(!stats.isSymbolicLink(), `${description} must not traverse a symbolic link: ${current}`);
146
+ }
147
+ }
148
+ async function readAssetFile(manifestDirectory, allowedRoots, specification, description) {
149
+ const file = nonEmptyString(specification.file, `${description}.file`);
150
+ assert(!path.isAbsolute(file) && !file.includes("\\"), `${description}.file must be relative.`);
151
+ const resolved = path.resolve(manifestDirectory, file);
152
+ const lexicalRoot = allowedRoots.find(({ lexical }) => isContained(lexical, resolved));
153
+ assert(lexicalRoot, `${description}.file is outside the allowed project asset roots: ${file}`);
154
+ await assertNoSymlinkPath(lexicalRoot.lexical, resolved, `${description}.file`);
155
+ const stats = await lstat(resolved);
156
+ assert(stats.isFile(), `${description}.file must be a regular file: ${resolved}`);
157
+ const resolvedRealPath = await realpath(resolved);
158
+ assert(allowedRoots.some(({ real }) => isContained(real, resolvedRealPath)), `${description}.file resolves outside the allowed project asset roots: ${file}`);
159
+ const contents = await readFile(resolved);
160
+ if (specification.size !== void 0) {
161
+ const expectedSize = safeInteger(specification.size, `${description}.size`);
162
+ assert(contents.length === expectedSize, `${description}.size differs: expected ${expectedSize}, got ${contents.length}`);
163
+ }
164
+ if (specification.sha256 !== void 0) {
165
+ assert(typeof specification.sha256 === "string" && /^[a-f0-9]{64}$/u.test(specification.sha256), `${description}.sha256 must be a lowercase SHA-256 hex digest.`);
166
+ const actualSha256 = sha256(contents);
167
+ assert(actualSha256 === specification.sha256, `${description}.sha256 differs: expected ${specification.sha256}, got ${actualSha256}`);
168
+ }
169
+ const inferredDataFormat = path.extname(file).slice(1).toLowerCase();
170
+ assert(/^[a-z0-9]+$/u.test(inferredDataFormat), `${description}.file extension is invalid: ${file}`);
171
+ if (specification.dataFormat !== void 0) {
172
+ const expectedDataFormat = nonEmptyString(specification.dataFormat, `${description}.dataFormat`);
173
+ assert(expectedDataFormat === inferredDataFormat, `${description}.dataFormat differs: expected ${expectedDataFormat}, got ${inferredDataFormat}`);
174
+ }
175
+ if (specification.license !== void 0) nonEmptyString(specification.license, `${description}.license`);
176
+ return {
177
+ contents,
178
+ dataFormat: inferredDataFormat,
179
+ file,
180
+ name: specification.name
181
+ };
182
+ }
183
+ async function inferSoundMetadata(contents, dataFormat, description) {
184
+ const mimeType = soundFormats.get(dataFormat);
185
+ assert(mimeType, `${description}.file uses unsupported sound format: ${dataFormat}`);
186
+ let metadata;
187
+ try {
188
+ metadata = await parseBuffer(contents, {
189
+ mimeType,
190
+ size: contents.length
191
+ }, {
192
+ duration: true,
193
+ skipCovers: true
194
+ });
195
+ } catch (error) {
196
+ throw new Error(`${description}.file is not valid ${dataFormat} audio.`, { cause: error });
197
+ }
198
+ const rate = metadata.format.sampleRate;
199
+ const sampleCount = metadata.format.numberOfSamples ?? (typeof metadata.format.duration === "number" && typeof rate === "number" ? Math.round(metadata.format.duration * rate) : void 0);
200
+ return {
201
+ rate: safeInteger(rate, `${description} inferred sample rate`, 1),
202
+ sampleCount: safeInteger(sampleCount, `${description} inferred sample count`)
203
+ };
204
+ }
205
+ function validateSprite(specification, name) {
206
+ const description = `Project asset sprite ${JSON.stringify(name)}`;
207
+ assert(isRecord(specification), `${description} must be an object.`);
208
+ exactKeys(specification, /* @__PURE__ */ new Set([
209
+ "layerOrder",
210
+ "visible",
211
+ "x",
212
+ "y",
213
+ "size",
214
+ "direction",
215
+ "draggable",
216
+ "rotationStyle",
217
+ "volume"
218
+ ]), description);
219
+ const layerOrder = safeInteger(specification.layerOrder, `${description}.layerOrder`);
220
+ assert(typeof specification.visible === "boolean", `${description}.visible must be boolean.`);
221
+ const x = finiteNumber(specification.x, `${description}.x`);
222
+ const y = finiteNumber(specification.y, `${description}.y`);
223
+ const size = finiteNumber(specification.size, `${description}.size`);
224
+ assert(size > 0, `${description}.size must be greater than zero.`);
225
+ const direction = finiteNumber(specification.direction, `${description}.direction`);
226
+ assert(typeof specification.draggable === "boolean", `${description}.draggable must be boolean.`);
227
+ const rotationStyle = specification.rotationStyle;
228
+ assert(rotationStyle === "all around" || rotationStyle === "left-right" || rotationStyle === "don't rotate", `${description}.rotationStyle is invalid: ${String(rotationStyle)}`);
229
+ const volume = finiteNumber(specification.volume, `${description}.volume`);
230
+ assert(volume >= 0 && volume <= 100, `${description}.volume must be between 0 and 100.`);
231
+ return {
232
+ direction,
233
+ draggable: specification.draggable,
234
+ layerOrder,
235
+ rotationStyle,
236
+ size,
237
+ visible: specification.visible,
238
+ volume,
239
+ x,
240
+ y
241
+ };
242
+ }
243
+ function validateAsset(specification, assetId) {
244
+ const description = `Project asset ${JSON.stringify(assetId)}`;
245
+ assert(isRecord(specification), `${description} must be an object.`);
246
+ assert(specification.kind === "backdrop" || specification.kind === "costume" || specification.kind === "sound", `${description}.kind must be backdrop, costume, or sound.`);
247
+ exactKeys(specification, specification.kind === "sound" ? soundAssetKeys : imageAssetKeys, description);
248
+ if (specification.kind === "backdrop") assert(specification.target === void 0, `${description}.target is not valid for a backdrop.`);
249
+ else if (specification.kind === "costume") nonEmptyString(specification.target, `${description}.target`);
250
+ else if (specification.target !== void 0) nonEmptyString(specification.target, `${description}.target`);
251
+ if (specification.name !== void 0) nonEmptyString(specification.name, `${description}.name`);
252
+ return {
253
+ description,
254
+ specification
255
+ };
256
+ }
257
+ function addAssetContents(assetContents, archiveEntries, contents, filename, description) {
258
+ const existing = assetContents.get(filename);
259
+ if (existing) {
260
+ assert(Buffer.from(existing).equals(contents), `${description} collides with different contents: ${filename}`);
261
+ return false;
262
+ }
263
+ assetContents.set(filename, contents);
264
+ archiveEntries.push(filename);
265
+ return true;
266
+ }
267
+ /**
268
+ * Validate a JSON or YAML project-assets manifest and compose it into one in-memory build.
269
+ * The expanded source and all manifest inputs remain unchanged.
270
+ */
271
+ async function applyProjectAssetAdditions({ allowedAssetRoots = [], assetContents, archiveEntries, manifestPath, project }) {
272
+ assert(typeof manifestPath === "string", "projectAssetsPath must be a string.");
273
+ assert(isRecord(project), "Project asset additions require a project object.");
274
+ assert(assetContents instanceof Map, "Project asset additions require an asset contents Map.");
275
+ assert(Array.isArray(archiveEntries), "Project asset additions require archive entries.");
276
+ const resolvedManifestPath = path.resolve(manifestPath);
277
+ const manifestDirectory = path.dirname(resolvedManifestPath);
278
+ const [manifest, allowedRoots] = await Promise.all([readManifestFile(resolvedManifestPath), validateAllowedRoots(manifestDirectory, allowedAssetRoots)]);
279
+ assert(isRecord(manifest), "Project asset additions manifest must be an object.");
280
+ exactKeys(manifest, /* @__PURE__ */ new Set([
281
+ "formatVersion",
282
+ "sprites",
283
+ "assets"
284
+ ]), "Project asset additions manifest");
285
+ assert(manifest.formatVersion === 1, `Unsupported project asset additions formatVersion: ${manifest.formatVersion}`);
286
+ assert(manifest.sprites === void 0 || isRecord(manifest.sprites), "Project asset additions sprites must be an object when present.");
287
+ assert(isRecord(manifest.assets) && Object.keys(manifest.assets).length > 0, "Project asset additions assets must be a non-empty object.");
288
+ assert(Array.isArray(project.targets), "Project asset additions require project.targets.");
289
+ const composedProject = structuredClone(project);
290
+ const composedTargets = composedProject.targets;
291
+ const composedAssetContents = new Map(assetContents);
292
+ const composedArchiveEntries = [...archiveEntries];
293
+ const targetByName = /* @__PURE__ */ new Map();
294
+ for (const target of composedTargets) {
295
+ assert(isRecord(target), "Existing project target must be an object.");
296
+ const targetName = nonEmptyString(target.name, "Existing project target name");
297
+ assert(!targetByName.has(targetName), `Project has duplicate target name: ${targetName}`);
298
+ assert(Array.isArray(target.costumes), `Project target ${targetName}.costumes must be an array.`);
299
+ assert(Array.isArray(target.sounds), `Project target ${targetName}.sounds must be an array.`);
300
+ targetByName.set(targetName, target);
301
+ }
302
+ const stages = composedTargets.filter(({ isStage }) => isStage);
303
+ assert(stages.length === 1, "Project asset additions require exactly one Stage target.");
304
+ const stage = stages[0];
305
+ const newSpriteNames = [];
306
+ for (const [rawName, rawSprite] of Object.entries(manifest.sprites ?? {})) {
307
+ const name = nonEmptyString(rawName, "Project asset sprite name");
308
+ const specification = validateSprite(rawSprite, name);
309
+ assert(!targetByName.has(name), `Project asset sprite already exists in the project: ${name}`);
310
+ const target = {
311
+ isStage: false,
312
+ name,
313
+ variables: {},
314
+ lists: {},
315
+ broadcasts: {},
316
+ blocks: {},
317
+ comments: {},
318
+ currentCostume: 0,
319
+ costumes: [],
320
+ sounds: [],
321
+ volume: specification.volume,
322
+ layerOrder: specification.layerOrder,
323
+ visible: specification.visible,
324
+ x: specification.x,
325
+ y: specification.y,
326
+ size: specification.size,
327
+ direction: specification.direction,
328
+ draggable: specification.draggable,
329
+ rotationStyle: specification.rotationStyle
330
+ };
331
+ composedTargets.push(target);
332
+ targetByName.set(name, target);
333
+ newSpriteNames.push(name);
334
+ }
335
+ let backdropCount = 0;
336
+ let costumeCount = 0;
337
+ let soundCount = 0;
338
+ let assetFileCount = 0;
339
+ for (const [rawAssetId, rawSpecification] of Object.entries(manifest.assets)) {
340
+ const assetId = nonEmptyString(rawAssetId, "Project asset ID");
341
+ const { description, specification } = validateAsset(rawSpecification, assetId);
342
+ const asset = await readAssetFile(manifestDirectory, allowedRoots, specification, description);
343
+ if (specification.kind !== "sound") assert(imageFormats.has(asset.dataFormat), `${description}.file uses unsupported image format: ${asset.dataFormat}`);
344
+ const scratchName = asset.name ?? assetId;
345
+ const owner = specification.kind === "backdrop" || specification.target === void 0 ? stage : targetByName.get(specification.target);
346
+ assert(owner, `${description}.target does not exist in the project: ${specification.target}`);
347
+ assert(specification.kind === "backdrop" || !owner.isStage || specification.kind === "sound", `${description}.target must name a sprite.`);
348
+ assert(specification.kind !== "sound" || specification.target === void 0 || !owner.isStage, `${description}.target must be omitted for a Stage sound.`);
349
+ const collection = specification.kind === "sound" ? owner.sounds : owner.costumes;
350
+ assert(!collection.some(({ name }) => name === scratchName), `${description}.name already exists on target ${owner.name}: ${scratchName}`);
351
+ const contentAssetId = md5(asset.contents);
352
+ const filename = `${contentAssetId}.${asset.dataFormat}`;
353
+ if (addAssetContents(composedAssetContents, composedArchiveEntries, asset.contents, filename, description)) assetFileCount += 1;
354
+ if (specification.kind === "sound") {
355
+ const inferred = await inferSoundMetadata(asset.contents, asset.dataFormat, description);
356
+ if (specification.rate !== void 0) {
357
+ const expectedRate = safeInteger(specification.rate, `${description}.rate`, 1);
358
+ assert(inferred.rate === expectedRate, `${description}.rate differs: expected ${expectedRate}, got ${inferred.rate}`);
359
+ }
360
+ if (specification.sampleCount !== void 0) {
361
+ const expectedSampleCount = safeInteger(specification.sampleCount, `${description}.sampleCount`);
362
+ assert(inferred.sampleCount === expectedSampleCount, `${description}.sampleCount differs: expected ${expectedSampleCount}, got ${inferred.sampleCount}`);
363
+ }
364
+ collection.push({
365
+ name: scratchName,
366
+ assetId: contentAssetId,
367
+ dataFormat: asset.dataFormat,
368
+ format: "",
369
+ md5ext: filename,
370
+ rate: inferred.rate,
371
+ sampleCount: inferred.sampleCount
372
+ });
373
+ soundCount += 1;
374
+ } else {
375
+ const bitmapResolution = specification.bitmapResolution === void 0 ? 1 : safeInteger(specification.bitmapResolution, `${description}.bitmapResolution`, 1);
376
+ assert(bitmapResolution === 1 || bitmapResolution === 2, `${description}.bitmapResolution must be 1 or 2.`);
377
+ collection.push({
378
+ name: scratchName,
379
+ bitmapResolution,
380
+ dataFormat: asset.dataFormat,
381
+ assetId: contentAssetId,
382
+ md5ext: filename,
383
+ rotationCenterX: finiteNumber(specification.rotationCenterX, `${description}.rotationCenterX`),
384
+ rotationCenterY: finiteNumber(specification.rotationCenterY, `${description}.rotationCenterY`)
385
+ });
386
+ if (specification.kind === "backdrop") backdropCount += 1;
387
+ else costumeCount += 1;
388
+ }
389
+ }
390
+ for (const name of newSpriteNames) {
391
+ const costumes = targetByName.get(name)?.costumes;
392
+ assert(Array.isArray(costumes) && costumes.length > 0, `Project asset sprite must receive at least one costume: ${name}`);
393
+ }
394
+ return {
395
+ archiveEntries: composedArchiveEntries,
396
+ assetContents: composedAssetContents,
397
+ assetReferenceCount: backdropCount + costumeCount + soundCount,
398
+ manifestPath: resolvedManifestPath,
399
+ project: composedProject,
400
+ summary: Object.freeze({
401
+ assetFileCount,
402
+ backdropCount,
403
+ costumeCount,
404
+ soundCount,
405
+ spriteCount: newSpriteNames.length
406
+ })
407
+ };
408
+ }
409
+ //#endregion
410
+ export { applyProjectAssetAdditions, projectAssetAdditionsFormatVersion };
411
+
412
+ //# sourceMappingURL=project-asset-additions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"project-asset-additions.js","names":[],"sources":["../src/project-asset-additions.ts"],"sourcesContent":["// SPDX-License-Identifier: MPL-2.0\n\nimport {createHash} from 'node:crypto';\nimport type {Stats} from 'node:fs';\nimport {lstat, readFile, realpath} from 'node:fs/promises';\nimport path from 'node:path';\n\nimport {parseBuffer} from 'music-metadata';\nimport {isAlias, isPair, parseAllDocuments, visit} from 'yaml';\n\nimport {assert} from './assert';\nimport type {ProjectJson, UnknownRecord} from './types';\n\nexport const projectAssetAdditionsFormatVersion = 1;\n\ninterface AllowedAssetRoot {\n lexical: string;\n real: string;\n}\n\ninterface SpriteSpecification {\n direction: number;\n draggable: boolean;\n layerOrder: number;\n rotationStyle: string;\n size: number;\n visible: boolean;\n volume: number;\n x: number;\n y: number;\n}\n\ninterface AssetSpecification {\n bitmapResolution?: unknown;\n dataFormat?: unknown;\n file?: unknown;\n kind: 'backdrop' | 'costume' | 'sound';\n license?: unknown;\n name?: string;\n rate?: unknown;\n rotationCenterX?: unknown;\n rotationCenterY?: unknown;\n sampleCount?: unknown;\n sha256?: unknown;\n size?: unknown;\n target?: string;\n}\n\ninterface ResolvedAssetFile {\n contents: Buffer;\n dataFormat: string;\n file: string;\n name: string | undefined;\n}\n\nexport interface ProjectAssetAdditionsSummary {\n assetFileCount: number;\n backdropCount: number;\n costumeCount: number;\n soundCount: number;\n spriteCount: number;\n}\n\nexport interface ProjectAssetAdditionsInput {\n allowedAssetRoots?: string[];\n archiveEntries: string[];\n assetContents: Map<string, Uint8Array>;\n manifestPath: string;\n project: ProjectJson;\n}\n\nexport interface ProjectAssetAdditionsResult {\n archiveEntries: string[];\n assetContents: Map<string, Uint8Array>;\n assetReferenceCount: number;\n manifestPath: string;\n project: ProjectJson;\n summary: Readonly<ProjectAssetAdditionsSummary>;\n}\n\nconst maximumManifestBytes = 1024 * 1024;\nconst forbiddenMappingKeys = new Set(['__proto__', 'constructor', 'prototype']);\nconst lockedAssetKeys = new Set(['name', 'file', 'size', 'sha256', 'dataFormat', 'license']);\nconst imageAssetKeys = new Set([\n ...lockedAssetKeys,\n 'kind',\n 'target',\n 'bitmapResolution',\n 'rotationCenterX',\n 'rotationCenterY',\n]);\nconst soundAssetKeys = new Set([...lockedAssetKeys, 'kind', 'target', 'rate', 'sampleCount']);\nconst imageFormats = new Set(['svg', 'png', 'jpg', 'jpeg', 'gif']);\nconst soundFormats = new Map([\n ['wav', 'audio/wav'],\n ['mp3', 'audio/mpeg'],\n]);\n\nfunction isRecord(value: unknown): value is UnknownRecord {\n return typeof value === 'object' && value !== null && !Array.isArray(value);\n}\n\nfunction exactKeys(value: UnknownRecord, allowed: Set<string>, description: string): void {\n const unknown = Object.keys(value).filter((key) => !allowed.has(key));\n assert(unknown.length === 0, `${description} has unknown properties: ${unknown.join(', ')}`);\n}\n\nfunction nonEmptyString(value: unknown, description: string): string {\n assert(\n typeof value === 'string' &&\n value.length > 0 &&\n value === value.normalize('NFC') &&\n !/[\\u0000-\\u001f\\u007f]/u.test(value),\n `${description} must be a non-empty NFC string without control characters.`,\n );\n assert(!forbiddenMappingKeys.has(value), `${description} is not supported: ${value}`);\n return value;\n}\n\nfunction finiteNumber(value: unknown, description: string): number {\n assert(typeof value === 'number' && Number.isFinite(value), `${description} must be finite.`);\n return value;\n}\n\nfunction safeInteger(value: unknown, description: string, minimum = 0): number {\n assert(\n typeof value === 'number' && Number.isSafeInteger(value) && value >= minimum,\n `${description} must be a safe integer greater than or equal to ${minimum}.`,\n );\n return value;\n}\n\nfunction sha256(contents: Uint8Array | string): string {\n return createHash('sha256').update(contents).digest('hex');\n}\n\nfunction md5(contents: Uint8Array | string): string {\n return createHash('md5').update(contents).digest('hex');\n}\n\nfunction parseRestrictedYaml(source: string, manifestPath: string): unknown {\n const documents = parseAllDocuments(source, {\n prettyErrors: false,\n strict: true,\n uniqueKeys: true,\n version: '1.2',\n });\n const parserIssues = documents.flatMap((document) => [...document.errors, ...document.warnings]);\n assert(\n parserIssues.length === 0,\n `Project asset additions manifest is not valid YAML: ${manifestPath} ` +\n `(${parserIssues[0]?.message})`,\n );\n assert(\n documents.length === 1,\n `Project asset additions manifest must contain exactly one YAML document: ${manifestPath}`,\n );\n let restrictedFeature: string | undefined;\n visit(documents[0], (_key, node) => {\n if (restrictedFeature) return visit.BREAK;\n const yamlNode = node as {anchor?: unknown; key?: {value?: unknown}; tag?: unknown} | null;\n if (isAlias(node) || yamlNode?.anchor) restrictedFeature = 'aliases and anchors';\n else if (isPair(node) && yamlNode?.key?.value === '<<') restrictedFeature = 'merge keys';\n else if (yamlNode?.tag) restrictedFeature = 'custom tags';\n else if (isPair(node) && forbiddenMappingKeys.has(String(yamlNode?.key?.value))) {\n restrictedFeature = `mapping key ${String(yamlNode?.key?.value)}`;\n }\n return undefined;\n });\n assert(\n !restrictedFeature,\n `Project asset additions YAML does not support ${restrictedFeature}: ${manifestPath}`,\n );\n return documents[0].toJS({maxAliasCount: 0});\n}\n\nasync function readManifestFile(filePath: string): Promise<unknown> {\n let stats: Stats;\n try {\n stats = await lstat(filePath);\n } catch (error) {\n throw new Error(`Project asset additions manifest is not readable: ${filePath}`, {\n cause: error,\n });\n }\n assert(\n stats.isFile() && !stats.isSymbolicLink(),\n `Project asset additions manifest must be a regular file, not a symbolic link: ${filePath}`,\n );\n assert(\n stats.size <= maximumManifestBytes,\n `Project asset additions manifest exceeds ${maximumManifestBytes} bytes: ${filePath}`,\n );\n const source = await readFile(filePath, 'utf8');\n const extension = path.extname(filePath).toLowerCase();\n assert(\n extension === '.json' || extension === '.yml' || extension === '.yaml',\n `Project asset additions manifest must use .json, .yml, or .yaml: ${filePath}`,\n );\n if (extension === '.json') {\n let value: unknown;\n try {\n value = JSON.parse(source);\n } catch (error) {\n throw new Error(`Project asset additions manifest is not valid JSON: ${filePath}`, {\n cause: error,\n });\n }\n parseRestrictedYaml(source, filePath);\n return value;\n }\n return parseRestrictedYaml(source, filePath);\n}\n\nfunction isContained(root: string, candidate: string): boolean {\n const relative = path.relative(root, candidate);\n return relative === '' || (!relative.startsWith(`..${path.sep}`) && relative !== '..');\n}\n\nasync function validateAllowedRoots(\n manifestDirectory: string,\n allowedAssetRoots: unknown,\n): Promise<AllowedAssetRoot[]> {\n assert(Array.isArray(allowedAssetRoots), 'allowedAssetRoots must be an array.');\n const roots = [manifestDirectory, ...(allowedAssetRoots as unknown[])].map((root) => {\n assert(typeof root === 'string', 'Every allowed project asset root must be a string.');\n return path.resolve(root);\n });\n const uniqueRoots = [...new Set(roots)];\n return Promise.all(\n uniqueRoots.map(async (root) => {\n const stats = await lstat(root);\n assert(\n stats.isDirectory() && !stats.isSymbolicLink(),\n `Allowed project asset root must be a directory, not a symbolic link: ${root}`,\n );\n return {lexical: root, real: await realpath(root)};\n }),\n );\n}\n\nasync function assertNoSymlinkPath(\n root: string,\n candidate: string,\n description: string,\n): Promise<void> {\n const relative = path.relative(root, candidate);\n assert(isContained(root, candidate), `${description} escapes its allowed root: ${candidate}`);\n let current = root;\n for (const segment of relative.split(path.sep).filter(Boolean)) {\n current = path.join(current, segment);\n const stats = await lstat(current);\n assert(!stats.isSymbolicLink(), `${description} must not traverse a symbolic link: ${current}`);\n }\n}\n\nasync function readAssetFile(\n manifestDirectory: string,\n allowedRoots: AllowedAssetRoot[],\n specification: AssetSpecification,\n description: string,\n): Promise<ResolvedAssetFile> {\n const file = nonEmptyString(specification.file, `${description}.file`);\n assert(!path.isAbsolute(file) && !file.includes('\\\\'), `${description}.file must be relative.`);\n const resolved = path.resolve(manifestDirectory, file);\n const lexicalRoot = allowedRoots.find(({lexical}) => isContained(lexical, resolved));\n assert(lexicalRoot, `${description}.file is outside the allowed project asset roots: ${file}`);\n await assertNoSymlinkPath(lexicalRoot.lexical, resolved, `${description}.file`);\n const stats = await lstat(resolved);\n assert(stats.isFile(), `${description}.file must be a regular file: ${resolved}`);\n const resolvedRealPath = await realpath(resolved);\n assert(\n allowedRoots.some(({real}) => isContained(real, resolvedRealPath)),\n `${description}.file resolves outside the allowed project asset roots: ${file}`,\n );\n const contents = await readFile(resolved);\n if (specification.size !== undefined) {\n const expectedSize = safeInteger(specification.size, `${description}.size`);\n assert(\n contents.length === expectedSize,\n `${description}.size differs: expected ${expectedSize}, got ${contents.length}`,\n );\n }\n if (specification.sha256 !== undefined) {\n assert(\n typeof specification.sha256 === 'string' && /^[a-f0-9]{64}$/u.test(specification.sha256),\n `${description}.sha256 must be a lowercase SHA-256 hex digest.`,\n );\n const actualSha256 = sha256(contents);\n assert(\n actualSha256 === specification.sha256,\n `${description}.sha256 differs: expected ${specification.sha256}, got ${actualSha256}`,\n );\n }\n const inferredDataFormat = path.extname(file).slice(1).toLowerCase();\n assert(\n /^[a-z0-9]+$/u.test(inferredDataFormat),\n `${description}.file extension is invalid: ${file}`,\n );\n if (specification.dataFormat !== undefined) {\n const expectedDataFormat = nonEmptyString(\n specification.dataFormat,\n `${description}.dataFormat`,\n );\n assert(\n expectedDataFormat === inferredDataFormat,\n `${description}.dataFormat differs: expected ${expectedDataFormat}, got ${inferredDataFormat}`,\n );\n }\n if (specification.license !== undefined) {\n nonEmptyString(specification.license, `${description}.license`);\n }\n return {\n contents,\n dataFormat: inferredDataFormat,\n file,\n name: specification.name,\n };\n}\n\nasync function inferSoundMetadata(\n contents: Buffer,\n dataFormat: string,\n description: string,\n): Promise<{rate: number; sampleCount: number}> {\n const mimeType = soundFormats.get(dataFormat);\n assert(mimeType, `${description}.file uses unsupported sound format: ${dataFormat}`);\n let metadata: Awaited<ReturnType<typeof parseBuffer>>;\n try {\n metadata = await parseBuffer(\n contents,\n {mimeType, size: contents.length},\n {duration: true, skipCovers: true},\n );\n } catch (error) {\n throw new Error(`${description}.file is not valid ${dataFormat} audio.`, {cause: error});\n }\n const rate = metadata.format.sampleRate;\n const sampleCount =\n metadata.format.numberOfSamples ??\n (typeof metadata.format.duration === 'number' && typeof rate === 'number'\n ? Math.round(metadata.format.duration * rate)\n : undefined);\n return {\n rate: safeInteger(rate, `${description} inferred sample rate`, 1),\n sampleCount: safeInteger(sampleCount, `${description} inferred sample count`),\n };\n}\n\nfunction validateSprite(specification: unknown, name: string): SpriteSpecification {\n const description = `Project asset sprite ${JSON.stringify(name)}`;\n assert(isRecord(specification), `${description} must be an object.`);\n exactKeys(\n specification,\n new Set([\n 'layerOrder',\n 'visible',\n 'x',\n 'y',\n 'size',\n 'direction',\n 'draggable',\n 'rotationStyle',\n 'volume',\n ]),\n description,\n );\n const layerOrder = safeInteger(specification.layerOrder, `${description}.layerOrder`);\n assert(typeof specification.visible === 'boolean', `${description}.visible must be boolean.`);\n const x = finiteNumber(specification.x, `${description}.x`);\n const y = finiteNumber(specification.y, `${description}.y`);\n const size = finiteNumber(specification.size, `${description}.size`);\n assert(size > 0, `${description}.size must be greater than zero.`);\n const direction = finiteNumber(specification.direction, `${description}.direction`);\n assert(typeof specification.draggable === 'boolean', `${description}.draggable must be boolean.`);\n const rotationStyle = specification.rotationStyle;\n assert(\n rotationStyle === 'all around' ||\n rotationStyle === 'left-right' ||\n rotationStyle === \"don't rotate\",\n `${description}.rotationStyle is invalid: ${String(rotationStyle)}`,\n );\n const volume = finiteNumber(specification.volume, `${description}.volume`);\n assert(volume >= 0 && volume <= 100, `${description}.volume must be between 0 and 100.`);\n return {\n direction,\n draggable: specification.draggable,\n layerOrder,\n rotationStyle,\n size,\n visible: specification.visible,\n volume,\n x,\n y,\n };\n}\n\nfunction validateAsset(\n specification: unknown,\n assetId: string,\n): {description: string; specification: AssetSpecification} {\n const description = `Project asset ${JSON.stringify(assetId)}`;\n assert(isRecord(specification), `${description} must be an object.`);\n assert(\n specification.kind === 'backdrop' ||\n specification.kind === 'costume' ||\n specification.kind === 'sound',\n `${description}.kind must be backdrop, costume, or sound.`,\n );\n exactKeys(\n specification,\n specification.kind === 'sound' ? soundAssetKeys : imageAssetKeys,\n description,\n );\n if (specification.kind === 'backdrop') {\n assert(\n specification.target === undefined,\n `${description}.target is not valid for a backdrop.`,\n );\n } else if (specification.kind === 'costume') {\n nonEmptyString(specification.target, `${description}.target`);\n } else if (specification.target !== undefined) {\n nonEmptyString(specification.target, `${description}.target`);\n }\n if (specification.name !== undefined) nonEmptyString(specification.name, `${description}.name`);\n return {description, specification: specification as unknown as AssetSpecification};\n}\n\nfunction addAssetContents(\n assetContents: Map<string, Uint8Array>,\n archiveEntries: string[],\n contents: Buffer,\n filename: string,\n description: string,\n): boolean {\n const existing = assetContents.get(filename);\n if (existing) {\n assert(\n Buffer.from(existing).equals(contents),\n `${description} collides with different contents: ${filename}`,\n );\n return false;\n }\n assetContents.set(filename, contents);\n archiveEntries.push(filename);\n return true;\n}\n\n/**\n * Validate a JSON or YAML project-assets manifest and compose it into one in-memory build.\n * The expanded source and all manifest inputs remain unchanged.\n */\nexport async function applyProjectAssetAdditions({\n allowedAssetRoots = [],\n assetContents,\n archiveEntries,\n manifestPath,\n project,\n}: ProjectAssetAdditionsInput): Promise<ProjectAssetAdditionsResult> {\n assert(typeof manifestPath === 'string', 'projectAssetsPath must be a string.');\n assert(isRecord(project), 'Project asset additions require a project object.');\n assert(assetContents instanceof Map, 'Project asset additions require an asset contents Map.');\n assert(Array.isArray(archiveEntries), 'Project asset additions require archive entries.');\n const resolvedManifestPath = path.resolve(manifestPath);\n const manifestDirectory = path.dirname(resolvedManifestPath);\n const [manifest, allowedRoots] = await Promise.all([\n readManifestFile(resolvedManifestPath),\n validateAllowedRoots(manifestDirectory, allowedAssetRoots),\n ]);\n assert(isRecord(manifest), 'Project asset additions manifest must be an object.');\n exactKeys(\n manifest,\n new Set(['formatVersion', 'sprites', 'assets']),\n 'Project asset additions manifest',\n );\n assert(\n manifest.formatVersion === projectAssetAdditionsFormatVersion,\n `Unsupported project asset additions formatVersion: ${manifest.formatVersion}`,\n );\n assert(\n manifest.sprites === undefined || isRecord(manifest.sprites),\n 'Project asset additions sprites must be an object when present.',\n );\n assert(\n isRecord(manifest.assets) && Object.keys(manifest.assets).length > 0,\n 'Project asset additions assets must be a non-empty object.',\n );\n assert(Array.isArray(project.targets), 'Project asset additions require project.targets.');\n\n const composedProject = structuredClone(project);\n const composedTargets = composedProject.targets as UnknownRecord[];\n const composedAssetContents = new Map<string, Uint8Array>(assetContents);\n const composedArchiveEntries = [...archiveEntries];\n const targetByName = new Map<string, UnknownRecord>();\n for (const target of composedTargets) {\n assert(isRecord(target), 'Existing project target must be an object.');\n const targetName = nonEmptyString(target.name, 'Existing project target name');\n assert(!targetByName.has(targetName), `Project has duplicate target name: ${targetName}`);\n assert(\n Array.isArray(target.costumes),\n `Project target ${targetName}.costumes must be an array.`,\n );\n assert(Array.isArray(target.sounds), `Project target ${targetName}.sounds must be an array.`);\n targetByName.set(targetName, target);\n }\n const stages = composedTargets.filter(({isStage}) => isStage);\n assert(stages.length === 1, 'Project asset additions require exactly one Stage target.');\n const stage = stages[0];\n const newSpriteNames: string[] = [];\n\n for (const [rawName, rawSprite] of Object.entries(manifest.sprites ?? {})) {\n const name = nonEmptyString(rawName, 'Project asset sprite name');\n const specification = validateSprite(rawSprite, name);\n assert(!targetByName.has(name), `Project asset sprite already exists in the project: ${name}`);\n const target: UnknownRecord = {\n isStage: false,\n name,\n variables: {},\n lists: {},\n broadcasts: {},\n blocks: {},\n comments: {},\n currentCostume: 0,\n costumes: [],\n sounds: [],\n volume: specification.volume,\n layerOrder: specification.layerOrder,\n visible: specification.visible,\n x: specification.x,\n y: specification.y,\n size: specification.size,\n direction: specification.direction,\n draggable: specification.draggable,\n rotationStyle: specification.rotationStyle,\n };\n composedTargets.push(target);\n targetByName.set(name, target);\n newSpriteNames.push(name);\n }\n\n let backdropCount = 0;\n let costumeCount = 0;\n let soundCount = 0;\n let assetFileCount = 0;\n\n for (const [rawAssetId, rawSpecification] of Object.entries(manifest.assets)) {\n const assetId = nonEmptyString(rawAssetId, 'Project asset ID');\n const {description, specification} = validateAsset(rawSpecification, assetId);\n const asset = await readAssetFile(manifestDirectory, allowedRoots, specification, description);\n if (specification.kind !== 'sound') {\n assert(\n imageFormats.has(asset.dataFormat),\n `${description}.file uses unsupported image format: ${asset.dataFormat}`,\n );\n }\n const scratchName = asset.name ?? assetId;\n const owner =\n specification.kind === 'backdrop' || specification.target === undefined\n ? stage\n : targetByName.get(specification.target);\n assert(owner, `${description}.target does not exist in the project: ${specification.target}`);\n assert(\n specification.kind === 'backdrop' || !owner.isStage || specification.kind === 'sound',\n `${description}.target must name a sprite.`,\n );\n assert(\n specification.kind !== 'sound' || specification.target === undefined || !owner.isStage,\n `${description}.target must be omitted for a Stage sound.`,\n );\n const collection = (\n specification.kind === 'sound' ? owner.sounds : owner.costumes\n ) as UnknownRecord[];\n assert(\n !collection.some(({name}) => name === scratchName),\n `${description}.name already exists on target ${owner.name}: ${scratchName}`,\n );\n const contentAssetId = md5(asset.contents);\n const filename = `${contentAssetId}.${asset.dataFormat}`;\n if (\n addAssetContents(\n composedAssetContents,\n composedArchiveEntries,\n asset.contents,\n filename,\n description,\n )\n ) {\n assetFileCount += 1;\n }\n if (specification.kind === 'sound') {\n const inferred = await inferSoundMetadata(asset.contents, asset.dataFormat, description);\n if (specification.rate !== undefined) {\n const expectedRate = safeInteger(specification.rate, `${description}.rate`, 1);\n assert(\n inferred.rate === expectedRate,\n `${description}.rate differs: expected ${expectedRate}, got ${inferred.rate}`,\n );\n }\n if (specification.sampleCount !== undefined) {\n const expectedSampleCount = safeInteger(\n specification.sampleCount,\n `${description}.sampleCount`,\n );\n assert(\n inferred.sampleCount === expectedSampleCount,\n `${description}.sampleCount differs: expected ${expectedSampleCount}, got ${inferred.sampleCount}`,\n );\n }\n collection.push({\n name: scratchName,\n assetId: contentAssetId,\n dataFormat: asset.dataFormat,\n format: '',\n md5ext: filename,\n rate: inferred.rate,\n sampleCount: inferred.sampleCount,\n });\n soundCount += 1;\n } else {\n const bitmapResolution =\n specification.bitmapResolution === undefined\n ? 1\n : safeInteger(specification.bitmapResolution, `${description}.bitmapResolution`, 1);\n assert(\n bitmapResolution === 1 || bitmapResolution === 2,\n `${description}.bitmapResolution must be 1 or 2.`,\n );\n collection.push({\n name: scratchName,\n bitmapResolution,\n dataFormat: asset.dataFormat,\n assetId: contentAssetId,\n md5ext: filename,\n rotationCenterX: finiteNumber(\n specification.rotationCenterX,\n `${description}.rotationCenterX`,\n ),\n rotationCenterY: finiteNumber(\n specification.rotationCenterY,\n `${description}.rotationCenterY`,\n ),\n });\n if (specification.kind === 'backdrop') backdropCount += 1;\n else costumeCount += 1;\n }\n }\n\n for (const name of newSpriteNames) {\n const costumes = targetByName.get(name)?.costumes;\n assert(\n Array.isArray(costumes) && costumes.length > 0,\n `Project asset sprite must receive at least one costume: ${name}`,\n );\n }\n\n return {\n archiveEntries: composedArchiveEntries,\n assetContents: composedAssetContents,\n assetReferenceCount: backdropCount + costumeCount + soundCount,\n manifestPath: resolvedManifestPath,\n project: composedProject,\n summary: Object.freeze({\n assetFileCount,\n backdropCount,\n costumeCount,\n soundCount,\n spriteCount: newSpriteNames.length,\n }),\n };\n}\n"],"mappings":";;;;;;;AAaA,IAAa,qCAAqC;AAmElD,IAAM,uBAAuB;AAC7B,IAAM,uCAAuB,IAAI,IAAI;CAAC;CAAa;CAAe;AAAW,CAAC;AAC9E,IAAM,kCAAkB,IAAI,IAAI;CAAC;CAAQ;CAAQ;CAAQ;CAAU;CAAc;AAAS,CAAC;AAC3F,IAAM,iCAAiB,IAAI,IAAI;CAC7B,GAAG;CACH;CACA;CACA;CACA;CACA;AACF,CAAC;AACD,IAAM,iCAAiB,IAAI,IAAI;CAAC,GAAG;CAAiB;CAAQ;CAAU;CAAQ;AAAa,CAAC;AAC5F,IAAM,+BAAe,IAAI,IAAI;CAAC;CAAO;CAAO;CAAO;CAAQ;AAAK,CAAC;AACjE,IAAM,+BAAe,IAAI,IAAI,CAC3B,CAAC,OAAO,WAAW,GACnB,CAAC,OAAO,YAAY,CACtB,CAAC;AAED,SAAS,SAAS,OAAwC;CACxD,OAAO,OAAO,UAAU,YAAY,UAAU,QAAQ,CAAC,MAA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C1B,cAAc,aACd,GAAG,YAAY,aACjB;IACA,OACE,SAAS,gBAAgB,qBACzB,GAAG,YAAY,iCAAiC,oBAAoB,QAAQ,SAAS,aACvF;GACF;GACA,WAAW,KAAK;IACd,MAAM;IACN,SAAS;IACT,YAAY,MAAM;IAClB,QAAQ;IACR,QAAQ;IACR,MAAM,SAAS;IACf,aAAa,SAAS;GACxB,CAAC;GACD,cAAc;EAChB,OAAO;GACL,MAAM,mBACJ,cAAc,qBAAqB,KAAA,IAC/B,IACA,YAAY,cAAc,kBAAkB,GAAG,YAAY,oBAAoB,CAAC;GACtF,OACE,qBAAqB,KAAK,qBAAqB,GAC/C,GAAG,YAAY,kCACjB;GACA,WAAW,KAAK;IACd,MAAM;IACN;IACA,YAAY,MAAM;IAClB,SAAS;IACT,QAAQ;IACR,iBAAiB,aACf,cAAc,iBACd,GAAG,YAAY,iBACjB;IACA,iBAAiB,aACf,cAAc,iBACd,GAAG,YAAY,iBACjB;GACF,CAAC;GACD,IAAI,cAAc,SAAS,YAAY,iBAAiB;QACnD,gBAAgB;EACvB;CACF;CAEA,KAAK,MAAM,QAAQ,gBAAgB;EACjC,MAAM,WAAW,aAAa,IAAI,IAAI,CAAC,EAAE;EACzC,OACE,MAAM,QAAQ,QAAQ,KAAK,SAAS,SAAS,GAC7C,2DAA2D,MAC7D;CACF;CAEA,OAAO;EACL,gBAAgB;EAChB,eAAe;EACf,qBAAqB,gBAAgB,eAAe;EACpD,cAAc;EACd,SAAS;EACT,SAAS,OAAO,OAAO;GACrB;GACA;GACA;GACA;GACA,aAAa,eAAe;EAC9B,CAAC;CACH;AACF"}
@@ -0,0 +1,75 @@
1
+ import { UnknownRecord } from './types';
2
+ export type ReleaseSnapshotState = 'candidate' | 'frozen' | 'published';
3
+ export type ReleaseSourceFiles = Map<string, Buffer | Uint8Array | string>;
4
+ export interface ReleaseSnapshotArtifact {
5
+ filename: string;
6
+ sha256: string;
7
+ size: number;
8
+ url?: string;
9
+ }
10
+ export interface ReleaseSnapshotPublication {
11
+ urls?: Record<string, string>;
12
+ [key: string]: unknown;
13
+ }
14
+ export interface Sb3ReleaseSnapshotMetadata {
15
+ artifact: ReleaseSnapshotArtifact;
16
+ formatVersion: number;
17
+ publication: ReleaseSnapshotPublication;
18
+ sourceIdentity: string;
19
+ state: ReleaseSnapshotState;
20
+ [key: string]: unknown;
21
+ }
22
+ export interface CreateReleaseSnapshotMetadataInput {
23
+ artifact: {
24
+ archive: Buffer | Uint8Array | string;
25
+ filename: string;
26
+ url?: string;
27
+ };
28
+ metadata?: UnknownRecord;
29
+ publication?: ReleaseSnapshotPublication;
30
+ sourceFiles: ReleaseSourceFiles;
31
+ state?: ReleaseSnapshotState;
32
+ }
33
+ export interface BuiltReleaseArtifact {
34
+ archive: Buffer | Uint8Array | string;
35
+ }
36
+ export interface CreateReleaseSnapshotInput {
37
+ artifact: {
38
+ filename: string;
39
+ url?: string;
40
+ };
41
+ createSb3: () => BuiltReleaseArtifact | Promise<BuiltReleaseArtifact>;
42
+ metadata?: UnknownRecord;
43
+ publication?: ReleaseSnapshotPublication;
44
+ sourceFiles: ReleaseSourceFiles;
45
+ state?: ReleaseSnapshotState;
46
+ }
47
+ export interface VerifyReleaseSnapshotOptions {
48
+ createSb3?: () => BuiltReleaseArtifact | Promise<BuiltReleaseArtifact>;
49
+ fetchPublishedArtifact?: (snapshot: Sb3ReleaseSnapshotMetadata) => Buffer | Uint8Array | string | Promise<Buffer | Uint8Array | string>;
50
+ metadata: unknown;
51
+ sourceFiles?: ReleaseSourceFiles;
52
+ }
53
+ export declare function computeReleaseSourceIdentity(sourceFiles: ReleaseSourceFiles): string;
54
+ export declare function createSb3ReleaseSnapshotMetadata({ artifact, metadata, publication, sourceFiles, state, }: CreateReleaseSnapshotMetadataInput): Sb3ReleaseSnapshotMetadata;
55
+ export declare function assertSb3ReleaseSnapshotMetadata(value: unknown): Sb3ReleaseSnapshotMetadata;
56
+ export declare function createSb3ReleaseSnapshot({ artifact, createSb3, metadata, publication, sourceFiles, state, }: CreateReleaseSnapshotInput): Promise<{
57
+ archive: Buffer;
58
+ metadata: Sb3ReleaseSnapshotMetadata;
59
+ sourceFiles: ReleaseSourceFiles;
60
+ }>;
61
+ export declare function verifySb3ReleaseSnapshot(options: VerifyReleaseSnapshotOptions): Promise<Sb3ReleaseSnapshotMetadata>;
62
+ export declare function writeSb3ReleaseCandidate({ artifactPath, archive, metadata, metadataPath, }: {
63
+ artifactPath: string;
64
+ archive: Buffer | Uint8Array | string;
65
+ metadata: Sb3ReleaseSnapshotMetadata;
66
+ metadataPath: string;
67
+ }): Promise<{
68
+ artifactPath: string;
69
+ metadataPath: string;
70
+ }>;
71
+ export declare function freezeSb3ReleaseSnapshot(metadata: unknown): Sb3ReleaseSnapshotMetadata;
72
+ export declare function readSb3ReleaseSnapshotMetadata(metadataPath: string): Promise<Sb3ReleaseSnapshotMetadata>;
73
+ export declare function recordPublishedSb3ReleaseSnapshot(metadata: unknown, urls: Record<string, string>, options?: {
74
+ fetchPublishedArtifact?: VerifyReleaseSnapshotOptions['fetchPublishedArtifact'];
75
+ }): Promise<Sb3ReleaseSnapshotMetadata>;