@emulsify/core 4.2.0 → 4.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (79) hide show
  1. package/.storybook/main-vite.js +91 -36
  2. package/README.md +185 -56
  3. package/config/a11y.config.js +2 -1
  4. package/config/vite/entries.js +4 -4
  5. package/config/vite/plugins/{copy-src-assets.js → assets/copy-src-assets.js} +1 -1
  6. package/config/vite/plugins/{copy-twig-files.js → assets/copy-twig-files.js} +1 -1
  7. package/config/vite/plugins/{css-asset-relativizer.js → assets/css-asset-relativizer.js} +9 -0
  8. package/config/vite/plugins/{mirror-components.js → assets/mirror-components.js} +2 -28
  9. package/config/vite/plugins/{source-file-index.js → assets/source-file-index.js} +1 -1
  10. package/config/vite/plugins/{svg-sprite.js → assets/svg-sprite.js} +2 -2
  11. package/config/vite/plugins/index.js +23 -14
  12. package/config/vite/plugins/reporter/asset-resolver.js +541 -0
  13. package/config/vite/plugins/reporter/build-errors.js +284 -0
  14. package/config/vite/plugins/reporter/diagnostics.js +366 -0
  15. package/config/vite/plugins/reporter/format.js +199 -0
  16. package/config/vite/plugins/reporter/index.js +308 -0
  17. package/config/vite/plugins/reporter/render.js +758 -0
  18. package/config/vite/plugins/reporter/sass-logger.js +237 -0
  19. package/config/vite/plugins/reporter/vite-logger.js +188 -0
  20. package/config/vite/plugins/reporter/watch-mode.js +40 -0
  21. package/config/vite/plugins/{twig-extension-installers.js → twig/extension-installers.js} +1 -1
  22. package/config/vite/{twig-extensions.js → plugins/twig/extensions.js} +2 -2
  23. package/config/vite/plugins/{twig-module.js → twig/twig-module.js} +387 -115
  24. package/config/vite/plugins/{virtual-twig-asset-sources.js → twig/virtual-twig-asset-sources.js} +37 -136
  25. package/config/vite/plugins/{virtual-twig-globs.js → twig/virtual-twig-globs.js} +3 -32
  26. package/config/vite/plugins/{vituum-patch.js → twig/vituum-patch.js} +3 -3
  27. package/config/vite/plugins.js +1 -1
  28. package/config/vite/project-config.js +1 -1
  29. package/config/vite/project-structure.js +1 -1
  30. package/config/vite/utils/lru.js +77 -0
  31. package/config/vite/utils/package-version.js +42 -0
  32. package/config/vite/utils/paths.js +1 -9
  33. package/config/vite/utils/react-singleton.js +1 -1
  34. package/config/vite/vite.config.js +51 -5
  35. package/package.json +93 -58
  36. package/scripts/a11y.js +115 -23
  37. package/scripts/audit/checks/core-imports.js +78 -0
  38. package/scripts/audit/checks/css-asset-references.js +99 -0
  39. package/scripts/audit/checks/drupal-assumptions.js +48 -0
  40. package/scripts/audit/checks/files-outside-roots.js +53 -0
  41. package/scripts/audit/checks/generated-package-scripts.js +113 -0
  42. package/scripts/audit/checks/legacy-twig-stories.js +33 -0
  43. package/scripts/audit/checks/package-overrides.js +91 -0
  44. package/scripts/audit/checks/project-config.js +71 -0
  45. package/scripts/audit/checks/story-discovery.js +35 -0
  46. package/scripts/audit/checks/twig-references.js +69 -0
  47. package/scripts/audit/checks/twig-volume.js +54 -0
  48. package/scripts/audit/checks/webpack-patterns.js +86 -0
  49. package/scripts/audit/index.js +177 -0
  50. package/scripts/audit/lib/css.js +165 -0
  51. package/scripts/audit/lib/files.js +168 -0
  52. package/scripts/audit/lib/findings.js +31 -0
  53. package/scripts/audit/lib/package-json.js +65 -0
  54. package/scripts/audit/lib/twig.js +227 -0
  55. package/scripts/audit/report.js +273 -0
  56. package/scripts/audit-twig-stories.js +115 -78
  57. package/scripts/audit.js +150 -1632
  58. package/scripts/check-node-version.js +136 -10
  59. package/scripts/inspect-components.js +456 -0
  60. package/scripts/lib/cli.js +179 -0
  61. package/scripts/lib/fs.js +31 -0
  62. package/scripts/lib/proc.js +78 -0
  63. package/scripts/lib/text.js +14 -0
  64. package/scripts/loadYaml.js +2 -2
  65. package/src/extensions/shared/attributes.js +3 -3
  66. package/src/extensions/shared/lists.js +2 -6
  67. package/src/extensions/shared/root-relative.js +38 -0
  68. package/src/storybook/index.js +4 -0
  69. package/src/storybook/render-twig.js +1 -1
  70. package/src/storybook/render-web-component.js +459 -0
  71. package/src/storybook/twig/asset-source-runtime.js +193 -0
  72. package/src/storybook/twig/{source-extensions.js → constants.js} +3 -1
  73. package/src/storybook/twig/reference-paths.js +2 -13
  74. package/src/storybook/twig/resolver.js +20 -3
  75. package/src/storybook/twig/setup.js +12 -2
  76. package/src/storybook/twig/source-function.js +5 -2
  77. package/config/vite/utils/unique.js +0 -36
  78. package/src/storybook/twig/include.js +0 -28
  79. package/src/storybook/twig/source-events.js +0 -5
