Skip to content

Commit

Permalink
fix: add buffer and allow browser tests
Browse files Browse the repository at this point in the history
Add buffer dependency related to this ipfs/js-ipfs#2924

Remove dependency on path and fs and allow for browser tests.
  • Loading branch information
hugomrdias committed Mar 14, 2020
1 parent 65f5927 commit d214dad
Show file tree
Hide file tree
Showing 23 changed files with 27 additions and 58 deletions.
2 changes: 1 addition & 1 deletion bench/index.js
Original file line number Diff line number Diff line change
@@ -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
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion src/compile/encode.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
'use strict'

const { Buffer } = require('buffer')
var defined = require('./utils').defined
var varint = require('varint')

Expand Down
2 changes: 1 addition & 1 deletion src/compile/encodings.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict'

var schema = require('protocol-buffers-schema')
const { Buffer } = require('buffer')
var compile = require('./compile')

var flatten = function (values) {
Expand Down
4 changes: 1 addition & 3 deletions test/basic.js
Original file line number Diff line number Diff line change
@@ -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

Expand Down
5 changes: 2 additions & 3 deletions test/booleans.js
Original file line number Diff line number Diff line change
@@ -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({
Expand Down
4 changes: 1 addition & 3 deletions test/bytes.js
Original file line number Diff line number Diff line change
@@ -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({
Expand Down
4 changes: 1 addition & 3 deletions test/custom-types.js
Original file line number Diff line number Diff line change
@@ -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({
Expand Down
4 changes: 1 addition & 3 deletions test/defaults.js
Original file line number Diff line number Diff line change
@@ -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
Expand Down
4 changes: 1 addition & 3 deletions test/enums.js
Original file line number Diff line number Diff line change
@@ -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
Expand Down
4 changes: 1 addition & 3 deletions test/float.js
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
4 changes: 1 addition & 3 deletions test/integers.js
Original file line number Diff line number Diff line change
@@ -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({
Expand Down
4 changes: 1 addition & 3 deletions test/map.js
Original file line number Diff line number Diff line change
@@ -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({
Expand Down
4 changes: 1 addition & 3 deletions test/nested.js
Original file line number Diff line number Diff line change
@@ -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({
Expand Down
4 changes: 1 addition & 3 deletions test/notpacked.js
Original file line number Diff line number Diff line change
@@ -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

Expand Down
4 changes: 1 addition & 3 deletions test/oneof.js
Original file line number Diff line number Diff line change
@@ -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

Expand Down
4 changes: 1 addition & 3 deletions test/optional.js
Original file line number Diff line number Diff line change
@@ -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) {
Expand Down
4 changes: 1 addition & 3 deletions test/packed.js
Original file line number Diff line number Diff line change
@@ -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({
Expand Down
4 changes: 1 addition & 3 deletions test/repeated.js
Original file line number Diff line number Diff line change
@@ -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({
Expand Down
4 changes: 1 addition & 3 deletions test/strings.js
Original file line number Diff line number Diff line change
@@ -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({
Expand Down
5 changes: 3 additions & 2 deletions test/test.proto → test/test.proto.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
message Basic {
'use strict'
module.exports = `message Basic {
required double num = 1;
required bytes payload = 2;
}
Expand Down Expand Up @@ -129,4 +130,4 @@ message ComplexProperty {
int32 int_value = 9;
string string_value = 10;
}
}
}`
4 changes: 1 addition & 3 deletions test/utf-8.js
Original file line number Diff line number Diff line change
@@ -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 = {
Expand Down

0 comments on commit d214dad

Please sign in to comment.