11cb0ef41Sopenharmony_ciconst reifyOutput = require('./reify-output.js')
21cb0ef41Sopenharmony_ciconst ini = require('ini')
31cb0ef41Sopenharmony_ciconst { writeFile } = require('fs').promises
41cb0ef41Sopenharmony_ciconst { resolve } = require('path')
51cb0ef41Sopenharmony_ci
61cb0ef41Sopenharmony_ciconst reifyFinish = async (npm, arb) => {
71cb0ef41Sopenharmony_ci  await saveBuiltinConfig(npm, arb)
81cb0ef41Sopenharmony_ci  reifyOutput(npm, arb)
91cb0ef41Sopenharmony_ci}
101cb0ef41Sopenharmony_ci
111cb0ef41Sopenharmony_ciconst saveBuiltinConfig = async (npm, arb) => {
121cb0ef41Sopenharmony_ci  const { options: { global }, actualTree } = arb
131cb0ef41Sopenharmony_ci  if (!global) {
141cb0ef41Sopenharmony_ci    return
151cb0ef41Sopenharmony_ci  }
161cb0ef41Sopenharmony_ci
171cb0ef41Sopenharmony_ci  // if we are using a builtin config, and just installed npm as
181cb0ef41Sopenharmony_ci  // a top-level global package, we have to preserve that config.
191cb0ef41Sopenharmony_ci  const npmNode = actualTree.inventory.get('node_modules/npm')
201cb0ef41Sopenharmony_ci  if (!npmNode) {
211cb0ef41Sopenharmony_ci    return
221cb0ef41Sopenharmony_ci  }
231cb0ef41Sopenharmony_ci
241cb0ef41Sopenharmony_ci  const builtinConf = npm.config.data.get('builtin')
251cb0ef41Sopenharmony_ci  if (builtinConf.loadError) {
261cb0ef41Sopenharmony_ci    return
271cb0ef41Sopenharmony_ci  }
281cb0ef41Sopenharmony_ci
291cb0ef41Sopenharmony_ci  const content = ini.stringify(builtinConf.raw).trim() + '\n'
301cb0ef41Sopenharmony_ci  await writeFile(resolve(npmNode.path, 'npmrc'), content)
311cb0ef41Sopenharmony_ci}
321cb0ef41Sopenharmony_ci
331cb0ef41Sopenharmony_cimodule.exports = reifyFinish
34