@kubohiroya/sb3-toolchain 0.16.0 → 0.17.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 CHANGED
@@ -1,5 +1,12 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.17.0 - 2026-10-25
4
+
5
+ - Add opt-in module builds that combine installed extension factories into one browser dependency graph.
6
+ - Share explicitly pinned dependencies such as yaml, validate module integrity and compatible ranges, and report input digests.
7
+ - Preserve member opcode, storage, editor, sandbox and recovery behavior; initialize each member once and register the composite once.
8
+ - Keep classic mode as the default. Rollback: select classic mode, or pin `@kubohiroya/sb3-toolchain@0.16.0`.
9
+
3
10
  ## 0.16.0 - 2026-10-20
4
11
 
5
12
  - Supply all three palette colors for normal and sandboxed bundles, replacing the downstream app patch.
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.16.0
34
+ pnpm add --save-dev --save-exact @kubohiroya/sb3-toolchain@0.17.0
35
35
  ```
36
36
 
37
37
  ## クイックスタート
@@ -136,7 +136,7 @@ await unbundleSb3({
136
136
  - [`docs/ja/project-asset-additions.md`](docs/ja/project-asset-additions.md): `--project-assets`のJSON/YAML、backdrop、編集/strict lock仕様
137
137
  - [`docs/ja/extension-id-migration.md`](docs/ja/extension-id-migration.md): プロジェクトで使用中の機能拡張IDの移行
138
138
  - [`docs/ja/extension-api-compatibility.md`](docs/ja/extension-api-compatibility.md): 機能拡張更新時の任意の静的API互換性検査
139
- - [`docs/ja/extension-bundles.md`](docs/ja/extension-bundles.md): 1つの権限単位への静的bundleと可逆的なunbundle
139
+ - [`docs/ja/extension-bundles.md`](docs/ja/extension-bundles.md): 静的bundle、共有依存を持つ明示選択のmodule統合ビルド、可逆的なunbundle
140
140
 
141
141
  ## 開発
142
142
 
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.16.0
35
+ pnpm add --save-dev --save-exact @kubohiroya/sb3-toolchain@0.17.0
36
36
  ```
37
37
 
38
38
  ## Quick start
@@ -117,6 +117,8 @@ await bundleExtensions({
117
117
  extensionIds: ['extensionone', 'extensiontwo'],
118
118
  yes: true,
119
119
  });
