fix(commonjs): short-circuit to actual module entry point when using circular ref through a different entry #888
+669
−107
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.
Rollup Plugin Name:
commonjs
This PR contains:
Are tests included?
Breaking Changes?
Description
A friend encountered an issue with the latest version of the
redis
module,where there is a circular reference, but one of the internal files references to the main index.js using
require('../')
.Now commonjs just resolves this to
index.js
and requires it, but in our case it started a newmodule
/exports
context, requiredindex.js
, and then attached the result to theexport
. Which failed, as theexports
should already have had a few properties attach by the time the circular ref hit.Now I brought this even closer to the commonjs implementation - we now store information about the correct target, so the virtual commonjs system will know to actually require the
index.js
in the first place, and not as a secondary require.I've also thought of the possibility to do this in the transform - changing the require calls in the source - but this will not work for many cases where the
require
path is built dynamically.(Btw, the new circular dependencies support with commonjs@19 fails with this module too. Some cases are just too weird)