"use strict";var e=this&&this.__awaiter||function(e,t,o,i){return new(o||(o=Promise))((function(n,r){function c(e){try{u(i.next(e))}catch(e){r(e)}}function l(e){try{u(i.throw(e))}catch(e){r(e)}}function u(e){var t;e.done?n(e.value):(t=e.value,t instanceof o?t:new o((function(e){e(t)}))).then(c,l)}u((i=i.apply(e,t||[])).next())}))},t=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.resolveDepVersionConflict=void 0;const o=require("../locker"),i=t(require("../../log")),n=require("../dependency/tree-builder/AsyncTreeBuilder"),r=require("../dependency/util"),c=require("../install/service/updateCommandLineInputDependencies"),l=require("../install/service/handleCliInput"),u=require("../registry/registry");exports.resolveDepVersionConflict=function(t){return e(this,void 0,void 0,(function*(){const e=Date.now();i.default.debug("conflictResolve",`rebuilding tree to resolve conflict, roughListSize: ${t.roughDepList.length}, rootDir: "${t.moduleRootDir}".`);const s=o.PackageLockerManager.getInstance();t.roughDepList.forEach((e=>{if(e.isRoot)return;if(e.isNativeSoType)return;const o=s.getMaxVersionData(e.name),n=o.pinnedSpec,c=e.registryType===u.RegistryType.local?e.fetchSpec:e.saveSpec,l=s.getLockSpec(t.moduleRootDir,e.name,c);s.deletePackage(t.moduleRootDir,l),s.updateLockSpec(t.moduleRootDir,e.name,c,n),s.updateLockPkg(t.moduleRootDir,e.name,n,(0,r.getLockPkgFromNodeData)(o)),i.default.debug("resolveConflict",`rewrite lockfile specifier ${e.name}@${c}: ${l} -> ${s.getLockSpec(t.moduleRootDir,e.name,c)} in ${t.moduleRootDir}`)})),(0,c.updateCommandLineInputDependencies)(t,l.cliInputNames),s.clearVisitedSet(t.moduleRootDir);const a=new n.AsyncTreeBuilder({resolveConflict:!0});return yield a.build(t.moduleRootDir,t.root),t=a.getResult(),i.default.debug("conflictResolve",`resolve conflict success. finalListSize: ${t.finalDepList.length}, rootDir: "${t.moduleRootDir}"`),function(e,t){const o=(new Date).getTime()-e,n=Math.floor(o/1e3),r=o%1e3,c=t?`${t}`:"";i.default.debug("conflictResolve",`${c} completed in ${n}s ${r}ms`)}(e),t}))};