From 97efce92736c2881cda5cfd0d1a1407786c36d95 Mon Sep 17 00:00:00 2001 From: Thijs Koerselman Date: Thu, 28 Nov 2024 18:20:51 +0100 Subject: [PATCH] Use assert and add extra check for filename --- src/lib/utils/pack.ts | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/lib/utils/pack.ts b/src/lib/utils/pack.ts index 114381e..8286432 100644 --- a/src/lib/utils/pack.ts +++ b/src/lib/utils/pack.ts @@ -1,3 +1,4 @@ +import assert from "node:assert"; import { exec } from "node:child_process"; import fs from "node:fs"; import path from "node:path"; @@ -49,11 +50,13 @@ export async function pack(srcDir: string, dstDir: string) { }); const lastLine = stdout.trim().split("\n").at(-1); - if (!lastLine) { - throw new Error(`Failed to parse last line from stdout: ${stdout.trim()}`); - } + + assert(lastLine, `Failed to parse last line from stdout: ${stdout.trim()}`); + const fileName = path.basename(lastLine); + assert(fileName, `Failed to parse file name from: ${lastLine}`); + const filePath = path.join(dstDir, fileName); if (!fs.existsSync(filePath)) {