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