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

als-require

Package Overview
Dependencies
Maintainers
0
Versions
36
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

als-require - npm Package Compare versions

Comparing version 1.5.0 to 1.5.1

1

browser/build.js

@@ -17,2 +17,3 @@ const UglifyJS = require("uglify-js");

const content = `const Require = (function(){
const packageJsonCache = {};
${contents.map(fn => fn.toString()).join('\n')}

@@ -19,0 +20,0 @@ return Require;

2

package.json
{
"name": "als-require",
"version": "1.5.0",
"version": "1.5.1",
"main": "index.js",

@@ -5,0 +5,0 @@ "scripts": {

const Require = (function(){
const packageJsonCache = {};
function isCyclyc(fullPath, path) {

@@ -3,0 +4,0 @@ if (Require.contents[fullPath] && Require.contents[fullPath].children.includes(path)) {

@@ -1,8 +0,8 @@

let Require=(()=>{function h(e,t){if(o.contents[e]&&o.contents[e].children.includes(t))throw`cyclic dependency between ${t} and `+e}function i(e,t){var n,e=e.split("/"),r=[];for(n of[...t.split("/").slice(0,-1),...e])".."===n?0<r.length&&".."!==r[r.length-1]?r.pop():r.push(n):"."!==n&&r.push(n);t=r.join("/");return t.endsWith(".js")?t:t+".js"}async function d(e,t="text"){e=await fetch(e);if(e.ok)return e[t]();throw new Error("HTTP error! status: "+e.status)}async function e({contents:n,fullPath:e},a){let r=async s=>{if(void 0===n[s]){if(!a.contents[s]){let e=await d(s),r=[],o=[];e=e.replace(/^(?!\/\/|\/\*.*\*\/).*require\(["'`](.*)["'`]\)/gm,(e,t)=>{var n;return t.startsWith(".")?(h(n=i(t,s),s),r.push(n),e.replace(t,n)):(o.push({match:e,modulePath:t}),e)}),e=await(async(e,o,s)=>{if(0!==e.length)for(var{match:a,modulePath:i}of e){let n,e,t,r=i;i.includes("/")&&(c=i.split("/"),r=c.shift(),e=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 {}`)):(packageJsonCache[c]?t=packageJsonCache[c]:({main:l="index.js"}=await d(c,"json"),packageJsonCache[c]=l),(n=(n=e?((l=t.split("/")).pop(),`/node_modules/${r}/${l.join("/")}/`+e):`/node_modules/${r}/`+t).replace(/\/\.?\//g,"/")).endsWith(".js")||(n+=".js"),h(n,i),o.push(n),s=s.replace(a,a.replace(u,(e,t)=>`require(${t}${n}${t})`)))}return s})(o,r,e),a.contents[s]={content:e,children:r}}let{content:e,children:t}=a.contents[s];n[s]=e,await Promise.all(t.map(e=>r(e)))}};await r(e)}class o{static contents={};static async getModule(e,t,n,r){e=new o(e);return await e.getContent(),e.build(r,t,n)}constructor(e){this.contents={},this.path=e,this.fullPath=i(e,location.pathname),this.contentReady=!1}async getContent(){return this.contentReady||(await e(this,o),this.keys=((t,n)=>{let r=new Set,o=e=>{e.forEach(e=>{t[e]&&(o(n.contents[e].children),r.add(e))})};return o(Object.keys(t).reverse()),Array.from(r)})(this.contents,o),this.contentReady=!0),this}build(e={},t={},r="context"){var{fn:r,modulesLines:o,curLastLine:s}=((e="context",r)=>{let o={},s=3;var t=r.keys.map((e,t)=>{let n=`modules['${e}'] = (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 {}`)):(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 (){
const module = { exports: {} }
const exports = module.exports
${r.contents[e]}
${r.contents[t]}
return module.exports;
})();`;return t===r.keys.length-1&&(n+=`
return modules['${e}']`),o[e]={from:s+1},s+=n.split("\n").length,o[e].to=s,n}).join("\n");return{fn:new Function("modules",e,`function require(path) { return modules[path] || null };
`+t),modulesLines:o,curLastLine:s}})(r,this);try{return r(e,t)}catch(n){{r=n;var a=o;var i=s;let[e,...t]=r.stack.split("\n");throw t=t.map(e=>{var t=e.match(/<anonymous>:(\d*):(\d*)\)$/);if(t){let n=Number(t[1]);if(n+1!==i){var r,o,t=Number(t[2]),s=Object.entries(a).filter(([,{from:e,to:t}])=>n>=e&&n<=t);if(0!==s.length)return[s,{from:r,to:o}]=s[0],` at ${e.match(/at\s(.*?)\s/)[1]} ${s} (${n-r-2}:${t})`}}}).filter(Boolean),r.stack=e+"\n"+t.join("\n"),r;return}}}}return o})(),require=Require.getModule;
})();`;return e===r.keys.length-1&&(n+=`
return modules['${t}']`),o[t]={from:s+1},s+=n.split("\n").length,o[t].to=s,n}).join("\n");return{fn:new Function("modules",t,`function require(path) { return modules[path] || null };
`+e),modulesLines:o,curLastLine:s}})(r,this);try{return r(t,e)}catch(n){{r=n;var a=o;var i=s;let[t,...e]=r.stack.split("\n");throw e=e.map(t=>{var e=t.match(/<anonymous>:(\d*):(\d*)\)$/);if(e){let n=Number(e[1]);if(n+1!==i){var r,o,e=Number(e[2]),s=Object.entries(a).filter(([,{from:t,to:e}])=>n>=t&&n<=e);if(0!==s.length)return[s,{from:r,to:o}]=s[0],` at ${t.match(/at\s(.*?)\s/)[1]} ${s} (${n-r-2}:${e})`}}}).filter(Boolean),r.stack=t+"\n"+e.join("\n"),r;return}}}}return o})(),require=Require.getModule;
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