120
+ // Opt in to one dependency graph when every member provides a pinned source.module entry:
121
+ // await bundleExtensions({...options, buildMode: 'module', sharedDependencies: {yaml: '2.9.1'}});
120
122
  await unbundleExtensions({
121
123
  sourceDirectory: 'app',
122
124
  bundleId: 'projectbundle',
@@ -137,7 +139,7 @@ await unbundleSb3({
137
139
  - [`docs/project-asset-additions.md`](docs/project-asset-additions.md): JSON/YAML `--project-assets`, backdrops, and editable or strict locks
138
140
  - [`docs/extension-id-migration.md`](docs/extension-id-migration.md): migration of extension IDs already used by a project
139
141
  - [`docs/extension-api-compatibility.md`](docs/extension-api-compatibility.md) ([日本語](docs/ja/extension-api-compatibility.md)): opt-in static API compatibility checks for extension updates
140
- - [`docs/extension-bundles.md`](docs/extension-bundles.md): static bundling into one permission unit and reversible unbundling
142
+ - [`docs/extension-bundles.md`](docs/extension-bundles.md): static bundling, opt-in module builds with shared dependencies, and reversible unbundling
141
143
 
142
144
  ## Development
143
145
 
package/dist/cli.d.ts CHANGED
@@ -60,6 +60,8 @@ export interface ExtensionsBundleCliOptions {
60
60
  recoveryCapsule: boolean;
61
61
  sourceDirectory: string;
62
62
  yes: boolean;
63
+ buildMode?: 'classic' | 'module';
64
+ sharedDependencies?: Record<string, string>;
63
65
  }
64
66
  export interface ExtensionsUnbundleSourceCliOptions {
65
67
  action: 'unbundle';
package/dist/cli.js CHANGED
@@ -20,7 +20,7 @@ function usage() {
20
20
  sb3-toolchain extensions sync SOURCE_DIR [--yes]
21
21
  sb3-toolchain extensions update SOURCE_DIR [EXTENSION_ID] [--migrate-id NEW_ID] [--artifact PATH] [--api-manifest-artifact PATH] [--allow-breaking-api --yes]
22
22
  sb3-toolchain extensions migrate-id SOURCE_DIR --from OLD_ID --to NEW_ID [--yes]
23
- sb3-toolchain extensions bundle SOURCE_DIR --id BUNDLE_ID --name NAME [EXTENSION_ID ...] [--include-recovery-capsule] [--yes]
23
+ sb3-toolchain extensions bundle SOURCE_DIR --id BUNDLE_ID --name NAME [EXTENSION_ID ...] [--build-mode classic|module] [--share PACKAGE@EXACT_VERSION] [--include-recovery-capsule] [--yes]
24
24
  sb3-toolchain extensions unbundle SOURCE_DIR BUNDLE_ID [--yes]
25
25
  sb3-toolchain extensions unbundle INPUT.sb3 BUNDLE_ID --output OUTPUT.sb3 [--yes]
26
26
 
@@ -239,6 +239,8 @@ function parseExtensionBundleArguments(arguments_) {
239
239
  let sourceDirectory;
240
240
  const extensionIds = [];
241
241
  let yes = false;
242
+ let buildMode;
243
+ const sharedDependencies = {};
242
244
  for (let index = 0; index < arguments_.length; index += 1) {
243
245
  const argument = arguments_[index];
244
246
  if (argument === "--id") {
@@ -249,7 +251,22 @@ function parseExtensionBundleArguments(arguments_) {
249
251
  index += 1;
250
252
  } else if (argument === "--yes") yes = true;
251
253
  else if (argument === "--include-recovery-capsule") recoveryCapsule = true;
252
- else {
254
+ else if (argument === "--build-mode") {
255
+ const value = takeValue(arguments_, index, "--build-mode");
256
+ assert(value === "classic" || value === "module", "--build-mode must be classic or module.");
257
+ buildMode = value;
258
+ index += 1;
259
+ } else if (argument === "--share") {
260
+ const value = takeValue(arguments_, index, "--share");
261
+ const separator = value.lastIndexOf("@");
262
+ assert(separator > 0, "--share requires PACKAGE@EXACT_VERSION.");
263
+ const name = value.slice(0, separator);
264
+ assert(/^(?:@[a-z0-9][a-z0-9._-]*\/)?[a-z0-9][a-z0-9._-]*$/u.test(name), `Invalid shared dependency name: ${name}`);
265
+ assert(/^\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?$/u.test(value.slice(separator + 1)), "--share requires an exact semantic version.");
266
+ assert(!Object.hasOwn(sharedDependencies, name), `Duplicate shared dependency: ${name}`);
267
+ sharedDependencies[name] = value.slice(separator + 1);
268
+ index += 1;
269
+ } else {
253
270
  assert(!argument.startsWith("-"), `Unknown option: ${argument}`);
254
271
  if (!sourceDirectory) sourceDirectory = path.resolve(argument);
255
272
  else {
@@ -261,6 +278,7 @@ function parseExtensionBundleArguments(arguments_) {
261
278
  assert(sourceDirectory, "The extensions bundle command requires SOURCE_DIR.");
262
279
  assert(bundleId, "The extensions bundle command requires --id BUNDLE_ID.");
263
280
  assert(bundleName, "The extensions bundle command requires --name NAME.");
281
+ assert(!Object.keys(sharedDependencies).length || buildMode === "module", "--share requires --build-mode module.");
264
282
  return {
265
283
  action: "bundle",
266
284
  bundleId,
@@ -269,7 +287,9 @@ function parseExtensionBundleArguments(arguments_) {
269
287
  extensionIds,
270
288
  recoveryCapsule,
271
289
  sourceDirectory,
272
- yes
290
+ yes,
291
+ ...buildMode === void 0 ? {} : { buildMode },
292
+ ...Object.keys(sharedDependencies).length ? { sharedDependencies } : {}
273
293
  };
274
294
  }
275
295
  function parseExtensionUnbundleArguments(arguments_) {
@@ -446,6 +466,8 @@ async function runCli(arguments_, { fetch: fetchImplementation = globalThis.fetc
446
466
  bundleName: options.bundleName,
447
467
  extensionIds: options.extensionIds,
448
468
  recoveryCapsule: options.recoveryCapsule,
469
+ buildMode: options.buildMode,
470
+ sharedDependencies: options.sharedDependencies,
449
471
  sourceDirectory: options.sourceDirectory,
450
472
  yes: options.yes
451
473
  });
package/dist/cli.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"cli.js","names":[],"sources":["../src/cli.ts"],"sourcesContent":["// SPDX-License-Identifier: MPL-2.0\n\nimport path from 'node:path';\nimport process from 'node:process';\nimport {createInterface} from 'node:readline/promises';\n\nimport {assert} from './assert';\nimport {buildSb3} from './build';\nimport {packageVersion} from './constants';\nimport {unbundleSb3} from './extension-bundle-archive';\nimport {bundleExtensions, unbundleExtensions} from './extension-bundle-configuration';\nimport {migrateExtensionId} from './extension-id-migration';\nimport type {ExtensionIdMigrationCounts, ExtensionIdReference} from './extension-id-migration';\nimport {extensionStatus, syncExtensions, updateExtensions} from './extension-sync';\nimport type {ExtensionSyncConfirmContext, FetchImplementation} from './extension-sync';\nimport {importSb3} from './import';\nimport type {OutputReplacementContext} from './import';\nimport type {DirectoryDifferences} from './output-safety';\nimport {createDeterministicSb3, validateSb3Source} from './source';\n\nexport interface HelpCliOptions {\n command: 'help';\n}\n\nexport interface VersionCliOptions {\n command: 'version';\n}\n\nexport interface ImportCliOptions {\n command: 'import';\n discardLocalChanges: boolean;\n inputPath: string;\n outputDirectory: string;\n yes: boolean;\n}\n\nexport interface CheckCliOptions {\n allowedAssetRoots?: string[];\n command: 'check';\n projectAssetsPath?: string;\n sourceDirectory: string;\n}\n\nexport interface BuildCliOptions {\n allowedAssetRoots?: string[];\n cleanUpBlocks?: boolean;\n command: 'build';\n outputPath: string;\n projectAssetsPath?: string;\n sourceDirectory: string;\n yes: boolean;\n}\n\nexport interface ExtensionsStatusCliOptions {\n action: 'status';\n command: 'extensions';\n sourceDirectory: string;\n}\n\nexport interface ExtensionsMutationCliOptions {\n action: 'sync' | 'update';\n allowBreakingApi?: boolean;\n apiManifestArtifact?: string;\n command: 'extensions';\n extensionId?: string;\n migrateToId?: string;\n sourceArtifact?: string;\n sourceDirectory: string;\n yes: boolean;\n}\n\nexport interface ExtensionsMigrateIdCliOptions {\n action: 'migrate-id';\n command: 'extensions';\n fromId: string;\n sourceDirectory: string;\n toId: string;\n yes: boolean;\n}\n\nexport interface ExtensionsBundleCliOptions {\n action: 'bundle';\n bundleId: string;\n bundleName: string;\n command: 'extensions';\n extensionIds: string[];\n recoveryCapsule: boolean;\n sourceDirectory: string;\n yes: boolean;\n}\n\nexport interface ExtensionsUnbundleSourceCliOptions {\n action: 'unbundle';\n bundleId: string;\n command: 'extensions';\n sourceDirectory: string;\n yes: boolean;\n}\n\nexport interface ExtensionsUnbundleArchiveCliOptions {\n action: 'unbundle';\n bundleId: string;\n command: 'extensions';\n inputPath: string;\n outputPath: string;\n yes: boolean;\n}\n\nexport type ExtensionsCliOptions =\n | ExtensionsStatusCliOptions\n | ExtensionsMutationCliOptions\n | ExtensionsMigrateIdCliOptions\n | ExtensionsBundleCliOptions\n | ExtensionsUnbundleSourceCliOptions\n | ExtensionsUnbundleArchiveCliOptions;\n\nexport type CliOptions =\n | HelpCliOptions\n | VersionCliOptions\n | ImportCliOptions\n | CheckCliOptions\n | BuildCliOptions\n | ExtensionsCliOptions;\n\nexport interface RunCliOptions {\n fetch?: FetchImplementation;\n log?: (message: string) => void;\n}\n\ninterface MigrationLogResult {\n applied: boolean;\n artifactReady: boolean;\n counts: ExtensionIdMigrationCounts;\n fromId: string | undefined;\n toId: string | undefined;\n totalChanges: number;\n unclassifiedReferences: ExtensionIdReference[];\n}\n\nexport function usage() {\n return `Usage:\n sb3-toolchain import INPUT.sb3 --output SOURCE_DIR [--yes] [--discard-local-changes]\n sb3-toolchain check SOURCE_DIR [--project-assets MANIFEST.json] [--allow-asset-root DIR ...]\n sb3-toolchain build SOURCE_DIR --output OUTPUT.sb3 [--project-assets MANIFEST.json] [--allow-asset-root DIR ...] [--clean-up-blocks] [--yes]\n sb3-toolchain extensions status SOURCE_DIR\n sb3-toolchain extensions sync SOURCE_DIR [--yes]\n sb3-toolchain extensions update SOURCE_DIR [EXTENSION_ID] [--migrate-id NEW_ID] [--artifact PATH] [--api-manifest-artifact PATH] [--allow-breaking-api --yes]\n sb3-toolchain extensions migrate-id SOURCE_DIR --from OLD_ID --to NEW_ID [--yes]\n sb3-toolchain extensions bundle SOURCE_DIR --id BUNDLE_ID --name NAME [EXTENSION_ID ...] [--include-recovery-capsule] [--yes]\n sb3-toolchain extensions unbundle SOURCE_DIR BUNDLE_ID [--yes]\n sb3-toolchain extensions unbundle INPUT.sb3 BUNDLE_ID --output OUTPUT.sb3 [--yes]\n\nCommands:\n import Expand an SB3 into Git-friendly source files.\n check Validate an expanded SB3 source directory.\n build Build a deterministic SB3 from expanded sources.\n extensions Inspect, restore, or update managed embedded extensions.\n\nBuild layout cleanup:\n --clean-up-blocks applies a deterministic TurboWarp-style \"Clean up Blocks\"\n layout to every target in the generated SB3. It never deletes blocks,\n variables, lists, or comments. The expanded source is unchanged, but the\n generated SB3 might not be able to undo the coordinate changes.\n\nProject asset additions:\n --project-assets validates a JSON or YAML manifest and adds its sprites,\n backdrops, costumes, and sounds only to the generated SB3. Input files are confined to the\n manifest directory unless --allow-asset-root explicitly permits another root.\n\nReplacement safety:\n Differing outputs require interactive confirmation or --yes.\n Import refuses to discard uncommitted Git changes unless\n --discard-local-changes is also specified. --force is not supported.`;\n}\n\nfunction takeValue(arguments_: string[], index: number, option: string): string {\n const value = arguments_[index + 1];\n assert(value && !value.startsWith('-'), `${option} requires a value.`);\n return value;\n}\n\nfunction parseImportArguments(arguments_: string[]): ImportCliOptions {\n let inputPath: string | undefined;\n let outputDirectory: string | undefined;\n let discardLocalChanges = false;\n let yes = false;\n\n for (let index = 0; index < arguments_.length; index += 1) {\n const argument = arguments_[index];\n if (argument === '--output') {\n outputDirectory = path.resolve(takeValue(arguments_, index, '--output'));\n index += 1;\n } else if (argument === '--yes') {\n yes = true;\n } else if (argument === '--discard-local-changes') {\n discardLocalChanges = true;\n } else {\n assert(\n argument !== '--force',\n '--force is intentionally unsupported. Use --yes and, only when necessary, ' +\n '--discard-local-changes.',\n );\n assert(!argument.startsWith('-'), `Unknown option: ${argument}`);\n assert(!inputPath, 'Only one input SB3 may be specified.');\n inputPath = path.resolve(argument);\n }\n }\n\n assert(inputPath, 'The import command requires INPUT.sb3.');\n assert(outputDirectory, 'The import command requires --output SOURCE_DIR.');\n return {command: 'import', discardLocalChanges, inputPath, outputDirectory, yes};\n}\n\nfunction parseCheckArguments(arguments_: string[]): CheckCliOptions {\n const allowedAssetRoots: string[] = [];\n let projectAssetsPath: string | undefined;\n let sourceDirectory: string | undefined;\n for (let index = 0; index < arguments_.length; index += 1) {\n const argument = arguments_[index];\n if (argument === '--project-assets') {\n projectAssetsPath = path.resolve(takeValue(arguments_, index, '--project-assets'));\n index += 1;\n } else if (argument === '--allow-asset-root') {\n allowedAssetRoots.push(path.resolve(takeValue(arguments_, index, '--allow-asset-root')));\n index += 1;\n } else {\n assert(!argument.startsWith('-'), `Unknown option: ${argument}`);\n assert(!sourceDirectory, 'Only one SB3 source directory may be specified.');\n sourceDirectory = path.resolve(argument);\n }\n }\n assert(sourceDirectory, 'The check command requires SOURCE_DIR.');\n assert(\n allowedAssetRoots.length === 0 || projectAssetsPath,\n '--allow-asset-root requires --project-assets.',\n );\n return {\n ...(allowedAssetRoots.length > 0 ? {allowedAssetRoots} : {}),\n command: 'check',\n ...(projectAssetsPath ? {projectAssetsPath} : {}),\n sourceDirectory,\n };\n}\n\nfunction parseBuildArguments(arguments_: string[]): BuildCliOptions {\n const allowedAssetRoots: string[] = [];\n let cleanUpBlocks = false;\n let sourceDirectory: string | undefined;\n let outputPath: string | undefined;\n let projectAssetsPath: string | undefined;\n let yes = false;\n\n for (let index = 0; index < arguments_.length; index += 1) {\n const argument = arguments_[index];\n if (argument === '--clean-up-blocks') {\n cleanUpBlocks = true;\n } else if (argument === '--project-assets') {\n projectAssetsPath = path.resolve(takeValue(arguments_, index, '--project-assets'));\n index += 1;\n } else if (argument === '--allow-asset-root') {\n allowedAssetRoots.push(path.resolve(takeValue(arguments_, index, '--allow-asset-root')));\n index += 1;\n } else if (argument === '--output') {\n outputPath = path.resolve(takeValue(arguments_, index, '--output'));\n index += 1;\n } else if (argument === '--yes') {\n yes = true;\n } else {\n assert(!argument.startsWith('-'), `Unknown option: ${argument}`);\n assert(!sourceDirectory, 'Only one SB3 source directory may be specified.');\n sourceDirectory = path.resolve(argument);\n }\n }\n\n assert(sourceDirectory, 'The build command requires SOURCE_DIR.');\n assert(outputPath, 'The build command requires --output OUTPUT.sb3.');\n assert(\n allowedAssetRoots.length === 0 || projectAssetsPath,\n '--allow-asset-root requires --project-assets.',\n );\n return {\n ...(allowedAssetRoots.length > 0 ? {allowedAssetRoots} : {}),\n ...(cleanUpBlocks ? {cleanUpBlocks} : {}),\n command: 'build',\n outputPath,\n ...(projectAssetsPath ? {projectAssetsPath} : {}),\n sourceDirectory,\n yes,\n };\n}\n\nfunction parseExtensionMutationArguments(\n action: 'sync' | 'update',\n arguments_: string[],\n): ExtensionsMutationCliOptions {\n let allowBreakingApi = false;\n let apiManifestArtifact: string | undefined;\n let sourceDirectory: string | undefined;\n let extensionId: string | undefined;\n let migrateToId: string | undefined;\n let sourceArtifact: string | undefined;\n let yes = false;\n\n for (let index = 0; index < arguments_.length; index += 1) {\n const argument = arguments_[index];\n if (argument === '--yes') {\n yes = true;\n } else if (argument === '--allow-breaking-api') {\n assert(action === 'update', '--allow-breaking-api is only valid for extensions update.');\n allowBreakingApi = true;\n } else if (argument === '--migrate-id') {\n assert(action === 'update', '--migrate-id is only valid for extensions update.');\n migrateToId = takeValue(arguments_, index, '--migrate-id');\n index += 1;\n } else if (argument === '--artifact') {\n assert(action === 'update', '--artifact is only valid for extensions update.');\n sourceArtifact = takeValue(arguments_, index, '--artifact');\n index += 1;\n } else if (argument === '--api-manifest-artifact') {\n assert(action === 'update', '--api-manifest-artifact is only valid for extensions update.');\n apiManifestArtifact = takeValue(arguments_, index, '--api-manifest-artifact');\n index += 1;\n } else {\n assert(!argument.startsWith('-'), `Unknown option: ${argument}`);\n if (!sourceDirectory) {\n sourceDirectory = path.resolve(argument);\n } else {\n assert(action === 'update', `The extensions ${action} command accepts only SOURCE_DIR.`);\n assert(!extensionId, 'Only one EXTENSION_ID may be specified.');\n assert(\n /^[A-Za-z0-9._-]+$/u.test(argument),\n `Invalid embedded extension ID: ${JSON.stringify(argument)}`,\n );\n extensionId = argument;\n }\n }\n }\n\n assert(sourceDirectory, `The extensions ${action} command requires SOURCE_DIR.`);\n assert(\n migrateToId === undefined || extensionId !== undefined,\n '--migrate-id requires an explicit existing EXTENSION_ID.',\n );\n assert(\n sourceArtifact === undefined || migrateToId !== undefined,\n '--artifact requires --migrate-id.',\n );\n assert(\n apiManifestArtifact === undefined || migrateToId !== undefined,\n '--api-manifest-artifact requires --migrate-id.',\n );\n assert(!allowBreakingApi || yes, '--allow-breaking-api requires --yes.');\n return {\n action,\n ...(allowBreakingApi ? {allowBreakingApi} : {}),\n ...(apiManifestArtifact ? {apiManifestArtifact} : {}),\n command: 'extensions',\n extensionId,\n migrateToId,\n sourceArtifact,\n sourceDirectory,\n yes,\n };\n}\n\nfunction parseExtensionIdMigrationArguments(arguments_: string[]): ExtensionsMigrateIdCliOptions {\n let fromId: string | undefined;\n let sourceDirectory: string | undefined;\n let toId: string | undefined;\n let yes = false;\n\n for (let index = 0; index < arguments_.length; index += 1) {\n const argument = arguments_[index];\n if (argument === '--from') {\n fromId = takeValue(arguments_, index, '--from');\n index += 1;\n } else if (argument === '--to') {\n toId = takeValue(arguments_, index, '--to');\n index += 1;\n } else if (argument === '--yes') {\n yes = true;\n } else {\n assert(!argument.startsWith('-'), `Unknown option: ${argument}`);\n assert(!sourceDirectory, 'Only one SB3 source directory may be specified.');\n sourceDirectory = path.resolve(argument);\n }\n }\n assert(sourceDirectory, 'The extensions migrate-id command requires SOURCE_DIR.');\n assert(fromId, 'The extensions migrate-id command requires --from OLD_ID.');\n assert(toId, 'The extensions migrate-id command requires --to NEW_ID.');\n return {\n action: 'migrate-id',\n command: 'extensions',\n fromId,\n sourceDirectory,\n toId,\n yes,\n };\n}\n\nfunction parseExtensionBundleArguments(arguments_: string[]): ExtensionsBundleCliOptions {\n let bundleId: string | undefined;\n let bundleName: string | undefined;\n let recoveryCapsule = false;\n let sourceDirectory: string | undefined;\n const extensionIds: string[] = [];\n let yes = false;\n\n for (let index = 0; index < arguments_.length; index += 1) {\n const argument = arguments_[index];\n if (argument === '--id') {\n bundleId = takeValue(arguments_, index, '--id');\n index += 1;\n } else if (argument === '--name') {\n bundleName = takeValue(arguments_, index, '--name');\n index += 1;\n } else if (argument === '--yes') {\n yes = true;\n } else if (argument === '--include-recovery-capsule') {\n recoveryCapsule = true;\n } else {\n assert(!argument.startsWith('-'), `Unknown option: ${argument}`);\n if (!sourceDirectory) {\n sourceDirectory = path.resolve(argument);\n } else {\n assert(\n /^[a-z0-9]+$/u.test(argument),\n `Bundle member ID must use TurboWarp's [a-z0-9]+ format: ${JSON.stringify(argument)}`,\n );\n extensionIds.push(argument);\n }\n }\n }\n assert(sourceDirectory, 'The extensions bundle command requires SOURCE_DIR.');\n assert(bundleId, 'The extensions bundle command requires --id BUNDLE_ID.');\n assert(bundleName, 'The extensions bundle command requires --name NAME.');\n return {\n action: 'bundle',\n bundleId,\n bundleName,\n command: 'extensions',\n extensionIds,\n recoveryCapsule,\n sourceDirectory,\n yes,\n };\n}\n\nfunction parseExtensionUnbundleArguments(\n arguments_: string[],\n): ExtensionsUnbundleSourceCliOptions | ExtensionsUnbundleArchiveCliOptions {\n let bundleId: string | undefined;\n let input: string | undefined;\n let outputPath: string | undefined;\n let yes = false;\n for (let index = 0; index < arguments_.length; index += 1) {\n const argument = arguments_[index];\n if (argument === '--yes') {\n yes = true;\n } else if (argument === '--output') {\n outputPath = path.resolve(takeValue(arguments_, index, '--output'));\n index += 1;\n } else {\n assert(!argument.startsWith('-'), `Unknown option: ${argument}`);\n if (!input) {\n input = path.resolve(argument);\n } else {\n assert(!bundleId, 'Only one BUNDLE_ID may be specified.');\n bundleId = argument;\n }\n }\n }\n assert(input, 'The extensions unbundle command requires SOURCE_DIR or INPUT.sb3.');\n assert(bundleId, 'The extensions unbundle command requires BUNDLE_ID.');\n if (path.extname(input).toLowerCase() === '.sb3') {\n assert(outputPath, 'SB3 unbundle requires --output OUTPUT.sb3.');\n return {\n action: 'unbundle',\n bundleId,\n command: 'extensions',\n inputPath: input,\n outputPath,\n yes,\n };\n }\n assert(!outputPath, '--output is only valid when unbundling an SB3 file.');\n return {\n action: 'unbundle',\n bundleId,\n command: 'extensions',\n sourceDirectory: input,\n yes,\n };\n}\n\nfunction parseExtensionsArguments(arguments_: string[]): ExtensionsCliOptions {\n const [action, ...actionArguments] = arguments_;\n assert(\n action === 'bundle' ||\n action === 'migrate-id' ||\n action === 'status' ||\n action === 'sync' ||\n action === 'unbundle' ||\n action === 'update',\n 'The extensions command requires status, sync, update, migrate-id, bundle, or unbundle.',\n );\n if (action === 'status') {\n assert(\n actionArguments.length === 1 && !actionArguments[0].startsWith('-'),\n 'The extensions status command requires exactly one SOURCE_DIR.',\n );\n return {\n action,\n command: 'extensions',\n sourceDirectory: path.resolve(actionArguments[0]),\n };\n }\n if (action === 'migrate-id') {\n return parseExtensionIdMigrationArguments(actionArguments);\n }\n if (action === 'bundle') {\n return parseExtensionBundleArguments(actionArguments);\n }\n if (action === 'unbundle') {\n return parseExtensionUnbundleArguments(actionArguments);\n }\n return parseExtensionMutationArguments(action, actionArguments);\n}\n\nexport function parseCliArguments(arguments_: string[]): CliOptions {\n const normalized = arguments_.filter((argument) => argument !== '--');\n if (normalized.length === 0 || normalized[0] === '--help' || normalized[0] === '-h') {\n return {command: 'help'};\n }\n if (normalized[0] === '--version' || normalized[0] === '-v') {\n return {command: 'version'};\n }\n\n const [command, ...commandArguments] = normalized;\n if (commandArguments.includes('--help') || commandArguments.includes('-h')) {\n return {command: 'help'};\n }\n if (command === 'import') return parseImportArguments(commandArguments);\n if (command === 'check') return parseCheckArguments(commandArguments);\n if (command === 'build') return parseBuildArguments(commandArguments);\n if (command === 'extensions') return parseExtensionsArguments(commandArguments);\n throw new Error(`Unknown command: ${command}`);\n}\n\nfunction formatDifferenceLines(differences: DirectoryDifferences): string {\n const labels: Record<string, string> = {added: '+', modified: '~', removed: '-'};\n const lines = Object.entries(differences).flatMap(([kind, paths]) =>\n paths.map((relativePath: string) => `${labels[kind]} ${relativePath}`),\n );\n const visibleLines = lines.slice(0, 12);\n if (lines.length > visibleLines.length) {\n visibleLines.push(`... and ${lines.length - visibleLines.length} more`);\n }\n return visibleLines.join('\\n');\n}\n\nasync function confirmImportReplacement(context: OutputReplacementContext): Promise<boolean> {\n const {comparison, discardLocalChanges, gitState, outputDirectory} = context;\n assert(\n process.stdin.isTTY && process.stdout.isTTY,\n `Output directory already exists: ${outputDirectory}. ` +\n 'Non-interactive replacement requires --yes.',\n );\n const readline = createInterface({input: process.stdin, output: process.stdout});\n try {\n const gitMessage = gitState.clean\n ? 'Git state: clean'\n : 'Git state: uncommitted changes will be discarded';\n const answer = await readline.question(\n `Existing SB3 source differs from the import candidate:\\n` +\n ` ${outputDirectory}\\n` +\n `${formatDifferenceLines(comparison.differences)}\\n` +\n `${gitMessage}\\n` +\n `${discardLocalChanges ? 'WARNING: --discard-local-changes is active.\\n' : ''}` +\n 'Replace the existing source directory? [y/N] ',\n );\n return /^(?:y|yes)$/iu.test(answer.trim());\n } finally {\n readline.close();\n }\n}\n\nasync function confirmBuildReplacement(outputPath: string): Promise<boolean> {\n assert(\n process.stdin.isTTY && process.stdout.isTTY,\n `Existing SB3 output differs: ${outputPath}. Non-interactive replacement requires --yes.`,\n );\n const readline = createInterface({input: process.stdin, output: process.stdout});\n try {\n const answer = await readline.question(\n `Existing generated SB3 will be replaced:\\n ${outputPath}\\nContinue? [y/N] `,\n );\n return /^(?:y|yes)$/iu.test(answer.trim());\n } finally {\n readline.close();\n }\n}\n\nasync function confirmExtensionReplacement({\n comparison,\n sourceDirectory,\n}: ExtensionSyncConfirmContext): Promise<boolean> {\n assert(\n process.stdin.isTTY && process.stdout.isTTY,\n `Managed extension files differ in ${sourceDirectory}. ` +\n 'Non-interactive replacement requires --yes.',\n );\n const readline = createInterface({input: process.stdin, output: process.stdout});\n try {\n const answer = await readline.question(\n `Managed extension changes will be installed:\\n` +\n ` ${sourceDirectory}\\n` +\n `${formatDifferenceLines(comparison.differences)}\\n` +\n 'Replace these files? [y/N] ',\n );\n return /^(?:y|yes)$/iu.test(answer.trim());\n } finally {\n readline.close();\n }\n}\n\nfunction logMigrationResult(result: MigrationLogResult, log: (message: string) => void): void {\n const counts = Object.entries(result.counts)\n .filter(([, count]) => count > 0)\n .map(([kind, count]) => `${kind}=${count}`)\n .join(', ');\n const action = result.applied ? 'Migrated' : 'Dry run';\n log(\n `${action}: ${result.fromId} -> ${result.toId}; ` +\n `${result.totalChanges} classified changes (${counts || 'none'}); ` +\n `artifact=${result.artifactReady ? 'ready' : 'requires-new-ID'}.`,\n );\n for (const reference of result.unclassifiedReferences) {\n log(\n `Unclassified ${reference.kind}: ${reference.file}${reference.path} = ` +\n JSON.stringify(reference.value),\n );\n }\n}\n\nexport async function runCli(\n arguments_: string[],\n {fetch: fetchImplementation = globalThis.fetch, log = console.log}: RunCliOptions = {},\n): Promise<void> {\n const options = parseCliArguments(arguments_);\n if (options.command === 'help') {\n log(usage());\n return;\n }\n if (options.command === 'version') {\n log(packageVersion);\n return;\n }\n if (options.command === 'check') {\n assert(\n 'sourceDirectory' in options && !('action' in options),\n 'Internal CLI check command routing error.',\n );\n if (options.projectAssetsPath) {\n const result = await createDeterministicSb3(options.sourceDirectory, {\n allowedAssetRoots: options.allowedAssetRoots,\n projectAssetsPath: options.projectAssetsPath,\n });\n log(\n `Valid SB3 source with project assets: ${result.source.resolvedSourceDirectory} ` +\n `(${result.entryCount} entries, ${result.assetCount} assets, ` +\n `${result.assetReferenceCount} references, ${result.embeddedExtensionCount} embedded extensions).`,\n );\n return;\n }\n const result = await validateSb3Source(options.sourceDirectory);\n log(\n `Valid SB3 source: ${result.resolvedSourceDirectory} ` +\n `(${result.sourceManifest.archiveEntries.length} entries, ` +\n `${result.assetContents.size} assets, ${result.assetReferenceCount} references, ` +\n `${result.extensions.length} embedded extensions).`,\n );\n return;\n }\n if (\n options.command === 'build' &&\n 'outputPath' in options &&\n 'sourceDirectory' in options &&\n !('action' in options)\n ) {\n const result = await buildSb3({\n allowedAssetRoots: options.allowedAssetRoots,\n cleanUpBlocks: options.cleanUpBlocks,\n confirmReplace: confirmBuildReplacement,\n outputPath: options.outputPath,\n projectAssetsPath: options.projectAssetsPath,\n sourceDirectory: options.sourceDirectory,\n yes: options.yes,\n });\n const action = result.changed ? 'Built' : 'Already up to date';\n const cleanUpMessage = result.blockCleanUp\n ? `, ${result.blockCleanUp.movedScriptCount}/${result.blockCleanUp.scriptCount} scripts laid out`\n : '';\n log(\n `${action}: ${result.outputPath} (${result.entryCount} entries, ` +\n `${result.assetCount} assets, ${result.embeddedExtensionCount} embedded extensions` +\n `${cleanUpMessage}).`,\n );\n if (result.rollbackCleanupWarning) log(result.rollbackCleanupWarning);\n return;\n }\n if (options.command === 'extensions') {\n if (options.action === 'bundle') {\n const result = await bundleExtensions({\n bundleId: options.bundleId,\n bundleName: options.bundleName,\n extensionIds: options.extensionIds,\n recoveryCapsule: options.recoveryCapsule,\n sourceDirectory: options.sourceDirectory,\n yes: options.yes,\n });\n log(\n `${result.applied ? 'Configured' : 'Dry run'} extension bundle: ${result.bundleId} ` +\n `(${result.members.join(', ')}).`,\n );\n if (result.rollbackCleanupWarning) log(result.rollbackCleanupWarning);\n return;\n }\n if (options.action === 'unbundle') {\n if ('inputPath' in options) {\n const result = await unbundleSb3({\n bundleId: options.bundleId,\n inputPath: options.inputPath,\n outputPath: options.outputPath,\n yes: options.yes,\n });\n log(\n `${result.applied ? 'Wrote' : 'Dry run'} unbundled SB3: ${result.bundleId} ` +\n `(${result.members.join(', ')}) -> ${result.outputPath}.`,\n );\n if (result.rollbackCleanupWarning) log(result.rollbackCleanupWarning);\n return;\n }\n const result = await unbundleExtensions({\n bundleId: options.bundleId,\n sourceDirectory: options.sourceDirectory,\n yes: options.yes,\n });\n log(\n `${result.applied ? 'Removed' : 'Dry run'} extension bundle: ${result.bundleId} ` +\n `(${result.members.join(', ')}).`,\n );\n if (result.rollbackCleanupWarning) log(result.rollbackCleanupWarning);\n return;\n }\n if (options.action === 'migrate-id') {\n const result = await migrateExtensionId({\n fromId: options.fromId,\n sourceDirectory: options.sourceDirectory,\n toId: options.toId,\n yes: options.yes,\n });\n logMigrationResult(result, log);\n if (result.rollbackCleanupWarning) log(result.rollbackCleanupWarning);\n return;\n }\n if (options.action === 'status') {\n const statuses = await extensionStatus(options.sourceDirectory, {\n fetch: fetchImplementation,\n });\n if (statuses.length === 0) {\n log(`No managed embedded extensions: ${options.sourceDirectory}`);\n return;\n }\n for (const status of statuses) {\n if ('package' in status) {\n log(\n `${status.id}: ${status.state}; local=${status.local}; ` +\n `${status.package}@${status.version} (installed ${status.installedVersion})`,\n );\n continue;\n }\n log(\n `${status.id}: ${status.state}; local=${status.local}; ` +\n `${status.ref} -> ${status.remoteCommit} ` +\n `(installed ${status.resolvedCommit})`,\n );\n }\n return;\n }\n\n const operationOptions = {\n confirmReplace: confirmExtensionReplacement,\n fetch: fetchImplementation,\n sourceDirectory: options.sourceDirectory,\n yes: options.yes,\n };\n const result =\n options.action === 'sync'\n ? await syncExtensions(operationOptions)\n : await updateExtensions({\n ...operationOptions,\n allowBreakingApi: options.allowBreakingApi,\n apiManifestArtifact: options.apiManifestArtifact,\n extensionId: options.extensionId,\n migrateToId: options.migrateToId,\n sourceArtifact: options.sourceArtifact,\n });\n const action = result.changed ? 'Updated' : 'Already up to date';\n log(\n `${action}: ${result.sourceDirectory} ` +\n `(${result.extensions.map((extension) => extension.id).join(', ')}).`,\n );\n if (result.migration) {\n logMigrationResult(\n {\n applied: result.changed,\n artifactReady: true,\n ...result.migration,\n },\n log,\n );\n }\n for (const compatibility of result.apiCompatibility) {\n for (const change of compatibility.changes) {\n log(\n `API ${compatibility.id}: ${change.breaking ? 'breaking' : 'compatible'} ` +\n `${change.kind} ${change.path}`,\n );\n }\n }\n if (result.rollbackCleanupWarning) log(result.rollbackCleanupWarning);\n return;\n }\n\n assert(\n options.command === 'import' && 'inputPath' in options,\n 'Internal CLI command routing error.',\n );\n const result = await importSb3({\n confirmReplace: confirmImportReplacement,\n discardLocalChanges: options.discardLocalChanges,\n inputPath: options.inputPath,\n outputDirectory: options.outputDirectory,\n yes: options.yes,\n });\n if (result.changed) {\n const differenceMessage = result.differenceCounts\n ? ` Changes: +${result.differenceCounts.added} ` +\n `~${result.differenceCounts.modified} -${result.differenceCounts.removed}.`\n : '';\n log(\n `Imported ${result.archiveEntryCount} SB3 entries into ${result.outputDirectory} ` +\n `(${result.assetCount} assets, ${result.embeddedExtensionCount} embedded extensions).` +\n differenceMessage,\n );\n } else {\n log(`Already up to date; no files changed: ${result.outputDirectory}`);\n }\n if (result.rollbackCleanupWarning) log(result.rollbackCleanupWarning);\n}\n"],"mappings":";;;;;;;;;;;;;AA2IA,SAAgB,QAAQ;CACtB,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiCT;AAEA,SAAS,UAAU,YAAsB,OAAe,QAAwB;CAC9E,MAAM,QAAQ,WAAW,QAAQ;CACjC,OAAO,SAAS,CAAC,MAAM,WAAW,GAAG,GAAG,GAAG,OAAO,mBAAmB;CACrE,OAAO;AACT;AAEA,SAAS,qBAAqB,YAAwC;CACpE,IAAI;CACJ,IAAI;CACJ,IAAI,sBAAsB;CAC1B,IAAI,MAAM;CAEV,KAAK,IAAI,QAAQ,GAAG,QAAQ,WAAW,QAAQ,SAAS,GAAG;EACzD,MAAM,WAAW,WAAW;EAC5B,IAAI,aAAa,YAAY;GAC3B,kBAAkB,KAAK,QAAQ,UAAU,YAAY,OAAO,UAAU,CAAC;GACvE,SAAS;EACX,OAAO,IAAI,aAAa,SACtB,MAAM;OACD,IAAI,aAAa,2BACtB,sBAAsB;OACjB;GACL,OACE,aAAa,WACb,oGAEF;GACA,OAAO,CAAC,SAAS,WAAW,GAAG,GAAG,mBAAmB,UAAU;GAC/D,OAAO,CAAC,WAAW,sCAAsC;GACzD,YAAY,KAAK,QAAQ,QAAQ;EACnC;CACF;CAEA,OAAO,WAAW,wCAAwC;CAC1D,OAAO,iBAAiB,kDAAkD;CAC1E,OAAO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GACA,GACF;EAEF,KAAK,MAAM,iBAAiB,OAAO,kBACjC,KAAK,MAAM,UAAU,cAAc,SACjC,IACE,OAAO,cAAc,GAAG,IAAI,OAAO,WAAW,aAAa,aAAa,GACnE,OAAO,KAAK,GAAG,OAAO,MAC7B;EAGJ,IAAI,OAAO,wBAAwB,IAAI,OAAO,sBAAsB;EACpE;CACF;CAEA,OACE,QAAQ,YAAY,YAAY,eAAe,SAC/C,qCACF;CACA,MAAM,SAAS,MAAM,UAAU;EAC7B,gBAAgB;EAChB,qBAAqB,QAAQ;EAC7B,WAAW,QAAQ;EACnB,iBAAiB,QAAQ;EACzB,KAAK,QAAQ;CACf,CAAC;CACD,IAAI,OAAO,SAAS;EAClB,MAAM,oBAAoB,OAAO,mBAC7B,cAAc,OAAO,iBAAiB,MAAM,IACxC,OAAO,iBAAiB,SAAS,IAAI,OAAO,iBAAiB,QAAQ,KACzE;EACJ,IACE,YAAY,OAAO,kBAAkB,oBAAoB,OAAO,gBAAgB,IAC1E,OAAO,WAAW,WAAW,OAAO,uBAAuB,0BAC/D,iBACJ;CACF,OACE,IAAI,yCAAyC,OAAO,iBAAiB;CAEvE,IAAI,OAAO,wBAAwB,IAAI,OAAO,sBAAsB;AACtE"}
1
+ {"version":3,"file":"cli.js","names":[],"sources":["../src/cli.ts"],"sourcesContent":["// SPDX-License-Identifier: MPL-2.0\n\nimport path from 'node:path';\nimport process from 'node:process';\nimport {createInterface} from 'node:readline/promises';\n\nimport {assert} from './assert';\nimport {buildSb3} from './build';\nimport {packageVersion} from './constants';\nimport {unbundleSb3} from './extension-bundle-archive';\nimport {bundleExtensions, unbundleExtensions} from './extension-bundle-configuration';\nimport {migrateExtensionId} from './extension-id-migration';\nimport type {ExtensionIdMigrationCounts, ExtensionIdReference} from './extension-id-migration';\nimport {extensionStatus, syncExtensions, updateExtensions} from './extension-sync';\nimport type {ExtensionSyncConfirmContext, FetchImplementation} from './extension-sync';\nimport {importSb3} from './import';\nimport type {OutputReplacementContext} from './import';\nimport type {DirectoryDifferences} from './output-safety';\nimport {createDeterministicSb3, validateSb3Source} from './source';\n\nexport interface HelpCliOptions {\n command: 'help';\n}\n\nexport interface VersionCliOptions {\n command: 'version';\n}\n\nexport interface ImportCliOptions {\n command: 'import';\n discardLocalChanges: boolean;\n inputPath: string;\n outputDirectory: string;\n yes: boolean;\n}\n\nexport interface CheckCliOptions {\n allowedAssetRoots?: string[];\n command: 'check';\n projectAssetsPath?: string;\n sourceDirectory: string;\n}\n\nexport interface BuildCliOptions {\n allowedAssetRoots?: string[];\n cleanUpBlocks?: boolean;\n command: 'build';\n outputPath: string;\n projectAssetsPath?: string;\n sourceDirectory: string;\n yes: boolean;\n}\n\nexport interface ExtensionsStatusCliOptions {\n action: 'status';\n command: 'extensions';\n sourceDirectory: string;\n}\n\nexport interface ExtensionsMutationCliOptions {\n action: 'sync' | 'update';\n allowBreakingApi?: boolean;\n apiManifestArtifact?: string;\n command: 'extensions';\n extensionId?: string;\n migrateToId?: string;\n sourceArtifact?: string;\n sourceDirectory: string;\n yes: boolean;\n}\n\nexport interface ExtensionsMigrateIdCliOptions {\n action: 'migrate-id';\n command: 'extensions';\n fromId: string;\n sourceDirectory: string;\n toId: string;\n yes: boolean;\n}\n\nexport interface ExtensionsBundleCliOptions {\n action: 'bundle';\n bundleId: string;\n bundleName: string;\n command: 'extensions';\n extensionIds: string[];\n recoveryCapsule: boolean;\n sourceDirectory: string;\n yes: boolean;\n buildMode?: 'classic' | 'module';\n sharedDependencies?: Record<string, string>;\n}\n\nexport interface ExtensionsUnbundleSourceCliOptions {\n action: 'unbundle';\n bundleId: string;\n command: 'extensions';\n sourceDirectory: string;\n yes: boolean;\n}\n\nexport interface ExtensionsUnbundleArchiveCliOptions {\n action: 'unbundle';\n bundleId: string;\n command: 'extensions';\n inputPath: string;\n outputPath: string;\n yes: boolean;\n}\n\nexport type ExtensionsCliOptions =\n | ExtensionsStatusCliOptions\n | ExtensionsMutationCliOptions\n | ExtensionsMigrateIdCliOptions\n | ExtensionsBundleCliOptions\n | ExtensionsUnbundleSourceCliOptions\n | ExtensionsUnbundleArchiveCliOptions;\n\nexport type CliOptions =\n | HelpCliOptions\n | VersionCliOptions\n | ImportCliOptions\n | CheckCliOptions\n | BuildCliOptions\n | ExtensionsCliOptions;\n\nexport interface RunCliOptions {\n fetch?: FetchImplementation;\n log?: (message: string) => void;\n}\n\ninterface MigrationLogResult {\n applied: boolean;\n artifactReady: boolean;\n counts: ExtensionIdMigrationCounts;\n fromId: string | undefined;\n toId: string | undefined;\n totalChanges: number;\n unclassifiedReferences: ExtensionIdReference[];\n}\n\nexport function usage() {\n return `Usage:\n sb3-toolchain import INPUT.sb3 --output SOURCE_DIR [--yes] [--discard-local-changes]\n sb3-toolchain check SOURCE_DIR [--project-assets MANIFEST.json] [--allow-asset-root DIR ...]\n sb3-toolchain build SOURCE_DIR --output OUTPUT.sb3 [--project-assets MANIFEST.json] [--allow-asset-root DIR ...] [--clean-up-blocks] [--yes]\n sb3-toolchain extensions status SOURCE_DIR\n sb3-toolchain extensions sync SOURCE_DIR [--yes]\n sb3-toolchain extensions update SOURCE_DIR [EXTENSION_ID] [--migrate-id NEW_ID] [--artifact PATH] [--api-manifest-artifact PATH] [--allow-breaking-api --yes]\n sb3-toolchain extensions migrate-id SOURCE_DIR --from OLD_ID --to NEW_ID [--yes]\n sb3-toolchain extensions bundle SOURCE_DIR --id BUNDLE_ID --name NAME [EXTENSION_ID ...] [--build-mode classic|module] [--share PACKAGE@EXACT_VERSION] [--include-recovery-capsule] [--yes]\n sb3-toolchain extensions unbundle SOURCE_DIR BUNDLE_ID [--yes]\n sb3-toolchain extensions unbundle INPUT.sb3 BUNDLE_ID --output OUTPUT.sb3 [--yes]\n\nCommands:\n import Expand an SB3 into Git-friendly source files.\n check Validate an expanded SB3 source directory.\n build Build a deterministic SB3 from expanded sources.\n extensions Inspect, restore, or update managed embedded extensions.\n\nBuild layout cleanup:\n --clean-up-blocks applies a deterministic TurboWarp-style \"Clean up Blocks\"\n layout to every target in the generated SB3. It never deletes blocks,\n variables, lists, or comments. The expanded source is unchanged, but the\n generated SB3 might not be able to undo the coordinate changes.\n\nProject asset additions:\n --project-assets validates a JSON or YAML manifest and adds its sprites,\n backdrops, costumes, and sounds only to the generated SB3. Input files are confined to the\n manifest directory unless --allow-asset-root explicitly permits another root.\n\nReplacement safety:\n Differing outputs require interactive confirmation or --yes.\n Import refuses to discard uncommitted Git changes unless\n --discard-local-changes is also specified. --force is not supported.`;\n}\n\nfunction takeValue(arguments_: string[], index: number, option: string): string {\n const value = arguments_[index + 1];\n assert(value && !value.startsWith('-'), `${option} requires a value.`);\n return value;\n}\n\nfunction parseImportArguments(arguments_: string[]): ImportCliOptions {\n let inputPath: string | undefined;\n let outputDirectory: string | undefined;\n let discardLocalChanges = false;\n let yes = false;\n\n for (let index = 0; index < arguments_.length; index += 1) {\n const argument = arguments_[index];\n if (argument === '--output') {\n outputDirectory = path.resolve(takeValue(arguments_, index, '--output'));\n index += 1;\n } else if (argument === '--yes') {\n yes = true;\n } else if (argument === '--discard-local-changes') {\n discardLocalChanges = true;\n } else {\n assert(\n argument !== '--force',\n '--force is intentionally unsupported. Use --yes and, only when necessary, ' +\n '--discard-local-changes.',\n );\n assert(!argument.startsWith('-'), `Unknown option: ${argument}`);\n assert(!inputPath, 'Only one input SB3 may be specified.');\n inputPath = path.resolve(argument);\n }\n }\n\n assert(inputPath, 'The import command requires INPUT.sb3.');\n assert(outputDirectory, 'The import command requires --output SOURCE_DIR.');\n return {command: 'import', discardLocalChanges, inputPath, outputDirectory, yes};\n}\n\nfunction parseCheckArguments(arguments_: string[]): CheckCliOptions {\n const allowedAssetRoots: string[] = [];\n let projectAssetsPath: string | undefined;\n let sourceDirectory: string | undefined;\n for (let index = 0; index < arguments_.length; index += 1) {\n const argument = arguments_[index];\n if (argument === '--project-assets') {\n projectAssetsPath = path.resolve(takeValue(arguments_, index, '--project-assets'));\n index += 1;\n } else if (argument === '--allow-asset-root') {\n allowedAssetRoots.push(path.resolve(takeValue(arguments_, index, '--allow-asset-root')));\n index += 1;\n } else {\n assert(!argument.startsWith('-'), `Unknown option: ${argument}`);\n assert(!sourceDirectory, 'Only one SB3 source directory may be specified.');\n sourceDirectory = path.resolve(argument);\n }\n }\n assert(sourceDirectory, 'The check command requires SOURCE_DIR.');\n assert(\n allowedAssetRoots.length === 0 || projectAssetsPath,\n '--allow-asset-root requires --project-assets.',\n );\n return {\n ...(allowedAssetRoots.length > 0 ? {allowedAssetRoots} : {}),\n command: 'check',\n ...(projectAssetsPath ? {projectAssetsPath} : {}),\n sourceDirectory,\n };\n}\n\nfunction parseBuildArguments(arguments_: string[]): BuildCliOptions {\n const allowedAssetRoots: string[] = [];\n let cleanUpBlocks = false;\n let sourceDirectory: string | undefined;\n let outputPath: string | undefined;\n let projectAssetsPath: string | undefined;\n let yes = false;\n\n for (let index = 0; index < arguments_.length; index += 1) {\n const argument = arguments_[index];\n if (argument === '--clean-up-blocks') {\n cleanUpBlocks = true;\n } else if (argument === '--project-assets') {\n projectAssetsPath = path.resolve(takeValue(arguments_, index, '--project-assets'));\n index += 1;\n } else if (argument === '--allow-asset-root') {\n allowedAssetRoots.push(path.resolve(takeValue(arguments_, index, '--allow-asset-root')));\n index += 1;\n } else if (argument === '--output') {\n outputPath = path.resolve(takeValue(arguments_, index, '--output'));\n index += 1;\n } else if (argument === '--yes') {\n yes = true;\n } else {\n assert(!argument.startsWith('-'), `Unknown option: ${argument}`);\n assert(!sourceDirectory, 'Only one SB3 source directory may be specified.');\n sourceDirectory = path.resolve(argument);\n }\n }\n\n assert(sourceDirectory, 'The build command requires SOURCE_DIR.');\n assert(outputPath, 'The build command requires --output OUTPUT.sb3.');\n assert(\n allowedAssetRoots.length === 0 || projectAssetsPath,\n '--allow-asset-root requires --project-assets.',\n );\n return {\n ...(allowedAssetRoots.length > 0 ? {allowedAssetRoots} : {}),\n ...(cleanUpBlocks ? {cleanUpBlocks} : {}),\n command: 'build',\n outputPath,\n ...(projectAssetsPath ? {projectAssetsPath} : {}),\n sourceDirectory,\n yes,\n };\n}\n\nfunction parseExtensionMutationArguments(\n action: 'sync' | 'update',\n arguments_: string[],\n): ExtensionsMutationCliOptions {\n let allowBreakingApi = false;\n let apiManifestArtifact: string | undefined;\n let sourceDirectory: string | undefined;\n let extensionId: string | undefined;\n let migrateToId: string | undefined;\n let sourceArtifact: string | undefined;\n let yes = false;\n\n for (let index = 0; index < arguments_.length; index += 1) {\n const argument = arguments_[index];\n if (argument === '--yes') {\n yes = true;\n } else if (argument === '--allow-breaking-api') {\n assert(action === 'update', '--allow-breaking-api is only valid for extensions update.');\n allowBreakingApi = true;\n } else if (argument === '--migrate-id') {\n assert(action === 'update', '--migrate-id is only valid for extensions update.');\n migrateToId = takeValue(arguments_, index, '--migrate-id');\n index += 1;\n } else if (argument === '--artifact') {\n assert(action === 'update', '--artifact is only valid for extensions update.');\n sourceArtifact = takeValue(arguments_, index, '--artifact');\n index += 1;\n } else if (argument === '--api-manifest-artifact') {\n assert(action === 'update', '--api-manifest-artifact is only valid for extensions update.');\n apiManifestArtifact = takeValue(arguments_, index, '--api-manifest-artifact');\n index += 1;\n } else {\n assert(!argument.startsWith('-'), `Unknown option: ${argument}`);\n if (!sourceDirectory) {\n sourceDirectory = path.resolve(argument);\n } else {\n assert(action === 'update', `The extensions ${action} command accepts only SOURCE_DIR.`);\n assert(!extensionId, 'Only one EXTENSION_ID may be specified.');\n assert(\n /^[A-Za-z0-9._-]+$/u.test(argument),\n `Invalid embedded extension ID: ${JSON.stringify(argument)}`,\n );\n extensionId = argument;\n }\n }\n }\n\n assert(sourceDirectory, `The extensions ${action} command requires SOURCE_DIR.`);\n assert(\n migrateToId === undefined || extensionId !== undefined,\n '--migrate-id requires an explicit existing EXTENSION_ID.',\n );\n assert(\n sourceArtifact === undefined || migrateToId !== undefined,\n '--artifact requires --migrate-id.',\n );\n assert(\n apiManifestArtifact === undefined || migrateToId !== undefined,\n '--api-manifest-artifact requires --migrate-id.',\n );\n assert(!allowBreakingApi || yes, '--allow-breaking-api requires --yes.');\n return {\n action,\n ...(allowBreakingApi ? {allowBreakingApi} : {}),\n ...(apiManifestArtifact ? {apiManifestArtifact} : {}),\n command: 'extensions',\n extensionId,\n migrateToId,\n sourceArtifact,\n sourceDirectory,\n yes,\n };\n}\n\nfunction parseExtensionIdMigrationArguments(arguments_: string[]): ExtensionsMigrateIdCliOptions {\n let fromId: string | undefined;\n let sourceDirectory: string | undefined;\n let toId: string | undefined;\n let yes = false;\n\n for (let index = 0; index < arguments_.length; index += 1) {\n const argument = arguments_[index];\n if (argument === '--from') {\n fromId = takeValue(arguments_, index, '--from');\n index += 1;\n } else if (argument === '--to') {\n toId = takeValue(arguments_, index, '--to');\n index += 1;\n } else if (argument === '--yes') {\n yes = true;\n } else {\n assert(!argument.startsWith('-'), `Unknown option: ${argument}`);\n assert(!sourceDirectory, 'Only one SB3 source directory may be specified.');\n sourceDirectory = path.resolve(argument);\n }\n }\n assert(sourceDirectory, 'The extensions migrate-id command requires SOURCE_DIR.');\n assert(fromId, 'The extensions migrate-id command requires --from OLD_ID.');\n assert(toId, 'The extensions migrate-id command requires --to NEW_ID.');\n return {\n action: 'migrate-id',\n command: 'extensions',\n fromId,\n sourceDirectory,\n toId,\n yes,\n };\n}\n\nfunction parseExtensionBundleArguments(arguments_: string[]): ExtensionsBundleCliOptions {\n let bundleId: string | undefined;\n let bundleName: string | undefined;\n let recoveryCapsule = false;\n let sourceDirectory: string | undefined;\n const extensionIds: string[] = [];\n let yes = false;\n let buildMode: 'classic' | 'module' | undefined;\n const sharedDependencies: Record<string, string> = {};\n\n for (let index = 0; index < arguments_.length; index += 1) {\n const argument = arguments_[index];\n if (argument === '--id') {\n bundleId = takeValue(arguments_, index, '--id');\n index += 1;\n } else if (argument === '--name') {\n bundleName = takeValue(arguments_, index, '--name');\n index += 1;\n } else if (argument === '--yes') {\n yes = true;\n } else if (argument === '--include-recovery-capsule') {\n recoveryCapsule = true;\n } else if (argument === '--build-mode') {\n const value = takeValue(arguments_, index, '--build-mode');\n assert(value === 'classic' || value === 'module', '--build-mode must be classic or module.');\n buildMode = value;\n index += 1;\n } else if (argument === '--share') {\n const value = takeValue(arguments_, index, '--share');\n const separator = value.lastIndexOf('@');\n assert(separator > 0, '--share requires PACKAGE@EXACT_VERSION.');\n const name = value.slice(0, separator);\n assert(\n /^(?:@[a-z0-9][a-z0-9._-]*\\/)?[a-z0-9][a-z0-9._-]*$/u.test(name),\n `Invalid shared dependency name: ${name}`,\n );\n assert(\n /^\\d+\\.\\d+\\.\\d+(?:-[0-9A-Za-z.-]+)?$/u.test(value.slice(separator + 1)),\n '--share requires an exact semantic version.',\n );\n assert(!Object.hasOwn(sharedDependencies, name), `Duplicate shared dependency: ${name}`);\n sharedDependencies[name] = value.slice(separator + 1);\n index += 1;\n } else {\n assert(!argument.startsWith('-'), `Unknown option: ${argument}`);\n if (!sourceDirectory) {\n sourceDirectory = path.resolve(argument);\n } else {\n assert(\n /^[a-z0-9]+$/u.test(argument),\n `Bundle member ID must use TurboWarp's [a-z0-9]+ format: ${JSON.stringify(argument)}`,\n );\n extensionIds.push(argument);\n }\n }\n }\n assert(sourceDirectory, 'The extensions bundle command requires SOURCE_DIR.');\n assert(bundleId, 'The extensions bundle command requires --id BUNDLE_ID.');\n assert(bundleName, 'The extensions bundle command requires --name NAME.');\n assert(\n !Object.keys(sharedDependencies).length || buildMode === 'module',\n '--share requires --build-mode module.',\n );\n return {\n action: 'bundle',\n bundleId,\n bundleName,\n command: 'extensions',\n extensionIds,\n recoveryCapsule,\n sourceDirectory,\n yes,\n ...(buildMode === undefined ? {} : {buildMode}),\n ...(Object.keys(sharedDependencies).length ? {sharedDependencies} : {}),\n };\n}\n\nfunction parseExtensionUnbundleArguments(\n arguments_: string[],\n): ExtensionsUnbundleSourceCliOptions | ExtensionsUnbundleArchiveCliOptions {\n let bundleId: string | undefined;\n let input: string | undefined;\n let outputPath: string | undefined;\n let yes = false;\n for (let index = 0; index < arguments_.length; index += 1) {\n const argument = arguments_[index];\n if (argument === '--yes') {\n yes = true;\n } else if (argument === '--output') {\n outputPath = path.resolve(takeValue(arguments_, index, '--output'));\n index += 1;\n } else {\n assert(!argument.startsWith('-'), `Unknown option: ${argument}`);\n if (!input) {\n input = path.resolve(argument);\n } else {\n assert(!bundleId, 'Only one BUNDLE_ID may be specified.');\n bundleId = argument;\n }\n }\n }\n assert(input, 'The extensions unbundle command requires SOURCE_DIR or INPUT.sb3.');\n assert(bundleId, 'The extensions unbundle command requires BUNDLE_ID.');\n if (path.extname(input).toLowerCase() === '.sb3') {\n assert(outputPath, 'SB3 unbundle requires --output OUTPUT.sb3.');\n return {\n action: 'unbundle',\n bundleId,\n command: 'extensions',\n inputPath: input,\n outputPath,\n yes,\n };\n }\n assert(!outputPath, '--output is only valid when unbundling an SB3 file.');\n return {\n action: 'unbundle',\n bundleId,\n command: 'extensions',\n sourceDirectory: input,\n yes,\n };\n}\n\nfunction parseExtensionsArguments(arguments_: string[]): ExtensionsCliOptions {\n const [action, ...actionArguments] = arguments_;\n assert(\n action === 'bundle' ||\n action === 'migrate-id' ||\n action === 'status' ||\n action === 'sync' ||\n action === 'unbundle' ||\n action === 'update',\n 'The extensions command requires status, sync, update, migrate-id, bundle, or unbundle.',\n );\n if (action === 'status') {\n assert(\n actionArguments.length === 1 && !actionArguments[0].startsWith('-'),\n 'The extensions status command requires exactly one SOURCE_DIR.',\n );\n return {\n action,\n command: 'extensions',\n sourceDirectory: path.resolve(actionArguments[0]),\n };\n }\n if (action === 'migrate-id') {\n return parseExtensionIdMigrationArguments(actionArguments);\n }\n if (action === 'bundle') {\n return parseExtensionBundleArguments(actionArguments);\n }\n if (action === 'unbundle') {\n return parseExtensionUnbundleArguments(actionArguments);\n }\n return parseExtensionMutationArguments(action, actionArguments);\n}\n\nexport function parseCliArguments(arguments_: string[]): CliOptions {\n const normalized = arguments_.filter((argument) => argument !== '--');\n if (normalized.length === 0 || normalized[0] === '--help' || normalized[0] === '-h') {\n return {command: 'help'};\n }\n if (normalized[0] === '--version' || normalized[0] === '-v') {\n return {command: 'version'};\n }\n\n const [command, ...commandArguments] = normalized;\n if (commandArguments.includes('--help') || commandArguments.includes('-h')) {\n return {command: 'help'};\n }\n if (command === 'import') return parseImportArguments(commandArguments);\n if (command === 'check') return parseCheckArguments(commandArguments);\n if (command === 'build') return parseBuildArguments(commandArguments);\n if (command === 'extensions') return parseExtensionsArguments(commandArguments);\n throw new Error(`Unknown command: ${command}`);\n}\n\nfunction formatDifferenceLines(differences: DirectoryDifferences): string {\n const labels: Record<string, string> = {added: '+', modified: '~', removed: '-'};\n const lines = Object.entries(differences).flatMap(([kind, paths]) =>\n paths.map((relativePath: string) => `${labels[kind]} ${relativePath}`),\n );\n const visibleLines = lines.slice(0, 12);\n if (lines.length > visibleLines.length) {\n visibleLines.push(`... and ${lines.length - visibleLines.length} more`);\n }\n return visibleLines.join('\\n');\n}\n\nasync function confirmImportReplacement(context: OutputReplacementContext): Promise<boolean> {\n const {comparison, discardLocalChanges, gitState, outputDirectory} = context;\n assert(\n process.stdin.isTTY && process.stdout.isTTY,\n `Output directory already exists: ${outputDirectory}. ` +\n 'Non-interactive replacement requires --yes.',\n );\n const readline = createInterface({input: process.stdin, output: process.stdout});\n try {\n const gitMessage = gitState.clean\n ? 'Git state: clean'\n : 'Git state: uncommitted changes will be discarded';\n const answer = await readline.question(\n `Existing SB3 source differs from the import candidate:\\n` +\n ` ${outputDirectory}\\n` +\n `${formatDifferenceLines(comparison.differences)}\\n` +\n `${gitMessage}\\n` +\n `${discardLocalChanges ? 'WARNING: --discard-local-changes is active.\\n' : ''}` +\n 'Replace the existing source directory? [y/N] ',\n );\n return /^(?:y|yes)$/iu.test(answer.trim());\n } finally {\n readline.close();\n }\n}\n\nasync function confirmBuildReplacement(outputPath: string): Promise<boolean> {\n assert(\n process.stdin.isTTY && process.stdout.isTTY,\n `Existing SB3 output differs: ${outputPath}. Non-interactive replacement requires --yes.`,\n );\n const readline = createInterface({input: process.stdin, output: process.stdout});\n try {\n const answer = await readline.question(\n `Existing generated SB3 will be replaced:\\n ${outputPath}\\nContinue? [y/N] `,\n );\n return /^(?:y|yes)$/iu.test(answer.trim());\n } finally {\n readline.close();\n }\n}\n\nasync function confirmExtensionReplacement({\n comparison,\n sourceDirectory,\n}: ExtensionSyncConfirmContext): Promise<boolean> {\n assert(\n process.stdin.isTTY && process.stdout.isTTY,\n `Managed extension files differ in ${sourceDirectory}. ` +\n 'Non-interactive replacement requires --yes.',\n );\n const readline = createInterface({input: process.stdin, output: process.stdout});\n try {\n const answer = await readline.question(\n `Managed extension changes will be installed:\\n` +\n ` ${sourceDirectory}\\n` +\n `${formatDifferenceLines(comparison.differences)}\\n` +\n 'Replace these files? [y/N] ',\n );\n return /^(?:y|yes)$/iu.test(answer.trim());\n } finally {\n readline.close();\n }\n}\n\nfunction logMigrationResult(result: MigrationLogResult, log: (message: string) => void): void {\n const counts = Object.entries(result.counts)\n .filter(([, count]) => count > 0)\n .map(([kind, count]) => `${kind}=${count}`)\n .join(', ');\n const action = result.applied ? 'Migrated' : 'Dry run';\n log(\n `${action}: ${result.fromId} -> ${result.toId}; ` +\n `${result.totalChanges} classified changes (${counts || 'none'}); ` +\n `artifact=${result.artifactReady ? 'ready' : 'requires-new-ID'}.`,\n );\n for (const reference of result.unclassifiedReferences) {\n log(\n `Unclassified ${reference.kind}: ${reference.file}${reference.path} = ` +\n JSON.stringify(reference.value),\n );\n }\n}\n\nexport async function runCli(\n arguments_: string[],\n {fetch: fetchImplementation = globalThis.fetch, log = console.log}: RunCliOptions = {},\n): Promise<void> {\n const options = parseCliArguments(arguments_);\n if (options.command === 'help') {\n log(usage());\n return;\n }\n if (options.command === 'version') {\n log(packageVersion);\n return;\n }\n if (options.command === 'check') {\n assert(\n 'sourceDirectory' in options && !('action' in options),\n 'Internal CLI check command routing error.',\n );\n if (options.projectAssetsPath) {\n const result = await createDeterministicSb3(options.sourceDirectory, {\n allowedAssetRoots: options.allowedAssetRoots,\n projectAssetsPath: options.projectAssetsPath,\n });\n log(\n `Valid SB3 source with project assets: ${result.source.resolvedSourceDirectory} ` +\n `(${result.entryCount} entries, ${result.assetCount} assets, ` +\n `${result.assetReferenceCount} references, ${result.embeddedExtensionCount} embedded extensions).`,\n );\n return;\n }\n const result = await validateSb3Source(options.sourceDirectory);\n log(\n `Valid SB3 source: ${result.resolvedSourceDirectory} ` +\n `(${result.sourceManifest.archiveEntries.length} entries, ` +\n `${result.assetContents.size} assets, ${result.assetReferenceCount} references, ` +\n `${result.extensions.length} embedded extensions).`,\n );\n return;\n }\n if (\n options.command === 'build' &&\n 'outputPath' in options &&\n 'sourceDirectory' in options &&\n !('action' in options)\n ) {\n const result = await buildSb3({\n allowedAssetRoots: options.allowedAssetRoots,\n cleanUpBlocks: options.cleanUpBlocks,\n confirmReplace: confirmBuildReplacement,\n outputPath: options.outputPath,\n projectAssetsPath: options.projectAssetsPath,\n sourceDirectory: options.sourceDirectory,\n yes: options.yes,\n });\n const action = result.changed ? 'Built' : 'Already up to date';\n const cleanUpMessage = result.blockCleanUp\n ? `, ${result.blockCleanUp.movedScriptCount}/${result.blockCleanUp.scriptCount} scripts laid out`\n : '';\n log(\n `${action}: ${result.outputPath} (${result.entryCount} entries, ` +\n `${result.assetCount} assets, ${result.embeddedExtensionCount} embedded extensions` +\n `${cleanUpMessage}).`,\n );\n if (result.rollbackCleanupWarning) log(result.rollbackCleanupWarning);\n return;\n }\n if (options.command === 'extensions') {\n if (options.action === 'bundle') {\n const result = await bundleExtensions({\n bundleId: options.bundleId,\n bundleName: options.bundleName,\n extensionIds: options.extensionIds,\n recoveryCapsule: options.recoveryCapsule,\n buildMode: options.buildMode,\n sharedDependencies: options.sharedDependencies,\n sourceDirectory: options.sourceDirectory,\n yes: options.yes,\n });\n log(\n `${result.applied ? 'Configured' : 'Dry run'} extension bundle: ${result.bundleId} ` +\n `(${result.members.join(', ')}).`,\n );\n if (result.rollbackCleanupWarning) log(result.rollbackCleanupWarning);\n return;\n }\n if (options.action === 'unbundle') {\n if ('inputPath' in options) {\n const result = await unbundleSb3({\n bundleId: options.bundleId,\n inputPath: options.inputPath,\n outputPath: options.outputPath,\n yes: options.yes,\n });\n log(\n `${result.applied ? 'Wrote' : 'Dry run'} unbundled SB3: ${result.bundleId} ` +\n `(${result.members.join(', ')}) -> ${result.outputPath}.`,\n );\n if (result.rollbackCleanupWarning) log(result.rollbackCleanupWarning);\n return;\n }\n const result = await unbundleExtensions({\n bundleId: options.bundleId,\n sourceDirectory: options.sourceDirectory,\n yes: options.yes,\n });\n log(\n `${result.applied ? 'Removed' : 'Dry run'} extension bundle: ${result.bundleId} ` +\n `(${result.members.join(', ')}).`,\n );\n if (result.rollbackCleanupWarning) log(result.rollbackCleanupWarning);\n return;\n }\n if (options.action === 'migrate-id') {\n const result = await migrateExtensionId({\n fromId: options.fromId,\n sourceDirectory: options.sourceDirectory,\n toId: options.toId,\n yes: options.yes,\n });\n logMigrationResult(result, log);\n if (result.rollbackCleanupWarning) log(result.rollbackCleanupWarning);\n return;\n }\n if (options.action === 'status') {\n const statuses = await extensionStatus(options.sourceDirectory, {\n fetch: fetchImplementation,\n });\n if (statuses.length === 0) {\n log(`No managed embedded extensions: ${options.sourceDirectory}`);\n return;\n }\n for (const status of statuses) {\n if ('package' in status) {\n log(\n `${status.id}: ${status.state}; local=${status.local}; ` +\n `${status.package}@${status.version} (installed ${status.installedVersion})`,\n );\n continue;\n }\n log(\n `${status.id}: ${status.state}; local=${status.local}; ` +\n `${status.ref} -> ${status.remoteCommit} ` +\n `(installed ${status.resolvedCommit})`,\n );\n }\n return;\n }\n\n const operationOptions = {\n confirmReplace: confirmExtensionReplacement,\n fetch: fetchImplementation,\n sourceDirectory: options.sourceDirectory,\n yes: options.yes,\n };\n const result =\n options.action === 'sync'\n ? await syncExtensions(operationOptions)\n : await updateExtensions({\n ...operationOptions,\n allowBreakingApi: options.allowBreakingApi,\n apiManifestArtifact: options.apiManifestArtifact,\n extensionId: options.extensionId,\n migrateToId: options.migrateToId,\n sourceArtifact: options.sourceArtifact,\n });\n const action = result.changed ? 'Updated' : 'Already up to date';\n log(\n `${action}: ${result.sourceDirectory} ` +\n `(${result.extensions.map((extension) => extension.id).join(', ')}).`,\n );\n if (result.migration) {\n logMigrationResult(\n {\n applied: result.changed,\n artifactReady: true,\n ...result.migration,\n },\n log,\n );\n }\n for (const compatibility of result.apiCompatibility) {\n for (const change of compatibility.changes) {\n log(\n `API ${compatibility.id}: ${change.breaking ? 'breaking' : 'compatible'} ` +\n `${change.kind} ${change.path}`,\n );\n }\n }\n if (result.rollbackCleanupWarning) log(result.rollbackCleanupWarning);\n return;\n }\n\n assert(\n options.command === 'import' && 'inputPath' in options,\n 'Internal CLI command routing error.',\n );\n const result = await importSb3({\n confirmReplace: confirmImportReplacement,\n discardLocalChanges: options.discardLocalChanges,\n inputPath: options.inputPath,\n outputDirectory: options.outputDirectory,\n yes: options.yes,\n });\n if (result.changed) {\n const differenceMessage = result.differenceCounts\n ? ` Changes: +${result.differenceCounts.added} ` +\n `~${result.differenceCounts.modified} -${result.differenceCounts.removed}.`\n : '';\n log(\n `Imported ${result.archiveEntryCount} SB3 entries into ${result.outputDirectory} ` +\n `(${result.assetCount} assets, ${result.embeddedExtensionCount} embedded extensions).` +\n differenceMessage,\n );\n } else {\n log(`Already up to date; no files changed: ${result.outputDirectory}`);\n }\n if (result.rollbackCleanupWarning) log(result.rollbackCleanupWarning);\n}\n"],"mappings":";;;;;;;;;;;;;AA6IA,SAAgB,QAAQ;CACtB,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiCT;AAEA,SAAS,UAAU,YAAsB,OAAe,QAAwB;CAC9E,MAAM,QAAQ,WAAW,QAAQ;CACjC,OAAO,SAAS,CAAC,MAAM,WAAW,GAAG,GAAG,GAAG,OAAO,mBAAmB;CACrE,OAAO;AACT;AAEA,SAAS,qBAAqB,YAAwC;CACpE,IAAI;CACJ,IAAI;CACJ,IAAI,sBAA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Ac,UAAU,EAAE,CAAC,CAAC,KAAK,IAAI,EAAE,GACtE;EACA,IAAI,OAAO,WACT,mBACE;GACE,SAAS,OAAO;GAChB,eAAe;GACf,GAAG,OAAO;EACZ,GACA,GACF;EAEF,KAAK,MAAM,iBAAiB,OAAO,kBACjC,KAAK,MAAM,UAAU,cAAc,SACjC,IACE,OAAO,cAAc,GAAG,IAAI,OAAO,WAAW,aAAa,aAAa,GACnE,OAAO,KAAK,GAAG,OAAO,MAC7B;EAGJ,IAAI,OAAO,wBAAwB,IAAI,OAAO,sBAAsB;EACpE;CACF;CAEA,OACE,QAAQ,YAAY,YAAY,eAAe,SAC/C,qCACF;CACA,MAAM,SAAS,MAAM,UAAU;EAC7B,gBAAgB;EAChB,qBAAqB,QAAQ;EAC7B,WAAW,QAAQ;EACnB,iBAAiB,QAAQ;EACzB,KAAK,QAAQ;CACf,CAAC;CACD,IAAI,OAAO,SAAS;EAClB,MAAM,oBAAoB,OAAO,mBAC7B,cAAc,OAAO,iBAAiB,MAAM,IACxC,OAAO,iBAAiB,SAAS,IAAI,OAAO,iBAAiB,QAAQ,KACzE;EACJ,IACE,YAAY,OAAO,kBAAkB,oBAAoB,OAAO,gBAAgB,IAC1E,OAAO,WAAW,WAAW,OAAO,uBAAuB,0BAC/D,iBACJ;CACF,OACE,IAAI,yCAAyC,OAAO,iBAAiB;CAEvE,IAAI,OAAO,wBAAwB,IAAI,OAAO,sBAAsB;AACtE"}
@@ -1,2 +1,2 @@
1
1
  export declare const packageName = "@kubohiroya/sb3-toolchain";
2
- export declare const packageVersion = "0.16.0";
2
+ export declare const packageVersion = "0.17.0";
package/dist/constants.js CHANGED
@@ -1,6 +1,6 @@
1
1
  //#region src/constants.ts
2
2
  var packageName = "@kubohiroya/sb3-toolchain";
3
- var packageVersion = "0.16.0";
3
+ var packageVersion = "0.17.0";
4
4
  //#endregion
5
5
  export { packageName, packageVersion };
6
6
 
@@ -1 +1 @@
1
- {"version":3,"file":"constants.js","names":[],"sources":["../src/constants.ts"],"sourcesContent":["// SPDX-License-Identifier: MPL-2.0\n\nexport const packageName = '@kubohiroya/sb3-toolchain';\nexport const packageVersion = '0.16.0';\n"],"mappings":";AAEA,IAAa,cAAc;AAC3B,IAAa,iBAAiB"}
1
+ {"version":3,"file":"constants.js","names":[],"sources":["../src/constants.ts"],"sourcesContent":["// SPDX-License-Identifier: MPL-2.0\n\nexport const packageName = '@kubohiroya/sb3-toolchain';\nexport const packageVersion = '0.17.0';\n"],"mappings":";AAEA,IAAa,cAAc;AAC3B,IAAa,iBAAiB"}
@@ -1,5 +1,7 @@
1
+ import { ExtensionModuleBuildReport } from './extension-module-bundle';
1
2
  import { ExtensionBundlePlan } from './extension-bundle';
2
3
  import { DirectoryComparison } from './output-safety';
4
+ import { ExtensionBundleConfiguration } from './types';
3
5
  interface ExtensionBundleComponentMetadata {
4
6
  author: string | null;
5
7
  description: string | null;
@@ -14,6 +16,8 @@ export interface ExtensionBundleConfigurationInput {
14
16
  recoveryCapsule?: boolean;
15
17
  sourceDirectory: string;
16
18
  yes?: boolean;
19
+ buildMode?: ExtensionBundleConfiguration['buildMode'];
20
+ sharedDependencies?: Record<string, string>;
17
21
  }
18
22
  export interface ExtensionBundlePlanResult {
19
23
  applied: boolean;
@@ -25,6 +29,7 @@ export interface ExtensionBundlePlanResult {
25
29
  members: string[];
26
30
  recoveryCapsule: boolean;
27
31
  sourceDirectory: string;
32
+ moduleBuild?: ExtensionModuleBuildReport;
28
33
  }
29
34
  export interface ExtensionBundleApplyResult extends ExtensionBundlePlanResult {
30
35
  comparison?: DirectoryComparison;
@@ -41,8 +46,8 @@ export interface ExtensionUnbundleApplyResult extends ExtensionUnbundlePlanResul
41
46
  comparison?: DirectoryComparison;
42
47
  rollbackCleanupWarning: string | null;
43
48
  }
44
- export declare function planExtensionBundle({ bundleId, bundleName, extensionIds, recoveryCapsule, sourceDirectory, }: ExtensionBundleConfigurationInput): Promise<ExtensionBundlePlanResult>;
45
- export declare function bundleExtensions({ bundleId, bundleName, extensionIds, recoveryCapsule, sourceDirectory, yes, }: ExtensionBundleConfigurationInput): Promise<ExtensionBundleApplyResult>;
49
+ export declare function planExtensionBundle({ bundleId, bundleName, extensionIds, recoveryCapsule, sourceDirectory, buildMode, sharedDependencies, }: ExtensionBundleConfigurationInput): Promise<ExtensionBundlePlanResult>;
50
+ export declare function bundleExtensions({ bundleId, bundleName, extensionIds, recoveryCapsule, sourceDirectory, yes, buildMode, sharedDependencies, }: ExtensionBundleConfigurationInput): Promise<ExtensionBundleApplyResult>;
46
51
  export declare function planExtensionUnbundle({ bundleId, sourceDirectory, }: {
47
52
  bundleId: string;
48
53
  sourceDirectory: string;
@@ -1,6 +1,7 @@
1
1
  import { assert } from "./assert.js";
2
2
  import { assertNoInterruptedRollback, compareDirectories, pathExists, replaceDirectoryTransactionally } from "./output-safety.js";
3
- import { buildExtensionBundles, validateBundleId, validateBundleName, validateExtensionBundleConfigurations } from "./extension-bundle.js";
3
+ import { validateBundleId, validateBundleName, validateExtensionBundleConfigurations } from "./extension-bundle.js";
4
+ import { buildExtensionBundlesWithModules } from "./extension-module-bundle.js";
4
5
  import { createDeterministicSb3, inspectSb3SourceForExtensionSync } from "./source.js";
5
6
  import path from "node:path";
6
7
  import { cp, lstat, mkdtemp, readFile, rm, writeFile } from "node:fs/promises";
@@ -20,7 +21,7 @@ async function readExtensionManifest(source) {
20
21
  const manifestPath = path.join(source.resolvedSourceDirectory, source.sourceManifest.embeddedExtensions);
21
22
  return JSON.parse(await readFile(manifestPath, "utf8"));
22
23
  }
23
- async function configurationContext({ bundleId, bundleName, extensionIds, recoveryCapsule, sourceDirectory, willReplace }) {
24
+ async function configurationContext({ bundleId, bundleName, extensionIds, recoveryCapsule, buildMode, sharedDependencies, sourceDirectory, willReplace }) {
24
25
  validateBundleId(bundleId);
25
26
  validateBundleName(bundleName);
26
27
  assert(typeof recoveryCapsule === "boolean", "recoveryCapsule must be a boolean.");
@@ -35,10 +36,13 @@ async function configurationContext({ bundleId, bundleName, extensionIds, recove
35
36
  id: bundleId,
36
37
  members,
37
38
  name: bundleName,
39
+ ...buildMode === void 0 ? {} : { buildMode },
40
+ ...sharedDependencies === void 0 ? {} : { sharedDependencies },
38
41
  ...recoveryCapsule === true ? { recoveryCapsule: true } : {}
39
42
  }];
40
43
  const extensionBundles = validateExtensionBundleConfigurations(candidateManifest.extensionBundles, candidateManifest.extensions);
41
- const buildPlan = buildExtensionBundles({
44
+ const buildPlan = await buildExtensionBundlesWithModules({
45
+ sourceDirectory: source.resolvedSourceDirectory,
42
46
  extensionBundles,
43
47
  extensionContents: source.extensionContents,
44
48
  extensions: source.extensions,
@@ -54,13 +58,15 @@ async function configurationContext({ bundleId, bundleName, extensionIds, recove
54
58
  source
55
59
  };
56
60
  }
57
- async function planExtensionBundle({ bundleId, bundleName, extensionIds, recoveryCapsule = false, sourceDirectory }) {
61
+ async function planExtensionBundle({ bundleId, bundleName, extensionIds, recoveryCapsule = false, sourceDirectory, buildMode, sharedDependencies }) {
58
62
  const context = await configurationContext({
59
63
  bundleId,
60
64
  bundleName,
61
65
  extensionIds,
62
66
  recoveryCapsule,
63
67
  sourceDirectory,
68
+ buildMode,
69
+ sharedDependencies,
64
70
  willReplace: false
65
71
  });
66
72
  return {
@@ -72,7 +78,8 @@ async function planExtensionBundle({ bundleId, bundleName, extensionIds, recover
72
78
  counts: context.configuredBundle.counts,
73
79
  members: [...context.configuredBundle.bundle.members],
74
80
  recoveryCapsule: context.configuredBundle.bundle.recoveryCapsule === true,
75
- sourceDirectory: context.source.resolvedSourceDirectory
81
+ sourceDirectory: context.source.resolvedSourceDirectory,
82
+ ...context.configuredBundle.moduleBuild ? { moduleBuild: context.configuredBundle.moduleBuild } : {}
76
83
  };
77
84
  }
78
85
  async function installManifestConfiguration(context, operation) {
@@ -107,13 +114,15 @@ async function installManifestConfiguration(context, operation) {
107
114
  });
108
115
  }
109
116
  }
110
- async function bundleExtensions({ bundleId, bundleName, extensionIds, recoveryCapsule = false, sourceDirectory, yes = false }) {
117
+ async function bundleExtensions({ bundleId, bundleName, extensionIds, recoveryCapsule = false, sourceDirectory, yes = false, buildMode, sharedDependencies }) {
111
118
  const context = await configurationContext({
112
119
  bundleId,
113
120
  bundleName,
114
121
  extensionIds,
115
122
  recoveryCapsule,
116
123
  sourceDirectory,
124
+ buildMode,
125
+ sharedDependencies,
117
126
  willReplace: yes
118
127
  });
119
128
  const plan = {
@@ -123,7 +132,8 @@ async function bundleExtensions({ bundleId, bundleName, extensionIds, recoveryCa
123
132
  counts: context.configuredBundle.counts,
124
133
  members: [...context.configuredBundle.bundle.members],
125
134
  recoveryCapsule: context.configuredBundle.bundle.recoveryCapsule === true,
126
- sourceDirectory: context.source.resolvedSourceDirectory
135
+ sourceDirectory: context.source.resolvedSourceDirectory,
136
+ ...context.configuredBundle.moduleBuild ? { moduleBuild: context.configuredBundle.moduleBuild } : {}
127
137
  };
128
138
  if (!yes) return {
129
139
  applied: false,
@@ -1 +1 @@
1
- {"version":3,"file":"extension-bundle-configuration.js","names":[],"sources":["../src/extension-bundle-configuration.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} from './assert';\nimport {\n buildExtensionBundles,\n validateBundleId,\n validateBundleName,\n validateExtensionBundleConfigurations,\n} from './extension-bundle';\nimport type {ExtensionBundlePlan} from './extension-bundle';\nimport {\n assertNoInterruptedRollback,\n compareDirectories,\n pathExists,\n replaceDirectoryTransactionally,\n} from './output-safety';\nimport type {DirectoryComparison} from './output-safety';\nimport {createDeterministicSb3, inspectSb3SourceForExtensionSync} from './source';\nimport type {InspectedSb3Source} from './source';\nimport type {EmbeddedExtensionManifest, ExtensionBundleConfiguration} from './types';\n\ninterface ExtensionBundleComponentMetadata {\n author: string | null;\n description: string | null;\n id: string | null;\n license: string | null;\n name: string | null;\n}\n\ninterface ConfigurationContext {\n buildPlan: ReturnType<typeof buildExtensionBundles>;\n candidateManifest: EmbeddedExtensionManifest;\n configuredBundle: ExtensionBundlePlan;\n extensionManifest: EmbeddedExtensionManifest;\n source: InspectedSb3Source;\n}\n\ninterface UnbundleContext {\n candidateManifest: EmbeddedExtensionManifest;\n extensionManifest: EmbeddedExtensionManifest;\n removedBundle: ExtensionBundleConfiguration;\n source: InspectedSb3Source;\n}\n\nexport interface ExtensionBundleConfigurationInput {\n bundleId: string;\n bundleName: string;\n extensionIds?: string[];\n recoveryCapsule?: boolean;\n sourceDirectory: string;\n yes?: boolean;\n}\n\nexport interface ExtensionBundlePlanResult {\n applied: boolean;\n bundleId: string;\n bundleName: string;\n changed: boolean;\n components: ExtensionBundleComponentMetadata[];\n counts: ExtensionBundlePlan['counts'];\n members: string[];\n recoveryCapsule: boolean;\n sourceDirectory: string;\n}\n\nexport interface ExtensionBundleApplyResult extends ExtensionBundlePlanResult {\n comparison?: DirectoryComparison;\n rollbackCleanupWarning: string | null;\n}\n\nexport interface ExtensionUnbundlePlanResult {\n applied: boolean;\n bundleId: string;\n changed: boolean;\n members: string[];\n sourceDirectory: string;\n}\n\nexport interface ExtensionUnbundleApplyResult extends ExtensionUnbundlePlanResult {\n comparison?: DirectoryComparison;\n rollbackCleanupWarning: string | null;\n}\n\nasync function inspectConfigurationSource(\n sourceDirectory: string,\n 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 while configuring extension bundles.',\n );\n assert(\n !(await pathExists(path.join(resolvedSourceDirectory, '.git'))),\n 'Refusing to replace a Git repository root while configuring extension bundles.',\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) await assertNoInterruptedRollback(resolvedSourceDirectory);\n return inspectSb3SourceForExtensionSync(resolvedSourceDirectory);\n}\n\nasync function readExtensionManifest(\n source: InspectedSb3Source,\n): Promise<EmbeddedExtensionManifest> {\n const manifestPath = path.join(\n source.resolvedSourceDirectory,\n source.sourceManifest.embeddedExtensions,\n );\n return JSON.parse(await readFile(manifestPath, 'utf8')) as EmbeddedExtensionManifest;\n}\n\nasync function configurationContext({\n bundleId,\n bundleName,\n extensionIds,\n recoveryCapsule,\n sourceDirectory,\n willReplace,\n}: Required<\n Pick<\n ExtensionBundleConfigurationInput,\n 'bundleId' | 'bundleName' | 'recoveryCapsule' | 'sourceDirectory'\n >\n> & {\n extensionIds?: string[];\n willReplace: boolean;\n}): Promise<ConfigurationContext> {\n validateBundleId(bundleId);\n validateBundleName(bundleName);\n assert(typeof recoveryCapsule === 'boolean', 'recoveryCapsule must be a boolean.');\n const source = await inspectConfigurationSource(sourceDirectory, willReplace);\n const extensionManifest = await readExtensionManifest(source);\n const existingBundles = validateExtensionBundleConfigurations(\n extensionManifest.extensionBundles,\n extensionManifest.extensions,\n );\n assert(\n !existingBundles.some((bundle) => bundle.id === bundleId),\n `Extension bundle already exists: ${bundleId}`,\n );\n const alreadyBundled = new Set(existingBundles.flatMap((bundle) => bundle.members));\n const members =\n extensionIds && extensionIds.length > 0\n ? [...extensionIds]\n : source.extensions\n .map((extension) => extension.id)\n .filter((extensionId) => !alreadyBundled.has(extensionId));\n const candidateManifest = structuredClone(extensionManifest);\n candidateManifest.extensionBundles = [\n ...existingBundles,\n {\n id: bundleId,\n members,\n name: bundleName,\n ...(recoveryCapsule === true ? {recoveryCapsule: true} : {}),\n },\n ];\n const extensionBundles = validateExtensionBundleConfigurations(\n candidateManifest.extensionBundles,\n candidateManifest.extensions,\n );\n const buildPlan = buildExtensionBundles({\n extensionBundles,\n extensionContents: source.extensionContents,\n extensions: source.extensions,\n project: source.project,\n });\n const configuredBundle = buildPlan.bundlePlans.find((plan) => plan.bundle.id === bundleId);\n assert(configuredBundle, `Extension bundle plan was not produced: ${bundleId}`);\n return {buildPlan, candidateManifest, configuredBundle, extensionManifest, source};\n}\n\nexport async function planExtensionBundle({\n bundleId,\n bundleName,\n extensionIds,\n recoveryCapsule = false,\n sourceDirectory,\n}: ExtensionBundleConfigurationInput): Promise<ExtensionBundlePlanResult> {\n const context = await configurationContext({\n bundleId,\n bundleName,\n extensionIds,\n recoveryCapsule,\n sourceDirectory,\n willReplace: false,\n });\n return {\n applied: false,\n bundleId,\n bundleName,\n changed: true,\n components: context.configuredBundle.components.map((component) => component.metadata),\n counts: context.configuredBundle.counts,\n members: [...context.configuredBundle.bundle.members],\n recoveryCapsule: context.configuredBundle.bundle.recoveryCapsule === true,\n sourceDirectory: context.source.resolvedSourceDirectory,\n };\n}\n\nasync function installManifestConfiguration(\n context: ConfigurationContext | UnbundleContext,\n operation: string,\n): Promise<{comparison: DirectoryComparison; rollbackCleanupWarning: string | null}> {\n const initialComparison = await compareDirectories(\n context.source.resolvedSourceDirectory,\n context.source.resolvedSourceDirectory,\n );\n assert(\n initialComparison.identical &&\n initialComparison.existingFingerprint === initialComparison.candidateFingerprint,\n `SB3 source changed while its initial ${operation} state was inspected.`,\n );\n const parentDirectory = path.dirname(context.source.resolvedSourceDirectory);\n const candidateDirectory = await mkdtemp(\n path.join(parentDirectory, `.${path.basename(context.source.resolvedSourceDirectory)}.bundle-`),\n );\n let installed = false;\n try {\n await cp(context.source.resolvedSourceDirectory, candidateDirectory, {\n preserveTimestamps: true,\n recursive: true,\n verbatimSymlinks: true,\n });\n await writeFile(\n path.join(candidateDirectory, context.source.sourceManifest.embeddedExtensions),\n `${JSON.stringify(context.candidateManifest, null, 2)}\\n`,\n );\n await createDeterministicSb3(candidateDirectory);\n const comparison = await compareDirectories(\n context.source.resolvedSourceDirectory,\n candidateDirectory,\n );\n assert(\n comparison.existingFingerprint === initialComparison.existingFingerprint,\n `SB3 source changed while the ${operation} candidate was prepared; refusing to replace it.`,\n );\n assert(!comparison.identical, `Extension bundle ${operation} produced no source changes.`);\n const latestComparison = await compareDirectories(\n context.source.resolvedSourceDirectory,\n candidateDirectory,\n );\n assert(\n latestComparison.existingFingerprint === comparison.existingFingerprint &&\n latestComparison.candidateFingerprint === comparison.candidateFingerprint,\n `SB3 source or ${operation} candidate changed during the operation; refusing to replace it.`,\n );\n const replacement = await replaceDirectoryTransactionally(\n candidateDirectory,\n context.source.resolvedSourceDirectory,\n );\n installed = true;\n return {comparison, ...replacement};\n } finally {\n if (!installed) await rm(candidateDirectory, {recursive: true, force: true});\n }\n}\n\nexport async function bundleExtensions({\n bundleId,\n bundleName,\n extensionIds,\n recoveryCapsule = false,\n sourceDirectory,\n yes = false,\n}: ExtensionBundleConfigurationInput): Promise<ExtensionBundleApplyResult> {\n const context = await configurationContext({\n bundleId,\n bundleName,\n extensionIds,\n recoveryCapsule,\n sourceDirectory,\n willReplace: yes,\n });\n const plan = {\n bundleId,\n bundleName,\n components: context.configuredBundle.components.map((component) => component.metadata),\n counts: context.configuredBundle.counts,\n members: [...context.configuredBundle.bundle.members],\n recoveryCapsule: context.configuredBundle.bundle.recoveryCapsule === true,\n sourceDirectory: context.source.resolvedSourceDirectory,\n };\n if (!yes) {\n return {applied: false, changed: true, ...plan, rollbackCleanupWarning: null};\n }\n const installation = await installManifestConfiguration(context, 'configuration');\n return {applied: true, changed: true, ...installation, ...plan};\n}\n\nasync function unbundleContext({\n bundleId,\n sourceDirectory,\n willReplace,\n}: {\n bundleId: string;\n sourceDirectory: string;\n willReplace: boolean;\n}): Promise<UnbundleContext> {\n validateBundleId(bundleId);\n const source = await inspectConfigurationSource(sourceDirectory, willReplace);\n const extensionManifest = await readExtensionManifest(source);\n const extensionBundles = validateExtensionBundleConfigurations(\n extensionManifest.extensionBundles,\n extensionManifest.extensions,\n );\n const removedBundle = extensionBundles.find((bundle) => bundle.id === bundleId);\n assert(removedBundle, `Extension bundle was not found: ${bundleId}`);\n const candidateManifest = structuredClone(extensionManifest);\n const remainingBundles = extensionBundles.filter((bundle) => bundle.id !== bundleId);\n if (remainingBundles.length === 0) {\n delete candidateManifest.extensionBundles;\n } else {\n candidateManifest.extensionBundles = remainingBundles;\n }\n return {candidateManifest, extensionManifest, removedBundle, source};\n}\n\nexport async function planExtensionUnbundle({\n bundleId,\n sourceDirectory,\n}: {\n bundleId: string;\n sourceDirectory: string;\n}): Promise<ExtensionUnbundlePlanResult> {\n const context = await unbundleContext({bundleId, sourceDirectory, willReplace: false});\n return {\n applied: false,\n bundleId,\n changed: true,\n members: [...context.removedBundle.members],\n sourceDirectory: context.source.resolvedSourceDirectory,\n };\n}\n\nexport async function unbundleExtensions({\n bundleId,\n sourceDirectory,\n yes = false,\n}: {\n bundleId: string;\n sourceDirectory: string;\n yes?: boolean;\n}): Promise<ExtensionUnbundleApplyResult> {\n const context = await unbundleContext({bundleId, sourceDirectory, willReplace: yes});\n const plan = {\n bundleId,\n members: [...context.removedBundle.members],\n sourceDirectory: context.source.resolvedSourceDirectory,\n };\n if (!yes) {\n return {applied: false, changed: true, ...plan, rollbackCleanupWarning: null};\n }\n const installation = await installManifestConfiguration(context, 'removal');\n return {applied: true, changed: true, ...installation, ...plan};\n}\n"],"mappings":";;;;;;;AAsFA,eAAe,2BACb,iBACA,aAC6B;CAC7B,MAAM,0BAA0B,KAAK,QAAQ,eAAe;CAC5D,IAAI,aAAa;EACf,OACE,4BAA4B,KAAK,MAAM,uBAAuB,CAAC,CAAC,MAChE,4EACF;EACA,OACE,CAAE,MAAM,WAAW,KAAK,KAAK,yBAAyB,MAAM,CAAC,GAC7D,gFACF;CACF;CACA,MAAM,QAAQ,MAAM,MAAM,uBAAuB;CACjD,OACE,MAAM,YAAY,KAAK,CAAC,MAAM,eAAe,GAC7C,gEAAgE,yBAClE;CACA,IAAI,aAAa,MAAM,4BAA4B,uBAAuB;CAC1E,OAAO,iCAAiC,uBAAuB;AACjE;AAEA,eAAe,sBACb,QACoC;CACpC,MAAM,eAAe,KAAK,KACxB,OAAO,yBACP,OAAO,eAAe,kBACxB;CACA,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O,OAAO,QAAQ;CACnF,IAAI,iBAAiB,WAAW,GAC9B,OAAO,kBAAkB;MAEzB,kBAAkB,mBAAmB;CAEvC,OAAO;EAAC;EAAmB;EAAmB;EAAe;CAAM;AACrE;AAEA,eAAsB,sBAAsB,EAC1C,UACA,mBAIuC;CACvC,MAAM,UAAU,MAAM,gBAAgB;EAAC;EAAU;EAAiB,aAAa;CAAK,CAAC;CACrF,OAAO;EACL,SAAS;EACT;EACA,SAAS;EACT,SAAS,CAAC,GAAG,QAAQ,cAAc,OAAO;EAC1C,iBAAiB,QAAQ,OAAO;CAClC;AACF;AAEA,eAAsB,mBAAmB,EACvC,UACA,iBACA,MAAM,SAKkC;CACxC,MAAM,UAAU,MAAM,gBAAgB;EAAC;EAAU;EAAiB,aAAa;CAAG,CAAC;CACnF,MAAM,OAAO;EACX;EACA,SAAS,CAAC,GAAG,QAAQ,cAAc,OAAO;EAC1C,iBAAiB,QAAQ,OAAO;CAClC;CACA,IAAI,CAAC,KACH,OAAO;EAAC,SAAS;EAAO,SAAS;EAAM,GAAG;EAAM,wBAAwB;CAAI;CAG9E,OAAO;EAAC,SAAS;EAAM,SAAS;EAAM,GAAG,MADd,6BAA6B,SAAS,SAAS;EACnB,GAAG;CAAI;AAChE"}
1
+ {"version":3,"file":"extension-bundle-configuration.js","names":[],"sources":["../src/extension-bundle-configuration.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} from './assert';\nimport {\n validateBundleId,\n validateBundleName,\n validateExtensionBundleConfigurations,\n} from './extension-bundle';\nimport {buildExtensionBundlesWithModules} from './extension-module-bundle';\nimport type {ExtensionModuleBuildReport} from './extension-module-bundle';\nimport type {ExtensionBundlePlan} from './extension-bundle';\nimport {\n assertNoInterruptedRollback,\n compareDirectories,\n pathExists,\n replaceDirectoryTransactionally,\n} from './output-safety';\nimport type {DirectoryComparison} from './output-safety';\nimport {createDeterministicSb3, inspectSb3SourceForExtensionSync} from './source';\nimport type {InspectedSb3Source} from './source';\nimport type {EmbeddedExtensionManifest, ExtensionBundleConfiguration} from './types';\n\ninterface ExtensionBundleComponentMetadata {\n author: string | null;\n description: string | null;\n id: string | null;\n license: string | null;\n name: string | null;\n}\n\ninterface ConfigurationContext {\n buildPlan: Awaited<ReturnType<typeof buildExtensionBundlesWithModules>>;\n candidateManifest: EmbeddedExtensionManifest;\n configuredBundle: ExtensionBundlePlan;\n extensionManifest: EmbeddedExtensionManifest;\n source: InspectedSb3Source;\n}\n\ninterface UnbundleContext {\n candidateManifest: EmbeddedExtensionManifest;\n extensionManifest: EmbeddedExtensionManifest;\n removedBundle: ExtensionBundleConfiguration;\n source: InspectedSb3Source;\n}\n\nexport interface ExtensionBundleConfigurationInput {\n bundleId: string;\n bundleName: string;\n extensionIds?: string[];\n recoveryCapsule?: boolean;\n sourceDirectory: string;\n yes?: boolean;\n buildMode?: ExtensionBundleConfiguration['buildMode'];\n sharedDependencies?: Record<string, string>;\n}\n\nexport interface ExtensionBundlePlanResult {\n applied: boolean;\n bundleId: string;\n bundleName: string;\n changed: boolean;\n components: ExtensionBundleComponentMetadata[];\n counts: ExtensionBundlePlan['counts'];\n members: string[];\n recoveryCapsule: boolean;\n sourceDirectory: string;\n moduleBuild?: ExtensionModuleBuildReport;\n}\n\nexport interface ExtensionBundleApplyResult extends ExtensionBundlePlanResult {\n comparison?: DirectoryComparison;\n rollbackCleanupWarning: string | null;\n}\n\nexport interface ExtensionUnbundlePlanResult {\n applied: boolean;\n bundleId: string;\n changed: boolean;\n members: string[];\n sourceDirectory: string;\n}\n\nexport interface ExtensionUnbundleApplyResult extends ExtensionUnbundlePlanResult {\n comparison?: DirectoryComparison;\n rollbackCleanupWarning: string | null;\n}\n\nasync function inspectConfigurationSource(\n sourceDirectory: string,\n 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 while configuring extension bundles.',\n );\n assert(\n !(await pathExists(path.join(resolvedSourceDirectory, '.git'))),\n 'Refusing to replace a Git repository root while configuring extension bundles.',\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) await assertNoInterruptedRollback(resolvedSourceDirectory);\n return inspectSb3SourceForExtensionSync(resolvedSourceDirectory);\n}\n\nasync function readExtensionManifest(\n source: InspectedSb3Source,\n): Promise<EmbeddedExtensionManifest> {\n const manifestPath = path.join(\n source.resolvedSourceDirectory,\n source.sourceManifest.embeddedExtensions,\n );\n return JSON.parse(await readFile(manifestPath, 'utf8')) as EmbeddedExtensionManifest;\n}\n\nasync function configurationContext({\n bundleId,\n bundleName,\n extensionIds,\n recoveryCapsule,\n buildMode,\n sharedDependencies,\n sourceDirectory,\n willReplace,\n}: Required<\n Pick<\n ExtensionBundleConfigurationInput,\n 'bundleId' | 'bundleName' | 'recoveryCapsule' | 'sourceDirectory'\n >\n> & {\n extensionIds?: string[];\n willReplace: boolean;\n buildMode?: ExtensionBundleConfiguration['buildMode'];\n sharedDependencies?: Record<string, string>;\n}): Promise<ConfigurationContext> {\n validateBundleId(bundleId);\n validateBundleName(bundleName);\n assert(typeof recoveryCapsule === 'boolean', 'recoveryCapsule must be a boolean.');\n const source = await inspectConfigurationSource(sourceDirectory, willReplace);\n const extensionManifest = await readExtensionManifest(source);\n const existingBundles = validateExtensionBundleConfigurations(\n extensionManifest.extensionBundles,\n extensionManifest.extensions,\n );\n assert(\n !existingBundles.some((bundle) => bundle.id === bundleId),\n `Extension bundle already exists: ${bundleId}`,\n );\n const alreadyBundled = new Set(existingBundles.flatMap((bundle) => bundle.members));\n const members =\n extensionIds && extensionIds.length > 0\n ? [...extensionIds]\n : source.extensions\n .map((extension) => extension.id)\n .filter((extensionId) => !alreadyBundled.has(extensionId));\n const candidateManifest = structuredClone(extensionManifest);\n candidateManifest.extensionBundles = [\n ...existingBundles,\n {\n id: bundleId,\n members,\n name: bundleName,\n ...(buildMode === undefined ? {} : {buildMode}),\n ...(sharedDependencies === undefined ? {} : {sharedDependencies}),\n ...(recoveryCapsule === true ? {recoveryCapsule: true} : {}),\n },\n ];\n const extensionBundles = validateExtensionBundleConfigurations(\n candidateManifest.extensionBundles,\n candidateManifest.extensions,\n );\n const buildPlan = await buildExtensionBundlesWithModules({\n sourceDirectory: source.resolvedSourceDirectory,\n extensionBundles,\n extensionContents: source.extensionContents,\n extensions: source.extensions,\n project: source.project,\n });\n const configuredBundle = buildPlan.bundlePlans.find((plan) => plan.bundle.id === bundleId);\n assert(configuredBundle, `Extension bundle plan was not produced: ${bundleId}`);\n return {buildPlan, candidateManifest, configuredBundle, extensionManifest, source};\n}\n\nexport async function planExtensionBundle({\n bundleId,\n bundleName,\n extensionIds,\n recoveryCapsule = false,\n sourceDirectory,\n buildMode,\n sharedDependencies,\n}: ExtensionBundleConfigurationInput): Promise<ExtensionBundlePlanResult> {\n const context = await configurationContext({\n bundleId,\n bundleName,\n extensionIds,\n recoveryCapsule,\n sourceDirectory,\n buildMode,\n sharedDependencies,\n willReplace: false,\n });\n return {\n applied: false,\n bundleId,\n bundleName,\n changed: true,\n components: context.configuredBundle.components.map((component) => component.metadata),\n counts: context.configuredBundle.counts,\n members: [...context.configuredBundle.bundle.members],\n recoveryCapsule: context.configuredBundle.bundle.recoveryCapsule === true,\n sourceDirectory: context.source.resolvedSourceDirectory,\n ...(context.configuredBundle.moduleBuild\n ? {moduleBuild: context.configuredBundle.moduleBuild}\n : {}),\n };\n}\n\nasync function installManifestConfiguration(\n context: ConfigurationContext | UnbundleContext,\n operation: string,\n): Promise<{comparison: DirectoryComparison; rollbackCleanupWarning: string | null}> {\n const initialComparison = await compareDirectories(\n context.source.resolvedSourceDirectory,\n context.source.resolvedSourceDirectory,\n );\n assert(\n initialComparison.identical &&\n initialComparison.existingFingerprint === initialComparison.candidateFingerprint,\n `SB3 source changed while its initial ${operation} state was inspected.`,\n );\n const parentDirectory = path.dirname(context.source.resolvedSourceDirectory);\n const candidateDirectory = await mkdtemp(\n path.join(parentDirectory, `.${path.basename(context.source.resolvedSourceDirectory)}.bundle-`),\n );\n let installed = false;\n try {\n await cp(context.source.resolvedSourceDirectory, candidateDirectory, {\n preserveTimestamps: true,\n recursive: true,\n verbatimSymlinks: true,\n });\n await writeFile(\n path.join(candidateDirectory, context.source.sourceManifest.embeddedExtensions),\n `${JSON.stringify(context.candidateManifest, null, 2)}\\n`,\n );\n await createDeterministicSb3(candidateDirectory);\n const comparison = await compareDirectories(\n context.source.resolvedSourceDirectory,\n candidateDirectory,\n );\n assert(\n comparison.existingFingerprint === initialComparison.existingFingerprint,\n `SB3 source changed while the ${operation} candidate was prepared; refusing to replace it.`,\n );\n assert(!comparison.identical, `Extension bundle ${operation} produced no source changes.`);\n const latestComparison = await compareDirectories(\n context.source.resolvedSourceDirectory,\n candidateDirectory,\n );\n assert(\n latestComparison.existingFingerprint === comparison.existingFingerprint &&\n latestComparison.candidateFingerprint === comparison.candidateFingerprint,\n `SB3 source or ${operation} candidate changed during the operation; refusing to replace it.`,\n );\n const replacement = await replaceDirectoryTransactionally(\n candidateDirectory,\n context.source.resolvedSourceDirectory,\n );\n installed = true;\n return {comparison, ...replacement};\n } finally {\n if (!installed) await rm(candidateDirectory, {recursive: true, force: true});\n }\n}\n\nexport async function bundleExtensions({\n bundleId,\n bundleName,\n extensionIds,\n recoveryCapsule = false,\n sourceDirectory,\n yes = false,\n buildMode,\n sharedDependencies,\n}: ExtensionBundleConfigurationInput): Promise<ExtensionBundleApplyResult> {\n const context = await configurationContext({\n bundleId,\n bundleName,\n extensionIds,\n recoveryCapsule,\n sourceDirectory,\n buildMode,\n sharedDependencies,\n willReplace: yes,\n });\n const plan = {\n bundleId,\n bundleName,\n components: context.configuredBundle.components.map((component) => component.metadata),\n counts: context.configuredBundle.counts,\n members: [...context.configuredBundle.bundle.members],\n recoveryCapsule: context.configuredBundle.bundle.recoveryCapsule === true,\n sourceDirectory: context.source.resolvedSourceDirectory,\n ...(context.configuredBundle.moduleBuild\n ? {moduleBuild: context.configuredBundle.moduleBuild}\n : {}),\n };\n if (!yes) {\n return {applied: false, changed: true, ...plan, rollbackCleanupWarning: null};\n }\n const installation = await installManifestConfiguration(context, 'configuration');\n return {applied: true, changed: true, ...installation, ...plan};\n}\n\nasync function unbundleContext({\n bundleId,\n sourceDirectory,\n willReplace,\n}: {\n bundleId: string;\n sourceDirectory: string;\n willReplace: boolean;\n}): Promise<UnbundleContext> {\n validateBundleId(bundleId);\n const source = await inspectConfigurationSource(sourceDirectory, willReplace);\n const extensionManifest = await readExtensionManifest(source);\n const extensionBundles = validateExtensionBundleConfigurations(\n extensionManifest.extensionBundles,\n extensionManifest.extensions,\n );\n const removedBundle = extensionBundles.find((bundle) => bundle.id === bundleId);\n assert(removedBundle, `Extension bundle was not found: ${bundleId}`);\n const candidateManifest = structuredClone(extensionManifest);\n const remainingBundles = extensionBundles.filter((bundle) => bundle.id !== bundleId);\n if (remainingBundles.length === 0) {\n delete candidateManifest.extensionBundles;\n } else {\n candidateManifest.extensionBundles = remainingBundles;\n }\n return {candidateManifest, extensionManifest, removedBundle, source};\n}\n\nexport async function planExtensionUnbundle({\n bundleId,\n sourceDirectory,\n}: {\n bundleId: string;\n sourceDirectory: string;\n}): Promise<ExtensionUnbundlePlanResult> {\n const context = await unbundleContext({bundleId, sourceDirectory, willReplace: false});\n return {\n applied: false,\n bundleId,\n changed: true,\n members: [...context.removedBundle.members],\n sourceDirectory: context.source.resolvedSourceDirectory,\n };\n}\n\nexport async function unbundleExtensions({\n bundleId,\n sourceDirectory,\n yes = false,\n}: {\n bundleId: string;\n sourceDirectory: string;\n yes?: boolean;\n}): Promise<ExtensionUnbundleApplyResult> {\n const context = await unbundleContext({bundleId, sourceDirectory, willReplace: yes});\n const plan = {\n bundleId,\n members: [...context.removedBundle.members],\n sourceDirectory: context.source.resolvedSourceDirectory,\n };\n if (!yes) {\n return {applied: false, changed: true, ...plan, rollbackCleanupWarning: null};\n }\n const installation = await installManifestConfiguration(context, 'removal');\n return {applied: true, changed: true, ...installation, ...plan};\n}\n"],"mappings":";;;;;;;;AA0FA,eAAe,2BACb,iBACA,aAC6B;CAC7B,MAAM,0BAA0B,KAAK,QAAQ,eAAe;CAC5D,IAAI,aAAa;EACf,OACE,4BAA4B,KAAK,MAAM,uBAAuB,CAAC,CAAC,MAChE,4EACF;EACA,OACE,CAAE,MAAM,WAAW,KAAK,KAAK,yBAAyB,MAAM,CAAC,GAC7D,gFACF;CACF;CACA,MAAM,QAAQ,MAAM,MAAM,uBAAuB;CACjD,OACE,MAAM,YAAY,KAAK,CAAC,MAAM,eAAe,GAC7C,gEAAgE,yBAClE;CACA,IAAI,aAAa,MAAM,4BAA4B,uBAAuB;CAC1E,OAAO,iCAAiC,uBAAuB;AACjE;AAEA,eAAe,sBACb,QACoC;CACpC,MAAM,eAAe,KAAK,KACxB,OAAO,yBACP,OAAO,eAAe,kBACxB;CACA,OAAO,KAAK,MAAM,MAAM,SAAS,cAAc,MAAM,CAAC;AACxD;AAEA,eAAe,qBAAqB,EAClC,UACA,YACA,cACA,iBACA,WACA,oBACA,iBACA,eAWgC;CAChC,iBAAiB,QAAQ;CACzB,mBAAmB,UAAU;CAC7B,OAAO,OAAO,oBAAoB,WAAW,oCAAoC;CACjF,MAAM,SAAS,MAAM,2BAA2B,iBAAiB,WAAW;CAC5E,MAAM,oBAAoB,MAAM,sBAAsB,MAAM;CAC5D,MAAM,kBAAkB,sCACtB,kBAAkB,kBAClB,kBAAkB,UACpB;CACA,OACE,CAAC,gBAAgB,MAAM,WAAW,OAAO,OAAO,QAAQ,GACxD,oCAAoC,UACtC;CACA,MAAM,iBAAiB,IAAI,IAAI,gBAAgB,SAAS,WAAW,OAAO,OAAO,CAAC;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