@@ -60,18 +60,6 @@ function loadInstFile (file, instrumentations) {
6060 } )
6161}
6262
63- function removeVersions ( instrumentations = [ ] , external ) {
64- return instrumentations . filter ( instrumentation => {
65- let keep = true
66- instrumentation . versions . forEach ( instVersion => {
67- external . versions . forEach ( ( extVersion ) => {
68- if ( semver . intersects ( instVersion , extVersion ) ) keep = false
69- } )
70- } )
71- return keep
72- } )
73- }
74-
7563function withVersions ( plugin , modules , range , cb ) {
7664 let instrumentations = typeof plugin === 'string' ? loadInst ( plugin ) : [ ] . concat ( plugin )
7765 const names = instrumentations . map ( instrumentation => instrumentation . name )
@@ -82,22 +70,29 @@ function withVersions (plugin, modules, range, cb) {
8270 if ( externals [ name ] ) {
8371 [ ] . concat ( externals [ name ] ) . forEach ( external => {
8472 const { nodeVersions } = external
85- let satisfies = true
86- if ( nodeVersions ) {
87- satisfies = false
88- for ( const version of nodeVersions ) {
89- if ( semver . satisfies ( process . version , version ) ) {
90- satisfies = true
91- break
92- }
93- }
94- }
73+ const satisfies = nodeVersions
74+ ? nodeVersions
75+ . reduce ( ( satisfies , version ) => satisfies || semver . satisfies ( process . version , version ) , false )
76+ : true
9577
9678 if ( satisfies ) {
79+ // use external in instrumentation
9780 instrumentations . push ( external )
9881 } else {
99- // remove all versions with that don't satisfy node version based on externals
100- instrumentations = removeVersions ( instrumentations , external )
82+ // node version not satisifed
83+ // don't add this external, and remove all other instrumentations from testing with overlapping versions
84+ instrumentations = instrumentations . filter ( instrumentation => {
85+ return instrumentation . versions
86+ . reduce ( ( crossed , instVersion ) => {
87+ external . versions . forEach ( extVersion => crossed . push ( [ instVersion , extVersion ] ) )
88+ return crossed
89+ }
90+ , [ ] ) // cross instrumentation versions with externals versions
91+ . reduce ( ( matches , versions ) => {
92+ const [ instVersion , extVersion ] = versions
93+ return matches && ! semver . intersects ( instVersion , extVersion )
94+ } , true ) // filter on matching overlaps
95+ } )
10196 }
10297 } )
10398 }
0 commit comments