From 7f00c90c3d89742ea8c610052e86c07f8475e7cf Mon Sep 17 00:00:00 2001 From: John Gozde Date: Sat, 26 Nov 2022 11:43:24 -0700 Subject: [PATCH] Stop esbuild in watch mode --- .../test/fixture/build/pkg-three/build.js | 42 ++++++++++++------- .../test/fixture/compile/build.js | 34 +++++++++------ 2 files changed, 48 insertions(+), 28 deletions(-) diff --git a/packages/esbuild-plugin-typecheck/test/fixture/build/pkg-three/build.js b/packages/esbuild-plugin-typecheck/test/fixture/build/pkg-three/build.js index 345b835..b4e2662 100755 --- a/packages/esbuild-plugin-typecheck/test/fixture/build/pkg-three/build.js +++ b/packages/esbuild-plugin-typecheck/test/fixture/build/pkg-three/build.js @@ -2,20 +2,30 @@ const { typecheckPlugin } = require('../../../lib'); const { build } = require('esbuild'); -const path = require('path'); -build({ - absWorkingDir: __dirname, - entryPoints: ['./three.ts'], - bundle: true, - format: 'esm', - outdir: './dist', - platform: 'node', - plugins: [ - typecheckPlugin({ - buildMode: process.env.BUILD_MODE, - }), - ], - watch: !!process.env.WATCH, - write: false, -}).catch(() => process.exit(1)); +async function main() { + try { + const result = await build({ + absWorkingDir: __dirname, + entryPoints: ['./three.ts'], + bundle: true, + format: 'esm', + outdir: './dist', + platform: 'node', + plugins: [ + typecheckPlugin({ + buildMode: process.env.BUILD_MODE, + }), + ], + watch: !!process.env.WATCH, + write: false, + }); + process.on('SIGTERM', () => { + result.stop(); + }); + } catch (error) { + process.exit(1); + } +} + +main(); diff --git a/packages/esbuild-plugin-typecheck/test/fixture/compile/build.js b/packages/esbuild-plugin-typecheck/test/fixture/compile/build.js index 90b4ede..befd30e 100755 --- a/packages/esbuild-plugin-typecheck/test/fixture/compile/build.js +++ b/packages/esbuild-plugin-typecheck/test/fixture/compile/build.js @@ -2,16 +2,26 @@ const { typecheckPlugin } = require('../../lib'); const { build } = require('esbuild'); -const path = require('path'); -build({ - absWorkingDir: __dirname, - entryPoints: ['./src/index.ts'], - bundle: true, - format: 'esm', - outdir: './dist', - platform: 'node', - plugins: [typecheckPlugin()], - watch: !!process.env.WATCH, - write: false, -}).catch(() => process.exit(1)); +async function main() { + try { + const result = await build({ + absWorkingDir: __dirname, + entryPoints: ['./src/index.ts'], + bundle: true, + format: 'esm', + outdir: './dist', + platform: 'node', + plugins: [typecheckPlugin()], + watch: !!process.env.WATCH, + write: false, + }); + process.on('SIGTERM', () => { + result.stop(); + }); + } catch (error) { + process.exit(1); + } +} + +main();