@kubohiroya/sb3-toolchain 0.11.0 → 0.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +19 -4
- package/README.ja.md +17 -1
- package/README.md +17 -1
- package/dist/archive.d.ts +1 -0
- package/dist/archive.js +16 -0
- package/dist/archive.js.map +1 -0
- package/dist/assert.d.ts +2 -0
- package/dist/assert.js +11 -0
- package/dist/assert.js.map +1 -0
- package/dist/bin.d.ts +1 -0
- package/dist/bin.js +12 -0
- package/dist/bin.js.map +1 -0
- package/dist/build.d.ts +23 -0
- package/dist/build.js +111 -0
- package/dist/build.js.map +1 -0
- package/dist/cli.d.ts +87 -0
- package/dist/cli.js +544 -0
- package/dist/cli.js.map +1 -0
- package/dist/constants.d.ts +2 -0
- package/dist/constants.js +7 -0
- package/dist/constants.js.map +1 -0
- package/dist/extension-api-manifest.d.ts +46 -0
- package/dist/extension-api-manifest.js +211 -0
- package/dist/extension-api-manifest.js.map +1 -0
- package/dist/extension-bundle-archive.d.ts +36 -0
- package/dist/extension-bundle-archive.js +302 -0
- package/dist/extension-bundle-archive.js.map +1 -0
- package/dist/extension-bundle-configuration.d.ts +55 -0
- package/dist/extension-bundle-configuration.js +200 -0
- package/dist/extension-bundle-configuration.js.map +1 -0
- package/dist/extension-bundle.d.ts +39 -0
- package/dist/extension-bundle.js +580 -0
- package/dist/extension-bundle.js.map +1 -0
- package/dist/extension-dependencies.d.ts +18 -0
- package/dist/extension-dependencies.js +59 -0
- package/dist/extension-dependencies.js.map +1 -0
- package/dist/extension-id-migration.d.ts +83 -0
- package/dist/extension-id-migration.js +292 -0
- package/dist/extension-id-migration.js.map +1 -0
- package/dist/extension-sync.d.ts +111 -0
- package/dist/extension-sync.js +463 -0
- package/dist/extension-sync.js.map +1 -0
- package/dist/import.d.ts +39 -0
- package/dist/import.js +244 -0
- package/dist/import.js.map +1 -0
- package/dist/index.d.ts +31 -0
- package/dist/index.js +18 -0
- package/dist/npm-extension-source.d.ts +13 -0
- package/dist/npm-extension-source.js +63 -0
- package/dist/npm-extension-source.js.map +1 -0
- package/dist/output-safety.d.ts +29 -0
- package/dist/output-safety.js +213 -0
- package/dist/output-safety.js.map +1 -0
- package/dist/project-asset-additions.d.ts +29 -0
- package/dist/project-asset-additions.js +412 -0
- package/dist/project-asset-additions.js.map +1 -0
- package/dist/release-snapshot.d.ts +75 -0
- package/dist/release-snapshot.js +177 -0
- package/dist/release-snapshot.js.map +1 -0
- package/dist/source.d.ts +41 -0
- package/dist/source.js +282 -0
- package/dist/source.js.map +1 -0
- package/dist/turbowarp-clean-up.d.ts +18 -0
- package/dist/turbowarp-clean-up.js +266 -0
- package/dist/turbowarp-clean-up.js.map +1 -0
- package/dist/types.d.ts +80 -0
- package/package.json +22 -13
- package/bin/sb3-toolchain.mjs +0 -9
- package/src/archive.js +0 -35
- package/src/build.js +0 -188
- package/src/cli.js +0 -748
- package/src/constants.js +0 -4
- package/src/extension-api-manifest.js +0 -336
- package/src/extension-bundle-archive.js +0 -422
- package/src/extension-bundle-configuration.js +0 -265
- package/src/extension-bundle.js +0 -695
- package/src/extension-dependencies.js +0 -114
- package/src/extension-id-migration.js +0 -496
- package/src/extension-sync.js +0 -754
- package/src/import.js +0 -397
- package/src/index.js +0 -75
- package/src/npm-extension-source.js +0 -111
- package/src/output-safety.js +0 -322
- package/src/project-asset-additions.js +0 -560
- package/src/release-snapshot.js +0 -247
- package/src/source.js +0 -468
- package/src/turbowarp-clean-up.js +0 -295
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { EmbeddedExtension, ExtensionSource } from './types';
|
|
2
|
+
export interface ExtensionHeaderMetadata {
|
|
3
|
+
author: string | null;
|
|
4
|
+
description: string | null;
|
|
5
|
+
id: string | null;
|
|
6
|
+
license: string | null;
|
|
7
|
+
name: string | null;
|
|
8
|
+
}
|
|
9
|
+
export interface ManagedExtensionContents {
|
|
10
|
+
actualId: string | null;
|
|
11
|
+
integrity: string;
|
|
12
|
+
source: ExtensionSource;
|
|
13
|
+
}
|
|
14
|
+
export declare function extensionIntegrity(contents: Uint8Array | string): string;
|
|
15
|
+
export declare function extensionHeaderId(contents: Uint8Array | string): string | null;
|
|
16
|
+
export declare function extensionHeaderMetadata(contents: Uint8Array | string): ExtensionHeaderMetadata;
|
|
17
|
+
export declare function validateExtensionSourceMetadata(extension: EmbeddedExtension): ExtensionSource | null;
|
|
18
|
+
export declare function validateManagedExtensionContents(extension: EmbeddedExtension, contents: Uint8Array | string): ManagedExtensionContents | null;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { assert } from "./assert.js";
|
|
2
|
+
import { validateArchiveEntryName } from "./archive.js";
|
|
3
|
+
import { validateExtensionApiManifestSourceMetadata } from "./extension-api-manifest.js";
|
|
4
|
+
import { createHash } from "node:crypto";
|
|
5
|
+
//#region src/extension-dependencies.ts
|
|
6
|
+
function extensionIntegrity(contents) {
|
|
7
|
+
return `sha256-${createHash("sha256").update(contents).digest("base64")}`;
|
|
8
|
+
}
|
|
9
|
+
function extensionHeaderId(contents) {
|
|
10
|
+
return extensionHeaderMetadata(contents).id;
|
|
11
|
+
}
|
|
12
|
+
function extensionHeaderMetadata(contents) {
|
|
13
|
+
const source = Buffer.from(contents).toString("utf8");
|
|
14
|
+
const readField = (field) => source.match(new RegExp(`^// ${field}: (.+)\\r?$`, "mu"))?.[1]?.trim() ?? null;
|
|
15
|
+
const id = readField("ID");
|
|
16
|
+
return {
|
|
17
|
+
author: readField("By"),
|
|
18
|
+
description: readField("Description"),
|
|
19
|
+
id: id && /^[A-Za-z0-9._-]+$/u.test(id) ? id : null,
|
|
20
|
+
license: readField("License"),
|
|
21
|
+
name: readField("Name")
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
function validateExtensionSourceMetadata(extension) {
|
|
25
|
+
if (extension.source === void 0) return null;
|
|
26
|
+
const source = extension.source;
|
|
27
|
+
assert(source && typeof source === "object" && !Array.isArray(source), `Managed extension source must be an object: ${extension.id}`);
|
|
28
|
+
if (source.provider === "github") {
|
|
29
|
+
assert(typeof source.repository === "string" && /^[A-Za-z0-9](?:[A-Za-z0-9-]{0,38})\/[A-Za-z0-9._-]+$/u.test(source.repository), `Invalid GitHub repository for extension ${extension.id}: ${source.repository}`);
|
|
30
|
+
assert(typeof source.ref === "string" && source.ref.length > 0 && !/[\u0000-\u0020\u007f]/u.test(source.ref), `Invalid Git ref for extension ${extension.id}: ${source.ref}`);
|
|
31
|
+
assert(typeof source.resolvedCommit === "string" && /^[a-f0-9]{40}$/u.test(source.resolvedCommit), `Managed extension ${extension.id} requires a 40-character resolvedCommit.`);
|
|
32
|
+
} else if (source.provider === "npm") {
|
|
33
|
+
assert(typeof source.package === "string" && /^(?:@[a-z0-9][a-z0-9._-]*\/)?[a-z0-9][a-z0-9._-]*$/u.test(source.package), `Invalid npm package for extension ${extension.id}: ${source.package}`);
|
|
34
|
+
assert(typeof source.version === "string" && /^[0-9]+\.[0-9]+\.[0-9]+(?:-[0-9A-Za-z.-]+)?(?:\+[0-9A-Za-z.-]+)?$/u.test(source.version), `Managed npm extension ${extension.id} requires an exact semantic version.`);
|
|
35
|
+
} else throw new Error(`Unsupported extension source provider for ${extension.id}: ${source.provider}`);
|
|
36
|
+
assert(typeof source.artifact === "string" && source.artifact.length > 0, `Managed extension ${extension.id} requires an artifact path.`);
|
|
37
|
+
validateArchiveEntryName(source.artifact);
|
|
38
|
+
assert(!source.artifact.endsWith("/"), `Managed extension artifact must be a file: ${source.artifact}`);
|
|
39
|
+
assert(typeof source.integrity === "string" && /^sha256-[A-Za-z0-9+/]{43}=$/u.test(source.integrity), `Managed extension ${extension.id} requires SHA-256 integrity.`);
|
|
40
|
+
validateExtensionApiManifestSourceMetadata(extension);
|
|
41
|
+
return source;
|
|
42
|
+
}
|
|
43
|
+
function validateManagedExtensionContents(extension, contents) {
|
|
44
|
+
const source = validateExtensionSourceMetadata(extension);
|
|
45
|
+
if (!source) return null;
|
|
46
|
+
const actualIntegrity = extensionIntegrity(contents);
|
|
47
|
+
assert(actualIntegrity === source.integrity, `Managed extension integrity mismatch for ${extension.id}: expected ${source.integrity}, got ${actualIntegrity}`);
|
|
48
|
+
const actualId = extensionHeaderId(contents);
|
|
49
|
+
assert(actualId === extension.id, `Managed extension header ID mismatch for ${extension.id}: expected ${extension.id}, got ${actualId ?? "(missing)"}`);
|
|
50
|
+
return {
|
|
51
|
+
actualId,
|
|
52
|
+
integrity: actualIntegrity,
|
|
53
|
+
source
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
//#endregion
|
|
57
|
+
export { extensionHeaderId, extensionHeaderMetadata, extensionIntegrity, validateExtensionSourceMetadata, validateManagedExtensionContents };
|
|
58
|
+
|
|
59
|
+
//# sourceMappingURL=extension-dependencies.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"extension-dependencies.js","names":[],"sources":["../src/extension-dependencies.ts"],"sourcesContent":["// SPDX-License-Identifier: MPL-2.0\n\nimport {createHash} from 'node:crypto';\n\nimport {validateArchiveEntryName} from './archive';\nimport {assert} from './assert';\nimport {validateExtensionApiManifestSourceMetadata} from './extension-api-manifest';\nimport type {EmbeddedExtension, ExtensionSource} from './types';\n\nexport interface ExtensionHeaderMetadata {\n author: string | null;\n description: string | null;\n id: string | null;\n license: string | null;\n name: string | null;\n}\n\nexport interface ManagedExtensionContents {\n actualId: string | null;\n integrity: string;\n source: ExtensionSource;\n}\n\nexport function extensionIntegrity(contents: Uint8Array | string): string {\n return `sha256-${createHash('sha256').update(contents).digest('base64')}`;\n}\n\nexport function extensionHeaderId(contents: Uint8Array | string): string | null {\n return extensionHeaderMetadata(contents).id;\n}\n\nexport function extensionHeaderMetadata(contents: Uint8Array | string): ExtensionHeaderMetadata {\n const source = Buffer.from(contents).toString('utf8');\n const readField = (field: string): string | null =>\n source.match(new RegExp(`^// ${field}: (.+)\\\\r?$`, 'mu'))?.[1]?.trim() ?? null;\n const id = readField('ID');\n return {\n author: readField('By'),\n description: readField('Description'),\n id: id && /^[A-Za-z0-9._-]+$/u.test(id) ? id : null,\n license: readField('License'),\n name: readField('Name'),\n };\n}\n\nexport function validateExtensionSourceMetadata(\n extension: EmbeddedExtension,\n): ExtensionSource | null {\n if (extension.source === undefined) {\n return null;\n }\n\n const source = extension.source as unknown as Record<string, unknown> | undefined;\n assert(\n source && typeof source === 'object' && !Array.isArray(source),\n `Managed extension source must be an object: ${extension.id}`,\n );\n if (source.provider === 'github') {\n assert(\n typeof source.repository === 'string' &&\n /^[A-Za-z0-9](?:[A-Za-z0-9-]{0,38})\\/[A-Za-z0-9._-]+$/u.test(source.repository),\n `Invalid GitHub repository for extension ${extension.id}: ${source.repository}`,\n );\n assert(\n typeof source.ref === 'string' &&\n source.ref.length > 0 &&\n !/[\\u0000-\\u0020\\u007f]/u.test(source.ref),\n `Invalid Git ref for extension ${extension.id}: ${source.ref}`,\n );\n assert(\n typeof source.resolvedCommit === 'string' && /^[a-f0-9]{40}$/u.test(source.resolvedCommit),\n `Managed extension ${extension.id} requires a 40-character resolvedCommit.`,\n );\n } else if (source.provider === 'npm') {\n assert(\n typeof source.package === 'string' &&\n /^(?:@[a-z0-9][a-z0-9._-]*\\/)?[a-z0-9][a-z0-9._-]*$/u.test(source.package),\n `Invalid npm package for extension ${extension.id}: ${source.package}`,\n );\n assert(\n typeof source.version === 'string' &&\n /^[0-9]+\\.[0-9]+\\.[0-9]+(?:-[0-9A-Za-z.-]+)?(?:\\+[0-9A-Za-z.-]+)?$/u.test(source.version),\n `Managed npm extension ${extension.id} requires an exact semantic version.`,\n );\n } else {\n throw new Error(\n `Unsupported extension source provider for ${extension.id}: ${source.provider}`,\n );\n }\n assert(\n typeof source.artifact === 'string' && source.artifact.length > 0,\n `Managed extension ${extension.id} requires an artifact path.`,\n );\n validateArchiveEntryName(source.artifact);\n assert(\n !source.artifact.endsWith('/'),\n `Managed extension artifact must be a file: ${source.artifact}`,\n );\n assert(\n typeof source.integrity === 'string' && /^sha256-[A-Za-z0-9+/]{43}=$/u.test(source.integrity),\n `Managed extension ${extension.id} requires SHA-256 integrity.`,\n );\n validateExtensionApiManifestSourceMetadata(extension);\n return source as unknown as ExtensionSource;\n}\n\nexport function validateManagedExtensionContents(\n extension: EmbeddedExtension,\n contents: Uint8Array | string,\n): ManagedExtensionContents | null {\n const source = validateExtensionSourceMetadata(extension);\n if (!source) {\n return null;\n }\n\n const actualIntegrity = extensionIntegrity(contents);\n assert(\n actualIntegrity === source.integrity,\n `Managed extension integrity mismatch for ${extension.id}: ` +\n `expected ${source.integrity}, got ${actualIntegrity}`,\n );\n const actualId = extensionHeaderId(contents);\n assert(\n actualId === extension.id,\n `Managed extension header ID mismatch for ${extension.id}: ` +\n `expected ${extension.id}, got ${actualId ?? '(missing)'}`,\n );\n return {actualId, integrity: actualIntegrity, source};\n}\n"],"mappings":";;;;;AAuBA,SAAgB,mBAAmB,UAAuC;CACxE,OAAO,UAAU,WAAW,QAAQ,CAAC,CAAC,OAAO,QAAQ,CAAC,CAAC,OAAO,QAAQ;AACxE;AAEA,SAAgB,kBAAkB,UAA8C;CAC9E,OAAO,wBAAwB,QAAQ,CAAC,CAAC;AAC3C;AAEA,SAAgB,wBAAwB,UAAwD;CAC9F,MAAM,SAAS,OAAO,KAAK,QAAQ,CAAC,CAAC,SAAS,MAAM;CACpD,MAAM,aAAa,UACjB,OAAO,MAAM,IAAI,OAAO,OAAO,MAAM,cAAc,IAAI,CAAC,CAAC,GAAG,EAAE,EAAE,KAAK,KAAK;CAC5E,MAAM,KAAK,UAAU,IAAI;CACzB,OAAO;EACL,QAAQ,UAAU,IAAI;EACtB,aAAa,UAAU,aAAa;EACpC,IAAI,MAAM,qBAAqB,KAAK,EAAE,IAAI,KAAK;EAC/C,SAAS,UAAU,SAAS;EAC5B,MAAM,UAAU,MAAM;CACxB;AACF;AAEA,SAAgB,gCACd,WACwB;CACxB,IAAI,UAAU,WAAW,KAAA,GACvB,OAAO;CAGT,MAAM,SAAS,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O,WAC3B,4CAA4C,UAAU,GAAG,aAC3C,OAAO,UAAU,QAAQ,iBACzC;CACA,MAAM,WAAW,kBAAkB,QAAQ;CAC3C,OACE,aAAa,UAAU,IACvB,4CAA4C,UAAU,GAAG,aAC3C,UAAU,GAAG,QAAQ,YAAY,aACjD;CACA,OAAO;EAAC;EAAU,WAAW;EAAiB;CAAM;AACtD"}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { EmbeddedExtensionManifest, ProjectJson } from './types';
|
|
2
|
+
export interface ExtensionIdReference {
|
|
3
|
+
file: string;
|
|
4
|
+
kind: 'key' | 'value';
|
|
5
|
+
path: string;
|
|
6
|
+
value: string;
|
|
7
|
+
}
|
|
8
|
+
export interface ExtensionIdMigrationCounts {
|
|
9
|
+
apiManifestArtifacts: number;
|
|
10
|
+
blockOpcodes: number;
|
|
11
|
+
extensionFiles: number;
|
|
12
|
+
extensionUrlKeys: number;
|
|
13
|
+
extensionUrlValues: number;
|
|
14
|
+
manifestIds: number;
|
|
15
|
+
manifestPaths: number;
|
|
16
|
+
monitorOpcodes: number;
|
|
17
|
+
projectExtensions: number;
|
|
18
|
+
sourceArtifacts: number;
|
|
19
|
+
}
|
|
20
|
+
export interface RewriteExtensionIdDocumentsInput {
|
|
21
|
+
apiManifestArtifact?: string;
|
|
22
|
+
extensionManifest: EmbeddedExtensionManifest;
|
|
23
|
+
newId: string;
|
|
24
|
+
oldId: string;
|
|
25
|
+
project: ProjectJson;
|
|
26
|
+
sourceArtifact?: string;
|
|
27
|
+
}
|
|
28
|
+
export interface RewriteExtensionIdDocumentsResult {
|
|
29
|
+
counts: ExtensionIdMigrationCounts;
|
|
30
|
+
extensionIndex: number;
|
|
31
|
+
extensionManifest: EmbeddedExtensionManifest;
|
|
32
|
+
newApiManifestPath: string | null;
|
|
33
|
+
newPath: string;
|
|
34
|
+
oldApiManifestPath: string | null;
|
|
35
|
+
oldPath: string;
|
|
36
|
+
project: ProjectJson;
|
|
37
|
+
totalChanges: number;
|
|
38
|
+
unclassifiedReferences: ExtensionIdReference[];
|
|
39
|
+
}
|
|
40
|
+
export declare function validateNewExtensionId(newId: unknown): string;
|
|
41
|
+
export declare function rewriteExtensionIdDocuments({ apiManifestArtifact, extensionManifest, newId, oldId, project, sourceArtifact, }: RewriteExtensionIdDocumentsInput): RewriteExtensionIdDocumentsResult;
|
|
42
|
+
export declare function planExtensionIdMigration({ fromId, sourceDirectory, toId, }: {
|
|
43
|
+
fromId: string;
|
|
44
|
+
sourceDirectory: string;
|
|
45
|
+
toId: string;
|
|
46
|
+
}): Promise<{
|
|
47
|
+
artifactReady: boolean;
|
|
48
|
+
counts: ExtensionIdMigrationCounts;
|
|
49
|
+
fromId: string;
|
|
50
|
+
sourceDirectory: string;
|
|
51
|
+
toId: string;
|
|
52
|
+
totalChanges: number;
|
|
53
|
+
unclassifiedReferences: ExtensionIdReference[];
|
|
54
|
+
}>;
|
|
55
|
+
export declare function migrateExtensionId({ fromId, sourceDirectory, toId, yes, }: {
|
|
56
|
+
fromId: string;
|
|
57
|
+
sourceDirectory: string;
|
|
58
|
+
toId: string;
|
|
59
|
+
yes?: boolean;
|
|
60
|
+
}): Promise<{
|
|
61
|
+
rollbackCleanupWarning: null;
|
|
62
|
+
artifactReady: boolean;
|
|
63
|
+
counts: ExtensionIdMigrationCounts;
|
|
64
|
+
fromId: string;
|
|
65
|
+
sourceDirectory: string;
|
|
66
|
+
toId: string;
|
|
67
|
+
totalChanges: number;
|
|
68
|
+
unclassifiedReferences: ExtensionIdReference[];
|
|
69
|
+
applied: boolean;
|
|
70
|
+
changed: boolean;
|
|
71
|
+
} | {
|
|
72
|
+
rollbackCleanupWarning: string | null;
|
|
73
|
+
artifactReady: boolean;
|
|
74
|
+
counts: ExtensionIdMigrationCounts;
|
|
75
|
+
fromId: string;
|
|
76
|
+
sourceDirectory: string;
|
|
77
|
+
toId: string;
|
|
78
|
+
totalChanges: number;
|
|
79
|
+
unclassifiedReferences: ExtensionIdReference[];
|
|
80
|
+
applied: boolean;
|
|
81
|
+
changed: boolean;
|
|
82
|
+
comparison: import('./output-safety').DirectoryComparison;
|
|
83
|
+
}>;
|
|
@@ -0,0 +1,292 @@
|
|
|
1
|
+
import { assert } from "./assert.js";
|
|
2
|
+
import { assertNoInterruptedRollback, compareDirectories, pathExists, replaceDirectoryTransactionally } from "./output-safety.js";
|
|
3
|
+
import { extensionApiManifestIntegrity, parseExtensionApiManifest } from "./extension-api-manifest.js";
|
|
4
|
+
import { extensionHeaderId, extensionIntegrity } from "./extension-dependencies.js";
|
|
5
|
+
import { createDeterministicSb3, inspectSb3SourceForExtensionSync } from "./source.js";
|
|
6
|
+
import path from "node:path";
|
|
7
|
+
import { cp, lstat, mkdtemp, readFile, rename, rm, writeFile } from "node:fs/promises";
|
|
8
|
+
//#region src/extension-id-migration.ts
|
|
9
|
+
function isObject(value) {
|
|
10
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
11
|
+
}
|
|
12
|
+
function escapeJsonPointer(value) {
|
|
13
|
+
return value.replaceAll("~", "~0").replaceAll("/", "~1");
|
|
14
|
+
}
|
|
15
|
+
function referenceKey(file, kind, pointer) {
|
|
16
|
+
return `${file}\u0000${kind}\u0000${pointer}`;
|
|
17
|
+
}
|
|
18
|
+
function collectUnclassifiedReferences(value, oldId, file, classified) {
|
|
19
|
+
const references = [];
|
|
20
|
+
function visit(current, pointer) {
|
|
21
|
+
if (typeof current === "string") {
|
|
22
|
+
if (current.includes(oldId) && !classified.has(referenceKey(file, "value", pointer))) references.push({
|
|
23
|
+
file,
|
|
24
|
+
kind: "value",
|
|
25
|
+
path: pointer || "/",
|
|
26
|
+
value: current
|
|
27
|
+
});
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
if (!current || typeof current !== "object") return;
|
|
31
|
+
if (Array.isArray(current)) {
|
|
32
|
+
for (const [index, entry] of current.entries()) visit(entry, `${pointer}/${index}`);
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
for (const [key, entry] of Object.entries(current)) {
|
|
36
|
+
const entryPointer = `${pointer}/${escapeJsonPointer(key)}`;
|
|
37
|
+
if (key.includes(oldId) && !classified.has(referenceKey(file, "key", entryPointer))) references.push({
|
|
38
|
+
file,
|
|
39
|
+
kind: "key",
|
|
40
|
+
path: entryPointer,
|
|
41
|
+
value: key
|
|
42
|
+
});
|
|
43
|
+
visit(entry, entryPointer);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
visit(value, "");
|
|
47
|
+
return references;
|
|
48
|
+
}
|
|
49
|
+
function replaceObjectKeyAtSamePosition(object, oldKey, newKey) {
|
|
50
|
+
const replacement = {};
|
|
51
|
+
for (const [key, value] of Object.entries(object)) replacement[key === oldKey ? newKey : key] = value;
|
|
52
|
+
return replacement;
|
|
53
|
+
}
|
|
54
|
+
function validateNewExtensionId(newId) {
|
|
55
|
+
assert(typeof newId === "string" && /^[a-z0-9]+$/u.test(newId), `New extension ID must use TurboWarp's [a-z0-9]+ format: ${JSON.stringify(newId)}`);
|
|
56
|
+
return newId;
|
|
57
|
+
}
|
|
58
|
+
function rewriteExtensionIdDocuments({ apiManifestArtifact = void 0, extensionManifest, newId, oldId, project, sourceArtifact = void 0 }) {
|
|
59
|
+
assert(typeof oldId === "string" && /^[A-Za-z0-9._-]+$/u.test(oldId), `Invalid existing extension ID: ${JSON.stringify(oldId)}`);
|
|
60
|
+
validateNewExtensionId(newId);
|
|
61
|
+
assert(oldId !== newId, "The existing and new extension IDs must differ.");
|
|
62
|
+
const originalProject = structuredClone(project);
|
|
63
|
+
const originalManifest = structuredClone(extensionManifest);
|
|
64
|
+
const migratedProject = structuredClone(project);
|
|
65
|
+
const migratedManifest = structuredClone(extensionManifest);
|
|
66
|
+
const extensions = migratedManifest.extensions;
|
|
67
|
+
assert(Array.isArray(extensions), "Embedded extension manifest requires extensions.");
|
|
68
|
+
const extensionIndex = extensions.findIndex((extension) => extension?.id === oldId);
|
|
69
|
+
assert(extensionIndex !== -1, `Embedded extension was not found: ${oldId}`);
|
|
70
|
+
assert(!extensions.some((extension) => extension?.id === newId), `Embedded extension ID already exists: ${newId}`);
|
|
71
|
+
const extensionUrls = migratedProject.extensionURLs;
|
|
72
|
+
assert(isObject(extensionUrls), "project.source.json extensionURLs must be an object.");
|
|
73
|
+
assert(Object.hasOwn(extensionUrls, oldId), `project.source.json has no extensionURLs entry for ${oldId}.`);
|
|
74
|
+
assert(!Object.hasOwn(extensionUrls, newId), `project.source.json extensionURLs already contains ${newId}.`);
|
|
75
|
+
assert(migratedProject.extensions === void 0 || Array.isArray(migratedProject.extensions), "project.source.json extensions must be an array when present.");
|
|
76
|
+
assert(migratedProject.monitors === void 0 || Array.isArray(migratedProject.monitors), "project.source.json monitors must be an array when present.");
|
|
77
|
+
const projectExtensions = migratedProject.extensions;
|
|
78
|
+
if (projectExtensions) assert(!projectExtensions.includes(newId), `project.source.json extensions already contains ${newId}.`);
|
|
79
|
+
const counts = {
|
|
80
|
+
apiManifestArtifacts: 0,
|
|
81
|
+
blockOpcodes: 0,
|
|
82
|
+
extensionFiles: 1,
|
|
83
|
+
extensionUrlKeys: 0,
|
|
84
|
+
extensionUrlValues: 0,
|
|
85
|
+
manifestIds: 0,
|
|
86
|
+
manifestPaths: 0,
|
|
87
|
+
monitorOpcodes: 0,
|
|
88
|
+
projectExtensions: 0,
|
|
89
|
+
sourceArtifacts: 0
|
|
90
|
+
};
|
|
91
|
+
const projectClassified = /* @__PURE__ */ new Set();
|
|
92
|
+
const manifestClassified = /* @__PURE__ */ new Set();
|
|
93
|
+
if (projectExtensions) {
|
|
94
|
+
for (const [index, extensionId] of projectExtensions.entries()) if (extensionId === oldId) {
|
|
95
|
+
projectExtensions[index] = newId;
|
|
96
|
+
counts.projectExtensions += 1;
|
|
97
|
+
projectClassified.add(referenceKey("project.source.json", "value", `/extensions/${index}`));
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
const oldExtensionUrl = extensionUrls[oldId];
|
|
101
|
+
const oldExtensionUrlPointer = `/extensionURLs/${escapeJsonPointer(oldId)}`;
|
|
102
|
+
projectClassified.add(referenceKey("project.source.json", "key", oldExtensionUrlPointer));
|
|
103
|
+
counts.extensionUrlKeys += 1;
|
|
104
|
+
const expectedOldUrl = `embedded-extension:extensions/${oldId}.js`;
|
|
105
|
+
assert(oldExtensionUrl === expectedOldUrl, `Embedded extension URL mismatch for ${oldId}: ${oldExtensionUrl}`);
|
|
106
|
+
extensionUrls[oldId] = `embedded-extension:extensions/${newId}.js`;
|
|
107
|
+
projectClassified.add(referenceKey("project.source.json", "value", oldExtensionUrlPointer));
|
|
108
|
+
counts.extensionUrlValues += 1;
|
|
109
|
+
migratedProject.extensionURLs = replaceObjectKeyAtSamePosition(extensionUrls, oldId, newId);
|
|
110
|
+
const migratedTargets = migratedProject.targets ?? [];
|
|
111
|
+
for (const [targetIndex, target] of migratedTargets.entries()) {
|
|
112
|
+
if (!isObject(target) || !isObject(target.blocks)) continue;
|
|
113
|
+
for (const [blockId, block] of Object.entries(target.blocks)) {
|
|
114
|
+
if (!isObject(block)) continue;
|
|
115
|
+
if (typeof block.opcode === "string" && block.opcode.startsWith(`${oldId}_`)) {
|
|
116
|
+
block.opcode = `${newId}_${block.opcode.slice(oldId.length + 1)}`;
|
|
117
|
+
counts.blockOpcodes += 1;
|
|
118
|
+
projectClassified.add(referenceKey("project.source.json", "value", `/targets/${targetIndex}/blocks/${escapeJsonPointer(blockId)}/opcode`));
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
const migratedMonitors = migratedProject.monitors ?? [];
|
|
123
|
+
for (const [monitorIndex, monitor] of migratedMonitors.entries()) if (isObject(monitor) && typeof monitor.opcode === "string" && monitor.opcode.startsWith(`${oldId}_`)) {
|
|
124
|
+
monitor.opcode = `${newId}_${monitor.opcode.slice(oldId.length + 1)}`;
|
|
125
|
+
counts.monitorOpcodes += 1;
|
|
126
|
+
projectClassified.add(referenceKey("project.source.json", "value", `/monitors/${monitorIndex}/opcode`));
|
|
127
|
+
}
|
|
128
|
+
const extension = extensions[extensionIndex];
|
|
129
|
+
extension.id = newId;
|
|
130
|
+
counts.manifestIds += 1;
|
|
131
|
+
manifestClassified.add(referenceKey("embedded-extensions.json", "value", `/extensions/${extensionIndex}/id`));
|
|
132
|
+
const oldPath = `extensions/${oldId}.js`;
|
|
133
|
+
assert(extension.path === oldPath, `Embedded extension path mismatch for ${oldId}: ${extension.path}`);
|
|
134
|
+
extension.path = `extensions/${newId}.js`;
|
|
135
|
+
counts.manifestPaths += 1;
|
|
136
|
+
manifestClassified.add(referenceKey("embedded-extensions.json", "value", `/extensions/${extensionIndex}/path`));
|
|
137
|
+
let oldApiManifestPath = null;
|
|
138
|
+
let newApiManifestPath = null;
|
|
139
|
+
if (apiManifestArtifact !== void 0) assert(extension.source?.apiManifest, `Extension ${oldId} has no managed API manifest metadata.`);
|
|
140
|
+
if (extension.source?.apiManifest) {
|
|
141
|
+
oldApiManifestPath = `extensions/${oldId}.manifest.json`;
|
|
142
|
+
newApiManifestPath = `extensions/${newId}.manifest.json`;
|
|
143
|
+
assert(extension.source.apiManifest.path === oldApiManifestPath, `Extension API manifest path mismatch for ${oldId}: ${extension.source.apiManifest.path}`);
|
|
144
|
+
extension.source.apiManifest.path = newApiManifestPath;
|
|
145
|
+
counts.manifestPaths += 1;
|
|
146
|
+
manifestClassified.add(referenceKey("embedded-extensions.json", "value", `/extensions/${extensionIndex}/source/apiManifest/path`));
|
|
147
|
+
if (apiManifestArtifact !== void 0 && extension.source.apiManifest.artifact !== apiManifestArtifact) {
|
|
148
|
+
extension.source.apiManifest.artifact = apiManifestArtifact;
|
|
149
|
+
counts.apiManifestArtifacts += 1;
|
|
150
|
+
manifestClassified.add(referenceKey("embedded-extensions.json", "value", `/extensions/${extensionIndex}/source/apiManifest/artifact`));
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
if (sourceArtifact !== void 0) {
|
|
154
|
+
assert(extension.source, `Extension ${oldId} has no managed source metadata.`);
|
|
155
|
+
if (extension.source.artifact !== sourceArtifact) {
|
|
156
|
+
extension.source.artifact = sourceArtifact;
|
|
157
|
+
counts.sourceArtifacts += 1;
|
|
158
|
+
manifestClassified.add(referenceKey("embedded-extensions.json", "value", `/extensions/${extensionIndex}/source/artifact`));
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
const unclassifiedReferences = [...collectUnclassifiedReferences(originalProject, oldId, "project.source.json", projectClassified), ...collectUnclassifiedReferences(originalManifest, oldId, "embedded-extensions.json", manifestClassified)];
|
|
162
|
+
const totalChanges = Object.values(counts).reduce((total, count) => total + count, 0);
|
|
163
|
+
return {
|
|
164
|
+
counts,
|
|
165
|
+
extensionIndex,
|
|
166
|
+
extensionManifest: migratedManifest,
|
|
167
|
+
newApiManifestPath,
|
|
168
|
+
newPath: `extensions/${newId}.js`,
|
|
169
|
+
oldApiManifestPath,
|
|
170
|
+
oldPath,
|
|
171
|
+
project: migratedProject,
|
|
172
|
+
totalChanges,
|
|
173
|
+
unclassifiedReferences
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
async function inspectMigrationSource(sourceDirectory, willReplace) {
|
|
177
|
+
const resolvedSourceDirectory = path.resolve(sourceDirectory);
|
|
178
|
+
if (willReplace) {
|
|
179
|
+
assert(resolvedSourceDirectory !== path.parse(resolvedSourceDirectory).root, "Refusing to replace a filesystem root during extension ID migration.");
|
|
180
|
+
assert(!await pathExists(path.join(resolvedSourceDirectory, ".git")), "Refusing to replace a Git repository root during extension ID migration.");
|
|
181
|
+
}
|
|
182
|
+
const stats = await lstat(resolvedSourceDirectory);
|
|
183
|
+
assert(stats.isDirectory() && !stats.isSymbolicLink(), `SB3 source must be a directory, not a file or symbolic link: ${resolvedSourceDirectory}`);
|
|
184
|
+
if (willReplace) await assertNoInterruptedRollback(resolvedSourceDirectory);
|
|
185
|
+
return inspectSb3SourceForExtensionSync(resolvedSourceDirectory);
|
|
186
|
+
}
|
|
187
|
+
async function migrationContext(sourceDirectory, oldId, newId, willReplace) {
|
|
188
|
+
const source = await inspectMigrationSource(sourceDirectory, willReplace);
|
|
189
|
+
const extensionManifestPath = path.join(source.resolvedSourceDirectory, source.sourceManifest.embeddedExtensions);
|
|
190
|
+
const rewrite = rewriteExtensionIdDocuments({
|
|
191
|
+
extensionManifest: JSON.parse(await readFile(extensionManifestPath, "utf8")),
|
|
192
|
+
newId,
|
|
193
|
+
oldId,
|
|
194
|
+
project: source.project
|
|
195
|
+
});
|
|
196
|
+
const extension = source.extensions[rewrite.extensionIndex];
|
|
197
|
+
const contents = source.extensionContents.get(oldId);
|
|
198
|
+
assert(contents, `Embedded extension has no contents: ${oldId}`);
|
|
199
|
+
const apiManifestContents = source.extensionApiManifestContents.get(oldId) ?? null;
|
|
200
|
+
let apiManifestReady = true;
|
|
201
|
+
if (extension.source?.apiManifest) {
|
|
202
|
+
apiManifestReady = apiManifestContents !== null && extensionApiManifestIntegrity(apiManifestContents) === extension.source.apiManifest.integrity;
|
|
203
|
+
if (apiManifestReady && apiManifestContents !== null) try {
|
|
204
|
+
parseExtensionApiManifest(apiManifestContents, { expectedId: newId });
|
|
205
|
+
} catch {
|
|
206
|
+
apiManifestReady = false;
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
return {
|
|
210
|
+
apiManifestContents,
|
|
211
|
+
artifactReady: extensionHeaderId(contents) === newId && apiManifestReady,
|
|
212
|
+
contents,
|
|
213
|
+
extension,
|
|
214
|
+
rewrite,
|
|
215
|
+
source
|
|
216
|
+
};
|
|
217
|
+
}
|
|
218
|
+
async function planExtensionIdMigration({ fromId, sourceDirectory, toId }) {
|
|
219
|
+
const context = await migrationContext(sourceDirectory, fromId, toId, false);
|
|
220
|
+
return {
|
|
221
|
+
artifactReady: context.artifactReady,
|
|
222
|
+
counts: context.rewrite.counts,
|
|
223
|
+
fromId,
|
|
224
|
+
sourceDirectory: context.source.resolvedSourceDirectory,
|
|
225
|
+
toId,
|
|
226
|
+
totalChanges: context.rewrite.totalChanges,
|
|
227
|
+
unclassifiedReferences: context.rewrite.unclassifiedReferences
|
|
228
|
+
};
|
|
229
|
+
}
|
|
230
|
+
async function migrateExtensionId({ fromId, sourceDirectory, toId, yes = false }) {
|
|
231
|
+
const context = await migrationContext(sourceDirectory, fromId, toId, yes);
|
|
232
|
+
const plan = {
|
|
233
|
+
artifactReady: context.artifactReady,
|
|
234
|
+
counts: context.rewrite.counts,
|
|
235
|
+
fromId,
|
|
236
|
+
sourceDirectory: context.source.resolvedSourceDirectory,
|
|
237
|
+
toId,
|
|
238
|
+
totalChanges: context.rewrite.totalChanges,
|
|
239
|
+
unclassifiedReferences: context.rewrite.unclassifiedReferences
|
|
240
|
+
};
|
|
241
|
+
if (!yes) return {
|
|
242
|
+
applied: false,
|
|
243
|
+
changed: false,
|
|
244
|
+
...plan,
|
|
245
|
+
rollbackCleanupWarning: null
|
|
246
|
+
};
|
|
247
|
+
assert(context.artifactReady, `Extension artifact must declare // ID: ${toId} before migration. For managed extensions, use extensions update ${fromId} --migrate-id ${toId}.`);
|
|
248
|
+
if (context.extension.source) assert(extensionIntegrity(context.contents) === context.extension.source.integrity, `Managed extension ${fromId} does not match its source integrity. Use extensions update with --migrate-id so provenance is updated atomically.`);
|
|
249
|
+
const initialComparison = await compareDirectories(context.source.resolvedSourceDirectory, context.source.resolvedSourceDirectory);
|
|
250
|
+
assert(initialComparison.identical && initialComparison.existingFingerprint === initialComparison.candidateFingerprint, "SB3 source changed while its initial migration state was being inspected.");
|
|
251
|
+
const parentDirectory = path.dirname(context.source.resolvedSourceDirectory);
|
|
252
|
+
const candidateDirectory = await mkdtemp(path.join(parentDirectory, `.${path.basename(context.source.resolvedSourceDirectory)}.id-`));
|
|
253
|
+
let installed = false;
|
|
254
|
+
try {
|
|
255
|
+
await cp(context.source.resolvedSourceDirectory, candidateDirectory, {
|
|
256
|
+
preserveTimestamps: true,
|
|
257
|
+
recursive: true,
|
|
258
|
+
verbatimSymlinks: true
|
|
259
|
+
});
|
|
260
|
+
const replacements = [
|
|
261
|
+
writeFile(path.join(candidateDirectory, context.source.sourceManifest.project), `${JSON.stringify(context.rewrite.project, null, 2)}\n`),
|
|
262
|
+
writeFile(path.join(candidateDirectory, context.source.sourceManifest.embeddedExtensions), `${JSON.stringify(context.rewrite.extensionManifest, null, 2)}\n`),
|
|
263
|
+
rename(path.join(candidateDirectory, context.rewrite.oldPath), path.join(candidateDirectory, context.rewrite.newPath))
|
|
264
|
+
];
|
|
265
|
+
if (context.rewrite.oldApiManifestPath && context.rewrite.newApiManifestPath) replacements.push(rename(path.join(candidateDirectory, context.rewrite.oldApiManifestPath), path.join(candidateDirectory, context.rewrite.newApiManifestPath)));
|
|
266
|
+
await Promise.all(replacements);
|
|
267
|
+
await createDeterministicSb3(candidateDirectory);
|
|
268
|
+
const comparison = await compareDirectories(context.source.resolvedSourceDirectory, candidateDirectory);
|
|
269
|
+
assert(comparison.existingFingerprint === initialComparison.existingFingerprint, "SB3 source changed while the ID migration candidate was prepared; refusing to replace it.");
|
|
270
|
+
assert(!comparison.identical, "Extension ID migration produced no source changes.");
|
|
271
|
+
const latestComparison = await compareDirectories(context.source.resolvedSourceDirectory, candidateDirectory);
|
|
272
|
+
assert(latestComparison.existingFingerprint === comparison.existingFingerprint && latestComparison.candidateFingerprint === comparison.candidateFingerprint, "SB3 source or ID migration candidate changed during migration; refusing to replace it.");
|
|
273
|
+
const replacement = await replaceDirectoryTransactionally(candidateDirectory, context.source.resolvedSourceDirectory);
|
|
274
|
+
installed = true;
|
|
275
|
+
return {
|
|
276
|
+
applied: true,
|
|
277
|
+
changed: true,
|
|
278
|
+
comparison,
|
|
279
|
+
...plan,
|
|
280
|
+
...replacement
|
|
281
|
+
};
|
|
282
|
+
} finally {
|
|
283
|
+
if (!installed) await rm(candidateDirectory, {
|
|
284
|
+
recursive: true,
|
|
285
|
+
force: true
|
|
286
|
+
});
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
//#endregion
|
|
290
|
+
export { migrateExtensionId, planExtensionIdMigration, rewriteExtensionIdDocuments, validateNewExtensionId };
|
|
291
|
+
|
|
292
|
+
//# sourceMappingURL=extension-id-migration.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"extension-id-migration.js","names":[],"sources":["../src/extension-id-migration.ts"],"sourcesContent":["// SPDX-License-Identifier: MPL-2.0\n\nimport {cp, lstat, mkdtemp, readFile, rename, rm, writeFile} from 'node:fs/promises';\nimport path from 'node:path';\n\nimport {assert} from './assert';\nimport {extensionApiManifestIntegrity, parseExtensionApiManifest} from './extension-api-manifest';\nimport {extensionHeaderId, extensionIntegrity} from './extension-dependencies';\nimport {\n assertNoInterruptedRollback,\n compareDirectories,\n pathExists,\n replaceDirectoryTransactionally,\n} from './output-safety';\nimport {createDeterministicSb3, inspectSb3SourceForExtensionSync} from './source';\nimport type {InspectedSb3Source} from './source';\nimport type {\n EmbeddedExtension,\n EmbeddedExtensionManifest,\n ProjectJson,\n UnknownRecord,\n} from './types';\n\nexport interface ExtensionIdReference {\n file: string;\n kind: 'key' | 'value';\n path: string;\n value: string;\n}\n\nexport interface ExtensionIdMigrationCounts {\n apiManifestArtifacts: number;\n blockOpcodes: number;\n extensionFiles: number;\n extensionUrlKeys: number;\n extensionUrlValues: number;\n manifestIds: number;\n manifestPaths: number;\n monitorOpcodes: number;\n projectExtensions: number;\n sourceArtifacts: number;\n}\n\nexport interface RewriteExtensionIdDocumentsInput {\n apiManifestArtifact?: string;\n extensionManifest: EmbeddedExtensionManifest;\n newId: string;\n oldId: string;\n project: ProjectJson;\n sourceArtifact?: string;\n}\n\nexport interface RewriteExtensionIdDocumentsResult {\n counts: ExtensionIdMigrationCounts;\n extensionIndex: number;\n extensionManifest: EmbeddedExtensionManifest;\n newApiManifestPath: string | null;\n newPath: string;\n oldApiManifestPath: string | null;\n oldPath: string;\n project: ProjectJson;\n totalChanges: number;\n unclassifiedReferences: ExtensionIdReference[];\n}\n\ninterface MigrationContext {\n apiManifestContents: Uint8Array | null;\n artifactReady: boolean;\n contents: Uint8Array;\n extension: EmbeddedExtension;\n rewrite: RewriteExtensionIdDocumentsResult;\n source: InspectedSb3Source;\n}\n\nfunction isObject(value: unknown): value is UnknownRecord {\n return typeof value === 'object' && value !== null && !Array.isArray(value);\n}\n\nfunction escapeJsonPointer(value: string): string {\n return value.replaceAll('~', '~0').replaceAll('/', '~1');\n}\n\nfunction referenceKey(file: string, kind: string, pointer: string): string {\n return `${file}\\u0000${kind}\\u0000${pointer}`;\n}\n\nfunction collectUnclassifiedReferences(\n value: unknown,\n oldId: string,\n file: string,\n classified: Set<string>,\n): ExtensionIdReference[] {\n const references: ExtensionIdReference[] = [];\n\n function visit(current: unknown, pointer: string): void {\n if (typeof current === 'string') {\n if (current.includes(oldId) && !classified.has(referenceKey(file, 'value', pointer))) {\n references.push({file, kind: 'value', path: pointer || '/', value: current});\n }\n return;\n }\n if (!current || typeof current !== 'object') return;\n\n if (Array.isArray(current)) {\n for (const [index, entry] of (current as unknown[]).entries()) {\n visit(entry, `${pointer}/${index}`);\n }\n return;\n }\n\n for (const [key, entry] of Object.entries(current as UnknownRecord)) {\n const entryPointer = `${pointer}/${escapeJsonPointer(key)}`;\n if (key.includes(oldId) && !classified.has(referenceKey(file, 'key', entryPointer))) {\n references.push({file, kind: 'key', path: entryPointer, value: key});\n }\n visit(entry, entryPointer);\n }\n }\n\n visit(value, '');\n return references;\n}\n\nfunction replaceObjectKeyAtSamePosition(\n object: UnknownRecord,\n oldKey: string,\n newKey: string,\n): UnknownRecord {\n const replacement: UnknownRecord = {};\n for (const [key, value] of Object.entries(object)) {\n replacement[key === oldKey ? newKey : key] = value;\n }\n return replacement;\n}\n\nexport function validateNewExtensionId(newId: unknown): string {\n assert(\n typeof newId === 'string' && /^[a-z0-9]+$/u.test(newId),\n `New extension ID must use TurboWarp's [a-z0-9]+ format: ${JSON.stringify(newId)}`,\n );\n return newId;\n}\n\nexport function rewriteExtensionIdDocuments({\n apiManifestArtifact = undefined,\n extensionManifest,\n newId,\n oldId,\n project,\n sourceArtifact = undefined,\n}: RewriteExtensionIdDocumentsInput): RewriteExtensionIdDocumentsResult {\n assert(\n typeof oldId === 'string' && /^[A-Za-z0-9._-]+$/u.test(oldId),\n `Invalid existing extension ID: ${JSON.stringify(oldId)}`,\n );\n validateNewExtensionId(newId);\n assert(oldId !== newId, 'The existing and new extension IDs must differ.');\n\n const originalProject = structuredClone(project);\n const originalManifest = structuredClone(extensionManifest);\n const migratedProject = structuredClone(project);\n const migratedManifest = structuredClone(extensionManifest);\n const extensions = migratedManifest.extensions;\n assert(Array.isArray(extensions), 'Embedded extension manifest requires extensions.');\n const extensionIndex = extensions.findIndex(\n (extension: EmbeddedExtension | undefined) => extension?.id === oldId,\n );\n assert(extensionIndex !== -1, `Embedded extension was not found: ${oldId}`);\n assert(\n !extensions.some((extension: EmbeddedExtension | undefined) => extension?.id === newId),\n `Embedded extension ID already exists: ${newId}`,\n );\n\n const extensionUrls: unknown = migratedProject.extensionURLs;\n assert(isObject(extensionUrls), 'project.source.json extensionURLs must be an object.');\n assert(\n Object.hasOwn(extensionUrls, oldId),\n `project.source.json has no extensionURLs entry for ${oldId}.`,\n );\n assert(\n !Object.hasOwn(extensionUrls, newId),\n `project.source.json extensionURLs already contains ${newId}.`,\n );\n assert(\n migratedProject.extensions === undefined || Array.isArray(migratedProject.extensions),\n 'project.source.json extensions must be an array when present.',\n );\n assert(\n migratedProject.monitors === undefined || Array.isArray(migratedProject.monitors),\n 'project.source.json monitors must be an array when present.',\n );\n const projectExtensions = migratedProject.extensions as unknown[] | undefined;\n if (projectExtensions) {\n assert(\n !projectExtensions.includes(newId),\n `project.source.json extensions already contains ${newId}.`,\n );\n }\n\n const counts: ExtensionIdMigrationCounts = {\n apiManifestArtifacts: 0,\n blockOpcodes: 0,\n extensionFiles: 1,\n extensionUrlKeys: 0,\n extensionUrlValues: 0,\n manifestIds: 0,\n manifestPaths: 0,\n monitorOpcodes: 0,\n projectExtensions: 0,\n sourceArtifacts: 0,\n };\n const projectClassified = new Set<string>();\n const manifestClassified = new Set<string>();\n\n if (projectExtensions) {\n for (const [index, extensionId] of projectExtensions.entries()) {\n if (extensionId === oldId) {\n projectExtensions[index] = newId;\n counts.projectExtensions += 1;\n projectClassified.add(referenceKey('project.source.json', 'value', `/extensions/${index}`));\n }\n }\n }\n\n const oldExtensionUrl = extensionUrls[oldId];\n const oldExtensionUrlPointer = `/extensionURLs/${escapeJsonPointer(oldId)}`;\n projectClassified.add(referenceKey('project.source.json', 'key', oldExtensionUrlPointer));\n counts.extensionUrlKeys += 1;\n const expectedOldUrl = `embedded-extension:extensions/${oldId}.js`;\n assert(\n oldExtensionUrl === expectedOldUrl,\n `Embedded extension URL mismatch for ${oldId}: ${oldExtensionUrl}`,\n );\n extensionUrls[oldId] = `embedded-extension:extensions/${newId}.js`;\n projectClassified.add(referenceKey('project.source.json', 'value', oldExtensionUrlPointer));\n counts.extensionUrlValues += 1;\n migratedProject.extensionURLs = replaceObjectKeyAtSamePosition(extensionUrls, oldId, newId);\n\n const migratedTargets = (migratedProject.targets as unknown[] | undefined) ?? [];\n for (const [targetIndex, target] of migratedTargets.entries()) {\n if (!isObject(target) || !isObject(target.blocks)) continue;\n for (const [blockId, block] of Object.entries(target.blocks)) {\n if (!isObject(block)) continue;\n if (typeof block.opcode === 'string' && block.opcode.startsWith(`${oldId}_`)) {\n block.opcode = `${newId}_${block.opcode.slice(oldId.length + 1)}`;\n counts.blockOpcodes += 1;\n projectClassified.add(\n referenceKey(\n 'project.source.json',\n 'value',\n `/targets/${targetIndex}/blocks/${escapeJsonPointer(blockId)}/opcode`,\n ),\n );\n }\n }\n }\n\n const migratedMonitors = (migratedProject.monitors as unknown[] | undefined) ?? [];\n for (const [monitorIndex, monitor] of migratedMonitors.entries()) {\n if (\n isObject(monitor) &&\n typeof monitor.opcode === 'string' &&\n monitor.opcode.startsWith(`${oldId}_`)\n ) {\n monitor.opcode = `${newId}_${monitor.opcode.slice(oldId.length + 1)}`;\n counts.monitorOpcodes += 1;\n projectClassified.add(\n referenceKey('project.source.json', 'value', `/monitors/${monitorIndex}/opcode`),\n );\n }\n }\n\n const extension = extensions[extensionIndex];\n extension.id = newId;\n counts.manifestIds += 1;\n manifestClassified.add(\n referenceKey('embedded-extensions.json', 'value', `/extensions/${extensionIndex}/id`),\n );\n const oldPath = `extensions/${oldId}.js`;\n assert(\n extension.path === oldPath,\n `Embedded extension path mismatch for ${oldId}: ${extension.path}`,\n );\n extension.path = `extensions/${newId}.js`;\n counts.manifestPaths += 1;\n manifestClassified.add(\n referenceKey('embedded-extensions.json', 'value', `/extensions/${extensionIndex}/path`),\n );\n let oldApiManifestPath = null;\n let newApiManifestPath = null;\n if (apiManifestArtifact !== undefined) {\n assert(\n extension.source?.apiManifest,\n `Extension ${oldId} has no managed API manifest metadata.`,\n );\n }\n if (extension.source?.apiManifest) {\n oldApiManifestPath = `extensions/${oldId}.manifest.json`;\n newApiManifestPath = `extensions/${newId}.manifest.json`;\n assert(\n extension.source.apiManifest.path === oldApiManifestPath,\n `Extension API manifest path mismatch for ${oldId}: ${extension.source.apiManifest.path}`,\n );\n extension.source.apiManifest.path = newApiManifestPath;\n counts.manifestPaths += 1;\n manifestClassified.add(\n referenceKey(\n 'embedded-extensions.json',\n 'value',\n `/extensions/${extensionIndex}/source/apiManifest/path`,\n ),\n );\n if (\n apiManifestArtifact !== undefined &&\n extension.source.apiManifest.artifact !== apiManifestArtifact\n ) {\n extension.source.apiManifest.artifact = apiManifestArtifact;\n counts.apiManifestArtifacts += 1;\n manifestClassified.add(\n referenceKey(\n 'embedded-extensions.json',\n 'value',\n `/extensions/${extensionIndex}/source/apiManifest/artifact`,\n ),\n );\n }\n }\n if (sourceArtifact !== undefined) {\n assert(extension.source, `Extension ${oldId} has no managed source metadata.`);\n if (extension.source.artifact !== sourceArtifact) {\n extension.source.artifact = sourceArtifact;\n counts.sourceArtifacts += 1;\n manifestClassified.add(\n referenceKey(\n 'embedded-extensions.json',\n 'value',\n `/extensions/${extensionIndex}/source/artifact`,\n ),\n );\n }\n }\n\n const unclassifiedReferences = [\n ...collectUnclassifiedReferences(\n originalProject,\n oldId,\n 'project.source.json',\n projectClassified,\n ),\n ...collectUnclassifiedReferences(\n originalManifest,\n oldId,\n 'embedded-extensions.json',\n manifestClassified,\n ),\n ];\n const totalChanges = Object.values(counts).reduce((total, count) => total + count, 0);\n return {\n counts,\n extensionIndex,\n extensionManifest: migratedManifest,\n newApiManifestPath,\n newPath: `extensions/${newId}.js`,\n oldApiManifestPath,\n oldPath,\n project: migratedProject,\n totalChanges,\n unclassifiedReferences,\n };\n}\n\nasync function inspectMigrationSource(\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 during extension ID migration.',\n );\n assert(\n !(await pathExists(path.join(resolvedSourceDirectory, '.git'))),\n 'Refusing to replace a Git repository root during extension ID migration.',\n );\n }\n const stats = await lstat(resolvedSourceDirectory);\n assert(\n stats.isDirectory() && !stats.isSymbolicLink(),\n `SB3 source must be a directory, not a file or symbolic link: ${resolvedSourceDirectory}`,\n );\n if (willReplace) {\n await assertNoInterruptedRollback(resolvedSourceDirectory);\n }\n return inspectSb3SourceForExtensionSync(resolvedSourceDirectory);\n}\n\nasync function migrationContext(\n sourceDirectory: string,\n oldId: string,\n newId: string,\n willReplace: boolean,\n): Promise<MigrationContext> {\n const source = await inspectMigrationSource(sourceDirectory, willReplace);\n const extensionManifestPath = path.join(\n source.resolvedSourceDirectory,\n source.sourceManifest.embeddedExtensions,\n );\n const extensionManifest = JSON.parse(\n await readFile(extensionManifestPath, 'utf8'),\n ) as EmbeddedExtensionManifest;\n const rewrite = rewriteExtensionIdDocuments({\n extensionManifest,\n newId,\n oldId,\n project: source.project,\n });\n const extension = source.extensions[rewrite.extensionIndex];\n const contents = source.extensionContents.get(oldId);\n assert(contents, `Embedded extension has no contents: ${oldId}`);\n const apiManifestContents = source.extensionApiManifestContents.get(oldId) ?? null;\n let apiManifestReady = true;\n if (extension.source?.apiManifest) {\n apiManifestReady =\n apiManifestContents !== null &&\n extensionApiManifestIntegrity(apiManifestContents) === extension.source.apiManifest.integrity;\n if (apiManifestReady && apiManifestContents !== null) {\n try {\n parseExtensionApiManifest(apiManifestContents, {expectedId: newId});\n } catch {\n apiManifestReady = false;\n }\n }\n }\n return {\n apiManifestContents,\n artifactReady: extensionHeaderId(contents) === newId && apiManifestReady,\n contents,\n extension,\n rewrite,\n source,\n };\n}\n\nexport async function planExtensionIdMigration({\n fromId,\n sourceDirectory,\n toId,\n}: {\n fromId: string;\n sourceDirectory: string;\n toId: string;\n}) {\n const context = await migrationContext(sourceDirectory, fromId, toId, false);\n return {\n artifactReady: context.artifactReady,\n counts: context.rewrite.counts,\n fromId,\n sourceDirectory: context.source.resolvedSourceDirectory,\n toId,\n totalChanges: context.rewrite.totalChanges,\n unclassifiedReferences: context.rewrite.unclassifiedReferences,\n };\n}\n\nexport async function migrateExtensionId({\n fromId,\n sourceDirectory,\n toId,\n yes = false,\n}: {\n fromId: string;\n sourceDirectory: string;\n toId: string;\n yes?: boolean;\n}) {\n const context = await migrationContext(sourceDirectory, fromId, toId, yes);\n const plan = {\n artifactReady: context.artifactReady,\n counts: context.rewrite.counts,\n fromId,\n sourceDirectory: context.source.resolvedSourceDirectory,\n toId,\n totalChanges: context.rewrite.totalChanges,\n unclassifiedReferences: context.rewrite.unclassifiedReferences,\n };\n if (!yes) {\n return {\n applied: false,\n changed: false,\n ...plan,\n rollbackCleanupWarning: null,\n };\n }\n\n assert(\n context.artifactReady,\n `Extension artifact must declare // ID: ${toId} before migration. ` +\n `For managed extensions, use extensions update ${fromId} --migrate-id ${toId}.`,\n );\n if (context.extension.source) {\n assert(\n extensionIntegrity(context.contents) === context.extension.source.integrity,\n `Managed extension ${fromId} does not match its source integrity. ` +\n 'Use extensions update with --migrate-id so provenance is updated atomically.',\n );\n }\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 migration state was being inspected.',\n );\n\n const parentDirectory = path.dirname(context.source.resolvedSourceDirectory);\n const candidateDirectory = await mkdtemp(\n path.join(parentDirectory, `.${path.basename(context.source.resolvedSourceDirectory)}.id-`),\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 const replacements = [\n writeFile(\n path.join(candidateDirectory, context.source.sourceManifest.project),\n `${JSON.stringify(context.rewrite.project, null, 2)}\\n`,\n ),\n writeFile(\n path.join(candidateDirectory, context.source.sourceManifest.embeddedExtensions),\n `${JSON.stringify(context.rewrite.extensionManifest, null, 2)}\\n`,\n ),\n rename(\n path.join(candidateDirectory, context.rewrite.oldPath),\n path.join(candidateDirectory, context.rewrite.newPath),\n ),\n ];\n if (context.rewrite.oldApiManifestPath && context.rewrite.newApiManifestPath) {\n replacements.push(\n rename(\n path.join(candidateDirectory, context.rewrite.oldApiManifestPath),\n path.join(candidateDirectory, context.rewrite.newApiManifestPath),\n ),\n );\n }\n await Promise.all(replacements);\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 ID migration candidate was prepared; refusing to replace it.',\n );\n assert(!comparison.identical, 'Extension ID migration 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 ID migration candidate changed during migration; refusing to replace it.',\n );\n const replacement = await replaceDirectoryTransactionally(\n candidateDirectory,\n context.source.resolvedSourceDirectory,\n );\n installed = true;\n return {\n applied: true,\n changed: true,\n comparison,\n ...plan,\n ...replacement,\n };\n } finally {\n if (!installed) {\n await rm(candidateDirectory, {recursive: true, force: true});\n }\n }\n}\n"],"mappings":";;;;;;;;AA0EA,SAAS,SAAS,OAAwC;CACxD,OAAO,OAAO,UAAU,YAAY,UAAU,QAAQ,CAAC,MAAM,QAAQ,KAAK;AAC5E;AAEA,SAAS,kBAAkB,OAAuB;CAChD,OAAO,MAAM,WAAW,KAAK,IAAI,CAAC,CAAC,WAAW,KAAK,IAAI;AACzD;AAEA,SAAS,aAAa,MAAc,MAAc,SAAyB;CACzE,OAAO,GAAG,KAAK,QAAQ,KAAK,QAAQ;AACtC;AAEA,SAAS,8BACP,OACA,OACA,MACA,YACwB;CACxB,MAAM,aAAqC,CAAC;CAE5C,SAAS,MAAM,SAAkB,SAAuB;EACtD,IAAI,OAAO,YAAY,UAAU;GAC/B,IAAI,QAAQ,SAAS,KAAK,KAAK,CAAC,WAAW,IAAI,aAAa,MAAM,SAAS,OAAO,CAAC,GACjF,WAAW,KAAK;IAAC;IAAM,MAAM;IAAS,MAAM,WAAW;IAAK,OAAO;GAAO,CAAC;GAE7E;EACF;EACA,IAAI,CAAC,WAAW,OAAO,YAAY,UAAU;EAE7C,IAAI,MAAM,QAAQ,OAAO,GAAG;GAC1B,KAAK,MAAM,CAAC,OAAO,UAAW,QAAsB,QAAQ,GAC1D,MAAM,OAAO,GAAG,QAAQ,GAAG,OAAO;GAEpC;EACF;EAEA,KAAK,MAAM,CAAC,KAAK,UAAU,OAAO,QAAQ,OAAwB,GAAG;GACnE,MAAM,eAAe,GAAG,QAAQ,GAAG,kBAAkB,GAAG;GACxD,IAAI,IAAI,SAAS,KAAK,KAAK,CAAC,WAAW,IAAI,aAAa,MAAM,OAAO,YAAY,CAAC,GAChF,WAAW,KAAK;IAAC;IAAM,MAAM;IAAO,MAAM;IAAc,OAAO;GAA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QAAQ,QAAQ,OAAO,GACrD,KAAK,KAAK,oBAAoB,QAAQ,QAAQ,OAAO,CACvD;EACF;EACA,IAAI,QAAQ,QAAQ,sBAAsB,QAAQ,QAAQ,oBACxD,aAAa,KACX,OACE,KAAK,KAAK,oBAAoB,QAAQ,QAAQ,kBAAkB,GAChE,KAAK,KAAK,oBAAoB,QAAQ,QAAQ,kBAAkB,CAClE,CACF;EAEF,MAAM,QAAQ,IAAI,YAAY;EAC9B,MAAM,uBAAuB,kBAAkB;EAC/C,MAAM,aAAa,MAAM,mBACvB,QAAQ,OAAO,yBACf,kBACF;EACA,OACE,WAAW,wBAAwB,kBAAkB,qBACrD,2FACF;EACA,OAAO,CAAC,WAAW,WAAW,oDAAoD;EAClF,MAAM,mBAAmB,MAAM,mBAC7B,QAAQ,OAAO,yBACf,kBACF;EACA,OACE,iBAAiB,wBAAwB,WAAW,uBAClD,iBAAiB,yBAAyB,WAAW,sBACvD,wFACF;EACA,MAAM,cAAc,MAAM,gCACxB,oBACA,QAAQ,OAAO,uBACjB;EACA,YAAY;EACZ,OAAO;GACL,SAAS;GACT,SAAS;GACT;GACA,GAAG;GACH,GAAG;EACL;CACF,UAAU;EACR,IAAI,CAAC,WACH,MAAM,GAAG,oBAAoB;GAAC,WAAW;GAAM,OAAO;EAAI,CAAC;CAE/D;AACF"}
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import { ExtensionApiCompatibilityChange } from './extension-api-manifest';
|
|
2
|
+
import { DirectoryComparison } from './output-safety';
|
|
3
|
+
export declare const defaultExtensionArtifactSizeLimit: number;
|
|
4
|
+
export type FetchImplementation = typeof globalThis.fetch;
|
|
5
|
+
export type ExtensionSyncMode = 'sync' | 'update';
|
|
6
|
+
export interface ExtensionSyncConfirmContext {
|
|
7
|
+
comparison: DirectoryComparison;
|
|
8
|
+
sourceDirectory: string;
|
|
9
|
+
}
|
|
10
|
+
export interface SyncExtensionsOptions {
|
|
11
|
+
confirmReplace?: (context: ExtensionSyncConfirmContext) => boolean | Promise<boolean>;
|
|
12
|
+
fetch?: FetchImplementation;
|
|
13
|
+
maximumArtifactBytes?: number;
|
|
14
|
+
maximumManifestBytes?: number;
|
|
15
|
+
sourceDirectory: string;
|
|
16
|
+
yes?: boolean;
|
|
17
|
+
}
|
|
18
|
+
export interface UpdateExtensionsOptions extends SyncExtensionsOptions {
|
|
19
|
+
allowBreakingApi?: boolean;
|
|
20
|
+
apiManifestArtifact?: string;
|
|
21
|
+
extensionId?: string;
|
|
22
|
+
migrateToId?: string;
|
|
23
|
+
sourceArtifact?: string;
|
|
24
|
+
}
|
|
25
|
+
export declare function extensionStatus(sourceDirectory: string, { fetch: fetchImplementation }?: {
|
|
26
|
+
fetch?: FetchImplementation;
|
|
27
|
+
}): Promise<({
|
|
28
|
+
id: string;
|
|
29
|
+
installedVersion: string;
|
|
30
|
+
local: string;
|
|
31
|
+
package: string;
|
|
32
|
+
state: string;
|
|
33
|
+
version: string;
|
|
34
|
+
ref?: undefined;
|
|
35
|
+
remoteCommit?: undefined;
|
|
36
|
+
resolvedCommit?: undefined;
|
|
37
|
+
} | {
|
|
38
|
+
id: string;
|
|
39
|
+
local: string;
|
|
40
|
+
ref: string;
|
|
41
|
+
remoteCommit: string;
|
|
42
|
+
resolvedCommit: string;
|
|
43
|
+
state: string;
|
|
44
|
+
installedVersion?: undefined;
|
|
45
|
+
package?: undefined;
|
|
46
|
+
version?: undefined;
|
|
47
|
+
})[]>;
|
|
48
|
+
export declare function syncExtensions({ confirmReplace, fetch: fetchImplementation, maximumArtifactBytes, maximumManifestBytes, sourceDirectory, yes, }: SyncExtensionsOptions): Promise<{
|
|
49
|
+
apiCompatibility: {
|
|
50
|
+
changes: ExtensionApiCompatibilityChange[];
|
|
51
|
+
id: string;
|
|
52
|
+
previousId: string | undefined;
|
|
53
|
+
}[];
|
|
54
|
+
extensions: ({
|
|
55
|
+
id: string;
|
|
56
|
+
package: string;
|
|
57
|
+
version: string | undefined;
|
|
58
|
+
previousId?: undefined;
|
|
59
|
+
resolvedCommit?: undefined;
|
|
60
|
+
} | {
|
|
61
|
+
id: string;
|
|
62
|
+
previousId: string | undefined;
|
|
63
|
+
resolvedCommit: string | null;
|
|
64
|
+
package?: undefined;
|
|
65
|
+
version?: undefined;
|
|
66
|
+
})[];
|
|
67
|
+
migration: {
|
|
68
|
+
counts: import('./extension-id-migration').ExtensionIdMigrationCounts;
|
|
69
|
+
fromId: string | undefined;
|
|
70
|
+
toId: string | undefined;
|
|
71
|
+
totalChanges: number;
|
|
72
|
+
unclassifiedReferences: import('./extension-id-migration').ExtensionIdReference[];
|
|
73
|
+
} | null;
|
|
74
|
+
mode: ExtensionSyncMode;
|
|
75
|
+
sourceDirectory: string;
|
|
76
|
+
changed: boolean;
|
|
77
|
+
comparison: DirectoryComparison;
|
|
78
|
+
rollbackCleanupWarning: string | null;
|
|
79
|
+
}>;
|
|
80
|
+
export declare function updateExtensions({ allowBreakingApi, apiManifestArtifact, confirmReplace, extensionId, fetch: fetchImplementation, maximumArtifactBytes, maximumManifestBytes, migrateToId, sourceArtifact, sourceDirectory, yes, }: UpdateExtensionsOptions): Promise<{
|
|
81
|
+
apiCompatibility: {
|
|
82
|
+
changes: ExtensionApiCompatibilityChange[];
|
|
83
|
+
id: string;
|
|
84
|
+
previousId: string | undefined;
|
|
85
|
+
}[];
|
|
86
|
+
extensions: ({
|
|
87
|
+
id: string;
|
|
88
|
+
package: string;
|
|
89
|
+
version: string | undefined;
|
|
90
|
+
previousId?: undefined;
|
|
91
|
+
resolvedCommit?: undefined;
|
|
92
|
+
} | {
|
|
93
|
+
id: string;
|
|
94
|
+
previousId: string | undefined;
|
|
95
|
+
resolvedCommit: string | null;
|
|
96
|
+
package?: undefined;
|
|
97
|
+
version?: undefined;
|
|
98
|
+
})[];
|
|
99
|
+
migration: {
|
|
100
|
+
counts: import('./extension-id-migration').ExtensionIdMigrationCounts;
|
|
101
|
+
fromId: string | undefined;
|
|
102
|
+
toId: string | undefined;
|
|
103
|
+
totalChanges: number;
|
|
104
|
+
unclassifiedReferences: import('./extension-id-migration').ExtensionIdReference[];
|
|
105
|
+
} | null;
|
|
106
|
+
mode: ExtensionSyncMode;
|
|
107
|
+
sourceDirectory: string;
|
|
108
|
+
changed: boolean;
|
|
109
|
+
comparison: DirectoryComparison;
|
|
110
|
+
rollbackCleanupWarning: string | null;
|
|
111
|
+
}>;
|