Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proposal: dependency system based on await import #1587

Open
FurryR opened this issue Jul 4, 2024 · 4 comments · May be fixed by #1591
Open

Proposal: dependency system based on await import #1587

FurryR opened this issue Jul 4, 2024 · 4 comments · May be fixed by #1591

Comments

@FurryR
Copy link
Contributor

FurryR commented Jul 4, 2024

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

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 added a commit to FurryR/extensions that referenced this issue Jul 4, 2024
@FurryR FurryR linked a pull request Jul 4, 2024 that will close this issue
@FurryR
Copy link
Contributor Author

FurryR commented Jul 4, 2024

Implemented by #1591

@FurryR
Copy link
Contributor Author

FurryR commented Jul 4, 2024

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
Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants