Skip to content
This repository has been archived by the owner on Sep 9, 2024. It is now read-only.

ensure that globals includes process and console #18

Merged
merged 1 commit into from
Jul 6, 2019

Conversation

teamdandelion
Copy link
Contributor

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.

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][1]. This means that for
users of this library with node>10, any `console.log`s 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.

[1]: nodejs/node#17708
@pierrec pierrec merged commit 5135bfb into pierrec:master Jul 6, 2019
@teamdandelion
Copy link
Contributor Author

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

@teamdandelion
Copy link
Contributor Author

Ah, I see you already did. Thanks!

teamdandelion added a commit to teamdandelion/static-site-generator-webpack-plugin that referenced this pull request Jul 6, 2019
The `eval` dependency has a bug in node v10 and above, where the
`console` won't be available to scripts, even if globals are supposed to
be available. See: pierrec/node-eval#18. For users of
static-site-generator-webpack-plugin, this means that index scripts
which contain logging statements will not work properly.

The bug is fixed in eval v0.1.4, so we just need to update the
dependency.

Test plan: `yarn test` still passes.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants