Skip to content

avoid importing package.json#905

Merged
tomusdrw merged 4 commits intomainfrom
td-fix-lib
Feb 8, 2026
Merged

avoid importing package.json#905
tomusdrw merged 4 commits intomainfrom
td-fix-lib

Conversation

@tomusdrw
Copy link
Copy Markdown
Member

@tomusdrw tomusdrw commented Feb 6, 2026

Importing package.json files causes them to be included in the built library, which in turn breaks the imports overrides defined in the top-level package.json only (i.e. nested package.json creates a local scope which does not have imports, hence it breaks).
The issues is not present when sub-exports are used and the affected packages are not imported, but it always appears when a default, top-level import is used.
Relying on a single package.json import in utils should resolve that issue, since none of the nested package.jsons will be included.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Feb 6, 2026

📝 Walkthrough

Summary by CodeRabbit

  • Refactor

    • Centralized name/version sourcing so banners, logs, tests, and metrics use a single utility export; metrics now use stable, fixed service identifiers.
  • Chores

    • Added a rule forbidding direct imports of package metadata.
    • Consolidated top-level dependency declarations for consistency.
  • New Features

    • Utilities package now publicly exposes project name and version.

Walkthrough

This PR centralizes package metadata by adding exports name and version in packages/core/utils (new package.ts and re-export from utils index) and replaces direct imports of local package.json with imports from @typeberry/utils across CLI bins, node packages, and metrics modules. Metrics modules also switch to fixed meter names and use the centralized version. A .coderabbit.yaml rule forbids importing package.json in TypeScript files. bin/lib/package.json dependencies were adjusted.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested reviewers

  • skoszuta
  • DrEverr

Poem

🐇 I hopped through nodes and bins today,
Gathered version, tucked package.json away,
One tidy import, no stray file to chase,
Metrics named steady, in their cozy place,
A little rabbit's code-cleaning pace. 🥕

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 57.14% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title 'avoid importing package.json' directly and accurately describes the main objective of the changeset—to stop importing package.json files across the codebase and centralize this import in a shared utils module.
Description check ✅ Passed The description clearly explains the technical problem (package.json imports break top-level imports overrides) and the solution (centralize the import in utils), which matches the changes shown in the raw summary.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch td-fix-lib

No actionable comments were generated in the recent review. 🎉


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In `@bin/lib/package.json`:
- Around line 48-52: The package is unconditionally exporting `@typeberry/native`
to browsers via the `@typeberry/lib` "./crypto" subpath which re-exports symbols
(bandersnatch, initAll) from `@typeberry/native`; update the package exports so
native bindings are not exposed to browser consumers by either (A) changing the
./crypto export to a conditional subpath (e.g., provide a node-specific export
like "./crypto": {"node": "./crypto.node.js", "default": "./crypto.browser.js"})
or (B) remove `@typeberry/native` from the public exports and import it only
internally in `@typeberry/crypto`, exposing a pure-JS/browser-safe facade from
`@typeberry/lib/crypto`; ensure references to bandersnatch and initAll are only
resolved by the node-specific module or internal import.
🧹 Nitpick comments (1)
bin/jam/args.ts (1)

6-6: Consider using @typeberry/utils for consistency with other CLI entry points.

While importing the top-level package.json is allowed per coding guidelines, other CLI files in this PR (e.g., bin/rpc/main.ts, bin/tci/args.ts, bin/convert/args.ts) now import version from @typeberry/utils. Consider aligning this file with the same pattern for consistency across the codebase.

♻️ Optional refactor for consistency
-import packageJson from "../../package.json" with { type: "json" };
+import { version } from "@typeberry/utils";

And update line 18:

-@typeberry/jam ${packageJson.version} by Fluffy Labs.
+@typeberry/jam ${version} by Fluffy Labs.

Comment thread bin/lib/package.json
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In @.coderabbit.yaml:
- Around line 74-77: Update the rule in the .coderabbit.yaml block that
currently replaces package.json imports with imports from `@typeberry/utils` to
either (A) add a documented exception for browser-only packages or (B) clarify
that the rule targets server/universal packages and relies on tree-shaking;
mention the browser-package exception by name and explain when to keep direct
package.json imports, and reference the Node-specific symbols in
`@typeberry/utils` (debug.ts: process.hrtime, env.ts: process.env, test.ts:
node:assert) so maintainers know why the exception exists and when to apply it.

Comment thread .coderabbit.yaml
Comment thread bin/jam/args.ts Outdated
@tomusdrw tomusdrw enabled auto-merge February 8, 2026 10:28
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Feb 8, 2026

