Skip to content

Commit

Permalink
Remove the need for core-js and building with babel
Browse files Browse the repository at this point in the history
Seems like overkill to have so many dependendies and a build step to just support `import` and `export`

Breaking changes:
- Requires node 8.3 or higher
- Removes all `lib` files from npm package
  • Loading branch information
cookpete committed Apr 10, 2020
1 parent 868d4ec commit 2383380
Show file tree
Hide file tree
Showing 29 changed files with 331 additions and 1,828 deletions.
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
node_modules
package-lock.json
yarn.lock
npm-debug.log
/lib
/coverage
1 change: 0 additions & 1 deletion .npmignore
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
src
test
33 changes: 6 additions & 27 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
"name": "auto-changelog",
"version": "1.16.4",
"description": "Command line tool for generating a changelog from git tags and commit history",
"main": "./lib/index.js",
"main": "./src/index.js",
"bin": {
"auto-changelog": "./lib/index.js"
"auto-changelog": "./src/index.js"
},
"engines" : {
"node" : ">=7.6"
"engines": {
"node": ">=8.3"
},
"scripts": {
"lint": "standard --verbose | snazzy",
Expand All @@ -16,12 +16,9 @@
"test": "cross-env NODE_ENV=test mocha -r @babel/register test",
"test-coverage": "cross-env NODE_ENV=test nyc mocha test",
"report-coverage": "nyc report --reporter=json && codecov -f coverage/coverage-final.json",
"clean": "rimraf lib coverage",
"build": "babel src -d lib",
"preversion": "npm run lint && npm run test",
"version": "babel-node src/index.js --package && git add CHANGELOG.md",
"prepublishOnly": "npm run clean && npm run build",
"generate-test-data": "cross-env NODE_ENV=test babel-node scripts/generate-test-data.js"
"version": "node src/index.js --package && git add CHANGELOG.md",
"generate-test-data": "cross-env NODE_ENV=test node scripts/generate-test-data.js"
},
"author": "Pete Cook <[email protected]> (https://github.com/cookpete)",
"homepage": "https://github.com/CookPete/auto-changelog",
Expand All @@ -47,21 +44,15 @@
"license": "MIT",
"dependencies": {
"commander": "^5.0.0",
"core-js": "^3.6.4",
"handlebars": "^4.7.3",
"lodash.uniqby": "^4.7.0",
"node-fetch": "^2.6.0",
"parse-github-url": "^1.0.2",
"regenerator-runtime": "^0.13.5",
"semver": "^6.3.0"
},
"devDependencies": {
"@babel/cli": "^7.8.4",
"@babel/core": "^7.9.0",
"@babel/node": "^7.8.7",
"@babel/preset-env": "^7.9.0",
"@babel/register": "^7.9.0",
"babel-eslint": "^10.1.0",
"babel-plugin-istanbul": "^6.0.0",
"babel-plugin-rewire": "^1.2.0",
"chai": "^4.2.0",
Expand All @@ -70,20 +61,10 @@
"markdownlint-cli": "^0.22.0",
"mocha": "^7.1.1",
"nyc": "^15.0.0",
"rimraf": "^3.0.2",
"snazzy": "^8.0.0",
"standard": "^14.3.3"
},
"babel": {
"presets": [
[
"@babel/preset-env",
{
"useBuiltIns": "usage",
"corejs": 3
}
]
],
"env": {
"test": {
"plugins": [
Expand All @@ -94,7 +75,6 @@
}
},
"standard": {
"parser": "babel-eslint",
"ignore": [
"test/data/"
]
Expand All @@ -108,7 +88,6 @@
"report-dir": "./coverage",
"temp-dir": "./coverage/.nyc_output",
"require": [
"core-js/stable",
"@babel/register"
],
"reporter": [
Expand Down
14 changes: 7 additions & 7 deletions scripts/generate-test-data.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { join } from 'path'
import { readFile, writeFile } from '../src/utils'
import { __get__ } from '../src/commits'
import { parseReleases } from '../src/releases'
import { compileTemplate } from '../src/template'
import remotes from '../test/data/remotes'
const { join } = require('path')
const { readFile, writeFile } = require('../src/utils')
const { __get__ } = require('../src/commits')
const { parseReleases } = require('../src/releases')
const { compileTemplate } = require('../src/template')
const remotes = require('../test/data/remotes')

const parseCommits = __get__('parseCommits')

Expand All @@ -17,7 +17,7 @@ const options = {
}

function writeObject (filename, object) {
return writeFile(join(DATA_DIR, filename), `export default ${JSON.stringify(object, null, 2)}\n`)
return writeFile(join(DATA_DIR, filename), `module.exports = ${JSON.stringify(object, null, 2)}\n`)
}

async function writeTemplate (filename, template, releases) {
Expand Down
19 changes: 13 additions & 6 deletions src/commits.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import semver from 'semver'
import { cmd, isLink, encodeHTML, replaceText, getGitVersion } from './utils'
const semver = require('semver')
const { cmd, isLink, encodeHTML, replaceText, getGitVersion } = require('./utils')

export const COMMIT_SEPARATOR = '__AUTO_CHANGELOG_COMMIT_SEPARATOR__'
export const MESSAGE_SEPARATOR = '__AUTO_CHANGELOG_MESSAGE_SEPARATOR__'
const COMMIT_SEPARATOR = '__AUTO_CHANGELOG_COMMIT_SEPARATOR__'
const MESSAGE_SEPARATOR = '__AUTO_CHANGELOG_MESSAGE_SEPARATOR__'
const MATCH_COMMIT = /(.*)\n(.*)\n(.*)\n(.*)\n([\S\s]+)/
const MATCH_STATS = /(\d+) files? changed(?:, (\d+) insertions?...)?(?:, (\d+) deletions?...)?/
const BODY_FORMAT = '%B'
Expand All @@ -18,7 +18,7 @@ const MERGE_PATTERNS = [
/^Merge branch .+ into .+\n\n(.+)[\S\s]+See merge request [^!]*!(\d+)/ // GitLab merge
]

export async function fetchCommits (diff, remote, options = {}) {
async function fetchCommits (diff, remote, options = {}) {
const format = await getLogFormat()
const log = await cmd(`git log ${diff} --shortstat --pretty=format:${format} ${options.appendGitLog}`)
return parseCommits(log, remote, options)
Expand All @@ -37,7 +37,7 @@ function parseCommits (string, remote, options = {}) {
.map(commit => parseCommit(commit, remote, options))
}

export function parseCommit (commit, remote, options = {}) {
function parseCommit (commit, remote, options = {}) {
const [, hash, date, author, email, tail] = commit.match(MATCH_COMMIT)
const [body, stats] = tail.split(MESSAGE_SEPARATOR)
const message = encodeHTML(body)
Expand Down Expand Up @@ -132,3 +132,10 @@ function getMerge (commit, message, remote, options = {}) {
}
return null
}

module.exports = {
COMMIT_SEPARATOR,
MESSAGE_SEPARATOR,
fetchCommits,
parseCommit
}
14 changes: 6 additions & 8 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
#!/usr/bin/env node

import 'core-js/stable'
import run from './run'
const { run } = require('./run')

run(process.argv)
.catch(error => {
console.log('\n')
console.error(error)
process.exit(1)
})
run(process.argv).catch(error => {
console.log('\n')
console.error(error)
process.exit(1)
})
12 changes: 8 additions & 4 deletions src/releases.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import semver from 'semver'
import { fetchCommits } from './commits'
import { niceDate } from './utils'
const semver = require('semver')
const { fetchCommits } = require('./commits')
const { niceDate } = require('./utils')

const MERGE_COMMIT_PATTERN = /^Merge (remote-tracking )?branch '.+'/
const COMMIT_MESSAGE_PATTERN = /\n+([\S\s]+)/
Expand Down Expand Up @@ -35,7 +35,7 @@ async function createRelease (tag, previousTag, diff, remote, options, onParsed)
return release
}

export function parseReleases (tags, remote, latestVersion, options, onParsed) {
function parseReleases (tags, remote, latestVersion, options, onParsed) {
const releases = tags.map((tag, index, tags) => {
const previousTag = tags[index + 1]
const diff = previousTag ? `${previousTag}..${tag}` : tag
Expand Down Expand Up @@ -112,3 +112,7 @@ function getCompareLink (previousTag, tag, remote, { tagPrefix = '' }) {
const to = tag ? `${tagPrefix}${tag}` : 'HEAD'
return remote.getCompareLink(from, to)
}

module.exports = {
parseReleases
}
13 changes: 9 additions & 4 deletions src/remote.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import parseRepoURL from 'parse-github-url'
import { cmd } from './utils'
const parseRepoURL = require('parse-github-url')
const { cmd } = require('./utils')

export async function fetchRemote (options) {
async function fetchRemote (options) {
const remoteURL = await cmd(`git config --get remote.${options.remote}.url`)
return getRemote(remoteURL, options)
}

export function getRemote (remoteURL, options = {}) {
function getRemote (remoteURL, options = {}) {
const overrides = getOverrides(options)
if (!remoteURL) {
// No point warning if everything is overridden
Expand Down Expand Up @@ -89,3 +89,8 @@ function getOverrides ({ commitUrl, issueUrl, mergeUrl, compareUrl }) {
if (compareUrl) overrides.getCompareLink = (from, to) => compareUrl.replace('{from}', from).replace('{to}', to)
return overrides
}

module.exports = {
fetchRemote,
getRemote
}
22 changes: 13 additions & 9 deletions src/run.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { Command } from 'commander'
import semver from 'semver'
import { version } from '../package.json'
import { fetchRemote } from './remote'
import { fetchTags } from './tags'
import { parseReleases } from './releases'
import { compileTemplate } from './template'
import { parseLimit, readJson, writeFile, fileExists, updateLog, formatBytes } from './utils'
const { Command } = require('commander')
const semver = require('semver')
const { version } = require('../package.json')
const { fetchRemote } = require('./remote')
const { fetchTags } = require('./tags')
const { parseReleases } = require('./releases')
const { compileTemplate } = require('./template')
const { parseLimit, readJson, writeFile, fileExists, updateLog, formatBytes } = require('./utils')

const DEFAULT_OPTIONS = {
output: 'CHANGELOG.md',
Expand Down Expand Up @@ -83,7 +83,7 @@ async function getLatestVersion (options, tags) {
return null
}

export default async function run (argv) {
async function run (argv) {
const options = await getOptions(argv)
const log = string => options.stdout ? null : updateLog(string)
log('Fetching remote…')
Expand All @@ -103,3 +103,7 @@ export default async function run (argv) {
const bytes = Buffer.byteLength(changelog, 'utf8')
log(`${formatBytes(bytes)} written to ${options.output}\n`)
}

module.exports = {
run
}
10 changes: 7 additions & 3 deletions src/tags.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import semver from 'semver'
import { cmd } from './utils'
const semver = require('semver')
const { cmd } = require('./utils')

export async function fetchTags (options) {
async function fetchTags (options) {
const tags = (await cmd('git tag --sort=committerdate'))
.trim()
.split('\n')
Expand Down Expand Up @@ -44,3 +44,7 @@ function inferSemver (tag) {
}
return tag
}

module.exports = {
fetchTags
}
14 changes: 9 additions & 5 deletions src/template.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { join } from 'path'
import Handlebars from 'handlebars'
import fetch from 'node-fetch'
import { readFile, fileExists } from './utils'
const { join } = require('path')
const Handlebars = require('handlebars')
const fetch = require('node-fetch')
const { readFile, fileExists } = require('./utils')

const TEMPLATES_DIR = join(__dirname, '..', 'templates')
const MATCH_URL = /^https?:\/\/.+/
Expand Down Expand Up @@ -76,7 +76,7 @@ function cleanTemplate (template) {
.replace(/\n\n$/, '\n')
}

export async function compileTemplate ({ template, handlebarsSetup }, data) {
async function compileTemplate ({ template, handlebarsSetup }, data) {
if (handlebarsSetup) {
const setup = require(join(process.cwd(), handlebarsSetup))
if (typeof setup === 'function') {
Expand All @@ -89,3 +89,7 @@ export async function compileTemplate ({ template, handlebarsSetup }, data) {
}
return cleanTemplate(compile(data))
}

module.exports = {
compileTemplate
}
Loading

0 comments on commit 2383380

Please sign in to comment.