function e(e,t){if(t==null||t>e.length)t=e.length;for(var r=0,n=new Array(t);r0&&i[i.length-1])&&(a[0]===6||a[0]===2)){o=0;continue}if(a[0]===3&&(!i||a[1]>i[0]&&a[1]1&&arguments[1]!==void 0?arguments[1]:[];i(this,e);P(this,"alertAggregator");P(this,"preferredLicenses");this.alertAggregator=t,this.preferredLicenses=r}o(e,[{key:"identifyLicense",value:function e(e,t){var r="".concat(e.name,"@").concat(e.version),n;return t.licenseOverrides[r]?n=t.licenseOverrides[r]:typeof e.license=="object"?n=e.license.type:e.license?n=e.license:Array.isArray(e.licenses)&&e.licenses.length>0?n=this.findPreferredLicense(e.licenses.map(function(e){return e.type}))||e.licenses[0].type:typeof e.licenses=="string"&&(n=e.licenses),n?t.unacceptableLicenseTest(n)?this.alertAggregator.addError('Found unacceptable license "'.concat(n,'" for ').concat(r)):(0,D.default)(n)||this.alertAggregator.addError('License "'.concat(n,'" for ').concat(r," is not a valid SPDX expression!")):this.alertAggregator.addError("Could not find license info for ".concat(r)),n||null}},{key:"findPreferredLicense",value:function e(e){var t=true,r=false,n=undefined,i=true,a=false,o=undefined;try{for(var s=this.preferredLicenses[Symbol.iterator](),u;!(i=(u=s.next()).done);i=true){var l=u.value;try{for(var c=e[Symbol.iterator](),f;!(t=(f=c.next()).done);t=true){var h=f.value;if(l===h)return l}}catch(e){r=true;n=e}finally{try{if(!t&&c.return!=null){c.return()}}finally{if(r){throw n}}}}}catch(e){a=true;o=e}finally{try{if(!i&&s.return!=null){s.return()}}finally{if(a){throw o}}}return null}}]);return e}();x(J,"LicenseIdentifier");var q=J;var N=require("path");var W=O(require("needle"),1);function _(e){return z.apply(this,arguments)}function z(){z=n(function(e){var t;return p(this,function(r){switch(r.label){case 0:return[4,(0,W.default)("get",e)];case 1:t=r.sent();return[2,t.statusCode===200?t.body:null]}})});return z.apply(this,arguments)}x(_,"fetch");var G="https://raw.githubusercontent.com/spdx/license-list-data",U=function(){"use strict";function e(){var t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:_;i(this,e);P(this,"request");P(this,"cache");this.request=t,this.cache={}}o(e,[{key:"retrieveLicenseText",value:function e(e){var t=this;return n(function(){var r;return p(this,function(n){switch(n.label){case 0:if(!!t.cache[e])return[3,2];return[4,t.request("".concat(G,"/master/text/").concat(e,".txt"))];case 1:r=n.sent();t.cache[e]=r;n.label=2;case 2:return[2,t.cache[e]||null]}})})()}}]);return e}();x(U,"DefaultLicenseTextProvider");var X=U;var V=function(){"use strict";function e(t,r,n){var a=arguments.length>3&&arguments[3]!==void 0?arguments[3]:new X;i(this,e);P(this,"alertAggregator");P(this,"fileSystem");P(this,"options");P(this,"defaultLicenseReader");this.alertAggregator=t,this.fileSystem=r,this.options=n,this.defaultLicenseReader=a}o(e,[{key:"readLicenseText",value:function e(e,t,r){var i=this;return n(function(){var n,a,o,s,u,l;return p(this,function(c){switch(c.label){case 0:n="".concat(e.name,"@").concat(e.version);if(!t)return[2,null];if(t.indexOf("SEE LICENSE IN ")===0){a=t.split(" ")[3];try{return[2,i.readFile(r,a)]}catch(e){i.alertAggregator.addError("could not find file specified in package.json license field of ".concat(n))}}o=i.fileSystem.listPaths(r),s=i.getLicenseFilename(o);if(!(s!==null))return[3,1];u=i.readFile(r,s);return[3,5];case 1:if(!i.options.replenishDefaultLicenseTexts)return[3,3];return[4,i.getDefaultLicenseText(t)];case 2:l=c.sent();return[3,4];case 3:l=null;c.label=4;case 4:u=l;c.label=5;case 5:return[2,u]}})})()}},{key:"getLicenseFilename",value:function e(e){var t=true,r=false,n=undefined;try{for(var i=e[Symbol.iterator](),a;!(t=(a=i.next()).done);t=true){var o=a.value;if(/^licen[cs]e/i.test(o))return o}}catch(e){r=true;n=e}finally{try{if(!t&&i.return!=null){i.return()}}finally{if(r){throw n}}}return null}},{key:"readFile",value:function e(e,t){return this.fileSystem.readFile((0,N.join)(e,t)).replace(/\r\n/g,"\n")}},{key:"getDefaultLicenseText",value:function e(e){var t=this;return n(function(){return p(this,function(r){switch(r.label){case 0:return[4,t.defaultLicenseReader.retrieveLicenseText(e)];case 1:return[2,r.sent()]}})})()}}]);return e}();x(V,"LicenseTextReader");var Y=V;var $=require("path");var B=function(){"use strict";function e(t){i(this,e);P(this,"fileSystem");this.fileSystem=t}o(e,[{key:"readNoticeText",value:function e(e){var t=this;return n(function(){var r,n;return p(this,function(i){r=t.fileSystem.listPaths(e).find(function(e){return/^notice/i.test(e)});if(!r)return[2,null];n=(0,$.join)(e,r);return[2,t.fileSystem.readFile(n).replace(/\r\n/g,"\n")]})})()}}]);return e}();x(B,"NoticeTextReader");var H=B;var K=function(){"use strict";function e(t,r,n,a){var o=arguments.length>4&&arguments[4]!==void 0?arguments[4]:new q(r),s=arguments.length>5&&arguments[5]!==void 0?arguments[5]:new Y(r,t,n),u=arguments.length>6&&arguments[6]!==void 0?arguments[6]:new H(t);i(this,e);P(this,"options");P(this,"packageJsonReader");P(this,"licenseIdentifier");P(this,"licenseTextReader");P(this,"noticeTextReader");this.options=n,this.packageJsonReader=a,this.licenseIdentifier=o,this.licenseTextReader=s,this.noticeTextReader=u}o(e,[{key:"getNpmTarballUrl",value:function e(e,t){var r=e[0]!=="@"?e:e.split("/")[1],n=t.indexOf("+"),i=n===-1?t:t.substring(0,n);return"https://registry.npmjs.org/".concat(e,"/-/").concat(r,"-").concat(i,".tgz")}},{key:"aggregateMeta",value:function e(e){var t=this;return n(function(){var r,n,i,a,o,s,u,l,f,h,d,v,y,g,b,m;return p(this,function(p){switch(p.label){case 0:r=new Set,n=[],i=e.sort(function(e,r){return t.packageJsonReader.readPackageJson(e).name.localeCompare(t.packageJsonReader.readPackageJson(r).name)});a=true,o=false,s=undefined;p.label=1;case 1:p.trys.push([1,9,10,11]);u=i[Symbol.iterator]();p.label=2;case 2:if(!!(a=(l=u.next()).done))return[3,8];f=l.value;h=t.packageJsonReader.readPackageJson(f),d="".concat(h.name,"@").concat(h.version);if(r.has(d)||t.options.excludedPackageTest(h.name,h.version))return[3,7];r.add(d);v=t.licenseIdentifier.identifyLicense(h,t.options);return[4,t.licenseTextReader.readLicenseText(h,v,f)];case 3:y=p.sent();if(!t.options.includeNoticeText)return[3,5];return[4,t.noticeTextReader.readNoticeText(f)];case 4:b=p.sent();return[3,6];case 5:b=void 0;p.label=6;case 6:g=b;n.push(c({name:h.name,version:h.version,author:t.getAuthor(h),repository:t.getRepository(h),source:t.getNpmTarballUrl(h.name,h.version),license:v,licenseText:y},g?{noticeText:g}:{}));p.label=7;case 7:a=true;return[3,2];case 8:return[3,11];case 9:m=p.sent();o=true;s=m;return[3,11];case 10:try{if(!a&&u.return!=null){u.return()}}finally{if(o){throw s}}return[7];case 11:return[2,n]}})})()}},{key:"getAuthor",value:function e(e){return typeof e.author=="object"?"".concat(e.author.name).concat(e.author.email?" <".concat(e.author.email,">"):"").concat(e.author.url?" (".concat(e.author.url,")"):""):e.author}},{key:"getRepository",value:function e(e){return e.repository&&e.repository.url?e.repository.url:typeof e.repository=="string"?e.repository:null}}]);return e}();x(K,"LicenseMetaAggregator");var Q=K;var Z=require("path");var ee=function(){"use strict";function e(t,r,n){i(this,e);P(this,"fileSystem");P(this,"buildRoot");P(this,"packageJsonReader");this.fileSystem=t,this.buildRoot=r,this.packageJsonReader=n}o(e,[{key:"getModuleDir",value:function e(e){var t=e.substring(0,e.lastIndexOf(Z.sep));return this.checkModuleDir(t)}},{key:"checkModuleDir",value:function e(e){var t=null,r=null,n=null;do{if(this.fileSystem.pathExists("".concat(e).concat(Z.sep,"package.json"))){var i=this.packageJsonReader.readPackageJson(e);i.name!==void 0&&i.version!==void 0&&(t=e,(i.license!==void 0||i.licenses!==void 0)&&(r=e))}n=e,e=(0,Z.resolve)("".concat(e).concat(Z.sep,"..").concat(Z.sep))}while(!r&&e!==n&&e!==this.buildRoot);return r||t}}]);return e}();x(ee,"ModuleDirectoryLocator");var et=ee;var er=O(require("spdx-expression-validate"),1);var en={additionalFiles:{},licenseOverrides:{},outputFilename:"oss-licenses.json",replenishDefaultLicenseTexts:!1,includeNoticeText:!1,unacceptableLicenseTest:function(){return!1},excludedPackageTest:function(){return!1},includePackages:function(){return[]}},ei=en;var ea=function(){"use strict";function e(t){i(this,e);P(this,"alertAggregator");this.alertAggregator=t}o(e,[{key:"getOptions",value:function e(e){return this.validateOptions(e),c({},ei,e)}},{key:"validateOptions",value:function e(e){var t=true,r=false,n=undefined;if(e.additionalFiles)try{for(var i=Object.keys(e.additionalFiles)[Symbol.iterator](),a;!(t=(a=i.next()).done);t=true){var o=a.value;typeof e.additionalFiles[o]!="function"&&this.alertAggregator.addError('Invalid additionalFiles option: Value for key "'.concat(o,'" is not a function!'))}}catch(e){r=true;n=e}finally{try{if(!t&&i.return!=null){i.return()}}finally{if(r){throw n}}}var s=true,u=false,l=undefined;if(e.licenseOverrides)try{for(var c=Object.keys(e.licenseOverrides)[Symbol.iterator](),f;!(s=(f=c.next()).done);s=true){var h=f.value;(0,er.default)(e.licenseOverrides[h])||this.alertAggregator.addError('Invalid licenseOverrides option: "'.concat(e.licenseOverrides[h],'" is not a valid SPDX expression!'))}}catch(e){u=true;l=e}finally{try{if(!s&&c.return!=null){c.return()}}finally{if(u){throw l}}}e.replenishDefaultLicenseTexts&&typeof e.replenishDefaultLicenseTexts!="boolean"&&this.alertAggregator.addError("Invalid replenishDefaultLicenseTexts option: Not a boolean!"),e.includePackages&&typeof e.includePackages!="function"&&this.alertAggregator.addError("Invalid includePackages option: Not a function!")}}]);return e}();x(ea,"OptionsProvider");var eo=ea;var es=require("path");var eu=function(){"use strict";function e(t){i(this,e);P(this,"fileSystem");P(this,"cache");this.fileSystem=t,this.cache={}}o(e,[{key:"readPackageJson",value:function e(e){if(!this.cache[e]){var t=(0,es.join)(e,"package.json"),r=JSON.parse(this.fileSystem.readFile(t));this.cache[e]=r}return this.cache[e]}}]);return e}();x(eu,"PackageJsonReader");var el=eu;var ec=O(require("webpack"),1);var ef=ec.default.WebpackError,eh=function(){"use strict";function e(t){i(this,e);P(this,"compilation");P(this,"errors");P(this,"warnings");this.compilation=t,this.errors=[],this.warnings=[]}o(e,[{key:"addError",value:function e(e){this.errors.push(e)}},{key:"addWarning",value:function e(e){this.warnings.push(e)}},{key:"flushAlerts",value:function e(e){var t,r;(t=this.compilation.errors).push.apply(t,f(this.errors.map(function(t){return new ef("".concat(e,": ").concat(t))}))),this.errors=[],(r=this.compilation.warnings).push.apply(r,f(this.warnings.map(function(t){return new ef("".concat(e,": ").concat(t))}))),this.warnings=[]}}]);return e}();x(eh,"WebpackAlertAggregator");var ed=eh;var ep=O(require("webpack"),1);var ev=ep.default.sources,ey=function(){"use strict";function e(t){i(this,e);P(this,"compilation");this.compilation=t}o(e,[{key:"addFile",value:function e(e,t){this.compilation.assets[e]=new ev.RawSource(t)}}]);return e}();x(ey,"WebpackAssetManager");var eg=ey;var eb=function(){"use strict";function e(){i(this,e)}o(e,[{key:"iterateModules",value:function e(e,t,r){var n=true,i=false,a=undefined,o=true,s=false,u=undefined;if(h(e.chunkGraph)<"u")try{for(var l=e.chunkGraph.getChunkModulesIterable(t)[Symbol.iterator](),c;!(n=(c=l.next()).done);n=true){var f=c.value;r(f)}}catch(e){i=true;a=e}finally{try{if(!n&&l.return!=null){l.return()}}finally{if(i){throw a}}}else if(h(t.modulesIterable)<"u")try{for(var d=t.modulesIterable[Symbol.iterator](),p;!(o=(p=d.next()).done);o=true){var v=p.value;r(v)}}catch(e){s=true;u=e}finally{try{if(!o&&d.return!=null){d.return()}}finally{if(s){throw u}}}else typeof t.forEachModule=="function"?t.forEachModule(r):Array.isArray(t.modules)&&t.modules.forEach(function(e){return r(e)});var y=true,g=false,b=undefined;if(h(e.chunkGraph)<"u")try{for(var m=e.chunkGraph.getChunkEntryModulesIterable(t)[Symbol.iterator](),k;!(y=(k=m.next()).done);y=true){var w=k.value;r(w)}}catch(e){g=true;b=e}finally{try{if(!y&&m.return!=null){m.return()}}finally{if(g){throw b}}}else t.entryModule&&r(t.entryModule)}}]);return e}();x(eb,"WebpackChunkModuleIterator");var em=eb;var ek=function(){"use strict";function e(){i(this,e)}o(e,[{key:"iterateFiles",value:function e(e,t){var r=e.resource,n=e.rootModule,i=e.fileDependencies,a=e.dependencies;r?t(r):(n===null||n===void 0?void 0:n.resource)&&t(n.resource),i&&i.forEach(function(e){return t(e)}),a&&a.forEach(function(e){var r=e.originModule,n=e._parentModule;(r===null||r===void 0?void 0:r.resource)&&t(r.resource),(n===null||n===void 0?void 0:n.resource)&&t(n.resource)})}}]);return e}();x(ek,"WebpackModuleFileIterator");var ew=ek;var ex=function(){"use strict";function e(){var t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:new em,r=arguments.length>1&&arguments[1]!==void 0?arguments[1]:new ew;i(this,e);P(this,"moduleIterator");P(this,"fileIterator");this.moduleIterator=t,this.fileIterator=r}o(e,[{key:"iterateChunks",value:function e(e,t){var r=this;var n=[];var i=true,a=false,o=undefined;try{for(var s=t[Symbol.iterator](),u;!(i=(u=s.next()).done);i=true){var l=u.value;this.moduleIterator.iterateModules(e,l,function(e){r.fileIterator.iterateFiles(e,function(e){n.push(e)})})}}catch(e){a=true;o=e}finally{try{if(!i&&s.return!=null){s.return()}}finally{if(a){throw o}}}return n}}]);return e}();x(ex,"WebpackChunkIterator");var eS=ex;var eA=function(){"use strict";function e(t){i(this,e);P(this,"fs");this.fs=t}o(e,[{key:"pathExists",value:function e(e){try{return this.fs.statSync(e),!0}catch(e){return!1}}},{key:"readFile",value:function e(e){return this.fs.readFileSync(e).toString("utf8")}},{key:"listPaths",value:function e(e){return this.fs.readdirSync(e)}}]);return e}();x(eA,"WebpackFileSystem");var eO=eA;var eL=T.default.WebpackError,eP="WebpackLicensePlugin",eF=function(){"use strict";function e(){var t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};i(this,e);P(this,"pluginOptions");P(this,"filenames");P(this,"createdFiles");P(this,"observedCompilers");this.pluginOptions=t,this.filenames=new Set,this.createdFiles=!1,this.observedCompilers=[]}o(e,[{key:"apply",value:function e(e){h(e.hooks)<"u"?(e.hooks.compilation.tap("webpack-license-plugin",this.handleCompilation.bind(this,e)),e.hooks.watchRun.tapAsync("webpack-license-plugin",this.handleWatchRun.bind(this))):h(e.plugin)<"u"&&(e.plugin("compilation",this.handleCompilation.bind(this,e)),e.plugin("watchRun",this.handleWatchRun.bind(this)))}},{key:"handleWatchRun",value:function e(e,t){var r=this;return n(function(){return p(this,function(e){r.createdFiles=!1,r.observedCompilers=[],t();return[2]})})()}},{key:"handleCompilation",value:function e(e,t){if(h(t.hooks)<"u")if(h(t.hooks.processAssets)<"u"){var r=this.handleChunkAssetOptimization.bind(this,e,t,t.chunks);t.hooks.processAssets.tapAsync({name:"webpack-license-plugin",stage:T.default.Compilation.PROCESS_ASSETS_STAGE_ANALYSE},function(e,t){return r(t)})}else t.hooks.optimizeChunkAssets.tapAsync("webpack-license-plugin",this.handleChunkAssetOptimization.bind(this,e,t));else h(t.plugin)<"u"&&t.plugin("optimize-chunk-assets",this.handleChunkAssetOptimization.bind(this,e,t))}},{key:"handleChunkAssetOptimization",value:function e(e,t,r,i){var a=this;return n(function(){var n,o,s,u,l,c,h,d,v,y,g,b,m;return p(this,function(p){switch(p.label){case 0:if(a.observedCompilers.push({name:t.compiler.name,isChild:t.compiler.isChild()}),a.createdFiles){n=a.observedCompilers.map(function(e){var t=e.name,r=e.isChild;return"compiler: ".concat(t,", isChild: ").concat(r)}).join("\n"),o=new eL("".concat(eP,": Found licenses after license files were already created.\nIf you see this message, you ran into an edge case we thought would not happen. Please open an isssue at https://github.com/codepunkt/webpack-license-plugin/issues with details of your webpack configuration so we can invastigate it further.\n").concat(n));t.errors.push(o),i();return[2]}t.compiler.isChild()||(a.createdFiles=!0);s=new ed(t),u=new eo(s).getOptions(a.pluginOptions);s.flushAlerts(eP);l=new eS;c=true,h=false,d=undefined;try{for(v=l.iterateChunks(t,r)[Symbol.iterator]();!(c=(y=v.next()).done);c=true){g=y.value;a.filenames.add(g)}}catch(e){h=true;d=e}finally{try{if(!c&&v.return!=null){v.return()}}finally{if(h){throw d}}}if(t.compiler.isChild()){i();return[2]}b=new eO(e.inputFileSystem),m=new el(b);return[4,new I(new eg(t),new et(b,e.options.context,m),new Q(b,s,u,m)).writeLicenseFiles(f(a.filenames),u)];case 1:p.sent(),s.flushAlerts(eP),i();return[2]}})})()}}]);return e}();x(eF,"WebpackLicensePlugin");var eT=eF;var eM=eT;module.exports=module.exports.default;//# sourceMappingURL=index.cjs.map