-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
feat(tanstackstart-react): Auto-copy build file to correct folder #19104
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
base: develop
Are you sure you want to change the base?
Conversation
Codecov Results 📊Generated by Codecov Action |
node-overhead report 🧳Note: This is a synthetic benchmark with a minimal express app and does not necessarily reflect the real-world performance impact in an application.
|
| } | ||
|
|
||
| const instrumentationFileName = options?.instrumentationFilePath || 'instrument.server.mjs'; | ||
| const instrumentationSource = path.resolve(process.cwd(), instrumentationFileName); |
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.
Bug: The source instrumentation file path is resolved using process.cwd(), while the destination uses resolvedConfig.root. This will fail when these paths differ, like in monorepos.
Severity: MEDIUM
Suggested Fix
In the configResolved hook, store resolvedConfig.root in a closure-scoped variable. Then, in the closeBundle hook, use this stored variable instead of process.cwd() to resolve the source instrumentation file's path. This ensures both source and destination paths are resolved relative to the same Vite project root.
Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent.
Verify if this is a real issue. If it is, propose a fix; if not, explain why it's not
valid.
Location: packages/tanstackstart-react/src/vite/copyInstrumentationFile.ts#L75
Potential issue: The plugin resolves the destination directory for the instrumentation
file using `resolvedConfig.root` but resolves the source file path using
`process.cwd()`. This inconsistency causes a problem when Vite is run with a custom root
directory or in a monorepo setup, as `process.cwd()` and `resolvedConfig.root` will
differ. In such cases, the plugin will fail to find the `instrument.server.mjs` file at
the expected location (relative to the project root), causing it to be silently omitted
from the final build, defeating the purpose of the plugin.
Did we get this right? 👍 / 👎 to inform future reviews.
Automatically copy
instrument.server.mjsinto the server build output after build. Output directory is auto-detected based on the deployment target (Nitro, Cloudflare, Netlify). We also provideinstrumentationFilePathandserverOutputDiroptions as escape hatches if auto-detection doesn't work.To detect the deployment target we search the vite plugin list for plugins with names containing the deployment target (e.g.
nitro). In the nitro case we then read the target directory fromnitroEnv.build.rollupOptions.output. For netlify and cloudflare we assumedist/server.Limitations:
instrument.server.mjsfiles in the root of the project. This is how we ask users to set it up in the docs and has basically no performance overhead. For other cases users will have to use the override options as it is now, but we could definitely think about extending that.Closes #18665