File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -574,6 +574,9 @@ export async function packageInit(
574574
575575 const tempDirPath = await mkdtemp ( join ( tmpdir ( ) , 'npmx-init-' ) )
576576
577+ let publishResult : NpmExecResult | null = null
578+ let publishError : unknown = null
579+
577580 try {
578581 // Determine access type based on whether it's a scoped package
579582 const isScoped = name . startsWith ( '@' )
@@ -621,8 +624,29 @@ export async function packageInit(
621624 logError ( result . stderr . split ( '\n' ) [ 0 ] || 'Command failed' )
622625 }
623626
624- return result
625- } finally {
627+ publishResult = result
628+ } catch ( error ) {
629+ publishError = error
630+ }
631+
632+ try {
626633 await rm ( tempDirPath , { recursive : true , force : true } )
634+ } catch ( cleanupError ) {
635+ if ( publishError ) {
636+ // Preserve original error
637+ Object . assign ( cleanupError as Error , { cause : publishError } )
638+ }
639+
640+ throw cleanupError
641+ }
642+
643+ if ( publishError ) {
644+ throw publishError
627645 }
646+
647+ if ( ! publishResult ) {
648+ throw new Error ( 'packageInit completed without a publish result' )
649+ }
650+
651+ return publishResult
628652}
You can’t perform that action at this time.
0 commit comments