Skip to content

Commit

Permalink
Update dependencies and configuration files
Browse files Browse the repository at this point in the history
  • Loading branch information
1aron committed Jan 27, 2024
1 parent 627ea2f commit 2745cd2
Show file tree
Hide file tree
Showing 12 changed files with 142 additions and 177 deletions.
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,8 @@
"dependencies": {
"cross-env": "^7.0.3",
"turbo": "^1.11.2"
},
"resolutions": {
"@semantic-release/commit-analyzer": "11.0.0"
}
}
20 changes: 3 additions & 17 deletions packages/conventional-changelog-config/package.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
{
"name": "conventional-changelog-techor",
"scripts": {
"build:cjs": "esbuild src/index.ts --bundle --outfile=dist/index.js --format=cjs --minify --sourcemap --loader:.hbs=file --asset-names=[dir]/[name] --platform=node --external:esbuild --external:fast-glob --external:require-from-string --external:@techor/extend --external:@techor/fs --external:upath",
"build:esm": "esbuild src/index.ts --bundle --outfile=dist/index.mjs --format=esm --minify --sourcemap --loader:.hbs=file --asset-names=[dir]/[name] --platform=node --external:esbuild --external:fast-glob --external:require-from-string --external:@techor/extend --external:@techor/fs --external:upath",
"build:type": "tsc --emitDeclarationOnly --preserveWatchOutput",
"build": "pnpm run \"/^build:.*/\"",
"dev": "pnpm run \"/^build:.*/\" --watch",
"test": "jest",
"build": "esbuild src/index.ts --bundle --outfile=dist/index.js --format=cjs --minify --loader:.hbs=file --asset-names=[dir]/[name] --platform=node --external:esbuild --external:fast-glob --external:require-from-string --external:@techor/extend --external:@techor/fs --external:upath",
"dev": "pnpm build --watch",
"test": "pnpm build && jest",
"type-check": "tsc --noEmit",
"lint": "eslint src"
},
Expand Down Expand Up @@ -37,17 +34,6 @@
"preset"
],
"main": "./dist/index.js",
"jsnext:main": "./dist/index.mjs",
"esnext": "./dist/index.mjs",
"module": "./dist/index.mjs",
"types": "./dist/index.d.ts",
"exports": {
".": {
"require": "./dist/index.js",
"import": "./dist/index.mjs",
"types": "./dist/index.d.ts"
}
},
"files": [
"dist"
],
Expand Down
9 changes: 3 additions & 6 deletions packages/conventional-changelog-config/src/changelog.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
const parserOpts = require('./parser-opts')
const writerOpts = require('./writer-opts')

