Skip to content

Commit

Permalink
chore: add ZXING_CPP_COMMIT export
Browse files Browse the repository at this point in the history
  • Loading branch information
Sec-ant committed Jan 23, 2025
1 parent 0674a3f commit 6321b02
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/lucky-fishes-draw.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"zxing-wasm": patch
---

Add `ZXING_CPP_COMMIT` export.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/full/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions src/global.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
1 change: 1 addition & 0 deletions src/reader/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions src/share.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ export type ZXingModuleOverrides = Partial<EmscriptenModule>;

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) => {
Expand Down
1 change: 1 addition & 0 deletions src/writer/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
6 changes: 6 additions & 0 deletions vite.config.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 6321b02

Please sign in to comment.