Skip to content

Commit cb4bbda

Browse files
committed
use jsDelivr API instead of fetching package.json
1 parent 7a21b58 commit cb4bbda

File tree

1 file changed

+4
-2
lines changed
  • packages/repl/src/lib/workers

1 file changed

+4
-2
lines changed

packages/repl/src/lib/workers/npm.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,12 @@ export async function resolve_version(name: string, version: string): Promise<st
6868
const key = `${name}@${version}`;
6969

7070
if (!versions.has(key)) {
71-
const promise = fetch(`https://cdn.jsdelivr.net/npm/${key}/package.json`).then(async (r) => {
71+
const promise = fetch(
72+
`https://data.jsdelivr.com/v1/packages/npm/${name}/resolved?specifier=${version}`
73+
).then(async (r) => {
7274
if (!r.ok) {
7375
versions.delete(key);
74-
throw new Error(await r.text());
76+
throw new Error(`Failed to import ${key}. Are you sure the package exists?`);
7577
}
7678

7779
return (await r.json()).version;

0 commit comments

Comments
 (0)