File tree Expand file tree Collapse file tree 7 files changed +11
-23
lines changed
Expand file tree Collapse file tree 7 files changed +11
-23
lines changed Original file line number Diff line number Diff line change 1+ ---
2+ ' @segment/analytics-node ' : major
3+ ---
4+
5+ Remove node-fetch dependency in favor of native globalThis.fetch (available since Node 18, package requires >= 20)
Original file line number Diff line number Diff line change 4040 "@segment/analytics-generic-utils" : " 1.2.0" ,
4141 "buffer" : " ^6.0.3" ,
4242 "jose" : " ^5.1.0" ,
43- "node-fetch" : " ^2.6.7" ,
4443 "tslib" : " ^2.4.1"
4544 },
4645 "devDependencies" : {
Original file line number Diff line number Diff line change 88 GroupTraits ,
99 HTTPClient ,
1010 FetchHTTPClient ,
11- HTTPFetchFn ,
1211 HTTPClientRequest ,
1312} from '../'
1413
@@ -90,10 +89,8 @@ export default {
9089 console . log ( { } as UserTraits )
9190 } ,
9291
93- 'HTTPFetchFn should be compatible with standard fetch and node-fetch interface, as well as functions' :
92+ 'HTTPFetchFn should be compatible with standard fetch interface, as well as functions' :
9493 ( ) => {
95- const fetch : HTTPFetchFn = require ( 'node-fetch' )
96- new Analytics ( { writeKey : 'foo' , httpClient : fetch } )
9794 new Analytics ( { writeKey : 'foo' , httpClient : globalThis . fetch } )
9895 } ,
9996
Original file line number Diff line number Diff line change @@ -43,7 +43,7 @@ export interface AnalyticsSettings {
4343 /**
4444 * Supply a default http client implementation (such as one supporting proxy).
4545 * Accepts either an HTTPClient instance or a fetch function.
46- * Default: an HTTP client that uses globalThis.fetch, with node-fetch as a fallback .
46+ * Default: an HTTP client that uses globalThis.fetch.
4747 */
4848 httpClient ?: HTTPFetchFn | HTTPClient
4949 /**
Original file line number Diff line number Diff line change 11import type { HTTPFetchFn } from './http-client'
22
3- export const fetch : HTTPFetchFn = async ( ...args ) => {
4- if ( globalThis . fetch ) {
5- return globalThis . fetch ( ...args )
6- }
7- // This guard causes is important, as it causes dead-code elimination to be enabled inside this block.
8- // @ts -ignore
9- else if ( typeof EdgeRuntime !== 'string' ) {
10- return ( await import ( 'node-fetch' ) ) . default ( ...args )
11- } else {
12- throw new Error (
13- 'Invariant: an edge runtime that does not support fetch should not exist'
14- )
15- }
3+ export const fetch : HTTPFetchFn = ( ...args ) => {
4+ return globalThis . fetch ( ...args )
165}
Original file line number Diff line number Diff line change @@ -2,8 +2,7 @@ import { abortSignalAfterTimeout } from './abort'
22import { fetch as defaultFetch } from './fetch'
33
44/**
5- * This interface is meant to be compatible with different fetch implementations (node and browser).
6- * Using the ambient fetch type is not possible because the AbortSignal type is not compatible with node-fetch.
5+ * This interface is meant to be compatible with different fetch implementations.
76 * @link https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API
87 */
98export interface HTTPFetchFn {
@@ -18,7 +17,7 @@ export interface HTTPFetchRequest {
1817 headers : Record < string , string >
1918 body : string
2019 method : HTTPClientRequest [ 'method' ]
21- signal : any // AbortSignal type does not play nicely with node-fetch
20+ signal : any
2221}
2322
2423/**
Original file line number Diff line number Diff line change @@ -4459,7 +4459,6 @@ __metadata:
44594459 axios: ^1.6.2
44604460 buffer: ^6.0.3
44614461 jose: ^5.1.0
4462- node-fetch: ^2.6.7
44634462 tslib: ^2.4.1
44644463 languageName: unknown
44654464 linkType: soft
You can’t perform that action at this time.
0 commit comments