Skip to content

Commit be3127a

Browse files
authored
[FIX] download commit archive instead of cloning whole repo (#27)
1 parent 5650c0a commit be3127a

File tree

3 files changed

+180
-46
lines changed

3 files changed

+180
-46
lines changed

js/package-lock.json

Lines changed: 123 additions & 21 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

js/package.json

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@reclaimprotocol/zk-symmetric-crypto",
3-
"version": "5.0.1",
3+
"version": "5.0.2",
44
"description": "JS Wrappers for Various ZK Snark Circuits",
55
"type": "module",
66
"exports": {
@@ -54,10 +54,10 @@
5454
"lib"
5555
],
5656
"peerDependencies": {
57+
"@reclaimprotocol/tls": "*",
5758
"koffi": "*",
5859
"p-queue": "*",
59-
"snarkjs": "*",
60-
"@reclaimprotocol/tls": "*"
60+
"snarkjs": "*"
6161
},
6262
"peerDependenciesMeta": {
6363
"snarkjs": {
@@ -79,6 +79,7 @@
7979
"@commitlint/config-conventional": "^17.7.0",
8080
"@reclaimprotocol/tls": "^0.1.0",
8181
"@types/node": "^22.0.0",
82+
"@types/unzipper": "^0.10.11",
8283
"circom_tester": "^0.0.20",
8384
"circomlib": "^2.0.5",
8485
"compare-versions": "^6.1.1",
@@ -87,6 +88,7 @@
8788
"p-queue": "^8.0.0",
8889
"snarkjs": "git+https://github.com/reclaimprotocol/snarkjs.git",
8990
"tinybench": "^3.0.3",
90-
"typescript": "^5.2.2"
91+
"typescript": "^5.2.2",
92+
"unzipper": "^0.12.3"
9193
}
9294
}

js/src/scripts/download-files.ts

Lines changed: 51 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,18 @@
1-
import { exec } from 'child_process'
1+
import { createReadStream, createWriteStream } from 'fs'
22
import { rename, rm } from 'fs/promises'
33
import { dirname, join } from 'path'
4-
import { promisify } from 'util'
4+
import { Readable } from 'stream'
5+
import { pipeline } from 'stream/promises'
6+
import { Extract } from 'unzipper'
57
import { GIT_COMMIT_HASH } from '../config.ts'
6-
import { Logger } from '../types.ts'
8+
import type { Logger } from '../types.ts'
79

8-
const execPromise = promisify(exec)
910

1011
const logger: Logger = console
1112

12-
const CLONE_DIR = './zk-symmetric-crypto'
13-
const CLONE_CMD = [
14-
`git clone https://github.com/reclaimprotocol/zk-symmetric-crypto ${CLONE_DIR}`,
15-
`cd ${CLONE_DIR}`,
16-
`git reset ${GIT_COMMIT_HASH} --hard`
17-
].join(' && ')
13+
const ZIP_URL = `https://github.com/reclaimprotocol/zk-symmetric-crypto/archive/${GIT_COMMIT_HASH}.zip`
14+
const DOWNLOAD_DIR = './zk-symmetric-crypto-download'
15+
const EXTRACTED_DIR = `./zk-symmetric-crypto-${GIT_COMMIT_HASH}`
1816

1917
const __dirname = dirname(import.meta.url.replace('file://', ''))
2018
const BASE_DIR = join(__dirname, '../../')
@@ -23,28 +21,60 @@ const DIRS_TO_COPY = [
2321
'bin'
2422
]
2523

24+
async function downloadAndExtractZip() {
25+
logger.info(`downloading archive from ${ZIP_URL}`)
26+
27+
const response = await fetch(ZIP_URL)
28+
if(!response.ok) {
29+
throw new Error(`Failed to download: ${response.status} ${response.statusText}`)
30+
}
31+
32+
const zipPath = join(DOWNLOAD_DIR, 'repo.zip')
33+
await rm(DOWNLOAD_DIR, { recursive: true, force: true })
34+
await rm(EXTRACTED_DIR, { recursive: true, force: true })
35+
36+
// Create download directory and download ZIP
37+
const { mkdir } = await import('fs/promises')
38+
await mkdir(DOWNLOAD_DIR, { recursive: true })
39+
40+
if(!response.body) {
41+
throw new Error('Response body is null')
42+
}
43+
44+
await pipeline(
45+
// @ts-ignore
46+
Readable.from(response.body),
47+
createWriteStream(zipPath)
48+
)
49+
50+
logger.info('downloaded ZIP, extracting...')
51+
52+
// Extract ZIP
53+
await pipeline(
54+
createReadStream(zipPath),
55+
Extract({ path: './' })
56+
)
57+
58+
logger.info(`extracted to ${EXTRACTED_DIR}`)
59+
}
60+
2661
async function main() {
2762
for(const dir of DIRS_TO_COPY) {
2863
await rm(join(BASE_DIR, dir), { recursive: true, force: true })
2964
logger.info(`removing old "${dir}" directory`)
3065
}
3166

32-
// remove in case it already exists -- we want to clone fresh
33-
await rm(CLONE_DIR, { recursive: true, force: true })
34-
logger.info(`removed old cloned "${CLONE_DIR}" directory`)
35-
36-
logger.info(`cloning repo, #${GIT_COMMIT_HASH}. This may take a while...`)
37-
38-
await execPromise(CLONE_CMD)
39-
logger.info(`cloned repo to "${CLONE_DIR}"`)
67+
await downloadAndExtractZip()
4068

4169
for(const dir of DIRS_TO_COPY) {
42-
await rename(join(CLONE_DIR, dir), join(BASE_DIR, dir))
70+
await rename(join(EXTRACTED_DIR, dir), join(BASE_DIR, dir))
4371
logger.info(`moved "${dir}" directory`)
4472
}
4573

46-
await rm(CLONE_DIR, { recursive: true, force: true })
47-
logger.info(`removed "${CLONE_DIR}" directory`)
74+
// Clean up
75+
await rm(DOWNLOAD_DIR, { recursive: true, force: true })
76+
await rm(EXTRACTED_DIR, { recursive: true, force: true })
77+
logger.info('cleaned up temporary files')
4878

4979
logger.info('done')
5080
}

0 commit comments

Comments
 (0)