update-lockfile-version.js 663 B

123456789101112131415161718192021222324252627
  1. "use strict";
  2. const path = require("path");
  3. const loadJsonFile = require("load-json-file");
  4. const writeJsonFile = require("write-json-file");
  5. module.exports.updateLockfileVersion = updateLockfileVersion;
  6. function updateLockfileVersion(pkg) {
  7. const lockfilePath = path.join(pkg.location, "package-lock.json");
  8. let chain = Promise.resolve();
  9. chain = chain.then(() => loadJsonFile(lockfilePath).catch(() => {}));
  10. chain = chain.then((obj) => {
  11. if (obj) {
  12. obj.version = pkg.version;
  13. return writeJsonFile(lockfilePath, obj, {
  14. detectIndent: true,
  15. indent: 2,
  16. }).then(() => lockfilePath);
  17. }
  18. });
  19. return chain;
  20. }