From 992190be02dd2116bed252bff563f4ec12562c02 Mon Sep 17 00:00:00 2001 From: YashRaj <91825864+YashRajCodes@users.noreply.github.com> Date: Fri, 27 Mar 2026 18:46:13 +0530 Subject: [PATCH] feat: add pnpm install prompt for missing dependencies (#929) * feat: add pnpm install prompt for missing dependencies * feat: use --frozen-lockfile * feat: remove ugly error on ctrl + c * feat: use pnpm list instead * feat: move dependencies checking to a seperate script * refactor: why have 2 lines when you can have 1 * refactor: remove redundant things * some changes I made that somehow work --------- Co-authored-by: thororen1234 <78185467+thororen1234@users.noreply.github.com> --- package.json | 9 +++++---- scripts/build/common.mjs | 7 ++++--- scripts/depCheck.mjs | 33 +++++++++++++++++++++++++++++++++ 3 files changed, 42 insertions(+), 7 deletions(-) create mode 100644 scripts/depCheck.mjs diff --git a/package.json b/package.json index 8c3219844..a91ed86b8 100644 --- a/package.json +++ b/package.json @@ -14,9 +14,9 @@ "license": "GPL-3.0-or-later", "author": "Equicord", "scripts": { - "build": "node --require=./scripts/suppressExperimentalWarnings.js scripts/build/build.mjs", + "build": "pnpm depCheck && node --require=./scripts/suppressExperimentalWarnings.js scripts/build/build.mjs", "buildStandalone": "pnpm build --standalone", - "buildWeb": "node --require=./scripts/suppressExperimentalWarnings.js scripts/build/buildWeb.mjs", + "buildWeb": "pnpm depCheck && node --require=./scripts/suppressExperimentalWarnings.js scripts/build/buildWeb.mjs", "buildWebStandalone": "pnpm buildWeb --standalone", "buildReporter": "pnpm buildWebStandalone --reporter --skip-extension", "buildReporterDesktop": "pnpm build --reporter", @@ -36,7 +36,8 @@ "lint:fix": "pnpm lint --fix", "test": "pnpm buildStandalone && pnpm testTsc && pnpm lint:fix && pnpm lint-styles && pnpm generatePluginJson", "testWeb": "pnpm lint:fix && pnpm buildWeb && pnpm testTsc", - "testTsc": "tsc --noEmit" + "testTsc": "tsc --noEmit", + "depCheck": "node scripts/depCheck.mjs" }, "dependencies": { "@ffmpeg/ffmpeg": "^0.12.10", @@ -96,7 +97,7 @@ "typescript-transform-paths": "^3.5.5", "zip-local": "^0.3.5" }, - "packageManager": "pnpm@10.32.1", + "packageManager": "pnpm@10.33.0", "pnpm": { "patchedDependencies": { "@types/less@3.0.8": "patches/@types__less@3.0.8.patch" diff --git a/scripts/build/common.mjs b/scripts/build/common.mjs index bcaf77362..8138fc0cf 100644 --- a/scripts/build/common.mjs +++ b/scripts/build/common.mjs @@ -79,11 +79,12 @@ export async function buildOrWatchAll(buildConfigs) { context(cfg).then(ctx => ctx.watch()) )); } else { - await Promise.all(buildConfigs.map(cfg => build(cfg))) - .catch(error => { + for (const cfg of buildConfigs) { + await build(cfg).catch(error => { console.error(error.message); - process.exit(1); // exit immediately to skip the rest of the builds + process.exit(1); }); + } } } diff --git a/scripts/depCheck.mjs b/scripts/depCheck.mjs new file mode 100644 index 000000000..0a333a900 --- /dev/null +++ b/scripts/depCheck.mjs @@ -0,0 +1,33 @@ +/* + * Vencord, a Discord client mod + * Copyright (c) 2026 Vendicated and contributors + * SPDX-License-Identifier: GPL-3.0-or-later + */ + +import { execSync } from "child_process"; +import { existsSync, readFileSync } from "fs"; +import { createInterface } from "readline/promises"; +import { dirname, join } from "path"; +import { fileURLToPath } from "url"; + +const root = join(dirname(fileURLToPath(import.meta.url)), ".."); +const PackageJSON = JSON.parse(readFileSync(join(root, "package.json"), "utf-8")); + +const allDeps = { ...PackageJSON.dependencies, ...PackageJSON.devDependencies }; +const requiredDeps = Object.keys(allDeps); +const missing = requiredDeps.filter(d => { + const v = allDeps[d]; + return !v.startsWith("link:") && !v.startsWith("workspace:") && !existsSync(join(root, "node_modules", d, "package.json")); +}); + +if (missing.length) { + console.error(`\x1b[31mMissing ${missing.length} package(s): ${missing.join(", ")}\x1b[0m`); + const rl = createInterface({ input: process.stdin, output: process.stderr }); + rl.on("SIGINT", () => { rl.close(); process.exit(1); }); + try { + const ans = await rl.question("\x1b[33mRun 'pnpm install'? [Y/n]: \x1b[0m"); + if (!ans || /^y/i.test(ans)) execSync("pnpm install --frozen-lockfile", { cwd: root, stdio: "inherit" }); + } finally { rl.close(); } +} else { + console.log("\x1b[32mAll dependencies are installed.\x1b[0m"); +}