Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(commonjs)!: use safe default value for ignoreTryCatch #1005

Merged
merged 1 commit into from
Oct 1, 2021
Merged
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
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;
tjenkinson marked this conversation as resolved.
Show resolved Hide resolved
: typeof options.ignoreTryCatch !== 'undefined'
? options.ignoreTryCatch
: true;

return {
canConvertRequire: mode !== 'remove' && mode !== true,
Expand Down