resolvewithplus
Advanced tools
Comparing version 2.0.4 to 2.0.6
{ | ||
"name": "resolvewithplus", | ||
"version": "2.0.4", | ||
"version": "2.0.6", | ||
"description": "resolvewith with extra power", | ||
@@ -5,0 +5,0 @@ "readmeFilename": "README.md", |
resolvewithplus | ||
=============== | ||
![npm](https://img.shields.io/npm/v/resolvewithplus) ![Build Status](https://github.com/iambumblehead/resolvewithplus/workflows/nodejs-ci/badge.svg) [![install size](https://packagephobia.now.sh/badge?p=resolvewithplus)](https://packagephobia.now.sh/result?p=resolvewithplus) | ||
![npm](https://img.shields.io/npm/v/resolvewithplus) ![Build Status](https://github.com/iambumblehead/resolvewithplus/workflows/test/badge.svg) [![install size](https://packagephobia.now.sh/badge?p=resolvewithplus)](https://packagephobia.now.sh/result?p=resolvewithplus) | ||
```javascript | ||
resolvewithplus('koa', '/root/resolvewith/test/') | ||
// 'file:///root/resolvewith/node_modules/koa/dist/koa.mjs' | ||
resolvewithplus('koa', '/resolvewith/test/') | ||
// 'file:///resolvewith/node_modules/koa/dist/koa.mjs' | ||
resolvewithplus('react-dom/server', '/resolvewith/test/', { | ||
isbrowser: true | ||
}) | ||
// 'file:///resolvewith/node_modules/react-dom/server.browser.js' | ||
resolvewithplus('react-dom/server', '/resolvewith/test/', { | ||
priority: ['deno', 'browser', 'default'] | ||
}) | ||
// 'file:///resolvewith/node_modules/react-dom/server.deno.js' | ||
``` | ||
`resolvewithplus` resolves module paths à la [node.js' import.meta.resolve function][33] and the [import-meta-resolve npm package.][35] It exists mostly to be small and to resolve module paths for `esmock`. [It's size is ~6kB][36] compared to [import-meta-resolve's ~63kB size.][37] For more details, [see the wiki.](https://github.com/iambumblehead/resolvewithplus/wiki) | ||
![scrounge](https://github.com/iambumblehead/scroungejs/raw/master/img/hand.png) | ||
`resolvewithplus` resolves module paths à la [node.js' import.meta.resolve function][33] and the [import-meta-resolve npm package.][35] It exists mostly to be small and to resolve module paths for `esmock`. [It's size is ~6kB][36] compared to [import-meta-resolve's ~76kB size.][37] For more details, [see the wiki.](https://github.com/iambumblehead/resolvewithplus/wiki) | ||
![scrounge](https://github.com/iambumblehead/scroungejs/raw/main/img/hand.png) | ||
[33]: https://nodejs.org/api/esm.html#importmetaresolvespecifier-parent | ||
@@ -15,0 +27,0 @@ [35]: https://www.npmjs.com/package/import-meta-resolve |
@@ -1,1 +0,1 @@ | ||
import w from"fs";import $ from"url";import r from"path";import S from"module";const g=S.createRequire(import.meta.url),T=w.realpathSync.native,_=new RegExp("^(?:node:)?("+S.builtinModules.join("|").replace("/","/")+")$"),C=/^\.?\.?([a-zA-Z]:)?(\/|\\)/,p=/^.\.?(?=\/|\\)/,E=/\\/g,D=/index.[tj]sx?$/,G=/[\\/]resolvewithplus[\\/]/,P=/\.js$/,J=/\.ts$/,Z=/(^@[^/]*\/[^/]*|^[^/]*)\/?(.*)$/,R=/^#/,F=/(\*)/g,v=/([./])/g,H=/^node:/,Q=/^file:/,O=[".js",".mjs",".ts",".tsx",".json",".node"],U="node_modules",h="package.json",A="node",L="default",x="import",d=".",k=t=>t&&typeof t=="object",b={},X=t=>H.test(t)?t:`node:${t}`,Y=t=>t&&$.pathToFileURL(t).href,I=t=>_.test(t),tt=t=>Q.test(t)?$.fileURLToPath(t):t,et=t=>r.resolve(r.extname(t)?r.dirname(t):t)+r.sep,y=t=>E.test(t)?t.replace(E,r.posix.sep):t,a=(t,s)=>{try{s=w.statSync(t)}catch{s=!1}return s&&(s.isFile()||s.isFIFO())},q=t=>t.split(r.sep).reduce((s,e,n)=>(e===U&&!G.test(t)||(e=n?r.join(s[0][n-1],e):e||r.sep,s[0].push(e),s[1].push(r.resolve(r.join(e,U)))),s),[[],[]])[1].reverse(),st=t=>{const s=t.split(r.sep).slice(1).reduce((e,n,o)=>(e.push(r.resolve(r.join(o?e[o-1]:r.sep,n))),e),[]).reverse().find(e=>a(r.join(e,h)));return s&&r.join(s,h)},nt=t=>(String(t).match(Z)||[]).slice(1),K=(t,s)=>new RegExp(t.replace(v,"\\$1").replace(F,".*")).test(s),ot=(t,s,e)=>{const n=new RegExp(t.replace(v,"\\$1").replace(F,"(.*)")),o=(e.match(n)||[])[1];return o&&s.replace("*",o)},M=(t,s,e,n=!1)=>(K(t,e)&&(s.includes("*")?K(s,e)?n=e:t.includes("*")&&t!==s&&(n=ot(t,s,e)):n=s),n),N=(t,s,e,n=t[0])=>t.length?(R.test(e)?R.test(n):p.test(n))&&typeof s[n]=="string"&&M(n,s[n],e)||N(t.slice(1),s,e):null,l=(t,s)=>{let e=!1;return typeof t=="string"?t:(!e&&Array.isArray(t)&&(e=t.reduce((n,o)=>n||l(o,s),null)),!e&&k(t)&&(typeof t[s]=="string"&&(e=t[s]),!e&&t[A]&&(e=l(t[A],s)),!e&&t[L]&&(e=l(t[L],s)),!e&&t[s]&&(e=l(t[s],s)),!e&&t[d]&&(e=typeof t[d]=="string"?s===x&&l(t[d],s):l(t[d],s)),e||(e=N(Object.keys(t),t,s))),e)},V=(t,s)=>{let e=s&&s.ismodule&&t.module,n=e||s&&s.browser&&t.browser,o=t.exports,c,i;return n&&(typeof n=="string"?i=n:k(n)&&([c]=Object.keys(n).filter(u=>D.test(u)),i=c in n&&n[c])),o&&(i=l(o,x)),i},f=(t,s={})=>{var e=null,n=s.isTypescript&&P.test(t)&&t.replace(P,".ts");return a(n)?e=n:a(t)?e=t:O.some(o=>a(t+o)&&(e=t+o)),e},W=(t,s)=>{let e=null,n,o=r.join(t,h),c=a(o)&&g(o);return(n=V(c,s))?e=f(r.join(t,n)):(n=c.main)?e=f(r.join(t,n),s)||f(r.join(t,r.join(n,"index"))):O.some(i=>(i=r.join(t,`index${i}`))&&a(i)&&(e=i)),e},z=(t,s,e)=>{const n=p.test(t)?r.join(s,t):t;return f(n,e)||W(n,e)},rt=(t,s,e)=>{const n=e&&e.imports,o=l(n,s);return o&&(p.test(o)?r.join(t,o):B(o,t,{isposixpath:!0}))},it=(t,s,e,n)=>{const o=l(n&&n.exports,e?"./"+e:x);return o&&r.join(t,s,o)},ct=(t,s,e,n)=>{const o=r.join(t,s,h),c=a(o),i=c&&g(o);return c&&it(t,s,e,i,n)},lt=(t,s,e)=>{const n=st(s),o=r.dirname(n);return n&&rt(o,t,g(n),e)},at=(t,s,e)=>{const[n,o]=nt(t);if(R.test(n))return lt(t,s,e);const c=q(s).sort((i,u)=>i.length>u.length);return function i(u,m,j=m-1){return m--?ct(r.join(u[j-m]),n,o,e)||z(r.join(u[j-m],t),null,e)||i(c,m,j):null}(c,c.length)},ut=(t,s,e)=>{var n=null;return s=typeof s=="string"?et(tt(decodeURI(s))):process.cwd(),_.test(t)?n=X(t):(n=C.test(t)?z(y(t),s,e):at(t,s,e),n=n&&(e.isposixpath?T(n):Y(y(T(n))))),n},mt=(t,s,e)=>(e=e||{},e.isTypescript=typeof e.isTypescript=="boolean"?e.isTypescript:J.test(s),e),B=(t,s,e)=>{let n=b[t+s];return n||(e=mt(t,s,e),n=ut(t,s,e),b[t+s]=n)};export default Object.assign(B,{pathToPosix:y,getasnode_module_paths:q,getesmkeyvalmatch:M,getasfilesync:f,getasdirsync:W,gettargetindex:V,iscoremodule:I,esmparse:l,cache:b}); | ||
import w from"fs";import S from"url";import i from"path";import _ from"module";const g=_.createRequire(import.meta.url),$=w.realpathSync.native,E=new RegExp("^(?:node:)?("+_.builtinModules.join("|").replace("/","/")+")$"),C=/^\.?\.?([a-zA-Z]:)?(\/|\\)/,x=/^.\.?(?=\/|\\)/,P=/\\/g,D=/index.[tj]sx?$/,G=/[\\/]resolvewithplus[\\/]/,v=/\.js$/,J=/\.ts$/,Z=/(^@[^/]*\/[^/]*|^[^/]*)\/?(.*)$/,y=/^#/,F=/(\*)/g,A=/([./])/g,H=/^node:/,Q=/^file:/,O=[".js",".mjs",".ts",".tsx",".json",".node"],X=O.map(e=>`index${e}`),T="node_modules",h="package.json",U="node",L="default",Y="browser",d="import",j=".",N=e=>e&&typeof e=="object",b={},I=e=>H.test(e)?e:`node:${e}`,ee=e=>e&&S.pathToFileURL(e).href,te=e=>E.test(e),ne=e=>Q.test(e)?S.fileURLToPath(e):e,se=e=>i.resolve(i.extname(e)?i.dirname(e):e)+i.sep,R=e=>P.test(e)?e.replace(P,i.posix.sep):e,a=(e,s)=>{try{s=w.statSync(e)}catch{s=!1}return s&&(s.isFile()||s.isFIFO())},re=(e,s)=>{const t=s.find(n=>a(e+n))||null;return t&&e+t},oe=(e,s)=>{const t=s.find(n=>a(i.join(e,n)))||null;return t&&i.join(e,t)},k=(e,s=e.split(i.sep))=>{const t=(n,r=[[],[]])=>{if(!n.length)return r[1].reverse();if(n[0]===T&&!G.test(e))return t(n.slice(1),r);const o=r[0].length?i.join(r[0].slice(-1)[0],n[0]):n[0]||i.sep;return r[0].push(o),r[1].push(i.resolve(i.join(o,T))),t(n.slice(1),r)};return t(s)},ie=e=>{const s=e.split(i.sep).slice(1).reduce((t,n,r)=>(t.push(i.resolve(i.join(r?t[r-1]:i.sep,n))),t),[]).reverse().find(t=>a(i.join(t,h)));return s&&i.join(s,h)},ce=e=>(String(e).match(Z)||[]).slice(1),q=(e,s)=>new RegExp(e.replace(A,"\\$1").replace(F,".*")).test(s),le=(e,s,t)=>{const n=new RegExp(e.replace(A,"\\$1").replace(F,"(.*)")),r=(t.match(n)||[])[1];return r&&s.replace("*",r)},K=(e,s,t,n=!1)=>(q(e,t)&&(s.includes("*")?q(s,t)?n=t:e.includes("*")&&e!==s&&(n=le(e,s,t)):n=s),n),M=(e,s,t,n=e[0])=>e.length?(y.test(t)?y.test(n):x.test(n))&&typeof s[n]=="string"&&K(n,s[n],t)||M(e.slice(1),s,t):null,l=(e,s,t={})=>{let n=!1;return typeof e=="string"?e:(!n&&Array.isArray(e)&&(n=e.reduce((r,o)=>r||l(o,s,t),null)),!n&&N(e)&&(typeof e[s]=="string"&&(n=e[s]),n||(n=(t.priority||[U,L]).reduce((r,o)=>r||l(e[o],s,t),!1)),!n&&e[s]&&(n=l(e[s],s,t)),!n&&e[j]&&(n=typeof e[j]=="string"?s===d&&l(e[j],s,t):l(e[j],s,t)),n||(n=M(Object.keys(e),e,s))),n)},V=(e,s)=>{let t=s&&s.isimport&&e.module,n=t||s&&s.isbrowser&&e.browser,r=e.exports,o,c;return n&&(typeof n=="string"?c=n:N(n)&&([o]=Object.keys(n).filter(u=>D.test(u)),c=o in n&&n[o])),r&&(c=l(r,d,s)),c},m=(e,s={})=>{var t=null,n=s.istypescript&&v.test(e)&&e.replace(v,".ts");return a(n)?t=n:a(e)?t=e:t=re(e,O),t},W=(e,s)=>{let t=null,n,r=i.join(e,h),o=a(r)&&g(r);return(n=V(o,s))?t=m(i.join(e,n)):(n=o.main)?t=m(i.join(e,n),s)||m(i.join(e,i.join(n,"index"))):t=oe(e,X),t},z=(e,s,t)=>{const n=x.test(e)?i.join(s,e):e;return m(n,t)||W(n,t)},ae=(e,s,t,n)=>{const r=t&&t.imports,o=l(r,s,n);return o&&(x.test(o)?i.join(e,o):B(o,e,{isposixpath:!0}))},ue=(e,s,t,n,r)=>{const o=l(n&&n.exports,t?"./"+t:d,r);return o&&i.join(e,s,o)},fe=(e,s,t,n)=>{const r=i.join(e,s,h),o=a(r),c=o&&g(r);return o&&ue(e,s,t,c,n)},me=(e,s,t)=>{const n=ie(s),r=i.dirname(n);return n&&ae(r,e,g(n),t)},he=(e,s,t)=>{const[n,r]=ce(e);if(y.test(n))return me(e,s,t);const o=k(s).sort((c,u)=>c.length>u.length);return function c(u,f,p=f-1){return f--?fe(i.join(u[p-f]),n,r,t)||z(i.join(u[p-f],e),null,t)||c(o,f,p):null}(o,o.length)},de=(e,s,t)=>{var n=null;return s=typeof s=="string"?se(ne(decodeURI(s))):process.cwd(),E.test(e)?n=I(e):(n=C.test(e)?z(R(e),s,t):he(e,s,t),n=n&&(t.isposixpath?$(n):ee(R($(n))))),n},je=(e,s,t)=>{const n=(r,o)=>typeof r=="boolean"?r:o;return t=t||{},t.istypescript=n(t.istypescript,J.test(s)),t.isbrowser=n(t.isbrowser,!1),t.isimport=n(t.isimport,!0),Array.isArray(t.priority)||(t.priority=[],t.isbrowser&&t.priority.push(Y),t.isimport&&t.priority.push(d),t.priority.push(U),t.priority.push(L)),t},B=(e,s,t)=>{let n=b[e+s];return n||(t=je(e,s,t),n=de(e,s,t),b[e+s]=n)};export default Object.assign(B,{pathToPosix:R,getasnode_module_paths:k,getesmkeyvalmatch:K,getasfilesync:m,getasdirsync:W,gettargetindex:V,iscoremodule:te,esmparse:l,cache:b}); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
6970
16
34