Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

esmock

Package Overview
Dependencies
Maintainers
1
Versions
107
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

esmock - npm Package Compare versions

Comparing version 2.0.8 to 2.0.9

2

package.json
{
"name": "esmock",
"type": "module",
"version": "2.0.8",
"version": "2.0.9",
"license": "ISC",

@@ -6,0 +6,0 @@ "readmeFilename": "README.md",

import Me from"process";var g=import.meta.url;var ye=(e,t)=>new Error(`invalid moduleId: "${e}" (used by ${t})`),be=(e,t)=>new Error(`un-mocked moduleId: "${e}" (used by ${t})`),Ie=()=>new Error("the loader chain process must include esmock. start the process using --loader=esmock."),d={errModuleIdNotFound:ye,errModuleIdNotMocked:be,errMissingLoader:Ie};var[P,we]=Me.versions.node.split(".").map(e=>+e),W=P<16||P===16&&we<12,xe=/\?esmkgdefs=.*/,Re=/.*\?esmkgdefs=/,L=/#-#esmkdefs/,K=/esmkTreeId=\d*/,$e=/esmkModuleId=([^&]*)/,z=/\?esmk=\d*/,U=/.*exportNames=(.*)/,Se=/.*#-#/,Ee=/isesm=true/,Oe=/isfound=false/,V=async(e,t,s)=>s.parentURL&&(s.conditions.slice(-1)[0]==="node-addons"||s.importAssertions||W)?await e(t,s):await e(t),It=async(e,t,s)=>{let{parentURL:o}=t,r=z.test(o)?global.esmockTreeIdGet(o.match(z)[0].split("=")[1]):o;if(!K.test(r))return V(s,e,t);let[c]=String(r).match(K),[n,a]=r.split(L),l=n&&n.replace(Re,"");if(r.includes(`esmkModuleId=${e}&isfound=false`)){let G=new RegExp(".*file:///"+e+"(\\?"+c+"(?:(?!#-#).)*).*"),D=(l.match(G)||a.match(G)||[])[1];if(D)return{shortCircuit:!0,url:g+D}}let u=await V(s,e,t),b=new RegExp(".*("+u.url+"\\?"+c+"(?:(?!#-#).)*).*"),k=b.test(a)&&a.replace(b,"$1")||b.test(l)&&l.replace(b,"$1");if(k?u.url=Ee.test(k)?k:g+"#-#"+k:l&&l!=="0"&&(u.url.startsWith("node:")||(u.url+="?esmkgdefs="+l)),/strict=3/.test(r)&&!k)throw d.errModuleIdNotMocked(u.url,r.split("?")[0]);return u},_="esmock-loader=true",ve=e=>`${e}?${_}`,B=async e=>(await import(ve(e))).default===!0,Ce=async(e,t,s)=>{if(e.endsWith(_))return{format:"module",shortCircuit:!0,responseURL:e,source:"export default true"};if(L.test(e))return s(e,t);e=e.replace(xe,""),e.startsWith(g)&&(e=e.replace(Se,""),Oe.test(e)&&(e=e.replace(g,`file:///${e.match($e)[1]}`)));let o=U.test(e)&&e.replace(U,"$1").split(",");return o.length?{format:"module",shortCircuit:!0,responseURL:encodeURI(e),source:o.map(r=>r==="default"?`export default global.esmockCacheGet("${e}").default`:`export const ${r} = global.esmockCacheGet("${e}").${r}`).join(`
`)}:s(e,t)},Mt=W&&Ce;var Z=(e=>async()=>e||(e=await B(import.meta.url)))();import Ye from"fs";import et from"node:url";import ee from"fs";import te from"url";import i from"path";import se from"module";var $=se.createRequire(import.meta.url),q=ee.realpathSync.native,oe=new RegExp("^(?:node:)?("+se.builtinModules.join("|").replace("/","/")+")$"),Te=/^\.?\.?([a-zA-Z]:)?(\/|\\)/,S=/^.\.?(?=\/|\\)/,H=/\\/g,Fe=/index.[tj]sx?$/,Ae=/[\\/]resolvewithplus[\\/]/,Ne=/(^@[^/]*\/[^/]*|^[^/]*)\/?(.*)$/,w=/^#/,re=/(\*)/g,ne=/([./])/g,Ge=/^node:/,De=/^file:/,ce=[".js",".mjs",".ts",".tsx",".json",".node"],Q="node_modules",M="package.json",J="node",X="default",E="import",I=".",ie=e=>e&&typeof e=="object",x={},Pe=e=>Ge.test(e)?e:`node:${e}`,Ke=e=>e&&te.pathToFileURL(e).href,ze=e=>oe.test(e),Ue=e=>De.test(e)?te.fileURLToPath(e):e,Ve=e=>i.resolve(i.extname(e)?i.dirname(e):e)+"/",R=e=>H.test(e)?e.replace(H,i.posix.sep):e,p=(e,t)=>{try{t=ee.statSync(e)}catch{t=!1}return t&&(t.isFile()||t.isFIFO())},ae=e=>e.split(i.sep).slice(1).reduce((t,s,o)=>(s===Q&&!Ae.test(e)||(s=i.resolve(i.join(o?t[0][o-1]:i.sep,s)),t[0].push(s),t[1].push(i.join(s,Q))),t),[[],[]])[1].reverse(),We=e=>{let t=e.split(i.sep).slice(1).reduce((s,o,r)=>(s.push(i.resolve(i.join(r?s[r-1]:i.sep,o))),s),[]).reverse().find(s=>p(i.join(s,M)));return t&&i.join(t,M)},Le=e=>(String(e).match(Ne)||[]).slice(1),Y=(e,t)=>new RegExp(e.replace(ne,"\\$1").replace(re,".*")).test(t),_e=(e,t,s)=>{let o=new RegExp(e.replace(ne,"\\$1").replace(re,"(.*)")),r=(s.match(o)||[])[1];return r&&t.replace("*",r)},le=(e,t,s,o=!1)=>(Y(e,s)&&(t.includes("*")?Y(t,s)?o=s:e.includes("*")&&e!==t&&(o=_e(e,t,s)):o=t),o),ue=(e,t,s,o=e[0])=>e.length?(w.test(s)?w.test(o):S.test(o))&&typeof t[o]=="string"&&le(o,t[o],s)||ue(e.slice(1),t,s):null,m=(e,t)=>{let s=!1;return typeof e=="string"?e:(!s&&Array.isArray(e)&&(s=e.reduce((o,r)=>o||m(r,t),null)),!s&&ie(e)&&(typeof e[t]=="string"&&(s=e[t]),!s&&e[J]&&(s=m(e[J],t)),!s&&e[X]&&(s=m(e[X],t)),!s&&e[t]&&(s=m(e[t],t)),!s&&e[I]&&(s=typeof e[I]=="string"?t===E&&m(e[I],t):m(e[I],t)),s||(s=ue(Object.keys(e),e,t))),s)},me=(e,t)=>{let s=t&&t.ismodule&&e.module,o=s||t&&t.browser&&e.browser,r=e.exports,c,n;return o&&(typeof o=="string"?n=o:ie(o)&&([c]=Object.keys(o).filter(a=>Fe.test(a)),n=c in o&&o[c])),r&&(n=m(r,E)),n},h=e=>{var t=null;return p(e)?t=e:ce.some(s=>p(e+s)&&(t=e+s)),t},de=(e,t)=>{let s=null,o,r=i.join(e,M),c=p(r)&&$(r);return(o=me(c,t))?s=h(i.join(e,o)):(o=c.main)?s=h(i.join(e,o))||h(i.join(e,i.join(o,"index"))):ce.some(n=>(n=i.join(e,`index${n}`))&&p(n)&&(s=n)),s},pe=(e,t,s)=>{let o=S.test(e)?i.join(t,e):e;return h(o,s)||de(o,s)},Be=(e,t,s)=>{let o=s&&s.imports,r=m(o,t);return r&&(S.test(r)?i.join(e,r):fe(r,e,{isposixpath:!0}))},Ze=(e,t,s,o)=>{let r=m(o&&o.exports,s?"./"+s:E);return r&&i.join(e,t,r)},qe=(e,t,s,o)=>{let r=i.join(e,t,M),c=p(r),n=c&&$(r);return c&&Ze(e,t,s,n,o)},He=(e,t,s)=>{let o=We(t),r=i.dirname(o);return o&&Be(r,e,$(o),s)},Qe=(e,t,s)=>{let[o,r]=Le(e);if(w.test(o))return He(e,t,s);let c=ae(t).sort((n,a)=>n.length>a.length);return function n(a,l,u=l-1){return l--?qe(i.join(a[u-l]),o,r,s)||pe(i.join(a[u-l],e),null,s)||n(c,l,u):null}(c,c.length)},Je=(e,t,s)=>{var o=null;return t=typeof t=="string"?Ve(Ue(decodeURI(t))):process.cwd(),oe.test(e)?o=Pe(e):(o=Te.test(e)?pe(R(e),t,s):Qe(e,t),o=o&&(s.isposixpath?q(o):Ke(R(q(o))))),o},fe=(e,t,s)=>{let o=x[e+t];return o||(o=Je(e,t,s||{}),x[e+t]=o)},j=Object.assign(fe,{pathToPosix:R,getasnode_module_paths:ae,getesmkeyvalmatch:le,getasfilesync:h,getasdirsync:de,gettargetindex:me,iscoremodule:ze,esmparse:m,cache:x});var O={isESM:{},mockDefs:{}},ke=(e,t)=>global.mockKeys[String(e)]=t,v=e=>global.mockKeys[String(e)],C=(e,t)=>global.esmockCache.mockDefs[e]=t,Xe=e=>global.esmockCache.mockDefs[e],ge=e=>O.isESM[e],he=(e,t)=>O.isESM[e]=t;Object.assign(global,{esmockCache:O,esmockCacheGet:Xe,esmockTreeIdGet:v,mockKeys:{}});var T=e=>typeof e=="object"&&e,F=e=>T(e)&&"default"in e,tt=/^\.?\.?([a-zA-Z]:)?(\/|\\)/,st=typeof import.meta.resolve=="function",ot=((e=0)=>()=>++e)(),rt=e=>e.startsWith("file://")?e:et.pathToFileURL(e),nt=(e,t)=>T(e)&&T(t)?Object.assign(Object.create(e),t):t,ct=(e,t,s)=>(t=Object.assign({},e||{},{default:nt(F(e)&&e.default,F(t)?t.default:t)},t),!j.iscoremodule(s)&&Object.isExtensible(t.default)&&(t.default.default=t.default),t),it=/(^\s*|[});\n]\s*)(import\s+(['"]|(\*\s+as\s+)?[^"'()\n;]+\s+from\s+['"]|\{)|export\s+\*\s+from\s+["']|export\s+(\{|default|function|class|var|const|let|async\s+function))/,at=(e,t)=>(t=ge(e),typeof t=="boolean"||(t=!j.iscoremodule(e)&&tt.test(e)&&it.test(Ye.readFileSync(e,"utf-8")),he(e,t)),t),lt=(e,t)=>{let s=F(e)&&e.default;return/boolean|string|number/.test(typeof s)?e:Object.isExtensible(s)?Object.assign(s,e,{esmkTreeId:t}):Object.assign({},s,e,{esmkTreeId:t})},ut=e=>{let t=c=>c==="null"||C(c,null),s=v(e.split("esmk=")[1]),[o,r]=s.split("#-#esmkdefs=");String(r).split("#-#").forEach(t),String(o.split("esmkgdefs=")[1]).split("#-#").forEach(t)},mt=async(e,t,s,o,r)=>{t=ct(r.strict||!o||await import(o),t,o);let c=(o||"file:///"+s)+"?"+["esmkTreeId="+e,"esmkModuleId="+s,"isfound="+Boolean(o),"isesm="+at(o),"exportNames="+Object.keys(t).sort().join()].join("&");return C(c,t),c},A=async(e,t,s,o,r,c,n)=>{if(o=o||Object.keys(s),n=o[0],c=c||[],!n)return c;let a=st?await import.meta.resolve(n,rt(e)).catch(()=>null):j(n,e);if(!a&&r.isModuleNotFoundError!==!1)throw d.errModuleIdNotFound(n,e);return c.push(await mt(t,s[n],n,a,r)),A(e,t,s,o.slice(1),r,c)},dt=async(e,t,s,o,r)=>{let c=j(e,t);if(!c)throw d.errModuleIdNotFound(e,t);let n=typeof r.id=="number"?r.id:ot(),a=`${c}?key=${n}&strict=${r.strict}?`+["esmkgdefs="+(o&&(await A(t,n,o,Object.keys(o),r)).join("#-#")||0),"esmkdefs=",s&&(await A(t,n,s,Object.keys(s),r)).join("#-#")||0].join("#-#");return ke(String(n),a),c+`?esmk=${n}`},y=Object.assign(dt,{purge:ut,sanitize:lt});var pt=/^.*(\(|at )(.*):[\d]*:[\d]*.*$/,je=(e,t)=>(e=typeof e[1]=="string"?e:[e[0],new Error().stack.split(`
`)}:s(e,t)},Mt=W&&Ce;var Z=(e=>async()=>e||(e=await B(import.meta.url)))();import Ye from"fs";import et from"node:url";import ee from"fs";import te from"url";import i from"path";import se from"module";var $=se.createRequire(import.meta.url),q=ee.realpathSync.native,oe=new RegExp("^(?:node:)?("+se.builtinModules.join("|").replace("/","/")+")$"),Te=/^\.?\.?([a-zA-Z]:)?(\/|\\)/,S=/^.\.?(?=\/|\\)/,H=/\\/g,Fe=/index.[tj]sx?$/,Ae=/[\\/]resolvewithplus[\\/]/,Ne=/(^@[^/]*\/[^/]*|^[^/]*)\/?(.*)$/,w=/^#/,re=/(\*)/g,ne=/([./])/g,Ge=/^node:/,De=/^file:/,ce=[".js",".mjs",".ts",".tsx",".json",".node"],Q="node_modules",M="package.json",J="node",X="default",E="import",I=".",ie=e=>e&&typeof e=="object",x={},Pe=e=>Ge.test(e)?e:`node:${e}`,Ke=e=>e&&te.pathToFileURL(e).href,ze=e=>oe.test(e),Ue=e=>De.test(e)?te.fileURLToPath(e):e,Ve=e=>i.resolve(i.extname(e)?i.dirname(e):e)+i.sep,R=e=>H.test(e)?e.replace(H,i.posix.sep):e,p=(e,t)=>{try{t=ee.statSync(e)}catch{t=!1}return t&&(t.isFile()||t.isFIFO())},ae=e=>e.split(i.sep).reduce((t,s,o)=>(s===Q&&!Ae.test(e)||(s=o?i.join(t[0][o-1],s):s||i.sep,t[0].push(s),t[1].push(i.resolve(i.join(s,Q)))),t),[[],[]])[1].reverse(),We=e=>{let t=e.split(i.sep).slice(1).reduce((s,o,r)=>(s.push(i.resolve(i.join(r?s[r-1]:i.sep,o))),s),[]).reverse().find(s=>p(i.join(s,M)));return t&&i.join(t,M)},Le=e=>(String(e).match(Ne)||[]).slice(1),Y=(e,t)=>new RegExp(e.replace(ne,"\\$1").replace(re,".*")).test(t),_e=(e,t,s)=>{let o=new RegExp(e.replace(ne,"\\$1").replace(re,"(.*)")),r=(s.match(o)||[])[1];return r&&t.replace("*",r)},le=(e,t,s,o=!1)=>(Y(e,s)&&(t.includes("*")?Y(t,s)?o=s:e.includes("*")&&e!==t&&(o=_e(e,t,s)):o=t),o),ue=(e,t,s,o=e[0])=>e.length?(w.test(s)?w.test(o):S.test(o))&&typeof t[o]=="string"&&le(o,t[o],s)||ue(e.slice(1),t,s):null,m=(e,t)=>{let s=!1;return typeof e=="string"?e:(!s&&Array.isArray(e)&&(s=e.reduce((o,r)=>o||m(r,t),null)),!s&&ie(e)&&(typeof e[t]=="string"&&(s=e[t]),!s&&e[J]&&(s=m(e[J],t)),!s&&e[X]&&(s=m(e[X],t)),!s&&e[t]&&(s=m(e[t],t)),!s&&e[I]&&(s=typeof e[I]=="string"?t===E&&m(e[I],t):m(e[I],t)),s||(s=ue(Object.keys(e),e,t))),s)},me=(e,t)=>{let s=t&&t.ismodule&&e.module,o=s||t&&t.browser&&e.browser,r=e.exports,c,n;return o&&(typeof o=="string"?n=o:ie(o)&&([c]=Object.keys(o).filter(a=>Fe.test(a)),n=c in o&&o[c])),r&&(n=m(r,E)),n},h=e=>{var t=null;return p(e)?t=e:ce.some(s=>p(e+s)&&(t=e+s)),t},de=(e,t)=>{let s=null,o,r=i.join(e,M),c=p(r)&&$(r);return(o=me(c,t))?s=h(i.join(e,o)):(o=c.main)?s=h(i.join(e,o))||h(i.join(e,i.join(o,"index"))):ce.some(n=>(n=i.join(e,`index${n}`))&&p(n)&&(s=n)),s},pe=(e,t,s)=>{let o=S.test(e)?i.join(t,e):e;return h(o,s)||de(o,s)},Be=(e,t,s)=>{let o=s&&s.imports,r=m(o,t);return r&&(S.test(r)?i.join(e,r):fe(r,e,{isposixpath:!0}))},Ze=(e,t,s,o)=>{let r=m(o&&o.exports,s?"./"+s:E);return r&&i.join(e,t,r)},qe=(e,t,s,o)=>{let r=i.join(e,t,M),c=p(r),n=c&&$(r);return c&&Ze(e,t,s,n,o)},He=(e,t,s)=>{let o=We(t),r=i.dirname(o);return o&&Be(r,e,$(o),s)},Qe=(e,t,s)=>{let[o,r]=Le(e);if(w.test(o))return He(e,t,s);let c=ae(t).sort((n,a)=>n.length>a.length);return function n(a,l,u=l-1){return l--?qe(i.join(a[u-l]),o,r,s)||pe(i.join(a[u-l],e),null,s)||n(c,l,u):null}(c,c.length)},Je=(e,t,s)=>{var o=null;return t=typeof t=="string"?Ve(Ue(decodeURI(t))):process.cwd(),oe.test(e)?o=Pe(e):(o=Te.test(e)?pe(R(e),t,s):Qe(e,t),o=o&&(s.isposixpath?q(o):Ke(R(q(o))))),o},fe=(e,t,s)=>{let o=x[e+t];return o||(o=Je(e,t,s||{}),x[e+t]=o)},j=Object.assign(fe,{pathToPosix:R,getasnode_module_paths:ae,getesmkeyvalmatch:le,getasfilesync:h,getasdirsync:de,gettargetindex:me,iscoremodule:ze,esmparse:m,cache:x});var O={isESM:{},mockDefs:{}},ke=(e,t)=>global.mockKeys[String(e)]=t,v=e=>global.mockKeys[String(e)],C=(e,t)=>global.esmockCache.mockDefs[e]=t,Xe=e=>global.esmockCache.mockDefs[e],ge=e=>O.isESM[e],he=(e,t)=>O.isESM[e]=t;Object.assign(global,{esmockCache:O,esmockCacheGet:Xe,esmockTreeIdGet:v,mockKeys:{}});var T=e=>typeof e=="object"&&e,F=e=>T(e)&&"default"in e,tt=/^\.?\.?([a-zA-Z]:)?(\/|\\)/,st=typeof import.meta.resolve=="function",ot=((e=0)=>()=>++e)(),rt=e=>e.startsWith("file://")?e:et.pathToFileURL(e),nt=(e,t)=>T(e)&&T(t)?Object.assign(Object.create(e),t):t,ct=(e,t,s)=>(t=Object.assign({},e||{},{default:nt(F(e)&&e.default,F(t)?t.default:t)},t),!j.iscoremodule(s)&&Object.isExtensible(t.default)&&(t.default.default=t.default),t),it=/(^\s*|[});\n]\s*)(import\s+(['"]|(\*\s+as\s+)?[^"'()\n;]+\s+from\s+['"]|\{)|export\s+\*\s+from\s+["']|export\s+(\{|default|function|class|var|const|let|async\s+function))/,at=(e,t)=>(t=ge(e),typeof t=="boolean"||(t=!j.iscoremodule(e)&&tt.test(e)&&it.test(Ye.readFileSync(e,"utf-8")),he(e,t)),t),lt=(e,t)=>{let s=F(e)&&e.default;return/boolean|string|number/.test(typeof s)?e:Object.isExtensible(s)?Object.assign(s,e,{esmkTreeId:t}):Object.assign({},s,e,{esmkTreeId:t})},ut=e=>{let t=c=>c==="null"||C(c,null),s=v(e.split("esmk=")[1]),[o,r]=s.split("#-#esmkdefs=");String(r).split("#-#").forEach(t),String(o.split("esmkgdefs=")[1]).split("#-#").forEach(t)},mt=async(e,t,s,o,r)=>{t=ct(r.strict||!o||await import(o),t,o);let c=(o||"file:///"+s)+"?"+["esmkTreeId="+e,"esmkModuleId="+s,"isfound="+Boolean(o),"isesm="+at(o),"exportNames="+Object.keys(t).sort().join()].join("&");return C(c,t),c},A=async(e,t,s,o,r,c,n)=>{if(o=o||Object.keys(s),n=o[0],c=c||[],!n)return c;let a=st?await import.meta.resolve(n,rt(e)).catch(()=>null):j(n,e);if(!a&&r.isModuleNotFoundError!==!1)throw d.errModuleIdNotFound(n,e);return c.push(await mt(t,s[n],n,a,r)),A(e,t,s,o.slice(1),r,c)},dt=async(e,t,s,o,r)=>{let c=j(e,t);if(!c)throw d.errModuleIdNotFound(e,t);let n=typeof r.id=="number"?r.id:ot(),a=`${c}?key=${n}&strict=${r.strict}?`+["esmkgdefs="+(o&&(await A(t,n,o,Object.keys(o),r)).join("#-#")||0),"esmkdefs=",s&&(await A(t,n,s,Object.keys(s),r)).join("#-#")||0].join("#-#");return ke(String(n),a),c+`?esmk=${n}`},y=Object.assign(dt,{purge:ut,sanitize:lt});var pt=/^.*(\(|at )(.*):[\d]*:[\d]*.*$/,je=(e,t)=>(e=typeof e[1]=="string"?e:[e[0],new Error().stack.split(`
`)[3].replace(pt,"$2"),...e.slice(1)],e[4]={...e[4],...t},e);var f=e=>async(...t)=>{let[s,o,r,c,n]=je(t,e);if(!await Z())throw d.errMissingLoader();let a=await y(s,o,r,c,n),l=await import(a);return n.purge!==!1&&y.purge(a),y.sanitize(l,a)},N=e=>e&&/object|function/.test(typeof e)&&"esmkTreeId"in e&&y.purge(e.esmkTreeId),ft=Object.assign(f({strict:1}),{purge:N,p:f({strict:1,purge:!1})}),kt=Object.assign(f({strict:3}),{purge:N,p:f({strict:3,purge:!1})}),Wt=Object.assign(f(),{purge:N,p:f({purge:!1}),strict:ft,strictest:kt});export{Wt as default,Mt as getSource,Ce as load,B as loaderIsVerified,It as resolve,ft as strict,kt as strictest};
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc