-
Notifications
You must be signed in to change notification settings - Fork 20.5k
Core: Move the factory to separate exports #5293
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
Merged
Merged
Conversation
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
Member
Author
|
Since the main builds no longer include the factory code in the wrapper, there's a small size reduction - bigger for ESM builds: |
2 tasks
f7f27e2 to
e9da84e
Compare
eb81726 to
3e6453c
Compare
Since versions 1.11.0/2.1.0, jQuery has used a module wrapper with one strange addition - in CommonJS environments, if a global `window` with a `document` was not present, jQuery exported a factory accepting a `window` implementation and returning jQuery. This approach created a number of problems: 1. Properly typing jQuery would be a nightmare as the exported value depends on the environment. In practice, typing definitions ignored the factory case. 2. Since we now use named exports for the jQuery module version, it felt weird to have `jQuery` and `$` pointing to the factory instead of real jQuery. Instead, for jQuery 4.0 we leverage the just added `exports` field in `package.json` to expose completely separate factory entry points: one for the full build, one for the slim one. Exports definitions for `./factory` & `./factory-slim` are simpler than for `.` and `./slim` - this is because it's a new entry point, we only expose a named export and so there's no issue with just pointing Node.js to the CommonJS version (we cannot use the module version for `import` from Node.js to avoid double package hazard). The factory entry points are also not meant for the Web browser which always has a proper `window` - and they'd be unfit for an inclusion in a regular script tag anyway. Because of that, we also don't generate minified versions of these entry points. The factory files are not pushed to the CDN since they are mostly aimed at Node.js.
3e6453c to
5911250
Compare
mgol
commented
Sep 18, 2023
mgol
commented
Sep 18, 2023
timmywil
reviewed
Sep 19, 2023
timmywil
reviewed
Sep 19, 2023
Member
Author
|
@timmywil PR updated |
timmywil
requested changes
Sep 19, 2023
Member
timmywil
left a comment
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.
See my comment on eslint config.
Member
Author
|
PR updated |
timmywil
approved these changes
Sep 19, 2023
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
Summary
Since versions 1.11.0/2.1.0, jQuery has used a module wrapper with one strange
addition - in CommonJS environments, if a global
windowwith adocumentwasnot present, jQuery exported a factory accepting a
windowimplementation andreturning jQuery.
This approach created a number of problems:
the environment. In practice, typing definitions ignored the factory case.
to have
jQueryand$pointing to the factory instead of real jQuery.Instead, for jQuery 4.0 we leverage the just added
exportsfield inpackage.jsonto expose completely separate factory entry points: one for thefull build, one for the slim one.
Exports definitions for
./factory&./factory-slimare simpler than for.and
./slim- this is because it's a new entry point, we only expose a namedexport and so there's no issue with just pointing Node.js to the CommonJS
version (we cannot use the module version for
importfrom Node.js to avoiddouble package hazard). The factory entry points are also not meant for the Web
browser which always has a proper
window- and they'd be unfit for aninclusion in a regular script tag anyway. Because of that, we also don't
generate minified versions of these entry points.
The factory files are not pushed to the CDN since they are mostly aimed
at Node.js.
Checklist
If needed, a docs issue/PR was created at https://github.com/jquery/api.jquery.com