@@ -5,18 +5,21 @@ const os = require('os')
5
5
const path = require ( 'path' )
6
6
const crypto = require ( 'crypto' )
7
7
const semver = require ( 'semver' )
8
- const proxyquire = require ( 'proxyquire' )
9
8
const exec = require ( './helpers/exec' )
10
- const childProcess = require ( 'child_process' )
11
9
const externals = require ( '../packages/dd-trace/test/plugins/externals' )
10
+ const {
11
+ getVersionList,
12
+ getInternals,
13
+ npmView
14
+ } = require ( './helpers/versioning' )
15
+ const latests = require ( '../packages/datadog-instrumentations/src/helpers/latests.json' )
12
16
13
17
const requirePackageJsonPath = require . resolve ( '../packages/dd-trace/src/require-package-json' )
14
18
15
19
// Can remove aerospike after removing support for aerospike < 5.2.0 (for Node.js 22, v5.12.1 is required)
16
20
// Can remove couchbase after removing support for couchbase <= 3.2.0
17
21
const excludeList = os . arch ( ) === 'arm64' ? [ 'aerospike' , 'couchbase' , 'grpc' , 'oracledb' ] : [ ]
18
22
const workspaces = new Set ( )
19
- const versionLists = { }
20
23
const deps = { }
21
24
const filter = process . env . hasOwnProperty ( 'PLUGINS' ) && process . env . PLUGINS . split ( '|' )
22
25
@@ -46,21 +49,7 @@ async function run () {
46
49
}
47
50
48
51
async function assertVersions ( ) {
49
- const internals = names
50
- . map ( key => {
51
- const instrumentations = [ ]
52
- const name = key
53
-
54
- try {
55
- loadInstFile ( `${ name } /server.js` , instrumentations )
56
- loadInstFile ( `${ name } /client.js` , instrumentations )
57
- } catch ( e ) {
58
- loadInstFile ( `${ name } .js` , instrumentations )
59
- }
60
-
61
- return instrumentations
62
- } )
63
- . reduce ( ( prev , next ) => prev . concat ( next ) , [ ] )
52
+ const internals = getInternals ( )
64
53
65
54
for ( const inst of internals ) {
66
55
await assertInstrumentation ( inst , false )
@@ -145,7 +134,17 @@ async function assertPackage (name, version, dependency, external) {
145
134
}
146
135
147
136
async function addDependencies ( dependencies , name , versionRange ) {
148
- const versionList = await getVersionList ( name )
137
+ let versionList = await getVersionList ( name )
138
+ if ( ! latests . pinned . includes ( name ) ) {
139
+ const maxVersion = latests . latests [ name ]
140
+ versionList = versionList . map ( version => {
141
+ if ( version . startsWith ( '>=' ) && ! version . includes ( '<' ) ) {
142
+ return version + ' <=' + maxVersion
143
+ } else {
144
+ return version
145
+ }
146
+ } )
147
+ }
149
148
const version = semver . maxSatisfying ( versionList , versionRange )
150
149
const pkgJson = await npmView ( `${ name } @${ version } ` )
151
150
for ( const dep of deps [ name ] ) {
@@ -158,27 +157,6 @@ async function addDependencies (dependencies, name, versionRange) {
158
157
}
159
158
}
160
159
161
- async function getVersionList ( name ) {
162
- if ( versionLists [ name ] ) {
163
- return versionLists [ name ]
164
- }
165
- const list = await npmView ( `${ name } versions` )
166
- versionLists [ name ] = list
167
- return list
168
- }
169
-
170
- function npmView ( input ) {
171
- return new Promise ( ( resolve , reject ) => {
172
- childProcess . exec ( `npm view ${ input } --json` , ( err , stdout ) => {
173
- if ( err ) {
174
- reject ( err )
175
- return
176
- }
177
- resolve ( JSON . parse ( stdout . toString ( 'utf8' ) ) )
178
- } )
179
- } )
180
- }
181
-
182
160
function assertIndex ( name , version ) {
183
161
const index = `'use strict'
184
162
@@ -234,18 +212,3 @@ function sha1 (str) {
234
212
shasum . update ( str )
235
213
return shasum . digest ( 'hex' )
236
214
}
237
-
238
- function loadInstFile ( file , instrumentations ) {
239
- const instrument = {
240
- addHook ( instrumentation ) {
241
- instrumentations . push ( instrumentation )
242
- }
243
- }
244
-
245
- const instPath = path . join ( __dirname , `../packages/datadog-instrumentations/src/${ file } ` )
246
-
247
- proxyquire . noPreserveCache ( ) ( instPath , {
248
- './helpers/instrument' : instrument ,
249
- '../helpers/instrument' : instrument
250
- } )
251
- }
0 commit comments