From ffd9a0678056c3f6d528811a115fd63ba3cc2fb4 Mon Sep 17 00:00:00 2001 From: lingbopro Date: Sun, 22 Dec 2024 12:03:08 +0800 Subject: [PATCH] chore: convert some operations in the build script to asynchronous --- dev/scripts/lib/build.mjs | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/dev/scripts/lib/build.mjs b/dev/scripts/lib/build.mjs index 966f6ce..d6e1aae 100644 --- a/dev/scripts/lib/build.mjs +++ b/dev/scripts/lib/build.mjs @@ -43,15 +43,24 @@ export async function main(options) { ); log('compiling TypeScript...'); // This may not seem like standard usage, but it can at least reduce the waiting time by 3s - child_process.spawnSync( + const tscProcess = child_process.spawn( 'node', [path.join(root, 'node_modules', 'typescript', 'lib', 'tsc.js')], { cwd: root }, ); + await new Promise((resolve) => tscProcess.once('exit', resolve)); logSuccess('success compiled TypeScript'); log('generating bundles...'); - const globedFiles = fs.globSync( - path.resolve(root, '.__compile_cache__', '**', '*.js'), + const globedFiles = await new Promise((resolve) => + fs.glob( + path.resolve(root, '.__compile_cache__', '**', '*.js'), + (err, matches) => { + if (err) { + throw err; + } + resolve(matches); + }, + ), ); debug({ globedFiles }); const generateBundlesResult = await rollup({