Skip to content

Commit

Permalink
Fix a bug where building a package that includes `@orca-so/whirlpools…
Browse files Browse the repository at this point in the history
…` using `tsc` fails (#446)

* Test

* Tests

* Remove nodejs bundle size test

* Tweak

* Fix
  • Loading branch information
wjthieme authored Nov 1, 2024
1 parent 35689a9 commit 3bac75a
Show file tree
Hide file tree
Showing 10 changed files with 391 additions and 14 deletions.
16 changes: 6 additions & 10 deletions ts-sdk/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,21 @@
"version": "0.0.1",
"main": "./dist/nodejs/orca_whirlpools_core_js_bindings.js",
"types": "./dist/nodejs/orca_whirlpools_core_js_bindings.d.ts",
"browser": "./dist/web/orca_whirlpools_core_js_bindings.js",
"browser": "./dist/browser/orca_whirlpools_core_js_bindings.js",
"type": "module",
"sideEffects": [
"./dist/web/snippets/*"
"./dist/browser/snippets/*",
"./dist/browser/orca_whirlpools_core_js_bindings.js"
],
"files": [
"dist/nodejs/orca_whirlpools_core_js_bindings_bg.wasm",
"dist/nodejs/orca_whirlpools_core_js_bindings.js",
"dist/nodejs/orca_whirlpools_core_js_bindings.d.ts",
"dist/web/orca_whirlpools_core_js_bindings_bg.wasm",
"dist/web/orca_whirlpools_core_js_bindings.js",
"dist/web/orca_whirlpools_core_js_bindings.d.ts",
"dist",
"README.md"
],
"scripts": {
"build": "wasm-pack build --out-dir ./dist/web --target web && wasm-pack build --out-dir ./dist/nodejs --target nodejs",
"build": "wasm-pack build --out-dir ./dist/nodejs --target nodejs && wasm-pack build --out-dir ./dist/browser --target browser",
"test": "tsc --noEmit && vitest run tests",
"clean": "cargo clean && rimraf dist",
"prepublishOnly": "rimraf dist/web/.gitignore dist/nodejs/.gitignore"
"prepublishOnly": "rimraf dist/nodejs/.gitignore dist/browser/.gitignore"
},
"devDependencies": {
"@orca-so/whirlpools-client": "*",
Expand Down
8 changes: 4 additions & 4 deletions ts-sdk/core/tests/size.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import { describe, it } from "vitest";

const WASM_SIZE_LIMIT = 25000; // 25KB

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

it.skip("Web", () => {
it.skip("browser", () => {
const output = execSync(
"gzip -c dist/web/orca_whirlpools_core_js_bindings_bg.wasm | wc -c",
"gzip -c dist/browser/orca_whirlpools_core_js_bindings_bg.wasm | wc -c",
).toString();
const size = parseInt(output);
if (size > WASM_SIZE_LIMIT) {
Expand Down
9 changes: 9 additions & 0 deletions ts-sdk/integration/configs/es6.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"compilerOptions": {
"target": "ES6",
"module": "ES6",
"moduleResolution": "Node",
"skipLibCheck": true
},
"include": ["../index.ts"]
}
9 changes: 9 additions & 0 deletions ts-sdk/integration/configs/esnext.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"compilerOptions": {
"target": "ESNext",
"module": "ESNext",
"moduleResolution": "Node",
"skipLibCheck": true
},
"include": ["../index.ts"]
}
9 changes: 9 additions & 0 deletions ts-sdk/integration/configs/nodenext.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"compilerOptions": {
"target": "ESNext",
"module": "NodeNext",
"moduleResolution": "NodeNext",
"skipLibCheck": true
},
"include": ["../index.ts"]
}
29 changes: 29 additions & 0 deletions ts-sdk/integration/index.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import assert from "assert";
import { execSync } from "child_process";
import { readdirSync } from "fs";
import { describe, it } from "vitest";

const commandTemplates = [
"tsx --tsconfig {} ./index.ts",
"tsc --project {} --outDir ./dist && node ./dist/index.js",
// FIXME: ts-node does not play nice with ESM since node 20
// "ts-node --esm --project {} ./index.ts",
// TODO: should we also add browser/bundler?
]

// commonjs not included here because wasm wouldn't support it
const tsConfigs = readdirSync("./configs");

describe("Integration", () => {
commandTemplates.forEach(template => {
tsConfigs.forEach(config => {
const command = template.replace("{}", `./configs/${config}`);
it(`Use '${command}'`, () => {
const output = execSync(command).toString();
assert(output.includes("2LecshUwdy9xi7meFgHtFJQNSKk4KdTrcpvaB56dP2NQ"));
assert(output.includes("256"));
assert(output.includes("whirLbMiicVdio4qvUfM5KAg6Ct8VwpYzGff3uctyCc"));
});
});
});
});
9 changes: 9 additions & 0 deletions ts-sdk/integration/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { DEFAULT_WHIRLPOOLS_CONFIG_ADDRESS } from "@orca-so/whirlpools";
import { _POSITION_BUNDLE_SIZE } from "@orca-so/whirlpools-core";
import { WHIRLPOOL_PROGRAM_ADDRESS } from "@orca-so/whirlpools-client";

console.info(
DEFAULT_WHIRLPOOLS_CONFIG_ADDRESS,
_POSITION_BUNDLE_SIZE(),
WHIRLPOOL_PROGRAM_ADDRESS,
);
16 changes: 16 additions & 0 deletions ts-sdk/integration/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"name": "@orca-so/whirlpools-integration",
"private": true,
"type": "module",
"scripts": {
"build": "tsc --noEmit",
"test": "vitest run index.test.ts"
},
"dependencies": {
"@orca-so/whirlpools": "*"
},
"devDependencies": {
"tsx": "^4.19.0",
"typescript": "^5.6.3"
}
}
7 changes: 7 additions & 0 deletions ts-sdk/integration/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"outDir": "./dist"
},
"include": ["index.ts"]
}
Loading

0 comments on commit 3bac75a

Please sign in to comment.