@@ -91,9 +91,26 @@ function findGroupedComponentEntry(map, candidates, env) {
91
91
 
92
92
  for (const { rootRel, suffix } of groupedComponentSuffixes(candidates, env)) {
93
93
  const rootPrefix = `${rootRel}/`;
94
- const match = entries.find(
95
- ([key]) => key.startsWith(rootPrefix) && key.endsWith(suffix),
96
- );
94
+ const matches = entries
95
+ .filter(([key]) => key.startsWith(rootPrefix) && key.endsWith(suffix))
96
+ .sort(([leftKey], [rightKey]) => {
97
+ const leftGroupingPath = leftKey.slice(
98
+ rootPrefix.length,
99
+ -suffix.length,
100
+ );
101
+ const rightGroupingPath = rightKey.slice(
102
+ rootPrefix.length,
103
+ -suffix.length,
104
+ );
105
+ const leftDepth = leftGroupingPath.split('/').filter(Boolean).length;
106
+ const rightDepth = rightGroupingPath.split('/').filter(Boolean).length;
107
+
108
+ if (leftDepth !== rightDepth) {
109
+ return leftDepth - rightDepth;
110
+ }
111
+ return leftKey === rightKey ? 0 : leftKey < rightKey ? -1 : 1;
112
+ });
113
+ const match = matches[0];
97
114
  if (match) {
98
115
  return { key: match[0], value: match[1] };
99
116
  }
@@ -3,7 +3,8 @@
3
3
  */
4
4
 
5
5
  import { registerTwigExtensions } from '../../extensions/twig/index.js';
6
- import twigInclude from './include.js';
6
+ import { createTwigIncludeFunction } from './include-function.js';
7
+ import resolveTemplate from './resolver.js';
7
8
  import twigSource from './source.js';
8
9
 
9
10
  /**
@@ -35,5 +36,14 @@ export function setupTwig(twig, options = {}) {
35
36
  return twig;
36
37
  }
37
38
 
38
- export { default as twigInclude } from './include.js';
39
+ /**
40
+ * Twig `include()` runtime helper.
41
+ *
42
+ * @param {Object} Twig - Twig.js module.
43
+ * @returns {undefined}
44
+ */
45
+ export function twigInclude(Twig) {
46
+ Twig.extendFunction('include', createTwigIncludeFunction(resolveTemplate));
47
+ }
48
+
39
49
  export { default as twigSource } from './source.js';
@@ -8,8 +8,11 @@ import {
8
8
  isAssetTextLoading,
9
9
  whenAssetTextLoaded,
10
10
  } from 'virtual:emulsify-twig-asset-sources';
11
- import { IMAGE_ASSET_EXTS, INLINE_ASSET_EXTS } from './source-extensions.js';
12
- import { TWIG_SOURCE_LOADED_EVENT } from './source-events.js';
11
+ import {
12
+ IMAGE_ASSET_EXTS,
13
+ INLINE_ASSET_EXTS,
14
+ TWIG_SOURCE_LOADED_EVENT,
15
+ } from './constants.js';
13
16
 
14
17
  const DEFAULT_ENV =
15
18
  (typeof __EMULSIFY_ENV__ !== 'undefined' && __EMULSIFY_ENV__) || {};
@@ -1,36 +0,0 @@
1
- /**
2
- * @file Shared array de-duplication helpers.
3
- */
4
-
5
- /**
6
- * Return values in first-seen order with duplicates removed.
7
- *
8
- * @template T
9
- * @param {T[]} values - Values to deduplicate.
10
- * @returns {T[]} Unique values.
11
- */
12
- export function unique(values = []) {
13
- return Array.from(new Set(values));
14
- }
15
-
16
- /**
17
- * Return values in first-seen order with duplicates removed by key.
18
- *
19
- * @template T
20
- * @param {T[]} values - Values to deduplicate.
21
- * @param {(value: T) => *} keyFn - Function that returns a comparable key.
22
- * @returns {T[]} Unique values.
23
- */
24
- export function uniqueBy(values = [], keyFn) {
25
- const seen = new Set();
26
- const result = [];
27
-
28
- for (const value of values) {
29
- const key = keyFn(value);
30
- if (seen.has(key)) continue;
31
- seen.add(key);
32
- result.push(value);
33
- }
34
-
35
- return result;
36
- }
@@ -1,28 +0,0 @@
1
- /**
2
- * @file Twig include() runtime helper for Storybook-rendered templates.
3
- */
4
-
5
- import { createTwigIncludeFunction as createIncludeFunction } from './include-function.js';
6
- import resolveTemplate from './resolver.js';
7
-
8
- /**
9
- * Create a Twig.js `include()` function with the Storybook template resolver.
10
- *
11
- * @param {Function} resolver - Template resolver.
12
- * @returns {Function} Twig.js function implementation.
13
- */
14
- export function createTwigIncludeFunction(resolver = resolveTemplate) {
15
- return createIncludeFunction(resolver);
16
- }
17
-
18
- /**
19
- * Twig `include()` runtime helper.
20
- *
21
- * @param {Object} Twig - Twig.js module.
22
- * @returns {undefined}
23
- */
24
- function twigInclude(Twig) {
25
- Twig.extendFunction('include', createIncludeFunction(resolveTemplate));
26
- }
27
-
28
- export default twigInclude;
@@ -1,5 +0,0 @@
1
- /**
2
- * @file Shared events for lazy Twig source loading.
3
- */
4
-
5
- export const TWIG_SOURCE_LOADED_EVENT = 'emulsify:twig-source-loaded';