@boundaries/elements 1.2.0 → 2.0.0-beta.2
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 +223 -64
- package/dist/index.browser.d.mts +219 -309
- package/dist/index.browser.d.ts +219 -309
- package/dist/index.browser.js +413 -419
- package/dist/index.browser.js.map +1 -1
- package/dist/index.browser.mjs +413 -419
- package/dist/index.browser.mjs.map +1 -1
- package/dist/index.d.mts +219 -309
- package/dist/index.d.ts +219 -309
- package/dist/index.js +416 -426
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +413 -419
- package/dist/index.mjs.map +1 -1
- package/package.json +4 -6
package/dist/index.browser.js
CHANGED
|
@@ -45,8 +45,9 @@ __export(src_exports, {
|
|
|
45
45
|
isBaseElementSelectorData: () => isBaseElementSelectorData,
|
|
46
46
|
isCapturedValuesSelector: () => isCapturedValuesSelector,
|
|
47
47
|
isCoreDependencyElement: () => isCoreDependencyElement,
|
|
48
|
+
isDependencyDataSelector: () => isDependencyDataSelector,
|
|
49
|
+
isDependencyDataSelectorData: () => isDependencyDataSelectorData,
|
|
48
50
|
isDependencyDescription: () => isDependencyDescription,
|
|
49
|
-
isDependencyElementDescription: () => isDependencyElementDescription,
|
|
50
51
|
isDependencyKind: () => isDependencyKind,
|
|
51
52
|
isDependencyRelationship: () => isDependencyRelationship,
|
|
52
53
|
isDependencyRelationshipDescription: () => isDependencyRelationshipDescription,
|
|
@@ -63,12 +64,6 @@ __export(src_exports, {
|
|
|
63
64
|
isElementsDependencyInfo: () => isElementsDependencyInfo,
|
|
64
65
|
isElementsSelector: () => isElementsSelector,
|
|
65
66
|
isExternalDependencyElement: () => isExternalDependencyElement,
|
|
66
|
-
isExternalLibrariesSelector: () => isExternalLibrariesSelector,
|
|
67
|
-
isExternalLibrarySelector: () => isExternalLibrarySelector,
|
|
68
|
-
isExternalLibrarySelectorOptions: () => isExternalLibrarySelectorOptions,
|
|
69
|
-
isExternalLibrarySelectorOptionsWithPath: () => isExternalLibrarySelectorOptionsWithPath,
|
|
70
|
-
isExternalLibrarySelectorOptionsWithSpecifiers: () => isExternalLibrarySelectorOptionsWithSpecifiers,
|
|
71
|
-
isExternalLibrarySelectorWithOptions: () => isExternalLibrarySelectorWithOptions,
|
|
72
67
|
isIgnoredElement: () => isIgnoredElement,
|
|
73
68
|
isInternalDependency: () => isInternalDependency,
|
|
74
69
|
isKnownLocalElement: () => isKnownLocalElement,
|
|
@@ -76,6 +71,7 @@ __export(src_exports, {
|
|
|
76
71
|
isLocalElement: () => isLocalElement,
|
|
77
72
|
isSimpleElementSelectorByType: () => isSimpleElementSelectorByType,
|
|
78
73
|
isUnknownLocalElement: () => isUnknownLocalElement,
|
|
74
|
+
normalizeElementSelector: () => normalizeElementSelector,
|
|
79
75
|
normalizeElementsSelector: () => normalizeElementsSelector
|
|
80
76
|
});
|
|
81
77
|
module.exports = __toCommonJS(src_exports);
|
|
@@ -84,12 +80,15 @@ module.exports = __toCommonJS(src_exports);
|
|
|
84
80
|
function isString(value) {
|
|
85
81
|
return typeof value === "string";
|
|
86
82
|
}
|
|
87
|
-
function
|
|
88
|
-
return value ===
|
|
83
|
+
function isUndefined(value) {
|
|
84
|
+
return value === void 0;
|
|
89
85
|
}
|
|
90
86
|
function isNull(value) {
|
|
91
87
|
return value === null;
|
|
92
88
|
}
|
|
89
|
+
function isNullish(value) {
|
|
90
|
+
return isUndefined(value) || isNull(value);
|
|
91
|
+
}
|
|
93
92
|
function isBoolean(value) {
|
|
94
93
|
return typeof value === "boolean";
|
|
95
94
|
}
|
|
@@ -199,102 +198,8 @@ var Config = class {
|
|
|
199
198
|
|
|
200
199
|
// src/Matcher/BaseElementsMatcher.ts
|
|
201
200
|
var import_handlebars = __toESM(require("handlebars"));
|
|
202
|
-
|
|
203
|
-
// src/Matcher/MatcherHelpers.ts
|
|
204
|
-
function isCapturedValuesSelector(value) {
|
|
205
|
-
if (!isObject(value) || isArray(value)) {
|
|
206
|
-
return false;
|
|
207
|
-
}
|
|
208
|
-
return Object.values(value).every(
|
|
209
|
-
(pattern) => isString(pattern) || isStringArray(pattern)
|
|
210
|
-
);
|
|
211
|
-
}
|
|
212
|
-
function isSimpleElementSelectorByType(value) {
|
|
213
|
-
return isString(value);
|
|
214
|
-
}
|
|
215
|
-
function isBaseElementSelectorData(value) {
|
|
216
|
-
return isObjectWithAnyOfProperties(value, [
|
|
217
|
-
"path",
|
|
218
|
-
"elementPath",
|
|
219
|
-
"internalPath",
|
|
220
|
-
"type",
|
|
221
|
-
"category",
|
|
222
|
-
"captured",
|
|
223
|
-
"origin",
|
|
224
|
-
"source",
|
|
225
|
-
"baseSource",
|
|
226
|
-
"isIgnored",
|
|
227
|
-
"isUnknown"
|
|
228
|
-
]);
|
|
229
|
-
}
|
|
230
|
-
function isElementSelectorData(value) {
|
|
231
|
-
return isBaseElementSelectorData(value) || isObjectWithAnyOfProperties(value, [
|
|
232
|
-
"relationship",
|
|
233
|
-
"kind",
|
|
234
|
-
"specifiers",
|
|
235
|
-
"nodeKind"
|
|
236
|
-
]);
|
|
237
|
-
}
|
|
238
|
-
function isElementSelectorWithLegacyOptions(value) {
|
|
239
|
-
return isArray(value) && (value.length === 2 && isSimpleElementSelectorByType(value[0]) && // NOTE: Arrays of length 2 with captured values selector as second element having a key "type" or "category" will be treated as legacy options instead of two different selectors. We have to live with this limitation for now.
|
|
240
|
-
isCapturedValuesSelector(value[1]) || // NOTE: Backwards compatibility: Allow arrays of length 1 with simple element selector. Some users might defined arrays without options.
|
|
241
|
-
value.length === 1 && isSimpleElementSelectorByType(value[0]));
|
|
242
|
-
}
|
|
243
|
-
function isElementSelector(value) {
|
|
244
|
-
return isSimpleElementSelectorByType(value) || isElementSelectorData(value) || isElementSelectorWithLegacyOptions(value);
|
|
245
|
-
}
|
|
246
|
-
function isElementsSelector(value) {
|
|
247
|
-
return isElementSelector(value) || isArray(value) && !isEmptyArray(value) && value.every(isElementSelector);
|
|
248
|
-
}
|
|
249
|
-
function isDependencySelector(value) {
|
|
250
|
-
return isObjectWithAnyOfProperties(value, ["from", "to"]);
|
|
251
|
-
}
|
|
252
|
-
function isExternalLibrarySelectorOptionsWithPath(value) {
|
|
253
|
-
return isObjectWithProperty(value, "path") && (isString(value.path) || isStringArray(value.path));
|
|
254
|
-
}
|
|
255
|
-
function isExternalLibrarySelectorOptionsWithSpecifiers(value) {
|
|
256
|
-
return isObjectWithProperty(value, "specifiers") && isStringArray(value.specifiers);
|
|
257
|
-
}
|
|
258
|
-
function isExternalLibrarySelectorOptions(value) {
|
|
259
|
-
return isExternalLibrarySelectorOptionsWithPath(value) || isExternalLibrarySelectorOptionsWithSpecifiers(value);
|
|
260
|
-
}
|
|
261
|
-
function isExternalLibrarySelectorWithOptions(value) {
|
|
262
|
-
return isArray(value) && value.length === 2 && isSimpleElementSelectorByType(value[0]) && isExternalLibrarySelectorOptions(value[1]);
|
|
263
|
-
}
|
|
264
|
-
function isExternalLibrarySelector(value) {
|
|
265
|
-
return isSimpleElementSelectorByType(value) || isExternalLibrarySelectorWithOptions(value);
|
|
266
|
-
}
|
|
267
|
-
function isExternalLibrariesSelector(value) {
|
|
268
|
-
return isExternalLibrarySelector(value) || isArray(value) && !isEmptyArray(value) && value.every(isExternalLibrarySelector);
|
|
269
|
-
}
|
|
270
|
-
|
|
271
|
-
// src/Matcher/BaseElementsMatcher.ts
|
|
272
|
-
var HANDLEBARS_TEMPLATE_REGEX = /{{\s*[^}\s]+(?:\s+[^}\s]+)*\s*}}/;
|
|
273
201
|
var LEGACY_TEMPLATE_REGEX = /\$\{([^}]+)\}/g;
|
|
274
|
-
|
|
275
|
-
if (isSimpleElementSelectorByType(selector)) {
|
|
276
|
-
return { type: selector };
|
|
277
|
-
}
|
|
278
|
-
if (isElementSelectorData(selector)) {
|
|
279
|
-
return { ...selector };
|
|
280
|
-
}
|
|
281
|
-
if (isElementSelectorWithLegacyOptions(selector)) {
|
|
282
|
-
return {
|
|
283
|
-
type: selector[0],
|
|
284
|
-
captured: selector[1] ? { ...selector[1] } : void 0
|
|
285
|
-
};
|
|
286
|
-
}
|
|
287
|
-
throw new Error("Invalid element selector");
|
|
288
|
-
}
|
|
289
|
-
function normalizeElementsSelector(elementsSelector) {
|
|
290
|
-
if (isArray(elementsSelector)) {
|
|
291
|
-
if (isElementSelectorWithLegacyOptions(elementsSelector)) {
|
|
292
|
-
return [normalizeSelector(elementsSelector)];
|
|
293
|
-
}
|
|
294
|
-
return elementsSelector.map((sel) => normalizeSelector(sel));
|
|
295
|
-
}
|
|
296
|
-
return [normalizeSelector(elementsSelector)];
|
|
297
|
-
}
|
|
202
|
+
var HANDLEBARS_TEMPLATE_REGEX = /{{\s*[^{}\s][^{}]*}}/;
|
|
298
203
|
var BaseElementsMatcher = class {
|
|
299
204
|
/**
|
|
300
205
|
* Option to use legacy templates with ${} syntax.
|
|
@@ -319,6 +224,9 @@ var BaseElementsMatcher = class {
|
|
|
319
224
|
* @returns The converted template.
|
|
320
225
|
*/
|
|
321
226
|
_getBackwardsCompatibleTemplate(template) {
|
|
227
|
+
if (!template) {
|
|
228
|
+
return template;
|
|
229
|
+
}
|
|
322
230
|
return template.replaceAll(LEGACY_TEMPLATE_REGEX, "{{ $1 }}");
|
|
323
231
|
}
|
|
324
232
|
/**
|
|
@@ -327,6 +235,9 @@ var BaseElementsMatcher = class {
|
|
|
327
235
|
* @returns True if the template contains Handlebars syntax, false otherwise.
|
|
328
236
|
*/
|
|
329
237
|
_isHandlebarsTemplate(template) {
|
|
238
|
+
if (!template) {
|
|
239
|
+
return false;
|
|
240
|
+
}
|
|
330
241
|
return HANDLEBARS_TEMPLATE_REGEX.test(template);
|
|
331
242
|
}
|
|
332
243
|
/**
|
|
@@ -358,6 +269,14 @@ var BaseElementsMatcher = class {
|
|
|
358
269
|
}
|
|
359
270
|
return this._getRenderedTemplate(template, templateData);
|
|
360
271
|
}
|
|
272
|
+
/**
|
|
273
|
+
* Cleans a micromatch pattern by removing falsy values from arrays.
|
|
274
|
+
* @param pattern The micromatch pattern(s) to clean.
|
|
275
|
+
* @returns The cleaned pattern. If an array is provided, falsy entries are removed and the resulting array may be empty. If null is provided, null is returned unchanged.
|
|
276
|
+
*/
|
|
277
|
+
cleanMicromatchPattern(pattern) {
|
|
278
|
+
return isArray(pattern) ? pattern.filter(Boolean) : pattern;
|
|
279
|
+
}
|
|
361
280
|
/**
|
|
362
281
|
* Returns whether the given value matches the micromatch pattern, converting non-string values to strings.
|
|
363
282
|
* Optimized version with caching for better performance.
|
|
@@ -366,9 +285,18 @@ var BaseElementsMatcher = class {
|
|
|
366
285
|
* @returns Whether the value matches the pattern.
|
|
367
286
|
*/
|
|
368
287
|
isMicromatchMatch(value, pattern) {
|
|
288
|
+
if (isNull(pattern)) {
|
|
289
|
+
return isNull(value);
|
|
290
|
+
}
|
|
291
|
+
if (isNull(value)) {
|
|
292
|
+
return isArray(pattern) && pattern.some(isNull);
|
|
293
|
+
}
|
|
294
|
+
const patternToCheck = this.cleanMicromatchPattern(pattern);
|
|
295
|
+
if (!patternToCheck?.length) {
|
|
296
|
+
return false;
|
|
297
|
+
}
|
|
369
298
|
const elementValueToCheck = !value || !isString(value) ? String(value) : value;
|
|
370
|
-
|
|
371
|
-
return this.micromatch.isMatch(elementValueToCheck, selectorValueToCheck);
|
|
299
|
+
return this.micromatch.isMatch(elementValueToCheck, patternToCheck);
|
|
372
300
|
}
|
|
373
301
|
/**
|
|
374
302
|
* Returns whether the given value matches the micromatch pattern after rendering it as a template.
|
|
@@ -378,18 +306,17 @@ var BaseElementsMatcher = class {
|
|
|
378
306
|
* @returns Whether the value matches the rendered pattern.
|
|
379
307
|
*/
|
|
380
308
|
isTemplateMicromatchMatch(pattern, templateData, value) {
|
|
381
|
-
if (
|
|
309
|
+
if (isUndefined(value)) {
|
|
382
310
|
return false;
|
|
383
311
|
}
|
|
384
312
|
const patternRendered = this.getRenderedTemplates(pattern, templateData);
|
|
385
|
-
if (!patternRendered) {
|
|
313
|
+
if (!isNull(patternRendered) && !patternRendered) {
|
|
386
314
|
return false;
|
|
387
315
|
}
|
|
388
|
-
const filteredPattern = isArray(patternRendered) ? patternRendered.filter(Boolean) : patternRendered;
|
|
389
316
|
if (isArray(value)) {
|
|
390
|
-
return value.some((val) => this.isMicromatchMatch(val,
|
|
317
|
+
return value.some((val) => this.isMicromatchMatch(val, patternRendered));
|
|
391
318
|
}
|
|
392
|
-
return this.isMicromatchMatch(value,
|
|
319
|
+
return this.isMicromatchMatch(value, patternRendered);
|
|
393
320
|
}
|
|
394
321
|
/**
|
|
395
322
|
* Whether the given element key matches the selector key as booleans.
|
|
@@ -433,20 +360,113 @@ var BaseElementsMatcher = class {
|
|
|
433
360
|
if (!(selectorKey in selector)) {
|
|
434
361
|
return true;
|
|
435
362
|
}
|
|
436
|
-
if (
|
|
437
|
-
return false;
|
|
438
|
-
}
|
|
439
|
-
if (!isObjectWithProperty(element, elementKey)) {
|
|
363
|
+
if (isUndefined(selectorValue) || !isObjectWithProperty(element, String(elementKey))) {
|
|
440
364
|
return false;
|
|
441
365
|
}
|
|
366
|
+
const elementValue = element[elementKey];
|
|
442
367
|
return this.isTemplateMicromatchMatch(
|
|
443
368
|
selectorValue,
|
|
444
369
|
templateData,
|
|
445
|
-
|
|
370
|
+
elementValue
|
|
446
371
|
);
|
|
447
372
|
}
|
|
448
373
|
};
|
|
449
374
|
|
|
375
|
+
// src/Matcher/MatcherHelpers.ts
|
|
376
|
+
function isCapturedValuesObjectSelector(value) {
|
|
377
|
+
if (!isObject(value) || isArray(value)) {
|
|
378
|
+
return false;
|
|
379
|
+
}
|
|
380
|
+
return Object.values(value).every(
|
|
381
|
+
(pattern) => isString(pattern) || isStringArray(pattern)
|
|
382
|
+
);
|
|
383
|
+
}
|
|
384
|
+
function isCapturedValuesSelector(value) {
|
|
385
|
+
if (isArray(value)) {
|
|
386
|
+
return value.every((item) => isCapturedValuesObjectSelector(item));
|
|
387
|
+
}
|
|
388
|
+
return isCapturedValuesObjectSelector(value);
|
|
389
|
+
}
|
|
390
|
+
function isSimpleElementSelectorByType(value) {
|
|
391
|
+
return isString(value);
|
|
392
|
+
}
|
|
393
|
+
function isBaseElementSelectorData(value) {
|
|
394
|
+
return isObjectWithAnyOfProperties(value, [
|
|
395
|
+
"path",
|
|
396
|
+
"elementPath",
|
|
397
|
+
"internalPath",
|
|
398
|
+
"type",
|
|
399
|
+
"category",
|
|
400
|
+
"captured",
|
|
401
|
+
"parent",
|
|
402
|
+
"origin",
|
|
403
|
+
"source",
|
|
404
|
+
"module",
|
|
405
|
+
"isIgnored",
|
|
406
|
+
"isUnknown"
|
|
407
|
+
]);
|
|
408
|
+
}
|
|
409
|
+
function isElementSelectorData(value) {
|
|
410
|
+
return isBaseElementSelectorData(value);
|
|
411
|
+
}
|
|
412
|
+
function isElementSelectorWithLegacyOptions(value) {
|
|
413
|
+
return isArray(value) && (value.length === 2 && isSimpleElementSelectorByType(value[0]) && // NOTE: Arrays of length 2 with captured values selector as second element having a key "type" or "category" will be treated as legacy options instead of two different selectors. We have to live with this limitation for now.
|
|
414
|
+
isCapturedValuesSelector(value[1]) || // NOTE: Backwards compatibility: Allow arrays of length 1 with simple element selector. Some users might defined arrays without options.
|
|
415
|
+
value.length === 1 && isSimpleElementSelectorByType(value[0]));
|
|
416
|
+
}
|
|
417
|
+
function isElementSelector(value) {
|
|
418
|
+
return isSimpleElementSelectorByType(value) || isElementSelectorData(value) || isElementSelectorWithLegacyOptions(value);
|
|
419
|
+
}
|
|
420
|
+
function isElementsSelector(value) {
|
|
421
|
+
return isElementSelector(value) || isArray(value) && !isEmptyArray(value) && value.every(isElementSelector);
|
|
422
|
+
}
|
|
423
|
+
function normalizeElementSelector(selector) {
|
|
424
|
+
if (isSimpleElementSelectorByType(selector)) {
|
|
425
|
+
return { type: selector };
|
|
426
|
+
}
|
|
427
|
+
if (isElementSelectorData(selector)) {
|
|
428
|
+
return { ...selector };
|
|
429
|
+
}
|
|
430
|
+
if (isElementSelectorWithLegacyOptions(selector)) {
|
|
431
|
+
return {
|
|
432
|
+
type: selector[0],
|
|
433
|
+
captured: selector[1] ? { ...selector[1] } : void 0
|
|
434
|
+
};
|
|
435
|
+
}
|
|
436
|
+
throw new Error("Invalid element selector");
|
|
437
|
+
}
|
|
438
|
+
function normalizeElementsSelector(elementsSelector) {
|
|
439
|
+
if (isArray(elementsSelector)) {
|
|
440
|
+
if (isElementSelectorWithLegacyOptions(elementsSelector)) {
|
|
441
|
+
return [normalizeElementSelector(elementsSelector)];
|
|
442
|
+
}
|
|
443
|
+
return elementsSelector.map((sel) => normalizeElementSelector(sel));
|
|
444
|
+
}
|
|
445
|
+
return [normalizeElementSelector(elementsSelector)];
|
|
446
|
+
}
|
|
447
|
+
function isDependencySelector(value) {
|
|
448
|
+
if (!isObjectWithAnyOfProperties(value, ["from", "to", "dependency"])) {
|
|
449
|
+
return false;
|
|
450
|
+
}
|
|
451
|
+
const fromIsValid = !isObjectWithProperty(value, "from") || isElementsSelector(value.from);
|
|
452
|
+
const toIsValid = !isObjectWithProperty(value, "to") || isElementsSelector(value.to);
|
|
453
|
+
const dependencyIsValid = !isObjectWithProperty(value, "dependency") || isDependencyDataSelector(value.dependency);
|
|
454
|
+
return fromIsValid && toIsValid && dependencyIsValid;
|
|
455
|
+
}
|
|
456
|
+
function isDependencyDataSelectorData(value) {
|
|
457
|
+
return isObjectWithAnyOfProperties(value, [
|
|
458
|
+
"kind",
|
|
459
|
+
"relationship",
|
|
460
|
+
"specifiers",
|
|
461
|
+
"nodeKind",
|
|
462
|
+
"source",
|
|
463
|
+
"module"
|
|
464
|
+
]);
|
|
465
|
+
}
|
|
466
|
+
function isDependencyDataSelector(value) {
|
|
467
|
+
return isDependencyDataSelectorData(value) || isArray(value) && !isEmptyArray(value) && value.every(isDependencyDataSelectorData);
|
|
468
|
+
}
|
|
469
|
+
|
|
450
470
|
// src/Matcher/DependenciesMatcher.ts
|
|
451
471
|
var DependenciesMatcher = class extends BaseElementsMatcher {
|
|
452
472
|
/**
|
|
@@ -469,68 +489,20 @@ var DependenciesMatcher = class extends BaseElementsMatcher {
|
|
|
469
489
|
* @param selector The dependency selector to normalize.
|
|
470
490
|
* @returns The normalized dependency selector.
|
|
471
491
|
*/
|
|
472
|
-
_normalizeDependencySelector(selector
|
|
492
|
+
_normalizeDependencySelector(selector) {
|
|
473
493
|
if (!isDependencySelector(selector)) {
|
|
474
494
|
throw new Error("Invalid dependency selector");
|
|
475
495
|
}
|
|
476
|
-
let normalizedDependencySelectors =
|
|
477
|
-
if (
|
|
478
|
-
normalizedDependencySelectors =
|
|
479
|
-
(depSelector) => {
|
|
480
|
-
return {
|
|
481
|
-
...dependencySelectorsGlobals,
|
|
482
|
-
...depSelector
|
|
483
|
-
};
|
|
484
|
-
}
|
|
485
|
-
);
|
|
496
|
+
let normalizedDependencySelectors = null;
|
|
497
|
+
if (selector.dependency && isDependencyDataSelector(selector.dependency)) {
|
|
498
|
+
normalizedDependencySelectors = isArray(selector.dependency) ? selector.dependency : [selector.dependency];
|
|
486
499
|
}
|
|
487
500
|
return {
|
|
488
501
|
from: selector.from ? normalizeElementsSelector(selector.from) : null,
|
|
489
|
-
to:
|
|
502
|
+
to: selector.to ? normalizeElementsSelector(selector.to) : null,
|
|
503
|
+
dependency: normalizedDependencySelectors
|
|
490
504
|
};
|
|
491
505
|
}
|
|
492
|
-
/**
|
|
493
|
-
* Converts a DependencyElementSelectorData to a BaseElementSelectorData, by removing dependency-specific properties.
|
|
494
|
-
* @param selector The dependency element selector data.
|
|
495
|
-
* @returns The base element selector data.
|
|
496
|
-
*/
|
|
497
|
-
_convertDependencyElementSelectorDataToBaseElementSelectorData(selector) {
|
|
498
|
-
const baseSelector = {};
|
|
499
|
-
if (selector.type) {
|
|
500
|
-
baseSelector.type = selector.type;
|
|
501
|
-
}
|
|
502
|
-
if (selector.category) {
|
|
503
|
-
baseSelector.category = selector.category;
|
|
504
|
-
}
|
|
505
|
-
if (selector.path) {
|
|
506
|
-
baseSelector.path = selector.path;
|
|
507
|
-
}
|
|
508
|
-
if (selector.elementPath) {
|
|
509
|
-
baseSelector.elementPath = selector.elementPath;
|
|
510
|
-
}
|
|
511
|
-
if (selector.internalPath) {
|
|
512
|
-
baseSelector.internalPath = selector.internalPath;
|
|
513
|
-
}
|
|
514
|
-
if (selector.captured) {
|
|
515
|
-
baseSelector.captured = selector.captured;
|
|
516
|
-
}
|
|
517
|
-
if (selector.origin) {
|
|
518
|
-
baseSelector.origin = selector.origin;
|
|
519
|
-
}
|
|
520
|
-
if (selector.baseSource) {
|
|
521
|
-
baseSelector.baseSource = selector.baseSource;
|
|
522
|
-
}
|
|
523
|
-
if (selector.source) {
|
|
524
|
-
baseSelector.source = selector.source;
|
|
525
|
-
}
|
|
526
|
-
if (!isNullish(selector.isIgnored)) {
|
|
527
|
-
baseSelector.isIgnored = selector.isIgnored;
|
|
528
|
-
}
|
|
529
|
-
if (!isNullish(selector.isUnknown)) {
|
|
530
|
-
baseSelector.isUnknown = selector.isUnknown;
|
|
531
|
-
}
|
|
532
|
-
return baseSelector;
|
|
533
|
-
}
|
|
534
506
|
/**
|
|
535
507
|
* Returns the selectors matching result for the given dependency.
|
|
536
508
|
* @param dependency The dependency description.
|
|
@@ -538,56 +510,37 @@ var DependenciesMatcher = class extends BaseElementsMatcher {
|
|
|
538
510
|
* @param extraTemplateData The extra template data for selector values.
|
|
539
511
|
* @returns The selectors matching result for the given dependency.
|
|
540
512
|
*/
|
|
541
|
-
|
|
542
|
-
const
|
|
543
|
-
for (const
|
|
544
|
-
const
|
|
545
|
-
dependency.from,
|
|
546
|
-
fromSelectorData,
|
|
547
|
-
{
|
|
548
|
-
extraTemplateData: templateData
|
|
549
|
-
}
|
|
550
|
-
);
|
|
551
|
-
const dependencyPropertiesMatch = this._dependencyFromPropertiesMatch(
|
|
513
|
+
_getSelectorsMatching(dependency, selector, templateData) {
|
|
514
|
+
const getDependencyMetadataSelectorMatching = () => {
|
|
515
|
+
for (const dependencySelectorData of selector.dependency) {
|
|
516
|
+
const dependencyPropertiesMatch = this._dependencyPropertiesMatch(
|
|
552
517
|
dependency,
|
|
553
|
-
|
|
518
|
+
dependencySelectorData,
|
|
554
519
|
templateData
|
|
555
520
|
);
|
|
556
|
-
if (
|
|
557
|
-
return
|
|
521
|
+
if (dependencyPropertiesMatch) {
|
|
522
|
+
return dependencySelectorData;
|
|
558
523
|
}
|
|
559
524
|
}
|
|
560
525
|
return null;
|
|
561
526
|
};
|
|
562
|
-
const
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
toSelectorData
|
|
568
|
-
),
|
|
569
|
-
{
|
|
570
|
-
extraTemplateData: templateData
|
|
571
|
-
}
|
|
572
|
-
) : true;
|
|
573
|
-
const dependencyPropertiesMatch = this._dependencyToPropertiesMatch(
|
|
574
|
-
dependency,
|
|
575
|
-
[toSelectorData],
|
|
576
|
-
templateData
|
|
577
|
-
);
|
|
578
|
-
if (toMatch && dependencyPropertiesMatch) {
|
|
579
|
-
return toSelectorData;
|
|
580
|
-
}
|
|
527
|
+
const fromSelectorMatching = selector.from ? this._elementsMatcher.getSelectorMatching(
|
|
528
|
+
dependency.from,
|
|
529
|
+
selector.from,
|
|
530
|
+
{
|
|
531
|
+
extraTemplateData: templateData
|
|
581
532
|
}
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
533
|
+
) : null;
|
|
534
|
+
const toSelectorMatching = selector.to ? this._elementsMatcher.getSelectorMatching(dependency.to, selector.to, {
|
|
535
|
+
extraTemplateData: templateData
|
|
536
|
+
}) : null;
|
|
537
|
+
const dependencyMetadataSelectorMatching = selector.dependency ? getDependencyMetadataSelectorMatching() : null;
|
|
586
538
|
return {
|
|
587
539
|
from: fromSelectorMatching,
|
|
588
540
|
to: toSelectorMatching,
|
|
541
|
+
dependency: dependencyMetadataSelectorMatching,
|
|
589
542
|
isMatch: Boolean(
|
|
590
|
-
(selector.from ? fromSelectorMatching : true) && (selector.to ? toSelectorMatching : true)
|
|
543
|
+
(selector.from ? fromSelectorMatching : true) && (selector.to ? toSelectorMatching : true) && (selector.dependency ? dependencyMetadataSelectorMatching : true)
|
|
591
544
|
)
|
|
592
545
|
};
|
|
593
546
|
}
|
|
@@ -597,12 +550,29 @@ var DependenciesMatcher = class extends BaseElementsMatcher {
|
|
|
597
550
|
* @param selector The data of an element selector.
|
|
598
551
|
* @returns Whether the dependency relationship matches the selector.
|
|
599
552
|
*/
|
|
600
|
-
|
|
601
|
-
if (!selector.relationship) {
|
|
553
|
+
_relationshipFromMatches(selector, relationship, templateData) {
|
|
554
|
+
if (!selector.relationship?.from) {
|
|
555
|
+
return true;
|
|
556
|
+
}
|
|
557
|
+
return this.isTemplateMicromatchMatch(
|
|
558
|
+
selector.relationship.from,
|
|
559
|
+
templateData,
|
|
560
|
+
relationship
|
|
561
|
+
);
|
|
562
|
+
}
|
|
563
|
+
/**
|
|
564
|
+
* Determines if the dependency origin relationship matches the selector.
|
|
565
|
+
* @param selector The dependency selector data.
|
|
566
|
+
* @param relationship The relationship from origin element to target element.
|
|
567
|
+
* @param templateData The template data for rendering selector values.
|
|
568
|
+
* @returns Whether the dependency origin relationship matches.
|
|
569
|
+
*/
|
|
570
|
+
_relationshipToMatches(selector, relationship, templateData) {
|
|
571
|
+
if (!selector.relationship?.to) {
|
|
602
572
|
return true;
|
|
603
573
|
}
|
|
604
574
|
return this.isTemplateMicromatchMatch(
|
|
605
|
-
selector.relationship,
|
|
575
|
+
selector.relationship.to,
|
|
606
576
|
templateData,
|
|
607
577
|
relationship
|
|
608
578
|
);
|
|
@@ -655,75 +625,85 @@ var DependenciesMatcher = class extends BaseElementsMatcher {
|
|
|
655
625
|
);
|
|
656
626
|
}
|
|
657
627
|
/**
|
|
658
|
-
* Determines if the dependency description matches the selector for '
|
|
628
|
+
* Determines if the dependency description matches the selector for 'to'.
|
|
659
629
|
* @param dependency The dependency description.
|
|
660
|
-
* @param
|
|
630
|
+
* @param toSelector The selector for 'to' elements.
|
|
661
631
|
* @param templateData The template data for rendering selector values
|
|
662
|
-
* @returns Whether the dependency properties match the selector for '
|
|
663
|
-
*/
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
632
|
+
* @returns Whether the dependency properties match the selector for 'to'.
|
|
633
|
+
*/
|
|
634
|
+
_sourceMatches(selector, source, templateData) {
|
|
635
|
+
if (!selector.source) {
|
|
636
|
+
return true;
|
|
637
|
+
}
|
|
638
|
+
return this.isTemplateMicromatchMatch(
|
|
639
|
+
selector.source,
|
|
640
|
+
templateData,
|
|
641
|
+
source
|
|
671
642
|
);
|
|
672
643
|
}
|
|
673
644
|
/**
|
|
674
|
-
* Determines if the
|
|
645
|
+
* Determines if the selector matches the module
|
|
646
|
+
* @param selector The dependency selector data
|
|
647
|
+
* @param module The module to check
|
|
648
|
+
* @param templateData The template data for rendering selector values
|
|
649
|
+
* @returns Whether the selector matches the module
|
|
650
|
+
*/
|
|
651
|
+
_moduleMatches(selector, dependencyModule, templateData) {
|
|
652
|
+
if (!selector.module) {
|
|
653
|
+
return true;
|
|
654
|
+
}
|
|
655
|
+
return this.isTemplateMicromatchMatch(
|
|
656
|
+
selector.module,
|
|
657
|
+
templateData,
|
|
658
|
+
dependencyModule
|
|
659
|
+
);
|
|
660
|
+
}
|
|
661
|
+
/**
|
|
662
|
+
* Determines if the dependency description matches the selector for dependency metadata.
|
|
675
663
|
* @param dependency The dependency description.
|
|
676
|
-
* @param
|
|
664
|
+
* @param selectorData The selector for dependency metadata.
|
|
677
665
|
* @param templateData The template data for rendering selector values
|
|
678
|
-
* @returns Whether the dependency properties match the selector
|
|
666
|
+
* @returns Whether the dependency properties match the selector.
|
|
679
667
|
*/
|
|
680
|
-
|
|
668
|
+
_dependencyPropertiesMatch(dependency, selectorData, templateData) {
|
|
681
669
|
const dependencyInfo = dependency.dependency;
|
|
670
|
+
const relationshipFrom = dependencyInfo.relationship.from;
|
|
682
671
|
const relationshipTo = dependencyInfo.relationship.to;
|
|
683
672
|
const kind = dependencyInfo.kind;
|
|
684
673
|
const nodeKind = dependencyInfo.nodeKind;
|
|
685
674
|
const specifiers = dependencyInfo.specifiers;
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
675
|
+
const source = dependencyInfo.source;
|
|
676
|
+
const dependencyModule = dependencyInfo.module;
|
|
677
|
+
return this._kindMatches(selectorData, kind, templateData) && this._nodeKindMatches(selectorData, nodeKind, templateData) && this._sourceMatches(selectorData, source, templateData) && this._moduleMatches(selectorData, dependencyModule, templateData) && this._relationshipFromMatches(
|
|
678
|
+
selectorData,
|
|
679
|
+
relationshipFrom,
|
|
680
|
+
templateData
|
|
681
|
+
) && this._relationshipToMatches(selectorData, relationshipTo, templateData) && this._specifierMatches(selectorData, specifiers, templateData);
|
|
692
682
|
}
|
|
693
683
|
/**
|
|
694
684
|
* Returns the selectors matching result for the given dependency.
|
|
695
685
|
* @param dependency The dependency to check.
|
|
696
686
|
* @param selector The selector to check against.
|
|
697
|
-
* @param options Extra options for matching, such as templates data,
|
|
687
|
+
* @param options Extra options for matching, such as templates data, etc.
|
|
698
688
|
* @returns The matching result for the dependency against the selector.
|
|
699
689
|
*/
|
|
700
|
-
getSelectorsMatching(dependency, selector, {
|
|
701
|
-
|
|
702
|
-
dependencySelectorsGlobals = {}
|
|
703
|
-
} = {}) {
|
|
704
|
-
const normalizedSelector = this._normalizeDependencySelector(
|
|
705
|
-
selector,
|
|
706
|
-
dependencySelectorsGlobals
|
|
707
|
-
);
|
|
690
|
+
getSelectorsMatching(dependency, selector, { extraTemplateData = {} } = {}) {
|
|
691
|
+
const normalizedSelector = this._normalizeDependencySelector(selector);
|
|
708
692
|
const fromExtraData = extraTemplateData.from || {};
|
|
709
693
|
const toExtraData = extraTemplateData.to || {};
|
|
710
694
|
const templateData = {
|
|
711
695
|
...extraTemplateData,
|
|
712
696
|
from: {
|
|
713
697
|
...dependency.from,
|
|
714
|
-
relationship: dependency.dependency.relationship.from,
|
|
715
698
|
...fromExtraData
|
|
716
699
|
},
|
|
717
700
|
to: {
|
|
718
701
|
...dependency.to,
|
|
719
|
-
relationship: dependency.dependency.relationship.to,
|
|
720
|
-
kind: dependency.dependency.kind,
|
|
721
|
-
nodeKind: dependency.dependency.nodeKind,
|
|
722
|
-
specifiers: dependency.dependency.specifiers,
|
|
723
702
|
...toExtraData
|
|
724
|
-
}
|
|
703
|
+
},
|
|
704
|
+
dependency: dependency.dependency
|
|
725
705
|
};
|
|
726
|
-
const result = this.
|
|
706
|
+
const result = this._getSelectorsMatching(
|
|
727
707
|
dependency,
|
|
728
708
|
normalizedSelector,
|
|
729
709
|
templateData
|
|
@@ -734,7 +714,7 @@ var DependenciesMatcher = class extends BaseElementsMatcher {
|
|
|
734
714
|
* Returns whether the given dependency matches the selector.
|
|
735
715
|
* @param dependency The dependency to check.
|
|
736
716
|
* @param selector The selector to check against.
|
|
737
|
-
* @param options Extra options for matching, such as templates data,
|
|
717
|
+
* @param options Extra options for matching, such as templates data, etc.
|
|
738
718
|
* @returns Whether the dependency matches the selector properties.
|
|
739
719
|
*/
|
|
740
720
|
isDependencyMatch(dependency, selector, options) {
|
|
@@ -749,8 +729,6 @@ var DependenciesMatcher = class extends BaseElementsMatcher {
|
|
|
749
729
|
|
|
750
730
|
// src/Matcher/ElementsMatcher.ts
|
|
751
731
|
var ElementsMatcher = class extends BaseElementsMatcher {
|
|
752
|
-
/** Whether the cache is enabled or not */
|
|
753
|
-
_cacheIsEnabled;
|
|
754
732
|
/**
|
|
755
733
|
* Creates a new ElementsSelectorMatcher.
|
|
756
734
|
* @param config Configuration options for the matcher.
|
|
@@ -863,41 +841,36 @@ var ElementsMatcher = class extends BaseElementsMatcher {
|
|
|
863
841
|
});
|
|
864
842
|
}
|
|
865
843
|
/**
|
|
866
|
-
*
|
|
867
|
-
* @param
|
|
868
|
-
* @param
|
|
869
|
-
* @param templateData The data to use for replace in selector
|
|
870
|
-
* @returns
|
|
871
|
-
*/
|
|
872
|
-
_isBaseSourceMatch(element, selector, templateData) {
|
|
873
|
-
return this.isElementKeyMicromatchMatch({
|
|
874
|
-
element,
|
|
875
|
-
selector,
|
|
876
|
-
elementKey: "baseSource",
|
|
877
|
-
selectorKey: "baseSource",
|
|
878
|
-
selectorValue: selector.baseSource,
|
|
879
|
-
templateData
|
|
880
|
-
});
|
|
881
|
-
}
|
|
882
|
-
/**
|
|
883
|
-
* Whether the given element source matches the selector source
|
|
884
|
-
* @param element The element to check.
|
|
885
|
-
* @param selector The selector to check against.
|
|
886
|
-
* @param templateData The data to use for replace in selector value
|
|
887
|
-
* @returns Whether the element source matches the selector source.
|
|
844
|
+
* Checks if a single captured values object matches the element.
|
|
845
|
+
* @param capturedValues The captured values to check.
|
|
846
|
+
* @param capturedSelector The captured values selector object to check against
|
|
847
|
+
* @param templateData The data to use for replace in selector values
|
|
848
|
+
* @returns True if all captured values in the selector match those in the element, false otherwise.
|
|
888
849
|
*/
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
850
|
+
_checkCapturedValuesObject(capturedValues, capturedSelector, templateData) {
|
|
851
|
+
if (!capturedValues) {
|
|
852
|
+
return false;
|
|
853
|
+
}
|
|
854
|
+
for (const [key, pattern] of Object.entries(capturedSelector)) {
|
|
855
|
+
const elementValue = capturedValues[key];
|
|
856
|
+
if (!elementValue) {
|
|
857
|
+
return false;
|
|
858
|
+
}
|
|
859
|
+
const renderedPattern = this.getRenderedTemplates(pattern, templateData);
|
|
860
|
+
const filteredPattern = this.cleanMicromatchPattern(renderedPattern);
|
|
861
|
+
if (!filteredPattern) {
|
|
862
|
+
return false;
|
|
863
|
+
}
|
|
864
|
+
const isMatch = this.micromatch.isMatch(elementValue, filteredPattern);
|
|
865
|
+
if (!isMatch) {
|
|
866
|
+
return false;
|
|
867
|
+
}
|
|
868
|
+
}
|
|
869
|
+
return true;
|
|
898
870
|
}
|
|
899
871
|
/**
|
|
900
872
|
* Determines if the captured values of the element match those in the selector.
|
|
873
|
+
* When the selector is an array, the element matches if it matches any of the array elements (OR logic).
|
|
901
874
|
* @param element The element to check.
|
|
902
875
|
* @param selector The selector to check against
|
|
903
876
|
* @param templateData The data to use for replace in selector values
|
|
@@ -907,23 +880,98 @@ var ElementsMatcher = class extends BaseElementsMatcher {
|
|
|
907
880
|
if (!selector.captured || isEmptyObject(selector.captured)) {
|
|
908
881
|
return true;
|
|
909
882
|
}
|
|
910
|
-
if (
|
|
911
|
-
|
|
912
|
-
}
|
|
913
|
-
for (const [key, pattern] of Object.entries(selector.captured)) {
|
|
914
|
-
const elementValue = element.captured?.[key];
|
|
915
|
-
if (!elementValue) {
|
|
916
|
-
return false;
|
|
917
|
-
}
|
|
918
|
-
const renderedPattern = this.getRenderedTemplates(pattern, templateData);
|
|
919
|
-
if (!renderedPattern) {
|
|
883
|
+
if (isArray(selector.captured)) {
|
|
884
|
+
if (selector.captured.length === 0) {
|
|
920
885
|
return false;
|
|
921
886
|
}
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
887
|
+
return selector.captured.some(
|
|
888
|
+
(capturedSelector) => this._checkCapturedValuesObject(
|
|
889
|
+
element.captured,
|
|
890
|
+
capturedSelector,
|
|
891
|
+
templateData
|
|
892
|
+
)
|
|
893
|
+
);
|
|
894
|
+
}
|
|
895
|
+
return this._checkCapturedValuesObject(
|
|
896
|
+
element.captured,
|
|
897
|
+
selector.captured,
|
|
898
|
+
templateData
|
|
899
|
+
);
|
|
900
|
+
}
|
|
901
|
+
/**
|
|
902
|
+
* Determines if the parent captured values match the selector.
|
|
903
|
+
* @param parentSelector The parent selector to match.
|
|
904
|
+
* @param parentCaptured The captured values from first parent.
|
|
905
|
+
* @param templateData The data to use for replace in selector values
|
|
906
|
+
* @returns True if the captured values match, false otherwise.
|
|
907
|
+
*/
|
|
908
|
+
_isParentCapturedValuesMatch(parentSelector, parentCaptured, templateData) {
|
|
909
|
+
if (!parentSelector.captured || isEmptyObject(parentSelector.captured)) {
|
|
910
|
+
return true;
|
|
911
|
+
}
|
|
912
|
+
if (isArray(parentSelector.captured)) {
|
|
913
|
+
if (parentSelector.captured.length === 0) {
|
|
925
914
|
return false;
|
|
926
915
|
}
|
|
916
|
+
return parentSelector.captured.some(
|
|
917
|
+
(capturedSelector) => this._checkCapturedValuesObject(
|
|
918
|
+
parentCaptured,
|
|
919
|
+
capturedSelector,
|
|
920
|
+
templateData
|
|
921
|
+
)
|
|
922
|
+
);
|
|
923
|
+
}
|
|
924
|
+
return this._checkCapturedValuesObject(
|
|
925
|
+
parentCaptured,
|
|
926
|
+
parentSelector.captured,
|
|
927
|
+
templateData
|
|
928
|
+
);
|
|
929
|
+
}
|
|
930
|
+
/**
|
|
931
|
+
* Whether the given element first parent matches the selector parent.
|
|
932
|
+
* @param element The element to check.
|
|
933
|
+
* @param selector The selector to check against.
|
|
934
|
+
* @param templateData The data to use for replace in selector values
|
|
935
|
+
* @returns Whether the first parent matches the selector parent.
|
|
936
|
+
*/
|
|
937
|
+
_isParentMatch(element, selector, templateData) {
|
|
938
|
+
if (isUndefined(selector.parent)) {
|
|
939
|
+
return true;
|
|
940
|
+
}
|
|
941
|
+
if (isNull(selector.parent)) {
|
|
942
|
+
return !element.parents || element.parents.length === 0;
|
|
943
|
+
}
|
|
944
|
+
const firstParent = element.parents?.[0];
|
|
945
|
+
if (!firstParent) {
|
|
946
|
+
return false;
|
|
947
|
+
}
|
|
948
|
+
if (!isUndefined(selector.parent.type) && !this.isTemplateMicromatchMatch(
|
|
949
|
+
selector.parent.type,
|
|
950
|
+
templateData,
|
|
951
|
+
firstParent.type
|
|
952
|
+
)) {
|
|
953
|
+
return false;
|
|
954
|
+
}
|
|
955
|
+
if (!isUndefined(selector.parent.category) && !this.isTemplateMicromatchMatch(
|
|
956
|
+
selector.parent.category,
|
|
957
|
+
templateData,
|
|
958
|
+
firstParent.category
|
|
959
|
+
)) {
|
|
960
|
+
return false;
|
|
961
|
+
}
|
|
962
|
+
if (!isUndefined(selector.parent.elementPath) && !this.isTemplateMicromatchMatch(
|
|
963
|
+
selector.parent.elementPath,
|
|
964
|
+
templateData,
|
|
965
|
+
firstParent.elementPath
|
|
966
|
+
)) {
|
|
967
|
+
return false;
|
|
968
|
+
}
|
|
969
|
+
if (!this._isParentCapturedValuesMatch(
|
|
970
|
+
selector.parent,
|
|
971
|
+
firstParent.captured,
|
|
972
|
+
templateData
|
|
973
|
+
)) {
|
|
974
|
+
return false;
|
|
927
975
|
}
|
|
928
976
|
return true;
|
|
929
977
|
}
|
|
@@ -968,7 +1016,7 @@ var ElementsMatcher = class extends BaseElementsMatcher {
|
|
|
968
1016
|
...extraTemplateData
|
|
969
1017
|
};
|
|
970
1018
|
for (const selectorData of selectorsData) {
|
|
971
|
-
if (!this._isTypeMatch(element, selectorData, templateData) || !this._isCategoryMatch(element, selectorData, templateData) || !this._isOriginMatch(element, selectorData, templateData) || !this._isIgnoredMatch(element, selectorData) || !this._isUnknownMatch(element, selectorData) || !this._isPathMatch(element, selectorData, templateData) || !this._isElementPathMatch(element, selectorData, templateData) || !this._isInternalPathMatch(element, selectorData, templateData) || !this.
|
|
1019
|
+
if (!this._isTypeMatch(element, selectorData, templateData) || !this._isCategoryMatch(element, selectorData, templateData) || !this._isOriginMatch(element, selectorData, templateData) || !this._isIgnoredMatch(element, selectorData) || !this._isUnknownMatch(element, selectorData) || !this._isPathMatch(element, selectorData, templateData) || !this._isElementPathMatch(element, selectorData, templateData) || !this._isInternalPathMatch(element, selectorData, templateData) || !this._isCapturedValuesMatch(element, selectorData, templateData) || !this._isParentMatch(element, selectorData, templateData)) {
|
|
972
1020
|
continue;
|
|
973
1021
|
}
|
|
974
1022
|
return selectorData;
|
|
@@ -980,7 +1028,7 @@ var ElementsMatcher = class extends BaseElementsMatcher {
|
|
|
980
1028
|
* It omits checks in keys applying only to dependency between elements, such as relationship.
|
|
981
1029
|
* @param element The element to check.
|
|
982
1030
|
* @param selector The selector to check against.
|
|
983
|
-
* @param options Extra options for matching, such as templates data,
|
|
1031
|
+
* @param options Extra options for matching, such as templates data, etc.
|
|
984
1032
|
* @returns The selector matching result for the given element, or null if none matches.
|
|
985
1033
|
*/
|
|
986
1034
|
getSelectorMatching(element, selector, { extraTemplateData = {} } = {}) {
|
|
@@ -992,7 +1040,7 @@ var ElementsMatcher = class extends BaseElementsMatcher {
|
|
|
992
1040
|
* It omits checks in keys applying only to dependency between elements, such as relationship.
|
|
993
1041
|
* @param element The element to check.
|
|
994
1042
|
* @param selector The selector to check against.
|
|
995
|
-
* @param options Extra options for matching, such as templates data,
|
|
1043
|
+
* @param options Extra options for matching, such as templates data, etc.
|
|
996
1044
|
* @returns Whether the element matches the selector properties applying to elements.
|
|
997
1045
|
*/
|
|
998
1046
|
isElementMatch(element, selector, options) {
|
|
@@ -1059,20 +1107,17 @@ function isUnknownLocalElement(value) {
|
|
|
1059
1107
|
function isKnownLocalElement(value) {
|
|
1060
1108
|
return isLocalElement(value) && value.isUnknown === false;
|
|
1061
1109
|
}
|
|
1062
|
-
function isDependencyElementDescription(value) {
|
|
1063
|
-
return isBaseElement(value) && isObjectWithProperty(value, "source") && isString(value.source);
|
|
1064
|
-
}
|
|
1065
|
-
function isElementDescription(value) {
|
|
1066
|
-
return isIgnoredElement(value) || isUnknownLocalElement(value) || isKnownLocalElement(value) || isDependencyElementDescription(value);
|
|
1067
|
-
}
|
|
1068
1110
|
function isLocalDependencyElement(value) {
|
|
1069
|
-
return
|
|
1111
|
+
return isLocalElement(value) && value.isIgnored === false;
|
|
1070
1112
|
}
|
|
1071
1113
|
function isExternalDependencyElement(value) {
|
|
1072
|
-
return
|
|
1114
|
+
return isBaseElement(value) && value.origin === ELEMENT_ORIGINS_MAP.EXTERNAL;
|
|
1073
1115
|
}
|
|
1074
1116
|
function isCoreDependencyElement(value) {
|
|
1075
|
-
return
|
|
1117
|
+
return isBaseElement(value) && value.origin === ELEMENT_ORIGINS_MAP.CORE;
|
|
1118
|
+
}
|
|
1119
|
+
function isElementDescription(value) {
|
|
1120
|
+
return isIgnoredElement(value) || isUnknownLocalElement(value) || isKnownLocalElement(value) || isExternalDependencyElement(value) || isCoreDependencyElement(value);
|
|
1076
1121
|
}
|
|
1077
1122
|
|
|
1078
1123
|
// src/Descriptor/DependenciesDescriptor.types.ts
|
|
@@ -1129,7 +1174,7 @@ function isDependencyRelationshipDescription(value) {
|
|
|
1129
1174
|
return isObjectWithProperty(value, "to") && (isNull(value.to) || isDependencyRelationship(value.to)) && isObjectWithProperty(value, "from") && (isNull(value.from) || isDependencyRelationship(value.from));
|
|
1130
1175
|
}
|
|
1131
1176
|
function isElementsDependencyInfo(value) {
|
|
1132
|
-
return isObjectWithProperty(value, "kind") && isDependencyKind(value.kind) && isObjectWithProperty(value, "relationship") && isDependencyRelationshipDescription(value.relationship) && isObjectWithProperty(value, "nodeKind") && (isNull(value.nodeKind) || isString(value.nodeKind));
|
|
1177
|
+
return isObjectWithProperty(value, "source") && isString(value.source) && isObjectWithProperty(value, "module") && (isNullish(value.module) || isString(value.module)) && isObjectWithProperty(value, "kind") && isDependencyKind(value.kind) && isObjectWithProperty(value, "relationship") && isDependencyRelationshipDescription(value.relationship) && isObjectWithProperty(value, "nodeKind") && (isNull(value.nodeKind) || isString(value.nodeKind)) && isObjectWithProperty(value, "specifiers") && (isNull(value.specifiers) || isStringArray(value.specifiers));
|
|
1133
1178
|
}
|
|
1134
1179
|
function isDependencyDescription(value) {
|
|
1135
1180
|
return isObjectWithProperty(value, "to") && isElementDescription(value.to) && isObjectWithProperty(value, "from") && isElementDescription(value.from) && isObjectWithProperty(value, "dependency") && isElementsDependencyInfo(value.dependency);
|
|
@@ -1467,17 +1512,20 @@ var DependenciesDescriptor = class {
|
|
|
1467
1512
|
return this._dependenciesCache.get(cacheKey);
|
|
1468
1513
|
}
|
|
1469
1514
|
const fromElement = this._elementsDescriptor.describeElement(from);
|
|
1470
|
-
const toElement = this._elementsDescriptor.
|
|
1471
|
-
|
|
1472
|
-
to
|
|
1473
|
-
);
|
|
1515
|
+
const toElement = this._elementsDescriptor.describeElement(to, source);
|
|
1516
|
+
const { module: dependencyModule, ...toElementDescription } = toElement;
|
|
1474
1517
|
const result = {
|
|
1475
1518
|
from: fromElement,
|
|
1476
|
-
to:
|
|
1519
|
+
to: toElementDescription,
|
|
1477
1520
|
dependency: {
|
|
1521
|
+
source,
|
|
1522
|
+
module: dependencyModule || null,
|
|
1478
1523
|
kind,
|
|
1479
1524
|
nodeKind: nodeKind || null,
|
|
1480
|
-
relationship: this._dependencyRelationships(
|
|
1525
|
+
relationship: this._dependencyRelationships(
|
|
1526
|
+
fromElement,
|
|
1527
|
+
toElementDescription
|
|
1528
|
+
),
|
|
1481
1529
|
specifiers: specifiers || null
|
|
1482
1530
|
}
|
|
1483
1531
|
};
|
|
@@ -1492,8 +1540,6 @@ var UNKNOWN_ELEMENT = {
|
|
|
1492
1540
|
path: null,
|
|
1493
1541
|
elementPath: null,
|
|
1494
1542
|
internalPath: null,
|
|
1495
|
-
source: null,
|
|
1496
|
-
baseSource: null,
|
|
1497
1543
|
parents: null,
|
|
1498
1544
|
type: null,
|
|
1499
1545
|
category: null,
|
|
@@ -1595,8 +1641,8 @@ var ElementsDescriptor = class {
|
|
|
1595
1641
|
*/
|
|
1596
1642
|
_dependencySourceIsCoreModule(dependencySource, baseDependencySource) {
|
|
1597
1643
|
if (this._mod) {
|
|
1598
|
-
const
|
|
1599
|
-
return this._mod.builtinModules.includes(
|
|
1644
|
+
const moduleWithoutPrefix = baseDependencySource.startsWith("node:") ? baseDependencySource.slice(5) : baseDependencySource;
|
|
1645
|
+
return this._mod.builtinModules.includes(moduleWithoutPrefix);
|
|
1600
1646
|
}
|
|
1601
1647
|
return (0, import_is_core_module.default)(dependencySource);
|
|
1602
1648
|
}
|
|
@@ -1621,7 +1667,7 @@ var ElementsDescriptor = class {
|
|
|
1621
1667
|
* @param dependencySource The source of the dependency to check.
|
|
1622
1668
|
* @returns The base source of the external module. (e.g., for "@scope/package/submodule", it returns "@scope/package")
|
|
1623
1669
|
*/
|
|
1624
|
-
|
|
1670
|
+
_getExternalOrCoreModuleModule(dependencySource) {
|
|
1625
1671
|
if (this._dependencySourceIsScoped(dependencySource)) {
|
|
1626
1672
|
const [scope, packageName] = dependencySource.split("/");
|
|
1627
1673
|
return `${scope}/${packageName}`;
|
|
@@ -1932,7 +1978,7 @@ var ElementsDescriptor = class {
|
|
|
1932
1978
|
* @returns The external or core dependency element, or null if it is a local dependency.
|
|
1933
1979
|
*/
|
|
1934
1980
|
_getExternalOrCoreDependencyElement(dependencySource, isOutsideRootPath, filePath) {
|
|
1935
|
-
const baseDependencySource = this.
|
|
1981
|
+
const baseDependencySource = this._getExternalOrCoreModuleModule(dependencySource);
|
|
1936
1982
|
const isCore = this._dependencySourceIsCoreModule(
|
|
1937
1983
|
dependencySource,
|
|
1938
1984
|
baseDependencySource
|
|
@@ -1940,8 +1986,7 @@ var ElementsDescriptor = class {
|
|
|
1940
1986
|
if (isCore) {
|
|
1941
1987
|
const coreElement = {
|
|
1942
1988
|
...UNKNOWN_ELEMENT,
|
|
1943
|
-
|
|
1944
|
-
baseSource: baseDependencySource,
|
|
1989
|
+
module: baseDependencySource,
|
|
1945
1990
|
origin: ELEMENT_ORIGINS_MAP.CORE
|
|
1946
1991
|
};
|
|
1947
1992
|
return coreElement;
|
|
@@ -1955,9 +2000,8 @@ var ElementsDescriptor = class {
|
|
|
1955
2000
|
const externalElement = {
|
|
1956
2001
|
...UNKNOWN_ELEMENT,
|
|
1957
2002
|
path: filePath || null,
|
|
1958
|
-
internalPath: dependencySource.replace(baseDependencySource, ""),
|
|
1959
|
-
|
|
1960
|
-
baseSource: baseDependencySource,
|
|
2003
|
+
internalPath: dependencySource.replace(baseDependencySource, "") || null,
|
|
2004
|
+
module: baseDependencySource,
|
|
1961
2005
|
origin: ELEMENT_ORIGINS_MAP.EXTERNAL
|
|
1962
2006
|
};
|
|
1963
2007
|
return externalElement;
|
|
@@ -1982,28 +2026,10 @@ var ElementsDescriptor = class {
|
|
|
1982
2026
|
return externalOrCoreDependencyElement;
|
|
1983
2027
|
}
|
|
1984
2028
|
const fileDescription = this._describeFile(relativePath);
|
|
1985
|
-
|
|
1986
|
-
|
|
1987
|
-
source: dependencySource
|
|
1988
|
-
} : fileDescription;
|
|
1989
|
-
this._descriptionsCache.set(cacheKey, elementResult);
|
|
1990
|
-
return elementResult;
|
|
2029
|
+
this._descriptionsCache.set(cacheKey, fileDescription);
|
|
2030
|
+
return fileDescription;
|
|
1991
2031
|
}
|
|
1992
|
-
|
|
1993
|
-
* Describes an element given its file path.
|
|
1994
|
-
* @param filePath The path of the file to describe. Can be absolute if rootPath is configured, or relative if not.
|
|
1995
|
-
* @returns The description of the element.
|
|
1996
|
-
*/
|
|
1997
|
-
describeElement(filePath) {
|
|
1998
|
-
return this._describeElement(filePath);
|
|
1999
|
-
}
|
|
2000
|
-
/**
|
|
2001
|
-
* Describes a dependency element given its dependency source and file path.
|
|
2002
|
-
* @param dependencySource The source of the dependency.
|
|
2003
|
-
* @param filePath The path of the file being the dependency, if known. Can be absolute if rootPath is configured, or relative if not.
|
|
2004
|
-
* @returns The description of the dependency element.
|
|
2005
|
-
*/
|
|
2006
|
-
describeDependencyElement(dependencySource, filePath) {
|
|
2032
|
+
describeElement(filePath, dependencySource) {
|
|
2007
2033
|
return this._describeElement(filePath, dependencySource);
|
|
2008
2034
|
}
|
|
2009
2035
|
};
|
|
@@ -2063,18 +2089,6 @@ var Descriptors = class {
|
|
|
2063
2089
|
describeElement(filePath) {
|
|
2064
2090
|
return this._elementsDescriptor.describeElement(filePath);
|
|
2065
2091
|
}
|
|
2066
|
-
/**
|
|
2067
|
-
* Describes a dependency element given its dependency source and file path.
|
|
2068
|
-
* @param dependencySource The source of the dependency.
|
|
2069
|
-
* @param filePath The path of the file being the dependency, if known.
|
|
2070
|
-
* @returns The description of the dependency element.
|
|
2071
|
-
*/
|
|
2072
|
-
describeDependencyElement(dependencySource, filePath) {
|
|
2073
|
-
return this._elementsDescriptor.describeDependencyElement(
|
|
2074
|
-
dependencySource,
|
|
2075
|
-
filePath
|
|
2076
|
-
);
|
|
2077
|
-
}
|
|
2078
2092
|
/**
|
|
2079
2093
|
* Describes elements in a dependency relationship, and provides additional information about the dependency itself.
|
|
2080
2094
|
* @param options The options for describing the elements and the dependency details.
|
|
@@ -2103,6 +2117,22 @@ var Matcher = class {
|
|
|
2103
2117
|
this._elementsMatcher = elementsMatcher;
|
|
2104
2118
|
this._dependenciesMatcher = dependenciesMatcher;
|
|
2105
2119
|
}
|
|
2120
|
+
/**
|
|
2121
|
+
* Describes an element given its file path.
|
|
2122
|
+
* @param filePath The path of the file to describe.
|
|
2123
|
+
* @returns The description of the element.
|
|
2124
|
+
*/
|
|
2125
|
+
describeElement(filePath) {
|
|
2126
|
+
return this._descriptors.describeElement(filePath);
|
|
2127
|
+
}
|
|
2128
|
+
/**
|
|
2129
|
+
* Describes elements in a dependency relationship, and provides additional information about the dependency itself.
|
|
2130
|
+
* @param options The options for describing the elements and the dependency details.
|
|
2131
|
+
* @returns The description of the dependency between the elements.
|
|
2132
|
+
*/
|
|
2133
|
+
describeDependency(options) {
|
|
2134
|
+
return this._descriptors.describeDependency(options);
|
|
2135
|
+
}
|
|
2106
2136
|
/**
|
|
2107
2137
|
* Determines if an element matches a given selector.
|
|
2108
2138
|
* @param filePath The file path of the element
|
|
@@ -2110,7 +2140,7 @@ var Matcher = class {
|
|
|
2110
2140
|
* @param options Extra matcher options
|
|
2111
2141
|
* @returns True if the element matches the selector, false otherwise
|
|
2112
2142
|
*/
|
|
2113
|
-
|
|
2143
|
+
isElementMatch(filePath, selector, options) {
|
|
2114
2144
|
const description = this._descriptors.describeElement(filePath);
|
|
2115
2145
|
return this._elementsMatcher.isElementMatch(description, selector, options);
|
|
2116
2146
|
}
|
|
@@ -2121,7 +2151,7 @@ var Matcher = class {
|
|
|
2121
2151
|
* @param options Extra matcher options
|
|
2122
2152
|
* @returns True if the dependency matches the selector, false otherwise
|
|
2123
2153
|
*/
|
|
2124
|
-
|
|
2154
|
+
isDependencyMatch(dependencyData, selector, options) {
|
|
2125
2155
|
const description = this._descriptors.describeDependency(dependencyData);
|
|
2126
2156
|
return this._dependenciesMatcher.isDependencyMatch(
|
|
2127
2157
|
description,
|
|
@@ -2129,20 +2159,6 @@ var Matcher = class {
|
|
|
2129
2159
|
options
|
|
2130
2160
|
);
|
|
2131
2161
|
}
|
|
2132
|
-
isMatch(descriptorOptions, selector, options) {
|
|
2133
|
-
if (isString(descriptorOptions)) {
|
|
2134
|
-
return this._isElementMatch(
|
|
2135
|
-
descriptorOptions,
|
|
2136
|
-
selector,
|
|
2137
|
-
options
|
|
2138
|
-
);
|
|
2139
|
-
}
|
|
2140
|
-
return this._isDependencyMatch(
|
|
2141
|
-
descriptorOptions,
|
|
2142
|
-
selector,
|
|
2143
|
-
options
|
|
2144
|
-
);
|
|
2145
|
-
}
|
|
2146
2162
|
/**
|
|
2147
2163
|
* Determines the selector matching for an element.
|
|
2148
2164
|
* @param filePath The file path of the element
|
|
@@ -2150,7 +2166,7 @@ var Matcher = class {
|
|
|
2150
2166
|
* @param options Extra options for matching
|
|
2151
2167
|
* @returns The matching selector data or null if no match is found
|
|
2152
2168
|
*/
|
|
2153
|
-
|
|
2169
|
+
getElementSelectorMatching(filePath, selector, options) {
|
|
2154
2170
|
const description = this._descriptors.describeElement(filePath);
|
|
2155
2171
|
return this._elementsMatcher.getSelectorMatching(
|
|
2156
2172
|
description,
|
|
@@ -2165,7 +2181,7 @@ var Matcher = class {
|
|
|
2165
2181
|
* @param options Extra options for matching
|
|
2166
2182
|
* @returns The matching dependency result or null if no match is found
|
|
2167
2183
|
*/
|
|
2168
|
-
|
|
2184
|
+
getDependencySelectorMatching(dependencyData, selector, options) {
|
|
2169
2185
|
const description = this._descriptors.describeDependency(dependencyData);
|
|
2170
2186
|
return this._dependenciesMatcher.getSelectorsMatching(
|
|
2171
2187
|
description,
|
|
@@ -2173,66 +2189,44 @@ var Matcher = class {
|
|
|
2173
2189
|
options
|
|
2174
2190
|
);
|
|
2175
2191
|
}
|
|
2176
|
-
|
|
2177
|
-
|
|
2178
|
-
|
|
2179
|
-
|
|
2192
|
+
/**
|
|
2193
|
+
* Returns the selectors matching result for the given element or dependency description.
|
|
2194
|
+
* @param description The element or dependency description to check.
|
|
2195
|
+
* @param selector The selector to check against.
|
|
2196
|
+
* @param options Extra options for matching, such as templates data, etc.
|
|
2197
|
+
* @returns The selectors matching result for the given description, and whether it matches or not.
|
|
2198
|
+
*/
|
|
2199
|
+
getDependencySelectorMatchingDescription(description, selector, options) {
|
|
2200
|
+
if (isDependencySelector(selector) && isDependencyDescription(description)) {
|
|
2201
|
+
return this._dependenciesMatcher.getSelectorsMatching(
|
|
2202
|
+
description,
|
|
2180
2203
|
selector,
|
|
2181
2204
|
options
|
|
2182
2205
|
);
|
|
2183
2206
|
}
|
|
2184
|
-
|
|
2185
|
-
|
|
2186
|
-
selector,
|
|
2187
|
-
options
|
|
2207
|
+
throw new Error(
|
|
2208
|
+
"Invalid arguments: Please provide a valid description and selector"
|
|
2188
2209
|
);
|
|
2189
2210
|
}
|
|
2190
|
-
|
|
2211
|
+
/**
|
|
2212
|
+
* Returns the first element selector matching result for the given element description.
|
|
2213
|
+
* @param description The element description to check.
|
|
2214
|
+
* @param selector The selector to check against.
|
|
2215
|
+
* @param options Extra options for matching, such as templates data, etc.
|
|
2216
|
+
* @returns The first matching selector result for the given description, or null if no match is found.
|
|
2217
|
+
*/
|
|
2218
|
+
getElementSelectorMatchingDescription(description, selector, options) {
|
|
2191
2219
|
if (isElementsSelector(selector) && isElementDescription(description)) {
|
|
2192
2220
|
return this._elementsMatcher.getSelectorMatching(
|
|
2193
2221
|
description,
|
|
2194
2222
|
selector,
|
|
2195
2223
|
options
|
|
2196
2224
|
);
|
|
2197
|
-
} else if (isDependencySelector(selector) && isDependencyDescription(description)) {
|
|
2198
|
-
return this._dependenciesMatcher.getSelectorsMatching(
|
|
2199
|
-
description,
|
|
2200
|
-
selector,
|
|
2201
|
-
options
|
|
2202
|
-
);
|
|
2203
2225
|
}
|
|
2204
2226
|
throw new Error(
|
|
2205
2227
|
"Invalid arguments: Please provide a valid description and selector"
|
|
2206
2228
|
);
|
|
2207
2229
|
}
|
|
2208
|
-
/**
|
|
2209
|
-
* Describes an element given its file path.
|
|
2210
|
-
* @param filePath The path of the file to describe.
|
|
2211
|
-
* @returns The description of the element.
|
|
2212
|
-
*/
|
|
2213
|
-
describeElement(filePath) {
|
|
2214
|
-
return this._descriptors.describeElement(filePath);
|
|
2215
|
-
}
|
|
2216
|
-
/**
|
|
2217
|
-
* Describes a dependency element given its dependency source and file path.
|
|
2218
|
-
* @param dependencySource The source of the dependency.
|
|
2219
|
-
* @param filePath The path of the file being the dependency, if known.
|
|
2220
|
-
* @returns The description of the dependency element.
|
|
2221
|
-
*/
|
|
2222
|
-
describeDependencyElement(dependencySource, filePath) {
|
|
2223
|
-
return this._descriptors.describeDependencyElement(
|
|
2224
|
-
dependencySource,
|
|
2225
|
-
filePath
|
|
2226
|
-
);
|
|
2227
|
-
}
|
|
2228
|
-
/**
|
|
2229
|
-
* Describes elements in a dependency relationship, and provides additional information about the dependency itself.
|
|
2230
|
-
* @param options The options for describing the elements and the dependency details.
|
|
2231
|
-
* @returns The description of the dependency between the elements.
|
|
2232
|
-
*/
|
|
2233
|
-
describeDependency(options) {
|
|
2234
|
-
return this._descriptors.describeDependency(options);
|
|
2235
|
-
}
|
|
2236
2230
|
/**
|
|
2237
2231
|
* Clears all caches.
|
|
2238
2232
|
*/
|