Skip to content
Snippets Groups Projects
Select Git revision
  • fbcfde2c4f269f0bf9b9d960faa850a091080ec1
  • main default protected
  • renovate/main-ghcr.io-renovatebot-base-image-10.x
  • renovate/main-ghcr.io-containerbase-devcontainer-13.x
  • next
  • revert-31645-feat/rename-gradle-wrapper-validation-action
  • renovate/main-redis-5.x
  • fix/36615b-branch-reuse-no-cache
  • chore/punycode
  • fix/36615-branch-reuse-bug
  • refactor/pin-new-value
  • feat/36219--git-x509-signing
  • feat/structured-logger
  • hotfix/39.264.1
  • feat/skip-dangling
  • gh-readonly-queue/next/pr-36034-7a061c4ca1024a19e2c295d773d9642625d1c2be
  • hotfix/39.238.3
  • refactor/gitlab-auto-approve
  • feat/template-strings
  • gh-readonly-queue/next/pr-35654-137d934242c784e0c45d4b957362214f0eade1d7
  • fix/32307-global-extends-merging
  • 41.31.1
  • 41.31.0
  • 41.30.5
  • 41.30.4
  • 41.30.3
  • 41.30.2
  • 41.30.1
  • 41.30.0
  • 41.29.1
  • 41.29.0
  • 41.28.2
  • 41.28.1
  • 41.28.0
  • 41.27.1
  • 41.27.0
  • 41.26.2
  • 41.26.1
  • 41.26.0
  • 41.25.1
  • 41.25.0
41 results

index.ts

Blame
  • yarn.js 2.75 KiB
    const fs = require('fs-extra');
    const upath = require('upath');
    const { getInstalledPath } = require('get-installed-path');
    const { exec } = require('child-process-promise');
    
    module.exports = {
      generateLockFile,
    };
    
    async function generateLockFile(tmpDir, env) {
      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 = upath.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 = upath.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 = upath.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';
        cmd += ' --ignore-platform';
        cmd += process.env.YARN_MUTEX_FILE
          ? ` --mutex file:${process.env.YARN_MUTEX_FILE}`
          : ' --mutex network:31879';
    
        // TODO: Switch to native util.promisify once using only node 8
        ({ stdout, stderr } = await exec(cmd, {
          cwd: tmpDir,
          shell: true,
          env,
        }));
        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(upath.join(tmpDir, 'yarn.lock'), 'utf8');
        logger.info(
          { seconds, type: 'yarn.lock', stdout, stderr },
          'Generated lockfile'
        );
      } catch (err) /* istanbul ignore next */ {
        logger.info(
          {
            err,
            stdout,
            stderr,
          },
          'yarn install error'
        );
        if (err.stderr && err.stderr.includes('ENOSPC: no space left on device')) {
          throw new Error('Out of disk space when generating yarn.lock');
        }
        return { error: true, stderr: err.stderr };
      }
      return { lockFile };
    }