Skip to content

Commit 2952fa2

Browse files
authored
feat(bundler): Add Node bundler plugins (#22125)
This PR adds Node.js specific bundler plugins that can be accessed directly as named exports on the `@sentry/node` package. - `@sentry/node/vite` - `@sentry/node/rollup` - `@sentry/node/webpack` - `@sentry/node/esbuild` These essentially combine the regular Sentry bundler plugins (debug ids + sourcemap upload) with the orchestrion injection plugins including all the default instrumentations. Framework SDKs can use these and optionally pass down additional instrumentations but this option is hidden in the jsdocs.
1 parent 42379bf commit 2952fa2

6 files changed

Lines changed: 206 additions & 1 deletion

File tree

packages/node/package.json

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,64 @@
5252
"require": {
5353
"default": "./build/cjs/preload.js"
5454
}
55+
},
56+
"./vite": {
57+
"import": {
58+
"types": "./build/types/bundler-plugin/vite.d.ts",
59+
"default": "./build/esm/bundler-plugin/vite.js"
60+
},
61+
"require": {
62+
"types": "./build/types/bundler-plugin/vite.d.ts",
63+
"default": "./build/cjs/bundler-plugin/vite.js"
64+
}
65+
},
66+
"./rollup": {
67+
"import": {
68+
"types": "./build/types/bundler-plugin/rollup.d.ts",
69+
"default": "./build/esm/bundler-plugin/rollup.js"
70+
},
71+
"require": {
72+
"types": "./build/types/bundler-plugin/rollup.d.ts",
73+
"default": "./build/cjs/bundler-plugin/rollup.js"
74+
}
75+
},
76+
"./webpack": {
77+
"import": {
78+
"types": "./build/types/bundler-plugin/webpack.d.ts",
79+
"default": "./build/esm/bundler-plugin/webpack.js"
80+
},
81+
"require": {
82+
"types": "./build/types/bundler-plugin/webpack.d.ts",
83+
"default": "./build/cjs/bundler-plugin/webpack.js"
84+
}
85+
},
86+
"./esbuild": {
87+
"import": {
88+
"types": "./build/types/bundler-plugin/esbuild.d.ts",
89+
"default": "./build/esm/bundler-plugin/esbuild.js"
90+
},
91+
"require": {
92+
"types": "./build/types/bundler-plugin/esbuild.d.ts",
93+
"default": "./build/cjs/bundler-plugin/esbuild.js"
94+
}
5595
}
5696
},
5797
"typesVersions": {
5898
"<5.0": {
5999
"build/types/index.d.ts": [
60100
"build/types-ts3.8/index.d.ts"
101+
],
102+
"vite": [
103+
"build/types-ts3.8/bundler-plugin/vite.d.ts"
104+
],
105+
"rollup": [
106+
"build/types-ts3.8/bundler-plugin/rollup.d.ts"
107+
],
108+
"webpack": [
109+
"build/types-ts3.8/bundler-plugin/webpack.d.ts"
110+
],
111+
"esbuild": [
112+
"build/types-ts3.8/bundler-plugin/esbuild.d.ts"
61113
]
62114
}
63115
},
@@ -73,6 +125,7 @@
73125
"@sentry/node-core": "10.67.0",
74126
"@sentry/opentelemetry": "10.67.0",
75127
"@sentry/server-utils": "10.67.0",
128+
"@sentry/bundler-plugins": "10.67.0",
76129
"import-in-the-middle": "^3.0.0"
77130
},
78131
"devDependencies": {

packages/node/rollup.npm.config.mjs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,17 @@ export default [
99
...makeOtelLoaders('./build', 'otel', { injectDiagnosticsChannel: true }),
1010
...makeNPMConfigVariants(
1111
makeBaseNPMConfig({
12-
entrypoints: ['src/index.ts', 'src/init.ts', 'src/preload.ts'],
12+
entrypoints: [
13+
'src/index.ts',
14+
'src/init.ts',
15+
'src/preload.ts',
16+
// Combined Sentry bundler plugins + orchestrion code transform, exposed
17+
// via the `@sentry/node/{vite,rollup,webpack,esbuild}` subpath exports.
18+
'src/bundler-plugin/vite.ts',
19+
'src/bundler-plugin/rollup.ts',
20+
'src/bundler-plugin/webpack.ts',
21+
'src/bundler-plugin/esbuild.ts',
22+
],
1323
packageSpecificConfig: {
1424
external: [/^@sentry\/opentelemetry/],
1525
output: {
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import { sentryEsbuildPlugin as sentryEsbuildBundlerPlugin } from '@sentry/bundler-plugins/esbuild';
2+
import type { SentryEsbuildPluginOptions as SentryEsbuildPluginOptionsBase } from '@sentry/bundler-plugins/esbuild';
3+
import { sentryOrchestrionPlugin } from '@sentry/server-utils/orchestrion/esbuild';
4+
5+
export type SentryEsbuildPluginOptions = SentryEsbuildPluginOptionsBase & {
6+
/**
7+
* @ignore This is for internal use only when this plugin is consumed by a framework SDK
8+
*/
9+
instrumentations?: NonNullable<Parameters<typeof sentryOrchestrionPlugin>[0]>['instrumentations'];
10+
};
11+
12+
type EsbuildPlugin = ReturnType<typeof sentryOrchestrionPlugin>;
13+
14+
/**
15+
* esbuild plugin that bundles the Sentry esbuild bundler plugin (source maps,
16+
* release injection, …) together with the code transformer
17+
* (build-time `diagnostics_channel` instrumentation for Node libraries).
18+
*
19+
* It is a drop-in replacement for `@sentry/bundler-plugins/esbuild` and accepts
20+
* the same options.
21+
* @example
22+
* ```ts
23+
* // build.mjs
24+
* import { sentryEsbuildPlugin } from '@sentry/node/esbuild';
25+
* await esbuild.build({ plugins: [sentryEsbuildPlugin({ org: '…', project: '…' })] });
26+
* ```
27+
*/
28+
export function sentryEsbuildPlugin(options?: SentryEsbuildPluginOptions): EsbuildPlugin {
29+
const bundlerPlugin = sentryEsbuildBundlerPlugin(options) as EsbuildPlugin;
30+
const orchestrionPlugin = sentryOrchestrionPlugin(options);
31+
32+
return {
33+
name: 'sentry-node-esbuild',
34+
async setup(build): Promise<void> {
35+
await bundlerPlugin.setup(build);
36+
await orchestrionPlugin.setup(build);
37+
},
38+
};
39+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import { sentryRollupPlugin as sentryRollupBundlerPlugin } from '@sentry/bundler-plugins/rollup';
2+
import type { SentryRollupPluginOptions as SentryRollupPluginOptionsBase } from '@sentry/bundler-plugins/rollup';
3+
import { sentryOrchestrionPlugin } from '@sentry/server-utils/orchestrion/rollup';
4+
5+
export type SentryRollupPluginOptions = SentryRollupPluginOptionsBase & {
6+
/**
7+
* @ignore This is for internal use only when this plugin is consumed by a framework SDK
8+
*/
9+
instrumentations?: NonNullable<Parameters<typeof sentryOrchestrionPlugin>[0]>['instrumentations'];
10+
};
11+
12+
type RollupPlugin = ReturnType<typeof sentryOrchestrionPlugin>;
13+
14+
/**
15+
* Rollup plugin that bundles the Sentry Rollup bundler plugin (source maps,
16+
* release injection, bundle size optimizations, …) together with the
17+
* code transformer (build-time `diagnostics_channel` instrumentation
18+
* for Node libraries).
19+
*
20+
* It is a drop-in replacement for `@sentry/bundler-plugins/rollup` and accepts
21+
* the same options.
22+
* @example
23+
* ```ts
24+
* // rollup.config.js
25+
* import { sentryRollupPlugin } from '@sentry/node/rollup';
26+
* export default { plugins: [sentryRollupPlugin({ org: '…', project: '…' })] };
27+
* ```
28+
*/
29+
export function sentryRollupPlugin(options?: SentryRollupPluginOptions): RollupPlugin[] {
30+
return [...sentryRollupBundlerPlugin(options), sentryOrchestrionPlugin(options)];
31+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import { sentryVitePlugin as sentryViteBundlerPlugin } from '@sentry/bundler-plugins/vite';
2+
import type { SentryVitePluginOptions as SentryVitePluginOptionsBase } from '@sentry/bundler-plugins/vite';
3+
import { sentryOrchestrionPlugin } from '@sentry/server-utils/orchestrion/vite';
4+
5+
export type SentryVitePluginOptions = SentryVitePluginOptionsBase & {
6+
/**
7+
* @ignore This is for internal use only when this plugin is consumed by a framework SDK
8+
*/
9+
instrumentations?: NonNullable<Parameters<typeof sentryOrchestrionPlugin>[0]>['instrumentations'];
10+
};
11+
12+
type VitePlugin = ReturnType<typeof sentryOrchestrionPlugin>;
13+
14+
/**
15+
* Vite plugin that bundles the Sentry Vite bundler plugin (source maps, release
16+
* injection, bundle size optimizations, …) together with the code
17+
* transformer (build-time `diagnostics_channel` instrumentation for Node
18+
* libraries).
19+
*
20+
* It is a drop-in replacement for `@sentry/bundler-plugins/vite` and accepts the
21+
* same options.
22+
*
23+
* @example
24+
* ```ts
25+
* // vite.config.ts
26+
* import { sentryVitePlugin } from '@sentry/node/vite';
27+
* export default { plugins: [sentryVitePlugin({ org: '…', project: '…' })] };
28+
* ```
29+
*/
30+
export function sentryVitePlugin(options?: SentryVitePluginOptions): VitePlugin[] {
31+
return [...sentryViteBundlerPlugin(options), sentryOrchestrionPlugin(options)];
32+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import { sentryWebpackPlugin as sentryWebpackBundlerPlugin } from '@sentry/bundler-plugins/webpack';
2+
import type { SentryWebpackPluginOptions as SentryWebpackPluginOptionsBase } from '@sentry/bundler-plugins/webpack';
3+
import { sentryOrchestrionWebpackPlugin } from '@sentry/server-utils/orchestrion/webpack';
4+
5+
export type SentryWebpackPluginOptions = SentryWebpackPluginOptionsBase & {
6+
/**
7+
* @ignore This is for internal use only when this plugin is consumed by a framework SDK
8+
*/
9+
instrumentations?: NonNullable<Parameters<typeof sentryOrchestrionWebpackPlugin>[0]>['instrumentations'];
10+
};
11+
12+
type WebpackCompiler = Parameters<ReturnType<typeof sentryWebpackBundlerPlugin>['apply']>[0];
13+
14+
/**
15+
* webpack plugin that bundles the Sentry webpack bundler plugin (source maps,
16+
* release injection, …) together with the code transformer
17+
* (build-time `diagnostics_channel` instrumentation for Node libraries).
18+
*
19+
* It is a drop-in replacement for `@sentry/bundler-plugins/webpack` and accepts
20+
* the same options.
21+
* @example
22+
* ```ts
23+
* // webpack.config.mjs
24+
* import { sentryWebpackPlugin } from '@sentry/node/webpack';
25+
* export default { plugins: [sentryWebpackPlugin({ org: '…', project: '…' })] };
26+
* ```
27+
*/
28+
export function sentryWebpackPlugin(options?: SentryWebpackPluginOptions): {
29+
apply: (compiler: WebpackCompiler) => void;
30+
} {
31+
const bundlerPlugin = sentryWebpackBundlerPlugin(options) as { apply: (compiler: WebpackCompiler) => void };
32+
const orchestrionPlugin = sentryOrchestrionWebpackPlugin(options) as { apply: (compiler: WebpackCompiler) => void };
33+
34+
return {
35+
apply(compiler: WebpackCompiler): void {
36+
bundlerPlugin.apply(compiler);
37+
orchestrionPlugin.apply(compiler);
38+
},
39+
};
40+
}

0 commit comments

Comments
 (0)