1717 */
1818
1919import { createHash } from 'node:crypto'
20- import { createReadStream , existsSync , readFileSync , promises as fs } from 'node:fs'
20+ import {
21+ createReadStream ,
22+ existsSync ,
23+ readFileSync ,
24+ promises as fs ,
25+ } from 'node:fs'
2126import os from 'node:os'
2227import path from 'node:path'
2328import { fileURLToPath } from 'node:url'
@@ -48,7 +53,9 @@ function parseChecksums(content) {
4853 const checksums = { }
4954 for ( const line of content . split ( '\n' ) ) {
5055 const trimmed = line . trim ( )
51- if ( ! trimmed ) continue
56+ if ( ! trimmed ) {
57+ continue
58+ }
5259 // Format: hash filename (two spaces or whitespace between)
5360 const match = trimmed . match ( / ^ ( [ a - f 0 - 9 ] { 64 } ) \s + ( .+ ) $ / )
5461 if ( match ) {
@@ -64,7 +71,7 @@ function parseChecksums(content) {
6471async function downloadFile ( url , destPath ) {
6572 const response = await fetch ( url , {
6673 headers : {
67- ' Accept' : 'application/octet-stream' ,
74+ Accept : 'application/octet-stream' ,
6875 'User-Agent' : 'socket-cli-sync-checksums' ,
6976 } ,
7077 redirect : 'follow' ,
@@ -87,21 +94,27 @@ async function downloadFile(url, destPath) {
8794 * Fetch checksums for a GitHub release.
8895 * First tries checksums.txt, then falls back to downloading assets.
8996 */
90- async function fetchGitHubReleaseChecksums ( repo , releaseTag , existingChecksums = { } ) {
97+ async function fetchGitHubReleaseChecksums (
98+ repo ,
99+ releaseTag ,
100+ existingChecksums = { } ,
101+ ) {
91102 const [ owner , repoName ] = repo . split ( '/' )
92103 const apiUrl = `https://api.github.com/repos/${ owner } /${ repoName } /releases/tags/${ releaseTag } `
93104
94105 console . log ( ` Fetching release info from ${ apiUrl } ...` )
95106
96107 const response = await fetch ( apiUrl , {
97108 headers : {
98- ' Accept' : 'application/vnd.github.v3+json' ,
109+ Accept : 'application/vnd.github.v3+json' ,
99110 'User-Agent' : 'socket-cli-sync-checksums' ,
100111 } ,
101112 } )
102113
103114 if ( ! response . ok ) {
104- throw new Error ( `GitHub API error: ${ response . status } ${ response . statusText } ` )
115+ throw new Error (
116+ `GitHub API error: ${ response . status } ${ response . statusText } ` ,
117+ )
105118 }
106119
107120 const release = await response . json ( )
@@ -111,7 +124,9 @@ async function fetchGitHubReleaseChecksums(repo, releaseTag, existingChecksums =
111124 const checksumsAsset = assets . find ( a => a . name === 'checksums.txt' )
112125 if ( checksumsAsset ) {
113126 console . log ( ` Found checksums.txt, downloading...` )
114- const tempDir = await fs . mkdtemp ( path . join ( os . tmpdir ( ) , 'socket-checksums-' ) )
127+ const tempDir = await fs . mkdtemp (
128+ path . join ( os . tmpdir ( ) , 'socket-checksums-' ) ,
129+ )
115130 const checksumPath = path . join ( tempDir , 'checksums.txt' )
116131
117132 try {
@@ -122,7 +137,9 @@ async function fetchGitHubReleaseChecksums(repo, releaseTag, existingChecksums =
122137 // Clean up.
123138 await fs . rm ( tempDir , { recursive : true } )
124139
125- console . log ( ` Parsed ${ Object . keys ( checksums ) . length } checksums from checksums.txt` )
140+ console . log (
141+ ` Parsed ${ Object . keys ( checksums ) . length } checksums from checksums.txt` ,
142+ )
126143 return checksums
127144 } catch ( error ) {
128145 console . log ( ` Failed to download checksums.txt: ${ error . message } ` )
@@ -139,7 +156,9 @@ async function fetchGitHubReleaseChecksums(repo, releaseTag, existingChecksums =
139156 return { }
140157 }
141158
142- console . log ( ` No checksums.txt found, downloading ${ assetNames . length } assets to compute checksums...` )
159+ console . log (
160+ ` No checksums.txt found, downloading ${ assetNames . length } assets to compute checksums...` ,
161+ )
143162
144163 const tempDir = await fs . mkdtemp ( path . join ( os . tmpdir ( ) , 'socket-checksums-' ) )
145164 const checksums = { }
@@ -192,24 +211,32 @@ async function main() {
192211 // Find all GitHub-released tools.
193212 const githubTools = Object . entries ( externalTools )
194213 . filter ( ( [ key , value ] ) => {
195- if ( key . startsWith ( '$' ) ) return false // Skip schema keys
214+ if ( key . startsWith ( '$' ) ) {
215+ return false
216+ } // Skip schema keys
196217 return value . release === 'asset'
197218 } )
198219 . map ( ( [ key , value ] ) => ( { key, ...value } ) )
199220
200221 if ( toolFilter ) {
201222 const filtered = githubTools . filter ( t => t . key === toolFilter )
202223 if ( filtered . length === 0 ) {
203- console . error ( `Error: Tool '${ toolFilter } ' not found or is not a GitHub release tool` )
204- console . log ( `Available GitHub release tools: ${ githubTools . map ( t => t . key ) . join ( ', ' ) } ` )
224+ console . error (
225+ `Error: Tool '${ toolFilter } ' not found or is not a GitHub release tool` ,
226+ )
227+ console . log (
228+ `Available GitHub release tools: ${ githubTools . map ( t => t . key ) . join ( ', ' ) } ` ,
229+ )
205230 process . exitCode = 1
206231 return
207232 }
208233 githubTools . length = 0
209234 githubTools . push ( ...filtered )
210235 }
211236
212- console . log ( `Syncing checksums for ${ githubTools . length } GitHub release tool(s)...\n` )
237+ console . log (
238+ `Syncing checksums for ${ githubTools . length } GitHub release tool(s)...\n` ,
239+ )
213240
214241 let updated = 0
215242 let unchanged = 0
@@ -235,10 +262,13 @@ async function main() {
235262
236263 // Check if update is needed.
237264 const oldChecksums = tool . checksums || { }
238- const checksumChanged = JSON . stringify ( newChecksums ) !== JSON . stringify ( oldChecksums )
265+ const checksumChanged =
266+ JSON . stringify ( newChecksums ) !== JSON . stringify ( oldChecksums )
239267
240268 if ( ! force && ! checksumChanged ) {
241- console . log ( ` Unchanged: ${ Object . keys ( newChecksums ) . length } checksums\n` )
269+ console . log (
270+ ` Unchanged: ${ Object . keys ( newChecksums ) . length } checksums\n` ,
271+ )
242272 unchanged ++
243273 continue
244274 }
@@ -269,7 +299,9 @@ async function main() {
269299 }
270300
271301 // Summary.
272- console . log ( `\nSummary: ${ updated } updated, ${ unchanged } unchanged, ${ failed } failed` )
302+ console . log (
303+ `\nSummary: ${ updated } updated, ${ unchanged } unchanged, ${ failed } failed` ,
304+ )
273305
274306 if ( failed > 0 ) {
275307 process . exitCode = 1
0 commit comments