-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Build: Preserve __esModule on window.wp.* IIFE globals for webpack interop
#78699
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
Closed
+8
−3
Closed
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
ef40f3e
Build: Preserve __esModule on window.wp.* IIFE globals for webpack in…
kraftbj 44b6c82
chore: merge trunk into fix-issue-78697
kraftbj 2ac1659
chore: merge trunk into fix-issue-78697
kraftbj be32a3d
Build: Simplify __esModule preservation to a single seeded Object.assign
kraftbj cbca833
docs: shorten __esModule footer comment per review
kraftbj d169d7d
Merge remote-tracking branch 'origin/trunk' into fix-issue-78697
kraftbj 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 hidden or 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 hidden or 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
Oops, something went wrong.
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 think that all we need to do is that instead of
Object.assign({}, ...)we doObject.assign({ __esModule: true }, ...). That covers everything, the patch doesn't need to be that complicated.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.
Good call, that's much cleaner — pre-seeding the target also makes the
writableconcern moot in the common case. One tweak: a plain{ __esModule: true }literal defines the property as enumerable, but esbuild's__toCommonJS(and webpack's own__webpack_require__.r) mark it non-enumerable, so the literal would leak__esModuleintoObject.keys(), spread, and downstreamObject.assign. Keeping it non-enumerable is still a one-liner:`if(${ globalName }&&typeof ${ globalName }==='object'){${ globalName }=Object.assign(Object.defineProperty({},'__esModule',{value:true,writable:true}),${ globalName });}`That drops both the conditional and the two-branch split. I kept
writable: trueas a cheap guard so a future esbuild change emitting an enumerable__esModulewouldn't trip a strict-mode write whenObject.assigncopies it — happy to drop it if you'd rather keep it minimal. Pushed in be32a3d.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.
Yes, it's great that
Object.definePropertyreturns the object 🙂