Skip to content

Commit

Permalink
chore: replace node-fetch for a smaller package (#1144)
Browse files Browse the repository at this point in the history
* replace node-fetch

* changeset

* casing

* add proxy script for testing
  • Loading branch information
AdrianGonz97 authored Jun 16, 2024
1 parent fa57db3 commit f201baa
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 86 deletions.
5 changes: 5 additions & 0 deletions .changeset/stupid-shirts-cheer.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"shadcn-svelte": patch
---

chore: Replaced `node-fetch` for `node-fetch-native`
6 changes: 3 additions & 3 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,9 @@
"dev": "tsup --watch --sourcemap",
"build": "tsup --minify",
"check": "tsc --noEmit",
"start:dev": "cross-env COMPONENTS_REGISTRY_URL=http://localhost:5173 node dist/index.js",
"start": "node dist/index.js",
"start:dev": "cross-env COMPONENTS_REGISTRY_URL=http://localhost:5173 node dist/index.js",
"start:proxy": "pnpm dlx straightforward@latest --port 9000",
"format": "prettier --write .",
"format:check": "prettier --check .",
"release": "changeset version",
Expand All @@ -46,9 +47,8 @@
"commander": "^10.0.1",
"execa": "^7.2.0",
"find-up": "^7.0.0",
"https-proxy-agent": "^7.0.4",
"is-unicode-supported": "^2.0.0",
"node-fetch": "^3.3.2"
"node-fetch-native": "^1.6.4"
},
"devDependencies": {
"@types/node": "^18.19.22",
Expand Down
10 changes: 6 additions & 4 deletions packages/cli/src/utils/registry/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import path from "node:path";
import process from "node:process";
import * as v from "valibot";
import fetch from "node-fetch";
import { HttpsProxyAgent } from "https-proxy-agent";
import { fetch } from "node-fetch-native";
import { createProxy } from "node-fetch-native/proxy";
import { error } from "../errors.js";
import { getEnvProxy } from "../get-env-proxy.js";
import type { Config } from "../get-config.js";
Expand Down Expand Up @@ -125,11 +125,13 @@ export function getItemTargetPath(

async function fetchRegistry(paths: string[]) {
const proxyUrl = getEnvProxy();
const agent = proxyUrl ? new HttpsProxyAgent(proxyUrl) : undefined;
const proxy = proxyUrl ? createProxy({ url: proxyUrl }) : {};
try {
const results = await Promise.all(
paths.map(async (path) => {
const response = await fetch(`${baseUrl}/registry/${path}`, { agent });
const response = await fetch(`${baseUrl}/registry/${path}`, {
...proxy,
});
return await response.json();
})
);
Expand Down
84 changes: 5 additions & 79 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 f201baa

Please sign in to comment.