1- import { DepDict , DepTree } from './types' ;
1+ import { DepDict , DepTree } from './types' ;
22
33const tabdown = require ( './tabdown' ) ;
44import * as types from './types' ;
55
6- export {
7- parse ,
8- parseSbtPluginResults ,
9- } ;
6+ export { parse , parseSbtPluginResults } ;
107
118function convertStrToTree ( dependenciesTextTree ) {
129 const lines = dependenciesTextTree . toString ( ) . split ( '\n' ) || [ ] ;
@@ -69,25 +66,25 @@ function convertCoursierStrToTree(dependenciesTextTree) {
6966function walkInTree ( toNode , fromNode ) {
7067 if ( fromNode . children && fromNode . children . length > 0 ) {
7168 for ( const j of Object . keys ( fromNode . children ) ) {
72- const externalNode = getPackageNameAndVersion (
73- fromNode . children [ j ] . data ) ;
69+ const externalNode = getPackageNameAndVersion ( fromNode . children [ j ] . data ) ;
7470 if ( externalNode ) {
7571 const newNode = {
7672 version : externalNode . version ,
7773 name : externalNode . name ,
7874 dependencies : [ ] ,
7975 } ;
8076 toNode . dependencies . push ( newNode ) ;
81- walkInTree ( toNode . dependencies [ toNode . dependencies . length - 1 ] ,
82- fromNode . children [ j ] ) ;
77+ walkInTree (
78+ toNode . dependencies [ toNode . dependencies . length - 1 ] ,
79+ fromNode . children [ j ] ,
80+ ) ;
8381 }
8482 }
8583 }
8684 delete toNode . parent ;
8785}
8886
8987function getPackageNameAndVersion ( packageDependency ) {
90- let splited ;
9188 let version ;
9289 let app ;
9390 if ( packageDependency . indexOf ( '(evicted by:' ) > - 1 ) {
@@ -96,13 +93,13 @@ function getPackageNameAndVersion(packageDependency) {
9693 if ( packageDependency . indexOf ( '->' ) > - 1 ) {
9794 return null ;
9895 }
99- splited = packageDependency . split ( ':' ) ;
96+ const splited = packageDependency . split ( ':' ) ;
10097 version = splited [ splited . length - 1 ] ;
10198 app = splited [ 0 ] + ':' + splited [ 1 ] ;
10299 app = app . split ( '\t' ) . join ( '' ) ;
103100 app = app . trim ( ) ;
104101 version = version . trim ( ) ;
105- return { name : app , version} ;
102+ return { name : app , version } ;
106103}
107104
108105function convertDepArrayToObject ( depsArr ) {
@@ -145,7 +142,7 @@ function createSnykTree(rootTree, name, version) {
145142
146143function getProjectName ( root ) {
147144 const app = root . split ( ' ' ) [ 0 ] . trim ( ) ;
148- return { name : app } ;
145+ return { name : app } ;
149146}
150147
151148function createCoursierSnykTree ( rootTree , name , version ) {
@@ -189,18 +186,26 @@ function parse(text, name, version, isCoursier): DepTree {
189186 return createSnykTree ( rootTree , name , version ) ;
190187}
191188
192- function parseSbtPluginResults ( sbtOutput : string , packageName : string , packageVersion : string ) : DepTree {
189+ function parseSbtPluginResults (
190+ sbtOutput : string ,
191+ packageName : string ,
192+ packageVersion : string ,
193+ ) : DepTree {
193194 // remove all other output
194195 const outputStart = 'Snyk Output Start' ;
195196 const outputEnd = 'Snyk Output End' ;
196197 const sbtProjectOutput = sbtOutput . substring (
197198 sbtOutput . indexOf ( outputStart ) + outputStart . length ,
198- sbtOutput . indexOf ( outputEnd ) ) ;
199+ sbtOutput . indexOf ( outputEnd ) ,
200+ ) ;
199201 const sbtOutputJson : types . SbtModulesGraph = JSON . parse ( sbtProjectOutput ) ;
200202
201203 if ( Object . keys ( sbtOutputJson ) . length === 1 ) {
202204 const project = Object . keys ( sbtOutputJson ) [ 0 ] ;
203- return parseSbtPluginProjectResultToDepTree ( project , sbtOutputJson [ project ] ) ;
205+ return parseSbtPluginProjectResultToDepTree (
206+ project ,
207+ sbtOutputJson [ project ] ,
208+ ) ;
204209 }
205210
206211 const depTree = {
@@ -211,7 +216,10 @@ function parseSbtPluginResults(sbtOutput: string, packageName: string, packageVe
211216
212217 // iterating over different project
213218 for ( const project of Object . keys ( sbtOutputJson ) ) {
214- depTree . dependencies [ project ] = parseSbtPluginProjectResultToDepTree ( project , sbtOutputJson [ project ] ) ;
219+ depTree . dependencies [ project ] = parseSbtPluginProjectResultToDepTree (
220+ project ,
221+ sbtOutputJson [ project ] ,
222+ ) ;
215223 }
216224
217225 return depTree ;
@@ -221,12 +229,13 @@ const PRODUCTION_SCOPES: string[] = ['compile', 'runtime', 'provided'];
221229
222230function parseSbtPluginProjectResultToDepTree (
223231 projectKey : string ,
224- sbtProjectOutput : types . SbtModulesGraph ) : DepTree {
225-
226- const pkgs = Object . keys ( sbtProjectOutput . modules )
227- . filter ( ( module ) => {
228- return sbtProjectOutput . modules [ module ] . configurations . some ( ( c ) => PRODUCTION_SCOPES . includes ( c ) ) ;
229- } ) ;
232+ sbtProjectOutput : types . SbtModulesGraph ,
233+ ) : DepTree {
234+ const pkgs = Object . keys ( sbtProjectOutput . modules ) . filter ( ( module ) => {
235+ return sbtProjectOutput . modules [ module ] . configurations . some ( ( c ) =>
236+ PRODUCTION_SCOPES . includes ( c ) ,
237+ ) ;
238+ } ) ;
230239
231240 const getDependenciesFor = ( name : string ) : DepTree => {
232241 if ( ! sbtProjectOutput . dependencies [ name ] ) {
@@ -237,7 +246,8 @@ function parseSbtPluginProjectResultToDepTree(
237246 }
238247 const dependencies : DepDict = { } ;
239248 for ( const subDepName of sbtProjectOutput . dependencies [ name ] ) {
240- if ( pkgs . indexOf ( subDepName ) > - 1 ) { // dependency is in production configuration
249+ if ( pkgs . indexOf ( subDepName ) > - 1 ) {
250+ // dependency is in production configuration
241251 dependencies [ subDepName ] = getDependenciesFor ( subDepName ) ;
242252 }
243253 }
0 commit comments