Skip to content

Commit 8cf9e86

Browse files
Trotttargos
andauthored
chore: move to ESM, update all dependencies (#113)
* chore: update nopt from 6.x to 7.0.0 nopt@7 drops support for Node.js 12.x so we'll drop support too. BREAKING CHANGE: drop support for Node.js 12.x * chore: switch to ESM in preparation for chalk update * chore: update chalk 4.x to 5.2.0 * Update .github/workflows/node.js.yml Co-authored-by: Michaël Zasso <[email protected]> * Update bin/cmd.mjs Co-authored-by: Michaël Zasso <[email protected]> * Update lib/tap.mjs Co-authored-by: Michaël Zasso <[email protected]> * Update lib/utils.mjs Co-authored-by: Michaël Zasso <[email protected]> * Update lib/utils.mjs Co-authored-by: Michaël Zasso <[email protected]> * Update lib/utils.mjs Co-authored-by: Michaël Zasso <[email protected]> * Update lib/utils.mjs Co-authored-by: Michaël Zasso <[email protected]> * Update lib/utils.mjs Co-authored-by: Michaël Zasso <[email protected]> * Update bin/cmd.mjs Co-authored-by: Michaël Zasso <[email protected]> * Update lib/format-pretty.mjs Co-authored-by: Michaël Zasso <[email protected]> * Update lib/utils.mjs Co-authored-by: Michaël Zasso <[email protected]> * Update test/utils-test.mjs Co-authored-by: Michaël Zasso <[email protected]> * Update lib/validator.mjs Co-authored-by: Michaël Zasso <[email protected]> * Update test/cli-test.mjs Co-authored-by: Michaël Zasso <[email protected]> * Update test/validator.mjs Co-authored-by: Michaël Zasso <[email protected]> * Update test/cli-test.mjs Co-authored-by: Michaël Zasso <[email protected]> * Update test/cli-test.mjs Co-authored-by: Michaël Zasso <[email protected]> * fixup! Update test/cli-test.mjs * Update test/validator.mjs Co-authored-by: Michaël Zasso <[email protected]> * fixup! Update test/validator.mjs * fixup: use package.json type field rather than .mjs file extension --------- Co-authored-by: Michaël Zasso <[email protected]>
1 parent e172a82 commit 8cf9e86

33 files changed

+136
-174
lines changed

.github/workflows/node.js.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ jobs:
1616

1717
strategy:
1818
matrix:
19-
node-version: [12.x, 14.x, 16.x, 17.x, 18.x, 19.x]
19+
node-version: [14.x, 16.x, 18.x, 19.x]
2020

2121
steps:
2222
- uses: actions/checkout@v3

bin/cmd.js

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,18 @@
11
#!/usr/bin/env node
22

3-
'use strict'
4-
5-
const exec = require('child_process').exec
6-
const fs = require('fs')
7-
const http = require('http')
8-
const https = require('https')
9-
const nopt = require('nopt')
10-
const path = require('path')
11-
const pretty = require('../lib/format-pretty')
12-
const formatTap = require('../lib/format-tap')
13-
const Validator = require('../lib')
14-
const Tap = require('../lib/tap')
15-
const utils = require('../lib/utils')
16-
const subsystem = require('../lib/rules/subsystem')
3+
import { exec } from 'node:child_process'
4+
import fs from 'node:fs'
5+
import http from 'node:http'
6+
import https from 'node:https'
7+
import path from 'node:path'
8+
import nopt from 'nopt'
9+
import pretty from '../lib/format-pretty.js'
10+
import formatTap from '../lib/format-tap.js'
11+
import Validator from '../lib/validator.js'
12+
import Tap from '../lib/tap.js'
13+
import * as utils from '../lib/utils.js'
14+
import subsystem from '../lib/rules/subsystem.js'
15+
1716
const knownOpts = {
1817
help: Boolean,
1918
version: Boolean,
@@ -34,14 +33,19 @@ const shortHand = {
3433
}
3534

3635
const parsed = nopt(knownOpts, shortHand)
37-
const usage = require('help')()
3836

3937
if (parsed.help) {
40-
usage()
38+
const usagePath = path.join(new URL(import.meta.url).pathname, '../usage.txt')
39+
const help = await fs.promises.readFile(usagePath, 'utf8')
40+
console.log(help)
41+
process.exit(0)
4142
}
4243

4344
if (parsed.version) {
44-
console.log('core-validate-commit', 'v' + require('../package').version)
45+
const pkgJsonPath = path.join(new URL(import.meta.url).pathname, '../../package.json')
46+
const pkgJson = await fs.promises.readFile(pkgJsonPath, 'utf8')
47+
const { version } = JSON.parse(pkgJson)
48+
console.log(`core-validate-commit v${version}`)
4549
process.exit(0)
4650
}
4751

index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
'use strict'
1+
import Validator from './lib/validator.js'
22

3-
module.exports = require('./lib')
3+
export default Validator

lib/format-pretty.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
1-
'use strict'
2-
3-
const chalk = require('chalk')
4-
const utils = require('./utils')
1+
import chalk from 'chalk'
2+
import * as utils from './utils.js'
53

64
const MAX_LINE_COL_LEN = 6
75

8-
module.exports = function formatPretty (context, msgs, validator, opts) {
6+
export default function formatPretty (context, msgs, validator, opts) {
97
opts = Object.assign({
108
detailed: false
119
}, opts)

lib/format-tap.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
'use strict'
2-
3-
module.exports = function formatTap (t, context, msgs, validator) {
1+
export default function formatTap (t, context, msgs, validator) {
42
for (const m of msgs) {
53
switch (m.level) {
64
case 'pass': {

lib/rule.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
'use strict'
2-
3-
module.exports = class Rule {
1+
export default class Rule {
42
constructor (opts) {
53
opts = Object.assign({
64
options: {},

lib/rules/co-authored-by-is-trailer.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
'use strict'
2-
31
const id = 'co-authored-by-is-trailer'
42

5-
module.exports = {
3+
export default {
64
id,
75
meta: {
86
description: 'enforce that "Co-authored-by:" lines are trailers',

lib/rules/fixes-url.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
1-
'use strict'
2-
31
const id = 'fixes-url'
42
const github = new RegExp('^https://github\\.com/[\\w-]+/[\\w-]+/' +
53
'(issues|pull)/\\d+(#issuecomment-\\d+|#discussion_r\\d+)?$'
64
)
75

8-
module.exports = {
6+
export default {
97
id,
108
meta: {
119
description: 'enforce format of Fixes URLs',

lib/rules/index.js

Lines changed: 0 additions & 12 deletions
This file was deleted.

lib/rules/line-after-title.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
'use strict'
2-
31
const id = 'line-after-title'
42

5-
module.exports = {
3+
export default {
64
id,
75
meta: {
86
description: 'enforce a blank newline after the commit title',

0 commit comments

Comments
 (0)