@@ -8,6 +8,7 @@ const language = resolveLanguage(process.env.MIAOPAN_CODE_LANGUAGE)
88
99const dir = fileURLToPath ( new URL ( ".." , import . meta. url ) )
1010process . chdir ( dir )
11+ const dryRun = process . argv . includes ( "--dry-run" )
1112
1213async function published ( name : string , version : string ) {
1314 return ( await $ `npm view ${ name } @${ version } version` . nothrow ( ) ) . exitCode === 0
@@ -18,23 +19,32 @@ const originalText = await Bun.file("package.json").text()
1819const pkg = JSON . parse ( originalText ) as {
1920 name : string
2021 version : string
21- exports : Record < string , string >
22+ exports : Record < string , string | { import : string ; types : string } >
23+ dependencies : Record < string , string >
2224}
23- if ( await published ( pkg . name , pkg . version ) ) {
24- console . log ( t ( language , "publish_already_published" , { name : pkg . name , version : pkg . version } ) )
25+ const version = Script . version
26+ if ( await published ( pkg . name , version ) ) {
27+ console . log ( t ( language , "publish_already_published" , { name : pkg . name , version } ) )
2528} else {
29+ pkg . version = version
30+ pkg . dependencies [ "@miaopan-code/sdk" ] = version
2631 for ( const [ key , value ] of Object . entries ( pkg . exports ) ) {
32+ if ( typeof value !== "string" ) continue
2733 const file = value . replace ( "./src/" , "./dist/" ) . replace ( ".ts" , "" )
28- // @ts -ignore
2934 pkg . exports [ key ] = {
3035 import : file + ".js" ,
3136 types : file + ".d.ts" ,
3237 }
3338 }
3439 await Bun . write ( "package.json" , JSON . stringify ( pkg , null , 2 ) )
3540 try {
41+ await $ `find . -maxdepth 1 -type f -name '*.tgz' -delete`
3642 await $ `bun pm pack`
37- await $ `npm publish *.tgz --tag ${ Script . channel } --access public`
43+ if ( dryRun ) {
44+ await $ `npm publish *.tgz --tag ${ Script . channel } --access public --dry-run`
45+ } else {
46+ await $ `npm publish *.tgz --tag ${ Script . channel } --access public`
47+ }
3848 } finally {
3949 await Bun . write ( "package.json" , originalText )
4050 }
0 commit comments