Comparing version 3.8.0 to 3.8.1
@@ -0,1 +1,7 @@ | ||
v3.8.1 (2019-05-02) | ||
------------------- | ||
[fix] Module resolver fixes | ||
[fix] require('events') works correctly in Node 12 | ||
[fix] SyntaxError not being instanceOf Error | ||
v3.8.0 (2019-04-21) | ||
@@ -2,0 +8,0 @@ ------------------- |
@@ -155,2 +155,3 @@ /* global host */ | ||
const base = host.Object.create(null); | ||
// eslint-disable-next-line prefer-const | ||
let proxy; | ||
@@ -457,2 +458,3 @@ | ||
const base = host.Object.create(null); | ||
// eslint-disable-next-line prefer-const | ||
let proxy; | ||
@@ -459,0 +461,0 @@ |
@@ -215,5 +215,6 @@ /* eslint-disable global-require, no-use-before-define */ | ||
const script = code instanceof VMScript ? code : new VMScript(code); | ||
script.compile(); | ||
try { | ||
return this._internal.Decontextify.value(script.compile()._compiled.runInContext(this._context, { | ||
return this._internal.Decontextify.value(script._compiled.runInContext(this._context, { | ||
filename: script.filename, | ||
@@ -440,5 +441,6 @@ displayErrors: false, | ||
script.wrap('(function (exports, require, module, __filename, __dirname) { ', ' \n})'); | ||
script.compile(); | ||
try { | ||
const closure = script.compile()._compiled.runInContext(this._context, { | ||
const closure = script._compiled.runInContext(this._context, { | ||
filename: script.filename, | ||
@@ -445,0 +447,0 @@ displayErrors: false |
@@ -107,2 +107,3 @@ /* eslint-disable no-shadow, no-invalid-this */ | ||
const _resolveFilename = (path) => { | ||
if (!path) return null; | ||
path = pa.resolve(path); | ||
@@ -117,2 +118,3 @@ | ||
// load as file | ||
for (let i = 0; i < vm.options.sourceExtensions.length; i++) { | ||
@@ -122,13 +124,11 @@ const ext = vm.options.sourceExtensions[i]; | ||
} | ||
if (fs.existsSync(`${path}.json`)) return `${path}.json`; | ||
if (fs.existsSync(`${path}.node`)) return `${path}.node`; | ||
if (fs.existsSync(`${path}.json`)) return `${path}.json`; | ||
// load as directory | ||
// load as module | ||
if (fs.existsSync(`${path}/package.json`)) { | ||
let pkg; | ||
try { | ||
pkg = JSON.parse(fs.readFileSync(`${path}/package.json`, 'utf8')); | ||
if (pkg.main == null || !fs.existsSync(pa.join(path, pkg.main))) pkg.main = 'index.js'; | ||
} catch (ex) { | ||
@@ -138,5 +138,15 @@ throw new VMError(`Module '${path}' has invalid package.json`, 'EMODULEINVALID'); | ||
return _resolveFilename(`${path}/${pkg.main}`); | ||
let main; | ||
if (pkg && pkg.main) { | ||
main = _resolveFilename(`${path}/${pkg.main}`); | ||
if (!main) main = _resolveFilename(`${path}/index`); | ||
} else { | ||
main = _resolveFilename(`${path}/index`); | ||
} | ||
return main; | ||
} | ||
// load as directory | ||
for (let i = 0; i < vm.options.sourceExtensions.length; i++) { | ||
@@ -147,2 +157,3 @@ const ext = vm.options.sourceExtensions[i]; | ||
if (fs.existsSync(`${path}/index.json`)) return `${path}/index.json`; | ||
if (fs.existsSync(`${path}/index.node`)) return `${path}/index.node`; | ||
@@ -171,5 +182,10 @@ | ||
if (moduleName === 'events') { | ||
if (moduleName === 'events' || moduleName === 'internal/errors') { | ||
try { | ||
const script = new Script(`(function (exports, require, module, process) { 'use strict'; ${BUILTIN_MODULES[moduleName]} \n});`, { | ||
const script = new Script(`(function (exports, require, module, process, internalBinding) { | ||
'use strict'; | ||
const primordials = global; | ||
${BUILTIN_MODULES[moduleName]} | ||
\n | ||
});`, { | ||
filename: `${moduleName}.vm.js` | ||
@@ -185,3 +201,3 @@ }); | ||
// run script | ||
script.runInContext(global)(module.exports, module.require, module, host.process); | ||
script.runInContext(global)(module.exports, module.require, module, host.process, host.process.binding); | ||
@@ -188,0 +204,0 @@ return module.exports; |
@@ -16,3 +16,3 @@ { | ||
], | ||
"version": "3.8.0", | ||
"version": "3.8.1", | ||
"main": "index.js", | ||
@@ -19,0 +19,0 @@ "repository": "github:patriksimek/vm2", |
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
77621
1718