MCPcopy Index your code
hub / github.com/getsentry/sentry-javascript / setup

Function setup

packages/nuxt/src/module.ts:32–243  ·  view source on GitHub ↗
(moduleOptionsParam, nuxt)

Source from the content-addressed store, hash-verified

30 },
31 defaults: {},
32 async setup(moduleOptionsParam, nuxt) {
33 if (moduleOptionsParam?.enabled === false) {
34 return;
35 }
36
37 const moduleOptions = {
38 ...moduleOptionsParam,
39 autoInjectServerSentry: moduleOptionsParam.autoInjectServerSentry,
40 experimental_entrypointWrappedFunctions: moduleOptionsParam.experimental_entrypointWrappedFunctions || [
41 'default',
42 'handler',
43 'server',
44 ],
45 };
46
47 const moduleDirResolver = createResolver(import.meta.url);
48 const buildDirResolver = createResolver(nuxt.options.buildDir);
49
50 const clientConfigFile = await findDefaultSdkInitFile('client', nuxt, moduleOptions);
51
52 if (clientConfigFile) {
53 // Inject the client-side Sentry config file with a side effect import
54 addPluginTemplate({
55 mode: 'client',
56 filename: 'sentry-client-config.mjs',
57 order: 0,
58
59 // Dynamic import of config file to wrap it within a Nuxt context (here: defineNuxtPlugin)
60 // Makes it possible to call useRuntimeConfig() in the user-defined sentry config file
61 getContents: () => `
62 import { defineNuxtPlugin } from "#imports";
63
64 export default defineNuxtPlugin({
65 name: 'sentry-client-config',
66 async setup() {
67 await import("${buildDirResolver.resolve(`/${clientConfigFile}`)}")
68 }
69 });`,
70 });
71
72 // Add the plugin which loads client integrations etc. -
73 // this must run after the sentry-client-config plugin has run, and the client is initialized!
74 addPlugin({
75 src: moduleDirResolver.resolve('./runtime/plugins/sentry.client'),
76 mode: 'client',
77 order: 1,
78 });
79 }
80
81 const serverConfigFile = await findDefaultSdkInitFile('server', nuxt, moduleOptions);
82 const isNitroV3 = (await getNitroMajorVersion()) >= 3;
83 const nuxtMajor = parseInt((nuxt as unknown as { _version: string })._version?.split('.')[0] ?? '3', 10);
84 const isMinNuxtV4 = nuxtMajor >= 4;
85
86 if (serverConfigFile) {
87 if (isNitroV3) {
88 addServerPlugin(moduleDirResolver.resolve('./runtime/plugins/handler.server'));
89 addServerPlugin(moduleDirResolver.resolve('./runtime/plugins/update-route-name.server'));

Callers

nothing calls this directly

Calls 15

findDefaultSdkInitFileFunction · 0.90
getNitroMajorVersionFunction · 0.90
addMiddlewareImportsFunction · 0.90
setupSourceMapsFunction · 0.90
consoleSandboxFunction · 0.90
addServerConfigToBuildFunction · 0.90
addSentryTopImportFunction · 0.90

Tested by

no test coverage detected