plugins
plugins copied to clipboard
fix(commonjs): keep `this` context for callbacks.
Rollup Plugin Name: commonjs
This PR contains:
- [x] bugfix
- [ ] feature
- [ ] refactor
- [ ] documentation
- [ ] other
Are tests included?
- [ ] yes (bugfixes and features will not be merged without tests)
- [x] no
Breaking Changes?
- [ ] yes (breaking changes will not be merged unless absolutely necessary)
- [x] no
If yes, then include "BREAKING CHANGES:" in the first commit message body, followed by a description of what is breaking.
List any relevant issue numbers:
Description
it's not possible to use the commonjs plugin in vitejs, as some callback functions are not called with the original context. edit: As I understand now, rollup already binds the context. but vitejs doesn't.
Looks like you need an upstream update:
git remote add upstream [email protected]:rollup/plugins.git
git fetch upstream
git merge upstream/master
git push
That should get you set so that actions run without errors.
We'll also need a new test that tests this explicit change before we can merge. It's the only way we'll be able to protect against a regression.
@lukastaegert what do you think about this change on the whole, given the info in the other comment thread?
@shellscape I think it is ok. It would be nice to have some kind of test, but this is really difficult as you would basically need to write a mock Rollup context, which in itself would be hard to maintain and likely not worth the effort, so we can go through with this once CI passes.
I think now this should be resolved in vitejs to also bind the functions just like rollup.
I also opened a PR on vitejs. But according to this comment https://github.com/vitejs/vite/pull/14569#pullrequestreview-1670210988 the functions are not bound in rollup. I also did a code search and could not find any .bind for load function. @lukastaegert
By the way, addWatchFile is not bound and access this
.
https://github.com/rollup/rollup/blob/fac5f1c1c12dc0409ff090664e305586747dc2f7/src/utils/PluginContext.ts#L61
Yes, that was indeed overlooked
@patricklx what's the state of this PR at the moment?
it should be ready. I also making a PR to vite as well
@patricklx circling back to this one. looks like linting need to be run locally, prettier isn't happy in CI.
@shellscape fixed prettier