Skip to content

Commit f201baa

Browse files
authored
chore: replace node-fetch for a smaller package (#1144)
* replace node-fetch * changeset * casing * add proxy script for testing
1 parent fa57db3 commit f201baa

File tree

4 files changed

+19
-86
lines changed

4 files changed

+19
-86
lines changed

.changeset/stupid-shirts-cheer.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"shadcn-svelte": patch
3+
---
4+
5+
chore: Replaced `node-fetch` for `node-fetch-native`

packages/cli/package.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,9 @@
3333
"dev": "tsup --watch --sourcemap",
3434
"build": "tsup --minify",
3535
"check": "tsc --noEmit",
36-
"start:dev": "cross-env COMPONENTS_REGISTRY_URL=http://localhost:5173 node dist/index.js",
3736
"start": "node dist/index.js",
37+
"start:dev": "cross-env COMPONENTS_REGISTRY_URL=http://localhost:5173 node dist/index.js",
38+
"start:proxy": "pnpm dlx straightforward@latest --port 9000",
3839
"format": "prettier --write .",
3940
"format:check": "prettier --check .",
4041
"release": "changeset version",
@@ -46,9 +47,8 @@
4647
"commander": "^10.0.1",
4748
"execa": "^7.2.0",
4849
"find-up": "^7.0.0",
49-
"https-proxy-agent": "^7.0.4",
5050
"is-unicode-supported": "^2.0.0",
51-
"node-fetch": "^3.3.2"
51+
"node-fetch-native": "^1.6.4"
5252
},
5353
"devDependencies": {
5454
"@types/node": "^18.19.22",

packages/cli/src/utils/registry/index.ts

+6-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import path from "node:path";
22
import process from "node:process";
33
import * as v from "valibot";
4-
import fetch from "node-fetch";
5-
import { HttpsProxyAgent } from "https-proxy-agent";
4+
import { fetch } from "node-fetch-native";
5+
import { createProxy } from "node-fetch-native/proxy";
66
import { error } from "../errors.js";
77
import { getEnvProxy } from "../get-env-proxy.js";
88
import type { Config } from "../get-config.js";
@@ -125,11 +125,13 @@ export function getItemTargetPath(
125125

126126
async function fetchRegistry(paths: string[]) {
127127
const proxyUrl = getEnvProxy();
128-
const agent = proxyUrl ? new HttpsProxyAgent(proxyUrl) : undefined;
128+
const proxy = proxyUrl ? createProxy({ url: proxyUrl }) : {};
129129
try {
130130
const results = await Promise.all(
131131
paths.map(async (path) => {
132-
const response = await fetch(`${baseUrl}/registry/${path}`, { agent });
132+
const response = await fetch(`${baseUrl}/registry/${path}`, {
133+
...proxy,
134+
});
133135
return await response.json();
134136
})
135137
);

pnpm-lock.yaml

+5-79
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)