Skip to content

Commit

Permalink
Lodash: Refactor away from _.merge() (#48239)
Browse files Browse the repository at this point in the history
* Lodash: Refactor away from _.merge()

* Add CHANGELOG entry

* Update package-lock.json

* Expand CHANGELOG message
  • Loading branch information
tyxla authored Feb 21, 2023
1 parent dfb0145 commit 6095747
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 5 deletions.
1 change: 1 addition & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ const restrictedImports = [
'mapKeys',
'maxBy',
'memoize',
'merge',
'negate',
'noop',
'nth',
Expand Down
11 changes: 10 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions packages/babel-plugin-makepot/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## Unreleased

### Internal

- Lodash: Refactor away from `_.merge()` and remove Lodash dependency ([#48239](https://github.com/WordPress/gutenberg/pull/48239)).

## 5.11.0 (2023-02-15)

## 5.10.0 (2023-02-01)
Expand Down
16 changes: 13 additions & 3 deletions packages/babel-plugin-makepot/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,9 @@
* External dependencies
*/

const deepmerge = require( 'deepmerge' );
const { isPlainObject } = require( 'is-plain-object' );
const { po } = require( 'gettext-parser' );
const { merge, isEmpty } = require( 'lodash' );
const { relative, sep } = require( 'path' );
const { writeFileSync } = require( 'fs' );

Expand Down Expand Up @@ -312,7 +313,10 @@ module.exports = () => {
},
exit( path, state ) {
const { filename } = this.file.opts;
if ( isEmpty( strings[ filename ] ) ) {
if (
! strings[ filename ] ||
! Object.values( strings[ filename ] ).length
) {
delete strings[ filename ];
return;
}
Expand Down Expand Up @@ -362,7 +366,13 @@ module.exports = () => {
}, {} );

// Merge translations from individual files into headers
const data = merge( {}, baseData, { translations } );
const data = deepmerge(
baseData,
{ translations },
{
isMergeableObject: isPlainObject,
}
);

// Ideally we could wait until Babel has finished parsing
// all files or at least asynchronously write, but the
Expand Down
3 changes: 2 additions & 1 deletion packages/babel-plugin-makepot/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@
],
"main": "index.js",
"dependencies": {
"deepmerge": "^4.3.0",
"gettext-parser": "^1.3.1",
"lodash": "^4.17.21"
"is-plain-object": "^5.0.0"
},
"peerDependencies": {
"@babel/core": "^7.12.9"
Expand Down

1 comment on commit 6095747

@github-actions
Copy link

Choose a reason for hiding this comment

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

Flaky tests detected in 6095747.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/4233475501
📝 Reported issues:

Please sign in to comment.