@sentry/nuxt 10.53.1 → 10.54.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/client/piniaIntegration.js +7 -19
- package/build/cjs/client/piniaIntegration.js.map +1 -1
- package/build/cjs/client/sdk.js +2 -9
- package/build/cjs/client/sdk.js.map +1 -1
- package/build/cjs/client/vueIntegration.js +3 -10
- package/build/cjs/client/vueIntegration.js.map +1 -1
- package/build/cjs/common/debug-build.js +0 -5
- package/build/cjs/common/debug-build.js.map +1 -1
- package/build/cjs/module.js +52 -107
- package/build/cjs/module.js.map +1 -1
- package/build/cjs/server/sdk.js +20 -60
- package/build/cjs/server/sdk.js.map +1 -1
- package/build/cjs/vendor/server-template.js +0 -6
- package/build/cjs/vendor/server-template.js.map +1 -1
- package/build/cjs/vite/addServerConfig.js +45 -144
- package/build/cjs/vite/addServerConfig.js.map +1 -1
- package/build/cjs/vite/databaseConfig.js +10 -32
- package/build/cjs/vite/databaseConfig.js.map +1 -1
- package/build/cjs/vite/middlewareConfig.js +11 -46
- package/build/cjs/vite/middlewareConfig.js.map +1 -1
- package/build/cjs/vite/sentryVitePlugin.js +7 -24
- package/build/cjs/vite/sentryVitePlugin.js.map +1 -1
- package/build/cjs/vite/sourceMaps.js +89 -248
- package/build/cjs/vite/sourceMaps.js.map +1 -1
- package/build/cjs/vite/storageConfig.js +4 -10
- package/build/cjs/vite/storageConfig.js.map +1 -1
- package/build/cjs/vite/utils.js +51 -143
- package/build/cjs/vite/utils.js.map +1 -1
- package/build/esm/client/piniaIntegration.js +7 -19
- package/build/esm/client/piniaIntegration.js.map +1 -1
- package/build/esm/client/sdk.js +2 -9
- package/build/esm/client/sdk.js.map +1 -1
- package/build/esm/client/vueIntegration.js +3 -10
- package/build/esm/client/vueIntegration.js.map +1 -1
- package/build/esm/common/debug-build.js +0 -5
- package/build/esm/common/debug-build.js.map +1 -1
- package/build/esm/module.js +52 -107
- package/build/esm/module.js.map +1 -1
- package/build/esm/package.json +1 -1
- package/build/esm/server/sdk.js +20 -60
- package/build/esm/server/sdk.js.map +1 -1
- package/build/esm/vendor/server-template.js +0 -6
- package/build/esm/vendor/server-template.js.map +1 -1
- package/build/esm/vite/addServerConfig.js +45 -144
- package/build/esm/vite/addServerConfig.js.map +1 -1
- package/build/esm/vite/databaseConfig.js +10 -32
- package/build/esm/vite/databaseConfig.js.map +1 -1
- package/build/esm/vite/middlewareConfig.js +11 -46
- package/build/esm/vite/middlewareConfig.js.map +1 -1
- package/build/esm/vite/sentryVitePlugin.js +7 -24
- package/build/esm/vite/sentryVitePlugin.js.map +1 -1
- package/build/esm/vite/sourceMaps.js +89 -248
- package/build/esm/vite/sourceMaps.js.map +1 -1
- package/build/esm/vite/storageConfig.js +4 -10
- package/build/esm/vite/storageConfig.js.map +1 -1
- package/build/esm/vite/utils.js +51 -143
- package/build/esm/vite/utils.js.map +1 -1
- package/build/module/module.d.mts +17 -0
- package/build/module/module.d.ts +17 -0
- package/build/module/module.json +1 -1
- package/build/module/module.mjs +6 -6
- package/build/types/common/types.d.ts +17 -0
- package/build/types/common/types.d.ts.map +1 -1
- package/build/types/vite/utils.d.ts +2 -1
- package/build/types/vite/utils.d.ts.map +1 -1
- package/package.json +8 -8
|
@@ -4,234 +4,135 @@ import { debug } from '@sentry/core';
|
|
|
4
4
|
import * as fs from 'fs';
|
|
5
5
|
import { getFilenameFromNodeStartCommand, SENTRY_WRAPPED_ENTRY, removeSentryQueryFromPath, SENTRY_WRAPPED_FUNCTIONS, SENTRY_REEXPORTED_FUNCTIONS, constructFunctionReExport, constructWrappedFunctionExportQuery, QUERY_END_INDICATOR } from './utils.js';
|
|
6
6
|
|
|
7
|
-
const SERVER_CONFIG_FILENAME =
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
*
|
|
12
|
-
* By adding a Rollup plugin to the Nitro Rollup options, the Sentry server config is transpiled and emitted to the server build.
|
|
13
|
-
*/
|
|
14
|
-
function addServerConfigToBuild(
|
|
15
|
-
moduleOptions,
|
|
16
|
-
nitro,
|
|
17
|
-
serverConfigFile,
|
|
18
|
-
) {
|
|
19
|
-
nitro.hooks.hook('rollup:before', (nitro, rollupConfig) => {
|
|
20
|
-
if (rollupConfig?.plugins === null || rollupConfig?.plugins === undefined) {
|
|
7
|
+
const SERVER_CONFIG_FILENAME = "sentry.server.config";
|
|
8
|
+
function addServerConfigToBuild(moduleOptions, nitro, serverConfigFile) {
|
|
9
|
+
nitro.hooks.hook("rollup:before", (nitro2, rollupConfig) => {
|
|
10
|
+
if (rollupConfig?.plugins === null || rollupConfig?.plugins === void 0) {
|
|
21
11
|
rollupConfig.plugins = [];
|
|
22
12
|
} else if (!Array.isArray(rollupConfig.plugins)) {
|
|
23
|
-
// `rollupConfig.plugins` can be a single plugin, so we want to put it into an array so that we can push our own plugin
|
|
24
13
|
rollupConfig.plugins = [rollupConfig.plugins];
|
|
25
14
|
}
|
|
26
|
-
|
|
27
|
-
rollupConfig.plugins.push(injectServerConfigPlugin(nitro, serverConfigFile, moduleOptions.debug));
|
|
15
|
+
rollupConfig.plugins.push(injectServerConfigPlugin(nitro2, serverConfigFile, moduleOptions.debug));
|
|
28
16
|
});
|
|
29
17
|
}
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* Adds the Sentry server config import at the top of the server entry file to load the SDK on the server.
|
|
33
|
-
* This is necessary for environments where modifying the node option `--import` is not possible.
|
|
34
|
-
* However, only limited tracing instrumentation is supported when doing this.
|
|
35
|
-
*/
|
|
36
18
|
function addSentryTopImport(moduleOptions, nitro) {
|
|
37
|
-
nitro.hooks.hook(
|
|
38
|
-
const fileNameFromCommand =
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
// other presets ('node-server' or 'vercel') have an index.mjs
|
|
42
|
-
const presetsWithServerFile = ['netlify'];
|
|
43
|
-
|
|
44
|
-
const entryFileName = fileNameFromCommand
|
|
45
|
-
? fileNameFromCommand
|
|
46
|
-
: typeof nitro.options.rollupConfig?.output.entryFileNames === 'string'
|
|
47
|
-
? nitro.options.rollupConfig?.output.entryFileNames
|
|
48
|
-
: presetsWithServerFile.includes(nitro.options.preset)
|
|
49
|
-
? 'server.mjs'
|
|
50
|
-
: 'index.mjs';
|
|
51
|
-
|
|
19
|
+
nitro.hooks.hook("close", async () => {
|
|
20
|
+
const fileNameFromCommand = nitro.options.commands.preview && getFilenameFromNodeStartCommand(nitro.options.commands.preview);
|
|
21
|
+
const presetsWithServerFile = ["netlify"];
|
|
22
|
+
const entryFileName = fileNameFromCommand ? fileNameFromCommand : typeof nitro.options.rollupConfig?.output.entryFileNames === "string" ? nitro.options.rollupConfig?.output.entryFileNames : presetsWithServerFile.includes(nitro.options.preset) ? "server.mjs" : "index.mjs";
|
|
52
23
|
const serverDirResolver = createResolver(nitro.options.output.serverDir);
|
|
53
24
|
const entryFilePath = serverDirResolver.resolve(entryFileName);
|
|
54
|
-
|
|
55
25
|
try {
|
|
56
|
-
fs.readFile(entryFilePath,
|
|
57
|
-
const updatedContent = `import './${SERVER_CONFIG_FILENAME}.mjs'
|
|
58
|
-
|
|
59
|
-
fs.writeFile(entryFilePath, updatedContent,
|
|
26
|
+
fs.readFile(entryFilePath, "utf8", (err, data) => {
|
|
27
|
+
const updatedContent = `import './${SERVER_CONFIG_FILENAME}.mjs';
|
|
28
|
+
${data}`;
|
|
29
|
+
fs.writeFile(entryFilePath, updatedContent, "utf8", () => {
|
|
60
30
|
if (moduleOptions.debug) {
|
|
61
|
-
// eslint-disable-next-line no-console
|
|
62
31
|
console.log(
|
|
63
|
-
`[Sentry] Successfully added the Sentry import to the server entry file "\`${entryFilePath}\`"
|
|
32
|
+
`[Sentry] Successfully added the Sentry import to the server entry file "\`${entryFilePath}\`"`
|
|
64
33
|
);
|
|
65
34
|
}
|
|
66
35
|
});
|
|
67
36
|
});
|
|
68
37
|
} catch (err) {
|
|
69
38
|
if (moduleOptions.debug) {
|
|
70
|
-
// eslint-disable-next-line no-console
|
|
71
39
|
console.warn(
|
|
72
40
|
`[Sentry] An error occurred when trying to add the Sentry import to the server entry file "\`${entryFilePath}\`":`,
|
|
73
|
-
err
|
|
41
|
+
err
|
|
74
42
|
);
|
|
75
43
|
}
|
|
76
44
|
}
|
|
77
45
|
});
|
|
78
46
|
}
|
|
79
|
-
|
|
80
|
-
/**
|
|
81
|
-
* This function modifies the Rollup configuration to include a plugin that wraps the entry file with a dynamic import (`import()`)
|
|
82
|
-
* and adds the Sentry server config with the static `import` declaration.
|
|
83
|
-
*
|
|
84
|
-
* With this, the Sentry server config can be loaded before all other modules of the application (which is needed for import-in-the-middle).
|
|
85
|
-
* See: https://nodejs.org/api/module.html#enabling
|
|
86
|
-
*/
|
|
87
|
-
function addDynamicImportEntryFileWrapper(
|
|
88
|
-
nitro,
|
|
89
|
-
serverConfigFile,
|
|
90
|
-
moduleOptions
|
|
91
|
-
,
|
|
92
|
-
) {
|
|
47
|
+
function addDynamicImportEntryFileWrapper(nitro, serverConfigFile, moduleOptions) {
|
|
93
48
|
if (!nitro.options.rollupConfig) {
|
|
94
49
|
nitro.options.rollupConfig = { output: {} };
|
|
95
50
|
}
|
|
96
|
-
|
|
97
|
-
if (nitro.options.rollupConfig?.plugins === null || nitro.options.rollupConfig?.plugins === undefined) {
|
|
51
|
+
if (nitro.options.rollupConfig?.plugins === null || nitro.options.rollupConfig?.plugins === void 0) {
|
|
98
52
|
nitro.options.rollupConfig.plugins = [];
|
|
99
53
|
} else if (!Array.isArray(nitro.options.rollupConfig.plugins)) {
|
|
100
|
-
// `rollupConfig.plugins` can be a single plugin, so we want to put it into an array so that we can push our own plugin
|
|
101
54
|
nitro.options.rollupConfig.plugins = [nitro.options.rollupConfig.plugins];
|
|
102
55
|
}
|
|
103
|
-
|
|
104
56
|
nitro.options.rollupConfig.plugins.push(
|
|
105
57
|
wrapEntryWithDynamicImport({
|
|
106
58
|
resolvedSentryConfigPath: createResolver(nitro.options.rootDir).resolve(`/${serverConfigFile}`),
|
|
107
|
-
experimental_entrypointWrappedFunctions: moduleOptions.experimental_entrypointWrappedFunctions
|
|
108
|
-
})
|
|
59
|
+
experimental_entrypointWrappedFunctions: moduleOptions.experimental_entrypointWrappedFunctions
|
|
60
|
+
})
|
|
109
61
|
);
|
|
110
62
|
}
|
|
111
|
-
|
|
112
|
-
/**
|
|
113
|
-
* Rollup plugin to include the Sentry server configuration file to the server build output.
|
|
114
|
-
*/
|
|
115
63
|
function injectServerConfigPlugin(nitro, serverConfigFile, isDebug) {
|
|
116
|
-
const filePrefix =
|
|
117
|
-
|
|
64
|
+
const filePrefix = "\0virtual:sentry-server-config:";
|
|
118
65
|
return {
|
|
119
|
-
name:
|
|
120
|
-
|
|
66
|
+
name: "rollup-plugin-inject-sentry-server-config",
|
|
121
67
|
buildStart() {
|
|
122
68
|
const configPath = createResolver(nitro.options.rootDir).resolve(`/${serverConfigFile}`);
|
|
123
|
-
|
|
124
69
|
if (!existsSync(configPath)) {
|
|
125
70
|
if (isDebug) {
|
|
126
71
|
debug.log(`[Sentry] Sentry server config file not found: ${configPath}`);
|
|
127
72
|
}
|
|
128
73
|
return;
|
|
129
74
|
}
|
|
130
|
-
|
|
131
|
-
// Emitting a file adds it to the build output (Rollup is aware of the file, and we can later return the code in resolveId)
|
|
132
75
|
this.emitFile({
|
|
133
|
-
type:
|
|
76
|
+
type: "chunk",
|
|
134
77
|
id: `${filePrefix}${serverConfigFile}`,
|
|
135
|
-
fileName: `${SERVER_CONFIG_FILENAME}.mjs
|
|
78
|
+
fileName: `${SERVER_CONFIG_FILENAME}.mjs`
|
|
136
79
|
});
|
|
137
80
|
},
|
|
138
|
-
|
|
139
81
|
resolveId(source) {
|
|
140
82
|
if (source.startsWith(filePrefix)) {
|
|
141
|
-
const originalFilePath = source.replace(filePrefix,
|
|
83
|
+
const originalFilePath = source.replace(filePrefix, "");
|
|
142
84
|
const configPath = createResolver(nitro.options.rootDir).resolve(`/${originalFilePath}`);
|
|
143
|
-
|
|
144
85
|
return { id: configPath };
|
|
145
86
|
}
|
|
146
87
|
return null;
|
|
147
|
-
}
|
|
88
|
+
}
|
|
148
89
|
};
|
|
149
90
|
}
|
|
150
|
-
|
|
151
|
-
/**
|
|
152
|
-
* A Rollup plugin which wraps the server entry with a dynamic `import()`. This makes it possible to initialize Sentry first
|
|
153
|
-
* by using a regular `import` and load the server after that.
|
|
154
|
-
* This also works with serverless `handler` functions, as it re-exports the `handler`.
|
|
155
|
-
*/
|
|
156
91
|
function wrapEntryWithDynamicImport({
|
|
157
92
|
resolvedSentryConfigPath,
|
|
158
93
|
experimental_entrypointWrappedFunctions,
|
|
159
|
-
debug
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
) {
|
|
163
|
-
// In order to correctly import the server config file
|
|
164
|
-
// and dynamically import the nitro runtime, we need to
|
|
165
|
-
// mark the resolutionId with '\0raw' to fall into the
|
|
166
|
-
// raw chunk group, c.f. https://github.com/nitrojs/nitro/commit/8b4a408231bdc222569a32ce109796a41eac4aa6#diff-e58102d2230f95ddeef2662957b48d847a6e891e354cfd0ae6e2e03ce848d1a2R142
|
|
167
|
-
const resolutionIdPrefix = '\0raw';
|
|
168
|
-
|
|
94
|
+
debug: debug2
|
|
95
|
+
}) {
|
|
96
|
+
const resolutionIdPrefix = "\0raw";
|
|
169
97
|
return {
|
|
170
|
-
name:
|
|
98
|
+
name: "sentry-wrap-entry-with-dynamic-import",
|
|
171
99
|
async resolveId(source, importer, options) {
|
|
172
100
|
if (source.includes(`/${SERVER_CONFIG_FILENAME}`)) {
|
|
173
101
|
return { id: source, moduleSideEffects: true };
|
|
174
102
|
}
|
|
175
|
-
|
|
176
|
-
if (source === 'import-in-the-middle/hook.mjs') {
|
|
177
|
-
// We are importing "import-in-the-middle" in the returned code of the `load()` function below
|
|
178
|
-
// By setting `moduleSideEffects` to `true`, the import is added to the bundle, although nothing is imported from it
|
|
179
|
-
// By importing "import-in-the-middle/hook.mjs", we can make sure this file is included, as not all node builders are including files imported with `module.register()`.
|
|
180
|
-
// Prevents the error "Failed to register ESM hook Error: Cannot find module 'import-in-the-middle/hook.mjs'"
|
|
103
|
+
if (source === "import-in-the-middle/hook.mjs") {
|
|
181
104
|
return { id: source, moduleSideEffects: true, external: true };
|
|
182
105
|
}
|
|
183
|
-
|
|
184
|
-
if (options.isEntry && source.includes('.mjs') && !source.includes(`.mjs${SENTRY_WRAPPED_ENTRY}`)) {
|
|
106
|
+
if (options.isEntry && source.includes(".mjs") && !source.includes(`.mjs${SENTRY_WRAPPED_ENTRY}`)) {
|
|
185
107
|
const resolution = await this.resolve(source, importer, options);
|
|
186
|
-
|
|
187
|
-
// If it cannot be resolved or is external, just return it so that Rollup can display an error
|
|
188
108
|
if (!resolution || resolution?.external) return resolution;
|
|
189
|
-
|
|
190
109
|
const moduleInfo = await this.load(resolution);
|
|
191
|
-
|
|
192
110
|
moduleInfo.moduleSideEffects = true;
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
.concat(
|
|
201
|
-
constructWrappedFunctionExportQuery(
|
|
202
|
-
moduleInfo.exportedBindings,
|
|
203
|
-
experimental_entrypointWrappedFunctions,
|
|
204
|
-
debug,
|
|
205
|
-
),
|
|
206
|
-
)
|
|
207
|
-
.concat(QUERY_END_INDICATOR)}`;
|
|
111
|
+
return resolution.id.includes(`.mjs${SENTRY_WRAPPED_ENTRY}`) ? resolution.id : `${resolutionIdPrefix}${resolution.id.concat(SENTRY_WRAPPED_ENTRY).concat(
|
|
112
|
+
constructWrappedFunctionExportQuery(
|
|
113
|
+
moduleInfo.exportedBindings,
|
|
114
|
+
experimental_entrypointWrappedFunctions,
|
|
115
|
+
debug2
|
|
116
|
+
)
|
|
117
|
+
).concat(QUERY_END_INDICATOR)}`;
|
|
208
118
|
}
|
|
209
119
|
return null;
|
|
210
120
|
},
|
|
211
121
|
load(id) {
|
|
212
122
|
if (id.includes(`.mjs${SENTRY_WRAPPED_ENTRY}`)) {
|
|
213
123
|
const entryId = removeSentryQueryFromPath(id).slice(resolutionIdPrefix.length);
|
|
214
|
-
|
|
215
|
-
// Mostly useful for serverless `handler` functions
|
|
216
|
-
const reExportedFunctions =
|
|
217
|
-
id.includes(SENTRY_WRAPPED_FUNCTIONS) || id.includes(SENTRY_REEXPORTED_FUNCTIONS)
|
|
218
|
-
? constructFunctionReExport(id, entryId)
|
|
219
|
-
: '';
|
|
220
|
-
|
|
124
|
+
const reExportedFunctions = id.includes(SENTRY_WRAPPED_FUNCTIONS) || id.includes(SENTRY_REEXPORTED_FUNCTIONS) ? constructFunctionReExport(id, entryId) : "";
|
|
221
125
|
return (
|
|
222
126
|
// Regular `import` of the Sentry config
|
|
223
|
-
`import ${JSON.stringify(resolvedSentryConfigPath)}
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
"import 'import-in-the-middle/hook.mjs';\n" +
|
|
229
|
-
`${reExportedFunctions}\n`
|
|
127
|
+
`import ${JSON.stringify(resolvedSentryConfigPath)};
|
|
128
|
+
import(${JSON.stringify(entryId)});
|
|
129
|
+
import 'import-in-the-middle/hook.mjs';
|
|
130
|
+
${reExportedFunctions}
|
|
131
|
+
`
|
|
230
132
|
);
|
|
231
133
|
}
|
|
232
|
-
|
|
233
134
|
return null;
|
|
234
|
-
}
|
|
135
|
+
}
|
|
235
136
|
};
|
|
236
137
|
}
|
|
237
138
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"addServerConfig.js","sources":["../../../src/vite/addServerConfig.ts"],"sourcesContent":["import { existsSync } from 'node:fs';\nimport { createResolver } from '@nuxt/kit';\nimport { debug } from '@sentry/core';\nimport * as fs from 'fs';\nimport type { Nitro } from 'nitropack';\nimport type { InputPluginOption } from 'rollup';\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} from './utils';\n\nconst SERVER_CONFIG_FILENAME = 'sentry.server.config';\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 (which is needed for import-in-the-middle).\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 */\nfunction 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 if (source.includes(`/${SERVER_CONFIG_FILENAME}`)) {\n return { id: source, moduleSideEffects: true };\n }\n\n if (source === 'import-in-the-middle/hook.mjs') {\n // We are importing \"import-in-the-middle\" in the returned code of the `load()` function below\n // By setting `moduleSideEffects` to `true`, the import is added to the bundle, although nothing is imported from it\n // By importing \"import-in-the-middle/hook.mjs\", we can make sure this file is included, as not all node builders are including files imported with `module.register()`.\n // Prevents the error \"Failed to register ESM hook Error: Cannot find module 'import-in-the-middle/hook.mjs'\"\n return { id: source, moduleSideEffects: true, external: true };\n }\n\n if (options.isEntry && source.includes('.mjs') && !source.includes(`.mjs${SENTRY_WRAPPED_ENTRY}`)) {\n const resolution = await this.resolve(source, 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 return null;\n },\n load(id: string) {\n if (id.includes(`.mjs${SENTRY_WRAPPED_ENTRY}`)) {\n const entryId = removeSentryQueryFromPath(id).slice(resolutionIdPrefix.length);\n\n // Mostly useful for serverless `handler` functions\n const reExportedFunctions =\n id.includes(SENTRY_WRAPPED_FUNCTIONS) || id.includes(SENTRY_REEXPORTED_FUNCTIONS)\n ? constructFunctionReExport(id, entryId)\n : '';\n\n return (\n // Regular `import` of the Sentry config\n `import ${JSON.stringify(resolvedSentryConfigPath)};\\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(entryId)});\\n` +\n // By importing \"import-in-the-middle/hook.mjs\", we can make sure this file wil be included, as not all node builders are including files imported with `module.register()`.\n \"import 'import-in-the-middle/hook.mjs';\\n\" +\n `${reExportedFunctions}\\n`\n );\n }\n\n return null;\n },\n };\n}\n"],"names":[],"mappings":";;;;;;AAkBA,MAAM,sBAAA,GAAyB,sBAAsB;;AAErD;AACA;AACA;AACA;AACA;AACO,SAAS,sBAAsB;AACtC,EAAE,aAAa;AACf,EAAE,KAAK;AACP,EAAE,gBAAgB;AAClB,EAAQ;AACR,EAAE,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,eAAe,EAAE,CAAC,KAAK,EAAE,YAAY,KAAK;AAC7D,IAAI,IAAI,YAAY,EAAE,OAAA,KAAY,IAAA,IAAQ,YAAY,EAAE,OAAA,KAAY,SAAS,EAAE;AAC/E,MAAM,YAAY,CAAC,OAAA,GAAU,EAAE;AAC/B,IAAI,CAAA,MAAO,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,YAAY,CAAC,OAAO,CAAC,EAAE;AACrD;AACA,MAAM,YAAY,CAAC,OAAA,GAAU,CAAC,YAAY,CAAC,OAAO,CAAC;AACnD,IAAI;;AAEJ,IAAI,YAAY,CAAC,OAAO,CAAC,IAAI,CAAC,wBAAwB,CAAC,KAAK,EAAE,gBAAgB,EAAE,aAAa,CAAC,KAAK,CAAC,CAAC;AACrG,EAAE,CAAC,CAAC;AACJ;;AAEA;AACA;AACA;AACA;AACA;AACO,SAAS,kBAAkB,CAAC,aAAa,EAA2B,KAAK,EAAe;AAC/F,EAAE,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,OAAO,EAAE,YAAY;AACxC,IAAI,MAAM,mBAAA;AACV,MAAM,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,OAAA,IAAW,+BAA+B,CAAC,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAC;;AAEvG;AACA,IAAI,MAAM,qBAAA,GAAwB,CAAC,SAAS,CAAC;;AAE7C,IAAI,MAAM,gBAAgB;AAC1B,QAAQ;AACR,QAAQ,O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,oBAAA,CAAA,CAAA,CAAA,EAAA;AACA,QAAA,MAAA,OAAA,GAAA,yBAAA,CAAA,EAAA,CAAA,CAAA,KAAA,CAAA,kBAAA,CAAA,MAAA,CAAA;;AAEA;AACA,QAAA,MAAA,mBAAA;AACA,UAAA,EAAA,CAAA,QAAA,CAAA,wBAAA,CAAA,IAAA,EAAA,CAAA,QAAA,CAAA,2BAAA;AACA,cAAA,yBAAA,CAAA,EAAA,EAAA,OAAA;AACA,cAAA,EAAA;;AAEA,QAAA;AACA;AACA,UAAA,CAAA,OAAA,EAAA,IAAA,CAAA,SAAA,CAAA,wBAAA,CAAA,CAAA,GAAA,CAAA;AACA;AACA;AACA,UAAA,CAAA,OAAA,EAAA,IAAA,CAAA,SAAA,CAAA,OAAA,CAAA,CAAA,IAAA,CAAA;AACA;AACA,UAAA,2CAAA;AACA,UAAA,CAAA,EAAA,mBAAA,CAAA,EAAA;AACA;AACA,MAAA;;AAEA,MAAA,OAAA,IAAA;AACA,IAAA,CAAA;AACA,GAAA;AACA;;;;"}
|
|
1
|
+
{"version":3,"file":"addServerConfig.js","sources":["../../../src/vite/addServerConfig.ts"],"sourcesContent":["import { existsSync } from 'node:fs';\nimport { createResolver } from '@nuxt/kit';\nimport { debug } from '@sentry/core';\nimport * as fs from 'fs';\nimport type { Nitro } from 'nitropack';\nimport type { InputPluginOption } from 'rollup';\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} from './utils';\n\nconst SERVER_CONFIG_FILENAME = 'sentry.server.config';\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 (which is needed for import-in-the-middle).\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 */\nfunction 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 if (source.includes(`/${SERVER_CONFIG_FILENAME}`)) {\n return { id: source, moduleSideEffects: true };\n }\n\n if (source === 'import-in-the-middle/hook.mjs') {\n // We are importing \"import-in-the-middle\" in the returned code of the `load()` function below\n // By setting `moduleSideEffects` to `true`, the import is added to the bundle, although nothing is imported from it\n // By importing \"import-in-the-middle/hook.mjs\", we can make sure this file is included, as not all node builders are including files imported with `module.register()`.\n // Prevents the error \"Failed to register ESM hook Error: Cannot find module 'import-in-the-middle/hook.mjs'\"\n return { id: source, moduleSideEffects: true, external: true };\n }\n\n if (options.isEntry && source.includes('.mjs') && !source.includes(`.mjs${SENTRY_WRAPPED_ENTRY}`)) {\n const resolution = await this.resolve(source, 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 return null;\n },\n load(id: string) {\n if (id.includes(`.mjs${SENTRY_WRAPPED_ENTRY}`)) {\n const entryId = removeSentryQueryFromPath(id).slice(resolutionIdPrefix.length);\n\n // Mostly useful for serverless `handler` functions\n const reExportedFunctions =\n id.includes(SENTRY_WRAPPED_FUNCTIONS) || id.includes(SENTRY_REEXPORTED_FUNCTIONS)\n ? constructFunctionReExport(id, entryId)\n : '';\n\n return (\n // Regular `import` of the Sentry config\n `import ${JSON.stringify(resolvedSentryConfigPath)};\\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(entryId)});\\n` +\n // By importing \"import-in-the-middle/hook.mjs\", we can make sure this file wil be included, as not all node builders are including files imported with `module.register()`.\n \"import 'import-in-the-middle/hook.mjs';\\n\" +\n `${reExportedFunctions}\\n`\n );\n }\n\n return null;\n },\n };\n}\n"],"names":["nitro","debug"],"mappings":";;;;;;AAkBA,MAAM,sBAAA,GAAyB,sBAAA;AAOxB,SAAS,sBAAA,CACd,aAAA,EACA,KAAA,EACA,gBAAA,EACM;AACN,EAAA,KAAA,CAAM,KAAA,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iBAAA,GAAoB,IAAA;AAG/B,QAAA,OAAO,WAAW,EAAA,CAAG,QAAA,CAAS,CAAA,IAAA,EAAO,oBAAoB,EAAE,CAAA,GACvD,UAAA,CAAW,EAAA,GACX,CAAA,EAAG,kBAAkB,CAAA,EAAG,UAAA,CAAW,EAAA,CAEhC,MAAA,CAAO,oBAAoB,CAAA,CAC3B,MAAA;AAAA,UACC,mCAAA;AAAA,YACE,UAAA,CAAW,gBAAA;AAAA,YACX,uCAAA;AAAA,YACAA;AAAA;AACF,SACF,CACC,MAAA,CAAO,mBAAmB,CAAC,CAAA,CAAA;AAAA,MACpC;AACA,MAAA,OAAO,IAAA;AAAA,IACT,CAAA;AAAA,IACA,KAAK,EAAA,EAAY;AACf,MAAA,IAAI,EAAA,CAAG,QAAA,CAAS,CAAA,IAAA,EAAO,oBAAoB,EAAE,CAAA,EAAG;AAC9C,QAAA,MAAM,UAAU,yBAAA,CAA0B,EAAE,CAAA,CAAE,KAAA,CAAM,mBAAmB,MAAM,CAAA;AAG7E,QAAA,MAAM,mBAAA,GACJ,EAAA,CAAG,QAAA,CAAS,wBAAwB,CAAA,IAAK,EAAA,CAAG,QAAA,CAAS,2BAA2B,CAAA,GAC5E,yBAAA,CAA0B,EAAA,EAAI,OAAO,CAAA,GACrC,EAAA;AAEN,QAAA;AAAA;AAAA,UAEE,CAAA,OAAA,EAAU,IAAA,CAAK,SAAA,CAAU,wBAAwB,CAAC,CAAA;AAAA,OAAA,EAGxC,IAAA,CAAK,SAAA,CAAU,OAAO,CAAC,CAAA;AAAA;AAAA,EAG9B,mBAAmB;AAAA;AAAA;AAAA,MAE1B;AAEA,MAAA,OAAO,IAAA;AAAA,IACT;AAAA,GACF;AACF;;;;"}
|
|
@@ -2,48 +2,26 @@ import { addServerPlugin, createResolver } from '@nuxt/kit';
|
|
|
2
2
|
import { consoleSandbox } from '@sentry/core';
|
|
3
3
|
import { addServerTemplate } from '../vendor/server-template.js';
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
* Sets up the database instrumentation.
|
|
7
|
-
*/
|
|
8
|
-
function addDatabaseInstrumentation(
|
|
9
|
-
nitro,
|
|
10
|
-
isLegacyNitro,
|
|
11
|
-
moduleOptions,
|
|
12
|
-
) {
|
|
5
|
+
function addDatabaseInstrumentation(nitro, isLegacyNitro, moduleOptions) {
|
|
13
6
|
if (!nitro.experimental?.database) {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
console.log(
|
|
20
|
-
'[Sentry] [Nitro Database Plugin]: No database configuration found. Skipping database instrumentation.',
|
|
21
|
-
);
|
|
22
|
-
});
|
|
23
|
-
|
|
7
|
+
moduleOptions?.debug && consoleSandbox(() => {
|
|
8
|
+
console.log(
|
|
9
|
+
"[Sentry] [Nitro Database Plugin]: No database configuration found. Skipping database instrumentation."
|
|
10
|
+
);
|
|
11
|
+
});
|
|
24
12
|
return;
|
|
25
13
|
}
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* This is a different option than the one in `experimental.database`, this configures multiple database instances.
|
|
29
|
-
* keys represent database names to be passed to `useDatabase(name?)`.
|
|
30
|
-
* We also use the config to populate database span attributes.
|
|
31
|
-
* https://nitro.build/guide/database#configuration
|
|
32
|
-
*/
|
|
33
14
|
const databaseConfig = nitro.database || { default: {} };
|
|
34
|
-
|
|
35
|
-
// Create a virtual module to pass this data to runtime
|
|
36
15
|
addServerTemplate({
|
|
37
|
-
filename:
|
|
16
|
+
filename: "#sentry/database-config.mjs",
|
|
38
17
|
getContents: () => {
|
|
39
18
|
return `export const databaseConfig = ${JSON.stringify(databaseConfig)};`;
|
|
40
|
-
}
|
|
19
|
+
}
|
|
41
20
|
});
|
|
42
|
-
|
|
43
21
|
if (isLegacyNitro) {
|
|
44
|
-
addServerPlugin(createResolver(import.meta.url).resolve(
|
|
22
|
+
addServerPlugin(createResolver(import.meta.url).resolve("./runtime/plugins/database-legacy.server"));
|
|
45
23
|
} else {
|
|
46
|
-
addServerPlugin(createResolver(import.meta.url).resolve(
|
|
24
|
+
addServerPlugin(createResolver(import.meta.url).resolve("./runtime/plugins/database.server"));
|
|
47
25
|
}
|
|
48
26
|
}
|
|
49
27
|
|
|
@@ -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(\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":[],"mappings":";;;;
|
|
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":[],"mappings":";;;;AASO,SAAS,0BAAA,CACd,KAAA,EACA,aAAA,EACA,aAAA,EACM;AACN,EAAA,IAAI,CAAC,KAAA,CAAM,YAAA,EAAc,QAAA,EAAU;AAGjC,IAAA,aAAA,EAAe,KAAA,IACb,eAAe,MAAM;AAEnB,MAAA,OAAA,CAAQ,GAAA;AAAA,QACN;AAAA,OACF;AAAA,IACF,CAAC,CAAA;AAEH,IAAA;AAAA,EACF;AAQA,EAAA,MAAM,iBAAiB,KAAA,CAAM,QAAA,IAAY,EAAE,OAAA,EAAS,EAAC,EAAE;AAGvD,EAAA,iBAAA,CAAkB;AAAA,IAChB,QAAA,EAAU,6BAAA;AAAA,IACV,aAAa,MAAM;AACjB,MAAA,OAAO,CAAA,8BAAA,EAAiC,IAAA,CAAK,SAAA,CAAU,cAAc,CAAC,CAAA,CAAA,CAAA;AAAA,IACxE;AAAA,GACD,CAAA;AAED,EAAA,IAAI,aAAA,EAAe;AACjB,IAAA,eAAA,CAAgB,eAAe,MAAA,CAAA,IAAA,CAAY,GAAG,CAAA,CAAE,OAAA,CAAQ,0CAA0C,CAAC,CAAA;AAAA,EACrG,CAAA,MAAO;AACL,IAAA,eAAA,CAAgB,eAAe,MAAA,CAAA,IAAA,CAAY,GAAG,CAAA,CAAE,OAAA,CAAQ,mCAAmC,CAAC,CAAA;AAAA,EAC9F;AACF;;;;"}
|
|
@@ -1,50 +1,30 @@
|
|
|
1
1
|
import { addServerImports, createResolver } from '@nuxt/kit';
|
|
2
2
|
import * as path from 'path';
|
|
3
3
|
|
|
4
|
-
/**
|
|
5
|
-
* Adds a server import for the middleware instrumentation.
|
|
6
|
-
*/
|
|
7
4
|
function addMiddlewareImports() {
|
|
8
5
|
addServerImports([
|
|
9
6
|
{
|
|
10
|
-
name:
|
|
11
|
-
from: createResolver(import.meta.url).resolve(
|
|
12
|
-
}
|
|
7
|
+
name: "wrapMiddlewareHandlerWithSentry",
|
|
8
|
+
from: createResolver(import.meta.url).resolve("./runtime/hooks/wrapMiddlewareHandler")
|
|
9
|
+
}
|
|
13
10
|
]);
|
|
14
11
|
}
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* Adds middleware instrumentation to the Nitro build.
|
|
18
|
-
*
|
|
19
|
-
* @param nitro Nitro instance
|
|
20
|
-
*/
|
|
21
12
|
function addMiddlewareInstrumentation(nitro) {
|
|
22
|
-
nitro.hooks.hook(
|
|
13
|
+
nitro.hooks.hook("rollup:before", (nitro2, rollupConfig) => {
|
|
23
14
|
if (!rollupConfig.plugins) {
|
|
24
15
|
rollupConfig.plugins = [];
|
|
25
16
|
}
|
|
26
|
-
|
|
27
17
|
if (!Array.isArray(rollupConfig.plugins)) {
|
|
28
18
|
rollupConfig.plugins = [rollupConfig.plugins];
|
|
29
19
|
}
|
|
30
|
-
|
|
31
|
-
rollupConfig.plugins.push(middlewareInstrumentationPlugin(nitro));
|
|
20
|
+
rollupConfig.plugins.push(middlewareInstrumentationPlugin(nitro2));
|
|
32
21
|
});
|
|
33
22
|
}
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* Creates a rollup plugin for the middleware instrumentation by transforming the middleware code.
|
|
37
|
-
*
|
|
38
|
-
* @param nitro Nitro instance
|
|
39
|
-
* @returns The rollup plugin for the middleware instrumentation.
|
|
40
|
-
*/
|
|
41
23
|
function middlewareInstrumentationPlugin(nitro) {
|
|
42
|
-
const middlewareFiles = new Set();
|
|
43
|
-
|
|
24
|
+
const middlewareFiles = /* @__PURE__ */ new Set();
|
|
44
25
|
return {
|
|
45
|
-
name:
|
|
26
|
+
name: "sentry-nuxt-middleware-instrumentation",
|
|
46
27
|
buildStart() {
|
|
47
|
-
// Collect middleware files during build start
|
|
48
28
|
nitro.scannedHandlers?.forEach(({ middleware, handler }) => {
|
|
49
29
|
if (middleware && handler) {
|
|
50
30
|
middlewareFiles.add(handler);
|
|
@@ -52,31 +32,19 @@ function middlewareInstrumentationPlugin(nitro) {
|
|
|
52
32
|
});
|
|
53
33
|
},
|
|
54
34
|
transform(code, id) {
|
|
55
|
-
// Only transform files we've identified as middleware
|
|
56
35
|
if (middlewareFiles.has(id)) {
|
|
57
36
|
const fileName = path.basename(id);
|
|
58
37
|
return {
|
|
59
38
|
code: wrapMiddlewareCode(code, fileName),
|
|
60
|
-
map: null
|
|
39
|
+
map: null
|
|
61
40
|
};
|
|
62
41
|
}
|
|
63
42
|
return null;
|
|
64
|
-
}
|
|
43
|
+
}
|
|
65
44
|
};
|
|
66
45
|
}
|
|
67
|
-
|
|
68
|
-
/**
|
|
69
|
-
* Wraps the middleware user code to instrument it.
|
|
70
|
-
*
|
|
71
|
-
* @param originalCode The original user code of the middleware.
|
|
72
|
-
* @param fileName The name of the middleware file, used for the span name and logging.
|
|
73
|
-
*
|
|
74
|
-
* @returns The wrapped user code of the middleware.
|
|
75
|
-
*/
|
|
76
46
|
function wrapMiddlewareCode(originalCode, fileName) {
|
|
77
|
-
|
|
78
|
-
const cleanFileName = fileName.replace(/\.(ts|js|mjs|mts|cts)$/, '');
|
|
79
|
-
|
|
47
|
+
const cleanFileName = fileName.replace(/\.(ts|js|mjs|mts|cts)$/, "");
|
|
80
48
|
return `
|
|
81
49
|
import { wrapMiddlewareHandlerWithSentry } from '#imports';
|
|
82
50
|
|
|
@@ -92,10 +60,7 @@ function defineInstrumentedHandler(handlerOrObject) {
|
|
|
92
60
|
return defineHandler(wrapMiddlewareHandlerWithSentry(handlerOrObject, '${cleanFileName}'));
|
|
93
61
|
}
|
|
94
62
|
|
|
95
|
-
${originalCode
|
|
96
|
-
.replace(/defineEventHandler\(/g, 'defineInstrumentedEventHandler(')
|
|
97
|
-
.replace(/eventHandler\(/g, 'instrumentedEventHandler(')
|
|
98
|
-
.replace(/defineHandler\(/g, 'defineInstrumentedHandler(')}
|
|
63
|
+
${originalCode.replace(/defineEventHandler\(/g, "defineInstrumentedEventHandler(").replace(/eventHandler\(/g, "instrumentedEventHandler(").replace(/defineHandler\(/g, "defineInstrumentedHandler(")}
|
|
99
64
|
`;
|
|
100
65
|
}
|
|
101
66
|
|
|
@@ -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\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":[],"mappings":";;;
|
|
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":["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;AAOO,SAAS,6BAA6B,KAAA,EAAoB;AAC/D,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,IA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A,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,45 +1,28 @@
|
|
|
1
1
|
import { extractNuxtSourceMapSetting, validateDifferentSourceMapSettings } from './sourceMaps.js';
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
* Creates a Vite plugin that adds the Sentry Vite plugin and validates source map settings.
|
|
5
|
-
*/
|
|
6
|
-
function validateSourceMapsOptionsPlugin(options
|
|
7
|
-
|
|
8
|
-
) {
|
|
3
|
+
function validateSourceMapsOptionsPlugin(options) {
|
|
9
4
|
const { nuxt, moduleOptions, sourceMapsEnabled } = options;
|
|
10
5
|
const isDebug = moduleOptions.debug;
|
|
11
|
-
|
|
12
6
|
return {
|
|
13
|
-
name:
|
|
7
|
+
name: "sentry-nuxt-source-map-validation",
|
|
14
8
|
config(viteConfig, env) {
|
|
15
|
-
|
|
16
|
-
if (!sourceMapsEnabled || env.mode === 'development' || nuxt.options?._prepare) {
|
|
9
|
+
if (!sourceMapsEnabled || env.mode === "development" || nuxt.options?._prepare) {
|
|
17
10
|
return;
|
|
18
11
|
}
|
|
19
|
-
|
|
20
|
-
// Detect runtime from Vite config
|
|
21
|
-
// In Nuxt, SSR builds have build.ssr: true, client builds don't
|
|
22
|
-
const runtime = viteConfig.build?.ssr ? 'server' : 'client';
|
|
23
|
-
|
|
12
|
+
const runtime = viteConfig.build?.ssr ? "server" : "client";
|
|
24
13
|
const nuxtSourceMapSetting = extractNuxtSourceMapSetting(nuxt, runtime);
|
|
25
|
-
|
|
26
|
-
// Initialize build config if needed
|
|
27
14
|
viteConfig.build = viteConfig.build || {};
|
|
28
15
|
const viteSourceMap = viteConfig.build.sourcemap;
|
|
29
|
-
|
|
30
16
|
if (isDebug) {
|
|
31
|
-
// eslint-disable-next-line no-console
|
|
32
17
|
console.log(`[Sentry] Validating Vite config for the ${runtime} runtime.`);
|
|
33
18
|
}
|
|
34
|
-
|
|
35
|
-
// Vite source map options are the same as the Nuxt source map config options (unless overwritten)
|
|
36
19
|
validateDifferentSourceMapSettings({
|
|
37
20
|
nuxtSettingKey: `sourcemap.${runtime}`,
|
|
38
21
|
nuxtSettingValue: nuxtSourceMapSetting,
|
|
39
|
-
otherSettingKey:
|
|
40
|
-
otherSettingValue: viteSourceMap
|
|
22
|
+
otherSettingKey: "viteConfig.build.sourcemap",
|
|
23
|
+
otherSettingValue: viteSourceMap
|
|
41
24
|
});
|
|
42
|
-
}
|
|
25
|
+
}
|
|
43
26
|
};
|
|
44
27
|
}
|
|
45
28
|
|