Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
57 lines (45 loc) · 1.63 KB

File metadata and controls

57 lines (45 loc) · 1.63 KB
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import { posix, sep } from 'node:path';
import { dirname } from '@sentry/utils';
/** normalizes Windows paths */
function normalizeWindowsPath(path: string): string {
return path
.replace(/^[A-Z]:/, '') // remove Windows-style prefix
.replace(/\\/g, '/'); // replace all `\` instances with `/`
}
/** Creates a function that gets the module name from a filename */
export function createGetModuleFromFilename(
basePath: string = process.argv[1] ? dirname(process.argv[1]) : process.cwd(),
isWindows: boolean = sep === '\\',
): (filename: string | undefined) => string | undefined {
const normalizedBase = isWindows ? normalizeWindowsPath(basePath) : basePath;
return (filename: string | undefined) => {
if (!filename) {
return;
}
const normalizedFilename = isWindows ? normalizeWindowsPath(filename) : filename;
// eslint-disable-next-line prefer-const
let { dir, base: file, ext } = posix.parse(normalizedFilename);
if (ext === '.js' || ext === '.mjs' || ext === '.cjs') {
file = file.slice(0, ext.length * -1);
}
if (!dir) {
// No dirname whatsoever
dir = '.';
}
const n = dir.lastIndexOf('/node_modules');
if (n > -1) {
return `${dir.slice(n + 14).replace(/\//g, '.')}:${file}`;
}
// Let's see if it's a part of the main module
// To be a part of main module, it has to share the same base
if (dir.startsWith(normalizedBase)) {
let moduleName = dir.slice(normalizedBase.length + 1).replace(/\//g, '.');
if (moduleName) {
moduleName += ':';
}
moduleName += file;
return moduleName;
}
return file;
};
}
Morty Proxy This is a proxified and sanitized view of the page, visit original site.