| Server IP : 82.148.16.210 / Your IP : 216.73.216.19 Web Server : nginx/1.29.5 System : Linux mail.sarafai.ru 6.1.0-43-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.1.162-1 (2026-02-08) x86_64 User : root ( 0) PHP Version : 7.4.33 Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare, MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : OFF Directory : /usr/share/nodejs/nyc/lib/ |
Upload File : |
'use strict'
const convertSourceMap = require('convert-source-map')
const libCoverage = require('istanbul-lib-coverage')
const libSourceMaps = require('istanbul-lib-source-maps')
const fs = require('./fs-promises')
const os = require('os')
const path = require('path')
const pMap = require('p-map')
class SourceMaps {
constructor (opts) {
this.cache = opts.cache
this.cacheDirectory = opts.cacheDirectory
this.loadedMaps = {}
this._sourceMapCache = libSourceMaps.createSourceMapStore()
}
cachedPath (source, hash) {
return path.join(
this.cacheDirectory,
`${path.parse(source).name}-${hash}.map`
)
}
purgeCache () {
this._sourceMapCache = libSourceMaps.createSourceMapStore()
this.loadedMaps = {}
}
extract (code, filename) {
const sourceMap = convertSourceMap.fromSource(code) || convertSourceMap.fromMapFileSource(code, path.dirname(filename))
return sourceMap ? sourceMap.toObject() : undefined
}
registerMap (filename, hash, sourceMap) {
if (!sourceMap) {
return
}
if (this.cache && hash) {
const mapPath = this.cachedPath(filename, hash)
fs.writeFileSync(mapPath, JSON.stringify(sourceMap))
} else {
this._sourceMapCache.registerMap(filename, sourceMap)
}
}
async remapCoverage (obj) {
const transformed = await this._sourceMapCache.transformCoverage(
libCoverage.createCoverageMap(obj)
)
return transformed.data
}
async reloadCachedSourceMaps (report) {
await pMap(
Object.entries(report),
async ([absFile, fileReport]) => {
if (!fileReport || !fileReport.contentHash) {
return
}
const hash = fileReport.contentHash
if (!(hash in this.loadedMaps)) {
try {
const mapPath = this.cachedPath(absFile, hash)
this.loadedMaps[hash] = JSON.parse(await fs.readFile(mapPath, 'utf8'))
} catch (e) {
// set to false to avoid repeatedly trying to load the map
this.loadedMaps[hash] = false
}
}
if (this.loadedMaps[hash]) {
this._sourceMapCache.registerMap(absFile, this.loadedMaps[hash])
}
},
{ concurrency: os.cpus().length }
)
}
}
module.exports = SourceMaps