Skip to content

Commit bf01918

Browse files
fix: allow repeat runs of "dxt clean" (#83)
1 parent b062c0e commit bf01918

File tree

1 file changed

+20
-5
lines changed

1 file changed

+20
-5
lines changed

src/node/validate.ts

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,8 @@ export async function cleanDxt(inputPath: string) {
7070
await unpackExtension({ dxtPath, silent: true, outputDir: unpackPath });
7171

7272
const manifestPath = resolve(unpackPath, "manifest.json");
73-
7473
const originalManifest = await fs.readFile(manifestPath, "utf-8");
7574
const manifestData = JSON.parse(originalManifest);
76-
7775
const result = LooseDxtManifestSchema.safeParse(manifestData);
7876

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

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

9997
const destroyer = new DestroyerOfModules({
10098
rootDirectory: unpackPath,
10199
});
102-
await destroyer.destroy();
103100

104-
console.log(" -- Galactus pruned node_modules");
101+
try {
102+
await destroyer.destroy();
103+
} catch (error) {
104+
// If modules have already been deleted in a previous clean, the walker
105+
// will fail when it can't find required dependencies. This is expected
106+
// and safe to ignore.
107+
if (
108+
error instanceof Error &&
109+
error.message.includes("Failed to locate module")
110+
) {
111+
console.log(
112+
" -- Some modules already removed, skipping remaining cleanup",
113+
);
114+
} else {
115+
throw error;
116+
}
117+
}
118+
119+
console.log(" -- Removed development dependencies from node_modules");
105120
} else {
106121
console.log(" -- No node_modules, not pruning");
107122
}

0 commit comments

Comments
 (0)