UNPKG

sdin

Version:

JavaScript package builder.

2 lines 2.06 kB
Object.defineProperty(exports,"__esModule",{value:!0}),exports.deepRead=r,exports.readExports=t,exports.readExportsSync=a;var u=require("fs-extra"),l=require("path"),e=require("./cache"),i=require("./errors"),n=require("../tools/typescript");async function R(e){var{name:e,source:r,offset:t,current:a,includeDir:i,handler:n,filter:o}=e,s=await(0,u.stat)(a);if(o&&!await o({name:e,offset:t,source:r,current:a,stats:s}))return;var c=s.isFile(),E=s.isDirectory();if((c||i&&E)&&await n({name:e,offset:t,source:r,current:a,stats:s}),E){var f=await(0,u.readdir)(a);for(let e=0;e<f.length;e++){var d=f[e];await R({filter:o,handler:n,source:r,name:d,offset:(0,l.join)(t,d),current:(0,l.resolve)(a,d)})}}}async function r(e){var{source:e,handler:r,filter:t}=e;if(await(0,u.pathExists)(e))return R({source:e,filter:t,handler:r,offset:"",current:e,name:(0,l.basename)(e)});throw new i.ReadingError(i.ReadingError.DEEP_READED_FILE_IS_NOT_EXIST,"Read file ".concat(e," is not exist."))}let o=(0,e.createCacher)();async function t(r,t,a){if(o.has(r))return o.get(r);a=await(0,n.compileTypeScriptFile)(r,t,a);if(a&&await(0,u.pathExists)(a))try{let e=void 0;return/\.json$/.test(a)?e=await(0,u.readJson)(a):/\.(js|mjs)$/.test(a)&&(e=require(a)),o.set(r,e),e}catch(e){if(t)throw new i.ReadingError(i.ReadingError.READED_EXPORTS_FILE_FAILED,"Read file ".concat(r," failed.\n").concat((0,i.getErrorMessage)(e)))}else if(t)throw new i.ReadingError(i.ReadingError.READED_EXPORTS_FILE_IS_NOT_EXIST,a?"File ".concat(a," not exist."):"Cannot read empty path.")}function a(r,t){if(o.has(r))return o.get(r);if(r&&(0,u.pathExistsSync)(r))try{let e=void 0;return/\.json$/.test(r)?e=(0,u.readJsonSync)(r):/\.(js|mjs)$/.test(r)&&(e=require(r)),o.set(r,e),e}catch(e){if(t)throw new i.ReadingError(i.ReadingError.READED_EXPORTS_FILE_FAILED,"Read file ".concat(r," failed.\n").concat((0,i.getErrorMessage)(e)))}else if(t)throw new i.ReadingError(i.ReadingError.READED_EXPORTS_FILE_IS_NOT_EXIST,r?"File ".concat(r," not exist."):"Cannot read empty path.")} //# sourceMappingURL=read.js.map