diff --git a/apis/websocket/scripts/build.ts b/apis/websocket/scripts/build.ts index 6a2d348..360fa97 100644 --- a/apis/websocket/scripts/build.ts +++ b/apis/websocket/scripts/build.ts @@ -1,9 +1,12 @@ import { createLogger } from '@revanced/bot-shared' -import { cp } from 'fs/promises' +import { cp, rm } from 'fs/promises' async function build(): Promise { const logger = createLogger() + logger.info('Cleaning previous build...') + await rm('./dist', { recursive: true }) + logger.info('Building Tesseract.js worker...') await Bun.build({ entrypoints: ['../../node_modules/tesseract.js/src/worker-script/node/index.js'], @@ -11,6 +14,9 @@ async function build(): Promise { outdir: './dist/worker', }) + logger.info('Copying Tesseract.js WASM...') + await cp('../../node_modules/tesseract.js-core', './dist/worker/core', { recursive: true }) + logger.info('Building WebSocket API...') await Bun.build({ entrypoints: ['./src/index.ts'], diff --git a/apis/websocket/src/context.ts b/apis/websocket/src/context.ts index 27b80a7..0f5301d 100644 --- a/apis/websocket/src/context.ts +++ b/apis/websocket/src/context.ts @@ -53,11 +53,14 @@ export interface WitMessageResponse { }> } -const TesseractWorkerPath = joinPath(import.meta.dir, 'worker', 'index.js') -const TesseractCompiledWorkerExists = await pathExists(TesseractWorkerPath) +const TesseractWorkerDirPath = joinPath(import.meta.dir, 'worker') +const TesseractWorkerPath = joinPath(TesseractWorkerDirPath, 'index.js') +const TesseractCorePath = joinPath(TesseractWorkerDirPath, 'core') export const tesseract = await createTesseractWorker( 'eng', OEM.DEFAULT, - TesseractCompiledWorkerExists ? { workerPath: TesseractWorkerPath } : undefined, + (await pathExists(TesseractWorkerDirPath)) + ? { workerPath: TesseractWorkerPath, corePath: TesseractCorePath } + : undefined, )