presidium 0.25.2 → 0.26.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,6 @@
1
1
  require('rubico/global')
2
2
  const fs = require('fs/promises')
3
+ const { minimatch } = require('minimatch')
3
4
  const pathResolve = require('./pathResolve')
4
5
  const isArray = require('./isArray')
5
6
 
@@ -20,29 +21,36 @@ const isArray = require('./isArray')
20
21
  * }) // -> Promise<paths Array<string>>
21
22
  * ```
22
23
  */
23
- const pathWalk = function (path, options) {
24
- const ignore = new Set(get('ignore', [])(options))
25
- return pipe([
26
- pathResolve,
27
- tryCatch(
28
- curry.arity(2, fs.readdir, __, { withFileTypes: true }),
29
- () => []),
24
+ const pathWalk = async function (path, options = {}) {
25
+ const { ignore = [] } = options
26
+ const absPath = pathResolve(path)
27
+ const dirents = await fs.readdir(absPath, { withFileTypes: true })
28
+ const result = []
30
29
 
31
- flatMap(dirent => {
32
- const direntName = dirent.name,
33
- direntPath = pathResolve(path, direntName)
34
- if (
35
- ignore.size > 0
36
- && (ignore.has(direntName) || ignore.has(direntPath))
37
- ) {
38
- return []
30
+ for (const dirent of dirents) {
31
+ const dirName = dirent.name
32
+ const dirPath = pathResolve(path, dirName)
33
+ let shouldIgnore = false
34
+ for (const pattern of ignore) {
35
+ if (minimatch(dirPath, pattern) || minimatch(dirName, pattern)) {
36
+ shouldIgnore = true
37
+ break
39
38
  }
40
- if (dirent.isDirectory()) {
41
- return pathWalk(direntPath)
42
- }
43
- return [direntPath]
44
- }),
45
- ])(path)
39
+ }
40
+
41
+ if (shouldIgnore) {
42
+ continue
43
+ }
44
+
45
+ if (dirent.isDirectory()) {
46
+ const subPaths = await pathWalk(dirPath, options)
47
+ result.push(...subPaths)
48
+ } else {
49
+ result.push(dirPath)
50
+ }
51
+ }
52
+
53
+ return result
46
54
  }
47
55
 
48
56
  module.exports = pathWalk
@@ -3,14 +3,23 @@ const Test = require('thunk-test')
3
3
  const pathWalk = require('./pathWalk')
4
4
  const pathResolve = require('./pathResolve')
5
5
 
6
- module.exports = Test('pathWalk', pathWalk)
7
- .case(__dirname, function (paths) {
8
- assert(paths.length > 0)
9
- this.allInternalPaths = paths
10
- })
11
- .case(__dirname, { ignore: ['pathWalk.js'] }, function (paths) {
12
- assert.equal(paths.length, this.allInternalPaths.length - 1)
13
- })
14
- .case(__dirname, { ignore: [pathResolve(__dirname, 'pathWalk.js')] }, function (paths) {
15
- assert.equal(paths.length, this.allInternalPaths.length - 1)
16
- })
6
+ const test = Test('pathWalk', pathWalk)
7
+
8
+ .case(__dirname, function (paths) {
9
+ assert(paths.length > 0)
10
+ this.allInternalPaths = paths
11
+ })
12
+
13
+ .case(__dirname, { ignore: ['pathWalk.js'] }, function (paths) {
14
+ assert.equal(paths.length, this.allInternalPaths.length - 1)
15
+ })
16
+
17
+ .case(__dirname, { ignore: [pathResolve(__dirname, 'pathWalk.js')] }, function (paths) {
18
+ assert.equal(paths.length, this.allInternalPaths.length - 1)
19
+ })
20
+
21
+ if (process.argv[1] == __filename) {
22
+ test()
23
+ }
24
+
25
+ module.exports = test
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "presidium",
3
- "version": "0.25.2",
3
+ "version": "0.26.0",
4
4
  "description": "A library for creating web services",
5
5
  "author": "Richard Tong",
6
6
  "license": "MIT",
@@ -33,6 +33,7 @@
33
33
  "aws-sdk": "^2.1123.0",
34
34
  "bcrypt": "^5.1.0",
35
35
  "ioredis": "^4.19.0",
36
+ "minimatch": "^9.0.3",
36
37
  "mongodb": "^3.6.3",
37
38
  "node-fetch": "^2.6.1",
38
39
  "rubico": "latest",