@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.
- package/CHANGELOG.md +30 -4
- 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 +65 -0
- package/dist/extension-api-manifest.js +231 -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 +31 -20
- 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
package/CHANGELOG.md
CHANGED
|
@@ -1,11 +1,37 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
-
## 0.
|
|
3
|
+
## 0.13.0 - 2026-09-14
|
|
4
4
|
|
|
5
|
-
-
|
|
6
|
-
|
|
5
|
+
- Add `tryParseExtensionApiManifest`, which returns `{manifest, error}` instead of throwing.
|
|
6
|
+
`parseExtensionApiManifest` aborts on the first problem, so a caller auditing several published
|
|
7
|
+
manifests could only report one failure per run; the new entry point lets it collect every
|
|
8
|
+
failure and report them together.
|
|
9
|
+
- Export `ExtensionApiManifestParseResult` and its `ExtensionApiManifestParseSuccess` /
|
|
10
|
+
`ExtensionApiManifestParseFailure` members from the package entry point.
|
|
7
11
|
|
|
8
|
-
Rollback: pin `@kubohiroya/sb3-toolchain@0.
|
|
12
|
+
Rollback: pin `@kubohiroya/sb3-toolchain@0.12.0`.
|
|
13
|
+
|
|
14
|
+
## 0.12.0 - 2026-09-10
|
|
15
|
+
|
|
16
|
+
- Ignore `.claude/**` in the ESLint config: flat config does not read `.gitignore`, so `eslint .`
|
|
17
|
+
was linting nested worktree checkouts of this repository and reporting their release snapshot
|
|
18
|
+
helpers as 47 errors.
|
|
19
|
+
- Re-release the 0.11.0 TypeScript migration. npm 0.11.0 was published from a stale base and shipped
|
|
20
|
+
a narrower, scripts-only migration instead of this one.
|
|
21
|
+
|
|
22
|
+
Rollback: pin `@kubohiroya/sb3-toolchain@0.10.0`.
|
|
23
|
+
|
|
24
|
+
## 0.11.0 - 2026-09-05
|
|
25
|
+
|
|
26
|
+
- Migrate the source, tests, and build to TypeScript with `strict` type checking.
|
|
27
|
+
- Build the published package with Vite in library mode; `dist/` now holds ESM output, `.d.ts`
|
|
28
|
+
declarations, and source maps, and `exports` points at `dist/` instead of `src/`.
|
|
29
|
+
- Replace the `node --test` runner with Vitest and lint TypeScript with `typescript-eslint`.
|
|
30
|
+
- Export the public domain types (`EmbeddedExtension`, `ProjectJson`, `ExtensionSource`, and the
|
|
31
|
+
option and result shapes of every exported function) from the package entry point.
|
|
32
|
+
|
|
33
|
+
Rollback: pin `@kubohiroya/sb3-toolchain@0.10.0`. The CLI and JavaScript API surfaces are unchanged;
|
|
34
|
+
only the published file layout and the development toolchain differ.
|
|
9
35
|
|
|
10
36
|
## 0.10.0 - 2026-08-27
|
|
11
37
|
|
package/README.ja.md
CHANGED
|
@@ -31,7 +31,7 @@ Scratch 3およびTurboWarpの`.sb3`プロジェクトを、Gitで差分を確
|
|
|
31
31
|
再現可能なインストールのため、検証済みのnpmバージョンを固定します。
|
|
32
32
|
|
|
33
33
|
```bash
|
|
34
|
-
pnpm add --save-dev --save-exact @kubohiroya/sb3-toolchain@0.
|
|
34
|
+
pnpm add --save-dev --save-exact @kubohiroya/sb3-toolchain@0.13.0
|
|
35
35
|
```
|
|
36
36
|
|
|
37
37
|
## クイックスタート
|
|
@@ -140,12 +140,28 @@ await unbundleSb3({
|
|
|
140
140
|
|
|
141
141
|
## 開発
|
|
142
142
|
|
|
143
|
+
ソースはTypeScriptで記述し、Viteのライブラリモードでビルドし、Vitestでテストします。
|
|
144
|
+
`pnpm run check`は、lint・format・typecheck・test・build・リポジトリポリシー・pack検査をこの順で実行します。
|
|
145
|
+
|
|
143
146
|
```bash
|
|
144
147
|
corepack enable
|
|
145
148
|
pnpm install --frozen-lockfile
|
|
146
149
|
pnpm run check
|
|
147
150
|
```
|
|
148
151
|
|
|
152
|
+
個別のステップ:
|
|
153
|
+
|
|
154
|
+
```bash
|
|
155
|
+
pnpm run typecheck
|
|
156
|
+
pnpm run test
|
|
157
|
+
pnpm run test:watch
|
|
158
|
+
pnpm run build
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
`pnpm run build`は`dist/`(ESMと`.d.ts`型定義、ソースマップ)を出力します。
|
|
162
|
+
ライブラリのエントリも`sb3-toolchain`実行ファイルも`src/`からビルドされるため、
|
|
163
|
+
チェックアウトからCLIを使う場合は先にビルドしてください。
|
|
164
|
+
|
|
149
165
|
## ライセンス
|
|
150
166
|
|
|
151
167
|
SPDX-License-Identifier: MPL-2.0
|
package/README.md
CHANGED
|
@@ -32,7 +32,7 @@ expanded sources and rebuilding bit-for-bit identical SB3 files from the same in
|
|
|
32
32
|
Pin the verified npm version for reproducible installation.
|
|
33
33
|
|
|
34
34
|
```bash
|
|
35
|
-
pnpm add --save-dev --save-exact @kubohiroya/sb3-toolchain@0.
|
|
35
|
+
pnpm add --save-dev --save-exact @kubohiroya/sb3-toolchain@0.13.0
|
|
36
36
|
```
|
|
37
37
|
|
|
38
38
|
## Quick start
|
|
@@ -141,12 +141,28 @@ await unbundleSb3({
|
|
|
141
141
|
|
|
142
142
|
## Development
|
|
143
143
|
|
|
144
|
+
The source is TypeScript, built with Vite in library mode and tested with Vitest. `pnpm run check`
|
|
145
|
+
runs lint, format, typecheck, tests, build, repository policy, and pack checks in that order.
|
|
146
|
+
|
|
144
147
|
```bash
|
|
145
148
|
corepack enable
|
|
146
149
|
pnpm install --frozen-lockfile
|
|
147
150
|
pnpm run check
|
|
148
151
|
```
|
|
149
152
|
|
|
153
|
+
Individual steps:
|
|
154
|
+
|
|
155
|
+
```bash
|
|
156
|
+
pnpm run typecheck
|
|
157
|
+
pnpm run test
|
|
158
|
+
pnpm run test:watch
|
|
159
|
+
pnpm run build
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
`pnpm run build` emits `dist/` (ESM plus `.d.ts` declarations and source maps). The library entry
|
|
163
|
+
and the `sb3-toolchain` executable are both built from `src/`, so run a build before using the CLI
|
|
164
|
+
from a checkout.
|
|
165
|
+
|
|
150
166
|
## License
|
|
151
167
|
|
|
152
168
|
SPDX-License-Identifier: MPL-2.0
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function validateArchiveEntryName(entryName: unknown): string;
|
package/dist/archive.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { assert } from "./assert.js";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
//#region src/archive.ts
|
|
4
|
+
function validateArchiveEntryName(entryName) {
|
|
5
|
+
assert(typeof entryName === "string" && entryName.length > 0, "SB3 archive contains an empty entry name.");
|
|
6
|
+
assert(!entryName.includes("\0"), `SB3 archive entry contains a NUL byte: ${JSON.stringify(entryName)}`);
|
|
7
|
+
assert(!entryName.includes("\\"), `SB3 archive entry uses a backslash: ${JSON.stringify(entryName)}`);
|
|
8
|
+
assert(!path.posix.isAbsolute(entryName) && !/^[A-Za-z]:/u.test(entryName), `SB3 archive entry is absolute: ${JSON.stringify(entryName)}`);
|
|
9
|
+
const segments = entryName.replace(/\/$/u, "").split("/");
|
|
10
|
+
assert(segments.every((segment) => segment !== "" && segment !== "." && segment !== ".."), `SB3 archive entry contains an unsafe path segment: ${JSON.stringify(entryName)}`);
|
|
11
|
+
return entryName;
|
|
12
|
+
}
|
|
13
|
+
//#endregion
|
|
14
|
+
export { validateArchiveEntryName };
|
|
15
|
+
|
|
16
|
+
//# sourceMappingURL=archive.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"archive.js","names":[],"sources":["../src/archive.ts"],"sourcesContent":["// SPDX-License-Identifier: MPL-2.0\n\nimport path from 'node:path';\n\nimport {assert} from './assert';\n\nexport function validateArchiveEntryName(entryName: unknown): string {\n assert(\n typeof entryName === 'string' && entryName.length > 0,\n 'SB3 archive contains an empty entry name.',\n );\n assert(\n !entryName.includes('\\0'),\n `SB3 archive entry contains a NUL byte: ${JSON.stringify(entryName)}`,\n );\n assert(\n !entryName.includes('\\\\'),\n `SB3 archive entry uses a backslash: ${JSON.stringify(entryName)}`,\n );\n assert(\n !path.posix.isAbsolute(entryName) && !/^[A-Za-z]:/u.test(entryName),\n `SB3 archive entry is absolute: ${JSON.stringify(entryName)}`,\n );\n\n const segments = entryName.replace(/\\/$/u, '').split('/');\n assert(\n segments.every((segment) => segment !== '' && segment !== '.' && segment !== '..'),\n `SB3 archive entry contains an unsafe path segment: ${JSON.stringify(entryName)}`,\n );\n return entryName;\n}\n"],"mappings":";;;AAMA,SAAgB,yBAAyB,WAA4B;CACnE,OACE,OAAO,cAAc,YAAY,UAAU,SAAS,GACpD,2CACF;CACA,OACE,CAAC,UAAU,SAAS,IAAI,GACxB,0CAA0C,KAAK,UAAU,SAAS,GACpE;CACA,OACE,CAAC,UAAU,SAAS,IAAI,GACxB,uCAAuC,KAAK,UAAU,SAAS,GACjE;CACA,OACE,CAAC,KAAK,MAAM,WAAW,SAAS,KAAK,CAAC,cAAc,KAAK,SAAS,GAClE,kCAAkC,KAAK,UAAU,SAAS,GAC5D;CAEA,MAAM,WAAW,UAAU,QAAQ,QAAQ,EAAE,CAAC,CAAC,MAAM,GAAG;CACxD,OACE,SAAS,OAAO,YAAY,YAAY,MAAM,YAAY,OAAO,YAAY,IAAI,GACjF,sDAAsD,KAAK,UAAU,SAAS,GAChF;CACA,OAAO;AACT"}
|
package/dist/assert.d.ts
ADDED
package/dist/assert.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
//#region src/assert.ts
|
|
2
|
+
function assert(condition, message) {
|
|
3
|
+
if (!condition) throw new Error(message);
|
|
4
|
+
}
|
|
5
|
+
function errorMessage(error) {
|
|
6
|
+
return error instanceof Error ? error.message : String(error);
|
|
7
|
+
}
|
|
8
|
+
//#endregion
|
|
9
|
+
export { assert, errorMessage };
|
|
10
|
+
|
|
11
|
+
//# sourceMappingURL=assert.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"assert.js","names":[],"sources":["../src/assert.ts"],"sourcesContent":["// SPDX-License-Identifier: MPL-2.0\n\nexport function assert(condition: unknown, message: string): asserts condition {\n if (!condition) {\n throw new Error(message);\n }\n}\n\nexport function errorMessage(error: unknown): string {\n return error instanceof Error ? error.message : String(error);\n}\n"],"mappings":";AAEA,SAAgB,OAAO,WAAoB,SAAoC;CAC7E,IAAI,CAAC,WACH,MAAM,IAAI,MAAM,OAAO;AAE3B;AAEA,SAAgB,aAAa,OAAwB;CACnD,OAAO,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK;AAC9D"}
|
package/dist/bin.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/bin.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { errorMessage } from "./assert.js";
|
|
3
|
+
import { runCli } from "./cli.js";
|
|
4
|
+
import process from "node:process";
|
|
5
|
+
//#region src/bin.ts
|
|
6
|
+
runCli(process.argv.slice(2)).catch((error) => {
|
|
7
|
+
console.error(errorMessage(error));
|
|
8
|
+
process.exitCode = 1;
|
|
9
|
+
});
|
|
10
|
+
//#endregion
|
|
11
|
+
|
|
12
|
+
//# sourceMappingURL=bin.js.map
|
package/dist/bin.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bin.js","names":[],"sources":["../src/bin.ts"],"sourcesContent":["// SPDX-License-Identifier: MPL-2.0\n\nimport process from 'node:process';\n\nimport {runCli} from './cli';\nimport {errorMessage} from './assert';\n\nrunCli(process.argv.slice(2)).catch((error: unknown) => {\n console.error(errorMessage(error));\n process.exitCode = 1;\n});\n"],"mappings":";;;;;AAOA,OAAO,QAAQ,KAAK,MAAM,CAAC,CAAC,CAAC,CAAC,OAAO,UAAmB;CACtD,QAAQ,MAAM,aAAa,KAAK,CAAC;CACjC,QAAQ,WAAW;AACrB,CAAC"}
|
package/dist/build.d.ts
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { DeterministicSb3 } from './source';
|
|
2
|
+
export interface WriteSb3ArchiveOptions {
|
|
3
|
+
archive: Uint8Array;
|
|
4
|
+
confirmReplace?: (outputPath: string) => boolean | Promise<boolean>;
|
|
5
|
+
outputPath: string;
|
|
6
|
+
yes?: boolean;
|
|
7
|
+
}
|
|
8
|
+
export interface WriteSb3ArchiveResult {
|
|
9
|
+
changed: boolean;
|
|
10
|
+
outputPath: string;
|
|
11
|
+
rollbackCleanupWarning: string | null;
|
|
12
|
+
}
|
|
13
|
+
export interface BuildSb3Options {
|
|
14
|
+
allowedAssetRoots?: string[];
|
|
15
|
+
cleanUpBlocks?: boolean;
|
|
16
|
+
confirmReplace?: (outputPath: string) => boolean | Promise<boolean>;
|
|
17
|
+
outputPath: string;
|
|
18
|
+
projectAssetsPath?: string;
|
|
19
|
+
sourceDirectory: string;
|
|
20
|
+
yes?: boolean;
|
|
21
|
+
}
|
|
22
|
+
export declare function writeSb3Archive({ archive, confirmReplace, outputPath, yes, }: WriteSb3ArchiveOptions): Promise<WriteSb3ArchiveResult>;
|
|
23
|
+
export declare function buildSb3({ allowedAssetRoots, cleanUpBlocks, confirmReplace, outputPath, projectAssetsPath, sourceDirectory, yes, }: BuildSb3Options): Promise<DeterministicSb3 & WriteSb3ArchiveResult>;
|
package/dist/build.js
ADDED
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import { assert, errorMessage } from "./assert.js";
|
|
2
|
+
import { pathExists } from "./output-safety.js";
|
|
3
|
+
import { createDeterministicSb3 } from "./source.js";
|
|
4
|
+
import path from "node:path";
|
|
5
|
+
import { randomUUID } from "node:crypto";
|
|
6
|
+
import { lstat, mkdir, mkdtemp, readFile, readdir, rename, rm, writeFile } from "node:fs/promises";
|
|
7
|
+
//#region src/build.ts
|
|
8
|
+
async function assertNoInterruptedRollback(outputPath) {
|
|
9
|
+
const parentDirectory = path.dirname(outputPath);
|
|
10
|
+
if (!await pathExists(parentDirectory)) return;
|
|
11
|
+
const rollbackPrefix = `.${path.basename(outputPath)}.rollback-`;
|
|
12
|
+
const leftovers = (await readdir(parentDirectory)).filter((entryName) => entryName.startsWith(rollbackPrefix)).map((entryName) => path.join(parentDirectory, entryName));
|
|
13
|
+
assert(leftovers.length === 0, `Found an interrupted SB3 build rollback file. Inspect or restore it before retrying: ` + leftovers.join(", "));
|
|
14
|
+
}
|
|
15
|
+
async function inspectOutput(outputPath) {
|
|
16
|
+
if (!await pathExists(outputPath)) return {
|
|
17
|
+
contents: null,
|
|
18
|
+
exists: false
|
|
19
|
+
};
|
|
20
|
+
const stats = await lstat(outputPath);
|
|
21
|
+
assert(stats.isFile() && !stats.isSymbolicLink(), `Refusing to replace a non-file or symbolic link: ${outputPath}`);
|
|
22
|
+
return {
|
|
23
|
+
contents: await readFile(outputPath),
|
|
24
|
+
exists: true
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
async function assertOutputUnchanged(outputPath, expectedOutput) {
|
|
28
|
+
const currentOutput = await inspectOutput(outputPath);
|
|
29
|
+
assert(currentOutput.exists === expectedOutput.exists && (!currentOutput.contents || !expectedOutput.contents || Buffer.compare(currentOutput.contents, expectedOutput.contents) === 0), `SB3 output changed while the build was running; refusing to replace it: ${outputPath}`);
|
|
30
|
+
}
|
|
31
|
+
async function installArchiveTransactionally(archive, outputPath, expectedOutput) {
|
|
32
|
+
const parentDirectory = path.dirname(outputPath);
|
|
33
|
+
await assertNoInterruptedRollback(outputPath);
|
|
34
|
+
const temporaryDirectory = await mkdtemp(path.join(parentDirectory, `.${path.basename(outputPath)}.build-`));
|
|
35
|
+
const temporaryPath = path.join(temporaryDirectory, path.basename(outputPath));
|
|
36
|
+
const rollbackPath = path.join(parentDirectory, `.${path.basename(outputPath)}.rollback-${randomUUID()}`);
|
|
37
|
+
await writeFile(temporaryPath, archive);
|
|
38
|
+
try {
|
|
39
|
+
await assertOutputUnchanged(outputPath, expectedOutput);
|
|
40
|
+
if (expectedOutput.exists) await rename(outputPath, rollbackPath);
|
|
41
|
+
try {
|
|
42
|
+
await rename(temporaryPath, outputPath);
|
|
43
|
+
} catch (installError) {
|
|
44
|
+
if (expectedOutput.exists) try {
|
|
45
|
+
await rename(rollbackPath, outputPath);
|
|
46
|
+
} catch (restoreError) {
|
|
47
|
+
throw new AggregateError([installError, restoreError], `SB3 build failed and automatic restoration also failed. Original output remains at: ${rollbackPath}`);
|
|
48
|
+
}
|
|
49
|
+
throw installError;
|
|
50
|
+
}
|
|
51
|
+
} finally {
|
|
52
|
+
await rm(temporaryDirectory, {
|
|
53
|
+
recursive: true,
|
|
54
|
+
force: true
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
if (!expectedOutput.exists) return null;
|
|
58
|
+
try {
|
|
59
|
+
await rm(rollbackPath);
|
|
60
|
+
return null;
|
|
61
|
+
} catch (error) {
|
|
62
|
+
return `Built SB3 was installed, but its temporary rollback file could not be removed: ${rollbackPath} (${errorMessage(error)})`;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
async function writeSb3Archive({ archive, confirmReplace = void 0, outputPath, yes = false }) {
|
|
66
|
+
assert(archive instanceof Uint8Array, "SB3 archive contents are required.");
|
|
67
|
+
assert(typeof outputPath === "string", "SB3 output path is required.");
|
|
68
|
+
const resolvedOutputPath = path.resolve(outputPath);
|
|
69
|
+
assert(path.extname(resolvedOutputPath).toLowerCase() === ".sb3", `SB3 output path must use the .sb3 extension: ${resolvedOutputPath}`);
|
|
70
|
+
await assertNoInterruptedRollback(resolvedOutputPath);
|
|
71
|
+
const existingOutput = await inspectOutput(resolvedOutputPath);
|
|
72
|
+
if (existingOutput.exists && existingOutput.contents) {
|
|
73
|
+
if (Buffer.compare(existingOutput.contents, Buffer.from(archive)) === 0) return {
|
|
74
|
+
changed: false,
|
|
75
|
+
outputPath: resolvedOutputPath,
|
|
76
|
+
rollbackCleanupWarning: null
|
|
77
|
+
};
|
|
78
|
+
if (!yes) {
|
|
79
|
+
assert(typeof confirmReplace === "function", `Existing SB3 output differs: ${resolvedOutputPath}. Non-interactive replacement requires --yes.`);
|
|
80
|
+
assert(await confirmReplace(resolvedOutputPath), "SB3 build cancelled; the existing output was not changed.");
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
await mkdir(path.dirname(resolvedOutputPath), { recursive: true });
|
|
84
|
+
return {
|
|
85
|
+
changed: true,
|
|
86
|
+
outputPath: resolvedOutputPath,
|
|
87
|
+
rollbackCleanupWarning: await installArchiveTransactionally(archive, resolvedOutputPath, existingOutput)
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
async function buildSb3({ allowedAssetRoots = [], cleanUpBlocks = false, confirmReplace, outputPath, projectAssetsPath, sourceDirectory, yes = false }) {
|
|
91
|
+
assert(typeof sourceDirectory === "string", "SB3 source directory is required.");
|
|
92
|
+
const built = await createDeterministicSb3(sourceDirectory, {
|
|
93
|
+
allowedAssetRoots,
|
|
94
|
+
cleanUpBlocks,
|
|
95
|
+
projectAssetsPath
|
|
96
|
+
});
|
|
97
|
+
const written = await writeSb3Archive({
|
|
98
|
+
archive: built.archive,
|
|
99
|
+
confirmReplace,
|
|
100
|
+
outputPath,
|
|
101
|
+
yes
|
|
102
|
+
});
|
|
103
|
+
return {
|
|
104
|
+
...built,
|
|
105
|
+
...written
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
//#endregion
|
|
109
|
+
export { buildSb3, writeSb3Archive };
|
|
110
|
+
|
|
111
|
+
//# sourceMappingURL=build.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"build.js","names":[],"sources":["../src/build.ts"],"sourcesContent":["// SPDX-License-Identifier: MPL-2.0\n\nimport {randomUUID} from 'node:crypto';\nimport {lstat, mkdir, mkdtemp, readdir, readFile, rename, rm, writeFile} from 'node:fs/promises';\nimport path from 'node:path';\n\nimport {assert, errorMessage} from './assert';\nimport {pathExists} from './output-safety';\nimport {createDeterministicSb3} from './source';\nimport type {DeterministicSb3} from './source';\n\ninterface ExistingOutput {\n contents: Buffer | null;\n exists: boolean;\n}\n\nexport interface WriteSb3ArchiveOptions {\n archive: Uint8Array;\n confirmReplace?: (outputPath: string) => boolean | Promise<boolean>;\n outputPath: string;\n yes?: boolean;\n}\n\nexport interface WriteSb3ArchiveResult {\n changed: boolean;\n outputPath: string;\n rollbackCleanupWarning: string | null;\n}\n\nexport interface BuildSb3Options {\n allowedAssetRoots?: string[];\n cleanUpBlocks?: boolean;\n confirmReplace?: (outputPath: string) => boolean | Promise<boolean>;\n outputPath: string;\n projectAssetsPath?: string;\n sourceDirectory: string;\n yes?: boolean;\n}\n\nasync function assertNoInterruptedRollback(outputPath: string): Promise<void> {\n const parentDirectory = path.dirname(outputPath);\n if (!(await pathExists(parentDirectory))) {\n return;\n }\n const rollbackPrefix = `.${path.basename(outputPath)}.rollback-`;\n const leftovers = (await readdir(parentDirectory))\n .filter((entryName) => entryName.startsWith(rollbackPrefix))\n .map((entryName) => path.join(parentDirectory, entryName));\n assert(\n leftovers.length === 0,\n `Found an interrupted SB3 build rollback file. Inspect or restore it before retrying: ` +\n leftovers.join(', '),\n );\n}\n\nasync function inspectOutput(outputPath: string): Promise<ExistingOutput> {\n if (!(await pathExists(outputPath))) {\n return {contents: null, exists: false};\n }\n const stats = await lstat(outputPath);\n assert(\n stats.isFile() && !stats.isSymbolicLink(),\n `Refusing to replace a non-file or symbolic link: ${outputPath}`,\n );\n return {contents: await readFile(outputPath), exists: true};\n}\n\nasync function assertOutputUnchanged(\n outputPath: string,\n expectedOutput: ExistingOutput,\n): Promise<void> {\n const currentOutput = await inspectOutput(outputPath);\n assert(\n currentOutput.exists === expectedOutput.exists &&\n (!currentOutput.contents ||\n !expectedOutput.contents ||\n Buffer.compare(currentOutput.contents, expectedOutput.contents) === 0),\n `SB3 output changed while the build was running; refusing to replace it: ${outputPath}`,\n );\n}\n\nasync function installArchiveTransactionally(\n archive: Uint8Array,\n outputPath: string,\n expectedOutput: ExistingOutput,\n): Promise<string | null> {\n const parentDirectory = path.dirname(outputPath);\n await assertNoInterruptedRollback(outputPath);\n const temporaryDirectory = await mkdtemp(\n path.join(parentDirectory, `.${path.basename(outputPath)}.build-`),\n );\n const temporaryPath = path.join(temporaryDirectory, path.basename(outputPath));\n const rollbackPath = path.join(\n parentDirectory,\n `.${path.basename(outputPath)}.rollback-${randomUUID()}`,\n );\n await writeFile(temporaryPath, archive);\n\n try {\n await assertOutputUnchanged(outputPath, expectedOutput);\n if (expectedOutput.exists) {\n await rename(outputPath, rollbackPath);\n }\n try {\n await rename(temporaryPath, outputPath);\n } catch (installError) {\n if (expectedOutput.exists) {\n try {\n await rename(rollbackPath, outputPath);\n } catch (restoreError) {\n throw new AggregateError(\n [installError, restoreError],\n `SB3 build failed and automatic restoration also failed. ` +\n `Original output remains at: ${rollbackPath}`,\n );\n }\n }\n throw installError;\n }\n } finally {\n await rm(temporaryDirectory, {recursive: true, force: true});\n }\n\n if (!expectedOutput.exists) {\n return null;\n }\n try {\n await rm(rollbackPath);\n return null;\n } catch (error) {\n return (\n `Built SB3 was installed, but its temporary rollback file could not be removed: ` +\n `${rollbackPath} (${errorMessage(error)})`\n );\n }\n}\n\nexport async function writeSb3Archive({\n archive,\n confirmReplace = undefined,\n outputPath,\n yes = false,\n}: WriteSb3ArchiveOptions): Promise<WriteSb3ArchiveResult> {\n assert(archive instanceof Uint8Array, 'SB3 archive contents are required.');\n assert(typeof outputPath === 'string', 'SB3 output path is required.');\n const resolvedOutputPath = path.resolve(outputPath);\n assert(\n path.extname(resolvedOutputPath).toLowerCase() === '.sb3',\n `SB3 output path must use the .sb3 extension: ${resolvedOutputPath}`,\n );\n await assertNoInterruptedRollback(resolvedOutputPath);\n const existingOutput = await inspectOutput(resolvedOutputPath);\n if (existingOutput.exists && existingOutput.contents) {\n if (Buffer.compare(existingOutput.contents, Buffer.from(archive)) === 0) {\n return {\n changed: false,\n outputPath: resolvedOutputPath,\n rollbackCleanupWarning: null,\n };\n }\n if (!yes) {\n assert(\n typeof confirmReplace === 'function',\n `Existing SB3 output differs: ${resolvedOutputPath}. ` +\n 'Non-interactive replacement requires --yes.',\n );\n assert(\n await confirmReplace(resolvedOutputPath),\n 'SB3 build cancelled; the existing output was not changed.',\n );\n }\n }\n\n await mkdir(path.dirname(resolvedOutputPath), {recursive: true});\n const rollbackCleanupWarning = await installArchiveTransactionally(\n archive,\n resolvedOutputPath,\n existingOutput,\n );\n return {\n changed: true,\n outputPath: resolvedOutputPath,\n rollbackCleanupWarning,\n };\n}\n\nexport async function buildSb3({\n allowedAssetRoots = [],\n cleanUpBlocks = false,\n confirmReplace,\n outputPath,\n projectAssetsPath,\n sourceDirectory,\n yes = false,\n}: BuildSb3Options): Promise<DeterministicSb3 & WriteSb3ArchiveResult> {\n assert(typeof sourceDirectory === 'string', 'SB3 source directory is required.');\n const built = await createDeterministicSb3(sourceDirectory, {\n allowedAssetRoots,\n cleanUpBlocks,\n projectAssetsPath,\n });\n const written = await writeSb3Archive({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,GACvC,2DACF;EACF;CACF;CAEA,MAAM,MAAM,KAAK,QAAQ,kBAAkB,GAAG,EAAC,WAAW,KAAI,CAAC;CAM/D,OAAO;EACL,SAAS;EACT,YAAY;EACZ,wBAAA,MARmC,8BACnC,SACA,oBACA,cACF;CAKA;AACF;AAEA,eAAsB,SAAS,EAC7B,oBAAoB,CAAC,GACrB,gBAAgB,OAChB,gBACA,YACA,mBACA,iBACA,MAAM,SAC+D;CACrE,OAAO,OAAO,oBAAoB,UAAU,mCAAmC;CAC/E,MAAM,QAAQ,MAAM,uBAAuB,iBAAiB;EAC1D;EACA;EACA;CACF,CAAC;CACD,MAAM,UAAU,MAAM,gBAAgB;EACpC,SAAS,MAAM;EACf;EACA;EACA;CACF,CAAC;CACD,OAAO;EAAC,GAAG;EAAO,GAAG;CAAO;AAC9B"}
|
package/dist/cli.d.ts
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { FetchImplementation } from './extension-sync';
|
|
2
|
+
export interface HelpCliOptions {
|
|
3
|
+
command: 'help';
|
|
4
|
+
}
|
|
5
|
+
export interface VersionCliOptions {
|
|
6
|
+
command: 'version';
|
|
7
|
+
}
|
|
8
|
+
export interface ImportCliOptions {
|
|
9
|
+
command: 'import';
|
|
10
|
+
discardLocalChanges: boolean;
|
|
11
|
+
inputPath: string;
|
|
12
|
+
outputDirectory: string;
|
|
13
|
+
yes: boolean;
|
|
14
|
+
}
|
|
15
|
+
export interface CheckCliOptions {
|
|
16
|
+
allowedAssetRoots?: string[];
|
|
17
|
+
command: 'check';
|
|
18
|
+
projectAssetsPath?: string;
|
|
19
|
+
sourceDirectory: string;
|
|
20
|
+
}
|
|
21
|
+
export interface BuildCliOptions {
|
|
22
|
+
allowedAssetRoots?: string[];
|
|
23
|
+
cleanUpBlocks?: boolean;
|
|
24
|
+
command: 'build';
|
|
25
|
+
outputPath: string;
|
|
26
|
+
projectAssetsPath?: string;
|
|
27
|
+
sourceDirectory: string;
|
|
28
|
+
yes: boolean;
|
|
29
|
+
}
|
|
30
|
+
export interface ExtensionsStatusCliOptions {
|
|
31
|
+
action: 'status';
|
|
32
|
+
command: 'extensions';
|
|
33
|
+
sourceDirectory: string;
|
|
34
|
+
}
|
|
35
|
+
export interface ExtensionsMutationCliOptions {
|
|
36
|
+
action: 'sync' | 'update';
|
|
37
|
+
allowBreakingApi?: boolean;
|
|
38
|
+
apiManifestArtifact?: string;
|
|
39
|
+
command: 'extensions';
|
|
40
|
+
extensionId?: string;
|
|
41
|
+
migrateToId?: string;
|
|
42
|
+
sourceArtifact?: string;
|
|
43
|
+
sourceDirectory: string;
|
|
44
|
+
yes: boolean;
|
|
45
|
+
}
|
|
46
|
+
export interface ExtensionsMigrateIdCliOptions {
|
|
47
|
+
action: 'migrate-id';
|
|
48
|
+
command: 'extensions';
|
|
49
|
+
fromId: string;
|
|
50
|
+
sourceDirectory: string;
|
|
51
|
+
toId: string;
|
|
52
|
+
yes: boolean;
|
|
53
|
+
}
|
|
54
|
+
export interface ExtensionsBundleCliOptions {
|
|
55
|
+
action: 'bundle';
|
|
56
|
+
bundleId: string;
|
|
57
|
+
bundleName: string;
|
|
58
|
+
command: 'extensions';
|
|
59
|
+
extensionIds: string[];
|
|
60
|
+
recoveryCapsule: boolean;
|
|
61
|
+
sourceDirectory: string;
|
|
62
|
+
yes: boolean;
|
|
63
|
+
}
|
|
64
|
+
export interface ExtensionsUnbundleSourceCliOptions {
|
|
65
|
+
action: 'unbundle';
|
|
66
|
+
bundleId: string;
|
|
67
|
+
command: 'extensions';
|
|
68
|
+
sourceDirectory: string;
|
|
69
|
+
yes: boolean;
|
|
70
|
+
}
|
|
71
|
+
export interface ExtensionsUnbundleArchiveCliOptions {
|
|
72
|
+
action: 'unbundle';
|
|
73
|
+
bundleId: string;
|
|
74
|
+
command: 'extensions';
|
|
75
|
+
inputPath: string;
|
|
76
|
+
outputPath: string;
|
|
77
|
+
yes: boolean;
|
|
78
|
+
}
|
|
79
|
+
export type ExtensionsCliOptions = ExtensionsStatusCliOptions | ExtensionsMutationCliOptions | ExtensionsMigrateIdCliOptions | ExtensionsBundleCliOptions | ExtensionsUnbundleSourceCliOptions | ExtensionsUnbundleArchiveCliOptions;
|
|
80
|
+
export type CliOptions = HelpCliOptions | VersionCliOptions | ImportCliOptions | CheckCliOptions | BuildCliOptions | ExtensionsCliOptions;
|
|
81
|
+
export interface RunCliOptions {
|
|
82
|
+
fetch?: FetchImplementation;
|
|
83
|
+
log?: (message: string) => void;
|
|
84
|
+
}
|
|
85
|
+
export declare function usage(): string;
|
|
86
|
+
export declare function parseCliArguments(arguments_: string[]): CliOptions;
|
|
87
|
+
export declare function runCli(arguments_: string[], { fetch: fetchImplementation, log }?: RunCliOptions): Promise<void>;
|