diff --git a/.changeset/lucky-fishes-draw.md b/.changeset/lucky-fishes-draw.md new file mode 100644 index 00000000..b187ed41 --- /dev/null +++ b/.changeset/lucky-fishes-draw.md @@ -0,0 +1,5 @@ +--- +"zxing-wasm": patch +--- + +Add `ZXING_CPP_COMMIT` export. diff --git a/README.md b/README.md index 929f23b3..f0c05819 100644 --- a/README.md +++ b/README.md @@ -346,6 +346,12 @@ For convenience, this library provides an exported `ZXING_WASM_VERSION` variable import { ZXING_WASM_VERSION } from "zxing-wasm"; ``` +The commit hash of the `zxing-cpp` submodule is exported as `ZXING_CPP_COMMIT`: + +```ts +import { ZXING_CPP_COMMIT } from "zxing-wasm"; +``` + The SHA-256 hash of the `.wasm` file (in hex format) is also exported as `ZXING_WASM_SHA256`, in case you want to make sure you are serving the exactly same file: ```ts diff --git a/src/full/index.ts b/src/full/index.ts index 8121ebd1..7b756145 100644 --- a/src/full/index.ts +++ b/src/full/index.ts @@ -111,6 +111,7 @@ export * from "../bindings/exposedReaderBindings.js"; export * from "../bindings/exposedWriterBindings.js"; export { ZXING_WASM_VERSION, + ZXING_CPP_COMMIT, type PrepareZXingModuleOptions, type ZXingFullModule, type ZXingModuleOverrides, diff --git a/src/global.d.ts b/src/global.d.ts index 9f293525..82604e0e 100644 --- a/src/global.d.ts +++ b/src/global.d.ts @@ -3,3 +3,4 @@ declare const NPM_PACKAGE_VERSION: string; declare const READER_HASH: string; declare const WRITER_HASH: string; declare const FULL_HASH: string; +declare const SUBMODULE_COMMIT: string; diff --git a/src/reader/index.ts b/src/reader/index.ts index 0c9cd62f..f5faaf27 100644 --- a/src/reader/index.ts +++ b/src/reader/index.ts @@ -102,6 +102,7 @@ export async function readBarcodesFromImageData( export * from "../bindings/exposedReaderBindings.js"; export { ZXING_WASM_VERSION, + ZXING_CPP_COMMIT, type PrepareZXingModuleOptions, type ZXingReaderModule, type ZXingModuleOverrides, diff --git a/src/share.ts b/src/share.ts index ca5d4ea1..2d0b530d 100644 --- a/src/share.ts +++ b/src/share.ts @@ -81,6 +81,8 @@ export type ZXingModuleOverrides = Partial; export const ZXING_WASM_VERSION = NPM_PACKAGE_VERSION; +export const ZXING_CPP_COMMIT = SUBMODULE_COMMIT; + const DEFAULT_MODULE_OVERRIDES: ZXingModuleOverrides = import.meta.env.PROD ? { locateFile: (path, prefix) => { diff --git a/src/writer/index.ts b/src/writer/index.ts index e923abc8..a3191552 100644 --- a/src/writer/index.ts +++ b/src/writer/index.ts @@ -89,6 +89,7 @@ export async function writeBarcode( export * from "../bindings/exposedWriterBindings.js"; export { ZXING_WASM_VERSION, + ZXING_CPP_COMMIT, type PrepareZXingModuleOptions, type ZXingWriterModule, type ZXingModuleOverrides, diff --git a/vite.config.ts b/vite.config.ts index 32dfb88c..0754e447 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -1,3 +1,4 @@ +import { execSync } from "node:child_process"; import { createHash } from "node:crypto"; import { readFile } from "node:fs/promises"; import { fileURLToPath } from "node:url"; @@ -79,6 +80,11 @@ export default defineConfig({ ) .digest("hex"), ), + SUBMODULE_COMMIT: JSON.stringify( + execSync("git submodule status | cut -c-41", { + encoding: "utf-8", + }).trim(), + ), }, test: { testTimeout: 10000,