11#!/usr/bin/env tsx
22import { execFileSync , execSync } from 'node:child_process'
3- import { existsSync } from 'node:fs'
3+ import { existsSync , readFileSync } from 'node:fs'
44import { homedir } from 'node:os'
55import { dirname , join , resolve } from 'node:path'
66import process from 'node:process'
@@ -16,6 +16,10 @@ const NATIVE_MODULES = [
1616const __dirname = import . meta. dirname ?? dirname ( fileURLToPath ( import . meta. url ) )
1717const root = resolve ( __dirname , '..' )
1818
19+ interface PackageManifestWithScripts {
20+ readonly scripts ?: Readonly < Record < string , string > >
21+ }
22+
1923function findCargo ( ) : string | null {
2024 const candidates : string [ ] = [
2125 process . env [ 'CARGO' ] ?? '' ,
@@ -57,6 +61,15 @@ for (const mod of NATIVE_MODULES) {
5761 const moduleDir = join ( root , mod . dir )
5862 console . log ( `[build-native] Building ${ mod . name } ...` )
5963 try {
64+ const packageJsonPath = join ( moduleDir , 'package.json' )
65+ if ( existsSync ( packageJsonPath ) ) {
66+ const packageJson = JSON . parse ( readFileSync ( packageJsonPath , 'utf8' ) ) as PackageManifestWithScripts
67+ if ( packageJson . scripts ?. [ 'build:ts' ] != null ) {
68+ console . log ( `[build-native] Building ${ mod . name } TypeScript artifacts...` )
69+ execSync ( 'pnpm run build:ts' , { stdio : 'inherit' , cwd : moduleDir , env : envWithCargo } )
70+ }
71+ }
72+
6073 execSync (
6174 'npx napi build --platform --release --output-dir dist -- --features napi' ,
6275 { stdio : 'inherit' , cwd : moduleDir , env : envWithCargo } ,
0 commit comments