@prisma/dev
Version:
A local Prisma Postgres server for development and testing
2 lines (1 loc) • 2.16 kB
JavaScript
import{createWriteStream as w,WriteStream as A}from"fs";import{access as D,chmod as x,constants as P,mkdir as E,readdir as T,readFile as _,rm as F,writeFile as O}from"fs/promises";import{promisify as v}from"util";import{unzip as L}from"zlib";import o from"path";import g from"os";import c from"process";var n=g.homedir(),a=g.tmpdir(),{env:e}=c,h=r=>{let t=o.join(n,"Library");return{data:o.join(t,"Application Support",r),config:o.join(t,"Preferences",r),cache:o.join(t,"Caches",r),log:o.join(t,"Logs",r),temp:o.join(a,r)}},y=r=>{let t=e.APPDATA||o.join(n,"AppData","Roaming"),i=e.LOCALAPPDATA||o.join(n,"AppData","Local");return{data:o.join(i,r,"Data"),config:o.join(t,r,"Config"),cache:o.join(i,r,"Cache"),log:o.join(i,r,"Log"),temp:o.join(a,r)}},j=r=>{let t=o.basename(n);return{data:o.join(e.XDG_DATA_HOME||o.join(n,".local","share"),r),config:o.join(e.XDG_CONFIG_HOME||o.join(n,".config"),r),cache:o.join(e.XDG_CACHE_HOME||o.join(n,".cache"),r),log:o.join(e.XDG_STATE_HOME||o.join(n,".local","state"),r),temp:o.join(a,t,r)}};function p(r,{suffix:t="nodejs"}={}){if(typeof r!="string")throw new TypeError(`Expected a string, got ${typeof r}`);return t&&(r+=`-${t}`),c.platform==="darwin"?h(r):c.platform==="win32"?y(r):j(r)}import C from"zeptomatch";var l=p("prisma-dev"),G=v(L);function z(r,t){return`${l.cache}/engine/${r}/${t}`}function I(r){return`${l.data}/${r}`}async function J(r){try{return await D(r,P.F_OK),!0}catch(t){if(u(t))return!1;throw t}}async function K(r,t){let i=await G(r);await O(t,i),await x(t,"755")}async function q(r,t){await r.stream().pipeTo(A.toWeb(w(t,{encoding:"utf-8"})))}function u(r){return r!=null&&typeof r=="object"&&"code"in r&&r.code==="ENOENT"}async function Q(r){try{return await _(r,{encoding:"utf-8"})}catch(t){if(u(t))return null;throw t}}async function U(r){await E(r,{recursive:!0})}async function V(r,t){try{return(await T(r,{withFileTypes:!0})).reduce((f,s)=>(s.isDirectory()&&!s.name.startsWith(".")&&(!t||C(t,s.name))&&f.push(s.name),f),[])}catch(i){if(u(i))return[];throw i}}async function Y(r){await F(r,{force:!0,recursive:!0})}export{z as a,I as b,J as c,K as d,q as e,Q as f,U as g,V as h,Y as i};