This repository has been archived by the owner on Jun 20, 2023. It is now read-only.
[Proposed] Auto-detect if Package is "User-Owned" or not #1876
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.
OK, Here is my proposed solution for supporting "user-owned" packages other than the "default" package.
Note: sometimes these are called "local" packages or just "not external" packages, but in the code, "local" and "external" can sometimes mean other things. So I'm using the term "user-owned" to mean "A package that we expect the user to modify". This is in contrast to packages that are downloaded from a package registry (things in node_modules) that the user should not modify. I derived the term from
PackageType.USER_PACKAGE
which is already in the code.Fuse-box already has a package
type
that can be eitherUSER_PACKAGE
orEXTERNAL_PACKAGE
. Thetype
determines how the package is treated by the cache. But currently only the "default" package is ever set toUSER_PACKAGE
. And so only the one "default" package is ever considered to be user-owned.This has been a problem for monorepo setups in particular where the user-owned code is itself split up into packages. The user will routinely change files outside of the "default" package and wants these things to break cache and to trigger HMR just like changes inside the "default" package do. But currently they don't because only
package.json
changes break cache iftype
is notUSER_PACKAGE
.My proposal is basically this: If a package's true location is outside of
node_modules
then treat it as user-owned. "True location" means: where it really is (after symlinks are dereferenced).(Yarn 2 Note: There is no node_modules in Yarn 2, so instead we resolving any PnP virtual path and seeing if that is a real directory, and if it is, then we consider that user-owned).
I think this is likely to resolve the problem @starsolaris is trying to solve with PR #1844 for, but does so automatically without requiring manual configuration. Note: that we could also later support a manual override, but if we did I think it should just override detection of "user/non-user". But I suspect that this solves @starsolaris's problem without any need to modify config.
This is currently split up into two commits. It is easiest to review them separately. The first one just refactors the way
fileLookup()
andnodeModuleLookup()
return errors. The feature I am proposing is in the second commit.