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

chore(lodash): [RO-26515] Removes unneeded lodash deps with native replacements #105

Merged
merged 1 commit into from
Apr 9, 2024
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
36 changes: 0 additions & 36 deletions package-lock.json

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

9 changes: 0 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,8 @@
"bluebird": "3.7.2",
"colors": "1.4.0",
"form-data": "4.0.0",
"lodash.assignin": "4.2.0",
"lodash.bindall": "4.4.0",
"lodash.compact": "3.0.1",
"lodash.foreach": "4.5.0",
"lodash.invokemap": "4.6.0",
"lodash.isempty": "4.4.0",
"lodash.isfunction": "3.0.9",
"lodash.map": "4.6.0",
"lodash.some": "4.6.0",
"lodash.union": "4.6.0",
"lodash.uniq": "4.5.0",
"spur-config": "2.0.5",
Expand All @@ -59,8 +52,6 @@
"devDependencies": {
"eslint": "8.57.0",
"jest": "29.7.0",
"lodash.every": "4.6.0",
"lodash.last": "3.0.0",
"nock": "13.5.4"
}
}
15 changes: 6 additions & 9 deletions src/core/BaseDelegate.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
const _forEach = require('lodash.foreach');
const _isFunction = require('lodash.isfunction');
const _some = require('lodash.some');

module.exports = function (console, consoleColors) {
class BaseDelegate {

Expand All @@ -26,10 +22,11 @@ module.exports = function (console, consoleColors) {
}

callDelegate(methodName, args) {
_forEach(this.delegates, (delegate) => {
if (_isFunction(delegate[methodName])) {
const items = this.delegates || [];
items.forEach((delegate) => {
if (typeof delegate[methodName] === 'function') {
delegate[methodName].apply(delegate, args);
} else if (_isFunction(delegate)) {
} else if (typeof delegate === 'function') {
delegate.call(this, methodName, args);
}
});
Expand All @@ -55,9 +52,9 @@ module.exports = function (console, consoleColors) {
const checkMethodType = (item) => item === methodName;
let color = 'cyan';

if (_some(['fatal', 'error'], checkMethodType)) {
if (['fatal', 'error'].some(checkMethodType)) {
color = 'red';
} else if (_some(['warn'], checkMethodType)) {
} else if (['warn'].some(checkMethodType)) {
color = 'yellow';
}

Expand Down
6 changes: 3 additions & 3 deletions src/fixtures/FixtureCache.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
const _bindAll = require('lodash.bindall');

module.exports = function (Promise) {
class FixtureCache {

constructor() {
this.cache = {};

_bindAll(this, ['set', 'get', 'getOrPromise', 'setAsync']);
this.get.bind(this);
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getOrPromise is not called in an async method in the class, so context is not needed

this.set.bind(this);
this.setAsync.bind(this);
}

set(key, value) {
Expand Down
3 changes: 0 additions & 3 deletions src/fixtures/FixtureUtil.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
const _bindAll = require('lodash.bindall');

module.exports = function (path, Promise, fsPromise, FixtureCache, Logger) {
class FixtureUtil {

constructor(fixturesPath) {
_bindAll(this, ['get', 'readAndProcessFile', 'startFileRead']);
this.fixturesPath = fixturesPath;
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not called within an async method, so removing.

this.cache = FixtureCache;
}
Expand Down
7 changes: 4 additions & 3 deletions src/http/HTTPResponseProcessing.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
const _isEmpty = require('lodash.isempty');

module.exports = function (SpurErrors) {
class HTTPResponseProcessing {

Expand Down Expand Up @@ -73,7 +71,10 @@ module.exports = function (SpurErrors) {

_setErrorData(res) {
if (this.error) {
const errorResponse = _isEmpty(res.body) ? res.text : res.body;
const body = res.body;
const errorResponse = (body && body != null && Object.keys(body).length > 0)
? res.body
: res.text;
this.error.setData(errorResponse);
}
}
Expand Down
6 changes: 2 additions & 4 deletions src/http/HTTPService.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
const _compact = require('lodash.compact');
const _map = require('lodash.map');
const _invokeMap = require('lodash.invokemap');
Copy link
Contributor

@otrreeves otrreeves Apr 9, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe the _invokeMap usage in this file could be replaced with

return self._pluginInstances.map(plugin => plugin.end());

Not sure if this is the only usage of _invokeMap though

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe so but it's not low-hanging fruit. I will take a look at it in the next set of PRs. Coverage is not great to catch is so I don't want to commit to writing additional tests and delaying the main need of the project right now.

const _uniq = require('lodash.uniq');
const _union = require('lodash.union');
const _some = require('lodash.some');

module.exports = function (superagent, Promise, FormData, HTTPResponseProcessing) {
const Request = superagent.Request;
Expand Down Expand Up @@ -41,7 +39,7 @@ module.exports = function (superagent, Promise, FormData, HTTPResponseProcessing
if (self.tags == null) { self.tags = {}; }

this._plugins = (this._plugins || []).concat(superagent.globalPlugins);
this._pluginInstances = _compact(_map(this._plugins, (p) => p.start(self)));
this._pluginInstances = _compact(this._plugins.map((p) => p.start(self)));

return new Promise((resolve, reject) => {
Request.prototype.end.call(self, (err, res) => {
Expand Down Expand Up @@ -115,7 +113,7 @@ module.exports = function (superagent, Promise, FormData, HTTPResponseProcessing

superagent.addGlobalPlugin = function (plugin) {
const checkPluginExists = (pluginOpt) => pluginOpt === plugin;
if (!_some(superagent.globalPlugins, checkPluginExists)) {
if (!superagent.globalPlugins.some(checkPluginExists)) {
superagent.globalPlugins.push(plugin);
}

Expand Down
9 changes: 1 addition & 8 deletions src/utils/Utils.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,9 @@
const _bindAll = require('lodash.bindall');
const _assignIn = require('lodash.assignin');

module.exports = function (Promise, fsPromise, JSON) {
class Utils {

constructor() {
_bindAll(this, ['readFile', 'readJsonFile']);
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not called within an async method, so removing.


prop(prop) { return (ob) => ob[prop]; }

extendWith(ob1) { return (ob2) => _assignIn(ob2, ob1); }
extendWith(ob1) { return (ob2) => Object.assign(ob2, ob1); }

capitalize(str) {
if (!str) {
Expand Down
Loading