Skip to content

Commit 6b29756

Browse files
committed
fix: update aegir and revert varint
This PR upgrade to aegir v31 and reverts varint to 5.0.2 to dedupe upstream. New base table with 1 new codec "thread" Notes on the aegir v31 release https://github.com/ipfs/aegir/releases/tag/v31.0.0
1 parent 139c2d5 commit 6b29756

File tree

10 files changed

+87
-52
lines changed

10 files changed

+87
-52
lines changed

.github/workflows/main.yml

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,12 @@ jobs:
1212
runs-on: ubuntu-latest
1313
steps:
1414
- uses: actions/checkout@v2
15-
- run: yarn
16-
- run: yarn lint
17-
- uses: gozala/[email protected].4
18-
- run: yarn build
19-
- run: yarn aegir dep-check
15+
- run: npm install
16+
- run: npx aegir lint
17+
- uses: gozala/[email protected].8
18+
- run: npx aegir build
19+
- run: npx aegir dep-check
2020
- uses: ipfs/aegir/actions/bundle-size@master
21-
name: size
2221
with:
2322
github_token: ${{ secrets.GITHUB_TOKEN }}
2423
test-node:
@@ -34,34 +33,45 @@ jobs:
3433
- uses: actions/setup-node@v1
3534
with:
3635
node-version: ${{ matrix.node }}
37-
- run: yarn
38-
- run: npx nyc --reporter=lcov aegir test -t node -- --bail
36+
- run: npm install
37+
- run: npx aegir test -t node --bail --cov
3938
- uses: codecov/codecov-action@v1
4039
test-chrome:
4140
needs: check
4241
runs-on: ubuntu-latest
4342
steps:
4443
- uses: actions/checkout@v2
45-
- run: yarn
46-
- run: npx aegir test -t browser -t webworker --bail
44+
- uses: microsoft/playwright-github-action@v1
45+
- run: npm install
46+
- run: npx aegir test -t browser -t webworker --bail --cov
47+
- uses: codecov/codecov-action@v1
4748
test-firefox:
4849
needs: check
4950
runs-on: ubuntu-latest
5051
steps:
5152
- uses: actions/checkout@v2
52-
- run: yarn
53-
- run: npx aegir test -t browser -t webworker --bail -- --browsers FirefoxHeadless
53+
- uses: microsoft/playwright-github-action@v1
54+
- run: npm install
55+
- run: npx aegir test -t browser -t webworker --bail -- --browser firefox
56+
test-webkit:
57+
needs: check
58+
runs-on: ubuntu-latest
59+
steps:
60+
- uses: actions/checkout@v2
61+
- uses: microsoft/playwright-github-action@v1
62+
- run: npm install
63+
- run: npx aegir test -t browser -t webworker --bail -- --browser webkit
5464
test-electron-main:
5565
needs: check
5666
runs-on: ubuntu-latest
5767
steps:
5868
- uses: actions/checkout@v2
59-
- run: yarn
69+
- run: npm install
6070
- run: npx xvfb-maybe aegir test -t electron-main --bail
6171
test-electron-renderer:
6272
needs: check
6373
runs-on: ubuntu-latest
6474
steps:
6575
- uses: actions/checkout@v2
66-
- run: yarn
76+
- run: npm install
6777
- run: npx xvfb-maybe aegir test -t electron-renderer --bail

