11import { spawn } from 'node:child_process' ;
22import { existsSync } from 'node:fs' ;
33import { mkdir , readdir , readFile , rm , writeFile } from 'node:fs/promises' ;
4+ import { createRequire } from 'node:module' ;
45import path from 'node:path' ;
56
7+ const require = createRequire ( import . meta. url ) ;
68const packageRoot = path . resolve ( import . meta. dirname , '..' ) ;
79const tempDir = path . join ( packageRoot , '.tmp-api-extractor' ) ;
810const dtsRoot = path . join ( tempDir , 'dts' ) ;
911const providerClientShimPath = path . join ( dtsRoot , 'provider-clients.d.ts' ) ;
12+ const tscBinPath = packageBinPath ( 'typescript' , 'bin/tsc' ) ;
13+ const apiExtractorBinPath = packageBinPath ( '@microsoft/api-extractor' , 'bin/api-extractor' ) ;
1014
1115const packageDirs = new Set ( [ 'agent-core' , 'kaos' , 'kosong' , 'node-sdk' , 'oauth' ] ) ;
1216const workspacePackages = new Map ( [
@@ -18,19 +22,21 @@ const workspacePackages = new Map([
1822
1923try {
2024 await rm ( tempDir , { recursive : true , force : true } ) ;
21- await run ( 'tsc' , [ '-p' , 'tsconfig.dts.json' ] ) ;
25+ await run ( 'tsc' , tscBinPath , [ '-p' , 'tsconfig.dts.json' ] ) ;
2226 await writeProviderClientShim ( ) ;
2327 await rewriteWorkspaceSpecifiers ( ) ;
24- await run ( 'api-extractor' , [ 'run' , '--local' ] ) ;
28+ await run ( 'api-extractor' , apiExtractorBinPath , [ 'run' , '--local' ] ) ;
2529} finally {
2630 await rm ( tempDir , { recursive : true , force : true } ) ;
2731}
2832
29- function run ( command , args ) {
30- const executable = process . platform === 'win32' ? `${ command } .cmd` : command ;
33+ function packageBinPath ( packageName , binPath ) {
34+ return path . join ( path . dirname ( require . resolve ( `${ packageName } /package.json` ) ) , binPath ) ;
35+ }
3136
37+ function run ( command , binPath , args ) {
3238 return new Promise ( ( resolve , reject ) => {
33- const child = spawn ( executable , args , {
39+ const child = spawn ( process . execPath , [ binPath , ... args ] , {
3440 cwd : packageRoot ,
3541 stdio : 'inherit' ,
3642 } ) ;
0 commit comments