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

[WIP] perf: reduce bundle size #1795

Closed
wants to merge 16 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,14 @@ Enable and configure experimental features.

Modify the default IPFS node config. This object will be *merged* with the default config; it will not replace it.

##### `options.ipld`

| Type | Default |
|------|---------|
| object | [`ipld-nodejs.js`](https://github.com/ipfs/js-ipfs/tree/master/src/core/runtime/ipld-nodejs.js) in Node.js, [`ipld-browser.js`](https://github.com/ipfs/js-ipfs/tree/master/src/core/runtime/ipld-browser.js) in browsers |

Modify the default IPLD config. This object will be *merged* with the default config; it will not replace it. Check IPLD [docs](https://github.com/ipld/js-ipld#ipld-constructor) for more information on the available options.

##### `options.libp2p`

| Type | Default |
Expand Down
32 changes: 19 additions & 13 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"./src/core/runtime/libp2p-nodejs.js": "./src/core/runtime/libp2p-browser.js",
"./src/core/runtime/preload-nodejs.js": "./src/core/runtime/preload-browser.js",
"./src/core/runtime/repo-nodejs.js": "./src/core/runtime/repo-browser.js",
"./src/core/runtime/ipld-nodejs.js": "./src/core/runtime/ipld-browser.js",
"./test/utils/create-repo-nodejs.js": "./test/utils/create-repo-browser.js",
"stream": "readable-stream",
"joi": "joi-browser"
Expand Down Expand Up @@ -68,8 +69,8 @@
"execa": "^1.0.0",
"form-data": "^2.3.3",
"hat": "0.0.3",
"interface-ipfs-core": "~0.98.1",
"ipfsd-ctl": "~0.41.0",
"interface-ipfs-core": "~0.99.0",
"ipfsd-ctl": "~0.42.1",
"libp2p-websocket-star": "~0.10.2",
"ncp": "^2.0.0",
"qs": "^6.5.2",
Expand All @@ -78,11 +79,10 @@
"stream-to-promise": "^2.2.0"
},
"dependencies": {
"@nodeutils/defaults-deep": "^1.1.0",
"async": "^2.6.1",
"bignumber.js": "^8.0.2",
"binary-querystring": "~0.1.2",
"bl": "^2.1.2",
"bl": "^3.0.0",
"boom": "^7.2.0",
"bs58": "^4.0.1",
"byteman": "^1.3.5",
Expand All @@ -92,6 +92,7 @@
"datastore-core": "~0.6.0",
"datastore-pubsub": "~0.1.1",
"debug": "^4.1.0",
"dlv": "^1.1.2",
"err-code": "^1.1.2",
"file-type": "^10.2.0",
"fnv1a": "^1.0.1",
Expand All @@ -103,14 +104,14 @@
"hoek": "^6.1.2",
"human-to-milliseconds": "^1.0.0",
"interface-datastore": "~0.6.0",
"ipfs-bitswap": "~0.22.0",
"ipfs-bitswap": "~0.23.0",
"ipfs-block": "~0.8.0",
"ipfs-block-service": "~0.15.1",
"ipfs-http-client": "^29.0.0",
"ipfs-http-client": "^30.1.0",
"ipfs-http-response": "~0.2.1",
"ipfs-mfs": "~0.9.1",
"ipfs-multipart": "~0.1.0",
"ipfs-repo": "~0.26.1",
"ipfs-repo": "~0.26.4",
"ipfs-unixfs": "~0.1.16",
"ipfs-unixfs-engine": "~0.35.3",
"ipld": "~0.21.1",
Expand All @@ -120,27 +121,31 @@
"ipld-git": "~0.2.2",
"ipld-zcash": "~0.1.6",
"ipns": "~0.5.0",
"is-ipfs": "~0.4.8",
"is-ipfs": "~0.6.0",
"is-pull-stream": "~0.0.0",
"is-stream": "^1.1.0",
"iso-url": "~0.4.4",
"joi": "^14.3.0",
"joi-browser": "^13.4.0",
"joi-multiaddr": "^4.0.0",
"just-flatten-it": "^2.1.0",
"just-range": "^2.1.0",
"just-safe-set": "^2.1.0",
"libp2p": "~0.25.0-rc.3",
"libp2p-bootstrap": "~0.9.3",
"libp2p-crypto": "~0.16.0",
"libp2p-kad-dht": "~0.14.7",
"libp2p-keychain": "~0.3.3",
"libp2p-keychain": "~0.4.1",
"libp2p-mdns": "~0.12.0",
"libp2p-mplex": "~0.8.4",
"libp2p-record": "~0.6.1",
"libp2p-secio": "~0.11.0",
"libp2p-tcp": "~0.13.0",
"libp2p-webrtc-star": "~0.15.5",
"libp2p-websocket-star-multi": "~0.4.0",
"libp2p-websocket-star-multi": "~0.4.4",
"libp2p-websockets": "~0.12.2",
"lodash": "^4.17.11",
"mafmt": "^6.0.2",
"merge-options": "^1.0.1",
"mime-types": "^2.1.21",
"mkdirp": "~0.5.1",
"multiaddr": "^6.0.0",
Expand Down Expand Up @@ -170,12 +175,13 @@
"readable-stream": "^3.1.1",
"receptacle": "^1.3.2",
"stream-to-pull-stream": "^1.7.2",
"superstruct": "~0.6.0",
"tar-stream": "^2.0.0",
"temp": "~0.9.0",
"update-notifier": "^2.5.0",
"uri-to-multiaddr": "^3.0.1",
"varint": "^5.0.0",
"yargs": "^12.0.5",
"yargs": "^13.2.2",
"yargs-promise": "^1.1.0"
},
"optionalDependencies": {
Expand Down Expand Up @@ -295,4 +301,4 @@
"Łukasz Magiera <[email protected]>",
"Максим Ильин <[email protected]>"
]
}
}
14 changes: 10 additions & 4 deletions src/cli/commands/add.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
'use strict'

