-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Babel Preset Default: Add polyfill for WordPress built from core-js #31279
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
#!/usr/bin/env node | ||
|
||
/** | ||
* External dependencies | ||
*/ | ||
const builder = require( 'core-js-builder' ); | ||
const { minify } = require( 'uglify-js' ); | ||
const { writeFile } = require( 'fs' ).promises; | ||
|
||
builder( { | ||
modules: [ 'es', 'web' ], | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
// core-js is extremely conservative in which polyfills to include. | ||
// Knowing about tiny browser implementation bugs that anyone rarely cares about, | ||
// we prevent some features from having the full polyfill included. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't really understand the comment. What does core-js being conservative have to do with use excluding more things? And what tiny browser implementation bugs? To me the latter makes it sound like it reimplements everything? |
||
// @see https://github.com/WordPress/gutenberg/pull/31279 | ||
exclude: [ 'es.promise' ], | ||
gziolo marked this conversation as resolved.
Show resolved
Hide resolved
|
||
targets: require( '@wordpress/browserslist-config' ), | ||
gziolo marked this conversation as resolved.
Show resolved
Hide resolved
|
||
filename: './build/polyfill.js', | ||
} ) | ||
.then( async ( code ) => { | ||
const output = minify( code, { | ||
output: { | ||
comments: ( node, comment ) => | ||
comment.value.indexOf( 'License' ) >= 0, | ||
}, | ||
} ); | ||
await writeFile( './build/polyfill.min.js', output.code ); | ||
} ) | ||
.catch( ( error ) => { | ||
// eslint-disable-next-line no-console | ||
console.log( error ); | ||
process.exit( 1 ); | ||
} ); |
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.
@gziolo: As much as I love shebangs, AFAIK they just don't work well or at all with Windows. This just emerged in #32329. I'm wondering if we should/could forbid it with our linter — wdyt?
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 copied it over from other scripts. What would be the alternative? If it causes issues we should teach ESLint to prevent issues.
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.
The alternative would be to just not have any shebang, meaning that scripts would just have code:
This would make it impossible for anyone in a UNIX system to invoke
./index.js
(they would have to explicitly call the interpreter withnode index.js
), thus eliminating the possibility of merging something that would break in Windows.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.
Sounds good, we can live with it 👍🏻
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.
Filed: #32504.