Skip to content

Commit 79ff8f2

Browse files
authored
fix(nuxt): Delete no longer needed Nitro 'close' hook (#15790)
Due to PR #15710 the Sentry server config is only processed inside the Nitro-part of Nuxt and the server config file is emitted through the Rollup plugin. It is not needed anymore to copy-paste the file manually (this has been the case before as the file was added to the `.nuxt` folder - as it was processed by Nuxt, not Nitro-only). This fixes the "no such file" error [posted in this comment](#13330 (comment)). closes #13330
1 parent 006479c commit 79ff8f2

File tree

1 file changed

+2
-38
lines changed

1 file changed

+2
-38
lines changed

packages/nuxt/src/vite/addServerConfig.ts

Lines changed: 2 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as fs from 'fs';
22
import { createResolver } from '@nuxt/kit';
3-
import { consoleSandbox, logger } from '@sentry/core';
3+
import { logger } from '@sentry/core';
44
import type { Nitro } from 'nitropack';
55
import type { InputPluginOption } from 'rollup';
66
import type { SentryNuxtModuleOptions } from '../common/types';
@@ -21,8 +21,7 @@ const SERVER_CONFIG_FILENAME = 'sentry.server.config';
2121
/**
2222
* 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.
2323
*
24-
* 1. Adding the file as a rollup import, so it is included in the build (automatically transpiles the file).
25-
* 2. Copying the file to the `.output` directory after the build process is finished.
24+
* By adding a Rollup plugin to the Nitro Rollup options, the Sentry server config is transpiled and emitted to the server build.
2625
*/
2726
export function addServerConfigToBuild(
2827
moduleOptions: SentryNuxtModuleOptions,
@@ -39,41 +38,6 @@ export function addServerConfigToBuild(
3938

4039
rollupConfig.plugins.push(injectServerConfigPlugin(nitro, serverConfigFile, moduleOptions.debug));
4140
});
42-
43-
/**
44-
* When the build process is finished, copy the `sentry.server.config` file to the `.output` directory.
45-
* This is necessary because we need to reference this file path in the node --import option.
46-
*/
47-
nitro.hooks.hook('close', async () => {
48-
const buildDirResolver = createResolver(nitro.options.buildDir);
49-
const serverDirResolver = createResolver(nitro.options.output.serverDir);
50-
const source = buildDirResolver.resolve(`dist/server/${SERVER_CONFIG_FILENAME}.mjs`);
51-
const destination = serverDirResolver.resolve(`${SERVER_CONFIG_FILENAME}.mjs`);
52-
53-
try {
54-
await fs.promises.access(source, fs.constants.F_OK);
55-
await fs.promises.copyFile(source, destination);
56-
57-
if (moduleOptions.debug) {
58-
consoleSandbox(() => {
59-
// eslint-disable-next-line no-console
60-
console.log(
61-
`[Sentry] Successfully added the content of the \`${serverConfigFile}\` file to \`${destination}\``,
62-
);
63-
});
64-
}
65-
} catch (error) {
66-
if (moduleOptions.debug) {
67-
consoleSandbox(() => {
68-
// eslint-disable-next-line no-console
69-
console.warn(
70-
`[Sentry] An error occurred when trying to add the \`${serverConfigFile}\` file to the \`.output\` directory`,
71-
error,
72-
);
73-
});
74-
}
75-
}
76-
});
7741
}
7842

7943
/**

0 commit comments

Comments
 (0)