View all
File Benchmark Ops
bytes/hex-from.ts[0] parse hex using Number with NaN checking 50055.06 ±0.65% 88.92% slower
bytes/hex-from.ts[1] parse hex from char codes 451954.14 ±0.49% fastest ✅
bytes/hex-from.ts[2] parse hex from string nibbles 247347.8 ±0.22% 45.27% slower
hash/index.ts[0] hash with numeric representation 70.92 ±0.26% 28.41% slower
hash/index.ts[1] hash with string representation 36.04 ±3.42% 63.62% slower
hash/index.ts[2] hash with symbol representation 67.11 ±1.01% 32.26% slower
hash/index.ts[3] hash with uint8 representation 68.02 ±0.24% 31.34% slower
hash/index.ts[4] hash with packed representation 99.07 ±0.47% fastest ✅
hash/index.ts[5] hash with bigint representation 76.44 ±0.46% 22.84% slower
hash/index.ts[6] hash with uint32 representation 83.34 ±0.19% 15.88% slower
logger/index.ts[0] console.log with string concat 4659294.52 ±22.94% fastest ✅
logger/index.ts[1] console.log with args 828127.18 ±86.8% 82.23% slower
collections/map-set.ts[0] 2 gets + conditional set 84041.44 ±0.48% fastest ✅
collections/map-set.ts[1] 1 get 1 set 48542.07 ±0.61% 42.24% slower
codec/bigint.decode.ts[0] decode custom 72998547.78 ±3.53% fastest ✅
codec/bigint.decode.ts[1] decode bigint 36058551.99 ±1.85% 50.6% slower
codec/bigint.compare.ts[0] compare custom 93097908.25 ±5.18% 3.78% slower
codec/bigint.compare.ts[1] compare bigint 96751012.84 ±5.5% fastest ✅
bytes/hex-to.ts[0] number toString + padding 81053.14 ±0.5% fastest ✅
bytes/hex-to.ts[1] manual 6240.66 ±0.31% 92.3% slower
math/count-bits-u64.ts[0] standard method 448092.67 ±0.89% 82.06% slower
math/count-bits-u64.ts[1] magic 2497478.58 ±0.52% fastest ✅
math/mul_overflow.ts[0] multiply and bring back to u32 95318875.76 ±5.56% 0.72% slower
math/mul_overflow.ts[1] multiply and take modulus 96007912.09 ±4.49% fastest ✅
math/switch.ts[0] switch 91877430.28 ±4.99% 0.66% slower
math/switch.ts[1] if 92488517.43 ±5.42% fastest ✅
math/add_one_overflow.ts[0] add and take modulus 94090479.78 ±5.25% 0.04% slower
math/add_one_overflow.ts[1] condition before calculation 94129456.15 ±4.87% fastest ✅
math/count-bits-u32.ts[0] standard method 40233972.23 ±1.92% 57.5% slower
math/count-bits-u32.ts[1] magic 94671028.33 ±4.44% fastest ✅
codec/decoding.ts[0] manual decode 7026172.3 ±2.21% 89.35% slower
codec/decoding.ts[1] int32array decode 63269541.76 ±4.12% 4.08% slower
codec/decoding.ts[2] dataview decode 65962462.26 ±3.15% fastest ✅
codec/encoding.ts[0] manual encode 874262.72 ±0.67% 15.72% slower
codec/encoding.ts[1] int32array encode 1037330.22 ±0.6% fastest ✅
codec/encoding.ts[2] dataview encode 1031722.56 ±0.64% 0.54% slower
bytes/bytes-to-number.ts[0] Conversion with bitops 2903.92 ±10.75% 17.56% slower
bytes/bytes-to-number.ts[1] Conversion without bitops 3522.32 ±6.02% fastest ✅
bytes/compare.ts[0] Comparing Uint32 bytes 9421.31 ±0.97% 1.28% slower
bytes/compare.ts[1] Comparing raw bytes 9543.45 ±0.27% fastest ✅
collections/hash-dict-vs-blob-dict_set.ts[0] StringHashDictionary 1431.6 ±1.04% 1.14% slower
collections/hash-dict-vs-blob-dict_set.ts[1] BlobDictionary(1) 1433.35 ±0.77% 1.01% slower
collections/hash-dict-vs-blob-dict_set.ts[2] BlobDictionary(2) 1441.52 ±0.65% 0.45% slower
collections/hash-dict-vs-blob-dict_set.ts[3] BlobDictionary(3) 1436.11 ±0.6% 0.82% slower
collections/hash-dict-vs-blob-dict_set.ts[4] BlobDictionary(4) 1448.04 ±0.63% fastest ✅
collections/hash-dict-vs-blob-dict_set.ts[5] BlobDictionary(5) 1444.49 ±0.66% 0.25% slower
collections/hash-dict-vs-blob-dict_get.ts[0] StringHashDictionary 2035.97 ±0.48% fastest ✅
collections/hash-dict-vs-blob-dict_get.ts[1] BlobDictionary(1) 2024.87 ±0.63% 0.55% slower
collections/hash-dict-vs-blob-dict_get.ts[2] BlobDictionary(2) 1976.37 ±0.68% 2.93% slower
collections/hash-dict-vs-blob-dict_get.ts[3] BlobDictionary(3) 1963.9 ±0.76% 3.54% slower
collections/hash-dict-vs-blob-dict_get.ts[4] BlobDictionary(4) 1967.99 ±0.78% 3.34% slower
collections/hash-dict-vs-blob-dict_get.ts[5] BlobDictionary(5) 1949.25 ±0.68% 4.26% slower
collections/hash-dict-vs-blob-dict_delete.ts[0] StringHashDictionary 1960.27 ±1.01% 0.67% slower
collections/hash-dict-vs-blob-dict_delete.ts[1] BlobDictionary(1) 1874.33 ±0.58% 5.03% slower
collections/hash-dict-vs-blob-dict_delete.ts[2] BlobDictionary(2) 1913 ±0.92% 3.07% slower
collections/hash-dict-vs-blob-dict_delete.ts[3] BlobDictionary(3) 938.1 ±103.11% 52.47% slower
collections/hash-dict-vs-blob-dict_delete.ts[4] BlobDictionary(4) 1973.51 ±0.79% fastest ✅
collections/hash-dict-vs-blob-dict_delete.ts[5] BlobDictionary(5) 1941.76 ±0.76% 1.61% slower
codec/view_vs_collection.ts[0] Get first element from Decoded 11183.6 ±0.6% 56.8% slower
codec/view_vs_collection.ts[1] Get first element from View 25889.99 ±1.06% fastest ✅
codec/view_vs_collection.ts[2] Get 50th element from Decoded 11171.77 ±0.4% 56.85% slower
codec/view_vs_collection.ts[3] Get 50th element from View 13495.49 ±1.07% 47.87% slower
codec/view_vs_collection.ts[4] Get last element from Decoded 11357.14 ±0.35% 56.13% slower
codec/view_vs_collection.ts[5] Get last element from View 9504.1 ±0.55% 63.29% slower
codec/view_vs_object.ts[0] Get the first field from Decoded 173816.16 ±0.68% 0.56% slower
codec/view_vs_object.ts[1] Get the first field from View 42869.5 ±0.62% 75.47% slower
codec/view_vs_object.ts[2] Get the first field as view from View 43045.32 ±0.58% 75.37% slower
codec/view_vs_object.ts[3] Get two fields from Decoded 174689.99 ±0.6% 0.06% slower
codec/view_vs_object.ts[4] Get two fields from View 34008.82 ±0.77% 80.54% slower
codec/view_vs_object.ts[5] Get two fields from materialized from View 71017.91 ±0.48% 59.37% slower
codec/view_vs_object.ts[6] Get two fields as views from View 34758 ±0.5% 80.12% slower
codec/view_vs_object.ts[7] Get only third field from Decoded 174795.38 ±0.85% fastest ✅
codec/view_vs_object.ts[8] Get only third field from View 42760.3 ±1.05% 75.54% slower
codec/view_vs_object.ts[9] Get only third field as view from View 43414 ±0.54% 75.16% slower
collections/map_vs_sorted.ts[0] Map 120848.21 ±0.18% fastest ✅
collections/map_vs_sorted.ts[1] Map-array 45832.01 ±0.46% 62.07% slower
collections/map_vs_sorted.ts[2] Array 39498.53 ±0.3% 67.32% slower
collections/map_vs_sorted.ts[3] SortedArray 82223.12 ±0.2% 31.96% slower
hash/blake2b.ts[0] our hasher 1.11 ±0.21% fastest ✅
hash/blake2b.ts[1] blake2b js 0.03 ±0.57% 97.3% slower
crypto/ed25519.ts[0] native crypto 6.12 ±0.86% fastest ✅
crypto/ed25519.ts[1] wasm lib 2.13 ±0.24% 65.2% slower
crypto/ed25519.ts[2] wasm lib batch 2.12 ±0.4% 65.36% slower

Benchmarks summary: 83/83 OK ✅

@tomusdrw tomusdrw disabled auto-merge February 8, 2026 19:42
@tomusdrw tomusdrw enabled auto-merge February 8, 2026 19:43
@tomusdrw tomusdrw added this pull request to the merge queue Feb 8, 2026
Merged via the queue into main with commit d166a3a Feb 8, 2026
14 checks passed
@tomusdrw tomusdrw deleted the td-fix-lib branch February 8, 2026 19:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants