Skip to content

Commit fefdd85

Browse files
authored
fix: Fix module
Fully switch to ES Module
2 parents 3048711 + aa72526 commit fefdd85

22 files changed

+342
-129
lines changed

.changeset/clear-readers-fall.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@contentauth/c2pa-node": patch
3+
---
4+
5+
Convert package to ES Module

.commitlintrc.yml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# If updating this file, please also review `docs/release-process.md` and
2+
# `.github/workflows/pr_title.yml` and update the summary of these rules
3+
# in those files accordingly.
4+
5+
rules:
6+
# Body may be empty
7+
body-empty:
8+
level: ignore
9+
10+
# Description must not be empty
11+
description-empty:
12+
level: error
13+
14+
# Description should be <70 chars
15+
description-max-length:
16+
level: warning
17+
length: 70
18+
19+
# Subject line should exist
20+
subject-empty:
21+
level: error
22+
23+
# Type must be one of these options
24+
type:
25+
level: error
26+
options:
27+
- build
28+
- chore
29+
- ci
30+
- docs
31+
- feat
32+
- fix
33+
- perf
34+
- refactor
35+
- revert
36+
- style
37+
- test
38+
- update

.github/workflows/pr_title.yml

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
name: PR title
2+
3+
on:
4+
pull_request:
5+
types: [opened, synchronize, reopened, edited]
6+
7+
jobs:
8+
title_cc_validation:
9+
name: Conventional commits validation
10+
runs-on: ubuntu-latest
11+
12+
steps:
13+
- name: Checkout repository
14+
uses: actions/checkout@v4
15+
16+
# If changing this, please also see `.commitlintrc` and
17+
# `docs/release-process.md`.
18+
19+
- name: Check PR title
20+
env:
21+
PR_TITLE: ${{ github.event.pull_request.title }}
22+
run: |
23+
# If this step fails, please expand this step for more information.
24+
#
25+
# You will need to revise this pull request's title to
26+
# match the "summary" (first) line of a Conventional Commit message.
27+
# This enables us to automatically generate a meaningful changelog.
28+
#
29+
# The summary line (and thus the PR title) must have this exact format
30+
# (including punctuation):
31+
#
32+
# type: description
33+
#
34+
# `type` describes the nature of changes you are making. This project
35+
# requires the type to be one of these exact names:
36+
#
37+
# * fix
38+
# * feat (will cause a minor version bump)
39+
# * chore (will be omitted from changelog)
40+
# * update
41+
# * doc
42+
#
43+
# `description` is a short human-readable summary of the changes being made.
44+
# It is required.
45+
#
46+
# This project does not currently enforce the following items, but
47+
# we ask that you observe the following preferences in `description`:
48+
#
49+
# * The entire description should be written and capitalized as
50+
# an English-language sentence, except that the trailing period
51+
# should be omitted.
52+
# * Any acronyms such as JSON or YAML should be capitalized as per
53+
# common usage in English-language sentences.
54+
#
55+
# After you edit the PR title, this task will run again and the
56+
# warning should go away if you have made acceptable changes.
57+
#
58+
# For more information on Conventional Commits, please see:
59+
#
60+
# https://www.conventionalcommits.org/en/v1.0.0/
61+
#
62+
# ------------ (end of message) ------------
63+
64+
if echo "$PR_TITLE" | grep -E '^chore(\(.*\))?: release '; then
65+
echo "Exception / OK: chore release pattern"
66+
exit 0;
67+
fi
68+
69+
if echo "$PR_TITLE" | grep -E '^chore: release'; then
70+
echo "Exception / OK: chore release pattern"
71+
exit 0;
72+
fi
73+
74+
if echo "$PR_TITLE" | grep -E '^chore(\(deps\))?: bump '; then
75+
echo "Exception / OK: Dependabot update pattern"
76+
exit 0;
77+
fi
78+
79+
if echo "$PR_TITLE" | grep -E '^update: update '; then
80+
echo "Exception / OK: Dependabot update pattern"
81+
exit 0;
82+
fi
83+
84+
if echo "$PR_TITLE" | grep -E '^update: bump '; then
85+
echo "Exception / OK: Dependabot update pattern"
86+
exit 0;
87+
fi
88+
89+
echo "Installing commitlint-rs. Please wait 30-40 seconds ..."
90+
cargo install --quiet commitlint-rs
91+
set -e
92+
93+
echo  
94+
echo  
95+
echo --- commitlint results for PR title \"$PR_TITLE\" ---
96+
echo  
97+
98+
echo "$PR_TITLE" | commitlint -g .commitlintrc.yml
99+
100+
echo "✅ PR title matches all enforced rules."

