2
2
* Semantic Release Config
3
3
*/
4
4
5
- const fs = require ( 'fs' ) . promises ;
6
- const path = require ( 'path' ) ;
5
+ // For CommonJS use:
6
+ // const { readFile } = require('fs').promises;
7
+ // const { resolve } = require('path');
8
+
9
+ // For ES6 modules use:
10
+ import { readFile } from 'fs/promises' ;
11
+ import { resolve , dirname } from 'path' ;
12
+ import { fileURLToPath } from 'url' ;
7
13
8
14
// Get env vars
9
15
const ref = process . env . GITHUB_REF ;
@@ -24,7 +30,7 @@ const templates = {
24
30
async function config ( ) {
25
31
26
32
// Get branch
27
- const branch = ref . split ( '/' ) . pop ( ) ;
33
+ const branch = ref ? .split ( '/' ) ? .pop ( ) ?. split ( '-' ) [ 0 ] || '(current branch could not be determined)' ;
28
34
console . log ( `Running on branch: ${ branch } ` ) ;
29
35
30
36
// Set changelog file
@@ -97,15 +103,16 @@ async function config() {
97
103
98
104
async function loadTemplates ( ) {
99
105
for ( const template of Object . keys ( templates ) ) {
100
- const text = await readFile ( path . resolve ( __dirname , resourcePath , templates [ template ] . file ) ) ;
106
+ // For ES6 modules use:
107
+ const fileUrl = import . meta. url ;
108
+ const __dirname = dirname ( fileURLToPath ( fileUrl ) ) ;
109
+
110
+ const filePath = resolve ( __dirname , resourcePath , templates [ template ] . file ) ;
111
+ const text = await readFile ( filePath , 'utf-8' ) ;
101
112
templates [ template ] . text = text ;
102
113
}
103
114
}
104
115
105
- async function readFile ( filePath ) {
106
- return await fs . readFile ( filePath , 'utf-8' ) ;
107
- }
108
-
109
116
function getReleaseComment ( ) {
110
117
const url = repositoryUrl + '/releases/tag/${nextRelease.gitTag}' ;
111
118
let comment = '🎉 This change has been released in version [${nextRelease.version}](' + url + ')' ;
0 commit comments