Skip to content
This repository has been archived by the owner on Mar 10, 2020. It is now read-only.

Commit

Permalink
perf: reduce bundle size (#915)
Browse files Browse the repository at this point in the history
  • Loading branch information
hugomrdias authored and Alan Shaw committed Mar 15, 2019
1 parent c3cde76 commit 87dff04
Show file tree
Hide file tree
Showing 19 changed files with 72 additions and 81 deletions.
1 change: 1 addition & 0 deletions .aegir.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const createServer = require('ipfsd-ctl').createServer
const server = createServer()

module.exports = {
bundlesize: { maxSize: '231kB' },
webpack: {
resolve: {
mainFields: ['browser', 'main']
Expand Down
11 changes: 3 additions & 8 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ jobs:

- stage: check
script:
- npx aegir build --bundlesize
- npx aegir commitlint --travis
- npx aegir dep-check
- npm run lint
Expand All @@ -31,19 +32,13 @@ jobs:
name: chrome
addons:
chrome: stable
script: npx aegir test -t browser
script: npx aegir test -t browser -t webworker

- stage: test
name: firefox
addons:
firefox: latest
script: npx aegir test -t browser -- --browsers FirefoxHeadless

- stage: test
name: webworker
addons:
chrome: stable
script: npx aegir test -t webworker
script: npx aegir test -t browser -t webworker -- --browsers FirefoxHeadless

notifications:
email: false
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,19 @@
<a href="http://ipfs.io/"><img src="https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square" /></a>
<a href="http://webchat.freenode.net/?channels=%23ipfs"><img src="https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square" /></a>
<a href="https://waffle.io/ipfs/js-ipfs"><img src="https://img.shields.io/badge/pm-waffle-blue.svg?style=flat-square" /></a>
<a href="https://github.com/ipfs/interface-ipfs-core"><img src="https://img.shields.io/badge/interface--ipfs--core-API%20Docs-blue.svg"></a>
<a href="https://github.com/ipfs/interface-ipfs-core"><img src="https://img.shields.io/badge/interface--ipfs--core-API%20Docs-blue.svg?style=flat-square"></a>
</p>

<p align="center">
<a href="https://app.fossa.io/projects/git%2Bhttps%3A%2F%2Fgit.luolix.top%2Fipfs%2Fjs-ipfs-http-client?ref=badge_small" alt="FOSSA Status"><img src="https://app.fossa.io/api/projects/git%2Bhttps%3A%2F%2Fgit.luolix.top%2Fipfs%2Fjs-ipfs-http-client.svg?type=small"/></a>
<a href="https://travis-ci.com/ipfs/js-ipfs-http-client"><img src="https://flat.badgen.net/travis/ipfs/js-ipfs-http-client" /></a>
<a href="https://codecov.io/gh/ipfs/js-ipfs-http-client"><img src="https://codecov.io/gh/ipfs/js-ipfs-http-client/branch/master/graph/badge.svg"></a>
<a href="https://codecov.io/gh/ipfs/js-ipfs-http-client"><img src="https://img.shields.io/codecov/c/github/ipfs/js-ipfs-http-client/master.svg?style=flat-square"></a>
<a href="https://bundlephobia.com/result?p=ipfs-http-client"><img src="https://flat.badgen.net/bundlephobia/minzip/ipfs-http-client"></a>
<br>
<a href="https://david-dm.org/ipfs/js-ipfs-http-client"><img src="https://david-dm.org/ipfs/js-ipfs-http-client.svg?style=flat-square" /></a>
<a href="https://github.com/feross/standard"><img src="https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square"></a>
<a href="https://github.com/RichardLitt/standard-readme"><img src="https://img.shields.io/badge/standard--readme-OK-green.svg?style=flat-square" /></a>
<a href=""><img src="https://img.shields.io/badge/npm-%6E%3D3.0.0-orange.svg?style=flat-square" /></a>
<a href=""><img src="https://img.shields.io/badge/npm-%3E%3D3.0.0-orange.svg?style=flat-square" /></a>
<a href=""><img src="https://img.shields.io/badge/Node.js-%3E%3D10.0.0-orange.svg?style=flat-square" /></a>
<br>
</p>
Expand Down
49 changes: 22 additions & 27 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
"browser": {
"glob": false,
"fs": false,
"stream": "readable-stream",
"http": "stream-http"
"stream": "readable-stream"
},
"scripts": {
"test": "aegir test",
Expand All @@ -20,53 +19,50 @@
"release": "aegir release ",
"release-minor": "aegir release --type minor ",
"release-major": "aegir release --type major ",
"coverage": "aegir coverage --timeout 100000",
"coverage-publish": "aegir coverage --provider coveralls --timeout 100000",
"dep-check": "npx dependency-check package.json './test/**/*.js' './src/**/*.js'"
"coverage": "npx nyc -r html npm run test:node -- --bail"
},
"dependencies": {
"async": "^2.6.1",
"bignumber.js": "^8.0.2",
"bl": "^2.1.2",
"bl": "^3.0.0",
"bs58": "^4.0.1",
"cids": "~0.5.5",
"concat-stream": "^2.0.0",
"concat-stream": "hugomrdias/concat-stream#feat/smaller",
"debug": "^4.1.0",
"detect-node": "^2.0.4",
"end-of-stream": "^1.4.1",
"err-code": "^1.1.2",
"flatmap": "0.0.3",
"glob": "^7.1.3",
"ipfs-block": "~0.8.0",
"ipfs-unixfs": "~0.1.16",
"ipld-dag-cbor": "~0.13.0",
"ipld-dag-pb": "~0.15.0",
"is-ipfs": "~0.4.7",
"ipld-dag-cbor": "~0.13.1",
"ipld-dag-pb": "~0.15.3",
"is-ipfs": "~0.6.0",
"is-pull-stream": "0.0.0",
"is-stream": "^1.1.0",
"libp2p-crypto": "~0.16.0",
"lodash": "^4.17.11",
"iso-stream-http": "~0.1.1",
"iso-url": "~0.4.6",
"just-kebab-case": "^1.1.0",
"just-map-keys": "^1.1.0",
"lru-cache": "^5.1.1",
"multiaddr": "^6.0.0",
"multiaddr": "^6.0.6",
"multibase": "~0.6.0",
"multicodec": "~0.5.0",
"multihashes": "~0.4.14",
"ndjson": "^1.5.0",
"ndjson": "hugomrdias/ndjson#feat/readable-stream3",
"once": "^1.4.0",
"peer-id": "~0.12.1",
"peer-info": "~0.15.0",
"peer-id": "~0.12.2",
"peer-info": "~0.15.1",
"promisify-es6": "^1.0.3",
"pull-defer": "~0.2.3",
"pull-pushable": "^2.2.0",
"pull-stream-to-stream": "^1.3.4",
"pull-stream": "^3.6.9",
"pull-to-stream": "~0.1.0",
"pump": "^3.0.0",
"qs": "^6.5.2",
"readable-stream": "^3.0.6",
"stream-http": "^3.0.0",
"readable-stream": "^3.1.1",
"stream-to-pull-stream": "^1.7.2",
"streamifier": "~0.1.1",
"tar-stream": "^1.6.2",
"through2": "^3.0.0"
"tar-stream": "^2.0.1",
"through2": "^3.0.1"
},
"engines": {
"node": ">=10.0.0",
Expand All @@ -77,7 +73,7 @@
"url": "https://github.com/ipfs/js-ipfs-http-client"
},
"devDependencies": {
"aegir": "^18.0.2",
"aegir": "^18.2.1",
"browser-process-platform": "~0.1.1",
"chai": "^4.2.0",
"cross-env": "^5.2.0",
Expand All @@ -87,7 +83,6 @@
"interface-ipfs-core": "~0.99.0",
"ipfsd-ctl": "~0.42.0",
"nock": "^10.0.2",
"pull-stream": "^3.6.9",
"stream-equal": "^1.1.1"
},
"keywords": [
Expand Down Expand Up @@ -182,4 +177,4 @@
"url": "https://github.com/ipfs/js-ipfs-http-client/issues"
},
"homepage": "https://github.com/ipfs/js-ipfs-http-client"
}
}
13 changes: 11 additions & 2 deletions src/config/replace.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,23 @@
'use strict'

const streamifier = require('streamifier')
const { Readable } = require('readable-stream')
const promisify = require('promisify-es6')
const SendOneFile = require('../utils/send-one-file')

function toStream (input) {
return new Readable({
read () {
this.push(input)
this.push(null)
}
})
}

module.exports = (send) => {
const sendOneFile = SendOneFile(send, 'config/replace')
return promisify((config, callback) => {
if (typeof config === 'object') {
config = streamifier.createReadStream(Buffer.from(JSON.stringify(config)))
config = toStream(Buffer.from(JSON.stringify(config)))
}

sendOneFile(config, {}, callback)
Expand Down
2 changes: 1 addition & 1 deletion src/files-mfs/ls-readable-stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
const {
Transform,
PassThrough
} = require('stream')
} = require('readable-stream')
const pump = require('pump')
const ndjson = require('ndjson')
const isStream = require('is-stream')
Expand Down
4 changes: 2 additions & 2 deletions src/files-mfs/stat.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
'use strict'

const promisify = require('promisify-es6')
const mapKeys = require('lodash/mapKeys')
const kebabCase = require('lodash/kebabCase')
const mapKeys = require('just-map-keys')
const kebabCase = require('just-kebab-case')

const transform = function (data, callback) {
callback(null, {
Expand Down
6 changes: 3 additions & 3 deletions src/files-regular/add-from-url.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
'use strict'

const promisify = require('promisify-es6')
const { URL } = require('url')
const request = require('../utils/request')
const { URL } = require('iso-url')
const { getRequest } = require('iso-stream-http')
const SendOneFile = require('../utils/send-one-file-multiple-results')
const FileResultStreamConverter = require('../utils/file-result-stream-converter')

Expand Down Expand Up @@ -37,7 +37,7 @@ const validUrl = (url) => typeof url === 'string' && url.startsWith('http')
const requestWithRedirect = (url, opts, sendOneFile, callback) => {
const parsedUrl = new URL(url)

const req = request(parsedUrl.protocol)(url, (res) => {
const req = getRequest(parsedUrl, (res) => {
if (res.statusCode >= 400) {
return callback(new Error(`Failed to download with ${res.statusCode}`))
}
Expand Down
3 changes: 1 addition & 2 deletions src/files-regular/add.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ const promisify = require('promisify-es6')
const ConcatStream = require('concat-stream')
const once = require('once')
const isStream = require('is-stream')
const isString = require('lodash/isString')
const isSource = require('is-pull-stream').isSource
const FileResultStreamConverter = require('../utils/file-result-stream-converter')
const SendFilesStream = require('../utils/send-files-stream')
Expand Down Expand Up @@ -33,7 +32,7 @@ module.exports = (send) => {
// path is optional if content is present
if (obj.content) return isBufferOrStream(obj.content)
// path must be a non-empty string if no content
return Boolean(obj.path) && isString(obj.path)
return Boolean(obj.path) && typeof obj.path === 'string'
}
// An input atom: a buffer, stream or content object
const isInput = obj => isBufferOrStream(obj) || isContentObject(obj)
Expand Down
5 changes: 3 additions & 2 deletions src/files-regular/get-pull-stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
const cleanCID = require('../utils/clean-cid')
const TarStreamToObjects = require('../utils/tar-stream-to-objects')
const v = require('is-ipfs')
const pull = require('pull-stream')
const pull = require('pull-stream/pull')
const map = require('pull-stream/throughs/map')
const toPull = require('stream-to-pull-stream')
const deferred = require('pull-defer')

Expand All @@ -30,7 +31,7 @@ module.exports = (send) => {
p.resolve(
pull(
toPull.source(stream),
pull.map(file => {
map(file => {
const { path, content } = file
return content ? { path, content: toPull.source(content) } : file
})
Expand Down
4 changes: 2 additions & 2 deletions src/files-regular/ls-pull-stream.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict'

const moduleConfig = require('../utils/module-config')
const pull = require('pull-stream')
const values = require('pull-stream/sources/values')
const deferred = require('pull-defer')
const IsIpfs = require('is-ipfs')
const cleanCID = require('../utils/clean-cid')
Expand Down Expand Up @@ -54,7 +54,7 @@ module.exports = (arg) => {
type: typeOf(link)
}))

p.resolve(pull.values(result))
p.resolve(values(result))
})

return p
Expand Down
3 changes: 1 addition & 2 deletions src/pin/ls.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
'use strict'

const promisify = require('promisify-es6')
const keys = require('lodash/keys')

module.exports = (send) => {
return promisify((hash, opts, callback) => {
Expand All @@ -26,7 +25,7 @@ module.exports = (send) => {
if (err) {
return callback(err)
}
callback(null, keys(res.Keys).map(hash => (
callback(null, Object.keys(res.Keys).map(hash => (
{ hash, type: res.Keys[hash].Type }
)))
})
Expand Down
5 changes: 3 additions & 2 deletions src/stats/bw-pull-stream.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
'use strict'

const toPull = require('stream-to-pull-stream')
const pull = require('pull-stream')
const map = require('pull-stream/throughs/map')
const pull = require('pull-stream/pull')
const transformChunk = require('./bw-util')
const deferred = require('pull-defer')

Expand All @@ -21,7 +22,7 @@ module.exports = (send) => {

p.resolve(pull(
toPull.source(stream),
pull.map(transformChunk)
map(transformChunk)
))
})

Expand Down
6 changes: 3 additions & 3 deletions src/utils/multipart.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
'use strict'

const Transform = require('stream').Transform
const Transform = require('readable-stream').Transform
const isNode = require('detect-node')
const isSource = require('is-pull-stream').isSource
const toStream = require('pull-stream-to-stream')
const toStream = require('pull-to-stream')

const PADDING = '--'
const NEW_LINE = '\r\n'
Expand Down Expand Up @@ -78,7 +78,7 @@ class Multipart extends Transform {
}

if (isSource(content)) {
content = toStream.source(content)
content = toStream.readable(content)
}

// From now on we assume content is a stream
Expand Down
12 changes: 0 additions & 12 deletions src/utils/request.js

This file was deleted.

2 changes: 1 addition & 1 deletion src/utils/send-files-stream.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict'

const Duplex = require('stream').Duplex
const { Duplex } = require('readable-stream')
const eachSeries = require('async/eachSeries')
const isStream = require('is-stream')
const once = require('once')
Expand Down
4 changes: 2 additions & 2 deletions src/utils/send-request.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ const isNode = require('detect-node')
const ndjson = require('ndjson')
const pump = require('pump')
const once = require('once')
const { getRequest } = require('iso-stream-http')
const streamToValue = require('./stream-to-value')
const streamToJsonValue = require('./stream-to-json-value')
const request = require('./request')
const log = require('debug')('ipfs-http-client:request')

// -- Internal
Expand Down Expand Up @@ -171,7 +171,7 @@ function requestAPI (config, options, callback) {
protocol: `${config.protocol}:`
}

const req = request(config.protocol)(reqOptions, onRes(options.buffer, callback))
const req = getRequest(reqOptions, onRes(options.buffer, callback))

req.on('error', (err) => {
callback(err)
Expand Down
Loading

0 comments on commit 87dff04

Please sign in to comment.