-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ref(node): Partially remove dynamic
require
calls (#7377)
Remove a few dynamic `require` calls from our Node SDK in favor of making them top-level imports. * `Http` integration: `http` and `https` are now top-level imports. * Transport: `https-proxy-agent` is now a top-level import as v5 no longer produces side effects when importing. We need this change for the SvelteKit SDK, as SvelteKit doesn't accept `require` calls in server code by default.
- Loading branch information
Showing
6 changed files
with
55 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1 @@ | ||
declare module 'https-proxy-agent'; | ||
declare module 'async-limiter'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,11 +17,7 @@ jest.mock('@sentry/core', () => { | |
}; | ||
}); | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-var-requires | ||
const httpProxyAgent = require('https-proxy-agent'); | ||
jest.mock('https-proxy-agent', () => { | ||
return jest.fn().mockImplementation(() => new http.Agent({ keepAlive: false, maxSockets: 30, timeout: 2000 })); | ||
}); | ||
import * as httpProxyAgent from 'https-proxy-agent'; | ||
|
||
const SUCCESS = 200; | ||
const RATE_LIMIT = 429; | ||
|
@@ -211,15 +207,20 @@ describe('makeNewHttpTransport()', () => { | |
}); | ||
|
||
describe('proxy', () => { | ||
const proxyAgentSpy = jest | ||
.spyOn(httpProxyAgent, 'HttpsProxyAgent') | ||
// @ts-ignore | ||
.mockImplementation(() => new http.Agent({ keepAlive: false, maxSockets: 30, timeout: 2000 })); | ||
|
||
it('can be configured through option', () => { | ||
makeNodeTransport({ | ||
...defaultOptions, | ||
url: 'http://[email protected]:8989/mysubpath/50622', | ||
proxy: 'http://example.com', | ||
}); | ||
|
||
expect(httpProxyAgent).toHaveBeenCalledTimes(1); | ||
expect(httpProxyAgent).toHaveBeenCalledWith('http://example.com'); | ||
expect(proxyAgentSpy).toHaveBeenCalledTimes(1); | ||
expect(proxyAgentSpy).toHaveBeenCalledWith('http://example.com'); | ||
}); | ||
|
||
it('can be configured through env variables option', () => { | ||
|
@@ -229,8 +230,8 @@ describe('makeNewHttpTransport()', () => { | |
url: 'http://[email protected]:8989/mysubpath/50622', | ||
}); | ||
|
||
expect(httpProxyAgent).toHaveBeenCalledTimes(1); | ||
expect(httpProxyAgent).toHaveBeenCalledWith('http://example.com'); | ||
expect(proxyAgentSpy).toHaveBeenCalledTimes(1); | ||
expect(proxyAgentSpy).toHaveBeenCalledWith('http://example.com'); | ||
delete process.env.http_proxy; | ||
}); | ||
|
||
|
@@ -242,8 +243,8 @@ describe('makeNewHttpTransport()', () => { | |
proxy: 'http://bar.com', | ||
}); | ||
|
||
expect(httpProxyAgent).toHaveBeenCalledTimes(1); | ||
expect(httpProxyAgent).toHaveBeenCalledWith('http://bar.com'); | ||
expect(proxyAgentSpy).toHaveBeenCalledTimes(1); | ||
expect(proxyAgentSpy).toHaveBeenCalledWith('http://bar.com'); | ||
delete process.env.http_proxy; | ||
}); | ||
|
||
|
@@ -255,7 +256,7 @@ describe('makeNewHttpTransport()', () => { | |
proxy: 'http://example.com', | ||
}); | ||
|
||
expect(httpProxyAgent).not.toHaveBeenCalled(); | ||
expect(proxyAgentSpy).not.toHaveBeenCalled(); | ||
|
||
delete process.env.no_proxy; | ||
}); | ||
|
@@ -269,7 +270,7 @@ describe('makeNewHttpTransport()', () => { | |
url: 'http://[email protected]:8989/mysubpath/50622', | ||
}); | ||
|
||
expect(httpProxyAgent).not.toHaveBeenCalled(); | ||
expect(proxyAgentSpy).not.toHaveBeenCalled(); | ||
|
||
delete process.env.no_proxy; | ||
delete process.env.http_proxy; | ||
|
@@ -284,7 +285,7 @@ describe('makeNewHttpTransport()', () => { | |
url: 'http://[email protected]:8989/mysubpath/50622', | ||
}); | ||
|
||
expect(httpProxyAgent).not.toHaveBeenCalled(); | ||
expect(proxyAgentSpy).not.toHaveBeenCalled(); | ||
|
||
delete process.env.no_proxy; | ||
delete process.env.http_proxy; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,11 +19,7 @@ jest.mock('@sentry/core', () => { | |
}; | ||
}); | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-var-requires | ||
const httpProxyAgent = require('https-proxy-agent'); | ||
jest.mock('https-proxy-agent', () => { | ||
return jest.fn().mockImplementation(() => new http.Agent({ keepAlive: false, maxSockets: 30, timeout: 2000 })); | ||
}); | ||
import * as httpProxyAgent from 'https-proxy-agent'; | ||
|
||
const SUCCESS = 200; | ||
const RATE_LIMIT = 429; | ||
|
@@ -185,6 +181,11 @@ describe('makeNewHttpsTransport()', () => { | |
}); | ||
|
||
describe('proxy', () => { | ||
const proxyAgentSpy = jest | ||
.spyOn(httpProxyAgent, 'HttpsProxyAgent') | ||
// @ts-ignore | ||
.mockImplementation(() => new http.Agent({ keepAlive: false, maxSockets: 30, timeout: 2000 })); | ||
|
||
it('can be configured through option', () => { | ||
makeNodeTransport({ | ||
...defaultOptions, | ||
|
@@ -193,8 +194,8 @@ describe('makeNewHttpsTransport()', () => { | |
proxy: 'https://example.com', | ||
}); | ||
|
||
expect(httpProxyAgent).toHaveBeenCalledTimes(1); | ||
expect(httpProxyAgent).toHaveBeenCalledWith('https://example.com'); | ||
expect(proxyAgentSpy).toHaveBeenCalledTimes(1); | ||
expect(proxyAgentSpy).toHaveBeenCalledWith('https://example.com'); | ||
}); | ||
|
||
it('can be configured through env variables option (http)', () => { | ||
|
@@ -205,8 +206,8 @@ describe('makeNewHttpsTransport()', () => { | |
url: 'https://[email protected]:8989/mysubpath/50622', | ||
}); | ||
|
||
expect(httpProxyAgent).toHaveBeenCalledTimes(1); | ||
expect(httpProxyAgent).toHaveBeenCalledWith('https://example.com'); | ||
expect(proxyAgentSpy).toHaveBeenCalledTimes(1); | ||
expect(proxyAgentSpy).toHaveBeenCalledWith('https://example.com'); | ||
delete process.env.http_proxy; | ||
}); | ||
|
||
|
@@ -218,8 +219,8 @@ describe('makeNewHttpsTransport()', () => { | |
url: 'https://[email protected]:8989/mysubpath/50622', | ||
}); | ||
|
||
expect(httpProxyAgent).toHaveBeenCalledTimes(1); | ||
expect(httpProxyAgent).toHaveBeenCalledWith('https://example.com'); | ||
expect(proxyAgentSpy).toHaveBeenCalledTimes(1); | ||
expect(proxyAgentSpy).toHaveBeenCalledWith('https://example.com'); | ||
delete process.env.https_proxy; | ||
}); | ||
|
||
|
@@ -232,8 +233,8 @@ describe('makeNewHttpsTransport()', () => { | |
proxy: 'https://bar.com', | ||
}); | ||
|
||
expect(httpProxyAgent).toHaveBeenCalledTimes(1); | ||
expect(httpProxyAgent).toHaveBeenCalledWith('https://bar.com'); | ||
expect(proxyAgentSpy).toHaveBeenCalledTimes(1); | ||
expect(proxyAgentSpy).toHaveBeenCalledWith('https://bar.com'); | ||
delete process.env.https_proxy; | ||
}); | ||
|
||
|
@@ -246,7 +247,7 @@ describe('makeNewHttpsTransport()', () => { | |
proxy: 'https://example.com', | ||
}); | ||
|
||
expect(httpProxyAgent).not.toHaveBeenCalled(); | ||
expect(proxyAgentSpy).not.toHaveBeenCalled(); | ||
|
||
delete process.env.no_proxy; | ||
}); | ||
|
@@ -261,7 +262,7 @@ describe('makeNewHttpsTransport()', () => { | |
url: 'https://[email protected]:8989/mysubpath/50622', | ||
}); | ||
|
||
expect(httpProxyAgent).not.toHaveBeenCalled(); | ||
expect(proxyAgentSpy).not.toHaveBeenCalled(); | ||
|
||
delete process.env.no_proxy; | ||
delete process.env.http_proxy; | ||
|
@@ -277,7 +278,7 @@ describe('makeNewHttpsTransport()', () => { | |
url: 'https://[email protected]:8989/mysubpath/50622', | ||
}); | ||
|
||
expect(httpProxyAgent).not.toHaveBeenCalled(); | ||
expect(proxyAgentSpy).not.toHaveBeenCalled(); | ||
|
||
delete process.env.no_proxy; | ||
delete process.env.http_proxy; | ||
|