Skip to content

Commit 782fbfc

Browse files
committed
ref(js): only shim require
1 parent 947e70c commit 782fbfc

2 files changed

Lines changed: 7 additions & 17 deletions

File tree

packages/profiling-node/rollup.npm.config.mjs

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,9 @@ import { makeBaseNPMConfig, makeNPMConfigVariants } from '@sentry-internal/rollu
33

44
export const ESMShim = `
55
import cjsUrl from 'node:url';
6-
import cjsPath from 'node:path';
7-
import cjsModule from 'node:module';
8-
9-
if(typeof __filename === 'undefined'){
10-
const __filename = cjsUrl.fileURLToPath(import.meta.url);
11-
}
12-
13-
if(typeof __dirname === 'undefined'){
14-
const __dirname = cjsPath.dirname(__filename);
15-
}
166
177
if(typeof require === 'undefined'){
18-
const require = cjsModule.createRequire(import.meta.url);
8+
globalThis.require = cjsModule.createRequire(import.meta.url);
199
}
2010
`;
2111

packages/profiling-node/src/cpu_profiler.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@ import type {
1515
} from './types';
1616
import type { ProfileFormat } from './types';
1717

18+
// #START_SENTRY_ESM_SHIM
19+
// When building for ESM, we shim require to use createRequire and __dirname.
20+
// We need to do this because .node extensions in esm are not supported.
21+
// The comment below this line exists as a placeholder for where to insert the shim.
22+
// #END_SENTRY_ESM_SHIM
23+
1824
const stdlib = familySync();
1925
const platform = process.env['BUILD_PLATFORM'] || _platform();
2026
const arch = process.env['BUILD_ARCH'] || _arch();
@@ -28,12 +34,6 @@ const built_from_source_path = resolve(__dirname, '..', `./sentry_cpu_profiler-$
2834
*/
2935
// eslint-disable-next-line complexity
3036
export function importCppBindingsModule(): PrivateV8CpuProfilerBindings {
31-
// #START_SENTRY_ESM_SHIM
32-
// When building for ESM, we shim require to use createRequire and __dirname.
33-
// We need to do this because .node extensions in esm are not supported.
34-
// The comment below this line exists as a placeholder for where to insert the shim.
35-
// #END_SENTRY_ESM_SHIM
36-
//
3737
// If a binary path is specified, use that.
3838
if (env['SENTRY_PROFILER_BINARY_PATH']) {
3939
const envPath = env['SENTRY_PROFILER_BINARY_PATH'];

0 commit comments

Comments
 (0)