diff --git a/.eslintrc.js b/.eslintrc.js index 70926c8a9c541f..f86c08ac4705ab 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -106,6 +106,7 @@ const restrictedImports = [ 'mapKeys', 'maxBy', 'memoize', + 'merge', 'negate', 'noop', 'nth', diff --git a/package-lock.json b/package-lock.json index 4dce5bc1ffe168..0cdc23a73239f1 100644 --- a/package-lock.json +++ b/package-lock.json @@ -17226,8 +17226,17 @@ "version": "file:packages/babel-plugin-makepot", "dev": true, "requires": { + "deepmerge": "^4.3.0", "gettext-parser": "^1.3.1", - "lodash": "^4.17.21" + "is-plain-object": "^5.0.0" + }, + "dependencies": { + "deepmerge": { + "version": "4.3.0", + "resolved": "https://registry.npmjs.org/deepmerge/-/deepmerge-4.3.0.tgz", + "integrity": "sha512-z2wJZXrmeHdvYJp/Ux55wIjqo81G5Bp4c+oELTW+7ar6SogWHajt5a9gO3s3IDaGSAXjDk0vlQKN3rms8ab3og==", + "dev": true + } } }, "@wordpress/babel-preset-default": { diff --git a/packages/babel-plugin-makepot/CHANGELOG.md b/packages/babel-plugin-makepot/CHANGELOG.md index 4e059b869e5850..581a001cfd0bba 100644 --- a/packages/babel-plugin-makepot/CHANGELOG.md +++ b/packages/babel-plugin-makepot/CHANGELOG.md @@ -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) diff --git a/packages/babel-plugin-makepot/index.js b/packages/babel-plugin-makepot/index.js index a1ea1a79cccc13..846a29a7955b34 100644 --- a/packages/babel-plugin-makepot/index.js +++ b/packages/babel-plugin-makepot/index.js @@ -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' ); @@ -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; } @@ -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 diff --git a/packages/babel-plugin-makepot/package.json b/packages/babel-plugin-makepot/package.json index f172ca8f270a9e..8938b24467faa9 100644 --- a/packages/babel-plugin-makepot/package.json +++ b/packages/babel-plugin-makepot/package.json @@ -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"