@md-code/component-uniqueness 0.1.3 → 0.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 (188) hide show
  1. package/CHANGELOG.md +17 -0
  2. package/LICENSE +202 -0
  3. package/README.md +21 -3
  4. package/dist/config.d.ts +50 -0
  5. package/dist/config.js +402 -0
  6. package/dist/constants.d.ts +55 -0
  7. package/dist/constants.js +86 -0
  8. package/dist/decision-maker.d.ts +39 -0
  9. package/dist/decision-maker.js +119 -0
  10. package/dist/filter/child-element.d.ts +3 -0
  11. package/dist/filter/child-element.js +17 -0
  12. package/dist/filter/missing-component.d.ts +10 -0
  13. package/dist/filter/missing-component.js +96 -0
  14. package/dist/filter/no-structure.d.ts +3 -0
  15. package/dist/filter/no-structure.js +16 -0
  16. package/dist/filter/usages.d.ts +3 -0
  17. package/dist/filter/usages.js +14 -0
  18. package/dist/index.d.ts +105 -0
  19. package/dist/index.js +244 -0
  20. package/dist/lib-registry.d.ts +4 -0
  21. package/dist/lib-registry.js +376 -0
  22. package/dist/logger.d.ts +7 -0
  23. package/dist/logger.js +70 -0
  24. package/dist/main.d.ts +25 -0
  25. package/dist/main.js +666 -0
  26. package/dist/matcher/a11y.d.ts +19 -0
  27. package/dist/matcher/a11y.js +311 -0
  28. package/dist/matcher/behavior.d.ts +10 -0
  29. package/dist/matcher/behavior.js +32 -0
  30. package/dist/matcher/css-matching.d.ts +18 -0
  31. package/dist/matcher/css-matching.js +159 -0
  32. package/dist/matcher/framework/index.d.ts +2 -0
  33. package/dist/matcher/framework/index.js +37 -0
  34. package/dist/matcher/framework/react.d.ts +12 -0
  35. package/dist/matcher/framework/react.js +70 -0
  36. package/dist/matcher/index.d.ts +64 -0
  37. package/dist/matcher/index.js +38 -0
  38. package/dist/matcher/name.d.ts +15 -0
  39. package/dist/matcher/name.js +154 -0
  40. package/dist/matcher/structure.d.ts +22 -0
  41. package/dist/matcher/structure.js +329 -0
  42. package/dist/matcher/styles.d.ts +20 -0
  43. package/dist/matcher/styles.js +49 -0
  44. package/dist/normalize/candidate.d.ts +3 -0
  45. package/dist/normalize/candidate.js +21 -0
  46. package/dist/normalize/dom.d.ts +22 -0
  47. package/dist/normalize/dom.js +180 -0
  48. package/dist/normalize/external-html.d.ts +5 -0
  49. package/dist/normalize/external-html.js +40 -0
  50. package/dist/normalize/framework.d.ts +20 -0
  51. package/dist/normalize/framework.js +130 -0
  52. package/dist/normalize/resolver.d.ts +7 -0
  53. package/dist/normalize/resolver.js +28 -0
  54. package/dist/normalize/style-resolver.d.ts +7 -0
  55. package/dist/normalize/style-resolver.js +28 -0
  56. package/dist/normalize/style.d.ts +15 -0
  57. package/dist/normalize/style.js +174 -0
  58. package/dist/normalize/words.d.ts +3 -0
  59. package/dist/normalize/words.js +40 -0
  60. package/dist/package.json +88 -0
  61. package/dist/playgrounds/angular.d.ts +7 -0
  62. package/dist/playgrounds/angular.js +9 -0
  63. package/dist/playgrounds/framework-entrypoint.d.ts +10 -0
  64. package/dist/playgrounds/framework-entrypoint.js +102 -0
  65. package/dist/playgrounds/framework.d.ts +10 -0
  66. package/dist/playgrounds/framework.js +102 -0
  67. package/dist/playgrounds/react.d.ts +14 -0
  68. package/dist/playgrounds/react.js +1288 -0
  69. package/dist/playgrounds/scss.d.ts +6 -0
  70. package/dist/playgrounds/scss.js +9 -0
  71. package/dist/playgrounds/style-entrypoint.d.ts +13 -0
  72. package/dist/playgrounds/style-entrypoint.js +82 -0
  73. package/dist/playgrounds/style.d.ts +13 -0
  74. package/dist/playgrounds/style.js +82 -0
  75. package/dist/playgrounds/styled-components.d.ts +7 -0
  76. package/dist/playgrounds/styled-components.js +190 -0
  77. package/dist/playgrounds/tailwind.d.ts +15 -0
  78. package/dist/playgrounds/tailwind.js +256 -0
  79. package/dist/playgrounds/vue.d.ts +7 -0
  80. package/dist/playgrounds/vue.js +9 -0
  81. package/dist/report/asks.d.ts +27 -0
  82. package/dist/report/asks.js +28 -0
  83. package/dist/report/cli-report.d.ts +7 -0
  84. package/dist/report/cli-report.js +187 -0
  85. package/dist/report/codes/index.d.ts +37 -0
  86. package/dist/report/codes/index.js +31 -0
  87. package/dist/report/errorTypes/index.d.ts +92 -0
  88. package/dist/report/errorTypes/index.js +186 -0
  89. package/dist/report/evidence.d.ts +2 -0
  90. package/dist/report/evidence.js +8 -0
  91. package/dist/report/explain.d.ts +27 -0
  92. package/dist/report/explain.js +76 -0
  93. package/dist/report/index.d.ts +2 -0
  94. package/dist/report/index.js +24 -0
  95. package/dist/report/matchers/a11y/model.d.ts +20 -0
  96. package/dist/report/matchers/a11y/model.js +14 -0
  97. package/dist/report/matchers/a11y/text.d.ts +2 -0
  98. package/dist/report/matchers/a11y/text.js +22 -0
  99. package/dist/report/matchers/behavior/model.d.ts +20 -0
  100. package/dist/report/matchers/behavior/model.js +12 -0
  101. package/dist/report/matchers/behavior/text.d.ts +2 -0
  102. package/dist/report/matchers/behavior/text.js +22 -0
  103. package/dist/report/matchers/framework/model.d.ts +10 -0
  104. package/dist/report/matchers/framework/model.js +39 -0
  105. package/dist/report/matchers/framework/text.d.ts +2 -0
  106. package/dist/report/matchers/framework/text.js +26 -0
  107. package/dist/report/matchers/index.d.ts +5 -0
  108. package/dist/report/matchers/index.js +97 -0
  109. package/dist/report/matchers/name/model.d.ts +20 -0
  110. package/dist/report/matchers/name/model.js +30 -0
  111. package/dist/report/matchers/name/text.d.ts +2 -0
  112. package/dist/report/matchers/name/text.js +17 -0
  113. package/dist/report/matchers/set-model.d.ts +31 -0
  114. package/dist/report/matchers/set-model.js +42 -0
  115. package/dist/report/matchers/structure/model.d.ts +10 -0
  116. package/dist/report/matchers/structure/model.js +58 -0
  117. package/dist/report/matchers/structure/text.d.ts +2 -0
  118. package/dist/report/matchers/structure/text.js +40 -0
  119. package/dist/report/matchers/styles/model.d.ts +11 -0
  120. package/dist/report/matchers/styles/model.js +36 -0
  121. package/dist/report/matchers/styles/text.d.ts +2 -0
  122. package/dist/report/matchers/styles/text.js +40 -0
  123. package/dist/report/user-report/build/bundle.d.ts +3 -0
  124. package/dist/report/user-report/build/bundle.js +185 -0
  125. package/dist/report/user-report/build/bundle.prebuilt.js +955 -0
  126. package/dist/report/user-report/data/collect.d.ts +68 -0
  127. package/dist/report/user-report/data/collect.js +150 -0
  128. package/dist/report/user-report/data/folders.d.ts +3 -0
  129. package/dist/report/user-report/data/folders.js +73 -0
  130. package/dist/report/user-report/data/groups.d.ts +13 -0
  131. package/dist/report/user-report/data/groups.js +76 -0
  132. package/dist/report/user-report/data/links.d.ts +39 -0
  133. package/dist/report/user-report/data/links.js +222 -0
  134. package/dist/report/user-report/data/snapshot.d.ts +9 -0
  135. package/dist/report/user-report/data/snapshot.js +180 -0
  136. package/dist/report/user-report/data/source.d.ts +13 -0
  137. package/dist/report/user-report/data/source.js +58 -0
  138. package/dist/report/user-report/data/word.d.ts +3 -0
  139. package/dist/report/user-report/data/word.js +32 -0
  140. package/dist/report/user-report/html/shell.d.ts +2 -0
  141. package/dist/report/user-report/html/shell.js +27 -0
  142. package/dist/report/user-report/index.d.ts +7 -0
  143. package/dist/report/user-report/index.js +47 -0
  144. package/dist/report/vocabulary/evidence.d.ts +48 -0
  145. package/dist/report/vocabulary/evidence.js +66 -0
  146. package/dist/report/vocabulary/format.d.ts +4 -0
  147. package/dist/report/vocabulary/format.js +20 -0
  148. package/dist/report/vocabulary/labels.d.ts +134 -0
  149. package/dist/report/vocabulary/labels.js +87 -0
  150. package/dist/report/vocabulary/phrases.d.ts +20 -0
  151. package/dist/report/vocabulary/phrases.js +34 -0
  152. package/dist/self-catalog.d.ts +4 -0
  153. package/dist/self-catalog.js +179 -0
  154. package/dist/utils.d.ts +6 -0
  155. package/dist/utils.js +125 -0
  156. package/package.json +86 -60
  157. package/config.js +0 -362
  158. package/decision-maker.js +0 -109
  159. package/filter/drop-child-element.js +0 -13
  160. package/filter/drop-usages.js +0 -13
  161. package/filter/missing-component.js +0 -68
  162. package/index.js +0 -184
  163. package/logger.js +0 -44
  164. package/main.js +0 -539
  165. package/matcher/a11y.js +0 -65
  166. package/matcher/behavior.js +0 -31
  167. package/matcher/framework/index.js +0 -15
  168. package/matcher/framework/react.js +0 -25
  169. package/matcher/index.js +0 -36
  170. package/matcher/name.js +0 -132
  171. package/matcher/structure.js +0 -208
  172. package/normalize/candidate.js +0 -22
  173. package/normalize/dom.js +0 -167
  174. package/normalize/framework.js +0 -129
  175. package/normalize/style-resolver.js +0 -24
  176. package/normalize/style.js +0 -175
  177. package/normalize/words.js +0 -40
  178. package/playgrounds/angular.js +0 -11
  179. package/playgrounds/framework-entrypoint.js +0 -90
  180. package/playgrounds/react.js +0 -997
  181. package/playgrounds/scss.js +0 -7
  182. package/playgrounds/style-entrypoint.js +0 -78
  183. package/playgrounds/styled-components.js +0 -138
  184. package/playgrounds/tailwind.js +0 -186
  185. package/playgrounds/vue.js +0 -11
  186. package/plugin.js +0 -3
  187. package/report.js +0 -159
  188. package/utils.js +0 -92
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.text = void 0;
4
+ // The STRUCTURE CLI text: the score, the chain facts, then WHICH nodes
5
+ // correspond — the aligned tag pairs (`div↔div:32`, `header↔header:33`), the
6
+ // same correspondence the Structure tab draws.
7
+ const pct = (n) => `${Math.round((n ?? 0) * 100)}%`;
8
+ const text = (model) => {
9
+ if (!model || !model.hasEvidence)
10
+ return [];
11
+ const ev = model.evidence ?? {};
12
+ const head = `${pct(model.score)} structure (${ev.mode ?? "tree"})`;
13
+ const lines = [head];
14
+ const facts = [];
15
+ if (ev.chainSize != null)
16
+ facts.push(`chain ${ev.chainSize}/${ev.refSize ?? "?"}`);
17
+ if (ev.quality != null)
18
+ facts.push(`quality ${pct(ev.quality)}`);
19
+ if (ev.agreement != null)
20
+ facts.push(`CSS agreement ${pct(ev.agreement)}`);
21
+ if (ev.conflicts)
22
+ facts.push(`${ev.conflicts} CSS conflict(s)`);
23
+ if (ev.classesDiffer)
24
+ facts.push("class names differ");
25
+ if (facts.length > 0)
26
+ lines.push(facts.join(" · "));
27
+ const nodes = ev.nodes ?? [];
28
+ if (nodes.length > 0) {
29
+ const shown = nodes.slice(0, 20).map((p) => {
30
+ const pair = p.left === p.right ? p.left : `${p.left}↔${p.right}`;
31
+ const at = p.leftLine != null ? `:${p.leftLine}` : "";
32
+ return `${pair}${at}`;
33
+ });
34
+ if (nodes.length > 20)
35
+ shown.push(`…+${nodes.length - 20} more`);
36
+ lines.push(`matched nodes ${shown.join(", ")}`);
37
+ }
38
+ return lines;
39
+ };
40
+ exports.text = text;
@@ -0,0 +1,11 @@
1
+ declare const build: (left: any, right: any, signal: any) => {
2
+ rows: any[];
3
+ details: any;
4
+ sharedCount: number;
5
+ leftCount: number;
6
+ rightCount: number;
7
+ score: any;
8
+ hasEvidence: boolean;
9
+ evidence: any;
10
+ };
11
+ export { build };
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.build = void 0;
4
+ // The STYLES model: per matched node pair, the CSS properties that matter for
5
+ // its element role and whether they agree. The engine already scored the pair;
6
+ // this arranges the evidence into rows the board draws.
7
+ const build = (left, right, signal) => {
8
+ if (!left || !right || !signal)
9
+ return null;
10
+ const ev = signal.evidence ?? {};
11
+ const details = ev.details ?? [];
12
+ const rows = [];
13
+ for (const detail of details) {
14
+ for (const row of detail.rows ?? []) {
15
+ rows.push({
16
+ tag: detail.tag,
17
+ name: row.prop,
18
+ left: row.left === null ? null : { name: `${row.prop}: ${row.left}` },
19
+ right: row.right === null ? null : { name: `${row.prop}: ${row.right}` },
20
+ shared: row.left !== null && row.right !== null,
21
+ same: row.same,
22
+ });
23
+ }
24
+ }
25
+ return {
26
+ rows,
27
+ details,
28
+ sharedCount: rows.filter((r) => r.same).length,
29
+ leftCount: rows.filter((r) => r.left).length,
30
+ rightCount: rows.filter((r) => r.right).length,
31
+ score: signal.score ?? 0,
32
+ hasEvidence: signal.applicable !== false && rows.length > 0,
33
+ evidence: ev,
34
+ };
35
+ };
36
+ exports.build = build;
@@ -0,0 +1,2 @@
1
+ declare const text: (model: any) => string[];
2
+ export { text };
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.text = void 0;
4
+ // The STYLES CLI text: the score, then WHICH styles are duplicated — per node
5
+ // tag, the agreeing properties with their values, comma-separated (the same
6
+ // rows the Styles tab paints), then the properties that differ.
7
+ const pct = (n) => `${Math.round((n ?? 0) * 100)}%`;
8
+ const valueOf = (side) => (side ? side.name.split(": ").slice(1).join(": ") : "—");
9
+ const text = (model) => {
10
+ if (!model || !model.hasEvidence)
11
+ return [];
12
+ const ev = model.evidence ?? {};
13
+ const head = `${pct(model.score)} styles (${ev.agreeing ?? 0}/${ev.properties ?? 0} properties agree across ${ev.pairs ?? 0} node pair(s))`;
14
+ const lines = [head];
15
+ // Per node tag: what exactly agrees. `div display: flex, gap: 24px` reads as
16
+ // the Styles board's div block, in one line. Repeated tags (two divs matched)
17
+ // keep their declarations distinct; identical declarations dedupe.
18
+ const byTag = new Map();
19
+ for (const row of model.rows) {
20
+ if (!row.shared || !row.same)
21
+ continue;
22
+ const list = byTag.get(row.tag) ?? new Set();
23
+ list.add(`${row.name}: ${valueOf(row.left)}`);
24
+ byTag.set(row.tag, list);
25
+ }
26
+ for (const [tag, props] of byTag)
27
+ lines.push(`${tag} ${[...props].join(", ")}`);
28
+ const differing = model.rows.filter((r) => !r.same && r.left && r.right);
29
+ if (differing.length > 0) {
30
+ lines.push(`differ ${differing.map((r) => `${r.tag} ${r.name}: ${valueOf(r.left)} ≠ ${valueOf(r.right)}`).join(", ")}`);
31
+ }
32
+ const onlyA = model.rows.filter((r) => r.left && !r.right);
33
+ const onlyB = model.rows.filter((r) => r.right && !r.left);
34
+ if (onlyA.length > 0)
35
+ lines.push(`only local ${onlyA.map((r) => `${r.tag} ${r.name}: ${valueOf(r.left)}`).join(", ")}`);
36
+ if (onlyB.length > 0)
37
+ lines.push(`only canonical ${onlyB.map((r) => `${r.tag} ${r.name}: ${valueOf(r.right)}`).join(", ")}`);
38
+ return lines;
39
+ };
40
+ exports.text = text;
@@ -0,0 +1,3 @@
1
+ declare const readPrebuiltBundle: () => string;
2
+ declare const getBundle: () => any;
3
+ export { getBundle, readPrebuiltBundle };
@@ -0,0 +1,185 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.readPrebuiltBundle = exports.getBundle = void 0;
27
+ // The React overview bundle.
28
+ //
29
+ // PRIMARY PATH (published): `scripts/build-report-bundle.mjs` compiles `src/`
30
+ // with the SAME esbuild config at PACKAGE BUILD time and writes the minified
31
+ // IIFE to `dist/report/user-report/build/bundle.prebuilt.js`. This module reads
32
+ // that asset, so a published package needs neither esbuild nor React installed
33
+ // at runtime.
34
+ //
35
+ // DEV FALLBACK: when the asset is missing (a contributor running from source)
36
+ // and esbuild is resolvable, the source is compiled on the fly and cached in
37
+ // `os.tmpdir()`, keyed by the mtime+size of every source file. Only this path
38
+ // pulls in esbuild or React.
39
+ //
40
+ // Required LAZILY from `./html/shell.js`: loading the ESLint rule must never
41
+ // pull in esbuild or React.
42
+ const fs = __importStar(require("node:fs"));
43
+ const os = __importStar(require("node:os"));
44
+ const path = __importStar(require("node:path"));
45
+ const node_module_1 = require("node:module");
46
+ // The lazy CommonJS loader the dev fallback needs. `createRequire` keeps the
47
+ // resolution inside this module without hiding a bare `require` call (the same
48
+ // shape follow-architecture's bundle uses).
49
+ const nodeRequire = (0, node_module_1.createRequire)(__filename);
50
+ // The React source lives at report/user-report/src. When this module runs from
51
+ // the compiled dist/ tree, __dirname is dist/report/user-report/build (four
52
+ // levels below the package root); from source it is report/user-report/build
53
+ // (three levels). Try both so the bundle works in either layout.
54
+ const candidateRoots = [path.resolve(__dirname, "..", "..", "..", ".."), path.resolve(__dirname, "..", "..", "..")];
55
+ const PKG_ROOT = candidateRoots.find((r) => fs.existsSync(path.join(r, "report", "user-report", "src"))) ?? candidateRoots[0];
56
+ const SRC_DIR = path.join(PKG_ROOT, "report", "user-report", "src");
57
+ const ENTRY = path.join(SRC_DIR, "main.tsx");
58
+ const CACHE_DIR = path.join(os.tmpdir(), "component-uniqueness-overview");
59
+ const CACHE_FILE = path.join(CACHE_DIR, "bundle.js");
60
+ const STAMP_FILE = path.join(CACHE_DIR, "stamp.json");
61
+ // The prebuilt asset. From the compiled dist/ tree __dirname is
62
+ // dist/report/user-report/build and the asset sits right here; from source (a
63
+ // test run or a dev workspace) it lives under the package's dist/ if a build
64
+ // has run. Either way a published install has it.
65
+ const PREBUILT_CANDIDATES = [
66
+ path.join(__dirname, "bundle.prebuilt.js"),
67
+ path.join(PKG_ROOT, "dist", "report", "user-report", "build", "bundle.prebuilt.js"),
68
+ ];
69
+ const listSources = (dir) => {
70
+ const out = [];
71
+ for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {
72
+ const abs = path.join(dir, entry.name);
73
+ if (entry.isDirectory())
74
+ out.push(...listSources(abs));
75
+ else if (/\.(jsx?|tsx?|mjs)$/.test(entry.name))
76
+ out.push(abs);
77
+ }
78
+ return out.sort();
79
+ };
80
+ const stampOf = (files) => files.map((file) => {
81
+ const stat = fs.statSync(file);
82
+ return `${file}:${stat.size}:${stat.mtimeMs}`;
83
+ });
84
+ const readCached = (stamp) => {
85
+ try {
86
+ const cached = JSON.parse(fs.readFileSync(STAMP_FILE, "utf8"));
87
+ if (JSON.stringify(cached) !== JSON.stringify(stamp))
88
+ return null;
89
+ return fs.readFileSync(CACHE_FILE, "utf8");
90
+ }
91
+ catch {
92
+ return null;
93
+ }
94
+ };
95
+ const writeCached = (bundle, stamp) => {
96
+ try {
97
+ fs.mkdirSync(CACHE_DIR, { recursive: true });
98
+ fs.writeFileSync(CACHE_FILE, bundle, "utf8");
99
+ fs.writeFileSync(STAMP_FILE, JSON.stringify(stamp), "utf8");
100
+ }
101
+ catch {
102
+ // A read-only tmpdir is not a reason to fail the report.
103
+ }
104
+ };
105
+ // The published bundle: a string read from disk. No esbuild, no React, no
106
+ // source tree — this is the whole runtime path of a published package.
107
+ const readPrebuiltBundle = () => {
108
+ for (const file of PREBUILT_CANDIDATES) {
109
+ try {
110
+ return fs.readFileSync(file, "utf8");
111
+ }
112
+ catch {
113
+ // Try the next layout.
114
+ }
115
+ }
116
+ return null;
117
+ };
118
+ exports.readPrebuiltBundle = readPrebuiltBundle;
119
+ // A package DIRECTORY, so that `react/jsx-runtime` still resolves inside it.
120
+ const ROOT = (name) => path.dirname(nodeRequire.resolve(`${name}/package.json`));
121
+ const compile = () => {
122
+ const esbuild = nodeRequire("esbuild");
123
+ const result = esbuild.buildSync({
124
+ entryPoints: [ENTRY],
125
+ bundle: true,
126
+ write: false,
127
+ format: "iife",
128
+ platform: "browser",
129
+ target: ["es2020"],
130
+ jsx: "automatic",
131
+ loader: { ".js": "jsx", ".jsx": "jsx", ".ts": "ts", ".tsx": "tsx" },
132
+ define: { "process.env.NODE_ENV": '"production"' },
133
+ alias: {
134
+ react: ROOT("react"),
135
+ "react-dom": ROOT("react-dom"),
136
+ "styled-components": ROOT("styled-components"),
137
+ },
138
+ minify: true,
139
+ logLevel: "silent",
140
+ });
141
+ return result.outputFiles[0].text;
142
+ };
143
+ // The view is a package shipped as compiled `dist`: its files change without any
144
+ // change under `src`. The package is RESOLVED, not assumed (pnpm hoists it).
145
+ const vendorDist = () => {
146
+ try {
147
+ return path.dirname(nodeRequire.resolve("@md-code/sections/code-diff/board", { paths: [__dirname] }));
148
+ }
149
+ catch {
150
+ return null;
151
+ }
152
+ };
153
+ const vendorSources = () => {
154
+ const dist = vendorDist();
155
+ if (dist === null)
156
+ return [];
157
+ try {
158
+ return listSources(dist).filter((file) => file.endsWith(".js"));
159
+ }
160
+ catch {
161
+ return [];
162
+ }
163
+ };
164
+ let memoryCache = null;
165
+ const getBundle = () => {
166
+ if (memoryCache)
167
+ return memoryCache;
168
+ const prebuilt = readPrebuiltBundle();
169
+ if (prebuilt !== null) {
170
+ memoryCache = prebuilt;
171
+ return prebuilt;
172
+ }
173
+ // Dev fallback: no build has run. Compile from source and memoise on disk.
174
+ const stamp = stampOf([...listSources(SRC_DIR), ...vendorSources()]);
175
+ const cached = readCached(stamp);
176
+ if (cached) {
177
+ memoryCache = cached;
178
+ return cached;
179
+ }
180
+ const bundle = compile();
181
+ writeCached(bundle, stamp);
182
+ memoryCache = bundle;
183
+ return bundle;
184
+ };
185
+ exports.getBundle = getBundle;