Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions dev-packages/rollup-utils/npmHelpers.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,11 @@ export function makeBaseNPMConfig(options = {}) {
// (We don't need it, so why waste the bytes?)
freeze: false,

// Assume externals are ESM-shaped (`__esModule` + `.default`), which our own `@sentry/*`
// packages satisfy via `esModule: 'if-default-prop'`. This keeps `import * as x` a live
// reference to the real module rather than an `_interopNamespace` copy — instrumentation code
// relies on that to monkey-patch modules like `fs` in place. Packages that pull in bare-CJS
// third-party deps (no `.default`) override this per-module (see server-utils).
interop: 'esModule',
},

Expand Down
2 changes: 1 addition & 1 deletion packages/nextjs/src/config/webpack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,7 @@ export function constructWebpackConfigFunction({

// Orchestrion code-transform loader — Node server runtime only, never the edge compilation
if (runtime === 'server' && userSentryOptions._experimental?.useDiagnosticsChannelInjection) {
newConfig.plugins.push(sentryOrchestrionWebpackPlugin() as WebpackPluginInstance);
newConfig.plugins.push(sentryOrchestrionWebpackPlugin() as unknown as WebpackPluginInstance);
}

return newConfig;
Expand Down
8 changes: 8 additions & 0 deletions packages/server-utils/rollup.npm.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,14 @@ export default [
exports: 'named',
// set preserveModules to true because we don't want to bundle everything into one file.
preserveModules: true,
// `@apm-js-collab/code-transformer-bundler-plugins` ships CJS entries as bare
// `module.exports = fn` with no `__esModule`/`.default`. The repo default
// `interop: 'esModule'` assumes ESM-shaped externals and would dereference a nonexistent
// `.default`, so a default import compiles to `codeTransformer.default(...)` → "not a
// function". Use 'auto' for just these so Rollup emits its interop helper. Scoped here (not
// repo-wide) because 'auto' also turns `import * as x` into a copy, which breaks in-place
// monkey-patching that other packages (e.g. the OTel fs instrumentation) depend on.
interop: id => (id?.startsWith('@apm-js-collab/code-transformer-bundler-plugins') ? 'auto' : 'esModule'),
},
},
}),
Expand Down
9 changes: 3 additions & 6 deletions packages/server-utils/src/orchestrion/bundler/webpack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { createRequire } from 'node:module';
import { dirname } from 'node:path';
import type { InstrumentationConfig } from '@apm-js-collab/code-transformer';
import { SENTRY_INSTRUMENTATIONS } from '../config';
import codeTransformer from '@apm-js-collab/code-transformer-bundler-plugins/webpack';

// Both branches use `createRequire` (never alias the CJS `require`) so bundlers consuming this
// module don't emit a "Critical dependency" warning.
Expand Down Expand Up @@ -46,10 +47,6 @@ export function getSentryInstrumentations(): InstrumentationConfig[] {
* does NOT inject the `__SENTRY_ORCHESTRION__.bundler` marker — that would disable the runtime
* module hook, which externalized packages still need (hybrid setup).
*/
export function sentryOrchestrionWebpackPlugin(): unknown {
const mod = getOrchestrionRequire()('@apm-js-collab/code-transformer-bundler-plugins/webpack') as {
default?: (options: { instrumentations: InstrumentationConfig[] }) => unknown;
};
const codeTransformerWebpack = mod.default ?? (mod as unknown as NonNullable<typeof mod.default>);
return codeTransformerWebpack({ instrumentations: SENTRY_INSTRUMENTATIONS });
export function sentryOrchestrionWebpackPlugin(): ReturnType<typeof codeTransformer> {
return codeTransformer({ instrumentations: SENTRY_INSTRUMENTATIONS });
}
Loading