All files / src/install-from-boilerplate install-consumer-dependencies.js

100% Statements 10/10
100% Branches 5/5
100% Functions 1/1
100% Lines 10/10

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 322x 2x                 3x   3x             3x 1x     2x 1x     1x     2x  
const { spawnSync } = require('node:child_process');
const Logger = require('../utils/logger');
 
/**
 * Installs the consuming repo's dependencies after package.json was rewritten.
 * Uses the caller's PATH so nvm / fnm / Windows npm.cmd keep working.
 *
 * @param {string} [cwd=process.cwd()] - Consuming project root.
 */
function installConsumerDependencies(cwd = process.cwd()) {
    Logger.info('Installing updated dependencies...');
 
    const result = spawnSync('npm', ['install'], {
        cwd,
        stdio: 'inherit',
        env: process.env,
        shell: process.platform === 'win32'
    });
 
    if (result.error) {
        throw result.error;
    }
 
    if (result.status !== 0) {
        throw new Error(`npm install failed with exit code ${result.status}`);
    }
 
    Logger.success('Dependencies installed');
}
 
module.exports = installConsumerDependencies;