From 6afa82c186be4e8cd7177115fdadc18355b0cbc5 Mon Sep 17 00:00:00 2001 From: Ben McCann <322311+benmccann@users.noreply.github.com> Date: Fri, 1 Oct 2021 10:13:18 -0700 Subject: [PATCH] fix(commonjs)!: use safe default value for ignoreTryCatch (#1005) BREAKING CHANGES: changed the default value of ignoreTryCatch to true fix fix --- packages/commonjs/README.md | 2 +- packages/commonjs/src/index.js | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/commonjs/README.md b/packages/commonjs/README.md index 31b1f1e6d..c52fe1be2 100644 --- a/packages/commonjs/README.md +++ b/packages/commonjs/README.md @@ -123,7 +123,7 @@ Sometimes you have to leave require statements unconverted. Pass an array contai ### `ignoreTryCatch` Type: `boolean | 'remove' | string[] | ((id: string) => boolean)`
-Default: `false` +Default: `true` In most cases, where `require` calls are inside a `try-catch` clause, they should be left unconverted as it requires an optional dependency that may or may not be installed beside the rolled up package. Due to the conversion of `require` to a static `import` - the call is hoisted to the top of the file, outside of the `try-catch` clause. diff --git a/packages/commonjs/src/index.js b/packages/commonjs/src/index.js index 09925de34..ef3976f3b 100644 --- a/packages/commonjs/src/index.js +++ b/packages/commonjs/src/index.js @@ -88,7 +88,9 @@ export default function commonjs(options = {}) { ? options.ignoreTryCatch(id) : Array.isArray(options.ignoreTryCatch) ? options.ignoreTryCatch.includes(id) - : options.ignoreTryCatch || false; + : typeof options.ignoreTryCatch !== 'undefined' + ? options.ignoreTryCatch + : true; return { canConvertRequire: mode !== 'remove' && mode !== true,