-
Notifications
You must be signed in to change notification settings - Fork 151
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: Handle the scenario where a package.json#browser field could be false
#427
Changes from 10 commits
b8174ce
a68c80a
30fcf60
103aac3
d36adc4
416fca3
5f5e7f6
4e3ece6
154b203
d225ebb
c201632
18927d8
1d48d95
4195963
59758c2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# include node_modules for testing | ||
!node_modules |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
require('pkg'); | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
[ | ||
"package.json", | ||
"test/unit/browser-remappings-false/input.js", | ||
"test/unit/browser-remappings-false/node_modules/pkg/browser.js", | ||
"test/unit/browser-remappings-false/node_modules/pkg/index.js", | ||
"test/unit/browser-remappings-false/node_modules/pkg/package.json" | ||
] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"conditions": ["browser"] | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# include node_modules for testing | ||
!node_modules |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
require('pkg'); | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
[ | ||
"package.json", | ||
"test/unit/browser-remappings-undefined/input.js", | ||
"test/unit/browser-remappings-undefined/node_modules/pkg/index.js", | ||
"test/unit/browser-remappings-undefined/node_modules/pkg/package.json", | ||
"test/unit/browser-remappings-undefined/node_modules/pkg/require-main.cjs", | ||
"test/unit/browser-remappings-undefined/node_modules/pkg/subdir/import-main.js", | ||
"test/unit/browser-remappings-undefined/node_modules/pkg/subdir/package.json" | ||
] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"conditions": ["browser"] | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually now that I think about it, isn't there a case where browser can be a string?
We should add a test for this case as well
https://gist.github.com/defunctzombie/4339901/49493836fb873ddaa4b8a7aa0ef2352119f69211
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It can be, but I saw this test and now I think that maybe we should update its implementation (and rename). It's ensuring that the field specified in the browser field is not in the output, but it's not imported anywhere in the other modules so I think it's a false positive (as you pointed out when we were pairing).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jeffsee55 That is very strange.
Maybe talk to @dvoytenko to see if that is a mistake since I would expect to see import-main-browser.js in the output.js.
Also, that test seems very oddly written since
pkg
is its own package boundary andpkg/subdir
is another package boundary, but thebrowser
field is referencing files from one to the other. I don't think thats common (or even allowed?)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @styfle , will follow up with Dima.
For posterity, here are my thoughts on the current state of these tests, it seems like the
output.js
should expect only files that are traceable fromnft
, but in the tests the browser-specific files aren't imported or required by the paths the relate to the input entrypoint. So in my test I required it specifically. So it seemed like the other tests aren't asserting the right behavior because those browser files just aren't part of the dependency graph.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it could be a string, as in "main export file for browser". TBH, I haven't seen those in the wild and not what I've been trying to support in one of my previous PRs. But I think it's a use case in its own right and probably should be supported too. It's a relatively under-defined and legacy area - most of folk moved away from
browser
, but I found the best way to debug them is by trying out to build examples usingesbuild
- it understandsbrowser
correctly.