Skip to content

Commit

Permalink
feat!: move from CommonJS to ESM (#1144)
Browse files Browse the repository at this point in the history
BREAKING CHANGE: Now all packages, except gulp-conventional-changelog, are ESM-only.
  • Loading branch information
dangreen committed Sep 11, 2023
1 parent fac8045 commit c5b859d
Show file tree
Hide file tree
Showing 138 changed files with 449 additions and 643 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"type": "module",
"author": {
"name": "Steve Mao",
"email": "maochenyan@gmail.com",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
'use strict'

function createConventionalChangelogOpts (parserOpts, writerOpts) {
export function createConventionalChangelogOpts (parserOpts, writerOpts) {
return {
parserOpts,
writerOpts
}
}

module.exports.createConventionalChangelogOpts = createConventionalChangelogOpts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
'use strict'

function createConventionalRecommendedBumpOpts (parserOpts) {
export function createConventionalRecommendedBumpOpts (parserOpts) {
return {
parserOpts,

Expand Down Expand Up @@ -30,5 +28,3 @@ function createConventionalRecommendedBumpOpts (parserOpts) {
}
}
}

module.exports.createConventionalRecommendedBumpOpts = createConventionalRecommendedBumpOpts
14 changes: 5 additions & 9 deletions packages/conventional-changelog-angular/index.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
'use strict'
import { createParserOpts } from './parserOpts.js'
import { createWriterOpts } from './writerOpts.js'
import { createConventionalChangelogOpts } from './conventionalChangelog.js'
import { createConventionalRecommendedBumpOpts } from './conventionalRecommendedBump.js'

const { createParserOpts } = require('./parserOpts')
const { createWriterOpts } = require('./writerOpts')
const { createConventionalChangelogOpts } = require('./conventionalChangelog')
const { createConventionalRecommendedBumpOpts } = require('./conventionalRecommendedBump')

async function createPreset () {
export default async function createPreset () {
const parserOpts = createParserOpts()
const writerOpts = await createWriterOpts()
const recommendedBumpOpts = createConventionalRecommendedBumpOpts(parserOpts)
Expand All @@ -18,5 +16,3 @@ async function createPreset () {
conventionalChangelog
}
}

module.exports = createPreset
3 changes: 2 additions & 1 deletion packages/conventional-changelog-angular/package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
{
"name": "conventional-changelog-angular",
"type": "module",
"version": "7.0.0",
"description": "conventional-changelog angular preset",
"main": "index.js",
"exports": "./index.js",
"repository": {
"type": "git",
"url": "https://github.com/conventional-changelog/conventional-changelog.git"
Expand Down
6 changes: 1 addition & 5 deletions packages/conventional-changelog-angular/parserOpts.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
'use strict'

function createParserOpts () {
export function createParserOpts () {
return {
headerPattern: /^(\w*)(?:\((.*)\))?: (.*)$/,
headerCorrespondence: [
Expand All @@ -13,5 +11,3 @@ function createParserOpts () {
revertCorrespondence: ['header', 'hash']
}
}

module.exports.createParserOpts = createParserOpts
4 changes: 2 additions & 2 deletions packages/conventional-changelog-angular/test/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import path from 'path'
import { describe, it, expect } from 'vitest'
import BetterThanBefore from 'better-than-before'
import conventionalChangelogCore from 'conventional-changelog-core'
import { TestTools } from '../../../tools/test-tools'
import preset from '../'
import { TestTools } from '../../../tools/test-tools.js'
import preset from '../index.js'

const { setups, preparing, tearsWithJoy } = BetterThanBefore()
let testTools
Expand Down
21 changes: 10 additions & 11 deletions packages/conventional-changelog-angular/writerOpts.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
'use strict'
import { readFile } from 'fs/promises'
import { resolve } from 'path'
import { fileURLToPath } from 'url'
import compareFunc from 'compare-func'

const compareFunc = require('compare-func')
const { readFile } = require('fs').promises
const { resolve } = require('path')
const dirname = fileURLToPath(new URL('.', import.meta.url))

async function createWriterOpts () {
export async function createWriterOpts () {
const [template, header, commit, footer] = await Promise.all([
readFile(resolve(__dirname, './templates/template.hbs'), 'utf-8'),
readFile(resolve(__dirname, './templates/header.hbs'), 'utf-8'),
readFile(resolve(__dirname, './templates/commit.hbs'), 'utf-8'),
readFile(resolve(__dirname, './templates/footer.hbs'), 'utf-8')
readFile(resolve(dirname, './templates/template.hbs'), 'utf-8'),
readFile(resolve(dirname, './templates/header.hbs'), 'utf-8'),
readFile(resolve(dirname, './templates/commit.hbs'), 'utf-8'),
readFile(resolve(dirname, './templates/footer.hbs'), 'utf-8')
])
const writerOpts = getWriterOpts()

Expand All @@ -21,8 +22,6 @@ async function createWriterOpts () {
return writerOpts
}

module.exports.createWriterOpts = createWriterOpts

function getWriterOpts () {
return {
transform: (commit, context) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
'use strict'

function createConventionalChangelogOpts (parserOpts, writerOpts) {
export function createConventionalChangelogOpts (parserOpts, writerOpts) {
return {
parserOpts,
writerOpts
}
}

module.exports.createConventionalChangelogOpts = createConventionalChangelogOpts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
'use strict'

function createConventionalRecommendedBumpOpts (parserOpts) {
export function createConventionalRecommendedBumpOpts (parserOpts) {
return {
parserOpts,

Expand Down Expand Up @@ -28,5 +26,3 @@ function createConventionalRecommendedBumpOpts (parserOpts) {
}
}
}

module.exports.createConventionalRecommendedBumpOpts = createConventionalRecommendedBumpOpts
14 changes: 5 additions & 9 deletions packages/conventional-changelog-atom/index.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
'use strict'
import { createParserOpts } from './parserOpts.js'
import { createWriterOpts } from './writerOpts.js'
import { createConventionalChangelogOpts } from './conventionalChangelog.js'
import { createConventionalRecommendedBumpOpts } from './conventionalRecommendedBump.js'

const { createParserOpts } = require('./parserOpts')
const { createWriterOpts } = require('./writerOpts')
const { createConventionalChangelogOpts } = require('./conventionalChangelog')
const { createConventionalRecommendedBumpOpts } = require('./conventionalRecommendedBump')

async function createPreset () {
export default async function createPreset () {
const parserOpts = createParserOpts()
const writerOpts = await createWriterOpts()
const recommendedBumpOpts = createConventionalRecommendedBumpOpts(parserOpts)
Expand All @@ -18,5 +16,3 @@ async function createPreset () {
conventionalChangelog
}
}

module.exports = createPreset
3 changes: 2 additions & 1 deletion packages/conventional-changelog-atom/package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
{
"name": "conventional-changelog-atom",
"type": "module",
"version": "4.0.0",
"description": "conventional-changelog atom preset",
"main": "index.js",
"exports": "./index.js",
"repository": {
"type": "git",
"url": "https://github.com/conventional-changelog/conventional-changelog.git"
Expand Down
6 changes: 1 addition & 5 deletions packages/conventional-changelog-atom/parserOpts.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
'use strict'

function createParserOpts () {
export function createParserOpts () {
return {
headerPattern: /^(:.*?:) (.*)$/,
headerCorrespondence: [
Expand All @@ -9,5 +7,3 @@ function createParserOpts () {
]
}
}

module.exports.createParserOpts = createParserOpts
4 changes: 2 additions & 2 deletions packages/conventional-changelog-atom/test/index.spec.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { describe, beforeAll, afterAll, it, expect } from 'vitest'
import conventionalChangelogCore from 'conventional-changelog-core'
import { TestTools } from '../../../tools/test-tools'
import preset from '../'
import { TestTools } from '../../../tools/test-tools.js'
import preset from '../index.js'

let testTools

Expand Down
39 changes: 19 additions & 20 deletions packages/conventional-changelog-atom/writerOpts.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,8 @@
'use strict'
import { readFile } from 'fs/promises'
import { resolve } from 'path'
import { fileURLToPath } from 'url'

const { readFile } = require('fs').promises
const { resolve } = require('path')

async function createWriterOpts () {
const [template, header, commit] = await Promise.all([
readFile(resolve(__dirname, './templates/template.hbs'), 'utf-8'),
readFile(resolve(__dirname, './templates/header.hbs'), 'utf-8'),
readFile(resolve(__dirname, './templates/commit.hbs'), 'utf-8')
])
const writerOpts = getWriterOpts()

writerOpts.mainTemplate = template
writerOpts.headerPartial = header
writerOpts.commitPartial = commit

return writerOpts
}

module.exports.createWriterOpts = createWriterOpts
const dirname = fileURLToPath(new URL('.', import.meta.url))

function getWriterOpts () {
return {
Expand All @@ -45,3 +29,18 @@ function getWriterOpts () {
commitsSort: ['emoji', 'shortDesc']
}
}

export async function createWriterOpts () {
const [template, header, commit] = await Promise.all([
readFile(resolve(dirname, './templates/template.hbs'), 'utf-8'),
readFile(resolve(dirname, './templates/header.hbs'), 'utf-8'),
readFile(resolve(dirname, './templates/commit.hbs'), 'utf-8')
])
const writerOpts = getWriterOpts()

writerOpts.mainTemplate = template
writerOpts.headerPartial = header
writerOpts.commitPartial = commit

return writerOpts
}
File renamed without changes.
5 changes: 3 additions & 2 deletions packages/conventional-changelog-cli/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"name": "conventional-changelog-cli",
"type": "module",
"version": "4.1.0",
"description": "Generate a changelog from git metadata",
"bugs": {
Expand All @@ -16,10 +17,10 @@
"url": "https://github.com/stevemao"
},
"bin": {
"conventional-changelog": "cli.mjs"
"conventional-changelog": "cli.js"
},
"files": [
"cli.mjs"
"cli.js"
],
"keywords": [
"cli",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
'use strict'

module.exports = {
writerOpts: {
mainTemplate: '{{commitGroups.[0].commits.[0].type}}{{testContext}}template'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
'use strict'

module.exports = Promise.resolve({
writerOpts: {
mainTemplate: '{{commitGroups.[0].commits.[0].type}}{{testContext}}template'
Expand Down
16 changes: 8 additions & 8 deletions packages/conventional-changelog-cli/test/index.spec.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { describe, beforeAll, afterAll, it, expect } from 'vitest'
import path from 'path'
import { TestTools } from '../../../tools/test-tools'
import { TestTools } from '../../../tools/test-tools.js'

const CLI_PATH = path.join(__dirname, '../cli.mjs')
const CLI_PATH = path.join(__dirname, '../cli.js')
const FIXTURE_CHANGELOG_PATH = path.join(__dirname, 'fixtures/_CHANGELOG.md')
let testTools

Expand Down Expand Up @@ -220,7 +220,7 @@ describe('conventional-changelog-cli', () => {

it('--context should work with relative path', async () => {
const context = path.relative(testTools.cwd, path.join(__dirname, 'fixtures/context.json'))
const config = path.relative(testTools.cwd, path.join(__dirname, 'fixtures/config.js'))
const config = path.relative(testTools.cwd, path.join(__dirname, 'fixtures/config.cjs'))

const { stdout } = await testTools.fork(
CLI_PATH,
Expand All @@ -233,28 +233,28 @@ describe('conventional-changelog-cli', () => {
it('--context should work with absolute path', async () => {
const { stdout } = await testTools.fork(
CLI_PATH,
['--context', path.join(__dirname, 'fixtures/context.json'), '--config', path.join(__dirname, 'fixtures/config.js')]
['--context', path.join(__dirname, 'fixtures/context.json'), '--config', path.join(__dirname, 'fixtures/config.cjs')]
)

expect(stdout).toBe('unicorn template')
})

it('--config should work with a return promise', async () => {
const { stdout } = await testTools.fork(CLI_PATH, ['--config', path.join(__dirname, 'fixtures/promise-config.js')])
const { stdout } = await testTools.fork(CLI_PATH, ['--config', path.join(__dirname, 'fixtures/promise-config.cjs')])

expect(stdout).toBe('template')
})

it('--config should work with relative path', async () => {
const config = path.relative(testTools.cwd, path.join(__dirname, 'fixtures/config.js'))
const config = path.relative(testTools.cwd, path.join(__dirname, 'fixtures/config.cjs'))

const { stdout } = await testTools.fork(CLI_PATH, ['--config', config])

expect(stdout).toBe('template')
})

it('--config should work with absolute path', async () => {
const { stdout } = await testTools.fork(CLI_PATH, ['--config', path.join(__dirname, 'fixtures/config.js')])
const { stdout } = await testTools.fork(CLI_PATH, ['--config', path.join(__dirname, 'fixtures/config.cjs')])

expect(stdout).toBe('template')
})
Expand All @@ -280,7 +280,7 @@ describe('conventional-changelog-cli', () => {
it('--config should work with --preset', async () => {
const { stdout } = await testTools.fork(
CLI_PATH,
['--preset', 'angular', '--config', path.join(__dirname, 'fixtures/config.js')]
['--preset', 'angular', '--config', path.join(__dirname, 'fixtures/config.cjs')]
)

expect(stdout).toBe('Bug Fixestemplate')
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
'use strict'

function createConventionalChangelogOpts (parserOpts, writerOpts) {
export function createConventionalChangelogOpts (parserOpts, writerOpts) {
return {
parserOpts,
writerOpts
}
}

module.exports.createConventionalChangelogOpts = createConventionalChangelogOpts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
'use strict'

function createConventionalRecommendedBumpOpts (parserOpts) {
export function createConventionalRecommendedBumpOpts (parserOpts) {
return {
parserOpts,

Expand Down Expand Up @@ -28,5 +26,3 @@ function createConventionalRecommendedBumpOpts (parserOpts) {
}
}
}

module.exports.createConventionalRecommendedBumpOpts = createConventionalRecommendedBumpOpts

0 comments on commit c5b859d

Please sign in to comment.