@sentry/nuxt 10.45.0 → 10.47.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/module.js +46 -27
- package/build/cjs/module.js.map +1 -1
- package/build/cjs/vite/databaseConfig.js +10 -2
- package/build/cjs/vite/databaseConfig.js.map +1 -1
- package/build/cjs/vite/middlewareConfig.js +6 -1
- package/build/cjs/vite/middlewareConfig.js.map +1 -1
- package/build/cjs/vite/sentryVitePlugin.js.map +1 -1
- package/build/cjs/vite/storageConfig.js +6 -2
- package/build/cjs/vite/storageConfig.js.map +1 -1
- package/build/cjs/vite/utils.js +21 -2
- package/build/cjs/vite/utils.js.map +1 -1
- package/build/esm/module.js +48 -29
- package/build/esm/module.js.map +1 -1
- package/build/esm/package.json +1 -1
- package/build/esm/vite/databaseConfig.js +10 -2
- package/build/esm/vite/databaseConfig.js.map +1 -1
- package/build/esm/vite/middlewareConfig.js +6 -1
- package/build/esm/vite/middlewareConfig.js.map +1 -1
- package/build/esm/vite/sentryVitePlugin.js.map +1 -1
- package/build/esm/vite/storageConfig.js +6 -2
- package/build/esm/vite/storageConfig.js.map +1 -1
- package/build/esm/vite/utils.js +21 -3
- package/build/esm/vite/utils.js.map +1 -1
- package/build/module/module.json +1 -1
- package/build/module/module.mjs +68 -30
- package/build/module/runtime/hooks/updateRouteBeforeResponse.d.ts +3 -1
- package/build/module/runtime/hooks/updateRouteBeforeResponse.js +7 -2
- package/build/module/runtime/hooks/wrapMiddlewareHandler.js +25 -15
- package/build/module/runtime/plugins/database-legacy.server.d.ts +5 -0
- package/build/module/runtime/plugins/database-legacy.server.js +6 -0
- package/build/module/runtime/plugins/database.server.d.ts +1 -1
- package/build/module/runtime/plugins/database.server.js +3 -147
- package/build/module/runtime/plugins/handler-legacy.server.d.ts +2 -0
- package/build/module/runtime/plugins/handler-legacy.server.js +4 -0
- package/build/module/runtime/plugins/handler.server.d.ts +6 -0
- package/build/module/runtime/plugins/handler.server.js +6 -0
- package/build/module/runtime/plugins/route-detector-legacy.server.d.ts +2 -0
- package/build/module/runtime/plugins/route-detector-legacy.server.js +37 -0
- package/build/module/runtime/plugins/route-detector.server.js +1 -1
- package/build/module/runtime/plugins/sentry.server.js +6 -31
- package/build/module/runtime/plugins/storage-legacy.server.d.ts +5 -0
- package/build/module/runtime/plugins/storage-legacy.server.js +6 -0
- package/build/module/runtime/plugins/storage.server.d.ts +4 -2
- package/build/module/runtime/plugins/storage.server.js +3 -168
- package/build/module/runtime/plugins/update-route-name-legacy.server.d.ts +2 -0
- package/build/module/runtime/plugins/update-route-name-legacy.server.js +4 -0
- package/build/module/runtime/plugins/update-route-name.server.d.ts +4 -0
- package/build/module/runtime/plugins/update-route-name.server.js +4 -0
- package/build/module/runtime/utils/database-span-data.d.ts +16 -2
- package/build/module/runtime/utils/instrumentDatabase.d.ts +9 -0
- package/build/module/runtime/utils/instrumentDatabase.js +147 -0
- package/build/module/runtime/utils/instrumentStorage.d.ts +7 -0
- package/build/module/runtime/utils/instrumentStorage.js +169 -0
- package/build/module/runtime/utils/patchEventHandler.d.ts +6 -0
- package/build/module/runtime/utils/patchEventHandler.js +25 -0
- package/build/types/module.d.ts.map +1 -1
- package/build/types/runtime/hooks/updateRouteBeforeResponse.d.ts +3 -1
- package/build/types/runtime/hooks/updateRouteBeforeResponse.d.ts.map +1 -1
- package/build/types/runtime/hooks/wrapMiddlewareHandler.d.ts.map +1 -1
- package/build/types/runtime/plugins/database-legacy.server.d.ts +6 -0
- package/build/types/runtime/plugins/database-legacy.server.d.ts.map +1 -0
- package/build/types/runtime/plugins/database.server.d.ts +1 -1
- package/build/types/runtime/plugins/database.server.d.ts.map +1 -1
- package/build/types/runtime/plugins/handler-legacy.server.d.ts +3 -0
- package/build/types/runtime/plugins/handler-legacy.server.d.ts.map +1 -0
- package/build/types/runtime/plugins/handler.server.d.ts +7 -0
- package/build/types/runtime/plugins/handler.server.d.ts.map +1 -0
- package/build/types/runtime/plugins/route-detector-legacy.server.d.ts +3 -0
- package/build/types/runtime/plugins/route-detector-legacy.server.d.ts.map +1 -0
- package/build/types/runtime/plugins/sentry.server.d.ts.map +1 -1
- package/build/types/runtime/plugins/storage-legacy.server.d.ts +6 -0
- package/build/types/runtime/plugins/storage-legacy.server.d.ts.map +1 -0
- package/build/types/runtime/plugins/storage.server.d.ts +4 -2
- package/build/types/runtime/plugins/storage.server.d.ts.map +1 -1
- package/build/types/runtime/plugins/update-route-name-legacy.server.d.ts +3 -0
- package/build/types/runtime/plugins/update-route-name-legacy.server.d.ts.map +1 -0
- package/build/types/runtime/plugins/update-route-name.server.d.ts +5 -0
- package/build/types/runtime/plugins/update-route-name.server.d.ts.map +1 -0
- package/build/types/runtime/utils/database-span-data.d.ts +16 -2
- package/build/types/runtime/utils/database-span-data.d.ts.map +1 -1
- package/build/types/runtime/utils/instrumentDatabase.d.ts +10 -0
- package/build/types/runtime/utils/instrumentDatabase.d.ts.map +1 -0
- package/build/types/runtime/utils/instrumentStorage.d.ts +8 -0
- package/build/types/runtime/utils/instrumentStorage.d.ts.map +1 -0
- package/build/types/runtime/utils/patchEventHandler.d.ts +7 -0
- package/build/types/runtime/utils/patchEventHandler.d.ts.map +1 -0
- package/build/types/runtime/utils.d.ts.map +1 -1
- package/build/types/vite/databaseConfig.d.ts +1 -1
- package/build/types/vite/databaseConfig.d.ts.map +1 -1
- package/build/types/vite/sentryVitePlugin.d.ts.map +1 -1
- package/build/types/vite/storageConfig.d.ts +1 -1
- package/build/types/vite/storageConfig.d.ts.map +1 -1
- package/build/types/vite/utils.d.ts +6 -1
- package/build/types/vite/utils.d.ts.map +1 -1
- package/package.json +16 -8
package/build/cjs/module.js
CHANGED
|
@@ -18,7 +18,7 @@ const module$1 = kit.defineNuxtModule({
|
|
|
18
18
|
},
|
|
19
19
|
},
|
|
20
20
|
defaults: {},
|
|
21
|
-
setup(moduleOptionsParam, nuxt) {
|
|
21
|
+
async setup(moduleOptionsParam, nuxt) {
|
|
22
22
|
if (moduleOptionsParam?.enabled === false) {
|
|
23
23
|
return;
|
|
24
24
|
}
|
|
@@ -68,47 +68,66 @@ const module$1 = kit.defineNuxtModule({
|
|
|
68
68
|
}
|
|
69
69
|
|
|
70
70
|
const serverConfigFile = utils.findDefaultSdkInitFile('server', nuxt);
|
|
71
|
+
const isNitroV3 = (await utils.getNitroMajorVersion()) >= 3;
|
|
72
|
+
const nuxtMajor = parseInt((nuxt )._version?.split('.')[0] ?? '3', 10);
|
|
73
|
+
const isMinNuxtV4 = nuxtMajor >= 4;
|
|
71
74
|
|
|
72
75
|
if (serverConfigFile) {
|
|
76
|
+
if (isNitroV3) {
|
|
77
|
+
kit.addServerPlugin(moduleDirResolver.resolve('./runtime/plugins/handler.server'));
|
|
78
|
+
kit.addServerPlugin(moduleDirResolver.resolve('./runtime/plugins/update-route-name.server'));
|
|
79
|
+
} else {
|
|
80
|
+
kit.addServerPlugin(moduleDirResolver.resolve('./runtime/plugins/handler-legacy.server'));
|
|
81
|
+
kit.addServerPlugin(moduleDirResolver.resolve('./runtime/plugins/update-route-name-legacy.server'));
|
|
82
|
+
}
|
|
83
|
+
|
|
73
84
|
kit.addServerPlugin(moduleDirResolver.resolve('./runtime/plugins/sentry.server'));
|
|
74
85
|
|
|
75
|
-
|
|
76
|
-
src: moduleDirResolver.resolve('./runtime/plugins/route-detector.server'),
|
|
77
|
-
|
|
78
|
-
|
|
86
|
+
if (isMinNuxtV4) {
|
|
87
|
+
kit.addPlugin({ src: moduleDirResolver.resolve('./runtime/plugins/route-detector.server'), mode: 'server' });
|
|
88
|
+
} else {
|
|
89
|
+
kit.addPlugin({ src: moduleDirResolver.resolve('./runtime/plugins/route-detector-legacy.server'), mode: 'server' });
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
// Preps the middleware instrumentation module.
|
|
93
|
+
middlewareConfig.addMiddlewareImports();
|
|
94
|
+
storageConfig.addStorageInstrumentation(nuxt, !isNitroV3);
|
|
95
|
+
databaseConfig.addDatabaseInstrumentation(nuxt.options.nitro, !isNitroV3, moduleOptions);
|
|
79
96
|
}
|
|
80
97
|
|
|
81
98
|
if (clientConfigFile || serverConfigFile) {
|
|
82
99
|
sourceMaps.setupSourceMaps(moduleOptions, nuxt, kit.addVitePlugin);
|
|
83
100
|
}
|
|
84
101
|
|
|
85
|
-
utils.addOTelCommonJSImportAlias(nuxt);
|
|
102
|
+
utils.addOTelCommonJSImportAlias(nuxt, isNitroV3);
|
|
86
103
|
|
|
87
|
-
|
|
88
|
-
filename: 'sentry--nuxt-pages-data.mjs',
|
|
89
|
-
// Initial empty array (later filled in pages:extend hook)
|
|
90
|
-
// Template needs to be created in the root-level of the module to work
|
|
91
|
-
getContents: () => 'export default [];',
|
|
92
|
-
});
|
|
104
|
+
let pagesData = [];
|
|
93
105
|
|
|
94
106
|
nuxt.hooks.hook('pages:extend', pages => {
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
.
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
});
|
|
102
|
-
|
|
103
|
-
return `export default ${JSON.stringify(pagesSubset, null, 2)};`;
|
|
104
|
-
};
|
|
107
|
+
pagesData = pages
|
|
108
|
+
.map(page => ({ file: page.file, path: page.path }))
|
|
109
|
+
.filter(page => {
|
|
110
|
+
// Check for dynamic parameter (e.g., :userId or [userId])
|
|
111
|
+
return page.path.includes(':') || page?.file?.includes('[');
|
|
112
|
+
});
|
|
105
113
|
});
|
|
106
114
|
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
115
|
+
if (isMinNuxtV4) {
|
|
116
|
+
const pagesDataVirtualModuleId = '#sentry/nuxt-pages-data.mjs';
|
|
117
|
+
|
|
118
|
+
// Vite virtual plugin (for the Vite SSR build, where addPlugin mode:'server' plugins are bundled)
|
|
119
|
+
kit.addVitePlugin({
|
|
120
|
+
name: 'sentry-nuxt-pages-data-virtual',
|
|
121
|
+
resolveId: id => (id === pagesDataVirtualModuleId ? `\0${pagesDataVirtualModuleId}` : null),
|
|
122
|
+
load: id =>
|
|
123
|
+
id === `\0${pagesDataVirtualModuleId}` ? `export default ${JSON.stringify(pagesData, null, 2)};` : undefined,
|
|
124
|
+
});
|
|
125
|
+
} else {
|
|
126
|
+
// Nuxt v3: register as a build template (accessible via #build/)
|
|
127
|
+
kit.addTemplate({
|
|
128
|
+
filename: 'sentry--nuxt-pages-data.mjs',
|
|
129
|
+
getContents: () => `export default ${JSON.stringify(pagesData, null, 2)};`,
|
|
130
|
+
});
|
|
112
131
|
}
|
|
113
132
|
|
|
114
133
|
// Add the sentry config file to the include array
|
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';\nimport { consoleSandbox } from '@sentry/core';\nimport * as path from 'path';\nimport type { SentryNuxtModuleOptions } from './common/types';\nimport { addDynamicImportEntryFileWrapper, addSentryTopImport, addServerConfigToBuild } from './vite/addServerConfig';\nimport { addDatabaseInstrumentation } from './vite/databaseConfig';\nimport { addMiddlewareImports, addMiddlewareInstrumentation } from './vite/middlewareConfig';\nimport { setupSourceMaps } from './vite/sourceMaps';\nimport { addStorageInstrumentation } from './vite/storageConfig';\nimport { addOTelCommonJSImportAlias, findDefaultSdkInitFile } from './vite/utils';\n\nexport type ModuleOptions = SentryNuxtModuleOptions;\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 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 = findDefaultSdkInitFile('client', nuxt);\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 = findDefaultSdkInitFile('server', nuxt);\n\n if (serverConfigFile) {\n addServerPlugin(moduleDirResolver.resolve('./runtime/plugins/sentry.server'));\n\n addPlugin({\n src: moduleDirResolver.resolve('./runtime/plugins/route-detector.server'),\n mode: 'server',\n });\n }\n\n if (clientConfigFile || serverConfigFile) {\n setupSourceMaps(moduleOptions, nuxt, addVitePlugin);\n }\n\n addOTelCommonJSImportAlias(nuxt);\n\n const pagesDataTemplate = addTemplate({\n filename: 'sentry--nuxt-pages-data.mjs',\n // Initial empty array (later filled in pages:extend hook)\n // Template needs to be created in the root-level of the module to work\n getContents: () => 'export default [];',\n });\n\n nuxt.hooks.hook('pages:extend', pages => {\n pagesDataTemplate.getContents = () => {\n const pagesSubset = 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 return `export default ${JSON.stringify(pagesSubset, null, 2)};`;\n };\n });\n\n // Preps the the middleware instrumentation module.\n if (serverConfigFile) {\n addMiddlewareImports();\n addStorageInstrumentation(nuxt);\n addDatabaseInstrumentation(nuxt.options.nitro, moduleOptions);\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\n if (serverConfigFile?.includes('.server.config')) {\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 addServerConfigToBuild(moduleOptions, nitro, serverConfigFile);\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 = `.${path.sep}${path.relative(nitro.options.rootDir, serverConfigPath)}`;\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 ${serverConfigRelativePath}' nuxt dev\\`. The file is generated in the build directory (usually '.nuxt'). If you delete the build directory, run \\`nuxt dev\\` 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","addServerPlugin","setupSourceMaps","addVitePlugin","addOTelCommonJSImportAlias","addTemplate","addMiddlewareImports","addStorageInstrumentation","addDatabaseInstrumentation","addMiddlewareInstrumentation","consoleSandbox","addServerConfigToBuild","addSentryTopImport","addDynamicImportEntryFileWrapper"],"mappings":";;;;;;;;;;;AAqBA,iBAAeA,oBAAgB,CAAgB;AAC/C,EAAE,IAAI,EAAE;AACR,IAAI,IAAI,EAAE,qBAAqB;AAC/B,IAAI,SAAS,EAAE,QAAQ;AACvB,IAAI,aAAa,EAAE;AACnB,MAAM,IAAI,EAAE,SAAS;AACrB,KAAK;AACL,GAAG;AACH,EAAE,QAAQ,EAAE,EAAE;AACd,EAAE,KAAK,CAAC,kBAAkB,EAAE,IAAI,EAAE;AAClC,IAAI,IAAI,kBAAkB,EAAE,OAAA,KAAY,KAAK,EAAE;AAC/C,MAAM;AACN,IAAI;;AAEJ,IAAI,MAAM,gBAAgB;AAC1B,MAAM,GAAG,kBAAkB;AAC3B,MAAM,sBAAsB,EAAE,kBAAkB,CAAC,sBAAsB;AACvE,MAAM,uCAAuC,EAAE,kBAAkB,CAAC,2CAA2C;AAC7G,QAAQ,SAAS;AACjB,QAAQ,SAAS;AACjB,QAAQ,QAAQ;AAChB,OAAO;AACP,KAAK;;AAEL,IAAI,MAAM,iBAAA,GAAoBC,kBAAc,CAAC,2PAAe,CAAC;AAC7D,IAAI,MAAM,gBAAA,GAAmBA,kBAAc,CAAC,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC;;AAElE,IAAI,MAAM,mBAAmBC,4BAAsB,CAAC,QAAQ,EAAE,IAAI,CAAC;;AAEnE,IAAI,IAAI,gBAAgB,EAAE;AAC1B;AACA,MAAMC,qBAAiB,CAAC;AACxB,QAAQ,IAAI,EAAE,QAAQ;AACtB,QAAQ,QAAQ,EAAE,0BAA0B;AAC5C,QAAQ,KAAK,EAAE,CAAC;;AAEhB;AACA;AACA,QAAQ,WAAW,EAAE,MAAM;AAC3B;;AAEA;AACA;A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;AACA;AACA,cAAA,OAAA,CAAA,GAAA;AACA,gBAAA,CAAA,iBAAA,EAAA,gBAAA,CAAA,sSAAA,CAAA;AACA,eAAA;;AAEA,cAAA,IAAA,KAAA,CAAA,OAAA,CAAA,GAAA,EAAA;AACA;AACA,gBAAA,OAAA,CAAA,GAAA;AACA,kBAAA,CAAA,iHAAA,EAAA,wBAAA,CAAA,mJAAA,CAAA;AACA,iBAAA;AACA,cAAA,CAAA,MAAA;AACA;AACA,gBAAA,OAAA,CAAA,GAAA;AACA,kBAAA,CAAA,sGAAA,EAAA,wBAAA,CAAA,mEAAA,EAAA,wBAAA,CAAA,gBAAA,CAAA;AACA,iBAAA;AACA,cAAA;AACA,YAAA,CAAA,CAAA;AACA,UAAA;AACA,QAAA;;AAEA,QAAA,IAAA,aAAA,CAAA,sBAAA,KAAA,kBAAA,EAAA;AACA,UAAAE,kCAAA,CAAA,aAAA,EAAA,KAAA,CAAA;AACA,QAAA;;AAEA,QAAA,IAAA,aAAA,CAAA,sBAAA,KAAA,6BAAA,EAAA;AACA,UAAAC,gDAAA,CAAA,KAAA,EAAA,gBAAA,EAAA,aAAA,CAAA;;AAEA,UAAA,IAAA,aAAA,CAAA,KAAA,EAAA;AACA,YAAAH,mBAAA,CAAA,MAAA;AACA;AACA,cAAA,OAAA,CAAA,GAAA;AACA,gBAAA,8HAAA;AACA,eAAA;AACA,YAAA,CAAA,CAAA;AACA,UAAA;AACA,QAAA;AACA,MAAA;AACA,IAAA,CAAA,CAAA;AACA,EAAA,CAAA;AACA,CAAA,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';\nimport { consoleSandbox } from '@sentry/core';\nimport * as path from 'path';\nimport type { SentryNuxtModuleOptions } from './common/types';\nimport { addDynamicImportEntryFileWrapper, addSentryTopImport, addServerConfigToBuild } from './vite/addServerConfig';\nimport { addDatabaseInstrumentation } from './vite/databaseConfig';\nimport { addMiddlewareImports, addMiddlewareInstrumentation } from './vite/middlewareConfig';\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 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 = findDefaultSdkInitFile('client', nuxt);\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 = findDefaultSdkInitFile('server', nuxt);\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 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\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\n if (serverConfigFile?.includes('.server.config')) {\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 addServerConfigToBuild(moduleOptions, nitro, serverConfigFile);\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 = `.${path.sep}${path.relative(nitro.options.rootDir, serverConfigPath)}`;\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 ${serverConfigRelativePath}' nuxt dev\\`. The file is generated in the build directory (usually '.nuxt'). If you delete the build directory, run \\`nuxt dev\\` 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","addServerPlugin","addMiddlewareImports","addStorageInstrumentation","addDatabaseInstrumentation","setupSourceMaps","addVitePlugin","addOTelCommonJSImportAlias","addTemplate","addMiddlewareInstrumentation","consoleSandbox","addServerConfigToBuild","addSentryTopImport","addDynamicImportEntryFileWrapper"],"mappings":";;;;;;;;;;;AAsBA,iBAAeA,oBAAgB,CAAgB;AAC/C,EAAE,IAAI,EAAE;AACR,IAAI,IAAI,EAAE,qBAAqB;AAC/B,IAAI,SAAS,EAAE,QAAQ;AACvB,IAAI,aAAa,EAAE;AACnB,MAAM,IAAI,EAAE,SAAS;AACrB,KAAK;AACL,GAAG;AACH,EAAE,QAAQ,EAAE,EAAE;AACd,EAAE,MAAM,KAAK,CAAC,kBAAkB,EAAE,IAAI,EAAE;AACxC,IAAI,IAAI,kBAAkB,EAAE,OAAA,KAAY,KAAK,EAAE;AAC/C,MAAM;AACN,IAAI;;AAEJ,IAAI,MAAM,gBAAgB;AAC1B,MAAM,GAAG,kBAAkB;AAC3B,MAAM,sBAAsB,EAAE,kBAAkB,CAAC,sBAAsB;AACvE,MAAM,uCAAuC,EAAE,kBAAkB,CAAC,2CAA2C;AAC7G,QAAQ,SAAS;AACjB,QAAQ,SAAS;AACjB,QAAQ,QAAQ;AAChB,OAAO;AACP,KAAK;;AAEL,IAAI,MAAM,iBAAA,GAAoBC,kBAAc,CAAC,2PAAe,CAAC;AAC7D,IAAI,MAAM,gBAAA,GAAmBA,kBAAc,CAAC,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC;;AAElE,IAAI,MAAM,mBAAmBC,4BAAsB,CAAC,QAAQ,EAAE,IAAI,CAAC;;AAEnE,IAAI,IAAI,gBAAgB,EAAE;AAC1B;AACA,MAAMC,qBAAiB,CAAC;AACxB,QAAQ,IAAI,EAAE,QAAQ;AACtB,QAAQ,QAAQ,EAAE,0BAA0B;AAC5C,QAAQ,KAAK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CAAA;;AAEA,YAAAc,mBAAA,CAAA,MAAA;AACA;AACA,cAAA,OAAA,CAAA,GAAA;AACA,gBAAA,CAAA,iBAAA,EAAA,gBAAA,CAAA,sSAAA,CAAA;AACA,eAAA;;AAEA,cAAA,IAAA,KAAA,CAAA,OAAA,CAAA,GAAA,EAAA;AACA;AACA,gBAAA,OAAA,CAAA,GAAA;AACA,kBAAA,CAAA,iHAAA,EAAA,wBAAA,CAAA,mJAAA,CAAA;AACA,iBAAA;AACA,cAAA,CAAA,MAAA;AACA;AACA,gBAAA,OAAA,CAAA,GAAA;AACA,kBAAA,CAAA,sGAAA,EAAA,wBAAA,CAAA,mEAAA,EAAA,wBAAA,CAAA,gBAAA,CAAA;AACA,iBAAA;AACA,cAAA;AACA,YAAA,CAAA,CAAA;AACA,UAAA;AACA,QAAA;;AAEA,QAAA,IAAA,aAAA,CAAA,sBAAA,KAAA,kBAAA,EAAA;AACA,UAAAE,kCAAA,CAAA,aAAA,EAAA,KAAA,CAAA;AACA,QAAA;;AAEA,QAAA,IAAA,aAAA,CAAA,sBAAA,KAAA,6BAAA,EAAA;AACA,UAAAC,gDAAA,CAAA,KAAA,EAAA,gBAAA,EAAA,aAAA,CAAA;;AAEA,UAAA,IAAA,aAAA,CAAA,KAAA,EAAA;AACA,YAAAH,mBAAA,CAAA,MAAA;AACA;AACA,cAAA,OAAA,CAAA,GAAA;AACA,gBAAA,8HAAA;AACA,eAAA;AACA,YAAA,CAAA,CAAA;AACA,UAAA;AACA,QAAA;AACA,MAAA;AACA,IAAA,CAAA,CAAA;AACA,EAAA,CAAA;AACA,CAAA,CAAA;;;;"}
|
|
@@ -8,7 +8,11 @@ var _documentCurrentScript = typeof document !== 'undefined' ? document.currentS
|
|
|
8
8
|
/**
|
|
9
9
|
* Sets up the database instrumentation.
|
|
10
10
|
*/
|
|
11
|
-
function addDatabaseInstrumentation(
|
|
11
|
+
function addDatabaseInstrumentation(
|
|
12
|
+
nitro,
|
|
13
|
+
isLegacyNitro,
|
|
14
|
+
moduleOptions,
|
|
15
|
+
) {
|
|
12
16
|
if (!nitro.experimental?.database) {
|
|
13
17
|
// We cannot use DEBUG_BUILD here because it is a runtime flag, so it is not available for build time scripts
|
|
14
18
|
// So we have to pass in the module options to the build time script
|
|
@@ -39,7 +43,11 @@ function addDatabaseInstrumentation(nitro, moduleOptions) {
|
|
|
39
43
|
},
|
|
40
44
|
});
|
|
41
45
|
|
|
42
|
-
|
|
46
|
+
if (isLegacyNitro) {
|
|
47
|
+
kit.addServerPlugin(kit.createResolver((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('vite/databaseConfig.js', document.baseURI).href))).resolve('./runtime/plugins/database-legacy.server'));
|
|
48
|
+
} else {
|
|
49
|
+
kit.addServerPlugin(kit.createResolver((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('vite/databaseConfig.js', document.baseURI).href))).resolve('./runtime/plugins/database.server'));
|
|
50
|
+
}
|
|
43
51
|
}
|
|
44
52
|
|
|
45
53
|
exports.addDatabaseInstrumentation = addDatabaseInstrumentation;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"databaseConfig.js","sources":["../../../src/vite/databaseConfig.ts"],"sourcesContent":["import { addServerPlugin, createResolver } from '@nuxt/kit';\nimport { consoleSandbox } from '@sentry/core';\nimport type { NitroConfig } from 'nitropack/types';\nimport type { SentryNuxtModuleOptions } from '../common/types';\nimport { addServerTemplate } from '../vendor/server-template';\n\n/**\n * Sets up the database instrumentation.\n */\nexport function addDatabaseInstrumentation(nitro: NitroConfig
|
|
1
|
+
{"version":3,"file":"databaseConfig.js","sources":["../../../src/vite/databaseConfig.ts"],"sourcesContent":["import { addServerPlugin, createResolver } from '@nuxt/kit';\nimport { consoleSandbox } from '@sentry/core';\nimport type { NitroConfig } from 'nitropack/types';\nimport type { SentryNuxtModuleOptions } from '../common/types';\nimport { addServerTemplate } from '../vendor/server-template';\n\n/**\n * Sets up the database instrumentation.\n */\nexport function addDatabaseInstrumentation(\n nitro: NitroConfig,\n isLegacyNitro: boolean,\n moduleOptions?: SentryNuxtModuleOptions,\n): void {\n if (!nitro.experimental?.database) {\n // We cannot use DEBUG_BUILD here because it is a runtime flag, so it is not available for build time scripts\n // So we have to pass in the module options to the build time script\n moduleOptions?.debug &&\n consoleSandbox(() => {\n // eslint-disable-next-line no-console\n console.log(\n '[Sentry] [Nitro Database Plugin]: No database configuration found. Skipping database instrumentation.',\n );\n });\n\n return;\n }\n\n /**\n * This is a different option than the one in `experimental.database`, this configures multiple database instances.\n * keys represent database names to be passed to `useDatabase(name?)`.\n * We also use the config to populate database span attributes.\n * https://nitro.build/guide/database#configuration\n */\n const databaseConfig = nitro.database || { default: {} };\n\n // Create a virtual module to pass this data to runtime\n addServerTemplate({\n filename: '#sentry/database-config.mjs',\n getContents: () => {\n return `export const databaseConfig = ${JSON.stringify(databaseConfig)};`;\n },\n });\n\n if (isLegacyNitro) {\n addServerPlugin(createResolver(import.meta.url).resolve('./runtime/plugins/database-legacy.server'));\n } else {\n addServerPlugin(createResolver(import.meta.url).resolve('./runtime/plugins/database.server'));\n }\n}\n"],"names":["consoleSandbox","addServerTemplate","addServerPlugin","createResolver"],"mappings":";;;;;;;AAMA;AACA;AACA;AACO,SAAS,0BAA0B;AAC1C,EAAE,KAAK;AACP,EAAE,aAAa;AACf,EAAE,aAAa;AACf,EAAQ;AACR,EAAE,IAAI,CAAC,KAAK,CAAC,YAAY,EAAE,QAAQ,EAAE;AACrC;AACA;AACA,IAAI,aAAa,EAAE,KAAA;AACnB,MAAMA,mBAAc,CAAC,MAAM;AAC3B;AACA,QAAQ,OAAO,CAAC,GAAG;AACnB,UAAU,uGAAuG;AACjH,SAAS;AACT,MAAM,CAAC,CAAC;;AAER,IAAI;AACJ,EAAE;;AAEF;AACA;AACA;AACA;AACA;AACA;AACA,EAAE,MAAM,cAAA,GAAiB,KAAK,CAAC,QAAA,IAAY,EAAE,OAAO,EAAE,EAAC,EAAG;;AAE1D;AACA,EAAEC,gCAAiB,CAAC;AACpB,IAAI,QAAQ,EAAE,6BAA6B;AAC3C,IAAI,WAAW,EAAE,MAAM;AACvB,MAAM,OAAO,CAAC,8BAA8B,EAAE,IAAI,CAAC,SAAS,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC;AAC/E,IAAI,CAAC;AACL,GAAG,CAAC;;AAEJ,EAAE,IAAI,aAAa,EAAE;AACrB,IAAIC,mBAAe,CAACC,kBAAc,CAAC,wQAAe,CAAC,CAAC,OAAO,CAAC,0CAA0C,CAAC,CAAC;AACxG,EAAE,OAAO;AACT,IAAID,mBAAe,CAACC,kBAAc,CAAC,wQAAe,CAAC,CAAC,OAAO,CAAC,mCAAmC,CAAC,CAAC;AACjG,EAAE;AACF;;;;"}
|
|
@@ -91,9 +91,14 @@ function instrumentedEventHandler(handlerOrObject) {
|
|
|
91
91
|
return eventHandler(wrapMiddlewareHandlerWithSentry(handlerOrObject, '${cleanFileName}'));
|
|
92
92
|
}
|
|
93
93
|
|
|
94
|
+
function defineInstrumentedHandler(handlerOrObject) {
|
|
95
|
+
return defineHandler(wrapMiddlewareHandlerWithSentry(handlerOrObject, '${cleanFileName}'));
|
|
96
|
+
}
|
|
97
|
+
|
|
94
98
|
${originalCode
|
|
95
99
|
.replace(/defineEventHandler\(/g, 'defineInstrumentedEventHandler(')
|
|
96
|
-
.replace(/eventHandler\(/g, 'instrumentedEventHandler(')
|
|
100
|
+
.replace(/eventHandler\(/g, 'instrumentedEventHandler(')
|
|
101
|
+
.replace(/defineHandler\(/g, 'defineInstrumentedHandler(')}
|
|
97
102
|
`;
|
|
98
103
|
}
|
|
99
104
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"middlewareConfig.js","sources":["../../../src/vite/middlewareConfig.ts"],"sourcesContent":["import { addServerImports, createResolver } from '@nuxt/kit';\nimport type { Nitro } from 'nitropack/types';\nimport * as path from 'path';\nimport type { InputPluginOption } from 'rollup';\n\n/**\n * Adds a server import for the middleware instrumentation.\n */\nexport function addMiddlewareImports(): void {\n addServerImports([\n {\n name: 'wrapMiddlewareHandlerWithSentry',\n from: createResolver(import.meta.url).resolve('./runtime/hooks/wrapMiddlewareHandler'),\n },\n ]);\n}\n\n/**\n * Adds middleware instrumentation to the Nitro build.\n *\n * @param nitro Nitro instance\n */\nexport function addMiddlewareInstrumentation(nitro: Nitro): void {\n nitro.hooks.hook('rollup:before', (nitro, rollupConfig) => {\n if (!rollupConfig.plugins) {\n rollupConfig.plugins = [];\n }\n\n if (!Array.isArray(rollupConfig.plugins)) {\n rollupConfig.plugins = [rollupConfig.plugins];\n }\n\n rollupConfig.plugins.push(middlewareInstrumentationPlugin(nitro));\n });\n}\n\n/**\n * Creates a rollup plugin for the middleware instrumentation by transforming the middleware code.\n *\n * @param nitro Nitro instance\n * @returns The rollup plugin for the middleware instrumentation.\n */\nfunction middlewareInstrumentationPlugin(nitro: Nitro): InputPluginOption {\n const middlewareFiles = new Set<string>();\n\n return {\n name: 'sentry-nuxt-middleware-instrumentation',\n buildStart() {\n // Collect middleware files during build start\n nitro.scannedHandlers?.forEach(({ middleware, handler }) => {\n if (middleware && handler) {\n middlewareFiles.add(handler);\n }\n });\n },\n transform(code: string, id: string) {\n // Only transform files we've identified as middleware\n if (middlewareFiles.has(id)) {\n const fileName = path.basename(id);\n return {\n code: wrapMiddlewareCode(code, fileName),\n map: null,\n };\n }\n return null;\n },\n };\n}\n\n/**\n * Wraps the middleware user code to instrument it.\n *\n * @param originalCode The original user code of the middleware.\n * @param fileName The name of the middleware file, used for the span name and logging.\n *\n * @returns The wrapped user code of the middleware.\n */\nfunction wrapMiddlewareCode(originalCode: string, fileName: string): string {\n // Remove common file extensions\n const cleanFileName = fileName.replace(/\\.(ts|js|mjs|mts|cts)$/, '');\n\n return `\nimport { wrapMiddlewareHandlerWithSentry } from '#imports';\n\nfunction defineInstrumentedEventHandler(handlerOrObject) {\n return defineEventHandler(wrapMiddlewareHandlerWithSentry(handlerOrObject, '${cleanFileName}'));\n}\n\nfunction instrumentedEventHandler(handlerOrObject) {\n return eventHandler(wrapMiddlewareHandlerWithSentry(handlerOrObject, '${cleanFileName}'));\n}\n\n${originalCode\n .replace(/defineEventHandler\\(/g, 'defineInstrumentedEventHandler(')\n .replace(/eventHandler\\(/g, 'instrumentedEventHandler(')}\n`;\n}\n"],"names":["addServerImports","createResolver"],"mappings":";;;;;;AAKA;AACA;AACA;AACO,SAAS,oBAAoB,GAAS;AAC7C,EAAEA,oBAAgB,CAAC;AACnB,IAAI;AACJ,MAAM,IAAI,EAAE,iCAAiC;AAC7C,MAAM,IAAI,EAAEC,kBAAc,CAAC,0QAAe,CAAC,CAAC,OAAO,CAAC,uCAAuC,CAAC;AAC5F,KAAK;AACL,GAAG,CAAC;AACJ;;AAEA;AACA;AACA;AACA;AACA;AACO,SAAS,4BAA4B,CAAC,KAAK,EAAe;AACjE,EAAE,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,eAAe,EAAE,CAAC,KAAK,EAAE,YAAY,KAAK;AAC7D,IAAI,IAAI,CAAC,YAAY,CAAC,OAAO,EAAE;AAC/B,MAAM,YAAY,CAAC,OAAA,GAAU,EAAE;AAC/B,IAAI;;AAEJ,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,YAAY,CAAC,OAAO,CAAC,EAAE;AAC9C,MAAM,YAAY,CAAC,OAAA,GAAU,CAAC,YAAY,CAAC,OAAO,CAAC;AACnD,IAAI;;AAEJ,IAAI,YAAY,CAAC,OAAO,CAAC,IAAI,CAAC,+BAA+B,CAAC,KAAK,CAAC,CAAC;AACrE,EAAE,CAAC,CAAC;AACJ;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA,SAAS,+BAA+B,CAAC,KAAK,EAA4B;AAC1E,EAAE,MAAM,eAAA,GAAkB,IAAI,GAAG,EAAU;;AAE3C,EAAE,OAAO;AACT,IAAI,IAAI,EAAE,wCAAwC;AAClD,IAAI,UAAU,GAAG;AACjB;AACA,MAAM,KAAK,CAAC,eAAe,EAAE,OAAO,CAAC,CAAC,EAAE,UAAU,EAAE,OAAA,EAAS,KAAK;AAClE,QAAQ,IAAI,UAAA,IAAc,OAAO,EAAE;AACnC,UAAU,eAAe,CAAC,GAAG,CAAC,OAAO,CAAC;AACtC,QAAQ;AACR,MAAM,CAAC,CAAC;AACR,IAAI,CAAC;AACL,IAAI,SAAS,CAAC,IAAI,EAAU,EAAE,EAAU;AACxC;AACA,MAAM,IAAI,eAAe,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE;AACnC,QAAQ,MAAM,WAAW,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC;AAC1C,QAAQ,OAAO;AACf,UAAU,IAAI,EAAE,kBAAkB,CAAC,IAAI,EAAE,QAAQ,CAAC;AAClD,UAAU,GAAG,EAAE,IAAI;AACnB,SAAS;AACT,MAAM;AACN,MAAM,OAAO,IAAI;AACjB,IAAI,CAAC;AACL,GAAG;AACH;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAAS,kBAAkB,CAAC,YAAY,EAAU,QAAQ,EAAkB;AAC5E;AACA,EAAE,MAAM,aAAA,GAAgB,QAAQ,CAAC,OAAO,CAAC,wBAAwB,EAAE,EAAE,CAAC;;AAEtE,EAAE,OAAO;AACT;;AAEA;AACA,8EAA8E,EAAE,aAAa,CAAC;AAC9F;;AAEA;AACA,wEAAwE,EAAE,aAAa,CAAC;AACxF;;AAEA,EAAE;AACF,GAAG,OAAO,CAAC,uBAAuB,EAAE,iCAAiC;AACrE,GAAG,OAAO,CAAC,iBAAiB,EAAE,2BAA2B,CAAC;
|
|
1
|
+
{"version":3,"file":"middlewareConfig.js","sources":["../../../src/vite/middlewareConfig.ts"],"sourcesContent":["import { addServerImports, createResolver } from '@nuxt/kit';\nimport type { Nitro } from 'nitropack/types';\nimport * as path from 'path';\nimport type { InputPluginOption } from 'rollup';\n\n/**\n * Adds a server import for the middleware instrumentation.\n */\nexport function addMiddlewareImports(): void {\n addServerImports([\n {\n name: 'wrapMiddlewareHandlerWithSentry',\n from: createResolver(import.meta.url).resolve('./runtime/hooks/wrapMiddlewareHandler'),\n },\n ]);\n}\n\n/**\n * Adds middleware instrumentation to the Nitro build.\n *\n * @param nitro Nitro instance\n */\nexport function addMiddlewareInstrumentation(nitro: Nitro): void {\n nitro.hooks.hook('rollup:before', (nitro, rollupConfig) => {\n if (!rollupConfig.plugins) {\n rollupConfig.plugins = [];\n }\n\n if (!Array.isArray(rollupConfig.plugins)) {\n rollupConfig.plugins = [rollupConfig.plugins];\n }\n\n rollupConfig.plugins.push(middlewareInstrumentationPlugin(nitro));\n });\n}\n\n/**\n * Creates a rollup plugin for the middleware instrumentation by transforming the middleware code.\n *\n * @param nitro Nitro instance\n * @returns The rollup plugin for the middleware instrumentation.\n */\nfunction middlewareInstrumentationPlugin(nitro: Nitro): InputPluginOption {\n const middlewareFiles = new Set<string>();\n\n return {\n name: 'sentry-nuxt-middleware-instrumentation',\n buildStart() {\n // Collect middleware files during build start\n nitro.scannedHandlers?.forEach(({ middleware, handler }) => {\n if (middleware && handler) {\n middlewareFiles.add(handler);\n }\n });\n },\n transform(code: string, id: string) {\n // Only transform files we've identified as middleware\n if (middlewareFiles.has(id)) {\n const fileName = path.basename(id);\n return {\n code: wrapMiddlewareCode(code, fileName),\n map: null,\n };\n }\n return null;\n },\n };\n}\n\n/**\n * Wraps the middleware user code to instrument it.\n *\n * @param originalCode The original user code of the middleware.\n * @param fileName The name of the middleware file, used for the span name and logging.\n *\n * @returns The wrapped user code of the middleware.\n */\nfunction wrapMiddlewareCode(originalCode: string, fileName: string): string {\n // Remove common file extensions\n const cleanFileName = fileName.replace(/\\.(ts|js|mjs|mts|cts)$/, '');\n\n return `\nimport { wrapMiddlewareHandlerWithSentry } from '#imports';\n\nfunction defineInstrumentedEventHandler(handlerOrObject) {\n return defineEventHandler(wrapMiddlewareHandlerWithSentry(handlerOrObject, '${cleanFileName}'));\n}\n\nfunction instrumentedEventHandler(handlerOrObject) {\n return eventHandler(wrapMiddlewareHandlerWithSentry(handlerOrObject, '${cleanFileName}'));\n}\n\nfunction defineInstrumentedHandler(handlerOrObject) {\n return defineHandler(wrapMiddlewareHandlerWithSentry(handlerOrObject, '${cleanFileName}'));\n}\n\n${originalCode\n .replace(/defineEventHandler\\(/g, 'defineInstrumentedEventHandler(')\n .replace(/eventHandler\\(/g, 'instrumentedEventHandler(')\n .replace(/defineHandler\\(/g, 'defineInstrumentedHandler(')}\n`;\n}\n"],"names":["addServerImports","createResolver"],"mappings":";;;;;;AAKA;AACA;AACA;AACO,SAAS,oBAAoB,GAAS;AAC7C,EAAEA,oBAAgB,CAAC;AACnB,IAAI;AACJ,MAAM,IAAI,EAAE,iCAAiC;AAC7C,MAAM,IAAI,EAAEC,kBAAc,CAAC,0QAAe,CAAC,CAAC,OAAO,CAAC,uCAAuC,CAAC;AAC5F,KAAK;AACL,GAAG,CAAC;AACJ;;AAEA;AACA;AACA;AACA;AACA;AACO,SAAS,4BAA4B,CAAC,KAAK,EAAe;AACjE,EAAE,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,eAAe,EAAE,CAAC,KAAK,EAAE,YAAY,KAAK;AAC7D,IAAI,IAAI,CAAC,YAAY,CAAC,OAAO,EAAE;AAC/B,MAAM,YAAY,CAAC,OAAA,GAAU,EAAE;AAC/B,IAAI;;AAEJ,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,YAAY,CAAC,OAAO,CAAC,EAAE;AAC9C,MAAM,YAAY,CAAC,OAAA,GAAU,CAAC,YAAY,CAAC,OAAO,CAAC;AACnD,IAAI;;AAEJ,IAAI,YAAY,CAAC,OAAO,CAAC,IAAI,CAAC,+BAA+B,CAAC,KAAK,CAAC,CAAC;AACrE,EAAE,CAAC,CA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AAC,iBAAiB,EAAE,2BAA2B;AACzD,GAAG,OAAO,CAAC,kBAAkB,EAAE,4BAA4B,CAAC;AAC5D,CAAC;AACD;;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sentryVitePlugin.js","sources":["../../../src/vite/sentryVitePlugin.ts"],"sourcesContent":["import type { Nuxt } from '@nuxt/schema';\nimport
|
|
1
|
+
{"version":3,"file":"sentryVitePlugin.js","sources":["../../../src/vite/sentryVitePlugin.ts"],"sourcesContent":["import type { Nuxt } from '@nuxt/schema';\nimport type { ConfigEnv, Plugin, UserConfig } from 'vite';\nimport type { SentryNuxtModuleOptions } from '../common/types';\nimport { extractNuxtSourceMapSetting, validateDifferentSourceMapSettings } from './sourceMaps';\n\n/**\n * Creates a Vite plugin that adds the Sentry Vite plugin and validates source map settings.\n */\nexport function validateSourceMapsOptionsPlugin(options: {\n nuxt: Nuxt;\n moduleOptions: SentryNuxtModuleOptions;\n sourceMapsEnabled: boolean;\n}): Plugin {\n const { nuxt, moduleOptions, sourceMapsEnabled } = options;\n const isDebug = moduleOptions.debug;\n\n return {\n name: 'sentry-nuxt-source-map-validation',\n config(viteConfig: UserConfig, env: ConfigEnv) {\n // Only run in production builds\n if (!sourceMapsEnabled || env.mode === 'development' || nuxt.options?._prepare) {\n return;\n }\n\n // Detect runtime from Vite config\n // In Nuxt, SSR builds have build.ssr: true, client builds don't\n const runtime = viteConfig.build?.ssr ? 'server' : 'client';\n\n const nuxtSourceMapSetting = extractNuxtSourceMapSetting(nuxt, runtime);\n\n // Initialize build config if needed\n viteConfig.build = viteConfig.build || {};\n const viteSourceMap = viteConfig.build.sourcemap;\n\n if (isDebug) {\n // eslint-disable-next-line no-console\n console.log(`[Sentry] Validating Vite config for the ${runtime} runtime.`);\n }\n\n // Vite source map options are the same as the Nuxt source map config options (unless overwritten)\n validateDifferentSourceMapSettings({\n nuxtSettingKey: `sourcemap.${runtime}`,\n nuxtSettingValue: nuxtSourceMapSetting,\n otherSettingKey: 'viteConfig.build.sourcemap',\n otherSettingValue: viteSourceMap,\n });\n },\n };\n}\n"],"names":["extractNuxtSourceMapSetting","validateDifferentSourceMapSettings"],"mappings":";;;;AAKA;AACA;AACA;AACO,SAAS,+BAA+B,CAAC;;AAIhD,EAAW;AACX,EAAE,MAAM,EAAE,IAAI,EAAE,aAAa,EAAE,iBAAA,EAAkB,GAAI,OAAO;AAC5D,EAAE,MAAM,OAAA,GAAU,aAAa,CAAC,KAAK;;AAErC,EAAE,OAAO;AACT,IAAI,IAAI,EAAE,mCAAmC;AAC7C,IAAI,MAAM,CAAC,UAAU,EAAc,GAAG,EAAa;AACnD;AACA,MAAM,IAAI,CAAC,iBAAA,IAAqB,GAAG,CAAC,IAAA,KAAS,aAAA,IAAiB,IAAI,CAAC,OAAO,EAAE,QAAQ,EAAE;AACtF,QAAQ;AACR,MAAM;;AAEN;AACA;AACA,MAAM,MAAM,OAAA,GAAU,UAAU,CAAC,KAAK,EAAE,GAAA,GAAM,QAAA,GAAW,QAAQ;;AAEjE,MAAM,MAAM,uBAAuBA,sCAA2B,CAAC,IAAI,EAAE,OAAO,CAAC;;AAE7E;AACA,MAAM,UAAU,CAAC,KAAA,GAAQ,UAAU,CAAC,KAAA,IAAS,EAAE;AAC/C,MAAM,MAAM,aAAA,GAAgB,UAAU,CAAC,KAAK,CAAC,SAAS;;AAEtD,MAAM,IAAI,OAAO,EAAE;AACnB;AACA,QAAQ,OAAO,CAAC,GAAG,CAAC,CAAC,wCAAwC,EAAE,OAAO,CAAC,SAAS,CAAC,CAAC;AAClF,MAAM;;AAEN;AACA,MAAMC,6CAAkC,CAAC;AACzC,QAAQ,cAAc,EAAE,CAAC,UAAU,EAAE,OAAO,CAAC,CAAA;AACA,QAAA,gBAAA,EAAA,oBAAA;AACA,QAAA,eAAA,EAAA,4BAAA;AACA,QAAA,iBAAA,EAAA,aAAA;AACA,OAAA,CAAA;AACA,IAAA,CAAA;AACA,GAAA;AACA;;;;"}
|
|
@@ -7,7 +7,7 @@ var _documentCurrentScript = typeof document !== 'undefined' ? document.currentS
|
|
|
7
7
|
/**
|
|
8
8
|
* Prepares the storage config export to be used in the runtime storage instrumentation.
|
|
9
9
|
*/
|
|
10
|
-
function addStorageInstrumentation(nuxt) {
|
|
10
|
+
function addStorageInstrumentation(nuxt, isLegacyNitro) {
|
|
11
11
|
const moduleDirResolver = kit.createResolver((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('vite/storageConfig.js', document.baseURI).href)));
|
|
12
12
|
const userStorageMounts = Object.keys(nuxt.options.nitro.storage || {});
|
|
13
13
|
|
|
@@ -19,7 +19,11 @@ function addStorageInstrumentation(nuxt) {
|
|
|
19
19
|
},
|
|
20
20
|
});
|
|
21
21
|
|
|
22
|
-
|
|
22
|
+
if (isLegacyNitro) {
|
|
23
|
+
kit.addServerPlugin(moduleDirResolver.resolve('./runtime/plugins/storage-legacy.server'));
|
|
24
|
+
} else {
|
|
25
|
+
kit.addServerPlugin(moduleDirResolver.resolve('./runtime/plugins/storage.server'));
|
|
26
|
+
}
|
|
23
27
|
}
|
|
24
28
|
|
|
25
29
|
exports.addStorageInstrumentation = addStorageInstrumentation;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"storageConfig.js","sources":["../../../src/vite/storageConfig.ts"],"sourcesContent":["import { addServerPlugin, createResolver } from '@nuxt/kit';\nimport type { Nuxt } from '@nuxt/schema';\nimport { addServerTemplate } from '../vendor/server-template';\n\n/**\n * Prepares the storage config export to be used in the runtime storage instrumentation.\n */\nexport function addStorageInstrumentation(nuxt: Nuxt): void {\n const moduleDirResolver = createResolver(import.meta.url);\n const userStorageMounts = Object.keys(nuxt.options.nitro.storage || {});\n\n // Create a virtual module to pass this data to runtime\n addServerTemplate({\n filename: '#sentry/storage-config.mjs',\n getContents: () => {\n return `export const userStorageMounts = ${JSON.stringify(userStorageMounts)};`;\n },\n });\n\n addServerPlugin(moduleDirResolver.resolve('./runtime/plugins/storage.server'));\n}\n"],"names":["createResolver","addServerTemplate","addServerPlugin"],"mappings":";;;;;;AAIA;AACA;AACA;AACO,SAAS,yBAAyB,CAAC,IAAI,
|
|
1
|
+
{"version":3,"file":"storageConfig.js","sources":["../../../src/vite/storageConfig.ts"],"sourcesContent":["import { addServerPlugin, createResolver } from '@nuxt/kit';\nimport type { Nuxt } from '@nuxt/schema';\nimport { addServerTemplate } from '../vendor/server-template';\n\n/**\n * Prepares the storage config export to be used in the runtime storage instrumentation.\n */\nexport function addStorageInstrumentation(nuxt: Nuxt, isLegacyNitro: boolean): void {\n const moduleDirResolver = createResolver(import.meta.url);\n const userStorageMounts = Object.keys(nuxt.options.nitro.storage || {});\n\n // Create a virtual module to pass this data to runtime\n addServerTemplate({\n filename: '#sentry/storage-config.mjs',\n getContents: () => {\n return `export const userStorageMounts = ${JSON.stringify(userStorageMounts)};`;\n },\n });\n\n if (isLegacyNitro) {\n addServerPlugin(moduleDirResolver.resolve('./runtime/plugins/storage-legacy.server'));\n } else {\n addServerPlugin(moduleDirResolver.resolve('./runtime/plugins/storage.server'));\n }\n}\n"],"names":["createResolver","addServerTemplate","addServerPlugin"],"mappings":";;;;;;AAIA;AACA;AACA;AACO,SAAS,yBAAyB,CAAC,IAAI,EAAQ,aAAa,EAAiB;AACpF,EAAE,MAAM,iBAAA,GAAoBA,kBAAc,CAAC,uQAAe,CAAC;AAC3D,EAAE,MAAM,iBAAA,GAAoB,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,WAAW,EAAE,CAAC;;AAEzE;AACA,EAAEC,gCAAiB,CAAC;AACpB,IAAI,QAAQ,EAAE,4BAA4B;AAC1C,IAAI,WAAW,EAAE,MAAM;AACvB,MAAM,OAAO,CAAC,iCAAiC,EAAE,IAAI,CAAC,SAAS,CAAC,iBAAiB,CAAC,CAAC,CAAC,CAAC;AACrF,IAAI,CAAC;AACL,GAAG,CAAC;;AAEJ,EAAE,IAAI,aAAa,EAAE;AACrB,IAAIC,mBAAe,CAAC,iBAAiB,CAAC,OAAO,CAAC,yCAAyC,CAAC,CAAC;AACzF,EAAE,OAAO;AACT,IAAIA,mBAAe,CAAC,iBAAiB,CAAC,OAAO,CAAC,kCAAkC,CAAC,CAAC;AAClF,EAAE;AACF;;;;"}
|
package/build/cjs/vite/utils.js
CHANGED
|
@@ -4,6 +4,24 @@ const core = require('@sentry/core');
|
|
|
4
4
|
const fs = require('fs');
|
|
5
5
|
const path = require('path');
|
|
6
6
|
|
|
7
|
+
/**
|
|
8
|
+
* Gets the major version of the installed nitro package.
|
|
9
|
+
* Returns 2 as the default if nitro is not found or the version cannot be determined.
|
|
10
|
+
*/
|
|
11
|
+
async function getNitroMajorVersion() {
|
|
12
|
+
try {
|
|
13
|
+
const { getPackageInfo } = await import('local-pkg');
|
|
14
|
+
const info = await getPackageInfo('nitro');
|
|
15
|
+
if (info?.version) {
|
|
16
|
+
const major = parseInt(info.version.split('.')[0] ?? '2', 10);
|
|
17
|
+
return isNaN(major) ? 2 : major;
|
|
18
|
+
}
|
|
19
|
+
} catch {
|
|
20
|
+
// If local-pkg is unavailable or nitro is not found, default to v2
|
|
21
|
+
}
|
|
22
|
+
return 2;
|
|
23
|
+
}
|
|
24
|
+
|
|
7
25
|
/**
|
|
8
26
|
* Find the default SDK init file for the given type (client or server).
|
|
9
27
|
* The sentry.server.config file is prioritized over the instrument.server file.
|
|
@@ -191,8 +209,8 @@ function constructFunctionReExport(pathWithQuery, entryId) {
|
|
|
191
209
|
*
|
|
192
210
|
* @see https://nuxt.com/docs/guide/concepts/esm#aliasing-libraries
|
|
193
211
|
*/
|
|
194
|
-
function addOTelCommonJSImportAlias(nuxt) {
|
|
195
|
-
if (!nuxt.options.dev) {
|
|
212
|
+
function addOTelCommonJSImportAlias(nuxt, isNitroV3 = false) {
|
|
213
|
+
if (!nuxt.options.dev || isNitroV3) {
|
|
196
214
|
return;
|
|
197
215
|
}
|
|
198
216
|
|
|
@@ -215,5 +233,6 @@ exports.constructWrappedFunctionExportQuery = constructWrappedFunctionExportQuer
|
|
|
215
233
|
exports.extractFunctionReexportQueryParameters = extractFunctionReexportQueryParameters;
|
|
216
234
|
exports.findDefaultSdkInitFile = findDefaultSdkInitFile;
|
|
217
235
|
exports.getFilenameFromNodeStartCommand = getFilenameFromNodeStartCommand;
|
|
236
|
+
exports.getNitroMajorVersion = getNitroMajorVersion;
|
|
218
237
|
exports.removeSentryQueryFromPath = removeSentryQueryFromPath;
|
|
219
238
|
//# sourceMappingURL=utils.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sources":["../../../src/vite/utils.ts"],"sourcesContent":["import type { Nuxt } from '@nuxt/schema';\nimport { consoleSandbox } from '@sentry/core';\nimport * as fs from 'fs';\nimport * as path from 'path';\n\n/**\n * Find the default SDK init file for the given type (client or server).\n * The sentry.server.config file is prioritized over the instrument.server file.\n */\nexport function findDefaultSdkInitFile(type: 'server' | 'client', nuxt?: Nuxt): string | undefined {\n const possibleFileExtensions = ['ts', 'js', 'mjs', 'cjs', 'mts', 'cts'];\n const relativePaths: string[] = [];\n\n if (type === 'server') {\n for (const ext of possibleFileExtensions) {\n relativePaths.push(`sentry.${type}.config.${ext}`);\n relativePaths.push(path.join('public', `instrument.${type}.${ext}`));\n }\n } else {\n for (const ext of possibleFileExtensions) {\n relativePaths.push(`sentry.${type}.config.${ext}`);\n }\n }\n\n // Get layers from highest priority to lowest\n const layers = [...(nuxt?.options._layers ?? [])].reverse();\n\n for (const layer of layers) {\n for (const relativePath of relativePaths) {\n const fullPath = path.resolve(layer.cwd, relativePath);\n if (fs.existsSync(fullPath)) {\n return fullPath;\n }\n }\n }\n\n // As a fallback, also check CWD (left for pure compatibility)\n const cwd = process.cwd();\n for (const relativePath of relativePaths) {\n const fullPath = path.resolve(cwd, relativePath);\n if (fs.existsSync(fullPath)) {\n return fullPath;\n }\n }\n\n return undefined;\n}\n\n/**\n * Extracts the filename from a node command with a path.\n */\nexport function getFilenameFromNodeStartCommand(nodeCommand: string): string | null {\n const regex = /[^/\\\\]+\\.[^/\\\\]+$/;\n const match = nodeCommand.match(regex);\n return match ? match[0] : null;\n}\n\nexport const SENTRY_WRAPPED_ENTRY = '?sentry-query-wrapped-entry';\nexport const SENTRY_WRAPPED_FUNCTIONS = '?sentry-query-wrapped-functions=';\nexport const SENTRY_REEXPORTED_FUNCTIONS = '?sentry-query-reexported-functions=';\nexport const QUERY_END_INDICATOR = 'SENTRY-QUERY-END';\n\n/**\n * Strips the Sentry query part from a path.\n * Example: example/path?sentry-query-wrapped-entry?sentry-query-functions-reexport=foo,SENTRY-QUERY-END -> /example/path\n *\n * Only exported for testing.\n */\nexport function removeSentryQueryFromPath(url: string): string {\n // oxlint-disable-next-line sdk/no-regexp-constructor\n const regex = new RegExp(`\\\\${SENTRY_WRAPPED_ENTRY}.*?\\\\${QUERY_END_INDICATOR}`);\n return url.replace(regex, '');\n}\n\n/**\n * Extracts and sanitizes function re-export and function wrap query parameters from a query string.\n * If it is a default export, it is not considered for re-exporting.\n *\n * Only exported for testing.\n */\nexport function extractFunctionReexportQueryParameters(query: string): { wrap: string[]; reexport: string[] } {\n // Regex matches the comma-separated params between the functions query\n // oxlint-disable-next-line sdk/no-regexp-constructor\n const wrapRegex = new RegExp(\n `\\\\${SENTRY_WRAPPED_FUNCTIONS}(.*?)(\\\\${QUERY_END_INDICATOR}|\\\\${SENTRY_REEXPORTED_FUNCTIONS})`,\n );\n // oxlint-disable-next-line sdk/no-regexp-constructor\n const reexportRegex = new RegExp(`\\\\${SENTRY_REEXPORTED_FUNCTIONS}(.*?)(\\\\${QUERY_END_INDICATOR})`);\n\n const wrapMatch = query.match(wrapRegex);\n const reexportMatch = query.match(reexportRegex);\n\n const wrap =\n wrapMatch?.[1]\n ?.split(',')\n .filter(param => param !== '')\n // Sanitize, as code could be injected with another rollup plugin\n .map((str: string) => str.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&')) || [];\n\n const reexport =\n reexportMatch?.[1]\n ?.split(',')\n .filter(param => param !== '' && param !== 'default')\n // Sanitize, as code could be injected with another rollup plugin\n .map((str: string) => str.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&')) || [];\n\n return { wrap, reexport };\n}\n\n/**\n * Constructs a comma-separated string with all functions that need to be re-exported later from the server entry.\n * It uses Rollup's `exportedBindings` to determine the functions to re-export. Functions which should be wrapped\n * (e.g. serverless handlers) are wrapped by Sentry.\n */\nexport function constructWrappedFunctionExportQuery(\n exportedBindings: Record<string, string[]> | null,\n entrypointWrappedFunctions: string[],\n debug?: boolean,\n): string {\n const functionsToExport: { wrap: string[]; reexport: string[] } = {\n wrap: [],\n reexport: [],\n };\n\n // `exportedBindings` can look like this: `{ '.': [ 'handler' ] }` or `{ '.': [], './firebase-gen-1.mjs': [ 'server' ] }`\n // The key `.` refers to exports within the current file, while other keys show from where exports were imported first.\n Object.values(exportedBindings || {}).forEach(functions =>\n functions.forEach(fn => {\n if (entrypointWrappedFunctions.includes(fn)) {\n functionsToExport.wrap.push(fn);\n } else {\n functionsToExport.reexport.push(fn);\n }\n }),\n );\n\n if (debug && functionsToExport.wrap.length === 0) {\n consoleSandbox(() =>\n // eslint-disable-next-line no-console\n console.warn(\n \"[Sentry] No functions found to wrap. In case the server needs to export async functions other than `handler` or `server`, consider adding the name(s) to Sentry's build options `sentry.experimental_entrypointWrappedFunctions` in `nuxt.config.ts`.\",\n ),\n );\n }\n\n const wrapQuery = functionsToExport.wrap.length\n ? `${SENTRY_WRAPPED_FUNCTIONS}${functionsToExport.wrap.join(',')}`\n : '';\n const reexportQuery = functionsToExport.reexport.length\n ? `${SENTRY_REEXPORTED_FUNCTIONS}${functionsToExport.reexport.join(',')}`\n : '';\n\n return [wrapQuery, reexportQuery].join('');\n}\n\n/**\n * Constructs a code snippet with function reexports (can be used in Rollup plugins as a return value for `load()`)\n */\nexport function constructFunctionReExport(pathWithQuery: string, entryId: string): string {\n const { wrap: wrapFunctions, reexport: reexportFunctions } = extractFunctionReexportQueryParameters(pathWithQuery);\n\n return wrapFunctions\n .reduce(\n (functionsCode, currFunctionName) =>\n functionsCode.concat(\n `async function ${currFunctionName}_sentryWrapped(...args) {\\n` +\n ` const res = await import(${JSON.stringify(entryId)});\\n` +\n ` return res.${currFunctionName}.call(this, ...args);\\n` +\n '}\\n' +\n `export { ${currFunctionName}_sentryWrapped as ${currFunctionName} };\\n`,\n ),\n '',\n )\n .concat(\n reexportFunctions.reduce(\n (functionsCode, currFunctionName) =>\n functionsCode.concat(`export { ${currFunctionName} } from ${JSON.stringify(entryId)};`),\n '',\n ),\n );\n}\n\n/**\n * Sets up alias to work around OpenTelemetry's incomplete ESM imports.\n * https://github.com/getsentry/sentry-javascript/issues/15204\n *\n * OpenTelemetry's @opentelemetry/resources package has incomplete imports missing\n * the .js file extensions (like execAsync for machine-id detection). This causes module resolution\n * errors in certain Nuxt configurations, particularly when local Nuxt modules in Nuxt 4 are present.\n *\n * @see https://nuxt.com/docs/guide/concepts/esm#aliasing-libraries\n */\nexport function addOTelCommonJSImportAlias(nuxt: Nuxt): void {\n if (!nuxt.options.dev) {\n return;\n }\n\n if (!nuxt.options.alias) {\n nuxt.options.alias = {};\n }\n\n if (!nuxt.options.alias['@opentelemetry/resources']) {\n nuxt.options.alias['@opentelemetry/resources'] = '@opentelemetry/resources/build/src/index.js';\n }\n}\n"],"names":["consoleSandbox"],"mappings":";;;;;;AAKA;AACA;AACA;AACA;AACO,SAAS,sBAAsB,CAAC,IAAI,EAAuB,IAAI,EAA6B;AACnG,EAAE,MAAM,sBAAA,GAAyB,CAAC,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,CAAC;AACzE,EAAE,MAAM,aAAa,GAAa,EAAE;;AAEpC,EAAE,IAAI,IAAA,KAAS,QAAQ,EAAE;AACzB,IAAI,KAAK,MAAM,G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;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAAA,0BAAA,CAAA,IAAA,EAAA;AACA,EAAA,IAAA,CAAA,IAAA,CAAA,OAAA,CAAA,GAAA,EAAA;AACA,IAAA;AACA,EAAA;;AAEA,EAAA,IAAA,CAAA,IAAA,CAAA,OAAA,CAAA,KAAA,EAAA;AACA,IAAA,IAAA,CAAA,OAAA,CAAA,KAAA,GAAA,EAAA;AACA,EAAA;;AAEA,EAAA,IAAA,CAAA,IAAA,CAAA,OAAA,CAAA,KAAA,CAAA,0BAAA,CAAA,EAAA;AACA,IAAA,IAAA,CAAA,OAAA,CAAA,KAAA,CAAA,0BAAA,CAAA,GAAA,6CAAA;AACA,EAAA;AACA;;;;;;;;;;;;;;"}
|
|
1
|
+
{"version":3,"file":"utils.js","sources":["../../../src/vite/utils.ts"],"sourcesContent":["import type { Nuxt } from '@nuxt/schema';\nimport { consoleSandbox } from '@sentry/core';\nimport * as fs from 'fs';\nimport * as path from 'path';\n\n/**\n * Gets the major version of the installed nitro package.\n * Returns 2 as the default if nitro is not found or the version cannot be determined.\n */\nexport async function getNitroMajorVersion(): Promise<number> {\n try {\n const { getPackageInfo } = await import('local-pkg');\n const info = await getPackageInfo('nitro');\n if (info?.version) {\n const major = parseInt(info.version.split('.')[0] ?? '2', 10);\n return isNaN(major) ? 2 : major;\n }\n } catch {\n // If local-pkg is unavailable or nitro is not found, default to v2\n }\n return 2;\n}\n\n/**\n * Find the default SDK init file for the given type (client or server).\n * The sentry.server.config file is prioritized over the instrument.server file.\n */\nexport function findDefaultSdkInitFile(type: 'server' | 'client', nuxt?: Nuxt): string | undefined {\n const possibleFileExtensions = ['ts', 'js', 'mjs', 'cjs', 'mts', 'cts'];\n const relativePaths: string[] = [];\n\n if (type === 'server') {\n for (const ext of possibleFileExtensions) {\n relativePaths.push(`sentry.${type}.config.${ext}`);\n relativePaths.push(path.join('public', `instrument.${type}.${ext}`));\n }\n } else {\n for (const ext of possibleFileExtensions) {\n relativePaths.push(`sentry.${type}.config.${ext}`);\n }\n }\n\n // Get layers from highest priority to lowest\n const layers = [...(nuxt?.options._layers ?? [])].reverse();\n\n for (const layer of layers) {\n for (const relativePath of relativePaths) {\n const fullPath = path.resolve(layer.cwd, relativePath);\n if (fs.existsSync(fullPath)) {\n return fullPath;\n }\n }\n }\n\n // As a fallback, also check CWD (left for pure compatibility)\n const cwd = process.cwd();\n for (const relativePath of relativePaths) {\n const fullPath = path.resolve(cwd, relativePath);\n if (fs.existsSync(fullPath)) {\n return fullPath;\n }\n }\n\n return undefined;\n}\n\n/**\n * Extracts the filename from a node command with a path.\n */\nexport function getFilenameFromNodeStartCommand(nodeCommand: string): string | null {\n const regex = /[^/\\\\]+\\.[^/\\\\]+$/;\n const match = nodeCommand.match(regex);\n return match ? match[0] : null;\n}\n\nexport const SENTRY_WRAPPED_ENTRY = '?sentry-query-wrapped-entry';\nexport const SENTRY_WRAPPED_FUNCTIONS = '?sentry-query-wrapped-functions=';\nexport const SENTRY_REEXPORTED_FUNCTIONS = '?sentry-query-reexported-functions=';\nexport const QUERY_END_INDICATOR = 'SENTRY-QUERY-END';\n\n/**\n * Strips the Sentry query part from a path.\n * Example: example/path?sentry-query-wrapped-entry?sentry-query-functions-reexport=foo,SENTRY-QUERY-END -> /example/path\n *\n * Only exported for testing.\n */\nexport function removeSentryQueryFromPath(url: string): string {\n // oxlint-disable-next-line sdk/no-regexp-constructor\n const regex = new RegExp(`\\\\${SENTRY_WRAPPED_ENTRY}.*?\\\\${QUERY_END_INDICATOR}`);\n return url.replace(regex, '');\n}\n\n/**\n * Extracts and sanitizes function re-export and function wrap query parameters from a query string.\n * If it is a default export, it is not considered for re-exporting.\n *\n * Only exported for testing.\n */\nexport function extractFunctionReexportQueryParameters(query: string): { wrap: string[]; reexport: string[] } {\n // Regex matches the comma-separated params between the functions query\n // oxlint-disable-next-line sdk/no-regexp-constructor\n const wrapRegex = new RegExp(\n `\\\\${SENTRY_WRAPPED_FUNCTIONS}(.*?)(\\\\${QUERY_END_INDICATOR}|\\\\${SENTRY_REEXPORTED_FUNCTIONS})`,\n );\n // oxlint-disable-next-line sdk/no-regexp-constructor\n const reexportRegex = new RegExp(`\\\\${SENTRY_REEXPORTED_FUNCTIONS}(.*?)(\\\\${QUERY_END_INDICATOR})`);\n\n const wrapMatch = query.match(wrapRegex);\n const reexportMatch = query.match(reexportRegex);\n\n const wrap =\n wrapMatch?.[1]\n ?.split(',')\n .filter(param => param !== '')\n // Sanitize, as code could be injected with another rollup plugin\n .map((str: string) => str.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&')) || [];\n\n const reexport =\n reexportMatch?.[1]\n ?.split(',')\n .filter(param => param !== '' && param !== 'default')\n // Sanitize, as code could be injected with another rollup plugin\n .map((str: string) => str.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&')) || [];\n\n return { wrap, reexport };\n}\n\n/**\n * Constructs a comma-separated string with all functions that need to be re-exported later from the server entry.\n * It uses Rollup's `exportedBindings` to determine the functions to re-export. Functions which should be wrapped\n * (e.g. serverless handlers) are wrapped by Sentry.\n */\nexport function constructWrappedFunctionExportQuery(\n exportedBindings: Record<string, string[]> | null,\n entrypointWrappedFunctions: string[],\n debug?: boolean,\n): string {\n const functionsToExport: { wrap: string[]; reexport: string[] } = {\n wrap: [],\n reexport: [],\n };\n\n // `exportedBindings` can look like this: `{ '.': [ 'handler' ] }` or `{ '.': [], './firebase-gen-1.mjs': [ 'server' ] }`\n // The key `.` refers to exports within the current file, while other keys show from where exports were imported first.\n Object.values(exportedBindings || {}).forEach(functions =>\n functions.forEach(fn => {\n if (entrypointWrappedFunctions.includes(fn)) {\n functionsToExport.wrap.push(fn);\n } else {\n functionsToExport.reexport.push(fn);\n }\n }),\n );\n\n if (debug && functionsToExport.wrap.length === 0) {\n consoleSandbox(() =>\n // eslint-disable-next-line no-console\n console.warn(\n \"[Sentry] No functions found to wrap. In case the server needs to export async functions other than `handler` or `server`, consider adding the name(s) to Sentry's build options `sentry.experimental_entrypointWrappedFunctions` in `nuxt.config.ts`.\",\n ),\n );\n }\n\n const wrapQuery = functionsToExport.wrap.length\n ? `${SENTRY_WRAPPED_FUNCTIONS}${functionsToExport.wrap.join(',')}`\n : '';\n const reexportQuery = functionsToExport.reexport.length\n ? `${SENTRY_REEXPORTED_FUNCTIONS}${functionsToExport.reexport.join(',')}`\n : '';\n\n return [wrapQuery, reexportQuery].join('');\n}\n\n/**\n * Constructs a code snippet with function reexports (can be used in Rollup plugins as a return value for `load()`)\n */\nexport function constructFunctionReExport(pathWithQuery: string, entryId: string): string {\n const { wrap: wrapFunctions, reexport: reexportFunctions } = extractFunctionReexportQueryParameters(pathWithQuery);\n\n return wrapFunctions\n .reduce(\n (functionsCode, currFunctionName) =>\n functionsCode.concat(\n `async function ${currFunctionName}_sentryWrapped(...args) {\\n` +\n ` const res = await import(${JSON.stringify(entryId)});\\n` +\n ` return res.${currFunctionName}.call(this, ...args);\\n` +\n '}\\n' +\n `export { ${currFunctionName}_sentryWrapped as ${currFunctionName} };\\n`,\n ),\n '',\n )\n .concat(\n reexportFunctions.reduce(\n (functionsCode, currFunctionName) =>\n functionsCode.concat(`export { ${currFunctionName} } from ${JSON.stringify(entryId)};`),\n '',\n ),\n );\n}\n\n/**\n * Sets up alias to work around OpenTelemetry's incomplete ESM imports.\n * https://github.com/getsentry/sentry-javascript/issues/15204\n *\n * OpenTelemetry's @opentelemetry/resources package has incomplete imports missing\n * the .js file extensions (like execAsync for machine-id detection). This causes module resolution\n * errors in certain Nuxt configurations, particularly when local Nuxt modules in Nuxt 4 are present.\n *\n * @see https://nuxt.com/docs/guide/concepts/esm#aliasing-libraries\n */\nexport function addOTelCommonJSImportAlias(nuxt: Nuxt, isNitroV3 = false): void {\n if (!nuxt.options.dev || isNitroV3) {\n return;\n }\n\n if (!nuxt.options.alias) {\n nuxt.options.alias = {};\n }\n\n if (!nuxt.options.alias['@opentelemetry/resources']) {\n nuxt.options.alias['@op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CAAA,IAAA,CAAA,OAAA,CAAA,KAAA,CAAA,0BAAA,CAAA,EAAA;AACA,IAAA,IAAA,CAAA,OAAA,CAAA,KAAA,CAAA,0BAAA,CAAA,GAAA,6CAAA;AACA,EAAA;AACA;;;;;;;;;;;;;;;"}
|
package/build/esm/module.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { defineNuxtModule, createResolver, addPluginTemplate, addPlugin, addServerPlugin,
|
|
1
|
+
import { defineNuxtModule, createResolver, addPluginTemplate, addPlugin, addServerPlugin, addVitePlugin, addTemplate } from '@nuxt/kit';
|
|
2
2
|
import { consoleSandbox } from '@sentry/core';
|
|
3
3
|
import * as path from 'path';
|
|
4
4
|
import { addServerConfigToBuild, addSentryTopImport, addDynamicImportEntryFileWrapper } from './vite/addServerConfig.js';
|
|
@@ -6,7 +6,7 @@ import { addDatabaseInstrumentation } from './vite/databaseConfig.js';
|
|
|
6
6
|
import { addMiddlewareImports, addMiddlewareInstrumentation } from './vite/middlewareConfig.js';
|
|
7
7
|
import { setupSourceMaps } from './vite/sourceMaps.js';
|
|
8
8
|
import { addStorageInstrumentation } from './vite/storageConfig.js';
|
|
9
|
-
import { findDefaultSdkInitFile, addOTelCommonJSImportAlias } from './vite/utils.js';
|
|
9
|
+
import { findDefaultSdkInitFile, getNitroMajorVersion, addOTelCommonJSImportAlias } from './vite/utils.js';
|
|
10
10
|
|
|
11
11
|
const module$1 = defineNuxtModule({
|
|
12
12
|
meta: {
|
|
@@ -17,7 +17,7 @@ const module$1 = defineNuxtModule({
|
|
|
17
17
|
},
|
|
18
18
|
},
|
|
19
19
|
defaults: {},
|
|
20
|
-
setup(moduleOptionsParam, nuxt) {
|
|
20
|
+
async setup(moduleOptionsParam, nuxt) {
|
|
21
21
|
if (moduleOptionsParam?.enabled === false) {
|
|
22
22
|
return;
|
|
23
23
|
}
|
|
@@ -67,47 +67,66 @@ const module$1 = defineNuxtModule({
|
|
|
67
67
|
}
|
|
68
68
|
|
|
69
69
|
const serverConfigFile = findDefaultSdkInitFile('server', nuxt);
|
|
70
|
+
const isNitroV3 = (await getNitroMajorVersion()) >= 3;
|
|
71
|
+
const nuxtMajor = parseInt((nuxt )._version?.split('.')[0] ?? '3', 10);
|
|
72
|
+
const isMinNuxtV4 = nuxtMajor >= 4;
|
|
70
73
|
|
|
71
74
|
if (serverConfigFile) {
|
|
75
|
+
if (isNitroV3) {
|
|
76
|
+
addServerPlugin(moduleDirResolver.resolve('./runtime/plugins/handler.server'));
|
|
77
|
+
addServerPlugin(moduleDirResolver.resolve('./runtime/plugins/update-route-name.server'));
|
|
78
|
+
} else {
|
|
79
|
+
addServerPlugin(moduleDirResolver.resolve('./runtime/plugins/handler-legacy.server'));
|
|
80
|
+
addServerPlugin(moduleDirResolver.resolve('./runtime/plugins/update-route-name-legacy.server'));
|
|
81
|
+
}
|
|
82
|
+
|
|
72
83
|
addServerPlugin(moduleDirResolver.resolve('./runtime/plugins/sentry.server'));
|
|
73
84
|
|
|
74
|
-
|
|
75
|
-
src: moduleDirResolver.resolve('./runtime/plugins/route-detector.server'),
|
|
76
|
-
|
|
77
|
-
|
|
85
|
+
if (isMinNuxtV4) {
|
|
86
|
+
addPlugin({ src: moduleDirResolver.resolve('./runtime/plugins/route-detector.server'), mode: 'server' });
|
|
87
|
+
} else {
|
|
88
|
+
addPlugin({ src: moduleDirResolver.resolve('./runtime/plugins/route-detector-legacy.server'), mode: 'server' });
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
// Preps the middleware instrumentation module.
|
|
92
|
+
addMiddlewareImports();
|
|
93
|
+
addStorageInstrumentation(nuxt, !isNitroV3);
|
|
94
|
+
addDatabaseInstrumentation(nuxt.options.nitro, !isNitroV3, moduleOptions);
|
|
78
95
|
}
|
|
79
96
|
|
|
80
97
|
if (clientConfigFile || serverConfigFile) {
|
|
81
98
|
setupSourceMaps(moduleOptions, nuxt, addVitePlugin);
|
|
82
99
|
}
|
|
83
100
|
|
|
84
|
-
addOTelCommonJSImportAlias(nuxt);
|
|
101
|
+
addOTelCommonJSImportAlias(nuxt, isNitroV3);
|
|
85
102
|
|
|
86
|
-
|
|
87
|
-
filename: 'sentry--nuxt-pages-data.mjs',
|
|
88
|
-
// Initial empty array (later filled in pages:extend hook)
|
|
89
|
-
// Template needs to be created in the root-level of the module to work
|
|
90
|
-
getContents: () => 'export default [];',
|
|
91
|
-
});
|
|
103
|
+
let pagesData = [];
|
|
92
104
|
|
|
93
105
|
nuxt.hooks.hook('pages:extend', pages => {
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
.
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
});
|
|
101
|
-
|
|
102
|
-
return `export default ${JSON.stringify(pagesSubset, null, 2)};`;
|
|
103
|
-
};
|
|
106
|
+
pagesData = pages
|
|
107
|
+
.map(page => ({ file: page.file, path: page.path }))
|
|
108
|
+
.filter(page => {
|
|
109
|
+
// Check for dynamic parameter (e.g., :userId or [userId])
|
|
110
|
+
return page.path.includes(':') || page?.file?.includes('[');
|
|
111
|
+
});
|
|
104
112
|
});
|
|
105
113
|
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
114
|
+
if (isMinNuxtV4) {
|
|
115
|
+
const pagesDataVirtualModuleId = '#sentry/nuxt-pages-data.mjs';
|
|
116
|
+
|
|
117
|
+
// Vite virtual plugin (for the Vite SSR build, where addPlugin mode:'server' plugins are bundled)
|
|
118
|
+
addVitePlugin({
|
|
119
|
+
name: 'sentry-nuxt-pages-data-virtual',
|
|
120
|
+
resolveId: id => (id === pagesDataVirtualModuleId ? `\0${pagesDataVirtualModuleId}` : null),
|
|
121
|
+
load: id =>
|
|
122
|
+
id === `\0${pagesDataVirtualModuleId}` ? `export default ${JSON.stringify(pagesData, null, 2)};` : undefined,
|
|
123
|
+
});
|
|
124
|
+
} else {
|
|
125
|
+
// Nuxt v3: register as a build template (accessible via #build/)
|
|
126
|
+
addTemplate({
|
|
127
|
+
filename: 'sentry--nuxt-pages-data.mjs',
|
|
128
|
+
getContents: () => `export default ${JSON.stringify(pagesData, null, 2)};`,
|
|
129
|
+
});
|
|
111
130
|
}
|
|
112
131
|
|
|
113
132
|
// Add the sentry config file to the include array
|