Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: make all packages build to be consistent and compatible with cjs and esm #426

Merged
merged 31 commits into from
Dec 20, 2024
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
798d556
Update ts config for all packages
nazarhussain Dec 18, 2024
8655319
Update package.json files
nazarhussain Dec 18, 2024
18961f3
Add file prefixes to all imports
nazarhussain Dec 18, 2024
b5ad3ef
Update the ts-node config to use esm
nazarhussain Dec 18, 2024
ce0017e
Upgrade typescript
nazarhussain Dec 19, 2024
3b0d5ef
Upgrade typescript settings
nazarhussain Dec 19, 2024
b47f353
Fix the TS warnings and issues
nazarhussain Dec 19, 2024
ef491d2
Fix import paths for types
nazarhussain Dec 19, 2024
86e45a0
Update import path
nazarhussain Dec 19, 2024
507c767
Update the import paths in tests
nazarhussain Dec 19, 2024
f1d3aa6
Fix lint errors
nazarhussain Dec 19, 2024
92e1d22
Fix lint formatting on config files
nazarhussain Dec 19, 2024
25e8e5f
Update the benchmark to use ts loader
nazarhussain Dec 19, 2024
1655e70
Disable the browser tests
nazarhussain Dec 19, 2024
d2d1232
Fix the loader for the esm
nazarhussain Dec 19, 2024
fae5a65
fix: convert prettierrc to yaml
matthewkeil Dec 20, 2024
8b965a4
fix: __dirname to ESM
matthewkeil Dec 20, 2024
1016197
fix: revert TS version to fix download-spec-tests ts-node issue
matthewkeil Dec 20, 2024
443a878
feat: use spec-test-util for ESM and wget compatibility
matthewkeil Dec 20, 2024
e1b868a
fix: remove ts-expect-error after downgrading TS version
matthewkeil Dec 20, 2024
dd221fc
fix: update SPEC_TEST_LOCATION
matthewkeil Dec 20, 2024
c3b0b87
chore: update eslint deps to remove lint error
matthewkeil Dec 20, 2024
dea9709
chore: lint code per updated lint rules from package update
matthewkeil Dec 20, 2024
b5bc7e0
fix: convert to node 20 compatible dirname
matthewkeil Dec 20, 2024
6f79cbe
fix: convert to node 20 compatible dirname
matthewkeil Dec 20, 2024
68e3d1d
Cleanup benchmark loader for ts
nazarhussain Dec 20, 2024
fd9adcc
Update the hasher for benchmark
nazarhussain Dec 20, 2024
5668123
Revert "Update the hasher for benchmark"
nazarhussain Dec 20, 2024
55d287f
Update the hasher for benchmark
nazarhussain Dec 20, 2024
9a587b5
Update package output dirs
nazarhussain Dec 20, 2024
09bba35
Update hasher path
nazarhussain Dec 20, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ packages/ssz/spec-tests

benchmark_data/
.failedTest.txt
*.tsbuildinfo

