Skip to content

Commit

Permalink
ref(js): only shim require
Browse files Browse the repository at this point in the history
  • Loading branch information
JonasBa committed Sep 30, 2024
1 parent 947e70c commit 782fbfc
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 17 deletions.
12 changes: 1 addition & 11 deletions packages/profiling-node/rollup.npm.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,9 @@ import { makeBaseNPMConfig, makeNPMConfigVariants } from '@sentry-internal/rollu

export const ESMShim = `
import cjsUrl from 'node:url';
import cjsPath from 'node:path';
import cjsModule from 'node:module';
if(typeof __filename === 'undefined'){
const __filename = cjsUrl.fileURLToPath(import.meta.url);
}
if(typeof __dirname === 'undefined'){
const __dirname = cjsPath.dirname(__filename);
}
if(typeof require === 'undefined'){
const require = cjsModule.createRequire(import.meta.url);
globalThis.require = cjsModule.createRequire(import.meta.url);
}
`;

Expand Down
12 changes: 6 additions & 6 deletions packages/profiling-node/src/cpu_profiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ import type {
} from './types';
import type { ProfileFormat } from './types';

// #START_SENTRY_ESM_SHIM
// When building for ESM, we shim require to use createRequire and __dirname.
// We need to do this because .node extensions in esm are not supported.
// The comment below this line exists as a placeholder for where to insert the shim.
// #END_SENTRY_ESM_SHIM

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

0 comments on commit 782fbfc

Please sign in to comment.