insert-module-globals
Advanced tools
Comparing version 0.1.3 to 0.2.0
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'; |
{ | ||
"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
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
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
120129
24
3346
5
10
1