From 190a8977284e827116b8188b6211959f58a07bd0 Mon Sep 17 00:00:00 2001 From: ox42 Date: Sun, 1 Mar 2026 14:27:34 +0100 Subject: [PATCH] Install dev dependencies separately --- .npmrc | 1 + README.md | 1 - exam/common.js | 34 ++++++++++++++++++++++++++++++---- 3 files changed, 31 insertions(+), 5 deletions(-) create mode 100644 .npmrc 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 882559f..e0f9cfc 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..360be11 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.'); + } + } +} \ No newline at end of file