no need for this to be async

pull/15950/head
Rich Harris 4 months ago
parent 9b1b9417ae
commit f44c96edaf

@ -11,12 +11,7 @@ const [, , watch_flag] = process.argv;
const watch = watch_flag === '-w'; const watch = watch_flag === '-w';
/** function run() {
* @type {((value?: any) => void) | undefined}
*/
let resolve_writing_promise;
async function run() {
/** @type {Record<string, Record<string, { messages: string[], details: string | null }>>} */ /** @type {Record<string, Record<string, { messages: string[], details: string | null }>>} */
const messages = {}; const messages = {};
const seen = new Set(); const seen = new Set();
@ -67,18 +62,10 @@ async function run() {
sorted.sort((a, b) => (a.code < b.code ? -1 : 1)); sorted.sort((a, b) => (a.code < b.code ? -1 : 1));
const writing_promise = watch
? new Promise((resolve) => {
resolve_writing_promise = resolve;
})
: Promise.resolve();
fs.writeFileSync( fs.writeFileSync(
`messages/${category}/${file}`, `messages/${category}/${file}`,
sorted.map((x) => x._.trim()).join('\n\n') + '\n' sorted.map((x) => x._.trim()).join('\n\n') + '\n'
); );
await writing_promise;
} }
fs.writeFileSync( fs.writeFileSync(
@ -435,15 +422,10 @@ async function run() {
if (watch) { if (watch) {
fs.watch('messages', { recursive: true }, () => { fs.watch('messages', { recursive: true }, () => {
if (resolve_writing_promise) {
resolve_writing_promise();
resolve_writing_promise = undefined;
return;
}
// eslint-disable-next-line no-console // eslint-disable-next-line no-console
console.log('Regenerating messages...'); console.log('Regenerating messages...');
run(); run();
}); });
} }
await run(); run();

Loading…
Cancel
Save