File tree Expand file tree Collapse file tree 1 file changed +14
-5
lines changed Expand file tree Collapse file tree 1 file changed +14
-5
lines changed Original file line number Diff line number Diff line change 1
1
import { basename , dirname } from '@sentry/utils' ;
2
2
3
+ /** normalizes Windows paths */
4
+ function normalisePath ( path : string ) : string {
5
+ return path
6
+ . replace ( / ^ [ A - Z ] : / , '' ) // remove Windows-style prefix
7
+ . replace ( / \\ / g, '/' ) ; // replace all `\` instances with `/`
8
+ }
9
+
3
10
/** Gets the module from a filename */
4
11
export function getModule ( filename : string | undefined ) : string | undefined {
5
12
if ( ! filename ) {
6
13
return ;
7
14
}
8
15
16
+ const normalizedFilename = normalisePath ( filename ) ;
17
+
9
18
// We could use optional chaining here but webpack does like that mixed with require
10
- const base = ` ${
11
- ( require && require . main && require . main . filename && dirname ( require . main . filename ) ) || global . process . cwd ( )
12
- } /` ;
19
+ const base = normalisePath (
20
+ ` ${ ( require && require . main && require . main . filename && dirname ( require . main . filename ) ) || global . process . cwd ( ) } /` ,
21
+ ) ;
13
22
14
23
// It's specifically a module
15
- const file = basename ( filename , '.js' ) ;
24
+ const file = basename ( normalizedFilename , '.js' ) ;
16
25
17
- const path = dirname ( filename ) ;
26
+ const path = dirname ( normalizedFilename ) ;
18
27
let n = path . lastIndexOf ( '/node_modules/' ) ;
19
28
if ( n > - 1 ) {
20
29
// /node_modules/ is 14 chars
You can’t perform that action at this time.
0 commit comments