22 * Semantic Release Config
33 */
44
5- const fs = require ( 'fs' ) . promises ;
6- const path = require ( 'path' ) ;
5+ const { readFile } = require ( 'fs' ) . promises ;
6+ const { resolve } = require ( 'path' ) ;
7+
8+ // For ES6 modules use:
9+ // import { readFile } from 'fs/promises';
10+ // import { resolve, dirname } from 'path';
11+ // import { fileURLToPath } from 'url';
712
813// Get env vars
914const ref = process . env . GITHUB_REF ;
@@ -24,7 +29,7 @@ const templates = {
2429async function config ( ) {
2530
2631 // Get branch
27- const branch = ref . split ( '/' ) . pop ( ) . split ( '-' ) [ 0 ] ;
32+ const branch = ref ? .split ( '/' ) ? .pop ( ) ? .split ( '-' ) [ 0 ] || '(current branch could not be determined)' ;
2833 console . log ( `Running on branch: ${ branch } ` ) ;
2934
3035 // Set changelog file
@@ -89,7 +94,7 @@ async function config() {
8994 [
9095 "@saithodev/semantic-release-backmerge" ,
9196 {
92- "branches " : [
97+ "backmergeBranches " : [
9398 { from : "beta" , to : "alpha" } ,
9499 { from : "release" , to : "beta" } ,
95100 ]
@@ -103,15 +108,17 @@ async function config() {
103108
104109async function loadTemplates ( ) {
105110 for ( const template of Object . keys ( templates ) ) {
106- const text = await readFile ( path . resolve ( __dirname , resourcePath , templates [ template ] . file ) ) ;
111+
112+ // For ES6 modules use:
113+ // const fileUrl = import.meta.url;
114+ // const __dirname = dirname(fileURLToPath(fileUrl));
115+
116+ const filePath = resolve ( __dirname , resourcePath , templates [ template ] . file ) ;
117+ const text = await readFile ( filePath , 'utf-8' ) ;
107118 templates [ template ] . text = text ;
108119 }
109120}
110121
111- async function readFile ( filePath ) {
112- return await fs . readFile ( filePath , 'utf-8' ) ;
113- }
114-
115122function getReleaseComment ( ) {
116123 const url = repositoryUrl + '/releases/tag/${nextRelease.gitTag}' ;
117124 const comment = '🎉 This change has been released in version [${nextRelease.version}](' + url + ')' ;
0 commit comments