Repository navigation
Commit a00fa8e
authored
Implement Scratch.external - extensions part (TurboWarp#2267)
5 new APIs:
* Scratch.external.importModule() is a wrapper around import() that gets
inlined at build time
* Scratch.external.fetch() is a wrapper around fetch() that gets inlined
at build time
* Scratch.external.dataURL() is like external.fetch() but it gives you a
base64 data: URL
* Scratch.external.blob() is like external.fetch() but it gives you a
Blob
* Scratch.external.evalAndReturn() is for executing scripts inside of a
function and then returning an expression of your choice
In development, all of these call directly into VM implementation which
does actually go and fetch each time the extension runs. In production,
all of these are inlined in various ways so that everything is inside
the JS file. All references to Scratch.external go away, so we're not
breaking compatibility with anything. A new concept called "build
snippets" are added into built JS as needed to implement things like
base85 and zstd decompression.
URLs should point to jsdelivr, unpkg, raw.githubusercontent.com, etc. In
development mode, new URLs will be found and fetched so their SHA-256
can be stored. In production builds, these resources get fetched and the
hashes are checked to ensure no tampering. Must use an immutable URL
pinned to an npm tag or commit hash.
Face sensing has been updated to use these as a first example.
Ideally this API would be called Scratch.import, but using "import"
verbatim causes various issues in TypeScript and elsewhere so we're
avoiding that. Hence, "Scratch.external" and "importModule"1 parent c08a1f8 commit a00fa8e
17 files changed
Lines changed: 1626 additions & 101 deletions
File tree
- build-snippets
- development
- extensions/lab
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
| 1 | + | |
2 | 2 | | |
| 3 | + | |
3 | 4 | | |
4 | 5 | | |
5 | 6 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
| 9 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
0 commit comments