@magic/fs 0.0.33 → 0.0.35

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.
package/README.md CHANGED
@@ -321,7 +321,16 @@ update dependencies
321
321
 
322
322
  - fix import mapping from .mjs to .js
323
323
 
324
- ##### 0.0.34 - unreleased
324
+ ##### 0.0.34
325
+
326
+ - update types
327
+
328
+ ##### 0.0.35
329
+
330
+ - fs.getDirectories maxDepth will be at least 2 if noRoot is set.
331
+ - update dependencies
332
+
333
+ ##### 0.0.36 - unreleased
325
334
 
326
335
  ...
327
336
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@magic/fs",
3
- "version": "0.0.33",
3
+ "version": "0.0.35",
4
4
  "author": "Wizards & Witches",
5
5
  "description": "nodejs fs promises + goodies",
6
6
  "license": "AGPL-3.0",
@@ -42,8 +42,8 @@
42
42
  "@magic-themes/docs": "0.0.15",
43
43
  "@magic/core": "0.0.156",
44
44
  "@magic/format": "0.0.68",
45
- "@magic/test": "0.2.22",
46
- "@types/node": "24.7.2",
45
+ "@magic/test": "0.2.24",
46
+ "@types/node": "24.9.1",
47
47
  "typescript": "5.9.3"
48
48
  },
