Skip to content

Commit 3ab43b4

Browse files
committed
fix: package build for packages/sdk
1 parent 5af54ba commit 3ab43b4

File tree

15 files changed

+124
-93
lines changed

15 files changed

+124
-93
lines changed

.yarn/install-state.gz

1.07 KB
Binary file not shown.

package.json

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,12 @@
77
],
88
"scripts": {
99
"prepare": "husky install",
10-
"wasm:ts:node": "tsc -p tsconfig.lib.node.json",
11-
"wasm:ts:web": "tsc -p tsconfig.lib.web.json",
10+
"ts:web": "tspc -p packages/sdk/tsconfig.web.json",
11+
"ts:web-multicore": "tspc -p packages/sdk-multicore/tsconfig.web.json",
12+
"ts:node": "tspc -p packages/sdk-node/tsconfig.web.json",
13+
"ts:node-multicore": "tspc -p packages/sdk-node-multicore/tsconfig.json",
14+
"wasm:ts:node": "tspc -p tsconfig.lib.node.json",
15+
"wasm:ts:web": "tspc -p tsconfig.lib.web.json",
1216
"wasm:build": "yarn wasm:ts:web && node ./scripts/build.js --release",
1317
"wasm:build:multicore": "yarn wasm:ts:web && node ./scripts/build.js --release --multicore",
1418
"wasm:build:dev": "yarn wasm:ts:web && node ./scripts/build.js",
@@ -27,6 +31,7 @@
2731
"lint-staged": "^15.2.0",
2832
"prettier": "^3.3.3",
2933
"prettier-plugin-organize-imports": "^3.2.4",
34+
"ts-patch": "^3.1.2",
3035
"typescript": "5.5.4",
3136
"wsrun": "^5.2.4"
3237
},

packages/lib/src/tx/types.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
export { TxType, TxTypeLabel } from "../wasm";
2-
export type { SupportedTx } from "../wasm";
1+
export { TxType, TxTypeLabel } from "@namada/wasm";
2+
export type { SupportedTx } from "@namada/wasm";

