Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
7 changes: 6 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@ module.exports = {
},
parser: "@typescript-eslint/parser",
parserOptions: {
ecmaVersion: 10,
ecmaVersion: "latest",
project: "./tsconfig.json",
// Support ESM modules
sourceType: "module",
},
plugins: ["@typescript-eslint", "eslint-plugin-import", "eslint-plugin-node", "no-only-tests", "prettier"],
extends: [
Expand Down Expand Up @@ -124,6 +126,9 @@ module.exports = {

// Prevents accidentally pushing a commit with .only in Mocha tests
"no-only-tests/no-only-tests": "error",

// TEMP Disabled while eslint-plugin-import support ESM (Typescript does support it) https://github.com/import-js/eslint-plugin-import/issues/2170
"import/no-unresolved": "off",
},
overrides: [
{
Expand Down
5 changes: 5 additions & 0 deletions packages/utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
"url": "https://github.com/ChainSafe/lodestar/issues"
},
"version": "0.29.3",
"type": "module",
"exports": "./lib/index.js",
"main": "lib/index.js",
"files": [
"lib/**/*.d.ts",
Expand All @@ -20,6 +22,9 @@
"*.d.ts",
"*.js"
],
"engines": {
"node": "^12.20.0 || ^14.13.1 || >=16.0.0"
},
"scripts": {
"clean": "rm -rf lib && rm -f *.tsbuildinfo",
"build": "tsc -p tsconfig.build.json",
Expand Down
30 changes: 15 additions & 15 deletions packages/utils/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
export * from "./logger";
export * from "./yaml";
export * from "./assert";
export * from "./bytes";
export * from "./errors";
export * from "./format";
export * from "./math";
export * from "./objects";
export * from "./notNullish";
export * from "./sleep";
export * from "./sort";
export * from "./timeout";
export * from "./types";
export * from "./verifyMerkleBranch";
export * from "./json";
export * from "./logger/index.js";
export * from "./yaml/index.js";
export * from "./assert.js";
export * from "./bytes.js";
export * from "./errors.js";
export * from "./format.js";
export * from "./math.js";
export * from "./objects.js";
export * from "./notNullish.js";
export * from "./sleep.js";
export * from "./sort.js";
export * from "./timeout.js";
export * from "./types.js";
export * from "./verifyMerkleBranch.js";
export * from "./json.js";
4 changes: 2 additions & 2 deletions packages/utils/src/json.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {Json, toHexString} from "@chainsafe/ssz";
import {LodestarError} from "./errors";
import {mapValues} from "./objects";
import {LodestarError} from "./errors.js";
import {mapValues} from "./objects.js";

export const CIRCULAR_REFERENCE_TAG = "CIRCULAR_REFERENCE";

Expand Down
2 changes: 1 addition & 1 deletion packages/utils/src/logger/format.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {Json} from "@chainsafe/ssz";
import {format} from "winston";
import {toJson, toString} from "../json";
import {toJson, toString} from "../json.js";
import {Context, ILoggerOptions, TimestampFormatCode} from "./interface";
import {formatEpochSlotTime} from "./util";

Expand Down
6 changes: 3 additions & 3 deletions packages/utils/src/logger/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
*/

export * from "./interface";
export * from "./format";
export * from "./transport";
export * from "./winston";
export * from "./format.js";
export * from "./transport.js";
export * from "./winston.js";
4 changes: 2 additions & 2 deletions packages/utils/src/logger/winston.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
import {createLogger, Logger} from "winston";
import {Context, defaultLogLevel, ILogger, ILoggerOptions, LogLevel, logLevelNum} from "./interface";
import chalk from "chalk";
import {getFormat} from "./format";
import {getFormat} from "./format.js";
import {Writable} from "stream";
import {TransportOpts, TransportType, fromTransportOpts} from "./transport";
import {TransportOpts, TransportType, fromTransportOpts} from "./transport.js";

const defaultTransportOpts: TransportOpts = {type: TransportType.console};

Expand Down
2 changes: 1 addition & 1 deletion packages/utils/src/sleep.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {AbortSignal} from "@chainsafe/abort-controller";
import {ErrorAborted} from "./errors";
import {ErrorAborted} from "./errors.js";

/**
* Abortable sleep function. Cleans everything on all cases preventing leaks
Expand Down
4 changes: 2 additions & 2 deletions packages/utils/src/timeout.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {AbortSignal, AbortController} from "@chainsafe/abort-controller";
import {anySignal} from "any-signal";
import {TimeoutError} from "./errors";
import {sleep} from "./sleep";
import {TimeoutError} from "./errors.js";
import {sleep} from "./sleep.js";

export async function withTimeout<T>(
asyncFn: (timeoutAndParentSignal?: AbortSignal) => Promise<T>,
Expand Down
3 changes: 1 addition & 2 deletions packages/utils/src/verifyMerkleBranch.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import {intDiv} from "./math";
import {hash} from "@chainsafe/ssz";

/**
Expand All @@ -14,7 +13,7 @@ export function verifyMerkleBranch(
): boolean {
let value = leaf;
for (let i = 0; i < depth; i++) {
if (intDiv(index, 2 ** i) % 2) {
if (Math.floor(index / 2 ** i) % 2) {
value = hash(Buffer.concat([proof[i], value]));
} else {
value = hash(Buffer.concat([value, proof[i]]));
Expand Down
4 changes: 2 additions & 2 deletions packages/utils/src/yaml/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {load, dump} from "js-yaml";
import {schema} from "./schema";
import {objectToExpectedCase} from "../objects";
import {schema} from "./schema.js";
import {objectToExpectedCase} from "../objects.js";

export function loadYaml(yaml: string): Record<string, unknown> {
return objectToExpectedCase<Record<string, unknown>>(load(yaml, {schema}));
Expand Down
2 changes: 1 addition & 1 deletion packages/utils/src/yaml/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import boolType from "js-yaml/lib/js-yaml/type/bool";
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
import floatType from "js-yaml/lib/js-yaml/type/float";
import {intType} from "./int";
import {intType} from "./int.js";

export const schema = new Schema({
include: [failsafe],
Expand Down
6 changes: 5 additions & 1 deletion packages/utils/tsconfig.build.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
"extends": "../../tsconfig.build.json",
"include": ["src"],
"compilerOptions": {
"outDir": "./lib"
"outDir": "./lib",
"target": "es2020",
"module": "esnext",
"moduleResolution": "Node",
"allowSyntheticDefaultImports": true
}
}
7 changes: 6 additions & 1 deletion packages/utils/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {}
"compilerOptions": {
"target": "es2020",
"module": "ES2020",
"moduleResolution": "Node",
"allowSyntheticDefaultImports": true
}
}