Skip to content

Commit

Permalink
Revert "refactor: update fetch import for node v21+ compatibility (gl…
Browse files Browse the repository at this point in the history
…ideapps#2573)"

This reverts commit 8d4169b.
  • Loading branch information
inferrinizzard committed Apr 28, 2024
1 parent 532dd77 commit df1321d
Showing 1 changed file with 2 additions and 9 deletions.
11 changes: 2 additions & 9 deletions packages/quicktype-core/src/input/io/NodeIO.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
import * as fs from "fs";
import { Readable } from "readable-stream";
import { Readable as NodeReadable } from "stream";
import { isNode } from "browser-or-node";
import { getStream } from "./get-stream";
import { defined, exceptionToString } from "@glideapps/ts-necessities";
import { messageError, panic } from "../../index";

const isURL = require("is-url");

const fetch = (global as any).fetch ?? require("cross-fetch").default;
import fetch from "cross-fetch";

interface HttpHeaders {
[key: string]: string;
Expand Down Expand Up @@ -42,13 +40,8 @@ export async function readableFromFileOrURL(fileOrURL: string, httpHeaders?: str
const response = await fetch(fileOrURL, {
headers: parseHeaders(httpHeaders)
});
const maybeWebReadable = defined(response.body)!;

if (!maybeWebReadable.once) {
// if the `once` function does not exist, this is likely a web [ReadableStream](https://developer.mozilla.org/docs/Web/API/ReadableStream) instead of a node one
return NodeReadable.fromWeb(maybeWebReadable) as Readable;
}
return maybeWebReadable as Readable;
return defined(response.body) as unknown as Readable;
} else if (isNode) {
if (fileOrURL === "-") {
// Cast node readable to isomorphic readable from readable-stream
Expand Down

0 comments on commit df1321d

Please sign in to comment.