@@ -25,7 +25,8 @@ export function registryVersion(raw: string, name: string): string {
2525 } catch {
2626 // Fall through to the stable error below.
2727 }
28- throw new Error ( `npm registry returned an invalid version for ${ name } ` ) ;
28+ const summary = raw . trim ( ) . replaceAll ( / \s + / g, " " ) . slice ( 0 , 200 ) || "<empty>" ;
29+ throw new Error ( `npm registry returned an invalid version for ${ name } ; received: ${ summary } ` ) ;
2930}
3031
3132export function commonRegistryVersion ( entries : ReadonlyArray < { name : string ; version : string } > ) : string {
@@ -46,11 +47,14 @@ function run(command: string[], cwd: string, stdout: "inherit" | "pipe" = "inher
4647}
4748
4849function npmVersion ( name : string , requested : string ) : string {
49- const result = Bun . spawnSync ( [ "npm" , "view" , `${ name } @${ requested } ` , "version" , "--json" , "--registry" , REGISTRY ] , {
50- cwd : root ,
51- stdout : "pipe" ,
52- stderr : "pipe" ,
53- } ) ;
50+ const result = Bun . spawnSync (
51+ [ "npm" , "view" , `${ name } @${ requested } ` , "version" , "--json" , "--prefer-online" , "--registry" , REGISTRY ] ,
52+ {
53+ cwd : root ,
54+ stdout : "pipe" ,
55+ stderr : "pipe" ,
56+ } ,
57+ ) ;
5458 if ( result . exitCode !== 0 ) {
5559 throw new Error ( result . stderr . toString ( ) . trim ( ) || `${ name } @${ requested } is not visible in the npm registry` ) ;
5660 }
@@ -72,20 +76,29 @@ export function resolvePublishedVersion(requested: string): string {
7276export async function waitForRegistry (
7377 requested : string ,
7478 options : { attempts ?: number ; delayMs ?: number } = { } ,
79+ dependencies : {
80+ resolve ?: ( requested : string ) => string ;
81+ sleep ?: ( delayMs : number ) => Promise < void > ;
82+ log ?: ( message : string ) => void ;
83+ } = { } ,
7584) : Promise < string > {
76- const attempts = options . attempts ?? 30 ;
85+ const attempts = options . attempts ?? 90 ;
7786 const delayMs = options . delayMs ?? 10_000 ;
87+ const resolve = dependencies . resolve ?? resolvePublishedVersion ;
88+ const sleep = dependencies . sleep ?? Bun . sleep ;
89+ const log = dependencies . log ?? console . log ;
7890 let lastError : unknown ;
7991 for ( let attempt = 1 ; attempt <= attempts ; attempt ++ ) {
8092 try {
81- const version = resolvePublishedVersion ( requested ) ;
82- console . log ( `✓ All published packages are visible at ${ version } ` ) ;
93+ const version = resolve ( requested ) ;
94+ log ( `✓ All published packages are visible at ${ version } ` ) ;
8395 return version ;
8496 } catch ( error ) {
8597 lastError = error ;
8698 if ( attempt === attempts ) break ;
87- console . log ( `Registry not ready (${ attempt } /${ attempts } ); retrying in ${ delayMs / 1000 } s...` ) ;
88- await Bun . sleep ( delayMs ) ;
99+ const reason = error instanceof Error ? error . message : String ( error ) ;
100+ log ( `Registry not ready (${ attempt } /${ attempts } ): ${ reason } ; retrying in ${ delayMs / 1000 } s...` ) ;
101+ await sleep ( delayMs ) ;
89102 }
90103 }
91104 throw lastError ;
0 commit comments