@@ -50,10 +50,28 @@ function normalize(
5050 return fileObject ;
5151}
5252
53+ function normalizeJSDelivr (
54+ depName : string ,
55+ files : any ,
56+ fileObject : Meta = { } ,
57+ rootPath
58+ ) {
59+ for ( let i = 0 ; i < files . length ; i += 1 ) {
60+ const absolutePath = pathUtils . join ( rootPath , files [ i ] . name ) ;
61+ fileObject [ absolutePath ] = true ; // eslint-disable-line no-param-reassign
62+ }
63+
64+ return fileObject ;
65+ }
66+
67+ const TEMP_USE_JSDELIVR = true ;
68+
5369function getUnpkgUrl ( name : string , version : string ) {
5470 const nameWithoutAlias = name . replace ( / \/ \d * \. \d * \. \d * $ / , '' ) ;
5571
56- return `https://unpkg.com/${ nameWithoutAlias } @${ version } ` ;
72+ return TEMP_USE_JSDELIVR
73+ ? `https://cdn.jsdelivr.net/npm/${ nameWithoutAlias } @${ version } `
74+ : `https://unpkg.com/${ nameWithoutAlias } @${ version } ` ;
5775}
5876
5977function getMeta ( name : string , version : string ) {
@@ -64,7 +82,11 @@ function getMeta(name: string, version: string) {
6482 }
6583
6684 metas [ id ] = window
67- . fetch ( `https://unpkg.com/${ nameWithoutAlias } @${ version } /?meta` )
85+ . fetch (
86+ TEMP_USE_JSDELIVR
87+ ? `https://data.jsdelivr.com/v1/package/npm/${ nameWithoutAlias } @${ version } /flat`
88+ : `https://unpkg.com/${ nameWithoutAlias } @${ version } /?meta`
89+ )
6890 . then ( x => x . json ( ) ) ;
6991
7092 return metas [ id ] ;
@@ -270,7 +292,8 @@ export default async function fetchModule(
270292
271293 const meta = await getMeta ( dependencyName , version ) ;
272294
273- const normalizedMeta = normalize (
295+ const normalizeFunction = TEMP_USE_JSDELIVR ? normalizeJSDelivr : normalize ;
296+ const normalizedMeta = normalizeFunction (
274297 dependencyName ,
275298 meta . files ,
276299 { } ,
0 commit comments