Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/npm/cli.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorRuy Adorno <ruyadorno@hotmail.com>2022-03-24 18:46:54 +0300
committerGitHub <noreply@github.com>2022-03-24 18:46:54 +0300
commit723a0918a5a9d9f795584f85d04506fafda9ca42 (patch)
tree37f0f659d7b81abd9b6cb6d2038ce83571e2c2b4 /lib
parent362831c4eba2554b44feec60fdff197d92eac0c1 (diff)
feat(version): reify on workspace version change (#4588)
Adds a minimalistic reify step that updates the installed tree after a version change within one of the configured workspaces when using any of the workspaces config options. It's also possible to use the `--save` config option in order to auto update semver ranges of dependencies declarations accross dependent `package.json` files. Fixes: https://github.com/npm/cli/issues/3403 Relates to: https://github.com/npm/rfcs/issues/556 Relates to: https://github.com/npm/cli/issues/3757 Relates to: https://github.com/npm/cli/issues/4193
Diffstat (limited to 'lib')
-rw-r--r--lib/commands/version.js35
-rw-r--r--lib/utils/config/definitions.js10
2 files changed, 45 insertions, 0 deletions
diff --git a/lib/commands/version.js b/lib/commands/version.js
index f49a309a7..ed506f663 100644
--- a/lib/commands/version.js
+++ b/lib/commands/version.js
@@ -3,6 +3,9 @@ const { resolve } = require('path')
const { promisify } = require('util')
const readFile = promisify(require('fs').readFile)
+const Arborist = require('@npmcli/arborist')
+const reifyFinish = require('../utils/reify-finish.js')
+
const BaseCommand = require('../base-command.js')
class Version extends BaseCommand {
@@ -17,6 +20,7 @@ class Version extends BaseCommand {
'sign-git-tag',
'workspace',
'workspaces',
+ 'workspaces-update',
'include-workspace-root',
]
@@ -81,6 +85,7 @@ class Version extends BaseCommand {
async changeWorkspaces (args, filters) {
const prefix = this.npm.config.get('tag-version-prefix')
await this.setWorkspaces(filters)
+ const updatedWorkspaces = []
for (const [name, path] of this.workspaces) {
this.npm.output(name)
const version = await libnpmversion(args[0], {
@@ -88,8 +93,10 @@ class Version extends BaseCommand {
'git-tag-version': false,
path,
})
+ updatedWorkspaces.push(name)
this.npm.output(`${prefix}${version}`)
}
+ return this.update(updatedWorkspaces)
}
async list (results = {}) {
@@ -129,6 +136,34 @@ class Version extends BaseCommand {
}
return this.list(results)
}
+
+ async update (args) {
+ if (!this.npm.flatOptions.workspacesUpdate || !args.length) {
+ return
+ }
+
+ // default behavior is to not save by default in order to avoid
+ // race condition problems when publishing multiple workspaces
+ // that have dependencies on one another, it might still be useful
+ // in some cases, which then need to set --save
+ const save = this.npm.config.isDefault('save')
+ ? false
+ : this.npm.config.get('save')
+
+ // runs a minimalistic reify update, targetting only the workspaces
+ // that had version updates and skipping fund/audit/save
+ const opts = {
+ ...this.npm.flatOptions,
+ audit: false,
+ fund: false,
+ path: this.npm.localPrefix,
+ save,
+ }
+ const arb = new Arborist(opts)
+
+ await arb.reify({ ...opts, update: args })
+ await reifyFinish(this.npm, arb)
+ }
}
module.exports = Version
diff --git a/lib/utils/config/definitions.js b/lib/utils/config/definitions.js
index ddccb1475..abc989d0e 100644
--- a/lib/utils/config/definitions.js
+++ b/lib/utils/config/definitions.js
@@ -2270,6 +2270,16 @@ define('workspaces', {
},
})
+define('workspaces-update', {
+ default: true,
+ type: Boolean,
+ description: `
+ If set to true, the npm cli will run an update after operations that may
+ possibly change the workspaces installed to the \`node_modules\` folder.
+ `,
+ flatten,
+})
+
define('yes', {
default: null,
type: [null, Boolean],