Skip to content
Snippets Groups Projects
Select Git revision
  • e27f575347b382d7dc17fb967e4804c5701c8c20
  • main default protected
  • release-0.14
  • 14-env
  • fix-version-3
  • automated-updates-fix-action
  • release-0.15
  • automated-updates-main
  • release-0.13
  • automated-updates-release-0.13
  • release-0.10
  • release-0.11
  • release-0.12
  • fix-versions-action
  • versions-fix
  • release-0.9
  • release-0.8
  • release-0.7
  • release-0.6
  • release-0.5
  • release-0.4
  • v0.15.0
  • v0.14.0
  • v0.13.0
  • v0.12.0
  • v0.11.0
  • v0.10.0
  • v0.9.0
  • v0.8.0
  • v0.7.0
  • v0.6.0
  • v0.5.0
  • v0.4.0
  • v0.3.0
  • v0.2.0
  • v0.1.0
36 results

tools.go

Blame
  • yarn.js 2.44 KiB
    const fs = require('fs-extra');
    const path = require('path');
    const { getInstalledPath } = require('get-installed-path');
    const { exec } = require('child-process-promise');
    
    module.exports = {
      generateLockFile,
    };
    
    async function generateLockFile(tmpDir) {
      logger.debug(`Spawning yarn install to create ${tmpDir}/yarn.lock`);
      let lockFile = null;
      let stdout;
      let stderr;
      try {
        const startTime = process.hrtime();
        let cmd;
        try {
          // See if renovate is installed locally
          const installedPath = path.join(
            await getInstalledPath('yarn', {
              local: true,
            }),
            'bin/yarn.js'
          );
          cmd = `node ${installedPath}`;
        } catch (localerr) {
          logger.debug('No locally installed yarn found');
          // Look inside globally installed renovate
          try {
            const renovateLocation = await getInstalledPath('renovate');
            const installedPath = path.join(
              await getInstalledPath('yarn', {
                local: true,
                cwd: renovateLocation,
              }),
              'bin/yarn.js'
            );
            cmd = `node ${installedPath}`;
          } catch (nestederr) {
            logger.debug('Could not find globally nested yarn');
            // look for global yarn
            try {
              const installedPath = path.join(
                await getInstalledPath('yarn'),
                'bin/yarn.js'
              );
              cmd = `node ${installedPath}`;
            } catch (globalerr) {
              logger.warn('Could not find globally installed yarn');
              cmd = 'yarn';
            }
          }
        }
        logger.debug(`Using yarn: ${cmd}`);
        cmd += ' install';
        cmd += ' --ignore-scripts';
        cmd += ' --ignore-engines';
        // TODO: Switch to native util.promisify once using only node 8
        ({ stdout, stderr } = await exec(cmd, {
          cwd: tmpDir,
          shell: true,
          env: { NODE_ENV: 'dev', PATH: process.env.PATH },
        }));
        logger.debug(`yarn stdout:\n${stdout}`);
        logger.debug(`yarn stderr:\n${stderr}`);
        const duration = process.hrtime(startTime);
        const seconds = Math.round(duration[0] + duration[1] / 1e9);
        lockFile = await fs.readFile(path.join(tmpDir, 'yarn.lock'), 'utf8');
        logger.info(
          { seconds, type: 'yarn.lock', stdout, stderr },
          'Generated lockfile'
        );
      } catch (err) /* istanbul ignore next */ {
        logger.info(
          {
            err,
          },
          'yarn install error'
        );
        return { error: true, stderr: err.stderr };
      }
      return { lockFile };
    }