@sentry/nuxt 11.0.0-beta.1 → 11.0.0-rc.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/cjs/common/devMode.js +16 -0
- package/build/cjs/common/devMode.js.map +1 -1
- package/build/cjs/module.js +32 -48
- package/build/cjs/module.js.map +1 -1
- package/build/cjs/server/sdk.js +15 -0
- package/build/cjs/server/sdk.js.map +1 -1
- package/build/cjs/vite/addServerConfig.js +81 -30
- package/build/cjs/vite/addServerConfig.js.map +1 -1
- package/build/cjs/vite/middlewareConfig.js +7 -6
- package/build/cjs/vite/middlewareConfig.js.map +1 -1
- package/build/cjs/vite/orchestrion.js +2 -1
- package/build/cjs/vite/orchestrion.js.map +1 -1
- package/build/cjs/vite/utils.js +15 -9
- package/build/cjs/vite/utils.js.map +1 -1
- package/build/esm/common/devMode.js +12 -1
- package/build/esm/common/devMode.js.map +1 -1
- package/build/esm/module.js +34 -50
- package/build/esm/module.js.map +1 -1
- package/build/esm/package.json +1 -1
- package/build/esm/server/sdk.js +17 -2
- package/build/esm/server/sdk.js.map +1 -1
- package/build/esm/vite/addServerConfig.js +82 -31
- package/build/esm/vite/addServerConfig.js.map +1 -1
- package/build/esm/vite/middlewareConfig.js +7 -6
- package/build/esm/vite/middlewareConfig.js.map +1 -1
- package/build/esm/vite/orchestrion.js +2 -1
- package/build/esm/vite/orchestrion.js.map +1 -1
- package/build/esm/vite/utils.js +15 -9
- package/build/esm/vite/utils.js.map +1 -1
- package/build/module/common/devMode.d.ts +12 -2
- package/build/module/common/types.d.ts +7 -0
- package/build/module/module.json +1 -1
- package/build/module/module.mjs +133 -89
- package/build/module/runtime/utils/instrumentDatabase.js +26 -23
- package/build/module/vite/addServerConfig.d.ts +10 -8
- package/build/module/vite/middlewareConfig.d.ts +2 -1
- package/build/module/vite/utils.d.ts +11 -3
- package/build/types/common/devMode.d.ts +12 -2
- package/build/types/common/devMode.d.ts.map +1 -1
- package/build/types/common/types.d.ts +7 -0
- package/build/types/common/types.d.ts.map +1 -1
- package/build/types/index.types.d.ts +1 -0
- package/build/types/index.types.d.ts.map +1 -1
- package/build/types/module.d.ts.map +1 -1
- package/build/types/runtime/utils/instrumentDatabase.d.ts.map +1 -1
- package/build/types/server/sdk.d.ts.map +1 -1
- package/build/types/vite/addServerConfig.d.ts +10 -8
- package/build/types/vite/addServerConfig.d.ts.map +1 -1
- package/build/types/vite/middlewareConfig.d.ts +2 -1
- package/build/types/vite/middlewareConfig.d.ts.map +1 -1
- package/build/types/vite/orchestrion.d.ts.map +1 -1
- package/build/types/vite/utils.d.ts +11 -3
- package/build/types/vite/utils.d.ts.map +1 -1
- package/package.json +10 -10
|
@@ -3,10 +3,26 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
3
3
|
const core = require('@sentry/core');
|
|
4
4
|
|
|
5
5
|
const NUXT_DEV_MODE_FLAG = "__SENTRY_NUXT_DEV_MODE__";
|
|
6
|
+
const NUXT_PRERENDER_FLAG = "__SENTRY_NUXT_PRERENDER__";
|
|
7
|
+
const NUXT_SERVER_INITIALIZED_FLAG = "__SENTRY_NUXT_SERVER_INITIALIZED__";
|
|
6
8
|
function isNuxtDevRuntime() {
|
|
7
9
|
return NUXT_DEV_MODE_FLAG in core.GLOBAL_OBJ && core.GLOBAL_OBJ[NUXT_DEV_MODE_FLAG] === true;
|
|
8
10
|
}
|
|
11
|
+
function isNuxtPrerenderRuntime() {
|
|
12
|
+
return NUXT_PRERENDER_FLAG in core.GLOBAL_OBJ && core.GLOBAL_OBJ[NUXT_PRERENDER_FLAG] === true;
|
|
13
|
+
}
|
|
14
|
+
function isNuxtServerInitialized() {
|
|
15
|
+
return NUXT_SERVER_INITIALIZED_FLAG in core.GLOBAL_OBJ && core.GLOBAL_OBJ[NUXT_SERVER_INITIALIZED_FLAG] === true;
|
|
16
|
+
}
|
|
17
|
+
function markNuxtServerInitialized() {
|
|
18
|
+
core.GLOBAL_OBJ[NUXT_SERVER_INITIALIZED_FLAG] = true;
|
|
19
|
+
}
|
|
9
20
|
|
|
10
21
|
exports.NUXT_DEV_MODE_FLAG = NUXT_DEV_MODE_FLAG;
|
|
22
|
+
exports.NUXT_PRERENDER_FLAG = NUXT_PRERENDER_FLAG;
|
|
23
|
+
exports.NUXT_SERVER_INITIALIZED_FLAG = NUXT_SERVER_INITIALIZED_FLAG;
|
|
11
24
|
exports.isNuxtDevRuntime = isNuxtDevRuntime;
|
|
25
|
+
exports.isNuxtPrerenderRuntime = isNuxtPrerenderRuntime;
|
|
26
|
+
exports.isNuxtServerInitialized = isNuxtServerInitialized;
|
|
27
|
+
exports.markNuxtServerInitialized = markNuxtServerInitialized;
|
|
12
28
|
//# sourceMappingURL=devMode.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"devMode.js","sources":["../../../src/common/devMode.ts"],"sourcesContent":["import { GLOBAL_OBJ } from '@sentry/core';\n\n/** Global flag set by the generated
|
|
1
|
+
{"version":3,"file":"devMode.js","sources":["../../../src/common/devMode.ts"],"sourcesContent":["import { GLOBAL_OBJ } from '@sentry/core';\n\n/** Global flag set by the generated runtime-flags module before the Sentry server config evaluates. */\nexport const NUXT_DEV_MODE_FLAG = '__SENTRY_NUXT_DEV_MODE__';\n\n/** Global flag set by the generated runtime-flags module during a prerender build. */\nexport const NUXT_PRERENDER_FLAG = '__SENTRY_NUXT_PRERENDER__';\n\n/** Global flag set by the Nuxt server SDK after a successful `init`, to guard against a second init. */\nexport const NUXT_SERVER_INITIALIZED_FLAG = '__SENTRY_NUXT_SERVER_INITIALIZED__';\n\n/** Whether the server runs in `nuxt dev`. */\nexport function isNuxtDevRuntime(): boolean {\n return NUXT_DEV_MODE_FLAG in GLOBAL_OBJ && GLOBAL_OBJ[NUXT_DEV_MODE_FLAG] === true;\n}\n\n/** Whether the server bundle is executed by the Nitro prerenderer at build time. */\nexport function isNuxtPrerenderRuntime(): boolean {\n return NUXT_PRERENDER_FLAG in GLOBAL_OBJ && GLOBAL_OBJ[NUXT_PRERENDER_FLAG] === true;\n}\n\n/** Whether a Nuxt server SDK `init` already ran in this process. */\nexport function isNuxtServerInitialized(): boolean {\n return NUXT_SERVER_INITIALIZED_FLAG in GLOBAL_OBJ && GLOBAL_OBJ[NUXT_SERVER_INITIALIZED_FLAG] === true;\n}\n\n/** Records that the Nuxt server SDK initialized in this process. */\nexport function markNuxtServerInitialized(): void {\n (GLOBAL_OBJ as typeof GLOBAL_OBJ & { [NUXT_SERVER_INITIALIZED_FLAG]?: boolean })[NUXT_SERVER_INITIALIZED_FLAG] = true;\n}\n"],"names":["GLOBAL_OBJ"],"mappings":";;;;AAGO,MAAM,kBAAA,GAAqB;AAG3B,MAAM,mBAAA,GAAsB;AAG5B,MAAM,4BAAA,GAA+B;AAGrC,SAAS,gBAAA,GAA4B;AAC1C,EAAA,OAAO,kBAAA,IAAsBA,eAAA,IAAcA,eAAA,CAAW,kBAAkB,CAAA,KAAM,IAAA;AAChF;AAGO,SAAS,sBAAA,GAAkC;AAChD,EAAA,OAAO,mBAAA,IAAuBA,eAAA,IAAcA,eAAA,CAAW,mBAAmB,CAAA,KAAM,IAAA;AAClF;AAGO,SAAS,uBAAA,GAAmC;AACjD,EAAA,OAAO,4BAAA,IAAgCA,eAAA,IAAcA,eAAA,CAAW,4BAA4B,CAAA,KAAM,IAAA;AACpG;AAGO,SAAS,yBAAA,GAAkC;AAChD,EAACA,eAAA,CAAgF,4BAA4B,CAAA,GAAI,IAAA;AACnH;;;;;;;;;;"}
|
package/build/cjs/module.js
CHANGED
|
@@ -25,7 +25,9 @@ const module$1 = kit.defineNuxtModule({
|
|
|
25
25
|
}
|
|
26
26
|
const moduleOptions = {
|
|
27
27
|
...moduleOptionsParam,
|
|
28
|
+
// oxlint-disable-next-line typescript/no-deprecated -- supported until removal
|
|
28
29
|
autoInjectServerSentry: moduleOptionsParam.autoInjectServerSentry,
|
|
30
|
+
// oxlint-disable-next-line typescript/no-deprecated -- supported until removal
|
|
29
31
|
experimental_entrypointWrappedFunctions: moduleOptionsParam.experimental_entrypointWrappedFunctions || [
|
|
30
32
|
"default",
|
|
31
33
|
"handler",
|
|
@@ -59,11 +61,15 @@ const module$1 = kit.defineNuxtModule({
|
|
|
59
61
|
});
|
|
60
62
|
}
|
|
61
63
|
const serverConfigFile = await utils.findDefaultSdkInitFile("server", nuxt, moduleOptions);
|
|
62
|
-
const isNitroV3 = await utils.getNitroMajorVersion() >= 3;
|
|
64
|
+
const isNitroV3 = await utils.getNitroMajorVersion(nuxt.options.rootDir) >= 3;
|
|
63
65
|
const nuxtMajor = parseInt(nuxt._version?.split(".")[0] ?? "3", 10);
|
|
64
66
|
const isMinNuxtV4 = nuxtMajor >= 4;
|
|
65
67
|
orchestrion.setupOrchestrion(nuxt, !!serverConfigFile, moduleOptions.buildTimeInstrumentation);
|
|
68
|
+
const usesDeprecatedInjectMode = moduleOptions.autoInjectServerSentry === "top-level-import" || moduleOptions.autoInjectServerSentry === "experimental_dynamic-import";
|
|
66
69
|
if (serverConfigFile) {
|
|
70
|
+
if (!usesDeprecatedInjectMode) {
|
|
71
|
+
addServerConfig.addServerConfigPlugin(nuxt, serverConfigFile, !isNitroV3);
|
|
72
|
+
}
|
|
67
73
|
if (isNitroV3) {
|
|
68
74
|
kit.addServerPlugin(moduleDirResolver.resolve("./runtime/plugins/handler.server"));
|
|
69
75
|
kit.addServerPlugin(moduleDirResolver.resolve("./runtime/plugins/update-route-name.server"));
|
|
@@ -80,9 +86,6 @@ const module$1 = kit.defineNuxtModule({
|
|
|
80
86
|
middlewareConfig.addMiddlewareImports();
|
|
81
87
|
storageConfig.addStorageInstrumentation(nuxt, !isNitroV3);
|
|
82
88
|
databaseConfig.addDatabaseInstrumentation(nuxt.options.nitro, !isNitroV3, moduleOptions);
|
|
83
|
-
if (isNitroV3) {
|
|
84
|
-
addServerConfig.addDevServerConfigFile(nuxt, serverConfigFile);
|
|
85
|
-
}
|
|
86
89
|
}
|
|
87
90
|
if (clientConfigFile || serverConfigFile) {
|
|
88
91
|
sourceMaps.setupSourceMaps(moduleOptions, nuxt, kit.addVitePlugin);
|
|
@@ -126,56 +129,37 @@ const module$1 = kit.defineNuxtModule({
|
|
|
126
129
|
return;
|
|
127
130
|
}
|
|
128
131
|
if (serverConfigFile) {
|
|
129
|
-
middlewareConfig.addMiddlewareInstrumentation(nitro);
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
if (serverDir.includes(".netlify") || !!process.env.NETLIFY) {
|
|
133
|
-
console.warn(
|
|
134
|
-
"[Sentry] Warning: The Sentry SDK detected a Netlify build. Server-side support for the Sentry Nuxt SDK on Netlify is currently unreliable due to technical limitations of serverless functions. Traces are not collected, and errors may occasionally not be reported. For more information on setting up Sentry on the Nuxt server-side, please refer to the documentation: https://docs.sentry.io/platforms/javascript/guides/nuxt/install/"
|
|
135
|
-
);
|
|
136
|
-
}
|
|
137
|
-
if (serverDir.includes(".vercel") || !!process.env.VERCEL) {
|
|
138
|
-
console.warn(
|
|
139
|
-
"[Sentry] Warning: The Sentry SDK detected a Vercel build. The Sentry Nuxt SDK currently does not support tracing on Vercel. For more information on setting up Sentry on the Nuxt server-side, please refer to the documentation: https://docs.sentry.io/platforms/javascript/guides/nuxt/install/"
|
|
140
|
-
);
|
|
141
|
-
}
|
|
142
|
-
});
|
|
143
|
-
if (moduleOptions.autoInjectServerSentry !== "experimental_dynamic-import") {
|
|
144
|
-
if (!(isNitroV3 && nitro.options.dev)) {
|
|
145
|
-
addServerConfig.addServerConfigToBuild(moduleOptions, nitro, serverConfigFile);
|
|
146
|
-
}
|
|
132
|
+
middlewareConfig.addMiddlewareInstrumentation(nitro, isNitroV3);
|
|
133
|
+
if (!usesDeprecatedInjectMode) {
|
|
134
|
+
addServerConfig.addServerConfigShimWithWarning(nitro);
|
|
147
135
|
if (moduleOptions.debug) {
|
|
148
|
-
const serverDirResolver = kit.createResolver(nitro.options.output.serverDir);
|
|
149
|
-
const serverConfigPath = serverDirResolver.resolve("sentry.server.config.mjs");
|
|
150
|
-
const serverConfigRelativePath = utils.toImportSpecifier(nitro.options.rootDir, serverConfigPath);
|
|
151
|
-
const devConfigRelativePath = isNitroV3 ? utils.toImportSpecifier(nuxt.options.rootDir, path.join(nuxt.options.buildDir, addServerConfig.DEV_SERVER_CONFIG_PATH)) : serverConfigRelativePath;
|
|
152
136
|
core.consoleSandbox(() => {
|
|
153
137
|
console.log(
|
|
154
|
-
`[Sentry]
|
|
138
|
+
`[Sentry] Bundled \`${serverConfigFile}\` into the Nitro server build. The SDK initializes itself at server startup \u2014 no \`node --import\` preload needed.`
|
|
155
139
|
);
|
|
156
|
-
if (nitro.options.dev) {
|
|
157
|
-
console.log(
|
|
158
|
-
`[Sentry] During development, preload Sentry with the NODE_OPTIONS environment variable: \`NODE_OPTIONS='--import ${devConfigRelativePath}' nuxt dev\`. The file is generated in the build directory (usually '.nuxt'). If you delete the build directory, run \`nuxt prepare\` to regenerate it.`
|
|
159
|
-
);
|
|
160
|
-
} else {
|
|
161
|
-
console.log(
|
|
162
|
-
`[Sentry] When running your built application, preload Sentry via a command-line flag (\`node --import ${serverConfigRelativePath} [...]\`) or via an environment variable (\`NODE_OPTIONS='--import ${serverConfigRelativePath}' node [...]\`).`
|
|
163
|
-
);
|
|
164
|
-
}
|
|
165
140
|
});
|
|
166
141
|
}
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
if (moduleOptions.
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
142
|
+
} else {
|
|
143
|
+
core.consoleSandbox(() => {
|
|
144
|
+
console.warn(
|
|
145
|
+
`[Sentry] \`autoInjectServerSentry: '${moduleOptions.autoInjectServerSentry}'\` is deprecated and will be removed in a future major version. The Sentry server config is bundled into the Nitro server build by default now. Remove the option to use the default behavior.`
|
|
146
|
+
);
|
|
147
|
+
});
|
|
148
|
+
if (moduleOptions.autoInjectServerSentry === "top-level-import") {
|
|
149
|
+
if (!(isNitroV3 && nitro.options.dev)) {
|
|
150
|
+
addServerConfig.addServerConfigToBuild(moduleOptions, nitro, serverConfigFile);
|
|
151
|
+
}
|
|
152
|
+
addServerConfig.addSentryTopImport(moduleOptions, nitro);
|
|
153
|
+
}
|
|
154
|
+
if (moduleOptions.autoInjectServerSentry === "experimental_dynamic-import") {
|
|
155
|
+
addServerConfig.addDynamicImportEntryFileWrapper(nitro, serverConfigFile, moduleOptions);
|
|
156
|
+
if (moduleOptions.debug) {
|
|
157
|
+
core.consoleSandbox(() => {
|
|
158
|
+
console.log(
|
|
159
|
+
"[Sentry] Wrapping the server entry file with a dynamic `import()`, so Sentry can be preloaded before the server initializes."
|
|
160
|
+
);
|
|
161
|
+
});
|
|
162
|
+
}
|
|
179
163
|
}
|
|
180
164
|
}
|
|
181
165
|
}
|
package/build/cjs/module.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"module.js","sources":["../../src/module.ts"],"sourcesContent":["import {\n addPlugin,\n addPluginTemplate,\n addServerPlugin,\n addTemplate,\n addVitePlugin,\n createResolver,\n defineNuxtModule,\n} from '@nuxt/kit';\n// Needed to make TS evaluate the augmentation of Nitro types (https://github.com/nuxt/nuxt/pull/34039)\nimport type {} from '@nuxt/nitro-server';\n\nimport { consoleSandbox } from '@sentry/core';\nimport * as path from 'path';\nimport type { SentryNuxtModuleOptions } from './common/types';\nimport {\n addDevServerConfigFile,\n addDynamicImportEntryFileWrapper,\n addSentryTopImport,\n addServerConfigToBuild,\n DEV_SERVER_CONFIG_PATH,\n} from './vite/addServerConfig';\nimport { addDatabaseInstrumentation } from './vite/databaseConfig';\nimport { addMiddlewareImports, addMiddlewareInstrumentation } from './vite/middlewareConfig';\nimport { setupOrchestrion } from './vite/orchestrion';\nimport { setupSourceMaps } from './vite/sourceMaps';\nimport { addStorageInstrumentation } from './vite/storageConfig';\nimport {\n addOTelCommonJSImportAlias,\n findDefaultSdkInitFile,\n getNitroMajorVersion,\n toImportSpecifier,\n} from './vite/utils';\n\nexport type ModuleOptions = SentryNuxtModuleOptions;\ntype NuxtPageSubset = { file?: string; path: string };\n\nexport default defineNuxtModule<ModuleOptions>({\n meta: {\n name: '@sentry/nuxt/module',\n configKey: 'sentry',\n compatibility: {\n nuxt: '>=3.7.0',\n },\n },\n defaults: {},\n async setup(moduleOptionsParam, nuxt) {\n if (moduleOptionsParam?.enabled === false) {\n return;\n }\n\n const moduleOptions = {\n ...moduleOptionsParam,\n autoInjectServerSentry: moduleOptionsParam.autoInjectServerSentry,\n experimental_entrypointWrappedFunctions: moduleOptionsParam.experimental_entrypointWrappedFunctions || [\n 'default',\n 'handler',\n 'server',\n ],\n };\n\n const moduleDirResolver = createResolver(import.meta.url);\n const buildDirResolver = createResolver(nuxt.options.buildDir);\n\n const clientConfigFile = await findDefaultSdkInitFile('client', nuxt, moduleOptions);\n\n if (clientConfigFile) {\n // Inject the client-side Sentry config file with a side effect import\n addPluginTemplate({\n mode: 'client',\n filename: 'sentry-client-config.mjs',\n order: 0,\n\n // Dynamic import of config file to wrap it within a Nuxt context (here: defineNuxtPlugin)\n // Makes it possible to call useRuntimeConfig() in the user-defined sentry config file\n getContents: () => `\n import { defineNuxtPlugin } from \"#imports\";\n\n export default defineNuxtPlugin({\n name: 'sentry-client-config',\n async setup() {\n await import(\"${buildDirResolver.resolve(`/${clientConfigFile}`)}\")\n }\n });`,\n });\n\n // Add the plugin which loads client integrations etc. -\n // this must run after the sentry-client-config plugin has run, and the client is initialized!\n addPlugin({\n src: moduleDirResolver.resolve('./runtime/plugins/sentry.client'),\n mode: 'client',\n order: 1,\n });\n }\n\n const serverConfigFile = await findDefaultSdkInitFile('server', nuxt, moduleOptions);\n const isNitroV3 = (await getNitroMajorVersion()) >= 3;\n const nuxtMajor = parseInt((nuxt as unknown as { _version: string })._version?.split('.')[0] ?? '3', 10);\n const isMinNuxtV4 = nuxtMajor >= 4;\n\n // Orchestrion runs on both the Node path (gated on a server config file) and the Cloudflare path\n // (which has no server config file — the SDK is set up via `sentryCloudflareNitroPlugin`). The\n // Cloudflare detection happens inside, keyed off the resolved Nitro preset.\n setupOrchestrion(nuxt, !!serverConfigFile, moduleOptions.buildTimeInstrumentation);\n\n if (serverConfigFile) {\n if (isNitroV3) {\n addServerPlugin(moduleDirResolver.resolve('./runtime/plugins/handler.server'));\n addServerPlugin(moduleDirResolver.resolve('./runtime/plugins/update-route-name.server'));\n } else {\n addServerPlugin(moduleDirResolver.resolve('./runtime/plugins/handler-legacy.server'));\n addServerPlugin(moduleDirResolver.resolve('./runtime/plugins/update-route-name-legacy.server'));\n }\n\n addServerPlugin(moduleDirResolver.resolve('./runtime/plugins/sentry.server'));\n\n if (isMinNuxtV4) {\n addPlugin({ src: moduleDirResolver.resolve('./runtime/plugins/route-detector.server'), mode: 'server' });\n } else {\n addPlugin({ src: moduleDirResolver.resolve('./runtime/plugins/route-detector-legacy.server'), mode: 'server' });\n }\n\n // Preps the middleware instrumentation module.\n addMiddlewareImports();\n addStorageInstrumentation(nuxt, !isNitroV3);\n addDatabaseInstrumentation(nuxt.options.nitro, !isNitroV3, moduleOptions);\n\n // Outside `nitro:init` so that `nuxt prepare` writes the file before the first `nuxt dev`.\n if (isNitroV3) {\n addDevServerConfigFile(nuxt, serverConfigFile);\n }\n }\n\n if (clientConfigFile || serverConfigFile) {\n setupSourceMaps(moduleOptions, nuxt, addVitePlugin);\n }\n\n addOTelCommonJSImportAlias(nuxt, isNitroV3);\n\n let pagesData: NuxtPageSubset[] = [];\n\n nuxt.hooks.hook('pages:extend', pages => {\n pagesData = pages\n .map(page => ({ file: page.file, path: page.path }))\n .filter(page => {\n // Check for dynamic parameter (e.g., :userId or [userId])\n return page.path.includes(':') || page?.file?.includes('[');\n });\n });\n\n if (isMinNuxtV4) {\n const pagesDataVirtualModuleId = '#sentry/nuxt-pages-data.mjs';\n\n // Vite virtual plugin (for the Vite SSR build, where addPlugin mode:'server' plugins are bundled)\n addVitePlugin({\n name: 'sentry-nuxt-pages-data-virtual',\n resolveId: id => (id === pagesDataVirtualModuleId ? `\\0${pagesDataVirtualModuleId}` : null),\n load: id =>\n id === `\\0${pagesDataVirtualModuleId}` ? `export default ${JSON.stringify(pagesData, null, 2)};` : undefined,\n });\n } else {\n // Nuxt v3: register as a build template (accessible via #build/)\n addTemplate({\n filename: 'sentry--nuxt-pages-data.mjs',\n getContents: () => `export default ${JSON.stringify(pagesData, null, 2)};`,\n });\n }\n\n // Add the sentry config file to the include array\n nuxt.hook('prepare:types', options => {\n const tsConfig = options.tsConfig as { include?: string[] };\n\n if (!tsConfig.include) {\n tsConfig.include = [];\n }\n\n // Add type references for useRuntimeConfig in root files for nuxt v4\n // Should be relative to `root/.nuxt`\n if (clientConfigFile) {\n const relativePath = path.relative(nuxt.options.buildDir, clientConfigFile);\n tsConfig.include.push(relativePath);\n }\n if (serverConfigFile) {\n const relativePath = path.relative(nuxt.options.buildDir, serverConfigFile);\n tsConfig.include.push(relativePath);\n }\n });\n\n nuxt.hooks.hook('nitro:init', nitro => {\n if (nuxt.options?._prepare) {\n return;\n }\n\n if (serverConfigFile) {\n addMiddlewareInstrumentation(nitro);\n\n consoleSandbox(() => {\n const serverDir = nitro.options.output.serverDir;\n\n // Netlify env: https://docs.netlify.com/configure-builds/environment-variables/#build-metadata\n if (serverDir.includes('.netlify') || !!process.env.NETLIFY) {\n // eslint-disable-next-line no-console\n console.warn(\n '[Sentry] Warning: The Sentry SDK detected a Netlify build. Server-side support for the Sentry Nuxt SDK on Netlify is currently unreliable due to technical limitations of serverless functions. Traces are not collected, and errors may occasionally not be reported. For more information on setting up Sentry on the Nuxt server-side, please refer to the documentation: https://docs.sentry.io/platforms/javascript/guides/nuxt/install/',\n );\n }\n\n // Vercel env: https://vercel.com/docs/projects/environment-variables/system-environment-variables#VERCEL\n if (serverDir.includes('.vercel') || !!process.env.VERCEL) {\n // eslint-disable-next-line no-console\n console.warn(\n '[Sentry] Warning: The Sentry SDK detected a Vercel build. The Sentry Nuxt SDK currently does not support tracing on Vercel. For more information on setting up Sentry on the Nuxt server-side, please refer to the documentation: https://docs.sentry.io/platforms/javascript/guides/nuxt/install/',\n );\n }\n });\n\n if (moduleOptions.autoInjectServerSentry !== 'experimental_dynamic-import') {\n // Nitro 3 (in Nuxt 5) is not bundled in dev mode. See `addDevServerConfigFile` for how we add the file now.\n if (!(isNitroV3 && nitro.options.dev)) {\n addServerConfigToBuild(moduleOptions, nitro, serverConfigFile);\n }\n\n if (moduleOptions.debug) {\n const serverDirResolver = createResolver(nitro.options.output.serverDir);\n const serverConfigPath = serverDirResolver.resolve('sentry.server.config.mjs');\n\n // For the default nitro node-preset build output this relative path would be: ./.output/server/sentry.server.config.mjs\n const serverConfigRelativePath = toImportSpecifier(nitro.options.rootDir, serverConfigPath);\n const devConfigRelativePath = isNitroV3\n ? toImportSpecifier(nuxt.options.rootDir, path.join(nuxt.options.buildDir, DEV_SERVER_CONFIG_PATH))\n : serverConfigRelativePath;\n\n consoleSandbox(() => {\n // eslint-disable-next-line no-console\n console.log(\n `[Sentry] Using \\`${serverConfigFile}\\` for server-side Sentry configuration. To activate Sentry on the Nuxt server-side, this file must be preloaded when starting your application. Make sure to add this where you deploy and/or run your application. Read more here: https://docs.sentry.io/platforms/javascript/guides/nuxt/install/.`,\n );\n\n if (nitro.options.dev) {\n // eslint-disable-next-line no-console\n console.log(\n `[Sentry] During development, preload Sentry with the NODE_OPTIONS environment variable: \\`NODE_OPTIONS='--import ${devConfigRelativePath}' nuxt dev\\`. The file is generated in the build directory (usually '.nuxt'). If you delete the build directory, run \\`nuxt prepare\\` to regenerate it.`,\n );\n } else {\n // eslint-disable-next-line no-console\n console.log(\n `[Sentry] When running your built application, preload Sentry via a command-line flag (\\`node --import ${serverConfigRelativePath} [...]\\`) or via an environment variable (\\`NODE_OPTIONS='--import ${serverConfigRelativePath}' node [...]\\`).`,\n );\n }\n });\n }\n }\n\n if (moduleOptions.autoInjectServerSentry === 'top-level-import') {\n addSentryTopImport(moduleOptions, nitro);\n }\n\n if (moduleOptions.autoInjectServerSentry === 'experimental_dynamic-import') {\n addDynamicImportEntryFileWrapper(nitro, serverConfigFile, moduleOptions);\n\n if (moduleOptions.debug) {\n consoleSandbox(() => {\n // eslint-disable-next-line no-console\n console.log(\n '[Sentry] Wrapping the server entry file with a dynamic `import()`, so Sentry can be preloaded before the server initializes.',\n );\n });\n }\n }\n }\n });\n },\n});\n"],"names":["defineNuxtModule","createResolver","findDefaultSdkInitFile","addPluginTemplate","addPlugin","getNitroMajorVersion","setupOrchestrion","addServerPlugin","addMiddlewareImports","addStorageInstrumentation","addDatabaseInstrumentation","addDevServerConfigFile","setupSourceMaps","addVitePlugin","addOTelCommonJSImportAlias","addTemplate","addMiddlewareInstrumentation","consoleSandbox","addServerConfigToBuild","toImportSpecifier","DEV_SERVER_CONFIG_PATH","addSentryTopImport","addDynamicImportEntryFileWrapper"],"mappings":";;;;;;;;;;;;AAqCA,iBAAeA,oBAAA,CAAgC;AAAA,EAC7C,IAAA,EAAM;AAAA,IACJ,IAAA,EAAM,qBAAA;AAAA,IACN,SAAA,EAAW,QAAA;AAAA,IACX,aAAA,EAAe;AAAA,MACb,IAAA,EAAM;AAAA;AACR,GACF;AAAA,EACA,UAAU,EAAC;AAAA,EACX,MAAM,KAAA,CAAM,kBAAA,EAAoB,IAAA,EAAM;AACpC,IAAA,IAAI,kBAAA,EAAoB,YAAY,KAAA,EAAO;AACzC,MAAA;AAAA,IACF;AAEA,IAAA,MAAM,aAAA,GAAgB;AAAA,MACpB,GAAG,kBAAA;AAAA,MACH,wBAAwB,kBAAA,CAAmB,sBAAA;AAAA,MAC3C,uCAAA,EAAyC,mBAAmB,uCAAA,IAA2C;AAAA,QACrG,SAAA;AAAA,QACA,SAAA;AAAA,QACA;AAAA;AACF,KACF;AAEA,IAAA,MAAM,iBAAA,GAAoBC,kBAAA,CAAe,2PAAe,CAAA;AACxD,IAAA,MAAM,gBAAA,GAAmBA,kBA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AQ,GAAA;AAAA,gBACN;AAAA,eACF;AAAA,YACF,CAAC,CAAA;AAAA,UACH;AAAA,QACF;AAAA,MACF;AAAA,IACF,CAAC,CAAA;AAAA,EACH;AACF,CAAC,CAAA;;;;"}
|
|
1
|
+
{"version":3,"file":"module.js","sources":["../../src/module.ts"],"sourcesContent":["import {\n addPlugin,\n addPluginTemplate,\n addServerPlugin,\n addTemplate,\n addVitePlugin,\n createResolver,\n defineNuxtModule,\n} from '@nuxt/kit';\n// Needed to make TS evaluate the augmentation of Nitro types (https://github.com/nuxt/nuxt/pull/34039)\nimport type {} from '@nuxt/nitro-server';\n\nimport { consoleSandbox } from '@sentry/core';\nimport * as path from 'path';\nimport type { SentryNuxtModuleOptions } from './common/types';\nimport {\n addDynamicImportEntryFileWrapper,\n addServerConfigShimWithWarning,\n addSentryTopImport,\n addServerConfigPlugin,\n addServerConfigToBuild,\n} from './vite/addServerConfig';\nimport { addDatabaseInstrumentation } from './vite/databaseConfig';\nimport { addMiddlewareImports, addMiddlewareInstrumentation } from './vite/middlewareConfig';\nimport { setupOrchestrion } from './vite/orchestrion';\nimport { setupSourceMaps } from './vite/sourceMaps';\nimport { addStorageInstrumentation } from './vite/storageConfig';\nimport { addOTelCommonJSImportAlias, findDefaultSdkInitFile, getNitroMajorVersion } from './vite/utils';\n\nexport type ModuleOptions = SentryNuxtModuleOptions;\ntype NuxtPageSubset = { file?: string; path: string };\n\nexport default defineNuxtModule<ModuleOptions>({\n meta: {\n name: '@sentry/nuxt/module',\n configKey: 'sentry',\n compatibility: {\n nuxt: '>=3.7.0',\n },\n },\n defaults: {},\n async setup(moduleOptionsParam, nuxt) {\n if (moduleOptionsParam?.enabled === false) {\n return;\n }\n\n const moduleOptions = {\n ...moduleOptionsParam,\n // oxlint-disable-next-line typescript/no-deprecated -- supported until removal\n autoInjectServerSentry: moduleOptionsParam.autoInjectServerSentry,\n // oxlint-disable-next-line typescript/no-deprecated -- supported until removal\n experimental_entrypointWrappedFunctions: moduleOptionsParam.experimental_entrypointWrappedFunctions || [\n 'default',\n 'handler',\n 'server',\n ],\n };\n\n const moduleDirResolver = createResolver(import.meta.url);\n const buildDirResolver = createResolver(nuxt.options.buildDir);\n\n const clientConfigFile = await findDefaultSdkInitFile('client', nuxt, moduleOptions);\n\n if (clientConfigFile) {\n // Inject the client-side Sentry config file with a side effect import\n addPluginTemplate({\n mode: 'client',\n filename: 'sentry-client-config.mjs',\n order: 0,\n\n // Dynamic import of config file to wrap it within a Nuxt context (here: defineNuxtPlugin)\n // Makes it possible to call useRuntimeConfig() in the user-defined sentry config file\n getContents: () => `\n import { defineNuxtPlugin } from \"#imports\";\n\n export default defineNuxtPlugin({\n name: 'sentry-client-config',\n async setup() {\n await import(\"${buildDirResolver.resolve(`/${clientConfigFile}`)}\")\n }\n });`,\n });\n\n // Add the plugin which loads client integrations etc. -\n // this must run after the sentry-client-config plugin has run, and the client is initialized!\n addPlugin({\n src: moduleDirResolver.resolve('./runtime/plugins/sentry.client'),\n mode: 'client',\n order: 1,\n });\n }\n\n const serverConfigFile = await findDefaultSdkInitFile('server', nuxt, moduleOptions);\n const isNitroV3 = (await getNitroMajorVersion(nuxt.options.rootDir)) >= 3;\n const nuxtMajor = parseInt((nuxt as unknown as { _version: string })._version?.split('.')[0] ?? '3', 10);\n const isMinNuxtV4 = nuxtMajor >= 4;\n\n // Orchestrion runs on both the Node path (gated on a server config file) and the Cloudflare path\n // (which has no server config file — the SDK is set up via `sentryCloudflareNitroPlugin`). The\n // Cloudflare detection happens inside, keyed off the resolved Nitro preset.\n setupOrchestrion(nuxt, !!serverConfigFile, moduleOptions.buildTimeInstrumentation);\n\n // The deprecated inject modes replace the default in-bundle initialization until their removal\n const usesDeprecatedInjectMode =\n moduleOptions.autoInjectServerSentry === 'top-level-import' ||\n moduleOptions.autoInjectServerSentry === 'experimental_dynamic-import';\n\n if (serverConfigFile) {\n if (!usesDeprecatedInjectMode) {\n addServerConfigPlugin(nuxt, serverConfigFile, !isNitroV3);\n }\n\n if (isNitroV3) {\n addServerPlugin(moduleDirResolver.resolve('./runtime/plugins/handler.server'));\n addServerPlugin(moduleDirResolver.resolve('./runtime/plugins/update-route-name.server'));\n } else {\n addServerPlugin(moduleDirResolver.resolve('./runtime/plugins/handler-legacy.server'));\n addServerPlugin(moduleDirResolver.resolve('./runtime/plugins/update-route-name-legacy.server'));\n }\n\n addServerPlugin(moduleDirResolver.resolve('./runtime/plugins/sentry.server'));\n\n if (isMinNuxtV4) {\n addPlugin({ src: moduleDirResolver.resolve('./runtime/plugins/route-detector.server'), mode: 'server' });\n } else {\n addPlugin({ src: moduleDirResolver.resolve('./runtime/plugins/route-detector-legacy.server'), mode: 'server' });\n }\n\n // Preps the middleware instrumentation module.\n addMiddlewareImports();\n addStorageInstrumentation(nuxt, !isNitroV3);\n addDatabaseInstrumentation(nuxt.options.nitro, !isNitroV3, moduleOptions);\n }\n\n if (clientConfigFile || serverConfigFile) {\n setupSourceMaps(moduleOptions, nuxt, addVitePlugin);\n }\n\n addOTelCommonJSImportAlias(nuxt, isNitroV3);\n\n let pagesData: NuxtPageSubset[] = [];\n\n nuxt.hooks.hook('pages:extend', pages => {\n pagesData = pages\n .map(page => ({ file: page.file, path: page.path }))\n .filter(page => {\n // Check for dynamic parameter (e.g., :userId or [userId])\n return page.path.includes(':') || page?.file?.includes('[');\n });\n });\n\n if (isMinNuxtV4) {\n const pagesDataVirtualModuleId = '#sentry/nuxt-pages-data.mjs';\n\n // Vite virtual plugin (for the Vite SSR build, where addPlugin mode:'server' plugins are bundled)\n addVitePlugin({\n name: 'sentry-nuxt-pages-data-virtual',\n resolveId: id => (id === pagesDataVirtualModuleId ? `\\0${pagesDataVirtualModuleId}` : null),\n load: id =>\n id === `\\0${pagesDataVirtualModuleId}` ? `export default ${JSON.stringify(pagesData, null, 2)};` : undefined,\n });\n } else {\n // Nuxt v3: register as a build template (accessible via #build/)\n addTemplate({\n filename: 'sentry--nuxt-pages-data.mjs',\n getContents: () => `export default ${JSON.stringify(pagesData, null, 2)};`,\n });\n }\n\n // Add the sentry config file to the include array\n nuxt.hook('prepare:types', options => {\n const tsConfig = options.tsConfig as { include?: string[] };\n\n if (!tsConfig.include) {\n tsConfig.include = [];\n }\n\n // Add type references for useRuntimeConfig in root files for nuxt v4\n // Should be relative to `root/.nuxt`\n if (clientConfigFile) {\n const relativePath = path.relative(nuxt.options.buildDir, clientConfigFile);\n tsConfig.include.push(relativePath);\n }\n if (serverConfigFile) {\n const relativePath = path.relative(nuxt.options.buildDir, serverConfigFile);\n tsConfig.include.push(relativePath);\n }\n });\n\n nuxt.hooks.hook('nitro:init', nitro => {\n if (nuxt.options?._prepare) {\n return;\n }\n\n if (serverConfigFile) {\n addMiddlewareInstrumentation(nitro, isNitroV3);\n\n if (!usesDeprecatedInjectMode) {\n addServerConfigShimWithWarning(nitro);\n\n if (moduleOptions.debug) {\n consoleSandbox(() => {\n // eslint-disable-next-line no-console\n console.log(\n `[Sentry] Bundled \\`${serverConfigFile}\\` into the Nitro server build. The SDK initializes itself at server startup — no \\`node --import\\` preload needed.`,\n );\n });\n }\n } else {\n consoleSandbox(() => {\n // eslint-disable-next-line no-console\n console.warn(\n `[Sentry] \\`autoInjectServerSentry: '${moduleOptions.autoInjectServerSentry}'\\` is deprecated and will be removed in a future major version. The Sentry server config is bundled into the Nitro server build by default now. Remove the option to use the default behavior.`,\n );\n });\n\n if (moduleOptions.autoInjectServerSentry === 'top-level-import') {\n // Nitro 3 (in Nuxt 5) is not bundled in dev mode, so there is no build to emit into.\n if (!(isNitroV3 && nitro.options.dev)) {\n addServerConfigToBuild(moduleOptions, nitro, serverConfigFile);\n }\n addSentryTopImport(moduleOptions, nitro);\n }\n\n if (moduleOptions.autoInjectServerSentry === 'experimental_dynamic-import') {\n addDynamicImportEntryFileWrapper(nitro, serverConfigFile, moduleOptions);\n\n if (moduleOptions.debug) {\n consoleSandbox(() => {\n // eslint-disable-next-line no-console\n console.log(\n '[Sentry] Wrapping the server entry file with a dynamic `import()`, so Sentry can be preloaded before the server initializes.',\n );\n });\n }\n }\n }\n }\n });\n },\n});\n"],"names":["defineNuxtModule","createResolver","findDefaultSdkInitFile","addPluginTemplate","addPlugin","getNitroMajorVersion","setupOrchestrion","addServerConfigPlugin","addServerPlugin","addMiddlewareImports","addStorageInstrumentation","addDatabaseInstrumentation","setupSourceMaps","addVitePlugin","addOTelCommonJSImportAlias","addTemplate","addMiddlewareInstrumentation","addServerConfigShimWithWarning","consoleSandbox","addServerConfigToBuild","addSentryTopImport","addDynamicImportEntryFileWrapper"],"mappings":";;;;;;;;;;;;AAgCA,iBAAeA,oBAAA,CAAgC;AAAA,EAC7C,IAAA,EAAM;AAAA,IACJ,IAAA,EAAM,qBAAA;AAAA,IACN,SAAA,EAAW,QAAA;AAAA,IACX,aAAA,EAAe;AAAA,MACb,IAAA,EAAM;AAAA;AACR,GACF;AAAA,EACA,UAAU,EAAC;AAAA,EACX,MAAM,KAAA,CAAM,kBAAA,EAAoB,IAAA,EAAM;AACpC,IAAA,IAAI,kBAAA,EAAoB,YAAY,KAAA,EAAO;AACzC,MAAA;AAAA,IACF;AAEA,IAAA,MAAM,aAAA,GAAgB;AAAA,MACpB,GAAG,kBAAA;AAAA;AAAA,MAEH,wBAAwB,kBAAA,CAAmB,sBAAA;AAAA;AAAA,MAE3C,uCAAA,EAAyC,mBAAmB,uCAAA,IAA2C;AAAA,QACrG,SAAA;AAAA,QACA,SAAA;AAAA,QACA;AAAA;AACF,KACF;AAEA,IAAA,MAAM,iBAAA,GAAoBC,kBAAA,CAAe,2PAAe,CAAA;AACxD,IAAA,MAAM,gBAAA,GAAmBA,kBAAA,CAAe,IAAA,CAAK,OAAA,CAAQ,QAAQ,CAAA;AAE7D,IAAA,MAAM,gBAAA,GAAmB,MAAMC,4BAAA,CAAuB,QAAA,EAAU,MAAM,aAAa,CAAA;AAEnF,IAAA,IAAI,gBAAA,EAAkB;AAEpB,MAAAC,qBAAA,CAAkB;AAAA,QAChB,IAAA,EAAM,QAAA;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,EAA+B;AAC1E,YAAAC,gDAAA,CAAiC,KAAA,EAAO,kBAAkB,aAAa,CAAA;AAEvE,YAAA,IAAI,cAAc,KAAA,EAAO;AACvB,cAAAH,mBAAA,CAAe,MAAM;AAEnB,gBAAA,OAAA,CAAQ,GAAA;AAAA,kBACN;AAAA,iBACF;AAAA,cACF,CAAC,CAAA;AAAA,YACH;AAAA,UACF;AAAA,QACF;AAAA,MACF;AAAA,IACF,CAAC,CAAA;AAAA,EACH;AACF,CAAC,CAAA;;;;"}
|
package/build/cjs/server/sdk.js
CHANGED
|
@@ -7,6 +7,18 @@ const debugBuild = require('../common/debug-build.js');
|
|
|
7
7
|
const devMode = require('../common/devMode.js');
|
|
8
8
|
|
|
9
9
|
function init(options) {
|
|
10
|
+
if (devMode.isNuxtPrerenderRuntime()) {
|
|
11
|
+
debugBuild.DEBUG_BUILD && core.debug.log("Detected a Nitro prerender build. Skipping Sentry server initialization.");
|
|
12
|
+
return void 0;
|
|
13
|
+
}
|
|
14
|
+
if (devMode.isNuxtServerInitialized()) {
|
|
15
|
+
core.consoleSandbox(() => {
|
|
16
|
+
console.log(
|
|
17
|
+
"[Sentry] The Sentry server SDK is already initialized, skipping a second initialization. The Sentry server config is bundled into the Nitro server build, so a `node --import` preload of the config file is no longer needed and can be removed."
|
|
18
|
+
);
|
|
19
|
+
});
|
|
20
|
+
return core.getClient();
|
|
21
|
+
}
|
|
10
22
|
const envFallback = devMode.isNuxtDevRuntime() ? core.DEV_ENVIRONMENT : core.DEFAULT_ENVIRONMENT;
|
|
11
23
|
const sentryOptions = {
|
|
12
24
|
environment: options.environment ?? process.env.SENTRY_ENVIRONMENT ?? envFallback,
|
|
@@ -14,6 +26,9 @@ function init(options) {
|
|
|
14
26
|
};
|
|
15
27
|
core.applySdkMetadata(sentryOptions, "nuxt", ["nuxt", "node"]);
|
|
16
28
|
const client = node.init(sentryOptions);
|
|
29
|
+
if (client) {
|
|
30
|
+
devMode.markNuxtServerInitialized();
|
|
31
|
+
}
|
|
17
32
|
core.getGlobalScope().addEventProcessor(lowQualityTransactionsFilter(options));
|
|
18
33
|
core.getGlobalScope().addEventProcessor(clientSourceMapErrorFilter(options));
|
|
19
34
|
return client;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sdk.js","sources":["../../../src/server/sdk.ts"],"sourcesContent":["import * as path from 'node:path';\nimport type { Client, Event, EventProcessor } from '@sentry/core';\nimport {
|
|
1
|
+
{"version":3,"file":"sdk.js","sources":["../../../src/server/sdk.ts"],"sourcesContent":["import * as path from 'node:path';\nimport type { Client, Event, EventProcessor } from '@sentry/core';\nimport {\n applySdkMetadata,\n consoleSandbox,\n debug,\n DEFAULT_ENVIRONMENT,\n DEV_ENVIRONMENT,\n getClient,\n getGlobalScope,\n} from '@sentry/core';\nimport { init as initNode } from '@sentry/node';\nimport { DEBUG_BUILD } from '../common/debug-build';\nimport {\n isNuxtDevRuntime,\n isNuxtPrerenderRuntime,\n isNuxtServerInitialized,\n markNuxtServerInitialized,\n} from '../common/devMode';\nimport type { SentryNuxtServerOptions } from '../common/types';\n\n/**\n * Initializes the server-side of the Nuxt SDK\n *\n * @param options Configuration options for the SDK.\n */\nexport function init(options: SentryNuxtServerOptions): Client | undefined {\n // The prerenderer executes the server bundle (including nitro plugins) at build time (pollutes release health and adds build-time traces)\n if (isNuxtPrerenderRuntime()) {\n // potential follow-up: configurable with `capturePrerenderErrors`\n DEBUG_BUILD && debug.log('Detected a Nitro prerender build. Skipping Sentry server initialization.');\n return undefined;\n }\n\n // Since the server config is bundled into the Nitro build, a `node --import` preload of a config\n // file initializes the SDK a second time. The first init wins so a preload keeps its semantics.\n if (isNuxtServerInitialized()) {\n consoleSandbox(() => {\n // eslint-disable-next-line no-console\n console.log(\n '[Sentry] The Sentry server SDK is already initialized, skipping a second initialization. The Sentry server config is bundled into the Nitro server build, so a `node --import` preload of the config file is no longer needed and can be removed.',\n );\n });\n return getClient();\n }\n\n let isDevBuild = false;\n /*! rollup-include-esm-only */\n isDevBuild = !!import.meta.dev;\n /*! rollup-include-esm-only-end */\n\n // `import.meta.dev` is only substituted when this file itself is bundled; the generated\n // runtime-flags module sets the global flag for the (usual) externalized case.\n const envFallback = isDevBuild || isNuxtDevRuntime() ? DEV_ENVIRONMENT : DEFAULT_ENVIRONMENT;\n\n const sentryOptions = {\n environment: options.environment ?? process.env.SENTRY_ENVIRONMENT ?? envFallback,\n ...options,\n };\n\n applySdkMetadata(sentryOptions, 'nuxt', ['nuxt', 'node']);\n\n const client = initNode(sentryOptions);\n\n if (client) {\n markNuxtServerInitialized();\n }\n\n getGlobalScope().addEventProcessor(lowQualityTransactionsFilter(options));\n getGlobalScope().addEventProcessor(clientSourceMapErrorFilter(options));\n\n return client;\n}\n\n/**\n * Filter out transactions for resource requests which we don't want to send to Sentry\n * for quota reasons.\n *\n * Only exported for testing\n */\nexport function lowQualityTransactionsFilter(options: SentryNuxtServerOptions): EventProcessor {\n return Object.assign(\n (event => {\n if (event.type !== 'transaction' || !event.transaction || isCacheEvent(event)) {\n return event;\n }\n\n // Check if this looks like a parametrized route (contains :param or :param() patterns)\n const hasRouteParameters = /\\/:[^(/\\s]*(\\([^)]*\\))?[^/\\s]*/.test(event.transaction);\n\n if (hasRouteParameters) {\n return event;\n }\n\n // We don't want to send transaction for file requests, so everything ending with a *.someExtension should be filtered out\n // path.extname will return an empty string for normal page requests\n if (path.extname(event.transaction)) {\n options.debug &&\n DEBUG_BUILD &&\n debug.log('NuxtLowQualityTransactionsFilter filtered transaction: ', event.transaction);\n return null;\n }\n return event;\n }) satisfies EventProcessor,\n { id: 'NuxtLowQualityTransactionsFilter' },\n );\n}\n\n/**\n * The browser devtools try to get the source maps, but as client source maps may not be available there is going to be an error (no problem for the application though).\n *\n * Only exported for testing\n */\nexport function clientSourceMapErrorFilter(options: SentryNuxtServerOptions): EventProcessor {\n return Object.assign(\n (event => {\n const errorMsg = event.exception?.values?.[0]?.value;\n if (errorMsg?.match(/^ENOENT: no such file or directory, open '.*\\/_nuxt\\/.*\\.js\\.map'/)) {\n options.debug && DEBUG_BUILD && debug.log('NuxtClientSourceMapErrorFilter filtered error: ', errorMsg);\n return null;\n }\n return event;\n }) satisfies EventProcessor,\n { id: 'NuxtClientSourceMapErrorFilter' },\n );\n}\n\n/**\n * Checks if the event is a cache event.\n */\nfunction isCacheEvent(e: Event): boolean {\n return e.contexts?.trace?.origin === 'auto.cache.nuxt';\n}\n"],"names":["isNuxtPrerenderRuntime","DEBUG_BUILD","debug","isNuxtServerInitialized","consoleSandbox","getClient","isNuxtDevRuntime","DEV_ENVIRONMENT","DEFAULT_ENVIRONMENT","applySdkMetadata","initNode","markNuxtServerInitialized","getGlobalScope"],"mappings":";;;;;;;;AA0BO,SAAS,KAAK,OAAA,EAAsD;AAEzE,EAAA,IAAIA,gCAAuB,EAAG;AAE5B,IAAAC,sBAAA,IAAeC,UAAA,CAAM,IAAI,0EAA0E,CAAA;AACnG,IAAA,OAAO,MAAA;AAAA,EACT;AAIA,EAAA,IAAIC,iCAAwB,EAAG;AAC7B,IAAAC,mBAAA,CAAe,MAAM;AAEnB,MAAA,OAAA,CAAQ,GAAA;AAAA,QACN;AAAA,OACF;AAAA,IACF,CAAC,CAAA;AACD,IAAA,OAAOC,cAAA,EAAU;AAAA,EACnB;AAEiB,EACjB,MAAA,WAAA,GAAAC,wBAAA,EAAA,GAAAC,oBAAA,GAAAC,wBAAA;AACA,EAAA,MAAA,aAAe,GAAA;AAAY,IAC3B,WAAA,EAAA,OAAA,CAAA,WAAA,IAAA,OAAA,CAAA,GAAA,CAAA,kBAAA,IAAA,WAAA;AAIA,IAAA,GAAA;AAEA,GAAA;AAAsB,EAAAC,qBACP,CAAA,aAAQ,EAAA,MAAe,EAAA,CAAA,cAAY,CAAA,CAAA;AAAsB,EAAA,MACnE,MAAA,GAAAC,SAAA,CAAA,aAAA,CAAA;AAAA,EACL,IAAA,MAAA,EAAA;AAEA,IAAAC,iCAAiB,EAAA;AAEjB,EAAA;AAEA,EAA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AAQ;AACR,IAAA,CAAA;AAAO,IAAA,EACT,EAAA,EAAA,gCAAA;AACA,GAAA;AAAO;AACT,qBACM,CAAA,CAAA,EAAA;AAAiC,EACzC,OAAA,CAAA,CAAA,QAAA,EAAA,KAAA,EAAA,MAAA,KAAA,iBAAA;AACF;;;;;;"}
|
|
@@ -1,46 +1,20 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
2
|
|
|
3
3
|
const node_fs = require('node:fs');
|
|
4
|
-
const path
|
|
4
|
+
const path = require('node:path');
|
|
5
5
|
const node_url = require('node:url');
|
|
6
6
|
const kit = require('@nuxt/kit');
|
|
7
7
|
const core = require('@sentry/core');
|
|
8
8
|
const fs = require('fs');
|
|
9
|
-
const path = require('path');
|
|
10
9
|
const devMode = require('../common/devMode.js');
|
|
11
10
|
const utils = require('./utils.js');
|
|
12
11
|
|
|
13
|
-
const DEV_SERVER_CONFIG_PATH = `dev/${utils.SERVER_CONFIG_FILENAME}.mjs`;
|
|
14
|
-
function addDevServerConfigFile(nuxt, serverConfigFile) {
|
|
15
|
-
const configPath = kit.createResolver(nuxt.options.rootDir).resolve(serverConfigFile);
|
|
16
|
-
const importSpecifier = utils.toImportSpecifier(
|
|
17
|
-
nuxt.options.rootDir,
|
|
18
|
-
path.join(nuxt.options.buildDir, DEV_SERVER_CONFIG_PATH)
|
|
19
|
-
);
|
|
20
|
-
const failureMessage = `[Sentry] Could not load \`${path.basename(configPath)}\`, so Sentry is disabled during development. Node loads this file without a build step, so it supports neither path aliases (like #import) nor non-erasable TypeScript syntax (like enums).`;
|
|
21
|
-
kit.addTemplate({
|
|
22
|
-
filename: DEV_SERVER_CONFIG_PATH,
|
|
23
|
-
write: true,
|
|
24
|
-
getContents: () => [
|
|
25
|
-
"// Generated by @sentry/nuxt. Preload it to enable Sentry during development:",
|
|
26
|
-
`// NODE_OPTIONS='--import ${importSpecifier}' nuxt dev`,
|
|
27
|
-
// A static import would hoist above this assignment, and would make a broken config crash the dev server.
|
|
28
|
-
`globalThis.${devMode.NUXT_DEV_MODE_FLAG} = true;`,
|
|
29
|
-
"try {",
|
|
30
|
-
` await import(${JSON.stringify(node_url.pathToFileURL(configPath).href)});`,
|
|
31
|
-
"} catch (error) {",
|
|
32
|
-
` console.warn(${JSON.stringify(failureMessage)}, error);`,
|
|
33
|
-
"}",
|
|
34
|
-
""
|
|
35
|
-
].join("\n")
|
|
36
|
-
});
|
|
37
|
-
}
|
|
38
12
|
const CONFIG_EXTENSIONS = [".ts", ".js", ".mjs", ".cjs", ".mts", ".cts"];
|
|
39
13
|
function isServerConfigFile(sourcePath, resolvedPath) {
|
|
40
14
|
if (sourcePath === resolvedPath) {
|
|
41
15
|
return true;
|
|
42
16
|
}
|
|
43
|
-
const name = path
|
|
17
|
+
const name = path.basename(sourcePath);
|
|
44
18
|
return name === utils.SERVER_CONFIG_FILENAME || CONFIG_EXTENSIONS.some((ext) => name === `${utils.SERVER_CONFIG_FILENAME}${ext}`);
|
|
45
19
|
}
|
|
46
20
|
function addServerConfigToBuild(moduleOptions, nitro, serverConfigFile) {
|
|
@@ -82,6 +56,82 @@ ${data}`;
|
|
|
82
56
|
}
|
|
83
57
|
});
|
|
84
58
|
}
|
|
59
|
+
function addServerConfigPlugin(nuxt, serverConfigFile, isLegacyNitro) {
|
|
60
|
+
const configPath = kit.createResolver(nuxt.options.rootDir).resolve(serverConfigFile);
|
|
61
|
+
const runtimeFlagsTemplate = kit.addTemplate({
|
|
62
|
+
filename: "sentry-runtime-flags.mjs",
|
|
63
|
+
write: true,
|
|
64
|
+
getContents: () => [
|
|
65
|
+
"// Generated by @sentry/nuxt. Sets runtime flags before the Sentry server config evaluates.",
|
|
66
|
+
`globalThis.${devMode.NUXT_DEV_MODE_FLAG} = import.meta.dev === true;`,
|
|
67
|
+
`globalThis.${devMode.NUXT_PRERENDER_FLAG} = import.meta.prerender === true;`,
|
|
68
|
+
""
|
|
69
|
+
].join("\n")
|
|
70
|
+
});
|
|
71
|
+
const configPluginTemplate = kit.addTemplate({
|
|
72
|
+
filename: "sentry-server-config-plugin.mjs",
|
|
73
|
+
write: true,
|
|
74
|
+
getContents: () => `import ${JSON.stringify(runtimeFlagsTemplate.dst)};
|
|
75
|
+
import ${JSON.stringify(configPath)};
|
|
76
|
+
export default () => {};
|
|
77
|
+
`
|
|
78
|
+
});
|
|
79
|
+
kit.addServerPlugin(configPluginTemplate.dst);
|
|
80
|
+
if (isLegacyNitro) {
|
|
81
|
+
nuxt.options.nitro.moduleSideEffects = [
|
|
82
|
+
...nuxt.options.nitro.moduleSideEffects ?? [],
|
|
83
|
+
configPath,
|
|
84
|
+
runtimeFlagsTemplate.dst
|
|
85
|
+
];
|
|
86
|
+
}
|
|
87
|
+
nuxt.hook("nitro:config", (nitroConfig) => {
|
|
88
|
+
if (utils.isCloudflarePreset(nitroConfig.preset)) {
|
|
89
|
+
nitroConfig.plugins = (nitroConfig.plugins ?? []).filter((plugin) => plugin !== configPluginTemplate.dst);
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
const plugins = nitroConfig.plugins ?? [];
|
|
93
|
+
nitroConfig.plugins = [configPluginTemplate.dst, ...plugins.filter((plugin) => plugin !== configPluginTemplate.dst)];
|
|
94
|
+
if (isLegacyNitro) {
|
|
95
|
+
const externals = nitroConfig.externals ?? (nitroConfig.externals = {});
|
|
96
|
+
const inline = externals.inline;
|
|
97
|
+
const existingInline = Array.isArray(inline) ? inline : inline ? [inline] : [];
|
|
98
|
+
externals.inline = [...existingInline, configPath, configPluginTemplate.dst, runtimeFlagsTemplate.dst];
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
nuxt.hook("nitro:init", (nitro) => {
|
|
102
|
+
if (nuxt.options._prepare || !utils.isCloudflarePreset(nitro.options.preset)) {
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
nitro.options.plugins = (nitro.options.plugins ?? []).filter((plugin) => plugin !== configPluginTemplate.dst);
|
|
106
|
+
core.consoleSandbox(() => {
|
|
107
|
+
console.warn(
|
|
108
|
+
`[Sentry] Found \`${path.basename(configPath)}\`, but the Nitro preset targets Cloudflare, where this file is not used. Set up the SDK with \`sentryCloudflareNitroPlugin\` instead: https://docs.sentry.io/platforms/javascript/guides/nuxt/install/cloudflare-workers/`
|
|
109
|
+
);
|
|
110
|
+
});
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
function addServerConfigShimWithWarning(nitro) {
|
|
114
|
+
nitro.hooks.hook("close", async () => {
|
|
115
|
+
if (nitro.options.dev || nitro.options.preset === "nitro-prerender" || utils.isCloudflarePreset(nitro.options.preset)) {
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
const shimPath = kit.createResolver(nitro.options.output.serverDir).resolve(`${utils.SERVER_CONFIG_FILENAME}.mjs`);
|
|
119
|
+
const contents = [
|
|
120
|
+
"// Generated by @sentry/nuxt.",
|
|
121
|
+
"// The Sentry server config is bundled into the server build and initializes automatically.",
|
|
122
|
+
"// This file only keeps existing `node --import ./.output/server/sentry.server.config.mjs` commands working.",
|
|
123
|
+
"console.warn('[Sentry] The `--import` flag for the Sentry server config is no longer needed and should be removed.');",
|
|
124
|
+
""
|
|
125
|
+
].join("\n");
|
|
126
|
+
try {
|
|
127
|
+
await fs.promises.writeFile(shimPath, contents, "utf8");
|
|
128
|
+
} catch (error) {
|
|
129
|
+
core.consoleSandbox(() => {
|
|
130
|
+
console.warn(`[Sentry] Could not write the \`--import\` compatibility shim to ${shimPath}`, error);
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
});
|
|
134
|
+
}
|
|
85
135
|
function addDynamicImportEntryFileWrapper(nitro, serverConfigFile, moduleOptions) {
|
|
86
136
|
if (!nitro.options.rollupConfig) {
|
|
87
137
|
nitro.options.rollupConfig = { output: {} };
|
|
@@ -94,6 +144,7 @@ function addDynamicImportEntryFileWrapper(nitro, serverConfigFile, moduleOptions
|
|
|
94
144
|
nitro.options.rollupConfig.plugins.push(
|
|
95
145
|
wrapEntryWithDynamicImport({
|
|
96
146
|
resolvedSentryConfigPath: kit.createResolver(nitro.options.rootDir).resolve(serverConfigFile),
|
|
147
|
+
// oxlint-disable-next-line typescript/no-deprecated -- supported until removal
|
|
97
148
|
experimental_entrypointWrappedFunctions: moduleOptions.experimental_entrypointWrappedFunctions
|
|
98
149
|
})
|
|
99
150
|
);
|
|
@@ -182,10 +233,10 @@ ${reExportedFunctions}
|
|
|
182
233
|
};
|
|
183
234
|
}
|
|
184
235
|
|
|
185
|
-
exports.DEV_SERVER_CONFIG_PATH = DEV_SERVER_CONFIG_PATH;
|
|
186
|
-
exports.addDevServerConfigFile = addDevServerConfigFile;
|
|
187
236
|
exports.addDynamicImportEntryFileWrapper = addDynamicImportEntryFileWrapper;
|
|
188
237
|
exports.addSentryTopImport = addSentryTopImport;
|
|
238
|
+
exports.addServerConfigPlugin = addServerConfigPlugin;
|
|
239
|
+
exports.addServerConfigShimWithWarning = addServerConfigShimWithWarning;
|
|
189
240
|
exports.addServerConfigToBuild = addServerConfigToBuild;
|
|
190
241
|
exports.wrapEntryWithDynamicImport = wrapEntryWithDynamicImport;
|
|
191
242
|
//# sourceMappingURL=addServerConfig.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"addServerConfig.js","sources":["../../../src/vite/addServerConfig.ts"],"sourcesContent":["import { existsSync } from 'node:fs';\nimport { basename } from 'node:path';\nimport { pathToFileURL } from 'node:url';\nimport { addTemplate, createResolver } from '@nuxt/kit';\nimport type { Nuxt } from '@nuxt/schema';\nimport { debug } from '@sentry/core';\nimport * as fs from 'fs';\nimport type { Nitro } from 'nitropack';\nimport * as path from 'path';\nimport type { InputPluginOption } from 'rollup';\nimport { NUXT_DEV_MODE_FLAG } from '../common/devMode';\nimport type { SentryNuxtModuleOptions } from '../common/types';\nimport {\n constructFunctionReExport,\n constructWrappedFunctionExportQuery,\n getFilenameFromNodeStartCommand,\n QUERY_END_INDICATOR,\n removeSentryQueryFromPath,\n SENTRY_REEXPORTED_FUNCTIONS,\n SENTRY_WRAPPED_ENTRY,\n SENTRY_WRAPPED_FUNCTIONS,\n SERVER_CONFIG_FILENAME,\n toImportSpecifier,\n toResolvablePath,\n} from './utils';\n\n/** Path of the generated dev-mode config file, relative to the Nuxt build directory. */\nexport const DEV_SERVER_CONFIG_PATH = `dev/${SERVER_CONFIG_FILENAME}.mjs`;\n\n/**\n * Writes the file users preload with `node --import` to enable Sentry in `nuxt dev` (for Nuxt 5 with Nitro 3).\n *\n * In dev-mode, Nitro v3 has no server bundle to emit into, so Node loads the server config file as it is written.\n */\nexport function addDevServerConfigFile(nuxt: Nuxt, serverConfigFile: string): void {\n const configPath = createResolver(nuxt.options.rootDir).resolve(serverConfigFile);\n const importSpecifier = toImportSpecifier(\n nuxt.options.rootDir,\n path.join(nuxt.options.buildDir, DEV_SERVER_CONFIG_PATH),\n );\n\n const failureMessage =\n `[Sentry] Could not load \\`${path.basename(configPath)}\\`, so Sentry is disabled during development. ` +\n 'Node loads this file without a build step, so it supports neither path aliases (like #import) nor non-erasable TypeScript syntax (like enums).';\n\n addTemplate({\n filename: DEV_SERVER_CONFIG_PATH,\n write: true,\n getContents: () =>\n [\n '// Generated by @sentry/nuxt. Preload it to enable Sentry during development:',\n `// NODE_OPTIONS='--import ${importSpecifier}' nuxt dev`,\n // A static import would hoist above this assignment, and would make a broken config crash the dev server.\n `globalThis.${NUXT_DEV_MODE_FLAG} = true;`,\n 'try {',\n ` await import(${JSON.stringify(pathToFileURL(configPath).href)});`,\n '} catch (error) {',\n ` console.warn(${JSON.stringify(failureMessage)}, error);`,\n '}',\n '',\n ].join('\\n'),\n });\n}\nconst CONFIG_EXTENSIONS = ['.ts', '.js', '.mjs', '.cjs', '.mts', '.cts'];\n\nfunction isServerConfigFile(sourcePath: string, resolvedPath: string): boolean {\n if (sourcePath === resolvedPath) {\n return true;\n }\n const name = basename(sourcePath);\n return name === SERVER_CONFIG_FILENAME || CONFIG_EXTENSIONS.some(ext => name === `${SERVER_CONFIG_FILENAME}${ext}`);\n}\n\n/**\n * 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.\n *\n * By adding a Rollup plugin to the Nitro Rollup options, the Sentry server config is transpiled and emitted to the server build.\n */\nexport function addServerConfigToBuild(\n moduleOptions: SentryNuxtModuleOptions,\n nitro: Nitro,\n serverConfigFile: string,\n): void {\n nitro.hooks.hook('rollup:before', (nitro, rollupConfig) => {\n if (rollupConfig?.plugins === null || rollupConfig?.plugins === undefined) {\n rollupConfig.plugins = [];\n } else if (!Array.isArray(rollupConfig.plugins)) {\n // `rollupConfig.plugins` can be a single plugin, so we want to put it into an array so that we can push our own plugin\n rollupConfig.plugins = [rollupConfig.plugins];\n }\n\n rollupConfig.plugins.push(injectServerConfigPlugin(nitro, serverConfigFile, moduleOptions.debug));\n });\n}\n\n/**\n * Adds the Sentry server config import at the top of the server entry file to load the SDK on the server.\n * This is necessary for environments where modifying the node option `--import` is not possible.\n * However, only limited tracing instrumentation is supported when doing this.\n */\nexport function addSentryTopImport(moduleOptions: SentryNuxtModuleOptions, nitro: Nitro): void {\n nitro.hooks.hook('close', async () => {\n const fileNameFromCommand =\n nitro.options.commands.preview && getFilenameFromNodeStartCommand(nitro.options.commands.preview);\n\n // other presets ('node-server' or 'vercel') have an index.mjs\n const presetsWithServerFile = ['netlify'];\n\n const entryFileName = fileNameFromCommand\n ? fileNameFromCommand\n : typeof nitro.options.rollupConfig?.output.entryFileNames === 'string'\n ? nitro.options.rollupConfig?.output.entryFileNames\n : presetsWithServerFile.includes(nitro.options.preset)\n ? 'server.mjs'\n : 'index.mjs';\n\n const serverDirResolver = createResolver(nitro.options.output.serverDir);\n const entryFilePath = serverDirResolver.resolve(entryFileName);\n\n try {\n fs.readFile(entryFilePath, 'utf8', (err, data) => {\n const updatedContent = `import './${SERVER_CONFIG_FILENAME}.mjs';\\n${data}`;\n\n fs.writeFile(entryFilePath, updatedContent, 'utf8', () => {\n if (moduleOptions.debug) {\n // eslint-disable-next-line no-console\n console.log(\n `[Sentry] Successfully added the Sentry import to the server entry file \"\\`${entryFilePath}\\`\"`,\n );\n }\n });\n });\n } catch (err) {\n if (moduleOptions.debug) {\n // eslint-disable-next-line no-console\n console.warn(\n `[Sentry] An error occurred when trying to add the Sentry import to the server entry file \"\\`${entryFilePath}\\`\":`,\n err,\n );\n }\n }\n });\n}\n\n/**\n * This function modifies the Rollup configuration to include a plugin that wraps the entry file with a dynamic import (`import()`)\n * and adds the Sentry server config with the static `import` declaration.\n *\n * With this, the Sentry server config can be loaded before all other modules of the application.\n * See: https://nodejs.org/api/module.html#enabling\n */\nexport function addDynamicImportEntryFileWrapper(\n nitro: Nitro,\n serverConfigFile: string,\n moduleOptions: Omit<SentryNuxtModuleOptions, 'experimental_entrypointWrappedFunctions'> &\n Required<Pick<SentryNuxtModuleOptions, 'experimental_entrypointWrappedFunctions'>>,\n): void {\n if (!nitro.options.rollupConfig) {\n nitro.options.rollupConfig = { output: {} };\n }\n\n if (nitro.options.rollupConfig?.plugins === null || nitro.options.rollupConfig?.plugins === undefined) {\n nitro.options.rollupConfig.plugins = [];\n } else if (!Array.isArray(nitro.options.rollupConfig.plugins)) {\n // `rollupConfig.plugins` can be a single plugin, so we want to put it into an array so that we can push our own plugin\n nitro.options.rollupConfig.plugins = [nitro.options.rollupConfig.plugins];\n }\n\n nitro.options.rollupConfig.plugins.push(\n wrapEntryWithDynamicImport({\n resolvedSentryConfigPath: createResolver(nitro.options.rootDir).resolve(serverConfigFile),\n experimental_entrypointWrappedFunctions: moduleOptions.experimental_entrypointWrappedFunctions,\n }),\n );\n}\n\n/**\n * Rollup plugin to include the Sentry server configuration file to the server build output.\n */\nfunction injectServerConfigPlugin(nitro: Nitro, serverConfigFile: string, isDebug?: boolean): InputPluginOption {\n const filePrefix = '\\0virtual:sentry-server-config:';\n\n return {\n name: 'rollup-plugin-inject-sentry-server-config',\n\n buildStart() {\n const configPath = createResolver(nitro.options.rootDir).resolve(serverConfigFile);\n\n if (!existsSync(configPath)) {\n if (isDebug) {\n debug.log(`[Sentry] Sentry server config file not found: ${configPath}`);\n }\n return;\n }\n\n // Emitting a file adds it to the build output (Rollup is aware of the file, and we can later return the code in resolveId)\n this.emitFile({\n type: 'chunk',\n id: `${filePrefix}${serverConfigFile}`,\n fileName: `${SERVER_CONFIG_FILENAME}.mjs`,\n });\n },\n\n resolveId(source) {\n if (source.startsWith(filePrefix)) {\n const originalFilePath = source.replace(filePrefix, '');\n const configPath = createResolver(nitro.options.rootDir).resolve(originalFilePath);\n\n return { id: configPath };\n }\n return null;\n },\n };\n}\n\n/**\n * A Rollup plugin which wraps the server entry with a dynamic `import()`. This makes it possible to initialize Sentry first\n * by using a regular `import` and load the server after that.\n * This also works with serverless `handler` functions, as it re-exports the `handler`.\n *\n * Only exported for testing.\n */\nexport function wrapEntryWithDynamicImport({\n resolvedSentryConfigPath,\n experimental_entrypointWrappedFunctions,\n debug,\n}: {\n resolvedSentryConfigPath: string;\n experimental_entrypointWrappedFunctions: string[];\n debug?: boolean;\n}): InputPluginOption {\n // In order to correctly import the server config file\n // and dynamically import the nitro runtime, we need to\n // mark the resolutionId with '\\0raw' to fall into the\n // raw chunk group, c.f. https://github.com/nitrojs/nitro/commit/8b4a408231bdc222569a32ce109796a41eac4aa6#diff-e58102d2230f95ddeef2662957b48d847a6e891e354cfd0ae6e2e03ce848d1a2R142\n const resolutionIdPrefix = '\\0raw';\n\n return {\n name: 'sentry-wrap-entry-with-dynamic-import',\n async resolveId(source, importer, options) {\n // `load()` emits `file://` specifiers because Node's ESM loader rejects bare Windows paths,\n // but Rollup's resolver only understands filesystem paths.\n const resolvable = toResolvablePath(source);\n if (!resolvable) {\n return null;\n }\n const { path: normalizedSource, wasFileUrl } = resolvable;\n\n if (isServerConfigFile(normalizedSource, resolvedSentryConfigPath)) {\n return { id: normalizedSource, moduleSideEffects: true };\n }\n\n if (\n options.isEntry &&\n normalizedSource.includes('.mjs') &&\n !normalizedSource.includes(`.mjs${SENTRY_WRAPPED_ENTRY}`)\n ) {\n const resolution = await this.resolve(normalizedSource, importer, options);\n\n // If it cannot be resolved or is external, just return it so that Rollup can display an error\n if (!resolution || resolution?.external) return resolution;\n\n const moduleInfo = await this.load(resolution);\n\n moduleInfo.moduleSideEffects = true;\n\n // The enclosing `if` already checks for the suffix in `source`, but a check in `resolution.id` is needed as well to prevent multiple attachment of the suffix\n return resolution.id.includes(`.mjs${SENTRY_WRAPPED_ENTRY}`)\n ? resolution.id\n : `${resolutionIdPrefix}${resolution.id\n // Concatenates the query params to mark the file (also attaches names of re-exports - this is needed for serverless functions to re-export the handler)\n .concat(SENTRY_WRAPPED_ENTRY)\n .concat(\n constructWrappedFunctionExportQuery(\n moduleInfo.exportedBindings,\n experimental_entrypointWrappedFunctions,\n debug,\n ),\n )\n .concat(QUERY_END_INDICATOR)}`;\n }\n\n // Pass isEntry:false to avoid re-entering the isEntry branch and double-wrapping\n // (normalizedSource strips the SENTRY_WRAPPED_ENTRY query suffix).\n if (wasFileUrl) {\n const resolved = await this.resolve(normalizedSource, importer, { ...options, isEntry: false });\n if (resolved) return resolved;\n return { id: normalizedSource };\n }\n\n return null;\n },\n load(id: string) {\n if (id.includes(`.mjs${SENTRY_WRAPPED_ENTRY}`)) {\n const entryId = removeSentryQueryFromPath(id).slice(resolutionIdPrefix.length);\n const entryIdUrl = pathToFileURL(entryId).href;\n const configUrl = pathToFileURL(resolvedSentryConfigPath).href;\n\n // Use entryIdUrl so Node's runtime ESM loader receives file:// on Windows; Rollup normalizes it in resolveId.\n // Mostly useful for serverless `handler` functions\n const reExportedFunctions =\n id.includes(SENTRY_WRAPPED_FUNCTIONS) || id.includes(SENTRY_REEXPORTED_FUNCTIONS)\n ? constructFunctionReExport(id, entryIdUrl)\n : '';\n\n return (\n // Regular `import` of the Sentry config\n `import ${JSON.stringify(configUrl)};\\n` +\n // Dynamic `import()` for the previous, actual entry point.\n // `import()` can be used for any code that should be run after the hooks are registered (https://nodejs.org/api/module.html#enabling)\n `import(${JSON.stringify(entryIdUrl)});\\n` +\n `${reExportedFunctions}\\n`\n );\n }\n\n return null;\n },\n };\n}\n"],"names":["SERVER_CONFIG_FILENAME","createResolver","toImportSpecifier","addTemplate","NUXT_DEV_MODE_FLAG","pathToFileURL","basename","nitro","getFilenameFromNodeStartCommand","existsSync","debug","toResolvablePath","SENTRY_WRAPPED_ENTRY","constructWrappedFunctionExportQuery","QUERY_END_INDICATOR","removeSentryQueryFromPath","SENTRY_WRAPPED_FUNCTIONS","SENTRY_REEXPORTED_FUNCTIONS","constructFunctionReExport"],"mappings":";;;;;;;;;;;;AA2BO,MAAM,sBAAA,GAAyB,OAAOA,4BAAsB,CAAA,IAAA;AAO5D,SAAS,sBAAA,CAAuB,MAAY,gBAAA,EAAgC;AACjF,EAAA,MAAM,aAAaC,kBAAA,CAAe,IAAA,CAAK,QAAQ,OAAO,CAAA,CAAE,QAAQ,gBAAgB,CAAA;AAChF,EAAA,MAAM,eAAA,GAAkBC,uBAAA;AAAA,IACtB,KAAK,OAAA,CAAQ,OAAA;AAAA,IACb,IAAA,CAAK,IAAA,CAAK,IAAA,CAAK,OAAA,CAAQ,UAAU,sBAAsB;AAAA,GACzD;AAEA,EAAA,MAAM,cAAA,GACJ,CAAA,0BAAA,EAA6B,IAAA,CAAK,QAAA,CAAS,UAAU,CAAC,CAAA,4LAAA,CAAA;AAGxD,EAAAC,eAAA,CAAY;AAAA,IACV,QAAA,EAAU,sBAAA;AAAA,IACV,KAAA,EAAO,IAAA;AAAA,IACP,aAAa,MACX;AAAA,MACE,+EAAA;AAAA,MACA,+BAA+B,eAAe,CAAA,UAAA,CAAA;AAAA;AAAA,MAE9C,cAAcC,0BAAkB,CAAA,QAAA,CAAA;AAAA,MAChC,OAAA;AAAA,MACA,kBAAkB,IAAA,CAAK,SAAA,CAAUC,uBAAc,UAAU,CAAA,CAAE,IAAI,CAAC,CAAA,EAAA,CAAA;AAAA,MAChE,mBAAA;AAAA,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A,MAChC;AAEA,MAAA,OAAO,IAAA;AAAA,IACT,CAAA;AAAA,IACA,KAAK,EAAA,EAAY;AACf,MAAA,IAAI,EAAA,CAAG,QAAA,CAAS,CAAA,IAAA,EAAOF,0BAAoB,EAAE,CAAA,EAAG;AAC9C,QAAA,MAAM,UAAUG,+BAAA,CAA0B,EAAE,CAAA,CAAE,KAAA,CAAM,mBAAmB,MAAM,CAAA;AAC7E,QAAA,MAAM,UAAA,GAAaV,sBAAA,CAAc,OAAO,CAAA,CAAE,IAAA;AAC1C,QAAA,MAAM,SAAA,GAAYA,sBAAA,CAAc,wBAAwB,CAAA,CAAE,IAAA;AAI1D,QAAA,MAAM,mBAAA,GACJ,EAAA,CAAG,QAAA,CAASW,8BAAwB,CAAA,IAAK,EAAA,CAAG,QAAA,CAASC,iCAA2B,CAAA,GAC5EC,+BAAA,CAA0B,EAAA,EAAI,UAAU,CAAA,GACxC,EAAA;AAEN,QAAA;AAAA;AAAA,UAEE,CAAA,OAAA,EAAU,IAAA,CAAK,SAAA,CAAU,SAAS,CAAC,CAAA;AAAA,OAAA,EAGzB,IAAA,CAAK,SAAA,CAAU,UAAU,CAAC,CAAA;AAAA,EACjC,mBAAmB;AAAA;AAAA;AAAA,MAE1B;AAEA,MAAA,OAAO,IAAA;AAAA,IACT;AAAA,GACF;AACF;;;;;;;;;"}
|
|
1
|
+
{"version":3,"file":"addServerConfig.js","sources":["../../../src/vite/addServerConfig.ts"],"sourcesContent":["import { existsSync } from 'node:fs';\nimport { basename } from 'node:path';\nimport { pathToFileURL } from 'node:url';\nimport { addServerPlugin, addTemplate, createResolver } from '@nuxt/kit';\nimport type { Nuxt } from '@nuxt/schema';\nimport { consoleSandbox, debug } from '@sentry/core';\nimport * as fs from 'fs';\nimport type { Nitro } from 'nitropack';\nimport type { InputPluginOption } from 'rollup';\nimport { NUXT_DEV_MODE_FLAG, NUXT_PRERENDER_FLAG } from '../common/devMode';\nimport type { SentryNuxtModuleOptions } from '../common/types';\nimport {\n constructFunctionReExport,\n constructWrappedFunctionExportQuery,\n getFilenameFromNodeStartCommand,\n isCloudflarePreset,\n QUERY_END_INDICATOR,\n removeSentryQueryFromPath,\n SENTRY_REEXPORTED_FUNCTIONS,\n SENTRY_WRAPPED_ENTRY,\n SENTRY_WRAPPED_FUNCTIONS,\n SERVER_CONFIG_FILENAME,\n toResolvablePath,\n} from './utils';\n\nconst CONFIG_EXTENSIONS = ['.ts', '.js', '.mjs', '.cjs', '.mts', '.cts'];\n\nfunction isServerConfigFile(sourcePath: string, resolvedPath: string): boolean {\n if (sourcePath === resolvedPath) {\n return true;\n }\n const name = basename(sourcePath);\n return name === SERVER_CONFIG_FILENAME || CONFIG_EXTENSIONS.some(ext => name === `${SERVER_CONFIG_FILENAME}${ext}`);\n}\n\n/**\n * 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.\n *\n * By adding a Rollup plugin to the Nitro Rollup options, the Sentry server config is transpiled and emitted to the server build.\n */\nexport function addServerConfigToBuild(\n moduleOptions: SentryNuxtModuleOptions,\n nitro: Nitro,\n serverConfigFile: string,\n): void {\n nitro.hooks.hook('rollup:before', (nitro, rollupConfig) => {\n if (rollupConfig?.plugins === null || rollupConfig?.plugins === undefined) {\n rollupConfig.plugins = [];\n } else if (!Array.isArray(rollupConfig.plugins)) {\n // `rollupConfig.plugins` can be a single plugin, so we want to put it into an array so that we can push our own plugin\n rollupConfig.plugins = [rollupConfig.plugins];\n }\n\n rollupConfig.plugins.push(injectServerConfigPlugin(nitro, serverConfigFile, moduleOptions.debug));\n });\n}\n\n/**\n * Adds the Sentry server config import at the top of the server entry file to load the SDK on the server.\n * This is necessary for environments where modifying the node option `--import` is not possible.\n * However, only limited tracing instrumentation is supported when doing this.\n */\nexport function addSentryTopImport(moduleOptions: SentryNuxtModuleOptions, nitro: Nitro): void {\n nitro.hooks.hook('close', async () => {\n const fileNameFromCommand =\n nitro.options.commands.preview && getFilenameFromNodeStartCommand(nitro.options.commands.preview);\n\n // other presets ('node-server' or 'vercel') have an index.mjs\n const presetsWithServerFile = ['netlify'];\n\n const entryFileName = fileNameFromCommand\n ? fileNameFromCommand\n : typeof nitro.options.rollupConfig?.output.entryFileNames === 'string'\n ? nitro.options.rollupConfig?.output.entryFileNames\n : presetsWithServerFile.includes(nitro.options.preset)\n ? 'server.mjs'\n : 'index.mjs';\n\n const serverDirResolver = createResolver(nitro.options.output.serverDir);\n const entryFilePath = serverDirResolver.resolve(entryFileName);\n\n try {\n fs.readFile(entryFilePath, 'utf8', (err, data) => {\n const updatedContent = `import './${SERVER_CONFIG_FILENAME}.mjs';\\n${data}`;\n\n fs.writeFile(entryFilePath, updatedContent, 'utf8', () => {\n if (moduleOptions.debug) {\n // eslint-disable-next-line no-console\n console.log(\n `[Sentry] Successfully added the Sentry import to the server entry file \"\\`${entryFilePath}\\`\"`,\n );\n }\n });\n });\n } catch (err) {\n if (moduleOptions.debug) {\n // eslint-disable-next-line no-console\n console.warn(\n `[Sentry] An error occurred when trying to add the Sentry import to the server entry file \"\\`${entryFilePath}\\`\":`,\n err,\n );\n }\n }\n });\n}\n\n/**\n * Registers a Nitro plugin that statically imports the Sentry server config, so the SDK initializes\n * at server startup without a `node --import` preload.\n */\nexport function addServerConfigPlugin(nuxt: Nuxt, serverConfigFile: string, isLegacyNitro: boolean): void {\n const configPath = createResolver(nuxt.options.rootDir).resolve(serverConfigFile);\n\n // `Sentry.init` reads these flags, and a statement above the config import would not survive\n // import hoisting — so they live in their own module which is imported first.\n const runtimeFlagsTemplate = addTemplate({\n filename: 'sentry-runtime-flags.mjs',\n write: true,\n getContents: () =>\n [\n '// Generated by @sentry/nuxt. Sets runtime flags before the Sentry server config evaluates.',\n `globalThis.${NUXT_DEV_MODE_FLAG} = import.meta.dev === true;`,\n `globalThis.${NUXT_PRERENDER_FLAG} = import.meta.prerender === true;`,\n '',\n ].join('\\n'),\n });\n\n const configPluginTemplate = addTemplate({\n filename: 'sentry-server-config-plugin.mjs',\n write: true,\n getContents: () =>\n `import ${JSON.stringify(runtimeFlagsTemplate.dst)};\\nimport ${JSON.stringify(configPath)};\\nexport default () => {};\\n`,\n });\n\n addServerPlugin(configPluginTemplate.dst);\n\n // Nitro v2 treeshakes side-effect-only imports outside its runtime dir, which would silently drop\n // the top-level `Sentry.init` and the flag assignments.\n // Nitro v3 dropped the option and keeps both.\n if (isLegacyNitro) {\n nuxt.options.nitro.moduleSideEffects = [\n ...(nuxt.options.nitro.moduleSideEffects ?? []),\n configPath,\n runtimeFlagsTemplate.dst,\n ];\n }\n\n nuxt.hook('nitro:config', nitroConfig => {\n // Early skip for explicitly configured Cloudflare presets. The authoritative check runs on\n // `nitro:init`: env-derived presets (`NITRO_PRESET`, Cloudflare Pages CI) resolve only inside Nitro.\n if (isCloudflarePreset(nitroConfig.preset)) {\n nitroConfig.plugins = (nitroConfig.plugins ?? []).filter(plugin => plugin !== configPluginTemplate.dst);\n return;\n }\n\n // Front the config plugin so `Sentry.init` evaluates before plugins registered by other Nuxt\n // modules (Nitro appends scanned user plugins after the configured ones anyway).\n const plugins = nitroConfig.plugins ?? [];\n nitroConfig.plugins = [configPluginTemplate.dst, ...plugins.filter(plugin => plugin !== configPluginTemplate.dst)];\n\n // The Nitro v2 dev bundle would otherwise externalize these files, making Node load the raw\n // `.ts` config — which needs type stripping (Node >= 22.18). Inlining keeps them transpiled.\n // Nitro v3 has no `externals` option; its dev server runs the config through Vite's transform.\n if (isLegacyNitro) {\n const externals = (nitroConfig.externals ??= {});\n const inline = externals.inline;\n const existingInline = Array.isArray(inline) ? inline : inline ? [inline] : [];\n externals.inline = [...existingInline, configPath, configPluginTemplate.dst, runtimeFlagsTemplate.dst];\n }\n });\n\n // On Cloudflare the SDK is set up through `sentryCloudflareNitroPlugin`; the Node SDK config\n // must not end up in the worker bundle. `nitro.options.preset` is resolved here.\n nuxt.hook('nitro:init', nitro => {\n if (nuxt.options._prepare || !isCloudflarePreset(nitro.options.preset)) {\n return;\n }\n\n nitro.options.plugins = (nitro.options.plugins ?? []).filter(plugin => plugin !== configPluginTemplate.dst);\n consoleSandbox(() => {\n // eslint-disable-next-line no-console\n console.warn(\n `[Sentry] Found \\`${basename(configPath)}\\`, but the Nitro preset targets Cloudflare, where this file is not used. Set up the SDK with \\`sentryCloudflareNitroPlugin\\` instead: https://docs.sentry.io/platforms/javascript/guides/nuxt/install/cloudflare-workers/`,\n );\n });\n });\n}\n\n/**\n * Writes a shim to the former `--import` config path, so existing `node --import` start commands\n * keep working now that the config is bundled into the server build.\n */\nexport function addServerConfigShimWithWarning(nitro: Nitro): void {\n nitro.hooks.hook('close', async () => {\n if (nitro.options.dev || nitro.options.preset === 'nitro-prerender' || isCloudflarePreset(nitro.options.preset)) {\n return;\n }\n\n const shimPath = createResolver(nitro.options.output.serverDir).resolve(`${SERVER_CONFIG_FILENAME}.mjs`);\n const contents = [\n '// Generated by @sentry/nuxt.',\n '// The Sentry server config is bundled into the server build and initializes automatically.',\n '// This file only keeps existing `node --import ./.output/server/sentry.server.config.mjs` commands working.',\n \"console.warn('[Sentry] The `--import` flag for the Sentry server config is no longer needed and should be removed.');\",\n '',\n ].join('\\n');\n\n try {\n await fs.promises.writeFile(shimPath, contents, 'utf8');\n } catch (error) {\n // A missing shim breaks `node --import` start commands, so always warn (`debug` is off at build time).\n consoleSandbox(() => {\n // eslint-disable-next-line no-console\n console.warn(`[Sentry] Could not write the \\`--import\\` compatibility shim to ${shimPath}`, error);\n });\n }\n });\n}\n\n/**\n * This function modifies the Rollup configuration to include a plugin that wraps the entry file with a dynamic import (`import()`)\n * and adds the Sentry server config with the static `import` declaration.\n *\n * With this, the Sentry server config can be loaded before all other modules of the application.\n * See: https://nodejs.org/api/module.html#enabling\n */\nexport function addDynamicImportEntryFileWrapper(\n nitro: Nitro,\n serverConfigFile: string,\n moduleOptions: Omit<SentryNuxtModuleOptions, 'experimental_entrypointWrappedFunctions'> &\n Required<Pick<SentryNuxtModuleOptions, 'experimental_entrypointWrappedFunctions'>>,\n): void {\n if (!nitro.options.rollupConfig) {\n nitro.options.rollupConfig = { output: {} };\n }\n\n if (nitro.options.rollupConfig?.plugins === null || nitro.options.rollupConfig?.plugins === undefined) {\n nitro.options.rollupConfig.plugins = [];\n } else if (!Array.isArray(nitro.options.rollupConfig.plugins)) {\n // `rollupConfig.plugins` can be a single plugin, so we want to put it into an array so that we can push our own plugin\n nitro.options.rollupConfig.plugins = [nitro.options.rollupConfig.plugins];\n }\n\n nitro.options.rollupConfig.plugins.push(\n wrapEntryWithDynamicImport({\n resolvedSentryConfigPath: createResolver(nitro.options.rootDir).resolve(serverConfigFile),\n // oxlint-disable-next-line typescript/no-deprecated -- supported until removal\n experimental_entrypointWrappedFunctions: moduleOptions.experimental_entrypointWrappedFunctions,\n }),\n );\n}\n\n/**\n * Rollup plugin to include the Sentry server configuration file to the server build output.\n */\nfunction injectServerConfigPlugin(nitro: Nitro, serverConfigFile: string, isDebug?: boolean): InputPluginOption {\n const filePrefix = '\\0virtual:sentry-server-config:';\n\n return {\n name: 'rollup-plugin-inject-sentry-server-config',\n\n buildStart() {\n const configPath = createResolver(nitro.options.rootDir).resolve(serverConfigFile);\n\n if (!existsSync(configPath)) {\n if (isDebug) {\n debug.log(`[Sentry] Sentry server config file not found: ${configPath}`);\n }\n return;\n }\n\n // Emitting a file adds it to the build output (Rollup is aware of the file, and we can later return the code in resolveId)\n this.emitFile({\n type: 'chunk',\n id: `${filePrefix}${serverConfigFile}`,\n fileName: `${SERVER_CONFIG_FILENAME}.mjs`,\n });\n },\n\n resolveId(source) {\n if (source.startsWith(filePrefix)) {\n const originalFilePath = source.replace(filePrefix, '');\n const configPath = createResolver(nitro.options.rootDir).resolve(originalFilePath);\n\n return { id: configPath };\n }\n return null;\n },\n };\n}\n\n/**\n * A Rollup plugin which wraps the server entry with a dynamic `import()`. This makes it possible to initialize Sentry first\n * by using a regular `import` and load the server after that.\n * This also works with serverless `handler` functions, as it re-exports the `handler`.\n *\n * Only exported for testing.\n */\nexport function wrapEntryWithDynamicImport({\n resolvedSentryConfigPath,\n experimental_entrypointWrappedFunctions,\n debug,\n}: {\n resolvedSentryConfigPath: string;\n experimental_entrypointWrappedFunctions: string[];\n debug?: boolean;\n}): InputPluginOption {\n // In order to correctly import the server config file\n // and dynamically import the nitro runtime, we need to\n // mark the resolutionId with '\\0raw' to fall into the\n // raw chunk group, c.f. https://github.com/nitrojs/nitro/commit/8b4a408231bdc222569a32ce109796a41eac4aa6#diff-e58102d2230f95ddeef2662957b48d847a6e891e354cfd0ae6e2e03ce848d1a2R142\n const resolutionIdPrefix = '\\0raw';\n\n return {\n name: 'sentry-wrap-entry-with-dynamic-import',\n async resolveId(source, importer, options) {\n // `load()` emits `file://` specifiers because Node's ESM loader rejects bare Windows paths,\n // but Rollup's resolver only understands filesystem paths.\n const resolvable = toResolvablePath(source);\n if (!resolvable) {\n return null;\n }\n const { path: normalizedSource, wasFileUrl } = resolvable;\n\n if (isServerConfigFile(normalizedSource, resolvedSentryConfigPath)) {\n return { id: normalizedSource, moduleSideEffects: true };\n }\n\n if (\n options.isEntry &&\n normalizedSource.includes('.mjs') &&\n !normalizedSource.includes(`.mjs${SENTRY_WRAPPED_ENTRY}`)\n ) {\n const resolution = await this.resolve(normalizedSource, importer, options);\n\n // If it cannot be resolved or is external, just return it so that Rollup can display an error\n if (!resolution || resolution?.external) return resolution;\n\n const moduleInfo = await this.load(resolution);\n\n moduleInfo.moduleSideEffects = true;\n\n // The enclosing `if` already checks for the suffix in `source`, but a check in `resolution.id` is needed as well to prevent multiple attachment of the suffix\n return resolution.id.includes(`.mjs${SENTRY_WRAPPED_ENTRY}`)\n ? resolution.id\n : `${resolutionIdPrefix}${resolution.id\n // Concatenates the query params to mark the file (also attaches names of re-exports - this is needed for serverless functions to re-export the handler)\n .concat(SENTRY_WRAPPED_ENTRY)\n .concat(\n constructWrappedFunctionExportQuery(\n moduleInfo.exportedBindings,\n experimental_entrypointWrappedFunctions,\n debug,\n ),\n )\n .concat(QUERY_END_INDICATOR)}`;\n }\n\n // Pass isEntry:false to avoid re-entering the isEntry branch and double-wrapping\n // (normalizedSource strips the SENTRY_WRAPPED_ENTRY query suffix).\n if (wasFileUrl) {\n const resolved = await this.resolve(normalizedSource, importer, { ...options, isEntry: false });\n if (resolved) return resolved;\n return { id: normalizedSource };\n }\n\n return null;\n },\n load(id: string) {\n if (id.includes(`.mjs${SENTRY_WRAPPED_ENTRY}`)) {\n const entryId = removeSentryQueryFromPath(id).slice(resolutionIdPrefix.length);\n const entryIdUrl = pathToFileURL(entryId).href;\n const configUrl = pathToFileURL(resolvedSentryConfigPath).href;\n\n // Use entryIdUrl so Node's runtime ESM loader receives file:// on Windows; Rollup normalizes it in resolveId.\n // Mostly useful for serverless `handler` functions\n const reExportedFunctions =\n id.includes(SENTRY_WRAPPED_FUNCTIONS) || id.includes(SENTRY_REEXPORTED_FUNCTIONS)\n ? constructFunctionReExport(id, entryIdUrl)\n : '';\n\n return (\n // Regular `import` of the Sentry config\n `import ${JSON.stringify(configUrl)};\\n` +\n // Dynamic `import()` for the previous, actual entry point.\n // `import()` can be used for any code that should be run after the hooks are registered (https://nodejs.org/api/module.html#enabling)\n `import(${JSON.stringify(entryIdUrl)});\\n` +\n `${reExportedFunctions}\\n`\n );\n }\n\n return null;\n },\n };\n}\n"],"names":["basename","SERVER_CONFIG_FILENAME","nitro","getFilenameFromNodeStartCommand","createResolver","addTemplate","NUXT_DEV_MODE_FLAG","NUXT_PRERENDER_FLAG","addServerPlugin","isCloudflarePreset","consoleSandbox","existsSync","debug","toResolvablePath","SENTRY_WRAPPED_ENTRY","constructWrappedFunctionExportQuery","QUERY_END_INDICATOR","removeSentryQueryFromPath","pathToFileURL","SENTRY_WRAPPED_FUNCTIONS","SENTRY_REEXPORTED_FUNCTIONS","constructFunctionReExport"],"mappings":";;;;;;;;;;;AAyBA,MAAM,oBAAoB,CAAC,KAAA,EAAO,OAAO,MAAA,EAAQ,MAAA,EAAQ,QAAQ,MAAM,CAAA;AAEvE,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,GAC5EC,+BAAA,CAA0B,EAAA,EAAI,UAAU,CAAA,GACxC,EAAA;AAEN,QAAA;AAAA;AAAA,UAEE,CAAA,OAAA,EAAU,IAAA,CAAK,SAAA,CAAU,SAAS,CAAC,CAAA;AAAA,OAAA,EAGzB,IAAA,CAAK,SAAA,CAAU,UAAU,CAAC,CAAA;AAAA,EACjC,mBAAmB;AAAA;AAAA;AAAA,MAE1B;AAEA,MAAA,OAAO,IAAA;AAAA,IACT;AAAA,GACF;AACF;;;;;;;;;"}
|
|
@@ -12,7 +12,7 @@ function addMiddlewareImports() {
|
|
|
12
12
|
}
|
|
13
13
|
]);
|
|
14
14
|
}
|
|
15
|
-
function addMiddlewareInstrumentation(nitro) {
|
|
15
|
+
function addMiddlewareInstrumentation(nitro, isNitroV3) {
|
|
16
16
|
nitro.hooks.hook("rollup:before", (nitro2, rollupConfig) => {
|
|
17
17
|
if (!rollupConfig.plugins) {
|
|
18
18
|
rollupConfig.plugins = [];
|
|
@@ -20,11 +20,12 @@ function addMiddlewareInstrumentation(nitro) {
|
|
|
20
20
|
if (!Array.isArray(rollupConfig.plugins)) {
|
|
21
21
|
rollupConfig.plugins = [rollupConfig.plugins];
|
|
22
22
|
}
|
|
23
|
-
rollupConfig.plugins.push(middlewareInstrumentationPlugin(nitro2));
|
|
23
|
+
rollupConfig.plugins.push(middlewareInstrumentationPlugin(nitro2, isNitroV3));
|
|
24
24
|
});
|
|
25
25
|
}
|
|
26
|
-
function middlewareInstrumentationPlugin(nitro) {
|
|
26
|
+
function middlewareInstrumentationPlugin(nitro, isNitroV3) {
|
|
27
27
|
const middlewareFiles = /* @__PURE__ */ new Set();
|
|
28
|
+
const wrapperModule = isNitroV3 ? "#imports/server" : "#imports";
|
|
28
29
|
return {
|
|
29
30
|
name: "sentry-nuxt-middleware-instrumentation",
|
|
30
31
|
buildStart() {
|
|
@@ -38,7 +39,7 @@ function middlewareInstrumentationPlugin(nitro) {
|
|
|
38
39
|
if (middlewareFiles.has(id)) {
|
|
39
40
|
const fileName = path.basename(id);
|
|
40
41
|
return {
|
|
41
|
-
code: wrapMiddlewareCode(code, fileName),
|
|
42
|
+
code: wrapMiddlewareCode(code, fileName, wrapperModule),
|
|
42
43
|
map: null
|
|
43
44
|
};
|
|
44
45
|
}
|
|
@@ -46,10 +47,10 @@ function middlewareInstrumentationPlugin(nitro) {
|
|
|
46
47
|
}
|
|
47
48
|
};
|
|
48
49
|
}
|
|
49
|
-
function wrapMiddlewareCode(originalCode, fileName) {
|
|
50
|
+
function wrapMiddlewareCode(originalCode, fileName, wrapperModule) {
|
|
50
51
|
const cleanFileName = fileName.replace(/\.(ts|js|mjs|mts|cts)$/, "");
|
|
51
52
|
return `
|
|
52
|
-
import { wrapMiddlewareHandlerWithSentry } from '
|
|
53
|
+
import { wrapMiddlewareHandlerWithSentry } from '${wrapperModule}';
|
|
53
54
|
|
|
54
55
|
function defineInstrumentedEventHandler(handlerOrObject) {
|
|
55
56
|
return defineEventHandler(wrapMiddlewareHandlerWithSentry(handlerOrObject, '${cleanFileName}'));
|