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: correctly ignore optional deps when bundling vite deps #4223

Merged
merged 1 commit into from Jul 12, 2021

Conversation

sodatea
Copy link
Member

@sodatea sodatea commented Jul 12, 2021

Description

Fixes #3977
Fixes #3850

😅 I've accidentally committed the actual fix in 25d86eb#diff-d17472499351c5bf75d44c67aaa203337dcce321fb578ff05302c61b2b2a3a8aR172

So this PR just removes the erroneous ingoreDepPlugin, and moves
the comments to the ignore option of the commonjs plugin.

The cause of the issues is this line: https://github.com/websockets/ws/blob/4c1849a61e773fe0ce016f6eb59bc3877f09aeee/lib/buffer-util.js#L105

When we ignore the optional deps when bundling, we expect
require('bufferutil') to throw an error.

However, with the previous ignoreDepPlugin implementation, the
require expression is turned into:

var bufferutil = {
	__proto__: null
};

var require$$1 = /*@__PURE__*/getAugmentedNamespace(bufferutil);

// ...

const bufferUtil = require$$1;

No error is thrown, so the code executes into the wrong branch.

After the fix, the require expression is left as-is. As bufferutil
is not installed in the user project, the error is thrown as expected.

Additional context


What is the purpose of this pull request?

  • Bug fix
  • New Feature
  • Documentation update
  • Other

Before submitting the PR, please make sure you do the following

  • Read the Contributing Guidelines.
  • Read the Pull Request Guidelines and follow the Commit Convention.
  • Check that there isn't already a PR that solves the problem the same way to avoid creating a duplicate.
  • Provide a description in this PR that addresses what the PR is solving, or reference the issue that it solves (e.g. fixes #123).
  • Ideally, include relevant tests that fail without this PR but pass with it.

Fixes vitejs#3977
Fixes vitejs#3850

😅 I've accidentally committed the actual fix in vitejs@25d86eb#diff-d17472499351c5bf75d44c67aaa203337dcce321fb578ff05302c61b2b2a3a8aR172

So this PR just removes the erroneous `ingoreDepPlugin`, and moves
the comments to the `ignore` option of the commonjs plugin.

The cause of the issues is this line: https://github.com/websockets/ws/blob/4c1849a61e773fe0ce016f6eb59bc3877f09aeee/lib/buffer-util.js#L105

When we ignore the optional deps when bundling, we expect
`require('bufferutil')` to throw an error.

However, with the previous `ignoreDepPlugin` implementation, the
`require` expression is turned into:
```js
var bufferutil = {
	__proto__: null
};

var require$$1 = /*@__PURE__*/getAugmentedNamespace(bufferutil);

// ...
const bufferUtil = require$$1;
```
No error is throwed, so the code executes into the wrong branch.

After the fix, the `require` expression is left as-is. As `bufferutil`
is not installed in the user project, the error is thrown as expected.
@Shinigami92 Shinigami92 added the p3-minor-bug An edge case that only affects very specific usage (priority) label Jul 12, 2021
@patak-dev patak-dev changed the title fix: correctly ignore optional dependencies when bundling vite deps fix: correctly ignore optional deps when bundling vite deps Jul 12, 2021
@patak-dev patak-dev merged commit b5ab77d into vitejs:main Jul 12, 2021
aleclarson pushed a commit to aleclarson/vite that referenced this pull request Nov 8, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
p3-minor-bug An edge case that only affects very specific usage (priority)
Projects
None yet
4 participants