Skip to content

Commit

Permalink
Merge pull request #14 from tjx666/perf/remove-axios-and-got
Browse files Browse the repository at this point in the history
perf: remove axios and got
  • Loading branch information
tjx666 authored Jul 14, 2024
2 parents 8faad7a + dcb99fe commit 0dbc89f
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 26 deletions.
6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,6 @@
"dependencies": {
"@npmcli/config": "^8.3.4",
"@pnpm/config": "^21.6.1",
"axios": "^1.7.2",
"detect-package-manager": "^3.0.2",
"escape-string-regexp": "^5.0.0",
"execa": "^9.3.0",
Expand Down Expand Up @@ -374,5 +373,10 @@
"tsx": "^4.16.2",
"type-fest": "^4.21.0",
"typescript": "~5.5.3"
},
"pnpm": {
"patchedDependencies": {
"[email protected]": "patches/[email protected]"
}
}
}
23 changes: 23 additions & 0 deletions patches/[email protected]
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
diff --git a/build/src/main.js b/build/src/main.js
index 4d2f1549cb2793091846f0b9b3ab9a04be218ffe..15d60c4edfaa0bb8d2b7fa695ac680bc23b4be23 100644
--- a/build/src/main.js
+++ b/build/src/main.js
@@ -2,7 +2,6 @@ import{env}from"node:process";

import{handleOfflineError}from"./cache/offline.js";
import{readCachedVersions,writeCachedVersions}from"./cache/read.js";
-import{fetchIndex}from"./fetch.js";
import{normalizeIndex}from"./normalize.js";
import{getOpts}from"./options.js";

@@ -55,3 +54,10 @@ return versionsInfo
return handleOfflineError(error)
}
};
+
+const fetchIndex=async(fetchNodeOpts)=>{
+ const mirror=fetchNodeOpts?.mirror ?? "https://nodejs.org/dist";
+ const url=`${mirror}/index.json`;
+ const response=await fetch(url);
+ return response.json()
+};
28 changes: 7 additions & 21 deletions pnpm-lock.yaml

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

6 changes: 2 additions & 4 deletions src/apis.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import allNodeVersions from 'all-node-versions';
import axios from 'axios';
import ExpiryMap from 'expiry-map';
import pMemoize from 'p-memoize';
import fetchPackageJson from 'package-json';
Expand Down Expand Up @@ -56,9 +55,8 @@ export const fetchRemotePackageJson = (() => {
export const fetchBundleSize = (() => {
const request = async (pkgNameAndVersion: string) => {
const url = `https://bundlephobia.com/api/size?package=${pkgNameAndVersion}`;
const { data } = await axios.get<{ gzip?: number; size?: number }>(url, {
timeout: 3 * 1000,
});
const response = await fetch(url);
const data = (await response.json()) as { gzip?: number; size?: number };
if (data && typeof data.size === 'number') {
return {
gzip: data.gzip!,
Expand Down

0 comments on commit 0dbc89f

Please sign in to comment.