fix dynamic require of node:-namespaced builtins #2755
+271
−39
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.
Closes: #2754
Description
This fixes a couple of bugs, actually:
inferExports
no longer throws when encountering the plainly-invalid-but-first-discovered-in-the-wild export alias of./
. This alias is now ignored.importNowHook
now handles dynamically-required builtins without considering them to first be packages, which a) is faster and b) avoids a potential thrown exception when aFileUrlToPathFn
encounters a module specifier that appears to have a scheme but is not thefile:
scheme (likenode:fs
). This was the root cause of the issue in compartment-mapper: dynamic require of "node:"-prefixed builtins fails #2754.And some tangents:
inferExports
issue, I refactored type signatures to usePackageDescriptor
instead ofobject
. This required defining a few more fields inPackageDescriptor
whichinfer-exports.js
considers.WILDCARD_POLICY_VALUE
is now interally-exported frompolicy-format.js
which should probably be used instead of'any'
in the context of policy (wherever possible). It's now used in the test suite for dynamic requires.And with shame:
mapParsers
to have the signature that I had originally intended. And I didn't feel like it deserved an entire PR. This is completely unrelated to anything else hereSecurity Considerations
n/a
Scaling Considerations
It should be faster for
@endo/compartment-mapper
to crunch dynamically-required builtins.Documentation Considerations
I don't think this needs any documentation changes.
Testing Considerations
I've added coverage for #2754, but did not add coverage for anything else. I should probably add coverage for the change to
inferExports
.Compatibility Considerations
Backwards compatible
Upgrade Considerations