node_modules
.yarn/*
Expand Down
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"@dapplion/benchmark": "^0.2.2",
"@types/chai": "^4.2.15",
"@types/mocha": "^8.2.2",
"@types/node": "^14.14.17",
"@types/node": "^22.10.2",
"@typescript-eslint/eslint-plugin": "^4.19.0",
"@typescript-eslint/parser": "^4.19.0",
"babel-loader": "^8.2.2",
Expand All @@ -49,9 +49,9 @@
"mocha": "^8.3.2",
"nyc": "^15.0.0",
"prettier": "^2.2.1",
"ts-loader": "^9.2.8",
"ts-node": "^9.1.1",
"typescript": "~4.2.3",
"ts-loader": "^9.5.1",
"ts-node": "^10.9.2",
"typescript": "~5.7.2",
"webpack": "^5.75.0",
"webpack-cli": "^5.0.1",
"webpack-dev-server": "^3.11.2"
Expand Down
25 changes: 10 additions & 15 deletions packages/as-sha256/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,10 @@
"type": "git",
"url": "git+https://github.com/chainsafe/ssz.git"
},
"main": "lib/index.js",
"typesVersions": {
"*": {
"*": [
"*",
"lib/*",
"lib/*/index"
]
}
},
"types": "lib/index.d.ts",
"type": "module",
"main": "./lib/cjs/index.js",
"module": "./lib/esm/index.js",
"types": "./lib/types/index.d.ts",
"files": [
"lib",
"build"
Expand All @@ -31,17 +24,19 @@
"clean": "rm -rf ./dist",
"lint": "echo 'no linting for this package'",
"check-types": "echo 'no type check for this package'",
"generate": "rm -rf ./dist && node -r ts-node/register ./scripts/codegen.ts",
"build": "yarn asbuild:untouched && yarn asbuild:optimized && yarn build:lib",
"generate": "rm -rf ./dist && node --loader ts-node/esm ./scripts/codegen.ts",
"build": "yarn asbuild:untouched && yarn asbuild:optimized && yarn build:cjs && yarn build:esm && yarn build:types",
"asbuild:untouched": "asc assembly/index.ts -o build/untouched.wasm -t build/untouched.wat --runtime minimal --target debug --enable simd",
"asbuild:optimized": "asc assembly/index.ts -o build/optimized.wasm -t build/optimized.wat --runtime minimal --target release -O3z --noAssert --enable simd",
"build:lib": "tsc -p tsconfig.build.json",
"build:esm": "tsc -p tsconfig.build.esm.json && echo '{\"type\": \"module\"}' > ./lib/esm/package.json",
"build:cjs": "tsc -p tsconfig.build.cjs.json && echo '{\"type\": \"commonjs\"}' > ./lib/cjs/package.json",
"build:types": "tsc -p tsconfig.build.types.json",
"build:web": "webpack --mode production --entry ./index.js --output ./dist/as-sha256.min.js",
"test": "yarn run test:unit",
"test:unit": "yarn run test:unit:node && yarn run test:unit:browser",
"test:unit:node": "mocha -r ts-node/register test/unit/*.test.ts",
"test:unit:browser": "karma start --single-run --browsers ChromeHeadless,FirefoxHeadless karma.config.js",
"benchmark": "node -r ts-node/register ./node_modules/.bin/benchmark 'test/perf/*.test.ts'",
"benchmark": "node --loader ts-node/esm ./node_modules/.bin/benchmark 'test/perf/*.test.ts'",
"benchmark:local": "yarn benchmark --local",
"test:ci": "yarn test:as-ci"
},
Expand Down
29 changes: 0 additions & 29 deletions packages/as-sha256/src/index.d.ts

This file was deleted.

8 changes: 4 additions & 4 deletions packages/as-sha256/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {allocUnsafe} from "./alloc";
import {newInstance} from "./wasm";
import {HashObject, byteArrayIntoHashObject, byteArrayToHashObject, hashObjectToByteArray} from "./hashObject";
import SHA256 from "./sha256";
import {allocUnsafe} from "./alloc.js";
import {newInstance} from "./wasm.js";
import {HashObject, byteArrayIntoHashObject, byteArrayToHashObject, hashObjectToByteArray} from "./hashObject.js";
import SHA256 from "./sha256.js";
export {HashObject, byteArrayToHashObject, hashObjectToByteArray, byteArrayIntoHashObject, SHA256};

const ctx = newInstance();
Expand Down
2 changes: 1 addition & 1 deletion packages/as-sha256/src/sha256.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {newInstance, WasmContext} from "./wasm";
import {newInstance, WasmContext} from "./wasm.js";

