-
-
Notifications
You must be signed in to change notification settings - Fork 592
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): keep this
context for callbacks.
#1603
Conversation
@@ -108,7 +108,7 @@ export function getRequireResolver(extensions, detectCyclesAndConditional, curre | |||
setInitialParentType(parentId, parentMeta.initialCommonJSType); | |||
await Promise.all( | |||
parentRequires.map(({ resolved, isConditional }) => | |||
analyzeRequiredModule(parentId, resolved, isConditional, this.load) | |||
analyzeRequiredModule(parentId, resolved, isConditional, this.load.bind(this)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fair enough, but Rollup already this-binds all context functions. This is by design, but admittedly, this is not well-communicated.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah, okay. this issue appeared while using commonjs plugin with vitejs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting. So I assume this happened in dev mode? Then this would mean that Vite does not this.bind. Maybe an issue to raise with Vite. But this would also make it harder to write a test as you would need to test with a fake plugin context.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, Andrew will not like that you skipped the PR template where you should have added all this information.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think so too ^^ 😅
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added it now
Looks like you need an upstream update:
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. |
I think now this should be resolved in vitejs to also bind the functions just like rollup. |
I also opened a PR on vitejs. |
By the way, addWatchFile is not bound and access |
Yes, that was indeed overlooked |
a69c299
to
a9b9cd3
Compare
@patricklx what's the state of this PR at the moment? |
it should be ready. I also making a PR to vite as well |
this
context for callbacks
@patricklx circling back to this one. looks like linting need to be run locally, prettier isn't happy in CI. |
@shellscape fixed prettier |
this
context for callbacksthis
context for callbacks.
@patricklx thanks for fixing the last issue. it looks like your changes are good to go, but we require tests for fixes and features to protect against regressions. would you be able to add a test for these changes? |
Closing as abandoned. |
Rollup Plugin Name:
commonjs
This PR contains:
Are tests included?
Breaking Changes?
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.