Skip to content

Commit 8bf8ca6

Browse files
committed
fix: better handling of appPrefix
1 parent efc9b93 commit 8bf8ca6

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

src/backend.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ export interface NativescriptOptions extends BrowserOptions {
3434

3535
/** Should the native nagger alert be shown or not. */
3636
enableNativeNagger?: boolean;
37+
/**
38+
* Optional prefix to add while rewriting frames
39+
*/
40+
appPrefix?: string;
3741
}
3842

3943
/** The Sentry Nativescript SDK Backend. */

src/sdk.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,21 @@ export function init(
3838
new RewriteFrames({
3939
iteratee: (frame: StackFrame) => {
4040
if (frame.filename) {
41-
frame.filename = frame.filename
41+
let filename = (frame.filename = frame.filename
4242
.replace(/^file\:\/\//, '')
4343
.replace(/^address at /, '')
44-
.replace(/^.*\/[^\.]+(\.app|CodePush|.*(?=\/))/, '');
44+
.replace(/^.*\/[^\.]+(\.app|CodePush|.*(?=\/))/, ''));
4545

46-
const appPrefix = 'app://';
47-
console.log('RewriteFrames', frame.filename);
46+
// const appPrefix = 'app://';
47+
const appPrefix = options.appPrefix || '';
48+
if (appPrefix.endsWith('//') && !appPrefix.endsWith('///')) {
49+
filename = frame.filename.indexOf('/') === 0 ? `${appPrefix}${frame.filename}` : `${appPrefix}/${frame.filename}`;
50+
} else {
51+
filename = frame.filename.indexOf('/') === 0 ? `${appPrefix}${frame.filename.slice(1)}` : `${appPrefix}${frame.filename}`;
52+
}
53+
console.log('RewriteFrames', frame.filename, appPrefix, filename);
54+
frame.filename = filename;
4855
// We always want to have a tripple slash
49-
frame.filename = frame.filename.indexOf('/') === 0 ? `${appPrefix}${frame.filename}` : `${appPrefix}/${frame.filename}`;
5056
}
5157
return frame;
5258
}

0 commit comments

Comments
 (0)