Skip to content

Commit

Permalink
fix(version): update package-lock in the root if exists
Browse files Browse the repository at this point in the history
  • Loading branch information
fahslaj committed Aug 12, 2022
1 parent 20bdc18 commit a87c1da
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions commands/version/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ const pPipe = require("p-pipe");
const pReduce = require("p-reduce");
const pWaterfall = require("p-waterfall");
const semver = require("semver");
const path = require("path");
const fs = require("fs");

const { Command } = require("@lerna/command");
const { recommendVersion, updateChangelog } = require("@lerna/conventional-commits");
Expand All @@ -20,6 +22,7 @@ const { createRunner } = require("@lerna/run-lifecycle");
const { runTopologically } = require("@lerna/run-topologically");
const { ValidationError } = require("@lerna/validation-error");
const { prereleaseIdFromVersion } = require("@lerna/prerelease-id-from-version");
const childProcess = require("@lerna/child-process");

const { getCurrentBranch } = require("./lib/get-current-branch");
const { gitAdd } = require("./lib/git-add");
Expand Down Expand Up @@ -610,6 +613,18 @@ class VersionCommand extends Command {
);
}

if (this.options.npmClient === "npm" || !this.options.npmClient) {
const lockfilePath = path.join(this.project.rootPath, "package-lock.json");
if (fs.existsSync(lockfilePath)) {
chain = chain.then(() => {
this.logger.verbose("version", "Updating root package-lock.json");
return childProcess.exec("npm", ["install", "--package-lock-only"], this.execOpts).then(() => {
changedFiles.add(lockfilePath);
});
});
}
}

if (!this.hasRootedLeaf) {
// exec version lifecycle in root (after all updates)
chain = chain.then(() => this.runRootLifecycle("version"));
Expand Down

0 comments on commit a87c1da

Please sign in to comment.