eslint.config.js renamed to eslint.config.cjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ module.exports = [
6363
},
6464
},
6565
{
66-
files: ['scripts/**/*.js'],
66+
files: ['scripts/**/*.js', 'scripts/**/*.cjs'],
6767
languageOptions: {
6868
ecmaVersion: 'latest',
6969
sourceType: 'commonjs',

js-src/Builder.spec.ts

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,22 @@
1313

1414
/* eslint-disable @typescript-eslint/no-non-null-assertion */
1515

16+
import type { Manifest, ResourceRef } from "@contentauth/c2pa-types";
17+
import * as fs from "fs-extra";
18+
import path from "path";
19+
import * as crypto from "crypto";
20+
1621
import type {
1722
BuilderInterface,
1823
JsCallbackSignerConfig,
1924
DestinationBufferAsset,
2025
SourceBufferAsset,
2126
FileAsset,
22-
} from "./types";
23-
import { isActionsAssertion } from "./assertions";
24-
import type { Manifest, ResourceRef } from "@contentauth/c2pa-types";
25-
import { CallbackSigner, LocalSigner } from "./Signer";
26-
import { Reader } from "./Reader";
27-
import { Builder } from "./Builder";
28-
import * as fs from "fs-extra";
29-
import path from "path";
30-
import * as crypto from "crypto";
27+
} from "./types.d.ts";
28+
import { isActionsAssertion } from "./assertions.js";
29+
import { CallbackSigner, LocalSigner } from "./Signer.js";
30+
import { Reader } from "./Reader.js";
31+
import { Builder } from "./Builder.js";
3132

3233
const tempDir = path.join(__dirname, "tmp");
3334

js-src/Builder.ts

Lines changed: 45 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@
1111
// specific language governing permissions and limitations under
1212
// each license.
1313

14-
const neon = require("./index.node");
14+
import type { Manifest } from "@contentauth/c2pa-types";
15+
16+
import { getNeonBinary } from "./binary.js";
1517
import type {
1618
BuilderInterface,
1719
CallbackSignerInterface,
@@ -24,15 +26,14 @@ import type {
2426
ManifestAssertionKind,
2527
SourceAsset,
2628
NeonBuilderHandle,
27-
} from "./types";
28-
import { IdentityAssertionSigner } from "./IdentityAssertion";
29-
import type { Manifest } from "@contentauth/c2pa-types";
29+
} from "./types.d.ts";
30+
import { IdentityAssertionSigner } from "./IdentityAssertion.js";
3031

3132
export class Builder implements BuilderInterface {
3233
private constructor(private builder: NeonBuilderHandle) {}
3334

3435
static new(): Builder {
35-
const builder: NeonBuilderHandle = neon.builderNew();
36+
const builder: NeonBuilderHandle = getNeonBinary().builderNew();
3637
return new Builder(builder);
3738
}
3839

@@ -51,24 +52,25 @@ export class Builder implements BuilderInterface {
5152
"Failed to stringify JSON Manifest Definition: Unknown error",
5253
);
5354
}
54-
const builder: NeonBuilderHandle = neon.builderWithJson(jsonString);
55+
const builder: NeonBuilderHandle =
56+
getNeonBinary().builderWithJson(jsonString);
5557
return new Builder(builder);
5658
}
5759

5860
setNoEmbed(noEmbed = true): void {
59-
neon.builderSetNoEmbed.call(this.builder, noEmbed);
61+
getNeonBinary().builderSetNoEmbed.call(this.builder, noEmbed);
6062
}
6163

6264
setRemoteUrl(remoteUrl: string): void {
63-
neon.builderSetRemoteUrl.call(this.builder, remoteUrl);
65+
getNeonBinary().builderSetRemoteUrl.call(this.builder, remoteUrl);
6466
}
6567

