@oracle/oraclejet-audit 16.1.4 → 17.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/corePackMigrator/cli.js +1 -1
- package/corePackMigrator/corePackMigrator.js +2 -2
- package/corePackMigrator/metadata/actionCardMetadata.json +10 -0
- package/corePackMigrator/metadata/avatarMetadata.json +11 -1
- package/corePackMigrator/metadata/bindIfMetadata.json +4 -0
- package/corePackMigrator/metadata/buttonMetadata.json +65 -49
- package/corePackMigrator/metadata/chartMetadata.json +53 -0
- package/corePackMigrator/metadata/collapsibleMetadata.json +27 -12
- package/corePackMigrator/metadata/conveyorBeltMetadata.json +34 -0
- package/corePackMigrator/metadata/datePickerMetadata.json +43 -0
- package/corePackMigrator/metadata/drawerLayoutMetadata.json +18 -0
- package/corePackMigrator/metadata/drawerPopupMetadata.json +27 -14
- package/corePackMigrator/metadata/filePickerMetadata.json +20 -7
- package/corePackMigrator/metadata/formLayoutMetadata.json +11 -1
- package/corePackMigrator/metadata/highlightTextMetadata.json +10 -0
- package/corePackMigrator/metadata/inputDateMetadata.json +110 -0
- package/corePackMigrator/metadata/inputNumberMetadata.json +107 -75
- package/corePackMigrator/metadata/inputPasswordMetadata.json +111 -75
- package/corePackMigrator/metadata/inputTextMetadata.json +118 -81
- package/corePackMigrator/metadata/labelValueMetadata.json +245 -0
- package/corePackMigrator/metadata/legendItemMetadata.json +11 -1
- package/corePackMigrator/metadata/legendMetadata.json +59 -49
- package/corePackMigrator/metadata/listItemLayoutMetadata.json +11 -1
- package/corePackMigrator/metadata/listviewMetadata.json +104 -63
- package/corePackMigrator/metadata/messageBannerMetadata.json +10 -0
- package/corePackMigrator/metadata/messagesMetadata.json +11 -1
- package/corePackMigrator/metadata/progressBarMetadata.json +11 -1
- package/corePackMigrator/metadata/progressCircleMetadata.json +10 -0
- package/corePackMigrator/metadata/radiosetMetadata.json +11 -1
- package/corePackMigrator/metadata/ratingGaugeMetadata.json +113 -87
- package/corePackMigrator/metadata/selectManyMetadata.json +72 -42
- package/corePackMigrator/metadata/selectSingleMetadata.json +61 -46
- package/corePackMigrator/metadata/selectorMetadata.json +1 -1
- package/corePackMigrator/metadata/statusMeterGaugeMetadata.json +1 -1
- package/corePackMigrator/metadata/tagCloudMetadata.json +10 -0
- package/corePackMigrator/metadata/textAreaMetadata.json +88 -46
- package/corePackMigrator/resource/astUtils.js +1 -1
- package/corePackMigrator/resource/componentMigrator.js +1 -1
- package/corePackMigrator/resource/fileScanner.js +1 -1
- package/corePackMigrator/resource/htmlUtils.js +1 -1
- package/corePackMigrator/resource/manifest.json +137 -36
- package/corePackMigrator/resource/testUtils.js +6 -0
- package/corePackMigrator/templates/componentMetaData.json +118 -14
- package/corePackMigrator/templates/migrationConfig.json +4 -0
- package/corePackMigrator/utilities/deltaWebElementAPIs.js +6 -0
- package/corePackMigrator/utilities/logging.js +1 -1
- package/jaf-amd.js +1 -1
- package/lib/AstJson.js +1 -1
- package/lib/Components.js +1 -1
- package/lib/Config.js +1 -1
- package/lib/ConfigEx.js +6 -0
- package/lib/ConfigLib.js +1 -1
- package/lib/MetaLib.js +1 -1
- package/lib/OjCPack.js +1 -1
- package/lib/RegTypes.js +1 -1
- package/lib/RulePack.js +1 -1
- package/lib/RuleSet.js +1 -1
- package/lib/Rules.js +1 -1
- package/lib/TsxUtils.js +1 -1
- package/lib/checkage.js +1 -1
- package/lib/defaults.js +1 -1
- package/lib/extends.js +1 -1
- package/lib/migrator.js +1 -1
- package/lib/ns.js +1 -1
- package/libext/expparser.js +1 -1
- package/meta/16.1.0/jetauditmeta.js +1 -1
- package/meta/17.0.0/jetauditmeta.js +9 -0
- package/meta/metaverlist.json +1 -1
- package/package.json +3 -3
- package/profiles/best-practice.json +97 -78
- package/profiles/redwood-strict.json +22 -14
- package/rulepacks/csp/csp-json-unsafe-expr.js +1 -1
- package/rulepacks/jetwc/jetwc-bootstrap.js +1 -1
- package/rulepacks/jetwc/jetwc-css-scoping.js +1 -1
- package/rulepacks/jetwc/jetwc-displayname.js +1 -1
- package/rulepacks/jetwc/jetwc-jet-version.js +1 -1
- package/rulepacks/jetwc/jetwc-markdown-link.js +1 -1
- package/rulepacks/jetwc/jetwc-namespace.js +1 -1
- package/rulepacks/jetwc/jetwc-nls-languages.js +1 -1
- package/rulepacks/jetwc/jetwc-property-nesting.js +1 -1
- package/rulepacks/jetwc/jetwc-property-translatable.js +1 -1
- package/rulepacks/jetwc/jetwc-require-paths.js +1 -1
- package/rulepacks/jetwc/jetwc-reserved-property.js +1 -1
- package/rulepacks/jetwc/jetwc-schema.js +1 -1
- package/rulepacks/jetwc/jetwc-standard-files.js +1 -1
- package/rulepacks/jetwc/jetwc-vb-category.js +1 -1
- package/rulepacks/jetwc/rules.json +1 -1
- package/rulepacks/jetwc-lib/jetwcutils-auditComponentCacheManager.js +1 -1
- package/rulepacks/jetwc-lib/jetwcutils-commonListenerImpls.js +1 -1
- package/rulepacks/jetwc-lib/jetwcutils-componentAuditUtils.js +1 -1
- package/rulepacks/jetwc-lib/jetwcutils-componentFinder.js +1 -1
- package/rulepacks/jetwc-lib/jetwcutils-tsxUtils.js +1 -1
- package/rulepacks/jetwco/jetwco-bootstrap.js +1 -1
- package/rulepacks/jetwco/jetwco-component-api-baseline-changes.js +1 -1
- package/rulepacks/jetwco/jetwco-component-api-changes.js +1 -1
- package/rulepacks/jetwco/jetwco-component-api-controlled-changes.js +1 -1
- package/rulepacks/jetwco/jetwco-license-info.js +1 -1
- package/rulepacks/jetwco/jetwco-prerelease-cdn.js +1 -1
- package/rulepacks/jetwco/jetwco-validate-applied-audits.js +1 -1
- package/rulepacks/jetwco/rules.json +1 -1
- package/rules/jet/helpers/cssHelper.js +1 -1
- package/rules/jet/helpers/has-attrib-value.js +6 -0
- package/rules/jet/helpers/tsx/has-prop-value.js +6 -0
- package/rules/jet/msgid.json +1 -1
- package/rules/jet/oj-acc-button-label.js +6 -0
- package/rules/jet/oj-css-style-bp-display.js +1 -1
- package/rules/jet/oj-html-attr-expr-writeback.js +1 -1
- package/rules/jet/oj-html-bindif-test.js +1 -1
- package/rules/jet/oj-html-binding-as-slot-child.js +1 -1
- package/rules/jet/oj-html-bp-button-xs-chroming.js +6 -0
- package/rules/jet/oj-html-bp-title-to-tooltip.js +6 -0
- package/rules/jet/oj-html-button-size-chroming.js +6 -0
- package/rules/jet/oj-html-dlg-title.js +1 -1
- package/rules/jet/oj-html-form-bindif.js +1 -1
- package/rules/jet/oj-html-ko-comment.js +1 -1
- package/rules/jet/oj-html-ko-databind.js +1 -1
- package/rules/jet/oj-html-ojattr-value.js +1 -1
- package/rules/jet/oj-html-ojtag-ns.js +1 -1
- package/rules/jet/oj-html-redwood-clear-icon.js +6 -0
- package/rules/jet/oj-html-slot-default.js +1 -1
- package/rules/jet/oj-html-slot-pref-content.js +1 -1
- package/rules/jet/oj-html-style-abs-units.js +1 -1
- package/rules/jet/oj-html-style-bp-color.js +1 -1
- package/rules/jet/oj-html-style-bp-display.js +1 -1
- package/rules/jet/oj-html-style-bp-font-family.js +1 -1
- package/rules/jet/oj-html-style-bp-font.js +1 -1
- package/rules/jet/oj-html-style-bp-margin-padding.js +6 -0
- package/rules/jet/oj-html-wctag-maintenance.js +1 -1
- package/rules/jet/oj-tsx-acc-button-label.js +6 -0
- package/rules/jet/oj-tsx-bp-button-xs-chroming.js +6 -0
- package/rules/jet/oj-tsx-bp-title-to-tooltip.js +6 -0
- package/rules/jet/oj-tsx-button-size-chroming.js +6 -0
- package/rules/jet/oj-tsx-dlg-title.js +1 -1
- package/rules/jet/oj-tsx-form-bindif.js +1 -1
- package/rules/jet/oj-tsx-ojtag-ns.js +1 -1
- package/rules/jet/oj-tsx-redwood-clear-icon.js +6 -0
- package/rules/jet/oj-tsx-slot-default.js +6 -0
- package/rules/jet/oj-tsx-slot-pref-content.js +1 -1
- package/rules/jet/oj-tsx-style-abs-units.js +6 -0
- package/rules/jet/oj-tsx-style-bp-margin-padding.js +6 -0
- package/rules/jet/oj-tsx-wctag-maintenance.js +1 -1
- package/rules/jet/rules.json +1 -1
- package/schema/component-schema.json +1 -1
- package/src/JafCore.js +1 -1
- package/types/index.d.ts +3 -0
package/lib/AstJson.js
CHANGED
|
@@ -3,4 +3,4 @@
|
|
|
3
3
|
* Licensed under The Universal Permissive License (UPL), Version 1.0
|
|
4
4
|
* as shown at https://oss.oracle.com/licenses/upl/
|
|
5
5
|
*/
|
|
6
|
-
const PROP="P";const RBRACE="}";const LBRACE="{";const LSQUARE="[";const RSQUARE="]";const NUMBER="N";const STRING="S";const BOOL="B";const NULL="NL";const COLON=":";const DQUOTE="\"";const ESCAPE="\\";const COMMA=",";const UNARY_MINUS="-";const $DIGIT="$digit";const EOF="";function AstJson(msgContext){this._msgContext=msgContext};AstJson.prototype.parse=function(data){var ret;this._data=data;this._index=-1;this._row=1;this._col=0;this._curChar=null;this._objStack=[];this._listStack=[];this._curProp=null;this._curObj=null;this._tokValue=null;ret=this._parse();return ret};AstJson.prototype._parse=function(){var tok;do{switch(tok){case STRING:case NUMBER:case BOOL:case NULL:{if(this._curProp){this._curProp.value=this._tokValue}else{this._curProp=this._tokValue}this._curList.push(this._curProp);this._curProp=null;break}case PROP:{this._curProp={name:this._tokValue.rawValue,pos:{row:this._startRow,col:this._startCol,start:this._startIndex,end:this._getTokEndIndex(this._tokValue.rawValue,this._startIndex,"string"),index:this._startIndex}};this._next(COLON);break}case LBRACE:{if(this._curProp){this._curProp.value=this._tokValue}if(this._curObj){this._objStack.push(this._curObj)}this._curObj=this._tokValue;this._curObj.members=[];if(this._curList){if(this._curProp)this._curList.push(this._curProp);else this._curList.push(this._curObj)}this._listStack.push(this._curList);this._curList=this._curObj.members;break}case RBRACE:{if(this._objStack.length){this._curObj=this._objStack.pop()}if(this._listStack.length){this._curList=this._listStack.pop()}break}case LSQUARE:{if(this._curList){this._listStack.push(this._curList)}if(this._curProp){this._curProp.value=this._tokValue;this._curList.push(this._curProp)}else if(this._curList){this._curList.push(this._tokValue)}this._curList=this._tokValue.members;this._curProp=null;break}case RSQUARE:{this._curList=this._listStack.pop();break}}}while((tok=this._getToken())!==EOF);return this._startToken===LBRACE?this._curObj:this._curList};AstJson.prototype._getToken=function(){var s;while(true){s=this._getNextChar();if(s===DQUOTE){this._tokValue=this._getString();this._getTokValue("string",this._tokValue,true);return this._peekNext(COLON)?PROP:STRING}else if(this._isNumber(s)){this._tokValue=this._getNumber(s);this._getTokValue("number",this._tokValue,true);return NUMBER}else if(s==="t"||s==="f"){this._tokValue=this._getBoolean(s);this._getTokValue("boolean",this._tokValue,true);return BOOL}else if(s==="n"){this._tokValue=this._getNull();this._getTokValue("null",this._tokValue,true);return NULL}else if(s===LBRACE){this._tokValue={type:"Object",value:"{",pos:{row:this._row,col:this._col,start:this._index,end:this._index,index:this._index}};if(!this._startToken){this._startToken=LBRACE}return LBRACE}else if(s===RBRACE){return RBRACE}else if(s===LSQUARE){this._tokValue={type:"array",pos:{row:this._row,col:this._col,start:this._index,end:this._index,index:this._index},members:[]};if(!this._startToken){this._startToken=LSQUARE}return LSQUARE}else if(s===RSQUARE){return RSQUARE}else if(s===EOF){return EOF}else if(s===COMMA){continue}else{if(this._msgContext){this._msgContext.assert("JSON -> AST - unexpected char '"+s+"'")}return s}}};AstJson.prototype._getString=function(){var str="",s,inEscape;this._startRow=this._row;this._startCol=this._col;this._startIndex=this._index;while(
|
|
6
|
+
const PROP="P";const RBRACE="}";const LBRACE="{";const LSQUARE="[";const RSQUARE="]";const NUMBER="N";const STRING="S";const BOOL="B";const NULL="NL";const COLON=":";const DQUOTE="\"";const ESCAPE="\\";const COMMA=",";const UNARY_MINUS="-";const $DIGIT="$digit";const EOF="";function AstJson(msgContext){this._msgContext=msgContext};AstJson.prototype.parse=function(data){var ret;this._data=data;this._index=-1;this._row=1;this._col=0;this._curChar=null;this._objStack=[];this._listStack=[];this._curProp=null;this._curObj=null;this._tokValue=null;ret=this._parse();return ret};AstJson.prototype._parse=function(){var tok;do{switch(tok){case STRING:case NUMBER:case BOOL:case NULL:{if(this._curProp){this._curProp.value=this._tokValue}else{this._curProp=this._tokValue}this._curList.push(this._curProp);this._curProp=null;break}case PROP:{this._curProp={name:this._tokValue.rawValue,pos:{row:this._startRow,col:this._startCol,start:this._startIndex,end:this._getTokEndIndex(this._tokValue.rawValue,this._startIndex,"string"),index:this._startIndex}};this._next(COLON);break}case LBRACE:{if(this._curProp){this._curProp.value=this._tokValue}if(this._curObj){this._objStack.push(this._curObj)}this._curObj=this._tokValue;this._curObj.members=[];if(this._curList){if(this._curProp)this._curList.push(this._curProp);else this._curList.push(this._curObj)}this._listStack.push(this._curList);this._curList=this._curObj.members;break}case RBRACE:{if(this._objStack.length){this._curObj=this._objStack.pop()}if(this._listStack.length){this._curList=this._listStack.pop()}break}case LSQUARE:{if(this._curList){this._listStack.push(this._curList)}if(this._curProp){this._curProp.value=this._tokValue;this._curList.push(this._curProp)}else if(this._curList){this._curList.push(this._tokValue)}this._curList=this._tokValue.members;this._curProp=null;break}case RSQUARE:{this._curList=this._listStack.pop();break}}}while((tok=this._getToken())!==EOF);return this._startToken===LBRACE?this._curObj:this._curList};AstJson.prototype._getToken=function(){var s;while(true){s=this._getNextChar();if(s===DQUOTE){this._tokValue=this._getString();this._getTokValue("string",this._tokValue,true);return this._peekNext(COLON)?PROP:STRING}else if(this._isNumber(s)){this._tokValue=this._getNumber(s);this._getTokValue("number",this._tokValue,true);return NUMBER}else if(s==="t"||s==="f"){this._tokValue=this._getBoolean(s);this._getTokValue("boolean",this._tokValue,true);return BOOL}else if(s==="n"){this._tokValue=this._getNull();this._getTokValue("null",this._tokValue,true);return NULL}else if(s===LBRACE){this._tokValue={type:"Object",value:"{",pos:{row:this._row,col:this._col,start:this._index,end:this._index,index:this._index}};if(!this._startToken){this._startToken=LBRACE}return LBRACE}else if(s===RBRACE){return RBRACE}else if(s===LSQUARE){this._tokValue={type:"array",pos:{row:this._row,col:this._col,start:this._index,end:this._index,index:this._index},members:[]};if(!this._startToken){this._startToken=LSQUARE}return LSQUARE}else if(s===RSQUARE){return RSQUARE}else if(s===EOF){return EOF}else if(s===COMMA){continue}else{if(this._msgContext){this._msgContext.assert("JSON -> AST - unexpected char '"+s+"'")}return s}}};AstJson.prototype._getString=function(){var str="",s,inEscape;this._startRow=this._row;this._startCol=this._col;this._startIndex=this._index;while((s=this._getChar())!==EOF){if(s===ESCAPE&&!inEscape){inEscape=true;continue}if(inEscape){inEscape=false;if(s==="n"){str+"\n"}else if(s==="\""){str+="\""}else if(s==="t"){str+="\t"}else{str+=" "+s}continue}if(s===DQUOTE){break}str+=s}return{value:str,rawValue:str}};AstJson.prototype._getNumber=function(s){var str=s;this._startRow=this._row;this._startCol=this._col;this._startIndex=this._index;while(true){s=this._getChar();if(this._isNumber(s)){if(s!==UNARY_MINUS){str+=s;continue}}this._unget();break}return{value:parseInt(str),rawValue:str}};AstJson.prototype._getBoolean=function(s){var ret={};this._startRow=this._row;this._startCol=this._col;this._startIndex=this._index;if(s==="t"){this._next("r");this._next("u");this._next("e");ret.value=true;ret.rawValue="true"}else{this._next("a");this._next("l");this._next("s");this._next("e");ret.value=false;ret.rawValue="false"}return ret};AstJson.prototype._getNull=function(){this._startRow=this._row;this._startCol=this._col;this._startIndex=this._index;this._next("u");this._next("l");this._next("l");return{value:null,rawValue:"null"}};AstJson.prototype._getTokValue=function(type,tokValue,startRc){this._tokValue={type:type,value:this._tokValue.value,rawValue:this._tokValue.rawValue,pos:{row:startRc?this._startRow:this._row,col:startRc?this._startCol:this._col,start:this._startIndex,end:this._getTokEndIndex(this._tokValue.rawValue,this._startIndex,type),index:this._startIndex}}};AstJson.prototype._next=function(s){while(true){if(this._getNextChar()===s){break}}};AstJson.prototype._peekNext=function(s){var n,r,c,val,ret=false;n=this._index;r=this._row;c=this._col;if(s===$DIGIT){val=this._getNextChar();ret=!isNaN(parseInt(val,10))}else{ret=this._getNextChar()===s}this._index=n;this._row=r;this._col=c;return ret};AstJson.prototype._getNextChar=function(){var s;while(true){s=this._getChar();if(s===EOF){return EOF}if(!_isWhite(s)){return s}}};AstJson.prototype._getChar=function(){if(!this._doNotadvance){this._index=this._index>=0?++this._index:0}else{this._unget=false}if(this._index<this._data.length){this._curChar=this._data.substr(this._index,1);if(this._curChar==="\n"){this._row++;this._col=0}else if(this._curChar!=="\r"){this._col++}return this._curChar}return EOF};AstJson.prototype._unget=function(){this._doNotAdvance=true};AstJson.prototype._getTokEndIndex=function(s,start,type){var end=start;if(type==="string"){end+=2}return end+s.length-1};AstJson.prototype._isNumber=function(s){var num;if(s===UNARY_MINUS){num=this._peekNext($DIGIT);return num>="0"&&num<="9"}return!isNaN(parseInt(s,10))};function _isWhite(s){return s==" "||s==="\n"||s==="\r"||s==="\t"};module.exports=AstJson;
|
package/lib/Components.js
CHANGED
|
@@ -3,4 +3,4 @@
|
|
|
3
3
|
* Licensed under The Universal Permissive License (UPL), Version 1.0
|
|
4
4
|
* as shown at https://oss.oracle.com/licenses/upl/
|
|
5
5
|
*/
|
|
6
|
-
"use strict";const COMPONENT_JSON="component.json";const PROPERTIES="properties";const PROP_SLOTS="slots";const PROP_DYNAMIC_SLOTS="dynamicSlots";const PROP_PROPS="props";const PROP_EVENTS="events";const PROP_STYLECLASSES="styleClasses";const PROP_IMPLEMENTS="implements";const PROP_REQUIRED="required";const PROP_FOLDER="folder";const PROP_VERSION="version";const PROP_UNSUP_THEME="unsupTheme";const PROP_STATUS="status";const PROP_SUBCOMPONENT_TYPE="subcomponentType";const PROP_DEPENDENCIES="dependencies";const PROP_TYPE="type";const PROP_PACK="pack";const PROPERTY_VALUE="propertyValue";const PROPERTY_TYPE="propertyType";const PACK_PRIVATE="packPrivate";const DEPRECATED="deprecated";const MAINTENANCE="maintenance";const SUPERSEDES="supersedes";const ANTIPATTERN="antiPattern";const DYNAMIC_FORM_ELEM="DynamicFormElement";const DYNAMIC_TABLE_ELEM="DynamicTableElement";const VB_FRAGMENT_ELEM="VbFragmentElement";const CUSTOM_ELEMENT="@customElement";const REGISTER_CUSTOM_ELEMENT="registerCustomElement";const OJ_C="oj-c";const DOT=".";const CHANGED="Changed";const FT_HTML="html";const FT_TSX="tsx";const REGXPR=/string|number|object|array|boolean|[\|.<>]/gi;function Components(nd,runMode,cwd,compSvcs,urlBase,urls,filePaths,metaLib,ojcPack,jetCore,runOpts,msgCtx,appCtx){this._nd=nd;this._tagLookup={};this._jetTagLookup={};this._VCompLookup={};this._styleLookup={};this._ignored={};this._maintenance=null;this._supersedes=null;this._antiPattern=null;this._meta={};this._path=null;this._reqAttrs=null;this._metaLib=metaLib;this._ojcPack=ojcPack;this._utils=appCtx.utils;this._fsUtils=appCtx.fsUtils;this._tsUtils=appCtx.tsUtils;this._curFileType=null;this._oConfig=appCtx.config;this._VFilesInspected=null;this._VTypes=null;this._compSvcs=compSvcs;this._isAMD=runMode==="amd";this._cwd=cwd;this._error=msgCtx.error;this._warn=msgCtx.warn;this._debug=msgCtx.debug;this._info=msgCtx.info;this._msg=msgCtx.msg;this._console=msgCtx.console;this._jafMsg=msgCtx.jafMsg;this._isDebug=msgCtx.isDebug;this._isVerbose=msgCtx.isVerbose;this._count=0;this._isOk=true;this._runOpts=runOpts;this._init(urlBase,urls,filePaths,jetCore);if(this._tsUtils){this._initVComponents()}};Components.prototype.isUserTag=function(tagName){var tag=_removeChevrons(tagName);return!!(this._tagLookup[tag]||this._VCompLookup[tag])};Components.prototype.isJetCoreTag=function(tagName){return!!this._jetTagLookup[_removeChevrons(tagName)]};Components.prototype.isVComponentTag=function(tagName){return!!this._VCompLookup[_removeChevrons(tagName)]};Components.prototype.isKnownTag=function(tagName){return!!this._lookupTag(tagName)};Components.prototype._lookupTag=function(tagName){tagName=_removeChevrons(tagName);return this._jetTagLookup[tagName]||this._tagLookup[tagName]||this._VCompLookup[tagName]};Components.prototype.isTagAttr=function(tagName,attrName){return this.isTagProp(tagName,attrName)||this.isJetTagProp(tagName,attrName)};Components.prototype.isJetTagAttr=function(tagName,attrName){return this.isJetTagProp(tagName,attrName)};Components.prototype.isTagDeprecated=function(tag){var comp,stats,status,ret=null;if(comp=this._lookupTag(_removeChevrons(tag))){if(stats=comp.status){for(status of stats){if((!status.type||status.type===DEPRECATED)&&!status.hasOwnProperty("target")){ret=status;if(ret.description){ret.description=this._utils.removeLink(ret.description)}break}}}}return ret};Components.prototype.isTagAttrDeprecated=function(tagName,attrName){var prop,status,stats,o,ret=null;if((prop=this.getAnyTagProp(tagName,attrName))&&(stats=prop.status)){ret=[];for(status of stats){if(!status.type||status.type===DEPRECATED){o={type:DEPRECATED};if(status.hasOwnProperty("target")){o.target=status.target}if(status.hasOwnProperty("description")){o.description=status.description}if(status.hasOwnProperty("since")){o.since=status.since}if(status.hasOwnProperty("value")){o.value=status.value}ret.push(o)}}ret=ret.length?ret:null}return ret};Components.prototype.isTagEventDeprecated=function(tagName,eventName){var event,stats,ret=null;if(event=this.getAnyTagEvent(tagName,eventName)){if(stats=event.status){stats.forEach(stat=>{if(!stat.type||stat.type===DEPRECATED){if(!ret){ret=[]}ret.push(stat)}})}}return ret};Components.prototype.getTagPropertyFromEvent=function(tagName,eventName){var o,ret;if(o=this.getTagEventName(tagName,eventName)){ret=o.name}return ret?ret:null};Components.prototype.isTagAttrTranslatable=function(tag,attr){var prop=this.getAnyTagProp(tag,attr);return prop&&prop.translatable};Components.prototype.isTagAttrReadOnly=function(tag,attr){var prop=this.getAnyTagProp(tag,attr);return prop&&prop.readonly};Components.prototype.isTagAttrWriteback=function(tag,attr){var prop=this.getAnyTagProp(tag,attr);return prop&&prop.writeback};Components.prototype.isTagProp=function(tagName,propName){return!!this.getTagProp(tagName,propName)};Components.prototype.isJetTagProp=function(tagName,propName){return!!this.getJetTagProp(tagName,propName)};Components.prototype.getTagProp=function(tagName,propName){var ret;if(this.isUserTag(tagName)){ret=this._getTagProp(tagName,propName,false)}return ret?ret:null};Components.prototype.getJetTagProp=function(tagName,propName){var ret;if(this.isJetCoreTag(tagName)){ret=this._getTagProp(tagName,propName,true)}return ret?ret:null};Components.prototype.getAnyTagProp=function(tagName,propName){return this._getTagProp(tagName,propName,true)||this._getTagProp(tagName,propName,false)};Components.prototype._getTagProp=function(tagName,propName,isOJC){var tag,props,list;tagName=_removeChevrons(tagName);if(isOJC){tag=this._jetTagLookup[tagName]}else{tag=this._tagLookup[tagName]||this._VCompLookup[tagName]};props=tag?tag[PROP_PROPS]:null;if(props){propName=propName.charAt(0)===":"?propName.substring(1):propName;if(this._curFileType!=="tsx"){propName=_propToCamelCase(propName)}}return props?props[propName]:null};Components.prototype.getTagPropType=function(tagName,propName){var prop,ret;if(prop=this.getTagProp(tagName,propName)){ret=prop?prop.type:undefined}return ret};Components.prototype.getAnyTagEvent=function(tag,event){return this._getTagEvent(tag,event,true)||this._getTagEvent(tag,event,false)};Components.prototype._getTagEvent=function(tagName,eventName,isOJC){var tagObj,events,event;if(!eventName.startsWith("on")){return null}tagName=_removeChevrons(tagName);if(isOJC){tagObj=this._jetTagLookup[tagName]}else{tagObj=this._tagLookup[tagName]||this._VCompLookup[tagName]}if(!tagObj){return null}if(!(events=tagObj[PROP_EVENTS])){return null}if(eventName.includes("-")){eventName=eventName.substring(3);eventName=_propToCamelCase(eventName)}else{eventName=eventName.substring(2)}event=events[eventName];return event?event:null};Components.prototype.getComponentPropMetadata=function(tagName,propName){var comp,sofar,props;tagName=_removeChevrons(tagName);if(!(comp=this._meta[tagName])||!(props=comp.properties)){return null}let subprops=propName.split(DOT);if(this._curFileType===FT_HTML){subprops.forEach((subprop,i,ar)=>{ar[i]=_propToCamelCase(subprop)})}if(subprops.length===1){return props[propName]||null}sofar=comp;let nextprop,i;for(i=0;i<subprops.length;i++){nextprop=subprops[i];if(sofar.hasOwnProperty(PROPERTIES)){sofar=sofar.properties[nextprop]||null;if(!sofar){break}}else{sofar=null;break}}return sofar};Components.prototype.getComponentMetadata=function(tag){return this._meta[tag]||null};Components.prototype.getAllCustomMetadata=function(){var name,comp,obj;var ret={};var i=2;var lookup=this._tagLookup;while(i){for(name in lookup){ret[name]=obj={};comp=lookup[name];obj.folder=comp.folder;obj.json=this.getComponentMetadata(name);if(i===1){obj.VCType=this._VTypes[name]}}i--;lookup=this._VCompLookup}return ret};Components.prototype.getJetTag=function(tag){var o;return(o=this._jetTagLookup[tag])?o:null};Components.prototype.getMaintenanceTags=function(){return this._maintenance};Components.prototype.isTagEvent=function(tagName,eventName){return!!this.getTagEventName(tagName,eventName)};Components.prototype.getTagEventName=function(tagName,eventName){var propName,tagObj,events,impls;tagObj=this._lookupTag(_removeChevrons(tagName));if(!tagObj||!eventName.startsWith("on")){return null}if(eventName.includes("-")){eventName=eventName.substring(3);eventName=_propToCamelCase(eventName)}else{eventName=eventName.substring(2)}if(tagObj.events&&tagObj.events[eventName]){return{type:"event",name:eventName}}if((impls=tagObj.implements)&&(impls.includes(DYNAMIC_FORM_ELEM)||impls.includes(DYNAMIC_TABLE_ELEM)||impls.includes(VB_FRAGMENT_ELEM))){return{type:"dynamic",name:eventName}}if(eventName.endsWith(CHANGED)&&tagObj.props){propName=eventName.replace(CHANGED,"");if(tagObj.props[propName]){return{type:"property",name:propName}};}return null};Components.prototype.isTagStyle=function(tag,style){var tagObj,ret=false;if(tagObj=this._lookupTag(_removeChevrons(tag))){let styles;if(styles=tagObj.styleClasses){ret=!!styles[style]}}return ret};Components.prototype.isJetStyle=function(style){var tag,ret=false;if(tag=this._styleLookup[style]){ret=!!this._jetTagLookup[tag]}return ret};Components.prototype.isStyle=function(style){return!!this._styleLookup[style]};Components.prototype.getStyleMetadata=function(style){var tag,styles,sc,ret=null;if(tag=this._styleLookup[style]){if(styles=this._tagLookup[tag].styleClasses){if(sc=styles[style]){ret={tag:tag,meta:sc}}}}return ret};Components.prototype.getStyleSelector=function(style){var sm=this.getStyleMetadata(style);return sm&&sm.meta?sm.meta.styleSelector:null};Components.prototype.hasTagSlotName=function(tagName,slotName){var o=this._lookupTag(_removeChevrons(tagName));return!!(o&&o.slots&&o.slots[slotName])};Components.prototype.getPreferredSlotContent=function(tag,slotName,impls){var o,slot,prefContent=null,comps=null,content;if(this._utils.hasAnyProps(impls)){if(o=this._lookupTag(_removeChevrons(tag))){if(o.slots){slotName=slotName?slotName:"";if(slot=o.slots[slotName]){if((prefContent=slot.preferredContent)&&prefContent.length){prefContent.forEach(impl=>{if(content=impls[impl]){if(!comps){comps=[]}comps.push(...content)}})}else{prefContent=null}}}}}return prefContent||comps?{interfaces:prefContent,components:comps}:null};Components.prototype.getTagSlotMetadata=function(tag,slot){var o,ret;if(o=this._lookupTag(_removeChevrons(tag))){if(o.slots){slot=slot?slot:"";if(slot=o.slots[slot]){ret=slot}}}return ret};Components.prototype.hasTagDynamicSlot=function(tag){var o,ret=false;if(o=this._lookupTag(_removeChevrons(tag))){ret=o.hasOwnProperty(PROP_DYNAMIC_SLOTS)}return ret};Components.prototype.hasTagAttrValues=function(tagName,attrName){var prop,ret=false;if((prop=this.getTagProp(tagName,attrName))||(prop=this.getJetTagProp(tagName,attrName))){ret=!!prop.enumValues}return ret};Components.prototype.isTagAttrValue=function(tagName,attrName,value){var prop,ret;if((prop=this.getTagProp(tagName,attrName))||(prop=this.getJetTagProp(tagName,attrName))){if(prop&&prop.enumValues){ret=prop.enumValues.indexOf(value)>=0}}return!!ret};Components.prototype.isTagAttrEnumDeprecated=function(tag,attr,val){var prop,stats,status,ret=null;if(prop=this.getAnyTagProp(tag,attr)){if(stats=prop.status){for(status of stats){if((!status.type||status.type===DEPRECATED)&&status.target===PROPERTY_VALUE){if(status.value&&status.value.includes(val)){ret={type:DEPRECATED};if(status.hasOwnProperty("target")){ret.target=status.target}if(status.hasOwnProperty("description")){ret.description=status.description}if(status.hasOwnProperty("since")){ret.since=status.since}if(status.hasOwnProperty("value")){ret.value=status.value}break}}}}}return ret};Components.prototype.isTagSupportedInTheme=function(tag,theme){var o,unsup,ret=true;if(o=this._lookupTag(tag)){if(unsup=o[PROP_UNSUP_THEME]){ret=!unsup.includes(theme)}}return ret};Components.prototype.isAttrSupportedInTheme=function(tag,attr,theme){var prop,unsup,ret=true;if(prop=this.getAnyTagProp(tag,attr)){if(unsup=prop[PROP_UNSUP_THEME]){ret=!unsup.includes(theme)}}return ret};Components.prototype.isTagPackPrivate=function(tag){var o,ret;if(o=this._lookupTag(_removeChevrons(tag))){ret=o[PROP_SUBCOMPONENT_TYPE]===PACK_PRIVATE}return ret};Components.prototype.getSubcomponentType=function(tag){var o,ret;if(o=this._lookupTag(_removeChevrons(tag))){ret=o[PROP_SUBCOMPONENT_TYPE]}return ret||null};Components.prototype.getRequiredProps=function(tagName){var tag,props,prop,propName,obj,ret=null;tagName=_removeChevrons(tagName);if(this._reqAttrs){let r=this._reqAttrs[tagName];if(r){return typeof r==="boolean"?null:r}}tag=this._lookupTag(tagName);if(tag&&tag.props){if(!this._reqAttrs){this._reqAttrs={}}if(!this._reqAttrs[tagName]){this._reqAttrs[tagName]=true}props=tag.props;for(propName in props){prop=props[propName];if(prop.required){if(!obj){obj=[]}obj.push(propName)}}}if(obj&&obj.length){let i,j,p;for(i=0;i<obj.length;i++){if(p=obj[i]){p+=".";for(j=i+1;j<obj.length;j++){if(obj[j].startsWith(p)){obj.splice(i,1);i--;break}}}}this._reqAttrs[tagName]=obj;ret=obj}return ret};Components.prototype.getRequiredAttrs=function(tagName){return this.getRequiredProps(tagName)};Components.prototype.getInterfaces=function(tag){var o,ret;if(o=this._lookupTag(_removeChevrons(tag))){ret=o.implements}return ret?ret:null};Components.prototype.getCount=function(){return this._count};Components.prototype.isTagStatus=function(tag,statType){return!!this._getTagStatus(tag,statType)};Components.prototype.getTagStatus=function(tag,statType){var ret=null,omitted=statType===undefined;var comp,arStat,stat,stType,i;if(comp=this._lookupTag(_removeChevrons(tag))){if(arStat=comp.status){for(i=0;i<arStat.length;i++){stat=arStat[i];stType=stat.type||DEPRECATED;if(omitted||stType===statType){if(!ret){ret=[]}ret.push(stat)}}}}return ret};Components.prototype.getPropStatus=function(tagName,propName,statType){let comp,arStat,ret;if(comp=this._lookupTag(_removeChevrons(tagName))){if(arStat=comp?.props[propName]?.status){let stat,stType,i,omitted=statType===undefined;for(i=0;i<arStat.length;i++){stat=arStat[i];stType=stat.type||DEPRECATED;if(omitted||stType===statType){if(!ret){ret=[]}ret.push(stat)}}}}return ret?ret:null};Components.prototype.isRuleIgnored=function(compName,ruleName){var ret,ar;if(ar=this._ignored[compName]){ret=ar.includes(ruleName)}return!!ret};Components.prototype.isOk=function(){return this._isOk};Components.prototype.setCurFileType=function(ft){this._curFileType=ft};Components.prototype._init=function(base,urls,filePaths,jetCore){if(this._isAMD){this._processJetCorePack();return}if(base){base=base.trim();if(base.charAt(base.length-1)!=="/"){base=base+"/"}}else{base=""}this._processFilePaths(filePaths);this._processUrls(base,urls);this._processJetCorePack();this._createStyleLookup();this._processJetCore(jetCore)};Components.prototype._processFilePaths=function(filePaths){var obj,compEntry,fpath,i,j;if(!filePaths){return}this._console("\nPre-processing user-declared web component metadata...");for(i=0;i<filePaths.length;i++){compEntry=filePaths[i];var dirStack=this._nd.glob.sync(compEntry);for(j=0;j<dirStack.length;j++){fpath=dirStack[j];if(this._runOpts.isDryRun||this._runOpts.isDebug){let msg="-".repeat(70)+"\n"+(this._runOpts.isDryRun?"* ":"")+"processing component path '"+fpath+"' ...";if(this._runOpts.isDryRun){console.log(msg)}else{this._debug(msg)}}if(fpath.toLowerCase().endsWith(".zip")){obj=this._compSvcs._extractComponentJsonFromZip(fpath);if(obj.obj){this.processComponentJson(obj.obj,fpath)}else if(obj.msg){this._error("Failed to parse component.json : "+obj.msg+" - "+fpath)}else if(obj.error){this._error("Failed to unzip '"+fpath+"'")}continue}if(this._isComponentJsonPath(fpath)){if(obj=this._readComponentJson(fpath)){if(obj.type&&obj.type==="pack"){continue}this.processComponentJson(obj,this._nd.path.dirname(fpath))}continue}this._recurse(fpath)}}if(this._isDebug){this._debug("-".repeat(70))}};Components.prototype._recurse=function(fpath){var dirs,inFile,obj,i;try{dirs=this._nd.fs.readdirSync(fpath);if(this._isDebug){this._debug(` processing ${fpath} ${dirs.length} component dirs ...`)}for(i=0;i<dirs.length;i++){inFile=dirs[i];if(inFile===COMPONENT_JSON){inFile=this._nd.path.join(fpath,COMPONENT_JSON);if(this._isDebug){this._debug(" processing "+inFile+"...")}obj=this._readComponentJson(inFile);if(obj){if(!obj.type||obj.type==="composite"){this.processComponentJson(obj,fpath)}}else{return}}var curPath=this._nd.path.join(fpath,inFile);if(this._fsUtils.getFileType(curPath)==="d"){this._recurse(curPath)}}}catch(e){this._error("Component check failed - "+e);this._isOk=false}};Components.prototype._processUrls=function(base,urls){var url,i;if(!urls){return}for(i=0;i<urls.length;i++){url=urls[i];if(this._runOpts.isDryRun||this._runOpts.isDebug){let msg;msg="-".repeat(70)+"\nprocessing URL '"+url+"'";if(this._runOpts.isDryRun){console.log(msg);continue}else{this._debug(msg)}}if(_isRelativeUrl(url)){url=base+url;if(_isRelativeUrl(url)){this._error("component URL incomplete - '"+url+"'");continue}}this._processUrl(url)}};Components.prototype._processUrl=function(url){var resp,obj,rc,tempFile,tmp;try{resp=this._compSvcs.loadUrl(url);if(resp.eCode==="ETIMEDOUT"){this._error("config.componentUrls - request timed-out for '"+url+"'");this._isOk=false;return}try{if(resp.type==="json"){if(resp.body){obj=JSON.parse(resp.body);if(!this.processComponentJson(obj,url)){this._isOk=false}}else{this._error("Server responded with "+resp.statusCode+" URL: '"+url+"'")}}else if(resp.type=="zip"){rc=this._compSvcs.writeZipBufferToFile(resp.body);if(typeof rc==="boolean"&&rc){tempFile=this._compSvcs.getLastZipFilePath();obj=this._compSvcs.extractComponentJsonFromZip(tempFile);if(obj.obj){this.processComponentJson(obj.obj,url)}else if(obj.msg){this._error("Failed to parse component.json : "+obj.msg+" - "+url)}else if(obj.error){this._error("Failed to unzip '"+url+"'")}this._compSvcs.deleteZipFile(tempFile)}else{this._error("Failed to create local temp zip file from URL '"+url+"' : rc.message");this._isOk=false}}else{tmp=typeof resp.type==="string"?resp.type:"?";this._error("Server responded with unexpected data ('"+tmp+"') : '"+url+"'");this._isOk=false}}catch(e){this._error("Invalid JSON - URL '"+url+"' : "+e);this._isOk=false}}catch(e1){this._error("URL access failed "+(e1.message.includes("ENOTFOUND")?"(NOT FOUND)":"")+" - URL '"+url+"'");this._isOk=false}};Components.prototype._processJetCorePack=function(){var comps,comp;if(comps=this._ojcPack.getComponents()){for(comp in comps){this.processComponentJson(comps[comp],"oj-c")}}};Components.prototype.processComponentJson=function(obj,fromLocation,vcomp){var comp,props,events,event,eventName,compName,metaObj;var isOJC;compName=obj.pack?obj.pack+"-"+obj.name:obj.name;isOJC=obj.pack===OJ_C;if(!this._isAMD){if(this._runOpts.isDryRun){console.log(" Would have processed '"+fromLocation+"'");return}if(obj.type&&obj.type==="pack"){return this._processJetPack(obj,fromLocation)}if(!isOJC&&!vcomp){if(!this._compSvcs.validateComponentJson(obj,fromLocation)){this._isOk=false;return false}}}if(this._lookupTag(compName)){this._jafMsg("jaf-sys-dup-component",`Ignoring duplicate component '${compName}' at '${fromLocation}'`,"W");return true}this._meta[compName]=obj;(isOJC?this._jetTagLookup:vcomp?this._VCompLookup:this._tagLookup)[compName]=comp={};comp[PROP_FOLDER]=fromLocation;comp[PROP_VERSION]=obj.version;if(obj.extension&&obj.extension.audit&&obj.extension.audit.ignore){let ar;if((ar=obj.extension.audit.ignore)&&ar.length){this._ignored[compName]=[...ar]}}if(obj.hasOwnProperty(PROP_SLOTS)){comp[PROP_SLOTS]=obj[PROP_SLOTS]}if(obj.hasOwnProperty(PROP_DYNAMIC_SLOTS)){comp[PROP_DYNAMIC_SLOTS]=obj[PROP_DYNAMIC_SLOTS]}if(obj.properties){comp[PROP_PROPS]=props={};this._extractProps(props,null,obj.properties,obj.name)}if(obj.events){comp[PROP_EVENTS]=events={};for(event in obj.events){events[event]=obj.events[event];metaObj=obj.events}}if(obj.implements){comp[PROP_IMPLEMENTS]=obj.implements;this._metaLib.processImplements(compName,obj.implements)}if(obj.status){let status,i;metaObj=obj.status;for(i=0;i<metaObj.length;i++){status=metaObj[i];if(status.type===MAINTENANCE){if(!this._maintenance){this._maintenance=new Set}this._maintenance.add(compName)}else if(status.type===SUPERSEDES){if(!this._supercedes){this._supersedes=new Set}this._supersedes.add(compName)}else if(status.type===ANTIPATTERN){if(!this._antiPattern){this._antiPattern=new Set}this._antiPattern.add(compName)}}}if(obj.extension&&obj.extension.theme&&obj.extension.theme.unsupportedThemes){comp[PROP_UNSUP_THEME]=obj.extension.theme.unsupportedThemes}if(obj.hasOwnProperty(PROP_SUBCOMPONENT_TYPE)){comp[PROP_SUBCOMPONENT_TYPE]=obj[PROP_SUBCOMPONENT_TYPE]}if(obj.hasOwnProperty(PROP_DEPENDENCIES)){comp[PROP_DEPENDENCIES]=obj[PROP_DEPENDENCIES]}if(obj.type){comp[PROP_TYPE]=obj.type}if(obj.pack){comp[PROP_PACK]=obj.pack}if(obj.hasOwnProperty("required")){comp[PROP_REQUIRED]=obj.required}if(obj.status){comp[PROP_STATUS]=obj.status}if(obj.styleClasses){comp[PROP_STYLECLASSES]=this._extractStyles(obj.styleClasses)}this._count++;return true};Components.prototype._extractProps=function(propObj,propSoFar,properties,name,rdonly){var prop,thisProp,soFar,obj;for(prop in properties){soFar=(propSoFar?propSoFar+DOT:"")+prop;propObj[soFar]=obj={};thisProp=properties[prop];if(thisProp.hasOwnProperty("enumValues")){if(Array.isArray(thisProp.enumValues)){obj.enumValues=thisProp.enumValues}else{this._error(`Web component '${name}' property '${soFar}' has invalid 'enumValues' in component.json`)}}if(thisProp.hasOwnProperty("status")){obj.status=thisProp.status}if(thisProp.hasOwnProperty("type")){obj.type=thisProp.type}if(thisProp.required){obj.required=true}if(thisProp.extension&&thisProp.extension.theme&&thisProp.extension.theme.unsupportedThemes){obj[PROP_UNSUP_THEME]=thisProp.extension.theme.unsupportedThemes}if(thisProp.hasOwnProperty("translatable")){obj.translatable=true}if(typeof thisProp.readOnly==="boolean"){obj.readOnly=thisProp.readOnly}else{if(rdonly){obj.readOnly=true}}if(thisProp.hasOwnProperty("writeback")){obj.writeback=thisProp.writeback}if(thisProp.hasOwnProperty("properties")){obj.properties=true;this._extractProps(propObj,soFar,thisProp.properties,name,obj.readOnly)}}};Components.prototype._extractStyles=function(styleClasses){var so,si,obj,ret={},i,j;if(!Array.isArray(styleClasses)){return ret}for(i=0;i<styleClasses.length;i++){so=styleClasses[i];if(so.kind==="class"){ret[so.name]=this._extractStyleClass(so)}else if(so.kind==="set"&&so.styleItems&&Array.isArray(so.styleItems)){ret[so.name]=obj={kind:"set"};if(so.status){obj.status=so.status}obj.styleClasses={};for(j=0;j<so.styleItems.length;j++){si=so.styleItems[j];obj.styleClasses[si.name]=this._extractStyleClass(si)}}else if(so.kind==="template"){}}return ret};Components.prototype._extractStyleClass=function(so){var obj={};if(so.styleSelector){obj.styleSelector=so.styleSelector}if(so.status){obj.status=so.status}return obj};Components.prototype._processJetPack=function(obj,fromLocation){var deps,dep,urlKey,depUrl,msg,i;if(this._runOpts.isDryRun||this._runOpts.isDebug){msg="processing JET Pack "+obj.name+" (version: "+obj.version+") : '"+fromLocation+"'";if(this._runOpts.isDryRun){console.log("* "+msg);return}else{this._debug(msg)}}if(!fromLocation.includes("http")){this._error("JET packs loaded via config 'components' property (file based) are currently not supported");return false}i=fromLocation.indexOf(obj.name);if(i>=0){urlKey=fromLocation.substring(0,i)}else{this._error("Cannot handle Jet Pack URL format to load dependencies : "+fromLocation)}deps=obj.dependencies;if(deps){for(dep in deps){depUrl=urlKey+dep+"/versions/"+obj.dependencies[dep]+"/content/component.json";if(this._isDebug){this._debug(` processing dependency ${dep} ${obj.dependencies[dep]}`)}this._processUrls("",[depUrl])}}return false};Components.prototype._processJetCore=function(jetCorePath){var files,file,obj,i;if(!jetCorePath){return}this._console("-".repeat(70)+"\nPerforming schema analysis on JET Core components (dt) using '"+this._compSvcs.getSchemaName()+"'...");try{files=this._nd.fs.readdirSync(jetCorePath);this._console(` processing ${files.length} $jetCore components...`);for(i=0;i<files.length;i++){file=files[i];if(file.endsWith(".json")){file=this._nd.path.join(jetCorePath,file);try{obj=this._readComponentJson(file);if(obj){this._compSvcs.validateComponentJson(obj,file)}}catch(e){}}}}catch(e1){this._error("!!! $JetCore Component check failed - "+e1)}this._console(" processing "+(files?files.length+" ":"")+"$jetCore components completed");this._console("-".repeat(70))};Components.prototype._initVComponents=function(){let precompileCache,tscript;const preComp=this._tsUtils.getPreCompiler();const preCompUtils=this._tsUtils.getUtils();const auditBase=this._fsUtils.toJAFPath(this._oConfig.getBase());const projectPathInfo=preCompUtils.getKeyPathInfo(auditBase);if((tscript=this._oConfig.getTypescript())&&tscript.compile&&projectPathInfo.tsSource){this._console("Pre-processing VComponents...");if(!(precompileCache=preComp.getPrecompileCache(auditBase,projectPathInfo.tsSource,projectPathInfo.componentRootFolder))){return}if(!this._fsUtils.pathExistsSync(precompileCache)){this._debug(`VComponents: precompileCache not created - ${precompileCache}`)}else{this._getVComponentJson(precompileCache)}}};Components.prototype._getVComponentJson=function(jsonDir){var contents;if(contents=this._fsUtils.readDirSync(jsonDir)){let json;this._VFilesInspected=[];this._VTypes={};contents.forEach(file=>{if(file.isFile){json=this._fsUtils.readJsonSync(this._nd.path.join(jsonDir,file.name),false,false);if(typeof json==="string"){this._error(`Compiled metadata for x - ${json}`)}else{if(this._isDebug){this._debug(`Post compilation VComponent found : ${json.name}`)}this.processComponentJson(json,this._getVCompFolder(json.name),true)}}});this._VFilesInspected=null}};Components.prototype._getVCompFolder=function(name){var files,file,folder,ret=null,x,_self=this;const preComp=this._tsUtils.getPreCompiler();const srcFiles=preComp.getVFiles();if(srcFiles){for(file of srcFiles){if(this._VFilesInspected.includes(file)){continue}let src,VType;function _fail(errMsg){_self._warn(`Unexpected read error of '${file}'`)}if(!(src=this._fsUtils.readFileSync(file,_fail))){continue}if(!(VType=this._isVCompSrc(src,name))){continue}this._VFilesInspected.push(file);this._VTypes[name]=VType;ret=this._nd.path.dirname(file);break}}return ret};Components.prototype._isVCompSrc=function(src,name){var ret,start=0,utils=this._utils;function _extractCompName(data,x,closeDelim){let x2,comp,match=false;if((x=utils.eatWhitespace(data,x))>=0){if(data.charAt(x)==="("){if((x=utils.eatWhitespace(data,x+1))>=0){if((x2=data.indexOf(closeDelim,x))>=0){comp=data.substring(x,x2).trim();comp=comp.substring(1,comp.length-1);match=comp===name}}}}return match}while(start<src.length){let i;if((i=src.indexOf(CUSTOM_ELEMENT,start))>=0){start=i+=CUSTOM_ELEMENT.length;if(ret=_extractCompName(src,i,")")){return"class"}continue}else if((i=src.indexOf(REGISTER_CUSTOM_ELEMENT,start))>=0){start=i+=REGISTER_CUSTOM_ELEMENT.length;if(ret=_extractCompName(src,i,",")){return"func"}continue}break}return null};Components.prototype._createStyleLookup=function(){var tag,o,scl,st;for(tag in this._tagLookup){o=this._tagLookup[tag];if(scl=o.styleClasses){for(st in scl){this._styleLookup[st]=tag}}}};Components.prototype._readComponentJson=function(inFile){var obj=null;if(this._isDebug){this._debug(` loading '${inFile}'`)}obj=this._nd.jsonLoader.load(inFile,this._nd,this._error,false,this._utils);if(!obj){this._isOk=false}return obj};Components.prototype._isComponentJsonPath=function(filePath){return filePath.toLowerCase().endsWith(COMPONENT_JSON)};Components.prototype.dumpComponentNames=function(){var names,keys;this._dumpComponentNames(this._tagLookup,"--------- Declared Web Components ---------","No valid user (non-VComponent) components declared!","-------- End Declared Web Components ---------");this._dumpComponentNames(this._VCompLookup,"--------- Discovered VComponents ---------","No VComponents found!","-------- End Discovered VComponents ---------");this._dumpComponentNames(this._jetTagLookup,"--------- Declared JET OJ-C Pack Web Components ---------","No valid user JET Core Pack components declared!","-------- End Declared OJ-C Pack Web Components ---------")};Components.prototype._dumpComponentNames=function(lookup,start,none,end){var keys,meta,impls;const INFO="[info]";keys=Object.keys(lookup);if(!keys.length){this._console(`${INFO} ${none}\n`,"I");return}this._console(`${INFO} ${start}`,"I");keys.forEach(key=>{meta=lookup[key];this._console(`${INFO} ${key} (${meta.version})`,"I");impls=meta.implements&&meta.implements.length?meta.implements.join(", "):"none declared";this._console(`${INFO} Impls: ${impls}`)});this._console(`${INFO} ${end}\n`,"I")};function _isTagStatusType(statType){return type===SUPERSEDES||type===MAINTENANCE||type===DEPRECATED||type===ANTIPATTERN};function _propToKebabCase(str){return str.replace(/([a-z0-9])([A-Z])/g,"$1-$2").replace(/([A-Z])([A-Z])(?=[a-z])/g,"$1-$2").toLowerCase()};function _propToCamelCase(str){var parts,i;function _camelCase(str){return str.replace(/(?:^\w|[A-Z]|\b\w)/g,function(word,index){return index==0?word.toLowerCase():word.toUpperCase()}).replace(/-|\s+/g,"")};parts=str.split(DOT);for(i=0;i<parts.length;i++){parts[i]=_camelCase(parts[i])}return parts.join(DOT)};function _isRelativeUrl(url){url=url.toLowerCase();return!(url.indexOf("http://")===0||url.indexOf("https://")===0)};function _removeChevrons(tagName){if(tagName){let len=tagName.length-1;let start=tagName.charAt(0)==="<"?1:0;let end=tagName.charAt(len)===">"?len:++len;tagName=tagName.substring(start,end)}return tagName};module.exports=Components;
|
|
6
|
+
"use strict";const COMPONENT_JSON="component.json";const PROPERTIES="properties";const PROP_SLOTS="slots";const PROP_DYNAMIC_SLOTS="dynamicSlots";const PROP_PROPS="props";const PROP_EVENTS="events";const PROP_STYLECLASSES="styleClasses";const PROP_IMPLEMENTS="implements";const PROP_REQUIRED="required";const PROP_FOLDER="folder";const PROP_VERSION="version";const PROP_UNSUP_THEME="unsupTheme";const PROP_STATUS="status";const PROP_SUBCOMPONENT_TYPE="subcomponentType";const PROP_DEPENDENCIES="dependencies";const PROP_TYPE="type";const PROP_PACK="pack";const PROPERTY_VALUE="propertyValue";const PROPERTY_TYPE="propertyType";const PACK_PRIVATE="packPrivate";const DEPRECATED="deprecated";const MAINTENANCE="maintenance";const SUPERSEDES="supersedes";const ANTIPATTERN="antiPattern";const DYNAMIC_FORM_ELEM="DynamicFormElement";const DYNAMIC_TABLE_ELEM="DynamicTableElement";const VB_FRAGMENT_ELEM="VbFragmentElement";const CUSTOM_ELEMENT="@customElement";const REGISTER_CUSTOM_ELEMENT="registerCustomElement";const OJ_C="oj-c";const DOT=".";const CHANGED="Changed";const FT_HTML="html";const FT_TSX="tsx";const REGXPR=/string|number|object|array|boolean|[\|.<>]/gi;function Components(nd,runMode,cwd,compSvcs,urlBase,urls,filePaths,metaLib,ojcPack,jetCore,runOpts,msgCtx,appCtx){this._nd=nd;this._tagLookup={};this._jetTagLookup={};this._VCompLookup={};this._styleLookup={};this._ignored={};this._maintenance=null;this._supersedes=null;this._antiPattern=null;this._meta={};this._path=null;this._reqAttrs=null;this._metaLib=metaLib;this._ojcPack=ojcPack;this._utils=appCtx.utils;this._fsUtils=appCtx.fsUtils;this._tsUtils=appCtx.tsUtils;this._curFileType=null;this._oConfig=appCtx.config;this._VFilesInspected=null;this._VTypes=null;this._compSvcs=compSvcs;this._isAMD=runMode==="amd";this._cwd=cwd;this._error=msgCtx.error;this._warn=msgCtx.warn;this._debug=msgCtx.debug;this._info=msgCtx.info;this._msg=msgCtx.msg;this._console=msgCtx.console;this._jafMsg=msgCtx.jafMsg;this._isDebug=msgCtx.isDebug;this._isVerbose=msgCtx.isVerbose;this._count=0;this._isOk=true;this._runOpts=runOpts;this._init(urlBase,urls,filePaths,jetCore);if(this._tsUtils){this._initVComponents()}};Components.prototype.isUserTag=function(tagName){var tag=_removeChevrons(tagName);return!!(this._tagLookup[tag]||this._VCompLookup[tag])};Components.prototype.isJetCoreTag=function(tagName){return!!this._jetTagLookup[_removeChevrons(tagName)]};Components.prototype.isVComponentTag=function(tagName){return!!this._VCompLookup[_removeChevrons(tagName)]};Components.prototype.isKnownTag=function(tagName){return!!this._lookupTag(tagName)};Components.prototype._lookupTag=function(tagName){tagName=_removeChevrons(tagName);return this._jetTagLookup[tagName]||this._tagLookup[tagName]||this._VCompLookup[tagName]};Components.prototype.isTagAttr=function(tagName,attrName){return this.isTagProp(tagName,attrName)||this.isJetTagProp(tagName,attrName)};Components.prototype.isJetTagAttr=function(tagName,attrName){return this.isJetTagProp(tagName,attrName)};Components.prototype.isTagDeprecated=function(tag){var comp,stats,status,ret=null;if(comp=this._lookupTag(_removeChevrons(tag))){if(stats=comp.status){for(status of stats){if((!status.type||status.type===DEPRECATED)&&!status.hasOwnProperty("target")){ret=status;if(ret.description){ret.description=this._utils.removeLink(ret.description)}break}}}}return ret};Components.prototype.isTagAttrDeprecated=function(tagName,attrName){var prop,status,stats,o,ret=null;if((prop=this.getAnyTagProp(tagName,attrName))&&(stats=prop.status)){ret=[];for(status of stats){if(!status.type||status.type===DEPRECATED){o={type:DEPRECATED};if(status.hasOwnProperty("target")){o.target=status.target}if(status.hasOwnProperty("description")){o.description=status.description}if(status.hasOwnProperty("since")){o.since=status.since}if(status.hasOwnProperty("value")){o.value=status.value}ret.push(o)}}ret=ret.length?ret:null}return ret};Components.prototype.isTagEventDeprecated=function(tagName,eventName){var event,stats,ret=null;if(event=this.getAnyTagEvent(tagName,eventName)){if(stats=event.status){stats.forEach(stat=>{if(!stat.type||stat.type===DEPRECATED){if(!ret){ret=[]}ret.push(stat)}})}}return ret};Components.prototype.getTagPropertyFromEvent=function(tagName,eventName){var o,ret;if(o=this.getTagEventName(tagName,eventName)){ret=o.name}return ret?ret:null};Components.prototype.isTagAttrTranslatable=function(tag,attr){var prop=this.getAnyTagProp(tag,attr);return prop&&prop.translatable};Components.prototype.isTagAttrReadOnly=function(tag,attr){var prop=this.getAnyTagProp(tag,attr);return prop&&prop.readonly};Components.prototype.isTagAttrWriteback=function(tag,attr){var prop=this.getAnyTagProp(tag,attr);return prop&&prop.writeback};Components.prototype.isTagProp=function(tagName,propName){return!!this.getTagProp(tagName,propName)};Components.prototype.isJetTagProp=function(tagName,propName){return!!this.getJetTagProp(tagName,propName)};Components.prototype.getTagProp=function(tagName,propName){var ret;if(this.isUserTag(tagName)){ret=this._getTagProp(tagName,propName,false)}return ret?ret:null};Components.prototype.getJetTagProp=function(tagName,propName){var ret;if(this.isJetCoreTag(tagName)){ret=this._getTagProp(tagName,propName,true)}return ret?ret:null};Components.prototype.getAnyTagProp=function(tagName,propName){return this._getTagProp(tagName,propName,true)||this._getTagProp(tagName,propName,false)};Components.prototype._getTagProp=function(tagName,propName,isOJC){var tag,props,list;tagName=_removeChevrons(tagName);if(isOJC){tag=this._jetTagLookup[tagName]}else{tag=this._tagLookup[tagName]||this._VCompLookup[tagName]};props=tag?tag[PROP_PROPS]:null;if(props){propName=propName.charAt(0)===":"?propName.substring(1):propName;if(this._curFileType!=="tsx"){propName=_propToCamelCase(propName)}}return props?props[propName]:null};Components.prototype.getTagPropType=function(tagName,propName){var prop,ret;if(prop=this.getTagProp(tagName,propName)){ret=prop?prop.type:undefined}return ret};Components.prototype.getAnyTagEvent=function(tag,event){return this._getTagEvent(tag,event,true)||this._getTagEvent(tag,event,false)};Components.prototype._getTagEvent=function(tagName,eventName,isOJC){var tagObj,events,event;if(!eventName.startsWith("on")){return null}tagName=_removeChevrons(tagName);if(isOJC){tagObj=this._jetTagLookup[tagName]}else{tagObj=this._tagLookup[tagName]||this._VCompLookup[tagName]}if(!tagObj){return null}if(!(events=tagObj[PROP_EVENTS])){return null}if(eventName.includes("-")){eventName=eventName.substring(3);eventName=_propToCamelCase(eventName)}else{eventName=eventName.substring(2)}event=events[eventName];return event?event:null};Components.prototype.getComponentPropMetadata=function(tagName,propName){var comp,sofar,props;tagName=_removeChevrons(tagName);if(!(comp=this._meta[tagName])||!(props=comp.properties)){return null}let subprops=propName.split(DOT);if(this._curFileType===FT_HTML){subprops.forEach((subprop,i,ar)=>{ar[i]=_propToCamelCase(subprop)})}if(subprops.length===1){return props[propName]||null}sofar=comp;let nextprop,i;for(i=0;i<subprops.length;i++){nextprop=subprops[i];if(sofar.hasOwnProperty(PROPERTIES)){sofar=sofar.properties[nextprop]||null;if(!sofar){break}}else{sofar=null;break}}return sofar};Components.prototype.getComponentMetadata=function(tag){return this._meta[tag]||null};Components.prototype.getAllCustomMetadata=function(){var name,comp,obj;var ret={};var i=2;var lookup=this._tagLookup;while(i){for(name in lookup){ret[name]=obj={};comp=lookup[name];obj.folder=comp.folder;obj.json=this.getComponentMetadata(name);if(i===1){obj.VCType=this._VTypes[name]}}i--;lookup=this._VCompLookup}return ret};Components.prototype.getJetTag=function(tag){var o;return(o=this._jetTagLookup[tag])?o:null};Components.prototype.getMaintenanceTags=function(){return this._maintenance};Components.prototype.isTagEvent=function(tagName,eventName){return!!this.getTagEventName(tagName,eventName)};Components.prototype.getTagEventName=function(tagName,eventName){var propName,tagObj,events,impls;tagObj=this._lookupTag(_removeChevrons(tagName));if(!tagObj||!eventName.startsWith("on")){return null}if(eventName.includes("-")){eventName=eventName.substring(3);eventName=_propToCamelCase(eventName)}else{eventName=eventName.substring(2)}if(tagObj.events&&tagObj.events[eventName]){return{type:"event",name:eventName}}if((impls=tagObj.implements)&&(impls.includes(DYNAMIC_FORM_ELEM)||impls.includes(DYNAMIC_TABLE_ELEM)||impls.includes(VB_FRAGMENT_ELEM))){return{type:"dynamic",name:eventName}}if(eventName.endsWith(CHANGED)&&tagObj.props){propName=eventName.replace(CHANGED,"");if(tagObj.props[propName]){return{type:"property",name:propName}};}return null};Components.prototype.isTagStyle=function(tag,style){var tagObj,ret=false;if(tagObj=this._lookupTag(_removeChevrons(tag))){let styles;if(styles=tagObj.styleClasses){ret=!!styles[style]}}return ret};Components.prototype.isJetStyle=function(style){var tag,ret=false;if(tag=this._styleLookup[style]){ret=!!this._jetTagLookup[tag]}return ret};Components.prototype.isStyle=function(style){return!!this._styleLookup[style]};Components.prototype.getStyleMetadata=function(style){var tag,styles,sc,ret=null;if(tag=this._styleLookup[style]){if(styles=this._tagLookup[tag].styleClasses){if(sc=styles[style]){ret={tag:tag,meta:sc}}}}return ret};Components.prototype.getStyleSelector=function(style){var sm=this.getStyleMetadata(style);return sm&&sm.meta?sm.meta.styleSelector:null};Components.prototype.hasTagSlotName=function(tagName,slotName){var o=this._lookupTag(_removeChevrons(tagName));return!!(o&&o.slots&&o.slots[slotName])};Components.prototype.getPreferredSlotContent=function(tag,slotName,impls){var o,slot,prefContent=null,comps=null,content;if(this._utils.hasAnyProps(impls)){if(o=this._lookupTag(_removeChevrons(tag))){if(o.slots){slotName=slotName?slotName:"";if(slot=o.slots[slotName]){if((prefContent=slot.preferredContent)&&prefContent.length){prefContent.forEach(impl=>{if(content=impls[impl]){if(!comps){comps=[]}comps.push(...content)}})}else{prefContent=null}}}}}return prefContent||comps?{interfaces:prefContent,components:comps}:null};Components.prototype.getTagSlotMetadata=function(tag,slot){var o,ret;if(o=this._lookupTag(_removeChevrons(tag))){if(o.slots){slot=slot?slot:"";if(slot=o.slots[slot]){ret=slot}}}return ret};Components.prototype.hasTagDynamicSlot=function(tag){var o,ret=false;if(o=this._lookupTag(_removeChevrons(tag))){ret=o.hasOwnProperty(PROP_DYNAMIC_SLOTS)}return ret};Components.prototype.hasTagAttrValues=function(tagName,attrName){var prop,ret=false;if((prop=this.getTagProp(tagName,attrName))||(prop=this.getJetTagProp(tagName,attrName))){ret=!!prop.enumValues}return ret};Components.prototype.isTagAttrValue=function(tagName,attrName,value){var prop,ret;if((prop=this.getTagProp(tagName,attrName))||(prop=this.getJetTagProp(tagName,attrName))){if(prop&&prop.enumValues){ret=prop.enumValues.indexOf(value)>=0}}return!!ret};Components.prototype.isTagAttrEnumDeprecated=function(tag,attr,val){var prop,stats,status,ret=null;if(prop=this.getAnyTagProp(tag,attr)){if(stats=prop.status){for(status of stats){if((!status.type||status.type===DEPRECATED)&&status.target===PROPERTY_VALUE){if(status.value&&status.value.includes(val)){ret={type:DEPRECATED};if(status.hasOwnProperty("target")){ret.target=status.target}if(status.hasOwnProperty("description")){ret.description=status.description}if(status.hasOwnProperty("since")){ret.since=status.since}if(status.hasOwnProperty("value")){ret.value=status.value}break}}}}}return ret};Components.prototype.isTagSupportedInTheme=function(tag,theme){var o,unsup,ret=true;if(o=this._lookupTag(tag)){if(unsup=o[PROP_UNSUP_THEME]){ret=!unsup.includes(theme)}}return ret};Components.prototype.isAttrSupportedInTheme=function(tag,attr,theme){var prop,unsup,ret=true;if(prop=this.getAnyTagProp(tag,attr)){if(unsup=prop[PROP_UNSUP_THEME]){ret=!unsup.includes(theme)}}return ret};Components.prototype.isTagPackPrivate=function(tag){var o,ret;if(o=this._lookupTag(_removeChevrons(tag))){ret=o[PROP_SUBCOMPONENT_TYPE]===PACK_PRIVATE}return ret};Components.prototype.getSubcomponentType=function(tag){var o,ret;if(o=this._lookupTag(_removeChevrons(tag))){ret=o[PROP_SUBCOMPONENT_TYPE]}return ret||null};Components.prototype.getRequiredProps=function(tagName){var tag,props,prop,propName,obj,ret=null;tagName=_removeChevrons(tagName);if(this._reqAttrs){let r=this._reqAttrs[tagName];if(r){return typeof r==="boolean"?null:r}}tag=this._lookupTag(tagName);if(tag&&tag.props){if(!this._reqAttrs){this._reqAttrs={}}if(!this._reqAttrs[tagName]){this._reqAttrs[tagName]=true}props=tag.props;for(propName in props){prop=props[propName];if(prop.required){if(!obj){obj=[]}obj.push(propName)}}}if(obj&&obj.length){let i,j,p;for(i=0;i<obj.length;i++){if(p=obj[i]){p+=".";for(j=i+1;j<obj.length;j++){if(obj[j].startsWith(p)){obj.splice(i,1);i--;break}}}}this._reqAttrs[tagName]=obj;ret=obj}return ret};Components.prototype.getRequiredAttrs=function(tagName){return this.getRequiredProps(tagName)};Components.prototype.getInterfaces=function(tag){var o,ret;if(o=this._lookupTag(_removeChevrons(tag))){ret=o.implements}return ret?ret:null};Components.prototype.getCount=function(){return this._count};Components.prototype.isTagStatus=function(tag,statType){return!!this._getTagStatus(tag,statType)};Components.prototype.getTagStatus=function(tag,statType){var ret=null,omitted=statType===undefined;var comp,arStat,stat,stType,i;if(comp=this._lookupTag(_removeChevrons(tag))){if(arStat=comp.status){for(i=0;i<arStat.length;i++){stat=arStat[i];stType=stat.type||DEPRECATED;if(omitted||stType===statType){if(!ret){ret=[]}ret.push(stat)}}}}return ret};Components.prototype.getPropStatus=function(tagName,propName,statType){let comp,arStat,ret;if(comp=this._lookupTag(_removeChevrons(tagName))){if(comp.props&&(arStat=comp.props[propName]?.status)){let stat,stType,i,omitted=statType===undefined;for(i=0;i<arStat.length;i++){stat=arStat[i];stType=stat.type||DEPRECATED;if(omitted||stType===statType){if(!ret){ret=[]}ret.push(stat)}}}}return ret?ret:null};Components.prototype.isRuleIgnored=function(compName,ruleName){var ret,ar;if(ar=this._ignored[compName]){ret=ar.includes(ruleName)}return!!ret};Components.prototype.isOk=function(){return this._isOk};Components.prototype.setCurFileType=function(ft){this._curFileType=ft};Components.prototype._init=function(base,urls,filePaths,jetCore){if(this._isAMD){this._processJetCorePack();return}if(base){base=base.trim();if(base.charAt(base.length-1)!=="/"){base=base+"/"}}else{base=""}this._processFilePaths(filePaths);this._processUrls(base,urls);this._processJetCorePack();this._createStyleLookup();this._processJetCore(jetCore)};Components.prototype._processFilePaths=function(filePaths){var obj,compEntry,fpath,i,j;if(!filePaths){return}this._console("\nPre-processing user-declared web component metadata...");for(i=0;i<filePaths.length;i++){compEntry=filePaths[i];var dirStack=this._nd.glob.sync(compEntry);for(j=0;j<dirStack.length;j++){fpath=dirStack[j];if(this._runOpts.isDryRun||this._runOpts.isDebug){let msg="-".repeat(70)+"\n"+(this._runOpts.isDryRun?"* ":"")+"processing component path '"+fpath+"' ...";if(this._runOpts.isDryRun){console.log(msg)}else{this._debug(msg)}}if(fpath.toLowerCase().endsWith(".zip")){obj=this._compSvcs._extractComponentJsonFromZip(fpath);if(obj.obj){this.processComponentJson(obj.obj,fpath)}else if(obj.msg){this._error("Failed to parse component.json : "+obj.msg+" - "+fpath)}else if(obj.error){this._error("Failed to unzip '"+fpath+"'")}continue}if(this._isComponentJsonPath(fpath)){if(obj=this._readComponentJson(fpath)){if(obj.type&&obj.type==="pack"){continue}this.processComponentJson(obj,this._nd.path.dirname(fpath))}continue}this._recurse(fpath)}}if(this._isDebug){this._debug("-".repeat(70))}};Components.prototype._recurse=function(fpath){var dirs,inFile,obj,i;try{dirs=this._nd.fs.readdirSync(fpath);if(this._isDebug){this._debug(` processing ${fpath} ${dirs.length} component dirs ...`)}for(i=0;i<dirs.length;i++){inFile=dirs[i];if(inFile===COMPONENT_JSON){inFile=this._nd.path.join(fpath,COMPONENT_JSON);if(this._isDebug){this._debug(" processing "+inFile+"...")}obj=this._readComponentJson(inFile);if(obj){if(!obj.type||obj.type==="composite"){this.processComponentJson(obj,fpath)}}else{return}}var curPath=this._nd.path.join(fpath,inFile);if(this._fsUtils.getFileType(curPath)==="d"){this._recurse(curPath)}}}catch(e){this._error("Component check failed - "+e);this._isOk=false}};Components.prototype._processUrls=function(base,urls){var url,i;if(!urls){return}for(i=0;i<urls.length;i++){url=urls[i];if(this._runOpts.isDryRun||this._runOpts.isDebug){let msg;msg="-".repeat(70)+"\nprocessing URL '"+url+"'";if(this._runOpts.isDryRun){console.log(msg);continue}else{this._debug(msg)}}if(_isRelativeUrl(url)){url=base+url;if(_isRelativeUrl(url)){this._error("component URL incomplete - '"+url+"'");continue}}this._processUrl(url)}};Components.prototype._processUrl=function(url){var resp,obj,rc,tempFile,tmp;try{resp=this._compSvcs.loadUrl(url);if(resp.eCode==="ETIMEDOUT"){this._error("config.componentUrls - request timed-out for '"+url+"'");this._isOk=false;return}try{if(resp.type==="json"){if(resp.body){obj=JSON.parse(resp.body);if(!this.processComponentJson(obj,url)){this._isOk=false}}else{this._error("Server responded with "+resp.statusCode+" URL: '"+url+"'")}}else if(resp.type=="zip"){rc=this._compSvcs.writeZipBufferToFile(resp.body);if(typeof rc==="boolean"&&rc){tempFile=this._compSvcs.getLastZipFilePath();obj=this._compSvcs.extractComponentJsonFromZip(tempFile);if(obj.obj){this.processComponentJson(obj.obj,url)}else if(obj.msg){this._error("Failed to parse component.json : "+obj.msg+" - "+url)}else if(obj.error){this._error("Failed to unzip '"+url+"'")}this._compSvcs.deleteZipFile(tempFile)}else{this._error("Failed to create local temp zip file from URL '"+url+"' : rc.message");this._isOk=false}}else{tmp=typeof resp.type==="string"?resp.type:"?";this._error("Server responded with unexpected data ('"+tmp+"') : '"+url+"'");this._isOk=false}}catch(e){this._error("Invalid JSON - URL '"+url+"' : "+e);this._isOk=false}}catch(e1){this._error("URL access failed "+(e1.message.includes("ENOTFOUND")?"(NOT FOUND)":"")+" - URL '"+url+"'");this._isOk=false}};Components.prototype._processJetCorePack=function(){var comps,comp;if(comps=this._ojcPack.getComponents()){for(comp in comps){this.processComponentJson(comps[comp],"oj-c")}}};Components.prototype.processComponentJson=function(obj,fromLocation,vcomp){var comp,props,events,event,eventName,compName,metaObj;var isOJC;compName=obj.pack?obj.pack+"-"+obj.name:obj.name;isOJC=obj.pack===OJ_C;if(!this._isAMD){if(this._runOpts.isDryRun){console.log(" Would have processed '"+fromLocation+"'");return}if(obj.type&&obj.type==="pack"){return this._processJetPack(obj,fromLocation)}if(!isOJC&&!vcomp){if(!this._compSvcs.validateComponentJson(obj,fromLocation)){this._isOk=false;return false}}}if(this._lookupTag(compName)){this._jafMsg("jaf-sys-dup-component",`Ignoring duplicate component '${compName}' at '${fromLocation}'`,"W");return true}this._meta[compName]=obj;(isOJC?this._jetTagLookup:vcomp?this._VCompLookup:this._tagLookup)[compName]=comp={};comp[PROP_FOLDER]=fromLocation;comp[PROP_VERSION]=obj.version;if(obj.extension&&obj.extension.audit&&obj.extension.audit.ignore){let ar;if((ar=obj.extension.audit.ignore)&&ar.length){this._ignored[compName]=[...ar]}}if(obj.hasOwnProperty(PROP_SLOTS)){comp[PROP_SLOTS]=obj[PROP_SLOTS]}if(obj.hasOwnProperty(PROP_DYNAMIC_SLOTS)){comp[PROP_DYNAMIC_SLOTS]=obj[PROP_DYNAMIC_SLOTS]}if(obj.properties){comp[PROP_PROPS]=props={};this._extractProps(props,null,obj.properties,obj.name)}if(obj.events){comp[PROP_EVENTS]=events={};for(event in obj.events){events[event]=obj.events[event];metaObj=obj.events}}if(obj.implements){comp[PROP_IMPLEMENTS]=obj.implements;this._metaLib.processImplements(compName,obj.implements)}if(obj.status){let status,i;metaObj=obj.status;for(i=0;i<metaObj.length;i++){status=metaObj[i];if(status.type===MAINTENANCE){if(!this._maintenance){this._maintenance=new Set}this._maintenance.add(compName)}else if(status.type===SUPERSEDES){if(!this._supercedes){this._supersedes=new Set}this._supersedes.add(compName)}else if(status.type===ANTIPATTERN){if(!this._antiPattern){this._antiPattern=new Set}this._antiPattern.add(compName)}}}if(obj.extension&&obj.extension.theme&&obj.extension.theme.unsupportedThemes){comp[PROP_UNSUP_THEME]=obj.extension.theme.unsupportedThemes}if(obj.hasOwnProperty(PROP_SUBCOMPONENT_TYPE)){comp[PROP_SUBCOMPONENT_TYPE]=obj[PROP_SUBCOMPONENT_TYPE]}if(obj.hasOwnProperty(PROP_DEPENDENCIES)){comp[PROP_DEPENDENCIES]=obj[PROP_DEPENDENCIES]}if(obj.type){comp[PROP_TYPE]=obj.type}if(obj.pack){comp[PROP_PACK]=obj.pack}if(obj.hasOwnProperty("required")){comp[PROP_REQUIRED]=obj.required}if(obj.status){comp[PROP_STATUS]=obj.status}if(obj.styleClasses){comp[PROP_STYLECLASSES]=this._extractStyles(obj.styleClasses)}this._count++;return true};Components.prototype._extractProps=function(propObj,propSoFar,properties,name,rdonly){var prop,thisProp,soFar,obj;for(prop in properties){soFar=(propSoFar?propSoFar+DOT:"")+prop;propObj[soFar]=obj={};thisProp=properties[prop];if(thisProp.hasOwnProperty("enumValues")){if(Array.isArray(thisProp.enumValues)){obj.enumValues=thisProp.enumValues}else{this._error(`Web component '${name}' property '${soFar}' has invalid 'enumValues' in component.json`)}}if(thisProp.hasOwnProperty("status")){obj.status=thisProp.status}if(thisProp.hasOwnProperty("type")){obj.type=thisProp.type}if(thisProp.required){obj.required=true}if(thisProp.extension&&thisProp.extension.theme&&thisProp.extension.theme.unsupportedThemes){obj[PROP_UNSUP_THEME]=thisProp.extension.theme.unsupportedThemes}if(thisProp.hasOwnProperty("translatable")){obj.translatable=true}if(typeof thisProp.readOnly==="boolean"){obj.readOnly=thisProp.readOnly}else{if(rdonly){obj.readOnly=true}}if(thisProp.hasOwnProperty("writeback")){obj.writeback=thisProp.writeback}if(thisProp.hasOwnProperty("properties")){obj.properties=true;this._extractProps(propObj,soFar,thisProp.properties,name,obj.readOnly)}}};Components.prototype._extractStyles=function(styleClasses){var so,si,obj,ret={},i,j;if(!Array.isArray(styleClasses)){return ret}for(i=0;i<styleClasses.length;i++){so=styleClasses[i];if(so.kind==="class"){ret[so.name]=this._extractStyleClass(so)}else if(so.kind==="set"&&so.styleItems&&Array.isArray(so.styleItems)){ret[so.name]=obj={kind:"set"};if(so.status){obj.status=so.status}obj.styleClasses={};for(j=0;j<so.styleItems.length;j++){si=so.styleItems[j];obj.styleClasses[si.name]=this._extractStyleClass(si)}}else if(so.kind==="template"){}}return ret};Components.prototype._extractStyleClass=function(so){var obj={};if(so.styleSelector){obj.styleSelector=so.styleSelector}if(so.status){obj.status=so.status}return obj};Components.prototype._processJetPack=function(obj,fromLocation){var deps,dep,urlKey,depUrl,msg,i;if(this._runOpts.isDryRun||this._runOpts.isDebug){msg="processing JET Pack "+obj.name+" (version: "+obj.version+") : '"+fromLocation+"'";if(this._runOpts.isDryRun){console.log("* "+msg);return}else{this._debug(msg)}}if(!fromLocation.includes("http")){this._error("JET packs loaded via config 'components' property (file based) are currently not supported");return false}i=fromLocation.indexOf(obj.name);if(i>=0){urlKey=fromLocation.substring(0,i)}else{this._error("Cannot handle Jet Pack URL format to load dependencies : "+fromLocation)}deps=obj.dependencies;if(deps){for(dep in deps){depUrl=urlKey+dep+"/versions/"+obj.dependencies[dep]+"/content/component.json";if(this._isDebug){this._debug(` processing dependency ${dep} ${obj.dependencies[dep]}`)}this._processUrls("",[depUrl])}}return false};Components.prototype._processJetCore=function(jetCorePath){var files,file,obj,i;if(!jetCorePath){return}this._console("-".repeat(70)+"\nPerforming schema analysis on JET Core components (dt) using '"+this._compSvcs.getSchemaName()+"'...");try{files=this._nd.fs.readdirSync(jetCorePath);this._console(` processing ${files.length} $jetCore components...`);for(i=0;i<files.length;i++){file=files[i];if(file.endsWith(".json")){file=this._nd.path.join(jetCorePath,file);try{obj=this._readComponentJson(file);if(obj){this._compSvcs.validateComponentJson(obj,file)}}catch(e){}}}}catch(e1){this._error("!!! $JetCore Component check failed - "+e1)}this._console(" processing "+(files?files.length+" ":"")+"$jetCore components completed");this._console("-".repeat(70))};Components.prototype._initVComponents=function(){let precompileCache,tscript;const preComp=this._tsUtils.getPreCompiler();const preCompUtils=this._tsUtils.getUtils();const auditBase=this._fsUtils.toJAFPath(this._oConfig.getBase());const projectPathInfo=preCompUtils.getKeyPathInfo(auditBase);if((tscript=this._oConfig.getTypescript())&&tscript.compile&&projectPathInfo.tsSource){this._console("Pre-processing VComponents...");if(!(precompileCache=preComp.getPrecompileCache(auditBase,projectPathInfo.tsSource,projectPathInfo.componentRootFolder))){return}if(!this._fsUtils.pathExistsSync(precompileCache)){this._debug(`VComponents: precompileCache not created - ${precompileCache}`)}else{this._getVComponentJson(precompileCache)}}};Components.prototype._getVComponentJson=function(jsonDir){var contents;if(contents=this._fsUtils.readDirSync(jsonDir)){let json;this._VFilesInspected=[];this._VTypes={};contents.forEach(file=>{if(file.isFile){json=this._fsUtils.readJsonSync(this._nd.path.join(jsonDir,file.name),false,false);if(typeof json==="string"){this._error(`Compiled metadata for x - ${json}`)}else{if(this._isDebug){this._debug(`Post compilation VComponent found : ${json.name}`)}this.processComponentJson(json,this._getVCompFolder(json.name),true)}}});this._VFilesInspected=null}};Components.prototype._getVCompFolder=function(name){var files,file,folder,ret=null,x,_self=this;const preComp=this._tsUtils.getPreCompiler();const srcFiles=preComp.getVFiles();if(srcFiles){for(file of srcFiles){if(this._VFilesInspected.includes(file)){continue}let src,VType;function _fail(errMsg){_self._warn(`Unexpected read error of '${file}'`)}if(!(src=this._fsUtils.readFileSync(file,_fail))){continue}if(!(VType=this._isVCompSrc(src,name))){continue}this._VFilesInspected.push(file);this._VTypes[name]=VType;ret=this._nd.path.dirname(file);break}}return ret};Components.prototype._isVCompSrc=function(src,name){var ret,start=0,utils=this._utils;function _extractCompName(data,x,closeDelim){let x2,comp,match=false;if((x=utils.eatWhitespace(data,x))>=0){if(data.charAt(x)==="("){if((x=utils.eatWhitespace(data,x+1))>=0){if((x2=data.indexOf(closeDelim,x))>=0){comp=data.substring(x,x2).trim();comp=comp.substring(1,comp.length-1);match=comp===name}}}}return match}while(start<src.length){let i;if((i=src.indexOf(CUSTOM_ELEMENT,start))>=0){start=i+=CUSTOM_ELEMENT.length;if(ret=_extractCompName(src,i,")")){return"class"}continue}else if((i=src.indexOf(REGISTER_CUSTOM_ELEMENT,start))>=0){start=i+=REGISTER_CUSTOM_ELEMENT.length;if(ret=_extractCompName(src,i,",")){return"func"}continue}break}return null};Components.prototype._createStyleLookup=function(){var tag,o,scl,st;for(tag in this._tagLookup){o=this._tagLookup[tag];if(scl=o.styleClasses){for(st in scl){this._styleLookup[st]=tag}}}};Components.prototype._readComponentJson=function(inFile){var obj=null;if(this._isDebug){this._debug(` loading '${inFile}'`)}obj=this._nd.jsonLoader.load(inFile,this._nd,this._error,false,this._utils);if(!obj){this._isOk=false}return obj};Components.prototype._isComponentJsonPath=function(filePath){return filePath.toLowerCase().endsWith(COMPONENT_JSON)};Components.prototype.dumpComponentNames=function(){var names,keys;this._dumpComponentNames(this._tagLookup,"--------- Declared Web Components ---------","No valid user (non-VComponent) components declared!","-------- End Declared Web Components ---------");this._dumpComponentNames(this._VCompLookup,"--------- Discovered VComponents ---------","No VComponents found!","-------- End Discovered VComponents ---------");this._dumpComponentNames(this._jetTagLookup,"--------- Declared JET OJ-C Pack Web Components ---------","No valid user JET Core Pack components declared!","-------- End Declared OJ-C Pack Web Components ---------")};Components.prototype._dumpComponentNames=function(lookup,start,none,end){var keys,meta,impls;const INFO="[info]";keys=Object.keys(lookup);if(!keys.length){this._console(`${INFO} ${none}\n`,"I");return}this._console(`${INFO} ${start}`,"I");keys.forEach(key=>{meta=lookup[key];this._console(`${INFO} ${key} (${meta.version})`,"I");impls=meta.implements&&meta.implements.length?meta.implements.join(", "):"none declared";this._console(`${INFO} Impls: ${impls}`)});this._console(`${INFO} ${end}\n`,"I")};function _isTagStatusType(statType){return type===SUPERSEDES||type===MAINTENANCE||type===DEPRECATED||type===ANTIPATTERN};function _propToKebabCase(str){return str.replace(/([a-z0-9])([A-Z])/g,"$1-$2").replace(/([A-Z])([A-Z])(?=[a-z])/g,"$1-$2").toLowerCase()};function _propToCamelCase(str){var parts,i;function _camelCase(str){return str.replace(/(?:^\w|[A-Z]|\b\w)/g,function(word,index){return index==0?word.toLowerCase():word.toUpperCase()}).replace(/-|\s+/g,"")};parts=str.split(DOT);for(i=0;i<parts.length;i++){parts[i]=_camelCase(parts[i])}return parts.join(DOT)};function _isRelativeUrl(url){url=url.toLowerCase();return!(url.indexOf("http://")===0||url.indexOf("https://")===0)};function _removeChevrons(tagName){if(tagName){let len=tagName.length-1;let start=tagName.charAt(0)==="<"?1:0;let end=tagName.charAt(len)===">"?len:++len;tagName=tagName.substring(start,end)}return tagName};module.exports=Components;
|
package/lib/Config.js
CHANGED
|
@@ -3,4 +3,4 @@
|
|
|
3
3
|
* Licensed under The Universal Permissive License (UPL), Version 1.0
|
|
4
4
|
* as shown at https://oss.oracle.com/licenses/upl/
|
|
5
5
|
*/
|
|
6
|
-
const Helper=require("./ConfigLib");const MACROS=require("../lib/macros");const DEFAULTS=require("./defaults");var JET_VERSIONS;const TYPE_BOOLEAN="boolean";const AT_INCLUDE="@include(";const QUOTE="\"";const TSCONFIG="tsconfig.json";var Config=function(nd,base,iniPath,fnApplyMacros,rules,severity,cliGroups,cliSev,msgCtx,modeCtx,utils,fsUtils,cbDebug){this._path=iniPath;this._dir=null;this._config=null;this._tsCfgObj=null;this._preBuilt=false;this._isOJET=modeCtx.isOJET;this._isCLI=modeCtx.isCLI;this._isAPI=modeCtx.isAPI;this._isAMD=modeCtx.isAMD;this._isCliMode=modeCtx.isCLI||modeCtx.isOJETCLI;this._rules=rules;this._utils=utils;this._fsUtils=fsUtils;this._severity=severity;this._helper=new Helper(this,nd,severity,utils,fsUtils,msgCtx,modeCtx);this.applyMacros=fnApplyMacros;this._bErrors=false;this._console=msgCtx.console;this._error=msgCtx.error;this._warn=msgCtx.warn;this._info=msgCtx.info;this._debug=msgCtx.debug;this._isDebug=msgCtx.isDebug;this._isVerbose=msgCtx.isVerbose;JET_VERSIONS=nd.jetver.getVersions();this._cliGroups=cliGroups;this._cliSev=cliSev;this._nd=nd;if(iniPath){this._init(base,iniPath,cbDebug)}};Config.prototype.getConfig=function(){var tmp=JSON.parse(JSON.stringify(this._config));if(tmp._sev){delete tmp._sev}return tmp};Config.prototype.getFiles=function(){return this._config.files};Config.prototype.getExclude=function(){return this._config.exclude};Config.prototype.getOptions=function(){return this._config.options};Config.prototype.getJetVer=function(){return this._config.jetVer};Config.prototype.getComponentsBaseUrl=function(){return this._config.componentsBaseUrl};Config.prototype.getComponentsBase=function(){return this._config.componentsBase};Config.prototype.getComponents=function(){return this._config.components};Config.prototype.getComponentUrls=function(){return this._config.componentUrls};Config.prototype.getJetCorePack=function(){return this._config.jetCorePack};Config.prototype.getComponentOptions=function(){return this._config.componentOptions};Config.prototype.getTypescript=function(){return this._config.typescript};Config.prototype.getTsConfig=function(){var ret;if(this._config.typescript){ret=this._config.typescript.tsconfig}return ret};Config.prototype.getMarkdownOptions=function(){return this._config.markdownOptions};Config.prototype.getTsConfigObj=function(){return this._tsCfgObj};Config.prototype.getOutPath=function(){return this._config.outPath};Config.prototype.getRulePacks=function(){return this._config.rulePacks};Config.prototype.getRuleMods=function(){return this._config.ruleMods};Config.prototype.getEnable=function(){return this._config.ruleMods&&this._config.ruleMods.enable?this._config.ruleMods.enable:undefined};Config.prototype.getDisable=function(){return this._config.ruleMods&&this._config.ruleMods.disable?this._config.ruleMods.disable:undefined};Config.prototype.getRuleDescriptions=function(){return this._config.ruleDescriptions};Config.prototype.getRulesFired=function(){return this._config.rulesFired};Config.prototype.getGroups=function(){return this._config.groups};Config.prototype.setGroups=function(groups){this._config.groups=groups};Config.prototype.getDefGroups=function(){return this._config.defGroups};Config.prototype.getRunRuleNames=function(){return this._config.ruleNames};Config.prototype.isBuiltinJetRules=function(){return this._config.builtinJetRules};Config.prototype.isBuiltinCspRules=function(){return this._config.builtinCspRules};Config.prototype.isBuiltinJetWcRules=function(){return this._config.builtinJetWcRules};Config.prototype.isBuiltinJetWcOracleRules=function(){return this._config.builtinJetWcOracleRules};Config.prototype.isBuiltinSpocRules=function(){return this._config.builtinSpocRules};Config.prototype.isBuiltinOjcMigrationRules=function(){return this._config.builtinOjcMigrationRules};Config.prototype.isBuiltinWebDriverTestRules=function(){return this._config.builtinWebDriverTestRules};Config.prototype.getMessages=function(){return this._config.messages};Config.prototype.setMessages=function(msgid,state){return this._helper.setMessages(msgid,state)};Config.prototype.getFollowLinks=function(){return this._config.followLinks};Config.prototype.getFormat=function(){return this._config.format};Config.prototype.getProseFormat=function(){return this._config.proseFormat};Config.prototype.getLineFormat=function(){return this._config.lineFormat};Config.prototype.getBase=function(){return this._config.base};Config.prototype.getStylesets=function(){return this._config.stylesets};Config.prototype.getNameSpaces=function(){return this._config.nameSpaces};Config.prototype.getCommon=function(){return this._config.common||{}};Config.prototype.getSeverity=function(){return this._config.severity};Config.prototype.setSeverity=function(severity){return this._config.severity=severity};Config.prototype.getSevMap=function(){return this._config.sevMap};Config.prototype.getTheme=function(){return this._config.theme};Config.prototype.getComments=function(){return this._config.comments};Config.prototype.getEcmaVer=function(){return this._config.ecmaVer};Config.prototype.getTabs=function(){return this._config.tabs};Config.prototype.getTitle=function(){return this._config.title};Config.prototype.getRetCode=function(){var ret,o;if(this._config&&this._config.options){o=this._config.options;if(o.retCode!==undefined){ret=o.retCode}else if(o.rc!==undefined){ret=o.rc}else{ret="auto"}}else{ret="auto"}return ret};Config.prototype.isOk=function(){return!this._bErrors};Config.prototype.getUserDefs=function(){return this._config.userDefs};Config.prototype.getAppendFileList=function(){return this._helper.getAddFileList()};Config.prototype.getJetPagesOnly=function(){return this._config.jetPagesOnly};Config.prototype.getTempDir=function(){return this._config.tempDir};Config.prototype.getOrigConfig=function(){return this._origConfig};Config.prototype.get$JetCore=function(){return this._config.$JetCore};Config.prototype._init=function(base,iniPath,cbDebug){var i,s,val,val2,bUseDefaults=false;if(typeof iniPath==="string"){this._dir=this._nd.path.dirname(iniPath);bUseDefaults=this._loadConfig(iniPath);if(this._bErrors){return}}else{this._config=iniPath;this._dir=this._nd.process.cwd();this._preBuilt=true}this._origConfig=this._config;this._config=_cloneConfig(this._config);this._helper.setConfig(this._config,this._preBuilt?null:iniPath,this._dir);if(this._config.options){this._isVerbose=!!this._config.options.verbose;this._isDebug=!!this._config.options.debug;let opStat=cbDebug(this._isVerbose,this._isDebug);this._isVerbose=opStat.verbose;this._isDebug=opStat.debug;this._helper.setDebugStatus(this._isVerbose,this._isDebug)}if(!this._checkProperties()){this._bErrors=true;return}if(base){this._config.base=base}if(!this._config.base){this._config.base=this._dir}if(this._config.base===MACROS.cwd){this._config.base=this._nd.process.cwd()}if(!this._cleanBase()){return}if(!bUseDefaults&&!this._isOJET){this._info("[Info]: Analyzing "+(typeof iniPath==="string"?"config '"+iniPath+"'":"pre-built config object"),"I",true)}if(this._config.extends){if(!this._helper.processExtends()){this._bErrors=true;return}}if(this._config?.options?.experimental&&this._config.options.experimental!=="tsx"){this._error("Config entry 'experimental' - invalid value!");this._bErrors=true;return}if(typeof this._config.builtinJetRules!==TYPE_BOOLEAN){this._config.builtinJetRules=true}if(typeof this._config.builtinCspRules!==TYPE_BOOLEAN){this._config.builtinCspRules=false}if(typeof this._config.builtinJetWcRules!==TYPE_BOOLEAN){this._config.builtinJetWcRules=false}if(typeof this._config.builtinJetWcOracleRules!==TYPE_BOOLEAN){this._config.builtinJetWcOracleRules=false}if(typeof this._config.builtinWebDriverTestRules!==TYPE_BOOLEAN){this._config.builtinWebDriverTestRules=false}if(this._config.builtinSpocRules){if(typeof this._config.builtinSpocRules!==TYPE_BOOLEAN){this._error("Config entry 'builtinSpocRules' must be a boolean!");this._bErrors=true;return}if(this._config.builtinSpocRules){this._config.builtinJetRules=this._config.builtinJetWcRules=this._config.builtinJetWcOracleRules=false}}if(this._config.builtinOjcMigrationRules){if(typeof this._config.builtinOjcMigrationRules!==TYPE_BOOLEAN){this._error("Config entry 'builtinOjcMigrationRules' must be a boolean!");this._bErrors=true;return}else{this._config.builtinJetRules=this._config.builtinJetWcRules=this._config.builtinJetWcOracleRules=this._config.builtinCspRules=this._config.builtinSpocRules=false}}else{this._config.builtinOjcMigrationRules=false}this._config.jetPagesOnly=!!this._config.jetPagesOnly;if(!this._config.files){this._config.files=[]}if(!this._config.options){this._config.options={}}if(this._config.jetVer){val=this._config.jetVer;if(typeof val!=="string"){this._error("Config entry 'jetVer' is not a string!");this._bErrors=true;return}val=val.trim();val2=val.split(".");for(i=0;i<val2.length;i++){if(i===0&&val2[0].charAt(0).toLowerCase()==="v"){val2[0]=val2[0].substring(1)}s=parseInt(val2[i]);if(isNaN(s)){let part=["major","minor","patch"];this._error(`Config entry 'jetVer' --> '${val}' : '${part[i]}' value is invalid`);this._bErrors=true;return}val2[i]=""+s}val=val2.join(".");if(val2.length!==3||val2[2]==="0"){s=val2.length===3;val2=this._nd.jetver.getBestVersion(val,val2);if(!val2){s=s?`Config entry 'jetVer' --> '${val}' cannot be resolved to a supported JET version`:`Config entry 'jetVer' --> '${val}' is not a supported JET version`;this._error(s);this._bErrors=true;return}val=val2}if(!JET_VERSIONS[val]){this._error(`Config entry 'jetVer' --> '${val}' is not a supported JET version!`);this._bErrors=true;return}this._config.jetVer=val}else{this._config.jetVer=DEFAULTS.JETVER}if(!this._helper.processJetCorePack()){this._bErrors=true;return}if(!this._helper.processWebComponents()){this._bErrors=true;return}if(!this._helper.processRulePacks()){this._bErrors=true;return}if(!this._helper.processRuleMods()){this._bErrors=true;return}if(!this._helper.processFormat()){this._bErrors=true;return}if(!this._helper.processProseFormat()){this._bErrors=true;return}if(!this._helper.processLineFormat()){this._bErrors=true;return}if(!this._helper.processRuleDescriptions()){this._bErrors=true;return}if(!this._helper.processRulesFired()){this._bErrors=true;return}if(!this._helper.processSevMap()){this._bErrors=true;return}if(!this._helper.processSeverity(this._cliSev)){this._bErrors=true;return}if(!this._helper.processGroups(this._cliGroups)){this._bErrors=true;return}if(!this._helper.processDefGroups()){this._bErrors=true;return}if(!this._helper.processRuleNames()){this._bErrors=true;return}if(this._config.followLinks==null){this._config.followLinks=true}else{this._config.followLinks=!!this._config.followLinks}if(!Array.isArray(this._config.files)){this._error("Config entry 'files' is not an array!");this._bErrors=true;return}if(!this._helper.validateFileList(this._config.files)){this._bErrors=true;return}if(this._config.exclude){if(!Array.isArray(this._config.exclude)){this._error("Config entry 'exclude' is not an array!");this._bErrors=true;return}if(!this._helper.validateFileList(this._config.exclude)){this._bErrors=true;return}}else if(this._config.excludes){this._error("Config property 'excludes' found - did you mean 'exclude'?");this._bErrors=true;return}if(!this._helper.processAddFileList()){this._bErrors=true;return}if(this._config.stylesets){val=this._config.stylesets;if(!Array.isArray(val)){this._error("Config property 'stylesets' is not an array!");this._bErrors=true;return}}if(this._isAMD&&this._config.tempDir){this._error("Config entry 'tempDir' is not valid in AMD mode!");this._bErrors=true;return}if(this._config.tempDir){if(typeof this._config.tempDir!=="string"){this._error("Config property 'tempDir' is not a string!");this._bErrors=true;return}if(this._config.tempDir.startsWith(".")){this._config.tempDir=this._nd.path.resolve(this._nd.process.cwd(),this._config.tempDir)}}if(!this._helper.processTypeScript()){this._bErrors=true;return}if(!this._helper.processMarkdownOpts()){this._bErrors=true;return}if(!this._helper.processMessages()){this._bErrors=true;return}if(!this._helper.processNameSpaces()){this._bErrors=true;return}if(!this._helper.processTheme()){this._bErrors=true;return}if(!this._helper.processComments()){this._bErrors=true;return}if(!this._helper.processEcmaVer()){this._bErrors=true;return}if(!this._helper.processOptions()){this._bErrors=true;return}if(!this._helper.processTitle()){this._bErrors=true;return}if(!this._helper.processRetCode()){this._bErrors=true;return}if(!this._config.extends){this._cleanConfigPaths()}if(this._config.typescript&&(val=this._config.typescript.tsconfig)){if(!(this._tsCfgObj=this._loadTsConfig(val))){this._bErrors=true;return}}};Config.prototype.validateRetCode=function(val,cb){return this._helper.validateRetCode(val,cb)};Config.prototype._cleanConfigPaths=function(){var src,i,ftype,dir;var nd=this._nd;var base=this._config.base;function _resolve(fp){if(!nd.path.isAbsolute(fp)){fp=nd.path.normalize(fp);fp=nd.path.resolve(base,fp)}return fp};if(!this._config.extends){this._info("[Info]: Using config base '"+this._config.base+"'","I")}if(src=this._config.files){for(i=0;i<src.length;i++){if(!src[i].startsWith("http")){src[i]=_resolve(src[i])}}}if(src=this._config.exclude){for(i=0;i<src.length;i++){src[i]=_resolve(src[i])}}if(src=this._config.components){for(i=0;i<src.length;i++){src[i]=_resolve(src[i])}}src=this._config.outPath;if(src&&src!=="$noout"){this._config.outPath=_resolve(src)}src=this._config.rulePacks;if(src){for(i=0;i<src.length;i++){if(!nd.path.isAbsolute(src[i].path)){dir=nd.path.normalize(src[i].path);src[i].path=nd.path.resolve(this._config.base,dir)}if(src[i].path.endsWith(".zip")){continue}ftype=this._fsUtils.getFileType(src[i].path);if(ftype!=="d"){this._error("'rulePacks (entry "+(i+1)+"): path' is not a directory - \""+src[i].path+"\"");this._bErrors=true;return}}}if(this._config.typescript&&this._config.typescript.tsconfig)src=this._config.typescript.tsconfig;if(src&&typeof src==="string"){if(!nd.path.isAbsolute(src)){dir=nd.path.normalize(src);dir=nd.path.resolve(this._config.base,dir)}else{dir=src}if(!dir.endsWith(TSCONFIG)){dir=nd.path.join(dir,TSCONFIG)}this._config.typescript.tsconfig=dir}if(src=this._config.jetCorePack){this._config.jetCorePack=_resolve(src)}if(this._bErrors){return};};Config.prototype._cleanBase=function(){var p,ft;var nd=this._nd;p=this._config.base;p=nd.path.normalize(p);p=nd.path.resolve(this._dir,p);ft=this._fsUtils.getFileType(p);if(ft!=="d"){this._error(`Config file 'base' is not a directory - '${p}'`);this._bErrors=true;return false}p=nd.path.join(p,"/");this._config.base=p;this._info(`[Info]: Using Config base '${p}'`,"I");return true};Config.prototype._loadConfig=function(iniPath){var data,stats,bUseDefaults=false,msg;var nd=this._nd;try{stats=nd.fs.statSync(iniPath);if(!stats.isFile()){this._warn("\n[Warn]: Config file '"+iniPath+"' not found. Using defaults.\n");bUseDefaults=true}else{data=nd.fs.readFileSync(iniPath,"utf8");data=nd.decomment(data);data=this.processIncludes(data,iniPath);data=this.processTokens(data);if(this._bErrors){return}if(this._isDebug){if(!data){console.log("NO CONFIG DATA")}else{var a=data.split("\n");console.log("------------- Config Raw Text...");for(var i=0;i<a.length;i++){console.log(i+1+"] "+a[i])}console.log("-".repeat(40))}}if(data){this._config=JSON.parse(nd.decomment(data))}else{this._bErrors=true}}}catch(e){this._bErrors=true;if(e.code){if(e.message.startsWith("ENOENT:")){this._warn("\nConfig file \""+iniPath+"\" not found - using defaults.\n");this._bErrors=false;bUseDefaults=true}}else if(e.toString().startsWith("SyntaxError")){msg=_convertMsgToRowCol(e.message,data,this._utils)}else{msg=e.message}if(msg){msg=msg.replace(/\r/g,"");msg=msg.replace(/ +(?= )/g,"");this._error("Config parse error");this._error("Config file '"+iniPath+"' - "+msg)}}if(this._bErrors){return}if(bUseDefaults){this._config={exclude:["./**/*-min.js","./**/*-min.css","./**/node_modules/**/*.*"],builtinJetRules:true,builtinCspRules:false,builtinJetWcRules:false,builtinJetWcOracleRules:false,builtinOjcMigrationRules:false,followLinks:true,severity:this._severity.ALL,format:"prose",ecmaVer:DEFAULTS.ECMAVER,options:{verbose:false,color:true}}}return bUseDefaults};Config.prototype._checkProperties=function(){return this._helper.checkPropNames()};Config.prototype._loadTsConfig=function(fp){return this._nd.jsonLoader.load(fp,this._nd,m=>{this._error(`Error loading tsconfig : ${m}.`);this._bErrors=true},false,this._utils)};function _convertMsgToRowCol(msg,data,utils){var x,n,rc;x=msg.indexOf("position");if(x<0){return msg}n=parseInt(msg.substr(x+8).trim());rc=utils.getRowColFromIndex(data,n);return msg.substr(0,x)+"row "+rc.row+", col "+rc.col};Config.prototype.processTokens=function(data){const TOKENS="\"tokens\"";var token,sub,start,end,json,toks,count,subst,rc,x,n;if(this._isDebug){this._debug("Performing config 'tokens' substitution...")}x=data.indexOf(TOKENS);if(x<0)return data;x+=TOKENS.length;n=this._expect(data,x,":",true);if(n<0){rc=this._utils.getRowColFromIndex(data,x);this._error("Config: expected ':' after property "+TOKENS+" on line "+rc.row+" position "+rc.col+".");this._bErrors=true;return}n=this._expect(data,n,"{");if(n<0){rc=this._utils.getRowColFromIndex(data,n);this._error("Config: expected '{' after property "+TOKENS+" on line "+rc.row+".");this._bErrors=true;return}start=n;end=data.indexOf("}",start);if(end<0){rc=this._utils.getRowColFromIndex(data,x);this._error("Config: "+TOKENS+" property syntax error (on/after line "+rc.row+").");this._bErrors=true;return}json=data.substring(start,end+1);try{toks=JSON.parse(json)}catch(e){rc=this._utils.getRowColFromIndex(data,x);this._error("Config: syntax error "+TOKENS+" property (on/after line "+rc.row+").");this._bErrors=true;return}subst=0;count=0;for(token in toks){if(token.charAt(0)!=="@"){this._error("Config: token '"+token+"' : must be prefixed with '@'");this._bErrors=true;return}sub=toks[token];token=token.replace(/[.*+?^${}()|[\]\\]/g,"\\$&");token=new RegExp(token,"g");if(this._isVerbose||this._isDebug){n=data.match(token).length;subst+=n>1?--n:0}data=data.replace(token,sub);count++}if(count){try{start=data.indexOf(TOKENS);start=this._expect(data,start+TOKENS.length,":",true);start=this._expect(data,start,"{");end=data.indexOf("}",start+1);data=data.substring(0,start)+json+data.substring(end+1);if(this._isVerbose||this._isDebug){this._info("[Info]: "+subst+" config token substitution"+(subst!==1?"s":"")+" performed with "+count+" token"+(count!==1?"s":"")+".")}}catch(e){this._error("Config: \"tokens\" substitution failed - review \"tokens\" property value");this._bErrors=true}}return data};Config.prototype._expect=function(data,x,s,bump){var ret=-1;x=this._utils.eatWhitespace(data,x);if(x>=0&&data.substr(x,s.length)===s){ret=x+(bump?s.length:0)}return ret};Config.prototype.processIncludes=function(data,filepath,chain){var a,i,line,x,path,comma;var inserts,insert,incPath;var nd=this._nd;if(this._isDebug){this._debug("Checking for "+(chain?"sub ":"")+"@include. . .")}if((i=data.indexOf(AT_INCLUDE))<0||data.charAt(i-1)==="_"){if(this._isDebug){this._debug("No "+(chain?"sub ":"")+"@include found")}return data}inserts=[];a=data.split("\n");for(i=0;i<a.length;i++){line=a[i];x=line.indexOf(AT_INCLUDE);if(x<0){continue}path=_extractStringFromLine(line,x+AT_INCLUDE.length,this._utils);if(!path){this._error("Config - @include syntax error"+(chain?" in '"+filepath+"'":"!"));return null}incPath=nd.path.normalize(path);incPath=nd.path.resolve(this._dir,incPath);comma=_isTrailingComma(line,x+AT_INCLUDE.length,this._utils);try{if(this._isDebug){this._debug("Reading @include -> "+incPath)}insert=nd.fs.readFileSync(incPath,"utf8")}catch(e){this._error("Config @include - "+e);return null}if(!insert){this._error("Config - @include '"+incPath+"' not found!");return null}insert=this.processIncludes(insert,incPath,true);if(insert){inserts.push(i);inserts.push(insert+(comma?",":""))}else if(insert===null){return null}}if(inserts&&inserts.length){for(i=0;i<inserts.length;i++){a[inserts[i]]=inserts[++i]}}return a.join("\n")};function _extractStringFromLine(data,start,utils){var c,xEnd,wantQuote,antiQuote;start=utils.eatWhitespace(data,start);if(start<0){return null}c=data.charAt(start);wantQuote=c===QUOTE||c==="'"?c:null;if(wantQuote){antiQuote=c===QUOTE?"'":QUOTE;start++}for(xEnd=start;xEnd<data.length;xEnd++){c=data.charAt(xEnd);if(c===")"||wantQuote&&c===wantQuote){break}else if(c==="\n"||wantQuote&&c===antiQuote||!wantQuote&&(c===QUOTE||c==="'")){xEnd=-1;break}}if(xEnd<0||xEnd>=data.length||wantQuote&&data.charAt(xEnd)!==wantQuote){return null}data=data.substring(start,xEnd).trim();return data?data:null};function _isTrailingComma(s,x,utils){var n,ret=false;n=s.indexOf(")",x);if(n<0){return false}n=utils.eatWhitespace(s,n+1);if(n>=0){ret=s.charAt(n)===","}return ret};function _cloneConfig(o){return JSON.parse(JSON.stringify(o))};module.exports=Config;
|
|
6
|
+
const Helper=require("./ConfigEx");const ConfigLib=require("./ConfigLib");const MACROS=require("../lib/macros");const DEFAULTS=require("./defaults");var JET_VERSIONS;const TYPE_BOOLEAN="boolean";const AT_INCLUDE="@include(";const QUOTE="\"";const TSCONFIG="tsconfig.json";var Config=function(nd,base,iniPath,fnApplyMacros,rules,severity,cliGroups,cliSev,msgCtx,modeCtx,utils,fsUtils,cbDebug){this._path=iniPath;this._dir=null;this._config=null;this._tsCfgObj=null;this._preBuilt=false;this._isOJET=modeCtx.isOJET;this._isCLI=modeCtx.isCLI;this._isAPI=modeCtx.isAPI;this._isAMD=modeCtx.isAMD;this._isCliMode=modeCtx.isCLI||modeCtx.isOJETCLI;this._rules=rules;this._utils=utils;this._fsUtils=fsUtils;this._severity=severity;this._helper=new Helper(this,nd,severity,utils,fsUtils,msgCtx,modeCtx);this.applyMacros=fnApplyMacros;this._bErrors=false;this._console=msgCtx.console;this._error=msgCtx.error;this._warn=msgCtx.warn;this._info=msgCtx.info;this._debug=msgCtx.debug;this._isDebug=msgCtx.isDebug;this._isVerbose=msgCtx.isVerbose;JET_VERSIONS=nd.jetver.getVersions();this._cliGroups=cliGroups;this._cliSev=cliSev;this._nd=nd;if(iniPath){this._init(base,iniPath,cbDebug)}};Config.prototype.getConfig=function(){var tmp=JSON.parse(JSON.stringify(this._config));if(tmp._sev){delete tmp._sev}return tmp};Config.prototype.getConfigLib=function(){if(this._configLib){return this._configLib}this._configLib=new ConfigLib(this,this._helper);return this._configLib};Config.prototype.getFiles=function(){return this._config.files};Config.prototype.getExclude=function(){return this._config.exclude};Config.prototype.getOptions=function(){return this._config.options};Config.prototype.getJetVer=function(){return this._config.jetVer};Config.prototype.getComponentsBaseUrl=function(){return this._config.componentsBaseUrl};Config.prototype.getComponentsBase=function(){return this._config.componentsBase};Config.prototype.getComponents=function(){return this._config.components};Config.prototype.getComponentUrls=function(){return this._config.componentUrls};Config.prototype.getJetCorePack=function(){return this._config.jetCorePack};Config.prototype.getComponentOptions=function(){return this._config.componentOptions};Config.prototype.getTypescript=function(){return this._config.typescript};Config.prototype.getTsConfig=function(){var ret;if(this._config.typescript){ret=this._config.typescript.tsconfig}return ret};Config.prototype.getMarkdownOptions=function(){return this._config.markdownOptions};Config.prototype.getTsConfigObj=function(){return this._tsCfgObj};Config.prototype.getOutPath=function(){return this._config.outPath};Config.prototype.getRulePacks=function(){return this._config.rulePacks};Config.prototype.getRuleMods=function(){return this._config.ruleMods};Config.prototype.getEnable=function(){return this._config.ruleMods&&this._config.ruleMods.enable?this._config.ruleMods.enable:undefined};Config.prototype.getDisable=function(){return this._config.ruleMods&&this._config.ruleMods.disable?this._config.ruleMods.disable:undefined};Config.prototype.getRuleDescriptions=function(){return this._config.ruleDescriptions};Config.prototype.getRulesFired=function(){return this._config.rulesFired};Config.prototype.getGroups=function(){return this._config.groups};Config.prototype.setGroups=function(groups){this._config.groups=groups};Config.prototype.getDefGroups=function(){return this._config.defGroups};Config.prototype.getRunRuleNames=function(){return this._config.ruleNames};Config.prototype.isBuiltinJetRules=function(){return this._config.builtinJetRules};Config.prototype.isBuiltinCspRules=function(){return this._config.builtinCspRules};Config.prototype.isBuiltinJetWcRules=function(){return this._config.builtinJetWcRules};Config.prototype.isBuiltinJetWcOracleRules=function(){return this._config.builtinJetWcOracleRules};Config.prototype.isBuiltinSpocRules=function(){return this._config.builtinSpocRules};Config.prototype.isBuiltinOjcMigrationRules=function(){return this._config.builtinOjcMigrationRules};Config.prototype.isBuiltinWebDriverTestRules=function(){return this._config.builtinWebDriverTestRules};Config.prototype.getMessages=function(){return this._config.messages};Config.prototype.setMessages=function(msgid,state){return this._helper.setMessages(msgid,state)};Config.prototype.getFollowLinks=function(){return this._config.followLinks};Config.prototype.getFormat=function(){return this._config.format};Config.prototype.getProseFormat=function(){return this._config.proseFormat};Config.prototype.getLineFormat=function(){return this._config.lineFormat};Config.prototype.getBase=function(){return this._config.base};Config.prototype.getStylesets=function(){return this._config.stylesets};Config.prototype.getNameSpaces=function(){return this._config.nameSpaces};Config.prototype.getCommon=function(){return this._config.common||{}};Config.prototype.getSeverity=function(){return this._config.severity};Config.prototype.setSeverity=function(severity){return this._config.severity=severity};Config.prototype.getSevMap=function(){return this._config.sevMap};Config.prototype.getTheme=function(){return this._config.theme};Config.prototype.getComments=function(){return this._config.comments};Config.prototype.getEcmaVer=function(){return this._config.ecmaVer};Config.prototype.getTabs=function(){return this._config.tabs};Config.prototype.getTitle=function(){return this._config.title};Config.prototype.getRetCode=function(){var ret,o;if(this._config&&this._config.options){o=this._config.options;if(o.retCode!==undefined){ret=o.retCode}else if(o.rc!==undefined){ret=o.rc}else{ret="auto"}}else{ret="auto"}return ret};Config.prototype.isOk=function(){return!this._bErrors};Config.prototype.getUserDefs=function(){return this._config.userDefs};Config.prototype.getAppendFileList=function(){return this._helper.getAddFileList()};Config.prototype.getJetPagesOnly=function(){return this._config.jetPagesOnly};Config.prototype.getExtendsProfileName=function(){return this._profile};Config.prototype.getTempDir=function(){return this._config.tempDir};Config.prototype.getOrigConfig=function(){return this._origConfig};Config.prototype.get$JetCore=function(){return this._config.$JetCore};Config.prototype._init=function(base,iniPath,cbDebug){var i,s,val,val2,bUseDefaults=false;if(typeof iniPath==="string"){this._dir=this._nd.path.dirname(iniPath);bUseDefaults=this._loadConfig(iniPath);if(this._bErrors){return}}else{this._config=iniPath;this._dir=this._nd.process.cwd();this._preBuilt=true}this._origConfig=this._config;this._config=_cloneConfig(this._config);this._helper.setConfig(this._config,this._preBuilt?null:iniPath,this._dir);if(this._config.options){this._isVerbose=!!this._config.options.verbose;this._isDebug=!!this._config.options.debug;let opStat=cbDebug(this._isVerbose,this._isDebug);this._isVerbose=opStat.verbose;this._isDebug=opStat.debug;this._helper.setDebugStatus(this._isVerbose,this._isDebug)}if(!this._checkProperties()){this._bErrors=true;return}if(base){this._config.base=base}if(!this._config.base){this._config.base=this._dir}if(this._config.base===MACROS.cwd){this._config.base=this._nd.process.cwd()}if(!this._cleanBase()){return}if(!bUseDefaults&&!this._isOJET){this._info("[Info]: Analyzing "+(typeof iniPath==="string"?"config '"+iniPath+"'":"pre-built config object"),"I",true)}if(this._config.extends){if(!this._helper.processExtends()){this._bErrors=true;return}}if(this._config?.options?.experimental&&this._config.options.experimental!=="tsx"){this._error("Config entry 'experimental' - invalid value!");this._bErrors=true;return}if(typeof this._config.builtinJetRules!==TYPE_BOOLEAN){this._config.builtinJetRules=true}if(typeof this._config.builtinCspRules!==TYPE_BOOLEAN){this._config.builtinCspRules=false}if(typeof this._config.builtinJetWcRules!==TYPE_BOOLEAN){this._config.builtinJetWcRules=false}if(typeof this._config.builtinJetWcOracleRules!==TYPE_BOOLEAN){this._config.builtinJetWcOracleRules=false}if(typeof this._config.builtinWebDriverTestRules!==TYPE_BOOLEAN){this._config.builtinWebDriverTestRules=false}if(this._config.builtinSpocRules){if(typeof this._config.builtinSpocRules!==TYPE_BOOLEAN){this._error("Config entry 'builtinSpocRules' must be a boolean!");this._bErrors=true;return}if(this._config.builtinSpocRules){this._config.builtinJetRules=this._config.builtinJetWcRules=this._config.builtinJetWcOracleRules=false}}if(this._config.builtinOjcMigrationRules){if(typeof this._config.builtinOjcMigrationRules!==TYPE_BOOLEAN){this._error("Config entry 'builtinOjcMigrationRules' must be a boolean!");this._bErrors=true;return}else{this._config.builtinJetRules=this._config.builtinJetWcRules=this._config.builtinJetWcOracleRules=this._config.builtinCspRules=this._config.builtinSpocRules=false}}else{this._config.builtinOjcMigrationRules=false}this._config.jetPagesOnly=!!this._config.jetPagesOnly;if(!this._config.files){this._config.files=[]}if(!this._config.options){this._config.options={}}if(!this._helper.processRuleDiscriminant()){this._bErrors=true;return}if(this._config.jetVer){val=this._config.jetVer;if(typeof val!=="string"){this._error("Config entry 'jetVer' is not a string!");this._bErrors=true;return}val=val.trim();if((i=val.indexOf("-"))>=0){val=val.substring(0,i)}val2=val.split(".");if(val2.length>3){this._error(`Config entry 'jetVer' --> '${val}' is invalid`);this._bErrors=true;return}for(i=0;i<val2.length;i++){if(i===0&&val2[0].charAt(0).toLowerCase()==="v"){val2[0]=val2[0].substring(1)}s=parseInt(val2[i]);if(isNaN(s)){let part=["major","minor","patch"];this._error(`Config entry 'jetVer' --> '${val}' : '${part[i]}' value is invalid`);this._bErrors=true;return}val2[i]=""+s}val=val2.join(".");if(val2.length!==3||val2[2]==="0"){s=val2.length===3;val2=this._nd.jetver.getBestVersion(val,val2);if(!val2){s=s?`Config entry 'jetVer' --> '${val}' cannot be resolved to a supported JET version`:`Config entry 'jetVer' --> '${val}' is not a supported JET version`;this._error(s);this._bErrors=true;return}val=val2}if(!JET_VERSIONS[val]){this._error(`Config entry 'jetVer' --> '${val}' is not a supported JET version!`);this._bErrors=true;return}this._config.jetVer=val}else{this._config.jetVer=DEFAULTS.JETVER}if(!this._helper.processJetCorePack()){this._bErrors=true;return}if(!this._helper.processWebComponents()){this._bErrors=true;return}if(!this._helper.processRulePacks()){this._bErrors=true;return}if(!this._helper.processRuleMods()){this._bErrors=true;return}if(!this._helper.processFormat()){this._bErrors=true;return}if(!this._helper.processProseFormat()){this._bErrors=true;return}if(!this._helper.processLineFormat()){this._bErrors=true;return}if(!this._helper.processRuleDescriptions()){this._bErrors=true;return}if(!this._helper.processRulesFired()){this._bErrors=true;return}if(!this._helper.processSevMap()){this._bErrors=true;return}if(!this._helper.processSeverity(this._cliSev)){this._bErrors=true;return}if(!this._helper.processGroups(this._cliGroups)){this._bErrors=true;return}if(!this._helper.processDefGroups()){this._bErrors=true;return}if(!this._helper.processRuleNames()){this._bErrors=true;return}if(this._config.followLinks==null){this._config.followLinks=true}else{this._config.followLinks=!!this._config.followLinks}if(!Array.isArray(this._config.files)){this._error("Config entry 'files' is not an array!");this._bErrors=true;return}if(!this._helper.validateFileList(this._config.files)){this._bErrors=true;return}if(this._config.exclude){if(!Array.isArray(this._config.exclude)){this._error("Config entry 'exclude' is not an array!");this._bErrors=true;return}if(!this._helper.validateFileList(this._config.exclude)){this._bErrors=true;return}}else if(this._config.excludes){this._error("Config property 'excludes' found - did you mean 'exclude'?");this._bErrors=true;return}if(!this._helper.processAddFileList()){this._bErrors=true;return}if(this._config.stylesets){val=this._config.stylesets;if(!Array.isArray(val)){this._error("Config property 'stylesets' is not an array!");this._bErrors=true;return}}if(this._isAMD&&this._config.tempDir){this._error("Config entry 'tempDir' is not valid in AMD mode!");this._bErrors=true;return}if(this._config.tempDir){if(typeof this._config.tempDir!=="string"){this._error("Config property 'tempDir' is not a string!");this._bErrors=true;return}if(this._config.tempDir.startsWith(".")){this._config.tempDir=this._nd.path.resolve(this._nd.process.cwd(),this._config.tempDir)}}if(!this._helper.processTypeScript()){this._bErrors=true;return}if(!this._helper.processMarkdownOpts()){this._bErrors=true;return}if(!this._helper.processMessages()){this._bErrors=true;return}if(!this._helper.processNameSpaces()){this._bErrors=true;return}if(!this._helper.processTheme()){this._bErrors=true;return}if(!this._helper.processComments()){this._bErrors=true;return}if(!this._helper.processEcmaVer()){this._bErrors=true;return}if(!this._helper.processOptions()){this._bErrors=true;return}if(!this._helper.processTitle()){this._bErrors=true;return}if(!this._helper.processRetCode()){this._bErrors=true;return}if(!this._config.extends){this._cleanConfigPaths()}if(this._config.typescript&&(val=this._config.typescript.tsconfig)){if(!(this._tsCfgObj=this._loadTsConfig(val))){this._bErrors=true;return}}};Config.prototype.validateRetCode=function(val,cb){return this._helper.validateRetCode(val,cb)};Config.prototype._cleanConfigPaths=function(){var src,i,ftype,dir;var nd=this._nd;var base=this._config.base;function _resolve(fp){if(!nd.path.isAbsolute(fp)){fp=nd.path.normalize(fp);fp=nd.path.resolve(base,fp)}return fp};if(!this._config.extends){this._info("[Info]: Using config base '"+this._config.base+"'","I")}if(src=this._config.files){for(i=0;i<src.length;i++){if(!src[i].startsWith("http")){src[i]=_resolve(src[i])}}}if(src=this._config.exclude){for(i=0;i<src.length;i++){src[i]=_resolve(src[i])}}if(src=this._config.components){for(i=0;i<src.length;i++){src[i]=_resolve(src[i])}}src=this._config.outPath;if(src&&src!=="$noout"){this._config.outPath=_resolve(src)}src=this._config.rulePacks;if(src){for(i=0;i<src.length;i++){if(!nd.path.isAbsolute(src[i].path)){dir=nd.path.normalize(src[i].path);src[i].path=nd.path.resolve(this._config.base,dir)}if(src[i].path.endsWith(".zip")){continue}ftype=this._fsUtils.getFileType(src[i].path);if(ftype!=="d"){this._error("'rulePacks (entry "+(i+1)+"): path' is not a directory - \""+src[i].path+"\"");this._bErrors=true;return}}}if(this._config.typescript&&this._config.typescript.tsconfig)src=this._config.typescript.tsconfig;if(src&&typeof src==="string"){if(!nd.path.isAbsolute(src)){dir=nd.path.normalize(src);dir=nd.path.resolve(this._config.base,dir)}else{dir=src}if(!dir.endsWith(TSCONFIG)){dir=nd.path.join(dir,TSCONFIG)}this._config.typescript.tsconfig=dir}if(src=this._config.jetCorePack){this._config.jetCorePack=_resolve(src)}if(this._bErrors){return};};Config.prototype._cleanBase=function(){var p,ft;var nd=this._nd;p=this._config.base;p=nd.path.normalize(p);p=nd.path.resolve(this._dir,p);ft=this._fsUtils.getFileType(p);if(ft!=="d"){this._error(`Config file 'base' is not a directory - '${p}'`);this._bErrors=true;return false}p=nd.path.join(p,"/");this._config.base=p;this._info(`[Info]: Using Config base '${p}'`,"I");return true};Config.prototype._loadConfig=function(iniPath){var data,stats,bUseDefaults=false,msg;var nd=this._nd;try{stats=nd.fs.statSync(iniPath);if(!stats.isFile()){this._warn("\n[Warn]: Config file '"+iniPath+"' not found. Using defaults.\n");bUseDefaults=true}else{data=nd.fs.readFileSync(iniPath,"utf8");data=nd.decomment(data);data=this.processIncludes(data,iniPath);data=this.processTokens(data);if(this._bErrors){return}if(this._isDebug){if(!data){console.log("NO CONFIG DATA")}else{var a=data.split("\n");console.log("------------- Config Raw Text...");for(var i=0;i<a.length;i++){console.log(i+1+"] "+a[i])}console.log("-".repeat(40))}}if(data){this._config=JSON.parse(nd.decomment(data))}else{this._bErrors=true}}}catch(e){this._bErrors=true;if(e.code){if(e.message.startsWith("ENOENT:")){this._warn("\nConfig file \""+iniPath+"\" not found - using defaults.\n");this._bErrors=false;bUseDefaults=true}}else if(e.toString().startsWith("SyntaxError")){msg=_convertMsgToRowCol(e.message,data,this._utils)}else{msg=e.message}if(msg){msg=msg.replace(/\r/g,"");msg=msg.replace(/ +(?= )/g,"");this._error("Config parse error");this._error("Config file '"+iniPath+"' - "+msg)}}if(this._bErrors){return}if(bUseDefaults){this._config={exclude:["./**/*-min.js","./**/*-min.css","./**/node_modules/**/*.*"],builtinJetRules:true,builtinCspRules:false,builtinJetWcRules:false,builtinJetWcOracleRules:false,builtinOjcMigrationRules:false,followLinks:true,severity:this._severity.ALL,format:"prose",ecmaVer:DEFAULTS.ECMAVER,options:{verbose:false,color:true}}}return bUseDefaults};Config.prototype._checkProperties=function(){return this._helper.checkPropNames()};Config.prototype._loadTsConfig=function(fp){return this._nd.jsonLoader.load(fp,this._nd,m=>{this._error(`Error loading tsconfig : ${m}.`);this._bErrors=true},false,this._utils)};function _convertMsgToRowCol(msg,data,utils){var x,n,rc;x=msg.indexOf("position");if(x<0){return msg}n=parseInt(msg.substr(x+8).trim());rc=utils.getRowColFromIndex(data,n);return msg.substr(0,x)+"row "+rc.row+", col "+rc.col};Config.prototype.processTokens=function(data){const TOKENS="\"tokens\"";var token,sub,start,end,json,toks,count,subst,rc,x,n;if(this._isDebug){this._debug("Performing config 'tokens' substitution...")}x=data.indexOf(TOKENS);if(x<0)return data;x+=TOKENS.length;n=this._expect(data,x,":",true);if(n<0){rc=this._utils.getRowColFromIndex(data,x);this._error("Config: expected ':' after property "+TOKENS+" on line "+rc.row+" position "+rc.col+".");this._bErrors=true;return}n=this._expect(data,n,"{");if(n<0){rc=this._utils.getRowColFromIndex(data,n);this._error("Config: expected '{' after property "+TOKENS+" on line "+rc.row+".");this._bErrors=true;return}start=n;end=data.indexOf("}",start);if(end<0){rc=this._utils.getRowColFromIndex(data,x);this._error("Config: "+TOKENS+" property syntax error (on/after line "+rc.row+").");this._bErrors=true;return}json=data.substring(start,end+1);try{toks=JSON.parse(json)}catch(e){rc=this._utils.getRowColFromIndex(data,x);this._error("Config: syntax error "+TOKENS+" property (on/after line "+rc.row+").");this._bErrors=true;return}subst=0;count=0;for(token in toks){if(token.charAt(0)!=="@"){this._error("Config: token '"+token+"' : must be prefixed with '@'");this._bErrors=true;return}sub=toks[token];token=token.replace(/[.*+?^${}()|[\]\\]/g,"\\$&");token=new RegExp(token,"g");if(this._isVerbose||this._isDebug){n=data.match(token).length;subst+=n>1?--n:0}data=data.replace(token,sub);count++}if(count){try{start=data.indexOf(TOKENS);start=this._expect(data,start+TOKENS.length,":",true);start=this._expect(data,start,"{");end=data.indexOf("}",start+1);data=data.substring(0,start)+json+data.substring(end+1);if(this._isVerbose||this._isDebug){this._info("[Info]: "+subst+" config token substitution"+(subst!==1?"s":"")+" performed with "+count+" token"+(count!==1?"s":"")+".")}}catch(e){this._error("Config: \"tokens\" substitution failed - review \"tokens\" property value");this._bErrors=true}}return data};Config.prototype._expect=function(data,x,s,bump){var ret=-1;x=this._utils.eatWhitespace(data,x);if(x>=0&&data.substr(x,s.length)===s){ret=x+(bump?s.length:0)}return ret};Config.prototype.processIncludes=function(data,filepath,chain){var a,i,line,x,path,comma;var inserts,insert,incPath;var nd=this._nd;if(this._isDebug){this._debug("Checking for "+(chain?"sub ":"")+"@include. . .")}if((i=data.indexOf(AT_INCLUDE))<0||data.charAt(i-1)==="_"){if(this._isDebug){this._debug("No "+(chain?"sub ":"")+"@include found")}return data}inserts=[];a=data.split("\n");for(i=0;i<a.length;i++){line=a[i];x=line.indexOf(AT_INCLUDE);if(x<0){continue}path=_extractStringFromLine(line,x+AT_INCLUDE.length,this._utils);if(!path){this._error("Config - @include syntax error"+(chain?" in '"+filepath+"'":"!"));return null}incPath=nd.path.normalize(path);incPath=nd.path.resolve(this._dir,incPath);comma=_isTrailingComma(line,x+AT_INCLUDE.length,this._utils);try{if(this._isDebug){this._debug("Reading @include -> "+incPath)}insert=nd.fs.readFileSync(incPath,"utf8")}catch(e){this._error("Config @include - "+e);return null}if(!insert){this._error("Config - @include '"+incPath+"' not found!");return null}insert=this.processIncludes(insert,incPath,true);if(insert){inserts.push(i);inserts.push(insert+(comma?",":""))}else if(insert===null){return null}}if(inserts&&inserts.length){for(i=0;i<inserts.length;i++){a[inserts[i]]=inserts[++i]}}return a.join("\n")};function _extractStringFromLine(data,start,utils){var c,xEnd,wantQuote,antiQuote;start=utils.eatWhitespace(data,start);if(start<0){return null}c=data.charAt(start);wantQuote=c===QUOTE||c==="'"?c:null;if(wantQuote){antiQuote=c===QUOTE?"'":QUOTE;start++}for(xEnd=start;xEnd<data.length;xEnd++){c=data.charAt(xEnd);if(c===")"||wantQuote&&c===wantQuote){break}else if(c==="\n"||wantQuote&&c===antiQuote||!wantQuote&&(c===QUOTE||c==="'")){xEnd=-1;break}}if(xEnd<0||xEnd>=data.length||wantQuote&&data.charAt(xEnd)!==wantQuote){return null}data=data.substring(start,xEnd).trim();return data?data:null};function _isTrailingComma(s,x,utils){var n,ret=false;n=s.indexOf(")",x);if(n<0){return false}n=utils.eatWhitespace(s,n+1);if(n>=0){ret=s.charAt(n)===","}return ret};function _cloneConfig(o){return JSON.parse(JSON.stringify(o))};module.exports=Config;
|
package/lib/ConfigEx.js
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2018, 2024, Oracle and/or its affiliates.
|
|
3
|
+
* Licensed under The Universal Permissive License (UPL), Version 1.0
|
|
4
|
+
* as shown at https://oss.oracle.com/licenses/upl/
|
|
5
|
+
*/
|
|
6
|
+
const GROUPS=require("./groups");const DEFAULTS=require("./defaults");const SemVer=require("semver");const COMPOSITES="jet-composites";const TYPE_STRING="string";const TYPE_BOOLEAN="boolean";const AUTO="auto";const ERRORS="errors";const UNDEF="undefined";const NUMBER="number";const TOP_PROPS=["rulePacks","ruleMods","ruleDiscriminant","builtinJetRules","builtinCspRules","builtinSpocRules","builtinJetWcRules","builtinJetWcOracleRules","builtinOjcMigrationRules","builtinWebDriverTestRules","severity","groups","defGroups","ruleNames","base","files","exclude","typescript","jetPagesOnly","format","proseFormat","lineFormat","outPath","tabs","messages","addFileList","title","jetVer","components","componentUrls","componentOptions","jetCorePack","markdownOptions","stylesets","ecmaVer","ruleDescriptions","rulesFired","userDefs","options","comments","extends","extendOptions","nameSpaces","followLinks","tempDir","tokens","common","$JetCore","sevMap","theme","ojet","appendFileList"];const NOT_AMD=["addFileList","base","builtinJetWcRules","builtinJetWcOracleRules","builtinOjcMigrationRules","builtinWebDriverTestRules","components","componentOptions","componentUrls","extendOptions","files","exclude","followLinks","outPath","rulePacks","tempDir","tokens","typescript"];const OPTIONS_PROPS=["debug","verbose","color","msgid","ruleName","retCode","rc","ojetUpdate","experimental","$unittest"];const THEMES=["redwood","alta","stable","none"];const DEF_COMMENTS=false;const DEF_RULE_DESCRIPT="none";const DEF_GROUPS=["all"];const DEF_RETCODE="auto";const ISSUE_TAG="issueTag";const ECMA_VER=[5,6,7,8,9,10,11,12,13,14];const ECMA_YEAR=[-1,2015,2016,2017,2018,2019,2020,2021,2022,2023];function CfgEx(oConfig,nodeDeps,sevLib,utils,fsUtils,msgCtx,modeCtx){this._oConfig=oConfig;this._config=null;this._dir=null;this._sevLib=sevLib;this._extends=null;this._utils=utils;this._fsUtils=fsUtils;this._nd=nodeDeps;this._msgCtx=msgCtx;this._modeCtx=modeCtx;this._isVerbose=msgCtx.isVerbose;this._isCLI=modeCtx.isCLI||modeCtx.isOJETCLI;this._error=msgCtx.error;this._warn=msgCtx.warn;this._info=msgCtx.info};CfgEx.prototype.setDebugStatus=function(verbose,debug){this._isVerbose=this._msgCtx.isVerbose=verbose};CfgEx.prototype.processWebComponents=function(){var dir,o,t,i;var config=this._config;if(config.componentUrlBase){if(!typeof config.componentUrlBase===TYPE_STRING){this._error("Config entry 'componentUrlBase' must be a string!");return false}}if(config.componentUrls){if(typeof config.componentUrls===TYPE_STRING){config.componentUrls=[config.componentUrls]}else if(!Array.isArray(config.componentUrls)){this._error("Config entry 'componentUrls' must be a string or an aray of strings!");return false}for(i=0;i<this._config.componentUrls.length;i++){config.componentUrls[i]=config.componentUrls[i].trim();if(config.componentUrls[i].length===0){config.componentUrls.splice(i,1);i--}}}if(!config.components){if(this._isCLI&&!this._isOJET&&this._experimentalSet){dir=this._findCompositesDir(config.base);if(dir){config.components=[];config.components.push(this._nd.path.join(dir,COMPOSITES))}}}if(config.components){if(typeof config.components===TYPE_STRING){config.components=[config.components]}else if(!Array.isArray(config.components)){this._error("Config entry 'components' must be a string or an array of strings!");return false}for(i=0;i<config.components.length;i++){config.components[i]=config.components[i].trim();if(config.components[i].length===0){config.components.splice(i,1);i--}}}if(config.components&&config.components.length||config.componentUrls&&config.componentUrls.length){o=config.componentOptions;if(o){if(!this._utils.isObject(o)){this._error("Config 'components' sub-property 'componentOptions' must be an Object!");return false}t=typeof o.applySchema;if(t==="undefined"){o.applySchema=true}else if(t!=="boolean"){this._error("Config 'components' sub-property 'componentOptions' must be an Object!");return false}}}return true};CfgEx.prototype.processJetCorePack=function(){var config=this._config;var ret=true;if(!config.hasOwnProperty("jetCorePack")){return ret}let t=typeof config.jetCorePack;if(t===TYPE_BOOLEAN){if(config.jetCorePack){this._error("Config 'jetCorePack' property value cannot be boolean true!");ret=false}return ret}if(SemVer.lt(config.jetVer,"13.0.0")){this._error("Config 'jetCorePack' is valid for 'jetVer' values >= 13.0.0 only");ret=false}if(t!==TYPE_STRING){this._error("Config 'jetCorePack' property is not a string or a boolean!");ret=false}return ret};CfgEx.prototype.processTypeScript=function(){var ts,ret=true;if(this._config.hasOwnProperty("typescript")){ts=this._config.typescript;if(!this._utils.isObject(ts)){this._error("Config 'typescript' property is not an object!");ret=false}if(ts.hasOwnProperty("compile")){if(typeof ts.compile!=="boolean"){this._error("Config 'typescript' sub-property 'compile' is not a boolean!");ret=false}}if(ts.hasOwnProperty("tsconfig")){if(typeof ts.tsconfig!=="string"){this._error("Config 'typescript' sub-property 'tsconfig' must be a directory string!");ret=false}}}return ret};CfgEx.prototype.processRulePacks=function(){var packs,pack,i;var config=this._config;if(config.rulePacks){packs=this._config.rulePacks;if(!Array.isArray(packs)){this._error("Config entry 'rulePacks' is not an array!");return false}for(i=0;i<packs.length;i++){pack=packs[i];if(typeof pack!==TYPE_BOOLEAN){pack.enabled=true}if(!pack.path){this._error(`Config entry 'rulePacks' (entry ${i+1}) does not have a 'path' entry!`);return false}else{pack.path=pack.path.trim()}if(pack.status&&!Array.isArray(pack)){this._error(`Config entry 'rulePacks' (entry ${i+1}) 'status' property is not an array!`);return false}}}else{config.rulePacks=[]}return true};CfgEx.prototype.processRuleMods=function(cfg,fp){var mods,mod,val,rule;var config=cfg?cfg:this._config;const MSG="Config 'ruleMods' sub-property '${mod}' is not an array of rule names or group names";var self=this,b;if(!config.ruleMods){return true}function _emitRMError(s){s+=fp?` - in ${fp}`:"";self._error(s);b=true}mods=config.ruleMods;if(!this._utils.isObject(mods)){_emitRMError("Configuration property 'ruleMods' is not an object");return false}for(mod in mods){if(mod==="enabled"){_emitRMError("Config 'ruleMods' : invalid sub-property 'enabled' - did you mean 'enable'?")}else if(mod==="disabled"){_emitRMError("Config 'ruleMods' : invalid sub-property 'disabled' - did you mean 'disable'?")}if(b){return!b}val=mods[mod];if(mod==="enable"||mod==="disable"){if(!Array.isArray(val)){_emitRMError(this._utils.format(MSG,{mod:mod}))}if(!this._utils.isArrayContentsType(val,"string")){_emitRMError(this._utils.format(MSG,{mod:mod}))}}else{if(!this._utils.isObject(val)){_emitRMError(`Config 'ruleMods' sub-property '${mod}' is not an object!`)}else{for(rule in val){let o=val[rule];if(o.hasOwnProperty(ISSUE_TAG)){if(typeof o.issueTag!=="string"){_emitRMError(`Config 'ruleMods' for '${mod}' rule '${rule}' : '${ISSUE_TAG}' is not a string`)}}};}}}if(!b&&mods.enable&&mods.disable){mods.enable.forEach(function(r){if(mods.disable.includes(r)){_emitRMError(`Config 'ruleMods': 'enable' & 'disable' conflicting entry '${r}'`)}})}return!b};CfgEx.prototype.processFormat=function(){var config=this._config;if(config.format){if(config.format!=="json"&&config.format!=="prose"&&config.format!=="line"){this._error(`Config entry 'format' '${config.format}' not valid. Must be 'json', 'prose' or 'line'!`);return false}}return true};CfgEx.prototype.processProseFormat=function(){var config=this._config;if(config.proseFormat){if(typeof config.proseFormat==="string"){if(config.format!=="prose"){this._warn("Config entry 'proseFormat' ignored - not applicable if 'format is not 'prose'!")}}else{this._error(`Config entry 'proseFormat' '${config.proseFormat}' is not valid!`);return false}}return true};CfgEx.prototype.processLineFormat=function(){var config=this._config;if(config.lineFormat){if(typeof config.lineFormat==="string"){if(config.format!=="line"){this._warn("Config entry 'lineFormat' ignored - not applicable if 'format is not 'line'!")}}else{this._error(`Config entry 'lineFormat' '${config.lineFormat}' is not valid!`);return false}}return true};CfgEx.prototype.processRuleDescriptions=function(){var val,valType;var config=this._config;if(config.ruleDescriptions){val=config.ruleDescriptions;valType=typeof val;if(valType!=="string"||val!="all"&&val!=="short"&&val!=="long"&&val!=="none"){this._error(`Config entry 'ruleDescriptions' '${val}' is not valid!`);return false}}else{config.ruleDescriptions=DEF_RULE_DESCRIPT}return true};CfgEx.prototype.processRulesFired=function(){var config=this._config;if(config.rulesFired){if(!this._modeCtx.isAPI&&!this._modeCtx.isAMD&&(!config.format||config.format!=="json")){this._error(`Config entry 'rulesFired' - API/AMD mode required, or 'format' property set to 'json' for CLI mode!`);return false}}return true};CfgEx.prototype.processSevMap=function(){var config=this._config;var set,sev,msgs,inv,mapped,val,b,error;if(!config.sevMap){return true}set=config.sevMap.sevSet;if(set){b=error=false;for(val in set){if(!this._sevLib.isValidConfigSeverity(val)){this._error(`Config entry 'sevMap' sub-property 'sevSet' value '${val}' is not 'blocker/critical/major/minor/info'!`);error=true;continue}if(val==="all"){this._error("Config entry 'sevMap' sub-property 'sevSet' - pseudo severity 'all' cannot be remapped!");error=true;continue}if(typeof set[val]!=="string"){this._error(`Config entry 'sevMap' sub-property 'sevSet' value '${val}' is not a string!`);error=true;continue}b=true}if(error){return false}if(b){inv={};for(sev in set){mapped=set[sev];if(inv[mapped]){if(!Array.isArray(inv[mapped])){inv[mapped]=[inv[mapped]]}inv[mapped].push(sev)}else{inv[mapped]=sev}}this._sevLib.setSevMap(config.sevMap,inv)}else{config.sevMap.sevSet=null}}msgs=config.sevMap.sevMsg;if(msgs){if(!this._utils.isObject(msgs)){this._error("Config entry 'sevMap' sub-property 'sevMsg' is not an object!");return false}b=error=false;for(val in msgs){sev=msgs[val];if(typeof sev!=="string"){this._error(`Config entry 'sevMap' sub-property 'sevMsg' : '${val}' is not a string!`);error=true;continue}if(!this._sevLib.isSev(sev)){this._error(`Config entry 'sevMap' sub-property 'sevMsg' : '${sev}' is ${UNDEF}!`);error=true;continue}b=true}if(error){return false}if(b){this._sevLib.setSevMsg(msgs)}else{config.sevMap.sevMsg=null}}else{b=true;for(val in config.sevMap){if(val!=="sevSet"&&val!=="sevMsg"){this._error(`Config entry 'sevMap' unknown sub-property '${val}'!`);b=false}}if(!b){return false}}return true};CfgEx.prototype.processSeverity=function(cliSev){var config=this._config;var val,se,i;if(cliSev){config.severity=cliSev}if(config.severity){val=config.severity;if(typeof val==="string"){se=this._sevLib.getSevExpr(val);if(!this._sevLib.isValidConfigSeverity(val)){if(se.op&&se.sev==="all"){this._error(`Config entry 'severity' ('${val}') : 'all' cannot be used with a severity expression !`)}else if(cliSev){this._error(`command line --severity '${val}' is not 'major/minor/blocker/critical/info', 'all', or a remapped severity!`)}else{this._error(`Config entry 'severity' ('${val}') is not 'major/minor/blocker/critical/info', 'all', or a remapped severity!`)}return false}this._sevLib.setSevExpr(se)}else if(Array.isArray(val)&&this._utils.isArrayContentsType(val,"string")){for(i=0;i<val.length;i++){if(!this._sevLib.isValidConfigSeverity(val[i])){this._error(`Config entry 'severity' ('${val[i]}') is not 'major/minor/blocker/critical/info', 'all', or a remapped severity!`);return false}}}else{this._error("Config entry 'severity' is invalid!");return false}}else{config.severity=this._sevLib.ALL;this._sevLib.setSevExpr(this._sevLib.getSevExpr(this._sevLib.ALL))}return true};CfgEx.prototype.processGroups=function(cliGroups){var group,i;var config=this._config;if(cliGroups){config.groups=cliGroups}if(!config.groups){config.groups=DEF_GROUPS;return true}if(!Array.isArray(config.groups)){config.groups=[config.groups]}if(config.groups.length===0){config.groups.push("all")}else{for(i=0;i<config.groups.length;i++){group=config.groups[i];if(!GROUPS.isGroup(group)){if(group.startsWith("jet-")||group.startsWith("htm")){this._error(`Config 'groups' entry '${group}' is not defined!`);return false}}}}return true};CfgEx.prototype.processDefGroups=function(){var config=this._config;if(config.defGroups){if(!this._utils.isObject(config.defGroups)){this._error("Config entry 'defGroups' is not an object!");return false}}else{config.defGroups=null}return true};CfgEx.prototype.processRuleNames=function(){var config=this._config;if(config.ruleNames){if(!Array.isArray(config.ruleNames)){this._error("Config entry 'ruleNames' is not an array!");return false}}return true};CfgEx.prototype.processTheme=function(){var t,config=this._config;t=config.theme;if(t){t=t.toLowerCase();if(typeof t==="string"){if(!THEMES.includes(t)){this._error(`Invalid config theme '${t}' : must be 'Redwood', 'Alta', 'Stable' or 'none'`);return false}}else{this._error("Config entry 'theme' is not a string!");return false}if(t==="stable"){t="redwood"};config.theme=t.charAt(0).toUpperCase()+t.substring(1)}else{config.theme=SemVer.gte(config.jetVer,"12.0.0")?"Redwood":DEFAULTS.THEME;if(this._isVerbose){this._info(`[Info]: Default theme '${config.theme}' applied for jetVer ${config.jetVer}`)}}return true};CfgEx.prototype.processComments=function(){var t,config=this._config;t=typeof config.comments;if(t===UNDEF){config.comments=DEF_COMMENTS}else if(t!=="boolean"){this._error("Invalid 'comments' property - expected a boolean");return false}return true};CfgEx.prototype.processMarkdownOpts=function(){var config=this._config;var val=config.markdownOptions;var t=typeof val;if(t===UNDEF){config.markdownOptions={linkify:true}}else if(Array.isArray(val)||t!=="object"){this._error("Invalid 'markdownOptions' property - expected an object");return false}else{t=typeof val.linkify;if(t==="undefined"){val.linkify=true}else if(typeof val.linkify!=="boolean"){this._error("Invalid 'markdownOptions.linkify' - expected a boolean");return false}let n=Object.keys(val);if(!val.hasOwnProperty("linkify")){if(n.length){this._error("Invalid 'markdownOptions.linkify' - expected a boolean");return false}else{val.linkify=true}}else if(n.length>1){this._error("Invalid 'markdownOptions' properties found");return false}}return true};CfgEx.prototype.processEcmaVer=function(){var val,config=this._config;if(config.ecmaVer){val=config.ecmaVer;if(typeof val==="string"){if(val.substring(0,2).toLowerCase()==="es"){val=val.substring(2)}val=parseInt(val);if(isNaN(val)){val=0}}if(typeof val===NUMBER){if(!(ECMA_VER.includes(val)||ECMA_YEAR.includes(val))){this._error(`Config 'ecmaVer: ${config.ecmaVer}' is not in the version range ${ECMA_VER[0]}-${ECMA_VER[ECMA_VER.length-1]} or the year range ${ECMA_YEAR[1]}-${ECMA_YEAR[ECMA_YEAR.length-1]}!`);return false}}if(val>=2015){val=ECMA_YEAR.indexOf(val);config.ecmaVer=ECMA_VER[val]}else{config.ecmaVer=val}}else{config.ecmaVer=DEFAULTS.ECMAVER}return true};CfgEx.prototype.processMessages=function(){var val,config=this._config;if(config.messages){val=config.messages;if(!this._utils.isObject(val)){this._error("Config entry 'messages' is not an object!");return false}if(val.accept&&val.reject){this._error("Config entry 'messages' - 'accept' and 'reject' are mutually exclusive!");return false}if(val.accept){if(!Array.isArray(val.accept)){this._error("Config entry 'messages.accept' is not an array!");return false}else if(!this._utils.isArrayContentsType(val.accept,"string")){this._error("Config entry 'messages.accept' property array does not contain all strings");return false}}if(val.reject){if(!Array.isArray(val.reject)){this._error("Config entry 'messages.reject' is not an array!");return false}else if(!this._utils.isArrayContentsType(val.reject,"string")){this._error("Config entry 'messages.reject' property array does not contain all strings");return false}}}return true};CfgEx.prototype.processAddFileList=function(){var config=this._config;if(config.appendFileList){this._appendFileList=true;this._warn("Configuration property 'appendFileList' : change to 'addFileList'")}else if(config.addFileList){this._addFileList=true}return true};CfgEx.prototype.processNameSpaces=function(){var config,nsp,ns,e;config=this._config;if(!config.nameSpaces){return true}if(!Array.isArray(config.nameSpaces)){config.nameSpaces=[config.nameSpaces]}nsp=config.nameSpaces;for(let i=0;i<nsp.length;i++){ns=nsp[i];if(!ns||typeof ns!=="string"){this._error(`Config 'nameSpaces' entry "${ns}" at index ${i} is not a valid namespace`);e=true}else if(ns.startsWith("oj-")||ns.startsWith("ns-")){this._error(`Config 'nameSpaces' entry '${ns}' must not use reserved JET prefix ${ns.substring(0,3)}`);e=true}}return e?false:true};CfgEx.prototype.processOptions=function(){var prop,opts,config=this._config,isCLI=this._modeCtx.isCLI||this._modeCtx.isOJETCLI;if(config.options){opts=config.options;for(prop in opts){if(!OPTIONS_PROPS.includes(prop)){this._error(`Config - unknown 'options' sub-property '${prop}'`);return false}else if((prop==="retCode"||prop==="rc")&&!isCLI){this._error(`Config - 'options' property '${prop}' is valid in CLI mode only`);return false}}}return true};CfgEx.prototype.processExtends=function(){var config=this._config;var ext;if(this._modeCtx.isAMD){if(ext=config.extends){if(typeof ext==="string"){this._error("Config use of non-profile 'extends' property is not supported in AMD mode.");return false}}if(config.extendOptions){this._error("Config use of 'extendOptions' property is not supported in AMD mode.");return false}}if(this._config.extendOptions){if(!this._utils.isObject(this._config.extendOptions)){this._error("Config 'extendOptions' is not an object.");return false}}this._extends=this._config?.extends?.profile;var extLib=new this._nd.extends(this,this._oConfig,config,this._path,this._nd,this._msgCtx,this._utils,this._fsUtils,this._modeCtx.isAMD);var cfg=extLib.extend();return cfg};CfgEx.prototype.processTitle=function(){var t,config=this._config;if(config.title){t=this._utils.getType(config.title);if(t!=="string"&&t!=="array"){this._error(`Config entry 'title has incorrect type ('${t}')`);return false}}return true};CfgEx.prototype.processRetCode=function(){var rc,prop,ret,config=this._config;if(config.options){prop=typeof config.options.retCode!==UNDEF?"retCode":typeof config.options.rc!==UNDEF?"rc":null;if(prop){rc=config.options[prop];ret=this.validateRetCode(rc,sev=>{this._error(`Config entry 'options.${prop}' : unknown severity '${sev}'`)});if(ret||typeof ret==="number"){config.options[prop]=ret}else{config.options[prop]=AUTO;return false}}}if(!prop){if(!config.options){config.options={}}config.options.retCode=DEF_RETCODE}return true};CfgEx.prototype.processRuleDiscriminant=function(){var rd,config=this._config;if(!config.hasOwnProperty("ruleDiscriminant")){return true}if(typeof(rd=config.ruleDiscriminant)!=="string"){this._error("`Config entry 'ruleDiscriminant' : expected a string");return false}if(rd!=="redwood-strict"){this._error(`Config entry 'ruleDiscriminant' : invalid value '${rd}'`);return false}return true};CfgEx.prototype.validateFileList=function(aFiles){var i,j,f,msg,ret=true;;for(i=0;i<aFiles.length;i++){f=aFiles[i];if(typeof f==="string"){continue}if(!this._utils.isObject(f)){msg=" property entry "+(i+1)+" is not a string or an object";break}if(f.files){if(!(Array.isArray(f.files)&&this._utils.isArrayContentsType(f.files,"string"))){msg=" property entry "+(i+1)+" does not contain a 'files' property array, or not all elements are strings";break}}else{msg=" property entry "+(i+1)+", does not contain a 'files' property";break}if(!f.base){msg=" property entry "+(i+1)+" does not contain a 'base' property";break}for(j=0;j<f.files.length;j++){f.files[j]=this._nd.path.join(f.base,f.files[j])}}if(!msg){for(i=0;i<aFiles.length;i++){f=aFiles[i];if(this._utils.isObject(f)){aFiles.splice(i,1,...f.files)}}}if(msg){this._error(msg);ret=false}return ret};CfgEx.prototype.validateRetCode=function(val,cb){var t,i,b;t=typeof val;if(t==="number"||t==="string"&&val===DEF_RETCODE||val===ERRORS){return val}if(t==="string"){if(!this._sevLib.isSev(val)){cb(val);return false}else{return this._sevLib.unmap(val)}}if(Array.isArray(val)){b=true;for(i=0;i<val.length;i++){if(!this._sevLib.isSev(val[i])){cb(val[i]);b=false}else{val[i]=this._sevLib.unmap(val[i])}}if(b){for(i=0;i<val.length;i++){if(Array.isArray(val[i])){let ar=[];for(i=0;i<val.length;i++){ar=ar.concat(val[i])}val=ar;break}}return val}}return false};CfgEx.prototype.setMessages=function(msgid,state){var accept,reject,msgs,target,changed=false,i;var config=this._config;msgs=config.messages;state=!!state;if(!msgs){if(!state){config.messages={reject:[msgid]};changed=true}}else{reject=msgs.reject;accept=msgs.accept;target=accept||reject;i=target?target.indexOf(msgid):-1;if(state){if(!accept&&!reject){msgs.accept=accept=[]}if(reject){if(i>=0){reject.splice(i,1);changed=true;if(reject.length===0){delete msgs.reject}}}else if(accept){if(i<0){accept.push(msgid);changed=true}}}else{if(!accept&&!reject){msgs.reject=reject=[]}if(reject){if(i<0){reject.push(msgid);changed=true}}else if(accept){if(i>=0){accept.splice(i,1);if(accept.length===0){delete msgs.accept}changed=true}}}}return changed};CfgEx.prototype.getAddFileList=function(){return!!(this._addFileList||this._appendFileList)};CfgEx.prototype.checkPropNames=function(cfg,path){var prop,ret=true,config=cfg?cfg:this._config;path=path||this._path;for(prop in config){if(!TOP_PROPS.includes(prop)){if(prop.charAt(0)==="_"){delete config[prop];continue}this._error(`Config - unknown property '${prop}' ${path?"- "+path:""}`);ret=false}else if(this._modeCtx.isAMD&&NOT_AMD.includes(prop)){this._error(`Config - property '${prop}' is not available in AMD mode!`);ret=false}}return ret};CfgEx.prototype.getExtendsProfileName=function(){return this._extends};CfgEx.prototype.setConfig=function(cfg,cfgPath,dir){this._config=cfg;this._path=cfgPath;this._dir=dir};CfgEx.prototype._findCompositesDir=function(base){return this._fsUtils.findFile(base,COMPOSITES)};module.exports=CfgEx;
|
package/lib/ConfigLib.js
CHANGED
|
@@ -3,4 +3,4 @@
|
|
|
3
3
|
* Licensed under The Universal Permissive License (UPL), Version 1.0
|
|
4
4
|
* as shown at https://oss.oracle.com/licenses/upl/
|
|
5
5
|
*/
|
|
6
|
-
const GROUPS=require("./groups");const DEFAULTS=require("./defaults");const SemVer=require("semver");const COMPOSITES="jet-composites";const TYPE_STRING="string";const TYPE_BOOLEAN="boolean";const AUTO="auto";const ERRORS="errors";const UNDEF="undefined";const NUMBER="number";const TOP_PROPS=["rulePacks","ruleMods","builtinJetRules","builtinCspRules","builtinSpocRules","builtinJetWcRules","builtinJetWcOracleRules","builtinOjcMigrationRules","builtinWebDriverTestRules","severity","groups","defGroups","ruleNames","base","files","exclude","typescript","jetPagesOnly","format","proseFormat","lineFormat","outPath","tabs","messages","addFileList","title","jetVer","components","componentUrls","componentOptions","jetCorePack","markdownOptions","stylesets","ecmaVer","ruleDescriptions","rulesFired","userDefs","options","comments","extends","extendOptions","nameSpaces","followLinks","tempDir","tokens","common","$JetCore","sevMap","theme","ojet","appendFileList"];const NOT_AMD=["addFileList","base","builtinJetWcRules","builtinJetWcOracleRules","builtinOjcMigrationRules","builtinWebDriverTestRules","components","componentOptions","componentUrls","extendOptions","files","exclude","followLinks","outPath","rulePacks","tempDir","tokens","typescript"];const OPTIONS_PROPS=["debug","verbose","color","msgid","ruleName","retCode","rc","ojetUpdate","experimental","$unittest"];const THEMES=["redwood","alta","stable","none"];const DEF_COMMENTS=false;const DEF_RULE_DESCRIPT="none";const DEF_GROUPS=["all"];const DEF_RETCODE="auto";const ISSUE_TAG="issueTag";const ECMA_VER=[5,6,7,8,9,10,11,12,13,14];const ECMA_YEAR=[-1,2015,2016,2017,2018,2019,2020,2021,2022,2023];function CfgLib(oConfig,nodeDeps,sevLib,utils,fsUtils,msgCtx,modeCtx){this._oConfig=oConfig;this._config=null;this._dir=null;this._sevLib=sevLib;this._utils=utils;this._fsUtils=fsUtils;this._nd=nodeDeps;this._msgCtx=msgCtx;this._modeCtx=modeCtx;this._isVerbose=msgCtx.isVerbose;this._isCLI=modeCtx.isCLI||modeCtx.isOJETCLI;this._error=msgCtx.error;this._warn=msgCtx.warn;this._info=msgCtx.info};CfgLib.prototype.setDebugStatus=function(verbose,debug){this._isVerbose=this._msgCtx.isVerbose=verbose};CfgLib.prototype.processWebComponents=function(){var dir,o,t,i;var config=this._config;if(config.componentUrlBase){if(!typeof config.componentUrlBase===TYPE_STRING){this._error("Config entry 'componentUrlBase' must be a string!");return false}}if(config.componentUrls){if(typeof config.componentUrls===TYPE_STRING){config.componentUrls=[config.componentUrls]}else if(!Array.isArray(config.componentUrls)){this._error("Config entry 'componentUrls' must be a string or an aray of strings!");return false}for(i=0;i<this._config.componentUrls.length;i++){config.componentUrls[i]=config.componentUrls[i].trim();if(config.componentUrls[i].length===0){config.componentUrls.splice(i,1);i--}}}if(!config.components){if(this._isCLI&&!this._isOJET&&this._experimentalSet){dir=this._findCompositesDir(config.base);if(dir){config.components=[];config.components.push(this._nd.path.join(dir,COMPOSITES))}}}if(config.components){if(typeof config.components===TYPE_STRING){config.components=[config.components]}else if(!Array.isArray(config.components)){this._error("Config entry 'components' must be a string or an array of strings!");return false}for(i=0;i<config.components.length;i++){config.components[i]=config.components[i].trim();if(config.components[i].length===0){config.components.splice(i,1);i--}}}if(config.components&&config.components.length||config.componentUrls&&config.componentUrls.length){o=config.componentOptions;if(o){if(!this._utils.isObject(o)){this._error("Config 'components' sub-property 'componentOptions' must be an Object!");return false}t=typeof o.applySchema;if(t==="undefined"){o.applySchema=true}else if(t!=="boolean"){this._error("Config 'components' sub-property 'componentOptions' must be an Object!");return false}}}return true};CfgLib.prototype.processJetCorePack=function(){var config=this._config;var ret=true;if(!config.hasOwnProperty("jetCorePack")){return ret}let t=typeof config.jetCorePack;if(t===TYPE_BOOLEAN){if(config.jetCorePack){this._error("Config 'jetCorePack' property value cannot be boolean true!");ret=false}return ret}if(SemVer.lt(config.jetVer,"13.0.0")){this._error("Config 'jetCorePack' is valid for 'jetVer' values >= 13.0.0 only");ret=false}if(t!==TYPE_STRING){this._error("Config 'jetCorePack' property is not a string or a boolean!");ret=false}return ret};CfgLib.prototype.processTypeScript=function(){var ts,ret=true;if(this._config.hasOwnProperty("typescript")){ts=this._config.typescript;if(!this._utils.isObject(ts)){this._error("Config 'typescript' property is not an object!");ret=false}if(ts.hasOwnProperty("compile")){if(typeof ts.compile!=="boolean"){this._error("Config 'typescript' sub-property 'compile' is not a boolean!");ret=false}}if(ts.hasOwnProperty("tsconfig")){if(typeof ts.tsconfig!=="string"){this._error("Config 'typescript' sub-property 'tsconfig' must be a directory string!");ret=false}}}return ret};CfgLib.prototype.processRulePacks=function(){var packs,pack,i;var config=this._config;if(config.rulePacks){packs=this._config.rulePacks;if(!Array.isArray(packs)){this._error("Config entry 'rulePacks' is not an array!");return false}for(i=0;i<packs.length;i++){pack=packs[i];if(typeof pack!==TYPE_BOOLEAN){pack.enabled=true}if(!pack.path){this._error(`Config entry 'rulePacks' (entry ${i+1}) does not have a 'path' entry!`);return false}else{pack.path=pack.path.trim()}if(pack.status&&!Array.isArray(pack)){this._error(`Config entry 'rulePacks' (entry ${i+1}) 'status' property is not an array!`);return false}}}else{config.rulePacks=[]}return true};CfgLib.prototype.processRuleMods=function(cfg,fp){var mods,mod,val,rule;var config=cfg?cfg:this._config;const MSG="Config 'ruleMods' sub-property '${mod}' is not an array of rule names or group names";var self=this,b;if(!config.ruleMods){return true}function _emitRMError(s){s+=fp?` - in ${fp}`:"";self._error(s);b=true}mods=config.ruleMods;if(!this._utils.isObject(mods)){_emitRMError("Configuration property 'ruleMods' is not an object");return false}for(mod in mods){if(mod==="enabled"){_emitRMError("Config 'ruleMods' : invalid sub-property 'enabled' - did you mean 'enable'?")}else if(mod==="disabled"){_emitRMError("Config 'ruleMods' : invalid sub-property 'disabled' - did you mean 'disable'?")}if(b){return!b}val=mods[mod];if(mod==="enable"||mod==="disable"){if(!Array.isArray(val)){_emitRMError(this._utils.format(MSG,{mod:mod}))}if(!this._utils.isArrayContentsType(val,"string")){_emitRMError(this._utils.format(MSG,{mod:mod}))}}else{if(!this._utils.isObject(val)){_emitRMError(`Config 'ruleMods' sub-property '${mod}' is not an object!`)}else{for(rule in val){let o=val[rule];if(o.hasOwnProperty(ISSUE_TAG)){if(typeof o.issueTag!=="string"){_emitRMError(`Config 'ruleMods' for '${mod}' rule '${rule}' : '${ISSUE_TAG}' is not a string`)}}};}}}if(!b&&mods.enable&&mods.disable){mods.enable.forEach(function(r){if(mods.disable.includes(r)){_emitRMError(`Config 'ruleMods': 'enable' & 'disable' conflicting entry '${r}'`)}})}return!b};CfgLib.prototype.processFormat=function(){var config=this._config;if(config.format){if(config.format!=="json"&&config.format!=="prose"&&config.format!=="line"){this._error(`Config entry 'format' '${config.format}' not valid. Must be 'json', 'prose' or 'line'!`);return false}}return true};CfgLib.prototype.processProseFormat=function(){var config=this._config;if(config.proseFormat){if(typeof config.proseFormat==="string"){if(config.format!=="prose"){this._warn("Config entry 'proseFormat' ignored - not applicable if 'format is not 'prose'!")}}else{this._error(`Config entry 'proseFormat' '${config.proseFormat}' is not valid!`);return false}}return true};CfgLib.prototype.processLineFormat=function(){var config=this._config;if(config.lineFormat){if(typeof config.lineFormat==="string"){if(config.format!=="line"){this._warn("Config entry 'lineFormat' ignored - not applicable if 'format is not 'line'!")}}else{this._error(`Config entry 'lineFormat' '${config.lineFormat}' is not valid!`);return false}}return true};CfgLib.prototype.processRuleDescriptions=function(){var val,valType;var config=this._config;if(config.ruleDescriptions){val=config.ruleDescriptions;valType=typeof val;if(valType!=="string"||val!="all"&&val!=="short"&&val!=="long"&&val!=="none"){this._error(`Config entry 'ruleDescriptions' '${val}' is not valid!`);return false}}else{config.ruleDescriptions=DEF_RULE_DESCRIPT}return true};CfgLib.prototype.processRulesFired=function(){var config=this._config;if(config.rulesFired){if(!this._modeCtx.isAPI&&!this._modeCtx.isAMD&&(!config.format||config.format!=="json")){this._error(`Config entry 'rulesFired' - API/AMD mode required, or 'format' property set to 'json' for CLI mode!`);return false}}return true};CfgLib.prototype.processSevMap=function(){var config=this._config;var set,sev,msgs,inv,mapped,val,b,error;if(!config.sevMap){return true}set=config.sevMap.sevSet;if(set){b=error=false;for(val in set){if(!this._sevLib.isValidConfigSeverity(val)){this._error(`Config entry 'sevMap' sub-property 'sevSet' value '${val}' is not 'blocker/critical/major/minor/info'!`);error=true;continue}if(val==="all"){this._error("Config entry 'sevMap' sub-property 'sevSet' - pseudo severity 'all' cannot be remapped!");error=true;continue}if(typeof set[val]!=="string"){this._error(`Config entry 'sevMap' sub-property 'sevSet' value '${val}' is not a string!`);error=true;continue}b=true}if(error){return false}if(b){inv={};for(sev in set){mapped=set[sev];if(inv[mapped]){if(!Array.isArray(inv[mapped])){inv[mapped]=[inv[mapped]]}inv[mapped].push(sev)}else{inv[mapped]=sev}}this._sevLib.setSevMap(config.sevMap,inv)}else{config.sevMap.sevSet=null}}msgs=config.sevMap.sevMsg;if(msgs){if(!this._utils.isObject(msgs)){this._error("Config entry 'sevMap' sub-property 'sevMsg' is not an object!");return false}b=error=false;for(val in msgs){sev=msgs[val];if(typeof sev!=="string"){this._error(`Config entry 'sevMap' sub-property 'sevMsg' : '${val}' is not a string!`);error=true;continue}if(!this._sevLib.isSev(sev)){this._error(`Config entry 'sevMap' sub-property 'sevMsg' : '${sev}' is ${UNDEF}!`);error=true;continue}b=true}if(error){return false}if(b){this._sevLib.setSevMsg(msgs)}else{config.sevMap.sevMsg=null}}else{b=true;for(val in config.sevMap){if(val!=="sevSet"&&val!=="sevMsg"){this._error(`Config entry 'sevMap' unknown sub-property '${val}'!`);b=false}}if(!b){return false}}return true};CfgLib.prototype.processSeverity=function(cliSev){var config=this._config;var val,se,i;if(cliSev){config.severity=cliSev}if(config.severity){val=config.severity;if(typeof val==="string"){se=this._sevLib.getSevExpr(val);if(!this._sevLib.isValidConfigSeverity(val)){if(se.op&&se.sev==="all"){this._error(`Config entry 'severity' ('${val}') : 'all' cannot be used with a severity expression !`)}else if(cliSev){this._error(`command line --severity '${val}' is not 'major/minor/blocker/critical/info', 'all', or a remapped severity!`)}else{this._error(`Config entry 'severity' ('${val}') is not 'major/minor/blocker/critical/info', 'all', or a remapped severity!`)}return false}this._sevLib.setSevExpr(se)}else if(Array.isArray(val)&&this._utils.isArrayContentsType(val,"string")){for(i=0;i<val.length;i++){if(!this._sevLib.isValidConfigSeverity(val[i])){this._error(`Config entry 'severity' ('${val[i]}') is not 'major/minor/blocker/critical/info', 'all', or a remapped severity!`);return false}}}else{this._error("Config entry 'severity' is invalid!");return false}}else{config.severity=this._sevLib.ALL;this._sevLib.setSevExpr(this._sevLib.getSevExpr(this._sevLib.ALL))}return true};CfgLib.prototype.processGroups=function(cliGroups){var group,i;var config=this._config;if(cliGroups){config.groups=cliGroups}if(!config.groups){config.groups=DEF_GROUPS;return true}if(!Array.isArray(config.groups)){config.groups=[config.groups]}if(config.groups.length===0){config.groups.push("all")}else{for(i=0;i<config.groups.length;i++){group=config.groups[i];if(!GROUPS.isGroup(group)){if(group.startsWith("jet-")||group.startsWith("htm")){this._error(`Config 'groups' entry '${group}' is not defined!`);return false}}}}return true};CfgLib.prototype.processDefGroups=function(){var config=this._config;if(config.defGroups){if(!this._utils.isObject(config.defGroups)){this._error("Config entry 'defGroups' is not an object!");return false}}else{config.defGroups=null}return true};CfgLib.prototype.processRuleNames=function(){var config=this._config;if(config.ruleNames){if(!Array.isArray(config.ruleNames)){this._error("Config entry 'ruleNames' is not an array!");return false}}return true};CfgLib.prototype.processTheme=function(){var t,config=this._config;t=config.theme;if(t){t=t.toLowerCase();if(typeof t==="string"){if(!THEMES.includes(t)){this._error(`Invalid config theme '${t}' : must be 'Redwood', 'Alta', 'Stable' or 'none'`);return false}}else{this._error("Config entry 'theme' is not a string!");return false}if(t==="stable"){t="redwood"};config.theme=t.charAt(0).toUpperCase()+t.substring(1)}else{config.theme=SemVer.gte(config.jetVer,"12.0.0")?"Redwood":DEFAULTS.THEME;if(this._isVerbose){this._info(`[Info]: Default theme '${config.theme}' applied for jetVer ${config.jetVer}`)}}return true};CfgLib.prototype.processComments=function(){var t,config=this._config;t=typeof config.comments;if(t===UNDEF){config.comments=DEF_COMMENTS}else if(t!=="boolean"){this._error("Invalid 'comments' property - expected a boolean");return false}return true};CfgLib.prototype.processMarkdownOpts=function(){var config=this._config;var val=config.markdownOptions;var t=typeof val;if(t===UNDEF){config.markdownOptions={linkify:true}}else if(Array.isArray(val)||t!=="object"){this._error("Invalid 'markdownOptions' property - expected an object");return false}else{t=typeof val.linkify;if(t==="undefined"){val.linkify=true}else if(typeof val.linkify!=="boolean"){this._error("Invalid 'markdownOptions.linkify' - expected a boolean");return false}let n=Object.keys(val);if(!val.hasOwnProperty("linkify")){if(n.length){this._error("Invalid 'markdownOptions.linkify' - expected a boolean");return false}else{val.linkify=true}}else if(n.length>1){this._error("Invalid 'markdownOptions' properties found");return false}}return true};CfgLib.prototype.processEcmaVer=function(){var val,config=this._config;if(config.ecmaVer){val=config.ecmaVer;if(typeof val==="string"){if(val.substring(0,2).toLowerCase()==="es"){val=val.substring(2)}val=parseInt(val);if(isNaN(val)){val=0}}if(typeof val===NUMBER){if(!(ECMA_VER.includes(val)||ECMA_YEAR.includes(val))){this._error(`Config 'ecmaVer: ${config.ecmaVer}' is not in the version range ${ECMA_VER[0]}-${ECMA_VER[ECMA_VER.length-1]} or the year range ${ECMA_YEAR[1]}-${ECMA_YEAR[ECMA_YEAR.length-1]}!`);return false}}if(val>=2015){val=ECMA_YEAR.indexOf(val);config.ecmaVer=ECMA_VER[val]}else{config.ecmaVer=val}}else{config.ecmaVer=DEFAULTS.ECMAVER}return true};CfgLib.prototype.processMessages=function(){var val,config=this._config;if(config.messages){val=config.messages;if(!this._utils.isObject(val)){this._error("Config entry 'messages' is not an object!");return false}if(val.accept&&val.reject){this._error("Config entry 'messages' - 'accept' and 'reject' are mutually exclusive!");return false}if(val.accept){if(!Array.isArray(val.accept)){this._error("Config entry 'messages.accept' is not an array!");return false}else if(!this._utils.isArrayContentsType(val.accept,"string")){this._error("Config entry 'messages.accept' property array does not contain all strings");return false}}if(val.reject){if(!Array.isArray(val.reject)){this._error("Config entry 'messages.reject' is not an array!");return false}else if(!this._utils.isArrayContentsType(val.reject,"string")){this._error("Config entry 'messages.reject' property array does not contain all strings");return false}}}return true};CfgLib.prototype.processAddFileList=function(){var config=this._config;if(config.appendFileList){this._appendFileList=true;this._warn("Configuration property 'appendFileList' : change to 'addFileList'")}else if(config.addFileList){this._addFileList=true}return true};CfgLib.prototype.processNameSpaces=function(){var config,nsp,ns,e;config=this._config;if(!config.nameSpaces){return true}if(!Array.isArray(config.nameSpaces)){config.nameSpaces=[config.nameSpaces]}nsp=config.nameSpaces;for(let i=0;i<nsp.length;i++){ns=nsp[i];if(!ns||typeof ns!=="string"){this._error(`Config 'nameSpaces' entry "${ns}" at index ${i} is not a valid namespace`);e=true}else if(ns.startsWith("oj-")||ns.startsWith("ns-")){this._error(`Config 'nameSpaces' entry '${ns}' must not use reserved JET prefix ${ns.substring(0,3)}`);e=true}}return e?false:true};CfgLib.prototype.processOptions=function(){var prop,opts,config=this._config,isCLI=this._modeCtx.isCLI||this._modeCtx.isOJETCLI;if(config.options){opts=config.options;for(prop in opts){if(!OPTIONS_PROPS.includes(prop)){this._error(`Config - unknown 'options' sub-property '${prop}'`);return false}else if((prop==="retCode"||prop==="rc")&&!isCLI){this._error(`Config - 'options' property '${prop}' is valid in CLI mode only`);return false}}}return true};CfgLib.prototype.processExtends=function(){var config=this._config;var ext;if(this._modeCtx.isAMD){if(ext=config.extends){if(typeof ext==="string"){this._error("Config use of non-profile 'extends' property is not supported in AMD mode.");return false}}if(config.extendOptions){this._error("Config use of 'extendOptions' property is not supported in AMD mode.");return false}}if(this._config.extendOptions){if(!this._utils.isObject(this._config.extendOptions)){this._error("Config 'extendOptions' is not an object.");return false}}var extLib=new this._nd.extends(this,this._oConfig,config,this._path,this._nd,this._msgCtx,this._utils,this._fsUtils,this._modeCtx.isAMD);var cfg=extLib.extend();return cfg};CfgLib.prototype.processTitle=function(){var t,config=this._config;if(config.title){t=this._utils.getType(config.title);if(t!=="string"&&t!=="array"){this._error(`Config entry 'title has incorrect type ('${t}')`);return false}}return true};CfgLib.prototype.processRetCode=function(){var rc,prop,ret,config=this._config;if(config.options){prop=typeof config.options.retCode!==UNDEF?"retCode":typeof config.options.rc!==UNDEF?"rc":null;if(prop){rc=config.options[prop];ret=this.validateRetCode(rc,sev=>{this._error(`Config entry 'options.${prop}' : unknown severity '${sev}'`)});if(ret||typeof ret==="number"){config.options[prop]=ret}else{config.options[prop]=AUTO;return false}}}if(!prop){if(!config.options){config.options={}}config.options.retCode=DEF_RETCODE}return true};CfgLib.prototype.validateFileList=function(aFiles){var i,j,f,msg,ret=true;;for(i=0;i<aFiles.length;i++){f=aFiles[i];if(typeof f==="string"){continue}if(!this._utils.isObject(f)){msg=" property entry "+(i+1)+" is not a string or an object";break}if(f.files){if(!(Array.isArray(f.files)&&this._utils.isArrayContentsType(f.files,"string"))){msg=" property entry "+(i+1)+" does not contain a 'files' property array, or not all elements are strings";break}}else{msg=" property entry "+(i+1)+", does not contain a 'files' property";break}if(!f.base){msg=" property entry "+(i+1)+" does not contain a 'base' property";break}for(j=0;j<f.files.length;j++){f.files[j]=this._nd.path.join(f.base,f.files[j])}}if(!msg){for(i=0;i<aFiles.length;i++){f=aFiles[i];if(this._utils.isObject(f)){aFiles.splice(i,1,...f.files)}}}if(msg){this._error(msg);ret=false}return ret};CfgLib.prototype.validateRetCode=function(val,cb){var t,i,b;t=typeof val;if(t==="number"||t==="string"&&val===DEF_RETCODE||val===ERRORS){return val}if(t==="string"){if(!this._sevLib.isSev(val)){cb(val);return false}else{return this._sevLib.unmap(val)}}if(Array.isArray(val)){b=true;for(i=0;i<val.length;i++){if(!this._sevLib.isSev(val[i])){cb(val[i]);b=false}else{val[i]=this._sevLib.unmap(val[i])}}if(b){for(i=0;i<val.length;i++){if(Array.isArray(val[i])){let ar=[];for(i=0;i<val.length;i++){ar=ar.concat(val[i])}val=ar;break}}return val}}return false};CfgLib.prototype.setMessages=function(msgid,state){var accept,reject,msgs,target,changed=false,i;var config=this._config;msgs=config.messages;state=!!state;if(!msgs){if(!state){config.messages={reject:[msgid]};changed=true}}else{reject=msgs.reject;accept=msgs.accept;target=accept||reject;i=target?target.indexOf(msgid):-1;if(state){if(!accept&&!reject){msgs.accept=accept=[]}if(reject){if(i>=0){reject.splice(i,1);changed=true;if(reject.length===0){delete msgs.reject}}}else if(accept){if(i<0){accept.push(msgid);changed=true}}}else{if(!accept&&!reject){msgs.reject=reject=[]}if(reject){if(i<0){reject.push(msgid);changed=true}}else if(accept){if(i>=0){accept.splice(i,1);if(accept.length===0){delete msgs.accept}changed=true}}}}return changed};CfgLib.prototype.getAddFileList=function(){return!!(this._addFileList||this._appendFileList)};CfgLib.prototype.checkPropNames=function(cfg,path){var prop,ret=true,config=cfg?cfg:this._config;path=path||this._path;for(prop in config){if(!TOP_PROPS.includes(prop)){if(prop.charAt(0)==="_"){delete config[prop];continue}this._error(`Config - unknown property '${prop}' ${path?"- "+path:""}`);ret=false}else if(this._modeCtx.isAMD&&NOT_AMD.includes(prop)){this._error(`Config - property '${prop}' is not available in AMD mode!`);ret=false}}return ret};CfgLib.prototype.setConfig=function(cfg,cfgPath,dir){this._config=cfg;this._path=cfgPath;this._dir=dir};CfgLib.prototype._findCompositesDir=function(base){return this._fsUtils.findFile(base,COMPOSITES)};module.exports=CfgLib;
|
|
6
|
+
function CfgLib(cfg,cfgEx){this._cfg=cfg;this._cfgEx=cfgEx};CfgLib.prototype.getConfig=function(){return this._cfg.getConfig()};CfgLib.prototype.getOrigConfig=function(){return this._cfg.getOrigConfig()};CfgLib.prototype.getExtendsProfileName=function(){return this._cfgEx.getExtendsProfileName()};CfgLib.prototype.isBuiltinJetRules=function(){return this._cfg.builtinJetRules};CfgLib.prototype.isBuiltinCspRules=function(){return this._cfg.builtinCspRules};CfgLib.prototype.isBuiltinJetWcRules=function(){return this._cfg.builtinJetWcRules};CfgLib.prototype.isBuiltinJetWcOracleRules=function(){return this._cfg.builtinJetWcOracleRules};CfgLib.prototype.isBuiltinSpocRules=function(){return this._cfg.builtinSpocRules};CfgLib.prototype.isBuiltinOjcMigrationRules=function(){return this._cfg.builtinOjcMigrationRules};CfgLib.prototype.isBuiltinWebDriverTestRules=function(){return this._cfg.builtinWebDriverTestRules};module.exports=CfgLib;
|