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: add publish support for JSR #467

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
2 changes: 1 addition & 1 deletion .github/workflows/benchmark.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
with:
cache: yarn
node-version: 20
- run: yarn --immutable && yarn build && yarn generate
- run: yarn --immutable && yarn generate

- name: Run benchmarks
run: yarn benchmark
Expand Down
2 changes: 0 additions & 2 deletions .github/workflows/cd-manual.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ jobs:
node-version: '20'
- name: Bootstrap
run: yarn --immutable
- name: Build
run: yarn build
- name: Publish to Cloudflare Pages
uses: cloudflare/pages-action@1
with:
Expand Down
27 changes: 23 additions & 4 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ jobs:
registry-url: 'https://registry.npmjs.org'
if: ${{ steps.release.outputs.releases_created }}

- uses: denoland/setup-deno@v2
with:
deno-version: v2.x
if: ${{ steps.release.outputs.releases_created }}

- run: yarn install --immutable
if: ${{ steps.release.outputs.releases_created }}

Expand All @@ -46,7 +51,13 @@ jobs:
- run: git config user.name $(git --no-pager show -s --format='%an' HEAD)
if: ${{ steps.release.outputs.releases_created }}

- run: yarn build

- name: Build JSR
run: lerna run build:jsr
if: ${{ steps.release.outputs.releases_created }}

- name: Build NPM
run: lerna run build:npm
if: ${{ steps.release.outputs.releases_created }}

- env:
Expand All @@ -56,12 +67,20 @@ jobs:

- name: Check npm config
run: npm config list

- run: node_modules/.bin/lerna publish from-package --no-verify-access --yes

- name: Publish NPM
run: lerna run publish:npm
if: ${{ steps.release.outputs.releases_created }}
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

- name: Publish JSR
run: lerna run publish:jsr
if: ${{ steps.release.outputs.releases_created }}
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
JSR_AUTH_TOKEN: ${{ secrets.JSR_TOKEN }}


- name: Publish to Cloudflare Pages
if: ${{ steps.release.outputs.releases_created }}
uses: cloudflare/pages-action@1
Expand Down
6 changes: 0 additions & 6 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ jobs:
cache: yarn
- name: Bootstrap
run: yarn --immutable
- name: Build
run: yarn build
- name: Generate
run: yarn generate
- name: Check types
Expand Down Expand Up @@ -83,8 +81,6 @@ jobs:
bun-version: latest
- name: Install
run: yarn install --frozen-lockfile
- name: Build
run: yarn build
- name: Generate
run: bun run --filter '*' generate
- name: Unit Tests
Expand All @@ -103,8 +99,6 @@ jobs:
deno-version: v2.x
- name: Install
run: yarn install --frozen-lockfile
- name: Build
run: yarn build
# Deno does not run task in workspaces if same task exists on root package.json
- name: Clean root scripts
run: cat package.json | jq 'del( .scripts )' > package.json.backup && mv package.json.backup package.json
Expand Down
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,6 @@ node_modules
!.yarn/versions

