From e2e7e4489fc4ae6fec1f88c5920029be5f8b2df9 Mon Sep 17 00:00:00 2001 From: 2ws2khc2zh-rgb <292810318+2ws2khc2zh-rgb@users.noreply.github.com> Date: Thu, 11 Jun 2026 23:59:50 +0800 Subject: [PATCH] Handle Rollup fatal watch events --- src/index.ts | 6 +++++- test/index.test.ts | 8 +++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/index.ts b/src/index.ts index 2121a089..fc2faa0d 100644 --- a/src/index.ts +++ b/src/index.ts @@ -62,6 +62,10 @@ interface RollupConfigInput { type PluginFactory = (opts: any) => RollupPlugin type GetPlugin = (name: string) => Promise +export function isRollupErrorEvent(e: { code?: string }) { + return e.code === 'ERROR' || e.code === 'FATAL' +} + export class Bundler { rootDir: string config: NormalizedConfig @@ -629,7 +633,7 @@ export class Bundler { ) const watcher = watch(configs) watcher.on('event', (e) => { - if (e.code === 'ERROR') { + if (isRollupErrorEvent(e)) { logger.error(e.error.message) } }) diff --git a/test/index.test.ts b/test/index.test.ts index 1e281a15..dc7315e7 100644 --- a/test/index.test.ts +++ b/test/index.test.ts @@ -1,8 +1,14 @@ import path from 'path' -import { Bundler, Config, Options } from '../src' +import { Bundler, Config, Options, isRollupErrorEvent } from '../src' process.env.BABEL_ENV = 'anything-not-test' +test('detects rollup watch error events', () => { + expect(isRollupErrorEvent({ code: 'ERROR' })).toBe(true) + expect(isRollupErrorEvent({ code: 'FATAL' })).toBe(true) + expect(isRollupErrorEvent({ code: 'BUNDLE_END' })).toBe(false) +}) + function fixture(...args: string[]) { return path.join(__dirname, 'fixtures', ...args) }