This repository has no description
Something went wrong. Try again.
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455import { build } from 'esbuild';import { copyFile, mkdir } from 'node:fs/promises';import { syncShared } from './sync_shared.mjs';
await syncShared(['firefox']);
await mkdir('extension/firefox/lib', { recursive: true });await copyFile('node_modules/tesseract.js-core/tesseract-core-lstm.wasm.js', 'extension/firefox/lib/tesseract-core-lstm.wasm.js');await mkdir('extension/firefox/lib/licenses', { recursive: true });for (const [name, filename] of Object.entries({ 'tesseract.js': 'LICENSE.md', 'tesseract.js-core': 'LICENSE', 'bmp-js': 'LICENSE', 'idb-keyval': 'LICENCE', 'is-url': 'LICENSE-MIT', 'wasm-feature-detect': 'LICENSE', zlibjs: 'LICENSE', buffer: 'LICENSE', 'base64-js': 'LICENSE', ieee754: 'LICENSE',})) { await copyFile(`node_modules/${name}/${filename}`, `extension/firefox/lib/licenses/${name}.txt`);}
// Firefox 109 supports native async/generators and globalThis. Build directly// from upstream source rather than shipping legacy regenerator/webpack eval// fallbacks. This is reproducible from package-lock.json with npm ci.const options = { bundle: true, platform: 'browser', target: 'firefox109', format: 'iife', minify: true, legalComments: 'inline', define: { global: 'globalThis' }, inject: ['scripts/firefox_buffer_shim.mjs'], plugins: [{ name: 'native-async', setup(build) { build.onResolve({ filter: /^regenerator-runtime\/runtime$/ }, () => ({ path: 'native-async', namespace: 'native-async', })); build.onLoad({ filter: /.*/, namespace: 'native-async' }, () => ({ contents: '// Native async and generators require no runtime polyfill.', })); }, }],};
await build({ ...options, entryPoints: ['node_modules/tesseract.js/src/index.js'], globalName: 'Tesseract', outfile: 'extension/firefox/lib/tesseract.min.js',});await build({ ...options, entryPoints: ['node_modules/tesseract.js/src/worker-script/browser/index.js'], outfile: 'extension/firefox/lib/worker.min.js',});