packages/sdk-multicore/src/init.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export default async function init(): Promise<{
1111
memory: WebAssembly.Memory;
1212
}> {
1313
// Load and initialize shared wasm
14-
const sharedWasm = await fetch("shared.namada.wasm").then((wasm) =>
14+
const sharedWasm = await fetch("sdk.namada.wasm").then((wasm) =>
1515
wasm.arrayBuffer(),
1616
);
1717
const { memory } = await initSdk(sharedWasm);

packages/sdk-node/tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
],
99
"compilerOptions": {
1010
"declaration": true,
11-
"outDir": "dist/node",
11+
"outDir": "../../dist",
1212
"module": "node16",
1313
"moduleResolution": "node16",
1414
"plugins": [

packages/sdk/package.json

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,27 @@
22
"name": "@namada/sdk",
33
"version": "1.0.0",
44
"description": "Namada Web SDK",
5-
"main": "src/index.js",
6-
"types": "src/index.d.ts",
5+
"main": "sdk/src/index.js",
6+
"types": "sdk/src/index.d.ts",
77
"repository": "https://github.com/anoma/namada-sdkjs/",
88
"author": "Heliax Dev <info@heliax.dev>",
99
"license": "MIT",
1010
"files": [
11-
"dist/**/*.{js,ts,wasm}"
11+
"lib/**/*.{js,ts}",
12+
"sdk/**/*.{js,ts}",
13+
"wasm/**/*.{js,ts,wasm}"
1214
],
15+
"dependencies": {
16+
"@cosmjs/encoding": "^0.29.0",
17+
"@dao-xyz/borsh": "^5.1.5",
18+
"@ledgerhq/hw-transport": "^6.31.4",
19+
"@ledgerhq/hw-transport-webusb": "^6.29.4",
20+
"@zondax/ledger-namada": "^2.0.0",
21+
"bignumber.js": "^9.1.1",
22+
"buffer": "^6.0.3",
23+
"semver": "^7.6.3",
24+
"slip44": "^3.0.18"
25+
},
1326
"publishConfig": {
1427
"registry": "https://registry.npmjs.org",
1528
"access": "public"

packages/sdk/src/index.ts

Lines changed: 1 addition & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1 @@
1-
import { Query as QueryWasm, Sdk as SdkWasm } from "@namada/wasm";
2-
import { Sdk } from "@namada/lib";
3-
export * from "./index";
4-
// export * from "./utils";
5-
6-
/**
7-
* Get the SDK instance
8-
* @async
9-
* @param cryptoMemory - WebAssembly.Memory of crypto package
10-
* @param url - URL of the node
11-
* @param maspIndexerUrl - optional URL of the MASP indexer
12-
* @param dbName - Name of the database for the serialized wallet
13-
* @param [token] - Native token of the chain
14-
* @throws {Error} - Unable to Query native token
15-
* @returns - Sdk instance
16-
*/
17-
export function getSdk(
18-
cryptoMemory: WebAssembly.Memory,
19-
url: string,
20-
maspIndexerUrl: string,
21-
dbName: string,
22-
token: string,
23-
): Sdk {
24-
// We change empty string to undefined so it "maps" to the Option<String> in Rust
25-
const maspIndexerUrlOpt =
26-
maspIndexerUrl.length === 0 ? undefined : maspIndexerUrl;
27-
// Instantiate QueryWasm
28-
const query = new QueryWasm(url, maspIndexerUrlOpt);
29-
30-
// Instantiate SdkWasm
31-
const sdk = new SdkWasm(url, token, dbName);
32-
return new Sdk(sdk, query, cryptoMemory, url, token);
33-
}
34-
35-
/**
36-
* Query native token from the node
37-
* @async
38-
* @param rpc - URL of the node
39-
* @returns
40-
*/
41-
export async function getNativeToken(rpc: string): Promise<string> {
42-
return await new QueryWasm(rpc).query_native_token();
43-
}
1+
export * from "./init";

packages/sdk/src/init.ts

Lines changed: 30 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,41 @@
1-
// We have to use relative improts here othewise ts-patch is getting confused and produces wrong paths after compialtion
2-
import { init as initSdk } from "@namada/wasm/src/init";
3-
import { initThreadPool } from "../../wasm/src/init-thread-pool";
1+
import { Query as QueryWasm, Sdk as SdkWasm } from "@namada/wasm";
2+
// We have to use relative imports here othewise ts-patch is getting confused and produces wrong paths after compialtion
3+
import { init } from "../../wasm/src/init";
4+
import { Sdk, SdkWasmOptions } from "../../lib/src";
5+
6+
/**
7+
* Query native token from the node
8+
* @async
9+
* @param rpc - URL of the node
10+
* @returns
11+
*/
12+
export async function getNativeToken(rpc: string): Promise<string> {
13+
return await new QueryWasm(rpc).query_native_token();
14+
}
415

516
/**
617
* Initialize the SDK memory
718
* @async
8-
* @returns - The SDK wasm memory pointer
19+
* @param props - SdkWasmOptions object
20+
* @returns - Sdk instance
921
*/
10-
export default async function init(): Promise<{
11-
memory: WebAssembly.Memory;
12-
}> {
22+
export async function initSdk(props: SdkWasmOptions): Promise<Sdk> {
23+
const { rpcUrl, token, maspIndexerUrl, dbName = "" } = props;
1324
// Load and initialize sdk wasm
14-
const wasm = await fetch("shared.namada.wasm").then((wasm) =>
25+
const wasm = await fetch("sdk.namada.wasm").then((wasm) =>
1526
wasm.arrayBuffer(),
1627
);
17-
const { memory } = await initSdk(wasm);
28+
const { memory } = await init(wasm);
1829

19-
return { memory };
20-
}
30+
// We change empty string to undefined so it "maps" to the Option<String> in Rust
31+
const maspIndexerUrlOpt =
32+
maspIndexerUrl?.length === 0 ? undefined : maspIndexerUrl;
33+
// Instantiate QueryWasm
34+
const query = new QueryWasm(rpcUrl, maspIndexerUrlOpt);
2135

22-
/**
23-
* Initialize the SDK memory, with multicore support.
24-
* If you built wasm without multicore support, this will work as regular init.
25-
* @async
26-
* @returns - The SDK wasm memory pointer
27-
*/
28-
export async function initMulticore(): Promise<{
29-
memory: WebAssembly.Memory;
30-
}> {
31-
const res = await init();
32-
await initThreadPool(navigator.hardwareConcurrency);
33-
return res;
36+
// Instantiate SdkWasm
37+
const sdk = new SdkWasm(rpcUrl, token, dbName);
38+
return new Sdk(sdk, query, memory, rpcUrl, token);
3439
}
40+
41+
export * from "@namada/lib";

packages/sdk/tsconfig.json

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,32 @@
11
{
22
"extends": "../../tsconfig.base.json",
3-
"include": [
4-
"src/**/*"
5-
],
6-
"exclude": [
7-
"node_modules"
8-
],
93
"compilerOptions": {
10-
"declaration": true,
4+
"allowJs": true,
5+
"allowSyntheticDefaultImports": true,
6+
"baseUrl": "./src",
117
"outDir": "../../dist",
8+
"esModuleInterop": true,
9+
"experimentalDecorators": true,
10+
"forceConsistentCasingInFileNames": true,
11+
"isolatedModules": true,
12+
// "dom" is needed for WebAssembly typings
13+
"lib": ["esnext", "dom"],
1214
"module": "esnext",
1315
"moduleResolution": "bundler",
14-
"plugins": [
15-
// Transform paths in output .js files
16-
{ "transform": "typescript-transform-paths" },
17-
18-
// Transform paths in output .d.ts files (Include this line if you output declarations files)
19-
{ "transform": "typescript-transform-paths", "afterDeclarations": true }
20-
]
16+
"noEmit": false,
17+
"noFallthroughCasesInSwitch": true,
18+
"resolveJsonModule": true,
19+
"skipLibCheck": true,
20+
"sourceMap": true,
21+
"strict": true,
22+
"target": "es2015"
23+
},
24+
"include": ["src/**/*.ts", "examples/**/*.ts"],
25+
"exclude": ["node_modules"],
26+
"typeRoots": ["./node_modules/@types"],
27+
"ts-node": {
28+
"compilerOptions": {
29+
"module": "commonjs"
30+
}
2131
}
2232
}

packages/sdk/tsconfig.web.json

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"extends": "./tsconfig.json",
3+
"include": [
4+
"src/index.ts",
5+
"src/init.ts"
6+
],
7+
"exclude": [
8+
"**/*.test.ts",
9+
"node_modules",
10+
"scripts"
11+
],
12+
"compilerOptions": {
13+
"declaration": true,
14+
"outDir": "../../dist",
15+
"module": "esnext",
16+
"moduleResolution": "bundler",
17+
"plugins": [
18+
// Transform paths in output .js files
19+
{ "transform": "typescript-transform-paths" },
20+
21+
// Transform paths in output .d.ts files (Include this line if you output declarations files)
22+
{ "transform": "typescript-transform-paths", "afterDeclarations": true }
23+
]
24+
}
25+
}

packages/wasm/src/index.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import { Query as RustQuery } from "./sdk";
66
export * from "./sdk";
77
export * from "./types";
88
export * from "./utils";
9-
export * from "./loader";
109

1110
type TimeoutOpts = {
1211
// Timeout in milliseconds
@@ -63,4 +62,3 @@ export class Query extends RustQuery {
6362

6463
export * from "./types";
6564
export { Proposal, Proposals };
66-
export { initSdk } from "../wasm/loader";

packages/wasm/tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"allowJs": true,
55
"baseUrl": "./src",
66
"rootDir": "./src",
7-
"outDir": "./dist/",
7+
"outDir": "../../dist/",
88
"esModuleInterop": true,
99
"experimentalDecorators": true,
1010
"forceConsistentCasingInFileNames": true,

scripts/copy.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import { execSync } from "child_process";
2+
3+
execSync("cp -r ./packages/wasm/src/sdk ./dist/wasm/src/");
4+
execSync("cp -r ./packages/wasm/src/sdk/sdk_bg.wasm ./dist/sdk.namada.wasm");

tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
"target": "es2015"
2121
},
2222
"include": ["src/**/*.ts"],
23-
"exclude": ["node_modules"],
23+
"exclude": ["node_modules", "scripts"],
2424
"typeRoots": ["./node_modules/@types"],
2525
"ts-node": {
2626
"compilerOptions": {

yarn.lock

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1974,6 +1974,16 @@ __metadata:
19741974
"@namada/sdk@workspace:packages/sdk":
19751975
version: 0.0.0-use.local
19761976
resolution: "@namada/sdk@workspace:packages/sdk"
1977+
dependencies:
1978+
"@cosmjs/encoding": "npm:^0.29.0"
1979+
"@dao-xyz/borsh": "npm:^5.1.5"
1980+
"@ledgerhq/hw-transport": "npm:^6.31.4"
1981+
"@ledgerhq/hw-transport-webusb": "npm:^6.29.4"
1982+
"@zondax/ledger-namada": "npm:^2.0.0"
1983+
bignumber.js: "npm:^9.1.1"
1984+
buffer: "npm:^6.0.3"
1985+
semver: "npm:^7.6.3"
1986+
slip44: "npm:^3.0.18"
19771987
languageName: unknown
19781988
linkType: soft
19791989

@@ -7380,6 +7390,7 @@ __metadata:
73807390
lint-staged: "npm:^15.2.0"
73817391
prettier: "npm:^3.3.3"
73827392
prettier-plugin-organize-imports: "npm:^3.2.4"
7393+
ts-patch: "npm:^3.1.2"
73837394
typescript: "npm:5.5.4"
73847395
wsrun: "npm:^5.2.4"
73857396
languageName: unknown

0 commit comments

Comments
 (0)