-
Notifications
You must be signed in to change notification settings - Fork 20.6k
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
Core: Migrate from AMD to ES modules 🎉 #4541
Conversation
ES modules bindings are immutable and we relied on the `ajax/var/nonce.js` variable being mutable. Workaround it by creating a wrapper object. We might try to compress it somehow in the future.
The export: ```js export default jQuery.fn.delay; ``` was being cut out by Rollup as it was unused but due to the possibility of the `jQuery.fn.delay` access having side effects (e.g. via getters) it left the following line in: ```js jQuery.fn.delay; ``` This fails our ESLint setup and takes unnecessary space so this commit removes the export.
Test files themselves are still loaded via RequireJS as that has to work in IE 11.
…work) Custom compilations (excluding/including some modules) is not supported yet.
When custom compilation is used, the version string can get large.
This is necessary so that excluding some non-core modules doesn't exclude "core/parseHTML.js".
This PR now adds 89 bytes to the minified (non-gzipped) build & 5 bytes to the minified gzipped build. The gzipped difference mostly comes from the addition of the I'm OK with such a delta given the gains from using the modern module format & removing our brittle compile process hacks as it's now mostly relying on Rollup but maybe it's possible to optimize it a little. |
OK, apparently we can go back to -10 bytes minified gzipped (& minimal unminified diff from the current Git compilation) if we move the |
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.
This is so beautiful! 😍
jQuery source is now authored in ECMAScript modules. Native browser support for them requires full file names including extensions. Rollup works even if import paths don't specify extensions, though, so one import slipped through without such an extension, breaking native browser import of src/jquery.js. A new ESLint rule using eslint-plugin-import prevents us from regressing on that front. Ref jquerygh-4541 Ref 0753201
jQuery source is now authored in ECMAScript modules. Native browser support for them requires full file names including extensions. Rollup works even if import paths don't specify extensions, though, so one import slipped through without such an extension, breaking native browser import of src/jquery.js. A new ESLint rule using eslint-plugin-import prevents us from regressing on that front. Also, eslint-plugin-import's no-cycle rule is used to avoid import cycles. Closes gh-4544 Ref gh-4541 Ref 0753201
jQuery source has been migrated in jquerygh-4541 from AMD to ES modules. To maintain support for consumers of our AMD modules, this commits adds a task transpiling the ES modules sources in `src/` to AMD in `amd/`.
jQuery source has been migrated in jquerygh-4541 from AMD to ES modules. To maintain support for consumers of our AMD modules, this commits adds a task transpiling the ES modules sources in `src/` to AMD in `amd/`.
jQuery source has been migrated in jquerygh-4541 from AMD to ES modules. To maintain support for consumers of our AMD modules, this commits adds a task transpiling the ES modules sources in `src/` to AMD in `amd/`.
jQuery source has been migrated in jquerygh-4541 from AMD to ES modules. To maintain support for consumers of our AMD modules, this commits adds a task transpiling the ES modules sources in `src/` to AMD in `amd/`.
jQuery source has been migrated in jquerygh-4541 from AMD to ES modules. To maintain support for consumers of our AMD modules, this commits adds a task transpiling the ES modules sources in `src/` to AMD in `amd/`.
jQuery source has been migrated in jquerygh-4541 from AMD to ES modules. To maintain support for consumers of our AMD modules, this commits adds a task transpiling the ES modules sources in `src/` to AMD in `amd/`. A "Load with AMD" checkbox was also restored to the QUnit setup. Note that, contrary to jQuery 3.x, AMD files need to be generated via `grunt amd` or `grunt` as sources are not authored in ECMAScript modules. To achieve a similar no-compile experience during jQuery 4.x testing, use the new "Load as modules" checkbox which works in all supported browsers except for IE & Edge (the legacy, EdgeHTML-based one).
jQuery source has been migrated in jquerygh-4541 from AMD to ES modules. To maintain support for consumers of our AMD modules, this commits adds a task transpiling the ES modules sources in `src/` to AMD in `amd/`. A "Load with AMD" checkbox was also restored to the QUnit setup. Note that, contrary to jQuery 3.x, AMD files need to be generated via `grunt amd` or `grunt` as sources are not authored in ECMAScript modules. To achieve a similar no-compile experience during jQuery 4.x testing, use the new "Load as modules" checkbox which works in all supported browsers except for IE & Edge (the legacy, EdgeHTML-based one).
jQuery source has been migrated in jquerygh-4541 from AMD to ES modules. To maintain support for consumers of our AMD modules, this commits adds a task transpiling the ES modules sources in `src/` to AMD in `amd/`. A "Load with AMD" checkbox was also restored to the QUnit setup. Note that, contrary to jQuery 3.x, AMD files need to be generated via `grunt amd` or `grunt` as sources are not authored in ECMAScript modules. To achieve a similar no-compile experience during jQuery 4.x testing, use the new "Load as modules" checkbox which works in all supported browsers except for IE & Edge (the legacy, EdgeHTML-based one).
jQuery source has been migrated in jquerygh-4541 from AMD to ES modules. To maintain support for consumers of our AMD modules, this commits adds a task transpiling the ES modules sources in `src/` to AMD in `amd/`. A "Load with AMD" checkbox was also restored to the QUnit setup. Note that, contrary to jQuery 3.x, AMD files need to be generated via `grunt amd` or `grunt` as sources are not authored in ECMAScript modules. To achieve a similar no-compile experience during jQuery 4.x testing, use the new "Load as modules" checkbox which works in all supported browsers except for IE & Edge (the legacy, EdgeHTML-based one).
jQuery source has been migrated in jquerygh-4541 from AMD to ES modules. To maintain support for consumers of our AMD modules, this commits adds a task transpiling the ES modules sources in `src/` to AMD in `amd/`. A "Load with AMD" checkbox was also restored to the QUnit setup. Note that, contrary to jQuery 3.x, AMD files need to be generated via `grunt amd` or `grunt` as sources are not authored in ECMAScript modules. To achieve a similar no-compile experience during jQuery 4.x testing, use the new "Load as modules" checkbox which works in all supported browsers except for IE & Edge (the legacy, EdgeHTML-based one).
jQuery source has been migrated in gh-4541 from AMD to ES modules. To maintain support for consumers of our AMD modules, this commits adds a task transpiling the ES modules sources in `src/` to AMD in `amd/`. A "Load with AMD" checkbox was also restored to the QUnit setup. Note that, contrary to jQuery 3.x, AMD files need to be generated via `grunt amd` or `grunt` as sources are not authored in ECMAScript modules. To achieve a similar no-compile experience during jQuery 4.x testing, use the new "Load as modules" checkbox which works in all supported browsers except for IE & Edge (the legacy, EdgeHTML-based one). Ref gh-4541 Closes gh-4554
This commit aligns the `3.x-stable` branch with `master` in two aspects: 1. It migrates the nonce module to return an object instead of a primitive variable. This had to be changed on `master` as in ES modules you export live read-only bindings to variables, meaning you can't increment the nonce directly. Also, the way it was done so far was working differently in AMD & the single built file - in the built file one nonce variable was declared, accessed and incremented. In AMD mode separate instances were create for each module that depend on the nonce module, creating unintended nonce clashes. 2. Whether the `noGlobal` parameter was set to `true` is now checked using the typeof operator to align with `master`. Ref jquerygh-4541 Ref d0ce00c
This commit aligns the `3.x-stable` branch with `master` in two aspects: 1. It migrates the nonce module to return an object instead of a primitive variable. This had to be changed on `master` as in ES modules you export live read-only bindings to variables, meaning you can't increment the nonce directly. Also, the way it was done so far was working differently in AMD & the single built file - in the built file one nonce variable was declared, accessed and incremented. In AMD mode separate instances were create for each module that depend on the nonce module, creating unintended nonce clashes. 2. Whether the `noGlobal` parameter was set to `true` is now checked using the typeof operator to align with `master`. Closes gh-4612 Ref gh-4541 Ref d0ce00c
@mgol when will this effort be published to npm? |
@rart This is planned for jQuery 4.0.0 which will take at least several more months. Migrating this to the |
@mgol thanks for the quick reply. Have you guys considered an |
@rart There is still significant work planned for jQuery 4.0.0 so we don't plan any pre-release soon; it'd be too far from the final release. If you want to use ES modules from |
Summary
Migrate source to ES modules. RequireJS is still used to load tests, this may perhaps be changed in a separate PR.
Reviewing by commit might be the easiest.
@timmywil I'd appreciate especially a review of the build process after my changes as custom compilation works slightly differently now (for example, I had to add an explicit import of
./core/parseHTML.js
tojquery.js
as otherwise excluding AJAX cut out that module as well and a lot depends on it). If you could locally test some scenarios you had in mind when you initially wrote that & make sure they still work, that'd help.TODO:
amd/
Checklist
New tests have been added to show the fix or feature worksIf needed, a docs issue/PR was created at https://github.com/jquery/api.jquery.com