From 9290aa2b6156c6507d5bd91a9049d8d31c597676 Mon Sep 17 00:00:00 2001 From: Fabio Spampinato Date: Tue, 4 Jun 2019 03:14:35 +0200 Subject: [PATCH 1/4] =?UTF-8?q?Replaced=20=E2=80=9Cmoment=E2=80=9D=20with?= =?UTF-8?q?=20=E2=80=9Cmoment-mini"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 3 ++- src/diagrams/gantt/ganttDb.js | 2 +- src/logger.js | 2 +- yarn.lock | 11 ++++++++--- 4 files changed, 12 insertions(+), 6 deletions(-) diff --git a/package.json b/package.json index 77dfaae21..da68e89e7 100644 --- a/package.json +++ b/package.json @@ -42,7 +42,7 @@ "graphlibrary": "^2.2.0", "he": "^1.2.0", "lodash": "^4.17.11", - "moment": "^2.23.0", + "moment-mini": "^2.22.1", "scope-css": "^1.2.1" }, "devDependencies": { @@ -62,6 +62,7 @@ "identity-obj-proxy": "^3.0.0", "jest": "^23.6.0", "jison": "^0.4.18", + "moment": "^2.23.0", "node-sass": "^4.11.0", "sass-loader": "^7.1.0", "standard": "^12.0.1", diff --git a/src/diagrams/gantt/ganttDb.js b/src/diagrams/gantt/ganttDb.js index b4e4fda76..4b075f752 100644 --- a/src/diagrams/gantt/ganttDb.js +++ b/src/diagrams/gantt/ganttDb.js @@ -1,4 +1,4 @@ -import moment from 'moment' +import moment from 'moment-mini' import { logger } from '../../logger' let dateFormat = '' diff --git a/src/logger.js b/src/logger.js index adaadf31d..eefaccf34 100644 --- a/src/logger.js +++ b/src/logger.js @@ -1,4 +1,4 @@ -import moment from 'moment' +import moment from 'moment-mini' export const LEVELS = { debug: 1, diff --git a/yarn.lock b/yarn.lock index 8e373dc64..05126cf55 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5539,10 +5539,15 @@ mixin-object@^2.0.1: dependencies: minimist "0.0.8" +moment-mini@^2.22.1: + version "2.22.1" + resolved "https://registry.yarnpkg.com/moment-mini/-/moment-mini-2.22.1.tgz#bc32d73e43a4505070be6b53494b17623183420d" + integrity sha512-OUCkHOz7ehtNMYuZjNciXUfwTuz8vmF1MTbAy59ebf+ZBYZO5/tZKuChVWCX+uDo+4idJBpGltNfV8st+HwsGw== + moment@^2.23.0: - version "2.23.0" - resolved "https://registry.yarnpkg.com/moment/-/moment-2.23.0.tgz#759ea491ac97d54bac5ad776996e2a58cc1bc225" - integrity sha512-3IE39bHVqFbWWaPOMHZF98Q9c3LDKGTmypMiTM2QygGXXElkFWIH7GxfmlwmY2vwa+wmNsoYZmG2iusf1ZjJoA== + version "2.24.0" + resolved "https://registry.yarnpkg.com/moment/-/moment-2.24.0.tgz#0d055d53f5052aa653c9f6eb68bb5d12bf5c2b5b" + integrity sha512-bV7f+6l2QigeBBZSM/6yTNq4P2fNpSWj/0e7jQcy87A8e7o2nAfP/34/2ky5Vw4B9S446EtIhodAzkFCcR4dQg== move-concurrently@^1.0.1: version "1.0.1" From 00be016979c3bc732b488b5095ca2afbd71b8d0f Mon Sep 17 00:00:00 2001 From: Fabio Spampinato Date: Tue, 4 Jun 2019 03:17:14 +0200 Subject: [PATCH 2/4] =?UTF-8?q?Avoiding=20publishing=20the=20=E2=80=9Csrc?= =?UTF-8?q?=E2=80=9D=20folder=20to=20NPM?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/package.json b/package.json index da68e89e7..57d1d68a0 100644 --- a/package.json +++ b/package.json @@ -72,8 +72,7 @@ "yarn-upgrade-all": "^0.5.0" }, "files": [ - "dist", - "src" + "dist" ], "jest": { "moduleNameMapper": { From fef85cf25985bb388aac05b43a6d4f48953ea05c Mon Sep 17 00:00:00 2001 From: Fabio Spampinato Date: Tue, 4 Jun 2019 03:32:56 +0200 Subject: [PATCH 3/4] Importing only specific modules from "lodash" --- package.json | 5 ++++- src/diagrams/git/gitGraphAst.js | 23 +++++++++++++---------- src/diagrams/git/gitGraphRenderer.js | 25 ++++++++++++++++--------- yarn.lock | 15 +++++++++++++++ 4 files changed, 48 insertions(+), 20 deletions(-) diff --git a/package.json b/package.json index 57d1d68a0..e73b01299 100644 --- a/package.json +++ b/package.json @@ -41,7 +41,10 @@ "dagre-layout": "^0.8.8", "graphlibrary": "^2.2.0", "he": "^1.2.0", - "lodash": "^4.17.11", + "lodash.assign": "^4.2.0", + "lodash.maxby": "^4.6.0", + "lodash.orderby": "^4.6.0", + "lodash.uniqby": "^4.7.0", "moment-mini": "^2.22.1", "scope-css": "^1.2.1" }, diff --git a/src/diagrams/git/gitGraphAst.js b/src/diagrams/git/gitGraphAst.js index e734453b7..f71a15a8c 100644 --- a/src/diagrams/git/gitGraphAst.js +++ b/src/diagrams/git/gitGraphAst.js @@ -1,4 +1,6 @@ -import _ from 'lodash' +import maxBy from 'lodash.maxby' +import orderBy from 'lodash.orderby' +import uniqBy from 'lodash.uniqby' import { logger } from '../../logger' @@ -145,7 +147,7 @@ function upsert (arr, key, newval) { } function prettyPrintCommitHistory (commitArr) { - const commit = _.maxBy(commitArr, 'seq') + const commit = maxBy(commitArr, 'seq') let line = '' commitArr.forEach(function (c) { if (c === commit) { @@ -155,9 +157,9 @@ function prettyPrintCommitHistory (commitArr) { } }) const label = [line, commit.id, commit.seq] - _.each(branches, function (value, key) { - if (value === commit.id) label.push(key) - }) + for (let branch in branches) { + if (branches[branch] === commit.id) label.push(branch) + } logger.debug(label.join(' ')) if (Array.isArray(commit.parent)) { const newCommit = commits[commit.parent[0]] @@ -169,7 +171,7 @@ function prettyPrintCommitHistory (commitArr) { const nextCommit = commits[commit.parent] upsert(commitArr, commit, nextCommit) } - commitArr = _.uniqBy(commitArr, 'id') + commitArr = uniqBy(commitArr, 'id') prettyPrintCommitHistory(commitArr) } @@ -188,9 +190,10 @@ export const clear = function () { } export const getBranchesAsObjArray = function () { - const branchArr = _.map(branches, function (value, key) { - return { 'name': key, 'commit': commits[value] } - }) + const branchArr = [] + for (let branch in branches) { + branchArr.push({ name: branch, commit: commits[branches[branch]] }) + } return branchArr } @@ -201,7 +204,7 @@ export const getCommitsArray = function () { return commits[key] }) commitArr.forEach(function (o) { logger.debug(o.id) }) - return _.orderBy(commitArr, ['seq'], ['desc']) + return orderBy(commitArr, ['seq'], ['desc']) } export const getCurrentBranch = function () { return curBranch } export const getDirection = function () { return direction } diff --git a/src/diagrams/git/gitGraphRenderer.js b/src/diagrams/git/gitGraphRenderer.js index 3ef56478d..79aae45fe 100644 --- a/src/diagrams/git/gitGraphRenderer.js +++ b/src/diagrams/git/gitGraphRenderer.js @@ -1,5 +1,5 @@ -import _ from 'lodash' import * as d3 from 'd3' +import assign from 'lodash.assign' import db from './gitGraphAst' import gitGraphParser from './parser/gitGraph' @@ -160,7 +160,7 @@ function cloneNode (svg, selector) { function renderCommitHistory (svg, commitid, branches, direction) { let commit const numCommits = Object.keys(allCommitsDict).length - if (_.isString(commitid)) { + if (typeof commitid === 'string') { do { commit = allCommitsDict[commitid] logger.debug('in renderCommitHistory', commit.id, commit.seq) @@ -189,7 +189,13 @@ function renderCommitHistory (svg, commitid, branches, direction) { .attr('stroke', config.nodeStrokeColor) .attr('stroke-width', config.nodeStrokeWidth) - const branch = _.find(branches, ['commit', commit]) + let branch + for (let branchName in branches) { + if (branches[branchName].commit === commit) { + branch = branches[branchName] + break + } + } if (branch) { logger.debug('found branch ', branch.name) svg.select('#node-' + commit.id + ' p') @@ -211,7 +217,7 @@ function renderCommitHistory (svg, commitid, branches, direction) { } while (commitid && allCommitsDict[commitid]) } - if (_.isArray(commitid)) { + if (Array.isArray(commitid)) { logger.debug('found merge commmit', commitid) renderCommitHistory(svg, commitid[0], branches, direction) branchNum++ @@ -223,11 +229,11 @@ function renderCommitHistory (svg, commitid, branches, direction) { function renderLines (svg, commit, direction, branchColor) { branchColor = branchColor || 0 while (commit.seq > 0 && !commit.lineDrawn) { - if (_.isString(commit.parent)) { + if (typeof commit.parent === 'string') { svgDrawLineForCommits(svg, commit.id, commit.parent, direction, branchColor) commit.lineDrawn = true commit = allCommitsDict[commit.parent] - } else if (_.isArray(commit.parent)) { + } else if (Array.isArray(commit.parent)) { svgDrawLineForCommits(svg, commit.id, commit.parent[0], direction, branchColor) svgDrawLineForCommits(svg, commit.id, commit.parent[1], direction, branchColor + 1) renderLines(svg, allCommitsDict[commit.parent[1]], direction, branchColor + 1) @@ -246,7 +252,7 @@ export const draw = function (txt, id, ver) { // Parse the graph definition parser.parse(txt + '\n') - config = _.extend(config, apiConfig, db.getOptions()) + config = assign(config, apiConfig, db.getOptions()) logger.debug('effective options', config) const direction = db.getDirection() allCommitsDict = db.getCommits() @@ -259,11 +265,12 @@ export const draw = function (txt, id, ver) { const svg = d3.select(`[id="${id}"]`) svgCreateDefs(svg) branchNum = 1 - _.each(branches, function (v) { + for (let branch in branches) { + const v = branches[branch] renderCommitHistory(svg, v.commit.id, branches, direction) renderLines(svg, v.commit, direction) branchNum++ - }) + } svg.attr('height', function () { if (direction === 'BT') return Object.keys(allCommitsDict).length * config.nodeSpacing return (branches.length + 1) * config.branchOffset diff --git a/yarn.lock b/yarn.lock index 05126cf55..e0acdf892 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5163,11 +5163,21 @@ lodash.keys@^3.0.0: lodash.isarguments "^3.0.0" lodash.isarray "^3.0.0" +lodash.maxby@^4.6.0: + version "4.6.0" + resolved "https://registry.yarnpkg.com/lodash.maxby/-/lodash.maxby-4.6.0.tgz#082240068f3c7a227aa00a8380e4f38cf0786e3d" + integrity sha1-CCJABo88eiJ6oAqDgOTzjPB4bj0= + lodash.mergewith@^4.6.0: version "4.6.1" resolved "https://registry.yarnpkg.com/lodash.mergewith/-/lodash.mergewith-4.6.1.tgz#639057e726c3afbdb3e7d42741caa8d6e4335927" integrity sha512-eWw5r+PYICtEBgrBE5hhlT6aAa75f411bgDz/ZL2KZqYV03USvucsxcHUIlGTDTECs1eunpI7HOV7U+WLDvNdQ== +lodash.orderby@^4.6.0: + version "4.6.0" + resolved "https://registry.yarnpkg.com/lodash.orderby/-/lodash.orderby-4.6.0.tgz#e697f04ce5d78522f54d9338b32b81a3393e4eb3" + integrity sha1-5pfwTOXXhSL1TZM4syuBozk+TrM= + lodash.restparam@^3.0.0: version "3.6.1" resolved "https://registry.yarnpkg.com/lodash.restparam/-/lodash.restparam-3.6.1.tgz#936a4e309ef330a7645ed4145986c85ae5b20805" @@ -5203,6 +5213,11 @@ lodash.templatesettings@^3.0.0: lodash._reinterpolate "^3.0.0" lodash.escape "^3.0.0" +lodash.uniqby@^4.7.0: + version "4.7.0" + resolved "https://registry.yarnpkg.com/lodash.uniqby/-/lodash.uniqby-4.7.0.tgz#d99c07a669e9e6d24e1362dfe266c67616af1302" + integrity sha1-2ZwHpmnp5tJOE2Lf4mbGdhavEwI= + lodash@^4.0.0, lodash@^4.13.1, lodash@^4.17.10, lodash@^4.17.11, lodash@^4.3.0, lodash@~4.17.10: version "4.17.11" resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.11.tgz#b39ea6229ef607ecd89e2c8df12536891cac9b8d" From ed3d15501a54b3a1129f4083019fb0f7ad7e49e2 Mon Sep 17 00:00:00 2001 From: Fabio Spampinato Date: Tue, 4 Jun 2019 03:52:01 +0200 Subject: [PATCH 4/4] =?UTF-8?q?Aligned=20=E2=80=9Clodash=E2=80=9D=20versio?= =?UTF-8?q?n=20with=20other=20dependencies,=20so=20that=20it=20gets=20dedu?= =?UTF-8?q?plicated?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 5 +---- src/diagrams/git/gitGraphAst.js | 10 ++++------ src/diagrams/git/gitGraphRenderer.js | 4 ++-- yarn.lock | 15 --------------- 4 files changed, 7 insertions(+), 27 deletions(-) diff --git a/package.json b/package.json index e73b01299..6e26956a4 100644 --- a/package.json +++ b/package.json @@ -41,10 +41,7 @@ "dagre-layout": "^0.8.8", "graphlibrary": "^2.2.0", "he": "^1.2.0", - "lodash.assign": "^4.2.0", - "lodash.maxby": "^4.6.0", - "lodash.orderby": "^4.6.0", - "lodash.uniqby": "^4.7.0", + "lodash": "^4.17.5", "moment-mini": "^2.22.1", "scope-css": "^1.2.1" }, diff --git a/src/diagrams/git/gitGraphAst.js b/src/diagrams/git/gitGraphAst.js index f71a15a8c..f7338c5ed 100644 --- a/src/diagrams/git/gitGraphAst.js +++ b/src/diagrams/git/gitGraphAst.js @@ -1,6 +1,4 @@ -import maxBy from 'lodash.maxby' -import orderBy from 'lodash.orderby' -import uniqBy from 'lodash.uniqby' +import _ from 'lodash' import { logger } from '../../logger' @@ -147,7 +145,7 @@ function upsert (arr, key, newval) { } function prettyPrintCommitHistory (commitArr) { - const commit = maxBy(commitArr, 'seq') + const commit = _.maxBy(commitArr, 'seq') let line = '' commitArr.forEach(function (c) { if (c === commit) { @@ -171,7 +169,7 @@ function prettyPrintCommitHistory (commitArr) { const nextCommit = commits[commit.parent] upsert(commitArr, commit, nextCommit) } - commitArr = uniqBy(commitArr, 'id') + commitArr = _.uniqBy(commitArr, 'id') prettyPrintCommitHistory(commitArr) } @@ -204,7 +202,7 @@ export const getCommitsArray = function () { return commits[key] }) commitArr.forEach(function (o) { logger.debug(o.id) }) - return orderBy(commitArr, ['seq'], ['desc']) + return _.orderBy(commitArr, ['seq'], ['desc']) } export const getCurrentBranch = function () { return curBranch } export const getDirection = function () { return direction } diff --git a/src/diagrams/git/gitGraphRenderer.js b/src/diagrams/git/gitGraphRenderer.js index 79aae45fe..00f56ed1a 100644 --- a/src/diagrams/git/gitGraphRenderer.js +++ b/src/diagrams/git/gitGraphRenderer.js @@ -1,5 +1,5 @@ import * as d3 from 'd3' -import assign from 'lodash.assign' +import _ from 'lodash' import db from './gitGraphAst' import gitGraphParser from './parser/gitGraph' @@ -252,7 +252,7 @@ export const draw = function (txt, id, ver) { // Parse the graph definition parser.parse(txt + '\n') - config = assign(config, apiConfig, db.getOptions()) + config = _.assign(config, apiConfig, db.getOptions()) logger.debug('effective options', config) const direction = db.getDirection() allCommitsDict = db.getCommits() diff --git a/yarn.lock b/yarn.lock index e0acdf892..05126cf55 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5163,21 +5163,11 @@ lodash.keys@^3.0.0: lodash.isarguments "^3.0.0" lodash.isarray "^3.0.0" -lodash.maxby@^4.6.0: - version "4.6.0" - resolved "https://registry.yarnpkg.com/lodash.maxby/-/lodash.maxby-4.6.0.tgz#082240068f3c7a227aa00a8380e4f38cf0786e3d" - integrity sha1-CCJABo88eiJ6oAqDgOTzjPB4bj0= - lodash.mergewith@^4.6.0: version "4.6.1" resolved "https://registry.yarnpkg.com/lodash.mergewith/-/lodash.mergewith-4.6.1.tgz#639057e726c3afbdb3e7d42741caa8d6e4335927" integrity sha512-eWw5r+PYICtEBgrBE5hhlT6aAa75f411bgDz/ZL2KZqYV03USvucsxcHUIlGTDTECs1eunpI7HOV7U+WLDvNdQ== -lodash.orderby@^4.6.0: - version "4.6.0" - resolved "https://registry.yarnpkg.com/lodash.orderby/-/lodash.orderby-4.6.0.tgz#e697f04ce5d78522f54d9338b32b81a3393e4eb3" - integrity sha1-5pfwTOXXhSL1TZM4syuBozk+TrM= - lodash.restparam@^3.0.0: version "3.6.1" resolved "https://registry.yarnpkg.com/lodash.restparam/-/lodash.restparam-3.6.1.tgz#936a4e309ef330a7645ed4145986c85ae5b20805" @@ -5213,11 +5203,6 @@ lodash.templatesettings@^3.0.0: lodash._reinterpolate "^3.0.0" lodash.escape "^3.0.0" -lodash.uniqby@^4.7.0: - version "4.7.0" - resolved "https://registry.yarnpkg.com/lodash.uniqby/-/lodash.uniqby-4.7.0.tgz#d99c07a669e9e6d24e1362dfe266c67616af1302" - integrity sha1-2ZwHpmnp5tJOE2Lf4mbGdhavEwI= - lodash@^4.0.0, lodash@^4.13.1, lodash@^4.17.10, lodash@^4.17.11, lodash@^4.3.0, lodash@~4.17.10: version "4.17.11" resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.11.tgz#b39ea6229ef607ecd89e2c8df12536891cac9b8d"