1 | "use strict";
|
2 |
|
3 | const path = require("path");
|
4 | const loadJsonFile = require("load-json-file");
|
5 | const writeJsonFile = require("write-json-file");
|
6 |
|
7 | module.exports.updateLockfileVersion = updateLockfileVersion;
|
8 |
|
9 | function 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 | }
|