Skip to content
Snippets Groups Projects
Select Git revision
  • 8fadb8a01f394dabfa5837259075ad5941614cea
  • main default protected
  • renovate/github.com-prometheus-client_golang-1.x
  • renovate/immich
  • renovate/oauth2-proxy-7.x
  • renovate/ghcr.io-siderolabs-talosctl-1.x
  • renovate/siderolabs-talos-1.10.x
  • renovate/docker.io-helmunittest-helm-unittest-3.x
  • renovate/hcloud-exporter-4.x
  • renovate/gitlab-runner-0.x
  • renovate/redis-21.x
  • renovate/cloudflare-5.x
  • renovate/mikefarah-yq-4.x
  • renovate/prometheus-json-exporter-0.x
  • renovate/prometheus-smartctl-exporter-0.x
  • renovate/gcr.io-projectsigstore-cosign-2.x
  • renovate/docker.io-bitnami-kubectl-1.x
  • renovate/siderolabs-kubelet-1.33.x
  • renovate/mariadb-21.x
  • renovate/kubernetes-go
  • renovate/external-dns-1.x
  • v25.07
  • v25.06
  • v25.05
  • v25.04
  • v25.03
  • v25.02
  • v25.01
  • v24.12
  • v24.11
  • v24.10
  • v24.09
  • v24.08
  • v24.07
  • v24.06
  • v24.05
  • v24.04
  • v24.03
  • v24.02
  • v24.01
  • v23.12
41 results

validate.sh

Blame
  • npm.js 2.49 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) {
      logger.debug(`Spawning npm install to create ${tmpDir}/package-lock.json`);
      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('npm', {
              local: true,
            }),
            'bin/npm-cli.js'
          );
          cmd = `node ${installedPath}`;
        } catch (localerr) {
          logger.debug('No locally installed npm found');
          // Look inside globally installed renovate
          try {
            const renovateLocation = await getInstalledPath('renovate');
            const installedPath = upath.join(
              await getInstalledPath('npm', {
                local: true,
                cwd: renovateLocation,
              }),
              'bin/npm-cli.js'
            );
            cmd = `node ${installedPath}`;
          } catch (nestederr) {
            logger.debug('Could not find globally nested npm');
            // look for global npm
            try {
              const installedPath = upath.join(
                await getInstalledPath('npm'),
                'bin/npm-cli.js'
              );
              cmd = `node ${installedPath}`;
            } catch (globalerr) {
              logger.warn('Could not find globally installed npm');
              cmd = 'npm';
            }
          }
        }
        logger.debug(`Using npm: ${cmd}`);
        cmd = `ls -l && ${cmd} --version && ${cmd} install --package-lock-only`;
        // 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(`npm stdout:\n${stdout}`);
        logger.debug(`npm stderr:\n${stderr}`);
        const duration = process.hrtime(startTime);
        const seconds = Math.round(duration[0] + duration[1] / 1e9);
        lockFile = await fs.readFile(
          upath.join(tmpDir, 'package-lock.json'),
          'utf8'
        );
        logger.info(
          { seconds, type: 'package-lock.json', stdout, stderr },
          'Generated lockfile'
        );
      } catch (err) /* istanbul ignore next */ {
        logger.warn(
          {
            err,
            stdout,
            stderr,
          },
          'npm install error'
        );
        return { error: true, stderr };
      }
      return { lockFile };
    }