sdin
Version:
JavaScript package builder.
2 lines • 2.81 kB
JavaScript
import{posix as e,resolve as a}from"path";import{pathExists as i,pathExistsSync as s,stat as n}from"fs-extra";import{createLazyer as t}from"./cache";import{getDependenceName as c,getPackageRootPath as r}from"./npm";import{PathError as f}from"./errors";import{trim as o}from"lodash";let l=/[\/\\]+/,u=/^([a-zA-Z0-9]+)\:$/,h=[".tsx",".ts",".jsx",".js"],m=[".tsx",".ts",".jsx",".js",".json"],g=t(()=>r(__dirname));function p(){return g.get()}function _(t){var r=g.get();return t.startsWith(r)?t:a(r,t)}function w(r){var n=c(r),e=F(g.get());let o=g.get();for(let t=0;t<e.length;t++){if(s(a(o,"node_modules",n)))return a(o,"node_modules",r);o=a(o,"../")}throw new f(f.NOT_HAS_MODULE_PATH,"Cannot find module ".concat(n,"."))}let y=t(()=>process.cwd());function v(){return y.get()}function d(t){var r=y.get();return t.startsWith(r)?t:a(r,t)}async function x(t){try{var r=await n(t);return r.isDirectory()&&0<r.size}catch(t){return!1}}async function I(r){try{if(!(await n(r)).isDirectory())throw new f(f.DIR_IS_NOT_EXIST,"Folder ".concat(r," is not directory."))}catch(t){throw new f(f.DIR_IS_NOT_EXIST,"Folder ".concat(r," is not exist."))}}async function j(r){try{if(!(await n(r)).isFile())throw new f(f.FILE_IS_NOT_EXIST,"File ".concat(r," is not file."))}catch(t){throw new f(f.FILE_IS_NOT_EXIST,"File ".concat(r," is not exist."))}}function E(r,n,e){for(let t=0;t<e.length;t++){var o=a(r,n+e[t]);if(s(o))return o}return""}async function S(r,n,e){for(let t=0;t<e.length;t++){var o=a(r,n+e[t]);if(await i(o))return o}return""}function T(t,r,n){let e=o(t,"/ ");return e?(r&&(e="/"+e),n&&(e+="/")):(r||n)&&(e="/"),e}function F(t){var r,t=t.trim().split(l);return 0<t.length&&((r=t[0])?(r=r.match(u))&&r[1]&&(t[0]="/"+r[1].toUpperCase()):(t.shift(),t[0]="/"+t[0])),t}function A(t){return F(t).join("/")}function D(){for(var t=arguments.length,r=new Array(t),n=0;n<t;n++)r[n]=arguments[n];return e.resolve(...r.map(A))}function N(){for(var t=arguments.length,r=new Array(t),n=0;n<t;n++)r[n]=arguments[n];return e.join(...r.map(A))}function O(t,n){var e=F(t);for(let t=0,r="";t<e.length;t++){var o=n[r=r?r+"/"+e[t]:e[t]];if(o)return A([o,...e.slice(t+1)].join("/"))}}function L(t,r){let n=F(t),e=F(r);var o=Math.max(n.length,e.length);for(let t=0;t<o;t++)if(n[t]!==e[t]){n=n.slice(t),e=e.slice(t);break}let a="";return(a=1<n.length?new Array(n.length-1).fill("../").join(""):"./")+e.join("/")}export{h as TJSX_FILE_EXTENSIONS,m as TJSXS_FILE_EXTENSIONS,p as getRootPath,_ as withRootPath,w as withModulePath,v as getWorkPath,d as withWorkPath,x as isNonEmptyDir,I as dirExistOrThrow,j as fileExistOrThrow,E as resolveExtensionSync,S as resolveExtension,T as resolvePosixSlash,F as getPosixPathSegments,A as getPosixPath,D as resolvePosix,N as joinPosix,O as aliasPosix,L as relativePosix};
//# sourceMappingURL=path.js.map