Skip to content

Commit c003bf6

Browse files
committed
Use one request for compose wasm resource versions
1 parent a0e24c2 commit c003bf6

File tree

2 files changed

+18
-19
lines changed

2 files changed

+18
-19
lines changed

src/config.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,18 +65,15 @@ export const API_URLS = {
6565
get VERSIONS() {
6666
return `${this.server}/versions`;
6767
},
68-
SKIKO_VERSION() {
69-
return `${this.composeServer}/api/resource/skiko`;
68+
RESOURCE_VERSIONS() {
69+
return `${this.composeServer}/api/resource/compose-wasm-versions`;
7070
},
7171
SKIKO_MJS(version) {
7272
return `${this.composeResources}/api/resource/skiko-${version}.mjs`;
7373
},
7474
SKIKO_WASM(version) {
7575
return `${this.composeResources}/api/resource/skiko-${version}.wasm`;
7676
},
77-
STDLIB_HASH() {
78-
return `${this.composeServer}/api/resource/stdlib`;
79-
},
8077
STDLIB_MJS(hash) {
8178
return `${this.composeResources}/api/resource/stdlib-${hash}.mjs`;
8279
},

src/js-executor/index.js

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -183,32 +183,32 @@ export default class JsExecutor {
183183
}
184184
if (targetPlatform === TargetPlatforms.COMPOSE_WASM) {
185185

186-
const skikoExports = fetch(API_URLS.SKIKO_VERSION(), {
186+
const skikoStdlib = fetch(API_URLS.RESOURCE_VERSIONS(),{
187187
method: 'GET'
188-
}).then(response => response.text())
189-
.then(version =>
190-
fetch(API_URLS.SKIKO_MJS(version), {
188+
}).then(response => response.json())
189+
.then(versions => {
190+
const skikoVersion = versions["skiko"];
191+
192+
const skikoExports = fetch(API_URLS.SKIKO_MJS(skikoVersion), {
191193
method: 'GET',
192194
headers: {
193195
'Content-Type': 'text/javascript',
194196
}
195197
}).then(script => script.text())
196198
.then(script => script.replace(
197199
"new URL(\"skiko.wasm\",import.meta.url).href",
198-
`'${API_URLS.SKIKO_WASM(version)}'`
200+
`'${API_URLS.SKIKO_WASM(skikoVersion)}'`
199201
))
200202
.then(skikoCode =>
201203
executeJs(
202204
this.iframe.contentWindow,
203205
skikoCode,
204206
))
205-
.then(skikoExports => fixedSkikoExports(skikoExports)))
207+
.then(skikoExports => fixedSkikoExports(skikoExports))
206208

207-
const stdlibExports = fetch(API_URLS.STDLIB_HASH(), {
208-
method: 'GET'
209-
}).then(response => response.text())
210-
.then(hash =>
211-
fetch(API_URLS.STDLIB_MJS(hash), {
209+
const stdlibVersion = versions["stdlib"];
210+
211+
const stdlibExports = fetch(API_URLS.STDLIB_MJS(stdlibVersion), {
212212
method: 'GET',
213213
headers: {
214214
'Content-Type': 'text/javascript',
@@ -217,7 +217,7 @@ export default class JsExecutor {
217217
.then(script =>
218218
// necessary to load stdlib.wasm before its initialization to parallelize
219219
// language=JavaScript
220-
(`const stdlibWasm = fetch('${API_URLS.STDLIB_WASM(hash)}');\n` + script).replace(
220+
(`const stdlibWasm = fetch('${API_URLS.STDLIB_WASM(stdlibVersion)}');\n` + script).replace(
221221
"fetch(new URL('./stdlib_master.wasm',import.meta.url).href)",
222222
"stdlibWasm"
223223
).replace(
@@ -230,9 +230,11 @@ export default class JsExecutor {
230230
stdlibCode,
231231
)
232232
)
233-
)
234233

235-
this.stdlibExports = Promise.all([skikoExports, stdlibExports])
234+
return Promise.all([skikoExports, stdlibExports])
235+
})
236+
237+
this.stdlibExports = skikoStdlib
236238
.then(async ([skikoExportsResult, stdlibExportsResult]) => {
237239
return [
238240
await stdlibExportsResult.instantiate({

0 commit comments

Comments
 (0)