Skip to content
Merged
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
25 changes: 20 additions & 5 deletions src/node/validate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,8 @@ export async function cleanDxt(inputPath: string) {
await unpackExtension({ dxtPath, silent: true, outputDir: unpackPath });

const manifestPath = resolve(unpackPath, "manifest.json");

const originalManifest = await fs.readFile(manifestPath, "utf-8");
const manifestData = JSON.parse(originalManifest);

const result = LooseDxtManifestSchema.safeParse(manifestData);

if (!result.success) {
Expand All @@ -94,14 +92,31 @@ export async function cleanDxt(inputPath: string) {

const nodeModulesPath = resolve(unpackPath, "node_modules");
if (existsSync(nodeModulesPath)) {
console.log(" -- node_modules found, running galactus");
console.log(" -- node_modules found, deleting development dependencies");

const destroyer = new DestroyerOfModules({
rootDirectory: unpackPath,
});
await destroyer.destroy();

console.log(" -- Galactus pruned node_modules");
try {
await destroyer.destroy();
} catch (error) {
// If modules have already been deleted in a previous clean, the walker
// will fail when it can't find required dependencies. This is expected
// and safe to ignore.
if (
error instanceof Error &&
error.message.includes("Failed to locate module")
) {
console.log(
" -- Some modules already removed, skipping remaining cleanup",
);
} else {
throw error;
}
}

console.log(" -- Removed development dependencies from node_modules");
} else {
console.log(" -- No node_modules, not pruning");
}
Expand Down
Loading