fix: #10289, remove lodash dependency in src/cli/package-install.js

isekai-main
Julian Lam 3 years ago
parent a1593e35c0
commit 81fa2e22bc

@ -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));
};

Loading…
Cancel
Save