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 vite dep optimizer #1876
base: main
Are you sure you want to change the base?
fix vite dep optimizer #1876
Conversation
495565b
to
e5c7c9e
Compare
This is how things used to work. Doing it correctly requires more than just links to the rewritten packages, in general it requires you to rewrite the entire node_modules graph in order to make every package see all the correct dependencies. And I don't think it's necessary. I think that from the perspective of the rewritten-app, the rewritten-packages don't appear to be inside node_modules. But when we stop rewriting the app, they will. |
The problem is that vite needs a bare import and the importer cannot be in node modules. What we are currently doing for resolving rewritten-packages is doing a rehome inside the rewritten-packages, onto moved-target.js https://github.com/embroider-build/embroider/blob/main/packages/core/src/module-resolver.ts#L954 And here is how vite checks if it should optimise:
When we are doing a rehome, the importer is in node_modules... So rhat doesn't work https://github.com/vitejs/vite/blob/6c323d5b3ab3cdf81d21bbe965ed3c36aa7f0589/packages/vite/src/node/plugins/resolve.ts#L868 So it's not a problem of rewritten-app. |
6550053
to
41ac14e
Compare
return resolution; | ||
case 'ignored': | ||
case 'not_found': |
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.
ignored should fallback resolve
@@ -25,7 +25,11 @@ export default class Package { | |||
|
|||
@Memoize() | |||
protected get internalPackageJSON() { | |||
return JSON.parse(readFileSync(join(this.root, 'package.json'), 'utf8')); | |||
try { | |||
return JSON.parse(readFileSync(join(this.root, 'package.json'), 'utf8')); |
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.
workaround for fromFile pointing at /app/tests/package.json and vite/deps
c6e0aa3
to
a6a07a4
Compare
8bb7cd9
to
04cf95f
Compare
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 just discussed this on the Embroider Triage meeting with @patricklx and I'm going to do my best to summarise the situation here:
Firstly we started to spec out a way to test if a dependency was optimised correctly in the office hours last week. A good first draft of that work can be seen in #1880 where we run vite in dev mode and try to "audit" the app across HTTP. This will allow us to make sure that the dependencies we want to check are coming from the right place (i.e. from the .vite/deps folder)
This work is blocked on the refactor that myself and @ef4 are pairing on to allow audits to work across HTTP (and async) which hopefully will land this week.
Once the audit refactor lands we will make sure to provide a suite of tests that show the problems that @patricklx is identifying in this PR (and Discord discussions), we can then check those tests against other work that is going on (e.g. #1779 ) to make sure that they are still failing and we can fix accordingly 👍
0ca8071
to
ee59d64
Compare
773eb1d
to
1a39b4c
Compare
5473296
to
eaaf176
Compare
…-babel-launcher Fix pre support in portable babel launcher
9fc19d3
to
dddb59a
Compare
8072d97
to
503dcd1
Compare
503dcd1
to
817eb36
Compare
tests: https://github.com/embroider-build/embroider/pull/1876/files#diff-3e325354530b11c4e6b3ab941d93a8fe2ceb26087f9c13856c9d8684364a3fb3R62
dep optimizer has multiple phases
This is the order
Currently this is broken because of 2 things. app is in rewritten-app. It's actually easy to fix by changing to importer to the original app. Only needed when resolving bare imports.
The more difficult one is rewritten-packages. They must be node resolvable from original app. They are not currently.
I suggest to create a link from
@embroider/rewritten-packages
to the one inside . embroider and rewrite specifiers accordingly.It currently looks like it's working, because the initial scan detects the deps. But any new dep added later will not be optimized.
fixes: