11import { execSync } from 'node:child_process' ;
2- import { copyFileSync , existsSync , chmodSync } from 'node:fs' ;
2+ import { copyFileSync , existsSync , chmodSync , readFileSync , writeFileSync } from 'node:fs' ;
33import { readdir } from 'node:fs/promises' ;
44import { dirname , join } from 'node:path' ;
55import { fileURLToPath } from 'node:url' ;
@@ -33,10 +33,19 @@ await cli.artifacts({
3333 packageJsonPath : './package.json' ,
3434} ) ;
3535
36- // Copy Rust binaries to each platform package
36+ // Pre-publish (generates package.json files in npm directories)
37+ await cli . prePublish ( {
38+ cwd : currentDir ,
39+ packageJsonPath : './package.json' ,
40+ tagStyle : 'npm' ,
41+ ghRelease : false ,
42+ skipOptionalPublish : true ,
43+ } ) ;
44+
3745const npmDir = join ( currentDir , 'npm' ) ;
3846const platformDirs = await readdir ( npmDir ) ;
3947
48+ // Copy Rust binaries to each platform package and update package.json files
4049for ( const platformDir of platformDirs ) {
4150 const rustTarget = RUST_TARGETS [ platformDir ] ;
4251 if ( ! rustTarget ) {
@@ -59,19 +68,17 @@ for (const platformDir of platformDirs) {
5968 if ( ! isWindows ) {
6069 chmodSync ( rustBinaryDest , 0o755 ) ;
6170 }
71+
72+ // Add binary to package.json files field
73+ const platformPackageJsonPath = join ( npmDir , platformDir , 'package.json' ) ;
74+ const packageJson = JSON . parse ( readFileSync ( platformPackageJsonPath , 'utf-8' ) ) ;
75+ packageJson . files . push ( binaryName ) ;
76+ writeFileSync ( platformPackageJsonPath , JSON . stringify ( packageJson , null , 2 ) + '\n' ) ;
77+
6278 // eslint-disable-next-line no-console
6379 console . log ( `Copied Rust binary: ${ rustBinarySource } -> ${ rustBinaryDest } ` ) ;
6480}
6581
66- // Pre-publish (updates package.json files in npm directories)
67- await cli . prePublish ( {
68- cwd : currentDir ,
69- packageJsonPath : './package.json' ,
70- tagStyle : 'npm' ,
71- ghRelease : false ,
72- skipOptionalPublish : true ,
73- } ) ;
74-
7582// Publish each platform package
7683const npmTag = process . env . NPM_TAG || 'latest' ;
7784for ( const file of platformDirs ) {
0 commit comments