Skip to content

Commit c8c64e7

Browse files
committed
Remove fetch from functions
1 parent 69d789c commit c8c64e7

File tree

6 files changed

+8
-27
lines changed

6 files changed

+8
-27
lines changed

packages/functions/karma.conf.js

Lines changed: 1 addition & 12 deletions
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

Lines changed: 0 additions & 1 deletion
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/index.node.ts

Lines changed: 1 addition & 2 deletions
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';
2120

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

packages/functions/src/index.ts

Lines changed: 1 addition & 1 deletion
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

Lines changed: 4 additions & 6 deletions
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

Lines changed: 1 addition & 5 deletions
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) {

0 commit comments

Comments
 (0)