Skip to content

Commit

Permalink
feat(node): Export getModule for Electron SDK (#8488)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
timfish committed Jul 11, 2023
1 parent 704b846 commit 4d781bc
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 7 deletions.
1 change: 1 addition & 0 deletions packages/node/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ export { makeNodeTransport } from './transports';
export { defaultIntegrations, init, defaultStackParser, lastEventId, flush, close, getSentryRelease } from './sdk';
export { addRequestDataToEvent, DEFAULT_USER_INCLUDES, extractRequestData } from './requestdata';
export { deepReadDirSync } from './utils';
export { getModuleFromFilename } from './module';

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

Expand Down
2 changes: 1 addition & 1 deletion packages/node/src/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ function normalizeWindowsPath(path: string): string {
}

/** Gets the module from a filename */
export function getModule(
export function getModuleFromFilename(
filename: string | undefined,
normalizeWindowsPathSeparator: boolean = isWindowsPlatform,
): string | undefined {
Expand Down
4 changes: 2 additions & 2 deletions packages/node/src/sdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import {
RequestData,
Undici,
} from './integrations';
import { getModule } from './module';
import { getModuleFromFilename } from './module';
import { makeNodeTransport } from './transports';
import type { NodeClientOptions, NodeOptions } from './types';

Expand Down Expand Up @@ -267,7 +267,7 @@ export function getSentryRelease(fallback?: string): string | undefined {
}

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

/**
* Enable automatic Session Tracking for the node process.
Expand Down
8 changes: 4 additions & 4 deletions packages/node/test/module.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { getModule } from '../src/module';
import { getModuleFromFilename } from '../src/module';

function withFilename(fn: () => void, filename: string) {
const prevFilename = require.main?.filename;
Expand All @@ -15,16 +15,16 @@ function withFilename(fn: () => void, filename: string) {
}
}

describe('getModule', () => {
describe('getModuleFromFilename', () => {
test('Windows', () => {
withFilename(() => {
expect(getModule('C:\\Users\\users\\Tim\\Desktop\\node_modules\\module.js', true)).toEqual('module');
expect(getModuleFromFilename('C:\\Users\\users\\Tim\\Desktop\\node_modules\\module.js', true)).toEqual('module');
}, 'C:\\Users\\Tim\\app.js');
});

test('POSIX', () => {
withFilename(() => {
expect(getModule('/Users/users/Tim/Desktop/node_modules/module.js')).toEqual('module');
expect(getModuleFromFilename('/Users/users/Tim/Desktop/node_modules/module.js')).toEqual('module');
}, '/Users/Tim/app.js');
});
});

0 comments on commit 4d781bc

Please sign in to comment.