Skip to content

Commit e985b3e

Browse files
committed
yarn fix
1 parent 9a8026b commit e985b3e

File tree

2 files changed

+19
-21
lines changed

2 files changed

+19
-21
lines changed

packages/tanstackstart-react/src/vite/autoInstrumentMiddleware.ts

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -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(/^(['"])use (client|server)\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(/^(['"])use (client|server)\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+
}

packages/tanstackstart-react/test/vite/autoInstrumentMiddleware.test.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -334,9 +334,7 @@ describe('addSentryImport', () => {
334334
const code = 'const foo = 1;';
335335
const result = addSentryImport(code);
336336

337-
expect(result).toBe(
338-
"import { wrapMiddlewaresWithSentry } from '@sentry/tanstackstart-react';\nconst foo = 1;",
339-
);
337+
expect(result).toBe("import { wrapMiddlewaresWithSentry } from '@sentry/tanstackstart-react';\nconst foo = 1;");
340338
});
341339

342340
it('inserts import after use server directive', () => {

0 commit comments

Comments
 (0)