From 81fa2e22bc954a9c1878b0529cceee03f0f3a87b Mon Sep 17 00:00:00 2001 From: Julian Lam Date: Mon, 14 Feb 2022 14:36:50 -0500 Subject: [PATCH] fix: #10289, remove lodash dependency in src/cli/package-install.js --- src/cli/package-install.js | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/src/cli/package-install.js b/src/cli/package-install.js index f2e4e94913..9c618836a2 100644 --- a/src/cli/package-install.js +++ b/src/cli/package-install.js @@ -3,7 +3,6 @@ const path = require('path'); const fs = require('fs'); const cproc = require('child_process'); -const _ = require('lodash'); const { paths, pluginNamePattern } = require('../constants'); @@ -18,6 +17,23 @@ function sortDependencies(dependencies) { }, {}); } +function merge(to, from) { + // Poor man's version of _.merge() + if (Object.values(from).every(val => typeof val !== 'object')) { + return Object.assign(to, from); + } + + Object.keys(from).forEach((key) => { + if (Object.getPrototypeOf(from[key]) === Object.prototype) { + to[key] = merge(to[key], from[key]); + } else { + to[key] = from[key]; + } + }); + + return to; +} + pkgInstall.updatePackageFile = () => { let oldPackageContents = {}; @@ -43,7 +59,7 @@ pkgInstall.updatePackageFile = () => { // Sort dependencies alphabetically dependencies = sortDependencies({ ...dependencies, ...defaultPackageContents.dependencies }); - const packageContents = { ..._.merge(oldPackageContents, defaultPackageContents), dependencies, devDependencies }; + const packageContents = { ...merge(oldPackageContents, defaultPackageContents), dependencies, devDependencies }; fs.writeFileSync(paths.currentPackage, JSON.stringify(packageContents, null, 2)); };