"use strict";const unplugin=require("unplugin"),bundlerPluginCore=require("@codecov/bundler-plugin-core"),node_module=require("node:module"),f=require("node:path");var _documentCurrentScript=typeof document<"u"?document.currentScript:null;function _interopDefaultCompat(e){return e&&typeof e=="object"&&"default"in e?e.default:e}const f__default=_interopDefaultCompat(f),r=/(\w|\[|]|\/)/g,findFilenameFormat=({assetName:e,filename:o,assetModuleFilename:n,chunkFilename:s,cssFilename:t,cssChunkFilename:i})=>{const u=e.replaceAll(r,"");return o!==""&&u.includes(o.replaceAll(r,""))?o:s!==""&&u.includes(s.replaceAll(r,""))?s:t!==""&&u.includes(t.replaceAll(r,""))?t:i!==""&&u.includes(i.replaceAll(r,""))?i:n!==""&&u.includes(n.replaceAll(r,""))?n:""},processAssets=async({assets:e,compilation:o})=>{const n=o.outputOptions,s=[],t=typeof n.filename=="string"?n.filename:"",i=typeof n.assetModuleFilename=="string"?n.assetModuleFilename:"",u=typeof n.chunkFilename=="string"?n.chunkFilename:"",p=typeof n.cssFilename=="string"?n.cssFilename:"",d=typeof n.chunkFilename=="string"?n.chunkFilename:"";return await Promise.all(e.map(async m=>{const c=findFilenameFormat({assetName:m.name,filename:t,assetModuleFilename:i,chunkFilename:u,cssFilename:p,cssChunkFilename:d});if(f__default.extname(m.name)===".map")return;const h=o.getAsset(m.name);let _=null;h&&(_=await bundlerPluginCore.getCompressedSize({fileName:m.name,code:h.source.source()})),s.push({name:m.name,size:m.size,gzipSize:_,normalized:bundlerPluginCore.normalizePath(m.name,c)})})),s},processChunks=({chunks:e,chunkIdMap:o})=>{let n=0;return e.map(s=>{const t=s.id??"",i=`${n}-${t}`;return o.set(t,i),n+=1,{id:s.id?.toString()??"",uniqueId:i,entry:s.entry,initial:s.initial,files:s.files??[],names:s.names??[]}})},processModules=({modules:e,chunkIdMap:o})=>e.map(n=>{const s=n.chunks??[],t=[];return s.forEach(i=>{const u=o.get(i);u&&t.push(u)}),{name:n.name??"",size:n.size??0,chunkUniqueIds:t}}),a="@codecov/webpack-plugin",l="1.4.0",webpackBundleAnalysisPlugin=({output:e})=>({version:e.version,name:a,pluginVersion:l,buildStart:()=>{e.start(),e.setPlugin(a,l)},buildEnd:()=>{e.end()},writeBundle:async()=>{await e.write()},webpack(o){const n=node_module.createRequire(typeof document>"u"?require("url").pathToFileURL(__filename).href:_documentCurrentScript&&_documentCurrentScript.src||new URL("index.cjs",document.baseURI).href)("webpack");o.hooks.thisCompilation.tap(a,s=>{s.hooks.processAssets.tapPromise({name:a,stage:n.Compilation.PROCESS_ASSETS_STAGE_REPORT},async()=>{if(e.setBundleName(e.bundleName),typeof s.outputOptions.chunkFormat=="string"){s.name&&s.name!==""&&e.setBundleName(`${e.bundleName}-${s.name}`);let c=s.outputOptions.chunkFormat;c==="commonjs"?c="cjs":c==="module"&&(c="esm"),e.setBundleName(`${e.bundleName}-${c}`)}const t=s.getStats().toJson({assets:!0,chunks:!0,modules:!0,builtAt:!0,hash:!0});e.bundler={name:"webpack",version:n.version};const i=s.outputOptions,{assets:u,chunks:p,modules:d}=t;if(u){const c=await processAssets({assets:u,compilation:s});e.assets=c}const m=new Map;if(p&&(e.chunks=processChunks({chunks:p,chunkIdMap:m})),d&&(e.modules=processModules({modules:d,chunkIdMap:m})),e.duration=Date.now()-(e.builtAt??0),e.outputPath=i.path??"",e.dryRun){const{RawSource:c}=n.sources;s.emitAsset(`${e.bundleName}-stats.json`,new c(e.bundleStatsToJson()))}})})}}),k=unplugin.createWebpackPlugin((e,o)=>{if(bundlerPluginCore.checkNodeVersion(o))return[];const n=bundlerPluginCore.normalizeOptions(e);if(!n.success){const{shouldExit:i}=bundlerPluginCore.handleErrors(n);return i&&process.exit(1),[]}const s=[],t=new bundlerPluginCore.Output(n.options);return n.options.enableBundleAnalysis&&s.push(webpackBundleAnalysisPlugin({output:t})),s}),codecovWebpackPlugin=k,_internal_webpackBundleAnalysisPlugin=webpackBundleAnalysisPlugin,_internal_findFilenameFormat=findFilenameFormat,_internal_processAssets=processAssets,_internal_processChunks=processChunks,_internal_processModules=processModules;exports._internal_findFilenameFormat=_internal_findFilenameFormat,exports._internal_processAssets=_internal_processAssets,exports._internal_processChunks=_internal_processChunks,exports._internal_processModules=_internal_processModules,exports._internal_webpackBundleAnalysisPlugin=_internal_webpackBundleAnalysisPlugin,exports.codecovWebpackPlugin=codecovWebpackPlugin; //# sourceMappingURL=index.cjs.map