11// @ts -nocheck
22/* eslint-disable no-restricted-syntax */
33import swc from "@swc/core" ;
4- import { execSync } from "child_process" ;
4+ import { execFileSync , execSync } from "child_process" ;
55import crypto from "crypto" ;
66import { build } from "esbuild" ;
77import globalPlugin from "esbuild-plugin-globals" ;
@@ -10,6 +10,7 @@ import { fileURLToPath } from "url";
1010import yargs from "yargs-parser" ;
1111
1212import { printBuildSuccess } from "./util.mjs" ;
13+ import { readFile } from "fs/promises" ;
1314
1415/** @type string[] */
1516const metroDeps = await ( async ( ) => {
@@ -121,6 +122,23 @@ export async function buildBundle(overrideConfig = {}) {
121122 const initialStartTime = performance . now ( ) ;
122123 await build ( { ...config , ...overrideConfig } ) ;
123124
125+ const paths = {
126+ win32 : 'win64-bin/hermesc.exe' ,
127+ darwin : 'osx-bin/hermesc' ,
128+ linux : 'linux64-bin/hermesc' ,
129+ }
130+
131+ if ( ! ( process . platform in paths ) )
132+ throw new Error ( `Unsupported platform: ${ process . platform } ` )
133+
134+ const sdksDir = './node_modules/react-native/sdks'
135+ const binPath = `${ sdksDir } /hermesc/${ paths [ process . platform ] } `
136+
137+ execFileSync ( binPath , [ '-finline' , '-strict' , '-O' , '-g1' , '-reuse-prop-cache' , '-optimized-eval' , '-emit-binary' , '-Wno-undefined-variable' , '-out' , config . outfile ] , {
138+ input : await readFile ( config . outfile ) ,
139+ stdio : 'pipe'
140+ } ) ;
141+
124142 return {
125143 config,
126144 context,
0 commit comments