From 03f414ad6c4c8264e97116c18608f1f48df0adc4 Mon Sep 17 00:00:00 2001 From: "Christopher J. Brody" Date: Sat, 21 Jan 2023 21:24:00 -0500 Subject: [PATCH] fix: throw internal error in case of Terser error Improvement with better error handling was proposed in: - brodybits/rollup-plugin-size-snapshot#17 but a reproduction is needed to add a test case, see - https://github.com/brodybits/rollup-plugin-size-snapshot/issues/19 --- src/index.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/index.js b/src/index.js index 96d16c3..f74a775 100644 --- a/src/index.js +++ b/src/index.js @@ -77,7 +77,17 @@ export const sizeSnapshot = (options?: Options = {}): Plugin => { const outputName = chunk.fileName; + // Improvement with better error handling was proposed in + // brodybits/rollup-plugin-size-snapshot#17 + // but a reproduction is needed to add a test case, see + // https://github.com/brodybits/rollup-plugin-size-snapshot/issues/19 const minified = minify(source).code; + if (!minified) { + throw new Error( + "INTERNAL ERROR - terser error - see https://github.com/brodybits/rollup-plugin-size-snapshot/issues/19" + ); + } + const treeshakeSize = (code) => Promise.all([treeshakeWithRollup(code), treeshakeWithWebpack(code)]);