Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Core: Migrate from AMD to ES modules 🎉#4541

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
mgol merged 20 commits intojquery:masterfrommgol:es-modules
Nov 18, 2019
Merged

Conversation

mgol
Copy link
Member

@mgolmgol commentedNov 14, 2019
edited by timmywil
Loading

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:

  • Add AMD compilation toamd/
  • (optional) Add back AMD mode to QUnit

Checklist

jbedard reacted with thumbs up emojiavindra, yousan, eknis, sfc-gh-kbregula, and ecoms-ye reacted with heart emoji
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:```jsexport default jQuery.fn.delay;```was being cut out by Rollup as it was unused but due to the possibility ofthe `jQuery.fn.delay` access having side effects (e.g. via getters) it leftthe following line in:```jsjQuery.fn.delay;```This fails our ESLint setup and takes unnecessary space so this commit removesthe export.
Test files themselves are still loaded via RequireJS as that has to work inIE 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".
@mgol
Copy link
MemberAuthor

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./core/parseHTML.js import tojquery.js, without it it added 36 bytes to minified (non-gzipped) and actually reduced (!) the minified gzipped build by 10 bytes. This is only a result of re-shuffling the final file, apparently Uglify was compiling the previous one better.

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.

@mgol
Copy link
MemberAuthor

OK, apparently we can go back to -10 bytes minified gzipped (& minimal unminified diff from the current Git compilation) if we move the./core/parseHTML.js from directly after the./core.js import to just before the./ajax/load.js one.

Copy link
Member

@gibson042gibson042 left a comment
edited
Loading

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

This is so beautiful! 😍