/**
* Class based SHA256
Expand Down
2 changes: 1 addition & 1 deletion packages/as-sha256/src/wasm.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {wasmCode} from "./wasmCode";
import {wasmCode} from "./wasmCode.js";

const _module = new WebAssembly.Module(wasmCode);

Expand Down
2 changes: 1 addition & 1 deletion packages/as-sha256/test/perf/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {itBench, setBenchOpts} from "@dapplion/benchmark";
import * as sha256 from "../../src";
import * as sha256 from "../../src/index.js";

// Feb 2024 Mac M1
// digestTwoHashObjects vs digest64 vs digest
Expand Down
2 changes: 1 addition & 1 deletion packages/as-sha256/test/perf/simd.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {itBench, setBenchOpts} from "@dapplion/benchmark";
import * as sha256 from "../../src";
import * as sha256 from "../../src/index.js";
import {byteArrayToHashObject} from "../../src/hashObject";

/**
Expand Down
2 changes: 1 addition & 1 deletion packages/as-sha256/test/unit/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {Buffer} from "buffer";
import * as sha256 from "../../src";
import * as sha256 from "../../src/index.js";
import {expect} from "chai";

describe("sha256", function () {
Expand Down
2 changes: 1 addition & 1 deletion packages/as-sha256/test/unit/simd.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {expect} from "chai";
import crypto from "crypto";
import {byteArrayToHashObject, hashObjectToByteArray} from "../../src/hashObject";
import * as sha256 from "../../src";
import * as sha256 from "../../src/index.js";

describe("Test SIMD implementation of as-sha256", () => {
it("testHash4UintArray64s", () => {
Expand Down
8 changes: 8 additions & 0 deletions packages/as-sha256/tsconfig.build.cjs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"extends": "../../tsconfig.build.cjs.json",
"include": ["src"],
"compilerOptions": {
"outDir": "lib/cjs",
"typeRoots": ["../../node_modules/@types", "./node_modules/@types", "./types"],
}
}
8 changes: 8 additions & 0 deletions packages/as-sha256/tsconfig.build.esm.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"extends": "../../tsconfig.build.esm.json",
"include": ["src"],
"compilerOptions": {
"outDir": "lib/esm",
"typeRoots": ["../../node_modules/@types", "./node_modules/@types", "./types"],
}
}
28 changes: 0 additions & 28 deletions packages/as-sha256/tsconfig.build.json

This file was deleted.

8 changes: 8 additions & 0 deletions packages/as-sha256/tsconfig.build.types.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"extends": "../../tsconfig.build.types.json",
"include": ["src"],
"compilerOptions": {
"outDir": "lib/types",
"typeRoots": ["../../node_modules/@types", "./node_modules/@types", "./types"],
}
}
4 changes: 2 additions & 2 deletions packages/as-sha256/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"extends": "../../tsconfig.json",
"include": ["src", "test"],
"extends": "./tsconfig.build.json",
"compilerOptions": {
"incremental": true
"typeRoots": ["../../node_modules/@types", "./node_modules/@types", "./types"],
}
}
21 changes: 9 additions & 12 deletions packages/persistent-merkle-tree/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,23 @@
"name": "@chainsafe/persistent-merkle-tree",
"version": "0.8.0",
"description": "Merkle tree implemented as a persistent datastructure",
"main": "lib/index.js",
"typesVersions": {
"*": {
"*": [
"*",
"lib/*",
"lib/*/index"
]
}
},
"type": "module",
"module": "./lib/esm/index.js",
"main": "./lib/cjs/index.js",
"types": "./lib/types/index.d.ts",
"files": [
"lib"
],
"scripts": {
"check-types": "tsc --noEmit",
"clean": "rm -rf lib",
"build": "tsc",
"build": "yarn build:cjs && yarn build:esm && yarn build:types",
"build:esm": "tsc -p tsconfig.build.esm.json && echo '{\"type\": \"module\"}' > ./lib/esm/package.json",
"build:cjs": "tsc -p tsconfig.build.cjs.json && echo '{\"type\": \"commonjs\"}' > ./lib/cjs/package.json",
"build:types": "tsc -p tsconfig.build.types.json",
"lint": "eslint --color --ext .ts src/",
"lint:fix": "yarn run lint --fix",
"benchmark:files": "node --max-old-space-size=4096 --expose-gc -r ts-node/register ../../node_modules/.bin/benchmark",
"benchmark:files": "node --max-old-space-size=4096 --expose-gc --loader ts-node/esm ../../node_modules/.bin/benchmark",
"benchmark": "yarn benchmark:files 'test/perf/*.test.ts'",
"benchmark:local": "yarn benchmark --local",
"test": "mocha -r ts-node/register 'test/unit/**/*.test.ts'"
Expand Down
2 changes: 1 addition & 1 deletion packages/persistent-merkle-tree/src/hashComputation.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type {Node} from "./node";
import type {Node} from "./node.js";

/**
* HashComputation to be later used to compute hash of nodes from bottom up.
Expand Down
8 changes: 4 additions & 4 deletions packages/persistent-merkle-tree/src/hasher/as-sha256.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ import {
batchHash4HashObjectInputs,
hashInto,
} from "@chainsafe/as-sha256";
import type {Hasher} from "./types";
import {Node} from "../node";
import type {HashComputationLevel} from "../hashComputation";
import {BLOCK_SIZE, doDigestNLevel, doMerkleizeBlockArray, doMerkleizeBlocksBytes} from "./util";
import type {Hasher} from "./types.js";
import {Node} from "../node.js";
import type {HashComputationLevel} from "../hashComputation.js";
import {BLOCK_SIZE, doDigestNLevel, doMerkleizeBlockArray, doMerkleizeBlocksBytes} from "./util.js";

/**
* hashInto() function of as-sha256 loop through every 256 bytes
Expand Down
10 changes: 5 additions & 5 deletions packages/persistent-merkle-tree/src/hasher/hashtree.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import {hashInto} from "@chainsafe/hashtree";
import {Hasher, HashObject} from "./types";
import {Node} from "../node";
import type {HashComputationLevel} from "../hashComputation";
import {byteArrayIntoHashObject} from "@chainsafe/as-sha256/lib/hashObject";
import {doDigestNLevel, doMerkleizeBlockArray, doMerkleizeBlocksBytes} from "./util";
import {Hasher, HashObject} from "./types.js";
import {Node} from "../node.js";
import type {HashComputationLevel} from "../hashComputation.js";
import {byteArrayIntoHashObject} from "@chainsafe/as-sha256";
import {doDigestNLevel, doMerkleizeBlockArray, doMerkleizeBlocksBytes} from "./util.js";

/**
* Best SIMD implementation is in 512 bits = 64 bytes
Expand Down
10 changes: 5 additions & 5 deletions packages/persistent-merkle-tree/src/hasher/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import {Hasher} from "./types";
import {hasher as nobleHasher} from "./noble";
import type {HashComputationLevel} from "../hashComputation";
import {Hasher} from "./types.js";
import {hasher as nobleHasher} from "./noble.js";
import type {HashComputationLevel} from "../hashComputation.js";

export * from "./types";
export * from "./util";
export * from "./types.js";
export * from "./util.js";

/**
* Hasher used across the SSZ codebase, by default, this does not support batch hash.
Expand Down
4 changes: 2 additions & 2 deletions packages/persistent-merkle-tree/src/hasher/noble.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import {sha256} from "@noble/hashes/sha256";
import {digest64HashObjects, byteArrayIntoHashObject} from "@chainsafe/as-sha256";
import type {Hasher} from "./types";
import type {Hasher} from "./types.js";
import {
BLOCK_SIZE,
doDigestNLevel,
doMerkleizeBlockArray,
doMerkleizeBlocksBytes,
hashObjectToUint8Array,
} from "./util";
} from "./util.js";

const digest64 = (a: Uint8Array, b: Uint8Array): Uint8Array => sha256.create().update(a).update(b).digest();
const hashInto = (input: Uint8Array, output: Uint8Array): void => {
Expand Down
4 changes: 2 additions & 2 deletions packages/persistent-merkle-tree/src/hasher/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type {HashObject} from "@chainsafe/as-sha256/lib/hashObject";
import type {HashComputationLevel} from "../hashComputation";
import type {HashObject} from "@chainsafe/as-sha256";
import type {HashComputationLevel} from "../hashComputation.js";

export type {HashObject};

Expand Down
4 changes: 2 additions & 2 deletions packages/persistent-merkle-tree/src/hasher/util.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {byteArrayToHashObject, HashObject, hashObjectToByteArray} from "@chainsafe/as-sha256/lib/hashObject";
import {zeroHash} from "../zeroHash";
import {byteArrayToHashObject, HashObject, hashObjectToByteArray} from "@chainsafe/as-sha256";
import {zeroHash} from "../zeroHash.js";

export function hashObjectToUint8Array(obj: HashObject): Uint8Array {
const byteArr = new Uint8Array(32);
Expand Down
22 changes: 11 additions & 11 deletions packages/persistent-merkle-tree/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
export * from "./gindex";
export * from "./hasher";
export * from "./node";
export * from "./hashComputation";
export * from "./packedNode";
export * from "./proof";
export * from "./subtree";
export * from "./tree";
export * from "./zeroNode";
export * from "./zeroHash";
export * from "./snapshot";
export * from "./gindex.js";
export * from "./hasher/index.js";
export * from "./node.js";
export * from "./hashComputation.js";
export * from "./packedNode.js";
export * from "./proof/index.js";
export * from "./subtree.js";
export * from "./tree.js";
export * from "./zeroNode.js";
export * from "./zeroHash.js";
export * from "./snapshot.js";
Loading
Loading