@@ -129,7 +129,9 @@ export function absolute(path: string) {
129129 return "/" + path ;
130130}
131131
132- const ROOT_URL = `https://cdn.jsdelivr.net/` ;
132+ const UNPKG = true ;
133+
134+ const ROOT_URL = UNPKG ? `https://unpkg.com/` : `https://cdn.jsdelivr.net/npm/` ;
133135const loadedTypings = [ ] ;
134136
135137/**
@@ -168,7 +170,7 @@ const doFetch = url => {
168170} ;
169171
170172const fetchFromDefinitelyTyped = ( dependency , version , fetchedPaths ) => {
171- const depUrl = `${ ROOT_URL } npm/ @types/${ dependency
173+ const depUrl = `${ ROOT_URL } @types/${ dependency
172174 . replace ( "@" , "" )
173175 . replace ( / \/ / g, "__" ) } `;
174176
@@ -266,13 +268,21 @@ const transformFiles = dir =>
266268 } , { } )
267269 : { } ;
268270
269- const getFileMetaData = ( dependency , version , depPath ) =>
270- doFetch (
271+ const getFileMetaData = ( dependency , version , depPath ) => {
272+ if ( UNPKG ) {
273+ return doFetch (
274+ `https://unpkg.com/${ dependency } @${ version } /${ depPath } ?meta`
275+ )
276+ . then ( response => JSON . parse ( response ) )
277+ }
278+
279+ return doFetch (
271280 `https://data.jsdelivr.com/v1/package/npm/${ dependency } @${ version } /flat`
272281 )
273282 . then ( response => JSON . parse ( response ) )
274283 . then ( response => response . files . filter ( f => f . name . startsWith ( depPath ) ) )
275284 . then ( tempTransformFiles ) ;
285+ }
276286
277287const resolveAppropiateFile = ( fileMetaData , relativePath ) => {
278288 const absolutePath = `/${ relativePath } ` ;
@@ -297,7 +307,7 @@ const getFileTypes = (
297307
298308 if ( fetchedPaths [ virtualPath ] ) return null ;
299309
300- return doFetch ( `${ depUrl } / ${ depPath } ` ) . then ( typings => {
310+ return doFetch ( `${ depUrl } ${ depPath } ` ) . then ( typings => {
301311 if ( fetchedPaths [ virtualPath ] ) return null ;
302312
303313 addLib ( virtualPath , typings , fetchedPaths ) ;
@@ -378,7 +388,7 @@ function fetchFromMeta(dependency, version, fetchedPaths) {
378388}
379389
380390function fetchFromTypings ( dependency , version , fetchedPaths ) {
381- const depUrl = `${ ROOT_URL } npm/ ${ dependency } @${ version } ` ;
391+ const depUrl = `${ ROOT_URL } ${ dependency } @${ version } ` ;
382392 return doFetch ( `${ depUrl } /package.json` )
383393 . then ( response => JSON . parse ( response ) )
384394 . then ( packageJSON => {
0 commit comments