Skip to content

Commit 0b7a4f3

Browse files
committed
fix(nuxt): Inline nitro-utils function
1 parent 938fe65 commit 0b7a4f3

File tree

4 files changed

+43
-11
lines changed

4 files changed

+43
-11
lines changed

packages/nitro-utils/package.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"homepage": "https://github.com/getsentry/sentry-javascript/tree/master/packages/nitro-utils",
77
"author": "Sentry",
88
"license": "MIT",
9+
"private": true,
910
"engines": {
1011
"node": ">=16.20"
1112
},
@@ -35,9 +36,6 @@
3536
]
3637
}
3738
},
38-
"publishConfig": {
39-
"access": "public"
40-
},
4139
"dependencies": {
4240
"@sentry/core": "8.44.0"
4341
},

packages/nuxt/build.config.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,5 @@ import { defineBuildConfig } from 'unbuild';
22

33
// Build Config for the Nuxt Module Builder: https://github.com/nuxt/module-builder
44
export default defineBuildConfig({
5-
// The devDependency "@sentry-internal/nitro-utils" triggers "Inlined implicit external", but it's not external
6-
failOnWarn: false,
5+
failOnWarn: false
76
});

packages/nuxt/rollup.npm.config.mjs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,11 @@ export default [
1515
},
1616
}),
1717
),
18-
/* The Nuxt module plugins are also built with the @nuxt/module-builder.
19-
This rollup setup is still left here for an easier switch between the setups while
20-
manually testing different built outputs (module-builder vs. rollup only) */
18+
19+
// The Nuxt module plugins are also built with the @nuxt/module-builder.
20+
// This rollup setup is still left here for an easier switch between the setups while
21+
// manually testing different built outputs (module-builder vs. rollup only)
22+
/*
2123
...makeNPMConfigVariants(
2224
makeBaseNPMConfig({
2325
entrypoints: ['src/runtime/plugins/sentry.client.ts', 'src/runtime/plugins/sentry.server.ts'],
@@ -31,4 +33,5 @@ export default [
3133
},
3234
}),
3335
),
36+
*/
3437
];

packages/nuxt/src/runtime/plugins/sentry.server.ts

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,15 @@
1-
import { patchEventHandler } from '@sentry-internal/nitro-utils';
2-
import { GLOBAL_OBJ, flush, getClient, logger, vercelWaitUntil } from '@sentry/core';
1+
import {
2+
GLOBAL_OBJ,
3+
flush,
4+
getClient,
5+
getDefaultIsolationScope,
6+
getIsolationScope,
7+
logger,
8+
vercelWaitUntil,
9+
withIsolationScope,
10+
} from '@sentry/core';
311
import * as Sentry from '@sentry/node';
4-
import { H3Error } from 'h3';
12+
import { type EventHandler, H3Error } from 'h3';
513
import { defineNitroPlugin } from 'nitropack/runtime';
614
import type { NuxtRenderHTMLContext } from 'nuxt/app';
715
import { addSentryTracingMetaTags, extractErrorContext } from '../utils';
@@ -66,3 +74,27 @@ async function flushWithTimeout(): Promise<void> {
6674
isDebug && logger.log('Error while flushing events:\n', e);
6775
}
6876
}
77+
78+
// copied from '@sentry-internal/nitro-utils' - the nuxt-module-builder does not inline devDependencies
79+
function patchEventHandler(handler: EventHandler): EventHandler {
80+
return new Proxy(handler, {
81+
async apply(handlerTarget, handlerThisArg, handlerArgs: Parameters<EventHandler>) {
82+
const isolationScope = getIsolationScope();
83+
const newIsolationScope = isolationScope === getDefaultIsolationScope() ? isolationScope.clone() : isolationScope;
84+
85+
logger.log(
86+
`Patched h3 event handler. ${
87+
isolationScope === newIsolationScope ? 'Using existing' : 'Created new'
88+
} isolation scope.`,
89+
);
90+
91+
return withIsolationScope(newIsolationScope, async () => {
92+
try {
93+
return await handlerTarget.apply(handlerThisArg, handlerArgs);
94+
} finally {
95+
await flushIfServerless();
96+
}
97+
});
98+
},
99+
});
100+
}

0 commit comments

Comments
 (0)