Skip to content

Commit cd1e3bc

Browse files
timfishanonrig
authored andcommitted
fix(node): Make NODE_VERSION properties required (#9964)
These types have been annoying me for a while. We can safely assume the node version can be parsed.
1 parent cdf574e commit cd1e3bc

File tree

9 files changed

+10
-10
lines changed

9 files changed

+10
-10
lines changed

packages/node/src/async/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { setHooksAsyncContextStrategy } from './hooks';
99
* Node.js < 14 uses domains
1010
*/
1111
export function setNodeAsyncContextStrategy(): void {
12-
if (NODE_VERSION.major && NODE_VERSION.major >= 14) {
12+
if (NODE_VERSION.major >= 14) {
1313
setHooksAsyncContextStrategy();
1414
} else {
1515
setDomainAsyncContextStrategy();

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ export class Anr implements Integration {
6565

6666
/** @inheritdoc */
6767
public setup(client: NodeClient): void {
68-
if ((NODE_VERSION.major || 0) < 16) {
68+
if (NODE_VERSION.major < 16) {
6969
throw new Error('ANR detection requires Node 16 or later');
7070
}
7171

packages/node/src/integrations/http.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ export class Http implements Integration {
132132
// NOTE: Prior to Node 9, `https` used internals of `http` module, thus we don't patch it.
133133
// If we do, we'd get double breadcrumbs and double spans for `https` calls.
134134
// It has been changed in Node 9, so for all versions equal and above, we patch `https` separately.
135-
if (NODE_VERSION.major && NODE_VERSION.major > 8) {
135+
if (NODE_VERSION.major > 8) {
136136
// eslint-disable-next-line @typescript-eslint/no-var-requires
137137
const httpsModule = require('https');
138138
const wrappedHttpsHandlerMaker = _createWrappedRequestMethodFactory(

packages/node/src/integrations/localvariables.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ export class LocalVariables implements Integration {
353353
if (this._session && clientOptions.includeLocalVariables) {
354354
// Only setup this integration if the Node version is >= v18
355355
// https://github.com/getsentry/sentry-javascript/issues/7697
356-
const unsupportedNodeVersion = (NODE_VERSION.major || 0) < 18;
356+
const unsupportedNodeVersion = NODE_VERSION.major < 18;
357357

358358
if (unsupportedNodeVersion) {
359359
logger.log('The `LocalVariables` integration is only supported on Node >= v18.');

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ export class Undici implements Integration {
9696
*/
9797
public setupOnce(_addGlobalEventProcessor: (callback: EventProcessor) => void): void {
9898
// Requires Node 16+ to use the diagnostics_channel API.
99-
if (NODE_VERSION.major && NODE_VERSION.major < 16) {
99+
if (NODE_VERSION.major < 16) {
100100
return;
101101
}
102102

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ export function normalizeRequestArgs(
183183
// as it will always return `http`, even when using `https` module.
184184
//
185185
// See test/integrations/http.test.ts for more details on Node <=v8 protocol issue.
186-
if (NODE_VERSION.major && NODE_VERSION.major > 8) {
186+
if (NODE_VERSION.major > 8) {
187187
requestOptions.protocol =
188188
(httpModule?.globalAgent as any)?.protocol ||
189189
(requestOptions.agent as any)?.protocol ||

packages/node/src/nodeVersion.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
import { parseSemver } from '@sentry/utils';
22

3-
export const NODE_VERSION: ReturnType<typeof parseSemver> = parseSemver(process.versions.node);
3+
export const NODE_VERSION = parseSemver(process.versions.node) as { major: number; minor: number; patch: number };

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -648,7 +648,7 @@ describe('default protocols', () => {
648648
// intercepting a https:// request with http:// mock. It's a safe bet
649649
// because the latest versions of nock no longer support Node v8 and lower,
650650
// so won't bother dealing with this old Node edge case.
651-
if (NODE_VERSION.major && NODE_VERSION.major < 9) {
651+
if (NODE_VERSION.major < 9) {
652652
nockProtocol = 'http';
653653
}
654654
nock(`${nockProtocol}://${key}.ingest.sentry.io`).get('/api/123122332/store/').reply(200);
@@ -671,7 +671,7 @@ describe('default protocols', () => {
671671
const proxy = 'http://<PROXY_URL>:3128';
672672
const agent = HttpsProxyAgent(proxy);
673673

674-
if (NODE_VERSION.major && NODE_VERSION.major < 9) {
674+
if (NODE_VERSION.major < 9) {
675675
nockProtocol = 'http';
676676
}
677677

packages/node/test/integrations/localvariables.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ const exceptionEvent100Frames = {
150150
},
151151
};
152152

153-
describeIf((NODE_VERSION.major || 0) >= 18)('LocalVariables', () => {
153+
describeIf(NODE_VERSION.major >= 18)('LocalVariables', () => {
154154
it('Adds local variables to stack frames', async () => {
155155
const session = new MockDebugSession({
156156
'-6224981551105448869.1.2': { name: 'tim' },

0 commit comments

Comments
 (0)