Skip to content
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

Lodash: Refactor away from _.merge() #48239

Merged
merged 4 commits into from
Feb 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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