@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
package/playgrounds/scss.js
DELETED
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
const { normalizeOptions } = require("../config.js");
|
|
4
|
-
const { cssTextToStyles, styleObjectToText, mergeProfiles } = require("../normalize/style.js");
|
|
5
|
-
|
|
6
|
-
const PLAYGROUNDS = {
|
|
7
|
-
tailwind: () => require("./tailwind.js"),
|
|
8
|
-
scss: () => require("./scss.js"),
|
|
9
|
-
"styled-components": () => require("./styled-components.js"),
|
|
10
|
-
styled: () => require("./styled-components.js"),
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
const cache = new Map();
|
|
14
|
-
|
|
15
|
-
const getPlayground = (styleSystem) => {
|
|
16
|
-
const key = String(styleSystem || "tailwind").toLowerCase();
|
|
17
|
-
if (!cache.has(key)) {
|
|
18
|
-
const loader = PLAYGROUNDS[key] || PLAYGROUNDS.tailwind;
|
|
19
|
-
cache.set(key, loader());
|
|
20
|
-
}
|
|
21
|
-
return cache.get(key);
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
const getStyleSystem = (opts) => normalizeOptions(opts).styleSystem;
|
|
25
|
-
|
|
26
|
-
const normalizeStyles = async (className, styleObj, opts, label) => {
|
|
27
|
-
const pg = getPlayground(getStyleSystem(opts));
|
|
28
|
-
const parts = [];
|
|
29
|
-
if (typeof className === "string" && className.trim()) {
|
|
30
|
-
const tw = await pg.resolveClasses(className.trim().split(/\s+/));
|
|
31
|
-
parts.push(tw);
|
|
32
|
-
}
|
|
33
|
-
if (styleObj && typeof styleObj === "object") {
|
|
34
|
-
parts.push(cssTextToStyles(styleObjectToText(styleObj)));
|
|
35
|
-
}
|
|
36
|
-
if (parts.length === 0) return { css: {}, unresolved: [] };
|
|
37
|
-
const merged = parts.reduce(mergeProfiles, { css: {}, unresolved: [] });
|
|
38
|
-
return { css: merged.css, unresolved: merged.unresolved };
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
const normalizeStylesSync = (className, styleObj, opts, label) => {
|
|
42
|
-
const pg = getPlayground(getStyleSystem(opts));
|
|
43
|
-
const parts = [];
|
|
44
|
-
if (typeof className === "string" && className.trim()) {
|
|
45
|
-
const tw = pg.resolveClassesSync(className.trim().split(/\s+/));
|
|
46
|
-
parts.push(tw);
|
|
47
|
-
}
|
|
48
|
-
if (styleObj && typeof styleObj === "object") {
|
|
49
|
-
parts.push(cssTextToStyles(styleObjectToText(styleObj)));
|
|
50
|
-
}
|
|
51
|
-
if (parts.length === 0) return { css: {}, unresolved: [] };
|
|
52
|
-
const merged = parts.reduce(mergeProfiles, { css: {}, unresolved: [] });
|
|
53
|
-
return { css: merged.css, unresolved: merged.unresolved };
|
|
54
|
-
};
|
|
55
|
-
|
|
56
|
-
const escapeClass = (cls) => cls.replace(/[^a-zA-Z0-9_-]/g, (c) => `\\${c}`);
|
|
57
|
-
|
|
58
|
-
const buildStylesheet = (classes, opts) => {
|
|
59
|
-
const pg = getPlayground(getStyleSystem(opts));
|
|
60
|
-
if (!pg.classStyles) return "";
|
|
61
|
-
const { byClass } = pg.classStyles(classes);
|
|
62
|
-
const rules = [];
|
|
63
|
-
for (const [cls, decls] of Object.entries(byClass)) {
|
|
64
|
-
if (cls.includes(":")) continue;
|
|
65
|
-
const body = Object.entries(decls)
|
|
66
|
-
.map(([prop, values]) => `${prop}:${values[values.length - 1]}`)
|
|
67
|
-
.join(";");
|
|
68
|
-
rules.push(`.${escapeClass(cls)}{${body}}`);
|
|
69
|
-
}
|
|
70
|
-
return rules.join("\n");
|
|
71
|
-
};
|
|
72
|
-
|
|
73
|
-
const whenReady = async (opts) => {
|
|
74
|
-
const pg = getPlayground(getStyleSystem(opts));
|
|
75
|
-
if (pg.ready) await pg.ready;
|
|
76
|
-
};
|
|
77
|
-
|
|
78
|
-
module.exports = { normalizeStyles, normalizeStylesSync, getStyleSystem, getPlayground, buildStylesheet, whenReady };
|
|
@@ -1,138 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
const ts = require("typescript");
|
|
4
|
-
|
|
5
|
-
const MAX_LITERAL_DEPTH = 4;
|
|
6
|
-
const MAX_LITERAL_COUNT = 12;
|
|
7
|
-
|
|
8
|
-
const stringLiterals = (node, out, depth = 0) => {
|
|
9
|
-
if (!node || depth > MAX_LITERAL_DEPTH || out.length >= MAX_LITERAL_COUNT) return;
|
|
10
|
-
if (ts.isStringLiteral(node) || ts.isNoSubstitutionTemplateLiteral(node)) {
|
|
11
|
-
out.push(node.text);
|
|
12
|
-
return;
|
|
13
|
-
}
|
|
14
|
-
if (ts.isNumericLiteral(node)) {
|
|
15
|
-
out.push(node.text);
|
|
16
|
-
return;
|
|
17
|
-
}
|
|
18
|
-
if (ts.isParenthesizedExpression(node)) {
|
|
19
|
-
stringLiterals(node.expression, out, depth + 1);
|
|
20
|
-
return;
|
|
21
|
-
}
|
|
22
|
-
if (ts.isTemplateExpression(node)) {
|
|
23
|
-
if (node.head.text) out.push(node.head.text);
|
|
24
|
-
for (const span of node.templateSpans) {
|
|
25
|
-
if (span.literal.text) out.push(span.literal.text);
|
|
26
|
-
stringLiterals(span.expression, out, depth + 1);
|
|
27
|
-
}
|
|
28
|
-
return;
|
|
29
|
-
}
|
|
30
|
-
if (ts.isCallExpression(node)) {
|
|
31
|
-
for (const arg of node.arguments) stringLiterals(arg, out, depth + 1);
|
|
32
|
-
return;
|
|
33
|
-
}
|
|
34
|
-
if (ts.isConditionalExpression(node)) {
|
|
35
|
-
stringLiterals(node.whenTrue, out, depth + 1);
|
|
36
|
-
stringLiterals(node.whenFalse, out, depth + 1);
|
|
37
|
-
return;
|
|
38
|
-
}
|
|
39
|
-
if (ts.isBinaryExpression(node) && node.operatorToken.kind === ts.SyntaxKind.Plus) {
|
|
40
|
-
stringLiterals(node.left, out, depth + 1);
|
|
41
|
-
stringLiterals(node.right, out, depth + 1);
|
|
42
|
-
return;
|
|
43
|
-
}
|
|
44
|
-
};
|
|
45
|
-
|
|
46
|
-
const localDeclarations = (sf) => {
|
|
47
|
-
const map = new Map();
|
|
48
|
-
const visit = (node) => {
|
|
49
|
-
if (ts.isVariableDeclaration(node) && ts.isIdentifier(node.name) && node.initializer && !map.has(node.name.text)) {
|
|
50
|
-
map.set(node.name.text, node.initializer);
|
|
51
|
-
}
|
|
52
|
-
ts.forEachChild(node, visit);
|
|
53
|
-
};
|
|
54
|
-
visit(sf);
|
|
55
|
-
return map;
|
|
56
|
-
};
|
|
57
|
-
|
|
58
|
-
const literalOf = (expr, decls, depth = 0) => {
|
|
59
|
-
if (!expr || depth > 3) return null;
|
|
60
|
-
if (ts.isStringLiteral(expr) || ts.isNoSubstitutionTemplateLiteral(expr)) return expr.text;
|
|
61
|
-
if (ts.isNumericLiteral(expr)) return expr.text;
|
|
62
|
-
if (ts.isParenthesizedExpression(expr)) return literalOf(expr.expression, decls, depth + 1);
|
|
63
|
-
if (ts.isArrowFunction(expr) || ts.isFunctionExpression(expr)) {
|
|
64
|
-
let body = expr.body;
|
|
65
|
-
if (ts.isBlock(body)) {
|
|
66
|
-
const ret = body.statements.find((s) => ts.isReturnStatement(s) && s.expression);
|
|
67
|
-
if (!ret) return null;
|
|
68
|
-
body = ret.expression;
|
|
69
|
-
}
|
|
70
|
-
return literalOf(body, decls, depth + 1);
|
|
71
|
-
}
|
|
72
|
-
if (ts.isIdentifier(expr)) {
|
|
73
|
-
const decl = decls.get(expr.text);
|
|
74
|
-
if (!decl) return null;
|
|
75
|
-
return literalOf(decl, decls, depth + 1);
|
|
76
|
-
}
|
|
77
|
-
if (ts.isCallExpression(expr) && ts.isIdentifier(expr.expression)) {
|
|
78
|
-
const decl = decls.get(expr.expression.text);
|
|
79
|
-
if (!decl) return null;
|
|
80
|
-
return literalOf(decl, decls, depth + 1);
|
|
81
|
-
}
|
|
82
|
-
return null;
|
|
83
|
-
};
|
|
84
|
-
|
|
85
|
-
const templateToCss = (template, decls, sf) => {
|
|
86
|
-
const unresolved = [];
|
|
87
|
-
if (ts.isNoSubstitutionTemplateLiteral(template)) return { cssText: template.text, unresolved };
|
|
88
|
-
if (!ts.isTemplateExpression(template)) return { cssText: "", unresolved };
|
|
89
|
-
let text = template.head.text;
|
|
90
|
-
for (const span of template.templateSpans) {
|
|
91
|
-
const value = literalOf(span.expression, decls);
|
|
92
|
-
if (value !== null) {
|
|
93
|
-
text += value;
|
|
94
|
-
} else {
|
|
95
|
-
const strs = [];
|
|
96
|
-
stringLiterals(span.expression, strs);
|
|
97
|
-
if (strs.length > 0) text += strs.join(" ");
|
|
98
|
-
else unresolved.push(span.expression.getText(sf));
|
|
99
|
-
}
|
|
100
|
-
text += span.literal.text;
|
|
101
|
-
}
|
|
102
|
-
return { cssText: text, unresolved };
|
|
103
|
-
};
|
|
104
|
-
|
|
105
|
-
const styledTagInfo = (tag) => {
|
|
106
|
-
if (ts.isPropertyAccessExpression(tag) && ts.isIdentifier(tag.expression) && tag.expression.text === "styled" && ts.isIdentifier(tag.name)) {
|
|
107
|
-
return { baseTag: tag.name.text, componentRef: null };
|
|
108
|
-
}
|
|
109
|
-
if (ts.isCallExpression(tag) && ts.isIdentifier(tag.expression) && tag.expression.text === "styled" && tag.arguments.length === 1 && ts.isIdentifier(tag.arguments[0])) {
|
|
110
|
-
return { baseTag: null, componentRef: tag.arguments[0].text };
|
|
111
|
-
}
|
|
112
|
-
return null;
|
|
113
|
-
};
|
|
114
|
-
|
|
115
|
-
const styledDeclarations = (sf) => {
|
|
116
|
-
const out = new Map();
|
|
117
|
-
const decls = localDeclarations(sf);
|
|
118
|
-
const visit = (node) => {
|
|
119
|
-
if (ts.isVariableStatement(node)) {
|
|
120
|
-
for (const d of node.declarationList.declarations) {
|
|
121
|
-
if (!ts.isIdentifier(d.name) || !d.initializer || !ts.isTaggedTemplateExpression(d.initializer)) continue;
|
|
122
|
-
const info = styledTagInfo(d.initializer.tag);
|
|
123
|
-
if (!info) continue;
|
|
124
|
-
const { cssText, unresolved } = templateToCss(d.initializer.template, decls, sf);
|
|
125
|
-
out.set(d.name.text, { baseTag: info.baseTag, componentRef: info.componentRef, cssText, unresolved });
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
ts.forEachChild(node, visit);
|
|
129
|
-
};
|
|
130
|
-
visit(sf);
|
|
131
|
-
return out;
|
|
132
|
-
};
|
|
133
|
-
|
|
134
|
-
const resolveClasses = (classes) => {
|
|
135
|
-
return { css: {}, unresolved: [...(classes || [])] };
|
|
136
|
-
};
|
|
137
|
-
|
|
138
|
-
module.exports = { styledDeclarations, resolveClasses, available: () => true };
|
package/playgrounds/tailwind.js
DELETED
|
@@ -1,186 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
const fs = require("node:fs");
|
|
4
|
-
const path = require("node:path");
|
|
5
|
-
|
|
6
|
-
let compiled = null;
|
|
7
|
-
let failed = false;
|
|
8
|
-
let designSystem = null;
|
|
9
|
-
const ready = Promise.resolve()
|
|
10
|
-
.then(() => require("tailwindcss").__unstable__loadDesignSystem("@import \"tailwindcss\";", {
|
|
11
|
-
from: path.join(__dirname, "probe.css"),
|
|
12
|
-
loadStylesheet: (id, base) => {
|
|
13
|
-
if (id === "tailwindcss") {
|
|
14
|
-
const cssPath = require.resolve("tailwindcss/index.css");
|
|
15
|
-
return { path: cssPath, base: path.dirname(cssPath), content: fs.readFileSync(cssPath, "utf8") };
|
|
16
|
-
}
|
|
17
|
-
return { path: id, base: base || "", content: "" };
|
|
18
|
-
},
|
|
19
|
-
}))
|
|
20
|
-
.then((ds) => {
|
|
21
|
-
designSystem = ds;
|
|
22
|
-
})
|
|
23
|
-
.catch(() => {});
|
|
24
|
-
|
|
25
|
-
const compileOnce = async () => {
|
|
26
|
-
if (compiled) return compiled;
|
|
27
|
-
if (failed) return null;
|
|
28
|
-
try {
|
|
29
|
-
const { compile } = require("tailwindcss");
|
|
30
|
-
const cssPath = require.resolve("tailwindcss/index.css");
|
|
31
|
-
compiled = await compile("@import \"tailwindcss\";", {
|
|
32
|
-
from: path.join(__dirname, "probe.css"),
|
|
33
|
-
loadStylesheet: async (id, base) => {
|
|
34
|
-
if (id === "tailwindcss") {
|
|
35
|
-
return { path: cssPath, base: path.dirname(cssPath), content: fs.readFileSync(cssPath, "utf8") };
|
|
36
|
-
}
|
|
37
|
-
return { path: id, base: base || "", content: "" };
|
|
38
|
-
},
|
|
39
|
-
});
|
|
40
|
-
return compiled;
|
|
41
|
-
} catch {
|
|
42
|
-
failed = true;
|
|
43
|
-
return null;
|
|
44
|
-
}
|
|
45
|
-
};
|
|
46
|
-
|
|
47
|
-
const extractClass = (sel) => {
|
|
48
|
-
if (sel.startsWith(".")) sel = sel.slice(1);
|
|
49
|
-
let name = "";
|
|
50
|
-
for (let i = 0; i < sel.length; i++) {
|
|
51
|
-
const ch = sel[i];
|
|
52
|
-
if (ch === "\\") {
|
|
53
|
-
name += sel[i + 1] ?? "";
|
|
54
|
-
i++;
|
|
55
|
-
continue;
|
|
56
|
-
}
|
|
57
|
-
if (ch === ":" || ch === " " || ch === "," || ch === "[" || ch === "{" || ch === ".") break;
|
|
58
|
-
name += ch;
|
|
59
|
-
}
|
|
60
|
-
return name;
|
|
61
|
-
};
|
|
62
|
-
|
|
63
|
-
const parseCss = (css) => {
|
|
64
|
-
const vars = new Map();
|
|
65
|
-
for (const m of css.matchAll(/--([a-z0-9-]+)\s*:\s*([^;{}]+);/g)) vars.set(m[1], m[2].trim());
|
|
66
|
-
const map = {};
|
|
67
|
-
const layerIdx = css.indexOf("@layer utilities");
|
|
68
|
-
const layer = layerIdx >= 0 ? css.slice(layerIdx) : css;
|
|
69
|
-
const ruleRe = /([.#][^{]+)\{([^{}]*)\}/g;
|
|
70
|
-
let m;
|
|
71
|
-
while ((m = ruleRe.exec(layer))) {
|
|
72
|
-
const sel = m[1].trim();
|
|
73
|
-
if (!sel.startsWith(".")) continue;
|
|
74
|
-
const cls = extractClass(sel);
|
|
75
|
-
if (!cls) continue;
|
|
76
|
-
const styles = {};
|
|
77
|
-
for (const d of m[2].split(";")) {
|
|
78
|
-
const idx = d.indexOf(":");
|
|
79
|
-
if (idx < 0) continue;
|
|
80
|
-
const prop = d.slice(0, idx).trim().toLowerCase();
|
|
81
|
-
let value = d.slice(idx + 1).trim();
|
|
82
|
-
if (!prop || !value) continue;
|
|
83
|
-
if (value.startsWith("var(")) {
|
|
84
|
-
const vm = value.match(/^var\(\s*--([a-z0-9-]+)/);
|
|
85
|
-
if (vm && vars.has(vm[1])) value = vars.get(vm[1]);
|
|
86
|
-
}
|
|
87
|
-
if (!Object.prototype.hasOwnProperty.call(styles, prop)) styles[prop] = [];
|
|
88
|
-
if (!styles[prop].includes(value)) styles[prop].push(value);
|
|
89
|
-
}
|
|
90
|
-
const pairs = Object.entries(styles).map(([prop, values]) => [prop, values.join(" ")]);
|
|
91
|
-
if (pairs.length > 0) map[cls] = pairs;
|
|
92
|
-
}
|
|
93
|
-
return map;
|
|
94
|
-
};
|
|
95
|
-
|
|
96
|
-
const resolveClasses = async (classes) => {
|
|
97
|
-
const list = [...new Set(classes || [])];
|
|
98
|
-
const out = await compileOnce();
|
|
99
|
-
if (!out) return { css: {}, unresolved: list };
|
|
100
|
-
const cssText = await out.build(list);
|
|
101
|
-
const map = parseCss(cssText);
|
|
102
|
-
const css = {};
|
|
103
|
-
const unresolved = [];
|
|
104
|
-
for (const cls of list) {
|
|
105
|
-
const pairs = map[cls];
|
|
106
|
-
if (pairs && pairs.length > 0) {
|
|
107
|
-
for (const [prop, value] of pairs) {
|
|
108
|
-
css[prop] = css[prop] || [];
|
|
109
|
-
if (!css[prop].includes(value)) css[prop].push(value);
|
|
110
|
-
}
|
|
111
|
-
} else {
|
|
112
|
-
unresolved.push(cls);
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
return { css, unresolved };
|
|
116
|
-
};
|
|
117
|
-
|
|
118
|
-
const parseBlock = (block, vars, styles) => {
|
|
119
|
-
const ruleRe = /([.#][^{]+)\{([^{}]*)\}/g;
|
|
120
|
-
let m;
|
|
121
|
-
while ((m = ruleRe.exec(block))) {
|
|
122
|
-
const sel = m[1].trim();
|
|
123
|
-
if (!sel.startsWith(".")) continue;
|
|
124
|
-
const cls = extractClass(sel);
|
|
125
|
-
if (!cls) continue;
|
|
126
|
-
for (const d of m[2].split(";")) {
|
|
127
|
-
const idx = d.indexOf(":");
|
|
128
|
-
if (idx < 0) continue;
|
|
129
|
-
const prop = d.slice(0, idx).trim().toLowerCase();
|
|
130
|
-
let value = d.slice(idx + 1).trim();
|
|
131
|
-
if (!prop || !value) continue;
|
|
132
|
-
if (value.startsWith("var(")) {
|
|
133
|
-
const vm = value.match(/^var\(\s*--([a-z0-9-]+)/);
|
|
134
|
-
if (vm && vars.has(vm[1])) value = vars.get(vm[1]);
|
|
135
|
-
}
|
|
136
|
-
if (!Object.prototype.hasOwnProperty.call(styles, cls)) styles[cls] = {};
|
|
137
|
-
if (!Object.prototype.hasOwnProperty.call(styles[cls], prop)) styles[cls][prop] = [];
|
|
138
|
-
if (!styles[cls][prop].includes(value)) styles[cls][prop].push(value);
|
|
139
|
-
}
|
|
140
|
-
const inner = m[2];
|
|
141
|
-
if (inner.includes("{")) parseBlock(inner, vars, styles);
|
|
142
|
-
}
|
|
143
|
-
};
|
|
144
|
-
|
|
145
|
-
const substituteVars = (value, depth = 0) =>
|
|
146
|
-
value.replace(/var\(--([a-z0-9-]+)\)/g, (match, name) => {
|
|
147
|
-
if (depth >= 4) return match;
|
|
148
|
-
const resolved = designSystem.theme.resolve(null, [`--${name}`]);
|
|
149
|
-
return resolved && String(resolved) !== match ? substituteVars(String(resolved), depth + 1) : match;
|
|
150
|
-
});
|
|
151
|
-
|
|
152
|
-
const classStyles = (classes) => {
|
|
153
|
-
const list = [...new Set(classes || [])];
|
|
154
|
-
if (!designSystem) return { byClass: {}, unresolved: list };
|
|
155
|
-
const out = designSystem.candidatesToCss(list);
|
|
156
|
-
const vars = new Map();
|
|
157
|
-
for (const m of String(out).matchAll(/--([a-z0-9-]+)\s*:\s*([^;{}]+);/g)) vars.set(m[1], m[2].trim());
|
|
158
|
-
const styles = {};
|
|
159
|
-
for (const b of out) if (typeof b === "string") parseBlock(b, vars, styles);
|
|
160
|
-
const byClass = {};
|
|
161
|
-
const unresolved = [];
|
|
162
|
-
for (const cls of list) {
|
|
163
|
-
const decls = styles[cls];
|
|
164
|
-
if (decls && Object.keys(decls).length > 0) {
|
|
165
|
-
byClass[cls] = Object.fromEntries(Object.entries(decls).map(([prop, values]) => [prop, values.map((value) => substituteVars(value))]));
|
|
166
|
-
} else {
|
|
167
|
-
unresolved.push(cls);
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
return { byClass, unresolved };
|
|
171
|
-
};
|
|
172
|
-
|
|
173
|
-
const resolveClassesSync = (classes) => {
|
|
174
|
-
const { byClass, unresolved } = classStyles(classes);
|
|
175
|
-
const css = {};
|
|
176
|
-
for (const decls of Object.values(byClass)) {
|
|
177
|
-
for (const [prop, values] of Object.entries(decls)) {
|
|
178
|
-
css[prop] = css[prop] || [];
|
|
179
|
-
const joined = values.join(" ");
|
|
180
|
-
if (!css[prop].includes(joined)) css[prop].push(joined);
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
return { css, unresolved };
|
|
184
|
-
};
|
|
185
|
-
|
|
186
|
-
module.exports = { resolveClasses, resolveClassesSync, classStyles, ready, available: () => true };
|
package/playgrounds/vue.js
DELETED
package/plugin.js
DELETED
package/report.js
DELETED
|
@@ -1,162 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
const TIERS = ["duplicate", "similar"];
|
|
4
|
-
|
|
5
|
-
const TIER_LABEL = {
|
|
6
|
-
duplicate: "Duplicate (confidence ≥ threshold)",
|
|
7
|
-
similar: "Similar (below duplicate threshold)",
|
|
8
|
-
};
|
|
9
|
-
|
|
10
|
-
const duplicateText = (match) => {
|
|
11
|
-
const d = match.decision;
|
|
12
|
-
return `Component \`${match.app.name}\` duplicates canonical \`${match.canon.name}\` (${match.canon.path}) — ${d.reason}. Use the canonical component instead.`;
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
const rawHtmlText = (tag, suggestion) => {
|
|
16
|
-
return `Raw <${tag}> outside the canonical packages → replace with \`${suggestion.component}\` from ${suggestion.path}.`;
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
const renderHeader = (comp) => {
|
|
20
|
-
const lines = [];
|
|
21
|
-
lines.push("# Component duplicates (component-level funnel)");
|
|
22
|
-
lines.push("");
|
|
23
|
-
lines.push(`Scanned ${comp.files} app file(s), ${comp.appCount} app component(s) against ${comp.canonCount} canonical component(s).`);
|
|
24
|
-
const dupCount = comp.matches.filter((m) => m.decision.tier === "duplicate").length;
|
|
25
|
-
const simCount = comp.matches.filter((m) => m.decision.tier === "similar").length;
|
|
26
|
-
const missingCount = (comp.missingClusters || []).reduce((n, c) => n + c.matches.length, 0);
|
|
27
|
-
lines.push(`Found ${dupCount} duplicate component(s) and ${simCount} similar component(s)${comp.dropped && comp.dropped.length > 0 ? ` (after filtering out ${comp.dropped.length} match(es))` : ""}${missingCount > 0 ? `, plus ${missingCount} component(s) grouped under ${(comp.missingClusters || []).length} potentially missing component(s)` : ""}.`);
|
|
28
|
-
lines.push("");
|
|
29
|
-
return lines;
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
const renderTierSection = (tier, rows, title = TIER_LABEL[tier]) => {
|
|
33
|
-
const lines = [];
|
|
34
|
-
lines.push(`## ${title} (${rows.length})`);
|
|
35
|
-
lines.push("");
|
|
36
|
-
lines.push("| Local component | Location | Duplicates canonical | Canonical location | Confidence | Why |");
|
|
37
|
-
lines.push("| --- | --- | --- | --- | --- | --- |");
|
|
38
|
-
const sorted = [...rows].sort((a, b) => b.decision.confidence - a.decision.confidence || a.canon.name.localeCompare(b.canon.name));
|
|
39
|
-
for (const m of sorted) {
|
|
40
|
-
lines.push(`| ${m.app.name} | \`${m.app.path}:${m.app.line}\` | ${m.canon.name} | \`${m.canon.path}\` | ${m.decision.confidence.toFixed(2)} | ${m.decision.reason} |`);
|
|
41
|
-
}
|
|
42
|
-
lines.push("");
|
|
43
|
-
return lines;
|
|
44
|
-
};
|
|
45
|
-
|
|
46
|
-
const renderMissingSection = (clusters) => {
|
|
47
|
-
if (!clusters || clusters.length === 0) return [];
|
|
48
|
-
const lines = [];
|
|
49
|
-
lines.push(`## Potentially missing component (${clusters.length})`);
|
|
50
|
-
lines.push("");
|
|
51
|
-
lines.push("Several distinct components all matched the same canonical. This usually means the codebase is missing a shared component that would unify them — not that any single one is a duplicate. Consider extracting a new canonical component for each group below.");
|
|
52
|
-
lines.push("");
|
|
53
|
-
for (const cluster of clusters) {
|
|
54
|
-
lines.push(`### ${cluster.name}`);
|
|
55
|
-
lines.push("");
|
|
56
|
-
lines.push(`All ${cluster.matches.length} components below matched canonical \`${cluster.canon.name}\` (\`${cluster.canon.path}\`). They are structurally similar to each other but distinct enough that none is a clean duplicate — a shared \`${cluster.name}\` would likely cover them.`);
|
|
57
|
-
lines.push("");
|
|
58
|
-
lines.push("| Local component | Location | Matched canonical | Confidence | Why |");
|
|
59
|
-
lines.push("| --- | --- | --- | --- | --- |");
|
|
60
|
-
for (const m of cluster.matches) {
|
|
61
|
-
lines.push(`| ${m.app.name} | \`${m.app.path}:${m.app.line}\` | ${m.canon.name} | ${m.decision.confidence.toFixed(2)} | ${m.decision.reason} |`);
|
|
62
|
-
}
|
|
63
|
-
lines.push("");
|
|
64
|
-
}
|
|
65
|
-
return lines;
|
|
66
|
-
};
|
|
67
|
-
|
|
68
|
-
const renderRawHtmlSection = (rows) => {
|
|
69
|
-
if (rows.length === 0) return [];
|
|
70
|
-
const lines = [];
|
|
71
|
-
lines.push(`## Raw HTML outside canonical packages (${rows.length})`);
|
|
72
|
-
lines.push("");
|
|
73
|
-
lines.push("| Element | Location | Replace with | From | Why |");
|
|
74
|
-
lines.push("| --- | --- | --- | --- | --- |");
|
|
75
|
-
const sorted = [...rows].sort((a, b) => a.path.localeCompare(b.path));
|
|
76
|
-
for (const r of sorted) {
|
|
77
|
-
lines.push(`| <${r.tag}> | \`${r.path}:${r.line}\` | \`${r.suggestion.component}\` | ${r.suggestion.path} | ${r.reason} |`);
|
|
78
|
-
}
|
|
79
|
-
lines.push("");
|
|
80
|
-
return lines;
|
|
81
|
-
};
|
|
82
|
-
|
|
83
|
-
const renderPartsSection = (rows, title = "Parts of components that duplicate a canonical") => {
|
|
84
|
-
if (rows.length === 0) return [];
|
|
85
|
-
const lines = [];
|
|
86
|
-
lines.push(`## ${title} (${rows.length})`);
|
|
87
|
-
lines.push("");
|
|
88
|
-
lines.push("| Part | Location | Replace with | From | Why |");
|
|
89
|
-
lines.push("| --- | --- | --- | --- | --- |");
|
|
90
|
-
const primaryConf = (r) => (r.suggestions && r.suggestions[0] ? r.suggestions[0].confidence : r.confidence) || 0;
|
|
91
|
-
const sorted = [...rows].sort((a, b) => primaryConf(b) - primaryConf(a) || a.path.localeCompare(b.path) || a.line - b.line);
|
|
92
|
-
for (const r of sorted) {
|
|
93
|
-
const s = r.suggestions || [r];
|
|
94
|
-
const primary = s[0];
|
|
95
|
-
const alt = s.length > 1 ? `; alt: \`${s[1].component}\` (${s[1].confidence.toFixed(2)})` : "";
|
|
96
|
-
lines.push(`| ${r.owner} \u203a <${r.tag}> | \`${r.path}:${r.line}-${r.endLine}\` | \`${primary.component}\` (${primary.confidence.toFixed(2)})${alt} | ${primary.path} | ${primary.reason} |`);
|
|
97
|
-
}
|
|
98
|
-
lines.push("");
|
|
99
|
-
return lines;
|
|
100
|
-
};
|
|
101
|
-
|
|
102
|
-
const renderFilteredSection = (dropped) => {
|
|
103
|
-
const lines = [];
|
|
104
|
-
const byFilter = new Map();
|
|
105
|
-
for (const d of dropped) {
|
|
106
|
-
if (!byFilter.has(d.filter)) byFilter.set(d.filter, []);
|
|
107
|
-
byFilter.get(d.filter).push(d);
|
|
108
|
-
}
|
|
109
|
-
for (const [filter, rows] of byFilter) {
|
|
110
|
-
lines.push(`## Filtered out by \`${filter}\` (${rows.length})`);
|
|
111
|
-
lines.push("");
|
|
112
|
-
lines.push("| Local component | Location | Canonical | Why dropped |");
|
|
113
|
-
lines.push("| --- | --- | --- | --- |");
|
|
114
|
-
const sorted = [...rows].sort((a, b) => a.match.canon.name.localeCompare(b.match.canon.name));
|
|
115
|
-
for (const d of sorted) {
|
|
116
|
-
lines.push(`| ${d.match.app.name} | \`${d.match.app.path}:${d.match.app.line}\` | ${d.match.canon.name} | ${d.reason} |`);
|
|
117
|
-
}
|
|
118
|
-
lines.push("");
|
|
119
|
-
}
|
|
120
|
-
return lines;
|
|
121
|
-
};
|
|
122
|
-
|
|
123
|
-
const renderComponentReport = (comp, verbose) => {
|
|
124
|
-
const lines = [];
|
|
125
|
-
const folders = comp.layerFolders || [];
|
|
126
|
-
const inLayer = (p) => folders.some((d) => p.startsWith(d));
|
|
127
|
-
const appMatches = comp.matches.filter((m) => !inLayer(m.app.path));
|
|
128
|
-
const layerMatches = comp.matches.filter((m) => inLayer(m.app.path));
|
|
129
|
-
const appParts = (comp.parts || []).filter((r) => !inLayer(r.path));
|
|
130
|
-
const layerParts = (comp.parts || []).filter((r) => inLayer(r.path));
|
|
131
|
-
lines.push(...renderHeader(comp));
|
|
132
|
-
for (const tier of TIERS) {
|
|
133
|
-
const rows = appMatches.filter((m) => m.decision.tier === tier);
|
|
134
|
-
if (rows.length === 0) continue;
|
|
135
|
-
lines.push(...renderTierSection(tier, rows));
|
|
136
|
-
}
|
|
137
|
-
const missingClusters = (comp.missingClusters || []).filter((c) => c.matches.every((m) => !inLayer(m.app.path)));
|
|
138
|
-
lines.push(...renderMissingSection(missingClusters));
|
|
139
|
-
if (comp.rawHtml && comp.rawHtml.length > 0) lines.push(...renderRawHtmlSection(comp.rawHtml));
|
|
140
|
-
const layerIdx = (p) => folders.findIndex((d) => p.startsWith(d));
|
|
141
|
-
const layerName = (d) => d.split("/").filter(Boolean).pop();
|
|
142
|
-
for (let li = 0; li < folders.length; li += 1) {
|
|
143
|
-
const seen = folders.slice(0, li).map(layerName);
|
|
144
|
-
const suffix = seen.length > 0 ? ` (vs ${seen.join(" + ")})` : "";
|
|
145
|
-
for (const tier of TIERS) {
|
|
146
|
-
const rows = layerMatches.filter((m) => layerIdx(m.app.path) === li && m.decision.tier === tier);
|
|
147
|
-
if (rows.length === 0) continue;
|
|
148
|
-
lines.push(...renderTierSection(tier, rows, `Inside ${layerName(folders[li])}: ${TIER_LABEL[tier]}${suffix}`));
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
lines.push(...renderPartsSection([...appParts, ...layerParts], "Partial duplicates (parts)"));
|
|
152
|
-
if (verbose && comp.dropped && comp.dropped.length > 0) lines.push(...renderFilteredSection(comp.dropped));
|
|
153
|
-
return lines.join("\n");
|
|
154
|
-
};
|
|
155
|
-
|
|
156
|
-
module.exports = {
|
|
157
|
-
renderComponentReport,
|
|
158
|
-
duplicateText,
|
|
159
|
-
rawHtmlText,
|
|
160
|
-
TIERS,
|
|
161
|
-
TIER_LABEL,
|
|
162
|
-
};
|
package/utils.js
DELETED
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
const fs = require("node:fs");
|
|
4
|
-
const path = require("node:path");
|
|
5
|
-
const { DEFAULT_EXTS, DEFAULT_IGNORE_DIRS } = require("./config");
|
|
6
|
-
|
|
7
|
-
const walk = (dir, exts = DEFAULT_EXTS, ignoreDirs = DEFAULT_IGNORE_DIRS) => {
|
|
8
|
-
const extSet = new Set(exts);
|
|
9
|
-
const ignoreSet = new Set(ignoreDirs);
|
|
10
|
-
const out = [];
|
|
11
|
-
const visit = (d) => {
|
|
12
|
-
let list;
|
|
13
|
-
try {
|
|
14
|
-
list = fs.readdirSync(d, { withFileTypes: true });
|
|
15
|
-
} catch {
|
|
16
|
-
return;
|
|
17
|
-
}
|
|
18
|
-
for (const entry of list) {
|
|
19
|
-
if (entry.name.startsWith(".") || ignoreSet.has(entry.name)) continue;
|
|
20
|
-
const full = path.join(d, entry.name);
|
|
21
|
-
if (entry.isDirectory()) {
|
|
22
|
-
visit(full);
|
|
23
|
-
} else if ([...extSet].some((e) => entry.name.endsWith(e))) {
|
|
24
|
-
out.push(full);
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
};
|
|
28
|
-
visit(dir);
|
|
29
|
-
return out;
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
const dedupeAndSort = (components) => {
|
|
33
|
-
const seen = new Set();
|
|
34
|
-
const out = [];
|
|
35
|
-
for (const c of components) {
|
|
36
|
-
const key = JSON.stringify({ n: c.name, ...c });
|
|
37
|
-
if (seen.has(key)) continue;
|
|
38
|
-
seen.add(key);
|
|
39
|
-
out.push(c);
|
|
40
|
-
}
|
|
41
|
-
out.sort((a, b) => (a.name + a.tag + a.path).localeCompare(b.name + b.tag + b.path));
|
|
42
|
-
return out;
|
|
43
|
-
};
|
|
44
|
-
|
|
45
|
-
const writeCatalog = (outPath, components) => {
|
|
46
|
-
fs.mkdirSync(path.dirname(outPath), { recursive: true });
|
|
47
|
-
fs.writeFileSync(outPath, JSON.stringify({ generatedAt: new Date().toISOString(), components }, null, 2) + "\n", "utf8");
|
|
48
|
-
};
|
|
49
|
-
|
|
50
|
-
const buildDirNameMap = (repoRoot, registryPath) => {
|
|
51
|
-
const map = new Map();
|
|
52
|
-
const regPath = registryPath || path.join(repoRoot, "reports", "component-registry.json");
|
|
53
|
-
if (!fs.existsSync(regPath)) return map;
|
|
54
|
-
try {
|
|
55
|
-
const reg = JSON.parse(fs.readFileSync(regPath, "utf8"));
|
|
56
|
-
for (const [name, dirs] of Object.entries((reg && reg.names) || {})) {
|
|
57
|
-
for (const d of dirs) {
|
|
58
|
-
if (!map.has(d)) map.set(d, name);
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
} catch {}
|
|
62
|
-
return map;
|
|
63
|
-
};
|
|
64
|
-
|
|
65
|
-
const componentNameFor = (fileAbs, repoRoot, dirNameMap) => {
|
|
66
|
-
const dir = path.dirname(fileAbs);
|
|
67
|
-
let name = path.basename(fileAbs).replace(/\.[^.]+$/, "");
|
|
68
|
-
const isFileScoped = /^(index|styles|types|constants|utils|hooks|test|stories)$/i.test(name);
|
|
69
|
-
let up = dir;
|
|
70
|
-
if (/^[A-Z][A-Za-z0-9]*$/.test(path.basename(dir)) && isFileScoped) {
|
|
71
|
-
name = path.basename(dir);
|
|
72
|
-
} else {
|
|
73
|
-
for (let i = 0; i < 4; i += 1) {
|
|
74
|
-
const parent = path.dirname(up);
|
|
75
|
-
if (parent === up) break;
|
|
76
|
-
const bn = path.basename(parent);
|
|
77
|
-
if (/^[A-Z][A-Za-z0-9]*$/.test(bn)) {
|
|
78
|
-
up = parent;
|
|
79
|
-
if (isFileScoped) name = bn;
|
|
80
|
-
break;
|
|
81
|
-
}
|
|
82
|
-
up = parent;
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
const relDir = path.relative(repoRoot, dir).split(path.sep).join("/");
|
|
86
|
-
const relUp = path.relative(repoRoot, up).split(path.sep).join("/");
|
|
87
|
-
const regName = dirNameMap.get(relDir) || dirNameMap.get(relUp);
|
|
88
|
-
if (regName) name = regName;
|
|
89
|
-
return name;
|
|
90
|
-
};
|
|
91
|
-
|
|
92
|
-
module.exports = { walk, dedupeAndSort, writeCatalog, buildDirNameMap, componentNameFor };
|