Skip to content

refactor(create-react-router): use native Fetch #14140

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions jest/jest.config.shared.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@ module.exports = {
"@react-router/node$": "<rootDir>/../react-router-node/index.ts",
"@react-router/serve$": "<rootDir>/../react-router-serve/index.ts",
"^react-router$": "<rootDir>/../react-router/index.ts",
"^@web3-storage/multipart-parser$": require.resolve(
"@web3-storage/multipart-parser",
),
},
modulePathIgnorePatterns: ignorePatterns,
testMatch: ["<rootDir>/**/*-test.[jt]s?(x)"],
Expand Down
19 changes: 2 additions & 17 deletions packages/create-react-router/copy-template.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,11 @@ import fs from "node:fs";
import path from "node:path";
import stream from "node:stream";
import { promisify } from "node:util";
import { fetch } from "@remix-run/web-fetch";
import gunzip from "gunzip-maybe";
import tar from "tar-fs";
import { ProxyAgent } from "proxy-agent";

import { color, isUrl } from "./utils";

const defaultAgent = new ProxyAgent();
const httpsAgent = new ProxyAgent();
httpsAgent.protocol = "https:";
function agent(url: string) {
return new URL(url).protocol === "https:" ? httpsAgent : defaultAgent;
}

export async function copyTemplate(
template: string,
destPath: string,
Expand Down Expand Up @@ -234,10 +225,7 @@ async function downloadAndExtractTarball(
? `https://api.github.com/repos/${info.owner}/${info.name}/releases/latest`
: `https://api.github.com/repos/${info.owner}/${info.name}/releases/tags/${info.tag}`;

let response = await fetch(releaseUrl, {
agent: agent("https://api.github.com"),
headers,
});
let response = await fetch(releaseUrl, { headers });

if (response.status !== 200) {
throw new CopyTemplateError(
Expand Down Expand Up @@ -274,10 +262,7 @@ async function downloadAndExtractTarball(
resourceUrl = `https://api.github.com/repos/${info.owner}/${info.name}/releases/assets/${assetId}`;
headers.Accept = "application/octet-stream";
}
let response = await fetch(resourceUrl, {
agent: agent(resourceUrl),
headers,
});
let response = await fetch(resourceUrl, { headers });

if (!response.body || response.status !== 200) {
if (token) {
Expand Down
2 changes: 0 additions & 2 deletions packages/create-react-router/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,11 @@
}
},
"dependencies": {
"@remix-run/web-fetch": "^4.4.2",
"arg": "^5.0.1",
"chalk": "^4.1.2",
"execa": "5.1.1",
"gunzip-maybe": "^1.4.2",
"log-update": "^5.0.1",
"proxy-agent": "^6.3.0",
"semver": "^7.3.7",
"sisteransi": "^1.0.5",
"sort-package-json": "^1.55.0",
Expand Down
Loading
Loading