Skip to content

Commit

Permalink
ts: Remove usage of assert (#2535)
Browse files Browse the repository at this point in the history
  • Loading branch information
acheroncrypto authored Jun 17, 2023
1 parent 78d4855 commit 9d947cb
Show file tree
Hide file tree
Showing 16 changed files with 15 additions and 20 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ The minor version will be incremented upon a breaking change and the patch versi

### Fixes

- ts: Packages no longer depend on `assert` ([#2535](https://github.com/coral-xyz/anchor/pull/2535)).

### Breaking

## [0.28.0] - 2023-06-09
Expand Down
2 changes: 0 additions & 2 deletions ts/packages/anchor/rollup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import nodeResolve from "@rollup/plugin-node-resolve";
import typescript from "@rollup/plugin-typescript";
import replace from "@rollup/plugin-replace";
import commonjs from "@rollup/plugin-commonjs";
import { terser } from "rollup-plugin-terser";

const env = process.env.NODE_ENV;

Expand Down Expand Up @@ -34,7 +33,6 @@ export default {
external: [
"@coral-xyz/borsh",
"@solana/web3.js",
"assert",
"base64-js",
"bn.js",
"bs58",
Expand Down
18 changes: 13 additions & 5 deletions ts/packages/anchor/src/program/event.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { PublicKey } from "@solana/web3.js";
import * as assert from "assert";
import { IdlEvent, IdlEventField } from "../idl.js";
import { Coder } from "../coder/index.js";
import { DecodeType } from "./namespace/types.js";
Expand Down Expand Up @@ -144,8 +143,13 @@ export class EventManager {
}

// Kill the websocket connection if all listeners have been removed.
if (this._eventCallbacks.size == 0) {
assert.ok(this._eventListeners.size === 0);
if (this._eventCallbacks.size === 0) {
if (this._eventListeners.size !== 0) {
throw new Error(
`Expected event listeners size to be 0 but got ${this._eventListeners.size}`
);
}

if (this._onLogsSubscriptionId !== undefined) {
await this._provider!.connection.removeOnLogsListener(
this._onLogsSubscriptionId
Expand Down Expand Up @@ -273,7 +277,9 @@ class ExecutionContext {
stack: string[] = [];

program(): string {
assert.ok(this.stack.length > 0);
if (!this.stack.length) {
throw new Error("Expected the stack to have elements");
}
return this.stack[this.stack.length - 1];
}

Expand All @@ -282,7 +288,9 @@ class ExecutionContext {
}

pop() {
assert.ok(this.stack.length > 0);
if (!this.stack.length) {
throw new Error("Expected the stack to have elements");
}
this.stack.pop();
}
}
Expand Down
1 change: 0 additions & 1 deletion ts/packages/spl-associated-token-account/rollup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ export default {
external: [
"@coral-xyz/borsh",
"@solana/web3.js",
"assert",
"base64-js",
"bn.js",
"bs58",
Expand Down
1 change: 0 additions & 1 deletion ts/packages/spl-binary-option/rollup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ export default {
external: [
"@coral-xyz/borsh",
"@solana/web3.js",
"assert",
"base64-js",
"bn.js",
"bs58",
Expand Down
1 change: 0 additions & 1 deletion ts/packages/spl-binary-oracle-pair/rollup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ export default {
external: [
"@coral-xyz/borsh",
"@solana/web3.js",
"assert",
"base64-js",
"bn.js",
"bs58",
Expand Down
1 change: 0 additions & 1 deletion ts/packages/spl-feature-proposal/rollup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ export default {
external: [
"@coral-xyz/borsh",
"@solana/web3.js",
"assert",
"base64-js",
"bn.js",
"bs58",
Expand Down
1 change: 0 additions & 1 deletion ts/packages/spl-governance/rollup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ export default {
external: [
"@coral-xyz/borsh",
"@solana/web3.js",
"assert",
"base64-js",
"bn.js",
"bs58",
Expand Down
1 change: 0 additions & 1 deletion ts/packages/spl-memo/rollup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ export default {
external: [
"@coral-xyz/borsh",
"@solana/web3.js",
"assert",
"base64-js",
"bn.js",
"bs58",
Expand Down
1 change: 0 additions & 1 deletion ts/packages/spl-name-service/rollup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ export default {
external: [
"@coral-xyz/borsh",
"@solana/web3.js",
"assert",
"base64-js",
"bn.js",
"bs58",
Expand Down
1 change: 0 additions & 1 deletion ts/packages/spl-record/rollup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ export default {
external: [
"@coral-xyz/borsh",
"@solana/web3.js",
"assert",
"base64-js",
"bn.js",
"bs58",
Expand Down
1 change: 0 additions & 1 deletion ts/packages/spl-stake-pool/rollup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ export default {
external: [
"@coral-xyz/borsh",
"@solana/web3.js",
"assert",
"base64-js",
"bn.js",
"bs58",
Expand Down
1 change: 0 additions & 1 deletion ts/packages/spl-stateless-asks/rollup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ export default {
external: [
"@coral-xyz/borsh",
"@solana/web3.js",
"assert",
"base64-js",
"bn.js",
"bs58",
Expand Down
1 change: 0 additions & 1 deletion ts/packages/spl-token-lending/rollup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ export default {
external: [
"@coral-xyz/borsh",
"@solana/web3.js",
"assert",
"base64-js",
"bn.js",
"bs58",
Expand Down
1 change: 0 additions & 1 deletion ts/packages/spl-token-swap/rollup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ export default {
external: [
"@coral-xyz/borsh",
"@solana/web3.js",
"assert",
"base64-js",
"bn.js",
"bs58",
Expand Down
1 change: 0 additions & 1 deletion ts/packages/spl-token/rollup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ export default {
external: [
"@coral-xyz/borsh",
"@solana/web3.js",
"assert",
"base64-js",
"bn.js",
"bs58",
Expand Down

1 comment on commit 9d947cb

@vercel
Copy link

@vercel vercel bot commented on 9d947cb Jun 17, 2023

Choose a reason for hiding this comment

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

Successfully deployed to the following URLs:

anchor-docs – ./

anchor-docs-git-master-200ms.vercel.app
anchor-docs-200ms.vercel.app
anchor-lang.com
www.anchor-lang.com

Please sign in to comment.