Prevent bundling of Node polyfills when importing TestUtils/TestRenderer #15305
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I think this fixes #14853 (comment).
In particular, there are two cases we'd like to avoid:
require
expression being dynamic.timers
or forglobal
) because we access them. (This is happening on master.)Effectively, we want to obscure the
require
call from webpack. There are a few webpack-specific ways to do it but they seem brittle. Additionally, naïve ways to obscure it (like the current code) are inlined by GCC at our build step for the prod bundle.Instead, I'm reading
module.require
— which doesn't even exist in webpack runtime but exists in Node. Webpack doesn't analyze it. To further strengthen it, I make therequire
string itself dynamic. Seems like this is sufficient. I only tested webpack and Node. It might be worth testing that browserify or Rollup work as expected — but they also not known for noisy warnings so I assume it should be fine.This wouldn't work if TestRender or TestUtils were a Node ESM because there would be no
require
in it. But that's status quo anyway because our currentrequire
call wouldn't work either.