Skip to content

Commit 1279f0f

Browse files
committed
Build TypeScript artifacts before native modules
1 parent f7708b8 commit 1279f0f

1 file changed

Lines changed: 14 additions & 1 deletion

File tree

scripts/build-native.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env tsx
22
import {execFileSync, execSync} from 'node:child_process'
3-
import {existsSync} from 'node:fs'
3+
import {existsSync, readFileSync} from 'node:fs'
44
import {homedir} from 'node:os'
55
import {dirname, join, resolve} from 'node:path'
66
import process from 'node:process'
@@ -16,6 +16,10 @@ const NATIVE_MODULES = [
1616
const __dirname = import.meta.dirname ?? dirname(fileURLToPath(import.meta.url))
1717
const root = resolve(__dirname, '..')
1818

19+
interface PackageManifestWithScripts {
20+
readonly scripts?: Readonly<Record<string, string>>
21+
}
22+
1923
function 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

Comments
 (0)