From 84b2331b21ff6ceb4a68e72d00e75fe2e3aac0f7 Mon Sep 17 00:00:00 2001 From: Reaper Gelera Date: Sun, 3 Dec 2023 12:22:28 +0530 Subject: [PATCH] chore: atomic build script move errors and completion steps to each phase's own hooks --- build.js | 35 ++++++++++++++++++++--------------- 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/build.js b/build.js index e16f745..6aa1974 100644 --- a/build.js +++ b/build.js @@ -34,16 +34,33 @@ buildContext.add('cjs', { }) buildContext.hook('esm:complete', async () => { + await writeFile( + './dist/esm/package.json', + JSON.stringify({ type: 'module' }), + 'utf8' + ) + process.stdout.write('[custom-builder] ESM Built\n') }) buildContext.hook('cjs:complete', async () => { + await writeFile( + './dist/cjs/package.json', + JSON.stringify({ type: 'commonjs' }), + 'utf8' + ) + process.stdout.write('[custom-builder] CJS Built\n') }) +buildContext.hook('esm:error', async errors => { + process.stdout.write('[custom-builder] ESM Error:\n') + errors.map(x => console.error(x)) +}) + buildContext.hook('cjs:error', async errors => { process.stdout.write('[custom-builder] CJS Error:\n') - console.error(errors) + errors.map(x => console.error(x)) }) buildContext.hook('error', async error => { @@ -51,20 +68,6 @@ buildContext.hook('error', async error => { }) buildContext.hook('complete', async () => { - process.stdout.write('[custom-builder] Built\n') - - await writeFile( - './dist/cjs/package.json', - JSON.stringify({ type: 'commonjs' }), - 'utf8' - ) - - await writeFile( - './dist/esm/package.json', - JSON.stringify({ type: 'module' }), - 'utf8' - ) - tsc.build({ basePath: process.cwd(), compilerOptions: { @@ -81,6 +84,8 @@ buildContext.hook('complete', async () => { exclude: ['**/*.test.ts', '**/*.spec.ts'], }) + process.stdout.write('[custom-builder] Done\n') + if (isDev) return process.exit(0)