"use strict";var e=this&&this.__awaiter||function(e,t,r,i){return new(r||(r=Promise))((function(o,n){function a(e){try{s(i.next(e))}catch(e){n(e)}}function c(e){try{s(i.throw(e))}catch(e){n(e)}}function s(e){var t;e.done?o(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(a,c)}s((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.SourceCodeMetadataFetcherImpl=void 0;const r=require("../../../../util/FsUtil"),i=t(require("path")),o=require("../../util"),n=require("../../../../util"),a=require("../../../registry/registry"),c=require("../../../../common/message");exports.SourceCodeMetadataFetcherImpl=class{fetch(t){return e(this,void 0,void 0,(function*(){const e=yield this.readLockPkgFromSourceDir(t);return this.buildMetadataFetchResult(t,e,!0)}))}readLockPkgFromSourceDir(t){return e(this,void 0,void 0,(function*(){const e=i.default.resolve(t.where,t.fetchSpec);if(!(yield r.FsUtil.exists(e)))throw new Error((0,c.format)(c.Messages.Fetcher.SourceCode.FetchSourceCodeFailed,{path:e}));const s=yield(0,o.readPackageJsonFromLocalDir)(e);return n.PackageUtil.requireNotEmpty(s.name,`The name of package ${e}`),{name:s.name,version:s.version,resolved:t.fetchSpec,dependencies:s.dependencies,dynamicDependencies:s.dynamicDependencies,registryType:a.RegistryType.local,packageType:s.packageType}}))}buildMetadataFetchResult(e,t,r){const i={},o=t.packageType;let n;return n=t.registryType===a.RegistryType.local?t.resolved:t.version,i[n]=t,{name:t.name,versions:i,packageType:o,registryType:t.registryType,isFromLockFile:r}}};