@procedures/fs 0.60.1 → 0.62.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.
- package/CHANGELOG.md +30 -0
- package/README.md +2 -0
- package/dist/procedures/fs/glob.d.ts.map +1 -1
- package/dist/procedures/fs/glob.js +20 -32
- package/dist/procedures/fs/glob.js.map +1 -1
- package/dist/root.d.ts +3 -2
- package/dist/root.d.ts.map +1 -1
- package/dist/root.js +4 -6
- package/dist/root.js.map +1 -1
- package/package.json +3 -3
- package/src/procedures/fs/glob.ts +21 -32
- package/src/root.ts +4 -6
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,35 @@
|
|
|
1
1
|
# @procedures/fs
|
|
2
2
|
|
|
3
|
+
## 0.62.0
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- fdb89bc: The path, glob and walk functions of three packages move to their home, `@mark1russell7/files` (roadmap CLI-125).
|
|
8
|
+
|
|
9
|
+
- `@procedures/fs`: `isInside` is a re-export of `@mark1russell7/files`. With `dot: true`, `fs.glob` uses `findEntriesAsync` of `@mark1russell7/files`, and its walk does not block the event loop.
|
|
10
|
+
- `@procedures/fs`: with `dot: true`, an absolute pattern under `cwd` matches. Before, it matched nothing. The other matches do not change.
|
|
11
|
+
- `@procedures/lib`: `expandHome` is a re-export of `@mark1russell7/files`. `findWorkspaceRoot` uses `findUp`.
|
|
12
|
+
- `@procedures/archive`: the walk of `archive.create` uses `walk` of `@mark1russell7/files`. `portableLinkTarget` uses `toPosix`. The limits and the error codes do not change.
|
|
13
|
+
- `@procedures/peer`: the range of `@mark1russell7/files` is `^0.0.4`, as in the other packages. The code does not change.
|
|
14
|
+
- Updated dependencies [14f61a7]
|
|
15
|
+
- @procedures/client@0.62.0
|
|
16
|
+
|
|
17
|
+
## 0.61.0
|
|
18
|
+
|
|
19
|
+
### Patch Changes
|
|
20
|
+
|
|
21
|
+
- 84d9551: The CHANGELOG of 0.60.1 names only the brace groups of `fs.glob` with `dot: true`. Version 0.60.1 also changed three results of `fs.glob` with `dot: true`. Tests hold these results.
|
|
22
|
+
|
|
23
|
+
- A pattern `x/**` also gives the folder `x`, as `fs.glob` without `dot` does.
|
|
24
|
+
- An ignore pattern keeps the walk out of a folder only when it matches the folder or each entry in it. Before 0.60.1, `**/.*` stopped the walk at each folder, and `a/?` stopped it at the folder `a`.
|
|
25
|
+
- A pattern that starts with `./` matches. Before 0.60.1, it matched nothing.
|
|
26
|
+
|
|
27
|
+
Migration for the site and each app: examine each call of `fs.glob` with `dot: true` and a pattern that ends in `/**`. To get the matches of 0.60.0, remove the match that is equal to the folder.
|
|
28
|
+
- Updated dependencies [8506442]
|
|
29
|
+
- Updated dependencies [f9a78f9]
|
|
30
|
+
- Updated dependencies [3eb4b59]
|
|
31
|
+
- @procedures/client@0.61.0
|
|
32
|
+
|
|
3
33
|
## 0.60.1
|
|
4
34
|
|
|
5
35
|
### Patch Changes
|
package/README.md
CHANGED
|
@@ -602,6 +602,8 @@ Find files matching a glob pattern using the Node.js `fs.glob` API (`node:fs/pro
|
|
|
602
602
|
|
|
603
603
|
With `dot: true`, the walk uses the glob matcher of `@mark1russell7/files`. Each wildcard matches a name that starts with `.`, and a brace group can hold a dot name, for example `{.github,docs}/**`. The matcher knows `*`, `**`, `?`, sets and brace groups.
|
|
604
604
|
|
|
605
|
+
A pattern `x/**` also gives the folder `x`, as without `dot`. An ignore pattern keeps the walk out of a folder only when it matches the folder or each entry in it. A pattern can start with `./`.
|
|
606
|
+
|
|
605
607
|
```typescript
|
|
606
608
|
const result = await client.exec(
|
|
607
609
|
["fs", "glob"],
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"glob.d.ts","sourceRoot":"","sources":["../../../src/procedures/fs/glob.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAKH,OAAO,KAAK,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"glob.d.ts","sourceRoot":"","sources":["../../../src/procedures/fs/glob.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAKH,OAAO,KAAK,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AA6B5D;;GAEG;AACH,wBAAsB,IAAI,CAAC,KAAK,EAAE,SAAS,GAAG,OAAO,CAAC,UAAU,CAAC,CAqBhE"}
|
|
@@ -9,44 +9,32 @@
|
|
|
9
9
|
* Before, `ignore` was stripped by the input schema, and `absolute` and `dot` had no effect:
|
|
10
10
|
* `node:fs` glob has no such options (deep dive DATA-7).
|
|
11
11
|
*/
|
|
12
|
-
import { glob as nodeGlob
|
|
13
|
-
import { posix, resolve } from "node:path";
|
|
14
|
-
import {
|
|
15
|
-
/**
|
|
16
|
-
function toPosix(path) {
|
|
17
|
-
return path.split("\\").join("/");
|
|
18
|
-
}
|
|
12
|
+
import { glob as nodeGlob } from "node:fs/promises";
|
|
13
|
+
import { posix, relative as relativePath, resolve } from "node:path";
|
|
14
|
+
import { findEntriesAsync, matchesGlob, toPosix } from "@mark1russell7/files";
|
|
15
|
+
/** This function tells if an ignore pattern matches `path`, with the rules of `node:fs` glob. */
|
|
19
16
|
function ignored(path, ignore) {
|
|
20
17
|
return ignore.some((pattern) => posix.matchesGlob(path, pattern));
|
|
21
18
|
}
|
|
22
19
|
/**
|
|
23
|
-
*
|
|
24
|
-
* `@mark1russell7/files`
|
|
20
|
+
* This function gives all the matches of `pattern` under `root`, dot entries included. The walk is
|
|
21
|
+
* `findEntriesAsync` of `@mark1russell7/files` with `dot: true`, and it does not block the event loop.
|
|
22
|
+
* It enters `node_modules` and `.git`, and it does not enter an ignored folder. Thus `a/**` also
|
|
23
|
+
* matches the folder `a`, as the `node:fs` glob does.
|
|
24
|
+
* `findEntriesAsync` does not apply the ignore patterns to a pattern with no glob character, so this
|
|
25
|
+
* function applies them to each match again.
|
|
25
26
|
*/
|
|
26
27
|
async function walkWithDots(root, pattern, ignore) {
|
|
27
|
-
const
|
|
28
|
-
|
|
29
|
-
const
|
|
30
|
-
const
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
if (isIgnored(path) || isIgnored(`${path}/`))
|
|
38
|
-
continue;
|
|
39
|
-
if (matcher.test(path))
|
|
40
|
-
matches.push(path);
|
|
41
|
-
await visit(path);
|
|
42
|
-
}
|
|
43
|
-
else if (matcher.test(path) && !isIgnored(path)) {
|
|
44
|
-
matches.push(path);
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
await visit("");
|
|
49
|
-
return matches;
|
|
28
|
+
const isIgnored = (path) => ignore.some((glob) => matchesGlob(path, glob, { dot: true }));
|
|
29
|
+
// A folder is ignored when each path inside it is ignored: "a/" matches "a/**" and "a/*".
|
|
30
|
+
const folderIgnored = (path) => isIgnored(path) || isIgnored(`${path}/`);
|
|
31
|
+
const insideIgnored = (names) => names.slice(0, -1).some((_, index) => folderIgnored(names.slice(0, index + 1).join("/")));
|
|
32
|
+
const entries = await findEntriesAsync({ root, include: [pattern], ignore, skip: [], dot: true });
|
|
33
|
+
return entries.flatMap((entry) => {
|
|
34
|
+
const path = toPosix(relativePath(root, entry.path));
|
|
35
|
+
const ownIgnored = entry.kind === "directory" ? folderIgnored(path) : isIgnored(path);
|
|
36
|
+
return path === "" || ownIgnored || insideIgnored(path.split("/")) ? [] : [path];
|
|
37
|
+
});
|
|
50
38
|
}
|
|
51
39
|
/**
|
|
52
40
|
* Find files matching glob pattern
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"glob.js","sourceRoot":"","sources":["../../../src/procedures/fs/glob.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EAAE,IAAI,IAAI,QAAQ,EAAE,
|
|
1
|
+
{"version":3,"file":"glob.js","sourceRoot":"","sources":["../../../src/procedures/fs/glob.ts"],"names":[],"mapp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AAE,CAAC,EAAE,CAAC;YACjF,MAAM,IAAI,GAAG,OAAO,CAAC,KAAK,CAAC,CAAC;YAC5B,uFAAuF;YACvF,kBAAkB;YAClB,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,MAAM,CAAC;gBAAE,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAClD,CAAC;IACH,CAAC;IAED,QAAQ,CAAC,IAAI,EAAE,CAAC;IAChB,MAAM,OAAO,GAAG,QAAQ,CAAC,CAAC,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,OAAO,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC;IAClF,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,CAAC;AAC9B,CAAC"}
|
package/dist/root.d.ts
CHANGED
|
@@ -24,15 +24,16 @@
|
|
|
24
24
|
* A check and the operation of a call start in one hold of the roots (`root-hold.ts`). So the
|
|
25
25
|
* operation reads the links that the check read.
|
|
26
26
|
*/
|
|
27
|
+
import { isInside } from "@mark1russell7/files";
|
|
27
28
|
import { InvocationError, type ProcedurePath } from "@procedures/client";
|
|
28
29
|
export { holdRoots, type RootHoldMode } from "./root-hold.js";
|
|
29
30
|
/** The reason of the `FORBIDDEN` error for a path outside the root. */
|
|
30
31
|
export declare const OUTSIDE_ROOT = "outside-root";
|
|
31
32
|
/**
|
|
32
33
|
* This function tells if `path` is `folder` or a path in `folder`. The two paths are absolute.
|
|
33
|
-
* On Windows, the case of the letters is not significant.
|
|
34
|
+
* On Windows, the case of the letters is not significant. Its home is `@mark1russell7/files`.
|
|
34
35
|
*/
|
|
35
|
-
export
|
|
36
|
+
export { isInside };
|
|
36
37
|
/**
|
|
37
38
|
* This function gives the real path of an absolute path. For a path that does not exist, it
|
|
38
39
|
* gives the real path of the nearest existing ancestor and the rest of the path. A symlink whose
|
package/dist/root.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"root.d.ts","sourceRoot":"","sources":["../src/root.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAIH,OAAO,EAAE,eAAe,EAAE,KAAK,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAGzE,OAAO,EAAE,SAAS,EAAE,KAAK,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAE9D,uEAAuE;AACvE,eAAO,MAAM,YAAY,iBAAiB,CAAC;AAK3C;;;GAGG;AACH,
|
|
1
|
+
{"version":3,"file":"root.d.ts","sourceRoot":"","sources":["../src/root.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAIH,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAChD,OAAO,EAAE,eAAe,EAAE,KAAK,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAGzE,OAAO,EAAE,SAAS,EAAE,KAAK,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAE9D,uEAAuE;AACvE,eAAO,MAAM,YAAY,iBAAiB,CAAC;AAK3C;;;GAGG;AACH,OAAO,EAAE,QAAQ,EAAE,CAAC;AAcpB;;;;GAIG;AACH,wBAAsB,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,SAAI,GAAG,OAAO,CAAC,MAAM,CAAC,CAwBzE;AAED,uEAAuE;AACvE,MAAM,WAAW,YAAY;IAC3B,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;CACd;AAgBD;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,EAAE,QAAQ,GAAE,MAAM,CAAC,QAA2B,GAAG,OAAO,CAIxH;AAED;;;GAGG;AACH,wBAAsB,WAAW,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,SAAwB,GAAG,OAAO,CAAC,YAAY,CAAC,CAUpG;AAED,yDAAyD;AACzD,wBAAgB,WAAW,CAAC,SAAS,EAAE,aAAa,EAAE,OAAO,EAAE,MAAM,GAAG,eAAe,CAEtF;AAED,iEAAiE;AACjE,wBAAgB,aAAa,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAErD;AAED;;;;GAIG;AACH,wBAAsB,gBAAgB,CAAC,IAAI,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAG7F;AAED;;;;GAIG;AACH,wBAAsB,MAAM,CAAC,IAAI,EAAE,YAAY,EAAE,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,aAAa,EAAE,IAAI,GAAE,MAAoB,GAAG,OAAO,CAAC,MAAM,CAAC,CAgBpI"}
|
package/dist/root.js
CHANGED
|
@@ -25,7 +25,8 @@
|
|
|
25
25
|
* operation reads the links that the check read.
|
|
26
26
|
*/
|
|
27
27
|
import { readlink, realpath } from "node:fs/promises";
|
|
28
|
-
import { basename, dirname,
|
|
28
|
+
import { basename, dirname, join, resolve, win32 } from "node:path";
|
|
29
|
+
import { isInside } from "@mark1russell7/files";
|
|
29
30
|
import { InvocationError } from "@procedures/client";
|
|
30
31
|
import { isMissing, linkDestination } from "./link-target.js";
|
|
31
32
|
export { holdRoots } from "./root-hold.js";
|
|
@@ -35,12 +36,9 @@ export const OUTSIDE_ROOT = "outside-root";
|
|
|
35
36
|
const MAX_LINKS = 40;
|
|
36
37
|
/**
|
|
37
38
|
* This function tells if `path` is `folder` or a path in `folder`. The two paths are absolute.
|
|
38
|
-
* On Windows, the case of the letters is not significant.
|
|
39
|
+
* On Windows, the case of the letters is not significant. Its home is `@mark1russell7/files`.
|
|
39
40
|
*/
|
|
40
|
-
export
|
|
41
|
-
const rel = relative(folder, path);
|
|
42
|
-
return rel === "" || (!isAbsolute(rel) && rel !== ".." && !rel.startsWith(`..${sep}`));
|
|
43
|
-
}
|
|
41
|
+
export { isInside };
|
|
44
42
|
/** The target of a symlink, or undefined when the path is not a symlink or does not exist. */
|
|
45
43
|
async function linkTarget(path) {
|
|
46
44
|
try {
|
package/dist/root.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"root.js","sourceRoot":"","sources":["../src/root.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAEH,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AACtD,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"root.js","sourceRoot":"","sources":["../src/root.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAEH,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AACtD,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,WAAW,CAAC;AACpE,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAChD,OAAO,EAAE,eAAe,EAAsB,MAAM,oBAAoB,CAAC;AACzE,OAAO,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAE9D,OAAO,EAAE,SAAS,EAAqB,MAAM,gBAAgB,CAAC;AAE9D,uEAAuE;AACvE,MAAM,CAAC,MAAM,YAAY,GAAG,cAAc,CAAC;AAE3C,qGAAqG;AACrG,MAAM,SAAS,GAAG,EAAE,CAAC;AAErB;;;GAGG;AACH,OAAO,EAAE,QAAQ,EAAE,CAAC;AAEpB,8FAA8F;AAC9F,KAAK,UAAU,UAAU,CAAC,IAAY;IACpC,IAAI,CAAC;QACH,OAAO,MAAM,QAAQ,CAAC,IAAI,CAAC,CAAC;IAC9B,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,oCAAoC;QACpC,MAAM,IAAI,GAAI,KAA+B,CAAC,IAAI,CAAC;QACnD,IAAI,IAAI,KAAK,QAAQ,IAAI,SAAS,CAA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EAAE,CAAC;QACjC,MAAM,WAAW,CAAC,SAAS,EAAE,YAAY,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,iDAAiD,IAAI,CAAC,MAAM,EAAE,CAAC,CAAC;IAC/H,CAAC;IACD,MAAM,IAAI,GAAG,MAAM,UAAU,CAAC,QAAQ,CAAC,CAAC;IACxC,gGAAgG;IAChG,8FAA8F;IAC9F,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,MAAM,EAAE,QAAQ,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,EAAE,QAAQ,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,EAAE,CAAC;QACrG,MAAM,WAAW,CAAC,SAAS,EAAE,YAAY,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,wBAAwB,IAAI,CAAC,MAAM,EAAE,CAAC,CAAC;IACtG,CAAC;IACD,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,EAAE,CAAC;QAC/B,MAAM,WAAW,CAAC,SAAS,EAAE,YAAY,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,0BAA0B,IAAI,CAAC,MAAM,oBAAoB,CAAC,CAAC;IAC1H,CAAC;IACD,OAAO,QAAQ,CAAC;AAClB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$schema": "https://json.schemastore.org/package",
|
|
3
3
|
"name": "@procedures/fs",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.62.0",
|
|
5
5
|
"description": "File system procedures: read, write, copy, move, glob, exists, mkdir and JSON read and write, callable in process, over RPC or from Claude through MCP.",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"filesystem",
|
|
@@ -76,8 +76,8 @@
|
|
|
76
76
|
},
|
|
77
77
|
"dependencies": {
|
|
78
78
|
"@mark1russell7/collections": "^0.11.1",
|
|
79
|
-
"@mark1russell7/files": "^0.0.
|
|
80
|
-
"@procedures/client": "0.
|
|
79
|
+
"@mark1russell7/files": "^0.0.4",
|
|
80
|
+
"@procedures/client": "0.62.0",
|
|
81
81
|
"zod": "^4.6.5"
|
|
82
82
|
},
|
|
83
83
|
"devDependencies": {
|
|
@@ -10,47 +10,36 @@
|
|
|
10
10
|
* `node:fs` glob has no such options (deep dive DATA-7).
|
|
11
11
|
*/
|
|
12
12
|
|
|
13
|
-
import { glob as nodeGlob
|
|
14
|
-
import { posix, resolve } from "node:path";
|
|
15
|
-
import {
|
|
13
|
+
import { glob as nodeGlob } from "node:fs/promises";
|
|
14
|
+
import { posix, relative as relativePath, resolve } from "node:path";
|
|
15
|
+
import { findEntriesAsync, matchesGlob, toPosix } from "@mark1russell7/files";
|
|
16
16
|
import type { GlobInput, GlobOutput } from "../../types.js";
|
|
17
17
|
|
|
18
|
-
/**
|
|
19
|
-
function toPosix(path: string): string {
|
|
20
|
-
return path.split("\\").join("/");
|
|
21
|
-
}
|
|
22
|
-
|
|
18
|
+
/** This function tells if an ignore pattern matches `path`, with the rules of `node:fs` glob. */
|
|
23
19
|
function ignored(path: string, ignore: readonly string[]): boolean {
|
|
24
20
|
return ignore.some((pattern) => posix.matchesGlob(path, pattern));
|
|
25
21
|
}
|
|
26
22
|
|
|
27
23
|
/**
|
|
28
|
-
*
|
|
29
|
-
* `@mark1russell7/files`
|
|
24
|
+
* This function gives all the matches of `pattern` under `root`, dot entries included. The walk is
|
|
25
|
+
* `findEntriesAsync` of `@mark1russell7/files` with `dot: true`, and it does not block the event loop.
|
|
26
|
+
* It enters `node_modules` and `.git`, and it does not enter an ignored folder. Thus `a/**` also
|
|
27
|
+
* matches the folder `a`, as the `node:fs` glob does.
|
|
28
|
+
* `findEntriesAsync` does not apply the ignore patterns to a pattern with no glob character, so this
|
|
29
|
+
* function applies them to each match again.
|
|
30
30
|
*/
|
|
31
31
|
async function walkWithDots(root: string, pattern: string, ignore: readonly string[]): Promise<string[]> {
|
|
32
|
-
const
|
|
33
|
-
|
|
34
|
-
const
|
|
35
|
-
const
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
if (isIgnored(path) || isIgnored(`${path}/`)) continue;
|
|
44
|
-
if (matcher.test(path)) matches.push(path);
|
|
45
|
-
await visit(path);
|
|
46
|
-
} else if (matcher.test(path) && !isIgnored(path)) {
|
|
47
|
-
matches.push(path);
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
await visit("");
|
|
53
|
-
return matches;
|
|
32
|
+
const isIgnored = (path: string): boolean => ignore.some((glob) => matchesGlob(path, glob, { dot: true }));
|
|
33
|
+
// A folder is ignored when each path inside it is ignored: "a/" matches "a/**" and "a/*".
|
|
34
|
+
const folderIgnored = (path: string): boolean => isIgnored(path) || isIgnored(`${path}/`);
|
|
35
|
+
const insideIgnored = (names: readonly string[]): boolean =>
|
|
36
|
+
names.slice(0, -1).some((_, index) => folderIgnored(names.slice(0, index + 1).join("/")));
|
|
37
|
+
const entries = await findEntriesAsync({ root, include: [pattern], ignore, skip: [], dot: true });
|
|
38
|
+
return entries.flatMap((entry) => {
|
|
39
|
+
const path = toPosix(relativePath(root, entry.path));
|
|
40
|
+
const ownIgnored = entry.kind === "directory" ? folderIgnored(path) : isIgnored(path);
|
|
41
|
+
return path === "" || ownIgnored || insideIgnored(path.split("/")) ? [] : [path];
|
|
42
|
+
});
|
|
54
43
|
}
|
|
55
44
|
|
|
56
45
|
/**
|
package/src/root.ts
CHANGED
|
@@ -26,7 +26,8 @@
|
|
|
26
26
|
*/
|
|
27
27
|
|
|
28
28
|
import { readlink, realpath } from "node:fs/promises";
|
|
29
|
-
import { basename, dirname,
|
|
29
|
+
import { basename, dirname, join, resolve, win32 } from "node:path";
|
|
30
|
+
import { isInside } from "@mark1russell7/files";
|
|
30
31
|
import { InvocationError, type ProcedurePath } from "@procedures/client";
|
|
31
32
|
import { isMissing, linkDestination } from "./link-target.js";
|
|
32
33
|
|
|
@@ -40,12 +41,9 @@ const MAX_LINKS = 40;
|
|
|
40
41
|
|
|
41
42
|
/**
|
|
42
43
|
* This function tells if `path` is `folder` or a path in `folder`. The two paths are absolute.
|
|
43
|
-
* On Windows, the case of the letters is not significant.
|
|
44
|
+
* On Windows, the case of the letters is not significant. Its home is `@mark1russell7/files`.
|
|
44
45
|
*/
|
|
45
|
-
export
|
|
46
|
-
const rel = relative(folder, path);
|
|
47
|
-
return rel === "" || (!isAbsolute(rel) && rel !== ".." && !rel.startsWith(`..${sep}`));
|
|
48
|
-
}
|
|
46
|
+
export { isInside };
|
|
49
47
|
|
|
50
48
|
/** The target of a symlink, or undefined when the path is not a symlink or does not exist. */
|
|
51
49
|
async function linkTarget(path: string): Promise<string | undefined> {
|