package.json

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@
2323
"release": "aegir release",
2424
"release-minor": "aegir release --type minor",
2525
"release-major": "aegir release --type major",
26-
"coverage": "aegir coverage",
27-
"coverage-publish": "aegir coverage --provider coveralls",
2826
"update-table": "node tools/update-table.js"
2927
},
3028
"pre-push": [
@@ -50,14 +48,23 @@
5048
},
5149
"homepage": "https://github.com/multiformats/js-multicodec#readme",
5250
"dependencies": {
53-
"uint8arrays": "1.1.0",
54-
"varint": "^6.0.0"
51+
"uint8arrays": "^2.1.3",
52+
"varint": "^5.0.2"
5553
},
5654
"devDependencies": {
57-
"aegir": "^29.2.2",
55+
"@types/varint": "^5.0.0",
56+
"aegir": "^31.0.1",
5857
"bent": "^7.3.12",
5958
"pre-push": "~0.1.1"
6059
},
60+
"eslintConfig": {
61+
"extends": "ipfs"
62+
},
63+
"aegir": {
64+
"build": {
65+
"bundlesizeMax": "6.7kB"
66+
}
67+
},
6168
"contributors": [
6269
"Henrique Dias <[email protected]>",
6370
"David Dias <[email protected]>",

src/generated-table.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ const baseTable = Object.freeze({
104104
'udt': 0x012d,
105105
'utp': 0x012e,
106106
'unix': 0x0190,
107+
'thread': 0x0196,
107108
'p2p': 0x01a5,
108109
'ipfs': 0x01a5,
109110
'https': 0x01bb,

src/generated-types.d.ts

Lines changed: 21 additions & 0 deletions
Large diffs are not rendered by default.

src/generated-types.ts

Lines changed: 0 additions & 21 deletions
This file was deleted.

src/index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ function addPrefix (multicodecStrOrCode, data) {
4949
* @returns {Uint8Array}
5050
*/
5151
function rmPrefix (data) {
52-
varint.decode(data)
52+
varint.decode(/** @type {Buffer} */(data))
5353
return data.slice(varint.decode.bytes)
5454
}
5555

@@ -60,7 +60,7 @@ function rmPrefix (data) {
6060
* @returns {CodecName}
6161
*/
6262
function getNameFromData (prefixedData) {
63-
const code = varint.decode(prefixedData)
63+
const code = /** @type {CodecCode} */(varint.decode(/** @type {Buffer} */(prefixedData)))
6464
const name = codeToName[code]
6565
if (name === undefined) {
6666
throw new Error(`Code "${code}" not found`)
@@ -99,7 +99,7 @@ function getCodeFromName (name) {
9999
* @returns {CodecCode}
100100
*/
101101
function getCodeFromData (prefixedData) {
102-
return varint.decode(prefixedData)
102+
return /** @type {CodecCode} */(varint.decode(/** @type {Buffer} */(prefixedData)))
103103
}
104104

105105
/**

src/maps.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
/** @typedef {import('./generated-types').ConstantCodeMap} ConstantCodeMap */
44
/** @typedef {import('./generated-types').NameUint8ArrayMap} NameUint8ArrayMap */
55
/** @typedef {import('./generated-types').CodeNameMap} CodeNameMap */
6+
/** @typedef {import('./generated-types').CodecName} CodecName */
7+
/** @typedef {import('./generated-types').CodecConstant} CodecConstant */
68

79
const { baseTable } = require('./generated-table')
810
const varintEncode = require('./util').varintEncode
@@ -11,15 +13,17 @@ const nameToVarint = /** @type {NameUint8ArrayMap} */ ({})
1113
const constantToCode = /** @type {ConstantCodeMap} */({})
1214
const codeToName = /** @type {CodeNameMap} */({})
1315

16+
// eslint-disable-next-line guard-for-in
1417
for (const name in baseTable) {
15-
const code = baseTable[name]
16-
nameToVarint[name] = varintEncode(code)
18+
const codecName = /** @type {CodecName} */(name)
19+
const code = baseTable[codecName]
20+
nameToVarint[codecName] = varintEncode(code)
1721

18-
const constant = name.toUpperCase().replace(/-/g, '_')
22+
const constant = /** @type {CodecConstant} */(codecName.toUpperCase().replace(/-/g, '_'))
1923
constantToCode[constant] = code
2024

2125
if (!codeToName[code]) {
22-
codeToName[code] = name
26+
codeToName[code] = codecName
2327
}
2428
}
2529

src/util.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,16 @@ module.exports = {
1111
varintEncode
1212
}
1313

14+
/**
15+
* @param {Uint8Array} buf
16+
*/
1417
function uint8ArrayToNumber (buf) {
1518
return parseInt(uint8ArrayToString(buf, 'base16'), 16)
1619
}
1720

21+
/**
22+
* @param {number} num
23+
*/
1824
function numberToUint8Array (num) {
1925
let hexString = num.toString(16)
2026
if (hexString.length % 2 === 1) {
@@ -23,10 +29,16 @@ function numberToUint8Array (num) {
2329
return uint8ArrayFromString(hexString, 'base16')
2430
}
2531

32+
/**
33+
* @param {Uint8Array} input
34+
*/
2635
function varintUint8ArrayEncode (input) {
2736
return Uint8Array.from(varint.encode(uint8ArrayToNumber(input)))
2837
}
2938

39+
/**
40+
* @param {number} num
41+
*/
3042
function varintEncode (num) {
3143
return Uint8Array.from(varint.encode(num))
3244
}

test/multicodec.spec.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,9 @@ describe('multicodec', () => {
6161
})
6262

6363
it('returns all codec numbers from names', () => {
64+
// eslint-disable-next-line guard-for-in
6465
for (const name in nameToCode) {
65-
expect(multicodec.getCodeFromName(/** @type {CodecName} */(name))).to.eql(nameToCode[name])
66+
expect(multicodec.getCodeFromName(/** @type {CodecName} */(name))).to.eql(nameToCode[/** @type {CodecName} */(name)])
6667
}
6768
})
6869

tools/update-table.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,17 +32,17 @@ const run = async () => {
3232
/**
3333
* Constant names for all available codecs
3434
*/
35-
export type CodecConstant = ${names.map(n => `${n.toUpperCase().replace(/-/g, '_')}`).join(' | ')};
35+
export type CodecConstant = ${names.map(n => `${n.toUpperCase().replace(/-/g, '_')}`).join(' | ')}
3636
3737
/**
3838
* Names for all available codecs
3939
*/
40-
export type CodecName = ${names.join(' | ')};
40+
export type CodecName = ${names.join(' | ')}
4141
4242
/**
4343
* Number for all available codecs
4444
*/
45-
export type CodecCode = ${codes.join(' | ')};
45+
export type CodecCode = ${codes.join(' | ')}
4646
4747
export type ConstantCodeMap = Record<CodecConstant, CodecCode>
4848
export type NameUint8ArrayMap = Record<CodecName, Uint8Array>
@@ -64,7 +64,7 @@ ${processed}
6464
module.exports = { baseTable }
6565
`
6666

67-
fs.writeFileSync(path.join(__dirname, '../src/generated-types.ts'), typesTemplate)
67+
fs.writeFileSync(path.join(__dirname, '../src/generated-types.d.ts'), typesTemplate)
6868
fs.writeFileSync(path.join(__dirname, '../src/generated-table.js'), tableTemplate)
6969
}
7070

0 commit comments

Comments
 (0)