From a8b4e12883021231befc6bdfeb95a9b50637f361 Mon Sep 17 00:00:00 2001 From: Dan Onoshko Date: Tue, 7 Feb 2023 00:22:22 +0700 Subject: [PATCH] refactor!: drop lodash from dependencies where it possible (#959) BREAKING CHANGE: Node >= 14 is required --- .../package.json | 2 +- .../conventional-changelog-atom/package.json | 2 +- packages/conventional-changelog-cli/cli.js | 21 +++- .../conventional-changelog-cli/package.json | 3 +- .../package.json | 2 +- .../index.js | 3 +- .../package.json | 3 +- packages/conventional-changelog-core/index.js | 6 +- .../lib/merge-config.js | 76 +++++------ .../conventional-changelog-core/package.json | 3 +- .../conventional-changelog-ember/package.json | 2 +- .../package.json | 2 +- .../package.json | 2 +- .../package.json | 2 +- .../package.json | 2 +- .../package.json | 2 +- packages/conventional-changelog-writer/cli.js | 8 +- .../conventional-changelog-writer/index.js | 34 ++--- .../conventional-changelog-writer/lib/util.js | 119 ++++++++++++------ .../package.json | 3 +- .../templates/commit.hbs | 8 +- .../test/index.spec.js | 37 +++--- packages/conventional-changelog/package.json | 2 +- packages/conventional-commits-filter/index.js | 2 +- .../conventional-commits-filter/package.json | 4 +- packages/conventional-commits-parser/cli.js | 3 +- packages/conventional-commits-parser/index.js | 8 +- .../conventional-commits-parser/lib/parser.js | 44 +++---- .../conventional-commits-parser/package.json | 3 +- .../test/index.spec.js | 9 +- .../test/parser.spec.js | 11 +- .../package.json | 2 +- packages/git-raw-commits/index.js | 3 +- packages/git-raw-commits/package.json | 3 +- packages/git-semver-tags/package.json | 2 +- .../gulp-conventional-changelog/package.json | 2 +- packages/standard-changelog/cli.js | 5 +- packages/standard-changelog/package.json | 3 +- pnpm-lock.yaml | 26 +--- 39 files changed, 251 insertions(+), 223 deletions(-) diff --git a/packages/conventional-changelog-angular/package.json b/packages/conventional-changelog-angular/package.json index 8190a7b24..70c4a014c 100644 --- a/packages/conventional-changelog-angular/package.json +++ b/packages/conventional-changelog-angular/package.json @@ -25,7 +25,7 @@ ], "author": "Steve Mao", "engines": { - "node": ">=10" + "node": ">=14" }, "license": "ISC", "bugs": { diff --git a/packages/conventional-changelog-atom/package.json b/packages/conventional-changelog-atom/package.json index 38d1e24a4..f86e37b55 100644 --- a/packages/conventional-changelog-atom/package.json +++ b/packages/conventional-changelog-atom/package.json @@ -17,7 +17,7 @@ ], "author": "Steve Mao", "engines": { - "node": ">=10" + "node": ">=14" }, "license": "ISC", "files": [ diff --git a/packages/conventional-changelog-cli/cli.js b/packages/conventional-changelog-cli/cli.js index 2bbde3e10..d0c862764 100755 --- a/packages/conventional-changelog-cli/cli.js +++ b/packages/conventional-changelog-cli/cli.js @@ -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(` @@ -132,7 +131,7 @@ if (infile && infile === outfile) { } } -let options = _.omitBy({ +let options = { preset: flags.preset, pkg: { path: flags.pkg @@ -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) @@ -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 = {} } @@ -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) diff --git a/packages/conventional-changelog-cli/package.json b/packages/conventional-changelog-cli/package.json index 185c70c73..fdf206871 100644 --- a/packages/conventional-changelog-cli/package.json +++ b/packages/conventional-changelog-cli/package.json @@ -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" }, diff --git a/packages/conventional-changelog-codemirror/package.json b/packages/conventional-changelog-codemirror/package.json index e851b57d9..4c296d270 100644 --- a/packages/conventional-changelog-codemirror/package.json +++ b/packages/conventional-changelog-codemirror/package.json @@ -17,7 +17,7 @@ ], "author": "Steve Mao", "engines": { - "node": ">=10" + "node": ">=14" }, "license": "ISC", "files": [ diff --git a/packages/conventional-changelog-conventionalcommits/index.js b/packages/conventional-changelog-conventionalcommits/index.js index f22d3cff3..1f44c632e 100644 --- a/packages/conventional-changelog-conventionalcommits/index.js +++ b/packages/conventional-changelog-conventionalcommits/index.js @@ -1,6 +1,5 @@ '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') @@ -8,7 +7,7 @@ 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 diff --git a/packages/conventional-changelog-conventionalcommits/package.json b/packages/conventional-changelog-conventionalcommits/package.json index 31e256812..e45af2bb2 100644 --- a/packages/conventional-changelog-conventionalcommits/package.json +++ b/packages/conventional-changelog-conventionalcommits/package.json @@ -26,7 +26,7 @@ ], "author": "Ben Coe", "engines": { - "node": ">=10" + "node": ">=14" }, "license": "ISC", "bugs": { @@ -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" } } diff --git a/packages/conventional-changelog-core/index.js b/packages/conventional-changelog-core/index.js index 98662a8ee..3adae5296 100644 --- a/packages/conventional-changelog-core/index.js +++ b/packages/conventional-changelog-core/index.js @@ -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 @@ -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) diff --git a/packages/conventional-changelog-core/lib/merge-config.js b/packages/conventional-changelog-core/lib/merge-config.js index 1fa14bb70..4238a7bb5 100644 --- a/packages/conventional-changelog-core/lib/merge-config.js +++ b/packages/conventional-changelog-core/lib/merge-config.js @@ -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 @@ -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 @@ -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) @@ -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') { @@ -206,7 +210,7 @@ function mergeConfig (options, context, gitRawCommitsOpts, parserOpts, writerOpt } } - if (!_.isBoolean(options.outputUnreleased)) { + if (typeof options.outputUnreleased !== 'boolean') { options.outputUnreleased = true } @@ -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 = {} @@ -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] @@ -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, diff --git a/packages/conventional-changelog-core/package.json b/packages/conventional-changelog-core/package.json index ac3baf37d..8e1c9ce59 100644 --- a/packages/conventional-changelog-core/package.json +++ b/packages/conventional-changelog-core/package.json @@ -13,7 +13,7 @@ "log" ], "engines": { - "node": ">=10" + "node": ">=14" }, "license": "MIT", "files": [ @@ -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", diff --git a/packages/conventional-changelog-ember/package.json b/packages/conventional-changelog-ember/package.json index 21855ff11..46ae31153 100644 --- a/packages/conventional-changelog-ember/package.json +++ b/packages/conventional-changelog-ember/package.json @@ -17,7 +17,7 @@ ], "author": "Steve Mao", "engines": { - "node": ">=10" + "node": ">=14" }, "license": "ISC", "files": [ diff --git a/packages/conventional-changelog-eslint/package.json b/packages/conventional-changelog-eslint/package.json index 6578e6d88..046444d5b 100644 --- a/packages/conventional-changelog-eslint/package.json +++ b/packages/conventional-changelog-eslint/package.json @@ -17,7 +17,7 @@ ], "author": "Steve Mao", "engines": { - "node": ">=10" + "node": ">=14" }, "license": "ISC", "files": [ diff --git a/packages/conventional-changelog-express/package.json b/packages/conventional-changelog-express/package.json index c7e9bca86..3068caefa 100644 --- a/packages/conventional-changelog-express/package.json +++ b/packages/conventional-changelog-express/package.json @@ -17,7 +17,7 @@ ], "author": "Steve Mao", "engines": { - "node": ">=10" + "node": ">=14" }, "license": "ISC", "files": [ diff --git a/packages/conventional-changelog-jquery/package.json b/packages/conventional-changelog-jquery/package.json index 4f6373b2a..e40699237 100644 --- a/packages/conventional-changelog-jquery/package.json +++ b/packages/conventional-changelog-jquery/package.json @@ -17,7 +17,7 @@ ], "author": "Steve Mao", "engines": { - "node": ">=10" + "node": ">=14" }, "license": "ISC", "files": [ diff --git a/packages/conventional-changelog-jshint/package.json b/packages/conventional-changelog-jshint/package.json index 598f1ebe0..e75628d7c 100644 --- a/packages/conventional-changelog-jshint/package.json +++ b/packages/conventional-changelog-jshint/package.json @@ -17,7 +17,7 @@ ], "author": "Steve Mao", "engines": { - "node": ">=10" + "node": ">=14" }, "license": "ISC", "files": [ diff --git a/packages/conventional-changelog-preset-loader/package.json b/packages/conventional-changelog-preset-loader/package.json index eebf31660..e07980bd2 100644 --- a/packages/conventional-changelog-preset-loader/package.json +++ b/packages/conventional-changelog-preset-loader/package.json @@ -13,7 +13,7 @@ ], "license": "MIT", "engines": { - "node": ">=10" + "node": ">=14" }, "files": [ "index.js" diff --git a/packages/conventional-changelog-writer/cli.js b/packages/conventional-changelog-writer/cli.js index bf002ac4c..2b69002cb 100755 --- a/packages/conventional-changelog-writer/cli.js +++ b/packages/conventional-changelog-writer/cli.js @@ -1,7 +1,6 @@ #!/usr/bin/env node 'use strict' const conventionalChangelogWriter = require('./') -const forEach = require('lodash').forEach const fs = require('fs') const meow = require('meow') const path = require('path') @@ -32,13 +31,8 @@ const cli = meow(` } }) -const filePaths = [] const flags = cli.flags - -forEach(cli.input, function (input) { - filePaths.push(input) -}) - +const filePaths = cli.input const length = filePaths.length let templateContext diff --git a/packages/conventional-changelog-writer/index.js b/packages/conventional-changelog-writer/index.js index d627189a1..1ce593bc1 100644 --- a/packages/conventional-changelog-writer/index.js +++ b/packages/conventional-changelog-writer/index.js @@ -6,20 +6,20 @@ const readFileSync = require('fs').readFileSync const semverValid = require('semver').valid const through = require('through2') const util = require('./lib/util') -const _ = require('lodash') function conventionalChangelogWriterInit (context, options) { - context = _.extend({ + context = { commit: 'commits', issue: 'issues', - date: dateFormat(new Date(), 'yyyy-mm-dd', true) - }, context) + date: dateFormat(new Date(), 'yyyy-mm-dd', true), + ...context + } - if (!_.isBoolean(context.linkReferences) && (context.repository || context.repoUrl) && context.commit && context.issue) { + if (typeof context.linkReferences !== 'boolean' && (context.repository || context.repoUrl) && context.commit && context.issue) { context.linkReferences = true } - options = _.assign({ + options = { groupBy: 'type', commitsSort: 'header', noteGroupsSort: 'title', @@ -38,13 +38,14 @@ function conventionalChangelogWriterInit (context, options) { mainTemplate: readFileSync(join(__dirname, 'templates/template.hbs'), 'utf-8'), headerPartial: readFileSync(join(__dirname, 'templates/header.hbs'), 'utf-8'), commitPartial: readFileSync(join(__dirname, 'templates/commit.hbs'), 'utf-8'), - footerPartial: readFileSync(join(__dirname, 'templates/footer.hbs'), 'utf-8') - }, options) + footerPartial: readFileSync(join(__dirname, 'templates/footer.hbs'), 'utf-8'), + ...options + } - if ((!_.isFunction(options.transform) && _.isObject(options.transform)) || _.isUndefined(options.transform)) { - options.transform = _.assign({ + if (!options.transform || typeof options.transform === 'object') { + options.transform = { hash: function (hash) { - if (_.isString(hash)) { + if (typeof hash === 'string') { return hash.substring(0, 7) } }, @@ -57,16 +58,17 @@ function conventionalChangelogWriterInit (context, options) { } return dateFormat(date, 'yyyy-mm-dd', true) - } - }, options.transform) + }, + ...options.transform + } } let generateOn = options.generateOn - if (_.isString(generateOn)) { + if (typeof generateOn === 'string') { generateOn = function (commit) { - return !_.isUndefined(commit[options.generateOn]) + return typeof commit[options.generateOn] !== 'undefined' } - } else if (!_.isFunction(generateOn)) { + } else if (typeof generateOn !== 'function') { generateOn = function () { return false } diff --git a/packages/conventional-changelog-writer/lib/util.js b/packages/conventional-changelog-writer/lib/util.js index 8d4446e2d..852d22bbf 100644 --- a/packages/conventional-changelog-writer/lib/util.js +++ b/packages/conventional-changelog-writer/lib/util.js @@ -2,7 +2,6 @@ const conventionalCommitsFilter = require('conventional-commits-filter') const Handlebars = require('handlebars') const semver = require('semver') -const _ = require('lodash') const stringify = require('json-stringify-safe') function compileTemplates (templates) { @@ -12,23 +11,25 @@ function compileTemplates (templates) { const footerPartial = templates.footerPartial const partials = templates.partials - if (_.isString(headerPartial)) { + if (typeof headerPartial === 'string') { Handlebars.registerPartial('header', headerPartial) } - if (_.isString(commitPartial)) { + if (typeof commitPartial === 'string') { Handlebars.registerPartial('commit', commitPartial) } - if (_.isString(footerPartial)) { + if (typeof footerPartial === 'string') { Handlebars.registerPartial('footer', footerPartial) } - _.forEach(partials, function (partial, name) { - if (_.isString(partial)) { - Handlebars.registerPartial(name, partial) - } - }) + if (partials) { + Object.entries(partials).forEach(function ([name, partial]) { + if (typeof partial === 'string') { + Handlebars.registerPartial(name, partial) + } + }) + } return Handlebars.compile(main, { noEscape: true @@ -36,7 +37,7 @@ function compileTemplates (templates) { } function functionify (strOrArr) { - if (strOrArr && !_.isFunction(strOrArr)) { + if (strOrArr && typeof strOrArr !== 'function') { return (a, b) => { let str1 = '' let str2 = '' @@ -58,11 +59,19 @@ function functionify (strOrArr) { function getCommitGroups (groupBy, commits, groupsSort, commitsSort) { const commitGroups = [] - const commitGroupsObj = _.groupBy(commits, function (commit) { - return commit[groupBy] || '' - }) + const commitGroupsObj = commits.reduce(function (groups, commit) { + const key = commit[groupBy] || '' + + if (groups[key]) { + groups[key].push(commit) + } else { + groups[key] = [commit] + } + + return groups + }, {}) - _.forEach(commitGroupsObj, function (commits, title) { + Object.entries(commitGroupsObj).forEach(function ([title, commits]) { if (title === '') { title = false } @@ -87,11 +96,11 @@ function getCommitGroups (groupBy, commits, groupsSort, commitsSort) { function getNoteGroups (notes, noteGroupsSort, notesSort) { const retGroups = [] - _.forEach(notes, function (note) { + notes.forEach(function (note) { const title = note.title let titleExists = false - _.forEach(retGroups, function (group) { + retGroups.forEach(function (group) { if (group.title === title) { titleExists = true group.notes.push(note) @@ -112,7 +121,7 @@ function getNoteGroups (notes, noteGroupsSort, notesSort) { } if (notesSort) { - _.forEach(retGroups, function (group) { + retGroups.forEach(function (group) { group.notes.sort(notesSort) }) } @@ -120,6 +129,28 @@ function getNoteGroups (notes, noteGroupsSort, notesSort) { return retGroups } +function get (context, path) { + const parts = path.split('.') + + return parts.reduce((context, key) => + context ? context[key] : context + , context) +} + +function immutableSet (context, path, value) { + const parts = Array.isArray(path) ? path.slice() : path.split('.') + const key = parts.shift() + + if (!key) { + return context + } + + return { + ...context, + [key]: parts.length ? immutableSet(context[key], parts, value) : value + } +} + function processCommit (chunk, transform, context) { let commit @@ -127,9 +158,11 @@ function processCommit (chunk, transform, context) { chunk = JSON.parse(chunk) } catch (e) {} - commit = _.cloneDeep(chunk) + commit = { + ...chunk + } - if (_.isFunction(transform)) { + if (typeof transform === 'function') { commit = transform(commit, context) if (commit) { @@ -139,17 +172,19 @@ function processCommit (chunk, transform, context) { return commit } - _.forEach(transform, function (el, path) { - let value = _.get(commit, path) + if (transform) { + Object.entries(transform).forEach(function ([path, el]) { + let value = get(commit, path) - if (_.isFunction(el)) { - value = el(value, path) - } else { - value = el - } + if (typeof el === 'function') { + value = el(value, path) + } else { + value = el + } - _.set(commit, path, value) - }) + commit = immutableSet(commit, path, value) + }) + } commit.raw = chunk @@ -169,27 +204,35 @@ function getExtraContext (commits, notes, options) { } function generate (options, commits, context, keyCommit) { - let notes = [] + const notes = [] let filteredCommits const compiled = compileTemplates(options) if (options.ignoreReverted) { filteredCommits = conventionalCommitsFilter(commits) } else { - filteredCommits = _.clone(commits) + filteredCommits = commits.slice() } - _.forEach(filteredCommits, function (commit) { - _.map(commit.notes, function (note) { - note.commit = commit + filteredCommits = filteredCommits.map((commit) => ({ + ...commit, + notes: commit.notes.map((note) => { + const commitNote = { + ...note, + commit + } + + notes.push(commitNote) - return note + return commitNote }) + })) - notes = notes.concat(commit.notes) - }) - - context = _.merge({}, context, keyCommit, getExtraContext(filteredCommits, notes, options)) + context = { + ...context, + ...keyCommit, + ...getExtraContext(filteredCommits, notes, options) + } if (keyCommit && keyCommit.committerDate) { context.date = keyCommit.committerDate diff --git a/packages/conventional-changelog-writer/package.json b/packages/conventional-changelog-writer/package.json index aac12d10d..49f3e6329 100644 --- a/packages/conventional-changelog-writer/package.json +++ b/packages/conventional-changelog-writer/package.json @@ -17,7 +17,7 @@ }, "license": "MIT", "engines": { - "node": ">=10" + "node": ">=14" }, "files": [ "index.js", @@ -40,7 +40,6 @@ "dateformat": "^3.0.0", "handlebars": "^4.7.7", "json-stringify-safe": "^5.0.1", - "lodash": "^4.17.15", "meow": "^8.0.0", "semver": "^6.0.0", "split": "^1.0.0", diff --git a/packages/conventional-changelog-writer/templates/commit.hbs b/packages/conventional-changelog-writer/templates/commit.hbs index 28d929376..3b2cd6853 100644 --- a/packages/conventional-changelog-writer/templates/commit.hbs +++ b/packages/conventional-changelog-writer/templates/commit.hbs @@ -1,7 +1,7 @@ * {{header}} -{{~!-- commit link --}} {{#if @root.linkReferences~}} - ([{{hash}}]( +{{~!-- commit link --}} +{{~#if @root.linkReferences}} ([{{hash}}]( {{~#if @root.repository}} {{~#if @root.host}} {{~@root.host}}/ @@ -14,9 +14,7 @@ {{~@root.repoUrl}} {{~/if}}/ {{~@root.commit}}/{{hash}})) -{{~else}} - {{~hash}} -{{~/if}} +{{~else if hash}} {{hash}}{{~/if}} {{~!-- commit references --}} {{~#if references~}} diff --git a/packages/conventional-changelog-writer/test/index.spec.js b/packages/conventional-changelog-writer/test/index.spec.js index 1310bca74..e18cec6b7 100644 --- a/packages/conventional-changelog-writer/test/index.spec.js +++ b/packages/conventional-changelog-writer/test/index.spec.js @@ -5,7 +5,6 @@ const expect = require('chai').expect const mocha = require('mocha') const describe = mocha.describe const it = mocha.it -const map = require('lodash').map const through = require('through2') const today = require('dateformat')(new Date(), 'yyyy-mm-dd', true) @@ -223,7 +222,7 @@ describe('conventionalChangelogWriter', function () { const changelog = conventionalChangelogWriter.parseArray(commits, {}, { transform: { notes: function (notes) { - map(notes, function (note) { + notes.map(function (note) { if (note.title === 'BREAKING CHANGE') { note.title = 'BREAKING CHANGES' } @@ -242,7 +241,7 @@ describe('conventionalChangelogWriter', function () { .pipe(conventionalChangelogWriter({}, { transform: { notes: function (notes) { - map(notes, function (note) { + notes.map(function (note) { if (note.title === 'BREAKING CHANGE') { note.title = 'BREAKING CHANGES' } @@ -764,23 +763,23 @@ describe('conventionalChangelogWriter', function () { }) expect(changelog.trim()).to.equal(dedent(`## 1.0.1 (2015-04-07) - * feat(scope): broadcast $destroy event on scope destruction - - - + * feat(scope): broadcast $destroy event on scope destruction + + + ## 2.0.1 (2015-04-07) - - * fix(ng-list): Allow custom separator - - - + + * fix(ng-list): Allow custom separator + + + ## 4.0.1 (2015-04-07) - - * perf(template): tweak - * refactor(name): rename this module to conventional-changelog-writer - - - + + * perf(template): tweak + * refactor(name): rename this module to conventional-changelog-writer + + + ## (xxxx-xx-xx)`).replace('xxxx-xx-xx', today)) upstream .pipe(conventionalChangelogWriter({}, { @@ -973,7 +972,7 @@ describe('conventionalChangelogWriter', function () { upstream .pipe(conventionalChangelogWriter()) .pipe(through(function (chunk, enc, cb) { - expect(chunk.toString()).to.equal('## (' + today + ')\n\n* bla \n\n\n\n') + expect(chunk.toString()).to.equal('## (' + today + ')\n\n* bla\n\n\n\n') i++ cb(null) diff --git a/packages/conventional-changelog/package.json b/packages/conventional-changelog/package.json index fa9deb00f..d75a3aeeb 100644 --- a/packages/conventional-changelog/package.json +++ b/packages/conventional-changelog/package.json @@ -13,7 +13,7 @@ "log" ], "engines": { - "node": ">=10" + "node": ">=14" }, "license": "MIT", "files": [ diff --git a/packages/conventional-commits-filter/index.js b/packages/conventional-commits-filter/index.js index be4dfbf50..000b5f016 100644 --- a/packages/conventional-commits-filter/index.js +++ b/packages/conventional-commits-filter/index.js @@ -1,6 +1,6 @@ 'use strict' -const isMatch = require('lodash/isMatch') +const isMatch = require('lodash.ismatch') const modifyValues = require('modify-values') function modifyValue (val) { diff --git a/packages/conventional-commits-filter/package.json b/packages/conventional-commits-filter/package.json index 442e68d4b..5b79877b5 100644 --- a/packages/conventional-commits-filter/package.json +++ b/packages/conventional-commits-filter/package.json @@ -16,7 +16,7 @@ "url": "https://github.com/stevemao" }, "engines": { - "node": ">=10" + "node": ">=14" }, "files": [ "index.js" @@ -28,7 +28,7 @@ "commits" ], "dependencies": { - "lodash": "^4.17.15", + "lodash.ismatch": "^4.4.0", "modify-values": "^1.0.0" }, "scripts": { diff --git a/packages/conventional-commits-parser/cli.js b/packages/conventional-commits-parser/cli.js index debe09dec..fcc23a96f 100755 --- a/packages/conventional-commits-parser/cli.js +++ b/packages/conventional-commits-parser/cli.js @@ -1,7 +1,6 @@ #!/usr/bin/env node 'use strict' const conventionalCommitsParser = require('./') -const forEach = require('lodash').forEach const fs = require('fs') const isTextPath = require('is-text-path') const JSONStream = require('JSONStream') @@ -83,7 +82,7 @@ const cli = meow(` } }) -forEach(cli.input, function (arg) { +cli.input.forEach(function (arg) { if (isTextPath(arg)) { filePaths.push(arg) } else { diff --git a/packages/conventional-commits-parser/index.js b/packages/conventional-commits-parser/index.js index c62f2905d..94618f9ed 100644 --- a/packages/conventional-commits-parser/index.js +++ b/packages/conventional-commits-parser/index.js @@ -3,10 +3,9 @@ const parser = require('./lib/parser') const regex = require('./lib/regex') const through = require('through2') -const _ = require('lodash') function assignOpts (options) { - options = _.extend({ + options = { headerPattern: /^(\w*)(?:\(([\w$.\-*/ ]*)\))?: (.*)$/, headerCorrespondence: ['type', 'scope', 'subject'], referenceActions: [ @@ -27,8 +26,9 @@ function assignOpts (options) { revertCorrespondence: ['header', 'hash'], warn: function () {}, mergePattern: null, - mergeCorrespondence: null - }, options) + mergeCorrespondence: null, + ...options + } if (typeof options.headerPattern === 'string') { options.headerPattern = new RegExp(options.headerPattern) diff --git a/packages/conventional-commits-parser/lib/parser.js b/packages/conventional-commits-parser/lib/parser.js index fc9c94261..a88b29581 100644 --- a/packages/conventional-commits-parser/lib/parser.js +++ b/packages/conventional-commits-parser/lib/parser.js @@ -1,5 +1,4 @@ 'use strict' -const _ = require('lodash') const CATCH_ALL = /()(.+)/gi const SCISSOR = '# ------------------------ >8 ------------------------' @@ -91,11 +90,11 @@ function parser (raw, options, regex) { throw new TypeError('Expected a raw commit') } - if (_.isEmpty(options)) { + if (!options || (typeof options === 'object' && !Object.keys(options).length)) { throw new TypeError('Expected options') } - if (_.isEmpty(regex)) { + if (!regex) { throw new TypeError('Expected regex') } @@ -112,15 +111,15 @@ function parser (raw, options, regex) { let continueNote = false let isBody = true - const headerCorrespondence = _.map(options.headerCorrespondence, function (part) { + const headerCorrespondence = options.headerCorrespondence?.map(function (part) { return part.trim() - }) - const revertCorrespondence = _.map(options.revertCorrespondence, function (field) { + }) || [] + const revertCorrespondence = options.revertCorrespondence?.map(function (field) { return field.trim() - }) - const mergeCorrespondence = _.map(options.mergeCorrespondence, function (field) { + }) || [] + const mergeCorrespondence = options.mergeCorrespondence?.map(function (field) { return field.trim() - }) + }) || [] let body = null let footer = null @@ -166,7 +165,7 @@ function parser (raw, options, regex) { header = '' } - _.forEach(mergeCorrespondence, function (partName, index) { + mergeCorrespondence.forEach(function (partName, index) { const partValue = mergeMatch[index + 1] || null mergeParts[partName] = partValue }) @@ -174,30 +173,30 @@ function parser (raw, options, regex) { header = merge merge = null - _.forEach(mergeCorrespondence, function (partName) { + mergeCorrespondence.forEach(function (partName) { mergeParts[partName] = null }) } const headerMatch = header.match(options.headerPattern) if (headerMatch) { - _.forEach(headerCorrespondence, function (partName, index) { + headerCorrespondence.forEach(function (partName, index) { const partValue = headerMatch[index + 1] || null headerParts[partName] = partValue }) } else { - _.forEach(headerCorrespondence, function (partName) { + headerCorrespondence.forEach(function (partName) { headerParts[partName] = null }) } - Array.prototype.push.apply(references, getReferences(header, { + references.push(...getReferences(header, { references: regex.references, referenceParts: regex.referenceParts })) // body or footer - _.forEach(lines, function (line) { + lines.forEach(function (line) { if (options.fieldPattern) { const fieldMatch = options.fieldPattern.exec(line) @@ -285,7 +284,7 @@ function parser (raw, options, regex) { const revertMatch = raw.match(options.revertPattern) if (revertMatch) { revert = {} - _.forEach(revertCorrespondence, function (partName, index) { + revertCorrespondence.forEach(function (partName, index) { const partValue = revertMatch[index + 1] || null revert[partName] = partValue }) @@ -293,13 +292,13 @@ function parser (raw, options, regex) { revert = null } - _.map(notes, function (note) { + notes.forEach(function (note) { note.text = trimOffNewlines(note.text) - - return note }) - const msg = _.merge(headerParts, mergeParts, { + const msg = { + ...headerParts, + ...mergeParts, merge: merge, header: header, body: body ? trimOffNewlines(body) : null, @@ -307,8 +306,9 @@ function parser (raw, options, regex) { notes: notes, references: references, mentions: mentions, - revert: revert - }, otherFields) + revert: revert, + ...otherFields + } return msg } diff --git a/packages/conventional-commits-parser/package.json b/packages/conventional-commits-parser/package.json index 626dda771..0b52be06d 100644 --- a/packages/conventional-commits-parser/package.json +++ b/packages/conventional-commits-parser/package.json @@ -17,7 +17,7 @@ }, "license": "MIT", "engines": { - "node": ">=10" + "node": ">=14" }, "files": [ "index.js", @@ -35,7 +35,6 @@ "dependencies": { "is-text-path": "^1.0.1", "JSONStream": "^1.0.4", - "lodash": "^4.17.15", "meow": "^8.0.0", "split2": "^3.0.0", "through2": "^4.0.0" diff --git a/packages/conventional-commits-parser/test/index.spec.js b/packages/conventional-commits-parser/test/index.spec.js index 957c7a9eb..ca56c6477 100644 --- a/packages/conventional-commits-parser/test/index.spec.js +++ b/packages/conventional-commits-parser/test/index.spec.js @@ -4,7 +4,6 @@ const mocha = require('mocha') const describe = mocha.describe const it = mocha.it const expect = require('chai').expect -const forEach = require('lodash').forEach const through = require('through2') describe('conventionalCommitsParser', function () { @@ -34,7 +33,7 @@ describe('conventionalCommitsParser', function () { 'd7a40a29214f37d469e57d730dfd042b639d4d1f' ] - forEach(commits, function (commit) { + commits.forEach(function (commit) { stream.write(commit) }) stream.end() @@ -82,7 +81,7 @@ describe('conventionalCommitsParser', function () { 'bla bla bla\n\n' ] - forEach(commits, function (commit) { + commits.forEach(function (commit) { stream.write(commit) }) stream.end() @@ -150,7 +149,7 @@ describe('conventionalCommitsParser', function () { const stream = through() let i = 0 - forEach(commits, function (commit) { + commits.forEach(function (commit) { stream.write(commit) }) stream.end() @@ -211,7 +210,7 @@ describe('conventionalCommitsParser', function () { const stream = through() let i = 0 - forEach(commits, function (commit) { + commits.forEach(function (commit) { stream.write(commit) }) stream.write('blabla\n-hash-\n9b1aff905b638aa274a5fc8f88662df446d374bd') diff --git a/packages/conventional-commits-parser/test/parser.spec.js b/packages/conventional-commits-parser/test/parser.spec.js index 1891653a1..993754fd0 100644 --- a/packages/conventional-commits-parser/test/parser.spec.js +++ b/packages/conventional-commits-parser/test/parser.spec.js @@ -4,7 +4,6 @@ const mocha = require('mocha') const describe = mocha.describe const it = mocha.it const beforeEach = mocha.beforeEach -const _ = require('lodash') const parser = require('../lib/parser') const regex = require('../lib/regex') @@ -230,7 +229,10 @@ describe('parser', function () { }) it('should ignore comments according to commentChar', function () { - const commentOptions = _.assign({}, options, { commentChar: '#' }) + const commentOptions = { + ...options, + commentChar: '#' + } expect(parser('# comment', commentOptions, reg)).to.eql({ merge: null, @@ -276,7 +278,10 @@ describe('parser', function () { }) it('should respect commentChar config', function () { - const commentOptions = _.assign({}, options, { commentChar: '*' }) + const commentOptions = { + ...options, + commentChar: '*' + } expect(parser('* comment', commentOptions, reg)).to.eql({ merge: null, diff --git a/packages/conventional-recommended-bump/package.json b/packages/conventional-recommended-bump/package.json index 2e24a8145..b36374e9d 100644 --- a/packages/conventional-recommended-bump/package.json +++ b/packages/conventional-recommended-bump/package.json @@ -17,7 +17,7 @@ }, "license": "MIT", "engines": { - "node": ">=10" + "node": ">=14" }, "files": [ "index.js", diff --git a/packages/git-raw-commits/index.js b/packages/git-raw-commits/index.js index c2fbabc83..aebb8efc5 100644 --- a/packages/git-raw-commits/index.js +++ b/packages/git-raw-commits/index.js @@ -4,7 +4,6 @@ const dargs = require('dargs') const execFile = require('child_process').execFile const split = require('split2') const stream = require('stream') -const template = require('lodash/template') const through = require('through2') const DELIMITER = '------------------------ >8 ------------------------' @@ -24,7 +23,7 @@ function normalizeGitOpts (gitOpts) { } function getGitArgs (gitOpts) { - const gitFormat = template('--format=<%= format %>%n' + DELIMITER)(gitOpts) + const gitFormat = `--format=${gitOpts.format || ''}%n${DELIMITER}` const gitFromTo = [gitOpts.from, gitOpts.to].filter(Boolean).join('..') const gitArgs = ['log', gitFormat, gitFromTo] diff --git a/packages/git-raw-commits/package.json b/packages/git-raw-commits/package.json index cae640d3b..47f00e546 100644 --- a/packages/git-raw-commits/package.json +++ b/packages/git-raw-commits/package.json @@ -17,7 +17,7 @@ }, "license": "MIT", "engines": { - "node": ">=10" + "node": ">=14" }, "files": [ "index.js", @@ -34,7 +34,6 @@ ], "dependencies": { "dargs": "^7.0.0", - "lodash": "^4.17.15", "meow": "^8.0.0", "split2": "^3.0.0", "through2": "^4.0.0" diff --git a/packages/git-semver-tags/package.json b/packages/git-semver-tags/package.json index 295b5508d..2f2a27bd1 100644 --- a/packages/git-semver-tags/package.json +++ b/packages/git-semver-tags/package.json @@ -17,7 +17,7 @@ }, "license": "MIT", "engines": { - "node": ">=10" + "node": ">=14" }, "files": [ "index.js", diff --git a/packages/gulp-conventional-changelog/package.json b/packages/gulp-conventional-changelog/package.json index cbeb6151a..60f8bcadf 100644 --- a/packages/gulp-conventional-changelog/package.json +++ b/packages/gulp-conventional-changelog/package.json @@ -17,7 +17,7 @@ "url": "https://github.com/stevemao" }, "engines": { - "node": ">=10" + "node": ">=14" }, "scripts": { "test-windows": "mocha --timeout 30000" diff --git a/packages/standard-changelog/cli.js b/packages/standard-changelog/cli.js index ad45f65d1..4b997291b 100755 --- a/packages/standard-changelog/cli.js +++ b/packages/standard-changelog/cli.js @@ -6,7 +6,6 @@ const standardChangelog = require('./') const fs = require('fs') const meow = require('meow') const tempfile = require('tempfile') -const _ = require('lodash') const resolve = require('path').resolve const Readable = require('stream').Readable const rimraf = require('rimraf') @@ -90,7 +89,7 @@ const outfile = sameFile ? (flags.outfile || infile) : flags.outfile const append = flags.append const releaseCount = flags.firstRelease ? 0 : flags.releaseCount -const options = _.omitBy({ +const options = { preset: flags.preset, pkg: { path: flags.pkg @@ -98,7 +97,7 @@ const options = _.omitBy({ append: append, releaseCount: releaseCount, lernaPackage: flags.lernaPackage -}, _.isUndefined) +} if (flags.verbose) { options.warn = console.warn.bind(console) diff --git a/packages/standard-changelog/package.json b/packages/standard-changelog/package.json index 2cfa4f55a..22e8f7680 100644 --- a/packages/standard-changelog/package.json +++ b/packages/standard-changelog/package.json @@ -19,7 +19,7 @@ ], "license": "MIT", "engines": { - "node": ">=10" + "node": ">=14" }, "files": [ "index.js", @@ -32,7 +32,6 @@ "conventional-changelog-core": "^4.2.1", "figures": "^3.0.0", "fs-access": "^1.0.0", - "lodash": "^4.17.15", "meow": "^8.0.0", "rimraf": "^3.0.0", "sprintf-js": "^1.1.1", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index f13ed2966..2afe34a93 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -100,13 +100,11 @@ importers: specifiers: add-stream: ^1.0.0 conventional-changelog: ^3.1.24 - lodash: ^4.17.15 meow: ^8.0.0 tempfile: ^3.0.0 dependencies: add-stream: 1.0.0 conventional-changelog: link:../conventional-changelog - lodash: 4.17.21 meow: 8.1.2 tempfile: 3.0.0 @@ -119,11 +117,9 @@ importers: packages/conventional-changelog-conventionalcommits: specifiers: compare-func: ^2.0.0 - lodash: ^4.17.15 q: ^1.5.1 dependencies: compare-func: 2.0.0 - lodash: 4.17.21 q: 1.5.1 packages/conventional-changelog-core: @@ -137,7 +133,6 @@ importers: 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 @@ -152,7 +147,6 @@ importers: git-raw-commits: link:../git-raw-commits git-remote-origin-url: 2.0.0 git-semver-tags: link:../git-semver-tags - lodash: 4.17.21 normalize-package-data: 3.0.3 q: 1.5.1 read-pkg: 3.0.0 @@ -211,7 +205,6 @@ importers: forceable-tty: ^0.1.0 handlebars: ^4.7.7 json-stringify-safe: ^5.0.1 - lodash: ^4.17.15 meow: ^8.0.0 semver: ^6.0.0 split: ^1.0.0 @@ -221,7 +214,6 @@ importers: dateformat: 3.0.3 handlebars: 4.7.7 json-stringify-safe: 5.0.1 - lodash: 4.17.21 meow: 8.1.2 semver: 6.3.0 split: 1.0.1 @@ -232,10 +224,10 @@ importers: packages/conventional-commits-filter: specifiers: - lodash: ^4.17.15 + lodash.ismatch: ^4.4.0 modify-values: ^1.0.0 dependencies: - lodash: 4.17.21 + lodash.ismatch: 4.4.0 modify-values: 1.0.1 packages/conventional-commits-parser: @@ -243,14 +235,12 @@ importers: JSONStream: ^1.0.4 forceable-tty: ^0.1.0 is-text-path: ^1.0.1 - lodash: ^4.17.15 meow: ^8.0.0 split2: ^3.0.0 through2: ^4.0.0 dependencies: JSONStream: 1.3.5 is-text-path: 1.0.1 - lodash: 4.17.21 meow: 8.1.2 split2: 3.2.2 through2: 4.0.2 @@ -283,13 +273,11 @@ importers: packages/git-raw-commits: specifiers: dargs: ^7.0.0 - lodash: ^4.17.15 meow: ^8.0.0 split2: ^3.0.0 through2: ^4.0.0 dependencies: dargs: 7.0.0 - lodash: 4.17.21 meow: 8.1.2 split2: 3.2.2 through2: 4.0.2 @@ -328,7 +316,6 @@ importers: conventional-changelog-core: ^4.2.1 figures: ^3.0.0 fs-access: ^1.0.0 - lodash: ^4.17.15 meow: ^8.0.0 rimraf: ^3.0.0 sprintf-js: ^1.1.1 @@ -340,7 +327,6 @@ importers: conventional-changelog-core: link:../conventional-changelog-core figures: 3.2.0 fs-access: 1.0.1 - lodash: 4.17.21 meow: 8.1.2 rimraf: 3.0.2 sprintf-js: 1.1.2 @@ -2266,6 +2252,10 @@ packages: resolution: {integrity: sha512-z+Uw/vLuy6gQe8cfaFWD7p0wVv8fJl3mbzXh33RS+0oW2wvUqiRXiQ69gLWSLpgB5/6sU+r6BlQR0MBILadqTQ==} dev: true + /lodash.ismatch/4.4.0: + resolution: {integrity: sha512-fPMfXjGQEV9Xsq/8MTSgUf255gawYRbjwMyDbcvDhXgV7enSZA0hynz6vMPnpAb5iONEzBHBPsT+0zes5Z301g==} + dev: false + /lodash.merge/4.6.2: resolution: {integrity: sha512-0KpjqXRVvrYyCsX1swR/XTK0va6VQkQM6MNo7PqW77ByjAhoARA8EfrP1N4+KlKj8YS0ZUCtRT/YUuhyYDujIQ==} dev: true @@ -2274,10 +2264,6 @@ packages: resolution: {integrity: sha512-jttmRe7bRse52OsWIMDLaXxWqRAmtIUccAQ3garviCqJjafXOfNMO0yMfNpdD6zbGaTU0P5Nz7e7gAT6cKmJRw==} dev: true - /lodash/4.17.21: - resolution: {integrity: sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==} - dev: false - /log-driver/1.2.7: resolution: {integrity: sha512-U7KCmLdqsGHBLeWqYlFA0V0Sl6P08EE1ZrmA9cxjUE0WVqT9qnyVDPz1kzpFEP0jdJuFnasWIfSd7fsaNXkpbg==} engines: {node: '>=0.8.6'}