1- const analyzeCommits = require ( '@semantic-release/commit-analyzer' )
2- const SemanticReleaseError = require ( '@semantic-release/error' )
3- const execSync = require ( 'child_process' ) . execSync ;
4- const lastTag = require ( './lastTag' ) ;
5- const utils = require ( './utils' ) ;
1+ import SemanticReleaseError from '@semantic-release/error' ;
2+ import { execSync } from 'child_process' ;
3+ import { lastTag } from './lastTag.js' ;
4+ import { ghActionsBranch } from './utils.js' ;
65
76const until = f => array => {
87 const first = array [ 0 ] ;
@@ -11,7 +10,7 @@ const until = f => array => {
1110 return [ ] ;
1211 }
1312
14- return [ first , ...until ( f ) ( array . slice ( 1 ) ) ] ;
13+ return [ first , ...until ( f ) ( array . slice ( 1 ) ) ] ;
1514} ;
1615
1716const lastTaggedRelease = ( ) => {
@@ -21,47 +20,49 @@ const lastTaggedRelease = () => {
2120 return execSync ( `git rev-list ${ args } ` , { encoding : 'utf8' } ) . trim ( ) ;
2221} ;
2322
24- module . exports = function ( pluginConfig , config , cb ) {
23+ export default async function ( pluginConfig , config ) {
24+ let commitAnalyzer = ( await import ( '@semantic-release/commit-analyzer' ) ) ;
2525 // run standard commit analysis
26- return analyzeCommits ( pluginConfig , config , function ( error , type ) {
27- const branch = config . env . TRAVIS_BRANCH || config . env . GIT_LOCAL_BRANCH || utils . ghActionsBranch ( config . env ) ;
28- const branchTags = config . options . branchTags ;
29- const distTag = branchTags && branchTags [ branch ] ;
26+ const analyzeCommitsResult = await commitAnalyzer . analyzeCommits ( pluginConfig , config ) ;
27+ const type = analyzeCommitsResult ;
3028
31- // use default behavior if not publishing a custom dist-tag
32- if ( ! distTag ) {
33- return cb ( error , type ) ;
34- }
29+ const branch = config . env . TRAVIS_BRANCH || config . env . GIT_LOCAL_BRANCH || ghActionsBranch ( config . env ) ;
30+ const branchTags = config . options . branchTags ;
31+ const distTag = branchTags && branchTags [ branch ] ;
3532
36- let releaseType = type ;
37- if ( type ) {
38- // map all types of releases to prereleases
39- releaseType = {
40- 'major' : 'premajor' ,
41- 'minor' : 'preminor' ,
42- 'patch' : 'prepatch'
43- } [ type ] || type ;
33+ // use default behavior if not publishing a custom dist-tag
34+ if ( ! distTag ) {
35+ return type ;
36+ }
4437
45- console . log ( "Publishing a " + releaseType + " release." ) ;
46- }
38+ let releaseType = type ;
39+ if ( type ) {
40+ // map all types of releases to prereleases
41+ releaseType = {
42+ 'major' : 'premajor' ,
43+ 'minor' : 'preminor' ,
44+ 'patch' : 'prepatch'
45+ } [ type ] || type ;
4746
48- // suppress NPM releases of non-feature commits (chore/docs/etc)
49- const lastReleaseHash = lastTaggedRelease ( ) ;
50- const untilLastRelease = until ( commit => commit . hash === lastReleaseHash ) ;
51- const commits = untilLastRelease ( config . commits ) ;
52- const commitSubset = Object . assign ( { } , config , { commits } ) ;
47+ console . log ( "Publishing a " + releaseType + " release." ) ;
48+ }
5349
54- analyzeCommits ( pluginConfig , commitSubset , function ( _ , type ) {
55- if ( ! type ) {
56- // commits since last dist-tag release are empty, suppress release
57- return cb ( new SemanticReleaseError (
58- 'There are no relevant changes, so no new version is released.' ,
59- 'ENOCHANGE'
60- ) ) ;
61- }
50+ // suppress NPM releases of non-feature commits (chore/docs/etc)
51+ const lastReleaseHash = lastTaggedRelease ( ) ;
52+ const untilLastRelease = until ( commit => commit . hash === lastReleaseHash ) ;
53+ const commits = untilLastRelease ( config . commits ) ;
54+ const commitSubset = Object . assign ( { } , config , { commits } ) ;
6255
63- cb ( error , releaseType ) ;
64- } ) ;
65- } ) ;
66- } ;
56+ const result = await commitAnalyzer . analyzeCommits ( pluginConfig , commitSubset )
57+
58+ if ( ! type ) {
59+ // commits since last dist-tag release are empty, suppress release
60+ return new SemanticReleaseError (
61+ 'There are no relevant changes, so no new version is released.' ,
62+ 'ENOCHANGE'
63+ ) ;
64+ }
65+
66+ return result ;
67+ }
6768
0 commit comments