6668
addAssertion(
6769
label: string,
6870
assertion: unknown,
6971
assertionKind?: ManifestAssertionKind,
7072
): void {
71-
return neon.builderAddAssertion.call(
73+
return getNeonBinary().builderAddAssertion.call(
7274
this.builder,
7375
label,
7476
assertion,
@@ -77,34 +79,39 @@ export class Builder implements BuilderInterface {
7779
}
7880

7981
async addResource(uri: string, resource: SourceAsset): Promise<void> {
80-
return neon.builderAddResource.call(this.builder, uri, resource);
82+
return getNeonBinary().builderAddResource.call(this.builder, uri, resource);
8183
}
8284

8385
async addIngredient(
8486
ingredientJson: string,
8587
ingredient: SourceAsset,
8688
): Promise<void> {
87-
return neon.builderAddIngredient.call(
89+
return getNeonBinary().builderAddIngredient.call(
8890
this.builder,
8991
ingredientJson,
9092
ingredient,
9193
);
9294
}
9395

9496
async toArchive(asset: DestinationAsset): Promise<void> {
95-
return neon.builderToArchive.call(this.builder, asset);
97+
return getNeonBinary().builderToArchive.call(this.builder, asset);
9698
}
9799

98100
static async fromArchive(asset: SourceAsset): Promise<Builder> {
99-
return new Builder(await neon.builderFromArchive(asset));
101+
return new Builder(await getNeonBinary().builderFromArchive(asset));
100102
}
101103

102104
sign(
103105
signer: LocalSignerInterface,
104106
input: SourceAsset,
105107
output: DestinationAsset,
106108
): Buffer {
107-
return neon.builderSign.call(this.builder, signer.signer(), input, output);
109+
return getNeonBinary().builderSign.call(
110+
this.builder,
111+
signer.signer(),
112+
input,
113+
output,
114+
);
108115
}
109116

110117
signFile(
@@ -113,7 +120,12 @@ export class Builder implements BuilderInterface {
113120
output: DestinationAsset,
114121
): Buffer {
115122
const input: FileAsset = { path: filePath };
116-
return neon.builderSign.call(this.builder, signer.signer(), input, output);
123+
return getNeonBinary().builderSign.call(
124+
this.builder,
125+
signer.signer(),
126+
input,
127+
output,
128+
);
117129
}
118130

119131
async signConfigAsync(
@@ -122,8 +134,14 @@ export class Builder implements BuilderInterface {
122134
input: SourceAsset,
123135
output: DestinationAsset,
124136
): Promise<Buffer> {
125-
return neon.builderSignConfigAsync
126-
.call(this.builder, callback, signerConfig, input, output)
137+
return getNeonBinary()
138+
.builderSignConfigAsync.call(
139+
this.builder,
140+
callback,
141+
signerConfig,
142+
input,
143+
output,
144+
)
127145
.then((result: Buffer | { manifest: Buffer; signedAsset: Buffer }) => {
128146
// output is a buffer and result is the manifest and the signed asset.
129147
if ("buffer" in output) {
@@ -151,8 +169,8 @@ export class Builder implements BuilderInterface {
151169
const neonHandle = signer.signer();
152170
const isIdentity = signer instanceof IdentityAssertionSigner;
153171
const neonFn = isIdentity
154-
? neon.builderIdentitySignAsync
155-
: neon.builderSignAsync;
172+
? getNeonBinary().builderIdentitySignAsync
173+
: getNeonBinary().builderSignAsync;
156174
return neonFn
157175
.call(this.builder, neonHandle, input, output)
158176
.then((result: Buffer | { manifest: Buffer; signedAsset: Buffer }) => {
@@ -175,10 +193,16 @@ export class Builder implements BuilderInterface {
175193
}
176194

177195
getManifestDefinition(): Manifest {
178-
return JSON.parse(neon.builderManifestDefinition.call(this.builder));
196+
return JSON.parse(
197+
getNeonBinary().builderManifestDefinition.call(this.builder),
198+
);
179199
}
180200

181201
updateManifestProperty(property: string, value: ClaimVersion): void {
182-
neon.builderUpdateManifestProperty.call(this.builder, property, value);
202+
getNeonBinary().builderUpdateManifestProperty.call(
203+
this.builder,
204+
property,
205+
value,
206+
);
183207
}
184208
}

js-src/IdentityAssertion.spec.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,17 @@
1313

1414
/* eslint-disable @typescript-eslint/no-non-null-assertion */
1515

16+
import type { Manifest } from "@contentauth/c2pa-types";
17+
import * as fs from "fs-extra";
18+
import * as crypto from "crypto";
19+
import { encode } from "cbor2";
20+
1621
import type {
1722
JsCallbackSignerConfig,
1823
DestinationBufferAsset,
1924
SigningAlg,
2025
SignerPayload,
21-
} from "./types";
22-
import type { Manifest } from "@contentauth/c2pa-types";
23-
import * as fs from "fs-extra";
24-
import * as crypto from "crypto";
25-
import { encode } from "cbor2";
26+
} from "./types.d.ts";
2627

2728
class TestSigner {
2829
private privateKey: crypto.KeyObject;

0 commit comments

Comments
 (0)