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

browser-require

Package Overview
Dependencies
Maintainers
0
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

browser-require - npm Package Compare versions

Comparing version 0.0.1 to 0.0.2

test/hell.js

19

browser-require.js

@@ -136,3 +136,3 @@ var fs = require('fs')

// Wrap npm as promise $npm, for manageable async middleware
// Wrap npm in a promise, for manageable async middleware
NpmModule.isNpmLoaded = false;

@@ -162,2 +162,19 @@ NpmModule.callbacks = []; // Callbacks for loaded event

, filepath;
// The following continuous block handles incoming requires
// that exist above the base dir
var uq = url.split('?')
, chain = uq[0].split('/')
, q = uq[1]
, nAboveBase;
// prefix carries ..,..,.. information - i.e., how many levels above
if (q) {
match = q.match(/n=([^&]+)/);
if (match) nAboveBase = parseInt(match[1], 10);
}
if (nAboveBase) {
url = chain.join('/');
while (nAboveBase--) url = '/..' + url;
}
if (src = cache[url]) {

@@ -164,0 +181,0 @@ res.writeHead(200, {'Content-Type': 'text/javascript'});

27

client/browser_require.js

@@ -59,8 +59,12 @@ function browserRequire (path) {

var parts = name.split('/')
, clonedparts = dirparts.slice(0);
, clonedparts = dirparts.slice(0)
, aboveBase = false;
for (var i = 0, l = parts.length, part; i < l; i++) {
part = parts[i];
if (part === '.') continue;
else if (part === '..') clonedparts.pop();
else clonedparts.push(part);
else if (part === '..') {
if (clonedparts.length === 1) aboveBase = true;
if (!aboveBase) clonedparts.pop();
else clonedparts.push(part);
} else clonedparts.push(part);
}

@@ -80,7 +84,5 @@ return clonedparts.join('/') + '.js';

: ModulePath.normalize(name, parent);
this.basedir = ModulePath.isNpm(this.name)
? this.name.split('/').length > 2
? this.name.split('/').slice(0, -1).join('/')
: this.name.replace(/\.js$/, '')
: this.name.split('/').slice(0, -1).join('/');
var match = this.name.match(/(\/\.\.)/g);
this.numLevelsAboveBase = match ? match.length : 0;
this.basedir = this.name.split('/').slice(0, -1).join('/');
this.deps = [];

@@ -118,3 +120,3 @@ }

script.async = true;
script.src = this.name;
script.src = this.url();
script.onerror = function () {};

@@ -124,2 +126,9 @@ priorScript.parentNode.insertBefore(script, priorScript);

url: function () {
var n = this.numLevelsAboveBase;
if (n) {
return this.name + '?n=' + n;
} else return this.name
},
/**

@@ -126,0 +135,0 @@ * @param {String} dep

{
"name": "browser-require",
"description": "Use CommonJS and NPM modules from the browser",
"version": "0.0.1",
"version": "0.0.2",
"homepage": "https://github.com/bnoguchi/browser-require",

@@ -6,0 +6,0 @@ "repository": "https://github.com/bnoguchi/browser-require.git",

@@ -27,3 +27,4 @@ browser-require

// What to add
// The following line "app.use(..." is what you want to add to your project
// Make sure the browser-require middleware comes before staticProvider middleware
app.use(exposeRequire({

@@ -33,3 +34,2 @@ base: __dirname // This is where we look to find your non-global modules

// Make sure brequire middleware comes before staticProvider middleware
app.use(connect.staticProvider(__dirname));

@@ -101,3 +101,3 @@ app.listen(3000);

$ npm install data-structures-js
$npm install validator
$ npm install validator

@@ -116,4 +116,5 @@ First, start up the test server:

### Coming soon
### Planning on implementing
- Static compilation of all CommonJS dependencies into a single JavaScript file.
- A middleware filter mechanism to include things such as a Google Closure Compiler filter.

@@ -120,0 +121,0 @@ ### Contributors

Sorry, the diff of this file is not supported yet

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