fix: detect if @sanity/browserslist-config can't be resolved
#1533
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.
Fixes #1397 but unsure if it can land since
findPackageJSONisn't well supported yet. I initially tried withcreateRequire, but I couldn't get it to fail when running from within@sanity/pkg-utils, it has to detect resolution errors fromcwd. Since@sanity/pkg-utilshas a direct dependency on@sanity/browserslist-configthere's always going to be./node_modules/@sanity/pkg-utils/node_modules/@sanity/browserslist-configor./node_modules/@sanity/browserslist-config.It needs to detect the
./node_modules/@sanity/pkg-utils/node_modules/@sanity/browserslist-configcase specifically, or rather, that./node_modules/@sanity/browserslist-configis "missing" and thus"browserslist": "extends @sanity/browserslist-config"won't have an effect in other tooling than@sanity/pkg-utilsitself.I put "missing" in quotes, as it's not that simple.
./node_modules/@sanity/browserslist-configmight be missing and its fine, if../../node_modules/@sanity/browserslist-configdoes. That's why I'm trying to rely on core node resolution APIs so that we can know for a fact wether it's failing to resolve or not.