@@ -102,16 +102,31 @@ function handleAction(id: string | undefined) {
102102 close ()
103103}
104104
105- function downloadPackage() {
105+ async function downloadPackage() {
106106 const tarballUrl = props .version .dist .tarball
107107 if (! tarballUrl ) return
108108
109- const link = document .createElement (' a' )
110- link .href = tarballUrl
111- link .download = ` ${props .packageName }-${props .version .version }.tgz `
112- document .body .appendChild (link )
113- link .click ()
114- document .body .removeChild (link )
109+ try {
110+ const response = await fetch (tarballUrl )
111+ const blob = await response .blob ()
112+ const url = URL .createObjectURL (blob )
113+ const link = document .createElement (' a' )
114+ link .href = url
115+ link .download = ` ${props .packageName .replace (/ \/ / g , ' __' )}-${props .version .version }.tgz `
116+ document .body .appendChild (link )
117+ link .click ()
118+ document .body .removeChild (link )
119+ URL .revokeObjectURL (url )
120+ } catch (error ) {
121+ console .error (' Failed to download package:' , error )
122+ // Fallback to direct link for non-CORS or other issues, though download attribute may be ignored
123+ const link = document .createElement (' a' )
124+ link .href = tarballUrl
125+ link .download = ` ${props .packageName .replace (/ \/ / g , ' __' )}-${props .version .version }.tgz `
126+ document .body .appendChild (link )
127+ link .click ()
128+ document .body .removeChild (link )
129+ }
115130}
116131
117132function downloadDependenciesScript() {
@@ -125,18 +140,21 @@ function downloadDependenciesScript() {
125140 ]
126141
127142 // Add root package
128- const rootTarball = ( props .version .dist as any ) .tarball
143+ const rootTarball = props .version .dist .tarball
129144 if (rootTarball ) {
130145 lines .push (` # ${props .packageName }@${props .version .version } ` )
131146 lines .push (
132- ` curl -L ${rootTarball } -o ${props .packageName .replace (/ \/ / g , ' __' )}-${props .version .version }.tgz ` ,
147+ ` curl -L " ${rootTarball }" -o " ${props .packageName .replace (/ \/ / g , ' __' )}-${props .version .version }.tgz" ` ,
133148 )
134149 }
135150
136151 // Add dependencies
137- props .installSize .dependencies .forEach ((dep : any ) => {
152+ props .installSize .dependencies .forEach (dep => {
153+ if (! dep .tarballUrl ) return
138154 lines .push (` # ${dep .name }@${dep .version } ` )
139- lines .push (` curl -L ${dep .tarballUrl } -o ${dep .name .replace (/ \/ / g , ' __' )}-${dep .version }.tgz ` )
155+ lines .push (
156+ ` curl -L "${dep .tarballUrl }" -o "${dep .name .replace (/ \/ / g , ' __' )}-${dep .version }.tgz" ` ,
157+ )
140158 })
141159
142160 const blob = new Blob ([lines .join (' \n ' )], { type: ' text/x-shellscript' })
0 commit comments