@@ -20,6 +20,13 @@ const root = resolve(import.meta.dirname, "../..");
2020
2121type PackedPackage = { filename : string } ;
2222
23+ export function packedFilename ( raw : string , pkg : string ) : string {
24+ const parsed = JSON . parse ( raw ) as PackedPackage [ ] | Record < string , PackedPackage > ;
25+ const packed = Array . isArray ( parsed ) ? parsed : Object . values ( parsed ) ;
26+ if ( packed . length !== 1 || ! packed [ 0 ] ?. filename ) throw new Error ( `Unexpected npm pack output for ${ pkg } ` ) ;
27+ return packed [ 0 ] . filename ;
28+ }
29+
2330function run ( command : string [ ] , cwd : string , stdout : "inherit" | "pipe" = "inherit" ) : string {
2431 const result = Bun . spawnSync ( command , { cwd, stdout, stderr : "inherit" } ) ;
2532 if ( result . exitCode !== 0 ) throw new Error ( `Command failed (${ result . exitCode } ): ${ command . join ( " " ) } ` ) ;
@@ -38,9 +45,7 @@ function packPackages(destination: string): string[] {
3845 licenseStaged = true ;
3946 originalManifest = rewriteManifestForPublish ( pkgDir , versions ) ;
4047 const raw = run ( [ "npm" , "pack" , "--json" , "--pack-destination" , destination ] , pkgDir , "pipe" ) ;
41- const packed = JSON . parse ( raw ) as PackedPackage [ ] ;
42- if ( packed . length !== 1 || ! packed [ 0 ] ?. filename ) throw new Error ( `Unexpected npm pack output for ${ pkg } ` ) ;
43- return join ( destination , packed [ 0 ] . filename ) ;
48+ return join ( destination , packedFilename ( raw , pkg ) ) ;
4449 } finally {
4550 if ( originalManifest !== undefined ) restorePackageJson ( pkgDir , originalManifest ) ;
4651 if ( licenseStaged ) restoreLicense ( pkgDir , originalLicense ) ;
0 commit comments