const sortBy = require('lodash/sortBy')
const pull = require('pull-stream')
const promisify = require('promisify-es6')
const getFolderSize = promisify(require('get-folder-size'))
Expand Down Expand Up @@ -37,8 +36,16 @@ function addPipeline (source, addStream, options) {
print(added.pop().hash)
return resolve()
}

sortBy(added, 'path')
added
.sort((a, b) => {
if (a.path > b.path) {
return 1
}
if (a.path < b.path) {
return -1
}
return 0
})
.reverse()
.map((file) => {
const log = options.quiet ? [] : ['added']
Expand All @@ -47,7 +54,6 @@ function addPipeline (source, addStream, options) {
return log.join(' ')
})
.forEach((msg) => print(msg))

resolve()
})
)
Expand Down
2 changes: 1 addition & 1 deletion src/core/components/dag.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const CID = require('cids')
const pull = require('pull-stream')
const mapAsync = require('async/map')
const setImmediate = require('async/setImmediate')
const flattenDeep = require('lodash/flattenDeep')
const flattenDeep = require('just-flatten-it')
const errCode = require('err-code')

module.exports = function dag (self) {
Expand Down
2 changes: 1 addition & 1 deletion src/core/components/files-regular/add-from-url.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict'

const { URL } = require('url')
const { URL } = require('iso-url')
const fetch = require('../../runtime/fetch-nodejs')

module.exports = (self) => {
Expand Down
3 changes: 1 addition & 2 deletions src/core/components/files-regular/add.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ const pull = require('pull-stream')
const sort = require('pull-sort')
const isStream = require('is-stream')
const isSource = require('is-pull-stream').isSource
const isString = require('lodash/isString')

module.exports = function (self) {
const add = promisify((data, options, callback) => {
Expand All @@ -24,7 +23,7 @@ module.exports = function (self) {
// 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
4 changes: 2 additions & 2 deletions src/core/components/init.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
'use strict'

const peerId = require('peer-id')
const mergeOptions = require('merge-options')
const waterfall = require('async/waterfall')
const parallel = require('async/parallel')
const promisify = require('promisify-es6')
const defaultsDeep = require('@nodeutils/defaults-deep')
const defaultConfig = require('../runtime/config-nodejs.js')
const Keychain = require('libp2p-keychain')
const {
Expand Down Expand Up @@ -59,7 +59,7 @@ module.exports = function init (self) {
opts.bits = Number(opts.bits) || 2048
opts.log = opts.log || function () {}

const config = defaultsDeep(self._options.config, defaultConfig())
const config = mergeOptions(defaultConfig(), self._options.config)
let privateKey

waterfall([
Expand Down
6 changes: 3 additions & 3 deletions src/core/components/libp2p.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
'use strict'

const get = require('lodash/get')
const defaultsDeep = require('@nodeutils/defaults-deep')
const get = require('dlv')
const ipnsUtils = require('../ipns/routing/utils')
const mergeOptions = require('merge-options')

module.exports = function libp2p (self, config) {
const options = self._options || {}
Expand Down Expand Up @@ -102,7 +102,7 @@ function defaultBundle ({ datastore, peerInfo, peerBook, options, config }) {
})
}

const libp2pOptions = defaultsDeep(get(options, 'libp2p', {}), libp2pDefaults)
const libp2pOptions = mergeOptions(libp2pDefaults, get(options, 'libp2p', {}))

// Required inline to reduce startup time
// Note: libp2p-nodejs gets replaced by libp2p-browser when webpacked/browserified
Expand Down
4 changes: 2 additions & 2 deletions src/core/components/pre-start.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
const peerId = require('peer-id')
const PeerInfo = require('peer-info')
const multiaddr = require('multiaddr')
const mergeOptions = require('merge-options')
const waterfall = require('async/waterfall')
const Keychain = require('libp2p-keychain')
const defaultsDeep = require('@nodeutils/defaults-deep')
const NoKeychain = require('./no-keychain')
/*
* Load stuff from Repo into memory
Expand All @@ -22,7 +22,7 @@ module.exports = function preStart (self) {
return cb(null, config)
}

config = defaultsDeep(self._options.config, config)
config = mergeOptions(config, self._options.config)

self.config.replace(config, (err) => {
if (err) {
Expand Down
2 changes: 1 addition & 1 deletion src/core/components/start.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

const series = require('async/series')
const Bitswap = require('ipfs-bitswap')
const get = require('lodash/get')
const get = require('dlv')
const setImmediate = require('async/setImmediate')
const promisify = require('promisify-es6')
const { TieredDatastore } = require('datastore-core')
Expand Down
5 changes: 2 additions & 3 deletions src/core/components/swarm.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
'use strict'

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

const OFFLINE_ERROR = require('../utils').OFFLINE_ERROR

Expand All @@ -25,7 +24,7 @@ module.exports = function swarm (self) {

const peers = []

values(self._peerInfoBook.getAll()).forEach((peer) => {
Object.values(self._peerInfoBook.getAll()).forEach((peer) => {
const connectedAddr = peer.isConnected()

if (!connectedAddr) { return }
Expand All @@ -50,7 +49,7 @@ module.exports = function swarm (self) {
return callback(new Error(OFFLINE_ERROR))
}

const peers = values(self._peerInfoBook.getAll())
const peers = Object.values(self._peerInfoBook.getAll())

callback(null, peers)
}),
Expand Down
Loading