Comparing version 0.1.0 to 0.1.1
@@ -0,1 +1,5 @@ | ||
## 0.1.1 | ||
- Make it possible to add globals to the loaded script. | ||
- Added missing `__dirname` and `__filename`. | ||
## 0.1.0 | ||
@@ -2,0 +6,0 @@ - It exposes the compiler. |
23
index.js
@@ -21,3 +21,6 @@ 'use strict'; | ||
return compiler(read(location), path.basename(location)); | ||
return compiler(read(location), path.basename(location), { | ||
__filename: path.basename(location), | ||
__dirname: path.dirname(location) | ||
}); | ||
} | ||
@@ -30,6 +33,10 @@ | ||
* @param {String} name The name of the file. | ||
* @param {Object} globals Additional globals | ||
* @returns {Mixed} Things. | ||
* @api public | ||
*/ | ||
function compiler(code, name) { | ||
function compiler(code, name, globals) { | ||
name = name || 'load.js'; | ||
globals = globals || {}; | ||
var context = { load: require }; | ||
@@ -42,2 +49,7 @@ | ||
// Add extra globals. | ||
Object.keys(globals).forEach(function missingInVM(global) { | ||
context[global] = globals[global]; | ||
}); | ||
// Run it in a context so we can expose the globals. | ||
@@ -54,2 +66,7 @@ context = vm.createContext(context); | ||
}); | ||
Object.keys(globals).forEach(function missingInVM(global) { | ||
if (context[global] === globals[global]) { | ||
delete context[global]; | ||
} | ||
}); | ||
@@ -59,3 +76,3 @@ // If only one global was exported, we should simply expose it using the | ||
// all. | ||
var globals = Object.keys(context); | ||
globals = Object.keys(context); | ||
@@ -62,0 +79,0 @@ if (globals.length === 1) return context[globals.pop()]; |
{ | ||
"name": "load", | ||
"version": "0.1.0", | ||
"version": "0.1.1", | ||
"description": "Load JavaScript files that do not use the bloat module patterns", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
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
6600
10
157