Install dev dependencies separately

This commit is contained in:
2026-02-28 15:57:37 +01:00
parent 96e58bbf62
commit df9ee2814f
3 changed files with 31 additions and 5 deletions

1
.npmrc Normal file
View File

@@ -0,0 +1 @@
prefer-offline = true

View File

@@ -9,7 +9,6 @@ This is a Viem and Hardhat 3 project. To get started, please read the instructio
To start the lab, run: To start the lab, run:
```shell ```shell
npm install
npm run start npm run start
``` ```

View File

@@ -1,5 +1,8 @@
import fs from 'fs'; 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() { export function installDeps() {
// check if node_modules exists // check if node_modules exists
@@ -8,7 +11,30 @@ export function installDeps() {
} }
// install dependencies // install dependencies
console.log('Installing dependencies...'); console.log('Installing mandatory dependencies...');
execSync('npm install', { stdio: 'inherit' }); execSync('npm install --omit=dev', { stdio: 'inherit' });
console.log('Dependencies installed'); 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.');
}
}
} }