Comparing version 0.0.1 to 0.0.2
29
index.js
@@ -21,7 +21,12 @@ 'use strict'; | ||
var name = path.basename(location) | ||
, context = { load: require } | ||
var context = { load: require } | ||
, name = path.basename(location) | ||
, code = read(location); | ||
// Run it in a context so we can expose the globals | ||
// Add the missing globals that are not present in vm module. | ||
Object.keys(missing).forEach(function missingInVM(global) { | ||
context[global] = missing[global]; | ||
}); | ||
// Run it in a context so we can expose the globals. | ||
context = vm.createContext(context); | ||
@@ -32,2 +37,7 @@ vm.runInContext(code, context, name); | ||
if (context.load === require) delete context.load; | ||
Object.keys(missing).forEach(function missingInVM(global) { | ||
if (context[global] === missing[global]) { | ||
delete context[global]; | ||
} | ||
}); | ||
@@ -47,2 +57,15 @@ // If only one global was exported, we should simply expose it using the | ||
/** | ||
* The following properties are missing when loading plain ol files. | ||
* | ||
* @private | ||
*/ | ||
var missing = { | ||
console: console | ||
, setTimeout: setTimeout | ||
, clearTimeout: clearTimeout | ||
, setInterval: setInterval | ||
, clearInterval: clearInterval | ||
}; | ||
/** | ||
* Code reading and cleaning up. | ||
@@ -49,0 +72,0 @@ * |
{ | ||
"name": "load", | ||
"version": "0.0.1", | ||
"version": "0.0.2", | ||
"description": "Load JavaScript files that do not use the bloat module patterns", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
'use strict'; | ||
function test() { | ||
console.log('console.log(foo:bar)'); | ||
setTimeout(function () { | ||
console.log('setTimeout()'); | ||
}, 100); | ||
var x = setInterval(function () { | ||
console.log('setInterval()'); | ||
clearTimeout(x); | ||
}, 1000); | ||
return 'foo:bar'; | ||
} |
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
4007
99