-
Notifications
You must be signed in to change notification settings - Fork 3.3k
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
[Pthreads] Fix worker.js in ES6 module environments #21041
Merged
Merged
Changes from 5 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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'm confused about
ENVIRONMENT_MAY_BE_WEB
.. surelyrequire
never works on the web does it?Where does worker.js use other than below in the
ENVIRONMENT_MAY_BE_NODE
block?It we only use require for those two lines below maybe we should replace them with dyanmic imports?
e.g.:
#if EXPORT_ES6
var fs = await import('fs');
var vm = await import('vm');
#else
var fs = require('fs');
var vm = require('vm');
#endif
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.
Yeah in the main JS
ENVIRONMENT_MAY_BE_WEB
is only used because there are static imports for when we know that environment is Node.js and no other.In this case there are no static imports to fall back to, so it should either add them or just use
await import
like you suggested.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.
Yeah, it's confusing. The comment this refers to explains more:
emscripten/src/shell.js
Lines 193 to 196 in 7a14e5b
My understanding of the lines is that in a pure node build we don't emit this anyhow. But in a mixed build we can't do that, and so if we build for node or web but end up running in node, then we get to this location, and need something to put here (since we couldn't put the static thing for a pure node build).
(This is all separate from this PR, of course, as it's preexisting.)
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.
It turns out I was wrong, this is not separable. This PR was enough to fix the case of using a
package.json
file to force ES6 module format, but without such a file node.js uses the suffix to decide what to run. And this PR addsawait import
, which errors in a non-ES6 module.To fix that the PR now emits
.worker.mjs
whenEXPORT_ES6
. That is a breaking change unfortunately, which may break all users that copy files to a production environment that usepthreads+EXPORT_ES6
, but I don't see a way around it? Hopefully not many are usingEXPORT_ES6
, and probably few are because of issues like this, actually...Thoughts?
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 if you use
EXPORT_ES6
when it makes sense to create worker.mjs. I don't think think its a huge deal that we change this now. Maybe just mention it in the changelog.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.
Agreed, yeah, already added to the changelog.
If this breaking change sgty then let me know if you have any other feedback on the PR, otherwise I think it is done.