@md-code/component-uniqueness 0.1.4 → 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.
- package/CHANGELOG.md +17 -0
- package/LICENSE +202 -0
- package/README.md +21 -3
- package/dist/config.d.ts +50 -0
- package/dist/config.js +402 -0
- package/dist/constants.d.ts +55 -0
- package/dist/constants.js +86 -0
- package/dist/decision-maker.d.ts +39 -0
- package/dist/decision-maker.js +119 -0
- package/dist/filter/child-element.d.ts +3 -0
- package/dist/filter/child-element.js +17 -0
- package/dist/filter/missing-component.d.ts +10 -0
- package/dist/filter/missing-component.js +96 -0
- package/dist/filter/no-structure.d.ts +3 -0
- package/dist/filter/no-structure.js +16 -0
- package/dist/filter/usages.d.ts +3 -0
- package/dist/filter/usages.js +14 -0
- package/dist/index.d.ts +105 -0
- package/dist/index.js +244 -0
- package/dist/lib-registry.d.ts +4 -0
- package/dist/lib-registry.js +376 -0
- package/dist/logger.d.ts +7 -0
- package/dist/logger.js +70 -0
- package/dist/main.d.ts +25 -0
- package/dist/main.js +666 -0
- package/dist/matcher/a11y.d.ts +19 -0
- package/dist/matcher/a11y.js +311 -0
- package/dist/matcher/behavior.d.ts +10 -0
- package/dist/matcher/behavior.js +32 -0
- package/dist/matcher/css-matching.d.ts +18 -0
- package/dist/matcher/css-matching.js +159 -0
- package/dist/matcher/framework/index.d.ts +2 -0
- package/dist/matcher/framework/index.js +37 -0
- package/dist/matcher/framework/react.d.ts +12 -0
- package/dist/matcher/framework/react.js +70 -0
- package/dist/matcher/index.d.ts +64 -0
- package/dist/matcher/index.js +38 -0
- package/dist/matcher/name.d.ts +15 -0
- package/dist/matcher/name.js +154 -0
- package/dist/matcher/structure.d.ts +22 -0
- package/dist/matcher/structure.js +329 -0
- package/dist/matcher/styles.d.ts +20 -0
- package/dist/matcher/styles.js +49 -0
- package/dist/normalize/candidate.d.ts +3 -0
- package/dist/normalize/candidate.js +21 -0
- package/dist/normalize/dom.d.ts +22 -0
- package/dist/normalize/dom.js +180 -0
- package/dist/normalize/external-html.d.ts +5 -0
- package/dist/normalize/external-html.js +40 -0
- package/dist/normalize/framework.d.ts +20 -0
- package/dist/normalize/framework.js +130 -0
- package/dist/normalize/resolver.d.ts +7 -0
- package/dist/normalize/resolver.js +28 -0
- package/dist/normalize/style-resolver.d.ts +7 -0
- package/dist/normalize/style-resolver.js +28 -0
- package/dist/normalize/style.d.ts +15 -0
- package/dist/normalize/style.js +174 -0
- package/dist/normalize/words.d.ts +3 -0
- package/dist/normalize/words.js +40 -0
- package/dist/package.json +88 -0
- package/dist/playgrounds/angular.d.ts +7 -0
- package/dist/playgrounds/angular.js +9 -0
- package/dist/playgrounds/framework-entrypoint.d.ts +10 -0
- package/dist/playgrounds/framework-entrypoint.js +102 -0
- package/dist/playgrounds/framework.d.ts +10 -0
- package/dist/playgrounds/framework.js +102 -0
- package/dist/playgrounds/react.d.ts +14 -0
- package/dist/playgrounds/react.js +1288 -0
- package/dist/playgrounds/scss.d.ts +6 -0
- package/dist/playgrounds/scss.js +9 -0
- package/dist/playgrounds/style-entrypoint.d.ts +13 -0
- package/dist/playgrounds/style-entrypoint.js +82 -0
- package/dist/playgrounds/style.d.ts +13 -0
- package/dist/playgrounds/style.js +82 -0
- package/dist/playgrounds/styled-components.d.ts +7 -0
- package/dist/playgrounds/styled-components.js +190 -0
- package/dist/playgrounds/tailwind.d.ts +15 -0
- package/dist/playgrounds/tailwind.js +256 -0
- package/dist/playgrounds/vue.d.ts +7 -0
- package/dist/playgrounds/vue.js +9 -0
- package/dist/report/asks.d.ts +27 -0
- package/dist/report/asks.js +28 -0
- package/dist/report/cli-report.d.ts +7 -0
- package/dist/report/cli-report.js +187 -0
- package/dist/report/codes/index.d.ts +37 -0
- package/dist/report/codes/index.js +31 -0
- package/dist/report/errorTypes/index.d.ts +92 -0
- package/dist/report/errorTypes/index.js +186 -0
- package/dist/report/evidence.d.ts +2 -0
- package/dist/report/evidence.js +8 -0
- package/dist/report/explain.d.ts +27 -0
- package/dist/report/explain.js +76 -0
- package/dist/report/index.d.ts +2 -0
- package/dist/report/index.js +24 -0
- package/dist/report/matchers/a11y/model.d.ts +20 -0
- package/dist/report/matchers/a11y/model.js +14 -0
- package/dist/report/matchers/a11y/text.d.ts +2 -0
- package/dist/report/matchers/a11y/text.js +22 -0
- package/dist/report/matchers/behavior/model.d.ts +20 -0
- package/dist/report/matchers/behavior/model.js +12 -0
- package/dist/report/matchers/behavior/text.d.ts +2 -0
- package/dist/report/matchers/behavior/text.js +22 -0
- package/dist/report/matchers/framework/model.d.ts +10 -0
- package/dist/report/matchers/framework/model.js +39 -0
- package/dist/report/matchers/framework/text.d.ts +2 -0
- package/dist/report/matchers/framework/text.js +26 -0
- package/dist/report/matchers/index.d.ts +5 -0
- package/dist/report/matchers/index.js +97 -0
- package/dist/report/matchers/name/model.d.ts +20 -0
- package/dist/report/matchers/name/model.js +30 -0
- package/dist/report/matchers/name/text.d.ts +2 -0
- package/dist/report/matchers/name/text.js +17 -0
- package/dist/report/matchers/set-model.d.ts +31 -0
- package/dist/report/matchers/set-model.js +42 -0
- package/dist/report/matchers/structure/model.d.ts +10 -0
- package/dist/report/matchers/structure/model.js +58 -0
- package/dist/report/matchers/structure/text.d.ts +2 -0
- package/dist/report/matchers/structure/text.js +40 -0
- package/dist/report/matchers/styles/model.d.ts +11 -0
- package/dist/report/matchers/styles/model.js +36 -0
- package/dist/report/matchers/styles/text.d.ts +2 -0
- package/dist/report/matchers/styles/text.js +40 -0
- package/dist/report/user-report/build/bundle.d.ts +3 -0
- package/dist/report/user-report/build/bundle.js +185 -0
- package/dist/report/user-report/build/bundle.prebuilt.js +955 -0
- package/dist/report/user-report/data/collect.d.ts +68 -0
- package/dist/report/user-report/data/collect.js +150 -0
- package/dist/report/user-report/data/folders.d.ts +3 -0
- package/dist/report/user-report/data/folders.js +73 -0
- package/dist/report/user-report/data/groups.d.ts +13 -0
- package/dist/report/user-report/data/groups.js +76 -0
- package/dist/report/user-report/data/links.d.ts +39 -0
- package/dist/report/user-report/data/links.js +222 -0
- package/dist/report/user-report/data/snapshot.d.ts +9 -0
- package/dist/report/user-report/data/snapshot.js +180 -0
- package/dist/report/user-report/data/source.d.ts +13 -0
- package/dist/report/user-report/data/source.js +58 -0
- package/dist/report/user-report/data/word.d.ts +3 -0
- package/dist/report/user-report/data/word.js +32 -0
- package/dist/report/user-report/html/shell.d.ts +2 -0
- package/dist/report/user-report/html/shell.js +27 -0
- package/dist/report/user-report/index.d.ts +7 -0
- package/dist/report/user-report/index.js +47 -0
- package/dist/report/vocabulary/evidence.d.ts +48 -0
- package/dist/report/vocabulary/evidence.js +66 -0
- package/dist/report/vocabulary/format.d.ts +4 -0
- package/dist/report/vocabulary/format.js +20 -0
- package/dist/report/vocabulary/labels.d.ts +134 -0
- package/dist/report/vocabulary/labels.js +87 -0
- package/dist/report/vocabulary/phrases.d.ts +20 -0
- package/dist/report/vocabulary/phrases.js +34 -0
- package/dist/self-catalog.d.ts +4 -0
- package/dist/self-catalog.js +179 -0
- package/dist/utils.d.ts +6 -0
- package/dist/utils.js +125 -0
- package/package.json +86 -71
- package/config.js +0 -372
- package/decision-maker.js +0 -109
- package/filter/drop-child-element.js +0 -14
- package/filter/drop-no-structure.js +0 -13
- package/filter/drop-usages.js +0 -13
- package/filter/missing-component.js +0 -100
- package/index.js +0 -184
- package/logger.js +0 -44
- package/main.js +0 -584
- package/matcher/a11y.js +0 -65
- package/matcher/behavior.js +0 -31
- package/matcher/framework/index.js +0 -15
- package/matcher/framework/react.js +0 -25
- package/matcher/index.js +0 -36
- package/matcher/name.js +0 -132
- package/matcher/structure.js +0 -242
- package/normalize/candidate.js +0 -22
- package/normalize/dom.js +0 -187
- package/normalize/framework.js +0 -110
- package/normalize/style-resolver.js +0 -24
- package/normalize/style.js +0 -175
- package/normalize/words.js +0 -40
- package/playgrounds/angular.js +0 -11
- package/playgrounds/framework-entrypoint.js +0 -90
- package/playgrounds/react.js +0 -998
- package/playgrounds/scss.js +0 -7
- package/playgrounds/style-entrypoint.js +0 -78
- package/playgrounds/styled-components.js +0 -138
- package/playgrounds/tailwind.js +0 -186
- package/playgrounds/vue.js +0 -11
- package/plugin.js +0 -3
- package/report.js +0 -162
- 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,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,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,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;
|