Skip to content

Commit

Permalink
using native fetch
Browse files Browse the repository at this point in the history
  • Loading branch information
timbrinded committed Nov 23, 2023
1 parent 8400a95 commit eb5c0ff
Show file tree
Hide file tree
Showing 8 changed files with 7 additions and 21 deletions.
1 change: 0 additions & 1 deletion packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@
"inquirer-press-to-continue": "^1.2.0",
"jsonc-parser": "^3.2.0",
"minimatch": "^9.0.3",
"node-fetch": "^3.3.2",
"semver": "^7.5.4",
"viem": "^1.19.6",
"vitest": "1.0.0-beta.5",
Expand Down
3 changes: 1 addition & 2 deletions packages/cli/src/cmds/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { Effect } from "effect";
import fs from "fs";
import inquirer from "inquirer";
import PressToContinuePrompt from "inquirer-press-to-continue";
import fetch from "node-fetch";
import path from "path";
import { SemVer, lt } from "semver";
import pkg from "../../package.json" assert { type: "json" };
Expand Down Expand Up @@ -386,7 +385,7 @@ const printIntro = async () => {
let remoteVersion = "";
try {
const url = "https://api.github.com/repos/moonsong-labs/moonwall/releases";
const resp = await fetch(url);
const resp = (await fetch(url)) as any;
const json = (await resp.json()) as GithubResponse[];
remoteVersion = json.find((a) => a.tag_name.includes("@moonwall/cli@"))!.tag_name.split("@")[2];
} catch (error) {
Expand Down
3 changes: 1 addition & 2 deletions packages/cli/src/internal/cmdFunctions/downloader.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { SingleBar, Presets } from "cli-progress";
import fetch from "node-fetch";
import fs from "node:fs";

let progressBar: SingleBar;
Expand Down Expand Up @@ -30,7 +29,7 @@ export async function downloader(url: string, outputPath: string): Promise<void>
const writeStream = fs.createWriteStream(tempPath);
let transferredBytes = 0;

const response = await fetch(url);
const response = (await fetch(url)) as any;

if (!response.body) {
throw new Error("No response body");
Expand Down
3 changes: 1 addition & 2 deletions packages/cli/src/internal/cmdFunctions/fetchArtifact.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import fs from "node:fs/promises";
import path from "path";
import fetch from "node-fetch";
import semver from "semver";
import chalk from "chalk";
import { runTask } from "../processHelpers";
Expand Down Expand Up @@ -86,7 +85,7 @@ export async function getVersions(name: string, runtime: boolean = false) {
throw new Error(`Network not found for ${name}`);
}
const url = `https://api.github.com/repos/${repo.ghAuthor}/${repo.ghRepo}/releases`;
const releases = (await (await fetch(url)).json()) as Release[];
const releases = (await ((await fetch(url)) as any).json()) as Release[];
const versions = releases
.map((release) => {
let tag = release.tag_name;
Expand Down
5 changes: 2 additions & 3 deletions packages/cli/src/lib/rpcFunctions.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { importAsyncConfig } from "./configReader";
import fetch from "node-fetch";

export async function customDevRpcRequest(method: string, params: any[] = []): Promise<any> {
const globalConfig = await importAsyncConfig();
Expand All @@ -14,11 +13,11 @@ export async function customDevRpcRequest(method: string, params: any[] = []): P
params,
};

const response = await fetch(endpoint, {
const response = (await fetch(endpoint, {
method: "POST",
body: JSON.stringify(data),
headers: { "Content-Type": "application/json" },
});
})) as any;

const responseData = (await response.json()) as JsonRpcResponse;

Expand Down
1 change: 0 additions & 1 deletion packages/util/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@
"ethers": "6.8.1",
"inquirer": "^9.2.12",
"inquirer-press-to-continue": "^1.2.0",
"node-fetch": "^3.3.2",
"rlp": "^3.0.0",
"semver": "^7.5.4",
"viem": "^1.19.6",
Expand Down
6 changes: 2 additions & 4 deletions packages/util/src/functions/common.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import "@moonbeam-network/api-augment";
import { BN } from "@polkadot/util";
import fetch from "node-fetch";

// Sort dict by key
export function sortObjectByKeys(o) {
return Object.keys(o)
Expand Down Expand Up @@ -111,11 +109,11 @@ export async function directRpcRequest(
params,
};

const response = await fetch(endpoint, {
const response = (await fetch(endpoint, {
method: "POST",
body: JSON.stringify(data),
headers: { "Content-Type": "application/json" },
});
})) as any;

const responseData = (await response.json()) as JsonRpcResponse;

Expand Down
6 changes: 0 additions & 6 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit eb5c0ff

Please sign in to comment.