Skip to content

Commit b459f93

Browse files
committed
style: sprinkle comments
1 parent e061d98 commit b459f93

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

packages/nuxt/src/vite/middlewareConfig.ts

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import * as path from 'path';
44
import type { InputPluginOption } from 'rollup';
55

66
/**
7-
* Adds a template for the middleware instrumentation.
7+
* Adds a server import for the middleware instrumentation.
88
*/
99
export function addMiddlewareImports(): void {
1010
addServerImports([
@@ -34,12 +34,17 @@ export function addMiddlewareInstrumentation(nitro: Nitro): void {
3434
});
3535
}
3636

37+
/**
38+
* Creates a rollup plugin for the middleware instrumentation by transforming the middleware code.
39+
*
40+
* @param nitro Nitro instance
41+
* @returns The rollup plugin for the middleware instrumentation.
42+
*/
3743
function middlewareInstrumentationPlugin(nitro: Nitro): InputPluginOption {
3844
const middlewareFiles = new Set<string>();
3945

4046
return {
4147
name: 'sentry-nuxt-middleware-instrumentation',
42-
4348
buildStart() {
4449
// Collect middleware files during build start
4550
nitro.scannedHandlers?.forEach(({ middleware, handler }) => {
@@ -48,7 +53,6 @@ function middlewareInstrumentationPlugin(nitro: Nitro): InputPluginOption {
4853
}
4954
});
5055
},
51-
5256
transform(code: string, id: string) {
5357
// Only transform files we've identified as middleware
5458
if (middlewareFiles.has(id)) {
@@ -64,6 +68,14 @@ function middlewareInstrumentationPlugin(nitro: Nitro): InputPluginOption {
6468
};
6569
}
6670

71+
/**
72+
* Wraps the middleware user code to instrument it.
73+
*
74+
* @param originalCode The original user code of the middleware.
75+
* @param fileName The name of the middleware file, used for the span name and logging.
76+
*
77+
* @returns The wrapped user code of the middleware.
78+
*/
6779
function wrapMiddlewareCode(originalCode: string, fileName: string): string {
6880
return `
6981
import { instrumentMiddlewareHandler } from '#imports';

0 commit comments

Comments
 (0)