fix edge case when ~/package.json exists with type: module

This commit is contained in:
Vendicated 2025-02-12 13:16:46 +01:00
parent 670c62267e
commit d39c54b3ee
No known key found for this signature in database
GPG key ID: D66986BAF75ECF18

View file

@ -5,7 +5,7 @@
*/
import { mkdirSync } from "fs";
import { access, constants as FsConstants } from "fs/promises";
import { access, constants as FsConstants, writeFile } from "fs/promises";
import { join } from "path";
import { USER_AGENT, VENCORD_FILES_DIR } from "../constants";
@ -63,7 +63,8 @@ const existsAsync = (path: string) =>
.catch(() => false);
export async function isValidVencordInstall(dir: string) {
return Promise.all(FILES_TO_DOWNLOAD.map(f => existsAsync(join(dir, f)))).then(arr => !arr.includes(false));
const results = await Promise.all(["package.json", ...FILES_TO_DOWNLOAD].map(f => existsAsync(join(dir, f))));
return results.every(Boolean);
}
export async function ensureVencordFiles() {
@ -71,5 +72,5 @@ export async function ensureVencordFiles() {
mkdirSync(VENCORD_FILES_DIR, { recursive: true });
await downloadVencordFiles();
await Promise.all([downloadVencordFiles(), writeFile(join(VENCORD_FILES_DIR, "package.json"), "{}")]);
}