hud-sdk
Version:
Hud's Node SDK
2 lines • 2 kB
JavaScript
import{createRequire as t}from"node:module";const e=t(import.meta.url)("url"),o=t(import.meta.url)("../cjs/instrument"),r=t(import.meta.url)("../cjs/config"),n=t(import.meta.url)("../cjs/dto"),s=t(import.meta.url)("../cjs/lib"),i=t(import.meta.url)("../cjs/logger");let m,a,c=!1;const u=(0,s.isSupportedNative)(),g=async({port:t})=>{m=t,a=(0,s.shouldSupportSourceMap)(),setTimeout(()=>{try{i.instrument_logger.info("Getting tsconfig from esm loader"),(0,s.getUserTsNodeConfig)(!1)}catch(t){i.instrument_logger.error("Error getting tsconfig from esm loader",{msg:t instanceof Error?t.message:void 0,stack:t instanceof Error?t.stack:void 0})}},r.hudConfig.tsNodeConfigTimeout),(0,s.setInstrumentedFilesCountInterval)(!0)},l=async(t,r,g)=>{const l=process.hrtime.bigint(),d=await g(t,r);if(!u||!d.source)return d;const p=Number(process.hrtime.bigint()-l),f=process.hrtime.bigint();let h=0,b=0,y=0;try{if(d.format===n.Format.esm){const r=(0,e.fileURLToPath)(t);i.instrument_logger.debug("Loading module",{modulePath:r});const c=d.source?.toString();h=c?.length??0;const u=(0,o.patch)(c,r,n.Format.esm,m);if(d.source=u.code,b=u.map?.reduce((t,e)=>t+e.functionIds.length,0)??0,y=u.map?.reduce((t,e)=>t+e.totalFunctionsCountIncludeUninstrumented,0)??0,a&&u.map){const t=(0,s.combineSourceMaps)(u.map,r);t&&m.postMessage({key:"HudRetrieveFileCache",filename:r,content:t})}}else if(d.format===n.Format.moduleTypescript||d.format===n.Format.commonjsTypescript){c||(c=!0,i.instrument_logger.warning("Tried to load at least one unsupported typescript format"));const o=(0,e.fileURLToPath)(t);i.instrument_logger.debug("Loading unsupported format",{format:d.format,modulePath:o})}}catch(t){i.instrument_logger.error("Something went wrong in load hook",{msg:t instanceof Error?t.message:void 0,stack:t instanceof Error?t.stack:void 0})}finally{const t=Number(process.hrtime.bigint()-f);(0,s.incrementInstrumentedStats)(!0,t,p,h,b,y)}return d};export{g as initialize,l as load};
//# sourceMappingURL=loader.mjs.map