"use strict";var e=this&&this.__awaiter||function(e,t,n,i){return new(n||(n=Promise))((function(o,r){function a(e){try{l(i.next(e))}catch(e){r(e)}}function s(e){try{l(i.throw(e))}catch(e){r(e)}}function l(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(a,s)}l((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.installDependency=exports.InstallationPromiseCache=void 0;const n=require("../../../tools/ohpa/OhpaType"),i=require("./installSourceCodeArtifactDep"),o=require("./installLocalArtifactDep"),r=require("./installRegistryArtifactDep"),a=t(require("../../../log")),s=require("../../../common/Constants"),l=new Map([[n.OhpaType.SourceCode,i.installSourceCodeArtifactDep],[n.OhpaType.File,o.installLocalArtifact],[n.OhpaType.Tag,r.installRegistryArtifactDep],[n.OhpaType.Range,r.installRegistryArtifactDep],[n.OhpaType.Version,r.installRegistryArtifactDep]]);function p(t,n){return e(this,void 0,void 0,(function*(){try{yield n}catch(e){throw exports.InstallationPromiseCache.delete(t),e}}))}exports.InstallationPromiseCache=new Map,exports.installDependency=function(t,n){return e(this,void 0,void 0,(function*(){if(n.hspType!==s.HspType.BUNDLE_APP&&n.isShared){const e=exports.InstallationPromiseCache.get(n.resolvePkgStoreDir(t));if(e)return a.default.debug("installDependency",`found installation promise of depNode: ${n.nodeKey}`),void(yield p(n.resolvePkgStoreDir(t),e))}const e=l.get(n.ohpaType);e||(a.default.error("EDEPTYPE",`Unknown dependency type: ${n.ohpaType} of pkg: ${n.name}@${n.pinnedSpec}`),process.exit(1)),a.default.debug("installDependency",`start to install depNode: ${n.nodeKey}`);const i=e(t,n);exports.InstallationPromiseCache.set(n.resolvePkgStoreDir(t),i),yield p(n.resolvePkgStoreDir(t),i)}))};