Sha256: e760755f172de44782e1efe9f22d3702c1f371d236d5f579e1d51aa6c41d0c43

Contents?: true

Size: 1.56 KB

Versions: 173

Compression:

Stored size: 1.56 KB

Contents

const fs = require("fs");
const path = require("path");
const npm = require("npm");
const installer = require("npm/lib/install");

const { muteStderr, runAsync } = require("./helpers.js");

async function updateDependencyFile(directory, lockfileName) {
  const readFile = fileName =>
    fs.readFileSync(path.join(directory, fileName)).toString();

  // `force: true` ignores checks for platform (os, cpu) and engines
  // in npm/lib/install/validate-args.js
  // Platform is checked and raised from (EBADPLATFORM):
  // https://github.com/npm/npm-install-checks
  await runAsync(npm, npm.load, [{ loglevel: "silent", force: true }]);

  const dryRun = true;
  const initialInstaller = new installer.Installer(directory, dryRun, [], {
    packageLockOnly: true
  });

  // A bug in npm means the initial install will remove any git dependencies
  // from the lockfile. A subsequent install with no arguments fixes this.
  const cleanupInstaller = new installer.Installer(directory, dryRun, [], {
    packageLockOnly: true
  });

  // Skip printing the success message
  initialInstaller.printInstalled = cb => cb();
  cleanupInstaller.printInstalled = cb => cb();

  // There are some hard-to-prevent bits of output.
  // This is horrible, but works.
  const unmute = muteStderr();
  try {
    await runAsync(initialInstaller, initialInstaller.run, []);
    await runAsync(cleanupInstaller, cleanupInstaller.run, []);
  } finally {
    unmute();
  }

  const updatedLockfile = readFile(lockfileName);

  return { [lockfileName]: updatedLockfile };
}

module.exports = { updateDependencyFile };

Version data entries

173 entries across 173 versions & 2 rubygems

Version Path
dependabot-npm_and_yarn-0.95.26 helpers/npm/lib/subdependency-updater.js
dependabot-npm_and_yarn-0.95.25 helpers/npm/lib/subdependency-updater.js
dependabot-npm_and_yarn-0.95.24 helpers/npm/lib/subdependency-updater.js
dependabot-npm_and_yarn-0.95.23 helpers/npm/lib/subdependency-updater.js
dependabot-npm_and_yarn-0.95.22 helpers/npm/lib/subdependency-updater.js
dependabot-npm_and_yarn-0.95.21 helpers/npm/lib/subdependency-updater.js
dependabot-npm_and_yarn-0.95.20 helpers/npm/lib/subdependency-updater.js
dependabot-npm_and_yarn-0.95.19 helpers/npm/lib/subdependency-updater.js
dependabot-npm_and_yarn-0.95.18 helpers/npm/lib/subdependency-updater.js
dependabot-npm_and_yarn-0.95.17 helpers/npm/lib/subdependency-updater.js
dependabot-npm_and_yarn-0.95.16 helpers/npm/lib/subdependency-updater.js
dependabot-npm_and_yarn-0.95.15 helpers/npm/lib/subdependency-updater.js
dependabot-npm_and_yarn-0.95.14 helpers/npm/lib/subdependency-updater.js
dependabot-npm_and_yarn-0.95.13 helpers/npm/lib/subdependency-updater.js
dependabot-npm_and_yarn-0.95.12 helpers/npm/lib/subdependency-updater.js
dependabot-npm_and_yarn-0.95.11 helpers/npm/lib/subdependency-updater.js
dependabot-npm_and_yarn-0.95.10 helpers/npm/lib/subdependency-updater.js
dependabot-npm_and_yarn-0.95.9 helpers/npm/lib/subdependency-updater.js
dependabot-npm_and_yarn-0.95.8 helpers/npm/lib/subdependency-updater.js
dependabot-npm_and_yarn-0.95.7 helpers/npm/lib/subdependency-updater.js