Skip to content

Commit

Permalink
refactor: avoid default import of external deps
Browse files Browse the repository at this point in the history
esbuild 0.14.8 is able to generate smaller and more efficient code
in CommonJS format when default imports are avoided.
  • Loading branch information
Conaclos committed Jan 9, 2022
1 parent e4b2a1b commit 6fe63ac
Show file tree
Hide file tree
Showing 13 changed files with 15 additions and 11 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
assert.deepEqual(Array.from(bytes), [42, 24]) // Previously failed
```

* Smaller CommonJS bundle

## 0.1.0 (2022-01-02)

* `ByteCursor` abstraction to read and write safely a buffer of bytes
Expand Down
2 changes: 1 addition & 1 deletion src/codec/float-array.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import assert from "assert"
import { ok as assert } from "assert"
import type { ByteCursor } from "../core/index.js"
import { BareError } from "../core/index.js"
import { IS_LITTLE_ENDIAN_PLATFORM } from "../util/util.js"
Expand Down
2 changes: 1 addition & 1 deletion src/codec/i16-array.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import assert from "assert"
import { ok as assert } from "assert"
import type { ByteCursor } from "../core/index.js"
import { IS_LITTLE_ENDIAN_PLATFORM } from "../util/util.js"
import { decodeFixedData } from "./data.js"
Expand Down
2 changes: 1 addition & 1 deletion src/codec/i32-array.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import assert from "assert"
import { ok as assert } from "assert"
import type { ByteCursor } from "../core/index.js"
import { IS_LITTLE_ENDIAN_PLATFORM } from "../util/util.js"
import { decodeFixedData } from "./data.js"
Expand Down
2 changes: 1 addition & 1 deletion src/codec/i64-array.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import assert from "assert"
import { ok as assert } from "assert"
import type { ByteCursor } from "../core/index.js"
import { IS_LITTLE_ENDIAN_PLATFORM } from "../util/util.js"
import { decodeFixedData } from "./data.js"
Expand Down
2 changes: 1 addition & 1 deletion src/codec/primitive.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import assert from "assert"
import { ok as assert } from "assert"
import { BareError, type ByteCursor } from "../core/index.js"
import {
isI16,
Expand Down
2 changes: 1 addition & 1 deletion src/codec/u16-array.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import assert from "assert"
import { ok as assert } from "assert"
import type { ByteCursor } from "../core/index.js"
import { IS_LITTLE_ENDIAN_PLATFORM } from "../util/util.js"
import { decodeFixedData } from "./data.js"
Expand Down
2 changes: 1 addition & 1 deletion src/codec/u32-array.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import assert from "assert"
import { ok as assert } from "assert"
import type { ByteCursor } from "../core/index.js"
import { IS_LITTLE_ENDIAN_PLATFORM } from "../util/util.js"
import { decodeFixedData } from "./data.js"
Expand Down
2 changes: 1 addition & 1 deletion src/codec/u64-array.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import assert from "assert"
import { ok as assert } from "assert"
import type { ByteCursor } from "../core/index.js"
import { IS_LITTLE_ENDIAN_PLATFORM } from "../util/util.js"
import { decodeFixedData } from "./data.js"
Expand Down
2 changes: 1 addition & 1 deletion src/codec/u8-array.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import assert from "assert"
import { ok as assert } from "assert"
import type { ByteCursor } from "../core/index.js"
import { decodeUintSafe, encodeUintSafe } from "./primitive.js"

Expand Down
2 changes: 1 addition & 1 deletion src/core/byte-cursor.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import assert from "assert"
import { ok as assert } from "assert"
import { BareError } from "../core/bare-error.js"
import type { Config } from "./config.js"

Expand Down
2 changes: 1 addition & 1 deletion src/core/config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import assert from "assert"
import { ok as assert } from "assert"
import { isU32 } from "../util/validator.js"

const TOO_LARGE_NUMBER = "too large number"
Expand Down
2 changes: 2 additions & 0 deletions src/util/assert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,5 @@ export default function assert(
throw e
}
}

export const ok = assert

0 comments on commit 6fe63ac

Please sign in to comment.