-
Notifications
You must be signed in to change notification settings - Fork 57
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(build-info): fix detection of Remix and Hydrogen sites #5820
fix(build-info): fix detection of Remix and Hydrogen sites #5820
Conversation
This has gotten pretty complex: - Remix sites can either use Vite or the Remix Classic Compiler - These use different config files, different dev and build config, but almost identical npm dependencies (plus `vite` in the Remix Vite case) - Hydrogen (v2) uses Remix and, as of a few months ago, it supports Remix Vite in addition to the Remix Classic Compiler (it only supported this previously) - Netlify's Remix packages were renamed in late 2023, but the Remix detection code only listed the old names - Luckily, this still happened to work because it also listed the right config file, but only for Remix Classic Compiler sites - However this means that in the Remix Vite case we were failing to detect Remix. Sites were categorized as Vite instead. - The `remix` package itself was renamed to `@remix-run/dev`, `@remix-run/serve`, etc. in 2023. We hadn't updated this here either, which exarcerbated the above issues.
7a4dfbb
to
ab8c8f3
Compare
const viteDetection = await this.detectConfigFile(VITE_CONFIG_FILES) | ||
if (viteDetection) { | ||
this.detected = viteDetection | ||
this.dev = VITE_DEV | ||
this.build = VITE_BUILD | ||
return this as DetectedFramework | ||
} | ||
const classicCompilerDetection = await this.detectConfigFile(CLASSIC_COMPILER_CONFIG_FILES) | ||
if (classicCompilerDetection) { | ||
this.detected = classicCompilerDetection | ||
this.dev = CLASSIC_COMPILER_DEV | ||
this.build = CLASSIC_COMPILER_BUILD | ||
return this as DetectedFramework | ||
} |
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.
💡 It just occurred to me that I can simplify this implementation a bit. I can just set
configFiles = [...VITE_CONFIG_FILES, ...CLASSIC_COMPILER_CONFIG_FILES]
in the actual class body
and then simplify here to
const viteDetection = await this.detectConfigFile(VITE_CONFIG_FILES) | |
if (viteDetection) { | |
this.detected = viteDetection | |
this.dev = VITE_DEV | |
this.build = VITE_BUILD | |
return this as DetectedFramework | |
} | |
const classicCompilerDetection = await this.detectConfigFile(CLASSIC_COMPILER_CONFIG_FILES) | |
if (classicCompilerDetection) { | |
this.detected = classicCompilerDetection | |
this.dev = CLASSIC_COMPILER_DEV | |
this.build = CLASSIC_COMPILER_BUILD | |
return this as DetectedFramework | |
} | |
if (VITE_CONFIG_FILES.includes(this.detection.config)) { | |
this.dev = VITE_DEV | |
this.build = VITE_BUILD | |
return this as DetectedFramework | |
} | |
if (CLASSIC_COMPILER_CONFIG_FILES.includes(this.detection.config)) { | |
this.dev = CLASSIC_COMPILER_DEV | |
this.build = CLASSIC_COMPILER_BUILD | |
return this as DetectedFramework | |
} |
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.
This turned out not to be possible because when the "NPM dependency" detection gets "merged" with the "config file detection" it just picks the object with the highest accuracy and throws out the other, so we don't have .config
on the detection object. I could have refactored to fix this, but... meh.
You can't actually call `test()` within a `test.each` callback. I was only doing this because I can't use `test.for` to access the test context because we're on an old version of vitest... but anyway, a manual table test works here.
…tifies-remix-vite-sites-as-vite
…tifies-remix-vite-sites-as-vite
We noticed recently that the framework detection wasn't working correctly for all Remix sites. This leads to poor DX but it also affects our reporting that informs framework usage on the platform.
So, this has gotten pretty complex 😓:
vite
in the Remix Vite case)remix
package itself was renamed to@remix-run/dev
,@remix-run/serve
, etc. in 2023. We hadn't updated this here either, which exarcerbated the above issues.I added test fixtures from real sites for every case I could identify.