fix watch erroring when clean building

This commit is contained in:
Vendicated 2024-07-21 01:29:46 +02:00
parent 8c5217f9f2
commit f9fb3bbba7
No known key found for this signature in database
GPG key ID: D66986BAF75ECF18

View file

@ -261,6 +261,20 @@ export const stylePlugin: Plugin = {
}
};
let buildsFinished = Promise.resolve();
const buildsFinishedPlugin: Plugin = {
name: "builds-finished-plugin",
setup({ onEnd }) {
if (!watch) return;
let resolve: () => void;
const done = new Promise<void>(r => resolve = r);
buildsFinished = buildsFinished.then(() => done);
onEnd(() => resolve());
},
};
export const commonOpts = {
logLevel: "info",
bundle: true,
@ -268,7 +282,7 @@ export const commonOpts = {
sourcemap: watch ? "inline" : "external",
legalComments: "linked",
banner,
plugins: [fileUrlPlugin, gitHashPlugin, gitRemotePlugin, stylePlugin],
plugins: [fileUrlPlugin, gitHashPlugin, gitRemotePlugin, stylePlugin, buildsFinishedPlugin],
external: ["~plugins", "~git-hash", "~git-remote", "/assets/*"],
inject: ["./scripts/build/inject/react.mjs"],
jsxFactory: "VencordCreateElement",
@ -286,6 +300,8 @@ export async function buildOrWatchAll() {
if (watch) {
const contexts = await Promise.all(builds.map(context));
await Promise.all(contexts.map(ctx => ctx.watch()));
await buildsFinished;
} else {
try {
await Promise.all(builds.map(build));