@mgolmgol changed the titleCore: Migrate to ES modulesCore: Migrate from AMD to ES modules 🎉Nov 18, 2019
@mgolmgol merged commitd0ce00c intojquery:masterNov 18, 2019
@mgolmgol deleted the es-modules branchNovember 18, 2019 20:15
mgol added a commit to mgol/jquery that referenced this pull requestNov 20, 2019
jQuery source is now authored in ECMAScript modules. Native browser support forthem requires full file names including extensions. Rollup works even if importpaths don't specify extensions, though, so one import slipped through withoutsuch an extension, breaking native browser import of src/jquery.js.A new ESLint rule using eslint-plugin-import prevents us from regressing on thatfront.Refjquerygh-4541Ref0753201
mgol added a commit that referenced this pull requestNov 25, 2019
jQuery source is now authored in ECMAScript modules. Native browser supportfor them requires full file names including extensions. Rollup works evenif import paths don't specify extensions, though, so one import slippedthrough without such an extension, breaking native browser import ofsrc/jquery.js.A new ESLint rule using eslint-plugin-import prevents us from regressingon that front.Also, eslint-plugin-import's no-cycle rule is used to avoid import cycles.Closesgh-4544Refgh-4541Ref0753201
mgol added a commit to mgol/jquery that referenced this pull requestNov 27, 2019
jQuery source has been migrated injquerygh-4541 from AMD to ES modules. To maintainsupport for consumers of our AMD modules, this commits adds a task transpilingthe ES modules sources in `src/` to AMD in `amd/`.
mgol added a commit to mgol/jquery that referenced this pull requestNov 27, 2019
jQuery source has been migrated injquerygh-4541 from AMD to ES modules. To maintainsupport for consumers of our AMD modules, this commits adds a task transpilingthe ES modules sources in `src/` to AMD in `amd/`.
mgol added a commit to mgol/jquery that referenced this pull requestNov 27, 2019
jQuery source has been migrated injquerygh-4541 from AMD to ES modules. To maintainsupport for consumers of our AMD modules, this commits adds a task transpilingthe ES modules sources in `src/` to AMD in `amd/`.
mgol added a commit to mgol/jquery that referenced this pull requestNov 30, 2019
jQuery source has been migrated injquerygh-4541 from AMD to ES modules. To maintainsupport for consumers of our AMD modules, this commits adds a task transpilingthe ES modules sources in `src/` to AMD in `amd/`.
mgol added a commit to mgol/jquery that referenced this pull requestNov 30, 2019
jQuery source has been migrated injquerygh-4541 from AMD to ES modules. To maintainsupport for consumers of our AMD modules, this commits adds a task transpilingthe ES modules sources in `src/` to AMD in `amd/`.
mgol added a commit to mgol/jquery that referenced this pull requestNov 30, 2019
jQuery source has been migrated injquerygh-4541 from AMD to ES modules. To maintainsupport for consumers of our AMD modules, this commits adds a task transpilingthe 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 similarno-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).
@mgolmgol mentioned this pull requestNov 30, 2019
2 tasks
mgol added a commit to mgol/jquery that referenced this pull requestNov 30, 2019
jQuery source has been migrated injquerygh-4541 from AMD to ES modules. To maintainsupport for consumers of our AMD modules, this commits adds a task transpilingthe 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 similarno-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).
mgol added a commit to mgol/jquery that referenced this pull requestNov 30, 2019
jQuery source has been migrated injquerygh-4541 from AMD to ES modules. To maintainsupport for consumers of our AMD modules, this commits adds a task transpilingthe 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 similarno-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).
mgol added a commit to mgol/jquery that referenced this pull requestNov 30, 2019
jQuery source has been migrated injquerygh-4541 from AMD to ES modules. To maintainsupport for consumers of our AMD modules, this commits adds a task transpilingthe 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 similarno-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).
mgol added a commit to mgol/jquery that referenced this pull requestDec 2, 2019
jQuery source has been migrated injquerygh-4541 from AMD to ES modules. To maintainsupport for consumers of our AMD modules, this commits adds a task transpilingthe 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 similarno-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).
mgol added a commit that referenced this pull requestDec 9, 2019
jQuery source has been migrated ingh-4541 from AMD to ES modules. To maintainsupport for consumers of our AMD modules, this commits adds a task transpilingthe 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 similarno-compile experience during jQuery 4.x testing, use the new "Load as modules"checkbox which works in all supported browsers except for IE & Edge (thelegacy, EdgeHTML-based one).Refgh-4541Closesgh-4554
mgol added a commit to mgol/jquery that referenced this pull requestFeb 24, 2020
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 primitivevariable. This had to be changed on `master` as in ES modules you exportlive read-only bindings to variables, meaning you can't increment the noncedirectly. Also, the way it was done so far was working differently in AMD & thesingle built file - in the built file one nonce variable was declared, accessedand incremented. In AMD mode separate instances were create for each modulethat depend on the nonce module, creating unintended nonce clashes.2. Whether the `noGlobal` parameter was set to `true` is now checked using thetypeof operator to align with `master`.Refjquerygh-4541Refd0ce00c
mgol added a commit that referenced this pull requestFeb 24, 2020
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 primitivevariable. This had to be changed on `master` as in ES modules you exportlive read-only bindings to variables, meaning you can't increment the noncedirectly. Also, the way it was done so far was working differently in AMD & thesingle built file - in the built file one nonce variable was declared, accessedand incremented. In AMD mode separate instances were create for each modulethat depend on the nonce module, creating unintended nonce clashes.2. Whether the `noGlobal` parameter was set to `true` is now checked using thetypeof operator to align with `master`.Closesgh-4612Refgh-4541Refd0ce00c
@rart
Copy link

rart commentedApr 3, 2020

@mgol when will this effort be published to npm?

@mgol
Copy link
MemberAuthor

mgol commentedApr 3, 2020

@rart This is planned for jQuery 4.0.0 which will take at least several more months. Migrating this to the3.x-stable line while preserving backwards compatibility of the package structure might require non-trivial amount of work so at the moment we don't have plans to do it.

rart and mackieee reacted with thumbs up emoji

@rart
Copy link

rart commentedApr 4, 2020
edited
Loading

@mgol thanks for the quick reply.

Have you guys considered an4.0.0.rc sort of release/publish? (alpha, beta, rc)

@mgol
Copy link
MemberAuthor

mgol commentedApr 4, 2020

@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 frommaster, you can always copy oursrc directory. Just remember it's not stable so you'll need to be careful with upgrades.

rart and mackieee reacted with thumbs up emoji

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@gibson042gibson042gibson042 approved these changes

@timmywiltimmywilAwaiting requested review from timmywil

Assignees
No one assigned
Milestone
4.0.0
Development

Successfully merging this pull request may close these issues.

4 participants
@mgol@rart@timmywil@gibson042

[8]ページ先頭

©2009-2025 Movatter.jp