fix: Handle the scenario where a package.json#browser field could be false#427
fix: Handle the scenario where a package.json#browser field could be false#427kodiakhq[bot] merged 15 commits intomainfrom
false#427Conversation
…set to {'./some-path': false}
593191b to
b8174ce
Compare
Co-authored-by: Steven <steven@ceriously.com>
| const { browser: pkgBrowser } = pkgCfg; | ||
| if (!pkgBrowser) { | ||
| return; | ||
| } |
There was a problem hiding this comment.
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.
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.
@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 and pkg/subdir is another package boundary, but the browser 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.
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 from nft, 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.
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 using esbuild - it understands browser correctly.
false
|
This one is failing on Windows only: |
|
Confirmed this has nothing to do with this PR, tests are failing here too |
styfle
left a comment
There was a problem hiding this comment.
Is there a test for a string instead of object? For example, "browser": "./foo.js" ?
|
@styfle there was already one here https://github.com/vercel/nft/blob/main/test/unit/browser-remappings-malformed/node_modules/pkg/package.json. However I was hoping to revisit this after we land this to ensure that these tests are actually asserting what we think they are. That test, for example doesn't actually require the file mentioned in the |
|
@jeffsee55 I'm not suggesting that you change the existing test. I want a new test that tests for Something like: And then That would prove that your comment is correct when it says "Downstream processing is expected to handle this case, and it should remain in the mapping result" |
|
🎉 This PR is included in version 0.27.3 🎉 The release is available on: Your semantic-release bot 📦🚀 |
…ort (#11841) See [nft](vercel/nft#427) for details
We recently shipped support for the
browserfield, but we discovered an edge case where instead of mapping to another string, the value could befalse(eg,object-inspect), which indicates that this module should be treated as an empty object ({}) (evidenced by its usage here).The code was previously erroring on the string's
startsWithchecks, causing the entire package to be omitted from the file mapping result. This ensures that if the value isfalsewe'll continue on.