Skip to content

Commit

Permalink
refactor!: drop lodash from dependencies where it possible (#959)
Browse files Browse the repository at this point in the history
BREAKING CHANGE: Node >= 14 is required
  • Loading branch information
dangreen committed Feb 6, 2023
1 parent ccf5310 commit a8b4e12
Show file tree
Hide file tree
Showing 39 changed files with 251 additions and 223 deletions.
2 changes: 1 addition & 1 deletion packages/conventional-changelog-angular/package.json
Expand Up @@ -25,7 +25,7 @@
],
"author": "Steve Mao",
"engines": {
"node": ">=10"
"node": ">=14"
},
"license": "ISC",
"bugs": {
Expand Down
2 changes: 1 addition & 1 deletion packages/conventional-changelog-atom/package.json
Expand Up @@ -17,7 +17,7 @@
],
"author": "Steve Mao",
"engines": {
"node": ">=10"
"node": ">=14"
},
"license": "ISC",
"files": [
Expand Down
21 changes: 16 additions & 5 deletions packages/conventional-changelog-cli/cli.js
Expand Up @@ -6,7 +6,6 @@ const conventionalChangelog = require('conventional-changelog')
const fs = require('fs')
const meow = require('meow')
const tempfile = require('tempfile')
const _ = require('lodash')
const resolve = require('path').resolve

const cli = meow(`
Expand Down Expand Up @@ -132,7 +131,7 @@ if (infile && infile === outfile) {
}
}

let options = _.omitBy({
let options = {
preset: flags.preset,
pkg: {
path: flags.pkg
Expand All @@ -143,7 +142,7 @@ let options = _.omitBy({
outputUnreleased: flags.outputUnreleased,
lernaPackage: flags.lernaPackage,
tagPrefix: flags.tagPrefix
}, _.isUndefined)
}

if (flags.verbose) {
options.debug = console.info.bind(console)
Expand All @@ -162,7 +161,17 @@ try {
if (flags.config) {
config = require(resolve(process.cwd(), flags.config))
options.config = config
options = _.merge(options, config.options)

if (config.options) {
options = {
...options,
...config.options,
pkg: {
...options.pkg,
...config.options.pkg
}
}
}
} else {
config = {}
}
Expand All @@ -171,7 +180,9 @@ try {
process.exit(1)
}

const gitRawCommitsOpts = _.merge({}, config.gitRawCommitsOpts || {})
const gitRawCommitsOpts = {
...config.gitRawCommitsOpts
}
if (flags.commitPath) gitRawCommitsOpts.path = flags.commitPath

const changelogStream = conventionalChangelog(options, templateContext, gitRawCommitsOpts, config.parserOpts, config.writerOpts)
Expand Down
3 changes: 1 addition & 2 deletions packages/conventional-changelog-cli/package.json
Expand Up @@ -30,12 +30,11 @@
"log"
],
"engines": {
"node": ">=10"
"node": ">=14"
},
"dependencies": {
"add-stream": "^1.0.0",
"conventional-changelog": "^3.1.24",
"lodash": "^4.17.15",
"meow": "^8.0.0",
"tempfile": "^3.0.0"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/conventional-changelog-codemirror/package.json
Expand Up @@ -17,7 +17,7 @@
],
"author": "Steve Mao",
"engines": {
"node": ">=10"
"node": ">=14"
},
"license": "ISC",
"files": [
Expand Down
3 changes: 1 addition & 2 deletions packages/conventional-changelog-conventionalcommits/index.js
@@ -1,14 +1,13 @@
'use strict'
const Q = require('q')
const _ = require('lodash')
const conventionalChangelog = require('./conventional-changelog')
const parserOpts = require('./parser-opts')
const recommendedBumpOpts = require('./conventional-recommended-bump')
const writerOpts = require('./writer-opts')

module.exports = function (parameter) {
// parameter passed can be either a config object or a callback function
if (_.isFunction(parameter)) {
if (typeof parameter === 'function') {
// parameter is a callback object
const config = {}
// FIXME: use presetOpts(config) for callback
Expand Down
Expand Up @@ -26,7 +26,7 @@
],
"author": "Ben Coe",
"engines": {
"node": ">=10"
"node": ">=14"
},
"license": "ISC",
"bugs": {
Expand All @@ -35,7 +35,6 @@
"homepage": "https://github.com/conventional-changelog/conventional-changelog/tree/master/packages/conventional-changelog-conventionalcommits#readme",
"dependencies": {
"compare-func": "^2.0.0",
"lodash": "^4.17.15",
"q": "^1.5.1"
}
}
6 changes: 3 additions & 3 deletions packages/conventional-changelog-core/index.js
Expand Up @@ -4,7 +4,6 @@ const addStream = require('add-stream')
const gitRawCommits = require('git-raw-commits')
const conventionalCommitsParser = require('conventional-commits-parser')
const conventionalChangelogWriter = require('conventional-changelog-writer')
const _ = require('lodash')
const stream = require('stream')
const through = require('through2')
const execFileSync = require('child_process').execFileSync
Expand All @@ -26,10 +25,11 @@ function conventionalChangelog (options, context, gitRawCommitsOpts, parserOpts,
commitsStream._read = function () { }

function commitsRange (from, to) {
return gitRawCommits(_.merge({}, gitRawCommitsOpts, {
return gitRawCommits({
...gitRawCommitsOpts,
from: from,
to: to
}))
})
.on('error', function (err) {
if (!commitsErrorThrown) {
setImmediate(commitsStream.emit.bind(commitsStream), 'error', err)
Expand Down
76 changes: 39 additions & 37 deletions packages/conventional-changelog-core/lib/merge-config.js
Expand Up @@ -15,7 +15,6 @@ try {
const readPkg = require('read-pkg')
const readPkgUp = require('read-pkg-up')
const URL = require('url').URL
const _ = require('lodash')

const rhosts = /github|bitbucket|gitlab/i

Expand Down Expand Up @@ -61,18 +60,13 @@ function mergeConfig (options, context, gitRawCommitsOpts, parserOpts, writerOpt

const rtag = options && options.tagPrefix ? new RegExp(`tag:\\s*[=]?${options.tagPrefix}(.+?)[,)]`, 'gi') : /tag:\s*[v=]?(.+?)[,)]/gi

options = _.merge({
pkg: {
transform: function (pkg) {
return pkg
}
},
options = {
append: false,
releaseCount: 1,
skipUnstable: false,
debug: function () {},
transform: function (commit, cb) {
if (_.isString(commit.gitTags)) {
if (typeof commit.gitTags === 'string') {
const match = rtag.exec(commit.gitTags)
rtag.lastIndex = 0

Expand All @@ -87,13 +81,20 @@ function mergeConfig (options, context, gitRawCommitsOpts, parserOpts, writerOpt

cb(null, commit)
},
lernaPackage: null
}, options)
lernaPackage: null,
...options,
pkg: {
transform: function (pkg) {
return pkg
},
...options?.pkg
}
}

options.warn = options.warn || options.debug

if (options.config) {
if (_.isFunction(options.config)) {
if (typeof options.config === 'function') {
configPromise = Q.nfcall(options.config)
} else {
configPromise = Q(options.config)
Expand Down Expand Up @@ -132,7 +133,10 @@ function mergeConfig (options, context, gitRawCommitsOpts, parserOpts, writerOpt
config = {}
}

context = _.assign(context, config.context)
context = {
...context,
...config.context
}

if (options.pkg) {
if (pkgObj.state === 'fulfilled') {
Expand Down Expand Up @@ -206,7 +210,7 @@ function mergeConfig (options, context, gitRawCommitsOpts, parserOpts, writerOpt
}
}

if (!_.isBoolean(options.outputUnreleased)) {
if (typeof options.outputUnreleased !== 'boolean') {
options.outputUnreleased = true
}

Expand All @@ -225,10 +229,11 @@ function mergeConfig (options, context, gitRawCommitsOpts, parserOpts, writerOpt
if (type) {
hostOpts = require('../hosts/' + type)

context = _.assign({
context = {
issue: hostOpts.issue,
commit: hostOpts.commit
}, context)
commit: hostOpts.commit,
...context
}
} else {
options.warn('Host: "' + context.host + '" does not exist')
hostOpts = {}
Expand All @@ -241,35 +246,34 @@ function mergeConfig (options, context, gitRawCommitsOpts, parserOpts, writerOpt
fromTag = null
}

gitRawCommitsOpts = _.assign({
gitRawCommitsOpts = {
format: '%B%n-hash-%n%H%n-gitTags-%n%d%n-committerDate-%n%ci',
from: fromTag,
merges: false,
debug: options.debug
},
config.gitRawCommitsOpts,
gitRawCommitsOpts
)
debug: options.debug,
...config.gitRawCommitsOpts,
...gitRawCommitsOpts
}

if (options.append) {
gitRawCommitsOpts.reverse = gitRawCommitsOpts.reverse || true
}

parserOpts = _.assign(
{}, config.parserOpts, {
warn: options.warn
},
parserOpts)
parserOpts = {
...config.parserOpts,
warn: options.warn,
...parserOpts
}

if (hostOpts.referenceActions && parserOpts) {
parserOpts.referenceActions = hostOpts.referenceActions
}

if (_.isEmpty(parserOpts.issuePrefixes) && hostOpts.issuePrefixes) {
if (!parserOpts.issuePrefixes?.length && hostOpts.issuePrefixes) {
parserOpts.issuePrefixes = hostOpts.issuePrefixes
}

writerOpts = _.assign({
writerOpts = {
finalizeContext: function (context, writerOpts, filteredCommits, keyCommit, originalCommits) {
const firstCommit = originalCommits[0]
const lastCommit = originalCommits[originalCommits.length - 1]
Expand Down Expand Up @@ -316,20 +320,18 @@ function mergeConfig (options, context, gitRawCommitsOpts, parserOpts, writerOpt
}
}

if (!_.isBoolean(context.linkCompare) && context.previousTag && context.currentTag) {
if (typeof context.linkCompare !== 'boolean' && context.previousTag && context.currentTag) {
context.linkCompare = true
}

return context
},
debug: options.debug
},
config.writerOpts, {
debug: options.debug,
...config.writerOpts,
reverse: options.append,
doFlush: options.outputUnreleased
},
writerOpts
)
doFlush: options.outputUnreleased,
...writerOpts
}

return {
options: options,
Expand Down
3 changes: 1 addition & 2 deletions packages/conventional-changelog-core/package.json
Expand Up @@ -13,7 +13,7 @@
"log"
],
"engines": {
"node": ">=10"
"node": ">=14"
},
"license": "MIT",
"files": [
Expand All @@ -34,7 +34,6 @@
"git-raw-commits": "^2.0.8",
"git-remote-origin-url": "^2.0.0",
"git-semver-tags": "^4.1.1",
"lodash": "^4.17.15",
"normalize-package-data": "^3.0.0",
"q": "^1.5.1",
"read-pkg": "^3.0.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/conventional-changelog-ember/package.json
Expand Up @@ -17,7 +17,7 @@
],
"author": "Steve Mao",
"engines": {
"node": ">=10"
"node": ">=14"
},
"license": "ISC",
"files": [
Expand Down
2 changes: 1 addition & 1 deletion packages/conventional-changelog-eslint/package.json
Expand Up @@ -17,7 +17,7 @@
],
"author": "Steve Mao",
"engines": {
"node": ">=10"
"node": ">=14"
},
"license": "ISC",
"files": [
Expand Down
2 changes: 1 addition & 1 deletion packages/conventional-changelog-express/package.json
Expand Up @@ -17,7 +17,7 @@
],
"author": "Steve Mao",
"engines": {
"node": ">=10"
"node": ">=14"
},
"license": "ISC",
"files": [
Expand Down
2 changes: 1 addition & 1 deletion packages/conventional-changelog-jquery/package.json
Expand Up @@ -17,7 +17,7 @@
],
"author": "Steve Mao",
"engines": {
"node": ">=10"
"node": ">=14"
},
"license": "ISC",
"files": [
Expand Down
2 changes: 1 addition & 1 deletion packages/conventional-changelog-jshint/package.json
Expand Up @@ -17,7 +17,7 @@
],
"author": "Steve Mao",
"engines": {
"node": ">=10"
"node": ">=14"
},
"license": "ISC",
"files": [
Expand Down
2 changes: 1 addition & 1 deletion packages/conventional-changelog-preset-loader/package.json
Expand Up @@ -13,7 +13,7 @@
],
"license": "MIT",
"engines": {
"node": ">=10"
"node": ">=14"
},
"files": [
"index.js"
Expand Down

0 comments on commit a8b4e12

Please sign in to comment.