@oracle/oraclejet-audit 18.0.1 → 18.0.2
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/jaf-amd.js +1 -1
- package/lib/TsxUtils.js +1 -1
- package/lib/checkage.js +1 -1
- package/lib/defaults.js +1 -1
- package/lib/sublib/precomp/Precompiler.js +1 -1
- package/meta/18.0.0/jetauditmeta.js +1 -1
- package/meta/metaverlist.json +1 -1
- package/package.json +2 -2
- package/rules/jet/oj-html-alta-deprecated.js +1 -1
- package/rules/jet/oj-tsx-ojattr.js +1 -1
package/lib/TsxUtils.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 TSX2_UTILS=require("./TsxUtils2");const HTML_UTILS=require("./HtmlUtils");const CB_END="end";const CB_NEXT_COMP="next-comp";const TSX_COMPONENT="TsxComponent";const TSX_PROPERTY="TsxProperty";const TEMPLATE="template";const OJ_DEFER="oj-defer";const OJ_BIND="oj-bind";const BODY="body";var TsxUtils=function(assert){this._fnAssert=assert;this._metaLib=null};TsxUtils.prototype.extractTsxProperties=function(ruleCtx,tsxRC,cb){this._onTsxRC(ruleCtx,tsxRC,cb)};TsxUtils.prototype.getProperty=function(tsxObj,propName){return this._extractProp(tsxObj,propName)};TsxUtils.prototype._extractProp=function(tsxObj,propName){var ret,ot;if(tsxObj&&(ot=tsxObj.type)){if(ot===TSX_PROPERTY){return tsxObj}if(ot===TSX_COMPONENT&&propName){let props,prop,i;if(props=tsxObj.properties){for(i=0;i<props.length;i++){prop=props[i];if(prop.name===propName){ret=prop;break}}}}}return ret};TsxUtils.prototype.getPropertyRawValue=function(tsxComp,name,stripDelims){var prop,ret;if(prop=this.getProperty(tsxComp,name)){ret=prop.valueRaw;if(stripDelims&&ret.charAt(0)==="\""){ret=ret.charAt(1)==="\""?ret="":ret.substring(1,ret.length-1)}}return typeof ret==="string"?ret:null};TsxUtils.prototype.getPropertyValue=function(tsxComp,propName){var tsxProp,ret,obj,i;var a=propName.split(".");var major=a[0];if(tsxProp=this.getProperty(tsxComp,major)){if(a.length===1){return tsxProp.node.value}if(!this.isPropertyPreactExpr(tsxProp)){return undefined}obj=tsxProp.node.value;for(i=1;i<a.length;i++){major=a.shift();if(!_isObject(obj)){break}if((obj=obj[major])&&_isObject(obj)){continue}break}}return ret};TsxUtils.prototype.getPropertyStringValue=function(tsxObj,propName){var tsxProp,value,ret;if(tsxProp=this._extractProp(tsxObj,propName)){value=tsxProp.node.value;if(value!==null){ret=value.type==="Literal"&&typeof value.value==="string"?value.value:null}}else{ret=null}return ret};TsxUtils.prototype.isPropertyPreactExpr=function(tsxObj,propName){var tsxProp,ret=false;if(tsxProp=this._extractProp(tsxObj,propName)){ret=tsxProp.node.value.type==="JSXExpressionContainer"}return ret};TsxUtils.prototype.isPropertyObjectExpr=function(tsxObj,propName){var tsxProp,ret=false;if(tsxProp=this._extractProp(tsxObj,propName)){if(tsxProp.node.value.type==="JSXExpressionContainer"){let expr=tsxProp.node.value.expression;ret=expr&&expr.type==="ObjectExpression"}}return ret};TsxUtils.prototype.isPropertyString=function(tsxObj,propName){var tsxProp,ret=false;if(tsxProp=this._extractProp(tsxObj,propName)){ret=tsxProp.node.value.type==="Literal"&&typeof tsxProp.node.value.value==="string"}return ret};TsxUtils.prototype.getAncestor=function(tsxComp,name){var o,ret;name=name||tsxComp.name;while(o=tsxComp.parent){if(o.name===name){ret=o;break}tsxComp=o}return ret||null};TsxUtils.prototype.getChildren=function(tsxComp){return tsxComp.children};TsxUtils.prototype.getDescendant=function(tsxComp,name){var childs,child,ret,i;while(childs=tsxComp.children){for(i=0;i<childs.length;i++){child=childs[i];if(child.name===name){ret=child;break}if(ret=this.getDescendant(child,name)){break}}break}return ret||null};TsxUtils.prototype.getDirectDescendant=function(tsxComp,name){var childs,child,ret,i;if(childs=tsxComp.children){for(i=0;i<childs.length;i++){child=childs[i];if(child.name===name){ret=child;break}}}return ret||null};TsxUtils.prototype.isExpressionObject=function(tsxObj,propName){var tsxProp,ret;if(tsxProp=this._extractProp(tsxObj,propName)){if(tsxProp.node.value.type==="JSXExpressionContainer"){let expr=tsxProp.node.value.expression;ret=expr.type==="ObjectExpression"}}return!!ret};TsxUtils.prototype.getExpressionObject=function(tsxObj,propName){var tsxProp,obj;if(tsxProp=this._extractProp(tsxObj,propName)){if(!tsxProp.node.value){return null}if(tsxProp.node.value.type!=="JSXExpressionContainer"){return null}let expr=tsxProp.node.value.expression;if(expr.type==="ObjectExpression"){let props,stack;props=expr.properties;obj={};stack=[];props.forEach(prop=>{_doProp(prop,obj,stack,this._fnAssert)})}}return obj||null};TsxUtils.prototype.toCamelCase=function(str){return TSX2_UTILS.toCamelCase(str)};TsxUtils.prototype.toKebabCase=function(str){return TSX2_UTILS.toKebabCase(str)};function _doProp(prop,obj,stack,fnAssert){let key,elems,propx,pvType;if(prop.type==="Property"&&(prop.key.type==="Identifier"||prop.key.type==="Literal")){if(prop.key.type==="Identifier"){key=prop.key.name}else{key=prop.key.value}pvType=prop.value.type;if(pvType==="Literal"){obj[key]=prop.value.value}else if(pvType==="Identifier"){obj[key]=prop.value.name}else if(pvType==="ArrayExpression"){obj[key]=[];elems=prop.value.elements;elems.forEach(elem=>{if(elem.type==="Literal"){obj[key].push(elem.value)}else if(elem.type==="ObjectExpression"){elem.properties.forEach(prop=>{stack.push(obj);obj={};propx=_doProp(prop,obj,stack,fnAssert);obj=stack.pop();obj[key].push(propx)})}})}else if(prop.value.
|
|
6
|
+
const TSX2_UTILS=require("./TsxUtils2");const HTML_UTILS=require("./HtmlUtils");const CB_END="end";const CB_NEXT_COMP="next-comp";const TSX_COMPONENT="TsxComponent";const TSX_PROPERTY="TsxProperty";const TEMPLATE="template";const OJ_DEFER="oj-defer";const OJ_BIND="oj-bind";const BODY="body";var TsxUtils=function(assert){this._fnAssert=assert;this._metaLib=null};TsxUtils.prototype.extractTsxProperties=function(ruleCtx,tsxRC,cb){this._onTsxRC(ruleCtx,tsxRC,cb)};TsxUtils.prototype.getProperty=function(tsxObj,propName){return this._extractProp(tsxObj,propName)};TsxUtils.prototype._extractProp=function(tsxObj,propName){var ret,ot;if(tsxObj&&(ot=tsxObj.type)){if(ot===TSX_PROPERTY){return tsxObj}if(ot===TSX_COMPONENT&&propName){let props,prop,i;if(props=tsxObj.properties){for(i=0;i<props.length;i++){prop=props[i];if(prop.name===propName){ret=prop;break}}}}}return ret};TsxUtils.prototype.getPropertyRawValue=function(tsxComp,name,stripDelims){var prop,ret;if(prop=this.getProperty(tsxComp,name)){ret=prop.valueRaw;if(stripDelims&&ret.charAt(0)==="\""){ret=ret.charAt(1)==="\""?ret="":ret.substring(1,ret.length-1)}}return typeof ret==="string"?ret:null};TsxUtils.prototype.getPropertyValue=function(tsxComp,propName){var tsxProp,ret,obj,i;var a=propName.split(".");var major=a[0];if(tsxProp=this.getProperty(tsxComp,major)){if(a.length===1){return tsxProp.node.value}if(!this.isPropertyPreactExpr(tsxProp)){return undefined}obj=tsxProp.node.value;for(i=1;i<a.length;i++){major=a.shift();if(!_isObject(obj)){break}if((obj=obj[major])&&_isObject(obj)){continue}break}}return ret};TsxUtils.prototype.getPropertyStringValue=function(tsxObj,propName){var tsxProp,value,ret;if(tsxProp=this._extractProp(tsxObj,propName)){value=tsxProp.node.value;if(value!==null){ret=value.type==="Literal"&&typeof value.value==="string"?value.value:null}}else{ret=null}return ret};TsxUtils.prototype.isPropertyPreactExpr=function(tsxObj,propName){var tsxProp,ret=false;if(tsxProp=this._extractProp(tsxObj,propName)){ret=tsxProp.node.value.type==="JSXExpressionContainer"}return ret};TsxUtils.prototype.isPropertyObjectExpr=function(tsxObj,propName){var tsxProp,ret=false;if(tsxProp=this._extractProp(tsxObj,propName)){if(tsxProp.node.value.type==="JSXExpressionContainer"){let expr=tsxProp.node.value.expression;ret=expr&&expr.type==="ObjectExpression"}}return ret};TsxUtils.prototype.isPropertyString=function(tsxObj,propName){var tsxProp,ret=false;if(tsxProp=this._extractProp(tsxObj,propName)){ret=tsxProp.node.value.type==="Literal"&&typeof tsxProp.node.value.value==="string"}return ret};TsxUtils.prototype.getAncestor=function(tsxComp,name){var o,ret;name=name||tsxComp.name;while(o=tsxComp.parent){if(o.name===name){ret=o;break}tsxComp=o}return ret||null};TsxUtils.prototype.getChildren=function(tsxComp){return tsxComp.children};TsxUtils.prototype.getDescendant=function(tsxComp,name){var childs,child,ret,i;while(childs=tsxComp.children){for(i=0;i<childs.length;i++){child=childs[i];if(child.name===name){ret=child;break}if(ret=this.getDescendant(child,name)){break}}break}return ret||null};TsxUtils.prototype.getDirectDescendant=function(tsxComp,name){var childs,child,ret,i;if(childs=tsxComp.children){for(i=0;i<childs.length;i++){child=childs[i];if(child.name===name){ret=child;break}}}return ret||null};TsxUtils.prototype.isExpressionObject=function(tsxObj,propName){var tsxProp,ret;if(tsxProp=this._extractProp(tsxObj,propName)){if(tsxProp.node.value.type==="JSXExpressionContainer"){let expr=tsxProp.node.value.expression;ret=expr.type==="ObjectExpression"}}return!!ret};TsxUtils.prototype.getExpressionObject=function(tsxObj,propName){var tsxProp,obj;if(tsxProp=this._extractProp(tsxObj,propName)){if(!tsxProp.node.value){return null}if(tsxProp.node.value.type!=="JSXExpressionContainer"){return null}let expr=tsxProp.node.value.expression;if(expr.type==="ObjectExpression"){let props,stack;props=expr.properties;obj={};stack=[];props.forEach(prop=>{_doProp(prop,obj,stack,this._fnAssert)})}}return obj||null};TsxUtils.prototype.toCamelCase=function(str){return TSX2_UTILS.toCamelCase(str)};TsxUtils.prototype.toKebabCase=function(str){return TSX2_UTILS.toKebabCase(str)};function _doProp(prop,obj,stack,fnAssert){let key,elems,propx,pvType;if(prop.type==="Property"&&(prop.key.type==="Identifier"||prop.key.type==="Literal")){if(prop.key.type==="Identifier"){key=prop.key.name}else{key=prop.key.value}pvType=prop.value.type;if(pvType==="Literal"){obj[key]=prop.value.value}else if(pvType==="Identifier"){obj[key]=prop.value.name}else if(pvType==="ArrayExpression"){obj[key]=[];elems=prop.value.elements;elems.forEach(elem=>{if(elem.type==="Literal"){obj[key].push(elem.value)}else if(elem.type==="ObjectExpression"){elem.properties.forEach(prop=>{stack.push(obj);obj={};propx=_doProp(prop,obj,stack,fnAssert);obj=stack.pop();obj[key].push(propx)})}})}else if(pvType==="FunctionExpression"){obj[key]=prop.value.body.body}else if(pvType==="ArrowFunctionExpression"){obj[key]=prop.value.body}else if(pvType==="ObjectExpression"){let o,p,i,objProps=prop.value.properties;stack.push(obj);obj[key]=o={};obj=o;for(i=0;i<objProps.length;i++){p=objProps[i];if(p.key.type==="Identifier"){if(p.value.type==="Literal"){o[p.key.name]=p.value.value}else if(p.value.type==="ObjectExpression"){_doProp(p,obj,stack,fnAssert);obj=stack.pop()}else if(p.value.type==="Identifier"){o[p.key.name]=p.value.name}else if(p.value.type==="ArrowFunctionExpression"){o[p.key.name]=p.value}else{fnAssert(`TsxUtils._doProp file line=${prop?.loc.start.line} ${p.value.type}`)}}}}else if(pvType==="MemberExpression"){obj[key]=prop.value}else if(pvType==="TemplateLiteral"){obj[key]=null}else if(pvType==="LogicalExpression"){obj[key]=prop.value}else if(pvType==="CallExpression"){obj[key]=prop.value}else if(pvType==="ConditionalExpression"){obj[key]=prop.value}else if(pvType==="AssignmentPattern"){fnAssert(`TsxUtils._doProp2 unhandled prop key '${key}' value type '${pvType}', file line=${prop?.loc.start.line}`);obj[key]="?"}else{fnAssert(`TsxUtils._doProp3 unhandled prop key '${key}' value type '${pvType}', file line=${prop?.loc.start.line}`);obj[key]="?"}}return obj};TsxUtils.prototype.setIssuePosition=function(issue,obj){if(obj.type===TSX_COMPONENT||obj.type===TSX_PROPERTY){let loc=obj.loc;issue.setPosition(loc.start.line,loc.start.column,obj.range[0],obj.range[1])}else{issue.setPosition(0,0,0,0)}};TsxUtils.prototype.setIssuePropValuePosition=function(issue,tsxProp){if(tsxProp.type==="TsxProperty"){let loc=tsxProp.node.value.loc;issue.setPosition(loc.start.line,loc.start.column,tsxProp.node.value.range[0],tsxProp.node.value.range[1])}else{issue.setPosition(0,0,0,0)}};TsxUtils.prototype.getRawtext=function(ruleCtx,tsxRC){return ruleCtx&&tsxRC&&tsxRC.range?ruleCtx.data.substring(tsxRC.range[0],tsxRC.range[1]):""};TsxUtils.prototype._onTsxRC=function(ruleCtx,tsxRC,cb){var comps,tsxComp,ret,i;if(!(comps=tsxRC.components)){return}for(i=0;i<comps.length;i++){tsxComp=comps[i];ret=this._checkComp(ruleCtx,tsxComp,cb);if(ret===CB_END){break}};cb(ruleCtx,null)};TsxUtils.prototype._checkComp=function(ruleCtx,tsxComp,cb){var props;if(props=tsxComp.properties){let prop,ret,i;for(i=0;i<props.length;i++){prop=props[i];ret=cb(ruleCtx,prop);if(ret===CB_END||ret===CB_NEXT_COMP){return ret}};}if(tsxComp.children){tsxComp.children.forEach(child=>{this._checkComp(ruleCtx,child,cb)})}};TsxUtils.prototype.getSlotParent=function(ruleCtx,tsxProp,slotName){var parent,isOjDefer=false,ret=null;parent=tsxProp.parent;if(!(parent=parent.parent)){return}isOjDefer=parent.name==="oj-defer";if(parent&&parent.name){if(parent.name!==BODY){if(ruleCtx.utils.metaLib.isTagSlotName(parent.name,slotName)){ret=parent}if(!ret){if(isOjDefer&&parent.name===TEMPLATE||parent.name==="oj-switcher"){ret=parent}else if(parent.name===TEMPLATE||parent.name.startsWith(OJ_BIND)||parent.name===OJ_DEFER){ret=_continueUpwards(ruleCtx,parent,slotName)}}}}return ret};TsxUtils.prototype.isChildOfElem=function(elemName,tsxComp){var ret=null;while(tsxComp.parent){if(tsxComp.parent.name===elemName){ret=tsxComp.parent;break}tsxComp=tsxComp.parent}return ret};function _continueUpwards(ruleCtx,tsxComp,slotName){var ret=null,parent,tagName;while(parent=tsxComp.parent){tagName=parent.name;if(tagName===TEMPLATE||tagName.startsWith(OJ_BIND)||tagName===OJ_DEFER){tsxComp=parent;continue}if(parent.name!==BODY){if(ruleCtx.utils.metaLib.isTagSlotName(tagName,slotName)){ret=parent}}break}return ret};function _isObject(value){return typeof value==="object"&&!Array.isArray(value)};TsxUtils.prototype.setMetaLib=function(metaLib){this._metaLib=metaLib};TsxUtils.prototype.isCommonElem=function(elem){return HTML_UTILS.isCommonElem(elem)};TsxUtils.prototype.isCommonAttr=function(attrName){return TSX2_UTILS.isCommonProp(attrName)||this.isAriaAttr(attrName)};TsxUtils.prototype.isCommonEventAttr=function(attrName){return TSX2_UTILS.isCommonEventProp(attrName)};TsxUtils.prototype.isHtml5ObsoleteElem=function(tag){return HTML_UTILS.isHtml5ObsoleteElem(tag)};TsxUtils.prototype.isAriaAttr=function(attr){return HTML_UTILS.isAriaAttr(attr)};TsxUtils.prototype.isSelfClosingTag=function(tag){return HTML_UTILS.isSelfClosingTag(tag)};TsxUtils.prototype.isSvgElem=function(elem){return HTML_UTILS.isSvgElem(elem)};module.exports=TsxUtils;
|
package/lib/checkage.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 BUILT="2025-
|
|
6
|
+
const BUILT="2025-03-06T16:27:11.801Z";const MAJOR_RELS=2;function CheckAge(burnedInJetVer,msgCtx){this._jetRels=-1;this._msgCtx=msgCtx;this._burnedInMajor=parseInt(burnedInJetVer.split(".")[0])};CheckAge.prototype.checkAge=function(){var curDate;var buildDate;var buildMonth;var monthsToNow;curDate=new Date;buildDate=BUILT==="@BUILT@"?curDate:new Date(BUILT);buildMonth=buildDate.getMonth()+1;monthsToNow=_getElapsedMonths(buildDate,curDate);if(!monthsToNow){this._jetRels=0}else{this._jetRels=_getReleases(buildMonth,monthsToNow);if(this._jetRels>MAJOR_RELS){this._emitMsg(monthsToNow)}}return this._jetRels};CheckAge.prototype.getJafReleaseCount=function(){return this._jetRels};CheckAge.prototype.getMajorReleaseCount=function(major){if(typeof major==="string"){let a=major.split(".");major=parseInt(a[0])}if(isNaN(major)){return this._jetRels}let estimatedMajor=this._burnedInMajor+this._jetRels;return estimatedMajor-major};CheckAge.prototype._emitMsg=function(old){var INDENT=" ".repeat(12);var s,h,p;if(this._jetRels){s=""+this._jetRels;if(this._jetRels===1){h="has";p=""}else{h="have";p="s"}}else{s="at least one";h="has";p=""}var s=`\nThis version of JAF is ${old} month${old===1?"":"s"} old, and there ${h} been ${s} scheduled public\n`+`${INDENT}major JET release${p}, together with JAF updates and fixes. It is strongly\n`+INDENT+"recommended that you install the latest version of JAF. [JAF-9100]\n";this._msgCtx.warn(s,"JAF-9100",true)};function _getElapsedMonths(start,end){return end.getMonth()-start.getMonth()+12*(end.getFullYear()-start.getFullYear())};function _getReleases(buildMonth,months){var toNextRel,releases=0;if(buildMonth===1){toNextRel=0}else if(buildMonth>1&&buildMonth<7){toNextRel=7-buildMonth}else if(buildMonth===7){toNextRel=0}else{toNextRel=13-buildMonth}if((releases=months-toNextRel)>=0){releases=1+Math.floor(releases/6)}else{releases=0}return releases};module.exports=CheckAge;
|
package/lib/defaults.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 defaults={JETVER:"18.0.
|
|
6
|
+
const defaults={JETVER:"18.0.2".replace(/(\d*\.\d*)(\.\d*)+$/g,"$1")+".0",THEME:"Alta",ECMAVER:14};module.exports=defaults;
|
|
@@ -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 JAF_TEMP="jaf";const WORKING_ROOT_FOLDER="ts-temp";const TSCONFIG_JSON="tsconfig.json";const VCOMP_MSG_PREFIX="VComponent Processing:";var path;const PreCompiler=function(utils,jafUtils,fsUtils,msgCtx,semVer,nd){this._utils=utils;this._jafUtils=jafUtils;this._fsUtils=fsUtils;this._semVer=semVer;this._error=msgCtx.error;this._info=msgCtx.info;this._msg=msgCtx.msg;this._debug=msgCtx.debug;this._jafMsg=msgCtx.jafMsg;this._isDebug=msgCtx.isDebug;this._isVerbose=msgCtx.isVerbose;this._isVerboseOrDebug=this._isVerbose||this._isDebug;path=nd.path;this._workingRootFolder=this._utils.toJAFPath(path.join(nd.os.tmpdir(),JAF_TEMP,WORKING_ROOT_FOLDER));this._runOnce=false;this._vfiles=null};PreCompiler.prototype.getPrecompileCache=function(auditBase,tsSource,componentRootFolder){if(!this.runOnce){this._runOnce=true;this._precompileCache=this._transformVComponents(path.join(auditBase,TSCONFIG_JSON),auditBase,tsSource,componentRootFolder)}return this._precompileCache};PreCompiler.prototype.getVFiles=function(){return this._vfiles};PreCompiler.prototype._transformVComponents=function(tsConfigPath,auditBase,sourceBase,componentBase){const normalizedTsConfigPath=this._fsUtils.toJAFPath(tsConfigPath);if(!this._fsUtils.fileExistsSync(normalizedTsConfigPath)){if(this._isVerboseOrDebug){this._info(`Skipping pre-compilation - Typescript configuration file '${tsConfigPath}' not found!`)}return}const outputFolder=this._fsUtils.getUniqueFileNameSync("_XXXXXX");const compiledOutputFolder=this._utils.toJAFPath(`${this._workingRootFolder}/js${outputFolder}`);const compiledJSONFolder=this._utils.toJAFPath(`${this._workingRootFolder}/json${outputFolder}`);const allTsConfig=this._fsUtils.readJsonSync(tsConfigPath,true,error=>this._error(`Typescript configuration file ${tsConfigPath} cannot be read, unable to process VComponents.\nError: ${error}`));if(!allTsConfig){return}if(this._isDebug){this._debug(
|
|
6
|
+
const JAF_TEMP="jaf";const WORKING_ROOT_FOLDER="ts-temp";const TSCONFIG_JSON="tsconfig.json";const VCOMP_MSG_PREFIX="VComponent Processing:";var path;const PreCompiler=function(utils,jafUtils,fsUtils,msgCtx,semVer,nd){this._utils=utils;this._jafUtils=jafUtils;this._fsUtils=fsUtils;this._semVer=semVer;this._error=msgCtx.error;this._info=msgCtx.info;this._msg=msgCtx.msg;this._debug=msgCtx.debug;this._jafMsg=msgCtx.jafMsg;this._isDebug=msgCtx.isDebug;this._isVerbose=msgCtx.isVerbose;this._isVerboseOrDebug=this._isVerbose||this._isDebug;path=nd.path;this._workingRootFolder=this._utils.toJAFPath(path.join(nd.os.tmpdir(),JAF_TEMP,WORKING_ROOT_FOLDER));this._runOnce=false;this._vfiles=null};PreCompiler.prototype.getPrecompileCache=function(auditBase,tsSource,componentRootFolder){if(!this.runOnce){this._runOnce=true;if(this._isDebug){this._debug(`getPrecompileCache ->\n auditBase=\"${auditBase}\"\n tsSource=\"${tsSource}\"\n componentRootFolder=\"${componentRootFolder}\"`)}this._precompileCache=this._transformVComponents(path.join(auditBase,TSCONFIG_JSON),auditBase,tsSource,componentRootFolder)}return this._precompileCache};PreCompiler.prototype.getVFiles=function(){return this._vfiles};PreCompiler.prototype._transformVComponents=function(tsConfigPath,auditBase,sourceBase,componentBase){const normalizedTsConfigPath=this._fsUtils.toJAFPath(tsConfigPath);if(!this._fsUtils.fileExistsSync(normalizedTsConfigPath)){if(this._isVerboseOrDebug){this._info(`Skipping pre-compilation - Typescript configuration file '${tsConfigPath}' not found!`)}return}const outputFolder=this._fsUtils.getUniqueFileNameSync("_XXXXXX");const compiledOutputFolder=this._utils.toJAFPath(`${this._workingRootFolder}/js${outputFolder}`);const compiledJSONFolder=this._utils.toJAFPath(`${this._workingRootFolder}/json${outputFolder}`);const allTsConfig=this._fsUtils.readJsonSync(tsConfigPath,true,error=>this._error(`Typescript configuration file ${tsConfigPath} cannot be read, unable to process VComponents.\nError: ${error}`));if(!allTsConfig){return}if(this._isDebug){this._debug(`\nTypeScript Config ->\n${JSON.stringify(allTsConfig,null,3)}`)}if(this._isVerboseOrDebug){this._msg(`\n${VCOMP_MSG_PREFIX} Compiling project ...`)}if(this._isDebug){this._debug(`...transforming to full paths ->\n componentBase=\"${componentBase}\"\n auditBase=\"${auditBase}\"\n sourceBase=\"${sourceBase}\"\n componentBase=\"${componentBase}\"\n`)}allTsConfig.compilerOptions.paths[`${componentBase}/*`]=[`${auditBase}/${sourceBase}/${componentBase}/*`];const sourceBaseRoot=sourceBase.includes("/")?sourceBase.split("/")[0]:sourceBase;Object.entries(allTsConfig.compilerOptions.paths).forEach(([pathKey,pathValues])=>{if(this._isDebug){this._debug(`pathKey -> ${pathKey} pathValues -> ${pathValues}`)};const remapped=pathValues.map(mappedPath=>{return this._remapPath(mappedPath,sourceBaseRoot,auditBase)});allTsConfig.compilerOptions.paths[pathKey]=remapped});if(allTsConfig.compilerOptions.hasOwnProperty("typeRoots")){allTsConfig.compilerOptions.typeRoots=allTsConfig.compilerOptions.typeRoots.map(typeroot=>this._remapPath(typeroot,sourceBaseRoot,auditBase))}else if(this._isVerboseOrDebug){this._msg(`${VCOMP_MSG_PREFIX} tsconfig 'typeRoots' property not defined ...`)}if(allTsConfig.compilerOptions.hasOwnProperty("types")){allTsConfig.compilerOptions.types=allTsConfig.compilerOptions.types.map(type=>this._remapPath(type,sourceBaseRoot,auditBase))}else if(this._isVerboseOrDebug){this._msg(`${VCOMP_MSG_PREFIX} tsconfig 'types' property not defined ...`)}allTsConfig.compilerOptions.rootDir=auditBase;allTsConfig.compilerOptions.outDir=compiledOutputFolder;if(!this._fsUtils.pathExistsSync(this._workingRootFolder)){this._fsUtils.createFolderSync(this._workingRootFolder)}else{this._fsUtils.deleteFolderSync(this._workingRootFolder,false)}if(this._isVerboseOrDebug){this._msg(`${VCOMP_MSG_PREFIX} Typescript will be compiled into '${this._workingRootFolder}'`)}let nodeJetRoot=path.join(auditBase,"node_modules","@oracle","oraclejet");if(!this._fsUtils.pathExistsSync(nodeJetRoot)){nodeJetRoot=path.normalize(path.join(auditBase,"..","..","node_modules","@oracle","oraclejet"))}let nodeJetPackage=path.join(nodeJetRoot,"package.json");let customTsc=this._utils.toJAFPath(path.join(nodeJetRoot,"dist","custom-tsc"));if(!this._fsUtils.pathExistsSync(customTsc)||!this._fsUtils.pathExistsSync(nodeJetPackage)){this._error("Unable to run VComponent pre-compilation -the required packages are not available. Run \"ojet restore\" or \"npm install\" to correct this.");return}let jetVerString;const packageJson=this._fsUtils.readJsonSync(nodeJetPackage);if(packageJson){jetVerString=packageJson.version}if(this._isVerboseOrDebug){this._msg(`${VCOMP_MSG_PREFIX} oraclejet package version -> ${jetVerString?jetVerString:"not found"}`)}let CustomTypeScriptCompiler;if(this._isVerboseOrDebug){this._msg(`${VCOMP_MSG_PREFIX} loading TypeScript compiler...`)}try{CustomTypeScriptCompiler=require(customTsc)}catch(e){this._jafMsg("jaf-ts-loader",`${VCOMP_MSG_PREFIX} failure loading TypeScript <- '${customTsc}'`)}if(!CustomTypeScriptCompiler){return}const readFrom=path.join(auditBase,sourceBase);let files=this._discoverCompilableFiles(readFrom,readFrom);if(!files||!files.length){return}files.forEach((file,x)=>{files[x]=this._utils.toJAFPath(file)});if(this._isDebug){this._displayCompilableList(files)}const buildOptions={debug:false,dtDir:compiledJSONFolder,version:"",jetVersion:"",templatePath:path.join(customTsc,"templates"),tsBuiltDir:compiledOutputFolder,typesDir:compiledOutputFolder};const compileOptionsPre12={files,compilerOptions:allTsConfig.compilerOptions,buildOptions:buildOptions};const compileOptions1201={tsconfigJson:{compilerOptions:allTsConfig.compilerOptions,files},buildOptions:buildOptions};let compileOptions;if(jetVerString){if(this._semVer.gt(jetVerString,"12.0.0")){compileOptions=compileOptions1201}else{compileOptions=compileOptionsPre12}if(this._semVer.lt(jetVerString,"16.0.0")){compileOptions.mainEntryFile="loader.d.ts"}}if(compileOptions){if(this._isDebug){this._debug(`Using TypeScript compile options ->\n${JSON.stringify(compileOptions,null,3)}\n`)}try{if(this._isVerboseOrDebug){this._msg(`${VCOMP_MSG_PREFIX} compiling ${files.length} file${files.length>1?"s":""}...`)}const{errors}=CustomTypeScriptCompiler.compile(compileOptions);if(errors.length){this._error(`${errors.length} Error${errors.length>1?"s":""} found during TypeScript pre-compilation of VComponents`);errors.forEach(error=>{if(error.hasOwnProperty("message")){this._error(error.message);this._error(error.stack)}else{this._jafMsg("jaf-ts-precompile",JSON.stringify(error))}})}else{this._msg(`${VCOMP_MSG_PREFIX} Typescript compilation of ${files.length} file${files.length!==1?"s":""} successful ...`)}if(!errors.length){this._vfiles=files}return compiledJSONFolder}catch(uncaughtFromCompile){this._error("Uncaught error during TypeScript pre-compilation of VComponents");this._error(uncaughtFromCompile.stack)}}else{this._error("Unable to run VComponent pre-compilation, cannot detect JET custom compiler version")}};PreCompiler.prototype._discoverCompilableFiles=function(root,pathPrefix){const allSources=this._fsUtils.readDirSync(root);return allSources?this._extractCompilables(allSources,"").map(sourceFile=>`${pathPrefix}/${sourceFile}`):null};PreCompiler.prototype._extractCompilables=function(sources,folder){return sources.reduce((compilables,candidate)=>{if(candidate.isFile&&(candidate.name.endsWith(".ts")||candidate.name.endsWith(".tsx"))){compilables.push(`${folder}/${candidate.name}`)}else if(candidate.files){compilables=compilables.concat(this._extractCompilables(candidate.files,`${folder}/${candidate.name}`))}return compilables},new Array)};PreCompiler.prototype._remapPath=function(definedPath,sourceFolder,auditBase){let newPath=definedPath;const segs=definedPath.split("/");if(segs[0]==="."){segs.shift()}switch(segs[0]){case"node_modules":case"jet_components":case"exchange_components":case sourceFolder:newPath=`${auditBase}${segs.join("/")}`;break}return newPath};PreCompiler.prototype._displayCompilableList=function(files){let count=0;let flist;if(files&&files.length){count=files.length;flist="\n "+files.join("\n ")}this._debug(`VComponents: discovered ${count} compilable files:${flist}`)};module.exports=PreCompiler;
|