diff --git a/bench/index.js b/bench/index.js index 1772064..f330b99 100644 --- a/bench/index.js +++ b/bench/index.js @@ -1,6 +1,6 @@ 'use strict' -const Buffer = require('safe-buffer').Buffer +const { Buffer } = require('buffer') const Benchmark = require('benchmark') if (typeof window !== 'undefined') { window.Benchmark = Benchmark diff --git a/package.json b/package.json index 29b665e..1be1f4b 100644 --- a/package.json +++ b/package.json @@ -8,13 +8,13 @@ "url": "https://github.com/ipfs/protons" }, "dependencies": { + "buffer": "^5.5.0", "protocol-buffers-schema": "^3.3.1", - "safe-buffer": "^5.1.1", "signed-varint": "^2.0.1", "varint": "^5.0.0" }, "devDependencies": { - "aegir": "^20.4.1", + "aegir": "^21.3.0", "benchmark": "^2.1.4", "protocol-buffers": "^4.1.0", "protons": "^1.0.0", diff --git a/src/compile/encode.js b/src/compile/encode.js index d3df108..e0c1b03 100644 --- a/src/compile/encode.js +++ b/src/compile/encode.js @@ -1,5 +1,5 @@ 'use strict' - +const { Buffer } = require('buffer') var defined = require('./utils').defined var varint = require('varint') diff --git a/src/compile/encodings.js b/src/compile/encodings.js index beee237..97f98ba 100644 --- a/src/compile/encodings.js +++ b/src/compile/encodings.js @@ -2,7 +2,7 @@ var varint = require('varint') var svarint = require('signed-varint') -var Buffer = require('safe-buffer').Buffer +const { Buffer } = require('buffer') var encoder = function (type, encode, decode, encodingLength) { encode.bytes = decode.bytes = 0 diff --git a/src/index.js b/src/index.js index 7ff6cce..2a76852 100644 --- a/src/index.js +++ b/src/index.js @@ -1,6 +1,7 @@ 'use strict' var schema = require('protocol-buffers-schema') +const { Buffer } = require('buffer') var compile = require('./compile') var flatten = function (values) { diff --git a/test/basic.js b/test/basic.js index d41d509..a9fa85f 100644 --- a/test/basic.js +++ b/test/basic.js @@ -1,11 +1,9 @@ 'use strict' var tape = require('tape') -var fs = require('fs') var protobufNpm = require('protocol-buffers') var protobuf = require('../') -var path = require('path') -var proto = fs.readFileSync(path.join(__dirname, '/test.proto')) +var proto = require('./test.proto.js') var Basic = protobuf(proto).Basic var BasicNpm = protobufNpm(proto).Basic diff --git a/test/booleans.js b/test/booleans.js index ac8d6e5..ce0796d 100644 --- a/test/booleans.js +++ b/test/booleans.js @@ -1,10 +1,9 @@ 'use strict' var tape = require('tape') -var fs = require('fs') -var path = require('path') var protobuf = require('../src') -var Booleans = protobuf(fs.readFileSync(path.join(__dirname, '/test.proto'))).Booleans +var proto = require('./test.proto.js') +var Booleans = protobuf(proto).Booleans tape('booleans encode + decode', function (t) { var b1 = Booleans.encode({ diff --git a/test/bytes.js b/test/bytes.js index 7b5feb8..5bba0c2 100644 --- a/test/bytes.js +++ b/test/bytes.js @@ -1,10 +1,8 @@ 'use strict' var tape = require('tape') -var fs = require('fs') -var path = require('path') var protobuf = require('../src') -var Bytes = protobuf(fs.readFileSync(path.join(__dirname, '/test.proto'))).Bytes +var Bytes = protobuf(require('./test.proto.js')).Bytes tape('bytes encode + decode', function (t) { var b1 = Bytes.encode({ diff --git a/test/custom-types.js b/test/custom-types.js index 186a17d..6721758 100644 --- a/test/custom-types.js +++ b/test/custom-types.js @@ -1,10 +1,8 @@ 'use strict' var tape = require('tape') -var fs = require('fs') -var path = require('path') var protobuf = require('../src') -var CustomType = protobuf(fs.readFileSync(path.join(__dirname, '/test.proto'))).CustomType +var CustomType = protobuf(require('./test.proto.js')).CustomType tape('custom types encode + decode', function (t) { var b1 = CustomType.encode({ diff --git a/test/defaults.js b/test/defaults.js index 7094e93..35c895f 100644 --- a/test/defaults.js +++ b/test/defaults.js @@ -1,10 +1,8 @@ 'use strict' var tape = require('tape') -var fs = require('fs') -var path = require('path') var protobuf = require('../') -var Defaults = protobuf(fs.readFileSync(path.join(__dirname, '/test.proto'))).Defaults +var Defaults = protobuf(require('./test.proto.js')).Defaults tape('defaults decode', function (t) { var o1 = Defaults.decode(Buffer.alloc(0)) // everything default diff --git a/test/enums.js b/test/enums.js index dac0ead..421b654 100644 --- a/test/enums.js +++ b/test/enums.js @@ -1,10 +1,8 @@ 'use strict' var tape = require('tape') -var fs = require('fs') -var path = require('path') var protobuf = require('../') -var messages = protobuf(fs.readFileSync(path.join(__dirname, '/test.proto'))) +var messages = protobuf(require('./test.proto.js')) tape('enums', function (t) { var e = messages.FOO diff --git a/test/float.js b/test/float.js index 79783a0..41be22e 100644 --- a/test/float.js +++ b/test/float.js @@ -1,10 +1,8 @@ 'use strict' var tape = require('tape') -var fs = require('fs') -var path = require('path') var protobuf = require('../') -var Float = protobuf(fs.readFileSync(path.join(__dirname, '/test.proto'))).Float +var Float = protobuf(require('./test.proto.js')).Float tape('float encode + decode', function (t) { var arr = new Float32Array(3) diff --git a/test/integers.js b/test/integers.js index 710c833..f28a8e1 100644 --- a/test/integers.js +++ b/test/integers.js @@ -1,10 +1,8 @@ 'use strict' var tape = require('tape') -var fs = require('fs') -var path = require('path') var protobuf = require('../') -var Integers = protobuf(fs.readFileSync(path.join(__dirname, '/test.proto'))).Integers +var Integers = protobuf(require('./test.proto.js')).Integers tape('integers encode + decode', function (t) { var b1 = Integers.encode({ diff --git a/test/map.js b/test/map.js index 824dbf4..c3f2311 100644 --- a/test/map.js +++ b/test/map.js @@ -1,10 +1,8 @@ 'use strict' var tape = require('tape') -var fs = require('fs') -var path = require('path') var protobuf = require('../') -var Map = protobuf(fs.readFileSync(path.join(__dirname, '/test.proto'))).Map +var Map = protobuf(require('./test.proto.js')).Map tape('map encode + decode', function (t) { var b1 = Map.encode({ diff --git a/test/nested.js b/test/nested.js index 060e8e5..7ccea6e 100644 --- a/test/nested.js +++ b/test/nested.js @@ -1,10 +1,8 @@ 'use strict' var tape = require('tape') -var fs = require('fs') -var path = require('path') var protobuf = require('../') -var Nested = protobuf(fs.readFileSync(path.join(__dirname, '/test.proto'))).Nested +var Nested = protobuf(require('./test.proto.js')).Nested tape('nested encode', function (t) { var b1 = Nested.encode({ diff --git a/test/notpacked.js b/test/notpacked.js index efc81b8..4aaac4e 100644 --- a/test/notpacked.js +++ b/test/notpacked.js @@ -1,10 +1,8 @@ 'use strict' var tape = require('tape') -var fs = require('fs') -var path = require('path') var protobuf = require('../') -var proto = fs.readFileSync(path.join(__dirname, '/test.proto')) +var proto = require('./test.proto.js') var NotPacked = protobuf(proto).NotPacked var FalsePacked = protobuf(proto).FalsePacked diff --git a/test/oneof.js b/test/oneof.js index 237662c..11769b9 100644 --- a/test/oneof.js +++ b/test/oneof.js @@ -1,10 +1,8 @@ 'use strict' var tape = require('tape') -var fs = require('fs') -var path = require('path') var protobuf = require('../') -var proto = protobuf(fs.readFileSync(path.join(__dirname, '/test.proto'))) +var proto = protobuf(require('./test.proto.js')) var Property = proto.Property var PropertyNoOneof = proto.PropertyNoOneof diff --git a/test/optional.js b/test/optional.js index 6abf633..9bb638d 100644 --- a/test/optional.js +++ b/test/optional.js @@ -1,10 +1,8 @@ 'use strict' var tape = require('tape') -var fs = require('fs') var protobuf = require('../') -var path = require('path') -var proto = fs.readFileSync(path.join(__dirname, '/test.proto')) +var proto = require('./test.proto.js') var Optional = protobuf(proto).Optional tape('optional encode + decode has zero value', function (t) { diff --git a/test/packed.js b/test/packed.js index 7494963..df66fe6 100644 --- a/test/packed.js +++ b/test/packed.js @@ -1,10 +1,8 @@ 'use strict' var tape = require('tape') -var fs = require('fs') -var path = require('path') var protobuf = require('../') -var Packed = protobuf(fs.readFileSync(path.join(__dirname, '/test.proto'))).Packed +var Packed = protobuf(require('./test.proto.js')).Packed tape('Packed encode', function (t) { var b1 = Packed.encode({ diff --git a/test/repeated.js b/test/repeated.js index 8a13feb..a25f137 100644 --- a/test/repeated.js +++ b/test/repeated.js @@ -1,10 +1,8 @@ 'use strict' var tape = require('tape') -var fs = require('fs') -var path = require('path') var protobuf = require('../') -var Repeated = protobuf(fs.readFileSync(path.join(__dirname, '/test.proto'))).Repeated +var Repeated = protobuf(require('./test.proto.js')).Repeated tape('repeated encode', function (t) { var b1 = Repeated.encode({ diff --git a/test/strings.js b/test/strings.js index f3aa272..40ea05c 100644 --- a/test/strings.js +++ b/test/strings.js @@ -1,10 +1,8 @@ 'use strict' var tape = require('tape') -var fs = require('fs') -var path = require('path') var protobuf = require('../src') -var Strings = protobuf(fs.readFileSync(path.join(__dirname, '/test.proto'))).Strings +var Strings = protobuf(require('./test.proto.js')).Strings tape('strings encode + decode', function (t) { var b1 = Strings.encode({ diff --git a/test/test.proto b/test/test.proto.js similarity index 97% rename from test/test.proto rename to test/test.proto.js index 2439a85..18e32e5 100644 --- a/test/test.proto +++ b/test/test.proto.js @@ -1,4 +1,5 @@ -message Basic { +'use strict' +module.exports = `message Basic { required double num = 1; required bytes payload = 2; } @@ -129,4 +130,4 @@ message ComplexProperty { int32 int_value = 9; string string_value = 10; } -} +}` diff --git a/test/utf-8.js b/test/utf-8.js index 35ccead..09ab7b4 100644 --- a/test/utf-8.js +++ b/test/utf-8.js @@ -1,10 +1,8 @@ 'use strict' var tape = require('tape') -var fs = require('fs') -var path = require('path') var protobuf = require('../') -var UTF8 = protobuf(fs.readFileSync(path.join(__dirname, '/test.proto'))).UTF8 +var UTF8 = protobuf(require('./test.proto.js')).UTF8 tape('strings can be utf-8', function (t) { var ex = {