Skip to content

Commit

Permalink
feat(version): option to not ignore scripts on lock update (#3823)
Browse files Browse the repository at this point in the history
  • Loading branch information
matheo committed Sep 6, 2023
1 parent 489aa92 commit 4843c3c
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 2 deletions.
6 changes: 6 additions & 0 deletions libs/commands/version/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ Running `lerna version --conventional-commits` without the above flags will rele
- [`--no-push`](#--no-push)
- [`--npm-client-args`](#--npm-client-args)
- [`--preid`](#--preid)
- [`--run-scripts-on-lockfile-update`](#--run-scripts-on-lockfile-update)
- [`--signoff-git-commit`](#--signoff-git-commit)
- [`--sign-git-commit`](#--sign-git-commit)
- [`--sign-git-tag`](#--sign-git-tag)
Expand Down Expand Up @@ -502,6 +503,11 @@ lerna version prepatch --preid next
When run with this flag, `lerna version` will increment `premajor`, `preminor`, `prepatch`, or `prerelease` semver
bumps using the specified [prerelease identifier](http://semver.org/#spec-item-9).

### `--run-scripts-on-lockfile-update`

By default, `lerna version` skips any lifecycle script when syncing the package-lock file after the version bump.
With this option it will run `prepare`, `postinstall`, etc.

### `--signoff-git-commit`

Adds the `--signoff` flag to the git commit done by lerna version when executed.
Expand Down
4 changes: 4 additions & 0 deletions libs/commands/version/src/command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,10 @@ const command: CommandModule = {
"Allows users to specify a custom command to be used when applying git tags. For example, this may be useful for providing a wrapper command in CI/CD pipelines that have no direct write access.",
type: "string",
},
"run-scripts-on-lockfile-update": {
describe: "Do not disable all lifecycle scripts while updating the lock file after the version bump.",
type: "boolean",
},
"npm-client-args": {
describe: "Additional arguments to pass to the npm client when performing 'npm install'.",
type: "array",
Expand Down
16 changes: 14 additions & 2 deletions libs/commands/version/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ interface VersionCommandConfigOptions extends CommandConfigOptions {
gitTagCommand?: string;
message?: string;
npmClientArgs?: string[];
runScriptsOnLockfileUpdate?: boolean;
changelogPreset?: string;
changelogEntryAdditionalMarkdown?: string;
conventionalBumpPrerelease?: boolean;
Expand Down Expand Up @@ -622,6 +623,7 @@ class VersionCommand extends Command {
changelogPreset,
changelogEntryAdditionalMarkdown,
changelog = true,
runScriptsOnLockfileUpdate = false,
syncDistVersion = false,
} = this.options;
const independentVersions = this.project.isIndependent();
Expand Down Expand Up @@ -740,7 +742,12 @@ class VersionCommand extends Command {
this.logger.verbose("version", "Updating root pnpm-lock.yaml");
await childProcess.exec(
"pnpm",
["install", "--lockfile-only", "--ignore-scripts", ...npmClientArgs],
[
"install",
"--lockfile-only",
!runScriptsOnLockfileUpdate ? "--ignore-scripts" : "",
...npmClientArgs,
].filter(Boolean),
this.execOpts
);

Expand Down Expand Up @@ -773,7 +780,12 @@ class VersionCommand extends Command {
this.logger.verbose("version", "Updating root package-lock.json");
await childProcess.exec(
"npm",
["install", "--package-lock-only", "--ignore-scripts", ...npmClientArgs],
[
"install",
"--package-lock-only",
!runScriptsOnLockfileUpdate ? "--ignore-scripts" : "",
...npmClientArgs,
].filter(Boolean),
this.execOpts
);
changedFiles.add(lockfilePath);
Expand Down
7 changes: 7 additions & 0 deletions packages/lerna/schemas/lerna-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -1003,6 +1003,9 @@
"gitTagVersion": {
"$ref": "#/$defs/commandOptions/version/gitTagVersion"
},
"runScriptsOnLockfileUpdate": {
"$ref": "#/$defs/commandOptions/version/runScriptsOnLockfileUpdate"
},
"syncDistVersion": {
"$ref": "#/$defs/commandOptions/version/syncDistVersion"
},
Expand Down Expand Up @@ -1703,6 +1706,10 @@
"type": "boolean",
"description": "During `lerna version`, when true, commit and tag version changes."
},
"runScriptsOnLockfileUpdate": {
"type": "boolean",
"description": "During `lerna version`, when true, runs lifecycle scripts when syncing the lock file after the version bump."
},
"syncDistVersion": {
"type": "boolean",
"description": "During `lerna version`, when true, updates the version of the contents directory."
Expand Down

0 comments on commit 4843c3c

Please sign in to comment.