@@ -111,6 +111,10 @@ export async function handleSetConfig(field, value) {
111111 }
112112}
113113
114+ export async function handleUseAction ( version ) {
115+ handleSetConfig ( 'css-doodle' , version ) ;
116+ }
117+
114118export function handleDisplayConfig ( field ) {
115119 console . log ( config [ field ] ) ;
116120}
@@ -166,21 +170,33 @@ function readFromStdin() {
166170
167171async function fetchCssDoodleSource ( version ) {
168172 let result = '' , res , error ;
173+
174+ if ( / ^ c s s \- d o o d l e @ / . test ( version ) ) {
175+ version = version . split ( '@' ) [ 1 ] ;
176+ }
177+
169178 const messageInvalid = `error: invalid package version '${ version } '` ;
179+ const messageFailed = `error: failed to fetch css-doodle@${ version } ` ;
170180
171181 if ( ! ( version === 'latest' || / ^ \d + \. \d + \. \d + $ / . test ( version ) ) ) {
172182 return {
173183 result, error : new Error ( messageInvalid )
174184 }
175185 }
176186
177- console . log ( `Fetching css-doodle@${ version } ` ) ;
187+ console . log ( `Fetching css-doodle@${ version } from esm.sh ` ) ;
178188
179189 try {
180- res = await fetch ( `https://esm.sh/css-doodle@${ version } /css-doodle.min.js?raw` , { redirect :'follow' } ) ;
190+ res = await fetch ( `https://esm.sh/css-doodle@${ version } /css-doodle.min.js?raw` , { redirect : 'follow' } ) ;
181191 } catch ( error ) {
192+ try {
193+ console . log ( `Try jsdelivr.net` ) ;
194+ res = await fetch ( `https://cdn.jsdelivr.net/npm/css-doodle@${ version } /css-doodle.min.js` , { redirect : 'follow' } ) ;
195+ } catch ( error ) {
196+ return { result, error : new Error ( messageFailed ) }
197+ }
182198 return {
183- result, error : new Error ( `error: failed to fetch css-doodle@ ${ version } ` )
199+ result, error : new Error ( messageFailed )
184200 } ;
185201 }
186202
0 commit comments