@pattern-algebra/core 0.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 +571 -0
- package/dist/automaton/complement.d.ts +20 -0
- package/dist/automaton/complement.d.ts.map +1 -0
- package/dist/automaton/complement.js +36 -0
- package/dist/automaton/complement.js.map +1 -0
- package/dist/automaton/complement.test.d.ts +2 -0
- package/dist/automaton/complement.test.d.ts.map +1 -0
- package/dist/automaton/complement.test.js +114 -0
- package/dist/automaton/complement.test.js.map +1 -0
- package/dist/automaton/determinize.d.ts +41 -0
- package/dist/automaton/determinize.d.ts.map +1 -0
- package/dist/automaton/determinize.js +310 -0
- package/dist/automaton/determinize.js.map +1 -0
- package/dist/automaton/determinize.test.d.ts +2 -0
- package/dist/automaton/determinize.test.d.ts.map +1 -0
- package/dist/automaton/determinize.test.js +134 -0
- package/dist/automaton/determinize.test.js.map +1 -0
- package/dist/automaton/emptiness.d.ts +41 -0
- package/dist/automaton/emptiness.d.ts.map +1 -0
- package/dist/automaton/emptiness.js +262 -0
- package/dist/automaton/emptiness.js.map +1 -0
- package/dist/automaton/emptiness.test.d.ts +2 -0
- package/dist/automaton/emptiness.test.d.ts.map +1 -0
- package/dist/automaton/emptiness.test.js +154 -0
- package/dist/automaton/emptiness.test.js.map +1 -0
- package/dist/automaton/index.d.ts +10 -0
- package/dist/automaton/index.d.ts.map +1 -0
- package/dist/automaton/index.js +11 -0
- package/dist/automaton/index.js.map +1 -0
- package/dist/automaton/intersect.d.ts +35 -0
- package/dist/automaton/intersect.d.ts.map +1 -0
- package/dist/automaton/intersect.js +302 -0
- package/dist/automaton/intersect.js.map +1 -0
- package/dist/automaton/pattern-algebra.d.ts +62 -0
- package/dist/automaton/pattern-algebra.d.ts.map +1 -0
- package/dist/automaton/pattern-algebra.js +309 -0
- package/dist/automaton/pattern-algebra.js.map +1 -0
- package/dist/automaton/pattern-algebra.test.d.ts +2 -0
- package/dist/automaton/pattern-algebra.test.d.ts.map +1 -0
- package/dist/automaton/pattern-algebra.test.js +223 -0
- package/dist/automaton/pattern-algebra.test.js.map +1 -0
- package/dist/compile/automaton-builder.d.ts +47 -0
- package/dist/compile/automaton-builder.d.ts.map +1 -0
- package/dist/compile/automaton-builder.js +211 -0
- package/dist/compile/automaton-builder.js.map +1 -0
- package/dist/compile/compiler.d.ts +32 -0
- package/dist/compile/compiler.d.ts.map +1 -0
- package/dist/compile/compiler.js +47 -0
- package/dist/compile/compiler.js.map +1 -0
- package/dist/compile/index.d.ts +8 -0
- package/dist/compile/index.d.ts.map +1 -0
- package/dist/compile/index.js +8 -0
- package/dist/compile/index.js.map +1 -0
- package/dist/compile/quick-reject.d.ts +28 -0
- package/dist/compile/quick-reject.d.ts.map +1 -0
- package/dist/compile/quick-reject.js +147 -0
- package/dist/compile/quick-reject.js.map +1 -0
- package/dist/containment/analysis.d.ts +60 -0
- package/dist/containment/analysis.d.ts.map +1 -0
- package/dist/containment/analysis.js +378 -0
- package/dist/containment/analysis.js.map +1 -0
- package/dist/containment/containment.d.ts +23 -0
- package/dist/containment/containment.d.ts.map +1 -0
- package/dist/containment/containment.js +681 -0
- package/dist/containment/containment.js.map +1 -0
- package/dist/containment/containment.test.d.ts +2 -0
- package/dist/containment/containment.test.d.ts.map +1 -0
- package/dist/containment/containment.test.js +209 -0
- package/dist/containment/containment.test.js.map +1 -0
- package/dist/containment/index.d.ts +7 -0
- package/dist/containment/index.d.ts.map +1 -0
- package/dist/containment/index.js +7 -0
- package/dist/containment/index.js.map +1 -0
- package/dist/core-alpha.d.ts +1253 -0
- package/dist/core-beta.d.ts +1253 -0
- package/dist/core-public.d.ts +1253 -0
- package/dist/core-unstripped.d.ts +1253 -0
- package/dist/index.d.ts +32 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +49 -0
- package/dist/index.js.map +1 -0
- package/dist/match/index.d.ts +8 -0
- package/dist/match/index.d.ts.map +1 -0
- package/dist/match/index.js +8 -0
- package/dist/match/index.js.map +1 -0
- package/dist/match/matcher.d.ts +40 -0
- package/dist/match/matcher.d.ts.map +1 -0
- package/dist/match/matcher.js +256 -0
- package/dist/match/matcher.js.map +1 -0
- package/dist/match/matcher.test.d.ts +2 -0
- package/dist/match/matcher.test.d.ts.map +1 -0
- package/dist/match/matcher.test.js +185 -0
- package/dist/match/matcher.test.js.map +1 -0
- package/dist/match/path-utils.d.ts +132 -0
- package/dist/match/path-utils.d.ts.map +1 -0
- package/dist/match/path-utils.js +223 -0
- package/dist/match/path-utils.js.map +1 -0
- package/dist/match/path-utils.test.d.ts +2 -0
- package/dist/match/path-utils.test.d.ts.map +1 -0
- package/dist/match/path-utils.test.js +193 -0
- package/dist/match/path-utils.test.js.map +1 -0
- package/dist/match/segment-matcher.d.ts +25 -0
- package/dist/match/segment-matcher.d.ts.map +1 -0
- package/dist/match/segment-matcher.js +267 -0
- package/dist/match/segment-matcher.js.map +1 -0
- package/dist/parse/brace-expansion.d.ts +34 -0
- package/dist/parse/brace-expansion.d.ts.map +1 -0
- package/dist/parse/brace-expansion.js +294 -0
- package/dist/parse/brace-expansion.js.map +1 -0
- package/dist/parse/brace-expansion.test.d.ts +2 -0
- package/dist/parse/brace-expansion.test.d.ts.map +1 -0
- package/dist/parse/brace-expansion.test.js +105 -0
- package/dist/parse/brace-expansion.test.js.map +1 -0
- package/dist/parse/index.d.ts +8 -0
- package/dist/parse/index.d.ts.map +1 -0
- package/dist/parse/index.js +8 -0
- package/dist/parse/index.js.map +1 -0
- package/dist/parse/parser.d.ts +15 -0
- package/dist/parse/parser.d.ts.map +1 -0
- package/dist/parse/parser.js +526 -0
- package/dist/parse/parser.js.map +1 -0
- package/dist/parse/parser.test.d.ts +2 -0
- package/dist/parse/parser.test.d.ts.map +1 -0
- package/dist/parse/parser.test.js +266 -0
- package/dist/parse/parser.test.js.map +1 -0
- package/dist/parse/validator.d.ts +30 -0
- package/dist/parse/validator.d.ts.map +1 -0
- package/dist/parse/validator.js +115 -0
- package/dist/parse/validator.js.map +1 -0
- package/dist/parse/validator.test.d.ts +2 -0
- package/dist/parse/validator.test.d.ts.map +1 -0
- package/dist/parse/validator.test.js +45 -0
- package/dist/parse/validator.test.js.map +1 -0
- package/dist/types/ast.d.ts +158 -0
- package/dist/types/ast.d.ts.map +1 -0
- package/dist/types/ast.js +2 -0
- package/dist/types/ast.js.map +1 -0
- package/dist/types/automaton.d.ts +150 -0
- package/dist/types/automaton.d.ts.map +1 -0
- package/dist/types/automaton.js +2 -0
- package/dist/types/automaton.js.map +1 -0
- package/dist/types/containment.d.ts +257 -0
- package/dist/types/containment.d.ts.map +1 -0
- package/dist/types/containment.js +5 -0
- package/dist/types/containment.js.map +1 -0
- package/dist/types/errors.d.ts +37 -0
- package/dist/types/errors.d.ts.map +1 -0
- package/dist/types/errors.js +24 -0
- package/dist/types/errors.js.map +1 -0
- package/dist/types/index.d.ts +10 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +6 -0
- package/dist/types/index.js.map +1 -0
- package/package.json +48 -0
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Path normalization and manipulation utilities.
|
|
3
|
+
* @packageDocumentation
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Context for path resolution operations.
|
|
7
|
+
* @public
|
|
8
|
+
*/
|
|
9
|
+
export interface PathContext {
|
|
10
|
+
/** User's home directory for ~ expansion */
|
|
11
|
+
readonly homeDir: string;
|
|
12
|
+
/** Current working directory for relative path resolution */
|
|
13
|
+
readonly cwd: string;
|
|
14
|
+
/** Optional project root for project-relative patterns */
|
|
15
|
+
readonly projectRoot?: string;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Normalize a path to absolute form for consistent matching.
|
|
19
|
+
*
|
|
20
|
+
* Handles:
|
|
21
|
+
* - ~ expansion to home directory
|
|
22
|
+
* - Relative path resolution against cwd
|
|
23
|
+
* - . and .. resolution
|
|
24
|
+
* - Trailing slash normalization (removed)
|
|
25
|
+
* - Duplicate slash removal
|
|
26
|
+
* - Backslash to forward slash conversion (Windows compatibility)
|
|
27
|
+
*
|
|
28
|
+
* @param path - Input path (may be relative or contain ~)
|
|
29
|
+
* @param context - Context for resolution
|
|
30
|
+
* @returns Absolute, normalized path
|
|
31
|
+
*
|
|
32
|
+
* @public
|
|
33
|
+
*/
|
|
34
|
+
export declare function normalizePath(path: string, context: PathContext): string;
|
|
35
|
+
/**
|
|
36
|
+
* Split a normalized path into segments.
|
|
37
|
+
*
|
|
38
|
+
* @param path - A normalized absolute path (starting with /)
|
|
39
|
+
* @returns Array of path segments (excluding the root)
|
|
40
|
+
*
|
|
41
|
+
* @example
|
|
42
|
+
* pathToSegments('/home/user/dev/file.ts')
|
|
43
|
+
* // => ['home', 'user', 'dev', 'file.ts']
|
|
44
|
+
*
|
|
45
|
+
* @public
|
|
46
|
+
*/
|
|
47
|
+
export declare function pathToSegments(path: string): readonly string[];
|
|
48
|
+
/**
|
|
49
|
+
* Join segments back into a path.
|
|
50
|
+
*
|
|
51
|
+
* @param segments - Array of path segments
|
|
52
|
+
* @returns Absolute path string
|
|
53
|
+
*
|
|
54
|
+
* @example
|
|
55
|
+
* segmentsToPath(['home', 'user', 'dev', 'file.ts'])
|
|
56
|
+
* // => '/home/user/dev/file.ts'
|
|
57
|
+
*
|
|
58
|
+
* @public
|
|
59
|
+
*/
|
|
60
|
+
export declare function segmentsToPath(segments: readonly string[]): string;
|
|
61
|
+
/**
|
|
62
|
+
* Check if a path is absolute (starts with / or ~).
|
|
63
|
+
*
|
|
64
|
+
* @param path - Path to check
|
|
65
|
+
* @returns true if the path is absolute
|
|
66
|
+
*
|
|
67
|
+
* @public
|
|
68
|
+
*/
|
|
69
|
+
export declare function isAbsolutePath(path: string): boolean;
|
|
70
|
+
/**
|
|
71
|
+
* Get the file extension from a path segment or full path.
|
|
72
|
+
*
|
|
73
|
+
* @param pathOrSegment - A path or segment to extract extension from
|
|
74
|
+
* @returns The extension including the dot, or empty string if none
|
|
75
|
+
*
|
|
76
|
+
* @example
|
|
77
|
+
* getExtension('file.ts') // => '.ts'
|
|
78
|
+
* getExtension('file.test.ts') // => '.ts'
|
|
79
|
+
* getExtension('.gitignore') // => '' (dotfiles have no extension)
|
|
80
|
+
* getExtension('Makefile') // => ''
|
|
81
|
+
*
|
|
82
|
+
* @public
|
|
83
|
+
*/
|
|
84
|
+
export declare function getExtension(pathOrSegment: string): string;
|
|
85
|
+
/**
|
|
86
|
+
* Get the basename (final segment) from a path.
|
|
87
|
+
*
|
|
88
|
+
* @param path - Path to extract basename from
|
|
89
|
+
* @returns The final segment of the path
|
|
90
|
+
*
|
|
91
|
+
* @public
|
|
92
|
+
*/
|
|
93
|
+
export declare function getBasename(path: string): string;
|
|
94
|
+
/**
|
|
95
|
+
* Get the directory portion of a path (everything except the last segment).
|
|
96
|
+
*
|
|
97
|
+
* @param path - Path to extract directory from
|
|
98
|
+
* @returns The directory path
|
|
99
|
+
*
|
|
100
|
+
* @public
|
|
101
|
+
*/
|
|
102
|
+
export declare function getDirname(path: string): string;
|
|
103
|
+
/**
|
|
104
|
+
* Check if path A is a prefix of path B (A is an ancestor directory of B).
|
|
105
|
+
*
|
|
106
|
+
* @param ancestor - Potential ancestor path
|
|
107
|
+
* @param descendant - Potential descendant path
|
|
108
|
+
* @returns true if ancestor is a prefix of descendant
|
|
109
|
+
*
|
|
110
|
+
* @example
|
|
111
|
+
* isAncestorPath('/home/user', '/home/user/dev/file.ts') // => true
|
|
112
|
+
* isAncestorPath('/home/user', '/home/user') // => true (same path)
|
|
113
|
+
* isAncestorPath('/home/user', '/home/other') // => false
|
|
114
|
+
*
|
|
115
|
+
* @public
|
|
116
|
+
*/
|
|
117
|
+
export declare function isAncestorPath(ancestor: string, descendant: string): boolean;
|
|
118
|
+
/**
|
|
119
|
+
* Find the common prefix path between two paths.
|
|
120
|
+
*
|
|
121
|
+
* @param pathA - First path
|
|
122
|
+
* @param pathB - Second path
|
|
123
|
+
* @returns The longest common ancestor path
|
|
124
|
+
*
|
|
125
|
+
* @example
|
|
126
|
+
* commonPrefix('/home/user/a/b', '/home/user/c/d')
|
|
127
|
+
* // => '/home/user'
|
|
128
|
+
*
|
|
129
|
+
* @public
|
|
130
|
+
*/
|
|
131
|
+
export declare function commonPrefix(pathA: string, pathB: string): string;
|
|
132
|
+
//# sourceMappingURL=path-utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"path-utils.d.ts","sourceRoot":"","sources":["../../src/match/path-utils.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;GAGG;AACH,MAAM,WAAW,WAAW;IAC1B,4CAA4C;IAC5C,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAA;IAExB,6DAA6D;IAC7D,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAA;IAEpB,0DAA0D;IAC1D,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAA;CAC9B;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,WAAW,GAAG,MAAM,CAuCxE;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS,MAAM,EAAE,CAmB9D;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,cAAc,CAAC,QAAQ,EAAE,SAAS,MAAM,EAAE,GAAG,MAAM,CAKlE;AAED;;;;;;;GAOG;AACH,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAEpD;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,YAAY,CAAC,aAAa,EAAE,MAAM,GAAG,MAAM,CAY1D;AAED;;;;;;;GAOG;AACH,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAGhD;AAED;;;;;;;GAOG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAM/C;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,cAAc,CAAC,QAAQ,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,OAAO,CAe5E;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAgBjE"}
|
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Path normalization and manipulation utilities.
|
|
3
|
+
* @packageDocumentation
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Normalize a path to absolute form for consistent matching.
|
|
7
|
+
*
|
|
8
|
+
* Handles:
|
|
9
|
+
* - ~ expansion to home directory
|
|
10
|
+
* - Relative path resolution against cwd
|
|
11
|
+
* - . and .. resolution
|
|
12
|
+
* - Trailing slash normalization (removed)
|
|
13
|
+
* - Duplicate slash removal
|
|
14
|
+
* - Backslash to forward slash conversion (Windows compatibility)
|
|
15
|
+
*
|
|
16
|
+
* @param path - Input path (may be relative or contain ~)
|
|
17
|
+
* @param context - Context for resolution
|
|
18
|
+
* @returns Absolute, normalized path
|
|
19
|
+
*
|
|
20
|
+
* @public
|
|
21
|
+
*/
|
|
22
|
+
export function normalizePath(path, context) {
|
|
23
|
+
let normalized = path;
|
|
24
|
+
// Convert backslashes to forward slashes for cross-platform compatibility
|
|
25
|
+
normalized = normalized.replace(/\\/g, '/');
|
|
26
|
+
// Expand ~ to home directory
|
|
27
|
+
if (normalized === '~') {
|
|
28
|
+
normalized = context.homeDir;
|
|
29
|
+
}
|
|
30
|
+
else if (normalized.startsWith('~/')) {
|
|
31
|
+
normalized = context.homeDir + normalized.slice(1);
|
|
32
|
+
}
|
|
33
|
+
// Handle relative paths
|
|
34
|
+
if (!normalized.startsWith('/')) {
|
|
35
|
+
normalized = context.cwd + '/' + normalized;
|
|
36
|
+
}
|
|
37
|
+
// Split into segments and resolve . and ..
|
|
38
|
+
const segments = normalized.split('/').filter((s) => s !== '');
|
|
39
|
+
const resolved = [];
|
|
40
|
+
for (const segment of segments) {
|
|
41
|
+
if (segment === '.') {
|
|
42
|
+
// Current directory - skip
|
|
43
|
+
continue;
|
|
44
|
+
}
|
|
45
|
+
else if (segment === '..') {
|
|
46
|
+
// Parent directory - pop if possible
|
|
47
|
+
if (resolved.length > 0) {
|
|
48
|
+
resolved.pop();
|
|
49
|
+
}
|
|
50
|
+
// At root, .. is a no-op
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
resolved.push(segment);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
// Reconstruct path with leading slash
|
|
57
|
+
return '/' + resolved.join('/');
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Split a normalized path into segments.
|
|
61
|
+
*
|
|
62
|
+
* @param path - A normalized absolute path (starting with /)
|
|
63
|
+
* @returns Array of path segments (excluding the root)
|
|
64
|
+
*
|
|
65
|
+
* @example
|
|
66
|
+
* pathToSegments('/home/user/dev/file.ts')
|
|
67
|
+
* // => ['home', 'user', 'dev', 'file.ts']
|
|
68
|
+
*
|
|
69
|
+
* @public
|
|
70
|
+
*/
|
|
71
|
+
export function pathToSegments(path) {
|
|
72
|
+
// Handle edge cases
|
|
73
|
+
if (path === '' || path === '/') {
|
|
74
|
+
return [];
|
|
75
|
+
}
|
|
76
|
+
// Remove leading slash and split
|
|
77
|
+
const withoutLeadingSlash = path.startsWith('/') ? path.slice(1) : path;
|
|
78
|
+
// Remove trailing slash if present
|
|
79
|
+
const withoutTrailingSlash = withoutLeadingSlash.endsWith('/')
|
|
80
|
+
? withoutLeadingSlash.slice(0, -1)
|
|
81
|
+
: withoutLeadingSlash;
|
|
82
|
+
if (withoutTrailingSlash === '') {
|
|
83
|
+
return [];
|
|
84
|
+
}
|
|
85
|
+
return withoutTrailingSlash.split('/');
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Join segments back into a path.
|
|
89
|
+
*
|
|
90
|
+
* @param segments - Array of path segments
|
|
91
|
+
* @returns Absolute path string
|
|
92
|
+
*
|
|
93
|
+
* @example
|
|
94
|
+
* segmentsToPath(['home', 'user', 'dev', 'file.ts'])
|
|
95
|
+
* // => '/home/user/dev/file.ts'
|
|
96
|
+
*
|
|
97
|
+
* @public
|
|
98
|
+
*/
|
|
99
|
+
export function segmentsToPath(segments) {
|
|
100
|
+
if (segments.length === 0) {
|
|
101
|
+
return '/';
|
|
102
|
+
}
|
|
103
|
+
return '/' + segments.join('/');
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Check if a path is absolute (starts with / or ~).
|
|
107
|
+
*
|
|
108
|
+
* @param path - Path to check
|
|
109
|
+
* @returns true if the path is absolute
|
|
110
|
+
*
|
|
111
|
+
* @public
|
|
112
|
+
*/
|
|
113
|
+
export function isAbsolutePath(path) {
|
|
114
|
+
return path.startsWith('/') || path.startsWith('~');
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Get the file extension from a path segment or full path.
|
|
118
|
+
*
|
|
119
|
+
* @param pathOrSegment - A path or segment to extract extension from
|
|
120
|
+
* @returns The extension including the dot, or empty string if none
|
|
121
|
+
*
|
|
122
|
+
* @example
|
|
123
|
+
* getExtension('file.ts') // => '.ts'
|
|
124
|
+
* getExtension('file.test.ts') // => '.ts'
|
|
125
|
+
* getExtension('.gitignore') // => '' (dotfiles have no extension)
|
|
126
|
+
* getExtension('Makefile') // => ''
|
|
127
|
+
*
|
|
128
|
+
* @public
|
|
129
|
+
*/
|
|
130
|
+
export function getExtension(pathOrSegment) {
|
|
131
|
+
// Get the last segment if this is a full path
|
|
132
|
+
const lastSlash = pathOrSegment.lastIndexOf('/');
|
|
133
|
+
const segment = lastSlash >= 0 ? pathOrSegment.slice(lastSlash + 1) : pathOrSegment;
|
|
134
|
+
// Find the last dot that's not at the start (dotfiles don't count)
|
|
135
|
+
const lastDot = segment.lastIndexOf('.');
|
|
136
|
+
if (lastDot <= 0) {
|
|
137
|
+
return '';
|
|
138
|
+
}
|
|
139
|
+
return segment.slice(lastDot);
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Get the basename (final segment) from a path.
|
|
143
|
+
*
|
|
144
|
+
* @param path - Path to extract basename from
|
|
145
|
+
* @returns The final segment of the path
|
|
146
|
+
*
|
|
147
|
+
* @public
|
|
148
|
+
*/
|
|
149
|
+
export function getBasename(path) {
|
|
150
|
+
const segments = pathToSegments(path);
|
|
151
|
+
return segments.length > 0 ? segments[segments.length - 1] : '';
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Get the directory portion of a path (everything except the last segment).
|
|
155
|
+
*
|
|
156
|
+
* @param path - Path to extract directory from
|
|
157
|
+
* @returns The directory path
|
|
158
|
+
*
|
|
159
|
+
* @public
|
|
160
|
+
*/
|
|
161
|
+
export function getDirname(path) {
|
|
162
|
+
const segments = pathToSegments(path);
|
|
163
|
+
if (segments.length <= 1) {
|
|
164
|
+
return '/';
|
|
165
|
+
}
|
|
166
|
+
return segmentsToPath(segments.slice(0, -1));
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* Check if path A is a prefix of path B (A is an ancestor directory of B).
|
|
170
|
+
*
|
|
171
|
+
* @param ancestor - Potential ancestor path
|
|
172
|
+
* @param descendant - Potential descendant path
|
|
173
|
+
* @returns true if ancestor is a prefix of descendant
|
|
174
|
+
*
|
|
175
|
+
* @example
|
|
176
|
+
* isAncestorPath('/home/user', '/home/user/dev/file.ts') // => true
|
|
177
|
+
* isAncestorPath('/home/user', '/home/user') // => true (same path)
|
|
178
|
+
* isAncestorPath('/home/user', '/home/other') // => false
|
|
179
|
+
*
|
|
180
|
+
* @public
|
|
181
|
+
*/
|
|
182
|
+
export function isAncestorPath(ancestor, descendant) {
|
|
183
|
+
const ancestorSegments = pathToSegments(ancestor);
|
|
184
|
+
const descendantSegments = pathToSegments(descendant);
|
|
185
|
+
if (ancestorSegments.length > descendantSegments.length) {
|
|
186
|
+
return false;
|
|
187
|
+
}
|
|
188
|
+
for (let i = 0; i < ancestorSegments.length; i++) {
|
|
189
|
+
if (ancestorSegments[i] !== descendantSegments[i]) {
|
|
190
|
+
return false;
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
return true;
|
|
194
|
+
}
|
|
195
|
+
/**
|
|
196
|
+
* Find the common prefix path between two paths.
|
|
197
|
+
*
|
|
198
|
+
* @param pathA - First path
|
|
199
|
+
* @param pathB - Second path
|
|
200
|
+
* @returns The longest common ancestor path
|
|
201
|
+
*
|
|
202
|
+
* @example
|
|
203
|
+
* commonPrefix('/home/user/a/b', '/home/user/c/d')
|
|
204
|
+
* // => '/home/user'
|
|
205
|
+
*
|
|
206
|
+
* @public
|
|
207
|
+
*/
|
|
208
|
+
export function commonPrefix(pathA, pathB) {
|
|
209
|
+
const segmentsA = pathToSegments(pathA);
|
|
210
|
+
const segmentsB = pathToSegments(pathB);
|
|
211
|
+
const common = [];
|
|
212
|
+
const minLength = Math.min(segmentsA.length, segmentsB.length);
|
|
213
|
+
for (let i = 0; i < minLength; i++) {
|
|
214
|
+
if (segmentsA[i] === segmentsB[i]) {
|
|
215
|
+
common.push(segmentsA[i]);
|
|
216
|
+
}
|
|
217
|
+
else {
|
|
218
|
+
break;
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
return segmentsToPath(common);
|
|
222
|
+
}
|
|
223
|
+
//# sourceMappingURL=path-utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"path-utils.js","sourceRoot":"","sources":["../../src/match/path-utils.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAiBH;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,UAAU,aAAa,CAAC,IAAY,EAAE,OAAoB;IAC9D,IAAI,UAAU,GAAG,IAAI,CAAA;IAErB,0EAA0E;IAC1E,UAAU,GAAG,UAAU,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAA;IAE3C,6BAA6B;IAC7B,IAAI,UAAU,KAAK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;YAClD,OAAO,KAAK,CAAA;QACd,CAAC;IACH,CAAC;IAED,OAAO,IAAI,CAAA;AACb,CAAC;AAED;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,YAAY,CAAC,KAAa,EAAE,KAAa;IACvD,MAAM,SAAS,GAAG,cAAc,CAAC,KAAK,CAAC,CAAA;IACvC,MAAM,SAAS,GAAG,cAAc,CAAC,KAAK,CAAC,CAAA;IAEvC,MAAM,MAAM,GAAa,EAAE,CAAA;IAC3B,MAAM,SAAS,GAAG,IAAI,CAAC,GAAG,CAAC,SAAS,CAAC,MAAM,EAAE,SAAS,CAAC,MAAM,CAAC,CAAA;IAE9D,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,SAAS,EAAE,CAAC,EAAE,EAAE,CAAC;QACnC,IAAI,SAAS,CAAC,CAAC,CAAC,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC;YAClC,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAA;QAC3B,CAAC;aAAM,CAAC;YACN,MAAK;QACP,CAAC;IACH,CAAC;IAED,OAAO,cAAc,CAAC,MAAM,CAAC,CAAA;AAC/B,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"path-utils.test.d.ts","sourceRoot":"","sources":["../../src/match/path-utils.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
import { describe, it, expect } from 'vitest';
|
|
2
|
+
import { normalizePath, pathToSegments, segmentsToPath, isAbsolutePath, getExtension, getBasename, getDirname, isAncestorPath, commonPrefix, } from './path-utils';
|
|
3
|
+
const defaultContext = {
|
|
4
|
+
homeDir: '/home/user',
|
|
5
|
+
cwd: '/home/user/projects',
|
|
6
|
+
};
|
|
7
|
+
describe('normalizePath', () => {
|
|
8
|
+
it('expands ~ to home directory', () => {
|
|
9
|
+
expect(normalizePath('~', defaultContext)).toBe('/home/user');
|
|
10
|
+
expect(normalizePath('~/dev', defaultContext)).toBe('/home/user/dev');
|
|
11
|
+
expect(normalizePath('~/dev/project', defaultContext)).toBe('/home/user/dev/project');
|
|
12
|
+
});
|
|
13
|
+
it('resolves relative paths against cwd', () => {
|
|
14
|
+
expect(normalizePath('src', defaultContext)).toBe('/home/user/projects/src');
|
|
15
|
+
expect(normalizePath('src/index.ts', defaultContext)).toBe('/home/user/projects/src/index.ts');
|
|
16
|
+
});
|
|
17
|
+
it('leaves absolute paths unchanged (except normalization)', () => {
|
|
18
|
+
expect(normalizePath('/etc/passwd', defaultContext)).toBe('/etc/passwd');
|
|
19
|
+
expect(normalizePath('/home/other/file', defaultContext)).toBe('/home/other/file');
|
|
20
|
+
});
|
|
21
|
+
it('resolves . (current directory)', () => {
|
|
22
|
+
expect(normalizePath('./src', defaultContext)).toBe('/home/user/projects/src');
|
|
23
|
+
expect(normalizePath('src/./lib', defaultContext)).toBe('/home/user/projects/src/lib');
|
|
24
|
+
expect(normalizePath('/a/./b/./c', defaultContext)).toBe('/a/b/c');
|
|
25
|
+
});
|
|
26
|
+
it('resolves .. (parent directory)', () => {
|
|
27
|
+
expect(normalizePath('../other', defaultContext)).toBe('/home/user/other');
|
|
28
|
+
expect(normalizePath('src/../lib', defaultContext)).toBe('/home/user/projects/lib');
|
|
29
|
+
expect(normalizePath('/a/b/c/../d', defaultContext)).toBe('/a/b/d');
|
|
30
|
+
expect(normalizePath('/a/b/../c/../d', defaultContext)).toBe('/a/d');
|
|
31
|
+
});
|
|
32
|
+
it('handles .. at root (becomes no-op)', () => {
|
|
33
|
+
expect(normalizePath('/..', defaultContext)).toBe('/');
|
|
34
|
+
expect(normalizePath('/../a', defaultContext)).toBe('/a');
|
|
35
|
+
expect(normalizePath('/a/../../b', defaultContext)).toBe('/b');
|
|
36
|
+
});
|
|
37
|
+
it('removes trailing slashes', () => {
|
|
38
|
+
expect(normalizePath('/home/user/', defaultContext)).toBe('/home/user');
|
|
39
|
+
expect(normalizePath('~/dev/', defaultContext)).toBe('/home/user/dev');
|
|
40
|
+
});
|
|
41
|
+
it('removes duplicate slashes', () => {
|
|
42
|
+
expect(normalizePath('/home//user///dev', defaultContext)).toBe('/home/user/dev');
|
|
43
|
+
});
|
|
44
|
+
it('converts backslashes to forward slashes', () => {
|
|
45
|
+
expect(normalizePath('/home\\user\\dev', defaultContext)).toBe('/home/user/dev');
|
|
46
|
+
expect(normalizePath('src\\lib\\file.ts', defaultContext)).toBe('/home/user/projects/src/lib/file.ts');
|
|
47
|
+
});
|
|
48
|
+
it('handles empty path', () => {
|
|
49
|
+
expect(normalizePath('', defaultContext)).toBe('/home/user/projects');
|
|
50
|
+
});
|
|
51
|
+
});
|
|
52
|
+
describe('pathToSegments', () => {
|
|
53
|
+
it('splits path into segments', () => {
|
|
54
|
+
expect(pathToSegments('/home/user/dev')).toEqual(['home', 'user', 'dev']);
|
|
55
|
+
expect(pathToSegments('/a/b/c/d')).toEqual(['a', 'b', 'c', 'd']);
|
|
56
|
+
});
|
|
57
|
+
it('handles root path', () => {
|
|
58
|
+
expect(pathToSegments('/')).toEqual([]);
|
|
59
|
+
});
|
|
60
|
+
it('handles empty string', () => {
|
|
61
|
+
expect(pathToSegments('')).toEqual([]);
|
|
62
|
+
});
|
|
63
|
+
it('handles single segment', () => {
|
|
64
|
+
expect(pathToSegments('/file')).toEqual(['file']);
|
|
65
|
+
});
|
|
66
|
+
it('handles paths without leading slash', () => {
|
|
67
|
+
expect(pathToSegments('a/b/c')).toEqual(['a', 'b', 'c']);
|
|
68
|
+
});
|
|
69
|
+
it('handles trailing slash', () => {
|
|
70
|
+
expect(pathToSegments('/home/user/')).toEqual(['home', 'user']);
|
|
71
|
+
});
|
|
72
|
+
});
|
|
73
|
+
describe('segmentsToPath', () => {
|
|
74
|
+
it('joins segments into path', () => {
|
|
75
|
+
expect(segmentsToPath(['home', 'user', 'dev'])).toBe('/home/user/dev');
|
|
76
|
+
expect(segmentsToPath(['a', 'b', 'c'])).toBe('/a/b/c');
|
|
77
|
+
});
|
|
78
|
+
it('handles empty segments array', () => {
|
|
79
|
+
expect(segmentsToPath([])).toBe('/');
|
|
80
|
+
});
|
|
81
|
+
it('handles single segment', () => {
|
|
82
|
+
expect(segmentsToPath(['file'])).toBe('/file');
|
|
83
|
+
});
|
|
84
|
+
it('round-trips with pathToSegments', () => {
|
|
85
|
+
const paths = ['/home/user/dev', '/a/b/c/d', '/file', '/'];
|
|
86
|
+
for (const path of paths) {
|
|
87
|
+
expect(segmentsToPath(pathToSegments(path))).toBe(path);
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
});
|
|
91
|
+
describe('isAbsolutePath', () => {
|
|
92
|
+
it('returns true for paths starting with /', () => {
|
|
93
|
+
expect(isAbsolutePath('/home/user')).toBe(true);
|
|
94
|
+
expect(isAbsolutePath('/etc/passwd')).toBe(true);
|
|
95
|
+
expect(isAbsolutePath('/')).toBe(true);
|
|
96
|
+
});
|
|
97
|
+
it('returns true for paths starting with ~', () => {
|
|
98
|
+
expect(isAbsolutePath('~')).toBe(true);
|
|
99
|
+
expect(isAbsolutePath('~/dev')).toBe(true);
|
|
100
|
+
expect(isAbsolutePath('~/.config')).toBe(true);
|
|
101
|
+
});
|
|
102
|
+
it('returns false for relative paths', () => {
|
|
103
|
+
expect(isAbsolutePath('src')).toBe(false);
|
|
104
|
+
expect(isAbsolutePath('src/index.ts')).toBe(false);
|
|
105
|
+
expect(isAbsolutePath('./file')).toBe(false);
|
|
106
|
+
expect(isAbsolutePath('../parent')).toBe(false);
|
|
107
|
+
});
|
|
108
|
+
});
|
|
109
|
+
describe('getExtension', () => {
|
|
110
|
+
it('extracts file extension', () => {
|
|
111
|
+
expect(getExtension('file.ts')).toBe('.ts');
|
|
112
|
+
expect(getExtension('file.test.ts')).toBe('.ts');
|
|
113
|
+
expect(getExtension('archive.tar.gz')).toBe('.gz');
|
|
114
|
+
});
|
|
115
|
+
it('returns empty for files without extension', () => {
|
|
116
|
+
expect(getExtension('Makefile')).toBe('');
|
|
117
|
+
expect(getExtension('README')).toBe('');
|
|
118
|
+
});
|
|
119
|
+
it('returns empty for dotfiles (starting with dot)', () => {
|
|
120
|
+
expect(getExtension('.gitignore')).toBe('');
|
|
121
|
+
expect(getExtension('.env')).toBe('');
|
|
122
|
+
expect(getExtension('.bashrc')).toBe('');
|
|
123
|
+
});
|
|
124
|
+
it('handles dotfiles with extensions', () => {
|
|
125
|
+
expect(getExtension('.eslintrc.json')).toBe('.json');
|
|
126
|
+
expect(getExtension('.prettierrc.yaml')).toBe('.yaml');
|
|
127
|
+
});
|
|
128
|
+
it('handles full paths', () => {
|
|
129
|
+
expect(getExtension('/home/user/file.ts')).toBe('.ts');
|
|
130
|
+
expect(getExtension('/home/user/.gitignore')).toBe('');
|
|
131
|
+
});
|
|
132
|
+
});
|
|
133
|
+
describe('getBasename', () => {
|
|
134
|
+
it('returns the final segment', () => {
|
|
135
|
+
expect(getBasename('/home/user/file.ts')).toBe('file.ts');
|
|
136
|
+
expect(getBasename('/a/b/c')).toBe('c');
|
|
137
|
+
});
|
|
138
|
+
it('handles root path', () => {
|
|
139
|
+
expect(getBasename('/')).toBe('');
|
|
140
|
+
});
|
|
141
|
+
it('handles single segment', () => {
|
|
142
|
+
expect(getBasename('/file')).toBe('file');
|
|
143
|
+
});
|
|
144
|
+
});
|
|
145
|
+
describe('getDirname', () => {
|
|
146
|
+
it('returns the directory portion', () => {
|
|
147
|
+
expect(getDirname('/home/user/file.ts')).toBe('/home/user');
|
|
148
|
+
expect(getDirname('/a/b/c/d')).toBe('/a/b/c');
|
|
149
|
+
});
|
|
150
|
+
it('handles paths at root level', () => {
|
|
151
|
+
expect(getDirname('/file')).toBe('/');
|
|
152
|
+
expect(getDirname('/')).toBe('/');
|
|
153
|
+
});
|
|
154
|
+
});
|
|
155
|
+
describe('isAncestorPath', () => {
|
|
156
|
+
it('returns true for ancestor paths', () => {
|
|
157
|
+
expect(isAncestorPath('/home', '/home/user/dev')).toBe(true);
|
|
158
|
+
expect(isAncestorPath('/home/user', '/home/user/dev/file.ts')).toBe(true);
|
|
159
|
+
});
|
|
160
|
+
it('returns true for same path', () => {
|
|
161
|
+
expect(isAncestorPath('/home/user', '/home/user')).toBe(true);
|
|
162
|
+
});
|
|
163
|
+
it('returns false for non-ancestors', () => {
|
|
164
|
+
expect(isAncestorPath('/home/user', '/home/other')).toBe(false);
|
|
165
|
+
expect(isAncestorPath('/home/user/dev', '/home/user')).toBe(false);
|
|
166
|
+
});
|
|
167
|
+
it('handles root', () => {
|
|
168
|
+
expect(isAncestorPath('/', '/home/user')).toBe(true);
|
|
169
|
+
expect(isAncestorPath('/', '/')).toBe(true);
|
|
170
|
+
});
|
|
171
|
+
// Negative test: partial segment matches should fail
|
|
172
|
+
it('does not match partial segments', () => {
|
|
173
|
+
// '/home/user' is NOT an ancestor of '/home/username'
|
|
174
|
+
expect(isAncestorPath('/home/user', '/home/username')).toBe(false);
|
|
175
|
+
});
|
|
176
|
+
});
|
|
177
|
+
describe('commonPrefix', () => {
|
|
178
|
+
it('finds common prefix', () => {
|
|
179
|
+
expect(commonPrefix('/home/user/a/b', '/home/user/c/d')).toBe('/home/user');
|
|
180
|
+
expect(commonPrefix('/a/b/c', '/a/b/d')).toBe('/a/b');
|
|
181
|
+
});
|
|
182
|
+
it('returns root when no common prefix', () => {
|
|
183
|
+
expect(commonPrefix('/home/user', '/etc/passwd')).toBe('/');
|
|
184
|
+
});
|
|
185
|
+
it('returns full path when identical', () => {
|
|
186
|
+
expect(commonPrefix('/home/user', '/home/user')).toBe('/home/user');
|
|
187
|
+
});
|
|
188
|
+
it('handles one path being prefix of another', () => {
|
|
189
|
+
expect(commonPrefix('/home/user', '/home/user/dev')).toBe('/home/user');
|
|
190
|
+
expect(commonPrefix('/home/user/dev', '/home/user')).toBe('/home/user');
|
|
191
|
+
});
|
|
192
|
+
});
|
|
193
|
+
//# sourceMappingURL=path-utils.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"path-utils.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AC,kCAAkC,EAAE,GAAG,EAAE;QAC1C,MAAM,CAAC,YAAY,CAAC,YAAY,EAAE,YAAY,CAAC,CAAC,CAAC,IAAI,CAAC,YAAY,CAAC,CAAA;IACrE,CAAC,CAAC,CAAA;IAEF,EAAE,CAAC,0CAA0C,EAAE,GAAG,EAAE;QAClD,MAAM,CAAC,YAAY,CAAC,YAAY,EAAE,gBAAgB,CAAC,CAAC,CAAC,IAAI,CAAC,YAAY,CAAC,CAAA;QACvE,MAAM,CAAC,YAAY,CAAC,gBAAgB,EAAE,YAAY,CAAC,CAAC,CAAC,IAAI,CAAC,YAAY,CAAC,CAAA;IACzE,CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Segment-level matching utilities.
|
|
3
|
+
* @packageDocumentation
|
|
4
|
+
*/
|
|
5
|
+
import type { Segment } from '../types';
|
|
6
|
+
/**
|
|
7
|
+
* Check if a path segment matches a segment pattern.
|
|
8
|
+
*
|
|
9
|
+
* @param segment - The actual path segment (e.g., "file.ts")
|
|
10
|
+
* @param pattern - The pattern segment from AST
|
|
11
|
+
* @returns true if the segment matches
|
|
12
|
+
*
|
|
13
|
+
* @public
|
|
14
|
+
*/
|
|
15
|
+
export declare function matchSegment(segment: string, pattern: Segment): boolean;
|
|
16
|
+
/**
|
|
17
|
+
* Build a RegExp from a segment pattern for automaton transitions.
|
|
18
|
+
*
|
|
19
|
+
* @param pattern - Segment pattern
|
|
20
|
+
* @returns RegExp that matches the segment, or null for globstar/literal
|
|
21
|
+
*
|
|
22
|
+
* @public
|
|
23
|
+
*/
|
|
24
|
+
export declare function segmentToRegex(pattern: Segment): RegExp | null;
|
|
25
|
+
//# sourceMappingURL=segment-matcher.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"segment-matcher.d.ts","sourceRoot":"","sources":["../../src/match/segment-matcher.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAkF,MAAM,UAAU,CAAA;AAEvH;;;;;;;;GAQG;AACH,wBAAgB,YAAY,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,GAAG,OAAO,CAmBvE;AAwJD;;;;;;;GAOG;AACH,wBAAgB,cAAc,CAAC,OAAO,EAAE,OAAO,GAAG,MAAM,GAAG,IAAI,CAmB9D"}
|