Skip to content

Commit

Permalink
refactor: remove peerDependency of toolkit (#560)
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangyouxin committed Oct 13, 2023
1 parent ed5dc56 commit db34aef
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 25 deletions.
5 changes: 5 additions & 0 deletions .changeset/green-tips-accept.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@ckb-lumos/toolkit": patch
---

remove peer dependencies in toolkit
10 changes: 4 additions & 6 deletions packages/toolkit/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,14 @@
},
"author": "Xuejie Xiao",
"license": "MIT",
"peerDependencies": {
"cross-fetch": "^3.1.4",
"jsbi": "^4.1.0"
},
"publishConfig": {
"access": "public"
},
"dependencies": {
"@ckb-lumos/bi": "0.21.0-next.0"
},
"devDependencies": {
"@babel/plugin-proposal-export-namespace-from": "^7.18.9",
"@babel/plugin-transform-modules-commonjs": "^7.21.5",
"jsbi": "^4.1.0"
"@babel/plugin-transform-modules-commonjs": "^7.21.5"
}
}
4 changes: 2 additions & 2 deletions packages/toolkit/src/normalizers.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@
// Note this is only used when you need to deal with CKB structures in molecule
// format. If you are using RPCs or GraphQL to interact with CKB, chances are you
// will not need this package.
import JSBI from "jsbi";
import { BI } from "@ckb-lumos/bi";
import { Reader } from "./reader";
/**
* @deprecated please follow the {@link https://lumos-website.vercel.app/migrations/migrate-to-v0.19 migration-guide}
*/
function normalizeHexNumber(length) {
return function (debugPath, value) {
if (!(value instanceof ArrayBuffer)) {
let intValue = JSBI.BigInt(value).toString(16);
let intValue = BI.from(value).toString(16);
if (intValue.length % 2 !== 0) {
intValue = "0" + intValue;
}
Expand Down
32 changes: 32 additions & 0 deletions packages/toolkit/tests/normailizers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
const test = require("ava");
const { normalizers } = require("../lib");

test("correct outPoint should pass validation", (t) => {
const normalizedOutpoint = normalizers.NormalizeOutPoint({
txHash: `0x${"00".repeat(32)}`,
index: "0x1",
});
const expectedNormalizedIndex = new ArrayBuffer(4);
const view = new Int32Array(expectedNormalizedIndex);
view[0] = 1;

t.deepEqual(normalizedOutpoint, {
index: expectedNormalizedIndex,
txHash: new ArrayBuffer(32),
});
});

test("error outPoint should not pass validation", (t) => {
t.throws(() => {
normalizers.NormalizeOutPoint({
txHash: `0x${"00".repeat(32)}`,
index: "0x",
});
});
t.throws(() => {
normalizers.NormalizeOutPoint({
txHash: `0x${"00".repeat(32)}`,
index: "not a number",
});
});
});
11 changes: 0 additions & 11 deletions packages/toolkit/types/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import JSBI from "jsbi";

export * as validators from "./validators";

/**
Expand All @@ -17,15 +15,6 @@ export class Reader {
serializeJson(): string;
}

/**
* @deprecated please follow the {@link https://lumos-website.vercel.app/migrations/migrate-to-v0.19 migration-guide}
*/
export function HexStringToBigInt(hexString: string): JSBI;
/**
* @deprecated please follow the {@link https://lumos-website.vercel.app/migrations/migrate-to-v0.19 migration-guide}
*/
export function BigIntToHexString(i: JSBI): string;

/**
* @deprecated please follow the {@link https://lumos-website.vercel.app/migrations/migrate-to-v0.19 migration-guide}
*/
Expand Down
9 changes: 3 additions & 6 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 comments on commit db34aef

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

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

🚀 New canary release: 0.0.0-canary-db34aef-20231013061434

npm install @ckb-lumos/lumos@0.0.0-canary-db34aef-20231013061434

@vercel
Copy link

@vercel vercel bot commented on db34aef Oct 13, 2023

Choose a reason for hiding this comment

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

Please sign in to comment.