Skip to content

Commit 4d781bc

Browse files
authored
feat(node): Export getModule for Electron SDK (#8488)
I'm looking to fix [this Electron issue](getsentry/sentry-electron#686) and need access to the `getModule` function but it's not currently exported. Since we're now exporting this, I've renamed it to `getModuleFromFilename` since that better describes what it does.
1 parent 704b846 commit 4d781bc

File tree

4 files changed

+8
-7
lines changed

4 files changed

+8
-7
lines changed

packages/node/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ export { makeNodeTransport } from './transports';
6060
export { defaultIntegrations, init, defaultStackParser, lastEventId, flush, close, getSentryRelease } from './sdk';
6161
export { addRequestDataToEvent, DEFAULT_USER_INCLUDES, extractRequestData } from './requestdata';
6262
export { deepReadDirSync } from './utils';
63+
export { getModuleFromFilename } from './module';
6364

6465
import { Integrations as CoreIntegrations } from '@sentry/core';
6566

packages/node/src/module.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ function normalizeWindowsPath(path: string): string {
1010
}
1111

1212
/** Gets the module from a filename */
13-
export function getModule(
13+
export function getModuleFromFilename(
1414
filename: string | undefined,
1515
normalizeWindowsPathSeparator: boolean = isWindowsPlatform,
1616
): string | undefined {

packages/node/src/sdk.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ import {
3131
RequestData,
3232
Undici,
3333
} from './integrations';
34-
import { getModule } from './module';
34+
import { getModuleFromFilename } from './module';
3535
import { makeNodeTransport } from './transports';
3636
import type { NodeClientOptions, NodeOptions } from './types';
3737

@@ -267,7 +267,7 @@ export function getSentryRelease(fallback?: string): string | undefined {
267267
}
268268

269269
/** Node.js stack parser */
270-
export const defaultStackParser: StackParser = createStackParser(nodeStackLineParser(getModule));
270+
export const defaultStackParser: StackParser = createStackParser(nodeStackLineParser(getModuleFromFilename));
271271

272272
/**
273273
* Enable automatic Session Tracking for the node process.

packages/node/test/module.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { getModule } from '../src/module';
1+
import { getModuleFromFilename } from '../src/module';
22

33
function withFilename(fn: () => void, filename: string) {
44
const prevFilename = require.main?.filename;
@@ -15,16 +15,16 @@ function withFilename(fn: () => void, filename: string) {
1515
}
1616
}
1717

18-
describe('getModule', () => {
18+
describe('getModuleFromFilename', () => {
1919
test('Windows', () => {
2020
withFilename(() => {
21-
expect(getModule('C:\\Users\\users\\Tim\\Desktop\\node_modules\\module.js', true)).toEqual('module');
21+
expect(getModuleFromFilename('C:\\Users\\users\\Tim\\Desktop\\node_modules\\module.js', true)).toEqual('module');
2222
}, 'C:\\Users\\Tim\\app.js');
2323
});
2424

2525
test('POSIX', () => {
2626
withFilename(() => {
27-
expect(getModule('/Users/users/Tim/Desktop/node_modules/module.js')).toEqual('module');
27+
expect(getModuleFromFilename('/Users/users/Tim/Desktop/node_modules/module.js')).toEqual('module');
2828
}, '/Users/Tim/app.js');
2929
});
3030
});

0 commit comments

Comments
 (0)