@@ -42,24 +42,6 @@ export function wrapGlobalMiddleware(code: string, id: string, debug: boolean):
4242 return { code : transformed , didWrap, skipped } ;
4343}
4444
45- /**
46- * Adds the wrapMiddlewaresWithSentry import to the code.
47- * Handles 'use client' and 'use server' directives by inserting the import after them.
48- */
49- export function addSentryImport ( code : string ) : string {
50- const sentryImport = "import { wrapMiddlewaresWithSentry } from '@sentry/tanstackstart-react';\n" ;
51-
52- // Check for 'use server' or 'use client' directives, these need to be before any imports
53- const directiveMatch = code . match ( / ^ ( [ ' " ] ) u s e ( c l i e n t | s e r v e r ) \1; ? \s * \n ? / ) ;
54-
55- if ( ! directiveMatch ) {
56- return sentryImport + code ;
57- }
58-
59- const directive = directiveMatch [ 0 ] ;
60- return directive + sentryImport + code . slice ( directive . length ) ;
61- }
62-
6345/**
6446 * Wraps route middleware arrays in createFileRoute() files.
6547 */
@@ -189,3 +171,21 @@ export function arrayToObjectShorthand(contents: string): string | null {
189171
190172 return `{ ${ uniqueItems . join ( ', ' ) } }` ;
191173}
174+
175+ /**
176+ * Adds the wrapMiddlewaresWithSentry import to the code.
177+ * Handles 'use client' and 'use server' directives by inserting the import after them.
178+ */
179+ export function addSentryImport ( code : string ) : string {
180+ const sentryImport = "import { wrapMiddlewaresWithSentry } from '@sentry/tanstackstart-react';\n" ;
181+
182+ // Check for 'use server' or 'use client' directives, these need to be before any imports
183+ const directiveMatch = code . match ( / ^ ( [ ' " ] ) u s e ( c l i e n t | s e r v e r ) \1; ? \s * \n ? / ) ;
184+
185+ if ( ! directiveMatch ) {
186+ return sentryImport + code ;
187+ }
188+
189+ const directive = directiveMatch [ 0 ] ;
190+ return directive + sentryImport + code . slice ( directive . length ) ;
191+ }
0 commit comments