/*
 * Copyright (c) 2018, 2026, Oracle and/or its affiliates.
 * Licensed under The Universal Permissive License (UPL), Version 1.0
 * as shown at https://oss.oracle.com/licenses/upl/
 */
var path;const ComponentFinder=function(preCompUtils,jafUtils,fsUtils,tsxUtils,msgCtx,nd){this._Utils=preCompUtils;this._jafUtils=jafUtils;this._fsUtils=fsUtils;this._tsxUtils=tsxUtils;this._msgCtx=msgCtx;path=nd.path;this.runOnce=false};ComponentFinder.prototype.findAllComponents=function(projectPathInfo,componentRoots,precompileCache){let masterComponentList=[];if(!this.runOnce){if(projectPathInfo.exchangeCacheFolder){masterComponentList=masterComponentList.concat(this._discoverComponentsFromRoot(path.join(projectPathInfo.base,projectPathInfo.exchangeCacheFolder),false,false,null,null))}if(componentRoots&&componentRoots.length>0){componentRoots.forEach(root=>{let target=root;if(this._fsUtils.getFileTypeSync(target)==="f"){target=path.dirname(root);this.msgCtx.msg(`Warning: Incorrectly defined "components" array entry in JAF configuration file.  Entries should list folders only not explicit file names.\n  Bad entry: "${root}"\nAudit will process the "${target}" folder instead.\n`)}masterComponentList=masterComponentList.concat(this._discoverComponentsFromRoot(target,true,projectPathInfo.isBuiltOutput,null,precompileCache))})}else{if(projectPathInfo.componentRootFolder){masterComponentList=masterComponentList.concat(this._discoverComponentsFromRoot(path.join(projectPathInfo.base,projectPathInfo.jsSource,projectPathInfo.componentRootFolder),true,projectPathInfo.isBuiltOutput,null,precompileCache));if(projectPathInfo.tsSource&&projectPathInfo.tsSource!==projectPathInfo.jsSource){masterComponentList=masterComponentList.concat(this._discoverComponentsFromRoot(path.join(projectPathInfo.base,projectPathInfo.tsSource,projectPathInfo.componentRootFolder),true,false,null,precompileCache))}}}this.runOnce=true;this.masterComponentList=masterComponentList}return this.masterComponentList};ComponentFinder.prototype._discoverComponentsFromRoot=function(rootDir,isLocal,builtOutput,parentPack,precompileCache){let componentArray=[];if(!this._fsUtils.pathExistsSync(rootDir)){return componentArray}const compFileStructure=this._fsUtils.readDir(rootDir);compFileStructure.forEach(l1file=>{let componentInfo;if(!l1file.isFile&&l1file.files.length>0){l1file.files.forEach(l2file=>{if(!builtOutput){if(l2file.isFile&&l2file.name==="component.json"){componentInfo=this._Utils.extractComponentInfoFromJSONFile(path.join(rootDir,l1file.name),"component.json",isLocal,false);componentArray.push(componentInfo);if(componentInfo.type&&componentInfo.type==="pack"){const packMembers=this._discoverComponentsFromRoot(this._Utils.toJAFPath(path.join(rootDir,l1file.name)),isLocal,false,componentInfo.name,precompileCache);componentArray=componentArray.concat(packMembers)}}else if(l2file.isFile&&path.extname(l2file.name)===".tsx"&&precompileCache){componentInfo=this._tsxUtils.extractComponentInfoFromTSXFile(path.join(rootDir,l1file.name),l2file.name,isLocal,precompileCache);if(componentInfo){componentArray.push(componentInfo)}}}else{if(!l2file.isFile&&l2file.files.length>0){l2file.files.forEach(l3file=>{if(l3file.isFile&&l3file.name==="component.json"){componentInfo=this._Utils.extractComponentInfoFromJSONFile(path.join(rootDir,l1file.name,l2file.name),"component.json",isLocal,false);if(!componentInfo.pack){componentArray.push(componentInfo);if(componentInfo.type==="pack"){const packMembers=this._discoverComponentsFromRoot(this._Utils.toJAFPath(path.join(rootDir,l1file.name,l2file.name)),isLocal,false,componentInfo.name,precompileCache);componentArray=componentArray.concat(packMembers)}}}else if(l3file.isFile&&path.extname(l3file.name)===".tsx"&&precompileCache){componentInfo=this._tsxUtils.extractComponentInfoFromTSXFile(path.join(rootDir,l1file.name,l2file.name),l3file.name,isLocal,precompileCache);if(componentInfo){componentArray.push(componentInfo)}}})}}})}else{if(l1file.isFile&&l1file.name==="component.json"){componentInfo=this._Utils.extractComponentInfoFromJSONFile(rootDir,"component.json",isLocal,false);if(componentInfo.type!=="pack"||componentInfo.name!==parentPack){componentArray.push(componentInfo)}}else if(l1file.isFile&&path.extname(l1file.name)===".tsx"&&precompileCache){componentInfo=this._tsxUtils.extractComponentInfoFromTSXFile(rootDir,l1file.name,isLocal,precompileCache);if(componentInfo){componentArray.push(componentInfo)}}}});return componentArray};module.exports=ComponentFinder;