export default {
parserOpts,
writerOpts
module.exports = {
parserOpts: require('./parser-opts'),
writerOpts: require('./writer-opts')
}
17 changes: 6 additions & 11 deletions packages/conventional-changelog-config/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
import conventionalChangelog from './changelog'
import recommendedBumpOpts from './recommended-bump'
import parserOpts from './parser-opts'
import writerOpts from './writer-opts'

export {
conventionalChangelog,
parserOpts,
recommendedBumpOpts,
writerOpts
}
module.exports = async () => ({
conventionalChangelog: require('./changelog'),
parserOpts: require('./parser-opts'),
recommendedBumpOpts: require('./recommended-bump'),
writerOpts: require('./writer-opts')
})
2 changes: 1 addition & 1 deletion packages/conventional-changelog-config/src/parser-opts.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export default {
module.exports = {
headerPattern: /^([A-Z]\w*)(?:\(([0-9A-Z`_#~].*)\))?: ([0-9A-Z`_#~].*)$/,
headerCorrespondence: [
'type',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const parserOpts = require('./parser-opts')
const { commits: aronCommits } = require('techor-conventional-commits')

export default {
module.exports = {
parserOpts,
whatBump: (commits) => {
let level = null
Expand Down
13 changes: 8 additions & 5 deletions packages/conventional-changelog-config/src/writer-opts.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
import compareFunc from 'compare-func'
import { commits } from 'techor-conventional-commits'
import mainTemplatePath from './templates/template.hbs'
import footerPartialPath from './templates/footer.hbs'
import commitPartialPath from './templates/commit.hbs'
import { readFileSync } from 'fs'
import path from 'path'
import https from 'node:https'

const mainTemplate = readFileSync(path.resolve(__dirname, 'templates/template.hbs'), 'utf-8')
const footerPartial = readFileSync(path.resolve(__dirname, 'templates/footer.hbs'), 'utf-8')
const commitPartial = readFileSync(path.resolve(__dirname, 'templates/commit.hbs'), 'utf-8')
const mainTemplate = readFileSync(path.resolve(__dirname, mainTemplatePath), 'utf-8')
const footerPartial = readFileSync(path.resolve(__dirname, footerPartialPath), 'utf-8')
const commitPartial = readFileSync(path.resolve(__dirname, commitPartialPath), 'utf-8')

export default {
module.exports = {
transform: async (commit, context) => {
const issues = []
if (commit.header) {
Expand Down Expand Up @@ -43,7 +46,7 @@ export default {
? `${context.host}/${context.owner}/${context.repository}`
: context.repoUrl
if (url) {
// Issue URLs.
// Issue URLs.
const issuesUrl = `${url}/issues/`

commit.subject = commit.subject.replace(/#([0-9]+)/g, (_, issue) => {
Expand Down
181 changes: 83 additions & 98 deletions packages/conventional-changelog-config/tests/test.ts
Original file line number Diff line number Diff line change
@@ -1,116 +1,101 @@
import fs from 'fs'
import path from 'path'
import dedent from 'dedent'
import fs, { writeFile, writeFileSync } from 'fs'
import path, { resolve } from 'path'
import exec from '../../../utils/exec'
import commit from '../../../utils/commit'
import initFakeGit from '../../../utils/init-fake-git'
import { writeFileSync } from '../../fs/src'

const config = require('../src')
const createPreset = require('../dist')
const conventionalChangelogCore = require('conventional-changelog-core')

if (!fs.existsSync(path.join(__dirname, './dist'))) {
fs.mkdirSync(path.join(__dirname, './dist'))
}

if (process.platform === 'win32') {
test.todo('Skip conventional-changelog-config tests on Windows OS')
} else {
if (!fs.existsSync(path.join(__dirname, '../changelog-dist'))) {
fs.mkdirSync(path.join(__dirname, '../changelog-dist'))
}
initFakeGit()
describe('techor preset', () => {
initFakeGit()
test('changelog', async () => {
await testAronChangelog(
[
'Fix(CSS): `@media` and `@supports` doesn\'t transform `|` to ` ` #198',
'Build: First build setup',
'CI(Travis): Add TravisCI pipeline',
'New: Amazing new module',
'Fix(Compiler): Avoid a bug',
'Fix: Content not changed',
'Fix(Vite): HMR causes page reloaded',
'Breaking(API): Rename `extend` parameters',
'Fix(Normal.css): Layout shift',
'Breaking: Remove `configure()` method',
'Perf(`ngOptions`): Make it faster #1 #2',
'Drop(Syntax): Use `fg:color` instead of ~~`font:color`~~',
'Update(Contact): Address and tel',
'Drop(Commitlint Config): Remove `header-max-length` rule',
'Improve(UI): Call to action',
['Perf(`ngOptions`): Make it faster', ' #1 #2'],
'Docs: Add `font-size` demo',
'Revert(`ngOptions`): Bad commit',
'Revert \\"Fix(Repo): PeerDependencies -> Dependencies\\"\n\nThis reverts commit 123.\n',
'Chore: Move directory',
'Misc: Delete unused file',
'Upgrade: Bump `@dummy/package` from 7.1.2 to 8.0.0',
'Fix(*): Oops!',
'Feat(Awesome): Addresses the issue brought up in #133',
'Feat(API): New option for test #88',
'Feat(Search): Issue brought up by @1aron! on Friday',
'Revert \\"Fix: Content not changed\\"',
'new: lowercase type',
'New: lowercase summary',
'New starts with `New` and sentense case'
],
(changelog) => {
expect(changelog).toMatch('[@hparra](https://github.com/hparra)')
expect(changelog).toMatch('Amazing new module')
expect(changelog).toMatch('Compiler')
expect(changelog).toMatch('Avoid a bug')
expect(changelog).toMatch('Make it faster')
expect(changelog).toMatch('[#1](https://github.com/conventional-changelog/conventional-changelog/issues/1) [#2](https://github.com/conventional-changelog/conventional-changelog/issues/2)')
expect(changelog).toMatch('New Features')
expect(changelog).toMatch('Bug Fixes')
expect(changelog).toMatch('Performance Upgrades')
expect(changelog).toMatch('`ngOptions`')
expect(changelog).toMatch('Bad commit')
expect(changelog).not.toMatch('Delete unused file')
expect(changelog).not.toMatch('First build setup')
expect(changelog).not.toMatch('Add TravisCI pipeline')
expect(changelog).not.toMatch('Continuously integrated.')
expect(changelog).not.toMatch('CI')
expect(changelog).not.toMatch('Build')
expect(changelog).not.toMatch('Chore')
expect(changelog).not.toMatch('*** - **')
expect(changelog).not.toMatch(': Not backward compatible.')
// should replace #[0-9]+ with GitHub issue URL
expect(changelog).toMatch('[#133](https://github.com/conventional-changelog/conventional-changelog/issues/133)')
// should remove the issues that already appear in the subject
expect(changelog).toMatch('[#88](https://github.com/conventional-changelog/conventional-changelog/issues/88)')
// should replace @username with GitHub user URL
expect(changelog).toMatch('[@1aron](https://github.com/1aron)')

}, { changelogFileName: 'CHANGELOG.md' })
[
'Fix(CSS): `@media` and `@supports` doesn\'t transform `|` to ` ` #198',
'Build : First build setup',
'CI(Travis): Add TravisCI pipeline',
'New: Amazing new module',
'Fix(Compiler): Avoid a bug',
'Fix: Content not changed',
'Fix(Vite): HMR causes page reloaded',
'Breaking(API): Rename `extend` parameters',
'Fix(Normal.css): Layout shift',
'Breaking: Remove `configure()` method',
'Perf(`ngOptions`): Make it faster #1 #2',
'Drop(Syntax): Use `fg:color` instead of ~~`font:color`~~',
'Update(Contact): Address and tel',
'Drop(Commitlint Config): Remove `header-max-length` rule',
'Improve(UI): Call to action',
['Perf(`ngOptions`): Make it faster', ' #1 #2'],
'Docs: Add `font-size` demo',
'Revert(`ngOptions`): Bad commit',
'Revert \\"Fix(Repo): PeerDependencies -> Dependencies\\"\n\nThis reverts commit 123.\n',
'Chore: Move directory',
'Misc: Delete unused file',
'Upgrade: Bump `@dummy/package` from 7.1.2 to 8.0.0',
'Fix(*): Oops!',
'Feat(Awesome): Addresses the issue brought up in #133',
'Feat(API): New option for test #88',
'Feat(Search): Issue brought up by @1aron! on Friday',
'Revert \\"Fix: Content not changed\\"',
'new: lowercase type',
'New: lowercase summary',
'New starts with `New` and sentense case'
].forEach((message) => commit(message))
for await (let chunk of conventionalChangelogCore({
config: await createPreset(),
cwd: process.cwd()
})) {
chunk = chunk.toString()
writeFile(resolve(__dirname, './dist/CHANGELOG-1.md'), chunk, () => { })
expect(chunk).toMatch('[@hparra](https://github.com/hparra)')
expect(chunk).toMatch('Amazing new module')
expect(chunk).toMatch('Compiler')
expect(chunk).toMatch('Avoid a bug')
expect(chunk).toMatch('Make it faster')
expect(chunk).toMatch('[#1](https://github.com/conventional-changelog/conventional-changelog/issues/1) [#2](https://github.com/conventional-changelog/conventional-changelog/issues/2)')
expect(chunk).toMatch('New Features')
expect(chunk).toMatch('Bug Fixes')
expect(chunk).toMatch('Performance Upgrades')
expect(chunk).toMatch('`ngOptions`')
expect(chunk).toMatch('Bad commit')
expect(chunk).not.toMatch('Delete unused file')
expect(chunk).not.toMatch('First build setup')
expect(chunk).not.toMatch('Add TravisCI pipeline')
expect(chunk).not.toMatch('Continuously integrated.')
expect(chunk).not.toMatch('CI')
expect(chunk).not.toMatch('Build')
expect(chunk).not.toMatch('Chore')
expect(chunk).not.toMatch('*** - **')
expect(chunk).not.toMatch(': Not backward compatible.')
// should replace #[0-9]+ with GitHub issue URL
expect(chunk).toMatch('[#133](https://github.com/conventional-changelog/conventional-changelog/issues/133)')
// should remove the issues that already appear in the subject
expect(chunk).toMatch('[#88](https://github.com/conventional-changelog/conventional-changelog/issues/88)')
// should replace @username with GitHub user URL
expect(chunk).toMatch('[@1aron](https://github.com/1aron)')
}
}, 10000)

test('should work if there is a semver tag', async () => {
exec('git tag v1.0.0')
await testAronChangelog(
['Feat: `it` alias for `test`'],
(changelog) => {
expect(changelog).toMatch('`it` alias for `test`')
// not to include provious changes
expect(changelog).not.toMatch('Breaking Changes')
}, { changelogFileName: 'CHANGELOG.more.md' })
commit('Feat: `it` alias for `test`')
for await (let chunk of conventionalChangelogCore({
cwd: process.cwd()
})) {
chunk = chunk.toString()
writeFile(resolve(__dirname, './dist/CHANGELOG-2.md'), chunk, () => { })
expect(chunk).toMatch('`it` alias for `test`')
// not to include provious changes
expect(chunk).not.toMatch('Breaking Changes')
}
}, 10000)
})
}

export function testAronChangelog(commits, handle: (changelog: string) => void, { changelogFileName, pkg }: any) {
return new Promise<void>((resolve) => {
commits.forEach((eachCommit) => commit(eachCommit))
conventionalChangelogCore({
config,
pkg
})
.on('data', changelogChunk => {
const changelog = changelogChunk.toString()
writeFileSync(path.join(__dirname, 'dist', changelogFileName), dedent(changelog))
handle(changelog)
})
.on('error', (error) => {
console.log(error)
resolve()
})
.on('close', () => resolve())
})
}
5 changes: 1 addition & 4 deletions packages/repo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,13 @@
},
"peerDependencies": {
"@types/node": "",
"turbo": "",
"typescript": ""
},
"dependencies": {
"@techor/pack": "workspace:^",
"@techor/version": "workspace:^",
"@techor/jest": "workspace:^",
"commitlint-config-techor": "workspace:^",
"conventional-changelog-techor": "workspace:^",
"eslint-config-techor": "workspace:^",
"semantic-release-config-techor": "workspace:^"
"eslint-config-techor": "workspace:^"
}
}
1 change: 1 addition & 0 deletions packages/semantic-release-config/.npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
shamefully-hoist=true
6 changes: 3 additions & 3 deletions packages/semantic-release-config/tests/rules.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,16 +70,16 @@ test('Revert commit and +0.0.1', async () => {
test('Exclude commits if they have a matching revert commits', async () => {
const logSpy = createLogSpy()
const commits = commitFalsely(
{ message: 'Feat(Scope): First feature', hash: '123', },
'Fix(Scope): First fix',
{ message: 'Revert: Feat(Scope): First feature\n\nThis reverts commit 123.\n', hash: '456', },
'Fix(Scope): First fix'
{ message: 'Feat(Scope): First feature', hash: '123', }
)
const releaseType = await analyzeCommits(
{ preset: 'techor', releaseRules },
{ cwd: process.cwd(), commits, logger: console }
)
expect(releaseType).toBe('patch')
expect(logSpy).toHaveBeenCalledWith('Analyzing commit: %s', commits[2].message)
expect(logSpy).toHaveBeenCalledWith('Analyzing commit: %s', commits[0].message)
expect(logSpy).toHaveBeenCalledWith('The release type for the commit is %s', 'patch')
expect(logSpy).toHaveBeenCalledWith('Analysis of %s commits complete: %s release', 3, 'patch')
logSpy.mockRestore()
Expand Down
Loading

0 comments on commit 2745cd2

Please sign in to comment.