/**
 * Minified by jsDelivr using Terser v5.39.0.
 * Original file: /npm/nyc@18.0.0/index.js
 *
 * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files
 */
"use strict";const cachingTransform=require("caching-transform"),findCacheDir=require("find-cache-dir"),fs=require("./lib/fs-promises"),os=require("os"),{debuglog:debuglog}=require("util"),{glob:glob}=require("glob"),Hash=require("./lib/hash"),libCoverage=require("istanbul-lib-coverage"),libHook=require("istanbul-lib-hook"),{ProcessInfo:ProcessInfo,ProcessDB:ProcessDB}=require("istanbul-lib-processinfo"),mkdirp=require("make-dir"),Module=require("module"),onExit=require("signal-exit"),path=require("path"),{rimraf:rimraf}=require("rimraf"),SourceMaps=require("./lib/source-maps"),TestExclude=require("test-exclude"),pMap=require("p-map"),getPackageType=require("get-package-type"),debugLog=debuglog("nyc"),nycSelfCoverageHelper=Symbol.for("nyc self-test coverage helper"),selfCoverageHelper=global[nycSelfCoverageHelper]||{onExit(){}};function coverageFinder(){var e=global.__coverage__;return"object"==typeof __coverage__&&(e=__coverage__),e||(e=global.__coverage__={}),e}class NYC{constructor(e){this.config={...e},this.subprocessBin=e.subprocessBin||path.resolve(__dirname,"./bin/nyc.js"),this._tempDirectory=e.tempDirectory||e.tempDir||"./.nyc_output",this._instrumenterLib=require(e.instrumenter||"./lib/instrumenters/istanbul"),this._reportDir=e.reportDir||"coverage",this._sourceMap="boolean"!=typeof e.sourceMap||e.sourceMap,this._showProcessTree=e.showProcessTree||!1,this._eagerInstantiation=e.eager||!1,this.cwd=e.cwd||process.cwd(),this.reporter=[].concat(e.reporter||"text"),this.cacheDirectory=e.cacheDir&&path.resolve(e.cacheDir)||findCacheDir({name:"nyc",cwd:this.cwd}),this.cache=Boolean(this.cacheDirectory&&e.cache),this.extensions=[].concat(e.extension||[]).concat(".js").map((e=>e.toLowerCase())).filter(((e,t,r)=>r.indexOf(e)===t)),this.exclude=new TestExclude({cwd:this.cwd,include:e.include,exclude:e.exclude,excludeNodeModules:!1!==e.excludeNodeModules,extension:this.extensions}),this.sourceMaps=new SourceMaps({cache:this.cache,cacheDirectory:this.cacheDirectory}),this.require=[].concat(e.require||[]),this.transforms=this.extensions.reduce(((e,t)=>(e[t]=this._createTransform(t),e)),{}),this.hookRequire=e.hookRequire,this.hookRunInContext=e.hookRunInContext,this.hookRunInThisContext=e.hookRunInThisContext,this.fakeRequire=null,this.processInfo=new ProcessInfo(Object.assign({},e._processInfo,{directory:path.resolve(this.tempDirectory(),"processinfo")})),this.hashCache={}}_createTransform(e){const t={salt:Hash.salt(this.config),hashData:(e,t)=>[t.filename],filenamePrefix:e=>path.parse(e.filename).name+"-",onHash:(e,t,r)=>{this.hashCache[t.filename]=r},cacheDir:this.cacheDirectory,disableCache:this._disableCachingTransform(),ext:e};return this._eagerInstantiation?t.transform=this._transformFactory(this.cacheDirectory):t.factory=this._transformFactory.bind(this),cachingTransform(t)}_disableCachingTransform(){return!(this.cache&&this.config.isChildProcess)}_loadAdditionalModules(){if(!this.config.useSpawnWrap||0===this.require.length)return;const e=require("resolve-from");this.require.forEach((t=>{require(e.silent(this.cwd,t)||t)}))}instrumenter(){return this._instrumenter||(this._instrumenter=this._createInstrumenter())}_createInstrumenter(){return this._instrumenterLib({ignoreClassMethods:[].concat(this.config.ignoreClassMethod).filter((e=>e)),produceSourceMap:this.config.produceSourceMap,compact:this.config.compact,preserveComments:this.config.preserveComments,esModules:this.config.esModules,parserPlugins:this.config.parserPlugins})}addFile(e){const t=this._readTranspiledSource(e);this._maybeInstrumentSource(t,e)}_readTranspiledSource(e){var t=null,r=path.extname(e);return void 0===Module._extensions[r]&&(r=".js"),Module._extensions[r]({_compile:function(e,r){t=e}},e),t}_getSourceMap(e,t,r){const s={};return this._sourceMap?(s.sourceMap=this.sourceMaps.extract(e,t),s.registerMap=()=>this.sourceMaps.registerMap(t,r,s.sourceMap)):s.registerMap=()=>{},s}async addAllFiles(){this._loadAdditionalModules(),this.fakeRequire=!0;const e=await this.exclude.glob(this.cwd);for(const t of e){const e=path.resolve(this.cwd,t),r=path.extname(e);if(".mjs"===r||".js"===r&&"module"===await getPackageType(e)){const t=await fs.readFile(e,"utf8");this.instrumenter().instrumentSync(t,e,this._getSourceMap(t,e))}else this.addFile(e);const s=coverageFinder(),i=this.instrumenter().lastFileCoverage();i&&(s[i.path]={...i,all:!0})}this.fakeRequire=!1,this.writeCoverageFile()}async instrumentAllFiles(e,t){let r="."+path.sep;const s=async e=>{const s=path.resolve(r,e),i=await fs.readFile(s,"utf-8"),o=this._transform(i,s)||i;if(t){const{mode:r}=await fs.stat(s),i=path.resolve(t,e);await mkdirp(path.dirname(i)),await fs.writeFile(i,o),await fs.chmod(i,r)}else console.log(o)};this._loadAdditionalModules();if((await fs.lstat(e)).isDirectory()){r=e;const i=await this.exclude.glob(e),o=t?os.cpus().length:1;if(this.config.completeCopy&&t){const r=await glob(path.resolve(e,"**").split(path.sep).join("/"),{dot:!0,nodir:!0,ignore:["**/.git","**/.git/**",path.join(t,"**").split(path.sep).join("/")]}),s=new Set(r.map((r=>path.dirname(path.join(t,path.relative(e,r))))));await pMap(s,(e=>mkdirp(e)),{concurrency:o}),await pMap(r,(r=>fs.copyFile(r,path.join(t,path.relative(e,r)))),{concurrency:o})}await pMap(i,s,{concurrency:o})}else await s(e)}_transform(e,t){const r=path.extname(t).toLowerCase();return(this.transforms[r]||(()=>null))(e,{filename:t})}_maybeInstrumentSource(e,t){return this.exclude.shouldInstrument(t)?this._transform(e,t):null}maybePurgeSourceMapCache(){this.cache||this.sourceMaps.purgeCache()}_transformFactory(e){const t=this.instrumenter();let r;return(e,s,i)=>{const o=s.filename,a=this._getSourceMap(e,o,i);try{r=t.instrumentSync(e,o,a)}catch(t){debugLog("failed to instrument "+o+" with error: "+t.stack),this.config.exitOnError?(console.error("Failed to instrument "+o),process.exit(1)):r=e}return this.fakeRequire?"function x () {}":r}}_handleJs(e,t){const r=path.resolve(this.cwd,t.filename);return this._maybeInstrumentSource(e,r)||e}_addHook(e){const t=this._handleJs.bind(this);libHook["hook"+e]((()=>!0),t,{extensions:this.extensions})}_addRequireHooks(){this.hookRequire&&this._addHook("Require"),this.hookRunInContext&&this._addHook("RunInContext"),this.hookRunInThisContext&&this._addHook("RunInThisContext")}async createTempDirectory(){await mkdirp(this.tempDirectory()),this.cache&&await mkdirp(this.cacheDirectory),await mkdirp(this.processInfo.directory)}async reset(){process.env.NYC_CWD||await rimraf(this.tempDirectory()),await this.createTempDirectory()}_wrapExit(){selfCoverageHelper.registered=!0,onExit((()=>{this.writeCoverageFile(),selfCoverageHelper.onExit()}),{alwaysLast:!0})}wrap(e){if(process.env.NYC_PROCESS_ID=this.processInfo.uuid,!this.config.useSpawnWrap){require("./lib/register-env.js")("NYC_PROCESS_ID")}return this._addRequireHooks(),this._wrapExit(),this._loadAdditionalModules(),this}writeCoverageFile(){var e=coverageFinder();Object.keys(e).forEach((function(t){this.exclude.shouldInstrument(t)||delete e[t]}),this),this.cache&&Object.keys(e).forEach((function(t){this.hashCache[t]&&e[t]&&(e[t].contentHash=this.hashCache[t])}),this);var t=this.processInfo.uuid,r=path.resolve(this.tempDirectory(),t+".json");fs.writeFileSync(r,JSON.stringify(e),"utf-8"),this.processInfo.coverageFilename=r,this.processInfo.files=Object.keys(e),this.processInfo.saveSync()}async getCoverageMapFromAllCoverageFiles(e){const t=libCoverage.createCoverageMap({}),r=await this.coverageFiles(e);return await pMap(r,(async r=>{const s=await this.coverageFileLoad(r,e);t.merge(s)}),{concurrency:os.cpus().length}),t.data=await this.sourceMaps.remapCoverage(t.data),this.config.excludeAfterRemap&&t.filter((e=>this.exclude.shouldInstrument(e))),t}async report(){const e=require("istanbul-lib-report"),t=require("istanbul-reports"),r=e.createContext({dir:this.reportDirectory(),watermarks:this.config.watermarks,coverageMap:await this.getCoverageMapFromAllCoverageFiles()});this.reporter.forEach((e=>{t.create(e,{skipEmpty:this.config.skipEmpty,skipFull:this.config.skipFull,projectRoot:this.cwd,maxCols:process.stdout.columns||100}).execute(r)})),this._showProcessTree&&await this.showProcessTree()}async writeProcessIndex(){const e=new ProcessDB(this.processInfo.directory);await e.writeIndex()}async showProcessTree(){const e=new ProcessDB(this.processInfo.directory);console.log(await e.renderTree(this))}async checkCoverage(e,t){const r=await this.getCoverageMapFromAllCoverageFiles();t?r.files().forEach((t=>{this._checkCoverage(r.fileCoverageFor(t).toSummary(),e,t)})):this._checkCoverage(r.getCoverageSummary(),e)}_checkCoverage(e,t,r){Object.keys(t).forEach((function(s){var i=e[s].pct;i<t[s]&&(process.exitCode=1,r?console.error("ERROR: Coverage for "+s+" ("+i+"%) does not meet threshold ("+t[s]+"%) for "+r):console.error("ERROR: Coverage for "+s+" ("+i+"%) does not meet global threshold ("+t[s]+"%)"))}))}coverageFiles(e=this.tempDirectory()){return fs.readdir(e)}async coverageFileLoad(e,t=this.tempDirectory()){try{const r=JSON.parse(await fs.readFile(path.resolve(t,e)),"utf8");return await this.sourceMaps.reloadCachedSourceMaps(r),r}catch(e){return{}}}async coverageData(e){const t=await this.coverageFiles(e);return pMap(t,(t=>this.coverageFileLoad(t,e)),{concurrency:os.cpus().length})}tempDirectory(){return path.resolve(this.cwd,this._tempDirectory)}reportDirectory(){return path.resolve(this.cwd,this._reportDir)}}module.exports=NYC;
//# sourceMappingURL=/sm/b9490e8b21830f7fad94baaed26c3da8c36770c2a678b7d8d5a6223e5a30d908.map