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

Commit be4a542

Browse files
authored
feat: pull in new globSource (#3889)
* feat: pull in new globSource The new globSource module has a simpler api. Old: ```js await ipfs.addAll(globSource('*', { recursive: true, cwd: './somedir' }) ``` New: ```js await ipfs.addAll(globSource('./somedir', '**/*')) ``` See the [minimatch](https://www.npmjs.com/package/minimatch) docs for more on what the pattern supports. BREAKING CHANGE: the globSource api has changed from `globSource(dir, opts)` to `globSource(dir, pattern, opts)`
1 parent 5de1b13 commit be4a542

File tree

14 files changed

+44
-41
lines changed

14 files changed

+44
-41
lines changed

.github/workflows/test.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ jobs:
1515
with:
1616
node-version: 16
1717
- uses: actions/cache@v2
18+
id: cache
1819
env:
1920
CACHE_NAME: cache-node-modules
2021
with:
@@ -41,6 +42,7 @@ jobs:
4142
with:
4243
node-version: 16
4344
- uses: actions/cache@v2
45+
id: cache
4446
env:
4547
CACHE_NAME: cache-node-modules
4648
with:

docs/MODULE.md

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ Use the IPFS module as a dependency of your project to spawn in process instance
2323
- [`node.start()`](#nodestart)
2424
- [Static types and utils](#static-types-and-utils)
2525
- [Glob source](#glob-source)
26-
- [`globSource(path, [options])`](#globsourcepath-options)
26+
- [`globSource(path, pattern, [options])`](#globsourcepath-pattern-options)
2727
- [Example](#example)
2828
- [URL source](#url-source)
2929
- [`urlSource(url)`](#urlsourceurl)
@@ -398,12 +398,11 @@ import { CID } from 'ipfs'
398398

399399
A utility to allow files on the file system to be easily added to IPFS.
400400

401-
###### `globSource(path, [options])`
401+
###### `globSource(path, pattern, [options])`
402402

403403
- `path`: A path to a single file or directory to glob from
404+
- `pattern`: A pattern to match files under `path`
404405
- `options`: Optional options
405-
- `options.recursive`: If `path` is a directory, use option `{ recursive: true }` to add the directory and all its sub-directories.
406-
- `options.ignore`: To exclude file globs from the directory, use option `{ ignore: ['ignore/this/folder/**', 'and/this/file'] }`.
407406
- `options.hidden`: Hidden/dot files (files or folders starting with a `.`, for example, `.git/`) are not included by default. To add them, use the option `{ hidden: true }`.
408407

409408
Returns an async iterable that yields `{ path, content }` objects suitable for passing to `ipfs.add`.
@@ -415,7 +414,7 @@ import { create, globSource } from 'ipfs'
415414
416415
const ipfs = await create()
417416
418-
for await (const file of ipfs.addAll(globSource('./docs', { recursive: true }))) {
417+
for await (const file of ipfs.addAll(globSource('./docs', '**/*'))) {
419418
console.log(file)
420419
}
421420
/*

packages/interface-ipfs-core/package.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,7 @@
4444
"browser": {
4545
"fs": false,
4646
"os": false,
47-
"path": false,
48-
"ipfs-utils/src/files/glob-source": false
47+
"path": false
4948
},
5049
"scripts": {
5150
"clean": "rimraf ./dist",
@@ -76,7 +75,7 @@
7675
"ipfs-core-types": "^0.7.3",
7776
"ipfs-unixfs": "^6.0.3",
7877
"ipfs-unixfs-importer": "^9.0.3",
79-
"ipfs-utils": "^8.1.4",
78+
"ipfs-utils": "^9.0.1",
8079
"ipns": "^0.14.0",
8180
"is-ipfs": "^6.0.1",
8281
"iso-random-stream": "^2.0.0",

packages/interface-ipfs-core/src/add-all.js

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,7 @@ export function testAddAll (factory, options) {
397397
if (!isNode) this.skip()
398398
const filesPath = resolve('test/fixtures/test-folder', 'interface-ipfs-core')
399399

400-
const result = await all(ipfs.addAll(globSource(filesPath, { recursive: true })))
400+
const result = await all(ipfs.addAll(globSource(filesPath, '**/*')))
401401
expect(result.length).to.be.above(8)
402402
})
403403

@@ -407,7 +407,7 @@ export function testAddAll (factory, options) {
407407

408408
const filesPath = resolve('test/fixtures/weird name folder [v0]', 'interface-ipfs-core')
409409

410-
const result = await all(ipfs.addAll(globSource(filesPath, { recursive: true })))
410+
const result = await all(ipfs.addAll(globSource(filesPath, '**/*')))
411411
expect(result.length).to.be.above(8)
412412
})
413413

@@ -417,17 +417,17 @@ export function testAddAll (factory, options) {
417417

418418
const filesPath = resolve('test/fixtures/test-folder', 'interface-ipfs-core')
419419

420-
const result = await all(ipfs.addAll(globSource(filesPath, { recursive: true, ignore: ['files/**'] })))
421-
expect(result.length).to.be.below(9)
420+
const result = await all(ipfs.addAll(globSource(filesPath, '@(!(files*))')))
421+
expect(result.length).to.equal(6)
422422
})
423423

424424
it('should add a file from the file system', async function () {
425425
// @ts-ignore this is mocha
426426
if (!isNode) this.skip()
427427

428-
const filePath = resolve('test/fixtures/test-folder/ipfs-add.js', 'interface-ipfs-core')
428+
const filePath = resolve('test/fixtures/test-folder', 'interface-ipfs-core')
429429

430-
const result = await all(ipfs.addAll(globSource(filePath)))
430+
const result = await all(ipfs.addAll(globSource(filePath, 'ipfs-add.js')))
431431
expect(result.length).to.equal(1)
432432
expect(result[0].path).to.equal('ipfs-add.js')
433433
})
@@ -436,10 +436,9 @@ export function testAddAll (factory, options) {
436436
// @ts-ignore this is mocha
437437
if (!isNode) this.skip()
438438

439-
const filesPath = resolve('test/fixtures/hidden-files-folder', 'interface-ipfs-core')
439+
const filesPath = resolve('test/fixtures', 'interface-ipfs-core')
440440

441-
const result = await all(ipfs.addAll(globSource(filesPath, { recursive: true, hidden: true })))
442-
expect(result.length).to.be.above(10)
441+
const result = await all(ipfs.addAll(globSource(filesPath, 'hidden-files-folder/**/*', { hidden: true })))
443442
expect(result.map(object => object.path)).to.include('hidden-files-folder/.hiddenTest.txt')
444443
expect(result.map(object => object.cid.toString())).to.include('QmdbAjVmLRdpFyi8FFvjPfhTGB2cVXvWLuK7Sbt38HXrtt')
445444
})

packages/ipfs-cli/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,12 +71,13 @@
7171
"ipfs-daemon": "^0.9.8",
7272
"ipfs-http-client": "^52.0.5",
7373
"ipfs-repo": "^12.0.0",
74-
"ipfs-utils": "^8.1.4",
74+
"ipfs-utils": "^9.0.1",
7575
"it-all": "^1.0.4",
7676
"it-concat": "^2.0.0",
7777
"it-first": "^1.0.4",
7878
"it-glob": "1.0.0",
7979
"it-map": "^1.0.5",
80+
"it-merge": "^1.0.3",
8081
"it-pipe": "^1.1.0",
8182
"it-split": "^1.0.0",
8283
"it-tar": "^4.0.0",

packages/ipfs-cli/src/commands/add.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {
1313
} from '../utils.js'
1414
import globSource from 'ipfs-utils/src/files/glob-source.js'
1515
import parseDuration from 'parse-duration'
16+
import merge from 'it-merge'
1617

1718
const getFolderSize = promisify(getFolderSizeCb)
1819

@@ -286,15 +287,20 @@ export default {
286287
date = { secs: mtime, nsecs: mtimeNsecs }
287288
}
288289

290+
let pattern = '*'
291+
292+
if (recursive) {
293+
pattern = '**/*'
294+
}
295+
289296
const source = file
290-
? globSource(file, {
291-
recursive,
297+
? merge(...file.map(file => globSource(file, pattern, {
292298
hidden,
293299
preserveMode,
294300
preserveMtime,
295301
mode,
296302
mtime: date
297-
})
303+
})))
298304
: [{
299305
content: getStdin(),
300306
mode,

packages/ipfs-core-config/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@
8888
"err-code": "^3.0.1",
8989
"hashlru": "^2.3.0",
9090
"ipfs-repo": "^12.0.0",
91-
"ipfs-utils": "^8.1.4",
91+
"ipfs-utils": "^9.0.1",
9292
"ipns": "^0.14.0",
9393
"is-ipfs": "^6.0.1",
9494
"it-all": "^1.0.4",

packages/ipfs-core-utils/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@
112112
"err-code": "^3.0.1",
113113
"ipfs-core-types": "^0.7.3",
114114
"ipfs-unixfs": "^6.0.3",
115-
"ipfs-utils": "^8.1.4",
115+
"ipfs-utils": "^9.0.1",
116116
"it-all": "^1.0.4",
117117
"it-map": "^1.0.4",
118118
"it-peekable": "^1.0.2",

packages/ipfs-core/package.json

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,6 @@
4545
"import": "./src/components/config/profiles.js"
4646
}
4747
},
48-
"browser": {
49-
"ipfs-utils/src/files/glob-source": false
50-
},
5148
"repository": {
5249
"type": "git",
5350
"url": "git+https://github.com/ipfs/js-ipfs.git"
@@ -94,7 +91,7 @@
9491
"ipfs-unixfs": "^6.0.3",
9592
"ipfs-unixfs-exporter": "^7.0.3",
9693
"ipfs-unixfs-importer": "^9.0.3",
97-
"ipfs-utils": "^8.1.4",
94+
"ipfs-utils": "^9.0.1",
9895
"ipns": "^0.14.0",
9996
"is-domain-name": "^1.0.1",
10097
"is-ipfs": "^6.0.1",

packages/ipfs-daemon/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
"ipfs-grpc-server": "^0.6.6",
5151
"ipfs-http-gateway": "^0.6.5",
5252
"ipfs-http-server": "^0.7.6",
53-
"ipfs-utils": "^8.1.4",
53+
"ipfs-utils": "^9.0.1",
5454
"just-safe-set": "^2.2.1",
5555
"libp2p": "^0.32.0",
5656
"libp2p-webrtc-star": "^0.23.0"

packages/ipfs-http-client/README.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
- [Instance Utils](#instance-utils)
5050
- [Static Types and Utils](#static-types-and-utils)
5151
- [Glob source](#glob-source)
52-
- [`globSource(path, [options])`](#globsourcepath-options)
52+
- [`globSource(path, pattern, [options])`](#globsourcepath-pattern-options)
5353
- [Example](#example-1)
5454
- [URL source](#url-source)
5555
- [`urlSource(url)`](#urlsourceurl)
@@ -182,25 +182,25 @@ import { CID } from 'ipfs-http-client'
182182

183183
A utility to allow files on the file system to be easily added to IPFS.
184184

185-
##### `globSource(path, [options])`
185+
##### `globSource(path, pattern, [options])`
186186

187187
- `path`: A path to a single file or directory to glob from
188+
- `pattern`: A pattern to match files under `path`
188189
- `options`: Optional options
189-
- `options.recursive`: If `path` is a directory, use option `{ recursive: true }` to add the directory and all its sub-directories.
190-
- `options.ignore`: To exclude file globs from the directory, use option `{ ignore: ['ignore/this/folder/**', 'and/this/file'] }`.
191190
- `options.hidden`: Hidden/dot files (files or folders starting with a `.`, for example, `.git/`) are not included by default. To add them, use the option `{ hidden: true }`.
192191

193192
Returns an async iterable that yields `{ path, content }` objects suitable for passing to `ipfs.add`.
194193

195194
##### Example
196195

197196
```js
198-
import { create, globSource } from 'ipfs-http-client'
199-
const ipfs = create()
197+
import { create, globSource } from 'ipfs'
200198

201-
const file = await ipfs.add(globSource('./docs', { recursive: true }))
202-
console.log(file)
199+
const ipfs = await create()
203200

201+
for await (const file of ipfs.addAll(globSource('./docs', '**/*'))) {
202+
console.log(file)
203+
}
204204
/*
205205
{
206206
path: 'docs/assets/anchor.js',

packages/ipfs-http-client/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@
6262
"err-code": "^3.0.1",
6363
"ipfs-core-types": "^0.7.3",
6464
"ipfs-core-utils": "^0.10.5",
65-
"ipfs-utils": "^8.1.4",
65+
"ipfs-utils": "^9.0.1",
6666
"it-first": "^1.0.6",
6767
"it-last": "^1.0.4",
6868
"merge-options": "^3.0.4",

packages/ipfs-http-client/src/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
/* eslint-env browser */
32

43
import { Multibases } from 'ipfs-core-utils/multibases'
@@ -42,6 +41,7 @@ import { createResolve } from './resolve.js'
4241
import { createStart } from './start.js'
4342
import { createStop } from './stop.js'
4443
import { createVersion } from './version.js'
44+
import globSourceImport from 'ipfs-utils/src/files/glob-source.js'
4545

4646
/**
4747
* @typedef {import('./types').EndpointConfig} EndpointConfig
@@ -142,5 +142,5 @@ export function create (options = {}) {
142142

143143
export { CID } from 'multiformats/cid'
144144
export { Multiaddr as multiaddr } from 'multiaddr'
145-
export { default as globSource } from 'ipfs-utils/src/files/glob-source.js'
146145
export { default as urlSource } from 'ipfs-utils/src/files/url-source.js'
146+
export const globSource = globSourceImport

packages/ipfs/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,8 @@
8888
"ipfs-client": "^0.6.6",
8989
"ipfs-core-types": "^0.7.3",
9090
"ipfs-http-client": "^52.0.5",
91-
"ipfs-interop": "^6.0.1",
92-
"ipfs-utils": "^8.1.4",
91+
"ipfs-interop": "ipfs/interop#chore/update-globsource",
92+
"ipfs-utils": "^9.0.1",
9393
"ipfsd-ctl": "^10.0.3",
9494
"iso-url": "^1.0.0",
9595
"libp2p-webrtc-star": "^0.23.0",

0 commit comments

Comments
 (0)