Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ interface RollupConfigInput {
type PluginFactory = (opts: any) => RollupPlugin
type GetPlugin = (name: string) => Promise<PluginFactory>

export function isRollupErrorEvent(e: { code?: string }) {
return e.code === 'ERROR' || e.code === 'FATAL'
}

export class Bundler {
rootDir: string
config: NormalizedConfig
Expand Down Expand Up @@ -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)
}
})
Expand Down
8 changes: 7 additions & 1 deletion test/index.test.ts
Original file line number Diff line number Diff line change
@@ -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)
}
Expand Down