@homer0/package-info
Version:
Gets the content of the project's package.json
2 lines • 1.05 kB
JavaScript
import*as o from"fs";import*as r from"fs/promises";import{pathUtils as p}from"@homer0/path-utils";import{deferred as f}from"@homer0/deferred";import{providerCreator as g,injectHelper as P}from"@homer0/jimple";var a=P(),n=class{defer;contents;filepath;constructor({inject:e={}}={}){let s=a.get(e,"pathUtils",()=>p());this.filepath=s.join("package.json")}async get(){if(this.contents)return this.contents;if(this.defer)return this.defer.promise;this.defer=f();let e=await r.readFile(this.filepath,"utf8");return this.updateContents(e)}getSync(){if(this.contents)return this.contents;let e=o.readFileSync(this.filepath,"utf8");return this.updateContents(e)}updateContents(e){return this.contents=JSON.parse(e),this.defer&&(this.defer.resolve(this.contents),this.defer=void 0),this.contents}},I=(...t)=>new n(...t),l=g(({serviceName:t="packageInfo",...e}={})=>s=>{s.set(t,()=>{let{services:i={}}=e,c=a.resolve(["pathUtils"],s,i);return new n({inject:c})})});export{n as PackageInfo,I as packageInfo,l as packageInfoProvider};
//# sourceMappingURL=index.js.map