Skip to content

Conversation

Sahelisaha04
Copy link
Contributor

@Sahelisaha04 Sahelisaha04 commented Sep 24, 2025

Fixes #1696
/claim #1696

Screencast.From.2025-09-24.14-24-00.1.mp4

adding video

Resolves tscircuit#1696 by preventing unnecessary re-downloading of TypeScript dependencies.

- Add fetchWithPackageCaching function with 7-day TTL cache
- Remove complex closure patterns in ATA fetcher configuration
- Simplify @tsci package handling to single URL pattern
- Use compression for efficient storage
- Remove unnecessary hash functions and error handling complexity

The implementation now uses a clean function reference instead of confusing closures:
fetcher: fetchWithPackageCaching as typeof fetch
The apiUrl variable is still needed for the AI autocomplete feature.
Only the ATA fetcher was simplified to use fetchWithPackageCaching.
Auto-formatted code according to project style guidelines.
- Add proper type validation for cached data before destructuring
- Support all @tsci URL patterns: jsdelivr.net, data.jsdelivr.com resolve/npm
- Include jsdelivr_resolve parameter for resolve URLs
- Prevent runtime errors from corrupted cache data
Auto-format code for consistency with project style guidelines.
- Add missing package name transformation logic that was in original code
- Convert dots to slashes in package names for proper URL routing
- Fixes package resolution for @tsci packages with dots in names
- Maintains backward compatibility with existing package patterns
@Sahelisaha04
Copy link
Contributor Author

@seveibar can i get a review on this

…ication

- Restore CACHE_PREFIX variable and use it consistently
- Add TTL check for TypeScript lib files (7-day expiration)
- Replace complex regex with simple string operations using indexOf/substring
- Apply consistent cache data structure with timestamp for all cached items
- Maintain backward compatibility while improving code clarity

Addresses feedback from @imrishabh18:
- No more complex regex patterns
- Proper TTL handling for TypeScript library files
- Consistent use of CACHE_PREFIX constant
The original code used /\./ to replace only the FIRST dot, not all dots.
Using /\./g could break package resolution for packages with multiple dots.

Changes /\./g back to /\./ to maintain backward compatibility with
existing package naming conventions.
Extract status, statusText, and headers properties instead of passing
the entire Response object. The Response constructor expects a
ResponseInit object as the second parameter, not a Response instance.

This prevents potential runtime errors and ensures proper response
object creation with correct metadata.
@Sahelisaha04
Copy link
Contributor Author

@imrishabh18 can i get a another round of review for this ?

@Sahelisaha04
Copy link
Contributor Author

@seveibar can i get a review on this

Copy link

This PR has been automatically marked as stale because it has had no recent activity. It will be closed if no further activity occurs.

@github-actions github-actions bot added the stale label Sep 28, 2025
Copy link
Contributor

@baeoc baeoc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please update your PR. otherwise it's closed automatically

@github-actions github-actions bot removed the stale label Sep 29, 2025
@seveibar
Copy link
Contributor

This is pretty good

Copy link
Contributor

@seveibar seveibar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe @imrishabh18 can review & merge if it looks good.

@Sahelisaha04 if you want faster reviews, you can join the discord: https://tscircuit.com/join and shout in the #reviewme channel. Sorry it took so long for me to review

@Sahelisaha04
Copy link
Contributor Author

okay on it

@Sahelisaha04
Copy link
Contributor Author

cc @imrishabh18 can you pls review it

@imrishabh18 imrishabh18 merged commit d9a41e7 into tscircuit:main Sep 30, 2025
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Prevent re-download of typescript dependencies on package save (and cache in localStorage)
4 participants