# Deno
deno.lock
deno.lock
# Dnt generate npm package
packages/*/npm/
17 changes: 16 additions & 1 deletion deno.jsonc
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
{
"nodeModulesDir": "auto"
"$schema": "https://raw.githubusercontent.com/denoland/deno/refs/heads/main/cli/schemas/config-file.v1.json",
"nodeModulesDir": "auto",
"workspace": [
"./packages/as-sha256",
"./packages/persistent-merkle-tree",
"./packages/persistent-ts",
"./packages/simpleserialize.com",
"./packages/ssz"
],
"compilerOptions": {
"noImplicitOverride": false,
"types": ["node"]
},
"imports": {
"@deno/dnt": "jsr:@deno/dnt@^0.41.3"
}
}
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
"scripts": {
"clean": "lerna run clean",
"generate": "lerna run generate",
"build": "yarn clean && lerna run build",
"lint": "lerna run lint",
"check-types": "lerna run check-types",
"test:browsers": "lerna run test:browsers",
Expand Down
21 changes: 14 additions & 7 deletions packages/as-sha256/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,16 @@
"url": "git+https://github.com/chainsafe/ssz.git"
},
"type": "module",
"main": "./lib/index.js",
"types": "./lib/index.d.ts",
"files": [
"lib",
"build"
],
"exports": {
".": {
"import": "./src/index.ts"
}
},
"engines": {
"node": ">= 18",
"deno": ">= 2.2",
"bun": ">= 1.1"
},
"scripts": {
"clean": "rm -rf ./dist",
"lint": "echo 'no linting for this package'",
Expand All @@ -32,7 +36,10 @@
"asbuild:simd": "yarn asbuild:simd:untouched && yarn asbuild:simd:optimized",
"build:lib": "tsc -p tsconfig.build.json",
"build:web": "webpack --mode production --entry ./index.js --output ./dist/as-sha256.min.js",
"build": "yarn asbuild && yarn asbuild:simd && yarn generate && yarn build:lib",
"build:jsr": "yarn asbuild && yarn asbuild:simd && yarn generate && deno run -A ../../scripts/buildJsr.ts",
"build:npm": "yarn asbuild && yarn asbuild:simd && yarn generate && deno run -A ../../scripts/buildNpm.ts",
"publish:jsr": "deno publish",
"publish:npm": "cd npm && npm publish",
"test:unit": "vitest run --dir test/unit/",
"test:browsers": "vitest run --config ./vitest.browser.config.ts --dir test/unit",
"benchmark": "node -r ts-node/register ./node_modules/.bin/benchmark 'test/perf/*.test.ts'",
Expand Down
3 changes: 3 additions & 0 deletions packages/as-sha256/src/alloc.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import process from "node:process";
import {Buffer} from "node:buffer";

const isNode = typeof process !== "undefined" && process.versions != null && process.versions.node != null;

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

let ctx: WasmContext;
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.js";
import {newInstance, WasmContext} from "./wasm.ts";

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

export interface WasmContext {
readonly HAS_SIMD: boolean;
Expand Down
2 changes: 1 addition & 1 deletion packages/as-sha256/test/unit/getSimdTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
import {describe, beforeAll, expect, it} from "vitest";
import crypto from "crypto";
import {byteArrayToHashObject, hashObjectToByteArray} from "../../src/hashObject.js";
import {byteArrayToHashObject, hashObjectToByteArray} from "../../src/hashObject.ts";

// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
export function getSimdTests(sha256: any, useSimd: boolean): void {
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
Expand Up @@ -8,7 +8,7 @@ import {
digest64,
digest64HashObjects,
hashObjectToByteArray,
} from "../../src/index.js";
} from "../../src/index.ts";

describe("hashObjectToByteArray and byteArrayToHashObject", function () {
const tcs = [
Expand Down
4 changes: 2 additions & 2 deletions packages/as-sha256/test/unit/noSimd.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as sha256 from "../../src/index.js";
import {getSimdTests} from "./getSimdTests.js";
import * as sha256 from "../../src/index.ts";
import {getSimdTests} from "./getSimdTests.ts";

const useSimd = false;
getSimdTests(sha256, useSimd);
4 changes: 2 additions & 2 deletions packages/as-sha256/test/unit/simd.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as sha256 from "../../src/index.js";
import {getSimdTests} from "./getSimdTests.js";
import * as sha256 from "../../src/index.ts";
import {getSimdTests} from "./getSimdTests.ts";

const useSimd = true;
getSimdTests(sha256, useSimd);
8 changes: 0 additions & 8 deletions packages/as-sha256/tsconfig.build.json

This file was deleted.

42 changes: 13 additions & 29 deletions packages/persistent-merkle-tree/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,45 +4,29 @@
"description": "Merkle tree implemented as a persistent datastructure",
"type": "module",
"exports": {
".": {
"import": "./lib/index.js",
"types": "./lib/index.d.ts"
},
"./hasher/hashtree": {
"import": "./lib/hasher/hashtree.js",
"types": "./lib/hasher/hashtree.d.ts"
},
"./hasher/noble": {
"import": "./lib/hasher/noble.js",
"types": "./lib/hasher/noble.d.ts"
},
"./hasher/as-sha256": {
"import": "./lib/hasher/as-sha256.js",
"types": "./lib/hasher/as-sha256.d.ts"
}
".": "./src/index.ts",
"./hasher/hashtree": "./src/hasher/hashtree.ts",
"./hasher/noble": "./src/hasher/noble.ts",
"./hasher/as-sha256": "./src/hasher/as-sha256.ts"
},
"typesVersions": {
"*": {
"*": [
"*",
"lib/*",
"lib/*/index"
]
}
"engines": {
"node": ">= 18",
"deno": ">= 2.2",
"bun": ">= 1.1"
},
"files": [
"lib"
],
"scripts": {
"check-types": "tsc --noEmit",
"clean": "rm -rf lib",
"build": "tsc -p tsconfig.build.json",
"lint": "eslint --color --ext .ts src/",
"lint:fix": "yarn run lint --fix",
"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:unit": "vitest run --dir test/unit"
"test:unit": "vitest run --dir test/unit",
"build:jsr": "deno run -A ../../scripts/buildJsr.ts",
"build:npm": "deno run -A ../../scripts/buildNpm.ts",
"publish:jsr": "deno publish",
"publish:npm": "cd npm && npm publish"
},
"pre-push": [
"lint"
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.js";
import type {Node} from "./node.ts";

/**
* 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.js";
import {Node} from "../node.js";
import type {HashComputationLevel} from "../hashComputation.js";
import {BLOCK_SIZE, doDigestNLevel, doMerkleizeBlockArray, doMerkleizeBlocksBytes} from "./util.js";
import type {Hasher} from "./types.ts";
import {Node} from "../node.ts";
import type {HashComputationLevel} from "../hashComputation.ts";
import {BLOCK_SIZE, doDigestNLevel, doMerkleizeBlockArray, doMerkleizeBlocksBytes} from "./util.ts";

/**
* hashInto() function of as-sha256 loop through every 256 bytes
Expand Down
8 changes: 4 additions & 4 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.js";
import {Node} from "../node.js";
import type {HashComputationLevel} from "../hashComputation.js";
import {Hasher, HashObject} from "./types.ts";
import {Node} from "../node.ts";
import type {HashComputationLevel} from "../hashComputation.ts";
import {byteArrayIntoHashObject} from "@chainsafe/as-sha256";
import {doDigestNLevel, doMerkleizeBlockArray, doMerkleizeBlocksBytes} from "./util.js";
import {doDigestNLevel, doMerkleizeBlockArray, doMerkleizeBlocksBytes} from "./util.ts";

/**
* 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.js";
import {hasher as nobleHasher} from "./noble.js";
import type {HashComputationLevel} from "../hashComputation.js";
import {Hasher} from "./types.ts";
import {hasher as nobleHasher} from "./noble.ts";
import type {HashComputationLevel} from "../hashComputation.ts";

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

/**
* 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.js";
import type {Hasher} from "./types.ts";
import {
BLOCK_SIZE,
doDigestNLevel,
doMerkleizeBlockArray,
doMerkleizeBlocksBytes,
hashObjectToUint8Array,
} from "./util.js";
} from "./util.ts";

const digest64 = (a: Uint8Array, b: Uint8Array): Uint8Array => sha256.create().update(a).update(b).digest();
const hashInto = (input: Uint8Array, output: Uint8Array): void => {
Expand Down
2 changes: 1 addition & 1 deletion 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";
import type {HashComputationLevel} from "../hashComputation.js";
import type {HashComputationLevel} from "../hashComputation.ts";

export type {HashObject};

Expand Down
2 changes: 1 addition & 1 deletion 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";
import {zeroHash} from "../zeroHash.js";
import {zeroHash} from "../zeroHash.ts";

export function hashObjectToUint8Array(obj: HashObject): Uint8Array {
const byteArr = new Uint8Array(32);
Expand Down
Loading