11cb0ef41Sopenharmony_ci'use strict'
21cb0ef41Sopenharmony_ci
31cb0ef41Sopenharmony_ciconst reifyFinish = require('../utils/reify-finish.js')
41cb0ef41Sopenharmony_ci
51cb0ef41Sopenharmony_ciasync function updateWorkspaces ({
61cb0ef41Sopenharmony_ci  config,
71cb0ef41Sopenharmony_ci  flatOptions,
81cb0ef41Sopenharmony_ci  localPrefix,
91cb0ef41Sopenharmony_ci  npm,
101cb0ef41Sopenharmony_ci  workspaces,
111cb0ef41Sopenharmony_ci}) {
121cb0ef41Sopenharmony_ci  if (!flatOptions.workspacesUpdate || !workspaces.length) {
131cb0ef41Sopenharmony_ci    return
141cb0ef41Sopenharmony_ci  }
151cb0ef41Sopenharmony_ci
161cb0ef41Sopenharmony_ci  // default behavior is to not save by default in order to avoid
171cb0ef41Sopenharmony_ci  // race condition problems when publishing multiple workspaces
181cb0ef41Sopenharmony_ci  // that have dependencies on one another, it might still be useful
191cb0ef41Sopenharmony_ci  // in some cases, which then need to set --save
201cb0ef41Sopenharmony_ci  const save = config.isDefault('save')
211cb0ef41Sopenharmony_ci    ? false
221cb0ef41Sopenharmony_ci    : config.get('save')
231cb0ef41Sopenharmony_ci
241cb0ef41Sopenharmony_ci  // runs a minimalistic reify update, targeting only the workspaces
251cb0ef41Sopenharmony_ci  // that had version updates and skipping fund/audit/save
261cb0ef41Sopenharmony_ci  const opts = {
271cb0ef41Sopenharmony_ci    ...flatOptions,
281cb0ef41Sopenharmony_ci    audit: false,
291cb0ef41Sopenharmony_ci    fund: false,
301cb0ef41Sopenharmony_ci    path: localPrefix,
311cb0ef41Sopenharmony_ci    save,
321cb0ef41Sopenharmony_ci  }
331cb0ef41Sopenharmony_ci  const Arborist = require('@npmcli/arborist')
341cb0ef41Sopenharmony_ci  const arb = new Arborist(opts)
351cb0ef41Sopenharmony_ci
361cb0ef41Sopenharmony_ci  await arb.reify({ ...opts, update: workspaces })
371cb0ef41Sopenharmony_ci  await reifyFinish(npm, arb)
381cb0ef41Sopenharmony_ci}
391cb0ef41Sopenharmony_ci
401cb0ef41Sopenharmony_cimodule.exports = updateWorkspaces
41