Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove semver and replace with simpler semifies #5251

Merged
merged 2 commits into from
Feb 12, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion LICENSE-3rdparty.csv
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ require,protobufjs,BSD-3-Clause,Copyright 2016 Daniel Wirtz
require,tlhunter-sorted-set,MIT,Copyright (c) 2023 Datadog Inc.
require,retry,MIT,Copyright 2011 Tim Koschützki Felix Geisendörfer
require,rfdc,MIT,Copyright 2019 David Mark Clements
require,semver,ISC,Copyright Isaac Z. Schlueter and Contributors
require,semifies,Apache license 2.0,Copyright Authors
require,shell-quote,mit,Copyright (c) 2013 James Halliday
require,source-map,BSD-3-Clause,Copyright (c) 2009-2011, Mozilla Foundation and contributors
require,ttl-set,MIT,Copyright (c) 2024 Thomas Watson
Expand Down Expand Up @@ -68,6 +68,7 @@ dev,nock,MIT,Copyright 2017 Pedro Teixeira and other contributors
dev,nyc,ISC,Copyright 2015 Contributors
dev,proxyquire,MIT,Copyright 2013 Thorsten Lorenz
dev,rimraf,ISC,Copyright Isaac Z. Schlueter and Contributors
dev,semver,ISC,Copyright Isaac Z. Schlueter and Contributors
dev,sinon,BSD-3-Clause,Copyright 2010-2017 Christian Johansen
dev,sinon-chai,WTFPL and BSD-2-Clause,Copyright 2004 Sam Hocevar 2012–2017 Domenic Denicola
dev,tap,ISC,Copyright 2011-2022 Isaac Z. Schlueter and Contributors
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@
"protobufjs": "^7.2.5",
"retry": "^0.13.1",
"rfdc": "^1.3.1",
"semver": "^7.5.4",
"semifies": "^1.0.0",
"shell-quote": "^1.8.1",
"source-map": "^0.7.4",
"tlhunter-sorted-set": "^0.1.0",
Expand Down Expand Up @@ -152,6 +152,7 @@
"nyc": "^15.1.0",
"proxyquire": "^1.8.0",
"rimraf": "^3.0.0",
"semver": "^7.5.4",
"sinon": "^16.1.3",
"sinon-chai": "^3.7.0",
"tap": "^16.3.7",
Expand Down
4 changes: 2 additions & 2 deletions packages/datadog-instrumentations/src/helpers/instrument.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict'

const dc = require('dc-polyfill')
const semver = require('semver')
const satisfies = require('semifies')
const instrumentations = require('./instrumentations')
const { AsyncResource } = require('async_hooks')

Expand Down Expand Up @@ -36,7 +36,7 @@ exports.addHook = function addHook ({ name, versions, file, filePattern }, hook)

