22 * Semantic Release Config
33 */
44
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' ;
713
814// Get env vars
915const ref = process . env . GITHUB_REF ;
@@ -24,7 +30,7 @@ const templates = {
2430async function config ( ) {
2531
2632 // Get branch
27- const branch = ref . split ( '/' ) . pop ( ) ;
33+ const branch = ref ? .split ( '/' ) ? .pop ( ) ?. split ( '-' ) [ 0 ] || '(current branch could not be determined)' ;
2834 console . log ( `Running on branch: ${ branch } ` ) ;
2935
3036 // Set changelog file
@@ -97,15 +103,16 @@ async function config() {
97103
98104async function loadTemplates ( ) {
99105 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' ) ;
101112 templates [ template ] . text = text ;
102113 }
103114}
104115
105- async function readFile ( filePath ) {
106- return await fs . readFile ( filePath , 'utf-8' ) ;
107- }
108-
109116function getReleaseComment ( ) {
110117 const url = repositoryUrl + '/releases/tag/${nextRelease.gitTag}' ;
111118 let comment = '🎉 This change has been released in version [${nextRelease.version}](' + url + ')' ;
0 commit comments