forked from lerna/lerna
/
update-lockfile-version.js
37 lines (29 loc) · 1005 Bytes
/
update-lockfile-version.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
"use strict";
const path = require("path");
const loadJsonFile = require("load-json-file");
const writeJsonFile = require("write-json-file");
module.exports.updateLockfileVersion = updateLockfileVersion;
function updateLockfileVersion(pkg) {
const lockfilePath = path.join(pkg.location, "package-lock.json");
let chain = Promise.resolve();
chain = chain.then(() => loadJsonFile(lockfilePath).catch(() => {}));
chain = chain.then((obj) => {
if (obj) {
obj.version = pkg.version;
if (obj.packages && obj.packages[""]) {
obj.packages[""].version = pkg.version;
if (obj.packages[""].dependencies) {
obj.packages[""].dependencies = pkg.dependencies;
}
if (obj.packages[""].devDependencies) {
obj.packages[""].devDependencies = pkg.devDependencies;
}
}
return writeJsonFile(lockfilePath, obj, {
detectIndent: true,
indent: 2,
}).then(() => lockfilePath);
}
});
return chain;
}