-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
NodeResolver: Reload the closest package.json to an asset if it's a package entry #7909
Conversation
Benchmark ResultsKitchen Sink 🚨
Timings
Cold BundlesNo bundles found, this is probably a failed build... Cached BundlesNo bundles found, this is probably a failed build... React HackerNews ✅
Timings
Cold Bundles
Cached BundlesNo bundle changes detected. AtlasKit Editor 🚨
Timings
Cold BundlesNo bundles found, this is probably a failed build... Cached BundlesNo bundles found, this is probably a failed build... Three.js ✅
Timings
Cold BundlesNo bundle changes detected. Cached BundlesNo bundle changes detected. |
For future reference, this bug is just another version of #5975 |
Also, instead or additionally adding a resolver unit test might be good |
4e4b59f
to
68f885d
Compare
68f885d
to
d591a93
Compare
This update should definitely be done inside |
This doesn't really capture whether the file was loaded as a package entry, which is afaik the only thing that could invalidate the pkg we had loaded prior. It would also cause unnecessary reloads for files in packages with additional directories that were not themselves packages, yeah? |
de9569b
to
7845dc3
Compare
Right
Every folder can contain a package.json, but there is only one case where it wouldn't match. So there shouldn't be unnecessary reloads. (And if we do want to keep that flag, maybe rename |
So some of these new invalidations are just duplicates, some make sense (e.g. for it('should resolve a node_modules index.js', async function () {
let resolved = await resolver.resolve({
env: BROWSER_ENV,
filename: 'foo',
specifierType: 'esm',
parent: path.join(rootDir, 'foo.js'),
});
assert.deepEqual(resolved, {
filePath: path.join(rootDir, 'node_modules', 'foo', 'index.js'),
sideEffects: undefined,
query: undefined,
invalidateOnFileCreate: [
{
fileName: 'package.json',
aboveFilePath: path.join(rootDir, 'index'),
},
{
fileName: 'package.json',
aboveFilePath: path.join(rootDir, 'foo.js'),
},
{
fileName: 'node_modules/foo',
aboveFilePath: path.join(rootDir, 'foo.js'),
},
+ {
+ fileName: 'package.json',
+ aboveFilePath: path.join(rootDir, 'node_modules/foo/index.js'),
+ },
],
invalidateOnFileChange: [
path.join(rootDir, 'package.json'),
path.join(rootDir, 'node_modules', 'foo', 'package.json'),
], |
88735fa
to
9b09b63
Compare
9b09b63
to
b057b9f
Compare
This regressed the build time of a large app by about 3.4% (203s to 196s for a complete build), though it is arguably a correctness and compatibility issue with other bundlers. |
{ | ||
fileName: 'package.json', | ||
aboveFilePath: path.join( | ||
rootDir, | ||
'node_modules', | ||
'side-effects-false', | ||
'src', | ||
'index.js', | ||
), | ||
}, |
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.
@devongovett Does aboveFilePath
also stop the watching in parent folder after encountering node_modules
(like loadConfig
does)? Or is this fine?
Hmm that's unfortunate. |
Closes #7908.
This heuristic is enough to solve the example in #7908, but it wouldn't hold in the case that the package.json defines a main asUpdated to handle this case."./in/some/nested-package/index.js"
where"./in/some/nested-package/package.json"
also exists.Test Plan: Added an integration test.