"use strict";const bundlerPluginCore=require("@codecov/bundler-plugin-core"),c=require("node:path"),m=require("node:fs/promises"),h=require("micromatch");function _interopDefaultCompat(e){return e&&typeof e=="object"&&"default"in e?e.default:e}const c__default=_interopDefaultCompat(c),m__default=_interopDefaultCompat(m),h__default=_interopDefaultCompat(h),PLUGIN_NAME="@codecov/bundle-analyzer",PLUGIN_VERSION="1.4.0",t={beforeReportUpload:async e=>e,ignorePatterns:[],normalizeAssetsPattern:""};function normalizeBundleAnalyzerOptions(e={}){return{...t,...e}}const getAssets=async(e,r=[],a="")=>(await Promise.all(e.map(async n=>{const o=c__default.resolve(n),s=await listChildFilePaths(o),i=r.length?s.filter(l=>!h__default.isMatch(l,r,{dot:!0,matchBase:!0})):s;return await Promise.all(i.map(l=>getAsset(l,o,a)))}))).flat(),getAsset=async(e,r,a)=>{const n=c__default.relative(r,e),o=await m__default.readFile(e),s=o.byteLength,i=await bundlerPluginCore.getCompressedSize({fileName:n,code:o}),l=bundlerPluginCore.normalizePath(n,a);return{name:n,size:s,gzipSize:i,normalized:l}},listChildFilePaths=async e=>{const r=[],a=await m__default.readdir(e,{withFileTypes:!0});for(const n of a){const o=c__default.join(e,n.name);n.isDirectory()?(await listChildFilePaths(o)).forEach(s=>r.push(s)):n.isFile()&&r.push(o)}return r},createAndUploadReport=async(e,r,a)=>{const n=bundlerPluginCore.normalizeOptions(r);if(!n.success)throw new Error("Invalid options: "+n.errors.join(" "));const o=normalizeBundleAnalyzerOptions(a),s=await y(e,n.options,o);let i;try{i=await o.beforeReportUpload(s)}catch(l){throw new Error(`Error in beforeReportUpload: ${l}`)}return r.dryRun||await i.write(!0),i.bundleStatsToJson()},y=async(e,r,a)=>{const n=new bundlerPluginCore.Output(r);return n.start(),n.setPlugin(PLUGIN_NAME,PLUGIN_VERSION),n.assets=await getAssets(e,a.ignorePatterns,a.normalizeAssetsPattern),n.chunks=[],n.modules=[],n.end(),n};exports.createAndUploadReport=createAndUploadReport; //# sourceMappingURL=index.cjs.map