pierrec / node-eval

Evaluate node require() module content directly
MIT License
93 stars 20 forks source link

Unable to overwrite globals. #10

Open reggi opened 9 years ago

reggi commented 9 years ago

Here's an example where I'm requiring a file ./global.js Array.marker a property of a global variable is not being updated.

// file eval ./example.js
var _eval = require('eval')
var code = [
  'Array.marker = true',
  "require('./global.js')",
  'console.log(Array.marker)' // => true
].join('\n')

var fileName = __dirname + '/example.js'

_eval(code, fileName, {}, {
  'require': require
})
// file eval ./global.js
var hi = function () {
  Array.marker = false
}
module.exports = hi()

Is there any way to make it so that the required module edits the global value for Array.marker?

Note, I'm replacing requireLike with require. So we can see that it's not requireLike that is causing the issue.