@@ -107,7 +107,7 @@ func (s3 *s3Storage) Stat(name string) (stat Stat, err error) {
107107 if name == "" {
108108 return nil , errors .New ("name is required" )
109109 }
110- if s3 .fsCache != nil && ! strings . HasSuffix (name , ".mjs.map" ) {
110+ if s3 .shouldUseFSCache (name ) {
111111 stat , err = s3 .fsCache .Stat (name )
112112 if err == nil {
113113 return
@@ -160,7 +160,7 @@ func (s3 *s3Storage) Get(name string) (content io.ReadCloser, stat Stat, err err
160160 if name == "" {
161161 return nil , nil , errors .New ("name is required" )
162162 }
163- if s3 .fsCache != nil && ! strings . HasSuffix (name , ".mjs.map" ) {
163+ if s3 .shouldUseFSCache (name ) {
164164 content , stat , err = s3 .fsCache .Get (name )
165165 if err == nil {
166166 return
@@ -206,7 +206,7 @@ func (s3 *s3Storage) Get(name string) (content io.ReadCloser, stat Stat, err err
206206 contentLength : size ,
207207 lastModified : lastModified ,
208208 }
209- if s3 .fsCache != nil && ! strings . HasSuffix (name , ".mjs.map" ) {
209+ if s3 .shouldUseFSCache (name ) {
210210 pr , pw := io .Pipe ()
211211 go func () {
212212 unlock := s3 .fsCacheLock .Lock (name )
@@ -267,7 +267,7 @@ func (s3 *s3Storage) Put(name string, content io.Reader) (err error) {
267267 err = errors .New ("missing content length" )
268268 return
269269 }
270- if s3 .fsCache != nil && ! strings . HasSuffix (name , ".mjs.map" ) {
270+ if s3 .shouldUseFSCache (name ) {
271271 pr , pw := io .Pipe ()
272272 go func (content io.Reader ) {
273273 unlock := s3 .fsCacheLock .Lock (name )
@@ -295,7 +295,7 @@ func (s3 *s3Storage) Delete(name string) (err error) {
295295 if name == "" {
296296 return errors .New ("key is required" )
297297 }
298- if s3 .fsCache != nil && ! strings . HasSuffix (name , ".mjs.map" ) {
298+ if s3 .shouldUseFSCache (name ) {
299299 go s3 .fsCache .Delete (name )
300300 }
301301 req , _ := http .NewRequest ("DELETE" , s3 .apiEndpoint + "/" + name , nil )
@@ -417,6 +417,16 @@ func (s3 *s3Storage) sign(req *http.Request) {
417417 req .Header .Set ("Authorization" , strings .Join ([]string {"AWS4-HMAC-SHA256 Credential=" + s3 .accessKeyID + "/" + scope , "SignedHeaders=" + strings .Join (signedHeaders , ";" ), "Signature=" + toHex (signature )}, ", " ))
418418}
419419
420+ func (s3 * s3Storage ) shouldUseFSCache (name string ) bool {
421+ if s3 .fsCache == nil {
422+ return false
423+ }
424+ if strings .HasSuffix (name , ".mjs.map" ) || strings .HasSuffix (name , ".d.ts" ) || strings .HasSuffix (name , ".d.mts" ) || strings .HasSuffix (name , ".d.cts" ) {
425+ return false
426+ }
427+ return true
428+ }
429+
420430func parseS3Error (resp * http.Response ) error {
421431 var s3Error s3Error
422432 if xml .NewDecoder (resp .Body ).Decode (& s3Error ) != nil || s3Error .Code == "" {
0 commit comments