Skip to content

Commit

Permalink
Clean up changelog, comments and option name
Browse files Browse the repository at this point in the history
  • Loading branch information
sgomes committed Sep 13, 2024
1 parent f571732 commit b1c837d
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 15 deletions.
2 changes: 1 addition & 1 deletion bin/packages/get-babel-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ module.exports = ( environment = '', file ) => {
},
};
// Add `@wordpress/polyfill` import where needed.
callerOpts.caller.addPolyfillImport = true;
callerOpts.caller.addPolyfillComments = true;
switch ( environment ) {
case 'main':
// To be merged as a presetEnv option.
Expand Down
2 changes: 1 addition & 1 deletion packages/babel-preset-default/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

## Unreleased

- Added `addPolyfillImport` option. When used, it will automatically add `@wordpress/polyfill` imports where needed.
- Added `addPolyfillComments` option. When used, it will automatically add magic comments to mark files that need `wp-polyfill`.

## 8.7.0 (2024-09-05)

Expand Down
4 changes: 2 additions & 2 deletions packages/babel-preset-default/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ module.exports = ( api ) => {
'proposal-nullish-coalescing-operator',
'proposal-logical-assignment-operators',
],
...( wpBuildOpts.addPolyfillImport
...( wpBuildOpts.addPolyfillComments
? {
useBuiltIns: 'usage',
exclude: exclusions,
Expand Down Expand Up @@ -95,7 +95,7 @@ module.exports = ( api ) => {
},
],
maybeGetPluginTransformRuntime(),
wpBuildOpts.addPolyfillImport && replacePolyfills,
wpBuildOpts.addPolyfillComments && replacePolyfills,
].filter( Boolean ),
};
};
8 changes: 3 additions & 5 deletions packages/babel-preset-default/replace-polyfills.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// Babel plugin that looks for `core-js` imports (or requires)
// and replaces them with `@wordpress/polyfill`.
// and replaces them magic comments to mark the file as depending
// on wp-polyfill.
function replacePolyfills() {
return {
pre() {
Expand All @@ -10,10 +11,7 @@ function replacePolyfills() {
exit( path ) {
if ( this.hasAddedPolyfills ) {
// Add magic comment to top of file.
path.addComment(
'leading',
' wordpress: needs wp-polyfill '
);
path.addComment( 'leading', ' wp:polyfill ' );
}
},
},
Expand Down
6 changes: 1 addition & 5 deletions packages/dependency-extraction-webpack-plugin/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -287,11 +287,7 @@ class DependencyExtractionWebpackPlugin {
// Prepare to look for magic comments, in order to decide whether
// `wp-polyfill` is needed.
const processContentsForMagicComments = ( content ) => {
if (
content
.toString()
.includes( '/* wordpress: needs wp-polyfill */' )
) {
if ( content.toString().includes( '/* wp:polyfill */' ) ) {
chunkStaticDeps.add( 'wp-polyfill' );
}
};
Expand Down
2 changes: 1 addition & 1 deletion tools/webpack/shared.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const baseConfig = {
parallel: true,
terserOptions: {
output: {
comments: /(translators|wordpress):/i,
comments: /(translators|wp):/i,
},
compress: {
passes: 2,
Expand Down

0 comments on commit b1c837d

Please sign in to comment.