1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162 |
- Object.defineProperty(exports, '__esModule', { value: true });
- const path = require('path');
- const utils = require('@sentry/utils');
- function normalizeWindowsPath(path) {
- return path
- .replace(/^[A-Z]:/, '')
- .replace(/\\/g, '/');
- }
- function createGetModuleFromFilename(
- basePath = process.argv[1] ? utils.dirname(process.argv[1]) : process.cwd(),
- isWindows = path.sep === '\\',
- ) {
- const normalizedBase = isWindows ? normalizeWindowsPath(basePath) : basePath;
- return (filename) => {
- if (!filename) {
- return;
- }
- const normalizedFilename = isWindows ? normalizeWindowsPath(filename) : filename;
-
- let { dir, base: file, ext } = path.posix.parse(normalizedFilename);
- if (ext === '.js' || ext === '.mjs' || ext === '.cjs') {
- file = file.slice(0, ext.length * -1);
- }
- if (!dir) {
-
- dir = '.';
- }
- const n = dir.lastIndexOf('/node_modules');
- if (n > -1) {
- return `${dir.slice(n + 14).replace(/\//g, '.')}:${file}`;
- }
-
-
- if (dir.startsWith(normalizedBase)) {
- let moduleName = dir.slice(normalizedBase.length + 1).replace(/\//g, '.');
- if (moduleName) {
- moduleName += ':';
- }
- moduleName += file;
- return moduleName;
- }
- return file;
- };
- }
- exports.createGetModuleFromFilename = createGetModuleFromFilename;
|