@boundaries/elements 1.2.0 → 2.0.0-beta.1
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 +214 -308
- package/dist/index.browser.d.ts +214 -308
- 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 +214 -308
- package/dist/index.d.ts +214 -308
- 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.mjs
CHANGED
|
@@ -9,12 +9,15 @@ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require
|
|
|
9
9
|
function isString(value) {
|
|
10
10
|
return typeof value === "string";
|
|
11
11
|
}
|
|
12
|
-
function
|
|
13
|
-
return value ===
|
|
12
|
+
function isUndefined(value) {
|
|
13
|
+
return value === void 0;
|
|
14
14
|
}
|
|
15
15
|
function isNull(value) {
|
|
16
16
|
return value === null;
|
|
17
17
|
}
|
|
18
|
+
function isNullish(value) {
|
|
19
|
+
return isUndefined(value) || isNull(value);
|
|
20
|
+
}
|
|
18
21
|
function isBoolean(value) {
|
|
19
22
|
return typeof value === "boolean";
|
|
20
23
|
}
|
|
@@ -124,102 +127,8 @@ var Config = class {
|
|
|
124
127
|
|
|
125
128
|
// src/Matcher/BaseElementsMatcher.ts
|
|
126
129
|
import Handlebars from "handlebars";
|
|
127
|
-
|
|
128
|
-
// src/Matcher/MatcherHelpers.ts
|
|
129
|
-
function isCapturedValuesSelector(value) {
|
|
130
|
-
if (!isObject(value) || isArray(value)) {
|
|
131
|
-
return false;
|
|
132
|
-
}
|
|
133
|
-
return Object.values(value).every(
|
|
134
|
-
(pattern) => isString(pattern) || isStringArray(pattern)
|
|
135
|
-
);
|
|
136
|
-
}
|
|
137
|
-
function isSimpleElementSelectorByType(value) {
|
|
138
|
-
return isString(value);
|
|
139
|
-
}
|
|
140
|
-
function isBaseElementSelectorData(value) {
|
|
141
|
-
return isObjectWithAnyOfProperties(value, [
|
|
142
|
-
"path",
|
|
143
|
-
"elementPath",
|
|
144
|
-
"internalPath",
|
|
145
|
-
"type",
|
|
146
|
-
"category",
|
|
147
|
-
"captured",
|
|
148
|
-
"origin",
|
|
149
|
-
"source",
|
|
150
|
-
"baseSource",
|
|
151
|
-
"isIgnored",
|
|
152
|
-
"isUnknown"
|
|
153
|
-
]);
|
|
154
|
-
}
|
|
155
|
-
function isElementSelectorData(value) {
|
|
156
|
-
return isBaseElementSelectorData(value) || isObjectWithAnyOfProperties(value, [
|
|
157
|
-
"relationship",
|
|
158
|
-
"kind",
|
|
159
|
-
"specifiers",
|
|
160
|
-
"nodeKind"
|
|
161
|
-
]);
|
|
162
|
-
}
|
|
163
|
-
function isElementSelectorWithLegacyOptions(value) {
|
|
164
|
-
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.
|
|
165
|
-
isCapturedValuesSelector(value[1]) || // NOTE: Backwards compatibility: Allow arrays of length 1 with simple element selector. Some users might defined arrays without options.
|
|
166
|
-
value.length === 1 && isSimpleElementSelectorByType(value[0]));
|
|
167
|
-
}
|
|
168
|
-
function isElementSelector(value) {
|
|
169
|
-
return isSimpleElementSelectorByType(value) || isElementSelectorData(value) || isElementSelectorWithLegacyOptions(value);
|
|
170
|
-
}
|
|
171
|
-
function isElementsSelector(value) {
|
|
172
|
-
return isElementSelector(value) || isArray(value) && !isEmptyArray(value) && value.every(isElementSelector);
|
|
173
|
-
}
|
|
174
|
-
function isDependencySelector(value) {
|
|
175
|
-
return isObjectWithAnyOfProperties(value, ["from", "to"]);
|
|
176
|
-
}
|
|
177
|
-
function isExternalLibrarySelectorOptionsWithPath(value) {
|
|
178
|
-
return isObjectWithProperty(value, "path") && (isString(value.path) || isStringArray(value.path));
|
|
179
|
-
}
|
|
180
|
-
function isExternalLibrarySelectorOptionsWithSpecifiers(value) {
|
|
181
|
-
return isObjectWithProperty(value, "specifiers") && isStringArray(value.specifiers);
|
|
182
|
-
}
|
|
183
|
-
function isExternalLibrarySelectorOptions(value) {
|
|
184
|
-
return isExternalLibrarySelectorOptionsWithPath(value) || isExternalLibrarySelectorOptionsWithSpecifiers(value);
|
|
185
|
-
}
|
|
186
|
-
function isExternalLibrarySelectorWithOptions(value) {
|
|
187
|
-
return isArray(value) && value.length === 2 && isSimpleElementSelectorByType(value[0]) && isExternalLibrarySelectorOptions(value[1]);
|
|
188
|
-
}
|
|
189
|
-
function isExternalLibrarySelector(value) {
|
|
190
|
-
return isSimpleElementSelectorByType(value) || isExternalLibrarySelectorWithOptions(value);
|
|
191
|
-
}
|
|
192
|
-
function isExternalLibrariesSelector(value) {
|
|
193
|
-
return isExternalLibrarySelector(value) || isArray(value) && !isEmptyArray(value) && value.every(isExternalLibrarySelector);
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
// src/Matcher/BaseElementsMatcher.ts
|
|
197
|
-
var HANDLEBARS_TEMPLATE_REGEX = /{{\s*[^}\s]+(?:\s+[^}\s]+)*\s*}}/;
|
|
198
130
|
var LEGACY_TEMPLATE_REGEX = /\$\{([^}]+)\}/g;
|
|
199
|
-
|
|
200
|
-
if (isSimpleElementSelectorByType(selector)) {
|
|
201
|
-
return { type: selector };
|
|
202
|
-
}
|
|
203
|
-
if (isElementSelectorData(selector)) {
|
|
204
|
-
return { ...selector };
|
|
205
|
-
}
|
|
206
|
-
if (isElementSelectorWithLegacyOptions(selector)) {
|
|
207
|
-
return {
|
|
208
|
-
type: selector[0],
|
|
209
|
-
captured: selector[1] ? { ...selector[1] } : void 0
|
|
210
|
-
};
|
|
211
|
-
}
|
|
212
|
-
throw new Error("Invalid element selector");
|
|
213
|
-
}
|
|
214
|
-
function normalizeElementsSelector(elementsSelector) {
|
|
215
|
-
if (isArray(elementsSelector)) {
|
|
216
|
-
if (isElementSelectorWithLegacyOptions(elementsSelector)) {
|
|
217
|
-
return [normalizeSelector(elementsSelector)];
|
|
218
|
-
}
|
|
219
|
-
return elementsSelector.map((sel) => normalizeSelector(sel));
|
|
220
|
-
}
|
|
221
|
-
return [normalizeSelector(elementsSelector)];
|
|
222
|
-
}
|
|
131
|
+
var HANDLEBARS_TEMPLATE_REGEX = /{{\s*[^{}\s][^{}]*}}/;
|
|
223
132
|
var BaseElementsMatcher = class {
|
|
224
133
|
/**
|
|
225
134
|
* Option to use legacy templates with ${} syntax.
|
|
@@ -244,6 +153,9 @@ var BaseElementsMatcher = class {
|
|
|
244
153
|
* @returns The converted template.
|
|
245
154
|
*/
|
|
246
155
|
_getBackwardsCompatibleTemplate(template) {
|
|
156
|
+
if (!template) {
|
|
157
|
+
return template;
|
|
158
|
+
}
|
|
247
159
|
return template.replaceAll(LEGACY_TEMPLATE_REGEX, "{{ $1 }}");
|
|
248
160
|
}
|
|
249
161
|
/**
|
|
@@ -252,6 +164,9 @@ var BaseElementsMatcher = class {
|
|
|
252
164
|
* @returns True if the template contains Handlebars syntax, false otherwise.
|
|
253
165
|
*/
|
|
254
166
|
_isHandlebarsTemplate(template) {
|
|
167
|
+
if (!template) {
|
|
168
|
+
return false;
|
|
169
|
+
}
|
|
255
170
|
return HANDLEBARS_TEMPLATE_REGEX.test(template);
|
|
256
171
|
}
|
|
257
172
|
/**
|
|
@@ -283,6 +198,14 @@ var BaseElementsMatcher = class {
|
|
|
283
198
|
}
|
|
284
199
|
return this._getRenderedTemplate(template, templateData);
|
|
285
200
|
}
|
|
201
|
+
/**
|
|
202
|
+
* Cleans a micromatch pattern by removing falsy values from arrays.
|
|
203
|
+
* @param pattern The micromatch pattern(s) to clean.
|
|
204
|
+
* @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.
|
|
205
|
+
*/
|
|
206
|
+
cleanMicromatchPattern(pattern) {
|
|
207
|
+
return isArray(pattern) ? pattern.filter(Boolean) : pattern;
|
|
208
|
+
}
|
|
286
209
|
/**
|
|
287
210
|
* Returns whether the given value matches the micromatch pattern, converting non-string values to strings.
|
|
288
211
|
* Optimized version with caching for better performance.
|
|
@@ -291,9 +214,18 @@ var BaseElementsMatcher = class {
|
|
|
291
214
|
* @returns Whether the value matches the pattern.
|
|
292
215
|
*/
|
|
293
216
|
isMicromatchMatch(value, pattern) {
|
|
217
|
+
if (isNull(pattern)) {
|
|
218
|
+
return isNull(value);
|
|
219
|
+
}
|
|
220
|
+
if (isNull(value)) {
|
|
221
|
+
return isArray(pattern) && pattern.some(isNull);
|
|
222
|
+
}
|
|
223
|
+
const patternToCheck = this.cleanMicromatchPattern(pattern);
|
|
224
|
+
if (!patternToCheck?.length) {
|
|
225
|
+
return false;
|
|
226
|
+
}
|
|
294
227
|
const elementValueToCheck = !value || !isString(value) ? String(value) : value;
|
|
295
|
-
|
|
296
|
-
return this.micromatch.isMatch(elementValueToCheck, selectorValueToCheck);
|
|
228
|
+
return this.micromatch.isMatch(elementValueToCheck, patternToCheck);
|
|
297
229
|
}
|
|
298
230
|
/**
|
|
299
231
|
* Returns whether the given value matches the micromatch pattern after rendering it as a template.
|
|
@@ -303,18 +235,17 @@ var BaseElementsMatcher = class {
|
|
|
303
235
|
* @returns Whether the value matches the rendered pattern.
|
|
304
236
|
*/
|
|
305
237
|
isTemplateMicromatchMatch(pattern, templateData, value) {
|
|
306
|
-
if (
|
|
238
|
+
if (isUndefined(value)) {
|
|
307
239
|
return false;
|
|
308
240
|
}
|
|
309
241
|
const patternRendered = this.getRenderedTemplates(pattern, templateData);
|
|
310
|
-
if (!patternRendered) {
|
|
242
|
+
if (!isNull(patternRendered) && !patternRendered) {
|
|
311
243
|
return false;
|
|
312
244
|
}
|
|
313
|
-
const filteredPattern = isArray(patternRendered) ? patternRendered.filter(Boolean) : patternRendered;
|
|
314
245
|
if (isArray(value)) {
|
|
315
|
-
return value.some((val) => this.isMicromatchMatch(val,
|
|
246
|
+
return value.some((val) => this.isMicromatchMatch(val, patternRendered));
|
|
316
247
|
}
|
|
317
|
-
return this.isMicromatchMatch(value,
|
|
248
|
+
return this.isMicromatchMatch(value, patternRendered);
|
|
318
249
|
}
|
|
319
250
|
/**
|
|
320
251
|
* Whether the given element key matches the selector key as booleans.
|
|
@@ -358,20 +289,113 @@ var BaseElementsMatcher = class {
|
|
|
358
289
|
if (!(selectorKey in selector)) {
|
|
359
290
|
return true;
|
|
360
291
|
}
|
|
361
|
-
if (
|
|
362
|
-
return false;
|
|
363
|
-
}
|
|
364
|
-
if (!isObjectWithProperty(element, elementKey)) {
|
|
292
|
+
if (isUndefined(selectorValue) || !isObjectWithProperty(element, String(elementKey))) {
|
|
365
293
|
return false;
|
|
366
294
|
}
|
|
295
|
+
const elementValue = element[String(elementKey)];
|
|
367
296
|
return this.isTemplateMicromatchMatch(
|
|
368
297
|
selectorValue,
|
|
369
298
|
templateData,
|
|
370
|
-
|
|
299
|
+
elementValue
|
|
371
300
|
);
|
|
372
301
|
}
|
|
373
302
|
};
|
|
374
303
|
|
|
304
|
+
// src/Matcher/MatcherHelpers.ts
|
|
305
|
+
function isCapturedValuesObjectSelector(value) {
|
|
306
|
+
if (!isObject(value) || isArray(value)) {
|
|
307
|
+
return false;
|
|
308
|
+
}
|
|
309
|
+
return Object.values(value).every(
|
|
310
|
+
(pattern) => isString(pattern) || isStringArray(pattern)
|
|
311
|
+
);
|
|
312
|
+
}
|
|
313
|
+
function isCapturedValuesSelector(value) {
|
|
314
|
+
if (isArray(value)) {
|
|
315
|
+
return value.every((item) => isCapturedValuesObjectSelector(item));
|
|
316
|
+
}
|
|
317
|
+
return isCapturedValuesObjectSelector(value);
|
|
318
|
+
}
|
|
319
|
+
function isSimpleElementSelectorByType(value) {
|
|
320
|
+
return isString(value);
|
|
321
|
+
}
|
|
322
|
+
function isBaseElementSelectorData(value) {
|
|
323
|
+
return isObjectWithAnyOfProperties(value, [
|
|
324
|
+
"path",
|
|
325
|
+
"elementPath",
|
|
326
|
+
"internalPath",
|
|
327
|
+
"type",
|
|
328
|
+
"category",
|
|
329
|
+
"captured",
|
|
330
|
+
"parent",
|
|
331
|
+
"origin",
|
|
332
|
+
"source",
|
|
333
|
+
"module",
|
|
334
|
+
"isIgnored",
|
|
335
|
+
"isUnknown"
|
|
336
|
+
]);
|
|
337
|
+
}
|
|
338
|
+
function isElementSelectorData(value) {
|
|
339
|
+
return isBaseElementSelectorData(value);
|
|
340
|
+
}
|
|
341
|
+
function isElementSelectorWithLegacyOptions(value) {
|
|
342
|
+
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.
|
|
343
|
+
isCapturedValuesSelector(value[1]) || // NOTE: Backwards compatibility: Allow arrays of length 1 with simple element selector. Some users might defined arrays without options.
|
|
344
|
+
value.length === 1 && isSimpleElementSelectorByType(value[0]));
|
|
345
|
+
}
|
|
346
|
+
function isElementSelector(value) {
|
|
347
|
+
return isSimpleElementSelectorByType(value) || isElementSelectorData(value) || isElementSelectorWithLegacyOptions(value);
|
|
348
|
+
}
|
|
349
|
+
function isElementsSelector(value) {
|
|
350
|
+
return isElementSelector(value) || isArray(value) && !isEmptyArray(value) && value.every(isElementSelector);
|
|
351
|
+
}
|
|
352
|
+
function normalizeElementSelector(selector) {
|
|
353
|
+
if (isSimpleElementSelectorByType(selector)) {
|
|
354
|
+
return { type: selector };
|
|
355
|
+
}
|
|
356
|
+
if (isElementSelectorData(selector)) {
|
|
357
|
+
return { ...selector };
|
|
358
|
+
}
|
|
359
|
+
if (isElementSelectorWithLegacyOptions(selector)) {
|
|
360
|
+
return {
|
|
361
|
+
type: selector[0],
|
|
362
|
+
captured: selector[1] ? { ...selector[1] } : void 0
|
|
363
|
+
};
|
|
364
|
+
}
|
|
365
|
+
throw new Error("Invalid element selector");
|
|
366
|
+
}
|
|
367
|
+
function normalizeElementsSelector(elementsSelector) {
|
|
368
|
+
if (isArray(elementsSelector)) {
|
|
369
|
+
if (isElementSelectorWithLegacyOptions(elementsSelector)) {
|
|
370
|
+
return [normalizeElementSelector(elementsSelector)];
|
|
371
|
+
}
|
|
372
|
+
return elementsSelector.map((sel) => normalizeElementSelector(sel));
|
|
373
|
+
}
|
|
374
|
+
return [normalizeElementSelector(elementsSelector)];
|
|
375
|
+
}
|
|
376
|
+
function isDependencySelector(value) {
|
|
377
|
+
if (!isObjectWithAnyOfProperties(value, ["from", "to", "dependency"])) {
|
|
378
|
+
return false;
|
|
379
|
+
}
|
|
380
|
+
const fromIsValid = !isObjectWithProperty(value, "from") || isElementsSelector(value.from);
|
|
381
|
+
const toIsValid = !isObjectWithProperty(value, "to") || isElementsSelector(value.to);
|
|
382
|
+
const dependencyIsValid = !isObjectWithProperty(value, "dependency") || isDependencyDataSelector(value.dependency);
|
|
383
|
+
return fromIsValid && toIsValid && dependencyIsValid;
|
|
384
|
+
}
|
|
385
|
+
function isDependencyDataSelectorData(value) {
|
|
386
|
+
return isObjectWithAnyOfProperties(value, [
|
|
387
|
+
"kind",
|
|
388
|
+
"relationship",
|
|
389
|
+
"specifiers",
|
|
390
|
+
"nodeKind",
|
|
391
|
+
"source",
|
|
392
|
+
"module"
|
|
393
|
+
]);
|
|
394
|
+
}
|
|
395
|
+
function isDependencyDataSelector(value) {
|
|
396
|
+
return isDependencyDataSelectorData(value) || isArray(value) && !isEmptyArray(value) && value.every(isDependencyDataSelectorData);
|
|
397
|
+
}
|
|
398
|
+
|
|
375
399
|
// src/Matcher/DependenciesMatcher.ts
|
|
376
400
|
var DependenciesMatcher = class extends BaseElementsMatcher {
|
|
377
401
|
/**
|
|
@@ -394,68 +418,20 @@ var DependenciesMatcher = class extends BaseElementsMatcher {
|
|
|
394
418
|
* @param selector The dependency selector to normalize.
|
|
395
419
|
* @returns The normalized dependency selector.
|
|
396
420
|
*/
|
|
397
|
-
_normalizeDependencySelector(selector
|
|
421
|
+
_normalizeDependencySelector(selector) {
|
|
398
422
|
if (!isDependencySelector(selector)) {
|
|
399
423
|
throw new Error("Invalid dependency selector");
|
|
400
424
|
}
|
|
401
|
-
let normalizedDependencySelectors =
|
|
402
|
-
if (
|
|
403
|
-
normalizedDependencySelectors =
|
|
404
|
-
(depSelector) => {
|
|
405
|
-
return {
|
|
406
|
-
...dependencySelectorsGlobals,
|
|
407
|
-
...depSelector
|
|
408
|
-
};
|
|
409
|
-
}
|
|
410
|
-
);
|
|
425
|
+
let normalizedDependencySelectors = null;
|
|
426
|
+
if (selector.dependency && isDependencyDataSelector(selector.dependency)) {
|
|
427
|
+
normalizedDependencySelectors = isArray(selector.dependency) ? selector.dependency : [selector.dependency];
|
|
411
428
|
}
|
|
412
429
|
return {
|
|
413
430
|
from: selector.from ? normalizeElementsSelector(selector.from) : null,
|
|
414
|
-
to:
|
|
431
|
+
to: selector.to ? normalizeElementsSelector(selector.to) : null,
|
|
432
|
+
dependency: normalizedDependencySelectors
|
|
415
433
|
};
|
|
416
434
|
}
|
|
417
|
-
/**
|
|
418
|
-
* Converts a DependencyElementSelectorData to a BaseElementSelectorData, by removing dependency-specific properties.
|
|
419
|
-
* @param selector The dependency element selector data.
|
|
420
|
-
* @returns The base element selector data.
|
|
421
|
-
*/
|
|
422
|
-
_convertDependencyElementSelectorDataToBaseElementSelectorData(selector) {
|
|
423
|
-
const baseSelector = {};
|
|
424
|
-
if (selector.type) {
|
|
425
|
-
baseSelector.type = selector.type;
|
|
426
|
-
}
|
|
427
|
-
if (selector.category) {
|
|
428
|
-
baseSelector.category = selector.category;
|
|
429
|
-
}
|
|
430
|
-
if (selector.path) {
|
|
431
|
-
baseSelector.path = selector.path;
|
|
432
|
-
}
|
|
433
|
-
if (selector.elementPath) {
|
|
434
|
-
baseSelector.elementPath = selector.elementPath;
|
|
435
|
-
}
|
|
436
|
-
if (selector.internalPath) {
|
|
437
|
-
baseSelector.internalPath = selector.internalPath;
|
|
438
|
-
}
|
|
439
|
-
if (selector.captured) {
|
|
440
|
-
baseSelector.captured = selector.captured;
|
|
441
|
-
}
|
|
442
|
-
if (selector.origin) {
|
|
443
|
-
baseSelector.origin = selector.origin;
|
|
444
|
-
}
|
|
445
|
-
if (selector.baseSource) {
|
|
446
|
-
baseSelector.baseSource = selector.baseSource;
|
|
447
|
-
}
|
|
448
|
-
if (selector.source) {
|
|
449
|
-
baseSelector.source = selector.source;
|
|
450
|
-
}
|
|
451
|
-
if (!isNullish(selector.isIgnored)) {
|
|
452
|
-
baseSelector.isIgnored = selector.isIgnored;
|
|
453
|
-
}
|
|
454
|
-
if (!isNullish(selector.isUnknown)) {
|
|
455
|
-
baseSelector.isUnknown = selector.isUnknown;
|
|
456
|
-
}
|
|
457
|
-
return baseSelector;
|
|
458
|
-
}
|
|
459
435
|
/**
|
|
460
436
|
* Returns the selectors matching result for the given dependency.
|
|
461
437
|
* @param dependency The dependency description.
|
|
@@ -463,56 +439,37 @@ var DependenciesMatcher = class extends BaseElementsMatcher {
|
|
|
463
439
|
* @param extraTemplateData The extra template data for selector values.
|
|
464
440
|
* @returns The selectors matching result for the given dependency.
|
|
465
441
|
*/
|
|
466
|
-
|
|
467
|
-
const
|
|
468
|
-
for (const
|
|
469
|
-
const
|
|
470
|
-
dependency.from,
|
|
471
|
-
fromSelectorData,
|
|
472
|
-
{
|
|
473
|
-
extraTemplateData: templateData
|
|
474
|
-
}
|
|
475
|
-
);
|
|
476
|
-
const dependencyPropertiesMatch = this._dependencyFromPropertiesMatch(
|
|
442
|
+
_getSelectorsMatching(dependency, selector, templateData) {
|
|
443
|
+
const getDependencyMetadataSelectorMatching = () => {
|
|
444
|
+
for (const dependencySelectorData of selector.dependency) {
|
|
445
|
+
const dependencyPropertiesMatch = this._dependencyPropertiesMatch(
|
|
477
446
|
dependency,
|
|
478
|
-
|
|
447
|
+
dependencySelectorData,
|
|
479
448
|
templateData
|
|
480
449
|
);
|
|
481
|
-
if (
|
|
482
|
-
return
|
|
450
|
+
if (dependencyPropertiesMatch) {
|
|
451
|
+
return dependencySelectorData;
|
|
483
452
|
}
|
|
484
453
|
}
|
|
485
454
|
return null;
|
|
486
455
|
};
|
|
487
|
-
const
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
toSelectorData
|
|
493
|
-
),
|
|
494
|
-
{
|
|
495
|
-
extraTemplateData: templateData
|
|
496
|
-
}
|
|
497
|
-
) : true;
|
|
498
|
-
const dependencyPropertiesMatch = this._dependencyToPropertiesMatch(
|
|
499
|
-
dependency,
|
|
500
|
-
[toSelectorData],
|
|
501
|
-
templateData
|
|
502
|
-
);
|
|
503
|
-
if (toMatch && dependencyPropertiesMatch) {
|
|
504
|
-
return toSelectorData;
|
|
505
|
-
}
|
|
456
|
+
const fromSelectorMatching = selector.from ? this._elementsMatcher.getSelectorMatching(
|
|
457
|
+
dependency.from,
|
|
458
|
+
selector.from,
|
|
459
|
+
{
|
|
460
|
+
extraTemplateData: templateData
|
|
506
461
|
}
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
462
|
+
) : null;
|
|
463
|
+
const toSelectorMatching = selector.to ? this._elementsMatcher.getSelectorMatching(dependency.to, selector.to, {
|
|
464
|
+
extraTemplateData: templateData
|
|
465
|
+
}) : null;
|
|
466
|
+
const dependencyMetadataSelectorMatching = selector.dependency ? getDependencyMetadataSelectorMatching() : null;
|
|
511
467
|
return {
|
|
512
468
|
from: fromSelectorMatching,
|
|
513
469
|
to: toSelectorMatching,
|
|
470
|
+
dependency: dependencyMetadataSelectorMatching,
|
|
514
471
|
isMatch: Boolean(
|
|
515
|
-
(selector.from ? fromSelectorMatching : true) && (selector.to ? toSelectorMatching : true)
|
|
472
|
+
(selector.from ? fromSelectorMatching : true) && (selector.to ? toSelectorMatching : true) && (selector.dependency ? dependencyMetadataSelectorMatching : true)
|
|
516
473
|
)
|
|
517
474
|
};
|
|
518
475
|
}
|
|
@@ -522,12 +479,29 @@ var DependenciesMatcher = class extends BaseElementsMatcher {
|
|
|
522
479
|
* @param selector The data of an element selector.
|
|
523
480
|
* @returns Whether the dependency relationship matches the selector.
|
|
524
481
|
*/
|
|
525
|
-
|
|
526
|
-
if (!selector.relationship) {
|
|
482
|
+
_relationshipFromMatches(selector, relationship, templateData) {
|
|
483
|
+
if (!selector.relationship?.from) {
|
|
484
|
+
return true;
|
|
485
|
+
}
|
|
486
|
+
return this.isTemplateMicromatchMatch(
|
|
487
|
+
selector.relationship.from,
|
|
488
|
+
templateData,
|
|
489
|
+
relationship
|
|
490
|
+
);
|
|
491
|
+
}
|
|
492
|
+
/**
|
|
493
|
+
* Determines if the dependency origin relationship matches the selector.
|
|
494
|
+
* @param selector The dependency selector data.
|
|
495
|
+
* @param relationship The relationship from origin element to target element.
|
|
496
|
+
* @param templateData The template data for rendering selector values.
|
|
497
|
+
* @returns Whether the dependency origin relationship matches.
|
|
498
|
+
*/
|
|
499
|
+
_relationshipToMatches(selector, relationship, templateData) {
|
|
500
|
+
if (!selector.relationship?.to) {
|
|
527
501
|
return true;
|
|
528
502
|
}
|
|
529
503
|
return this.isTemplateMicromatchMatch(
|
|
530
|
-
selector.relationship,
|
|
504
|
+
selector.relationship.to,
|
|
531
505
|
templateData,
|
|
532
506
|
relationship
|
|
533
507
|
);
|
|
@@ -580,75 +554,85 @@ var DependenciesMatcher = class extends BaseElementsMatcher {
|
|
|
580
554
|
);
|
|
581
555
|
}
|
|
582
556
|
/**
|
|
583
|
-
* Determines if the dependency description matches the selector for '
|
|
557
|
+
* Determines if the dependency description matches the selector for 'to'.
|
|
584
558
|
* @param dependency The dependency description.
|
|
585
|
-
* @param
|
|
559
|
+
* @param toSelector The selector for 'to' elements.
|
|
586
560
|
* @param templateData The template data for rendering selector values
|
|
587
|
-
* @returns Whether the dependency properties match the selector for '
|
|
588
|
-
*/
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
561
|
+
* @returns Whether the dependency properties match the selector for 'to'.
|
|
562
|
+
*/
|
|
563
|
+
_sourceMatches(selector, source, templateData) {
|
|
564
|
+
if (!selector.source) {
|
|
565
|
+
return true;
|
|
566
|
+
}
|
|
567
|
+
return this.isTemplateMicromatchMatch(
|
|
568
|
+
selector.source,
|
|
569
|
+
templateData,
|
|
570
|
+
source
|
|
596
571
|
);
|
|
597
572
|
}
|
|
598
573
|
/**
|
|
599
|
-
* Determines if the
|
|
574
|
+
* Determines if the selector matches the module
|
|
575
|
+
* @param selector The dependency selector data
|
|
576
|
+
* @param module The module to check
|
|
577
|
+
* @param templateData The template data for rendering selector values
|
|
578
|
+
* @returns Whether the selector matches the module
|
|
579
|
+
*/
|
|
580
|
+
_moduleMatches(selector, dependencyModule, templateData) {
|
|
581
|
+
if (!selector.module) {
|
|
582
|
+
return true;
|
|
583
|
+
}
|
|
584
|
+
return this.isTemplateMicromatchMatch(
|
|
585
|
+
selector.module,
|
|
586
|
+
templateData,
|
|
587
|
+
dependencyModule
|
|
588
|
+
);
|
|
589
|
+
}
|
|
590
|
+
/**
|
|
591
|
+
* Determines if the dependency description matches the selector for dependency metadata.
|
|
600
592
|
* @param dependency The dependency description.
|
|
601
|
-
* @param
|
|
593
|
+
* @param selectorData The selector for dependency metadata.
|
|
602
594
|
* @param templateData The template data for rendering selector values
|
|
603
|
-
* @returns Whether the dependency properties match the selector
|
|
595
|
+
* @returns Whether the dependency properties match the selector.
|
|
604
596
|
*/
|
|
605
|
-
|
|
597
|
+
_dependencyPropertiesMatch(dependency, selectorData, templateData) {
|
|
606
598
|
const dependencyInfo = dependency.dependency;
|
|
599
|
+
const relationshipFrom = dependencyInfo.relationship.from;
|
|
607
600
|
const relationshipTo = dependencyInfo.relationship.to;
|
|
608
601
|
const kind = dependencyInfo.kind;
|
|
609
602
|
const nodeKind = dependencyInfo.nodeKind;
|
|
610
603
|
const specifiers = dependencyInfo.specifiers;
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
604
|
+
const source = dependencyInfo.source;
|
|
605
|
+
const dependencyModule = dependencyInfo.module;
|
|
606
|
+
return this._kindMatches(selectorData, kind, templateData) && this._nodeKindMatches(selectorData, nodeKind, templateData) && this._sourceMatches(selectorData, source, templateData) && this._moduleMatches(selectorData, dependencyModule, templateData) && this._relationshipFromMatches(
|
|
607
|
+
selectorData,
|
|
608
|
+
relationshipFrom,
|
|
609
|
+
templateData
|
|
610
|
+
) && this._relationshipToMatches(selectorData, relationshipTo, templateData) && this._specifierMatches(selectorData, specifiers, templateData);
|
|
617
611
|
}
|
|
618
612
|
/**
|
|
619
613
|
* Returns the selectors matching result for the given dependency.
|
|
620
614
|
* @param dependency The dependency to check.
|
|
621
615
|
* @param selector The selector to check against.
|
|
622
|
-
* @param options Extra options for matching, such as templates data,
|
|
616
|
+
* @param options Extra options for matching, such as templates data, etc.
|
|
623
617
|
* @returns The matching result for the dependency against the selector.
|
|
624
618
|
*/
|
|
625
|
-
getSelectorsMatching(dependency, selector, {
|
|
626
|
-
|
|
627
|
-
dependencySelectorsGlobals = {}
|
|
628
|
-
} = {}) {
|
|
629
|
-
const normalizedSelector = this._normalizeDependencySelector(
|
|
630
|
-
selector,
|
|
631
|
-
dependencySelectorsGlobals
|
|
632
|
-
);
|
|
619
|
+
getSelectorsMatching(dependency, selector, { extraTemplateData = {} } = {}) {
|
|
620
|
+
const normalizedSelector = this._normalizeDependencySelector(selector);
|
|
633
621
|
const fromExtraData = extraTemplateData.from || {};
|
|
634
622
|
const toExtraData = extraTemplateData.to || {};
|
|
635
623
|
const templateData = {
|
|
636
624
|
...extraTemplateData,
|
|
637
625
|
from: {
|
|
638
626
|
...dependency.from,
|
|
639
|
-
relationship: dependency.dependency.relationship.from,
|
|
640
627
|
...fromExtraData
|
|
641
628
|
},
|
|
642
629
|
to: {
|
|
643
630
|
...dependency.to,
|
|
644
|
-
relationship: dependency.dependency.relationship.to,
|
|
645
|
-
kind: dependency.dependency.kind,
|
|
646
|
-
nodeKind: dependency.dependency.nodeKind,
|
|
647
|
-
specifiers: dependency.dependency.specifiers,
|
|
648
631
|
...toExtraData
|
|
649
|
-
}
|
|
632
|
+
},
|
|
633
|
+
dependency: dependency.dependency
|
|
650
634
|
};
|
|
651
|
-
const result = this.
|
|
635
|
+
const result = this._getSelectorsMatching(
|
|
652
636
|
dependency,
|
|
653
637
|
normalizedSelector,
|
|
654
638
|
templateData
|
|
@@ -659,7 +643,7 @@ var DependenciesMatcher = class extends BaseElementsMatcher {
|
|
|
659
643
|
* Returns whether the given dependency matches the selector.
|
|
660
644
|
* @param dependency The dependency to check.
|
|
661
645
|
* @param selector The selector to check against.
|
|
662
|
-
* @param options Extra options for matching, such as templates data,
|
|
646
|
+
* @param options Extra options for matching, such as templates data, etc.
|
|
663
647
|
* @returns Whether the dependency matches the selector properties.
|
|
664
648
|
*/
|
|
665
649
|
isDependencyMatch(dependency, selector, options) {
|
|
@@ -674,8 +658,6 @@ var DependenciesMatcher = class extends BaseElementsMatcher {
|
|
|
674
658
|
|
|
675
659
|
// src/Matcher/ElementsMatcher.ts
|
|
676
660
|
var ElementsMatcher = class extends BaseElementsMatcher {
|
|
677
|
-
/** Whether the cache is enabled or not */
|
|
678
|
-
_cacheIsEnabled;
|
|
679
661
|
/**
|
|
680
662
|
* Creates a new ElementsSelectorMatcher.
|
|
681
663
|
* @param config Configuration options for the matcher.
|
|
@@ -788,41 +770,36 @@ var ElementsMatcher = class extends BaseElementsMatcher {
|
|
|
788
770
|
});
|
|
789
771
|
}
|
|
790
772
|
/**
|
|
791
|
-
*
|
|
792
|
-
* @param
|
|
793
|
-
* @param
|
|
794
|
-
* @param templateData The data to use for replace in selector
|
|
795
|
-
* @returns
|
|
796
|
-
*/
|
|
797
|
-
_isBaseSourceMatch(element, selector, templateData) {
|
|
798
|
-
return this.isElementKeyMicromatchMatch({
|
|
799
|
-
element,
|
|
800
|
-
selector,
|
|
801
|
-
elementKey: "baseSource",
|
|
802
|
-
selectorKey: "baseSource",
|
|
803
|
-
selectorValue: selector.baseSource,
|
|
804
|
-
templateData
|
|
805
|
-
});
|
|
806
|
-
}
|
|
807
|
-
/**
|
|
808
|
-
* Whether the given element source matches the selector source
|
|
809
|
-
* @param element The element to check.
|
|
810
|
-
* @param selector The selector to check against.
|
|
811
|
-
* @param templateData The data to use for replace in selector value
|
|
812
|
-
* @returns Whether the element source matches the selector source.
|
|
773
|
+
* Checks if a single captured values object matches the element.
|
|
774
|
+
* @param capturedValues The captured values to check.
|
|
775
|
+
* @param capturedSelector The captured values selector object to check against
|
|
776
|
+
* @param templateData The data to use for replace in selector values
|
|
777
|
+
* @returns True if all captured values in the selector match those in the element, false otherwise.
|
|
813
778
|
*/
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
779
|
+
_checkCapturedValuesObject(capturedValues, capturedSelector, templateData) {
|
|
780
|
+
if (!capturedValues) {
|
|
781
|
+
return false;
|
|
782
|
+
}
|
|
783
|
+
for (const [key, pattern] of Object.entries(capturedSelector)) {
|
|
784
|
+
const elementValue = capturedValues[key];
|
|
785
|
+
if (!elementValue) {
|
|
786
|
+
return false;
|
|
787
|
+
}
|
|
788
|
+
const renderedPattern = this.getRenderedTemplates(pattern, templateData);
|
|
789
|
+
const filteredPattern = this.cleanMicromatchPattern(renderedPattern);
|
|
790
|
+
if (!filteredPattern) {
|
|
791
|
+
return false;
|
|
792
|
+
}
|
|
793
|
+
const isMatch = this.micromatch.isMatch(elementValue, filteredPattern);
|
|
794
|
+
if (!isMatch) {
|
|
795
|
+
return false;
|
|
796
|
+
}
|
|
797
|
+
}
|
|
798
|
+
return true;
|
|
823
799
|
}
|
|
824
800
|
/**
|
|
825
801
|
* Determines if the captured values of the element match those in the selector.
|
|
802
|
+
* When the selector is an array, the element matches if it matches any of the array elements (OR logic).
|
|
826
803
|
* @param element The element to check.
|
|
827
804
|
* @param selector The selector to check against
|
|
828
805
|
* @param templateData The data to use for replace in selector values
|
|
@@ -832,23 +809,98 @@ var ElementsMatcher = class extends BaseElementsMatcher {
|
|
|
832
809
|
if (!selector.captured || isEmptyObject(selector.captured)) {
|
|
833
810
|
return true;
|
|
834
811
|
}
|
|
835
|
-
if (
|
|
836
|
-
|
|
837
|
-
}
|
|
838
|
-
for (const [key, pattern] of Object.entries(selector.captured)) {
|
|
839
|
-
const elementValue = element.captured?.[key];
|
|
840
|
-
if (!elementValue) {
|
|
841
|
-
return false;
|
|
842
|
-
}
|
|
843
|
-
const renderedPattern = this.getRenderedTemplates(pattern, templateData);
|
|
844
|
-
if (!renderedPattern) {
|
|
812
|
+
if (isArray(selector.captured)) {
|
|
813
|
+
if (selector.captured.length === 0) {
|
|
845
814
|
return false;
|
|
846
815
|
}
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
816
|
+
return selector.captured.some(
|
|
817
|
+
(capturedSelector) => this._checkCapturedValuesObject(
|
|
818
|
+
element.captured,
|
|
819
|
+
capturedSelector,
|
|
820
|
+
templateData
|
|
821
|
+
)
|
|
822
|
+
);
|
|
823
|
+
}
|
|
824
|
+
return this._checkCapturedValuesObject(
|
|
825
|
+
element.captured,
|
|
826
|
+
selector.captured,
|
|
827
|
+
templateData
|
|
828
|
+
);
|
|
829
|
+
}
|
|
830
|
+
/**
|
|
831
|
+
* Determines if the parent captured values match the selector.
|
|
832
|
+
* @param parentSelector The parent selector to match.
|
|
833
|
+
* @param parentCaptured The captured values from first parent.
|
|
834
|
+
* @param templateData The data to use for replace in selector values
|
|
835
|
+
* @returns True if the captured values match, false otherwise.
|
|
836
|
+
*/
|
|
837
|
+
_isParentCapturedValuesMatch(parentSelector, parentCaptured, templateData) {
|
|
838
|
+
if (!parentSelector.captured || isEmptyObject(parentSelector.captured)) {
|
|
839
|
+
return true;
|
|
840
|
+
}
|
|
841
|
+
if (isArray(parentSelector.captured)) {
|
|
842
|
+
if (parentSelector.captured.length === 0) {
|
|
850
843
|
return false;
|
|
851
844
|
}
|
|
845
|
+
return parentSelector.captured.some(
|
|
846
|
+
(capturedSelector) => this._checkCapturedValuesObject(
|
|
847
|
+
parentCaptured,
|
|
848
|
+
capturedSelector,
|
|
849
|
+
templateData
|
|
850
|
+
)
|
|
851
|
+
);
|
|
852
|
+
}
|
|
853
|
+
return this._checkCapturedValuesObject(
|
|
854
|
+
parentCaptured,
|
|
855
|
+
parentSelector.captured,
|
|
856
|
+
templateData
|
|
857
|
+
);
|
|
858
|
+
}
|
|
859
|
+
/**
|
|
860
|
+
* Whether the given element first parent matches the selector parent.
|
|
861
|
+
* @param element The element to check.
|
|
862
|
+
* @param selector The selector to check against.
|
|
863
|
+
* @param templateData The data to use for replace in selector values
|
|
864
|
+
* @returns Whether the first parent matches the selector parent.
|
|
865
|
+
*/
|
|
866
|
+
_isParentMatch(element, selector, templateData) {
|
|
867
|
+
if (isUndefined(selector.parent)) {
|
|
868
|
+
return true;
|
|
869
|
+
}
|
|
870
|
+
if (isNull(selector.parent)) {
|
|
871
|
+
return !element.parents || element.parents.length === 0;
|
|
872
|
+
}
|
|
873
|
+
const firstParent = element.parents?.[0];
|
|
874
|
+
if (!firstParent) {
|
|
875
|
+
return false;
|
|
876
|
+
}
|
|
877
|
+
if (!isUndefined(selector.parent.type) && !this.isTemplateMicromatchMatch(
|
|
878
|
+
selector.parent.type,
|
|
879
|
+
templateData,
|
|
880
|
+
firstParent.type
|
|
881
|
+
)) {
|
|
882
|
+
return false;
|
|
883
|
+
}
|
|
884
|
+
if (!isUndefined(selector.parent.category) && !this.isTemplateMicromatchMatch(
|
|
885
|
+
selector.parent.category,
|
|
886
|
+
templateData,
|
|
887
|
+
firstParent.category
|
|
888
|
+
)) {
|
|
889
|
+
return false;
|
|
890
|
+
}
|
|
891
|
+
if (!isUndefined(selector.parent.elementPath) && !this.isTemplateMicromatchMatch(
|
|
892
|
+
selector.parent.elementPath,
|
|
893
|
+
templateData,
|
|
894
|
+
firstParent.elementPath
|
|
895
|
+
)) {
|
|
896
|
+
return false;
|
|
897
|
+
}
|
|
898
|
+
if (!this._isParentCapturedValuesMatch(
|
|
899
|
+
selector.parent,
|
|
900
|
+
firstParent.captured,
|
|
901
|
+
templateData
|
|
902
|
+
)) {
|
|
903
|
+
return false;
|
|
852
904
|
}
|
|
853
905
|
return true;
|
|
854
906
|
}
|
|
@@ -893,7 +945,7 @@ var ElementsMatcher = class extends BaseElementsMatcher {
|
|
|
893
945
|
...extraTemplateData
|
|
894
946
|
};
|
|
895
947
|
for (const selectorData of selectorsData) {
|
|
896
|
-
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.
|
|
948
|
+
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)) {
|
|
897
949
|
continue;
|
|
898
950
|
}
|
|
899
951
|
return selectorData;
|
|
@@ -905,7 +957,7 @@ var ElementsMatcher = class extends BaseElementsMatcher {
|
|
|
905
957
|
* It omits checks in keys applying only to dependency between elements, such as relationship.
|
|
906
958
|
* @param element The element to check.
|
|
907
959
|
* @param selector The selector to check against.
|
|
908
|
-
* @param options Extra options for matching, such as templates data,
|
|
960
|
+
* @param options Extra options for matching, such as templates data, etc.
|
|
909
961
|
* @returns The selector matching result for the given element, or null if none matches.
|
|
910
962
|
*/
|
|
911
963
|
getSelectorMatching(element, selector, { extraTemplateData = {} } = {}) {
|
|
@@ -917,7 +969,7 @@ var ElementsMatcher = class extends BaseElementsMatcher {
|
|
|
917
969
|
* It omits checks in keys applying only to dependency between elements, such as relationship.
|
|
918
970
|
* @param element The element to check.
|
|
919
971
|
* @param selector The selector to check against.
|
|
920
|
-
* @param options Extra options for matching, such as templates data,
|
|
972
|
+
* @param options Extra options for matching, such as templates data, etc.
|
|
921
973
|
* @returns Whether the element matches the selector properties applying to elements.
|
|
922
974
|
*/
|
|
923
975
|
isElementMatch(element, selector, options) {
|
|
@@ -984,20 +1036,17 @@ function isUnknownLocalElement(value) {
|
|
|
984
1036
|
function isKnownLocalElement(value) {
|
|
985
1037
|
return isLocalElement(value) && value.isUnknown === false;
|
|
986
1038
|
}
|
|
987
|
-
function isDependencyElementDescription(value) {
|
|
988
|
-
return isBaseElement(value) && isObjectWithProperty(value, "source") && isString(value.source);
|
|
989
|
-
}
|
|
990
|
-
function isElementDescription(value) {
|
|
991
|
-
return isIgnoredElement(value) || isUnknownLocalElement(value) || isKnownLocalElement(value) || isDependencyElementDescription(value);
|
|
992
|
-
}
|
|
993
1039
|
function isLocalDependencyElement(value) {
|
|
994
|
-
return
|
|
1040
|
+
return isLocalElement(value) && value.isIgnored === false;
|
|
995
1041
|
}
|
|
996
1042
|
function isExternalDependencyElement(value) {
|
|
997
|
-
return
|
|
1043
|
+
return isBaseElement(value) && value.origin === ELEMENT_ORIGINS_MAP.EXTERNAL;
|
|
998
1044
|
}
|
|
999
1045
|
function isCoreDependencyElement(value) {
|
|
1000
|
-
return
|
|
1046
|
+
return isBaseElement(value) && value.origin === ELEMENT_ORIGINS_MAP.CORE;
|
|
1047
|
+
}
|
|
1048
|
+
function isElementDescription(value) {
|
|
1049
|
+
return isIgnoredElement(value) || isUnknownLocalElement(value) || isKnownLocalElement(value) || isExternalDependencyElement(value) || isCoreDependencyElement(value);
|
|
1001
1050
|
}
|
|
1002
1051
|
|
|
1003
1052
|
// src/Descriptor/DependenciesDescriptor.types.ts
|
|
@@ -1054,7 +1103,7 @@ function isDependencyRelationshipDescription(value) {
|
|
|
1054
1103
|
return isObjectWithProperty(value, "to") && (isNull(value.to) || isDependencyRelationship(value.to)) && isObjectWithProperty(value, "from") && (isNull(value.from) || isDependencyRelationship(value.from));
|
|
1055
1104
|
}
|
|
1056
1105
|
function isElementsDependencyInfo(value) {
|
|
1057
|
-
return isObjectWithProperty(value, "kind") && isDependencyKind(value.kind) && isObjectWithProperty(value, "relationship") && isDependencyRelationshipDescription(value.relationship) && isObjectWithProperty(value, "nodeKind") && (isNull(value.nodeKind) || isString(value.nodeKind));
|
|
1106
|
+
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));
|
|
1058
1107
|
}
|
|
1059
1108
|
function isDependencyDescription(value) {
|
|
1060
1109
|
return isObjectWithProperty(value, "to") && isElementDescription(value.to) && isObjectWithProperty(value, "from") && isElementDescription(value.from) && isObjectWithProperty(value, "dependency") && isElementsDependencyInfo(value.dependency);
|
|
@@ -1392,17 +1441,20 @@ var DependenciesDescriptor = class {
|
|
|
1392
1441
|
return this._dependenciesCache.get(cacheKey);
|
|
1393
1442
|
}
|
|
1394
1443
|
const fromElement = this._elementsDescriptor.describeElement(from);
|
|
1395
|
-
const toElement = this._elementsDescriptor.
|
|
1396
|
-
|
|
1397
|
-
to
|
|
1398
|
-
);
|
|
1444
|
+
const toElement = this._elementsDescriptor.describeElement(to, source);
|
|
1445
|
+
const { module: dependencyModule, ...toElementDescription } = toElement;
|
|
1399
1446
|
const result = {
|
|
1400
1447
|
from: fromElement,
|
|
1401
|
-
to:
|
|
1448
|
+
to: toElementDescription,
|
|
1402
1449
|
dependency: {
|
|
1450
|
+
source,
|
|
1451
|
+
module: dependencyModule || null,
|
|
1403
1452
|
kind,
|
|
1404
1453
|
nodeKind: nodeKind || null,
|
|
1405
|
-
relationship: this._dependencyRelationships(
|
|
1454
|
+
relationship: this._dependencyRelationships(
|
|
1455
|
+
fromElement,
|
|
1456
|
+
toElementDescription
|
|
1457
|
+
),
|
|
1406
1458
|
specifiers: specifiers || null
|
|
1407
1459
|
}
|
|
1408
1460
|
};
|
|
@@ -1417,8 +1469,6 @@ var UNKNOWN_ELEMENT = {
|
|
|
1417
1469
|
path: null,
|
|
1418
1470
|
elementPath: null,
|
|
1419
1471
|
internalPath: null,
|
|
1420
|
-
source: null,
|
|
1421
|
-
baseSource: null,
|
|
1422
1472
|
parents: null,
|
|
1423
1473
|
type: null,
|
|
1424
1474
|
category: null,
|
|
@@ -1520,8 +1570,8 @@ var ElementsDescriptor = class {
|
|
|
1520
1570
|
*/
|
|
1521
1571
|
_dependencySourceIsCoreModule(dependencySource, baseDependencySource) {
|
|
1522
1572
|
if (this._mod) {
|
|
1523
|
-
const
|
|
1524
|
-
return this._mod.builtinModules.includes(
|
|
1573
|
+
const moduleWithoutPrefix = baseDependencySource.startsWith("node:") ? baseDependencySource.slice(5) : baseDependencySource;
|
|
1574
|
+
return this._mod.builtinModules.includes(moduleWithoutPrefix);
|
|
1525
1575
|
}
|
|
1526
1576
|
return isCoreModule(dependencySource);
|
|
1527
1577
|
}
|
|
@@ -1546,7 +1596,7 @@ var ElementsDescriptor = class {
|
|
|
1546
1596
|
* @param dependencySource The source of the dependency to check.
|
|
1547
1597
|
* @returns The base source of the external module. (e.g., for "@scope/package/submodule", it returns "@scope/package")
|
|
1548
1598
|
*/
|
|
1549
|
-
|
|
1599
|
+
_getExternalOrCoreModuleModule(dependencySource) {
|
|
1550
1600
|
if (this._dependencySourceIsScoped(dependencySource)) {
|
|
1551
1601
|
const [scope, packageName] = dependencySource.split("/");
|
|
1552
1602
|
return `${scope}/${packageName}`;
|
|
@@ -1857,7 +1907,7 @@ var ElementsDescriptor = class {
|
|
|
1857
1907
|
* @returns The external or core dependency element, or null if it is a local dependency.
|
|
1858
1908
|
*/
|
|
1859
1909
|
_getExternalOrCoreDependencyElement(dependencySource, isOutsideRootPath, filePath) {
|
|
1860
|
-
const baseDependencySource = this.
|
|
1910
|
+
const baseDependencySource = this._getExternalOrCoreModuleModule(dependencySource);
|
|
1861
1911
|
const isCore = this._dependencySourceIsCoreModule(
|
|
1862
1912
|
dependencySource,
|
|
1863
1913
|
baseDependencySource
|
|
@@ -1865,8 +1915,7 @@ var ElementsDescriptor = class {
|
|
|
1865
1915
|
if (isCore) {
|
|
1866
1916
|
const coreElement = {
|
|
1867
1917
|
...UNKNOWN_ELEMENT,
|
|
1868
|
-
|
|
1869
|
-
baseSource: baseDependencySource,
|
|
1918
|
+
module: baseDependencySource,
|
|
1870
1919
|
origin: ELEMENT_ORIGINS_MAP.CORE
|
|
1871
1920
|
};
|
|
1872
1921
|
return coreElement;
|
|
@@ -1880,9 +1929,8 @@ var ElementsDescriptor = class {
|
|
|
1880
1929
|
const externalElement = {
|
|
1881
1930
|
...UNKNOWN_ELEMENT,
|
|
1882
1931
|
path: filePath || null,
|
|
1883
|
-
internalPath: dependencySource.replace(baseDependencySource, ""),
|
|
1884
|
-
|
|
1885
|
-
baseSource: baseDependencySource,
|
|
1932
|
+
internalPath: dependencySource.replace(baseDependencySource, "") || null,
|
|
1933
|
+
module: baseDependencySource,
|
|
1886
1934
|
origin: ELEMENT_ORIGINS_MAP.EXTERNAL
|
|
1887
1935
|
};
|
|
1888
1936
|
return externalElement;
|
|
@@ -1907,28 +1955,10 @@ var ElementsDescriptor = class {
|
|
|
1907
1955
|
return externalOrCoreDependencyElement;
|
|
1908
1956
|
}
|
|
1909
1957
|
const fileDescription = this._describeFile(relativePath);
|
|
1910
|
-
|
|
1911
|
-
|
|
1912
|
-
source: dependencySource
|
|
1913
|
-
} : fileDescription;
|
|
1914
|
-
this._descriptionsCache.set(cacheKey, elementResult);
|
|
1915
|
-
return elementResult;
|
|
1958
|
+
this._descriptionsCache.set(cacheKey, fileDescription);
|
|
1959
|
+
return fileDescription;
|
|
1916
1960
|
}
|
|
1917
|
-
|
|
1918
|
-
* Describes an element given its file path.
|
|
1919
|
-
* @param filePath The path of the file to describe. Can be absolute if rootPath is configured, or relative if not.
|
|
1920
|
-
* @returns The description of the element.
|
|
1921
|
-
*/
|
|
1922
|
-
describeElement(filePath) {
|
|
1923
|
-
return this._describeElement(filePath);
|
|
1924
|
-
}
|
|
1925
|
-
/**
|
|
1926
|
-
* Describes a dependency element given its dependency source and file path.
|
|
1927
|
-
* @param dependencySource The source of the dependency.
|
|
1928
|
-
* @param filePath The path of the file being the dependency, if known. Can be absolute if rootPath is configured, or relative if not.
|
|
1929
|
-
* @returns The description of the dependency element.
|
|
1930
|
-
*/
|
|
1931
|
-
describeDependencyElement(dependencySource, filePath) {
|
|
1961
|
+
describeElement(filePath, dependencySource) {
|
|
1932
1962
|
return this._describeElement(filePath, dependencySource);
|
|
1933
1963
|
}
|
|
1934
1964
|
};
|
|
@@ -1988,18 +2018,6 @@ var Descriptors = class {
|
|
|
1988
2018
|
describeElement(filePath) {
|
|
1989
2019
|
return this._elementsDescriptor.describeElement(filePath);
|
|
1990
2020
|
}
|
|
1991
|
-
/**
|
|
1992
|
-
* Describes a dependency element given its dependency source and file path.
|
|
1993
|
-
* @param dependencySource The source of the dependency.
|
|
1994
|
-
* @param filePath The path of the file being the dependency, if known.
|
|
1995
|
-
* @returns The description of the dependency element.
|
|
1996
|
-
*/
|
|
1997
|
-
describeDependencyElement(dependencySource, filePath) {
|
|
1998
|
-
return this._elementsDescriptor.describeDependencyElement(
|
|
1999
|
-
dependencySource,
|
|
2000
|
-
filePath
|
|
2001
|
-
);
|
|
2002
|
-
}
|
|
2003
2021
|
/**
|
|
2004
2022
|
* Describes elements in a dependency relationship, and provides additional information about the dependency itself.
|
|
2005
2023
|
* @param options The options for describing the elements and the dependency details.
|
|
@@ -2028,6 +2046,22 @@ var Matcher = class {
|
|
|
2028
2046
|
this._elementsMatcher = elementsMatcher;
|
|
2029
2047
|
this._dependenciesMatcher = dependenciesMatcher;
|
|
2030
2048
|
}
|
|
2049
|
+
/**
|
|
2050
|
+
* Describes an element given its file path.
|
|
2051
|
+
* @param filePath The path of the file to describe.
|
|
2052
|
+
* @returns The description of the element.
|
|
2053
|
+
*/
|
|
2054
|
+
describeElement(filePath) {
|
|
2055
|
+
return this._descriptors.describeElement(filePath);
|
|
2056
|
+
}
|
|
2057
|
+
/**
|
|
2058
|
+
* Describes elements in a dependency relationship, and provides additional information about the dependency itself.
|
|
2059
|
+
* @param options The options for describing the elements and the dependency details.
|
|
2060
|
+
* @returns The description of the dependency between the elements.
|
|
2061
|
+
*/
|
|
2062
|
+
describeDependency(options) {
|
|
2063
|
+
return this._descriptors.describeDependency(options);
|
|
2064
|
+
}
|
|
2031
2065
|
/**
|
|
2032
2066
|
* Determines if an element matches a given selector.
|
|
2033
2067
|
* @param filePath The file path of the element
|
|
@@ -2035,7 +2069,7 @@ var Matcher = class {
|
|
|
2035
2069
|
* @param options Extra matcher options
|
|
2036
2070
|
* @returns True if the element matches the selector, false otherwise
|
|
2037
2071
|
*/
|
|
2038
|
-
|
|
2072
|
+
isElementMatch(filePath, selector, options) {
|
|
2039
2073
|
const description = this._descriptors.describeElement(filePath);
|
|
2040
2074
|
return this._elementsMatcher.isElementMatch(description, selector, options);
|
|
2041
2075
|
}
|
|
@@ -2046,7 +2080,7 @@ var Matcher = class {
|
|
|
2046
2080
|
* @param options Extra matcher options
|
|
2047
2081
|
* @returns True if the dependency matches the selector, false otherwise
|
|
2048
2082
|
*/
|
|
2049
|
-
|
|
2083
|
+
isDependencyMatch(dependencyData, selector, options) {
|
|
2050
2084
|
const description = this._descriptors.describeDependency(dependencyData);
|
|
2051
2085
|
return this._dependenciesMatcher.isDependencyMatch(
|
|
2052
2086
|
description,
|
|
@@ -2054,20 +2088,6 @@ var Matcher = class {
|
|
|
2054
2088
|
options
|
|
2055
2089
|
);
|
|
2056
2090
|
}
|
|
2057
|
-
isMatch(descriptorOptions, selector, options) {
|
|
2058
|
-
if (isString(descriptorOptions)) {
|
|
2059
|
-
return this._isElementMatch(
|
|
2060
|
-
descriptorOptions,
|
|
2061
|
-
selector,
|
|
2062
|
-
options
|
|
2063
|
-
);
|
|
2064
|
-
}
|
|
2065
|
-
return this._isDependencyMatch(
|
|
2066
|
-
descriptorOptions,
|
|
2067
|
-
selector,
|
|
2068
|
-
options
|
|
2069
|
-
);
|
|
2070
|
-
}
|
|
2071
2091
|
/**
|
|
2072
2092
|
* Determines the selector matching for an element.
|
|
2073
2093
|
* @param filePath The file path of the element
|
|
@@ -2075,7 +2095,7 @@ var Matcher = class {
|
|
|
2075
2095
|
* @param options Extra options for matching
|
|
2076
2096
|
* @returns The matching selector data or null if no match is found
|
|
2077
2097
|
*/
|
|
2078
|
-
|
|
2098
|
+
getElementSelectorMatching(filePath, selector, options) {
|
|
2079
2099
|
const description = this._descriptors.describeElement(filePath);
|
|
2080
2100
|
return this._elementsMatcher.getSelectorMatching(
|
|
2081
2101
|
description,
|
|
@@ -2090,7 +2110,7 @@ var Matcher = class {
|
|
|
2090
2110
|
* @param options Extra options for matching
|
|
2091
2111
|
* @returns The matching dependency result or null if no match is found
|
|
2092
2112
|
*/
|
|
2093
|
-
|
|
2113
|
+
getDependencySelectorMatching(dependencyData, selector, options) {
|
|
2094
2114
|
const description = this._descriptors.describeDependency(dependencyData);
|
|
2095
2115
|
return this._dependenciesMatcher.getSelectorsMatching(
|
|
2096
2116
|
description,
|
|
@@ -2098,66 +2118,44 @@ var Matcher = class {
|
|
|
2098
2118
|
options
|
|
2099
2119
|
);
|
|
2100
2120
|
}
|
|
2101
|
-
|
|
2102
|
-
|
|
2103
|
-
|
|
2104
|
-
|
|
2121
|
+
/**
|
|
2122
|
+
* Returns the selectors matching result for the given element or dependency description.
|
|
2123
|
+
* @param description The element or dependency description to check.
|
|
2124
|
+
* @param selector The selector to check against.
|
|
2125
|
+
* @param options Extra options for matching, such as templates data, etc.
|
|
2126
|
+
* @returns The selectors matching result for the given description, and whether it matches or not.
|
|
2127
|
+
*/
|
|
2128
|
+
getDependencySelectorMatchingDescription(description, selector, options) {
|
|
2129
|
+
if (isDependencySelector(selector) && isDependencyDescription(description)) {
|
|
2130
|
+
return this._dependenciesMatcher.getSelectorsMatching(
|
|
2131
|
+
description,
|
|
2105
2132
|
selector,
|
|
2106
2133
|
options
|
|
2107
2134
|
);
|
|
2108
2135
|
}
|
|
2109
|
-
|
|
2110
|
-
|
|
2111
|
-
selector,
|
|
2112
|
-
options
|
|
2136
|
+
throw new Error(
|
|
2137
|
+
"Invalid arguments: Please provide a valid description and selector"
|
|
2113
2138
|
);
|
|
2114
2139
|
}
|
|
2115
|
-
|
|
2140
|
+
/**
|
|
2141
|
+
* Returns the first element selector matching result for the given element description.
|
|
2142
|
+
* @param description The element description to check.
|
|
2143
|
+
* @param selector The selector to check against.
|
|
2144
|
+
* @param options Extra options for matching, such as templates data, etc.
|
|
2145
|
+
* @returns The first matching selector result for the given description, or null if no match is found.
|
|
2146
|
+
*/
|
|
2147
|
+
getElementSelectorMatchingDescription(description, selector, options) {
|
|
2116
2148
|
if (isElementsSelector(selector) && isElementDescription(description)) {
|
|
2117
2149
|
return this._elementsMatcher.getSelectorMatching(
|
|
2118
2150
|
description,
|
|
2119
2151
|
selector,
|
|
2120
2152
|
options
|
|
2121
2153
|
);
|
|
2122
|
-
} else if (isDependencySelector(selector) && isDependencyDescription(description)) {
|
|
2123
|
-
return this._dependenciesMatcher.getSelectorsMatching(
|
|
2124
|
-
description,
|
|
2125
|
-
selector,
|
|
2126
|
-
options
|
|
2127
|
-
);
|
|
2128
2154
|
}
|
|
2129
2155
|
throw new Error(
|
|
2130
2156
|
"Invalid arguments: Please provide a valid description and selector"
|
|
2131
2157
|
);
|
|
2132
2158
|
}
|
|
2133
|
-
/**
|
|
2134
|
-
* Describes an element given its file path.
|
|
2135
|
-
* @param filePath The path of the file to describe.
|
|
2136
|
-
* @returns The description of the element.
|
|
2137
|
-
*/
|
|
2138
|
-
describeElement(filePath) {
|
|
2139
|
-
return this._descriptors.describeElement(filePath);
|
|
2140
|
-
}
|
|
2141
|
-
/**
|
|
2142
|
-
* Describes a dependency element given its dependency source and file path.
|
|
2143
|
-
* @param dependencySource The source of the dependency.
|
|
2144
|
-
* @param filePath The path of the file being the dependency, if known.
|
|
2145
|
-
* @returns The description of the dependency element.
|
|
2146
|
-
*/
|
|
2147
|
-
describeDependencyElement(dependencySource, filePath) {
|
|
2148
|
-
return this._descriptors.describeDependencyElement(
|
|
2149
|
-
dependencySource,
|
|
2150
|
-
filePath
|
|
2151
|
-
);
|
|
2152
|
-
}
|
|
2153
|
-
/**
|
|
2154
|
-
* Describes elements in a dependency relationship, and provides additional information about the dependency itself.
|
|
2155
|
-
* @param options The options for describing the elements and the dependency details.
|
|
2156
|
-
* @returns The description of the dependency between the elements.
|
|
2157
|
-
*/
|
|
2158
|
-
describeDependency(options) {
|
|
2159
|
-
return this._descriptors.describeDependency(options);
|
|
2160
|
-
}
|
|
2161
2159
|
/**
|
|
2162
2160
|
* Clears all caches.
|
|
2163
2161
|
*/
|
|
@@ -2453,8 +2451,9 @@ export {
|
|
|
2453
2451
|
isBaseElementSelectorData,
|
|
2454
2452
|
isCapturedValuesSelector,
|
|
2455
2453
|
isCoreDependencyElement,
|
|
2454
|
+
isDependencyDataSelector,
|
|
2455
|
+
isDependencyDataSelectorData,
|
|
2456
2456
|
isDependencyDescription,
|
|
2457
|
-
isDependencyElementDescription,
|
|
2458
2457
|
isDependencyKind,
|
|
2459
2458
|
isDependencyRelationship,
|
|
2460
2459
|
isDependencyRelationshipDescription,
|
|
@@ -2471,12 +2470,6 @@ export {
|
|
|
2471
2470
|
isElementsDependencyInfo,
|
|
2472
2471
|
isElementsSelector,
|
|
2473
2472
|
isExternalDependencyElement,
|
|
2474
|
-
isExternalLibrariesSelector,
|
|
2475
|
-
isExternalLibrarySelector,
|
|
2476
|
-
isExternalLibrarySelectorOptions,
|
|
2477
|
-
isExternalLibrarySelectorOptionsWithPath,
|
|
2478
|
-
isExternalLibrarySelectorOptionsWithSpecifiers,
|
|
2479
|
-
isExternalLibrarySelectorWithOptions,
|
|
2480
2473
|
isIgnoredElement,
|
|
2481
2474
|
isInternalDependency,
|
|
2482
2475
|
isKnownLocalElement,
|
|
@@ -2484,6 +2477,7 @@ export {
|
|
|
2484
2477
|
isLocalElement,
|
|
2485
2478
|
isSimpleElementSelectorByType,
|
|
2486
2479
|
isUnknownLocalElement,
|
|
2480
|
+
normalizeElementSelector,
|
|
2487
2481
|
normalizeElementsSelector
|
|
2488
2482
|
};
|
|
2489
2483
|
//# sourceMappingURL=index.mjs.map
|