Closed jbroma closed 5 months ago
All modified and coverable lines are covered by tests :white_check_mark:
Project coverage is 83.58%. Comparing base (
f8f7d55
) to head (bab106d
).
:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.
@huntie has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.
Huge thanks for working on this @jbroma.
From my testing just now I think there may be a bit more to this though that explains why an array is useful. It seems Node takes the first entry satisfying the asserted conditions.
Eg, with:
{
"name": "pkg",
"exports": [{"custom": "./foo.js"}, {"import": "./bar.js"}, "./baz.js"]
}
resolve-test node --conditions=custom -p 'require.resolve("pkg")'
/Users/robhogan/workspace/resolve-test/node_modules/pkg/foo.js
resolve-test node --experimental-default-type=module -e 'console.log(import.meta.resolve("pkg"))'
file:///Users/robhogan/workspace/resolve-test/node_modules/pkg/bar.js
resolve-test node -p 'require.resolve("pkg")'
/Users/robhogan/workspace/resolve-test/node_modules/pkg/baz.js
So I think the approach here would be to normalise to the equivalent object form, which I think is..
{
".": {
"custom": "./foo.js",
"import": "./bar.js",
"default": "./baz.js"
}
}
That needs a bit more verifcation against other resolvers though, and we might also want to consider nested arrays or more complex objects, although I think correctly dealing with the array of strings-or-flat-objects case would be a strict improvement on where we are.
@robhogan oh I absolutely agree - there is more to this than what meets the eye :)
I think we should proceed with merging this edge case and handle other scenarios in separate issues / PR's. The normalisation that you've provided seems like a good starting point to begin with. We can reuse the repro from the #1236 and just add more cases there.
Is there anything else that needs to be addressed in this PR? I see the FB internal job failed for some reason.
@huntie @robhogan is there anything blocking us from proceeding with this PR?
@huntie merged this pull request in facebook/metro@fa17a0d67c4ed06bb9347ee7d902147fa3893ef7.
Summary
This PR deals with array root shorthand edge case from #1236
[nonstrict]
test case to highlight that non-declared paths from array should not work normallyChangelog: [Experimental] Fix package exports array root shorthand resolution to behave like node (edge case)
Test plan