TurboWarp / extensions

User-contributed unsandboxed extension gallery for TurboWarp
https://extensions.turbowarp.org/
MIT License
114 stars 234 forks source link

Proposal: dependency system based on `await import` #1587

Open FurryR opened 3 months ago

FurryR commented 3 months ago

Extensions are now able to require external libraries via await import. When the gallery starts, it downloads all dependencies (via acorn parser) and replace their URLs with downloaded data URLs.

Example code:

(async function (Scratch) {
  // Dynamic URLs are not supported.
  const editor = await import('https://cdn.jsdelivr.com/...');
})(Scratch);

After processing:

(async function (Scratch) {
  const editor = await import('data:text/javascript;base64,...');
})(Scratch);

There will be a cache directory to store downloaded dependencies so that you do not need to download them twice.

namelessisbackbutnottodobadthingsiswear commented 3 months ago

The reason external libraries aren't allowed is because we cannot be sure whether the linked URL will always be up or not. For extensions that primarily utilize Scratch.fetch, this is a necessary evil, however it's just easier to paste in a DataURI for any needed libraries to ensure it's always online when the extension is.

FurryR commented 3 months ago

Implemented by #1591

FurryR commented 3 months ago

however it's just easier to paste in a DataURI for any needed libraries to ensure it's always online when the extension is.

This proposal is for automatically converting await import URLs into data URLs when building so it makes reviewers easier to ensure the integrity of dependencies.

LilyMakesThings commented 3 months ago

The reason external libraries aren't allowed is because we cannot be sure whether the linked URL will always be up or not.

This proposes that as part of the build process it will automatically convert the linked library to JS, since you're 100% right that we can't always rely on 3rd-party dependencies on such critical parts of projects.

In the grand scheme of things, this won't affect the front-end and will just make development a bit more readable.