Skip to content

Commit

Permalink
types
Browse files Browse the repository at this point in the history
  • Loading branch information
paula-stacho committed Mar 6, 2024
1 parent c73f835 commit a53c46d
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
7 changes: 6 additions & 1 deletion packages/cli-repl/src/update-notification-manager.ts
@@ -1,9 +1,14 @@
import semver from 'semver';
import { promises as fs } from 'fs';
import importNodeFetch from '@mongosh/import-node-fetch';
import type {
RequestInfo,
RequestInit,
Response,
} from '@mongosh/import-node-fetch';

// 'http' is not supported in startup snapshots yet.
const fetch = async (url: any, init?: any): Promise<any> =>
const fetch = async (url: RequestInfo, init?: RequestInit): Promise<Response> =>
await (await importNodeFetch()).default(url, init);

interface MongoshUpdateLocalFileContents {
Expand Down
2 changes: 2 additions & 0 deletions packages/import-node-fetch/src/index.ts
@@ -1,5 +1,7 @@
// eslint-disable-next-line @typescript-eslint/consistent-type-imports
export type TNodeFetch = typeof import('node-fetch');
export type { Request, Response, RequestInfo, RequestInit } from 'node-fetch';

export default async function importNodeFetch(): Promise<TNodeFetch> {
// Node-fetch is an ESM module from 3.x
// Importing ESM modules to CommonJS is possible with a dynamic import.
Expand Down
4 changes: 2 additions & 2 deletions packages/snippet-manager/src/snippet-manager.ts
Expand Up @@ -18,7 +18,7 @@ import zlib from 'zlib';
import bson from 'bson';
import joi from 'joi';
import importNodeFetch from '@mongosh/import-node-fetch';
import type { TNodeFetch } from '@mongosh/import-node-fetch';
import type { Response } from '@mongosh/import-node-fetch';
const pipeline = promisify(stream.pipeline);
const brotliCompress = promisify(zlib.brotliCompress);
const brotliDecompress = promisify(zlib.brotliDecompress);
Expand Down Expand Up @@ -193,7 +193,7 @@ export class SnippetManager implements ShellPlugin {
return this._instanceState.messageBus;
}

async fetch(url: string): Promise<InstanceType<TNodeFetch['Response']>> {
async fetch(url: string): Promise<Response> {
// 'http' is not supported in startup snapshots yet.
const fetch = await importNodeFetch();
return await fetch.default(url);
Expand Down

0 comments on commit a53c46d

Please sign in to comment.