From f08a7237f9fff154ce48301aa4e4129bd862caff Mon Sep 17 00:00:00 2001 From: Frank Wilkerson Date: Thu, 25 Jan 2018 20:46:36 -0700 Subject: [PATCH 1/4] add the option to emit build events when running microbundle programmatically --- src/index.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/index.js b/src/index.js index a93edc0..968e288 100644 --- a/src/index.js +++ b/src/index.js @@ -99,6 +99,7 @@ export default async function microbundle(options) { } if (options.watch) { + const emitEvents = options.emit; return new Promise( (resolve, reject) => { process.stdout.write(chalk.blue(`Watching source, compiling to ${relative(cwd, dirname(options.output))}:\n`)); steps.map( options => { @@ -109,6 +110,9 @@ export default async function microbundle(options) { if (e.code==='ERROR' || e.code==='FATAL') { return reject(e); } + if (emitEvents) { + process.emit('event', e); + } if (e.code==='END') { getSizeInfo(options._code, options.outputOptions.file).then( text => { process.stdout.write(`Wrote ${text.trim()}\n`); From 31ca55ab720e60543be7e0fcc127f020a6df65a0 Mon Sep 17 00:00:00 2001 From: Frank Wilkerson Date: Thu, 25 Jan 2018 20:55:51 -0700 Subject: [PATCH 2/4] include error events --- src/index.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/index.js b/src/index.js index 968e288..11526e8 100644 --- a/src/index.js +++ b/src/index.js @@ -107,12 +107,12 @@ export default async function microbundle(options) { output: options.outputOptions, watch: WATCH_OPTS }, options.inputOptions)).on('event', e => { - if (e.code==='ERROR' || e.code==='FATAL') { - return reject(e); - } if (emitEvents) { process.emit('event', e); } + if (e.code==='ERROR' || e.code==='FATAL') { + return reject(e); + } if (e.code==='END') { getSizeInfo(options._code, options.outputOptions.file).then( text => { process.stdout.write(`Wrote ${text.trim()}\n`); From 30fdc0592e254ff2bb53b7d28f83e4ca5919602c Mon Sep 17 00:00:00 2001 From: Frank Wilkerson Date: Thu, 25 Jan 2018 22:01:38 -0700 Subject: [PATCH 3/4] consistent naming --- src/index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/index.js b/src/index.js index 11526e8..4e8036a 100644 --- a/src/index.js +++ b/src/index.js @@ -99,7 +99,7 @@ export default async function microbundle(options) { } if (options.watch) { - const emitEvents = options.emit; + const emit = options.emit; return new Promise( (resolve, reject) => { process.stdout.write(chalk.blue(`Watching source, compiling to ${relative(cwd, dirname(options.output))}:\n`)); steps.map( options => { @@ -107,7 +107,7 @@ export default async function microbundle(options) { output: options.outputOptions, watch: WATCH_OPTS }, options.inputOptions)).on('event', e => { - if (emitEvents) { + if (emit) { process.emit('event', e); } if (e.code==='ERROR' || e.code==='FATAL') { From 4ffe9451e97a946980a9bf1fbb070483dc9bf4ce Mon Sep 17 00:00:00 2001 From: Frank Wilkerson Date: Fri, 26 Jan 2018 17:55:55 -0700 Subject: [PATCH 4/4] a more specific api than just emit --- src/index.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/index.js b/src/index.js index 4e8036a..16b519b 100644 --- a/src/index.js +++ b/src/index.js @@ -99,7 +99,7 @@ export default async function microbundle(options) { } if (options.watch) { - const emit = options.emit; + const onBuild = options.onBuild; return new Promise( (resolve, reject) => { process.stdout.write(chalk.blue(`Watching source, compiling to ${relative(cwd, dirname(options.output))}:\n`)); steps.map( options => { @@ -107,9 +107,6 @@ export default async function microbundle(options) { output: options.outputOptions, watch: WATCH_OPTS }, options.inputOptions)).on('event', e => { - if (emit) { - process.emit('event', e); - } if (e.code==='ERROR' || e.code==='FATAL') { return reject(e); } @@ -117,6 +114,9 @@ export default async function microbundle(options) { getSizeInfo(options._code, options.outputOptions.file).then( text => { process.stdout.write(`Wrote ${text.trim()}\n`); }); + if (typeof onBuild=='function') { + onBuild(e); + } } }); });