als-require
Advanced tools
Comparing version 1.5.1 to 1.5.2
@@ -26,2 +26,3 @@ const packageJsonCache = {} | ||
packageJsonCache[pkgJsonPath] = main | ||
filename = main | ||
} | ||
@@ -28,0 +29,0 @@ |
{ | ||
"name": "als-require", | ||
"version": "1.5.1", | ||
"version": "1.5.2", | ||
"main": "index.js", | ||
@@ -5,0 +5,0 @@ "scripts": { |
@@ -50,2 +50,3 @@ const Require = (function(){ | ||
packageJsonCache[pkgJsonPath] = main | ||
filename = main | ||
} | ||
@@ -52,0 +53,0 @@ |
@@ -1,2 +0,2 @@ | ||
let Require=(()=>{let h={};function d(t,e){if(o.contents[t]&&o.contents[t].children.includes(e))throw`cyclic dependency between ${e} and `+t}function i(t,e){var n,t=t.split("/"),r=[];for(n of[...e.split("/").slice(0,-1),...t])".."===n?0<r.length&&".."!==r[r.length-1]?r.pop():r.push(n):"."!==n&&r.push(n);e=r.join("/");return e.endsWith(".js")?e:e+".js"}async function p(t,e="text"){t=await fetch(t);if(t.ok)return t[e]();throw new Error("HTTP error! status: "+t.status)}async function t({contents:n,fullPath:t},a){let r=async s=>{if(void 0===n[s]){if(!a.contents[s]){let t=await p(s),r=[],o=[];t=t.replace(/^(?!\/\/|\/\*.*\*\/).*require\(["'`](.*)["'`]\)/gm,(t,e)=>{var n;return e.startsWith(".")?(d(n=i(e,s),s),r.push(n),t.replace(e,n)):(o.push({match:t,modulePath:e}),t)}),t=await(async(t,o,s)=>{if(0!==t.length)for(var{match:a,modulePath:i}of t){let n,t,e,r=i;i.includes("/")&&(c=i.split("/"),r=c.shift(),t=c.join("/"));var c=`/node_modules/${r}/package.json`,l=await fetch(c,{method:"HEAD"}),u=new RegExp(`require\\((["'\`])${i}["'\`]\\)`);!1===l.ok?(s=s.replace(u,"{}"),console.warn(`The module "${i}" can't be imported and will be replaced with {}`)):(h[c]?e=h[c]:({main:l="index.js"}=await p(c,"json"),h[c]=l),(n=(n=t?((l=e.split("/")).pop(),`/node_modules/${r}/${l.join("/")}/`+t):`/node_modules/${r}/`+e).replace(/\/\.?\//g,"/")).endsWith(".js")||(n+=".js"),d(n,i),o.push(n),s=s.replace(a,a.replace(u,(t,e)=>`require(${e}${n}${e})`)))}return s})(o,r,t),a.contents[s]={content:t,children:r}}let{content:t,children:e}=a.contents[s];n[s]=t,await Promise.all(e.map(t=>r(t)))}};await r(t)}class o{static contents={};static async getModule(t,e,n,r){t=new o(t);return await t.getContent(),t.build(r,e,n)}constructor(t){this.contents={},this.path=t,this.fullPath=i(t,location.pathname),this.contentReady=!1}async getContent(){return this.contentReady||(await t(this,o),this.keys=((e,n)=>{let r=new Set,o=t=>{t.forEach(t=>{e[t]&&(o(n.contents[t].children),r.add(t))})};return o(Object.keys(e).reverse()),Array.from(r)})(this.contents,o),this.contentReady=!0),this}build(t={},e={},r="context"){var{fn:r,modulesLines:o,curLastLine:s}=((t="context",r)=>{let o={},s=3;var e=r.keys.map((t,e)=>{let n=`modules['${t}'] = (function (){ | ||
let Require=(()=>{let h={};function d(t,e){if(o.contents[t]&&o.contents[t].children.includes(e))throw`cyclic dependency between ${e} and `+t}function i(t,e){var n,t=t.split("/"),r=[];for(n of[...e.split("/").slice(0,-1),...t])".."===n?0<r.length&&".."!==r[r.length-1]?r.pop():r.push(n):"."!==n&&r.push(n);e=r.join("/");return e.endsWith(".js")?e:e+".js"}async function p(t,e="text"){t=await fetch(t);if(t.ok)return t[e]();throw new Error("HTTP error! status: "+t.status)}async function t({contents:n,fullPath:t},a){let r=async s=>{if(void 0===n[s]){if(!a.contents[s]){let t=await p(s),r=[],o=[];t=t.replace(/^(?!\/\/|\/\*.*\*\/).*require\(["'`](.*)["'`]\)/gm,(t,e)=>{var n;return e.startsWith(".")?(d(n=i(e,s),s),r.push(n),t.replace(e,n)):(o.push({match:t,modulePath:e}),t)}),t=await(async(t,o,s)=>{if(0!==t.length)for(var{match:a,modulePath:i}of t){let n,t,e,r=i;i.includes("/")&&(c=i.split("/"),r=c.shift(),t=c.join("/"));var c=`/node_modules/${r}/package.json`,l=await fetch(c,{method:"HEAD"}),u=new RegExp(`require\\((["'\`])${i}["'\`]\\)`);!1===l.ok?(s=s.replace(u,"{}"),console.warn(`The module "${i}" can't be imported and will be replaced with {}`)):(e=h[c]||({main:l="index.js"}=await p(c,"json"),h[c]=l),(n=(n=t?((l=e.split("/")).pop(),`/node_modules/${r}/${l.join("/")}/`+t):`/node_modules/${r}/`+e).replace(/\/\.?\//g,"/")).endsWith(".js")||(n+=".js"),d(n,i),o.push(n),s=s.replace(a,a.replace(u,(t,e)=>`require(${e}${n}${e})`)))}return s})(o,r,t),a.contents[s]={content:t,children:r}}let{content:t,children:e}=a.contents[s];n[s]=t,await Promise.all(e.map(t=>r(t)))}};await r(t)}class o{static contents={};static async getModule(t,e,n,r){t=new o(t);return await t.getContent(),t.build(r,e,n)}constructor(t){this.contents={},this.path=t,this.fullPath=i(t,location.pathname),this.contentReady=!1}async getContent(){return this.contentReady||(await t(this,o),this.keys=((e,n)=>{let r=new Set,o=t=>{t.forEach(t=>{e[t]&&(o(n.contents[t].children),r.add(t))})};return o(Object.keys(e).reverse()),Array.from(r)})(this.contents,o),this.contentReady=!0),this}build(t={},e={},r="context"){var{fn:r,modulesLines:o,curLastLine:s}=((t="context",r)=>{let o={},s=3;var e=r.keys.map((t,e)=>{let n=`modules['${t}'] = (function (){ | ||
const module = { exports: {} } | ||
@@ -3,0 +3,0 @@ const exports = module.exports |
49557
747