diff --git a/.npmrc b/.npmrc new file mode 100644 index 0000000..ce8ae4e --- /dev/null +++ b/.npmrc @@ -0,0 +1 @@ +prefer-offline = true \ No newline at end of file diff --git a/README.md b/README.md index d17136c..4924a64 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,6 @@ This is a Viem and Hardhat 3 project. To get started, please read the instructio To start the lab, run: ```shell -npm install npm run start ``` diff --git a/exam/common.js b/exam/common.js index 654e595..7bc36dc 100644 --- a/exam/common.js +++ b/exam/common.js @@ -1,5 +1,8 @@ import fs from 'fs'; -import { execSync } from 'child_process'; +import { exec, execSync } from 'child_process'; +import { promisify } from 'util'; + +const execPromise = promisify(exec); export function installDeps() { // check if node_modules exists @@ -8,7 +11,30 @@ export function installDeps() { } // install dependencies - console.log('Installing dependencies...'); - execSync('npm install', { stdio: 'inherit' }); - console.log('Dependencies installed'); + console.log('Installing mandatory dependencies...'); + execSync('npm install --omit=dev', { stdio: 'inherit' }); + console.log('Mandatory dependencies installed'); + + // install dev dependencies (in the background) + console.log(); console.log(); console.log(); + console.log('Installing dev dependencies...'); + installDevDeps(); +} + +async function installDevDeps(attempt = 1) { + try { + await execPromise('npm install', { stdio: 'inherit' }); + console.log('Dev dependencies installed'); + } catch (error) { + console.error('Error installing dev dependencies:', error.message); + + if (attempt < 3) { + const retryDelay = 5000 * attempt; + console.log(`Retrying in ${Math.round(retryDelay / 1000)} seconds...`); + setTimeout(() => installDevDeps(attempt + 1), retryDelay); + } else { + console.error('Failed to install dev dependencies.'); + console.error('Please try again manually, by running "npm install" in the project directory.'); + } + } }