Skip to content

Commit

Permalink
ci: fix node-versions run for node <16 (#1653)
Browse files Browse the repository at this point in the history
* re-add updating to npm v7 for node versions <16
* only upgrade npm for node v <16
* fix bin/rlp js: node 12 doesn't support ES11 which added support for nullish coalescing operator (??) so we'll use ternary here
alternatively we could write this file in TS and compile to e.g. dist/bin/rlp (like we do in the client bin), but maybe if the file gets more complicated, in its current state i don't think it's so neccessary
* use same errorMsg format for JSON.parse, remove unneeded extra Uint8Array.from (already is uint8array)
  • Loading branch information
ryanio authored Jan 19, 2022
1 parent 476039a commit eb5bb56
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/node-versions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ jobs:
node-version: ${{ matrix.node }}
cache: 'npm'

- name: Use npm v7 for workspaces support
run: npm i -g npm@7
if: ${{ matrix.node-version < 16 }}

- run: npm i

- name: Test Block
Expand Down
11 changes: 7 additions & 4 deletions packages/rlp/bin/rlp
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,17 @@ if (method === 'encode') {
try {
json = JSON.parse(strInput)
} catch (error) {
return console.error(`Error could not parse JSON: ${JSON.stringify(error)}`)
const errorMsg = error.message ? error.message : error
return console.error(`Error could not parse JSON: ${errorMsg}`)
}

// Encode RLP
try {
const encoded = RLP.encode(json)
console.log('0x' + bytesToHex(Uint8Array.from(encoded)))
console.log('0x' + bytesToHex(encoded))
} catch (error) {
console.error(`Error encoding RLP: ${error.message ?? error}`)
const errorMsg = error.message ? error.message : error
console.error(`Error encoding RLP: ${errorMsg}`)
}
} else if (method === 'decode') {
// Decode
Expand All @@ -33,7 +35,8 @@ if (method === 'encode') {
const json = JSON.stringify(arrToJSON(decoded))
console.log(json)
} catch (error) {
console.error(`Error decoding RLP: ${error.message ?? error}`)
const errorMsg = error.message ? error.message : error
console.error(`Error decoding RLP: ${errorMsg}`)
}
} else {
console.error('Unsupported method')
Expand Down

0 comments on commit eb5bb56

Please sign in to comment.