/*
 * 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/
 */
const Utils=require("../jetwc-lib/jetwcutils-componentAuditUtils");const TsxUtils=require("../jetwc-lib/jetwcutils-tsxUtils");const ruleDef=function(){};ruleDef.prototype.getName=function(){return"jetwc-prerelease-dependencies"};ruleDef.prototype.getShortDescription=function(){return"Issue an info audit for any components that have pre-release dependencies"};ruleDef.prototype.getDescription=function(){return"This rule can be applied before production to ensure that all components depend, in turn, on release ready versions"};ruleDef.prototype.register=function(context){return{compjson:this._doAudit,Program:this._doVComponentAudit}};ruleDef.prototype._doAudit=function(context){if(context.suppData.obj){let issue;const componentMetadata=context.suppData.obj;const fullName=Utils.getComponentFullName(componentMetadata);if(componentMetadata.dependencies){const dependencyNames=Object.keys(componentMetadata.dependencies);dependencyNames.forEach(dependency=>{this._checkDependency(context,fullName,dependency,componentMetadata.dependencies[dependency])})}}};ruleDef.prototype._doVComponentAudit=function(context){const componentInfo=TsxUtils.matchToVComponentImpl(context,context.filepath);if(componentInfo&&componentInfo.dependencies){componentInfo.dependencies.forEach(dependency=>{this._checkDependency(context,componentInfo.fullName,dependency.name,dependency.range)})}};ruleDef.prototype._checkDependency=function(context,fullName,dependency,version){const depRangeMin=context.utils.semVerUtils.minVersion(version);if(depRangeMin.prerelease.length>0){issue=new context.Issue(`Component dependency ${dependency} for ${fullName} has a pre-release version number`);context.reporter.addIssue(issue,context)}};module.exports=ruleDef;