@jsenv/test 3.6.6 → 3.6.7

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.
@@ -2491,9 +2491,19 @@ const applyPatternMatching = ({ url, pattern }) => {
2491
2491
  return applyPattern({ url, pattern });
2492
2492
  };
2493
2493
 
2494
- const resolveAssociations = (associations, baseUrl) => {
2495
- if (baseUrl && typeof baseUrl.href === "string") baseUrl = baseUrl.href;
2496
- assertUrlLike(baseUrl, "baseUrl");
2494
+ const resolveAssociations = (associations, resolver) => {
2495
+ let resolve = () => {};
2496
+ if (typeof resolver === "function") {
2497
+ resolve = resolver;
2498
+ } else if (typeof resolver === "string") {
2499
+ const baseUrl = resolver;
2500
+ assertUrlLike(baseUrl, "baseUrl");
2501
+ resolve = (pattern) => new URL(pattern, baseUrl).href;
2502
+ } else if (resolver && typeof resolver.href === "string") {
2503
+ const baseUrl = resolver.href;
2504
+ assertUrlLike(baseUrl, "baseUrl");
2505
+ resolve = (pattern) => new URL(pattern, baseUrl).href;
2506
+ }
2497
2507
 
2498
2508
  const associationsResolved = {};
2499
2509
  for (const key of Object.keys(associations)) {
@@ -2504,12 +2514,11 @@ const resolveAssociations = (associations, baseUrl) => {
2504
2514
  const valueAssociated = value[pattern];
2505
2515
  let patternResolved;
2506
2516
  try {
2507
- patternResolved = String(new URL(pattern, baseUrl));
2517
+ patternResolved = resolve(pattern);
2508
2518
  } catch {
2509
2519
  // it's not really an url, no need to perform url resolution nor encoding
2510
2520
  patternResolved = pattern;
2511
2521
  }
2512
-
2513
2522
  valueMapResolved[patternResolved] = valueAssociated;
2514
2523
  }
2515
2524
  associationsResolved[key] = valueMapResolved;
@@ -2632,34 +2641,29 @@ const urlChildMayMatch = ({ url, associations, predicate }) => {
2632
2641
  };
2633
2642
 
2634
2643
  const applyAliases = ({ url, aliases }) => {
2635
- let aliasFullMatchResult;
2636
- const aliasMatchingKey = Object.keys(aliases).find((key) => {
2637
- const aliasMatchResult = applyPatternMatching({
2644
+ for (const key of Object.keys(aliases)) {
2645
+ const matchResult = applyPatternMatching({
2638
2646
  pattern: key,
2639
2647
  url,
2640
2648
  });
2641
- if (aliasMatchResult.matched) {
2642
- aliasFullMatchResult = aliasMatchResult;
2643
- return true;
2649
+ if (!matchResult.matched) {
2650
+ continue;
2644
2651
  }
2645
- return false;
2646
- });
2647
- if (!aliasMatchingKey) {
2648
- return url;
2649
- }
2650
- const { matchGroups } = aliasFullMatchResult;
2651
- const alias = aliases[aliasMatchingKey];
2652
- const parts = alias.split("*");
2653
- let newUrl = "";
2654
- let index = 0;
2655
- for (const part of parts) {
2656
- newUrl += `${part}`;
2657
- if (index < parts.length - 1) {
2658
- newUrl += matchGroups[index];
2652
+ const { matchGroups } = matchResult;
2653
+ const alias = aliases[key];
2654
+ const parts = alias.split("*");
2655
+ let newUrl = "";
2656
+ let index = 0;
2657
+ for (const part of parts) {
2658
+ newUrl += `${part}`;
2659
+ if (index < parts.length - 1) {
2660
+ newUrl += matchGroups[index];
2661
+ }
2662
+ index++;
2659
2663
  }
2660
- index++;
2664
+ return newUrl;
2661
2665
  }
2662
- return newUrl;
2666
+ return url;
2663
2667
  };
2664
2668
 
2665
2669
  const matches = (url, patterns) => {
@@ -336,9 +336,19 @@ const applyPatternMatching = ({ url, pattern }) => {
336
336
  return applyPattern({ url, pattern });
337
337
  };
338
338
 
339
- const resolveAssociations = (associations, baseUrl) => {
340
- if (baseUrl && typeof baseUrl.href === "string") baseUrl = baseUrl.href;
341
- assertUrlLike(baseUrl, "baseUrl");
339
+ const resolveAssociations = (associations, resolver) => {
340
+ let resolve = () => {};
341
+ if (typeof resolver === "function") {
342
+ resolve = resolver;
343
+ } else if (typeof resolver === "string") {
344
+ const baseUrl = resolver;
345
+ assertUrlLike(baseUrl, "baseUrl");
346
+ resolve = (pattern) => new URL(pattern, baseUrl).href;
347
+ } else if (resolver && typeof resolver.href === "string") {
348
+ const baseUrl = resolver.href;
349
+ assertUrlLike(baseUrl, "baseUrl");
350
+ resolve = (pattern) => new URL(pattern, baseUrl).href;
351
+ }
342
352
 
343
353
  const associationsResolved = {};
344
354
  for (const key of Object.keys(associations)) {
@@ -349,12 +359,11 @@ const resolveAssociations = (associations, baseUrl) => {
349
359
  const valueAssociated = value[pattern];
350
360
  let patternResolved;
351
361
  try {
352
- patternResolved = String(new URL(pattern, baseUrl));
362
+ patternResolved = resolve(pattern);
353
363
  } catch {
354
364
  // it's not really an url, no need to perform url resolution nor encoding
355
365
  patternResolved = pattern;
356
366
  }
357
-
358
367
  valueMapResolved[patternResolved] = valueAssociated;
359
368
  }
360
369
  associationsResolved[key] = valueMapResolved;
@@ -477,34 +486,29 @@ const urlChildMayMatch = ({ url, associations, predicate }) => {
477
486
  };
478
487
 
479
488
  const applyAliases = ({ url, aliases }) => {
480
- let aliasFullMatchResult;
481
- const aliasMatchingKey = Object.keys(aliases).find((key) => {
482
- const aliasMatchResult = applyPatternMatching({
489
+ for (const key of Object.keys(aliases)) {
490
+ const matchResult = applyPatternMatching({
483
491
  pattern: key,
484
492
  url,
485
493
  });
486
- if (aliasMatchResult.matched) {
487
- aliasFullMatchResult = aliasMatchResult;
488
- return true;
494
+ if (!matchResult.matched) {
495
+ continue;
489
496
  }
490
- return false;
491
- });
492
- if (!aliasMatchingKey) {
493
- return url;
494
- }
495
- const { matchGroups } = aliasFullMatchResult;
496
- const alias = aliases[aliasMatchingKey];
497
- const parts = alias.split("*");
498
- let newUrl = "";
499
- let index = 0;
500
- for (const part of parts) {
501
- newUrl += `${part}`;
502
- if (index < parts.length - 1) {
503
- newUrl += matchGroups[index];
497
+ const { matchGroups } = matchResult;
498
+ const alias = aliases[key];
499
+ const parts = alias.split("*");
500
+ let newUrl = "";
501
+ let index = 0;
502
+ for (const part of parts) {
503
+ newUrl += `${part}`;
504
+ if (index < parts.length - 1) {
505
+ newUrl += matchGroups[index];
506
+ }
507
+ index++;
504
508
  }
505
- index++;
509
+ return newUrl;
506
510
  }
507
- return newUrl;
511
+ return url;
508
512
  };
509
513
 
510
514
  const matches = (url, patterns) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jsenv/test",
3
- "version": "3.6.6",
3
+ "version": "3.6.7",
4
4
  "license": "MIT",
5
5
  "repository": {
6
6
  "type": "git",
@@ -42,14 +42,14 @@
42
42
  "@c88/v8-coverage": "0.1.1",
43
43
  "@jsenv/abort": "4.3.1",
44
44
  "@jsenv/ast": "6.6.6",
45
- "@jsenv/exception": "1.1.6",
46
- "@jsenv/filesystem": "4.14.4",
47
- "@jsenv/github-check-run": "0.2.19",
45
+ "@jsenv/exception": "1.1.7",
46
+ "@jsenv/filesystem": "4.14.5",
47
+ "@jsenv/github-check-run": "0.2.20",
48
48
  "@jsenv/node-esm-resolution": "1.1.0",
49
49
  "@jsenv/humanize": "1.3.1",
50
50
  "@jsenv/plugin-supervisor": "1.6.11",
51
51
  "@jsenv/sourcemap": "1.3.3",
52
- "@jsenv/url-meta": "8.5.5",
52
+ "@jsenv/url-meta": "8.5.6",
53
53
  "@jsenv/urls": "2.7.0",
54
54
  "@jsenv/utils": "2.2.1",
55
55
  "he": "1.2.0",