// AsyncResource.bind exists and binds `this` properly only from 17.8.0 and up.
// https://nodejs.org/api/async_context.html#asyncresourcebindfn-thisarg
if (semver.satisfies(process.versions.node, '>=17.8.0')) {
if (satisfies(process.versions.node, '>=17.8.0')) {
exports.AsyncResource = AsyncResource
} else {
exports.AsyncResource = class extends AsyncResource {
Expand Down
4 changes: 2 additions & 2 deletions packages/datadog-instrumentations/src/helpers/register.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

const { channel } = require('dc-polyfill')
const path = require('path')
const semver = require('semver')
const satisfies = require('semifies')
const Hook = require('./hook')
const requirePackageJson = require('../../../dd-trace/src/require-package-json')
const log = require('../../../dd-trace/src/log')
Expand Down Expand Up @@ -155,7 +155,7 @@ for (const packageName of names) {
}

function matchVersion (version, ranges) {
return !version || (ranges && ranges.some(range => semver.satisfies(semver.coerce(version), range)))
return !version || (ranges && ranges.some(range => satisfies(version, range)))
}

function getVersion (moduleBaseDir) {
Expand Down
6 changes: 3 additions & 3 deletions packages/datadog-instrumentations/src/mysql2.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ const {
AsyncResource
} = require('./helpers/instrument')
const shimmer = require('../../datadog-shimmer')
const semver = require('semver')
const satisfies = require('semifies')

function wrapConnection (Connection, version) {
const startCh = channel('apm:mysql2:query:start')
const finishCh = channel('apm:mysql2:query:finish')
const errorCh = channel('apm:mysql2:query:error')
const startOuterQueryCh = channel('datadog:mysql2:outerquery:start')
const shouldEmitEndAfterQueryAbort = semver.intersects(version, '>=1.3.3')
const shouldEmitEndAfterQueryAbort = satisfies(version, '>=1.3.3')

shimmer.wrap(Connection.prototype, 'addCommand', addCommand => function (cmd) {
if (!startCh.hasSubscribers) return addCommand.apply(this, arguments)
Expand Down Expand Up @@ -154,7 +154,7 @@ function wrapConnection (Connection, version) {
}
function wrapPool (Pool, version) {
const startOuterQueryCh = channel('datadog:mysql2:outerquery:start')
const shouldEmitEndAfterQueryAbort = semver.intersects(version, '>=1.3.3')
const shouldEmitEndAfterQueryAbort = satisfies(version, '>=1.3.3')

shimmer.wrap(Pool.prototype, 'query', query => function (sql, values, cb) {
if (!startOuterQueryCh.hasSubscribers) return query.apply(this, arguments)
Expand Down
10 changes: 5 additions & 5 deletions packages/datadog-instrumentations/src/playwright.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const semver = require('semver')
const satisfies = require('semifies')

const { addHook, channel, AsyncResource } = require('./helpers/instrument')
const shimmer = require('../../datadog-shimmer')
Expand Down Expand Up @@ -42,7 +42,7 @@ let isFlakyTestRetriesEnabled = false
let flakyTestRetriesCount = 0
let knownTests = {}
let rootDir = ''
const MINIMUM_SUPPORTED_VERSION_EFD = '1.38.0'
const MINIMUM_SUPPORTED_VERSION_RANGE_EFD = '>=1.38.0'

function isNewTest (test) {
const testSuite = getTestSuitePath(test._requireFile, rootDir)
Expand Down Expand Up @@ -431,7 +431,7 @@ function runnerHook (runnerExport, playwrightVersion) {
log.error('Playwright session start error', e)
}

if (isKnownTestsEnabled && semver.gte(playwrightVersion, MINIMUM_SUPPORTED_VERSION_EFD)) {
if (isKnownTestsEnabled && satisfies(playwrightVersion, MINIMUM_SUPPORTED_VERSION_RANGE_EFD)) {
try {
const { err, knownTests: receivedKnownTests } = await getChannelPromise(knownTestsCh)
if (!err) {
Expand Down Expand Up @@ -540,7 +540,7 @@ addHook({
addHook({
name: 'playwright',
file: 'lib/common/suiteUtils.js',
versions: [`>=${MINIMUM_SUPPORTED_VERSION_EFD}`]
versions: [MINIMUM_SUPPORTED_VERSION_RANGE_EFD]
}, suiteUtilsPackage => {
// We grab `applyRepeatEachIndex` to use it later
// `applyRepeatEachIndex` needs to be applied to a cloned suite
Expand All @@ -552,7 +552,7 @@ addHook({
addHook({
name: 'playwright',
file: 'lib/runner/loadUtils.js',
versions: [`>=${MINIMUM_SUPPORTED_VERSION_EFD}`]
versions: [MINIMUM_SUPPORTED_VERSION_RANGE_EFD]
}, (loadUtilsPackage) => {
const oldCreateRootSuite = loadUtilsPackage.createRootSuite

Expand Down
4 changes: 2 additions & 2 deletions packages/dd-trace/src/iitm.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
'use strict'

const semver = require('semver')
const satisfies = require('semifies')
const logger = require('./log')
const { addHook } = require('import-in-the-middle')
const dc = require('dc-polyfill')

if (semver.satisfies(process.versions.node, '>=14.13.1')) {
if (satisfies(process.versions.node, '>=14.13.1')) {
const moduleLoadStartChannel = dc.channel('dd-trace:moduleLoadStart')
addHook((name, namespace) => {
if (moduleLoadStartChannel.hasSubscribers) {
Expand Down
4 changes: 2 additions & 2 deletions packages/dd-trace/src/opentracing/span.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
const { performance } = require('perf_hooks')
const now = performance.now.bind(performance)
const dateNow = Date.now
const semver = require('semver')
const satisfies = require('semifies')
const SpanContext = require('./span_context')
const id = require('../id')
const tagger = require('../tagger')
Expand Down Expand Up @@ -365,7 +365,7 @@ class DatadogSpan {
}

function createRegistry (type) {
if (!semver.satisfies(process.version, '>=14.6')) return
if (!satisfies(process.version, '>=14.6')) return

return new global.FinalizationRegistry(name => {
runtimeMetrics.decrement(`runtime.node.spans.${type}`)
Expand Down
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4397,6 +4397,11 @@ scheduler@^0.20.2:
loose-envify "^1.1.0"
object-assign "^4.1.1"

semifies@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/semifies/-/semifies-1.0.0.tgz#b69569f32c2ba2ac04f705ea82831364289b2ae2"
integrity sha512-xXR3KGeoxTNWPD4aBvL5NUpMTT7WMANr3EWnaS190QVkY52lqqcVRD7Q05UVbBhiWDGWMlJEUam9m7uFFGVScw==

semver@^6.0.0, semver@^6.3.0, semver@^6.3.1:
version "6.3.1"
resolved "https://registry.yarnpkg.com/semver/-/semver-6.3.1.tgz#556d2ef8689146e46dcea4bfdd095f3434dffcb4"
Expand Down
Loading