Skip to content

Commit ae2214e

Browse files
committed
fix: remove node globals
This PR remove node globals, updates deps and fixes lint problems. related to this ipfs/js-ipfs#2924
1 parent b6bae8b commit ae2214e

16 files changed

+73
-39
lines changed

benchmarks/index.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* eslint-disable no-console */
12
'use strict'
23

34
console.log('PID: %s', process.pid)
@@ -24,7 +25,7 @@ const buffers = vectors
2425

2526
const suite = new Benchmark.Suite('cbor')
2627

27-
let vecLength = vectors.length
28+
const vecLength = vectors.length
2829
let res = []
2930

3031
suite.add(`encode - node-cbor - ${vecLength}`, () => {
@@ -40,9 +41,11 @@ suite.add(`encode - borc - ${vecLength}`, () => {
4041
})
4142

4243
suite.add(`encode - stream - borc - ${vecLength}`, () => {
43-
const enc = new fastCbor.Encoder({ stream (chunk) {
44-
res.push(chunk)
45-
} })
44+
const enc = new fastCbor.Encoder({
45+
stream (chunk) {
46+
res.push(chunk)
47+
}
48+
})
4649
for (let i = 0; i < vecLength; i++) {
4750
enc.write(vectors[i].decoded)
4851
}

bin/cbor2json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#!/usr/bin/env node
2+
/* eslint-disable no-console */
23
'use strict'
34

45
const cbor = require('../src/cbor')

package.json

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
"email": "[email protected]"
3939
},
4040
"devDependencies": {
41-
"aegir": "^18.0.1",
41+
"aegir": "^21.4.5",
4242
"benchmark": "^2.1.0",
4343
"budo": "^11.2.0",
4444
"cbor": "^4.0.0",
@@ -50,10 +50,12 @@
5050
"readmeFilename": "README.md",
5151
"dependencies": {
5252
"bignumber.js": "^9.0.0",
53+
"buffer": "^5.5.0",
5354
"commander": "^2.15.0",
54-
"ieee754": "^1.1.8",
55-
"iso-url": "~0.4.4",
56-
"json-text-sequence": "~0.1.0"
55+
"ieee754": "^1.1.13",
56+
"iso-url": "~0.4.7",
57+
"json-text-sequence": "~0.1.0",
58+
"readable-stream": "^3.6.0"
5759
},
5860
"engines": {
5961
"node": ">=4"

src/commented.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
'use strict'
22

3-
const stream = require('stream')
4-
const util = require('util')
5-
const utils = require('./utils')
6-
const Simple = require('./simple')
3+
const { Buffer } = require('buffer')
4+
const stream = require('readable-stream')
75
const Decoder = require('./decoder')
86
const constants = require('./constants')
97
const bignumber = require('bignumber.js').BigNumber
@@ -308,7 +306,7 @@ class Commented extends stream.Transform {
308306
this.push(val.toString())
309307
this.push('\n')
310308
} else {
311-
this.push(util.inspect(val))
309+
this.push(JSON.stringify(val))
312310
this.push('\n')
313311
}
314312

src/decoder.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
'use strict'
22

3+
const { Buffer } = require('buffer')
34
const ieee754 = require('ieee754')
45
const Bignumber = require('bignumber.js').BigNumber
56

@@ -55,6 +56,7 @@ class Decoder {
5556

5657
// Initialize asm based parser
5758
this.parser = parser(global, {
59+
// eslint-disable-next-line no-console
5860
log: console.log.bind(console),
5961
pushInt: this.pushInt.bind(this),
6062
pushInt32: this.pushInt32.bind(this),
@@ -327,7 +329,7 @@ class Decoder {
327329
}
328330

329331
createUndefined () {
330-
return void 0
332+
return undefined
331333
}
332334

333335
createInfinity () {

src/diagnose.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
'use strict'
22

3+
const { Buffer } = require('buffer')
34
const Decoder = require('./decoder')
45
const utils = require('./utils')
56

src/encoder.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
'use strict'
22

3+
const { Buffer } = require('buffer')
34
const { URL } = require('iso-url')
45
const Bignumber = require('bignumber.js').BigNumber
56

@@ -254,7 +255,7 @@ class Encoder {
254255
if (!gen._pushInt(obj.size, MT.ARRAY)) {
255256
return false
256257
}
257-
for (let x of obj) {
258+
for (const x of obj) {
258259
if (!gen.pushAny(x)) {
259260
return false
260261
}
@@ -425,7 +426,7 @@ class Encoder {
425426
case SYMS.NULL:
426427
return this._pushObject(null)
427428
case SYMS.UNDEFINED:
428-
return this._pushUndefined(void 0)
429+
return this._pushUndefined(undefined)
429430
// TODO: Add pluggable support for other symbols
430431
default:
431432
throw new Error('Unknown symbol: ' + obj.toString())

src/simple.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ class Simple {
8989
}
9090
case SIMPLE.UNDEFINED:
9191
if (hasParent) {
92-
return void 0
92+
return undefined
9393
} else {
9494
return SYMS.UNDEFINED
9595
}

src/tagged.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ class Tagged {
5858
*/
5959
convert (converters) {
6060
var er, f
61-
f = converters != null ? converters[this.tag] : void 0
61+
f = converters != null ? converters[this.tag] : undefined
6262
if (typeof f !== 'function') {
6363
f = Tagged['_tag' + this.tag]
6464
if (typeof f !== 'function') {

src/utils.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
'use strict'
22

3+
const { Buffer } = require('buffer')
34
const Bignumber = require('bignumber.js').BigNumber
45

56
const constants = require('./constants')

test/decoder.spec.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/* eslint-env mocha */
22
'use strict'
33

4+
const { Buffer } = require('buffer')
45
const chai = require('chai')
56
chai.use(require('dirty-chai'))
67
const expect = chai.expect

test/encoder.spec.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* eslint max-nested-callbacks: ["error", 8] */
22
/* eslint-env mocha */
33
'use strict'
4-
4+
const { Buffer } = require('buffer')
55
const expect = require('chai').expect
66
const Bignum = require('bignumber.js').BigNumber
77

@@ -61,7 +61,7 @@ describe('encoder', () => {
6161
it('addSemanticType', () => {
6262
// before the tag, this is an innocuous object:
6363
// {"value": "foo"}
64-
let tc = new cases.TempClass('foo')
64+
const tc = new cases.TempClass('foo')
6565
delete (cases.TempClass.prototype.encodeCBOR)
6666
expect(
6767
cbor.Encoder.encode(tc).toString('hex')
@@ -161,7 +161,7 @@ describe('encoder', () => {
161161
})
162162

163163
describe('numbers', () => {
164-
for (let numEnc of cases.canonNums) {
164+
for (const numEnc of cases.canonNums) {
165165
it(`${numEnc[0]} -> ${numEnc[1]}`, () => {
166166
expect(
167167
cbor.Encoder.encode(numEnc[0]).toString('hex')

test/fixtures/cases.js

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
'use strict'
22

3+
const { Buffer } = require('buffer')
34
const Bignum = require('bignumber.js').BigNumber
45
const { URL } = require('iso-url')
56
const expect = require('chai').expect
@@ -12,9 +13,11 @@ class TempClass {
1213
// render as the string tempClass with the tag 0xffff
1314
this.value = val || 'tempClass'
1415
}
16+
1517
encodeCBOR (gen) {
1618
return gen._pushTag(0xffff) && gen.pushAny(this.value)
1719
}
20+
1821
static toCBOR (gen, obj) {
1922
return gen._pushTag(0xfffe) && gen.pushAny(obj.value)
2023
}
@@ -323,11 +326,33 @@ exports.good = [
323326
61 -- String, length: 1
324327
45 -- {Val:4}, "E"
325328
0xa56161614161626142616361436164614461656145`],
326-
[{ 1: { 2: { 3: { 4: { 5: { 6: {
327-
7: { 8: { 9: { 10: { 11: { 12: {
328-
13: 'hello', 14: 'world'
329-
} } } } } }
330-
} } } } } } }, `{"1": {"2": {"3": {"4": {"5": {"6": {"7": {"8": {"9": {"10": {"11": {"12": {"13": "hello", "14": "world"}}}}}}}}}}}}}`, `
329+
[{
330+
1: {
331+
2: {
332+
3: {
333+
4: {
334+
5: {
335+
6: {
336+
7: {
337+
8: {
338+
9: {
339+
10: {
340+
11: {
341+
12: {
342+
13: 'hello', 14: 'world'
343+
}
344+
}
345+
}
346+
}
347+
}
348+
}
349+
}
350+
}
351+
}
352+
}
353+
}
354+
}
355+
}, '{"1": {"2": {"3": {"4": {"5": {"6": {"7": {"8": {"9": {"10": {"11": {"12": {"13": "hello", "14": "world"}}}}}}}}}}}}}', `
331356
a1 # map(1)
332357
61 # text(1)
333358
31 # "1"
@@ -977,7 +1002,7 @@ a1 # map(1)
9771002
}]
9781003
]
9791004
}
980-
}], `[true, {"#0": {"hxj(DOQZ-+%7>'": "oA|", "": true, "4(CX:": [-0.992622389595498_3, [{"Sedx": -0.49904045994866497_3, "f|mMuJDG2K2>b:Ob-WC": true, "t": {"}[": false, "O_b": true, "P;?V": true, ".mP2U!1r=": [null]}}]]}}]`, `
1005+
}], '[true, {"#0": {"hxj(DOQZ-+%7>\'": "oA|", "": true, "4(CX:": [-0.992622389595498_3, [{"Sedx": -0.49904045994866497_3, "f|mMuJDG2K2>b:Ob-WC": true, "t": {"}[": false, "O_b": true, "P;?V": true, ".mP2U!1r=": [null]}}]]}}]', `
9811006
82 # array(2)
9821007
f5 # primitive(21)
9831008
a1 # map(1)
@@ -1186,7 +1211,7 @@ class EncodeFailer extends cbor.Encoder {
11861211
let enc = new EncodeFailer()
11871212
enc.canonical = canonical
11881213
expect(enc.pushAny(f)).to.be.eql(true)
1189-
let used = enc.used
1214+
const used = enc.used
11901215
for (let i = 0; i < used; i++) {
11911216
enc = new EncodeFailer(i)
11921217
enc.canonical = canonical

test/garbage.spec.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@ const garbage = require('garbage')
66

77
const cbor = require('../src')
88

9-
const CBOR_GARBAGE = process.env.NODE_CBOR_GARBAGE
10-
const NO_GARBAGE = process.env.NO_GARBAGE
11-
const REPEATS = parseInt(CBOR_GARBAGE || 1000)
9+
// const CBOR_GARBAGE = global.process.env.NODE_CBOR_GARBAGE
10+
// const NO_GARBAGE = global.process.env.NO_GARBAGE
11+
const REPEATS = parseInt(1000)
1212

1313
describe('random data', () => {
14-
if (NO_GARBAGE) {
15-
it.skip('garbage', () => {})
16-
return
17-
}
14+
// if (NO_GARBAGE) {
15+
// it.skip('garbage', () => {})
16+
// return
17+
// }
1818

1919
it('garbage', function () {
2020
this.timeout(20 * 1000)

test/tagged.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* eslint-env mocha */
22
'use strict'
3-
3+
const { Buffer } = require('buffer')
44
const expect = require('chai').expect
55

66
const cbor = require('../')

test/utils.spec.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
11
/* eslint-env mocha */
22
'use strict'
3-
3+
const { Buffer } = require('buffer')
44
const expect = require('chai').expect
55
const utils = require('../src/utils')
66

77
function bin (s) {
8-
let chunks
8+
const chunks = []
99
let end
1010
let start
1111

1212
s = s.replace(/\s/g, '')
1313
start = 0
1414
end = (s.length % 8) || 8
15-
chunks = []
1615
while (end <= s.length) {
1716
chunks.push(parseInt(s.slice(start, end), 2))
1817
start = end

0 commit comments

Comments
 (0)