Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 27 additions & 16 deletions src/cli/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,22 +88,33 @@ program
program
.command("pack [directory] [output]")
.description("Pack a directory into an MCPB extension")
.action((directory: string = process.cwd(), output?: string) => {
void (async () => {
try {
const success = await packExtension({
extensionPath: directory,
outputPath: output,
});
process.exit(success ? 0 : 1);
} catch (error) {
console.error(
`ERROR: ${error instanceof Error ? error.message : "Unknown error"}`,
);
process.exit(1);
}
})();
});
.option(
"--manifest-version <version>",
"Override manifest version in the output bundle",
)
.action(
(
directory: string = process.cwd(),
output?: string,
options?: { manifestVersion?: string },
) => {
void (async () => {
try {
const success = await packExtension({
extensionPath: directory,
outputPath: output,
manifestVersion: options?.manifestVersion,
});
process.exit(success ? 0 : 1);
} catch (error) {
console.error(
`ERROR: ${error instanceof Error ? error.message : "Unknown error"}`,
);
process.exit(1);
}
})();
},
);

// Unpack command
program
Expand Down
37 changes: 36 additions & 1 deletion src/cli/pack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
extensionPath: string;
outputPath?: string;
silent?: boolean;
manifestVersion?: string;
}

function formatFileSize(bytes: number): string {
Expand Down Expand Up @@ -50,10 +51,22 @@
extensionPath,
outputPath,
silent,
manifestVersion: targetManifestVersion,
}: PackOptions): Promise<boolean> {
const resolvedPath = resolve(extensionPath);
const logger = getLogger({ silent });

// Validate target manifest version if provided
if (

Check warning on line 60 in src/cli/pack.ts

View workflow job for this annotation

GitHub Actions / Test (22.17.x, windows-latest)

Replace `⏎····targetManifestVersion·&&⏎····!(targetManifestVersion·in·MANIFEST_SCHEMAS)⏎··` with `targetManifestVersion·&&·!(targetManifestVersion·in·MANIFEST_SCHEMAS)`

Check warning on line 60 in src/cli/pack.ts

View workflow job for this annotation

GitHub Actions / Test (22.17.x, ubuntu-latest)

Replace `⏎····targetManifestVersion·&&⏎····!(targetManifestVersion·in·MANIFEST_SCHEMAS)⏎··` with `targetManifestVersion·&&·!(targetManifestVersion·in·MANIFEST_SCHEMAS)`

Check warning on line 60 in src/cli/pack.ts

View workflow job for this annotation

GitHub Actions / Test (20.19.x, ubuntu-latest)

Replace `⏎····targetManifestVersion·&&⏎····!(targetManifestVersion·in·MANIFEST_SCHEMAS)⏎··` with `targetManifestVersion·&&·!(targetManifestVersion·in·MANIFEST_SCHEMAS)`

Check warning on line 60 in src/cli/pack.ts

View workflow job for this annotation

GitHub Actions / Test (20.19.x, macos-latest)

Replace `⏎····targetManifestVersion·&&⏎····!(targetManifestVersion·in·MANIFEST_SCHEMAS)⏎··` with `targetManifestVersion·&&·!(targetManifestVersion·in·MANIFEST_SCHEMAS)`

Check warning on line 60 in src/cli/pack.ts

View workflow job for this annotation

GitHub Actions / Test (20.19.x, windows-latest)

Replace `⏎····targetManifestVersion·&&⏎····!(targetManifestVersion·in·MANIFEST_SCHEMAS)⏎··` with `targetManifestVersion·&&·!(targetManifestVersion·in·MANIFEST_SCHEMAS)`

Check warning on line 60 in src/cli/pack.ts

View workflow job for this annotation

GitHub Actions / Test (22.17.x, macos-latest)

Replace `⏎····targetManifestVersion·&&⏎····!(targetManifestVersion·in·MANIFEST_SCHEMAS)⏎··` with `targetManifestVersion·&&·!(targetManifestVersion·in·MANIFEST_SCHEMAS)`
targetManifestVersion &&
!(targetManifestVersion in MANIFEST_SCHEMAS)
) {
logger.error(
`ERROR: Invalid manifest version "${targetManifestVersion}". Supported versions: ${Object.keys(MANIFEST_SCHEMAS).join(", ")}`,
);
return false;
}

// Check if directory exists
if (!existsSync(resolvedPath) || !statSync(resolvedPath).isDirectory()) {
logger.error(`ERROR: Directory not found: ${extensionPath}`);
Expand Down Expand Up @@ -90,10 +103,11 @@

// Read and parse manifest
let manifest;
let finalManifestContent: string;
try {
const manifestContent = readFileSync(manifestPath, "utf-8");
const manifestData = JSON.parse(manifestContent);
const manifestVersion = getManifestVersionFromRawData(manifestData);
let manifestVersion = getManifestVersionFromRawData(manifestData);
if (!manifestVersion) {
logger.error(
`ERROR: Manifest version mismatch. Expected "${Object.keys(MANIFEST_SCHEMAS).join(" or ")}", found "${manifestVersion}"`,
Expand All @@ -104,7 +118,20 @@
return false;
}

// Override manifest version if target version is specified
if (targetManifestVersion && targetManifestVersion !== manifestVersion) {
logger.log(
`Overriding manifest version from ${manifestVersion} to ${targetManifestVersion}`,
);
manifestData.manifest_version = targetManifestVersion;
// Remove legacy dxt_version if present to avoid confusion
delete manifestData.dxt_version;
manifestVersion =

Check warning on line 129 in src/cli/pack.ts

View workflow job for this annotation

GitHub Actions / Test (22.17.x, windows-latest)

Delete `⏎·······`

Check warning on line 129 in src/cli/pack.ts

View workflow job for this annotation

GitHub Actions / Test (22.17.x, ubuntu-latest)

Delete `⏎·······`

Check warning on line 129 in src/cli/pack.ts

View workflow job for this annotation

GitHub Actions / Test (20.19.x, ubuntu-latest)

Delete `⏎·······`

Check warning on line 129 in src/cli/pack.ts

View workflow job for this annotation

GitHub Actions / Test (20.19.x, macos-latest)

Delete `⏎·······`

Check warning on line 129 in src/cli/pack.ts

View workflow job for this annotation

GitHub Actions / Test (20.19.x, windows-latest)

Delete `⏎·······`

Check warning on line 129 in src/cli/pack.ts

View workflow job for this annotation

GitHub Actions / Test (22.17.x, macos-latest)

Delete `⏎·······`
targetManifestVersion as keyof typeof MANIFEST_SCHEMAS;
}

manifest = MANIFEST_SCHEMAS[manifestVersion].parse(manifestData);
finalManifestContent = JSON.stringify(manifestData, null, 2);
} catch (error) {
logger.error("ERROR: Failed to parse manifest.json");
if (error instanceof Error) {
Expand Down Expand Up @@ -135,6 +162,14 @@
mcpbIgnorePatterns,
);

// Override manifest.json with potentially modified content (version override)
if (files[manifestPath]) {
files[manifestPath] = {
...files[manifestPath],
data: Buffer.from(finalManifestContent, "utf-8"),
};
}

// Print package header
logger.log(`\n📦 ${manifest.name}@${manifest.version}`);

Expand Down