Skip to content

Commit 4d91fc9

Browse files
Load cmijs only after api global is captured
1 parent cfd3bb4 commit 4d91fc9

1 file changed

Lines changed: 6 additions & 4 deletions

File tree

packages/dev-playground/src/CompilerApi.res

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -326,18 +326,20 @@ let getMapValueOrThrow = (map: Map.t<string, 'value>, key, message): 'value =>
326326
let ensureCompilerApi = async version => {
327327
let selectedVersion = versionOrDefault(version)
328328
if compilerApis->Map.has(selectedVersion) {
329-
let _ = await loadRuntimeLibraries(selectedVersion)
329+
await loadRuntimeLibraries(selectedVersion)
330330
compilerApis->getMapValueOrThrow(selectedVersion, "Compiler API was not cached")
331331
} else {
332332
let root = versionRoot(selectedVersion)
333-
let _ = await loadScript(`${root}/compiler.js`)
334-
let _ = await loadRuntimeLibraries(selectedVersion)
335-
333+
await loadScript(`${root}/compiler.js`)
336334
let api = switch Api.global {
337335
| Some(api) if hasFunction(api, "make") => api
338336
| _ => JsError.throwWithMessage("rescript_compiler global was not registered by compiler.js")
339337
}
340338

339+
// Load runtime .cmijs only after the global is captured to prevent loading
340+
// the wrong version after selecting a different compiler.
341+
await loadRuntimeLibraries(selectedVersion)
342+
341343
compilerApis->Map.set(selectedVersion, api)
342344
api
343345
}

0 commit comments

Comments
 (0)