From e579986b5c20ccc9dc04ffdd8541bcbf924c1846 Mon Sep 17 00:00:00 2001 From: Krzysztof Kaczor Date: Mon, 26 Nov 2018 22:59:09 +0100 Subject: [PATCH 1/5] use config extracted to ethereum-config package --- .nycrc | 12 +----------- .prettierrc | 6 ------ prettier.config.js | 1 + tsconfig.json | 18 +----------------- tslint.json | 12 +----------- 5 files changed, 4 insertions(+), 45 deletions(-) delete mode 100644 .prettierrc create mode 100644 prettier.config.js diff --git a/.nycrc b/.nycrc index fbcdf94..8cec4a0 100644 --- a/.nycrc +++ b/.nycrc @@ -1,13 +1,3 @@ { - "reporter": [ - "lcov", - "text" - ], - "include": [ - "src/**/*.ts" - ], - "extension": [ - ".ts" - ], - "all": true + "extends": "./node_modules/ethereumjs-config/typescript/nyc.json" } diff --git a/.prettierrc b/.prettierrc deleted file mode 100644 index 9532646..0000000 --- a/.prettierrc +++ /dev/null @@ -1,6 +0,0 @@ -{ - "tabWidth": 2, - "semi": false, - "singleQuote": true, - "trailingComma": "all" -} \ No newline at end of file diff --git a/prettier.config.js b/prettier.config.js new file mode 100644 index 0000000..85ff963 --- /dev/null +++ b/prettier.config.js @@ -0,0 +1 @@ +module.exports = require('ethereumjs-config/typescript/prettier.json') diff --git a/tsconfig.json b/tsconfig.json index 9309c4b..12a8c32 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,19 +1,3 @@ { - "compileOnSave": false, - "compilerOptions": { - "baseUrl": "./src", - "outDir": "./dist", - "sourceMap": false, - "declaration": false, - "module": "commonjs", - "moduleResolution": "node", - "emitDecoratorMetadata": false, - "experimentalDecorators": true, - "allowSyntheticDefaultImports": true, - "strict": true, - "noImplicitAny": true, - "target": "es5", - "typeRoots": ["node_modules/@types"], - "lib": ["es2018"] - } + "extends": "./node_modules/ethereumjs-config/typescript/tsconfig.json" } diff --git a/tslint.json b/tslint.json index 2fcd2c0..4b34357 100644 --- a/tslint.json +++ b/tslint.json @@ -1,13 +1,3 @@ { - "extends": "typestrict", - "rules": { - "no-console": true, - "no-debugger": true, - "mocha-avoid-only": true, - "prefer-const": true, - "no-var-keyword": true, - "interface-name": [true, "never-prefix"], - "no-commented-code": true, - "no-use-before-declare": false - } + "extends": "./node_modules/ethereumjs-config/typescript/tslint.json" } From 227f0be110366966e125b86d6068cf4dfb48fd1c Mon Sep 17 00:00:00 2001 From: Krzysztof Kaczor Date: Mon, 26 Nov 2018 23:26:42 +0100 Subject: [PATCH 2/5] fix package manifest, proper build --- bin/rlp | 2 +- package.json | 12 +++++++----- src/index.ts | 1 + tsconfig.json | 3 ++- tsconfig.prod.json | 7 +++++++ 5 files changed, 18 insertions(+), 7 deletions(-) create mode 100644 tsconfig.prod.json diff --git a/bin/rlp b/bin/rlp index 0c94baa..d1dddae 100755 --- a/bin/rlp +++ b/bin/rlp @@ -1,6 +1,6 @@ #!/usr/bin/env node -const rlp = require('../index.js') +const rlp = require('./dist/index.js') const command = process.argv[2] var raw = process.argv[3] diff --git a/package.json b/package.json index 91b3b56..b77e021 100644 --- a/package.json +++ b/package.json @@ -2,12 +2,14 @@ "name": "rlp", "version": "2.1.0", "description": "Recursive Length Prefix Encoding Module", - "main": "index.js", - "directories": { - "test": "test" - }, + "main": "./dist/index.js", + "types": "./dist/index.d.ts", + "files": [ + "dist/**", + "bin/**" + ], "scripts": { - "build": "tsc", + "build": "tsc -p ./tsconfig.prod.json", "coverage": "nyc mocha --reporter spec --require ts-node/register test/index.ts", "coveralls": "npm run coverage && nyc report --reporter=text-lcov | coveralls", "format": "prettier --list-different **/*.{ts,json,md,gql}", diff --git a/src/index.ts b/src/index.ts index 4a09625..940c0c4 100644 --- a/src/index.ts +++ b/src/index.ts @@ -55,6 +55,7 @@ function encodeLength(len: number, offset: number): Buffer { **/ export function decode(input: Buffer, stream?: boolean): Buffer export function decode(input: Buffer[], stream?: boolean): Buffer[] +export function decode(input: RLPInput, stream?: boolean): Buffer[] | Buffer | RLPDecoded export function decode( input: RLPInput, stream: boolean = false, diff --git a/tsconfig.json b/tsconfig.json index 12a8c32..c615a82 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,3 +1,4 @@ { - "extends": "./node_modules/ethereumjs-config/typescript/tsconfig.json" + "extends": "./node_modules/ethereumjs-config/typescript/tsconfig.json", + "include": ["src/**/*.ts", "test/**/*.ts"] } diff --git a/tsconfig.prod.json b/tsconfig.prod.json new file mode 100644 index 0000000..7b22cb5 --- /dev/null +++ b/tsconfig.prod.json @@ -0,0 +1,7 @@ +{ + "extends": "./node_modules/ethereumjs-config/typescript/tsconfig.json", + "compilerOptions": { + "outDir": "./dist" + }, + "include": ["src/**/*.ts"] +} From 9a082d00e4d38e600b9403df80360c6e9355005d Mon Sep 17 00:00:00 2001 From: Krzysztof Kaczor Date: Sat, 8 Dec 2018 23:03:44 +0100 Subject: [PATCH 3/5] update to new ethereumjs-config packages --- .nycrc | 2 +- prettier.config.js | 2 +- src/index.ts | 5 ++++- tsconfig.json | 2 +- tslint.json | 2 +- 5 files changed, 8 insertions(+), 5 deletions(-) diff --git a/.nycrc b/.nycrc index 8cec4a0..42c8161 100644 --- a/.nycrc +++ b/.nycrc @@ -1,3 +1,3 @@ { - "extends": "./node_modules/ethereumjs-config/typescript/nyc.json" + "extends": "ethereumjs-config-nyc" } diff --git a/prettier.config.js b/prettier.config.js index 85ff963..e2341ed 100644 --- a/prettier.config.js +++ b/prettier.config.js @@ -1 +1 @@ -module.exports = require('ethereumjs-config/typescript/prettier.json') +module.exports = require('ethereumjs-config-prettier') diff --git a/src/index.ts b/src/index.ts index 940c0c4..f511824 100644 --- a/src/index.ts +++ b/src/index.ts @@ -55,7 +55,10 @@ function encodeLength(len: number, offset: number): Buffer { **/ export function decode(input: Buffer, stream?: boolean): Buffer export function decode(input: Buffer[], stream?: boolean): Buffer[] -export function decode(input: RLPInput, stream?: boolean): Buffer[] | Buffer | RLPDecoded +export function decode( + input: RLPInput, + stream?: boolean, +): Buffer[] | Buffer | RLPDecoded export function decode( input: RLPInput, stream: boolean = false, diff --git a/tsconfig.json b/tsconfig.json index c615a82..d226448 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,4 +1,4 @@ { - "extends": "./node_modules/ethereumjs-config/typescript/tsconfig.json", + "extends": "ethereumjs-config-tsc", "include": ["src/**/*.ts", "test/**/*.ts"] } diff --git a/tslint.json b/tslint.json index 4b34357..2891ad9 100644 --- a/tslint.json +++ b/tslint.json @@ -1,3 +1,3 @@ { - "extends": "./node_modules/ethereumjs-config/typescript/tslint.json" + "extends": "ethereumjs-config-tslint" } From 542379252cfcfab999a2b4d0a38de8f53fcfd0fd Mon Sep 17 00:00:00 2001 From: Krzysztof Kaczor Date: Thu, 13 Dec 2018 12:06:13 +0100 Subject: [PATCH 4/5] add real packages as dependencies, reformat codebase --- .nycrc | 2 +- package.json | 4 ++++ prettier.config.js | 2 +- src/index.ts | 15 +++------------ src/types.ts | 10 +--------- test/index.ts | 10 ++-------- tsconfig.json | 2 +- tslint.json | 2 +- 8 files changed, 14 insertions(+), 33 deletions(-) diff --git a/.nycrc b/.nycrc index 42c8161..b54064b 100644 --- a/.nycrc +++ b/.nycrc @@ -1,3 +1,3 @@ { - "extends": "ethereumjs-config-nyc" + "extends": "@ethereumjs/config-nyc" } diff --git a/package.json b/package.json index b77e021..fc8c5c4 100644 --- a/package.json +++ b/package.json @@ -47,6 +47,10 @@ "safe-buffer": "^5.1.1" }, "devDependencies": { + "@ethereumjs/config-nyc": "^1.0.0", + "@ethereumjs/config-prettier": "^1.0.0", + "@ethereumjs/config-tsc": "^1.0.0", + "@ethereumjs/config-tslint": "^1.0.0", "@types/bn.js": "^4.11.3", "@types/mocha": "^5.2.5", "@types/node": "^10.12.2", diff --git a/prettier.config.js b/prettier.config.js index e2341ed..0f2e5b7 100644 --- a/prettier.config.js +++ b/prettier.config.js @@ -1 +1 @@ -module.exports = require('ethereumjs-config-prettier') +module.exports = require('@ethereumjs/config-prettier') diff --git a/src/index.ts b/src/index.ts index f511824..71784b3 100644 --- a/src/index.ts +++ b/src/index.ts @@ -55,14 +55,8 @@ function encodeLength(len: number, offset: number): Buffer { **/ export function decode(input: Buffer, stream?: boolean): Buffer export function decode(input: Buffer[], stream?: boolean): Buffer[] -export function decode( - input: RLPInput, - stream?: boolean, -): Buffer[] | Buffer | RLPDecoded -export function decode( - input: RLPInput, - stream: boolean = false, -): Buffer[] | Buffer | RLPDecoded { +export function decode(input: RLPInput, stream?: boolean): Buffer[] | Buffer | RLPDecoded +export function decode(input: RLPInput, stream: boolean = false): Buffer[] | Buffer | RLPDecoded { if (!input || (input).length === 0) { return Buffer.from([]) } @@ -105,10 +99,7 @@ export function getLength(input: RLPInput): Buffer | number { } else { // a list over 55 bytes long const llength = firstByte - 0xf6 - const length = safeParseInt( - inputBuffer.slice(1, llength).toString('hex'), - 16, - ) + const length = safeParseInt(inputBuffer.slice(1, llength).toString('hex'), 16) return llength + length } } diff --git a/src/types.ts b/src/types.ts index c13bbeb..185d4fb 100644 --- a/src/types.ts +++ b/src/types.ts @@ -1,14 +1,6 @@ import BN from 'bn.js' -export type RLPInput = - | Buffer - | string - | number - | Uint8Array - | BN - | RLPObject - | RLPArray - | null +export type RLPInput = Buffer | string | number | Uint8Array | BN | RLPObject | RLPArray | null export interface RLPArray extends Array {} interface RLPObject { diff --git a/test/index.ts b/test/index.ts index 3a9c006..eb2f4ed 100644 --- a/test/index.ts +++ b/test/index.ts @@ -182,10 +182,7 @@ describe('nested lists:', function() { let encoded: Buffer it('encode a nested list', function() { encoded = RLP.encode(nestedList) - assert.deepEqual( - encoded, - Buffer.from([0xc7, 0xc0, 0xc1, 0xc0, 0xc3, 0xc0, 0xc1, 0xc0]), - ) + assert.deepEqual(encoded, Buffer.from([0xc7, 0xc0, 0xc1, 0xc0, 0xc3, 0xc0, 0xc1, 0xc0])) }) it('should decode a nested list', function() { @@ -355,10 +352,7 @@ describe('offical tests', function() { } const encoded = RLP.encode(incoming) - assert.equal( - encoded.toString('hex'), - officalTests[test].out.toLowerCase(), - ) + assert.equal(encoded.toString('hex'), officalTests[test].out.toLowerCase()) } done() }) diff --git a/tsconfig.json b/tsconfig.json index d226448..6ca82b8 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,4 +1,4 @@ { - "extends": "ethereumjs-config-tsc", + "extends": "@ethereumjs/config-tsc", "include": ["src/**/*.ts", "test/**/*.ts"] } diff --git a/tslint.json b/tslint.json index 2891ad9..2ba21c4 100644 --- a/tslint.json +++ b/tslint.json @@ -1,3 +1,3 @@ { - "extends": "ethereumjs-config-tslint" + "extends": "@ethereumjs/config-tslint" } From 21b1654919e25a422b96351a64b3d8886672f24a Mon Sep 17 00:00:00 2001 From: Krzysztof Kaczor Date: Thu, 13 Dec 2018 12:17:02 +0100 Subject: [PATCH 5/5] fix build task, add build on CI --- .travis.yml | 3 +++ tsconfig.prod.json | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 7cc357e..8b340df 100644 --- a/.travis.yml +++ b/.travis.yml @@ -18,4 +18,7 @@ matrix: - os: linux node_js: "6" env: TEST_SUITE=lint + - os: linux + node_js: "6" + env: TEST_SUITE=build script: npm run $TEST_SUITE diff --git a/tsconfig.prod.json b/tsconfig.prod.json index 7b22cb5..21f1b75 100644 --- a/tsconfig.prod.json +++ b/tsconfig.prod.json @@ -1,5 +1,5 @@ { - "extends": "./node_modules/ethereumjs-config/typescript/tsconfig.json", + "extends": "@ethereumjs/config-tsc", "compilerOptions": { "outDir": "./dist" },