insert-module-globals
Advanced tools
Comparing version 7.1.0 to 7.2.0
21
index.js
@@ -1,4 +0,5 @@ | ||
var parseScope = require('lexical-scope'); | ||
var undeclaredIdentifiers = require('undeclared-identifiers'); | ||
var through = require('through2'); | ||
var merge = require('xtend'); | ||
var parse = require('acorn-node').parse; | ||
@@ -107,5 +108,5 @@ var path = require('path'); | ||
try { | ||
var scope = opts.always | ||
? { globals: { implicit: varNames } } | ||
: parseScope('(function(){\n' + source + '\n})()') | ||
var undeclared = opts.always | ||
? { identifiers: varNames, properties: [] } | ||
: undeclaredIdentifiers(parse(source), { wildcard: true }) | ||
; | ||
@@ -127,4 +128,4 @@ } | ||
var parts = name.split('.') | ||
var prop = (scope.globals.implicitProperties || {})[parts[0]] | ||
if (!prop || prop.length !== 1 || prop[0] !== parts[1]) return; | ||
var prop = undeclared.properties.indexOf(name) | ||
if (prop === -1 || countprops(undeclared.properties, parts[0]) > 1) return; | ||
var value = vars[name](file, basedir); | ||
@@ -139,3 +140,3 @@ if (!value) return; | ||
if (globals[name]) return; | ||
if (scope.globals.implicit.indexOf(name) < 0) return; | ||
if (undeclared.identifiers.indexOf(name) < 0) return; | ||
var value = vars[name](file, basedir); | ||
@@ -191,1 +192,7 @@ if (!value) return; | ||
} | ||
function countprops (props, name) { | ||
return props.filter(function (prop) { | ||
return prop.slice(0, name.length + 1) === name + '.'; | ||
}).length; | ||
} |
{ | ||
"name": "insert-module-globals", | ||
"version": "7.1.0", | ||
"version": "7.2.0", | ||
"description": "insert implicit module globals into a module-deps stream", | ||
@@ -11,9 +11,10 @@ "main": "index.js", | ||
"JSONStream": "^1.0.3", | ||
"acorn-node": "^1.5.2", | ||
"combine-source-map": "^0.8.0", | ||
"concat-stream": "^1.6.1", | ||
"is-buffer": "^1.1.0", | ||
"lexical-scope": "^1.2.0", | ||
"path-is-absolute": "^1.0.1", | ||
"process": "~0.11.0", | ||
"through2": "^2.0.0", | ||
"undeclared-identifiers": "^1.1.2", | ||
"xtend": "^4.0.0" | ||
@@ -23,5 +24,6 @@ }, | ||
"browser-pack": "^6.0.0", | ||
"buffer": "^3.0.0", | ||
"buffer": "^4.9.1", | ||
"convert-source-map": "~1.1.0", | ||
"module-deps": "^4.0.2", | ||
"nanobench": "^2.1.1", | ||
"tape": "^4.2.0", | ||
@@ -28,0 +30,0 @@ "timers-browserify": "^1.4.2" |
@@ -7,2 +7,5 @@ var test = require('tape'); | ||
var vm = require('vm'); | ||
// use is-buffer instead of builtin Buffer.isBuffer. The builtin | ||
// does `instanceof` which does not work on the browserified version | ||
var isBuffer = require('is-buffer'); | ||
@@ -26,4 +29,38 @@ test('isbuffer', function (t) { | ||
test('isbuffer (and Buffer.from)', function (t) { | ||
t.plan(5); | ||
var deps = mdeps() | ||
var pack = bpack({ raw: true, hasExports: true }); | ||
deps.pipe(pack).pipe(concat(function (src) { | ||
var c = { global: {} }; | ||
vm.runInNewContext(src, c); | ||
t.equal(c.require('main')(c.require('main').a()), true, 'is a buffer'); | ||
t.equal(c.require('main')('wow'), false, 'is not a buffer'); | ||
t.equal(isBuffer(c.require('main').a()), true, 'is a buffer'); | ||
t.ok(/require\("buffer"\)/.test(src), 'buffer required in source') | ||
t.equal(c.require('main').a().toString('hex'), 'abcd', 'is a buffer'); | ||
})); | ||
deps.write({ transform: inserter, global: true }); | ||
deps.end({ id: 'main', file: __dirname + '/isbuffer/both.js' }); | ||
}); | ||
test('isbuffer (and new Buffer)', function (t) { | ||
t.plan(5); | ||
var deps = mdeps() | ||
var pack = bpack({ raw: true, hasExports: true }); | ||
deps.pipe(pack).pipe(concat(function (src) { | ||
var c = { global: {} }; | ||
vm.runInNewContext(src, c); | ||
t.equal(c.require('main')(c.require('main').a()), true, 'is a buffer'); | ||
t.equal(c.require('main')('wow'), false, 'is not a buffer'); | ||
t.equal(isBuffer(c.require('main').a()), true, 'is a buffer'); | ||
t.ok(/require\("buffer"\)/.test(src), 'buffer required in source') | ||
t.equal(c.require('main').a().toString('utf8'), 'abcd', 'is a buffer'); | ||
})); | ||
deps.write({ transform: inserter, global: true }); | ||
deps.end({ id: 'main', file: __dirname + '/isbuffer/new.js' }); | ||
}); | ||
function inserter (file) { | ||
return insert(file, { basedir: __dirname + '/isbuffer' }); | ||
} |
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
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
32934
44
762
10
7
24
+ Addedacorn-node@^1.5.2
+ Addedacorn@7.4.1(transitive)
+ Addedacorn-node@1.8.2(transitive)
+ Addedacorn-walk@7.2.0(transitive)
+ Addeddash-ast@1.0.0(transitive)
+ Addedget-assigned-identifiers@1.2.0(transitive)
+ Addedsimple-concat@1.0.1(transitive)
+ Addedundeclared-identifiers@1.1.3(transitive)
- Removedlexical-scope@^1.2.0
- Removedacorn@4.0.13(transitive)
- Removedastw@2.2.0(transitive)
- Removedlexical-scope@1.2.0(transitive)