Skip to content
This repository has been archived by the owner on Feb 12, 2024. It is now read-only.

Commit

Permalink
fix: dont include util.textencoder in the browser (#2919)
Browse files Browse the repository at this point in the history
* fix: dont include util.textencoder in the browser

node 10 only has textencoder inside util and not in the global var so we need to do the standard node/browser swap to avoid including node util in the browser

* fix: fix object stat timeout test

* fix: add interop gh branch
  • Loading branch information
hugomrdias authored Mar 13, 2020
1 parent 9bc9625 commit 3207e3b
Show file tree
Hide file tree
Showing 9 changed files with 16 additions and 8 deletions.
2 changes: 1 addition & 1 deletion packages/interface-ipfs-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
"ipfs-unixfs": "^1.0.0",
"ipfs-utils": "^0.7.2",
"ipld-dag-cbor": "^0.15.1",
"ipld-dag-pb": "^0.18.2",
"ipld-dag-pb": "^0.18.3",
"is-ipfs": "^0.6.1",
"it-all": "^1.0.1",
"it-concat": "^1.0.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/interface-ipfs-core/src/object/stat.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ module.exports = (common, options) => {
expect(err.message).to.equal('failed to get block for QmNggDXca24S6cMPEYHZjeuc4QRmofkRrAEqVL3MzzzzzZ: context deadline exceeded')
}

expect(timeForRequest).to.not.lessThan(timeout - 0.1)
expect(timeForRequest).to.not.lessThan(timeout - 1000)
expect(timeForRequest).to.not.greaterThan(timeout + 1000)
})

Expand Down
2 changes: 1 addition & 1 deletion packages/ipfs-http-client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
"ipfs-block": "^0.8.1",
"ipfs-utils": "^0.7.2",
"ipld-dag-cbor": "^0.15.1",
"ipld-dag-pb": "^0.18.2",
"ipld-dag-pb": "^0.18.3",
"ipld-raw": "^4.0.1",
"iso-url": "^0.4.6",
"it-tar": "^1.2.1",
Expand Down
2 changes: 1 addition & 1 deletion packages/ipfs-mfs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
"ipfs-unixfs-exporter": "^1.0.1",
"ipfs-unixfs-importer": "^1.0.1",
"ipfs-utils": "^0.7.0",
"ipld-dag-pb": "^0.18.2",
"ipld-dag-pb": "^0.18.3",
"it-all": "^1.0.1",
"it-last": "^1.0.1",
"it-to-stream": "^0.1.1",
Expand Down
3 changes: 2 additions & 1 deletion packages/ipfs-utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
"Marcin Rataj <lidel@lidel.org>"
],
"browser": {
"fs-extra": false
"fs-extra": false,
"./src/text-encoder.js": "./src/text-encoder.browser.js"
}
}
2 changes: 1 addition & 1 deletion packages/ipfs-utils/src/http.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const fetch = require('node-fetch')
const merge = require('merge-options')
const { URL, URLSearchParams } = require('iso-url')
const global = require('./globalthis')
const TextDecoder = require('./text-encoder')
const Request = global.Request
const AbortController = global.AbortController

Expand Down Expand Up @@ -235,7 +236,6 @@ class HTTP {
* @returns {AsyncGenerator<Object, void, any>}
*/
const ndjson = async function * (source) {
const TextDecoder = globalThis.TextDecoder || require('util').TextDecoder
const decoder = new TextDecoder()
let buf = ''

Expand Down
5 changes: 5 additions & 0 deletions packages/ipfs-utils/src/text-encoder.browser.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
'use strict'

const global = require('./globalthis')

module.exports = global.TextDecoder
2 changes: 2 additions & 0 deletions packages/ipfs-utils/src/text-encoder.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
'use strict'
module.exports = require('util').TextDecoder
4 changes: 2 additions & 2 deletions packages/ipfs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@
"ipld": "^0.25.0",
"ipld-bitcoin": "^0.3.0",
"ipld-dag-cbor": "^0.15.1",
"ipld-dag-pb": "^0.18.2",
"ipld-dag-pb": "^0.18.3",
"ipld-ethereum": "^4.0.0",
"ipld-git": "^0.5.0",
"ipld-raw": "^4.0.1",
Expand Down Expand Up @@ -182,7 +182,7 @@
"go-ipfs-dep": "0.4.23-3",
"hat": "0.0.3",
"interface-ipfs-core": "^0.132.0",
"ipfs-interop": "^1.0.0",
"ipfs-interop": "ipfs/interop#fix/name-pubsub",
"ipfsd-ctl": "^3.0.0",
"it-first": "^1.0.1",
"ncp": "^2.0.0",
Expand Down

0 comments on commit 3207e3b

Please sign in to comment.