Skip to content

Commit 63f12e8

Browse files
committed
ci: commit ferric-example's declarations as a fixture instead of building them
kraenhansen suspected generateTypeScriptDeclarations doesn't actually skip a native build. Confirmed: napi-rs's `napi build` has no typegen-only mode — it always runs a real `cargo build`, and --dts-only leaves a fully populated ~123MB target/ directory (including a compiled libferric_example.so) behind. "Skipping the native build entirely" was wrong; only Android/Apple cross-compilation was actually skipped, and the lint job stayed coupled to the host Rust toolchain's health exactly as #414 wanted to avoid. Switch to the issue's other suggested option: commit ferric_example.d.ts and ferric_example.js as a checked-in fixture (no longer gitignored), and drop the ferric-example build:types step from the lint job entirely — it no longer needs to regenerate anything. --dts-only stays, now documented accurately, as the way to regenerate the fixture by hand after changing packages/ferric-example/src/lib.rs. To catch drift, the two CI jobs that already do a real `ferric build` (Android and Apple triplets) now `git diff --exit-code` the two committed files right after building. Both are label-gated rather than running on every PR, so this doesn't fully close the gap — flagged in the PR thread. Also excludes the two fixture files from Prettier: they're left in napi-rs's own output formatting so regenerating them reproduces the committed bytes exactly, and the new drift check doesn't false-positive on formatting alone. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DaK9eAAF5G8wj6UT8VekAm
1 parent cec5121 commit 63f12e8

7 files changed

Lines changed: 51 additions & 9 deletions

File tree

.changeset/wet-carrots-relax.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
"ferric-cli": patch
33
---
44

5-
Add `--dts-only` flag to `ferric build`, generating just the TypeScript declaration file and JS entrypoint without cross-compiling any Android/Apple binaries.
5+
Add `--dts-only` flag to `ferric build`, generating just the TypeScript declaration file and JS entrypoint without cross-compiling any Android/Apple binaries. It still runs a real host `cargo build` (napi-rs has no lighter typegen-only mode), so it's meant for regenerating a checked-in declarations fixture rather than for environments without a Rust toolchain.

.github/workflows/check.yml

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,13 @@ jobs:
6464
# Generate the TypeScript/C++ declarations that other packages' type-checking
6565
# depends on, without building any native binaries: weak-node-api's
6666
# "prebuild:prepare" only copies headers and runs codegen (needs clang-format,
67-
# set up above, but no JDK/Android SDK/NDK), and ferric's "--dts-only" flag
68-
# runs a plain host `cargo build` to emit ferric-example's .d.ts instead of
69-
# cross-compiling Android/Apple binaries. See #414.
67+
# set up above, but no JDK/Android SDK/NDK). ferric-example's declarations are
68+
# committed as a fixture instead (see packages/ferric-example/.gitignore) —
69+
# napi-rs's dts generation has no way to run without a real `cargo build`
70+
# (confirmed: it leaves a populated target/ directory), so unlike
71+
# weak-node-api's codegen it can't be reproduced here without reintroducing a
72+
# native build into the fastest-feedback job. See #414.
7073
- run: pnpm --filter weak-node-api run prebuild:prepare
71-
- run: pnpm --filter @react-native-node-api/ferric-example run build:types
7274
- run: pnpm run lint
7375
env:
7476
DEBUG: eslint:eslint
@@ -342,6 +344,9 @@ jobs:
342344
- name: Build ferric-example for all architectures
343345
run: pnpm run build --android
344346
working-directory: packages/ferric-example
347+
- name: Verify committed ferric-example TypeScript declarations are up to date
348+
run: git diff --exit-code -- ferric_example.d.ts ferric_example.js
349+
working-directory: packages/ferric-example
345350
- name: Run tests (Android)
346351
timeout-minutes: 75
347352
uses: reactivecircus/android-emulator-runner@v2
@@ -409,6 +414,9 @@ jobs:
409414
# Build Ferric example for all Apple architectures
410415
- run: pnpm exec ferric --apple
411416
working-directory: packages/ferric-example
417+
- name: Verify committed ferric-example TypeScript declarations are up to date
418+
run: git diff --exit-code -- ferric_example.d.ts ferric_example.js
419+
working-directory: packages/ferric-example
412420
- name: Inspect the structure of the prebuilt binary
413421
run: |
414422
lipo -info ferric_example.apple.node/*/libferric_example.framework/libferric_example > lipo-output.txt

.prettierignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,10 @@ packages/node-addon-examples/examples
1414
packages/node-tests/node
1515
packages/node-tests/tests
1616
packages/node-tests/*.generated.js
17+
18+
# Committed napi-rs codegen fixture (see packages/ferric-example/.gitignore) — left
19+
# in napi-rs's own output formatting so `pnpm run build:types` reproduces it exactly
20+
# and the CI drift check (see .github/workflows/check.yml) doesn't false-positive on
21+
# formatting alone.
22+
packages/ferric-example/ferric_example.d.ts
23+
packages/ferric-example/ferric_example.js

packages/ferric-example/.gitignore

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
/*.apple.node/
55
/*.android.node/
66

7-
# Generated files
8-
/ferric_example.d.ts
9-
/ferric_example.js
7+
# ferric_example.d.ts and ferric_example.js are intentionally NOT ignored: they're
8+
# committed as a fixture so `pnpm run lint` (which apps/test-app's App.tsx needs for
9+
# its `typeof import("@react-native-node-api/ferric-example")`) doesn't have to run a
10+
# native `cargo build` to get them. See #414. Regenerate with `pnpm run build:types`
11+
# after changing packages/ferric-example/src/lib.rs, and let the "Test app (Android)"
12+
# / "Test ferric Apple triplets" jobs' drift check catch anyone who forgets.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/**
2+
* This file was generated by
3+
* ╭─────────────────────────╮
4+
* │░█▀▀░█▀▀░█▀▄░█▀▄░▀█▀░█▀▀░│
5+
* │░█▀▀░█▀▀░█▀▄░█▀▄░░█░░█░░░│
6+
* │░▀░░░▀▀▀░▀░▀░▀░▀░▀▀▀░▀▀▀░│
7+
* ╰─────────────────────────╯
8+
* Powered by napi.rs
9+
*/
10+
/* eslint-disable */
11+
export declare function sum(a: number, b: number): number
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/* eslint-disable */
2+
3+
/**
4+
* This file was generated by
5+
* ╭─────────────────────────╮
6+
* │░█▀▀░█▀▀░█▀▄░█▀▄░▀█▀░█▀▀░│
7+
* │░█▀▀░█▀▀░█▀▄░█▀▄░░█░░█░░░│
8+
* │░▀░░░▀▀▀░▀░▀░▀░▀░▀▀▀░▀▀▀░│
9+
* ╰─────────────────────────╯
10+
* Powered by napi.rs
11+
*/
12+
13+
module.exports = require('./ferric_example.node');

packages/ferric/src/build.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ const xcframeworkExtensionOption = new Option(
106106
).default(false);
107107
const dtsOnlyOption = new Option(
108108
"--dts-only",
109-
"Only generate the TypeScript declarations, skipping the native build entirely (no Android/Apple toolchain needed)",
109+
"Only generate the TypeScript declarations and entrypoint, skipping Android/Apple cross-compilation. Still runs a real `cargo build` for the host target (napi-rs has no lighter typegen-only mode), so this is not a no-op — it's meant for regenerating a checked-in declarations fixture, not for toolchain-free environments.",
110110
).default(false);
111111

112112
const outputPathOption = new Option(

0 commit comments

Comments
 (0)