pierrec / node-eval

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

ensure that globals includes process and console #18

Closed teamdandelion closed 5 years ago

teamdandelion commented 5 years ago

The code attaches global properties to the sandbox context by iterating over all the enumerable properties of global. However, in node v10, console switched to being non-enmuerable. This means that for users of this library with node>10, any console.logs in evaluated scripts will fail.

This commit fixes this issue by manually attaching console to the sandbox (when globals are being used). A test has been added. Prior to the change to eval.js, the test would pass in node v8 but fail in v10 and v12.

Also, the tests were already failing in v12, because in v12 process also became non-enumerable. I've applied a similar fix to process to ensure that it's always available too.

teamdandelion commented 5 years ago

Thanks for merging this, @pierrec. Can you please cut a new release?

teamdandelion commented 5 years ago

Ah, I see you already did. Thanks!