49
49
  "dependencies": {
@@ -10,18 +10,9 @@ import { getFilePath } from './getFilePath.js'
10
10
 
11
11
  const libName = '@magic/fs.getDirectories'
12
12
 
13
- /**
14
- * @typedef {object} Options
15
- * @property {string} [root]
16
- * @property {number} [maxDepth]
17
- * @property {number} [minDepth]
18
- * @property {boolean | number} [depth]
19
- * @property {boolean} [noRoot]
20
- */
21
-
22
13
  /**
23
14
  * @param {string | string[]} dir
24
- * @param {number | false | Options} [options]
15
+ * @param {number | false | { root?: string, maxDepth?: number, minDepth?: number, depth?: boolean | number, noRoot?: boolean }} [options]
25
16
  * if options is a number, its the max depth of recursion.
26
17
  * if it is false, maxDepth is set to 1
27
18
  * @returns {Promise<string[]>}
@@ -47,6 +38,10 @@ export const getDirectories = async (dir, options = {}) => {
47
38
  minDepth = 0
48
39
  }
49
40
 
41
+ if (noRoot && maxDepth === 1) {
42
+ maxDepth += 1
43
+ }
44
+
50
45
  if (!is.array(dir) && !is.string(dir)) {
51
46
  throw error(`${libName}: need an array or a string as first argument`, 'E_ARG_TYPE')
52
47
  }
@@ -8,18 +8,11 @@ import { fs } from './fs.js'
8
8
  const libName = '@magic/fs.getFilePath'
9
9
 
10
10
  /**
11
- * @typedef {typeof import('./getFiles.js').getFiles} GetFiles
12
- * @typedef {import('./getFiles.js').Options} GetFilesOptions
13
- * @typedef {typeof import('./getDirectories.js').getDirectories} GetDirectories
14
11
  *
15
- */
16
-
17
- /**
18
- *
19
- * @param {GetFiles | GetDirectories} fn
12
+ * @param {import('./getFiles.js').getFiles | import('./getDirectories.js').getDirectories} fn
20
13
  * @param {string} dir
21
14
  * @param {string} file
22
- * @param {GetFilesOptions} args
15
+ * @param {number | {minDepth?: number, maxDepth?: number, depth?: number | false, extension?: string, ext?: string, root?: string}} [args]
23
16
  * @returns {Promise<string | string[] | undefined>}
24
17
  */
25
18
  export const getFilePath = async (fn, dir, file, args = {}) => {
package/src/getFiles.js CHANGED
@@ -9,24 +9,11 @@ import { fs } from './fs.js'
9
9
 
10
10
  const libName = '@magic/fs.getFiles'
11
11
 
12
- /**
13
- * @typedef {object} Options
14
- * @property {number} [minDepth]
15
- * @property {number} [maxDepth]
16
- * @property {number | false} [depth]
17
- * @property {string} [extension]
18
- * @property {string} [ext]
19
- * @property {string} [root]
20
- */
21
-
22
12
  /**
23
13
  * @param {string} dir
24
- * First argument: directory to scan
25
- * @param {number | Options} [options]
26
- * If number, sets maxDepth directly.
14
+ * @param {number | {minDepth?: number, maxDepth?: number, depth?: number | false, extension?: string, ext?: string, root?: string}} [options]
27
15
  * @returns {Promise<string[]>}
28
16
  */
29
-
30
17
  export const getFiles = async (dir, options = {}) => {
31
18
  if (is.number(options)) {
32
19
  options = {
package/src/rmrf.js CHANGED
@@ -9,17 +9,13 @@ const cwd = process.cwd()
9
9
 
10
10
  const libName = '@magic/fs.rmrf'
11
11
 
12
- /**
13
- * @typedef {object} Options
14
- * @property {boolean} [dryRun]
15
- */
16
-
17
12
  /**
18
13
  * Recursively removes a file or directory.
19
14
  *
20
15
  * @throws {Error} If the argument is invalid, outside cwd, or fs operations fail.
21
16
  * @param {string} dir
22
- * @param {Options} [opts]
17
+ * @param {object} [opts]
18
+ * @param {boolean} [opts.dryRun]
23
19
  * @returns {Promise<boolean | undefined>}
24
20
  */
25
21
  export const rmrf = async (dir, opts = {}) => {
@@ -1,11 +1,13 @@
1
1
  export function getDirectories(
2
2
  dir: string | string[],
3
- options?: number | false | Options,
3
+ options?:
4
+ | number
5
+ | false
6
+ | {
7
+ root?: string
8
+ maxDepth?: number
9
+ minDepth?: number
10
+ depth?: boolean | number
11
+ noRoot?: boolean
12
+ },
4
13
  ): Promise<string[]>
5
- export type Options = {
6
- root?: string | undefined
7
- maxDepth?: number | undefined
8
- minDepth?: number | undefined
9
- depth?: number | boolean | undefined
10
- noRoot?: boolean | undefined
11
- }
@@ -1,9 +1,41 @@
1
1
  export function getFilePath(
2
- fn: GetFiles | GetDirectories,
2
+ fn:
3
+ | ((
4
+ dir: string,
5
+ options?:
6
+ | number
7
+ | {
8
+ minDepth?: number
9
+ maxDepth?: number
10
+ depth?: number | false
11
+ extension?: string
12
+ ext?: string
13
+ root?: string
14
+ },
15
+ ) => Promise<string[]>)
16
+ | ((
17
+ dir: string | string[],
18
+ options?:
19
+ | number
20
+ | false
21
+ | {
22
+ root?: string
23
+ maxDepth?: number
24
+ minDepth?: number
25
+ depth?: boolean | number
26
+ noRoot?: boolean
27
+ },
28
+ ) => Promise<string[]>),
3
29
  dir: string,
4
30
  file: string,
5
- args?: GetFilesOptions,
31
+ args?:
32
+ | number
33
+ | {
34
+ minDepth?: number
35
+ maxDepth?: number
36
+ depth?: number | false
37
+ extension?: string
38
+ ext?: string
39
+ root?: string
40
+ },
6
41
  ): Promise<string | string[] | undefined>
7
- export type GetFiles = typeof import('./getFiles.js').getFiles
8
- export type GetFilesOptions = import('./getFiles.js').Options
9
- export type GetDirectories = typeof import('./getDirectories.js').getDirectories
@@ -1,9 +1,13 @@
1
- export function getFiles(dir: string, options?: number | Options): Promise<string[]>
2
- export type Options = {
3
- minDepth?: number | undefined
4
- maxDepth?: number | undefined
5
- depth?: number | false | undefined
6
- extension?: string | undefined
7
- ext?: string | undefined
8
- root?: string | undefined
9
- }
1
+ export function getFiles(
2
+ dir: string,
3
+ options?:
4
+ | number
5
+ | {
6
+ minDepth?: number
7
+ maxDepth?: number
8
+ depth?: number | false
9
+ extension?: string
10
+ ext?: string
11
+ root?: string
12
+ },
13
+ ): Promise<string[]>
package/types/index.d.ts CHANGED
@@ -1,19 +1,80 @@
1
1
  export const fs: {
2
2
  readonly mkdirp: (p: string) => Promise<boolean | void>
3
- readonly rmrf: (dir: string, opts?: Options) => Promise<boolean | undefined>
3
+ readonly rmrf: (
4
+ dir: string,
5
+ opts?: {
6
+ dryRun?: boolean | undefined
7
+ },
8
+ ) => Promise<boolean | undefined>
4
9
  readonly getFileType: (name: string) => string
5
10
  readonly getDirectories: (
6
11
  dir: string | string[],
7
- options?: number | false | Options,
12
+ options?:
13
+ | number
14
+ | false
15
+ | {
16
+ root?: string
17
+ maxDepth?: number
18
+ minDepth?: number
19
+ depth?: boolean | number
20
+ noRoot?: boolean
21
+ },
22
+ ) => Promise<string[]>
23
+ readonly getFiles: (
24
+ dir: string,
25
+ options?:
26
+ | number
27
+ | {
28
+ minDepth?: number
29
+ maxDepth?: number
30
+ depth?: number | false
31
+ extension?: string
32
+ ext?: string
33
+ root?: string
34
+ },
8
35
  ) => Promise<string[]>
9
- readonly getFiles: (dir: string, options?: number | Options) => Promise<string[]>
10
36
  readonly exists: (f: import('fs').PathLike) => Promise<boolean>
11
37
  readonly getContentType: (uri: string) => string
12
38
  readonly getFilePath: (
13
- fn: GetFiles | GetDirectories,
39
+ fn:
40
+ | ((
41
+ dir: string,
42
+ options?:
43
+ | number
44
+ | {
45
+ minDepth?: number
46
+ maxDepth?: number
47
+ depth?: number | false
48
+ extension?: string
49
+ ext?: string
50
+ root?: string
51
+ },
52
+ ) => Promise<string[]>)
53
+ | ((
54
+ dir: string | string[],
55
+ options?:
56
+ | number
57
+ | false
58
+ | {
59
+ root?: string
60
+ maxDepth?: number
61
+ minDepth?: number
62
+ depth?: boolean | number
63
+ noRoot?: boolean
64
+ },
65
+ ) => Promise<string[]>),
14
66
  dir: string,
15
67
  file: string,
16
- args?: GetFilesOptions,
68
+ args?:
69
+ | number
70
+ | {
71
+ minDepth?: number
72
+ maxDepth?: number
73
+ depth?: number | false
74
+ extension?: string
75
+ ext?: string
76
+ root?: string
77
+ },
17
78
  ) => Promise<string | string[] | undefined>
18
79
  readonly readdir: typeof import('fs/promises').readdir
19
80
  readonly readDir: typeof import('fs/promises').readdir
package/types/rmrf.d.ts CHANGED
@@ -1,4 +1,6 @@
1
- export function rmrf(dir: string, opts?: Options): Promise<boolean | undefined>
2
- export type Options = {
3
- dryRun?: boolean | undefined
4
- }
1
+ export function rmrf(
2
+ dir: string,
3
+ opts?: {
4
+ dryRun?: boolean | undefined
5
+ },
6
+ ): Promise<boolean | undefined>