Skip to content

Commit e210cf4

Browse files
committed
review suggestions
1 parent dfff967 commit e210cf4

File tree

10 files changed

+189
-21
lines changed

10 files changed

+189
-21
lines changed

dev-packages/rollup-utils/npmHelpers.mjs

+8-2
Original file line numberDiff line numberDiff line change
@@ -132,9 +132,15 @@ export function makeBaseNPMConfig(options = {}) {
132132
}
133133

134134
export function makeNPMConfigVariants(baseConfig, options = {}) {
135-
const { emitEsm = true } = options;
135+
const { emitEsm = true, emitCjs = true } = options;
136136

137-
const variantSpecificConfigs = [{ output: { format: 'cjs', dir: path.join(baseConfig.output.dir, 'cjs') } }];
137+
const variantSpecificConfigs = [];
138+
139+
if (emitCjs) {
140+
variantSpecificConfigs.push({
141+
output: { format: 'cjs', dir: path.join(baseConfig.output.dir, 'cjs') },
142+
});
143+
}
138144

139145
if (emitEsm) {
140146
variantSpecificConfigs.push({

packages/nitro-utils/package.json

+5-7
Original file line numberDiff line numberDiff line change
@@ -7,25 +7,21 @@
77
"author": "Sentry",
88
"license": "MIT",
99
"private": true,
10+
"type": "module",
1011
"engines": {
1112
"node": ">=14.18"
1213
},
1314
"files": [
1415
"/build"
1516
],
16-
"main": "build/cjs/index.js",
17-
"module": "build/esm/index.js",
17+
"main": "build/esm/index.js",
1818
"types": "build/types/index.d.ts",
1919
"exports": {
2020
"./package.json": "./package.json",
2121
".": {
2222
"import": {
2323
"types": "./build/types/index.d.ts",
2424
"default": "./build/esm/index.js"
25-
},
26-
"require": {
27-
"types": "./build/types/index.d.ts",
28-
"default": "./build/cjs/index.js"
2925
}
3026
}
3127
},
@@ -40,10 +36,12 @@
4036
"access": "public"
4137
},
4238
"dependencies": {
43-
"@sentry/core": "8.36.0",
4439
"@sentry/types": "8.36.0",
4540
"@sentry/utils": "8.36.0"
4641
},
42+
"devDependencies": {
43+
"rollup": "^4.24.4"
44+
},
4745
"scripts": {
4846
"build": "run-p build:transpile build:types",
4947
"build:dev": "yarn build",

packages/nitro-utils/rollup.npm.config.mjs

+1
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,5 @@ export default makeNPMConfigVariants(
1414
},
1515
},
1616
}),
17+
{ emitCjs: false },
1718
);

packages/nitro-utils/src/index.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,4 @@
1-
export { wrapServerEntryWithDynamicImport } from './rollupPlugins/wrapServerEntryWithDynamicImport';
1+
export {
2+
wrapServerEntryWithDynamicImport,
3+
type WrapServerEntryPluginOptions,
4+
} from './rollupPlugins/wrapServerEntryWithDynamicImport';

packages/nitro-utils/src/rollupPlugins/wrapServerEntryWithDynamicImport.ts

+24-10
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,15 @@ export const SENTRY_WRAPPED_FUNCTIONS = '?sentry-query-wrapped-functions=';
66
export const SENTRY_REEXPORTED_FUNCTIONS = '?sentry-query-reexported-functions=';
77
export const QUERY_END_INDICATOR = 'SENTRY-QUERY-END';
88

