@@ -98,6 +98,7 @@ type s3FS struct {
98
98
}
99
99
100
100
func newS3FS (version string ) * s3FS {
101
+ log .Printf ("[newS3FS] Creating filesystem for version: %s" , version )
101
102
return & s3FS {
102
103
version : version ,
103
104
files : map [string ]string {
@@ -115,7 +116,7 @@ func getFromCache(ctx context.Context, version, path string) *CacheEntry {
115
116
cacheKey := fmt .Sprintf ("%s%s" , version , strings .TrimPrefix (path , "/" ))
116
117
117
118
// Log S3 access for debugging
118
- // log.Printf("S3 lookup: bucket=%s, key=%s", s3Bucket, cacheKey)
119
+ log .Printf ("[getFromCache] S3 lookup: bucket=%s, key=%s, version=%s, path=%s " , s3Bucket , cacheKey , version , path )
119
120
120
121
// Check cache first
121
122
cacheMutex .RLock ()
@@ -150,7 +151,7 @@ func getFromCache(ctx context.Context, version, path string) *CacheEntry {
150
151
defer result .Body .Close ()
151
152
content , err := io .ReadAll (result .Body )
152
153
if err == nil {
153
- // log.Printf("S3 file found: %s (%d bytes)", cacheKey, len(content))
154
+ log .Printf ("[getFromCache] S3 file found: %s (%d bytes)" , cacheKey , len (content ))
154
155
entry := & CacheEntry {
155
156
Exists : true ,
156
157
IsFile : true ,
@@ -162,10 +163,10 @@ func getFromCache(ctx context.Context, version, path string) *CacheEntry {
162
163
cacheMutex .Unlock ()
163
164
return entry
164
165
} else {
165
- // log.Printf("S3 file read error for %s: %v", cacheKey, err)
166
+ log .Printf ("[getFromCache] S3 file read error for %s: %v" , cacheKey , err )
166
167
}
167
168
} else {
168
- // log.Printf("S3 file fetch error for %s: %v", cacheKey, err)
169
+ log .Printf ("[getFromCache] S3 file fetch error for %s: %v" , cacheKey , err )
169
170
}
170
171
171
172
// Not a file, try as directory
@@ -184,7 +185,7 @@ func getFromCache(ctx context.Context, version, path string) *CacheEntry {
184
185
185
186
if err != nil {
186
187
s3ListErrors .Inc ()
187
- // log.Printf("S3 list error for key %s: %v", cacheKey, err)
188
+ log .Printf ("[getFromCache] S3 list error for key %s: %v" , cacheKey , err )
188
189
// Cache as non-existent with shorter TTL
189
190
entry := & CacheEntry {
190
191
Exists : false ,
@@ -197,6 +198,7 @@ func getFromCache(ctx context.Context, version, path string) *CacheEntry {
197
198
}
198
199
199
200
// Build directory entry
201
+ log .Printf ("[getFromCache] S3 list results for %s: %d objects, %d prefixes" , cacheKey , len (listResult .Contents ), len (listResult .CommonPrefixes ))
200
202
entry := & CacheEntry {
201
203
Exists : false ,
202
204
IsFile : false ,
@@ -235,6 +237,7 @@ func getFromCache(ctx context.Context, version, path string) *CacheEntry {
235
237
}
236
238
237
239
// Cache the result
240
+ log .Printf ("[getFromCache] Caching result for %s: exists=%v, isFile=%v, files=%d, dirs=%d" , cacheKey , entry .Exists , entry .IsFile , len (entry .Files ), len (entry .Dirs ))
238
241
cacheMutex .Lock ()
239
242
cache .Add (cacheKey , entry )
240
243
cacheMutex .Unlock ()
@@ -256,15 +259,21 @@ func (fs *s3FS) FileExists(path string) bool {
256
259
return false
257
260
}
258
261
262
+ // Log the file access for debugging
263
+ log .Printf ("[FileExists] Checking path: %s (version: %s)" , path , fs .version )
264
+
259
265
// Check S3 cache
260
266
ctx := context .Background ()
261
267
entry := getFromCache (ctx , fs .version , path )
262
- return entry .Exists && entry .IsFile
268
+ result := entry .Exists && entry .IsFile
269
+ log .Printf ("[FileExists] Path: %s -> exists=%v, isFile=%v" , path , entry .Exists , entry .IsFile )
270
+ return result
263
271
}
264
272
265
273
func (fs * s3FS ) ReadFile (path string ) (string , bool ) {
266
274
// Check in-memory cache first
267
275
if content , ok := fs .files [path ]; ok {
276
+ log .Printf ("[ReadFile] Found in memory: %s (%d bytes)" , path , len (content ))
268
277
return content , true
269
278
}
270
279
@@ -274,13 +283,16 @@ func (fs *s3FS) ReadFile(path string) (string, bool) {
274
283
}
275
284
276
285
// Check S3 cache
286
+ log .Printf ("[ReadFile] Checking S3 for: %s (version: %s)" , path , fs .version )
277
287
ctx := context .Background ()
278
288
entry := getFromCache (ctx , fs .version , path )
279
289
if ! entry .Exists || ! entry .IsFile {
290
+ log .Printf ("[ReadFile] Not found or not a file: %s (exists: %v, isFile: %v)" , path , entry .Exists , entry .IsFile )
280
291
return "" , false
281
292
}
282
293
283
294
contentStr := string (entry .Content )
295
+ log .Printf ("[ReadFile] Found in S3: %s (%d bytes)" , path , len (contentStr ))
284
296
fs .files [path ] = contentStr // Cache locally for this request
285
297
return contentStr , true
286
298
}
@@ -299,11 +311,14 @@ func (fs *s3FS) DirectoryExists(path string) bool {
299
311
if path == "/" || path == "" {
300
312
return true
301
313
}
314
+ log .Printf ("[DirectoryExists] Checking: %s (version: %s)" , path , fs .version )
302
315
303
316
// Check S3 cache
304
317
ctx := context .Background ()
305
318
entry := getFromCache (ctx , fs .version , path )
306
- return entry .Exists && ! entry .IsFile
319
+ result := entry .Exists && ! entry .IsFile
320
+ log .Printf ("[DirectoryExists] Path: %s -> exists=%v, isFile=%v, result=%v" , path , entry .Exists , entry .IsFile , result )
321
+ return result
307
322
}
308
323
309
324
func (fs * s3FS ) GetAccessibleEntries (path string ) vfs.Entries {
@@ -448,7 +463,7 @@ func buildTypeScript(code string, version string) BuildResponse {
448
463
449
464
// Create virtual file resolver for esbuild
450
465
resolver := func (path string ) (api.OnLoadResult , error ) {
451
- log .Printf ("Resolving: %s" , path )
466
+ log .Printf ("[esbuild resolver] Resolving: %s" , path )
452
467
453
468
// Track package resolutions
454
469
trackPackageResolution (path )
@@ -463,7 +478,7 @@ func buildTypeScript(code string, version string) BuildResponse {
463
478
} else if strings .HasSuffix (path , ".json" ) {
464
479
loader = api .LoaderJSON
465
480
}
466
- log .Printf ("Found exact path: %s" , path )
481
+ log .Printf ("[esbuild resolver] Found exact path: %s (loader: %v) " , path , loader )
467
482
return api.OnLoadResult {
468
483
Contents : & content ,
469
484
Loader : loader ,
@@ -484,7 +499,7 @@ func buildTypeScript(code string, version string) BuildResponse {
484
499
} else if ext == ".json" {
485
500
loader = api .LoaderJSON
486
501
}
487
- log .Printf ("Found with extension: %s" , testPath )
502
+ log .Printf ("[esbuild resolver] Found with extension: %s (loader: %v) " , testPath , loader )
488
503
return api.OnLoadResult {
489
504
Contents : & content ,
490
505
Loader : loader ,
@@ -590,15 +605,15 @@ func buildTypeScript(code string, version string) BuildResponse {
590
605
} else if strings .HasSuffix (pattern , ".json" ) {
591
606
loader = api .LoaderJSON
592
607
}
593
- log .Printf ("Found at: %s" , pattern )
608
+ log .Printf ("[esbuild resolver] Found at: %s (loader: %v) " , pattern , loader )
594
609
return api.OnLoadResult {
595
610
Contents : & content ,
596
611
Loader : loader ,
597
612
}, nil
598
613
}
599
614
}
600
615
601
- log .Printf ("Tried patterns: %v" , patterns )
616
+ log .Printf ("[esbuild resolver] Failed to find %s. Tried patterns: %v" , path , patterns )
602
617
}
603
618
604
619
return api.OnLoadResult {}, fmt .Errorf ("file not found: %s" , path )
@@ -622,6 +637,7 @@ func buildTypeScript(code string, version string) BuildResponse {
622
637
Name : "virtual-fs" ,
623
638
Setup : func (pb api.PluginBuild ) {
624
639
pb .OnResolve (api.OnResolveOptions {Filter : ".*" }, func (args api.OnResolveArgs ) (api.OnResolveResult , error ) {
640
+ log .Printf ("[esbuild OnResolve] path=%s, importer=%s, kind=%v" , args .Path , args .Importer , args .Kind )
625
641
// Track package resolutions in esbuild plugin
626
642
trackPackageResolution (args .Path )
627
643
@@ -676,11 +692,13 @@ func buildTypeScript(code string, version string) BuildResponse {
676
692
})
677
693
678
694
pb .OnLoad (api.OnLoadOptions {Filter : ".*" , Namespace : "virtual" }, func (args api.OnLoadArgs ) (api.OnLoadResult , error ) {
695
+ log .Printf ("[esbuild OnLoad] path=%s, namespace=%s" , args .Path , args .Namespace )
679
696
return resolver (args .Path )
680
697
})
681
698
682
699
// Handle react global transform
683
700
pb .OnLoad (api.OnLoadOptions {Filter : ".*" , Namespace : "use-crayon-react-global" }, func (args api.OnLoadArgs ) (api.OnLoadResult , error ) {
701
+ log .Printf ("[esbuild OnLoad] React global transform for: %s" , args .Path )
684
702
contents := "module.exports = _CRAYONCORE_$REACT"
685
703
return api.OnLoadResult {
686
704
Contents : & contents ,
0 commit comments