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

insert-module-globals

Package Overview
Dependencies
Maintainers
1
Versions
64
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

insert-module-globals - npm Package Compare versions

Comparing version 0.1.3 to 0.2.0

buffer.js

30

index.js

@@ -8,5 +8,11 @@ var parseScope = require('lexical-scope');

var fs = require('fs');
var processModulePath = require.resolve('process/browser.js');
var processModuleSrc = fs.readFileSync(processModulePath, 'utf8');
var bufferModulePath = path.join(__dirname, 'buffer.js');
var bufferModuleSrc = fs.readFileSync(bufferModulePath, 'utf8');
var varNames = [ 'process', 'global', '__filename', '__dirname', 'Buffer' ];
module.exports = function (files, opts) {

@@ -27,3 +33,3 @@ if (!Array.isArray(files)) {

);
var resolvedProcess = false;
var resolved = { process: false, Buffer: false };

@@ -36,2 +42,3 @@ return through(write, end);

&& !/\bglobal\b/.test(row.source)
&& !/\bBuffer\b/.test(row.source)
&& !/\b__filename\b/.test(row.source)

@@ -42,5 +49,3 @@ && !/\b__dirname\b/.test(row.source)

var scope = opts.always
? { globals: {
implicit: [ 'process', 'global', '__filename', '__dirname' ]
} }
? { globals: { implicit: varNames } }
: parseScope(row.source)

@@ -51,3 +56,3 @@ ;

if (scope.globals.implicit.indexOf('process') >= 0) {
if (!resolvedProcess) {
if (!resolved.process) {
this.queue({

@@ -60,6 +65,19 @@ id: processModulePath,

resolvedProcess = true;
resolved.process = true;
row.deps.__browserify_process = processModulePath;
globals.process = 'require("__browserify_process")';
}
if (scope.globals.implicit.indexOf('Buffer') >= 0) {
if (!resolved.Buffer) {
this.queue({
id: bufferModulePath,
source: bufferModuleSrc,
deps: {}
});
}
resolved.Buffer = true;
row.deps.__browserify_buffer = bufferModulePath;
globals.Buffer = 'require("__browserify_buffer").Buffer';
}
if (scope.globals.implicit.indexOf('global') >= 0) {

@@ -66,0 +84,0 @@ globals.global = 'window';

9

package.json
{
"name": "insert-module-globals",
"version": "0.1.3",
"version": "0.2.0",
"description": "insert implicit module globals into a module-deps stream",

@@ -21,6 +21,9 @@ "main": "index.js",

"browser-pack": "~0.2.0",
"module-deps": "~0.2.0"
"buffer-browserify": "~0.0.5",
"module-deps": "~0.2.0",
"browserify": "~2.5.1"
},
"scripts": {
"test": "tap test/*.js"
"test": "tap test/*.js",
"prepublish": "./bundle.sh"
},

@@ -27,0 +30,0 @@ "repository": {

@@ -21,1 +21,16 @@ var test = require('tap').test;

});
test('buffer inserts', function (t) {
t.plan(2);
var files = [ __dirname + '/insert/buffer.js' ];
var s = mdeps(files)
.pipe(insert(files))
.pipe(bpack({ raw: true }))
;
var src = '';
s.on('data', function (buf) { src += buf });
s.on('end', function () {
var c = { t: t, setTimeout: setTimeout };
vm.runInNewContext(src, c);
});
});

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