Skip to content

Commit

Permalink
Merge pull request #8 from theogravity/lodash-replace
Browse files Browse the repository at this point in the history
Replace lodash with dedicated packages
  • Loading branch information
theogravity authored Jul 10, 2024
2 parents 3f9fd18 + b0bd274 commit 2784545
Show file tree
Hide file tree
Showing 9 changed files with 85 additions and 31 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog

## 12.0.1

Added a modification of @prashantswami PR [Replace Lodash with Smaller Modular Packages for Improved Performance and to remove security vulnerabilities](https://github.com/seppevs/migrate-mongo/pull/447) replaces the lone `lodash` dependency with smaller, more focused packages
to also address security issues.

## 12.0.0

- Rebased against the repo that this project is forked from, [`seppevs/migrate-mongo`](migrate-mongo)
Expand Down
7 changes: 4 additions & 3 deletions bin/migrate-mongo.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#! /usr/bin/env node

const program = require("commander");
const _ = require("lodash");
const isEmpty = require("lodash.isempty");
const values = require("lodash.values");
const Table = require("cli-table3");
const migrateMongo = require("../lib/migrate-mongo");
const pkgjson = require("../package.json");
Expand All @@ -21,7 +22,7 @@ function printStatusTable(statusItems) {
return migrateMongo.config.read().then(config => {
const useFileHash = config.useFileHash === true;
const table = new Table({ head: useFileHash ? ["Filename", "Hash", "Applied At"] : ["Filename", "Applied At"]});
statusItems.forEach(item => table.push(_.values(item)));
statusItems.forEach(item => table.push(values(item)));
console.log(table.toString());
})

Expand Down Expand Up @@ -137,6 +138,6 @@ program

program.parse(process.argv);

if (_.isEmpty(program.rawArgs)) {
if (isEmpty(program.rawArgs)) {
program.outputHelp();
}
4 changes: 2 additions & 2 deletions lib/actions/down.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const _ = require("lodash");
const last = require("lodash.last");

const status = require("./status");
const config = require("../env/config");
Expand All @@ -17,7 +17,7 @@ module.exports = async (db, client) => {
} = await config.read();
const appliedItems = statusItems.filter(item => item[dateField] !== "PENDING" && item.appliedManually !== true);
const manualMigrationFileToApply = global.options.migrationFile
const lastAppliedItem = _.last(appliedItems);
const lastAppliedItem = last(appliedItems);

if (!manualMigrationFileToApply && await lock.exist(db)) {
throw new Error("Could not migrate down, a lock is in place.");
Expand Down
2 changes: 1 addition & 1 deletion lib/actions/status.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { find } = require("lodash");
const find = require("lodash.find");
const migrationsDir = require("../env/migrationsDir");
const config = require("../env/config");
const getName = require('../utils/name');
Expand Down
4 changes: 2 additions & 2 deletions lib/actions/up.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint no-console: 0 */
const _ = require("lodash");
const filter = require("lodash.filter");
const pEachSeries = require("p-each-series");

const status = require("./status");
Expand All @@ -20,7 +20,7 @@ module.exports = async (db, client) => {
context,
} = configObject;

const pendingItems = _.filter(statusItems, { [dateField]: "PENDING" });
const pendingItems = filter(statusItems, { [dateField]: "PENDING" });
const migrated = [];
const manualMigrationFileToApply = global.options.migrationFile

Expand Down
2 changes: 1 addition & 1 deletion lib/env/config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const fs = require("fs-extra");
const path = require("path");
const url = require("url");
const { get } = require("lodash");
const get = require("lodash.get");
const moduleLoader = require('../utils/module-loader');

const DEFAULT_CONFIG_FILE_NAME = "migrate-mongo-config.js";
Expand Down
8 changes: 4 additions & 4 deletions lib/env/database.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
const { MongoClient } = require("mongodb");
const _ = require("lodash");
const get = require("lodash.get");
const config = require("./config");

module.exports = {
async connect() {
const configContent = await config.read();
const url = _.get(configContent, "mongodb.url");
const databaseName = _.get(configContent, "mongodb.databaseName");
const options = _.get(configContent, "mongodb.options");
const url = get(configContent, "mongodb.url");
const databaseName = get(configContent, "mongodb.databaseName");
const options = get(configContent, "mongodb.options");

if (!url) {
throw new Error("No `url` defined in config file!");
Expand Down
77 changes: 60 additions & 17 deletions package-lock.json

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

7 changes: 6 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,12 @@
"commander": "^9.1.0",
"date-fns": "^2.28.0",
"fs-extra": "^10.0.1",
"lodash": "^4.17.21",
"lodash.filter": "^4.6.0",
"lodash.find": "^4.6.0",
"lodash.get": "^4.4.2",
"lodash.isempty": "^4.4.0",
"lodash.last": "^3.0.0",
"lodash.values": "^4.3.0",
"p-each-series": "^2.2.0"
},
"peerDependencies": {
Expand Down

0 comments on commit 2784545

Please sign in to comment.