@j0hanz/filesystem-mcp 1.19.0 → 2.0.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/README.md +333 -838
- package/dist/cli-help.d.ts +3 -0
- package/dist/cli-help.d.ts.map +1 -0
- package/dist/cli-help.js +169 -0
- package/dist/cli-help.js.map +1 -0
- package/dist/cli.d.ts +28 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +168 -123
- package/dist/cli.js.map +1 -0
- package/dist/core/concurrency.d.ts +70 -0
- package/dist/core/concurrency.d.ts.map +1 -0
- package/dist/core/concurrency.js +173 -0
- package/dist/core/concurrency.js.map +1 -0
- package/dist/core/config.d.ts +19 -0
- package/dist/core/config.d.ts.map +1 -0
- package/dist/core/config.js +11 -0
- package/dist/core/config.js.map +1 -0
- package/dist/core/cursor.d.ts +23 -0
- package/dist/core/cursor.d.ts.map +1 -0
- package/dist/core/cursor.js +62 -0
- package/dist/core/cursor.js.map +1 -0
- package/dist/core/errors.d.ts +96 -0
- package/dist/core/errors.d.ts.map +1 -0
- package/dist/core/errors.js +356 -0
- package/dist/core/errors.js.map +1 -0
- package/dist/core/file-uri.d.ts +24 -0
- package/dist/core/file-uri.d.ts.map +1 -0
- package/dist/core/file-uri.js +52 -0
- package/dist/core/file-uri.js.map +1 -0
- package/dist/core/fmt.d.ts +38 -0
- package/dist/core/fmt.d.ts.map +1 -0
- package/dist/core/fmt.js +109 -0
- package/dist/core/fmt.js.map +1 -0
- package/dist/core/fs.d.ts +108 -0
- package/dist/core/fs.d.ts.map +1 -0
- package/dist/core/fs.js +243 -0
- package/dist/core/fs.js.map +1 -0
- package/dist/core/glob.d.ts +41 -0
- package/dist/core/glob.d.ts.map +1 -0
- package/dist/core/glob.js +399 -0
- package/dist/core/glob.js.map +1 -0
- package/dist/core/input-required.d.ts +147 -0
- package/dist/core/input-required.d.ts.map +1 -0
- package/dist/core/input-required.js +261 -0
- package/dist/core/input-required.js.map +1 -0
- package/dist/core/mime.d.ts +15 -0
- package/dist/core/mime.d.ts.map +1 -0
- package/dist/core/mime.js +188 -0
- package/dist/core/mime.js.map +1 -0
- package/dist/core/observability.d.ts +10 -0
- package/dist/core/observability.d.ts.map +1 -0
- package/dist/core/observability.js +76 -0
- package/dist/core/observability.js.map +1 -0
- package/dist/core/page-store.d.ts +41 -0
- package/dist/core/page-store.d.ts.map +1 -0
- package/dist/core/page-store.js +74 -0
- package/dist/core/page-store.js.map +1 -0
- package/dist/core/path-completer.d.ts +10 -0
- package/dist/core/path-completer.d.ts.map +1 -0
- package/dist/core/path-completer.js +227 -0
- package/dist/core/path-completer.js.map +1 -0
- package/dist/core/path-discovery.d.ts +8 -0
- package/dist/core/path-discovery.d.ts.map +1 -0
- package/dist/core/path-discovery.js +105 -0
- package/dist/core/path-discovery.js.map +1 -0
- package/dist/core/path-utils.d.ts +9 -0
- package/dist/core/path-utils.d.ts.map +1 -0
- package/dist/core/path-utils.js +121 -0
- package/dist/core/path-utils.js.map +1 -0
- package/dist/core/path.d.ts +148 -0
- package/dist/core/path.d.ts.map +1 -0
- package/dist/core/path.js +674 -0
- package/dist/core/path.js.map +1 -0
- package/dist/core/primitives.d.ts +23 -0
- package/dist/core/primitives.d.ts.map +1 -0
- package/dist/core/primitives.js +54 -0
- package/dist/core/primitives.js.map +1 -0
- package/dist/core/read.d.ts +74 -0
- package/dist/core/read.d.ts.map +1 -0
- package/dist/core/read.js +562 -0
- package/dist/core/read.js.map +1 -0
- package/dist/core/schema.d.ts +139 -0
- package/dist/core/schema.d.ts.map +1 -0
- package/dist/core/schema.js +345 -0
- package/dist/core/schema.js.map +1 -0
- package/dist/core/search.d.ts +100 -0
- package/dist/core/search.d.ts.map +1 -0
- package/dist/core/search.js +248 -0
- package/dist/core/search.js.map +1 -0
- package/dist/core/sensitive.d.ts +6 -0
- package/dist/core/sensitive.d.ts.map +1 -0
- package/dist/core/sensitive.js +142 -0
- package/dist/core/sensitive.js.map +1 -0
- package/dist/core/store.d.ts +57 -0
- package/dist/core/store.d.ts.map +1 -0
- package/dist/core/store.js +162 -0
- package/dist/core/store.js.map +1 -0
- package/dist/core/util.d.ts +26 -0
- package/dist/core/util.d.ts.map +1 -0
- package/dist/core/util.js +66 -0
- package/dist/core/util.js.map +1 -0
- package/dist/core/watcher-registry.d.ts +68 -0
- package/dist/core/watcher-registry.d.ts.map +1 -0
- package/dist/core/watcher-registry.js +312 -0
- package/dist/core/watcher-registry.js.map +1 -0
- package/dist/http-policy.d.ts +121 -0
- package/dist/http-policy.d.ts.map +1 -0
- package/dist/http-policy.js +340 -0
- package/dist/http-policy.js.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +77 -41
- package/dist/index.js.map +1 -0
- package/dist/instructions.d.ts +12 -0
- package/dist/instructions.d.ts.map +1 -0
- package/dist/instructions.js +71 -0
- package/dist/instructions.js.map +1 -0
- package/dist/prompts.d.ts +8 -6
- package/dist/prompts.d.ts.map +1 -0
- package/dist/prompts.js +74 -168
- package/dist/prompts.js.map +1 -0
- package/dist/resources.d.ts +73 -9
- package/dist/resources.d.ts.map +1 -0
- package/dist/resources.js +392 -163
- package/dist/resources.js.map +1 -0
- package/dist/server.d.ts +62 -1
- package/dist/server.d.ts.map +1 -0
- package/dist/server.js +139 -1
- package/dist/server.js.map +1 -0
- package/dist/tools/batch.d.ts +89 -0
- package/dist/tools/batch.d.ts.map +1 -0
- package/dist/tools/batch.js +157 -0
- package/dist/tools/batch.js.map +1 -0
- package/dist/tools/create.d.ts +2 -0
- package/dist/tools/create.d.ts.map +1 -0
- package/dist/tools/create.js +142 -0
- package/dist/tools/create.js.map +1 -0
- package/dist/tools/define.d.ts +110 -0
- package/dist/tools/define.d.ts.map +1 -0
- package/dist/tools/define.js +394 -0
- package/dist/tools/define.js.map +1 -0
- package/dist/tools/delete-file.d.ts +2 -4
- package/dist/tools/delete-file.d.ts.map +1 -0
- package/dist/tools/delete-file.js +330 -87
- package/dist/tools/delete-file.js.map +1 -0
- package/dist/tools/diff.d.ts +2 -0
- package/dist/tools/diff.d.ts.map +1 -0
- package/dist/tools/diff.js +94 -0
- package/dist/tools/diff.js.map +1 -0
- package/dist/tools/edit.d.ts +2 -0
- package/dist/tools/edit.d.ts.map +1 -0
- package/dist/tools/edit.js +442 -0
- package/dist/tools/edit.js.map +1 -0
- package/dist/tools/index.d.ts +26 -0
- package/dist/tools/index.d.ts.map +1 -0
- package/dist/tools/index.js +52 -0
- package/dist/tools/index.js.map +1 -0
- package/dist/tools/list.d.ts +2 -0
- package/dist/tools/list.d.ts.map +1 -0
- package/dist/tools/list.js +291 -0
- package/dist/tools/list.js.map +1 -0
- package/dist/tools/move.d.ts +2 -0
- package/dist/tools/move.d.ts.map +1 -0
- package/dist/tools/move.js +321 -0
- package/dist/tools/move.js.map +1 -0
- package/dist/tools/patch.d.ts +2 -0
- package/dist/tools/patch.d.ts.map +1 -0
- package/dist/tools/patch.js +155 -0
- package/dist/tools/patch.js.map +1 -0
- package/dist/tools/progress.d.ts +52 -0
- package/dist/tools/progress.d.ts.map +1 -0
- package/dist/tools/progress.js +172 -0
- package/dist/tools/progress.js.map +1 -0
- package/dist/tools/read.d.ts +2 -4
- package/dist/tools/read.d.ts.map +1 -0
- package/dist/tools/read.js +398 -152
- package/dist/tools/read.js.map +1 -0
- package/dist/tools/replace-in-files.d.ts +2 -4
- package/dist/tools/replace-in-files.d.ts.map +1 -0
- package/dist/tools/replace-in-files.js +435 -264
- package/dist/tools/replace-in-files.js.map +1 -0
- package/dist/tools/roots.d.ts +2 -4
- package/dist/tools/roots.d.ts.map +1 -0
- package/dist/tools/roots.js +29 -52
- package/dist/tools/roots.js.map +1 -0
- package/dist/tools/search-content.d.ts +2 -4
- package/dist/tools/search-content.d.ts.map +1 -0
- package/dist/tools/search-content.js +262 -228
- package/dist/tools/search-content.js.map +1 -0
- package/dist/tools/search-files.d.ts +2 -4
- package/dist/tools/search-files.d.ts.map +1 -0
- package/dist/tools/search-files.js +162 -161
- package/dist/tools/search-files.js.map +1 -0
- package/dist/tools/stat.d.ts +2 -4
- package/dist/tools/stat.d.ts.map +1 -0
- package/dist/tools/stat.js +202 -62
- package/dist/tools/stat.js.map +1 -0
- package/dist/transport/http.d.ts +5 -0
- package/dist/transport/http.d.ts.map +1 -0
- package/dist/transport/http.js +276 -0
- package/dist/transport/http.js.map +1 -0
- package/dist/transport/shared.d.ts +45 -0
- package/dist/transport/shared.d.ts.map +1 -0
- package/dist/transport/shared.js +65 -0
- package/dist/transport/shared.js.map +1 -0
- package/dist/transport/stdio.d.ts +32 -0
- package/dist/transport/stdio.d.ts.map +1 -0
- package/dist/transport/stdio.js +279 -0
- package/dist/transport/stdio.js.map +1 -0
- package/dist/transport.d.ts +5 -0
- package/dist/transport.d.ts.map +1 -0
- package/dist/transport.js +4 -0
- package/dist/transport.js.map +1 -0
- package/package.json +37 -46
- package/dist/assets/logo.svg +0 -35
- package/dist/completions.d.ts +0 -2
- package/dist/completions.js +0 -572
- package/dist/config.d.ts +0 -119
- package/dist/config.js +0 -31
- package/dist/lib/abort.d.ts +0 -7
- package/dist/lib/abort.js +0 -81
- package/dist/lib/constants.d.ts +0 -42
- package/dist/lib/constants.js +0 -313
- package/dist/lib/errors.d.ts +0 -28
- package/dist/lib/errors.js +0 -301
- package/dist/lib/file-operations/core.d.ts +0 -53
- package/dist/lib/file-operations/core.js +0 -144
- package/dist/lib/file-operations/metadata.d.ts +0 -77
- package/dist/lib/file-operations/metadata.js +0 -878
- package/dist/lib/file-operations/search.d.ts +0 -46
- package/dist/lib/file-operations/search.js +0 -1194
- package/dist/lib/file-operations/traversal.d.ts +0 -40
- package/dist/lib/file-operations/traversal.js +0 -310
- package/dist/lib/fs-helpers.d.ts +0 -46
- package/dist/lib/fs-helpers.js +0 -606
- package/dist/lib/globs.d.ts +0 -2
- package/dist/lib/globs.js +0 -19
- package/dist/lib/logger.d.ts +0 -27
- package/dist/lib/logger.js +0 -91
- package/dist/lib/observability.d.ts +0 -33
- package/dist/lib/observability.js +0 -373
- package/dist/lib/paths.d.ts +0 -35
- package/dist/lib/paths.js +0 -634
- package/dist/lib/resource-store.d.ts +0 -28
- package/dist/lib/resource-store.js +0 -195
- package/dist/lib/utils.d.ts +0 -7
- package/dist/lib/utils.js +0 -37
- package/dist/lib/zod-codecs.d.ts +0 -2
- package/dist/lib/zod-codecs.js +0 -18
- package/dist/pkg-info.d.ts +0 -7
- package/dist/pkg-info.js +0 -9
- package/dist/resources/generated-instructions.d.ts +0 -1
- package/dist/resources/generated-instructions.js +0 -105
- package/dist/resources/tool-catalog.d.ts +0 -2
- package/dist/resources/tool-catalog.js +0 -78
- package/dist/resources/tool-info.d.ts +0 -9
- package/dist/resources/tool-info.js +0 -206
- package/dist/resources/workflows.d.ts +0 -1
- package/dist/resources/workflows.js +0 -72
- package/dist/schemas.d.ts +0 -505
- package/dist/schemas.js +0 -676
- package/dist/server/bootstrap.d.ts +0 -6
- package/dist/server/bootstrap.js +0 -563
- package/dist/server/event-store.d.ts +0 -18
- package/dist/server/event-store.js +0 -71
- package/dist/server/roots-manager.d.ts +0 -28
- package/dist/server/roots-manager.js +0 -227
- package/dist/server/task-store.d.ts +0 -10
- package/dist/server/task-store.js +0 -91
- package/dist/tools/apply-patch.d.ts +0 -4
- package/dist/tools/apply-patch.js +0 -235
- package/dist/tools/calculate-hash.d.ts +0 -4
- package/dist/tools/calculate-hash.js +0 -187
- package/dist/tools/contract.d.ts +0 -50
- package/dist/tools/contract.js +0 -1
- package/dist/tools/create-directory.d.ts +0 -4
- package/dist/tools/create-directory.js +0 -68
- package/dist/tools/diff-files.d.ts +0 -4
- package/dist/tools/diff-files.js +0 -136
- package/dist/tools/edit-file.d.ts +0 -4
- package/dist/tools/edit-file.js +0 -256
- package/dist/tools/icons.d.ts +0 -15
- package/dist/tools/icons.js +0 -24
- package/dist/tools/list-directory.d.ts +0 -4
- package/dist/tools/list-directory.js +0 -218
- package/dist/tools/move-file.d.ts +0 -4
- package/dist/tools/move-file.js +0 -178
- package/dist/tools/read-multiple.d.ts +0 -4
- package/dist/tools/read-multiple.js +0 -207
- package/dist/tools/shared.d.ts +0 -172
- package/dist/tools/shared.js +0 -599
- package/dist/tools/stat-many.d.ts +0 -4
- package/dist/tools/stat-many.js +0 -104
- package/dist/tools/task-support.d.ts +0 -29
- package/dist/tools/task-support.js +0 -472
- package/dist/tools/tree.d.ts +0 -4
- package/dist/tools/tree.js +0 -102
- package/dist/tools/write-file.d.ts +0 -4
- package/dist/tools/write-file.js +0 -60
- package/dist/tools.d.ts +0 -5
- package/dist/tools.js +0 -54
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import type { Stats } from 'node:fs';
|
|
2
|
-
import type { DirentLike } from './core.js';
|
|
3
|
-
interface GlobEntry {
|
|
4
|
-
path: string;
|
|
5
|
-
relativePath?: string;
|
|
6
|
-
dirent: DirentLike;
|
|
7
|
-
stats?: Stats;
|
|
8
|
-
}
|
|
9
|
-
interface GlobEntriesOptions {
|
|
10
|
-
cwd: string;
|
|
11
|
-
pattern: string;
|
|
12
|
-
excludePatterns: readonly string[];
|
|
13
|
-
includeHidden: boolean;
|
|
14
|
-
baseNameMatch: boolean;
|
|
15
|
-
caseSensitiveMatch: boolean;
|
|
16
|
-
maxDepth?: number;
|
|
17
|
-
followSymbolicLinks: boolean;
|
|
18
|
-
onlyFiles: boolean;
|
|
19
|
-
stats: boolean;
|
|
20
|
-
suppressErrors?: boolean;
|
|
21
|
-
}
|
|
22
|
-
export declare function globEntries(options: GlobEntriesOptions): AsyncGenerator<GlobEntry>;
|
|
23
|
-
interface GlobConfig {
|
|
24
|
-
cwd: string;
|
|
25
|
-
pattern: string;
|
|
26
|
-
excludePatterns?: readonly string[];
|
|
27
|
-
includeHidden?: boolean;
|
|
28
|
-
baseNameMatch?: boolean;
|
|
29
|
-
caseSensitiveMatch?: boolean;
|
|
30
|
-
followSymbolicLinks?: boolean;
|
|
31
|
-
onlyFiles?: boolean;
|
|
32
|
-
stats?: boolean;
|
|
33
|
-
maxDepth?: number;
|
|
34
|
-
suppressErrors?: boolean;
|
|
35
|
-
}
|
|
36
|
-
/**
|
|
37
|
-
* Builds standard options for globEntries to ensure consistency across search tools.
|
|
38
|
-
*/
|
|
39
|
-
export declare function buildGlobOptions(config: GlobConfig): Parameters<typeof globEntries>[0];
|
|
40
|
-
export {};
|
|
@@ -1,310 +0,0 @@
|
|
|
1
|
-
import { glob as fsGlob, lstat, stat } from 'node:fs/promises';
|
|
2
|
-
import { isAbsolute, relative, resolve } from 'node:path';
|
|
3
|
-
import { getToolContextSnapshot, publishOpsTraceEnd, publishOpsTraceError, publishOpsTraceStart, shouldPublishOpsTrace, startPerfMeasure, } from '../observability.js';
|
|
4
|
-
import { toPosixPath } from '../paths.js';
|
|
5
|
-
import { isRecord } from '../utils.js';
|
|
6
|
-
const GLOB_MAGIC_RE = /[*?[\]{}!]/u;
|
|
7
|
-
const DEFAULT_MAX_HIDDEN_DEPTH = 10;
|
|
8
|
-
const GLOB_BATCH_CONCURRENCY = 64;
|
|
9
|
-
const SEP = '/';
|
|
10
|
-
const DOT_CHAR_CODE = 46;
|
|
11
|
-
const GLOB_BOOLEAN_OPTION_KEYS = [
|
|
12
|
-
'includeHidden',
|
|
13
|
-
'baseNameMatch',
|
|
14
|
-
'caseSensitiveMatch',
|
|
15
|
-
'followSymbolicLinks',
|
|
16
|
-
'onlyFiles',
|
|
17
|
-
'stats',
|
|
18
|
-
];
|
|
19
|
-
function normalizePattern(pattern, baseNameMatch) {
|
|
20
|
-
const normalized = toPosixPath(pattern);
|
|
21
|
-
if (!baseNameMatch)
|
|
22
|
-
return normalized;
|
|
23
|
-
if (normalized.includes(SEP))
|
|
24
|
-
return normalized;
|
|
25
|
-
return `**/${normalized}`;
|
|
26
|
-
}
|
|
27
|
-
function splitPatternPrefix(normalizedPattern) {
|
|
28
|
-
if (!GLOB_MAGIC_RE.test(normalizedPattern)) {
|
|
29
|
-
return { prefix: '', remainder: normalizedPattern };
|
|
30
|
-
}
|
|
31
|
-
const segments = normalizedPattern.split(SEP);
|
|
32
|
-
const splitIndex = segments.findIndex((seg) => GLOB_MAGIC_RE.test(seg));
|
|
33
|
-
if (splitIndex <= 0) {
|
|
34
|
-
return { prefix: '', remainder: normalizedPattern };
|
|
35
|
-
}
|
|
36
|
-
return {
|
|
37
|
-
prefix: segments.slice(0, splitIndex).join(SEP) + SEP,
|
|
38
|
-
remainder: segments.slice(splitIndex).join(SEP),
|
|
39
|
-
};
|
|
40
|
-
}
|
|
41
|
-
function buildHiddenPatterns(normalizedPattern, maxDepth) {
|
|
42
|
-
const patterns = new Set([normalizedPattern]);
|
|
43
|
-
const { prefix, remainder } = splitPatternPrefix(normalizedPattern);
|
|
44
|
-
if (remainder.length > 0) {
|
|
45
|
-
const segments = remainder.split(SEP);
|
|
46
|
-
const idx = segments.findIndex((seg) => seg !== '**' && seg.length > 0);
|
|
47
|
-
if (idx !== -1) {
|
|
48
|
-
const original = segments[idx];
|
|
49
|
-
if (original && original.charCodeAt(0) !== DOT_CHAR_CODE) {
|
|
50
|
-
const newSegments = [...segments];
|
|
51
|
-
newSegments[idx] = `.${original}`;
|
|
52
|
-
patterns.add(`${prefix}${newSegments.join(SEP)}`);
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
if (remainder.startsWith('**/')) {
|
|
57
|
-
const afterGlobstar = remainder.slice(3);
|
|
58
|
-
const addDotFile = afterGlobstar.length > 0 && afterGlobstar.charCodeAt(0) !== DOT_CHAR_CODE;
|
|
59
|
-
let depthPrefix = '';
|
|
60
|
-
for (let depth = 0; depth <= maxDepth; depth++) {
|
|
61
|
-
patterns.add(`${prefix}${depthPrefix}.*/**/${afterGlobstar}`);
|
|
62
|
-
if (addDotFile)
|
|
63
|
-
patterns.add(`${prefix}${depthPrefix}.${afterGlobstar}`);
|
|
64
|
-
depthPrefix += '*/';
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
return Array.from(patterns);
|
|
68
|
-
}
|
|
69
|
-
function assertOptionsShape(options) {
|
|
70
|
-
const optsUnknown = options;
|
|
71
|
-
if (typeof optsUnknown !== 'object' || optsUnknown === null) {
|
|
72
|
-
throw new TypeError('globEntries: options must be an object');
|
|
73
|
-
}
|
|
74
|
-
const opts = optsUnknown;
|
|
75
|
-
if (typeof opts.cwd !== 'string')
|
|
76
|
-
throw new TypeError('globEntries: options.cwd must be a string');
|
|
77
|
-
if (typeof opts.pattern !== 'string')
|
|
78
|
-
throw new TypeError('globEntries: options.pattern must be a string');
|
|
79
|
-
if (!Array.isArray(opts.excludePatterns) ||
|
|
80
|
-
opts.excludePatterns.some((p) => typeof p !== 'string')) {
|
|
81
|
-
throw new TypeError('globEntries: options.excludePatterns must be an array of strings');
|
|
82
|
-
}
|
|
83
|
-
for (const key of GLOB_BOOLEAN_OPTION_KEYS) {
|
|
84
|
-
if (typeof opts[key] !== 'boolean') {
|
|
85
|
-
throw new TypeError(`globEntries: options.${key} must be a boolean`);
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
if (opts.maxDepth !== undefined &&
|
|
89
|
-
(!Number.isFinite(opts.maxDepth) || typeof opts.maxDepth !== 'number')) {
|
|
90
|
-
throw new TypeError('globEntries: options.maxDepth must be a finite number');
|
|
91
|
-
}
|
|
92
|
-
if (opts.suppressErrors !== undefined &&
|
|
93
|
-
typeof opts.suppressErrors !== 'boolean') {
|
|
94
|
-
throw new TypeError('globEntries: options.suppressErrors must be a boolean');
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
function normalizeOptions(options) {
|
|
98
|
-
const cwd = resolve(options.cwd);
|
|
99
|
-
const normalizedPattern = normalizePattern(options.pattern, options.baseNameMatch);
|
|
100
|
-
const patterns = options.includeHidden
|
|
101
|
-
? buildHiddenPatterns(normalizedPattern, options.maxDepth ?? DEFAULT_MAX_HIDDEN_DEPTH)
|
|
102
|
-
: [normalizedPattern];
|
|
103
|
-
const normalized = {
|
|
104
|
-
cwd,
|
|
105
|
-
patterns,
|
|
106
|
-
exclude: options.excludePatterns.map(toPosixPath),
|
|
107
|
-
useDirents: !options.stats && !options.followSymbolicLinks,
|
|
108
|
-
suppressErrors: options.suppressErrors ?? false,
|
|
109
|
-
};
|
|
110
|
-
if (options.maxDepth !== undefined) {
|
|
111
|
-
normalized.maxDepth = options.maxDepth;
|
|
112
|
-
}
|
|
113
|
-
return normalized;
|
|
114
|
-
}
|
|
115
|
-
function getRelativeDepth(relativePath) {
|
|
116
|
-
if (relativePath.length === 0)
|
|
117
|
-
return 0;
|
|
118
|
-
let count = 0;
|
|
119
|
-
for (let i = 0; i < relativePath.length; i++) {
|
|
120
|
-
const code = relativePath.charCodeAt(i);
|
|
121
|
-
if (code === 47 || code === 92) {
|
|
122
|
-
count++;
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
return count + 1;
|
|
126
|
-
}
|
|
127
|
-
function isGlobDirentLike(value) {
|
|
128
|
-
if (!isRecord(value))
|
|
129
|
-
return false;
|
|
130
|
-
return (typeof value.name === 'string' &&
|
|
131
|
-
typeof value.isDirectory === 'function' &&
|
|
132
|
-
typeof value.isFile === 'function' &&
|
|
133
|
-
typeof value.isSymbolicLink === 'function');
|
|
134
|
-
}
|
|
135
|
-
function resolveDirentBase(cwd, parentPath) {
|
|
136
|
-
if (!parentPath)
|
|
137
|
-
return cwd;
|
|
138
|
-
return isAbsolute(parentPath) ? parentPath : resolve(cwd, parentPath);
|
|
139
|
-
}
|
|
140
|
-
function resolveStringMatchPath(cwd, match) {
|
|
141
|
-
return isAbsolute(match) ? match : resolve(cwd, match);
|
|
142
|
-
}
|
|
143
|
-
function* processDirentMatch(match, cwd, maxDepth, seen, onlyFiles) {
|
|
144
|
-
const base = resolveDirentBase(cwd, match.parentPath);
|
|
145
|
-
const absolutePath = resolve(base, match.name);
|
|
146
|
-
if (maxDepth !== undefined) {
|
|
147
|
-
const rel = relative(cwd, absolutePath);
|
|
148
|
-
if (getRelativeDepth(rel) > maxDepth)
|
|
149
|
-
return;
|
|
150
|
-
}
|
|
151
|
-
if (seen.has(absolutePath))
|
|
152
|
-
return;
|
|
153
|
-
seen.add(absolutePath);
|
|
154
|
-
if (onlyFiles && !match.isFile())
|
|
155
|
-
return;
|
|
156
|
-
yield { path: absolutePath, dirent: match };
|
|
157
|
-
}
|
|
158
|
-
async function resolveStringMatch(match, cwd, maxDepth, seen, onlyFiles, followSymlinks, returnStats, suppressErrors) {
|
|
159
|
-
if (maxDepth !== undefined) {
|
|
160
|
-
const depth = getRelativeDepth(match);
|
|
161
|
-
if (depth > maxDepth)
|
|
162
|
-
return null;
|
|
163
|
-
}
|
|
164
|
-
const absolutePath = resolveStringMatchPath(cwd, match);
|
|
165
|
-
if (seen.has(absolutePath))
|
|
166
|
-
return null;
|
|
167
|
-
seen.add(absolutePath);
|
|
168
|
-
try {
|
|
169
|
-
const stats = followSymlinks
|
|
170
|
-
? await stat(absolutePath)
|
|
171
|
-
: await lstat(absolutePath);
|
|
172
|
-
if (onlyFiles && !stats.isFile())
|
|
173
|
-
return null;
|
|
174
|
-
const entry = { path: absolutePath, dirent: stats };
|
|
175
|
-
if (!isAbsolute(match)) {
|
|
176
|
-
entry.relativePath = match;
|
|
177
|
-
}
|
|
178
|
-
if (returnStats)
|
|
179
|
-
entry.stats = stats;
|
|
180
|
-
return entry;
|
|
181
|
-
}
|
|
182
|
-
catch (error) {
|
|
183
|
-
if (!suppressErrors)
|
|
184
|
-
throw error;
|
|
185
|
-
return null;
|
|
186
|
-
}
|
|
187
|
-
}
|
|
188
|
-
async function* processIterable(iterable, context) {
|
|
189
|
-
const { cwd, maxDepth, seen, onlyFiles, followSymlinks, returnStats, suppressErrors, } = context;
|
|
190
|
-
let buffer = [];
|
|
191
|
-
const flush = async function* () {
|
|
192
|
-
if (buffer.length === 0)
|
|
193
|
-
return;
|
|
194
|
-
// Process buffer concurrently
|
|
195
|
-
const currentBuffer = buffer;
|
|
196
|
-
buffer = [];
|
|
197
|
-
const results = await Promise.all(currentBuffer.map((match) => resolveStringMatch(match, cwd, maxDepth, seen, onlyFiles, followSymlinks, returnStats, suppressErrors)));
|
|
198
|
-
for (const entry of results) {
|
|
199
|
-
if (entry !== null)
|
|
200
|
-
yield entry;
|
|
201
|
-
}
|
|
202
|
-
};
|
|
203
|
-
try {
|
|
204
|
-
for await (const match of iterable) {
|
|
205
|
-
if (typeof match === 'string') {
|
|
206
|
-
buffer.push(match);
|
|
207
|
-
if (buffer.length >= GLOB_BATCH_CONCURRENCY) {
|
|
208
|
-
yield* flush();
|
|
209
|
-
}
|
|
210
|
-
continue;
|
|
211
|
-
}
|
|
212
|
-
if (buffer.length > 0)
|
|
213
|
-
yield* flush();
|
|
214
|
-
if (isGlobDirentLike(match)) {
|
|
215
|
-
yield* processDirentMatch(match, cwd, maxDepth, seen, onlyFiles);
|
|
216
|
-
}
|
|
217
|
-
}
|
|
218
|
-
yield* flush();
|
|
219
|
-
}
|
|
220
|
-
catch (error) {
|
|
221
|
-
if (!suppressErrors)
|
|
222
|
-
throw error;
|
|
223
|
-
}
|
|
224
|
-
}
|
|
225
|
-
async function* nativeGlobEntries(options) {
|
|
226
|
-
const plan = normalizeOptions(options);
|
|
227
|
-
const seen = new Set();
|
|
228
|
-
const { cwd, maxDepth, suppressErrors } = plan;
|
|
229
|
-
const { onlyFiles, stats: returnStats, followSymbolicLinks: followSymlinks, } = options;
|
|
230
|
-
const context = {
|
|
231
|
-
cwd,
|
|
232
|
-
maxDepth,
|
|
233
|
-
seen,
|
|
234
|
-
onlyFiles,
|
|
235
|
-
followSymlinks,
|
|
236
|
-
returnStats,
|
|
237
|
-
suppressErrors,
|
|
238
|
-
};
|
|
239
|
-
for (const pattern of plan.patterns) {
|
|
240
|
-
let iterable;
|
|
241
|
-
try {
|
|
242
|
-
iterable = fsGlob(pattern, {
|
|
243
|
-
cwd,
|
|
244
|
-
exclude: plan.exclude,
|
|
245
|
-
withFileTypes: plan.useDirents,
|
|
246
|
-
});
|
|
247
|
-
}
|
|
248
|
-
catch (error) {
|
|
249
|
-
if (suppressErrors)
|
|
250
|
-
continue;
|
|
251
|
-
throw error;
|
|
252
|
-
}
|
|
253
|
-
yield* processIterable(iterable, context);
|
|
254
|
-
}
|
|
255
|
-
}
|
|
256
|
-
export async function* globEntries(options) {
|
|
257
|
-
const engine = 'node:fs/promises.glob';
|
|
258
|
-
const endMeasure = startPerfMeasure('globEntries', { engine });
|
|
259
|
-
const toolContext = getToolContextSnapshot();
|
|
260
|
-
const traceContext = shouldPublishOpsTrace()
|
|
261
|
-
? {
|
|
262
|
-
op: 'globEntries',
|
|
263
|
-
engine,
|
|
264
|
-
...(toolContext
|
|
265
|
-
? { tool: toolContext.tool, path: toolContext.path }
|
|
266
|
-
: {}),
|
|
267
|
-
}
|
|
268
|
-
: undefined;
|
|
269
|
-
if (traceContext)
|
|
270
|
-
publishOpsTraceStart(traceContext);
|
|
271
|
-
let ok = false;
|
|
272
|
-
try {
|
|
273
|
-
assertOptionsShape(options);
|
|
274
|
-
yield* nativeGlobEntries(options);
|
|
275
|
-
ok = true;
|
|
276
|
-
}
|
|
277
|
-
catch (error) {
|
|
278
|
-
if (traceContext)
|
|
279
|
-
publishOpsTraceError(traceContext, error);
|
|
280
|
-
throw error;
|
|
281
|
-
}
|
|
282
|
-
finally {
|
|
283
|
-
if (traceContext)
|
|
284
|
-
publishOpsTraceEnd(traceContext);
|
|
285
|
-
endMeasure?.(ok);
|
|
286
|
-
}
|
|
287
|
-
}
|
|
288
|
-
/**
|
|
289
|
-
* Builds standard options for globEntries to ensure consistency across search tools.
|
|
290
|
-
*/
|
|
291
|
-
export function buildGlobOptions(config) {
|
|
292
|
-
const options = {
|
|
293
|
-
cwd: config.cwd,
|
|
294
|
-
pattern: config.pattern,
|
|
295
|
-
excludePatterns: config.excludePatterns ?? [],
|
|
296
|
-
includeHidden: config.includeHidden ?? false,
|
|
297
|
-
baseNameMatch: config.baseNameMatch ?? false,
|
|
298
|
-
caseSensitiveMatch: config.caseSensitiveMatch ?? true,
|
|
299
|
-
followSymbolicLinks: config.followSymbolicLinks ?? false,
|
|
300
|
-
onlyFiles: config.onlyFiles ?? true,
|
|
301
|
-
stats: config.stats ?? false,
|
|
302
|
-
};
|
|
303
|
-
if (config.suppressErrors) {
|
|
304
|
-
options.suppressErrors = config.suppressErrors;
|
|
305
|
-
}
|
|
306
|
-
if (config.maxDepth !== undefined) {
|
|
307
|
-
options.maxDepth = config.maxDepth;
|
|
308
|
-
}
|
|
309
|
-
return options;
|
|
310
|
-
}
|
package/dist/lib/fs-helpers.d.ts
DELETED
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import { type Stats } from 'node:fs';
|
|
2
|
-
import { type FileHandle } from 'node:fs/promises';
|
|
3
|
-
import type { FileType } from '../config.js';
|
|
4
|
-
interface ParallelResult<R> {
|
|
5
|
-
results: R[];
|
|
6
|
-
errors: {
|
|
7
|
-
index: number;
|
|
8
|
-
error: Error;
|
|
9
|
-
}[];
|
|
10
|
-
}
|
|
11
|
-
export declare function processInParallel<T, R>(items: T[], processor: (item: T) => Promise<R>, concurrency?: number, signal?: AbortSignal): Promise<ParallelResult<R>>;
|
|
12
|
-
export declare function getFileType(stats: Stats): FileType;
|
|
13
|
-
export declare function isHidden(name: string): boolean;
|
|
14
|
-
export declare function isProbablyBinary(filePath: string, existingHandle?: FileHandle, signal?: AbortSignal): Promise<boolean>;
|
|
15
|
-
export declare function calculateFileContentHash(filePath: string, signal?: AbortSignal): Promise<string>;
|
|
16
|
-
type ReadMode = 'head' | 'full' | 'range' | 'tail';
|
|
17
|
-
interface ReadFileOptions {
|
|
18
|
-
encoding?: BufferEncoding;
|
|
19
|
-
maxSize?: number;
|
|
20
|
-
head?: number;
|
|
21
|
-
tail?: number;
|
|
22
|
-
startLine?: number;
|
|
23
|
-
endLine?: number;
|
|
24
|
-
skipBinary?: boolean;
|
|
25
|
-
signal?: AbortSignal;
|
|
26
|
-
}
|
|
27
|
-
interface ReadFileResult {
|
|
28
|
-
path: string;
|
|
29
|
-
content: string;
|
|
30
|
-
truncated: boolean;
|
|
31
|
-
totalLines?: number;
|
|
32
|
-
readMode: ReadMode;
|
|
33
|
-
head?: number;
|
|
34
|
-
tail?: number;
|
|
35
|
-
startLine?: number;
|
|
36
|
-
endLine?: number;
|
|
37
|
-
linesRead?: number;
|
|
38
|
-
hasMoreLines?: boolean;
|
|
39
|
-
}
|
|
40
|
-
export declare function readFileWithStats(filePath: string, validPath: string, stats: Stats, options?: ReadFileOptions): Promise<ReadFileResult>;
|
|
41
|
-
export declare function readFile(filePath: string, options?: ReadFileOptions): Promise<ReadFileResult>;
|
|
42
|
-
export declare function atomicWriteFile(filePath: string, content: string, options?: {
|
|
43
|
-
encoding?: BufferEncoding;
|
|
44
|
-
signal?: AbortSignal | undefined;
|
|
45
|
-
}): Promise<void>;
|
|
46
|
-
export {};
|