Skip to content

Commit a0e9489

Browse files
authored
chore(node): Extract node version constant (#7734)
1 parent c9fdf10 commit a0e9489

File tree

6 files changed

+13
-21
lines changed

6 files changed

+13
-21
lines changed

packages/node/src/integrations/http.ts

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,16 @@
11
import type { Hub } from '@sentry/core';
22
import { getCurrentHub } from '@sentry/core';
33
import type { EventProcessor, Integration, Span, TracePropagationTargets } from '@sentry/types';
4-
import {
5-
dynamicSamplingContextToSentryBaggageHeader,
6-
fill,
7-
logger,
8-
parseSemver,
9-
stringMatchesSomePattern,
10-
} from '@sentry/utils';
4+
import { dynamicSamplingContextToSentryBaggageHeader, fill, logger, stringMatchesSomePattern } from '@sentry/utils';
115
import type * as http from 'http';
126
import type * as https from 'https';
137
import { LRUMap } from 'lru_map';
148

159
import type { NodeClient } from '../client';
10+
import { NODE_VERSION } from '../nodeVersion';
1611
import type { RequestMethod, RequestMethodArgs } from './utils/http';
1712
import { cleanSpanDescription, extractRawUrl, extractUrl, isSentryRequest, normalizeRequestArgs } from './utils/http';
1813

19-
const NODE_VERSION = parseSemver(process.versions.node);
20-
2114
interface TracingOptions {
2215
/**
2316
* List of strings/regex controlling to which outgoing requests

packages/node/src/integrations/undici/index.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,15 @@ import type { EventProcessor, Integration } from '@sentry/types';
33
import {
44
dynamicRequire,
55
dynamicSamplingContextToSentryBaggageHeader,
6-
parseSemver,
76
stringMatchesSomePattern,
87
stripUrlQueryAndFragment,
98
} from '@sentry/utils';
109

1110
import type { NodeClient } from '../../client';
11+
import { NODE_VERSION } from '../../nodeVersion';
1212
import { isSentryRequest } from '../utils/http';
1313
import type { DiagnosticsChannel, RequestCreateMessage, RequestEndMessage, RequestErrorMessage } from './types';
1414

15-
const NODE_VERSION = parseSemver(process.versions.node);
16-
1715
export enum ChannelName {
1816
// https://github.com/nodejs/undici/blob/e6fc80f809d1217814c044f52ed40ef13f21e43c/docs/api/DiagnosticsChannel.md#undicirequestcreate
1917
RequestCreate = 'undici:request:create',

packages/node/src/integrations/utils/http.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
import { getCurrentHub } from '@sentry/core';
2-
import { parseSemver } from '@sentry/utils';
32
import type * as http from 'http';
43
import type * as https from 'https';
54
import { URL } from 'url';
65

7-
const NODE_VERSION = parseSemver(process.versions.node);
6+
import { NODE_VERSION } from '../../nodeVersion';
87

98
/**
109
* Checks whether given url points to Sentry server

packages/node/src/nodeVersion.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import { parseSemver } from '@sentry/utils';
2+
3+
export const NODE_VERSION: ReturnType<typeof parseSemver> = parseSemver(process.versions.node);

packages/node/test/integrations/http.test.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import type { Span, Transaction } from '@sentry/core';
22
import * as sentryCore from '@sentry/core';
33
import { addTracingExtensions, Hub } from '@sentry/core';
44
import type { TransactionContext } from '@sentry/types';
5-
import { logger, parseSemver, TRACEPARENT_REGEXP } from '@sentry/utils';
5+
import { logger, TRACEPARENT_REGEXP } from '@sentry/utils';
66
import * as http from 'http';
77
import * as https from 'https';
88
import * as HttpsProxyAgent from 'https-proxy-agent';
@@ -11,11 +11,10 @@ import * as nock from 'nock';
1111
import type { Breadcrumb } from '../../src';
1212
import { NodeClient } from '../../src/client';
1313
import { Http as HttpIntegration } from '../../src/integrations/http';
14+
import { NODE_VERSION } from '../../src/nodeVersion';
1415
import type { NodeClientOptions } from '../../src/types';
1516
import { getDefaultNodeClientOptions } from '../helper/node-client-options';
1617

17-
const NODE_VERSION = parseSemver(process.versions.node);
18-
1918
const originalHttpGet = http.get;
2019
const originalHttpRequest = http.request;
2120

packages/node/test/utils.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { parseSemver } from '@sentry/utils';
1+
import { NODE_VERSION } from '../src/nodeVersion';
22

33
/**
44
* Returns`describe` or `describe.skip` depending on allowed major versions of Node.
@@ -7,12 +7,12 @@ import { parseSemver } from '@sentry/utils';
77
* @return {*} {jest.Describe}
88
*/
99
export const conditionalTest = (allowedVersion: { min?: number; max?: number }): jest.Describe => {
10-
const NODE_VERSION = parseSemver(process.versions.node).major;
11-
if (!NODE_VERSION) {
10+
const major = NODE_VERSION.major;
11+
if (!major) {
1212
return describe.skip as jest.Describe;
1313
}
1414

15-
return NODE_VERSION < (allowedVersion.min || -Infinity) || NODE_VERSION > (allowedVersion.max || Infinity)
15+
return major < (allowedVersion.min || -Infinity) || major > (allowedVersion.max || Infinity)
1616
? (describe.skip as jest.Describe)
1717
: (describe as any);
1818
};

0 commit comments

Comments
 (0)