Skip to content

Commit 70b8934

Browse files
committed
fix(cli): transform yoga-sync.mjs to remove top-level await for CJS
The newer yoga-sync builds incorrectly use top-level await which isn't compatible with esbuild's CJS output format. Despite the name, yogaPromise is synchronous (-sWASM_ASYNC_COMPILATION=0), so we can call it directly. This workaround will become a no-op once socket-btm publishes a fixed release.
1 parent 5b39cc7 commit 70b8934

File tree

1 file changed

+29
-1
lines changed

1 file changed

+29
-1
lines changed

packages/cli/scripts/download-assets.mjs

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,29 @@ async function extractArchive(tarGzPath, extractConfig, assetName) {
208208
await fs.writeFile(versionPath, tag, 'utf-8')
209209
}
210210

211+
/**
212+
* Transform yoga-sync.mjs to remove top-level await for CJS compatibility.
213+
*
214+
* The newer yoga-sync builds incorrectly use top-level await which isn't
215+
* compatible with esbuild's CJS output format. Despite the name, yogaPromise
216+
* is synchronous (-sWASM_ASYNC_COMPILATION=0), so we can call it directly.
217+
*/
218+
function transformYogaSync(content) {
219+
// Pattern: const Yoga = wrapAssembly(await yogaPromise);
220+
// Transform to: const Yoga = wrapAssembly(yogaPromise);
221+
// (yogaPromise is synchronous despite its name)
222+
const hasTopLevelAwait = content.includes('wrapAssembly(await yogaPromise)')
223+
if (!hasTopLevelAwait) {
224+
return content
225+
}
226+
227+
// Replace the top-level await pattern with synchronous call.
228+
return content.replace(
229+
/const Yoga = wrapAssembly\(await yogaPromise\);/,
230+
'const Yoga = wrapAssembly(yogaPromise);',
231+
)
232+
}
233+
211234
/**
212235
* Process and transform asset (e.g., add header to JS file).
213236
*/
@@ -238,7 +261,12 @@ async function processAsset(assetPath, processConfig, assetName) {
238261
}
239262

240263
// Read the downloaded asset.
241-
const content = await fs.readFile(assetPath, 'utf-8')
264+
let content = await fs.readFile(assetPath, 'utf-8')
265+
266+
// Transform yoga-sync to remove top-level await for CJS compatibility.
267+
if (assetName === 'yoga') {
268+
content = transformYogaSync(content)
269+
}
242270

243271
// Compute source hash for cache validation.
244272
const sourceHash = await computeFileHash(assetPath)

0 commit comments

Comments
 (0)