@boundaries/elements 1.0.0 → 1.1.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 +8 -4
- package/dist/index.browser.d.mts +227 -137
- package/dist/index.browser.d.ts +227 -137
- package/dist/index.browser.js +600 -467
- package/dist/index.browser.js.map +1 -1
- package/dist/index.browser.mjs +600 -467
- package/dist/index.browser.mjs.map +1 -1
- package/dist/index.d.mts +227 -137
- package/dist/index.d.ts +227 -137
- package/dist/index.js +600 -467
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +600 -467
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -4
package/README.md
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
|
|
9
9
|
# @boundaries/elements
|
|
10
10
|
|
|
11
|
-
> Element descriptors and matchers for
|
|
11
|
+
> Element descriptors and matchers for `@boundaries` tools, such as `@boundaries/eslint-plugin`.
|
|
12
12
|
|
|
13
13
|
## Table of Contents
|
|
14
14
|
|
|
@@ -128,6 +128,7 @@ const elements = new Elements({
|
|
|
128
128
|
- **`ignorePaths`**: Micromatch pattern(s) to exclude certain paths from element matching (default: none)
|
|
129
129
|
- **`includePaths`**: Micromatch pattern(s) to include only specific paths (default: all paths)
|
|
130
130
|
- **`legacyTemplates`**: Whether to enable legacy template syntax support (default: `true`, but it will be `false` in future releases). This allows using `${variable}` syntax in templates for backward compatibility.
|
|
131
|
+
- **`cache`**: Whether to enable internal caching to improve performance (default: `true`)
|
|
131
132
|
|
|
132
133
|
### Creating a Matcher
|
|
133
134
|
|
|
@@ -384,7 +385,7 @@ const matcher = elements.getMatcher([
|
|
|
384
385
|
|
|
385
386
|
##### `clearCache`
|
|
386
387
|
|
|
387
|
-
Clears all cached matcher instances.
|
|
388
|
+
Clears all cached matcher instances and shared caches.
|
|
388
389
|
|
|
389
390
|
```ts
|
|
390
391
|
elements.clearCache();
|
|
@@ -392,14 +393,14 @@ elements.clearCache();
|
|
|
392
393
|
|
|
393
394
|
##### `serializeCache`
|
|
394
395
|
|
|
395
|
-
Serializes all cached matcher instances to a plain object.
|
|
396
|
+
Serializes all cached matcher instances and shared caches to a plain object.
|
|
396
397
|
|
|
397
398
|
```ts
|
|
398
399
|
const cache = elements.serializeCache();
|
|
399
400
|
```
|
|
400
401
|
|
|
401
402
|
##### `setCacheFromSerialized`
|
|
402
|
-
Sets the cached matcher instances from a serialized object.
|
|
403
|
+
Sets the cached matcher instances and shared caches from a serialized object.
|
|
403
404
|
|
|
404
405
|
```ts
|
|
405
406
|
const cache = elements.serializeCache();
|
|
@@ -495,6 +496,9 @@ Clears the matcher's internal cache.
|
|
|
495
496
|
matcher.clearCache();
|
|
496
497
|
```
|
|
497
498
|
|
|
499
|
+
> [!WARNING]
|
|
500
|
+
> This only clears the internal cache for this matcher instance. Shared cache for micromatch results, regex and captures is not affected. You can clear all caches using `Elements.clearCache()`.
|
|
501
|
+
|
|
498
502
|
#### `serializeCache`
|
|
499
503
|
|
|
500
504
|
Serializes the matcher's cache.
|
package/dist/index.browser.d.mts
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import { NotUndefined } from 'object-hash';
|
|
2
|
-
|
|
3
1
|
/**
|
|
4
2
|
* Type representing a micromatch pattern, which can be a string or an array of strings.
|
|
5
3
|
*/
|
|
@@ -15,11 +13,19 @@ type ConfigOptions = {
|
|
|
15
13
|
* When enabled, it supports using "${...}" syntax in templates.
|
|
16
14
|
**/
|
|
17
15
|
legacyTemplates?: boolean;
|
|
16
|
+
/** Whether to enable caching */
|
|
17
|
+
cache?: boolean;
|
|
18
18
|
};
|
|
19
|
-
type ConfigOptionsNormalized = Omit<ConfigOptions, "legacyTemplates"> & {
|
|
19
|
+
type ConfigOptionsNormalized = Omit<ConfigOptions, "legacyTemplates" | "cache"> & {
|
|
20
20
|
/** Whether to enable legacy template support */
|
|
21
21
|
legacyTemplates: boolean;
|
|
22
|
+
/** Cache configuration options */
|
|
23
|
+
cache: boolean;
|
|
22
24
|
};
|
|
25
|
+
/** Options for descriptors */
|
|
26
|
+
type DescriptorOptionsNormalized = Pick<ConfigOptionsNormalized, "includePaths" | "ignorePaths" | "cache">;
|
|
27
|
+
/** Options for element matchers */
|
|
28
|
+
type MatchersOptionsNormalized = Pick<ConfigOptionsNormalized, "legacyTemplates">;
|
|
23
29
|
|
|
24
30
|
/**
|
|
25
31
|
* Map of the modes to interpret the pattern in an ElementDescriptor.
|
|
@@ -116,7 +122,20 @@ type ElementDescriptors = ElementDescriptor[];
|
|
|
116
122
|
/**
|
|
117
123
|
* Serialized cache of element descriptions.
|
|
118
124
|
*/
|
|
119
|
-
type
|
|
125
|
+
type DescriptionsSerializedCache = Record<string, ElementDescription>;
|
|
126
|
+
/**
|
|
127
|
+
* Serialized cache of file elements.
|
|
128
|
+
*/
|
|
129
|
+
type FileElementsSerializedCache = Record<string, FileElement>;
|
|
130
|
+
/**
|
|
131
|
+
* Serialized cache for ElementsDescriptor class.
|
|
132
|
+
*/
|
|
133
|
+
type ElementsDescriptorSerializedCache = {
|
|
134
|
+
/** Serialized descriptions cache */
|
|
135
|
+
descriptions: DescriptionsSerializedCache;
|
|
136
|
+
/** Serialized files cache */
|
|
137
|
+
files: FileElementsSerializedCache;
|
|
138
|
+
};
|
|
120
139
|
/**
|
|
121
140
|
* Captured values from an element path.
|
|
122
141
|
*/
|
|
@@ -527,52 +546,6 @@ type DescriptorsSerializedCache = {
|
|
|
527
546
|
dependencies: DependenciesDescriptorSerializedCache;
|
|
528
547
|
};
|
|
529
548
|
|
|
530
|
-
/**
|
|
531
|
-
* Class with methods to describe elements and dependencies between them.
|
|
532
|
-
*/
|
|
533
|
-
declare class Descriptors {
|
|
534
|
-
private readonly _elementsDescriptor;
|
|
535
|
-
private readonly _dependenciesDescriptor;
|
|
536
|
-
/** Creates a new DescriptorsManager instance
|
|
537
|
-
* @param elementDescriptors The element descriptors.
|
|
538
|
-
* @param configOptions The configuration options.
|
|
539
|
-
*/
|
|
540
|
-
constructor(elementDescriptors: ElementDescriptors, configOptions?: ConfigOptions);
|
|
541
|
-
/**
|
|
542
|
-
* Serializes the elements and dependencies cache to a plain object.
|
|
543
|
-
* @returns The serialized elements and dependencies cache.
|
|
544
|
-
*/
|
|
545
|
-
serializeCache(): DescriptorsSerializedCache;
|
|
546
|
-
/**
|
|
547
|
-
* Sets the elements and dependencies cache from a serialized object.
|
|
548
|
-
* @param serializedCache The serialized elements and dependencies cache.
|
|
549
|
-
*/
|
|
550
|
-
setCacheFromSerialized(serializedCache: DescriptorsSerializedCache): void;
|
|
551
|
-
/**
|
|
552
|
-
* Clears all caches.
|
|
553
|
-
*/
|
|
554
|
-
clearCache(): void;
|
|
555
|
-
/**
|
|
556
|
-
* Describes an element given its file path.
|
|
557
|
-
* @param filePath The path of the file to describe.
|
|
558
|
-
* @returns The description of the element.
|
|
559
|
-
*/
|
|
560
|
-
describeElement(filePath?: string): FileElement;
|
|
561
|
-
/**
|
|
562
|
-
* Describes a dependency element given its dependency source and file path.
|
|
563
|
-
* @param dependencySource The source of the dependency.
|
|
564
|
-
* @param filePath The path of the file being the dependency, if known.
|
|
565
|
-
* @returns The description of the dependency element.
|
|
566
|
-
*/
|
|
567
|
-
describeDependencyElement(dependencySource: string, filePath?: string): DependencyElementDescription;
|
|
568
|
-
/**
|
|
569
|
-
* Describes elements in a dependency relationship, and provides additional information about the dependency itself.
|
|
570
|
-
* @param options The options for describing the elements and the dependency details.
|
|
571
|
-
* @returns The description of the dependency between the elements.
|
|
572
|
-
*/
|
|
573
|
-
describeDependency(options: DescribeDependencyOptions): DependencyDescription;
|
|
574
|
-
}
|
|
575
|
-
|
|
576
549
|
/**
|
|
577
550
|
* Result of matching an element selector against an element.
|
|
578
551
|
*/
|
|
@@ -592,10 +565,18 @@ type ElementsMatcherSerializedCache = Record<string, ElementSelectorData | null>
|
|
|
592
565
|
* Serialized cache of dependencies matcher.
|
|
593
566
|
*/
|
|
594
567
|
type DependenciesMatcherSerializedCache = Record<string, DependencyMatchResult>;
|
|
568
|
+
/**
|
|
569
|
+
* Serialized cache of matcher descriptors.
|
|
570
|
+
*/
|
|
595
571
|
type MatcherSerializedCache = {
|
|
596
572
|
descriptors: DescriptorsSerializedCache;
|
|
597
|
-
|
|
598
|
-
|
|
573
|
+
};
|
|
574
|
+
/**
|
|
575
|
+
* Serialized cache of micromatch matcher.
|
|
576
|
+
*/
|
|
577
|
+
type MicromatchSerializedCache = {
|
|
578
|
+
matchingResults: Record<string, boolean>;
|
|
579
|
+
captures: Record<string, string[] | null>;
|
|
599
580
|
};
|
|
600
581
|
/**
|
|
601
582
|
* Elements that can return a match when using an element selector.
|
|
@@ -784,6 +765,63 @@ type ExternalLibrarySelectors = ExternalLibrariesSelector;
|
|
|
784
765
|
*/
|
|
785
766
|
type ExternalLibrariesSelector = ExternalLibrarySelector | ExternalLibrarySelector[];
|
|
786
767
|
|
|
768
|
+
/**
|
|
769
|
+
* Micromatch wrapper class with caching capabilities.
|
|
770
|
+
*/
|
|
771
|
+
declare class Micromatch {
|
|
772
|
+
/**
|
|
773
|
+
* Cache for micromatch matching results
|
|
774
|
+
*/
|
|
775
|
+
private readonly _matchingResultsCache;
|
|
776
|
+
/**
|
|
777
|
+
* Cache for micromatch captures
|
|
778
|
+
*/
|
|
779
|
+
private readonly _capturesCache;
|
|
780
|
+
/**
|
|
781
|
+
* Cache for micromatch makeRe results
|
|
782
|
+
*/
|
|
783
|
+
private readonly _makeReCache;
|
|
784
|
+
/**
|
|
785
|
+
* Creates an instance of Micromatch class.
|
|
786
|
+
* @param cache Whether to use caching or not.
|
|
787
|
+
*/
|
|
788
|
+
constructor(cache: boolean);
|
|
789
|
+
/**
|
|
790
|
+
* Clears all caches.
|
|
791
|
+
*/
|
|
792
|
+
clearCache(): void;
|
|
793
|
+
/**
|
|
794
|
+
* Serializes the current cache state.
|
|
795
|
+
* @returns The serialized cache data.
|
|
796
|
+
*/
|
|
797
|
+
serializeCache(): MicromatchSerializedCache;
|
|
798
|
+
/**
|
|
799
|
+
* Restores the cache state from serialized data.
|
|
800
|
+
* @param serializedCache The serialized cache data.
|
|
801
|
+
*/
|
|
802
|
+
setFromSerialized(serializedCache: MicromatchSerializedCache): void;
|
|
803
|
+
/**
|
|
804
|
+
* Optimized micromatch match with caching.
|
|
805
|
+
* @param value The value to match.
|
|
806
|
+
* @param pattern The pattern to match against.
|
|
807
|
+
* @returns True if the value matches the pattern, false otherwise.
|
|
808
|
+
*/
|
|
809
|
+
isMatch(value: string, pattern: string | string[]): boolean;
|
|
810
|
+
/**
|
|
811
|
+
* Optimized micromatch capture with caching.
|
|
812
|
+
* @param pattern The pattern to match against.
|
|
813
|
+
* @param target The target string to test.
|
|
814
|
+
* @returns Captured groups or null if no match.
|
|
815
|
+
*/
|
|
816
|
+
capture(pattern: string, target: string): string[] | null;
|
|
817
|
+
/**
|
|
818
|
+
* Optimized micromatch makeRe with caching.
|
|
819
|
+
* @param pattern The pattern to convert to RegExp.
|
|
820
|
+
* @returns The RegExp instance.
|
|
821
|
+
*/
|
|
822
|
+
makeRe(pattern: string): RegExp;
|
|
823
|
+
}
|
|
824
|
+
|
|
787
825
|
/**
|
|
788
826
|
* Normalizes an ElementsSelector into an array of ElementSelectorData.
|
|
789
827
|
* @param elementsSelector The elements selector, in any supported format.
|
|
@@ -795,22 +833,37 @@ declare function normalizeElementsSelector(elementsSelector: DependencyElementsS
|
|
|
795
833
|
* Base matcher class to determine if elements or dependencies match a given selector.
|
|
796
834
|
*/
|
|
797
835
|
declare class BaseElementsMatcher {
|
|
836
|
+
/**
|
|
837
|
+
* Option to use legacy templates with ${} syntax.
|
|
838
|
+
*/
|
|
798
839
|
protected readonly _legacyTemplates: boolean;
|
|
840
|
+
/**
|
|
841
|
+
* Micromatch instance for matching.
|
|
842
|
+
*/
|
|
843
|
+
protected micromatch: Micromatch;
|
|
799
844
|
/**
|
|
800
845
|
* Creates a new BaseElementsMatcher.
|
|
801
846
|
* @param config Configuration options for the matcher.
|
|
847
|
+
* @param globalCache Global cache instance.
|
|
802
848
|
*/
|
|
803
|
-
constructor(config:
|
|
849
|
+
constructor(config: MatchersOptionsNormalized, micromatch: Micromatch);
|
|
804
850
|
/**
|
|
805
851
|
* Converts a template with ${} to Handlebars {{}} templates for backwards compatibility.
|
|
806
852
|
* @param template The template to convert.
|
|
807
853
|
* @returns The converted template.
|
|
808
854
|
*/
|
|
809
855
|
private _getBackwardsCompatibleTemplate;
|
|
856
|
+
/**
|
|
857
|
+
* Determines if a template contains Handlebars syntax.
|
|
858
|
+
* @param template The template to check.
|
|
859
|
+
* @returns True if the template contains Handlebars syntax, false otherwise.
|
|
860
|
+
*/
|
|
861
|
+
private _isHandlebarsTemplate;
|
|
810
862
|
/**
|
|
811
863
|
* Returns a rendered template using the provided template data.
|
|
864
|
+
* Optimized version with template caching for better performance.
|
|
812
865
|
* @param template The template to render.
|
|
813
|
-
* @param
|
|
866
|
+
* @param templateData The data to use for replace in the template.
|
|
814
867
|
* @returns The rendered template.
|
|
815
868
|
*/
|
|
816
869
|
private _getRenderedTemplate;
|
|
@@ -823,11 +876,20 @@ declare class BaseElementsMatcher {
|
|
|
823
876
|
protected getRenderedTemplates(template: MicromatchPattern, templateData: TemplateData): MicromatchPattern;
|
|
824
877
|
/**
|
|
825
878
|
* Returns whether the given value matches the micromatch pattern, converting non-string values to strings.
|
|
879
|
+
* Optimized version with caching for better performance.
|
|
826
880
|
* @param value The value to check.
|
|
827
881
|
* @param pattern The micromatch pattern to match against.
|
|
828
882
|
* @returns Whether the value matches the pattern.
|
|
829
883
|
*/
|
|
830
884
|
protected isMicromatchMatch(value: unknown, pattern: MicromatchPattern): boolean;
|
|
885
|
+
/**
|
|
886
|
+
* Returns whether the given value matches the micromatch pattern after rendering it as a template.
|
|
887
|
+
* @param pattern The micromatch pattern to render and match against.
|
|
888
|
+
* @param templateData The data to use for rendering the pattern as a template.
|
|
889
|
+
* @param value The value to check.
|
|
890
|
+
* @returns Whether the value matches the rendered pattern.
|
|
891
|
+
*/
|
|
892
|
+
protected isTemplateMicromatchMatch(pattern: MicromatchPattern, templateData: TemplateData, value?: unknown): boolean;
|
|
831
893
|
/**
|
|
832
894
|
* Whether the given element key matches the selector key as booleans.
|
|
833
895
|
* @param param0 The parameters object.
|
|
@@ -876,28 +938,15 @@ declare class BaseElementsMatcher {
|
|
|
876
938
|
* Matcher class to determine if elements match a given selector.
|
|
877
939
|
*/
|
|
878
940
|
declare class ElementsMatcher extends BaseElementsMatcher {
|
|
879
|
-
/**
|
|
880
|
-
|
|
881
|
-
*/
|
|
882
|
-
private readonly _cache;
|
|
941
|
+
/** Whether the cache is enabled or not */
|
|
942
|
+
private readonly _cacheIsEnabled;
|
|
883
943
|
/**
|
|
884
944
|
* Creates a new ElementsSelectorMatcher.
|
|
945
|
+
* @param config Configuration options for the matcher.
|
|
946
|
+
* @param micromatch Micromatch instance for matching.
|
|
947
|
+
* @param globalCache Global cache instance.
|
|
885
948
|
*/
|
|
886
|
-
constructor(config:
|
|
887
|
-
/**
|
|
888
|
-
* Serializes the cache to a plain object.
|
|
889
|
-
* @returns The serialized cache.
|
|
890
|
-
*/
|
|
891
|
-
serializeCache(): ElementsMatcherSerializedCache;
|
|
892
|
-
/**
|
|
893
|
-
* Sets the cache from a serialized object.
|
|
894
|
-
* @param serializedCache The serialized cache.
|
|
895
|
-
*/
|
|
896
|
-
setCacheFromSerialized(serializedCache: ElementsMatcherSerializedCache): void;
|
|
897
|
-
/**
|
|
898
|
-
* Clears the cache.
|
|
899
|
-
*/
|
|
900
|
-
clearCache(): void;
|
|
949
|
+
constructor(config: MatchersOptionsNormalized, micromatch: Micromatch);
|
|
901
950
|
/**
|
|
902
951
|
* Whether the given element type matches the selector type.
|
|
903
952
|
* @param element The element to check.
|
|
@@ -1016,32 +1065,18 @@ declare class ElementsMatcher extends BaseElementsMatcher {
|
|
|
1016
1065
|
* Matcher class to determine if dependencies match a given dependencies selector.
|
|
1017
1066
|
*/
|
|
1018
1067
|
declare class DependenciesMatcher extends BaseElementsMatcher {
|
|
1019
|
-
/**
|
|
1020
|
-
* Cache to store previously described dependencies.
|
|
1021
|
-
*/
|
|
1022
|
-
private readonly _cache;
|
|
1023
1068
|
/**
|
|
1024
1069
|
* Elements matcher to use for matching elements within dependencies.
|
|
1025
1070
|
*/
|
|
1026
1071
|
private readonly _elementsMatcher;
|
|
1027
1072
|
/**
|
|
1028
1073
|
* Creates a new DependenciesMatcher.
|
|
1074
|
+
* @param elementsMatcher Elements matcher to use for matching elements within dependencies.
|
|
1075
|
+
* @param config Configuration options for the matcher.
|
|
1076
|
+
* @param micromatch Micromatch instance for matching.
|
|
1077
|
+
* @param globalCache Global cache instance.
|
|
1029
1078
|
*/
|
|
1030
|
-
constructor(elementsMatcher: ElementsMatcher, config:
|
|
1031
|
-
/**
|
|
1032
|
-
* Serializes the cache to a plain object.
|
|
1033
|
-
* @returns The serialized cache.
|
|
1034
|
-
*/
|
|
1035
|
-
serializeCache(): DependenciesMatcherSerializedCache;
|
|
1036
|
-
/**
|
|
1037
|
-
* Sets the cache from a serialized object.
|
|
1038
|
-
* @param serializedCache The serialized cache.
|
|
1039
|
-
*/
|
|
1040
|
-
setCacheFromSerialized(serializedCache: DependenciesMatcherSerializedCache): void;
|
|
1041
|
-
/**
|
|
1042
|
-
* Clears the cache.
|
|
1043
|
-
*/
|
|
1044
|
-
clearCache(): void;
|
|
1079
|
+
constructor(elementsMatcher: ElementsMatcher, config: MatchersOptionsNormalized, micromatch: Micromatch);
|
|
1045
1080
|
/**
|
|
1046
1081
|
* Normalizes selector into DependencySelectorNormalized format, containing arrays of selectors data.
|
|
1047
1082
|
* @param selector The dependency selector to normalize.
|
|
@@ -1226,9 +1261,12 @@ declare class Matcher {
|
|
|
1226
1261
|
/**
|
|
1227
1262
|
* Constructor for the Matcher class.
|
|
1228
1263
|
* @param descriptors Element descriptors to use for matching.
|
|
1264
|
+
* @param elementsMatcher Elements matcher instance.
|
|
1265
|
+
* @param dependenciesMatcher Dependencies matcher instance.
|
|
1229
1266
|
* @param config Configuration options.
|
|
1267
|
+
* @param globalCache Global cache instance.
|
|
1230
1268
|
*/
|
|
1231
|
-
constructor(descriptors: ElementDescriptors, config:
|
|
1269
|
+
constructor(descriptors: ElementDescriptors, elementsMatcher: ElementsMatcher, dependenciesMatcher: DependenciesMatcher, config: DescriptorOptionsNormalized, micromatch: Micromatch);
|
|
1232
1270
|
/**
|
|
1233
1271
|
* Determines if an element matches a given selector.
|
|
1234
1272
|
* @param filePath The file path of the element
|
|
@@ -1268,7 +1306,7 @@ declare class Matcher {
|
|
|
1268
1306
|
* @param options Extra options for matching
|
|
1269
1307
|
* @returns The matching dependency result or null if no match is found
|
|
1270
1308
|
*/
|
|
1271
|
-
private
|
|
1309
|
+
private _getDependencySelectorMatching;
|
|
1272
1310
|
/**
|
|
1273
1311
|
* Determines the selector matching for a dependency or element.
|
|
1274
1312
|
* @param descriptorOptions The file path or dependency options to describe the element or dependency
|
|
@@ -1311,21 +1349,66 @@ declare class Matcher {
|
|
|
1311
1349
|
*/
|
|
1312
1350
|
clearCache(): void;
|
|
1313
1351
|
/**
|
|
1314
|
-
* Serializes the descriptors
|
|
1352
|
+
* Serializes the descriptors matchers cache to a plain object.
|
|
1315
1353
|
* @returns The serialized cache
|
|
1316
1354
|
*/
|
|
1317
1355
|
serializeCache(): MatcherSerializedCache;
|
|
1318
1356
|
/**
|
|
1319
|
-
* Sets the descriptors
|
|
1357
|
+
* Sets the descriptors matchers cache from a serialized object.
|
|
1320
1358
|
* @param serializedCache The serialized cache
|
|
1321
1359
|
*/
|
|
1322
1360
|
setCacheFromSerialized(serializedCache: {
|
|
1323
1361
|
descriptors: ReturnType<Descriptors["serializeCache"]>;
|
|
1324
|
-
elementsMatcher: ReturnType<ElementsMatcher["serializeCache"]>;
|
|
1325
|
-
dependenciesMatcher: ReturnType<DependenciesMatcher["serializeCache"]>;
|
|
1326
1362
|
}): void;
|
|
1327
1363
|
}
|
|
1328
1364
|
|
|
1365
|
+
/**
|
|
1366
|
+
* Class with methods to describe elements and dependencies between them.
|
|
1367
|
+
*/
|
|
1368
|
+
declare class Descriptors {
|
|
1369
|
+
private readonly _elementsDescriptor;
|
|
1370
|
+
private readonly _dependenciesDescriptor;
|
|
1371
|
+
/** Creates a new DescriptorsManager instance
|
|
1372
|
+
* @param elementDescriptors The element descriptors.
|
|
1373
|
+
* @param configOptions The configuration options.
|
|
1374
|
+
* @param micromatch The Micromatch instance.
|
|
1375
|
+
*/
|
|
1376
|
+
constructor(elementDescriptors: ElementDescriptors, config: DescriptorOptionsNormalized, micromatch: Micromatch);
|
|
1377
|
+
/**
|
|
1378
|
+
* Serializes the elements and dependencies cache to a plain object.
|
|
1379
|
+
* @returns The serialized elements and dependencies cache.
|
|
1380
|
+
*/
|
|
1381
|
+
serializeCache(): DescriptorsSerializedCache;
|
|
1382
|
+
/**
|
|
1383
|
+
* Sets the elements and dependencies cache from a serialized object.
|
|
1384
|
+
* @param serializedCache The serialized elements and dependencies cache.
|
|
1385
|
+
*/
|
|
1386
|
+
setCacheFromSerialized(serializedCache: DescriptorsSerializedCache): void;
|
|
1387
|
+
/**
|
|
1388
|
+
* Clears all caches.
|
|
1389
|
+
*/
|
|
1390
|
+
clearCache(): void;
|
|
1391
|
+
/**
|
|
1392
|
+
* Describes an element given its file path.
|
|
1393
|
+
* @param filePath The path of the file to describe.
|
|
1394
|
+
* @returns The description of the element.
|
|
1395
|
+
*/
|
|
1396
|
+
describeElement(filePath?: string): FileElement;
|
|
1397
|
+
/**
|
|
1398
|
+
* Describes a dependency element given its dependency source and file path.
|
|
1399
|
+
* @param dependencySource The source of the dependency.
|
|
1400
|
+
* @param filePath The path of the file being the dependency, if known.
|
|
1401
|
+
* @returns The description of the dependency element.
|
|
1402
|
+
*/
|
|
1403
|
+
describeDependencyElement(dependencySource: string, filePath?: string): DependencyElementDescription;
|
|
1404
|
+
/**
|
|
1405
|
+
* Describes elements in a dependency relationship, and provides additional information about the dependency itself.
|
|
1406
|
+
* @param options The options for describing the elements and the dependency details.
|
|
1407
|
+
* @returns The description of the dependency between the elements.
|
|
1408
|
+
*/
|
|
1409
|
+
describeDependency(options: DescribeDependencyOptions): DependencyDescription;
|
|
1410
|
+
}
|
|
1411
|
+
|
|
1329
1412
|
/**
|
|
1330
1413
|
* Serialized cache for Elements class.
|
|
1331
1414
|
*/
|
|
@@ -1336,10 +1419,7 @@ type ElementsSerializedCache = {
|
|
|
1336
1419
|
elementDescriptors: ElementDescriptors;
|
|
1337
1420
|
cache: MatcherSerializedCache;
|
|
1338
1421
|
}>;
|
|
1339
|
-
|
|
1340
|
-
elementsMatcher: ElementsMatcherSerializedCache;
|
|
1341
|
-
/** Cache for DependenciesMatcher */
|
|
1342
|
-
dependenciesMatcher: DependenciesMatcherSerializedCache;
|
|
1422
|
+
micromatch: MicromatchSerializedCache;
|
|
1343
1423
|
};
|
|
1344
1424
|
|
|
1345
1425
|
/**
|
|
@@ -1351,10 +1431,9 @@ declare class Elements {
|
|
|
1351
1431
|
private readonly _globalConfigOptions;
|
|
1352
1432
|
/** Cache manager for Matcher instances, unique for each different configuration */
|
|
1353
1433
|
private readonly _matchersCache;
|
|
1354
|
-
/**
|
|
1355
|
-
private readonly
|
|
1356
|
-
|
|
1357
|
-
private readonly _dependenciesMatcher;
|
|
1434
|
+
/** Micromatch instances for pattern matching */
|
|
1435
|
+
private readonly _micromatchWithCache;
|
|
1436
|
+
private readonly _micromatchWithoutCache;
|
|
1358
1437
|
/**
|
|
1359
1438
|
* Creates a new Elements instance
|
|
1360
1439
|
* @param configOptions The global configuration options for Elements. Can be overridden when getting a descriptor.
|
|
@@ -1378,10 +1457,10 @@ declare class Elements {
|
|
|
1378
1457
|
* Gets a Matcher instance for the given configuration options.
|
|
1379
1458
|
* It uses caching to return the same instance for the same configuration options. If no options are provided, the global configuration options are used.
|
|
1380
1459
|
* @param elementDescriptors The element descriptors to use.
|
|
1381
|
-
* @param
|
|
1460
|
+
* @param config Optional configuration options to override the global ones.
|
|
1382
1461
|
* @returns A matcher instance, unique for each different configuration.
|
|
1383
1462
|
*/
|
|
1384
|
-
getMatcher(elementDescriptors: ElementDescriptors,
|
|
1463
|
+
getMatcher(elementDescriptors: ElementDescriptors, config?: ConfigOptions): Matcher;
|
|
1385
1464
|
}
|
|
1386
1465
|
|
|
1387
1466
|
/**
|
|
@@ -1392,7 +1471,7 @@ declare class ElementsDescriptor {
|
|
|
1392
1471
|
/**
|
|
1393
1472
|
* Cache to store previously described elements.
|
|
1394
1473
|
*/
|
|
1395
|
-
private readonly
|
|
1474
|
+
private readonly _descriptionsCache;
|
|
1396
1475
|
/**
|
|
1397
1476
|
* Cache to store previously described files.
|
|
1398
1477
|
*/
|
|
@@ -1405,12 +1484,16 @@ declare class ElementsDescriptor {
|
|
|
1405
1484
|
* Element descriptors used by this descriptor.
|
|
1406
1485
|
*/
|
|
1407
1486
|
private readonly _elementDescriptors;
|
|
1487
|
+
/** Micromatch instance for path matching */
|
|
1488
|
+
private readonly _micromatch;
|
|
1408
1489
|
/**
|
|
1409
1490
|
* The configuration options for this descriptor.
|
|
1410
1491
|
* @param elementDescriptors The element descriptors.
|
|
1411
1492
|
* @param configOptions The configuration options.
|
|
1493
|
+
* @param globalCache The global cache for various caching needs.
|
|
1494
|
+
* @param micromatch The micromatch instance for path matching.
|
|
1412
1495
|
*/
|
|
1413
|
-
constructor(elementDescriptors: ElementDescriptors, configOptions
|
|
1496
|
+
constructor(elementDescriptors: ElementDescriptors, configOptions: DescriptorOptionsNormalized, micromatch: Micromatch);
|
|
1414
1497
|
/**
|
|
1415
1498
|
* Serializes the elements cache to a plain object.
|
|
1416
1499
|
* @returns The serialized elements cache.
|
|
@@ -1457,7 +1540,7 @@ declare class ElementsDescriptor {
|
|
|
1457
1540
|
* @param dependencySource The source of the dependency to check.
|
|
1458
1541
|
* @returns The base source of the external module. (e.g., for "@scope/package/submodule", it returns "@scope/package")
|
|
1459
1542
|
*/
|
|
1460
|
-
private
|
|
1543
|
+
private _getExternalOrCoreModuleBaseSource;
|
|
1461
1544
|
/**
|
|
1462
1545
|
* Determines if an element is external based on its file path and dependency source.
|
|
1463
1546
|
* Files inside "node_modules" are considered external.
|
|
@@ -1470,7 +1553,9 @@ declare class ElementsDescriptor {
|
|
|
1470
1553
|
private _isExternalDependency;
|
|
1471
1554
|
/**
|
|
1472
1555
|
* Determines if a given path is included based on the configuration.
|
|
1556
|
+
* Uses caching for better performance on repeated calls.
|
|
1473
1557
|
* @param elementPath The element path to check.
|
|
1558
|
+
* @param includeExternal Whether to include external files.
|
|
1474
1559
|
* @returns True if the path is included, false otherwise.
|
|
1475
1560
|
*/
|
|
1476
1561
|
private _pathIsIncluded;
|
|
@@ -1496,10 +1581,7 @@ declare class ElementsDescriptor {
|
|
|
1496
1581
|
*/
|
|
1497
1582
|
private _fileDescriptorMatch;
|
|
1498
1583
|
/**
|
|
1499
|
-
* Retrieves the description of
|
|
1500
|
-
* It does not identify external files. Files not matching any element are considered unknown.
|
|
1501
|
-
* If a file in node_modules does a match, it is considered local as well.
|
|
1502
|
-
* @param includeExternal Whether to include external files (inside node_modules) in the matching process.
|
|
1584
|
+
* Retrieves the description of a local file given its path.
|
|
1503
1585
|
* @param elementPath The path of the element to describe.
|
|
1504
1586
|
* @returns The description of the element.
|
|
1505
1587
|
*/
|
|
@@ -1512,12 +1594,12 @@ declare class ElementsDescriptor {
|
|
|
1512
1594
|
*/
|
|
1513
1595
|
private _describeFile;
|
|
1514
1596
|
/**
|
|
1515
|
-
*
|
|
1516
|
-
* @param element The file element to complete the description for.
|
|
1597
|
+
* Returns an external or core dependency element given its dependency source and file path.
|
|
1517
1598
|
* @param dependencySource The source of the dependency.
|
|
1518
|
-
* @
|
|
1599
|
+
* @param filePath The resolved file path of the dependency, if known.
|
|
1600
|
+
* @returns The external or core dependency element, or null if it is a local dependency.
|
|
1519
1601
|
*/
|
|
1520
|
-
private
|
|
1602
|
+
private _getExternalOrCoreDependencyElement;
|
|
1521
1603
|
/**
|
|
1522
1604
|
* Describes an element given its file path and dependency source, if any.
|
|
1523
1605
|
* @param filePath The path of the file to describe.
|
|
@@ -1552,11 +1634,16 @@ declare class DependenciesDescriptor {
|
|
|
1552
1634
|
* Elements descriptor instance.
|
|
1553
1635
|
*/
|
|
1554
1636
|
private readonly _elementsDescriptor;
|
|
1637
|
+
/**
|
|
1638
|
+
* Configuration options.
|
|
1639
|
+
*/
|
|
1640
|
+
private readonly _config;
|
|
1555
1641
|
/**
|
|
1556
1642
|
* Creates a new DependenciesDescriptor instance.
|
|
1557
1643
|
* @param elementsDescriptor The elements descriptor instance.
|
|
1644
|
+
* @param config The configuration options.
|
|
1558
1645
|
*/
|
|
1559
|
-
constructor(elementsDescriptor: ElementsDescriptor);
|
|
1646
|
+
constructor(elementsDescriptor: ElementsDescriptor, config: DescriptorOptionsNormalized);
|
|
1560
1647
|
/**
|
|
1561
1648
|
* Serializes the elements cache to a plain object.
|
|
1562
1649
|
* @returns The serialized elements cache.
|
|
@@ -1635,6 +1722,9 @@ declare class DependenciesDescriptor {
|
|
|
1635
1722
|
describeDependency({ from, to, source, kind, nodeKind, specifiers, }: DescribeDependencyOptions): DependencyDescription;
|
|
1636
1723
|
}
|
|
1637
1724
|
|
|
1725
|
+
type ObjectCacheKey = Record<string, unknown>;
|
|
1726
|
+
type NotUndefined = object | string | number | boolean | NotUndefined[];
|
|
1727
|
+
|
|
1638
1728
|
/**
|
|
1639
1729
|
* Generic cache manager class. Enables caching of values based on complex keys.
|
|
1640
1730
|
*/
|
|
@@ -1647,36 +1737,36 @@ declare class CacheManager<CacheKey extends NotUndefined, CachedValue> {
|
|
|
1647
1737
|
* Creates a new CacheManager instance
|
|
1648
1738
|
*/
|
|
1649
1739
|
constructor();
|
|
1740
|
+
/**
|
|
1741
|
+
* Generates a string key from the given cache key. Has to be implemented for non-string keys.
|
|
1742
|
+
* @param key The cache key to generate from
|
|
1743
|
+
* @returns The generated string key
|
|
1744
|
+
*/
|
|
1745
|
+
protected generateKey(key: CacheKey): string;
|
|
1650
1746
|
/**
|
|
1651
1747
|
* Generates a hashed key for the given cache key
|
|
1652
1748
|
* @param key The cache key to hash
|
|
1653
1749
|
* @returns The hashed key as a string
|
|
1654
1750
|
*/
|
|
1655
|
-
|
|
1751
|
+
getKey(key: CacheKey): string;
|
|
1656
1752
|
/**
|
|
1657
|
-
* Retrieves a value from the cache based on the given key
|
|
1658
|
-
* @param
|
|
1753
|
+
* Retrieves a value from the cache based on the given hashed key
|
|
1754
|
+
* @param hashedKey The hashed key to retrieve
|
|
1659
1755
|
* @returns The cached value or undefined if not found
|
|
1660
1756
|
*/
|
|
1661
|
-
get(
|
|
1757
|
+
get(hashedKey: string): CachedValue | undefined;
|
|
1662
1758
|
/**
|
|
1663
|
-
* Stores a value in the cache
|
|
1664
|
-
* @param
|
|
1759
|
+
* Stores a value in the cache with a given hashed key
|
|
1760
|
+
* @param hashedKey The hashed key to store
|
|
1665
1761
|
* @param value The value to cache
|
|
1666
1762
|
*/
|
|
1667
|
-
set(
|
|
1668
|
-
/**
|
|
1669
|
-
* Restores a value in the cache from a given already hashed key
|
|
1670
|
-
* @param key The hashed key to restore
|
|
1671
|
-
* @param value The value to restore
|
|
1672
|
-
*/
|
|
1673
|
-
restore(key: string, value: CachedValue): void;
|
|
1763
|
+
set(hashedKey: string, value: CachedValue): void;
|
|
1674
1764
|
/**
|
|
1675
|
-
* Checks if a value exists in the cache
|
|
1676
|
-
* @param
|
|
1765
|
+
* Checks if a value exists in the cache based on the given hashed key
|
|
1766
|
+
* @param hashedKey The hashed key to check
|
|
1677
1767
|
* @returns True if the value exists, false otherwise
|
|
1678
1768
|
*/
|
|
1679
|
-
has(
|
|
1769
|
+
has(hashedKey: string): boolean;
|
|
1680
1770
|
/**
|
|
1681
1771
|
* Retrieves all cached values
|
|
1682
1772
|
* @returns A map of all cached values
|
|
@@ -1698,4 +1788,4 @@ declare class CacheManager<CacheKey extends NotUndefined, CachedValue> {
|
|
|
1698
1788
|
setFromSerialized(serializedCache: Record<string, CachedValue>): void;
|
|
1699
1789
|
}
|
|
1700
1790
|
|
|
1701
|
-
export { type BaseDependencyElement, type BaseElement, type BaseElementDescriptor, type BaseElementSelector, type BaseElementSelectorData, type BaseElementSelectorWithOptions, type BaseElementsSelector, CacheManager, type CapturedValues, type CapturedValuesSelector, type ConfigOptions, type ConfigOptionsNormalized, type CoreDependencyElement, DEPENDENCY_KINDS_MAP, DEPENDENCY_KIND_TYPE, DEPENDENCY_KIND_VALUE, DEPENDENCY_RELATIONSHIPS_INVERTED_MAP, DEPENDENCY_RELATIONSHIPS_MAP, DependenciesDescriptor, type DependenciesDescriptorSerializedCache, DependenciesMatcher, type DependenciesMatcherSerializedCache, type DependencyDescription, type DependencyElementDescription, type DependencyElementSelector, type DependencyElementSelectorData, type DependencyElementSelectorWithOptions, type DependencyElementsSelector, type DependencyKind, type DependencyMatchResult, type DependencyRelationship, type DependencySelector, type DependencySelectorNormalized, type DescribeDependencyOptions, Descriptors, type DescriptorsSerializedCache, ELEMENT_DESCRIPTOR_MODES_MAP, ELEMENT_ORIGINS_MAP, type ElementDescription, type ElementDescriptor, type ElementDescriptorMode, type ElementDescriptorPattern, type ElementDescriptorWithCategory, type ElementDescriptorWithType, type ElementDescriptorWithTypeAndCategory, type ElementDescriptors, type ElementOrigin, type ElementParent, type ElementSelector, type ElementSelectorData, type ElementSelectorWithOptions, type ElementSelectors, Elements, type ElementsDependencyInfo, ElementsDescriptor, type ElementsDescriptorSerializedCache, ElementsMatcher, type ElementsMatcherSerializedCache, type ElementsSelector, type ElementsSerializedCache, type ExternalDependencyElement, type ExternalLibrariesSelector, type ExternalLibrarySelector, type ExternalLibrarySelectorOptions, type ExternalLibrarySelectorWithOptions, type ExternalLibrarySelectors, type FileElement, type IgnoredDependencyElement, type IgnoredElement, type LocalDependencyElement, type LocalDependencyElementKnown, type LocalDependencyElementUnknown, type LocalElementKnown, type LocalElementUnknown, Matcher, type MatcherOptions, type MatcherOptionsDependencySelectorsGlobals, type MatcherSerializedCache, type MicromatchPattern, type SelectableElement, type SimpleElementSelectorByType, type TemplateData, isBaseElement, isBaseElementDescriptor, isBaseElementSelectorData, isCapturedValuesSelector, isCoreDependencyElement, isDependencyDescription, isDependencyElementDescription, isDependencyKind, isDependencyRelationship, isDependencyRelationshipDescription, isDependencySelector, isElementDescription, isElementDescriptor, isElementDescriptorMode, isElementDescriptorPattern, isElementDescriptorWithCategory, isElementDescriptorWithType, isElementSelector, isElementSelectorData, isElementSelectorWithLegacyOptions, isElementsDependencyInfo, isElementsSelector, isExternalDependencyElement, isExternalLibrariesSelector, isExternalLibrarySelector, isExternalLibrarySelectorOptions, isExternalLibrarySelectorOptionsWithPath, isExternalLibrarySelectorOptionsWithSpecifiers, isExternalLibrarySelectorWithOptions, isIgnoredElement, isInternalDependency, isKnownLocalElement, isLocalDependencyElement, isLocalElement, isSimpleElementSelectorByType, isUnknownLocalElement, normalizeElementsSelector };
|
|
1791
|
+
export { type BaseDependencyElement, type BaseElement, type BaseElementDescriptor, type BaseElementSelector, type BaseElementSelectorData, type BaseElementSelectorWithOptions, type BaseElementsSelector, CacheManager, type CapturedValues, type CapturedValuesSelector, type ConfigOptions, type ConfigOptionsNormalized, type CoreDependencyElement, DEPENDENCY_KINDS_MAP, DEPENDENCY_KIND_TYPE, DEPENDENCY_KIND_VALUE, DEPENDENCY_RELATIONSHIPS_INVERTED_MAP, DEPENDENCY_RELATIONSHIPS_MAP, DependenciesDescriptor, type DependenciesDescriptorSerializedCache, DependenciesMatcher, type DependenciesMatcherSerializedCache, type DependencyDescription, type DependencyElementDescription, type DependencyElementSelector, type DependencyElementSelectorData, type DependencyElementSelectorWithOptions, type DependencyElementsSelector, type DependencyKind, type DependencyMatchResult, type DependencyRelationship, type DependencySelector, type DependencySelectorNormalized, type DescribeDependencyOptions, type DescriptionsSerializedCache, type DescriptorOptionsNormalized, Descriptors, type DescriptorsSerializedCache, ELEMENT_DESCRIPTOR_MODES_MAP, ELEMENT_ORIGINS_MAP, type ElementDescription, type ElementDescriptor, type ElementDescriptorMode, type ElementDescriptorPattern, type ElementDescriptorWithCategory, type ElementDescriptorWithType, type ElementDescriptorWithTypeAndCategory, type ElementDescriptors, type ElementOrigin, type ElementParent, type ElementSelector, type ElementSelectorData, type ElementSelectorWithOptions, type ElementSelectors, Elements, type ElementsDependencyInfo, ElementsDescriptor, type ElementsDescriptorSerializedCache, ElementsMatcher, type ElementsMatcherSerializedCache, type ElementsSelector, type ElementsSerializedCache, type ExternalDependencyElement, type ExternalLibrariesSelector, type ExternalLibrarySelector, type ExternalLibrarySelectorOptions, type ExternalLibrarySelectorWithOptions, type ExternalLibrarySelectors, type FileElement, type FileElementsSerializedCache, type IgnoredDependencyElement, type IgnoredElement, type LocalDependencyElement, type LocalDependencyElementKnown, type LocalDependencyElementUnknown, type LocalElementKnown, type LocalElementUnknown, Matcher, type MatcherOptions, type MatcherOptionsDependencySelectorsGlobals, type MatcherSerializedCache, type MatchersOptionsNormalized, type MicromatchPattern, type MicromatchSerializedCache, type NotUndefined, type ObjectCacheKey, type SelectableElement, type SimpleElementSelectorByType, type TemplateData, isBaseElement, isBaseElementDescriptor, isBaseElementSelectorData, isCapturedValuesSelector, isCoreDependencyElement, isDependencyDescription, isDependencyElementDescription, isDependencyKind, isDependencyRelationship, isDependencyRelationshipDescription, isDependencySelector, isElementDescription, isElementDescriptor, isElementDescriptorMode, isElementDescriptorPattern, isElementDescriptorWithCategory, isElementDescriptorWithType, isElementSelector, isElementSelectorData, isElementSelectorWithLegacyOptions, isElementsDependencyInfo, isElementsSelector, isExternalDependencyElement, isExternalLibrariesSelector, isExternalLibrarySelector, isExternalLibrarySelectorOptions, isExternalLibrarySelectorOptionsWithPath, isExternalLibrarySelectorOptionsWithSpecifiers, isExternalLibrarySelectorWithOptions, isIgnoredElement, isInternalDependency, isKnownLocalElement, isLocalDependencyElement, isLocalElement, isSimpleElementSelectorByType, isUnknownLocalElement, normalizeElementsSelector };
|