Skip to content

Commit

Permalink
fix(commonjs)!: use safe default value for ignoreTryCatch (#1005)
Browse files Browse the repository at this point in the history
BREAKING CHANGES: changed the default value of ignoreTryCatch to true

fix

fix
  • Loading branch information
benmccann authored Oct 1, 2021
1 parent 540767b commit 6afa82c
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
2 changes: 1 addition & 1 deletion packages/commonjs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ Sometimes you have to leave require statements unconverted. Pass an array contai
### `ignoreTryCatch`

Type: `boolean | 'remove' | string[] | ((id: string) => boolean)`<br>
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.
Expand Down
4 changes: 3 additions & 1 deletion packages/commonjs/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 6afa82c

Please sign in to comment.