fix(apis/websocket): build and runtime issues

This commit is contained in:
PalmDevs
2024-07-23 20:53:56 +07:00
parent f142c2b82e
commit 89d8ab1ee5
3 changed files with 26 additions and 25 deletions

View File

@@ -1,29 +1,33 @@
import { createLogger } from '@revanced/bot-shared'
import { cp, rm } from 'fs/promises'
async function build(): Promise<void> {
const logger = createLogger()
const logger = createLogger()
logger.info('Cleaning previous build...')
await rm('./dist', { recursive: true })
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'],
target: 'bun',
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({
logger.info('Building WebSocket API...')
await Bun.build({
entrypoints: ['./src/index.ts'],
outdir: './dist',
target: 'bun',
})
}
minify: true,
sourcemap: 'external',
})
await build()
logger.info('Building Tesseract.js worker...')
await Bun.build({
entrypoints: ['../../node_modules/tesseract.js/src/worker-script/node/index.js'],
target: 'bun',
outdir: './dist/worker',
minify: true,
sourcemap: 'external',
})
// Tesseract.js is really bad for minification
// It forcefully requires this core module to be present which contains the WASM files
logger.info('Copying Tesseract.js Core...')
await cp('../../node_modules/tesseract.js-core', './dist/node_modules/tesseract.js-core', { recursive: true })
logger.info('Copying config...')
await cp('config.json', 'dist/config.json')

View File

@@ -55,12 +55,9 @@ export interface WitMessageResponse {
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,
(await pathExists(TesseractWorkerDirPath))
? { workerPath: TesseractWorkerPath, corePath: TesseractCorePath }
: undefined,
(await pathExists(TesseractWorkerDirPath)) ? { workerPath: TesseractWorkerPath } : undefined,
)