@tryghost/mg-fs-utils 0.27.1 → 0.27.3
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 +1 -1
- package/lib/input.js +18 -4
- package/package.json +2 -3
package/README.md
CHANGED
|
@@ -58,7 +58,7 @@ const files = await fsUtils.listInputFiles('/path/to/exports', '*.zip');
|
|
|
58
58
|
// [{path: '/path/to/exports/a.zip', name: 'a.zip'}, {path: '/path/to/exports/b.zip', name: 'b.zip'}]
|
|
59
59
|
```
|
|
60
60
|
|
|
61
|
-
A file gives itself, named by its base name. A directory gives the files matching the
|
|
61
|
+
A file gives itself, named by its base name. A directory gives the files matching the glob pattern, sorted by path, named by their path relative to the directory with `/` separators. Directory scans use Node’s built-in globbing and include symlinks to regular files under the link’s own name. Broken links are skipped. Recursive patterns can omit files beneath symlinked directories. Hidden files are skipped by default. A directory with no matches gives an empty list, and a missing path rejects with `ENOENT`.
|
|
62
62
|
|
|
63
63
|
|
|
64
64
|
## Develop
|
package/lib/input.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import {stat} from 'node:fs/promises';
|
|
1
|
+
import {glob, stat} from 'node:fs/promises';
|
|
2
2
|
import {basename, relative, resolve} from 'node:path';
|
|
3
|
-
import fg from 'fast-glob';
|
|
4
3
|
|
|
5
4
|
/**
|
|
6
5
|
* Resolve an input path to the files a source reads: the file itself, or the files under a directory that match
|
|
@@ -10,7 +9,7 @@ import fg from 'fast-glob';
|
|
|
10
9
|
* relative to that directory with `/` separators. A directory with no matching files gives an empty list.
|
|
11
10
|
*
|
|
12
11
|
* @param {String} input - path to a file or a directory
|
|
13
|
-
* @param {String} globPattern -
|
|
12
|
+
* @param {String} globPattern - glob pattern for the files to read from a directory, such as `*.zip`
|
|
14
13
|
* @returns {Promise<Array<{path: String, name: String}>>}
|
|
15
14
|
*/
|
|
16
15
|
const listInputFiles = async (input, globPattern) => {
|
|
@@ -18,7 +17,22 @@ const listInputFiles = async (input, globPattern) => {
|
|
|
18
17
|
if (!(await stat(path)).isDirectory()) {
|
|
19
18
|
return [{path, name: basename(path)}];
|
|
20
19
|
}
|
|
21
|
-
const paths =
|
|
20
|
+
const paths = [];
|
|
21
|
+
for await (const entry of glob(globPattern, {cwd: path, withFileTypes: true})) {
|
|
22
|
+
const file = resolve(entry.parentPath, entry.name);
|
|
23
|
+
let target = entry;
|
|
24
|
+
if (entry.isSymbolicLink()) {
|
|
25
|
+
try {
|
|
26
|
+
target = await stat(file);
|
|
27
|
+
} catch {
|
|
28
|
+
// Skip links whose targets cannot be resolved.
|
|
29
|
+
continue;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
if (target.isFile()) {
|
|
33
|
+
paths.push(file);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
22
36
|
paths.sort();
|
|
23
37
|
return paths.map(file => ({path: file, name: relative(path, file).split('\\').join('/')}));
|
|
24
38
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tryghost/mg-fs-utils",
|
|
3
|
-
"version": "0.27.
|
|
3
|
+
"version": "0.27.3",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "git+https://github.com/TryGhost/migrate.git",
|
|
@@ -24,11 +24,10 @@
|
|
|
24
24
|
"@tryghost/errors": "3.4.8",
|
|
25
25
|
"@tryghost/image-transform": "1.4.19",
|
|
26
26
|
"@tryghost/string": "0.3.10",
|
|
27
|
-
"@tryghost/zip": "4.0
|
|
27
|
+
"@tryghost/zip": "4.1.0",
|
|
28
28
|
"adm-zip": "0.6.1",
|
|
29
29
|
"csv-parse": "7.0.3",
|
|
30
30
|
"dotenv": "18.0.10",
|
|
31
|
-
"fast-glob": "3.3.3",
|
|
32
31
|
"fs-extra": "11.4.1",
|
|
33
32
|
"sharp": "0.35.5",
|
|
34
33
|
"transliteration": "2.7.0",
|