Skip to content

Commit 33fb827

Browse files
authored
fix: update ipfs versions (#365)
Updates all examples to use ESM versions of IPFS, swaps parcel for vite everywhere and removes old browserify example because it only understands CJS.
1 parent f188aba commit 33fb827

File tree

10 files changed

+47
-47
lines changed

10 files changed

+47
-47
lines changed

README.md

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -84,15 +84,19 @@ By default IPFS is bundled with [dag-pb](https://www.npmjs.com/package/ipld-dag-
8484
To configure other types, we must pass the `ipld.formats` option to the `IPFS.create()` function:
8585

8686
```javascript
87-
const IPFS = require("ipfs");
87+
import * as IPFS from 'ipfs'
88+
import * as ipldGit from 'ipld-git'
89+
import * as ipldZcash from 'ipld-zcash'
90+
import * as ipldBitcoin from 'ipld-bitcoin'
91+
import * as ipldEth from 'ipld-ethereum'
8892

8993
const node = await IPFS.create({
9094
ipld: {
9195
formats: [
92-
require("ipld-git"),
93-
require("ipld-zcash"),
94-
require("ipld-bitcoin"),
95-
...Object.values(require("ipld-ethereum")), // this format exports multiple codecs so flatten into a list
96+
ipldGit,
97+
ipldZcash,
98+
ipldBitcoin,
99+
...Object.values(ipldEth), // this format exports multiple codecs so flatten into a list
96100
// etc, etc
97101
],
98102
},

create-node.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
'use strict'
2-
3-
const IPFS = require('ipfs-core')
1+
import * as IPFS from 'ipfs-core'
42

53
function createNode (options) {
64
options = options || {}
@@ -20,4 +18,4 @@ function createNode (options) {
2018
})
2119
}
2220

23-
module.exports = createNode
21+
export default createNode

eth.js

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,21 @@
1-
'use strict'
1+
import createNode from './create-node.js'
2+
import path from 'path'
3+
import { CID } from 'multiformats/cid'
4+
import * as MultihashDigest from 'multiformats/hashes/digest'
5+
import fs from 'fs/promises'
6+
import { toString as uint8ArrayToString } from 'uint8arrays/to-string'
7+
import { convert } from 'ipld-format-to-blockcodec'
8+
import sha3 from 'js-sha3'
9+
import { fileURLToPath } from 'url'
10+
import * as ipldEth from 'ipld-ethereum'
211

3-
const createNode = require('./create-node')
4-
const path = require('path')
5-
const { CID } = require('multiformats/cid')
6-
const MultihashDigest = require('multiformats/hashes/digest')
7-
const fs = require('fs').promises
8-
const { toString: uint8ArrayToString } = require('uint8arrays/to-string')
9-
const { convert } = require('ipld-format-to-blockcodec')
10-
const sha3 = require('js-sha3')
12+
const __dirname = path.dirname(fileURLToPath(import.meta.url))
1113

1214
async function main () {
1315
const ipfs = await createNode({
1416
ipld: {
1517
codecs: [
16-
...Object.values(require('ipld-ethereum')).map(format => convert(format))
18+
...Object.values(ipldEth).map(format => convert(format))
1719
],
1820
hashers: [{
1921
name: 'keccak-256',

get-path-accross-formats.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
'use strict'
2-
3-
const createNode = require('./create-node')
4-
const { fromString: uint8ArrayFromString } = require('uint8arrays/from-string')
1+
import createNode from './create-node.js'
2+
import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string'
53

64
async function main () {
75
const ipfs = await createNode()

get-path.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
'use strict'
2-
3-
const createNode = require('./create-node')
1+
import createNode from './create-node.js'
42

53
async function main () {
64
const ipfs = await createNode()

get.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
'use strict'
2-
3-
const createNode = require('./create-node')
1+
import createNode from './create-node.js'
42

53
async function main () {
64
const ipfs = await createNode()

git.js

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,21 @@
1-
'use strict'
1+
import createNode from './create-node.js'
2+
import path from 'path'
3+
import { CID } from 'multiformats/cid'
4+
import * as MultihashDigest from 'multiformats/hashes/digest'
5+
import fs from 'fs/promises'
6+
import { toString as uint8ArrayToString } from 'uint8arrays/to-string'
7+
import { convert } from 'ipld-format-to-blockcodec'
8+
import crypto from 'crypto'
9+
import { fileURLToPath } from 'url'
10+
import ipldGit from 'ipld-git'
211

3-
const createNode = require('./create-node')
4-
const path = require('path')
5-
const { CID } = require('multiformats/cid')
6-
const MultihashDigest = require('multiformats/hashes/digest')
7-
const fs = require('fs').promises
8-
const { toString: uint8ArrayToString } = require('uint8arrays/to-string')
9-
const { convert } = require('ipld-format-to-blockcodec')
10-
const crypto = require('crypto')
12+
const __dirname = path.dirname(fileURLToPath(import.meta.url))
1113

1214
async function main () {
1315
const ipfs = await createNode({
1416
ipld: {
1517
codecs: [
16-
convert(require('ipld-git'))
18+
convert(ipldGit)
1719
],
1820
hashers: [{
1921
name: 'sha1',

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"name": "example-traverse-ipld-graphs",
33
"version": "2.0.1",
44
"private": true,
5+
"type": "module",
56
"description": "How to traverse IPLD graphs",
67
"keywords": [],
78
"license": "MIT",
@@ -14,12 +15,12 @@
1415
},
1516
"dependencies": {
1617
"@ipld/dag-pb": "^2.1.3",
17-
"ipfs-core": "^0.14.0",
18+
"ipfs-core": "^0.15.2",
1819
"ipld-ethereum": "^6.0.0",
1920
"ipld-format-to-blockcodec": "0.0.1",
2021
"ipld-git": "^0.6.1",
2122
"js-sha3": "^0.8.0",
22-
"multiformats": "^9.4.1"
23+
"multiformats": "^9.6.5"
2324
},
2425
"devDependencies": {
2526
"test-util-ipfs-example": "^1.0.2"

put.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
'use strict'
2-
3-
const createNode = require('./create-node')
1+
import createNode from './create-node.js'
42

53
async function main () {
64
const ipfs = await createNode()

tests/test.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
'use strict'
1+
import path from 'path'
2+
import { node } from 'test-util-ipfs-example'
3+
import { fileURLToPath } from 'url'
24

3-
const path = require('path')
4-
const { node } = require('test-util-ipfs-example');
5+
const __dirname = path.dirname(fileURLToPath(import.meta.url))
56

67
async function runTest () {
78
console.info('Testing put.js')

0 commit comments

Comments
 (0)