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

@@ -37,4 +37,4 @@
"@types/ws": "^8.5.10", "@types/ws": "^8.5.10",
"typed-emitter": "^2.1.0" "typed-emitter": "^2.1.0"
} }
} }

View File

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

View File

@@ -55,12 +55,9 @@ export interface WitMessageResponse {
const TesseractWorkerDirPath = joinPath(import.meta.dir, 'worker') const TesseractWorkerDirPath = joinPath(import.meta.dir, 'worker')
const TesseractWorkerPath = joinPath(TesseractWorkerDirPath, 'index.js') const TesseractWorkerPath = joinPath(TesseractWorkerDirPath, 'index.js')
const TesseractCorePath = joinPath(TesseractWorkerDirPath, 'core')
export const tesseract = await createTesseractWorker( export const tesseract = await createTesseractWorker(
'eng', 'eng',
OEM.DEFAULT, OEM.DEFAULT,
(await pathExists(TesseractWorkerDirPath)) (await pathExists(TesseractWorkerDirPath)) ? { workerPath: TesseractWorkerPath } : undefined,
? { workerPath: TesseractWorkerPath, corePath: TesseractCorePath }
: undefined,
) )