Skip to content

Commit

Permalink
fix: Bundle less lodash
Browse files Browse the repository at this point in the history
- Use lodash sub modules
- Drop fork
  • Loading branch information
darscan committed Jun 12, 2020
1 parent 4e9e936 commit dc4505f
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 8 deletions.
12 changes: 8 additions & 4 deletions lib/ruby/gem-requirement.js
@@ -1,4 +1,8 @@
const _ = require('@snyk/lodash');
const _escapeRegExp = require('lodash.escaperegexp');
const _isEmpty = require('lodash.isempty');
const _flatten = require('lodash.flatten');
const _uniq = require('lodash.uniq');

const GemVersion = require('./gem-version');

const OPS = {
Expand All @@ -11,7 +15,7 @@ const OPS = {
'~>': (v, r) => v.compare(r) >= 0 && v.release().compare(r.bump()) < 0,
};

const quoted = Object.keys(OPS).map(k => _.escapeRegExp(k)).join('|');
const quoted = Object.keys(OPS).map(k => _escapeRegExp(k)).join('|');
const PATTERN_RAW = `\\s*(${quoted})?\\s*(${GemVersion.VERSION_PATTERN})\\s*`;
// --
// A regular expression that matches a requirement
Expand Down Expand Up @@ -78,9 +82,9 @@ module.exports = class GemRequirement {
// same as <tt>">= 0"</tt>.

constructor(...requirements) {
requirements = _(requirements).flatten().filter(Boolean).uniq().value();
requirements = _uniq(_flatten(requirements));

if (_.isEmpty(requirements)) {
if (_isEmpty(requirements)) {
this.requirements = [DefaultRequirement];
} else {
this.requirements = requirements.map(GemRequirement.parse);
Expand Down
7 changes: 4 additions & 3 deletions lib/ruby/gem-version.js
Expand Up @@ -147,7 +147,8 @@
//
// For the last example, single-digit versions are automatically extended with
// a zero to give a sensible result.
const _ = require('@snyk/lodash');
const _isNumber = require('lodash.isnumber');
const _isString = require('lodash.isstring');

const VERSION_PATTERN = '[0-9]+(\.[0-9a-zA-Z]+)*(-[0-9A-Za-z-]+(\.[0-9A-Za-z-]+)*)?';
const ANCHORED_VERSION_PATTERN = new RegExp(`^\\s*(${VERSION_PATTERN})?\\s*$`);
Expand Down Expand Up @@ -379,8 +380,8 @@ class GemVersion {
continue;
}

if (_.isString(lhs) && _.isNumber(rhs)) { return -1; }
if (_.isNumber(lhs) && _.isString(rhs)) { return 1; }
if (_isString(lhs) && _isNumber(rhs)) { return -1; }
if (_isNumber(lhs) && _isString(rhs)) { return 1; }

if (lhs < rhs) { return -1; }
if (lhs > rhs) { return 1; }
Expand Down
7 changes: 6 additions & 1 deletion package.json
Expand Up @@ -19,6 +19,11 @@
"node": ">=8"
},
"dependencies": {
"@snyk/lodash": "4.17.15-patch"
"lodash.escaperegexp": "^4.1.0",
"lodash.flatten": "^4.4.0",
"lodash.isempty": "^4.4.0",
"lodash.isnumber": "^3.0.0",
"lodash.isstring": "^4.0.0",
"lodash.uniq": "^4.5.0"
}
}

0 comments on commit dc4505f

Please sign in to comment.