Skip to content

Commit 18f21fe

Browse files
committed
feat: compile to bytecode
1 parent 16f9bc3 commit 18f21fe

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

scripts/build.mjs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// @ts-nocheck
22
/* eslint-disable no-restricted-syntax */
33
import swc from "@swc/core";
4-
import { execSync } from "child_process";
4+
import { execFileSync, execSync } from "child_process";
55
import crypto from "crypto";
66
import { build } from "esbuild";
77
import globalPlugin from "esbuild-plugin-globals";
@@ -10,6 +10,7 @@ import { fileURLToPath } from "url";
1010
import yargs from "yargs-parser";
1111

1212
import { printBuildSuccess } from "./util.mjs";
13+
import { readFile } from "fs/promises";
1314

1415
/** @type string[] */
1516
const 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,

scripts/serve.mjs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ export function serve(options) {
2727
timeTook
2828
);
2929

30-
res.writeHead(200, { "Content-Type": "application/javascript" });
31-
res.end(await readFile(config.outfile, "utf-8"));
30+
res.writeHead(200);
31+
res.end(await readFile(config.outfile));
3232
} catch {
3333
res.writeHead(500);
3434
res.end();

0 commit comments

Comments
 (0)