Skip to content

Commit a88cd4b

Browse files
committed
Update register and install_plugin_modules
Taken from Bryan
1 parent fd5e1be commit a88cd4b

File tree

2 files changed

+29
-25
lines changed

2 files changed

+29
-25
lines changed

packages/datadog-instrumentations/src/helpers/register.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ const {
1616

1717
const hooks = require('./hooks')
1818
const instrumentations = require('./instrumentations')
19+
const latests = require('./latests.json')
1920
const names = Object.keys(hooks)
2021
const pathSepExpr = new RegExp(`\\${path.sep}`, 'g')
2122
const disabledInstrumentations = new Set(
@@ -110,7 +111,7 @@ for (const packageName of names) {
110111
namesAndSuccesses[`${name}@${version}`] = false
111112
}
112113

113-
if (matchVersion(version, versions)) {
114+
if (matchVersion(version, versions) && matchesLatestSupported(name, version)) {
114115
// Check if the hook already has a set moduleExport
115116
if (hook[HOOK_SYMBOL].has(moduleExports)) {
116117
namesAndSuccesses[`${name}@${version}`] = true
@@ -158,6 +159,17 @@ function matchVersion (version, ranges) {
158159
return !version || (ranges && ranges.some(range => satisfies(version, range)))
159160
}
160161

162+
function matchesLatestSupported (name, version) {
163+
if (latests.pinned.includes(name)) {
164+
// These ones are deliberately pinned to a specific version. That
165+
// means we can skip this check, since it will already have been checked
166+
// to be lower than latest.
167+
return true
168+
}
169+
const latest = latests.latests[name]
170+
return matchVersion(version, ['<=' + latest])
171+
}
172+
161173
function getVersion (moduleBaseDir) {
162174
if (moduleBaseDir) {
163175
return requirePackageJson(moduleBaseDir, module).version

scripts/install_plugin_modules.js

Lines changed: 16 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,20 @@ const path = require('path')
66
const crypto = require('crypto')
77
const semver = require('semver')
88
const exec = require('./helpers/exec')
9-
const childProcess = require('child_process')
109
const externals = require('../packages/dd-trace/test/plugins/externals')
1110
const { getInstrumentation } = require('../packages/dd-trace/test/setup/helpers/load-inst')
11+
const {
12+
getVersionList,
13+
npmView
14+
} = require('./helpers/versioning')
15+
const latests = require('../packages/datadog-instrumentations/src/helpers/latests.json')
1216

1317
const requirePackageJsonPath = require.resolve('../packages/dd-trace/src/require-package-json')
1418

1519
// Can remove aerospike after removing support for aerospike < 5.2.0 (for Node.js 22, v5.12.1 is required)
1620
// Can remove couchbase after removing support for couchbase <= 3.2.0
1721
const excludeList = os.arch() === 'arm64' ? ['aerospike', 'couchbase', 'grpc', 'oracledb'] : []
1822
const workspaces = new Set()
19-
const versionLists = {}
2023
const deps = {}
2124
const filter = process.env.hasOwnProperty('PLUGINS') && process.env.PLUGINS.split('|')
2225

@@ -133,7 +136,17 @@ async function assertPackage (name, version, dependencyVersionRange, external) {
133136
}
134137

135138
async function addDependencies (dependencies, name, versionRange) {
136-
const versionList = await getVersionList(name)
139+
let versionList = await getVersionList(name)
140+
if (!latests.pinned.includes(name)) {
141+
const maxVersion = latests.latests[name]
142+
versionList = versionList.map(version => {
143+
if (version.startsWith('>=') && !version.includes('<')) {
144+
return version + ' <=' + maxVersion
145+
} else {
146+
return version
147+
}
148+
})
149+
}
137150
const version = semver.maxSatisfying(versionList, versionRange)
138151
const pkgJson = await npmView(`${name}@${version}`)
139152
for (const dep of deps[name]) {
@@ -152,27 +165,6 @@ async function addDependencies (dependencies, name, versionRange) {
152165
}
153166
}
154167

155-
async function getVersionList (name) {
156-
if (versionLists[name]) {
157-
return versionLists[name]
158-
}
159-
const list = await npmView(`${name} versions`)
160-
versionLists[name] = list
161-
return list
162-
}
163-
164-
function npmView (input) {
165-
return new Promise((resolve, reject) => {
166-
childProcess.exec(`npm view ${input} --json`, (err, stdout) => {
167-
if (err) {
168-
reject(err)
169-
return
170-
}
171-
resolve(JSON.parse(stdout.toString('utf8')))
172-
})
173-
})
174-
}
175-
176168
function assertIndex (name, version) {
177169
const index = `'use strict'
178170

0 commit comments

Comments
 (0)