"use strict";var e=this&&this.__awaiter||function(e,n,t,o){return new(t||(t=Promise))((function(r,s){function i(e){try{c(o.next(e))}catch(e){s(e)}}function l(e){try{c(o.throw(e))}catch(e){s(e)}}function c(e){var n;e.done?r(e.value):(n=e.value,n instanceof t?n:new t((function(e){e(n)}))).then(i,l)}c((o=o.apply(e,n||[])).next())}))},n=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.installModules=void 0;const t=n(require("../../../log")),o=require("../../dependency/tree-builder/AsyncTreeBuilder"),r=require("../../dependency/visitor"),s=require("../../dependency/walker"),i=require("../../locker"),l=require("../../resolve-version/resolveDepVersionConflict"),c=require("../../../config"),a=require("../../dependency/util/deleteUselessHarStoreDir"),u=require("../../../common/GlobalState"),d=require("../../dependency/util"),f=require("../../../tools/ohpa/OhpaType"),y=require("../../../common/Constants"),g=require("../../../tools/posh"),p=require("../../alarm"),h=n(require("path")),m=require("../../install-targets/TargetManager");exports.installModules=function(n){return e(this,void 0,void 0,(function*(){const v=!!m.targetManager.isTargetMod()||c.config.get(c.types.RESOLVE_CONFLICT),w=c.config.get(c.types.ENFORCE_DEPENDENCY_KEY),M=(0,p.conflictVersionAlarm)(v),D=(0,p.dependencyNameInconsistencyAlarm)(w),k=yield function(n,r,s){return e(this,void 0,void 0,(function*(){const a=[];let u=[];const d=Date.now();t.default.debug("TreeBuilding","building dependency trees.");const f=!!m.targetManager.isTargetMod()||c.config.get(c.types.RESOLVE_CONFLICT);for(const[e,t]of n){const n=new o.AsyncTreeBuilder({resolveConflict:f});a.push(n.build(e,t).then((()=>{const e=n.getResult();u.push(e)})))}return yield Promise.all(a),u.forEach((e=>{r.recordConflictMessage(e),s.recordInconsistencyMessage(e)})),f&&(u=yield function(n){return e(this,void 0,void 0,(function*(){i.PackageLockerManager.getInstance().clearLockerCache();const e=[],t=[];for(const o of n)t.push((0,l.resolveDepVersionConflict)(o).then((n=>{e.push(n)})));return yield Promise.all(t),e}))}(u)),t.default.debug("TreeBuilding",`all dependency trees are built successfully, cost: ${Date.now()-d}ms.`),u}))}(n,M,D);return D.alarmInconsistencyMessage(),yield function(n){return e(this,void 0,void 0,(function*(){const e=Date.now();t.default.debug("TreeInstall","installing dependency trees.");const o=r.DepNodeInstaller.getInstance(),i=[];for(const e of n)i.push(o.run(new s.AsyncFlattenTreeWalker(e)));yield Promise.all(i),t.default.debug("TreeInstall",`all dependency trees are installed successfully, cost: ${Date.now()-e}ms.`),u.GlobalState.installMode.includes(u.ExperimentalOption.INSTALL_ALL)&&(yield(0,a.deleteUselessHarStoreDir)(c.config.getProjectRoot()))}))}(k),yield function(n){return e(this,void 0,void 0,(function*(){const o=Date.now();t.default.debug("TreeSymlink","Symlinking dependency trees");const l=new r.DepNodeSymlinker,a=[];for(const e of n)a.push(l.run(new s.AsyncFlattenTreeWalker(e)));yield Promise.all(a),yield function(){return e(this,void 0,void 0,(function*(){const e=i.PackageLockerManager.getInstance();yield(0,d.deleteUselessLinks)(h.default.join(c.config.getProjectRoot(),y.Constants.MyModules,y.Constants.PmDir,y.Constants.MyModules),(n=>!!e.getMaxVersionData(n)))}))}(),t.default.debug("TreeSymlink",`all dependency trees are symlinked successfully, cost ${Date.now()-o}ms`)}))}(k),M.alarmConflictMessage(),function(e){const n=e.filter((e=>e.moduleRootDir===c.config.getProjectRoot()))[0];if(!n)return;const o=n.root,r=[];for(const e of Object.keys(o.rawRequirements)){const t=o.rawRequirements[e];(0,d.parseDependency)(`${e}@${t.spec}`,n.moduleRootDir).type===f.OhpaType.SourceCode&&r.push(`${e}@${t.spec}`)}r.length>0&&t.default.log("warn",g.posh.bold.bgBlack.yellowBright(`Source code dependencies in project-level "${y.Constants.MyPackageJson}" are as follows, which could lead to circular dependencies reference.`)+g.posh.yellow(`\n\t - "${r.join('",\n\t - "')}"\n`))}(k),k}))};