Skip to content

Commit 3bac75a

Browse files
authored
Fix a bug where building a package that includes @orca-so/whirlpools using tsc fails (#446)
* Test * Tests * Remove nodejs bundle size test * Tweak * Fix
1 parent 35689a9 commit 3bac75a

File tree

10 files changed

+391
-14
lines changed

10 files changed

+391
-14
lines changed

ts-sdk/core/package.json

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,21 @@
44
"version": "0.0.1",
55
"main": "./dist/nodejs/orca_whirlpools_core_js_bindings.js",
66
"types": "./dist/nodejs/orca_whirlpools_core_js_bindings.d.ts",
7-
"browser": "./dist/web/orca_whirlpools_core_js_bindings.js",
7+
"browser": "./dist/browser/orca_whirlpools_core_js_bindings.js",
88
"type": "module",
99
"sideEffects": [
10-
"./dist/web/snippets/*"
10+
"./dist/browser/snippets/*",
11+
"./dist/browser/orca_whirlpools_core_js_bindings.js"
1112
],
1213
"files": [
13-
"dist/nodejs/orca_whirlpools_core_js_bindings_bg.wasm",
14-
"dist/nodejs/orca_whirlpools_core_js_bindings.js",
15-
"dist/nodejs/orca_whirlpools_core_js_bindings.d.ts",
16-
"dist/web/orca_whirlpools_core_js_bindings_bg.wasm",
17-
"dist/web/orca_whirlpools_core_js_bindings.js",
18-
"dist/web/orca_whirlpools_core_js_bindings.d.ts",
14+
"dist",
1915
"README.md"
2016
],
2117
"scripts": {
22-
"build": "wasm-pack build --out-dir ./dist/web --target web && wasm-pack build --out-dir ./dist/nodejs --target nodejs",
18+
"build": "wasm-pack build --out-dir ./dist/nodejs --target nodejs && wasm-pack build --out-dir ./dist/browser --target browser",
2319
"test": "tsc --noEmit && vitest run tests",
2420
"clean": "cargo clean && rimraf dist",
25-
"prepublishOnly": "rimraf dist/web/.gitignore dist/nodejs/.gitignore"
21+
"prepublishOnly": "rimraf dist/nodejs/.gitignore dist/browser/.gitignore"
2622
},
2723
"devDependencies": {
2824
"@orca-so/whirlpools-client": "*",

ts-sdk/core/tests/size.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ import { describe, it } from "vitest";
55

66
const WASM_SIZE_LIMIT = 25000; // 25KB
77

8-
describe("WASM bundle size", () => {
9-
it.skip("NodeJS", () => {
8+
describe("Bundle size", () => {
9+
it.skip("nodejs", () => {
1010
const output = execSync(
1111
"gzip -c dist/nodejs/orca_whirlpools_core_js_bindings_bg.wasm | wc -c",
1212
).toString();
@@ -18,9 +18,9 @@ describe("WASM bundle size", () => {
1818
}
1919
});
2020

21-
it.skip("Web", () => {
21+
it.skip("browser", () => {
2222
const output = execSync(
23-
"gzip -c dist/web/orca_whirlpools_core_js_bindings_bg.wasm | wc -c",
23+
"gzip -c dist/browser/orca_whirlpools_core_js_bindings_bg.wasm | wc -c",
2424
).toString();
2525
const size = parseInt(output);
2626
if (size > WASM_SIZE_LIMIT) {
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"compilerOptions": {
3+
"target": "ES6",
4+
"module": "ES6",
5+
"moduleResolution": "Node",
6+
"skipLibCheck": true
7+
},
8+
"include": ["../index.ts"]
9+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"compilerOptions": {
3+
"target": "ESNext",
4+
"module": "ESNext",
5+
"moduleResolution": "Node",
6+
"skipLibCheck": true
7+
},
8+
"include": ["../index.ts"]
9+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"compilerOptions": {
3+
"target": "ESNext",
4+
"module": "NodeNext",
5+
"moduleResolution": "NodeNext",
6+
"skipLibCheck": true
7+
},
8+
"include": ["../index.ts"]
9+
}

ts-sdk/integration/index.test.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import assert from "assert";
2+
import { execSync } from "child_process";
3+
import { readdirSync } from "fs";
4+
import { describe, it } from "vitest";
5+
6+
const commandTemplates = [
7+
"tsx --tsconfig {} ./index.ts",
8+
"tsc --project {} --outDir ./dist && node ./dist/index.js",
9+
// FIXME: ts-node does not play nice with ESM since node 20
10+
// "ts-node --esm --project {} ./index.ts",
11+
// TODO: should we also add browser/bundler?
12+
]
13+
14+
// commonjs not included here because wasm wouldn't support it
15+
const tsConfigs = readdirSync("./configs");
16+
17+
describe("Integration", () => {
18+
commandTemplates.forEach(template => {
19+
tsConfigs.forEach(config => {
20+
const command = template.replace("{}", `./configs/${config}`);
21+
it(`Use '${command}'`, () => {
22+
const output = execSync(command).toString();
23+
assert(output.includes("2LecshUwdy9xi7meFgHtFJQNSKk4KdTrcpvaB56dP2NQ"));
24+
assert(output.includes("256"));
25+
assert(output.includes("whirLbMiicVdio4qvUfM5KAg6Ct8VwpYzGff3uctyCc"));
26+
});
27+
});
28+
});
29+
});

ts-sdk/integration/index.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { DEFAULT_WHIRLPOOLS_CONFIG_ADDRESS } from "@orca-so/whirlpools";
2+
import { _POSITION_BUNDLE_SIZE } from "@orca-so/whirlpools-core";
3+
import { WHIRLPOOL_PROGRAM_ADDRESS } from "@orca-so/whirlpools-client";
4+
5+
console.info(
6+
DEFAULT_WHIRLPOOLS_CONFIG_ADDRESS,
7+
_POSITION_BUNDLE_SIZE(),
8+
WHIRLPOOL_PROGRAM_ADDRESS,
9+
);

ts-sdk/integration/package.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"name": "@orca-so/whirlpools-integration",
3+
"private": true,
4+
"type": "module",
5+
"scripts": {
6+
"build": "tsc --noEmit",
7+
"test": "vitest run index.test.ts"
8+
},
9+
"dependencies": {
10+
"@orca-so/whirlpools": "*"
11+
},
12+
"devDependencies": {
13+
"tsx": "^4.19.0",
14+
"typescript": "^5.6.3"
15+
}
16+
}

ts-sdk/integration/tsconfig.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"extends": "../../tsconfig.json",
3+
"compilerOptions": {
4+
"outDir": "./dist"
5+
},
6+
"include": ["index.ts"]
7+
}

0 commit comments

Comments
 (0)