@@ -12,14 +12,39 @@ const VERSION = process.env.VERSION || "";
1212const dryRun = process . argv . includes ( "--dry-run" ) ;
1313const checkOnly = process . argv . includes ( "--check" ) ;
1414const resumeExisting = process . argv . includes ( "--resume-existing" ) ;
15+ const registryArg = process . argv . find ( ( arg ) => arg . startsWith ( "--registry=" ) ) ;
1516const unknownArgs = process . argv
1617 . slice ( 2 )
17- . filter ( ( arg ) => ! [ "--dry-run" , "--check" , "--resume-existing" ] . includes ( arg ) ) ;
18+ . filter (
19+ ( arg ) =>
20+ ! [ "--dry-run" , "--check" , "--resume-existing" ] . includes ( arg ) &&
21+ ! arg . startsWith ( "--registry=" )
22+ ) ;
23+
24+ const registries = {
25+ npm : {
26+ label : "npm" ,
27+ url : "https://registry.npmjs.org/" ,
28+ publishArgs : [ ] ,
29+ } ,
30+ "github-packages" : {
31+ label : "GitHub Packages" ,
32+ url : "https://npm.pkg.github.com/" ,
33+ // Provenance is generated for npmjs.org publishes; GitHub Packages uses GITHUB_TOKEN auth.
34+ publishArgs : [ "--provenance=false" ] ,
35+ } ,
36+ } ;
37+ const registryName = registryArg ? registryArg . slice ( "--registry=" . length ) : "npm" ;
38+ const registry = registries [ registryName ] ;
1839
1940if ( unknownArgs . length > 0 ) {
2041 console . error ( `Unknown argument(s): ${ unknownArgs . join ( ", " ) } ` ) ;
2142 process . exit ( 1 ) ;
2243}
44+ if ( ! registry ) {
45+ console . error ( `Unknown registry: ${ registryName } ` ) ;
46+ process . exit ( 1 ) ;
47+ }
2348if ( dryRun && checkOnly ) {
2449 console . error ( "--dry-run and --check cannot be used together" ) ;
2550 process . exit ( 1 ) ;
@@ -58,10 +83,14 @@ function fail(message) {
5883
5984function npmView ( packageName ) {
6085 try {
61- const output = execFileSync ( "npm" , [ "view" , `${ packageName } @${ version } ` , "--json" ] , {
62- encoding : "utf8" ,
63- stdio : [ "ignore" , "pipe" , "pipe" ] ,
64- } ) . trim ( ) ;
86+ const output = execFileSync (
87+ "npm" ,
88+ [ "view" , `${ packageName } @${ version } ` , "--json" , "--registry" , registry . url ] ,
89+ {
90+ encoding : "utf8" ,
91+ stdio : [ "ignore" , "pipe" , "pipe" ] ,
92+ }
93+ ) . trim ( ) ;
6594 if ( ! output ) {
6695 return null ;
6796 }
@@ -152,8 +181,9 @@ function publish(packageDir) {
152181 return ;
153182 }
154183 const args = dryRun
155- ? [ "publish" , "--dry-run" , "--access" , "public" ]
156- : [ "publish" , "--access" , "public" ] ;
184+ ? [ "publish" , "--dry-run" , "--access" , "public" , "--registry" , registry . url ]
185+ : [ "publish" , "--access" , "public" , "--registry" , registry . url ] ;
186+ args . push ( ...registry . publishArgs ) ;
157187 execFileSync ( "npm" , args , { cwd : packageDir , stdio : "inherit" } ) ;
158188}
159189
@@ -189,7 +219,7 @@ if (!dryRun && !checkOnly) {
189219 const remotePackage = npmView ( pkg . name ) ;
190220 if ( remotePackage ) {
191221 if ( ! resumeExisting ) {
192- fail ( `${ pkg . name } @${ version } already exists; use --resume-existing only after verifying recovery is intended` ) ;
222+ fail ( `${ pkg . name } @${ version } already exists in ${ registry . label } ; use --resume-existing only after verifying recovery is intended` ) ;
193223 }
194224 assertRemotePackageMatches ( pkg . dir , pkg . name , remotePackage ) ;
195225 existingPackages . set ( pkg . name , true ) ;
@@ -199,7 +229,7 @@ if (!dryRun && !checkOnly) {
199229
200230for ( const pkg of packages ) {
201231 if ( existingPackages . has ( pkg . name ) ) {
202- console . log ( `Skipping existing matching package ${ pkg . name } @${ version } ` ) ;
232+ console . log ( `Skipping existing matching ${ registry . label } package ${ pkg . name } @${ version } ` ) ;
203233 continue ;
204234 }
205235 publish ( pkg . dir ) ;
0 commit comments