9+
export type WrapServerEntryPluginOptions = {
10+
serverEntrypointFileName: string;
11+
serverConfigFileName: string;
12+
resolvedServerConfigPath: string;
13+
entrypointWrappedFunctions: string[];
14+
additionalImports?: string[];
15+
debug?: boolean;
16+
};
17+
918
/**
1019
* A Rollup plugin which wraps the server entry with a dynamic `import()`. This makes it possible to initialize Sentry first
1120
* by using a regular `import` and load the server after that.
@@ -18,15 +27,15 @@ export const QUERY_END_INDICATOR = 'SENTRY-QUERY-END';
1827
* @param config.additionalImports Adds additional imports to the entry file. Can be e.g. 'import-in-the-middle/hook.mjs'
1928
* @param config.debug Whether debug logs are enabled in the build time environment
2029
*/
21-
export function wrapServerEntryWithDynamicImport(config: {
22-
serverConfigFileName: string;
23-
resolvedServerConfigPath: string;
24-
entrypointWrappedFunctions: string[];
25-
additionalImports?: string[];
26-
debug?: boolean;
27-
}): InputPluginOption {
28-
const { serverConfigFileName, resolvedServerConfigPath, entrypointWrappedFunctions, additionalImports, debug } =
29-
config;
30+
export function wrapServerEntryWithDynamicImport(config: WrapServerEntryPluginOptions): InputPluginOption {
31+
const {
32+
serverEntrypointFileName,
33+
serverConfigFileName,
34+
resolvedServerConfigPath,
35+
entrypointWrappedFunctions,
36+
additionalImports,
37+
debug,
38+
} = config;
3039

3140
return {
3241
name: 'sentry-wrap-server-entry-with-dynamic-import',
@@ -43,7 +52,12 @@ export function wrapServerEntryWithDynamicImport(config: {
4352
return { id: source, moduleSideEffects: true, external: true };
4453
}
4554

46-
if (options.isEntry && source.includes('.mjs') && !source.includes(`.mjs${SENTRY_WRAPPED_ENTRY}`)) {
55+
if (
56+
options.isEntry &&
57+
source.includes(serverEntrypointFileName) &&
58+
source.includes('.mjs') &&
59+
!source.includes(`.mjs${SENTRY_WRAPPED_ENTRY}`)
60+
) {
4761
const resolution = await this.resolve(source, importer, options);
4862

4963
// If it cannot be resolved or is external, just return it so that Rollup can display an error

packages/nuxt/build.config.ts

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { defineBuildConfig } from 'unbuild';
2+
3+
// Build Config for the Nuxt Module Builder: https://github.com/nuxt/module-builder
4+
export default defineBuildConfig({
5+
// The devDependency "@sentry-internal/nitro-utils" triggers "Inlined implicit external", but it's not external
6+
failOnWarn: false,
7+
});

packages/nuxt/src/common/types.ts

+9
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,15 @@ export type SentryNuxtModuleOptions = {
130130
*/
131131
entrypointWrappedFunctions?: string[];
132132

133+
/**
134+
* By default—unless you configure `dynamicImportForServerEntry: false`—the SDK will try to wrap your Nitro server entrypoint
135+
* with a dynamic `import()` to ensure all dependencies can be properly instrumented.
136+
*
137+
* The server entrypoint filename is automatically set by the Sentry SDK depending on the Nitro present.
138+
* In case the server entrypoint has a different filename, you can overwrite it here.
139+
*/
140+
serverEntrypointFileName?: string;
141+
133142
/**
134143
* Options to be passed directly to the Sentry Rollup Plugin (`@sentry/rollup-plugin`) and Sentry Vite Plugin (`@sentry/vite-plugin`) that ship with the Sentry Nuxt SDK.
135144
* You can use this option to override any options the SDK passes to the Vite (for Nuxt) and Rollup (for Nitro) plugin.

packages/nuxt/src/vite/addServerConfig.ts

+1
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ export function addDynamicImportEntryFileWrapper(
9393

9494
nitro.options.rollupConfig.plugins.push(
9595
wrapServerEntryWithDynamicImport({
96+
serverEntrypointFileName: moduleOptions.serverEntrypointFileName || nitro.options.preset,
9697
serverConfigFileName: SERVER_CONFIG_FILENAME,
9798
resolvedServerConfigPath: createResolver(nitro.options.srcDir).resolve(`/${serverConfigFile}`),
9899
entrypointWrappedFunctions: moduleOptions.entrypointWrappedFunctions,

packages/nuxt/tsconfig.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"extends": "../../tsconfig.json",
33

4-
"include": ["src/**/*"],
4+
"include": ["src/**/*", "build.config.ts"],
55

66
"compilerOptions": {
77
// package-specific options

0 commit comments

Comments
 (0)