diff --git a/package-lock.json b/package-lock.json index 9b742b23..1ae98cbb 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "zkapp-cli", - "version": "0.6.3", + "version": "0.6.4", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "zkapp-cli", - "version": "0.6.3", + "version": "0.6.4", "hasInstallScript": true, "license": "Apache-2.0", "dependencies": { diff --git a/package.json b/package.json index 2cdc3182..f15cbf66 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "zkapp-cli", - "version": "0.6.3", + "version": "0.6.4", "description": "CLI to create a zkApp (\"zero-knowledge app\") for Mina Protocol.", "keywords": [ "cli", diff --git a/src/postinstall.js b/src/postinstall.js index 6e47a1ea..d8a2b3ac 100644 --- a/src/postinstall.js +++ b/src/postinstall.js @@ -43,6 +43,7 @@ async function warmNpmCache() { try { for await (const pkgWithVersion of toCache) { + console.log(` Adding ${pkgWithVersion} to the cache.`); await shExec(`npm cache add ${pkgWithVersion}`); } console.log(' Done.'); @@ -55,9 +56,37 @@ async function warmGittarCache() { console.log(' Warm cache for project template.'); try { + const fetchMaxTimeLimit = 15000; const src = 'github:o1-labs/zkapp-cli#main'; - await gittar.fetch(src, { force: true }); + console.log(' Fetching project template.'); + // Skips "Warm cache for project template" step if operation takes + // longer than the fetch max time limit. + const response = await executeInTimeLimit( + gittar.fetch(src, { force: true }), + fetchMaxTimeLimit + ); + + if (response === null) { + console.log(' Skip warm cache for project template'); + return; + } } catch (err) { console.error(err); } } + +async function executeInTimeLimit(operation, maxTimeLimit) { + let timeout; + + const timeoutPromise = new Promise((resolve, reject) => { + timeout = setTimeout(() => { + resolve(null); + }, maxTimeLimit); + }); + + const response = await Promise.race([operation, timeoutPromise]); + + if (timeout) clearTimeout(timeout); + + return response; +}