Skip to content
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

feat(nuxt): Add server config to root folder #13583

Merged
merged 8 commits into from
Sep 9, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/nuxt/src/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export default defineNuxtModule<ModuleOptions>({
if (moduleOptions.debug) {
// eslint-disable-next-line no-console
console.log(
`[Sentry] Using your ${serverConfigFile} file for the server-side Sentry configuration. In case you have a \`public/instrument.server\` file, the \`public/instrument.server\` file will be ignored. Make sure the file path in your node \`--import\` option matches your Sentry server config file.`,
`[Sentry] Using your \`${serverConfigFile}\` file for the server-side Sentry configuration. In case you have a \`public/instrument.server\` file, the \`public/instrument.server\` file will be ignored. Make sure the file path in your node \`--import\` option matches the Sentry server config file in your \`.output\` folder and has a \`.mjs\` extension.`,
andreiborza marked this conversation as resolved.
Show resolved Hide resolved
);
}

Expand Down
16 changes: 9 additions & 7 deletions packages/nuxt/src/vite/addServerConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import type { Nuxt } from '@nuxt/schema';
import type { SentryNuxtModuleOptions } from '../common/types';

/**
* Adds the `server.config.ts` file as `instrument-sentry.mjs` to the `.output` directory to be able to reference this file in the node --import option.
* Adds the `sentry.server.config.ts` file as `sentry.server.config.mjs` to the `.output` directory to be able to reference this file in the node --import option.
*
* 1. Adding the file as a rollup import, so it is included in the build (automatically transpiles the file).
* 2. Copying the file to the `.output` directory after the build process is finished.
Expand All @@ -20,8 +20,8 @@ export function addServerConfigToBuild(
typeof viteInlineConfig?.build?.rollupOptions?.input === 'object' &&
'server' in viteInlineConfig.build.rollupOptions.input
) {
// Create a rollup entry for the server config to add it as `instrument-sentry.mjs` to the build
(viteInlineConfig.build.rollupOptions.input as { [entryName: string]: string })['instrument-sentry'] =
// Create a rollup entry for the server config to add it as `sentry.server.config.mjs` to the build
(viteInlineConfig.build.rollupOptions.input as { [entryName: string]: string })['sentry.server.config'] =
createResolver(nuxt.options.srcDir).resolve(`/${serverConfigFile}`);
}

Expand All @@ -30,22 +30,24 @@ export function addServerConfigToBuild(
* This is necessary because we need to reference this file path in the node --import option.
*/
nuxt.hook('close', async () => {
const source = path.resolve('.nuxt/dist/server/instrument-sentry.mjs');
const destination = path.resolve('.output/server/instrument-sentry.mjs');
const source = path.resolve('.nuxt/dist/server/sentry.server.config.mjs');
const destination = path.resolve('.output/server/sentry.server.config.mjs');

try {
await fs.promises.access(source, fs.constants.F_OK);
await fs.promises.copyFile(source, destination);

if (moduleOptions.debug) {
// eslint-disable-next-line no-console
console.log(`[Sentry] Successfully added the content of the ${serverConfigFile} file to \`${destination}\``);
console.log(
`[Sentry] Successfully added the content of the \`${serverConfigFile}\` file to \`${destination}\``,
);
}
} catch (error) {
if (moduleOptions.debug) {
// eslint-disable-next-line no-console
console.warn(
`[Sentry] An error occurred when trying to add the ${serverConfigFile} file to the \`.output\` directory`,
`[Sentry] An error occurred when trying to add the \`${serverConfigFile}\` file to the \`.output\` directory`,
error,
);
}
Expand Down
Loading