@@ -11,12 +11,12 @@ async function published(name: string, version: string) {
1111 return ( await $ `npm view ${ name } @${ version } version` . nothrow ( ) ) . exitCode === 0
1212}
1313
14- const pkg = ( await import ( "../package.json" ) . then ( ( m ) => m . default ) ) as {
14+ const originalText = await Bun . file ( "package.json" ) . text ( )
15+ const pkg = JSON . parse ( originalText ) as {
1516 name : string
1617 version : string
1718 exports : Record < string , unknown >
1819}
19- const original = JSON . parse ( JSON . stringify ( pkg ) )
2020function transformExports ( exports : Record < string , unknown > ) {
2121 return Object . fromEntries (
2222 Object . entries ( exports ) . map ( ( [ key , value ] ) => {
@@ -33,10 +33,13 @@ function transformExports(exports: Record<string, unknown>) {
3333}
3434if ( await published ( pkg . name , pkg . version ) ) {
3535 console . log ( `already published ${ pkg . name } @${ pkg . version } ` )
36- process . exit ( 0 )
36+ } else {
37+ pkg . exports = transformExports ( pkg . exports )
38+ await Bun . write ( "package.json" , JSON . stringify ( pkg , null , 2 ) )
39+ try {
40+ await $ `bun pm pack`
41+ await $ `npm publish *.tgz --tag ${ Script . channel } --access public`
42+ } finally {
43+ await Bun . write ( "package.json" , originalText )
44+ }
3745}
38- pkg . exports = transformExports ( pkg . exports )
39- await Bun . write ( "package.json" , JSON . stringify ( pkg , null , 2 ) )
40- await $ `bun pm pack`
41- await $ `npm publish *.tgz --tag ${ Script . channel } --access public`
42- await Bun . write ( "package.json" , JSON . stringify ( original , null , 2 ) )
0 commit comments