feat(nuxt): allow custom configuration files paths in Nuxt module#20650
feat(nuxt): allow custom configuration files paths in Nuxt module#20650victorgarciaesgi wants to merge 16 commits intogetsentry:developfrom
Conversation
|
|
||
| expect(result).toBe(expectedPath); | ||
| expect(resolvePathMock).toHaveBeenCalledWith('~/server-sentry-config.ts'); | ||
| }); |
There was a problem hiding this comment.
Feat PR lacks integration or E2E test coverage
Low Severity
This feat PR only includes unit tests for findDefaultSdkInitFile and a type test. Per project rules, feat PRs need at least one integration or E2E test to verify the full feature works end-to-end (e.g., that a custom config file is correctly picked up and wired through the Nuxt module setup).
Triggered by project rule: PR Review Guidelines for Cursor Bot
Reviewed by Cursor Bugbot for commit b947a37. Configure here.
There was a problem hiding this comment.
This is a Nuxt module related change, I couln't find the need for an integration test
| } | ||
| } catch { | ||
| // Fails silently as the file is optional | ||
| } |
There was a problem hiding this comment.
Custom server config paths skip critical server-side setup
High Severity
When a custom serverConfigFile path is provided that doesn't contain the substring .server.config (e.g. the documented example ~/server-sentry-config.ts), the guard at module.ts line 173 (serverConfigFile?.includes('.server.config')) evaluates to false. This silently skips all critical server-side setup: addServerConfigToBuild, addSentryTopImport, and addDynamicImportEntryFileWrapper. The server SDK will register plugins but never actually load the config file, making autoInjectServerSentry non-functional for custom-named config files.
Additional Locations (1)
Reviewed by Cursor Bugbot for commit 490c666. Configure here.
s1gr1d
left a comment
There was a problem hiding this comment.
Thanks for this contribution!
Just a general question: how does your setup look like? Because in case you are using Nuxt layers, a shared config already works.
| * } | ||
| * ``` | ||
| */ | ||
| clientConfigFile?: string; |
There was a problem hiding this comment.
What do you think about adding clientConfigPath and serverConfigPath?
So you can provide a specific pathname to a folder where the SDK will look for the config.
There was a problem hiding this comment.
Yep that seems better i'll change it 👍
I've not handled the case of a folder path, could a single configRootDir: string work better? That way it works for both client and server
There was a problem hiding this comment.
True, that would be even better. You could call it configDir. The root part is a bit misleading as it's just a simple path for where we can find the config.
There was a problem hiding this comment.
@s1gr1d I implemented the single configRootDir, which is much simpler to use & implement 👍
There was a problem hiding this comment.
Sorry didn't see your comment, renamed it 👌
|
Hey @s1gr1d thanks for the fast response! We're not using layers yet, our structure basically looks like this: app-1/
|
Co-authored-by: Sigrid <32902192+s1gr1d@users.noreply.github.com>
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
There are 3 total unresolved issues (including 2 from previous reviews).
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 207be84. Configure here.
Co-authored-by: Sigrid <32902192+s1gr1d@users.noreply.github.com>
|
Suggestions applied 👌 |
Co-authored-by: Sigrid <32902192+s1gr1d@users.noreply.github.com>
| } | ||
|
|
||
| // As a fallback, also check CWD (left for pure compatibility) | ||
| const cwd = process.cwd(); | ||
| const rootDir = options?.configDir ? await resolvePath(options.configDir, { type: 'dir' }) : process.cwd(); | ||
| for (const relativePath of relativePaths) { | ||
| const fullPath = path.resolve(cwd, relativePath); | ||
| const fullPath = path.resolve(rootDir, relativePath); | ||
| if (fs.existsSync(fullPath)) { |
There was a problem hiding this comment.
Bug: The configDir option is only used as a fallback. If a Sentry config file exists in the project root (a default Nuxt layer), the configDir is silently ignored.
Severity: MEDIUM
Suggested Fix
Prioritize the configDir if it is provided. Before iterating through Nuxt layers, check if options.configDir is set. If it is, search for the configuration file exclusively within that directory. The layer-based search should only be used as a fallback when configDir is not specified.
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/nuxt/src/vite/utils.ts#L59-L65
Potential issue: The logic for finding the Sentry SDK init file prioritizes searching
through all Nuxt layers before considering the `configDir` option. In a standard Nuxt
application, the project root is one of the layers. Consequently, if a
`sentry.client.config.ts` or `sentry.server.config.ts` file is present in the project
root, it will be used, and the path specified in `configDir` will be silently ignored.
This contradicts the documented behavior that `configDir` should replace the default
lookup location, leading to unexpected configuration being loaded. The fallback comment
'As a fallback, also check CWD' confirms this last-resort implementation.


Before submitting a pull request, please take a look at our
Contributing guidelines and verify:
yarn lint) & (yarn test).Context
I work in a big monorepo with 60+ Nuxt apps.
To enable Sentry in all those apps, they use a shared configuration, handled by an internal "proxy" module.
Each app can just install and enable this module to share the same common configuration.
The problem is: with the official Sentry module, each app would have to declare its own:
sentry.client.config.tssentry.server.config.tsWhich isn't very convenient when we have 60+ apps to enable.
Basically in the "proxy" module, I wanted to do this:
Result
This PR adds
configDiroption to the Nuxt module, allowing more flexible configuration and avoid creating asentry.**.config.tsfor each app 👌The module can now search in a custom directory path instead of the project root path.
I'm successfully running this change as a
pnpm patchon my monorepo so I wanted to contribute it.