1- const fs = require ( "fs" ) ;
2- const path = require ( "path" ) ;
3- const { pathToFileURL } = require ( "url" ) ;
1+ import fs from "fs" ;
2+ import path from "path" ;
3+ import { execFile } from "../../../shared/src/exec.js" ;
44
5- const SHARED_SRC_ROOT = path . resolve ( __dirname , ".." , ".." , ".." , "shared" , "src" ) ;
6- const sharedModuleCache = new Map ( ) ;
75const ANSI = {
86 bold : "\u001b[1m" ,
97 cyan : "\u001b[36m" ,
@@ -15,45 +13,12 @@ function styleLog(text, ...styles) {
1513 return `${ styles . join ( "" ) } ${ text } ${ ANSI . reset } ` ;
1614}
1715
18- async function loadSharedModule ( fileName ) {
19- if ( sharedModuleCache . has ( fileName ) ) {
20- return sharedModuleCache . get ( fileName ) ;
21- }
22-
23- const filePath = path . join ( SHARED_SRC_ROOT , fileName ) ;
24- const modulePromise = import ( pathToFileURL ( filePath ) . href ) ;
25- sharedModuleCache . set ( fileName , modulePromise ) ;
26- return modulePromise ;
27- }
28-
2916async function runNode ( scriptRelativePath , workspace , core ) {
30- const { execFile, isExecError } = await loadSharedModule ( "exec.js" ) ;
31-
32- try {
33- const result = await execFile ( "node" , [ scriptRelativePath ] , {
34- cwd : workspace ,
35- logger : core ,
36- } ) ;
37-
38- if ( result . stdout ) {
39- core . info ( result . stdout . trimEnd ( ) ) ;
40- }
41- if ( result . stderr ) {
42- core . info ( result . stderr . trimEnd ( ) ) ;
43- }
44- } catch ( error ) {
45- if ( isExecError ( error ) ) {
46- if ( error . stdout ) {
47- core . info ( error . stdout . trimEnd ( ) ) ;
48- }
49- if ( error . stderr ) {
50- core . info ( error . stderr . trimEnd ( ) ) ;
51- }
52- }
53-
54- const status = isExecError ( error ) && Number . isInteger ( error . code ) ? error . code : 1 ;
55- throw new Error ( `Command failed (${ status } ): node ${ scriptRelativePath } ` ) ;
56- }
17+ await execFile ( "node" , [ scriptRelativePath ] , {
18+ cwd : workspace ,
19+ logger : core ,
20+ logOutput : true ,
21+ } ) ;
5722}
5823
5924function readLines ( fileRelativePath , workspace ) {
@@ -90,7 +55,7 @@ function formatIssueSection(title, apiFiles) {
9055 return lines . join ( "\n" ) ;
9156}
9257
93- module . exports = async function apiMdConsistency ( { core } ) {
58+ export default async function apiMdConsistency ( { core } ) {
9459 const workspace = process . env . GITHUB_WORKSPACE || process . cwd ( ) ;
9560
9661 await runNode ( ".github/workflows/src/api-md-consistency/find_affected.js" , workspace , core ) ;
0 commit comments