UNPKG

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