amd-conversion-analyser
Advanced tools
Comparing version 1.7.0 to 1.7.1
@@ -1,1 +0,1 @@ | ||
"use strict";var _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(a){return typeof a}:function(a){return a&&"function"==typeof Symbol&&a.constructor===Symbol&&a!==Symbol.prototype?"symbol":typeof a};function _toConsumableArray(a){if(Array.isArray(a)){for(var b=0,c=Array(a.length);b<a.length;b++)c[b]=a[b];return c}return Array.from(a)}var acorn=require("acorn"),glob=require("globby"),detectAMD=require("./detect-amd"),detectLegacyFallback=require("./detect-ajs-namespace"),detectGlobals=require("acorn-globals"),globals=require("globals"),arrayUniq=require("array-uniq"),_=require("lodash"),fs=require("fs"),path=require("path"),colors=require("colors/safe"),winston=require("winston");colors.setTheme({ok:"grey",warn:"yellow",error:"red"});function ConversionDetector(a,b,c){function d(a){return new winston.Logger({level:a})}var f=b.symbols,e=b.patterns||["**/*.js"],g=[],h=[],i=d(),j=d(),k=d(),l=d(c["file-log-level"]),m=d(),n=!!c["globals-summary"],o=c.globals||c["idea-globals"],p=!1!==c.ok;(function(){o&&i.add(winston.transports.Console,{showLevel:!1}),n&&j.add(winston.transports.Console,{showLevel:!1}),!1!==c.files&&(k.add(winston.transports.Console,{showLevel:!1}),l.add(winston.transports.Console,{showLevel:!1})),!1!==c.summary&&m.add(winston.transports.Console,{showLevel:!1})})(),this._excludedGlobals=[],this._globals=[],this._countNonAMD=0,this._countGlobals=0,this._countAMDDefine=0,this._countAMDRequire=0,this.setupExcludedGlobals=function(a,b){var c="undefined"==typeof b?[]:b;return a&&Object.keys(a).filter(function(b){return a[b]}).forEach(function(a){var b=globals[a];b&&(c=arrayUniq(c.concat(Object.keys(b))))}),c},this.getFilename=function(a){return path.basename(a)},this.markAsNonAMD=function(a){++this._countNonAMD,g.push({filepath:a,amd:!1,is:f.ERR,msg:"Not an AMD module"})},this.markAsAMD=function(a,b){++this._countAMDDefine,this.findGlobals(a,b)},this.markAsAMDRequire=function(a,b){++this._countAMDRequire,this.findGlobals(a,b)},this.trimToEndOfVariableName=function(a){for(var b,c=[],d=a.parents.length-1;0<=d;d--)if(b=a.parents[d],"Identifier"===b.type)c.push(b.name);else if("MemberExpression"===b.type)c.push(b.property.name||b.property.value);else if("ThisExpression"===b.type)c.push("this");else break;return namePath.join(".")},this.isExcludedVariable=function(a){var c=[],d=a.split(".").some(function(a){c.push(a);var d=c.join(".");return-1<b.exclude.variables.indexOf(d)});return d},this.isAMDDefine=function(a){return"object"===("undefined"==typeof a?"undefined":_typeof(a))&&a.hasOwnProperty("type")&&"define"===a.type},this.isAMDRequire=function(a){return"object"===("undefined"==typeof a?"undefined":_typeof(a))&&a.hasOwnProperty("type")&&"require"===a.type},this.isNamedAMDModule=function(a){return this.isAMDDefine(a)&&a.hasOwnProperty("name")&&!!a.name},this.getRelevantGlobals=function(a){var b=this;return detectGlobals(a).filter(function(c){if(-1<b._excludedGlobals.indexOf(c.name))return!1;var d=b.getRelevantOccurrences(a,c.nodes);return 0<d.length})},this.getRelevantOccurrences=function(a,b){var c=this;return b?b.filter(function(a){var b=c.trimToEndOfVariableName(a);return!c.isExcludedVariable(b)&&(++c._countGlobals,!0)}):[]},this.processRelevantOccurrences=function(a,b,c){var d=this;return b?b.map(function(b){var e=acorn.getLineInfo(a,b.start),f=d.trimToEndOfVariableName(b),g=d.isExcludedVariable(f);return{varName:f,lineInfo:e,isExcluded:g,fullFilePath:c}}):[]},this.getIDEALink=function(a,b,c){return b&&c?colors.grey.underline("http://localhost:63342/api/file/"+process.cwd()+"/"+a+":"+b+":"+c):colors.underline("http://localhost:63342/api/file/"+process.cwd()+"/"+a)},this.findGlobals=function(a,b){var c=this;try{var d=this.getRelevantGlobals(b),e=[];if(0===d.length)return void g.push({filepath:a,amd:!0,globals:!1,is:f.OK});o&&d.forEach(function(d){var f=c.processRelevantOccurrences(b,d.nodes,a);e=e.concat(f),c._globals=c._globals.concat(f)}),g.push({filepath:a,amd:!0,is:f.ALERT,globals:!0,globalsList:e,msg:"Globals detected"})}catch(b){g.push({filepath:a,amd:!0,is:f.ERR,err:b,msg:"Error finding globals"})}},this.handleFile=function(a,b,c,d){try{if(a)throw new Error(a.message?a.message:a);var e=detectAMD(b),i=e&&e[0];this.isNamedAMDModule(i)?this.markAsAMD(c,b):this.isAMDDefine(i)?this.markAsAMD(c,b):this.isAMDRequire(i)?this.markAsAMDRequire(c,b):this.markAsNonAMD(c);var j=detectLegacyFallback(b);j.length&&h.push.apply(h,_toConsumableArray(j))}catch(a){g.push({filepath:c,is:f.ERR,err:a,msg:"Error parsing file"})}d()},this.printFileSummary=function(){var a=this,b={};b[f.ERR]={color:colors.error,logger:l.error},b[f.ALERT]={color:colors.warn,logger:l.warn},b[f.OK]={color:colors.ok,logger:l.info};var d=_.sortBy(g,"filepath"),e="";d.forEach(function(d){var g=d.is,h=d.filepath,j=d.err,l=d.msg,m=d.globals,n=d.globalsList;if(p||g!==f.OK){var o=b[g],q=o.color,r=o.logger,s=g===f.OK?colors.green(g):q(g),t=a.getFilename(h),u=path.dirname(h),v="";l&&(v+=": "+l),j&&(v+=": \""+j.message+"\""),c.idea&&(v+=" ("+a.getIDEALink(h)+")"),e!==u&&(e=u,k.info(""+u)),r(q(""+(" "+s+" "+t)+v)),m&&n&&n.filter(function(a){return!a.isExcluded}).forEach(function(b){var d=b.varName,e=b.lineInfo,f=b.fullFilePath,g=colors.cyan(e.line+":"+e.column),h=" "+g+" "+d;c["idea-globals"]&&(h+=" ("+a.getIDEALink(f,e.line,e.column)+")"),i.warn(h)})}})},this.saveResults=function(){var a=c.save;if(a){var b=_.groupBy(g,function(a){return path.dirname(a.filepath)}),d={files:b,legacyFallbacks:h,globals:this._globals,stats:{}};d.stats.percentageOfCovered=this._percentageOfConverted(),d.stats.countTotalModules=this._totalModuleCount(),d.stats.countNonAMD=this._countNonAMD,d.stats.countGlobals=this._countGlobals,d.stats.countAMDDefine=this._countAMDDefine,d.stats.countAMDRequire=this._countAMDRequire,this._saveToFile(d,a)}},this._saveToFile=function(a,b){fs.writeFile(b,JSON.stringify(a),function(a){if(a)return console.error(a)})},this.printGlobalsSummary=function(){if(n){!1!==c.files&&j.info("=====================================");var a=[];_(this._globals).filter(function(a){return!a.isExcluded}).countBy("varName").forEach(function(b,c){return a.push({varName:c,count:b})}),_(a).sortBy(["count","varName"]).forEach(function(a){var b=a.count,c=a.varName;j.info(c+" - "+colors.warn(b))})}},this._totalModuleCount=function(){return this._countAMDDefine+this._countAMDRequire},this._percentageOfConverted=function(){var a=this._totalModuleCount();return 100*(a/(a+this._countNonAMD))},this.printSummary=function(a){if(a)throw a;if(!1!==c.summary){(!1!==c.files||n)&&m.info("=====================================");var b=this._percentageOfConverted();m.info("Files identified as AMD modules: "+this._totalModuleCount()),m.info(" define() calls: "+this._countAMDDefine),m.info(" require() calls: "+this._countAMDRequire),m.warn(colors.error("Files not converted: "+this._countNonAMD)),m.warn(colors.warn("Illegal globals found: "+this._countGlobals)),m.info((isNaN(b)?0:Math.round(b,2))+"% converted")}},this.getGlobs=function(a){var c=[],d=a+"/";return e.forEach(function(a){c.push(d+a)}),b.exclude.patterns&&b.exclude.patterns.forEach(function(a){c.push("!"+d+a)}),c},this.run=function(){var c=this;this._excludedGlobals=this.setupExcludedGlobals(b.env,Object.keys(globals.builtin));var d=glob.sync(this.getGlobs(a));d.forEach(function(a){var b=fs.readFileSync(a,"utf8");c.handleFile(null,b,a,function(){})}),this.printFileSummary(),this.printGlobalsSummary(),this.printSummary(),this.saveResults()}}module.exports=ConversionDetector; | ||
"use strict";var _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(a){return typeof a}:function(a){return a&&"function"==typeof Symbol&&a.constructor===Symbol&&a!==Symbol.prototype?"symbol":typeof a};function _toConsumableArray(a){if(Array.isArray(a)){for(var b=0,c=Array(a.length);b<a.length;b++)c[b]=a[b];return c}return Array.from(a)}var acorn=require("acorn"),glob=require("globby"),detectAMD=require("./detect-amd"),detectLegacyFallback=require("./detect-ajs-namespace"),detectGlobals=require("acorn-globals"),globals=require("globals"),arrayUniq=require("array-uniq"),_=require("lodash"),fs=require("fs"),path=require("path"),colors=require("colors/safe"),winston=require("winston");colors.setTheme({ok:"grey",warn:"yellow",error:"red"});function ConversionDetector(a,b,c){function d(a){return new winston.Logger({level:a})}var f=b.symbols,e=b.patterns||["**/*.js"],g=[],h=[],i=d(),j=d(),k=d(),l=d(c["file-log-level"]),m=d(),n=!!c["globals-summary"],o=c.globals||c["idea-globals"],p=!1!==c.ok;(function(){o&&i.add(winston.transports.Console,{showLevel:!1}),n&&j.add(winston.transports.Console,{showLevel:!1}),!1!==c.files&&(k.add(winston.transports.Console,{showLevel:!1}),l.add(winston.transports.Console,{showLevel:!1})),!1!==c.summary&&m.add(winston.transports.Console,{showLevel:!1})})(),this._excludedGlobals=[],this._globals=[],this._countNonAMD=0,this._countGlobals=0,this._countAMDDefine=0,this._countAMDRequire=0,this.setupExcludedGlobals=function(a,b){var c="undefined"==typeof b?[]:b;return a&&Object.keys(a).filter(function(b){return a[b]}).forEach(function(a){var b=globals[a];b&&(c=arrayUniq(c.concat(Object.keys(b))))}),c},this.getFilename=function(a){return path.basename(a)},this.markAsNonAMD=function(a){++this._countNonAMD,g.push({filepath:a,amd:!1,is:f.ERR,msg:"Not an AMD module"})},this.markAsAMD=function(a,b){++this._countAMDDefine,this.findGlobals(a,b)},this.markAsAMDRequire=function(a,b){++this._countAMDRequire,this.findGlobals(a,b)},this.trimToEndOfVariableName=function(a){for(var b,c=[],d=a.parents.length-1;0<=d;d--)if(b=a.parents[d],"Identifier"===b.type)c.push(b.name);else if("MemberExpression"===b.type)c.push(b.property.name||b.property.value);else if("ThisExpression"===b.type)c.push("this");else break;return c.join(".")},this.isExcludedVariable=function(a){var c=[],d=a.split(".").some(function(a){c.push(a);var d=c.join(".");return-1<b.exclude.variables.indexOf(d)});return d},this.isAMDDefine=function(a){return"object"===("undefined"==typeof a?"undefined":_typeof(a))&&a.hasOwnProperty("type")&&"define"===a.type},this.isAMDRequire=function(a){return"object"===("undefined"==typeof a?"undefined":_typeof(a))&&a.hasOwnProperty("type")&&"require"===a.type},this.isNamedAMDModule=function(a){return this.isAMDDefine(a)&&a.hasOwnProperty("name")&&!!a.name},this.getRelevantGlobals=function(a){var b=this;return detectGlobals(a).filter(function(c){if(-1<b._excludedGlobals.indexOf(c.name))return!1;var d=b.getRelevantOccurrences(a,c.nodes);return 0<d.length})},this.getRelevantOccurrences=function(a,b){var c=this;return b?b.filter(function(a){var b=c.trimToEndOfVariableName(a);return!c.isExcludedVariable(b)&&(++c._countGlobals,!0)}):[]},this.processRelevantOccurrences=function(a,b,c){var d=this;return b?b.map(function(b){var e=acorn.getLineInfo(a,b.start),f=d.trimToEndOfVariableName(b),g=d.isExcludedVariable(f);return{varName:f,lineInfo:e,isExcluded:g,fullFilePath:c}}):[]},this.getIDEALink=function(a,b,c){return b&&c?colors.grey.underline("http://localhost:63342/api/file/"+process.cwd()+"/"+a+":"+b+":"+c):colors.underline("http://localhost:63342/api/file/"+process.cwd()+"/"+a)},this.findGlobals=function(a,b){var c=this;try{var d=this.getRelevantGlobals(b),e=[];if(0===d.length)return void g.push({filepath:a,amd:!0,globals:!1,is:f.OK});o&&d.forEach(function(d){var f=c.processRelevantOccurrences(b,d.nodes,a);e=e.concat(f),c._globals=c._globals.concat(f)}),g.push({filepath:a,amd:!0,is:f.ALERT,globals:!0,globalsList:e,msg:"Globals detected"})}catch(b){g.push({filepath:a,amd:!0,is:f.ERR,err:b,msg:"Error finding globals"})}},this.handleFile=function(a,b,c,d){try{if(a)throw new Error(a.message?a.message:a);var e=detectAMD(b),i=e&&e[0];this.isNamedAMDModule(i)?this.markAsAMD(c,b):this.isAMDDefine(i)?this.markAsAMD(c,b):this.isAMDRequire(i)?this.markAsAMDRequire(c,b):this.markAsNonAMD(c);var j=detectLegacyFallback(b);j.length&&h.push.apply(h,_toConsumableArray(j))}catch(a){g.push({filepath:c,is:f.ERR,err:a,msg:"Error parsing file"})}d()},this.printFileSummary=function(){var a=this,b={};b[f.ERR]={color:colors.error,logger:l.error},b[f.ALERT]={color:colors.warn,logger:l.warn},b[f.OK]={color:colors.ok,logger:l.info};var d=_.sortBy(g,"filepath"),e="";d.forEach(function(d){var g=d.is,h=d.filepath,j=d.err,l=d.msg,m=d.globals,n=d.globalsList;if(p||g!==f.OK){var o=b[g],q=o.color,r=o.logger,s=g===f.OK?colors.green(g):q(g),t=a.getFilename(h),u=path.dirname(h),v="";l&&(v+=": "+l),j&&(v+=": \""+j.message+"\""),c.idea&&(v+=" ("+a.getIDEALink(h)+")"),e!==u&&(e=u,k.info(""+u)),r(q(""+(" "+s+" "+t)+v)),m&&n&&n.filter(function(a){return!a.isExcluded}).forEach(function(b){var d=b.varName,e=b.lineInfo,f=b.fullFilePath,g=colors.cyan(e.line+":"+e.column),h=" "+g+" "+d;c["idea-globals"]&&(h+=" ("+a.getIDEALink(f,e.line,e.column)+")"),i.warn(h)})}})},this.saveResults=function(){var a=c.save;if(a){var b=_.groupBy(g,function(a){return path.dirname(a.filepath)}),d={files:b,legacyFallbacks:h,globals:this._globals,stats:{}};d.stats.percentageOfCovered=this._percentageOfConverted(),d.stats.countTotalModules=this._totalModuleCount(),d.stats.countNonAMD=this._countNonAMD,d.stats.countGlobals=this._countGlobals,d.stats.countAMDDefine=this._countAMDDefine,d.stats.countAMDRequire=this._countAMDRequire,this._saveToFile(d,a)}},this._saveToFile=function(a,b){fs.writeFile(b,JSON.stringify(a),function(a){if(a)return console.error(a)})},this.printGlobalsSummary=function(){if(n){!1!==c.files&&j.info("=====================================");var a=[];_(this._globals).filter(function(a){return!a.isExcluded}).countBy("varName").forEach(function(b,c){return a.push({varName:c,count:b})}),_(a).sortBy(["count","varName"]).forEach(function(a){var b=a.count,c=a.varName;j.info(c+" - "+colors.warn(b))})}},this._totalModuleCount=function(){return this._countAMDDefine+this._countAMDRequire},this._percentageOfConverted=function(){var a=this._totalModuleCount();return 100*(a/(a+this._countNonAMD))},this.printSummary=function(a){if(a)throw a;if(!1!==c.summary){(!1!==c.files||n)&&m.info("=====================================");var b=this._percentageOfConverted();m.info("Files identified as AMD modules: "+this._totalModuleCount()),m.info(" define() calls: "+this._countAMDDefine),m.info(" require() calls: "+this._countAMDRequire),m.warn(colors.error("Files not converted: "+this._countNonAMD)),m.warn(colors.warn("Illegal globals found: "+this._countGlobals)),m.info((isNaN(b)?0:Math.round(b,2))+"% converted")}},this.getGlobs=function(a){var c=[],d=a+"/";return e.forEach(function(a){c.push(d+a)}),b.exclude.patterns&&b.exclude.patterns.forEach(function(a){c.push("!"+d+a)}),c},this.run=function(){var c=this;this._excludedGlobals=this.setupExcludedGlobals(b.env,Object.keys(globals.builtin));var d=glob.sync(this.getGlobs(a));d.forEach(function(a){var b=fs.readFileSync(a,"utf8");c.handleFile(null,b,a,function(){})}),this.printFileSummary(),this.printGlobalsSummary(),this.printSummary(),this.saveResults()}}module.exports=ConversionDetector; |
{ | ||
"name": "amd-conversion-analyser", | ||
"version": "1.7.0", | ||
"version": "1.7.1", | ||
"license": "Apache-2.0", | ||
@@ -21,2 +21,6 @@ "description": "", | ||
}, | ||
"publishConfig": { | ||
"access": "public", | ||
"registry": "https://registry.npmjs.com/" | ||
}, | ||
"author": "Atlassian", | ||
@@ -57,3 +61,3 @@ "contributors": [ | ||
"babel-preset-env": "^1.6.0", | ||
"babel-preset-minify": "^0.2.0", | ||
"babel-preset-minify": "^0.3.0", | ||
"chai": "^4.1.2", | ||
@@ -60,0 +64,0 @@ "chai-things": "^0.2.0", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
0
111419
34