@sentry/nuxt 11.0.0-beta.1 → 11.0.0-beta.2
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 +77 -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 +78 -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 +129 -89
- package/build/module/runtime/utils/instrumentDatabase.js +3 -2
- 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/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 +9 -9
|
@@ -1,38 +1,12 @@
|
|
|
1
1
|
import { existsSync } from 'node:fs';
|
|
2
2
|
import { basename } from 'node:path';
|
|
3
3
|
import { pathToFileURL } from 'node:url';
|
|
4
|
-
import { createResolver, addTemplate } from '@nuxt/kit';
|
|
5
|
-
import { debug } from '@sentry/core';
|
|
4
|
+
import { createResolver, addTemplate, addServerPlugin } from '@nuxt/kit';
|
|
5
|
+
import { consoleSandbox, debug } from '@sentry/core';
|
|
6
6
|
import * as fs from 'fs';
|
|
7
|
-
import
|
|
8
|
-
import {
|
|
9
|
-
import { SERVER_CONFIG_FILENAME, toImportSpecifier, getFilenameFromNodeStartCommand, SENTRY_WRAPPED_ENTRY, removeSentryQueryFromPath, SENTRY_WRAPPED_FUNCTIONS, SENTRY_REEXPORTED_FUNCTIONS, constructFunctionReExport, toResolvablePath, constructWrappedFunctionExportQuery, QUERY_END_INDICATOR } from './utils.js';
|
|
7
|
+
import { NUXT_DEV_MODE_FLAG, NUXT_PRERENDER_FLAG } from '../common/devMode.js';
|
|
8
|
+
import { isCloudflarePreset, SERVER_CONFIG_FILENAME, getFilenameFromNodeStartCommand, SENTRY_WRAPPED_ENTRY, removeSentryQueryFromPath, SENTRY_WRAPPED_FUNCTIONS, SENTRY_REEXPORTED_FUNCTIONS, constructFunctionReExport, toResolvablePath, constructWrappedFunctionExportQuery, QUERY_END_INDICATOR } from './utils.js';
|
|
10
9
|
|
|
11
|
-
const DEV_SERVER_CONFIG_PATH = `dev/${SERVER_CONFIG_FILENAME}.mjs`;
|
|
12
|
-
function addDevServerConfigFile(nuxt, serverConfigFile) {
|
|
13
|
-
const configPath = createResolver(nuxt.options.rootDir).resolve(serverConfigFile);
|
|
14
|
-
const importSpecifier = toImportSpecifier(
|
|
15
|
-
nuxt.options.rootDir,
|
|
16
|
-
path.join(nuxt.options.buildDir, DEV_SERVER_CONFIG_PATH)
|
|
17
|
-
);
|
|
18
|
-
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).`;
|
|
19
|
-
addTemplate({
|
|
20
|
-
filename: DEV_SERVER_CONFIG_PATH,
|
|
21
|
-
write: true,
|
|
22
|
-
getContents: () => [
|
|
23
|
-
"// Generated by @sentry/nuxt. Preload it to enable Sentry during development:",
|
|
24
|
-
`// NODE_OPTIONS='--import ${importSpecifier}' nuxt dev`,
|
|
25
|
-
// A static import would hoist above this assignment, and would make a broken config crash the dev server.
|
|
26
|
-
`globalThis.${NUXT_DEV_MODE_FLAG} = true;`,
|
|
27
|
-
"try {",
|
|
28
|
-
` await import(${JSON.stringify(pathToFileURL(configPath).href)});`,
|
|
29
|
-
"} catch (error) {",
|
|
30
|
-
` console.warn(${JSON.stringify(failureMessage)}, error);`,
|
|
31
|
-
"}",
|
|
32
|
-
""
|
|
33
|
-
].join("\n")
|
|
34
|
-
});
|
|
35
|
-
}
|
|
36
10
|
const CONFIG_EXTENSIONS = [".ts", ".js", ".mjs", ".cjs", ".mts", ".cts"];
|
|
37
11
|
function isServerConfigFile(sourcePath, resolvedPath) {
|
|
38
12
|
if (sourcePath === resolvedPath) {
|
|
@@ -80,6 +54,78 @@ ${data}`;
|
|
|
80
54
|
}
|
|
81
55
|
});
|
|
82
56
|
}
|
|
57
|
+
function addServerConfigPlugin(nuxt, serverConfigFile) {
|
|
58
|
+
const configPath = createResolver(nuxt.options.rootDir).resolve(serverConfigFile);
|
|
59
|
+
const runtimeFlagsTemplate = addTemplate({
|
|
60
|
+
filename: "sentry-runtime-flags.mjs",
|
|
61
|
+
write: true,
|
|
62
|
+
getContents: () => [
|
|
63
|
+
"// Generated by @sentry/nuxt. Sets runtime flags before the Sentry server config evaluates.",
|
|
64
|
+
`globalThis.${NUXT_DEV_MODE_FLAG} = import.meta.dev === true;`,
|
|
65
|
+
`globalThis.${NUXT_PRERENDER_FLAG} = import.meta.prerender === true;`,
|
|
66
|
+
""
|
|
67
|
+
].join("\n")
|
|
68
|
+
});
|
|
69
|
+
const configPluginTemplate = addTemplate({
|
|
70
|
+
filename: "sentry-server-config-plugin.mjs",
|
|
71
|
+
write: true,
|
|
72
|
+
getContents: () => `import ${JSON.stringify(runtimeFlagsTemplate.dst)};
|
|
73
|
+
import ${JSON.stringify(configPath)};
|
|
74
|
+
export default () => {};
|
|
75
|
+
`
|
|
76
|
+
});
|
|
77
|
+
addServerPlugin(configPluginTemplate.dst);
|
|
78
|
+
nuxt.options.nitro.moduleSideEffects = [
|
|
79
|
+
...nuxt.options.nitro.moduleSideEffects ?? [],
|
|
80
|
+
configPath,
|
|
81
|
+
runtimeFlagsTemplate.dst
|
|
82
|
+
];
|
|
83
|
+
nuxt.hook("nitro:config", (nitroConfig) => {
|
|
84
|
+
if (isCloudflarePreset(nitroConfig.preset)) {
|
|
85
|
+
nitroConfig.plugins = (nitroConfig.plugins ?? []).filter((plugin) => plugin !== configPluginTemplate.dst);
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
const plugins = nitroConfig.plugins ?? [];
|
|
89
|
+
nitroConfig.plugins = [configPluginTemplate.dst, ...plugins.filter((plugin) => plugin !== configPluginTemplate.dst)];
|
|
90
|
+
const externals = nitroConfig.externals ?? (nitroConfig.externals = {});
|
|
91
|
+
const inline = externals.inline;
|
|
92
|
+
const existingInline = Array.isArray(inline) ? inline : inline ? [inline] : [];
|
|
93
|
+
externals.inline = [...existingInline, configPath, configPluginTemplate.dst, runtimeFlagsTemplate.dst];
|
|
94
|
+
});
|
|
95
|
+
nuxt.hook("nitro:init", (nitro) => {
|
|
96
|
+
if (nuxt.options._prepare || !isCloudflarePreset(nitro.options.preset)) {
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
nitro.options.plugins = (nitro.options.plugins ?? []).filter((plugin) => plugin !== configPluginTemplate.dst);
|
|
100
|
+
consoleSandbox(() => {
|
|
101
|
+
console.warn(
|
|
102
|
+
`[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/`
|
|
103
|
+
);
|
|
104
|
+
});
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
function addServerConfigShimWithWarning(nitro) {
|
|
108
|
+
nitro.hooks.hook("close", async () => {
|
|
109
|
+
if (nitro.options.dev || nitro.options.preset === "nitro-prerender" || isCloudflarePreset(nitro.options.preset)) {
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
const shimPath = createResolver(nitro.options.output.serverDir).resolve(`${SERVER_CONFIG_FILENAME}.mjs`);
|
|
113
|
+
const contents = [
|
|
114
|
+
"// Generated by @sentry/nuxt.",
|
|
115
|
+
"// The Sentry server config is bundled into the server build and initializes automatically.",
|
|
116
|
+
"// This file only keeps existing `node --import ./.output/server/sentry.server.config.mjs` commands working.",
|
|
117
|
+
"console.warn('[Sentry] The `--import` flag for the Sentry server config is no longer needed and should be removed.');",
|
|
118
|
+
""
|
|
119
|
+
].join("\n");
|
|
120
|
+
try {
|
|
121
|
+
await fs.promises.writeFile(shimPath, contents, "utf8");
|
|
122
|
+
} catch (error) {
|
|
123
|
+
consoleSandbox(() => {
|
|
124
|
+
console.warn(`[Sentry] Could not write the \`--import\` compatibility shim to ${shimPath}`, error);
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
});
|
|
128
|
+
}
|
|
83
129
|
function addDynamicImportEntryFileWrapper(nitro, serverConfigFile, moduleOptions) {
|
|
84
130
|
if (!nitro.options.rollupConfig) {
|
|
85
131
|
nitro.options.rollupConfig = { output: {} };
|
|
@@ -92,6 +138,7 @@ function addDynamicImportEntryFileWrapper(nitro, serverConfigFile, moduleOptions
|
|
|
92
138
|
nitro.options.rollupConfig.plugins.push(
|
|
93
139
|
wrapEntryWithDynamicImport({
|
|
94
140
|
resolvedSentryConfigPath: createResolver(nitro.options.rootDir).resolve(serverConfigFile),
|
|
141
|
+
// oxlint-disable-next-line typescript/no-deprecated -- supported until removal
|
|
95
142
|
experimental_entrypointWrappedFunctions: moduleOptions.experimental_entrypointWrappedFunctions
|
|
96
143
|
})
|
|
97
144
|
);
|
|
@@ -180,5 +227,5 @@ ${reExportedFunctions}
|
|
|
180
227
|
};
|
|
181
228
|
}
|
|
182
229
|
|
|
183
|
-
export {
|
|
230
|
+
export { addDynamicImportEntryFileWrapper, addSentryTopImport, addServerConfigPlugin, addServerConfigShimWithWarning, addServerConfigToBuild, wrapEntryWithDynamicImport };
|
|
184
231
|
//# 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":["nitro","debug"],"mappings":";;;;;;;;;;AA2BO,MAAM,sBAAA,GAAyB,OAAO,sBAAsB,CAAA,IAAA;AAO5D,SAAS,sBAAA,CAAuB,MAAY,gBAAA,EAAgC;AACjF,EAAA,MAAM,aAAa,cAAA,CAAe,IAAA,CAAK,QAAQ,OAAO,CAAA,CAAE,QAAQ,gBAAgB,CAAA;AAChF,EAAA,MAAM,eAAA,GAAkB,iBAAA;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,EAAA,WAAA,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,cAAc,kBAAkB,CAAA,QAAA,CAAA;AAAA,MAChC,OAAA;AAAA,MACA,kBAAkB,IAAA,CAAK,SAAA,CAAU,cAAc,UAAU,CAAA,CAAE,IAAI,CAAC,CAAA,EAAA,CAAA;AAAA,MAChE,mBAAA;AAAA,MACA,CAAA,eAAA,EAAkB,IAAA,CAAK,SAAA,CAAU,cAAc,CAAC,CAAA,SAAA,CAAA;AAAA,MAChD,GAAA;AAAA,MACA;AAAA,KACF,CAAE,KAAK,IAAI;AAAA,GACd,CAAA;AACH;AACA,MAAM,oBAAoB,CAAC,KAAA,EAAO,OAAO,MAAA,EAAQ,MAAA,EAAQ,QAAQ,MAAM,CAAA;AAEvE,SA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,aAAA,CAAc,OAAO,CAAA,CAAE,IAAA;AAC1C,QAAA,MAAM,SAAA,GAAY,aAAA,CAAc,wBAAwB,CAAA,CAAE,IAAA;AAI1D,QAAA,MAAM,mBAAA,GACJ,EAAA,CAAG,QAAA,CAAS,wBAAwB,CAAA,IAAK,EAAA,CAAG,QAAA,CAAS,2BAA2B,CAAA,GAC5E,yBAAA,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): 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 treeshakes side-effect-only imports outside its runtime dir, which would silently drop\n // the top-level `Sentry.init` and the flag assignments.\n nuxt.options.nitro.moduleSideEffects = [\n ...(nuxt.options.nitro.moduleSideEffects ?? []),\n configPath,\n runtimeFlagsTemplate.dst,\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 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 // 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":["nitro","debug"],"mappings":";;;;;;;;;AAyBA,MAAM,oBAAoB,CAAC,KAAA,EAAO,OAAO,MAAA,EAAQ,MAAA,EAAQ,QAAQ,MAAM,CAAA;AAEvE,SAAS,kBAAA,CAAmB,YAAoB,YAAA,EAA+B;AAC7E,EAAA,IAAI,eAAe,YAAA,EAAc;AAC/B,IAAA,OAAO,IAAA;AAAA,EACT;AACA,EAAA,MAAM,IAAA,GAAO,SAAS,UAAU,CAAA;AAChC,EAAA,OAAO,IAAA,KAAS,sBAAA,IAA0B,iBAAA,CAAkB,IAAA,CAAK,CAAA,GAAA,KAAO,SAAS,CAAA,EAAG,sBAAsB,CAAA,EAAG,GAAG,CAAA,CAAE,CAAA;AACpH;AAOO,SAAS,sBAAA,CACd,aAAA,EACA,KAAA,EACA,gBAAA,EACM;AACN,EAAA,KAAA,CAAM,KAAA,CAAM,IAAA,CAAK,eAAA,EAAiB,CAACA,QAAO,YAAA,KAAiB;AACzD,IAAA,IAAI,YAAA,EAAc,OAAA,KAAY,IAAA,IAAQ,YAAA,EAAc,YAAY,MAAA,EAAW;AACzE,MAAA,YAAA,CAAa,UAAU,EAAC;AAAA,IAC1B,WAAW,CAAC,KAAA,CAAM,OAAA,CAAQ,YAAA,CAAa,OAAO,CAAA,EAAG;AAE/C,MAAA,YAAA,CAAa,OAAA,GAAU,CAAC,YAAA,CAAa,OAA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AAA,EAAG;AAC9C,QAAA,MAAM,UAAU,yBAAA,CAA0B,EAAE,CAAA,CAAE,KAAA,CAAM,mBAAmB,MAAM,CAAA;AAC7E,QAAA,MAAM,UAAA,GAAa,aAAA,CAAc,OAAO,CAAA,CAAE,IAAA;AAC1C,QAAA,MAAM,SAAA,GAAY,aAAA,CAAc,wBAAwB,CAAA,CAAE,IAAA;AAI1D,QAAA,MAAM,mBAAA,GACJ,EAAA,CAAG,QAAA,CAAS,wBAAwB,CAAA,IAAK,EAAA,CAAG,QAAA,CAAS,2BAA2B,CAAA,GAC5E,yBAAA,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;;;;"}
|
|
@@ -9,7 +9,7 @@ function addMiddlewareImports() {
|
|
|
9
9
|
}
|
|
10
10
|
]);
|
|
11
11
|
}
|
|
12
|
-
function addMiddlewareInstrumentation(nitro) {
|
|
12
|
+
function addMiddlewareInstrumentation(nitro, isNitroV3) {
|
|
13
13
|
nitro.hooks.hook("rollup:before", (nitro2, rollupConfig) => {
|
|
14
14
|
if (!rollupConfig.plugins) {
|
|
15
15
|
rollupConfig.plugins = [];
|
|
@@ -17,11 +17,12 @@ function addMiddlewareInstrumentation(nitro) {
|
|
|
17
17
|
if (!Array.isArray(rollupConfig.plugins)) {
|
|
18
18
|
rollupConfig.plugins = [rollupConfig.plugins];
|
|
19
19
|
}
|
|
20
|
-
rollupConfig.plugins.push(middlewareInstrumentationPlugin(nitro2));
|
|
20
|
+
rollupConfig.plugins.push(middlewareInstrumentationPlugin(nitro2, isNitroV3));
|
|
21
21
|
});
|
|
22
22
|
}
|
|
23
|
-
function middlewareInstrumentationPlugin(nitro) {
|
|
23
|
+
function middlewareInstrumentationPlugin(nitro, isNitroV3) {
|
|
24
24
|
const middlewareFiles = /* @__PURE__ */ new Set();
|
|
25
|
+
const wrapperModule = isNitroV3 ? "#imports/server" : "#imports";
|
|
25
26
|
return {
|
|
26
27
|
name: "sentry-nuxt-middleware-instrumentation",
|
|
27
28
|
buildStart() {
|
|
@@ -35,7 +36,7 @@ function middlewareInstrumentationPlugin(nitro) {
|
|
|
35
36
|
if (middlewareFiles.has(id)) {
|
|
36
37
|
const fileName = path.basename(id);
|
|
37
38
|
return {
|
|
38
|
-
code: wrapMiddlewareCode(code, fileName),
|
|
39
|
+
code: wrapMiddlewareCode(code, fileName, wrapperModule),
|
|
39
40
|
map: null
|
|
40
41
|
};
|
|
41
42
|
}
|
|
@@ -43,10 +44,10 @@ function middlewareInstrumentationPlugin(nitro) {
|
|
|
43
44
|
}
|
|
44
45
|
};
|
|
45
46
|
}
|
|
46
|
-
function wrapMiddlewareCode(originalCode, fileName) {
|
|
47
|
+
function wrapMiddlewareCode(originalCode, fileName, wrapperModule) {
|
|
47
48
|
const cleanFileName = fileName.replace(/\.(ts|js|mjs|mts|cts)$/, "");
|
|
48
49
|
return `
|
|
49
|
-
import { wrapMiddlewareHandlerWithSentry } from '
|
|
50
|
+
import { wrapMiddlewareHandlerWithSentry } from '${wrapperModule}';
|
|
50
51
|
|
|
51
52
|
function defineInstrumentedEventHandler(handlerOrObject) {
|
|
52
53
|
return defineEventHandler(wrapMiddlewareHandlerWithSentry(handlerOrObject, '${cleanFileName}'));
|
|
@@ -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 '
|
|
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 * @param isNitroV3 Whether the app builds with Nitro v3 (Nuxt 5)\n */\nexport function addMiddlewareInstrumentation(nitro: Nitro, isNitroV3: boolean): 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, isNitroV3));\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 * @param isNitroV3 Whether the app builds with Nitro v3 (Nuxt 5)\n * @returns The rollup plugin for the middleware instrumentation.\n */\nfunction middlewareInstrumentationPlugin(nitro: Nitro, isNitroV3: boolean): InputPluginOption {\n const middlewareFiles = new Set<string>();\n const wrapperModule = isNitroV3 ? '#imports/server' : '#imports';\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, wrapperModule),\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 * @param wrapperModule Import specifier resolving to `wrapMiddlewareHandlerWithSentry`.\n *\n * @returns The wrapped user code of the middleware.\n */\nfunction wrapMiddlewareCode(originalCode: string, fileName: string, wrapperModule: string): string {\n // Remove common file extensions\n const cleanFileName = fileName.replace(/\\.(ts|js|mjs|mts|cts)$/, '');\n\n return `\nimport { wrapMiddlewareHandlerWithSentry } from '${wrapperModule}';\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":["nitro"],"mappings":";;;AAQO,SAAS,oBAAA,GAA6B;AAC3C,EAAA,gBAAA,CAAiB;AAAA,IACf;AAAA,MACE,IAAA,EAAM,iCAAA;AAAA,MACN,MAAM,cAAA,CAAe,MAAA,CAAA,IAAA,CAAY,GAAG,CAAA,CAAE,QAAQ,uCAAuC;AAAA;AACvF,GACD,CAAA;AACH;AAQO,SAAS,4BAAA,CAA6B,OAAc,SAAA,EAA0B;AACnF,EAAA,KAAA,CAAM,KAAA,CAAM,IAAA,CAAK,eAAA,EAAiB,CAACA,QAAO,YAAA,KAAiB;AACzD,IAAA,IAAI,CAAC,aAAa,OAAA,EAAS;AACzB,MAAA,YAAA,CAAa,UAAU,EAAC;AAAA,IAC1B;AAEA,IAAA,IAAI,CAAC,KAAA,CAAM,OAAA,CAAQ,YAAA,CAAa,OAAO,CAAA,EAAG;AACxC,MAAA,YAAA,CAAa,OAAA,GAAU,CAA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,aAAa,CAAA;AAAA;;AAAA;AAAA,yEAAA,EAIZ,aAAa,CAAA;AAAA;;AAAA,EAGtF,YAAA,CACC,OAAA,CAAQ,uBAAA,EAAyB,iCAAiC,CAAA,CAClE,OAAA,CAAQ,iBAAA,EAAmB,2BAA2B,CAAA,CACtD,OAAA,CAAQ,kBAAA,EAAoB,4BAA4B,CAAC;AAAA,CAAA;AAE5D;;;;"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { INSTRUMENTED_MODULE_NAMES } from '@sentry/server-utils/orchestrion/config';
|
|
2
2
|
import { sentryOrchestrionPlugin } from '@sentry/server-utils/orchestrion/rollup';
|
|
3
|
+
import { isCloudflarePreset } from './utils.js';
|
|
3
4
|
|
|
4
5
|
const IORedisDependencies = ["standard-as-callback"];
|
|
5
6
|
function setupOrchestrion(nuxt, hasServerConfig, buildTimeInstrumentation) {
|
|
@@ -13,7 +14,7 @@ function setupOrchestrion(nuxt, hasServerConfig, buildTimeInstrumentation) {
|
|
|
13
14
|
if (nuxt.options?.dev) {
|
|
14
15
|
return;
|
|
15
16
|
}
|
|
16
|
-
const isCloudflare =
|
|
17
|
+
const isCloudflare = isCloudflarePreset(nitroConfig.preset);
|
|
17
18
|
if (!hasServerConfig && !isCloudflare) {
|
|
18
19
|
return;
|
|
19
20
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"orchestrion.js","sources":["../../../src/vite/orchestrion.ts"],"sourcesContent":["import type { Nuxt } from '@nuxt/schema';\nimport { INSTRUMENTED_MODULE_NAMES } from '@sentry/server-utils/orchestrion/config';\nimport { sentryOrchestrionPlugin } from '@sentry/server-utils/orchestrion/rollup';\nimport type { NitroConfig } from 'nitropack';\n\n// ioredis requires this CommonJS helper to be bundled with it. Leaving it\n// external makes Nitro resolve the default export as a namespace object.\nconst IORedisDependencies = ['standard-as-callback'];\n\n/**\n * Configures Nitro to bundle and transform dependencies that publish tracing\n * events through diagnostics channels.\n *\n * `hasServerConfig` reflects whether a `sentry.server.config` file was found. On Node the SDK is\n * initialized from that file, so orchestrion only makes sense when it exists. On Cloudflare the SDK\n * is initialized through `sentryCloudflareNitroPlugin` instead (no server config file), so the\n * transform must still run there — detected via the Nitro preset.\n */\nexport function setupOrchestrion(nuxt: Nuxt, hasServerConfig: boolean, buildTimeInstrumentation?: boolean): void {\n if (buildTimeInstrumentation === false) {\n return;\n }\n\n nuxt.hook('nitro:config', (nitroConfig: NitroConfig) => {\n if (nuxt.options?._prepare) {\n return;\n }\n\n // `nuxt dev` has no bundle to transform, and inlining the CommonJS drivers into Nitro's dev\n // server breaks them (`ioredis` throws `(0, lodash_1.defaults) is not a function`).\n if (nuxt.options?.dev) {\n return;\n }\n\n // On Cloudflare (workerd) the SDK is initialized through `sentryCloudflareNitroPlugin` (no\n // server config file), so the transform must still run there — detected via the Nitro preset.\n
|
|
1
|
+
{"version":3,"file":"orchestrion.js","sources":["../../../src/vite/orchestrion.ts"],"sourcesContent":["import type { Nuxt } from '@nuxt/schema';\nimport { INSTRUMENTED_MODULE_NAMES } from '@sentry/server-utils/orchestrion/config';\nimport { sentryOrchestrionPlugin } from '@sentry/server-utils/orchestrion/rollup';\nimport type { NitroConfig } from 'nitropack';\nimport { isCloudflarePreset } from './utils';\n\n// ioredis requires this CommonJS helper to be bundled with it. Leaving it\n// external makes Nitro resolve the default export as a namespace object.\nconst IORedisDependencies = ['standard-as-callback'];\n\n/**\n * Configures Nitro to bundle and transform dependencies that publish tracing\n * events through diagnostics channels.\n *\n * `hasServerConfig` reflects whether a `sentry.server.config` file was found. On Node the SDK is\n * initialized from that file, so orchestrion only makes sense when it exists. On Cloudflare the SDK\n * is initialized through `sentryCloudflareNitroPlugin` instead (no server config file), so the\n * transform must still run there — detected via the Nitro preset.\n */\nexport function setupOrchestrion(nuxt: Nuxt, hasServerConfig: boolean, buildTimeInstrumentation?: boolean): void {\n if (buildTimeInstrumentation === false) {\n return;\n }\n\n nuxt.hook('nitro:config', (nitroConfig: NitroConfig) => {\n if (nuxt.options?._prepare) {\n return;\n }\n\n // `nuxt dev` has no bundle to transform, and inlining the CommonJS drivers into Nitro's dev\n // server breaks them (`ioredis` throws `(0, lodash_1.defaults) is not a function`).\n if (nuxt.options?.dev) {\n return;\n }\n\n // On Cloudflare (workerd) the SDK is initialized through `sentryCloudflareNitroPlugin` (no\n // server config file), so the transform must still run there — detected via the Nitro preset.\n const isCloudflare = isCloudflarePreset(nitroConfig.preset);\n\n if (!hasServerConfig && !isCloudflare) {\n return;\n }\n\n nitroConfig.rollupConfig ??= {};\n\n if (nitroConfig.rollupConfig.plugins === null || nitroConfig.rollupConfig.plugins === undefined) {\n nitroConfig.rollupConfig.plugins = [];\n } else if (!Array.isArray(nitroConfig.rollupConfig.plugins)) {\n nitroConfig.rollupConfig.plugins = [nitroConfig.rollupConfig.plugins];\n }\n\n nitroConfig.rollupConfig.plugins.push(sentryOrchestrionPlugin({}));\n\n const externals = (nitroConfig.externals ||= {});\n const inline = externals.inline;\n const existingInline = Array.isArray(inline) ? inline : inline ? [inline] : [];\n externals.inline = [...new Set([...existingInline, ...INSTRUMENTED_MODULE_NAMES, ...IORedisDependencies])];\n });\n}\n"],"names":[],"mappings":";;;;AAQA,MAAM,mBAAA,GAAsB,CAAC,sBAAsB,CAAA;AAW5C,SAAS,gBAAA,CAAiB,IAAA,EAAY,eAAA,EAA0B,wBAAA,EAA0C;AAC/G,EAAA,IAAI,6BAA6B,KAAA,EAAO;AACtC,IAAA;AAAA,EACF;AAEA,EAAA,IAAA,CAAK,IAAA,CAAK,cAAA,EAAgB,CAAC,WAAA,KAA6B;AACtD,IAAA,IAAI,IAAA,CAAK,SAAS,QAAA,EAAU;AAC1B,MAAA;AAAA,IACF;AAIA,IAAA,IAAI,IAAA,CAAK,SAAS,GAAA,EAAK;AACrB,MAAA;AAAA,IACF;AAIA,IAAA,MAAM,YAAA,GAAe,kBAAA,CAAmB,WAAA,CAAY,MAAM,CAAA;AAE1D,IAAA,IAAI,CAAC,eAAA,IAAmB,CAAC,YAAA,EAAc;AACrC,MAAA;AAAA,IACF;AAEA,IAAA,WAAA,CAAY,YAAA,KAAZ,WAAA,CAAY,YAAA,GAAiB,EAAC,CAAA;AAE9B,IAAA,IAAI,YAAY,YAAA,CAAa,OAAA,KAAY,QAAQ,WAAA,CAAY,YAAA,CAAa,YAAY,MAAA,EAAW;AAC/F,MAAA,WAAA,CAAY,YAAA,CAAa,UAAU,EAAC;AAAA,IACtC,WAAW,CAAC,KAAA,CAAM,QAAQ,WAAA,CAAY,YAAA,CAAa,OAAO,CAAA,EAAG;AAC3D,MAAA,WAAA,CAAY,YAAA,CAAa,OAAA,GAAU,CAAC,WAAA,CAAY,aAAa,OAAO,CAAA;AAAA,IACtE;AAEA,IAAA,WAAA,CAAY,aAAa,OAAA,CAAQ,IAAA,CAAK,uBAAA,CAAwB,EAAE,CAAC,CAAA;AAEjE,IAAA,MAAM,SAAA,GAAa,WAAA,CAAY,SAAA,KAAZ,WAAA,CAAY,YAAc,EAAC,CAAA;AAC9C,IAAA,MAAM,SAAS,SAAA,CAAU,MAAA;AACzB,IAAA,MAAM,cAAA,GAAiB,KAAA,CAAM,OAAA,CAAQ,MAAM,CAAA,GAAI,SAAS,MAAA,GAAS,CAAC,MAAM,CAAA,GAAI,EAAC;AAC7E,IAAA,SAAA,CAAU,MAAA,GAAS,CAAC,mBAAG,IAAI,GAAA,CAAI,CAAC,GAAG,cAAA,EAAgB,GAAG,yBAAA,EAA2B,GAAG,mBAAmB,CAAC,CAAC,CAAA;AAAA,EAC3G,CAAC,CAAA;AACH;;;;"}
|
package/build/esm/vite/utils.js
CHANGED
|
@@ -4,17 +4,23 @@ import * as path from 'path';
|
|
|
4
4
|
import { fileURLToPath } from 'node:url';
|
|
5
5
|
import { resolvePath } from '@nuxt/kit';
|
|
6
6
|
|
|
7
|
-
async function getNitroMajorVersion() {
|
|
7
|
+
async function getNitroMajorVersion(rootDir) {
|
|
8
8
|
try {
|
|
9
9
|
const { getPackageInfo } = await import('local-pkg');
|
|
10
|
-
const
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
10
|
+
const fromPackage = (dir) => ({ paths: [path.join(dir, "package.json")] });
|
|
11
|
+
let provider = await getPackageInfo("nuxt", fromPackage(rootDir));
|
|
12
|
+
if (provider?.packageJson.dependencies?.["@nuxt/nitro-server"]) {
|
|
13
|
+
provider = await getPackageInfo("@nuxt/nitro-server", fromPackage(provider.rootPath)) ?? provider;
|
|
14
14
|
}
|
|
15
|
+
if (!provider?.packageJson.dependencies?.nitro) {
|
|
16
|
+
return 2;
|
|
17
|
+
}
|
|
18
|
+
const info = await getPackageInfo("nitro", fromPackage(provider.rootPath));
|
|
19
|
+
const major = parseInt(info?.version?.split(".")[0] ?? "", 10);
|
|
20
|
+
return isNaN(major) ? 3 : major;
|
|
15
21
|
} catch {
|
|
22
|
+
return 2;
|
|
16
23
|
}
|
|
17
|
-
return 2;
|
|
18
24
|
}
|
|
19
25
|
async function findDefaultSdkInitFile(type, nuxt, options) {
|
|
20
26
|
const possibleFileExtensions = ["ts", "js", "mjs", "cjs", "mts", "cts"];
|
|
@@ -38,8 +44,8 @@ async function findDefaultSdkInitFile(type, nuxt, options) {
|
|
|
38
44
|
return void 0;
|
|
39
45
|
}
|
|
40
46
|
const SERVER_CONFIG_FILENAME = "sentry.server.config";
|
|
41
|
-
function
|
|
42
|
-
return
|
|
47
|
+
function isCloudflarePreset(preset) {
|
|
48
|
+
return !!preset?.replace(/-/g, "_").startsWith("cloudflare");
|
|
43
49
|
}
|
|
44
50
|
function getFilenameFromNodeStartCommand(nodeCommand) {
|
|
45
51
|
const regex = /[^/\\]+\.[^/\\]+$/;
|
|
@@ -141,5 +147,5 @@ function addOTelCommonJSImportAlias(nuxt, isNitroV3 = false) {
|
|
|
141
147
|
}
|
|
142
148
|
}
|
|
143
149
|
|
|
144
|
-
export { QUERY_END_INDICATOR, SENTRY_REEXPORTED_FUNCTIONS, SENTRY_WRAPPED_ENTRY, SENTRY_WRAPPED_FUNCTIONS, SERVER_CONFIG_FILENAME, addOTelCommonJSImportAlias, constructFunctionReExport, constructWrappedFunctionExportQuery, extractFunctionReexportQueryParameters, findDefaultSdkInitFile, getFilenameFromNodeStartCommand, getNitroMajorVersion,
|
|
150
|
+
export { QUERY_END_INDICATOR, SENTRY_REEXPORTED_FUNCTIONS, SENTRY_WRAPPED_ENTRY, SENTRY_WRAPPED_FUNCTIONS, SERVER_CONFIG_FILENAME, addOTelCommonJSImportAlias, constructFunctionReExport, constructWrappedFunctionExportQuery, extractFunctionReexportQueryParameters, findDefaultSdkInitFile, getFilenameFromNodeStartCommand, getNitroMajorVersion, isCloudflarePreset, removeSentryQueryFromPath, toResolvablePath };
|
|
145
151
|
//# 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';\nimport { fileURLToPath } from 'node:url';\nimport type { SentryNuxtModuleOptions } from '../common/types';\nimport { resolvePath } from '@nuxt/kit';\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 */\nexport async function findDefaultSdkInitFile(\n type: 'server' | 'client',\n nuxt?: Nuxt,\n options?: SentryNuxtModuleOptions,\n): Promise<string | undefined> {\n const possibleFileExtensions = ['ts', 'js', 'mjs', 'cjs', 'mts', 'cts'];\n const relativePaths = possibleFileExtensions.map(ext => `sentry.${type}.config.${ext}`);\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 rootDir = options?.configDir ? await resolvePath(options.configDir, { type: 'dir' }) : process.cwd();\n for (const relativePath of relativePaths) {\n const fullPath = path.resolve(rootDir, relativePath);\n if (fs.existsSync(fullPath)) {\n return fullPath;\n }\n }\n\n return undefined;\n}\n\nexport const SERVER_CONFIG_FILENAME = 'sentry.server.config';\n\n/** Builds the value for `node --import`. Node reads it as a URL, so it needs forward slashes on Windows too. */\nexport function toImportSpecifier(fromDir: string, filePath: string): string {\n return `./${path.relative(fromDir, filePath).split(/[\\\\/]/).join('/')}`;\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 * `load()` emits `file://` specifiers because Node's ESM loader rejects bare Windows\n * paths (`ERR_UNSUPPORTED_ESM_URL_SCHEME`), but Rollup's resolver only understands\n * filesystem paths. Returns `undefined` for a malformed `file://` URL.\n *\n * Only exported for testing.\n */\nexport function toResolvablePath(source: string): { path: string; wasFileUrl: boolean } | undefined {\n if (!source.startsWith('file://')) {\n return { path: source, wasFileUrl: false };\n }\n if (source === 'file://' || source === 'file:///') {\n return undefined;\n }\n try {\n const filePath = fileURLToPath(source);\n if (!filePath || filePath === '/' || filePath === '\\\\') {\n return undefined;\n }\n return { path: filePath, wasFileUrl: true };\n } catch {\n return undefined;\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['@opentelemetry/resources'] = '@opentelemetry/resources/build/src/index.js';\n }\n}\n"],"names":[],"mappings":";;;;;;AAYA,eAAsB,oBAAA,GAAwC;AAC5D,EAAA,IAAI;AACF,IAAA,MAAM,EAAE,cAAA,EAAe,GAAI,MAAM,OAAO,WAAW,CAAA;AACnD,IAAA,MAAM,IAAA,GAAO,MAAM,cAAA,CAAe,OAAO,CAAA;AACzC,IAAA,IAAI,MAAM,OAAA,EAAS;AACjB,MAAA,MAAM,KAAA,GAAQ,QAAA,CAAS,IAAA,CAAK,OAAA,CAAQ,KAAA,CAAM,GAAG,CAAA,CAAE,CAAC,CAAA,IAAK,GAAA,EAAK,EAAE,CAAA;AAC5D,MAAA,OAAO,KAAA,CAAM,KAAK,CAAA,GAAI,CAAA,GAAI,KAAA;AAAA,IAC5B;AAAA,EACF,CAAA,CAAA,MAAQ;AAAA,EAER;AACA,EAAA,OAAO,CAAA;AACT;AAKA,eAAsB,sBAAA,CACpB,IAAA,EACA,IAAA,EACA,OAAA,EAC6B;AAC7B,EAAA,MAAM,yBAAyB,C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,GAAW,cAAc,MAAM,CAAA;AACrC,IAAA,IAAI,CAAC,QAAA,IAAY,QAAA,KAAa,GAAA,IAAO,aAAa,IAAA,EAAM;AACtD,MAAA,OAAO,KAAA,CAAA;AAAA,IACT;AACA,IAAA,OAAO,EAAE,IAAA,EAAM,QAAA,EAAU,UAAA,EAAY,IAAA,EAAK;AAAA,EAC5C,CAAA,CAAA,MAAQ;AACN,IAAA,OAAO,MAAA;AAAA,EACT;AACF;AAYO,SAAS,0BAAA,CAA2B,IAAA,EAAY,SAAA,GAAY,KAAA,EAAa;AAC9E,EAAA,IAAI,CAAC,IAAA,CAAK,OAAA,CAAQ,GAAA,IAAO,SAAA,EAAW;AAClC,IAAA;AAAA,EACF;AAEA,EAAA,IAAI,CAAC,IAAA,CAAK,OAAA,CAAQ,KAAA,EAAO;AACvB,IAAA,IAAA,CAAK,OAAA,CAAQ,QAAQ,EAAC;AAAA,EACxB;AAEA,EAAA,IAAI,CAAC,IAAA,CAAK,OAAA,CAAQ,KAAA,CAAM,0BAA0B,CAAA,EAAG;AACnD,IAAA,IAAA,CAAK,OAAA,CAAQ,KAAA,CAAM,0BAA0B,CAAA,GAAI,6CAAA;AAAA,EACnD;AACF;;;;"}
|
|
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';\nimport { fileURLToPath } from 'node:url';\nimport type { SentryNuxtModuleOptions } from '../common/types';\nimport { resolvePath } from '@nuxt/kit';\n\n/**\n * Gets the major version of the Nitro package used by the app's Nuxt installation.\n * Returns 2 as the default if the version cannot be determined.\n *\n * Nitro v2 is published as `nitropack`, v3 as `nitro`. Resolving `nitro` directly is\n * unreliable: module resolution walks up the directory tree, so in a monorepo an\n * unrelated `nitro` v3 above the app wins even when the app's Nuxt uses `nitropack` v2.\n * Instead, follow the dependency chain Nuxt itself imports Nitro through:\n * `nuxt` -> (`@nuxt/nitro-server` ->) `nitro` | `nitropack`.\n */\nexport async function getNitroMajorVersion(rootDir: string): Promise<number> {\n try {\n const { getPackageInfo } = await import('local-pkg');\n\n // `paths` entries must point at a file: for a bare directory, resolution starts at the\n // directory's parent and skips the directory's own `node_modules`, so a hoisted copy higher\n // up the tree (e.g. a monorepo root) wins over the app's actual dependency.\n const fromPackage = (dir: string): { paths: string[] } => ({ paths: [path.join(dir, 'package.json')] });\n\n // The package that declares the Nitro dependency: `nuxt` itself, or `@nuxt/nitro-server` (Nuxt >= 3.21) when nuxt delegates to it\n let provider = await getPackageInfo('nuxt', fromPackage(rootDir));\n if (provider?.packageJson.dependencies?.['@nuxt/nitro-server']) {\n provider = (await getPackageInfo('@nuxt/nitro-server', fromPackage(provider.rootPath))) ?? provider;\n }\n\n if (!provider?.packageJson.dependencies?.nitro) {\n return 2;\n }\n\n const info = await getPackageInfo('nitro', fromPackage(provider.rootPath));\n const major = parseInt(info?.version?.split('.')[0] ?? '', 10);\n // The provider imports `nitro` (not `nitropack`), so it is at least v3 even if the version is unreadable\n return isNaN(major) ? 3 : major;\n } catch {\n // If local-pkg is unavailable or resolution fails, default to v2\n return 2;\n }\n}\n\n/**\n * Find the default SDK init file for the given type (client or server).\n */\nexport async function findDefaultSdkInitFile(\n type: 'server' | 'client',\n nuxt?: Nuxt,\n options?: SentryNuxtModuleOptions,\n): Promise<string | undefined> {\n const possibleFileExtensions = ['ts', 'js', 'mjs', 'cjs', 'mts', 'cts'];\n const relativePaths = possibleFileExtensions.map(ext => `sentry.${type}.config.${ext}`);\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 rootDir = options?.configDir ? await resolvePath(options.configDir, { type: 'dir' }) : process.cwd();\n for (const relativePath of relativePaths) {\n const fullPath = path.resolve(rootDir, relativePath);\n if (fs.existsSync(fullPath)) {\n return fullPath;\n }\n }\n\n return undefined;\n}\n\nexport const SERVER_CONFIG_FILENAME = 'sentry.server.config';\n\n/** Whether a resolved Nitro preset targets Cloudflare (workerd). Nitro normalizes preset names, so any `cloudflare*` spelling matches. */\nexport function isCloudflarePreset(preset: string | undefined): boolean {\n return !!preset?.replace(/-/g, '_').startsWith('cloudflare');\n}\n\n/** Builds the value for `node --import`. Node reads it as a URL, so it needs forward slashes on Windows too. */\nexport function toImportSpecifier(fromDir: string, filePath: string): string {\n return `./${path.relative(fromDir, filePath).split(/[\\\\/]/).join('/')}`;\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 * `load()` emits `file://` specifiers because Node's ESM loader rejects bare Windows\n * paths (`ERR_UNSUPPORTED_ESM_URL_SCHEME`), but Rollup's resolver only understands\n * filesystem paths. Returns `undefined` for a malformed `file://` URL.\n *\n * Only exported for testing.\n */\nexport function toResolvablePath(source: string): { path: string; wasFileUrl: boolean } | undefined {\n if (!source.startsWith('file://')) {\n return { path: source, wasFileUrl: false };\n }\n if (source === 'file://' || source === 'file:///') {\n return undefined;\n }\n try {\n const filePath = fileURLToPath(source);\n if (!filePath || filePath === '/' || filePath === '\\\\') {\n return undefined;\n }\n return { path: filePath, wasFileUrl: true };\n } catch {\n return undefined;\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['@opentelemetry/resources'] = '@opentelemetry/resources/build/src/index.js';\n }\n}\n"],"names":[],"mappings":";;;;;;AAkBA,eAAsB,qBAAqB,OAAA,EAAkC;AAC3E,EAAA,IAAI;AACF,IAAA,MAAM,EAAE,cAAA,EAAe,GAAI,MAAM,OAAO,WAAW,CAAA;AAKnD,IAAA,MAAM,WAAA,GAAc,CAAC,GAAA,MAAsC,EAAE,KAAA,EAAO,CAAC,IAAA,CAAK,IAAA,CAAK,GAAA,EAAK,cAAc,CAAC,CAAA,EAAE,CAAA;AAGrG,IAAA,IAAI,WAAW,MAAM,cAAA,CAAe,MAAA,EAAQ,WAAA,CAAY,OAAO,CAAC,CAAA;AAChE,IAAA,IAAI,QAAA,EAAU,WAAA,CAAY,YAAA,GAAe,oBAAoB,CAAA,EAAG;AAC9D,MAAA,QAAA,GAAY,MAAM,cAAA,CAAe,oBAAA,EAAsB,YAAY,QAAA,CAAS,QAAQ,CAAC,CAAA,IAAM,QAAA;AAAA,IAC7F;AAEA,IAAA,IAAI,CAAC,QAAA,EAAU,WAAA,CAAY,YAAA,EAAc,KAAA,EAAO;AAC9C,MAAA,OAAO,CAAA;AAAA,IACT;AAEA,IAAA,MAAM,OAAO,MAAM,cAAA,CAAe,S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AAAA;AACF,GACF;AACJ;AASO,SAAS,iBAAiB,MAAA,EAAmE;AAClG,EAAA,IAAI,CAAC,MAAA,CAAO,UAAA,CAAW,SAAS,CAAA,EAAG;AACjC,IAAA,OAAO,EAAE,IAAA,EAAM,MAAA,EAAQ,UAAA,EAAY,KAAA,EAAM;AAAA,EAC3C;AACA,EAAA,IAAI,MAAA,KAAW,SAAA,IAAa,MAAA,KAAW,UAAA,EAAY;AACjD,IAAA,OAAO,MAAA;AAAA,EACT;AACA,EAAA,IAAI;AACF,IAAA,MAAM,QAAA,GAAW,cAAc,MAAM,CAAA;AACrC,IAAA,IAAI,CAAC,QAAA,IAAY,QAAA,KAAa,GAAA,IAAO,aAAa,IAAA,EAAM;AACtD,MAAA,OAAO,KAAA,CAAA;AAAA,IACT;AACA,IAAA,OAAO,EAAE,IAAA,EAAM,QAAA,EAAU,UAAA,EAAY,IAAA,EAAK;AAAA,EAC5C,CAAA,CAAA,MAAQ;AACN,IAAA,OAAO,MAAA;AAAA,EACT;AACF;AAYO,SAAS,0BAAA,CAA2B,IAAA,EAAY,SAAA,GAAY,KAAA,EAAa;AAC9E,EAAA,IAAI,CAAC,IAAA,CAAK,OAAA,CAAQ,GAAA,IAAO,SAAA,EAAW;AAClC,IAAA;AAAA,EACF;AAEA,EAAA,IAAI,CAAC,IAAA,CAAK,OAAA,CAAQ,KAAA,EAAO;AACvB,IAAA,IAAA,CAAK,OAAA,CAAQ,QAAQ,EAAC;AAAA,EACxB;AAEA,EAAA,IAAI,CAAC,IAAA,CAAK,OAAA,CAAQ,KAAA,CAAM,0BAA0B,CAAA,EAAG;AACnD,IAAA,IAAA,CAAK,OAAA,CAAQ,KAAA,CAAM,0BAA0B,CAAA,GAAI,6CAAA;AAAA,EACnD;AACF;;;;"}
|
|
@@ -1,4 +1,14 @@
|
|
|
1
|
-
/** Global flag set by the generated
|
|
1
|
+
/** Global flag set by the generated runtime-flags module before the Sentry server config evaluates. */
|
|
2
2
|
export declare const NUXT_DEV_MODE_FLAG = "__SENTRY_NUXT_DEV_MODE__";
|
|
3
|
-
/**
|
|
3
|
+
/** Global flag set by the generated runtime-flags module during a prerender build. */
|
|
4
|
+
export declare const NUXT_PRERENDER_FLAG = "__SENTRY_NUXT_PRERENDER__";
|
|
5
|
+
/** Global flag set by the Nuxt server SDK after a successful `init`, to guard against a second init. */
|
|
6
|
+
export declare const NUXT_SERVER_INITIALIZED_FLAG = "__SENTRY_NUXT_SERVER_INITIALIZED__";
|
|
7
|
+
/** Whether the server runs in `nuxt dev`. */
|
|
4
8
|
export declare function isNuxtDevRuntime(): boolean;
|
|
9
|
+
/** Whether the server bundle is executed by the Nitro prerenderer at build time. */
|
|
10
|
+
export declare function isNuxtPrerenderRuntime(): boolean;
|
|
11
|
+
/** Whether a Nuxt server SDK `init` already ran in this process. */
|
|
12
|
+
export declare function isNuxtServerInitialized(): boolean;
|
|
13
|
+
/** Records that the Nuxt server SDK initialized in this process. */
|
|
14
|
+
export declare function markNuxtServerInitialized(): void;
|
|
@@ -51,6 +51,10 @@ export type SentryNuxtModuleOptions = BuildTimeOptionsBase & {
|
|
|
51
51
|
* If `"experimental_dynamic-import"` is enabled, the Sentry SDK wraps the server entry file with `import()`.
|
|
52
52
|
*
|
|
53
53
|
* @default undefined
|
|
54
|
+
*
|
|
55
|
+
* @deprecated The Sentry server config is bundled into the Nitro server build by default now and
|
|
56
|
+
* initializes itself at server startup — no `node --import` preload and no inject mode needed.
|
|
57
|
+
* Remove this option to use the default behavior. It will be removed in a future major version.
|
|
54
58
|
*/
|
|
55
59
|
autoInjectServerSentry?: 'top-level-import' | 'experimental_dynamic-import';
|
|
56
60
|
/**
|
|
@@ -80,6 +84,9 @@ export type SentryNuxtModuleOptions = BuildTimeOptionsBase & {
|
|
|
80
84
|
* Any wrapped export is expected to be an async function.
|
|
81
85
|
*
|
|
82
86
|
* @default ['default', 'handler', 'server']
|
|
87
|
+
*
|
|
88
|
+
* @deprecated Only used with the deprecated `autoInjectServerSentry: 'experimental_dynamic-import'`
|
|
89
|
+
* mode. It will be removed in a future major version together with that mode.
|
|
83
90
|
*/
|
|
84
91
|
experimental_entrypointWrappedFunctions?: string[];
|
|
85
92
|
};
|
package/build/module/module.json
CHANGED