File tree Expand file tree Collapse file tree 2 files changed +21
-0
lines changed
Expand file tree Collapse file tree 2 files changed +21
-0
lines changed Original file line number Diff line number Diff line change 1+ import { USER_AGENT } from "../user-agent" ;
12import type PackagephobiaResponse from "./PackagephobiaResponse" ;
23import type PackagephobiaResults from "./PackagephobiaResult" ;
34
@@ -7,6 +8,9 @@ async function getPackage(spec: string): Promise<PackagephobiaResponse | null> {
78 `https://packagephobia.com/v2/api.json?p=${ spec } ` ,
89 {
910 signal : AbortSignal . timeout ( 7_500 ) ,
11+ headers : {
12+ "User-Agent" : USER_AGENT ,
13+ } ,
1014 } ,
1115 ) ;
1216
Original file line number Diff line number Diff line change 1+ const { VERCEL_ENV , VERCEL_DEPLOY_ID , VERCEL_GIT_COMMIT_SHA } = process . env ;
2+
3+ /**
4+ * Be nice to APIs and inform them who we are, with traceability when deployed on Vercel.
5+ */
6+ export const USER_AGENT = ( ( ) => {
7+ const parts = [ `env=${ VERCEL_ENV ?? "development" } ` ] ;
8+
9+ if ( VERCEL_DEPLOY_ID ) {
10+ parts . push ( `deploy=${ VERCEL_DEPLOY_ID } ` ) ;
11+ }
12+ if ( VERCEL_GIT_COMMIT_SHA ) {
13+ parts . push ( `commit=${ VERCEL_GIT_COMMIT_SHA } ` ) ;
14+ }
15+
16+ return `npm-diff.app (${ parts . join ( "; " ) } ; +https://github.com/oBusk/npm-diff.app)` ;
17+ } ) ( ) ;
You can’t perform that action at this time.
0 commit comments