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
diff options
context:
space:
mode:
authorRuy Adorno <ruyadorno@hotmail.com>2022-06-02 00:11:16 +0300
committerGitHub <noreply@github.com>2022-06-02 00:11:16 +0300
commitaee6fc857458ac660bf90ecd0af94212c7269fd7 (patch)
tree464eec61f9a60ea2e97d76ffd04f6a886f6b1396 /lib/workspaces
parent66981ecf08b888fde9188c162cc928fff7d6d9d6 (diff)
feat(init): reify on init new workspace (#4892)
Adds a minimalistic reify step that updates the installed tree after initializing a new workspace. Moved the shared update logic from `lib/commands/version.js` to a `lib/workspaces/update-workspaces.js` module that is reused between both `npm version` and `npm init`. Relates to: https://github.com/npm/rfcs/issues/556 Relates to: https://github.com/npm/cli/pull/4588
Diffstat (limited to 'lib/workspaces')
-rw-r--r--lib/workspaces/update-workspaces.js40
1 files changed, 40 insertions, 0 deletions
diff --git a/lib/workspaces/update-workspaces.js b/lib/workspaces/update-workspaces.js
new file mode 100644
index 000000000..4cba1245a
--- /dev/null
+++ b/lib/workspaces/update-workspaces.js
@@ -0,0 +1,40 @@
+'use strict'
+
+const Arborist = require('@npmcli/arborist')
+const reifyFinish = require('../utils/reify-finish.js')
+
+async function updateWorkspaces ({
+ config,
+ flatOptions,
+ localPrefix,
+ npm,
+ workspaces,
+}) {
+ if (!flatOptions.workspacesUpdate || !workspaces.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 = config.isDefault('save')
+ ? false
+ : config.get('save')
+
+ // runs a minimalistic reify update, targetting only the workspaces
+ // that had version updates and skipping fund/audit/save
+ const opts = {
+ ...flatOptions,
+ audit: false,
+ fund: false,
+ path: localPrefix,
+ save,
+ }
+ const arb = new Arborist(opts)
+
+ await arb.reify({ ...opts, update: workspaces })
+ await reifyFinish(npm, arb)
+}
+
+module.exports = updateWorkspaces