Skip to content

Commit

Permalink
fix: Resolve ReadableStream types issue in test suite (#2581)
Browse files Browse the repository at this point in the history
* cast response.body to node readable stream for url fetch

* add comment

* Revert "refactor: update fetch import for node v21+ compatibility (#2573)"

This reverts commit 8d4169b.

* Revert "Revert "refactor: update fetch import for node v21+ compatibility (#2573)""

This reverts commit df1321d.

* add FIXME comment

* only use cross-fetch in CI
  • Loading branch information
inferrinizzard authored Apr 28, 2024
1 parent e1bb838 commit 49e9e03
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions packages/quicktype-core/src/input/io/NodeIO.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import * as fs from "fs";
import { defined, exceptionToString } from "@glideapps/ts-necessities";
import { Readable } from "readable-stream";
import { isNode } from "browser-or-node";
import _fetch from "cross-fetch";
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;
// Only use cross-fetch in CI
const fetch = process.env.CI ? _fetch : (global as any).fetch ?? _fetch;

interface HttpHeaders {
[key: string]: string;
Expand Down Expand Up @@ -41,6 +43,7 @@ export async function readableFromFileOrURL(fileOrURL: string, httpHeaders?: str
const response = await fetch(fileOrURL, {
headers: parseHeaders(httpHeaders)
});

return defined(response.body) as unknown as Readable;
} else if (isNode) {
if (fileOrURL === "-") {
Expand Down

0 comments on commit 49e9e03

Please sign in to comment.