Skip to content

Commit 0c12c13

Browse files
committed
chore: upgrade ipfs to 0.55.x
Updates to the latest ipfs release. Some extra build config was needed because it uses optional chaining. This is supported out of the box by the version of acorn used by webpack 5 but vue is currently using webpack 4 so some extra config was necessary. Also uprades `to-buffer` - this now returns `Uint8Array`s instead of the node `Buffer` built in, which means you can't call `.toString(encoding)` on it any more, instead you need to use the global js `TextDecoder` class.
1 parent 805aaba commit 0c12c13

File tree

17 files changed

+13200
-53765
lines changed

17 files changed

+13200
-53765
lines changed

package-lock.json

Lines changed: 13146 additions & 53715 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,10 @@
3131
"googleapis": "^71.0.0",
3232
"highlight.js": "^9.12.0",
3333
"inquirer": "^7.1.0",
34-
"ipfs": "^0.50.2",
34+
"ipfs": "^0.55.1",
3535
"ipfs-css": "^0.6.0",
3636
"it-all": "^1.0.1",
37-
"it-to-buffer": "^1.0.1",
37+
"it-to-buffer": "^2.0.0",
3838
"lodash": "^4.17.19",
3939
"mailchimp-api-v3": "^1.13.1",
4040
"markdown-toc": "^1.2.0",
@@ -60,7 +60,10 @@
6060
"vuelidate": "^0.7.5"
6161
},
6262
"devDependencies": {
63+
"@babel/plugin-proposal-optional-chaining": "^7.14.2",
64+
"@babel/preset-env": "^7.14.2",
6365
"@cypress/webpack-preprocessor": "^4.1.1",
66+
"@vue/babel-preset-app": "^4.5.13",
6467
"@vue/cli-plugin-babel": "^3.12.1",
6568
"@vue/cli-plugin-eslint": "^3.12.1",
6669
"@vue/cli-service": "^3.12.1",
@@ -119,9 +122,7 @@
119122
}
120123
},
121124
"browserslist": [
122-
"> 1%",
123-
"last 2 versions",
124-
"not ie <= 8"
125+
"last 2 versions and not dead and > 2%"
125126
],
126127
"bin": {
127128
"protowizard": "./scripts/commands/wizard/index.js"

src/tutorials/0004-mutable-file-system/04.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ const validate = async (result, ipfs) => {
3636
let uploadedFilenames = uploadedFiles.map(file => file.name.toString()).sort()
3737
let ipfsFilenames = ipfsFiles.map(file => file.name.toString()).sort()
3838
let itemsMatch = JSON.stringify(ipfsFilenames) === JSON.stringify(uploadedFilenames)
39-
let itemsAreFiles = ipfsFiles.every(file => file.type === 0)
39+
let itemsAreFiles = ipfsFiles.every(file => file.type === 'file')
4040

4141
if (itemsMatch && itemsAreFiles) {
4242
return {

src/tutorials/0004-mutable-file-system/05.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ const validate = async (result, ipfs) => {
1414
let uploadedFilenames = uploadedFiles.map(file => file.name.toString()).sort()
1515
let ipfsFilenames = expected.map(file => file.name.toString()).sort()
1616
let itemsMatch = JSON.stringify(ipfsFilenames) === JSON.stringify(uploadedFilenames)
17-
let itemsAreFiles = expected.every(file => file.type === 0)
17+
let itemsAreFiles = expected.every(file => file.type === 'file')
1818
let rightFilesUploaded = itemsMatch && itemsAreFiles
1919

2020
if (!result) {

src/tutorials/0004-mutable-file-system/07.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@ const validate = async (result, ipfs) => {
1111
let stringifiedResult = JSON.stringify(result, null, 2)
1212
let ipfsFilesInRoot = await all(ipfs.files.ls('/'))
1313
let listedRoot = stringifiedResult === JSON.stringify(ipfsFilesInRoot, null, 2)
14-
let rootSomeItemIsFile = ipfsFilesInRoot.some(file => file.type === 0)
14+
let rootSomeItemIsFile = ipfsFilesInRoot.some(file => file.type === 'file')
1515

16-
const includesSome = ipfsFilesInRoot.some(file => file.name === 'some' && file.type === 1)
16+
const includesSome = ipfsFilesInRoot.some(file => file.name === 'some' && file.type === 'directory')
1717
if (includesSome) {
1818
const ipfsFilesInSome = await all(ipfs.files.ls('/some'))
1919
listedSome = stringifiedResult === JSON.stringify(ipfsFilesInSome, null, 2)
2020

21-
const includesStuff = ipfsFilesInSome.some(file => file.name === 'stuff' && file.type === 1)
21+
const includesStuff = ipfsFilesInSome.some(file => file.name === 'stuff' && file.type === 'directory')
2222
if (includesStuff) {
2323
const ipfsFilesInSomeStuff = await all(ipfs.files.ls('/some/stuff'))
2424
listedSomeStuff = stringifiedResult === JSON.stringify(ipfsFilesInSomeStuff, null, 2)

src/tutorials/0004-mutable-file-system/08.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ const validate = async (result, ipfs) => {
3333

3434
// check whether contents of /some/stuff are the right files
3535
itemsMatch = JSON.stringify(someStuffFilenames) === JSON.stringify(uploadedFilenames)
36-
itemsAreFiles = someStuffFiles.every(file => file.type === 0)
36+
itemsAreFiles = someStuffFiles.every(file => file.type === 'file')
3737
}
3838

3939
if (!result) {
@@ -61,7 +61,7 @@ const validate = async (result, ipfs) => {
6161
fail: utils.validationMessages.VALUE_IS_ASYNC_ITERABLE_ALL
6262
}
6363
} else if (rootIsEmpty) {
64-
return { fail: 'Your root directory is empty. Did you accidentally move the `some/stuff` directory? Remember to test whether each item is a file (`type === 0`) before moving it.' }
64+
return { fail: 'Your root directory is empty. Did you accidentally move the `some/stuff` directory? Remember to test whether each item is a file (`type === \'file\'`) before moving it.' }
6565
} else if (result instanceof Error && result.code === utils.ipfs.errorCodes.ERR_INVALID_PATH) {
6666
return {
6767
fail: 'Invalid path. Did you use just the file name when attempting to move each file? Remember to start the path with a leading `/`.',
@@ -119,11 +119,11 @@ const run = async (files) => {
119119
await ipfs.files.mkdir('/some/stuff', { parents: true })
120120
const rootDirectoryContents = await all(ipfs.files.ls('/'))
121121
122-
const filepathsToMove = rootDirectoryContents.filter(file => file.type === 0).map(file => '/' + file.name)
123-
await ipfs.files.mv(...filepathsToMove, '/some/stuff')
122+
const filepathsToMove = rootDirectoryContents.filter(file => file.type === 'file').map(file => '/' + file.name)
123+
await ipfs.files.mv(filepathsToMove, '/some/stuff')
124124
125125
// // alternatively, wrapping multiple mv calls into a single async function with await:
126-
// const filesToMove = rootDirectoryContents.filter(item => item.type === 0)
126+
// const filesToMove = rootDirectoryContents.filter(item => item.type === 'file')
127127
// await Promise.all(filesToMove.map(file => {
128128
// return ipfs.files.mv('/' + file.name, '/some/stuff')
129129
// }))

src/tutorials/0004-mutable-file-system/08.md

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ The method looks like this:
1111
await ipfs.files.mv(from, to, [options])
1212
```
1313

14-
`from` is the source path (or paths) of the content you'd like to move. `to` is the destination path.
14+
`from` is the source path (or paths) of the content you'd like to move and can be a string or an array of strings. `to` is the destination path.
1515

1616
If your destination path references parent directories that don't already exist, you'll need to use the `{ parents: true }` option, just as you did with `files.mkdir`.
1717

@@ -28,15 +28,9 @@ await ipfs.files.mv('/source-directory', '/destination-directory')
2828
await ipfs.files.mv('/source-file.txt', '/destination-file.txt')
2929
```
3030

31-
To move multiple files into a directory, you can add multiple source paths before the `to` argument:
31+
To move multiple files into a directory, you can pass `from` as an array of paths:
3232

3333
```js
3434
// move multiple files into a directory
35-
await ipfs.files.mv('/source-file-1.txt', '/source-file-2.txt', '/source-file-3.txt', '/destination-directory')
36-
```
37-
38-
If you're starting with an array of source paths, you can use JavaScript's [spread syntax](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Spread_syntax) to expand its elements into the required format:
39-
40-
```js
41-
await ipfs.files.mv(...fromArray, '/destination-directory')
35+
await ipfs.files.mv(['/source-file-1.txt', '/source-file-2.txt', '/source-file-3.txt'], '/destination-directory')
4236
```

src/tutorials/0004-mutable-file-system/09.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,8 @@ const run = async (files) => {
9191
await Promise.all(files.map(f => ipfs.files.write('/' + f.name, f, { create: true })))
9292
await ipfs.files.mkdir('/some/stuff', { parents: true })
9393
const rootDirectoryContents = await all(ipfs.files.ls('/'))
94-
const filepathsToMove = rootDirectoryContents.filter(file => file.type === 0).map(file => '/' + file.name)
95-
await ipfs.files.mv(...filepathsToMove, '/some/stuff')
94+
const filepathsToMove = rootDirectoryContents.filter(file => file.type === 'file').map(file => '/' + file.name)
95+
await ipfs.files.mv(filepathsToMove, '/some/stuff')
9696
9797
// Your code goes here
9898
@@ -109,8 +109,8 @@ const run = async (files) => {
109109
await Promise.all(files.map(f => ipfs.files.write('/' + f.name, f, { create: true })))
110110
await ipfs.files.mkdir('/some/stuff', { parents: true })
111111
const rootDirectoryContents = await all(ipfs.files.ls('/'))
112-
const filepathsToMove = rootDirectoryContents.filter(file => file.type === 0).map(file => '/' + file.name)
113-
await ipfs.files.mv(...filepathsToMove, '/some/stuff')
112+
const filepathsToMove = rootDirectoryContents.filter(file => file.type === 'file').map(file => '/' + file.name)
113+
await ipfs.files.mv(filepathsToMove, '/some/stuff')
114114
115115
await ipfs.files.cp('/ipfs/QmWCscor6qWPdx53zEQmZvQvuWQYxx1ARRCXwYVE4s9wzJ', '/some/stuff/success.txt')
116116

src/tutorials/0004-mutable-file-system/09.md

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ Unlike `files.mv`, which removes items from their source path when moving them t
77

88
The method looks like this:
99
```js
10-
await ipfs.files.cp(...from, to, [options])
10+
await ipfs.files.cp(from, to, [options])
1111
```
1212
However, you now have two formatting options for `from`. You can pass in either:
1313

@@ -25,11 +25,8 @@ You can use `files.cp` to perform a number of different operations:
2525
await ipfs.files.cp('/source-file.txt', '/destination-directory')
2626
await ipfs.files.cp('/ipfs/QmWGeRAEgtsHW3ec7U4qW2CyVy7eA2mFRVbk1nb24jFyks', '/destination-directory')
2727

28-
// copy multiple files into a directory (note the two acceptable formats with or without [ ])
29-
await ipfs.files.cp('/source-file-1.txt', '/source-file-2.txt', '/destination-directory')
28+
// copy multiple files into a directory (note `from` is now an array)
3029
await ipfs.files.cp(['/source-file-1.txt', '/source-file-2.txt'], '/destination-directory')
31-
await ipfs.files.cp('/ipfs/QmWGeRAEgtsHW3ec7U4qW2CyVy7eA2mFRVbk1nb24jFyks',
32-
'/ipfs/QmWGeRAEgtsHW3jk7U4qW2CyVy7eA2mFRVbk1nb24jFyre', '/destination-directory')
3330
await ipfs.files.cp(['/ipfs/QmWGeRAEgtsHW3ec7U4qW2CyVy7eA2mFRVbk1nb24jFyks',
3431
'/ipfs/QmWGeRAEgtsHW3jk7U4qW2CyVy7eA2mFRVbk1nb24jFyre'], '/destination-directory')
3532

src/tutorials/0004-mutable-file-system/10.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ const run = async (files) => {
3434
await Promise.all(files.map(f => ipfs.files.write('/' + f.name, f, { create: true })))
3535
await ipfs.files.mkdir('/some/stuff', { parents: true })
3636
let rootDirectoryContents = await all(ipfs.files.ls('/'))
37-
const filepathsToMove = rootDirectoryContents.filter(file => file.type === 0).map(file => '/' + file.name)
38-
await ipfs.files.mv(...filepathsToMove, '/some/stuff')
37+
const filepathsToMove = rootDirectoryContents.filter(file => file.type === 'file').map(file => '/' + file.name)
38+
await ipfs.files.mv(filepathsToMove, '/some/stuff')
3939
await ipfs.files.cp('/ipfs/QmWCscor6qWPdx53zEQmZvQvuWQYxx1ARRCXwYVE4s9wzJ', '/some/stuff/success.txt')
4040
let someStuffDirectoryContents = await all(ipfs.files.ls('/some/stuff'))
4141
@@ -53,12 +53,13 @@ const run = async (files) => {
5353
await Promise.all(files.map(f => ipfs.files.write('/' + f.name, f, { create: true })))
5454
await ipfs.files.mkdir('/some/stuff', { parents: true })
5555
let rootDirectoryContents = await all(ipfs.files.ls('/'))
56-
const filepathsToMove = rootDirectoryContents.filter(file => file.type === 0).map(file => '/' + file.name)
57-
await ipfs.files.mv(...filepathsToMove, '/some/stuff')
56+
const filepathsToMove = rootDirectoryContents.filter(file => file.type === 'file').map(file => '/' + file.name)
57+
await ipfs.files.mv(filepathsToMove, '/some/stuff')
5858
await ipfs.files.cp('/ipfs/QmWCscor6qWPdx53zEQmZvQvuWQYxx1ARRCXwYVE4s9wzJ', '/some/stuff/success.txt')
5959
let someStuffDirectoryContents = await all(ipfs.files.ls('/some/stuff'))
6060
61-
let secretMessage = (await toBuffer(ipfs.files.read('/some/stuff/success.txt'))).toString('utf8')
61+
let secretMessageContents = await toBuffer(ipfs.files.read('/some/stuff/success.txt'))
62+
let secretMessage = new TextDecoder().decode(secretMessageContents)
6263
6364
return secretMessage
6465
}

0 commit comments

Comments
 (0)