Skip to content

Commit c8937e7

Browse files
authored
V11 release removal of node-fetch and undici dependencies (#8492)
Our v11 release will require node 18+. Since fetch has been introduced in these node versions, we can remove our dependency on third party fetch implementations. This change removes our usage of fetch variants undici and node-fetch for our node target builds and our CI tools.
1 parent a377fb2 commit c8937e7

File tree

36 files changed

+102
-189
lines changed

36 files changed

+102
-189
lines changed

.changeset/plenty-beers-decide.md

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
---
2+
'@firebase/rules-unit-testing': patch
3+
'@firebase/firestore-compat': patch
4+
'@firebase/functions-compat': patch
5+
'@firebase/storage-compat': patch
6+
'@firebase/auth-compat': patch
7+
'@firebase/firestore': patch
8+
'@firebase/functions': patch
9+
'@firebase/storage': patch
10+
'@firebase/auth': patch
11+
---
12+
13+
Removed dependency on undici and node-fetch in our node bundles, replacing them with the native fetch implementation.

integration/messaging/package.json

-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
"express": "4.19.2",
1616
"geckodriver": "2.0.4",
1717
"mocha": "9.2.2",
18-
"undici": "6.19.7",
1918
"selenium-assistant": "6.1.1"
2019
},
2120
"engines": {

integration/messaging/test/utils/sendMessage.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
* limitations under the License.
1616
*/
1717

18-
const undici = require('undici');
1918
const FCM_SEND_ENDPOINT = 'https://fcm.googleapis.com/fcm/send';
2019
// Rotatable fcm server key. It's generally a bad idea to expose server keys. The reason is to
2120
// simplify testing process (no need to implement server side decryption of git secret). The
@@ -28,7 +27,7 @@ module.exports = async payload => {
2827
'Requesting to send an FCM message with payload: ' + JSON.stringify(payload)
2928
);
3029

31-
const response = await undici.fetch(FCM_SEND_ENDPOINT, {
30+
const response = await fetch(FCM_SEND_ENDPOINT, {
3231
method: 'POST',
3332
body: JSON.stringify(payload),
3433
headers: {

package.json

-1
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,6 @@
156156
"tslint": "6.1.3",
157157
"typedoc": "0.16.11",
158158
"typescript": "4.7.4",
159-
"undici": "6.19.7",
160159
"watch": "1.0.2",
161160
"webpack": "5.76.0",
162161
"yargs": "17.7.2"

packages/auth-compat/index.node.ts

+1-10
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,6 @@
2323
*/
2424
export * from './index';
2525
import { FetchProvider } from '@firebase/auth/internal';
26-
import {
27-
fetch as undiciFetch,
28-
Headers as undiciHeaders,
29-
Response as undiciResponse
30-
} from 'undici';
3126
import './index';
3227

33-
FetchProvider.initialize(
34-
undiciFetch as unknown as typeof fetch,
35-
undiciHeaders as unknown as typeof Headers,
36-
undiciResponse as unknown as typeof Response
37-
);
28+
FetchProvider.initialize(fetch, Headers, Response);

packages/auth-compat/karma.conf.js

-12
Original file line numberDiff line numberDiff line change
@@ -30,18 +30,6 @@ module.exports = function (config) {
3030
// frameworks to use
3131
// available frameworks: https://npmjs.org/browse/keyword/karma-adapter
3232
frameworks: ['mocha'],
33-
// undici is a fetch polyfill that test helpers call for Node tests, and browser tests should
34-
// ignore its import to avoid compilation errors in those test helpers.
35-
webpack: {
36-
...webpackBase,
37-
resolve: {
38-
...webpackBase.resolve,
39-
alias: {
40-
'undici': false
41-
}
42-
}
43-
},
44-
4533
client: Object.assign({}, karmaBase.client, getClientConfig())
4634
});
4735

packages/auth-compat/package.json

-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@
5555
"@firebase/auth-types": "0.12.2",
5656
"@firebase/component": "0.6.8",
5757
"@firebase/util": "1.9.7",
58-
"undici": "6.19.7",
5958
"tslib": "^2.1.0"
6059
},
6160
"license": "Apache-2.0",

packages/auth/karma.conf.js

-11
Original file line numberDiff line numberDiff line change
@@ -27,17 +27,6 @@ module.exports = function (config) {
2727
// frameworks to use
2828
// available frameworks: https://npmjs.org/browse/keyword/karma-adapter
2929
frameworks: ['mocha'],
30-
// undici is a fetch polyfill that test helpers call for Node tests, and browser tests should
31-
// ignore its import to avoid compilation errors in those test helpers.
32-
webpack: {
33-
...webpackBase,
34-
resolve: {
35-
...webpackBase.resolve,
36-
alias: {
37-
'undici': false
38-
}
39-
}
40-
},
4130
client: Object.assign({}, karmaBase.client, getClientConfig(argv))
4231
});
4332

packages/auth/package.json

-1
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,6 @@
130130
"@firebase/component": "0.6.8",
131131
"@firebase/logger": "0.4.2",
132132
"@firebase/util": "1.9.7",
133-
"undici": "6.19.7",
134133
"tslib": "^2.1.0"
135134
},
136135
"license": "Apache-2.0",

packages/auth/src/platform_node/index.ts

+1-10
Original file line numberDiff line numberDiff line change
@@ -28,18 +28,9 @@ import { AuthImpl } from '../core/auth/auth_impl';
2828

2929
import { FetchProvider } from '../core/util/fetch_provider';
3030
import { getDefaultEmulatorHost } from '@firebase/util';
31-
import {
32-
fetch as undiciFetch,
33-
Headers as undiciHeaders,
34-
Response as undiciResponse
35-
} from 'undici';
3631

3732
// Initialize the fetch polyfill, the types are slightly off so just cast and hope for the best
38-
FetchProvider.initialize(
39-
undiciFetch as unknown as typeof fetch,
40-
undiciHeaders as unknown as typeof Headers,
41-
undiciResponse as unknown as typeof Response
42-
);
33+
FetchProvider.initialize(fetch, Headers, Response);
4334

4435
// First, we set up the various platform-specific features for Node (register
4536
// the version and declare the Node getAuth function)

packages/auth/test/helpers/integration/emulator_rest_helpers.ts

+3-5
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
* limitations under the License.
1616
*/
1717

18-
import { fetch as undiciFetch, RequestInit as undiciRequestInit } from 'undici';
1918
import { getAppConfig, getEmulatorUrl } from './settings';
2019

2120
export interface VerificationSession {
@@ -88,9 +87,8 @@ function doFetch(url: string, request?: RequestInit): ReturnType<typeof fetch> {
8887
if (typeof document !== 'undefined') {
8988
return fetch(url, request);
9089
} else {
91-
return undiciFetch(
92-
url,
93-
request as undiciRequestInit
94-
) as unknown as ReturnType<typeof fetch>;
90+
return fetch(url, request as RequestInit) as unknown as ReturnType<
91+
typeof fetch
92+
>;
9593
}
9694
}

packages/firestore/package.json

-1
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,6 @@
103103
"@firebase/webchannel-wrapper": "1.0.1",
104104
"@grpc/grpc-js": "~1.9.0",
105105
"@grpc/proto-loader": "^0.7.8",
106-
"undici": "6.19.7",
107106
"tslib": "^2.1.0"
108107
},
109108
"peerDependencies": {

packages/firestore/src/platform/browser_lite/connection.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,5 @@ export { newConnectivityMonitor } from '../browser/connection';
2424

2525
/** Initializes the HTTP connection for the REST API. */
2626
export function newConnection(databaseInfo: DatabaseInfo): Connection {
27-
return new FetchConnection(databaseInfo, fetch.bind(null));
27+
return new FetchConnection(databaseInfo);
2828
}

packages/firestore/src/platform/browser_lite/fetch_connection.ts

+1-13
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
*/
1717

1818
import { Token } from '../../api/credentials';
19-
import { DatabaseInfo } from '../../core/database_info';
2019
import { Stream } from '../../remote/connection';
2120
import { RestConnection } from '../../remote/rest_connection';
2221
import { mapCodeFromHttpStatus } from '../../remote/rpc_error';
@@ -28,17 +27,6 @@ import { StringMap } from '../../util/types';
2827
* (e.g. `fetch` or a polyfill).
2928
*/
3029
export class FetchConnection extends RestConnection {
31-
/**
32-
* @param databaseInfo - The connection info.
33-
* @param fetchImpl - `fetch` or a Polyfill that implements the fetch API.
34-
*/
35-
constructor(
36-
databaseInfo: DatabaseInfo,
37-
private readonly fetchImpl: typeof fetch
38-
) {
39-
super(databaseInfo);
40-
}
41-
4230
openStream<Req, Resp>(
4331
rpcName: string,
4432
token: Token | null
@@ -56,7 +44,7 @@ export class FetchConnection extends RestConnection {
5644
let response: Response;
5745

5846
try {
59-
response = await this.fetchImpl(url, {
47+
response = await fetch(url, {
6048
method: 'POST',
6149
headers,
6250
body: requestJson

packages/firestore/src/platform/node_lite/connection.ts

+1-6
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@
1515
* limitations under the License.
1616
*/
1717

18-
import { fetch as undiciFetch } from 'undici';
19-
2018
import { DatabaseInfo } from '../../core/database_info';
2119
import { Connection } from '../../remote/connection';
2220
import { FetchConnection } from '../browser_lite/fetch_connection';
@@ -25,8 +23,5 @@ export { newConnectivityMonitor } from '../browser/connection';
2523

2624
/** Initializes the HTTP connection for the REST API. */
2725
export function newConnection(databaseInfo: DatabaseInfo): Connection {
28-
// undici is meant to be API compatible with `fetch`, but its type doesn't
29-
// match 100%.
30-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
31-
return new FetchConnection(databaseInfo, undiciFetch as any);
26+
return new FetchConnection(databaseInfo);
3227
}

packages/functions/karma.conf.js

+1-12
Original file line numberDiff line numberDiff line change
@@ -26,18 +26,7 @@ module.exports = function (config) {
2626
files,
2727
// frameworks to use
2828
// available frameworks: https://npmjs.org/browse/keyword/karma-adapter
29-
frameworks: ['mocha'],
30-
// undici is a fetch polyfill that test helpers call for Node tests, and browser tests should
31-
// ignore its import to avoid compilation errors in those test helpers.
32-
webpack: {
33-
...webpackBase,
34-
resolve: {
35-
...webpackBase.resolve,
36-
alias: {
37-
'undici': false
38-
}
39-
}
40-
}
29+
frameworks: ['mocha']
4130
});
4231

4332
config.set(karmaConfig);

packages/functions/package.json

-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,6 @@
7272
"@firebase/auth-interop-types": "0.2.3",
7373
"@firebase/app-check-interop-types": "0.3.2",
7474
"@firebase/util": "1.9.7",
75-
"undici": "6.19.7",
7675
"tslib": "^2.1.0"
7776
},
7877
"nyc": {

packages/functions/src/config.ts

+2-6
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,7 @@ const APP_CHECK_INTERNAL_NAME: AppCheckInternalComponentName =
3535
const MESSAGING_INTERNAL_NAME: MessagingInternalComponentName =
3636
'messaging-internal';
3737

38-
export function registerFunctions(
39-
fetchImpl: typeof fetch,
40-
variant?: string
41-
): void {
38+
export function registerFunctions(variant?: string): void {
4239
const factory: InstanceFactory<'functions'> = (
4340
container: ComponentContainer,
4441
{ instanceIdentifier: regionOrCustomDomain }
@@ -55,8 +52,7 @@ export function registerFunctions(
5552
authProvider,
5653
messagingProvider,
5754
appCheckProvider,
58-
regionOrCustomDomain,
59-
fetchImpl
55+
regionOrCustomDomain
6056
);
6157
};
6258

packages/functions/src/index.node.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,8 @@
1515
* limitations under the License.
1616
*/
1717
import { registerFunctions } from './config';
18-
import { fetch as undiciFetch } from 'undici';
1918

2019
export * from './api';
20+
export * from './public-types';
2121

22-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
23-
registerFunctions(undiciFetch as any, 'node');
22+
registerFunctions('node');

packages/functions/src/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,4 @@ import { registerFunctions } from './config';
2525
export * from './api';
2626
export * from './public-types';
2727

28-
registerFunctions(fetch.bind(self));
28+
registerFunctions();

packages/functions/src/service.ts

+4-6
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,7 @@ export class FunctionsService implements _FirebaseService {
104104
authProvider: Provider<FirebaseAuthInternalName>,
105105
messagingProvider: Provider<MessagingInternalComponentName>,
106106
appCheckProvider: Provider<AppCheckInternalComponentName>,
107-
regionOrCustomDomain: string = DEFAULT_REGION,
108-
readonly fetchImpl: typeof fetch
107+
regionOrCustomDomain: string = DEFAULT_REGION
109108
) {
110109
this.contextProvider = new ContextProvider(
111110
authProvider,
@@ -212,14 +211,13 @@ export function httpsCallableFromURL<RequestData, ResponseData>(
212211
async function postJSON(
213212
url: string,
214213
body: unknown,
215-
headers: { [key: string]: string },
216-
fetchImpl: typeof fetch
214+
headers: { [key: string]: string }
217215
): Promise<HttpResponse> {
218216
headers['Content-Type'] = 'application/json';
219217

220218
let response: Response;
221219
try {
222-
response = await fetchImpl(url, {
220+
response = await fetch(url, {
223221
method: 'POST',
224222
body: JSON.stringify(body),
225223
headers
@@ -296,7 +294,7 @@ async function callAtURL(
296294

297295
const failAfterHandle = failAfter(timeout);
298296
const response = await Promise.race([
299-
postJSON(url, body, headers, functionsInstance.fetchImpl),
297+
postJSON(url, body, headers),
300298
failAfterHandle.promise,
301299
functionsInstance.cancelAllRequests
302300
]);

packages/functions/test/utils.ts

+1-5
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import { FirebaseAuthInternalName } from '@firebase/auth-interop-types';
2121
import { AppCheckInternalComponentName } from '@firebase/app-check-interop-types';
2222
import { FunctionsService } from '../src/service';
2323
import { connectFunctionsEmulator } from '../src/api';
24-
import { fetch as undiciFetch } from 'undici';
2524
import { MessagingInternalComponentName } from '../../../packages/messaging-interop-types';
2625

2726
export function makeFakeApp(options: FirebaseOptions = {}): FirebaseApp {
@@ -58,15 +57,12 @@ export function createTestService(
5857
new ComponentContainer('test')
5958
)
6059
): FunctionsService {
61-
const fetchImpl: typeof fetch =
62-
typeof window !== 'undefined' ? fetch.bind(window) : (undiciFetch as any);
6360
const functions = new FunctionsService(
6461
app,
6562
authProvider,
6663
messagingProvider,
6764
appCheckProvider,
68-
region,
69-
fetchImpl
65+
region
7066
);
7167
const useEmulator = !!process.env.FIREBASE_FUNCTIONS_EMULATOR_ORIGIN;
7268
if (useEmulator) {

packages/rules-unit-testing/package.json

-4
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,5 @@
5353
"typings": "dist/index.d.ts",
5454
"bugs": {
5555
"url": "https://github.com/firebase/firebase-js-sdk/issues"
56-
},
57-
"dependencies": {
58-
"node-fetch": "2.6.7",
59-
"@types/node-fetch": "2.6.4"
6056
}
6157
}

packages/rules-unit-testing/src/impl/discovery.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
*/
1717

1818
import { EmulatorConfig, HostAndPort } from '../public_types';
19-
import nodeFetch from 'node-fetch';
2019
import { makeUrl, fixHostname } from './url';
2120

2221
/**
@@ -27,9 +26,9 @@ import { makeUrl, fixHostname } from './url';
2726
*/
2827
export async function discoverEmulators(
2928
hub: HostAndPort,
30-
fetch: typeof nodeFetch = nodeFetch
29+
fetchImpl: typeof fetch = fetch
3130
): Promise<DiscoveredEmulators> {
32-
const res = await fetch(makeUrl(hub, '/emulators'));
31+
const res = await fetchImpl(makeUrl(hub, '/emulators'));
3332
if (!res.ok) {
3433
throw new Error(
3534
`HTTP Error ${res.status} when attempting to reach Emulator Hub at ${res.url}, are you sure it is running?`

packages/rules-unit-testing/src/impl/rules.ts

-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717

1818
import { HostAndPort } from '../public_types';
1919
import { makeUrl } from './url';
20-
import fetch from 'node-fetch';
2120

2221
/**
2322
* @private

0 commit comments

Comments
 (0)