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
convert to es6 modules #2108
base: master
Are you sure you want to change the base?
convert to es6 modules #2108
Conversation
ba6faeb
to
132523a
Compare
are you still working on that? looks like it probably needs a rebase :-) |
Another reason why having ES modules would be great: having option to opt-in for global namespace pollution (see #2362) |
If anyone is interested in ES Modules implementation of current codebase, I’ve done it in my fork: https://github.com/niksy/modernizr-esm There are still tests to be modified and written! @patrickkettner @rejas let me know if this looks good to you! |
hi @niksy to be honest I didnt look at that or have given much thought baout converting to ES6. Mainly due to even @patrickkettner not showing up anymore from all the maintainers. I would love to get some PRs reviewed and maybe even a new version out but with so much stuff in the testing pipeline broken right now which I have no clue to fix (bnor any help), this is too much for me to worry about. Maybe someone of the original maintainers shows up. |
@rejas yeah, I completely understand. It’s unfortunate that Modernizr is now in this state, but we do what we can do. If you go with "modernizr-next", I would gladly switch dependancy to the fork and maintain ESM version of new features! |
So I just published https://www.npmjs.com/package/modernizr-next if you want to check it out @niksy |
132523a
to
52eb255
Compare
@rejas took ~3.5 years, but here is a esm rewrite I also rebuilt the site from the ground up, it can go live once this gets published. thank you for all of your work. |
f8932c4
to
5ec88fa
Compare
@patrickkettner anything particularly you found different in the approach I used in https://github.com/niksy/modernizr-esm? |
5ec88fa
to
a75f273
Compare
hi @niksy! I made a number of changes, mostly just code cleanups/modularizations. I think the only thing of concern in modernizr-esm was you are calling testRunner on every addTest call, which logarithmically slows down the script every test you add - ex. the full build that is used in the test suite, it was crashing the page |
a75f273
to
67a08a0
Compare
Oh, yeah, I see. It should probably filter only that particular test added with Did you find my approach viable for ESM version of Modernizr? I see that you don’t use named exports for features with multiple tests (e.g. Maybe we can join efforts and I can deprecate my package in favor of this? |
89ab3a4
to
f91e1f1
Compare
oversight, I think. ill have to double check
im more than open to it, but would want @rejas feedback |
8751887
to
5705e85
Compare
abb0244
to
a8d0baa
Compare
Looked at around 300 of the files already :-) What I did notice is that the test pages are not working currently. So when i do "npm run serve-gh-pages" and open http://localhost:8080/test/unit.html -> js errors, doesnt complete like https://modernizr.github.io/Modernizr/test/unit.html does http://localhost:8080/test/integration.html -> no errors but doesnt list all the tests. it counts only 692 while the v3 branch on https://modernizr.github.io/Modernizr/test/integration.html has more than 780.... first glance shows that nested tests lie audio.ogg dont appear |
Hoping to finish my review tomorrow. Nightinight! |
@rejas the unit page is failing because it needs a backend to build the IIFE wrapped versions of the modules. looking into the integration page now |
beh. bad news. a number of detects are failing. take this import Modernizr from '../src/Modernizr.js'
import featureDetectA from '../featureDetectA.js'
Modernizr.addTest('foo', a === 123)
export Modernizr.foo The thing being exported by every feature-detect will be undefined, because addTest is just pushing onto an an array, and won't be triggered until the modernizr-esm repo worked around this by calling testRunner() on every call to addTest(), but this ends up destroying performance for larger builds. I am thinking we will need to wrap the export in some kind of function. When it is invoked, we test if it is being imported and if it is, execute the test and return the value. or something. IDK. Need to figure this one out |
As I mentioned previously, maybe |
@niksy testRunner should only be running each test once anyway. As of now, testRunner hasnt been called, so there is nothing to be cached. having it called while other tests are being instrumented can impact their outcome, so it was trying to be avoided |
Yeah, I was afraid of that :) Maybe every test should be callable function, and that way we can keep consistency with async tests with test listeners? Just throwing ideas :) |
Improved language, clarity, etc. hashtagContinuousImprovement
I haven't had a ton of time to fix this yet, but the first thought has been to modify the rollup function to insert a import f from 'Modernizr/fakeFeatureDetectName.js the idea bring to reduce the number of times testRunner is called to the absolute minimum, without changing the interaction that people expect in modernizr |
@patrickkettner yeah, that seems valid! Maybe insert it just before first |
@@ -74,13 +74,6 @@ To see all available options run: | |||
./bin/modernizr | |||
``` | |||
|
|||
Or to generate everything in 'config-all.json' run this with npm: |
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.
obviously has to be updated :-)
@@ -39,30 +37,23 @@ var yargs = require('yargs') | |||
alias: 'uglify', | |||
describe: 'uglify/minify the output' | |||
}) | |||
.options('s', { |
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 option is gone for good?
@@ -133,16 +124,16 @@ if (argv.o || argv.f) { | |||
// special case around it :[ | |||
if (prop === 'setClasses') { | |||
return 'setClasses'; | |||
} else if (_.isUndefined(obj)) { | |||
throw new Error('invalid key value name - ' + prop); | |||
} else if (typeof obj === 'undefined') { |
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.
isnt (obj === undefined )
enough these days?
feature-detects/ambientlight.js
Outdated
@@ -6,12 +6,17 @@ | |||
"notes": [{ | |||
"name": "W3C Spec", | |||
"href": "https://www.w3.org/TR/ambient-light/" | |||
}] | |||
}], | |||
"caniuse": "ambient-light" |
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.
already in there
feature-detects/audio.js
Outdated
@@ -4,6 +4,7 @@ | |||
"property": "audio", | |||
"caniuse": "audio", | |||
"tags": ["html5", "audio", "media"], | |||
"caniuse": "audio", |
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.
already in there
Modernizr.addTest('textdecoder', result.textdecoder); | ||
|
||
|
||
export let textencoder = Modernizr.textencoder |
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.
why is here an export let ? why is that special?
@@ -13,15 +13,20 @@ | |||
} | |||
!*/ | |||
/* DOC | |||
Detects support for the `window.postMessage` protocol for cross-document messaging. | |||
Detects support for the `self.postMessage` protocol for cross-document messaging. |
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.
self?
"mq", | ||
"prefixed", | ||
"prefixes", | ||
"prefixedCSS", | ||
"setClasses", |
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.
why is that gone?
and could you document those changes (in the options) in the README too?
// Everyone supports fontSize | ||
expect(testProps(['fontSize'])).to.be.equal(true); |
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.
you dont like the "be"s?
@@ -1,338 +1,339 @@ | |||
define(['isSVG'], function(isSVG) { |
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.
that would be a thing: an update to html5shiv for es6 :-)
Sounds like a plan. Finished my review of the patch :-) Mostly documentation issues I'd say |
What is the plan for handling the requested changes here? (In this herculean effort that predates the Trump administration, including the election itself… :D) |
I've created a gist that adds the Avif that I introduced in #2539 so I can alleviate a little bit of the work Anything else I can work on just ping me 😄 |
@patrickkettner @rejas where are we with this? What can we do to continue with this effort? |
hi @niksy yeah, somebody needs to pick up the PR if @patrickkettner doesnt respond or doesnt find the time. Unfortunalty I dont have the time these days for such work myself so any help is appreciated.... |
Maybe we merge the PR into a v4 branch so it is possible to work on it @rejas ? |
Merging it in an unfinished state into the v4 branch I think is not good. Because what happens when the second maintainer also doesnt have time anymore? Then we have a stale branch that needs to be cleaned up again. And sicne it has merge conflicts anyway, it needs to be forked by whoever wants to work on it anway before we can merge it into any official branch. |
Thanks a lot for your afford so far! But 450 changes files is not an easy branch, hope you get it merged, the longer it stays like this, the harder it will be. If someone else stumbled upon this issue and read so far, there is also https://github.com/niksy/modernizr-esm to try out. |
TODO BEFORE MERGE
require('modernizr/emoji')