@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,376 @@
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.suggestFromLib = exports.fileImportSpecifiers = exports.buildLibRegistry = void 0;
27
+ const node_module_1 = require("node:module");
28
+ // Optional resolution (ts-morph/typescript, dependency package.json) is done
29
+ // lazily and gracefully; `createRequire` keeps those probes out of the import
30
+ // graph without hiding a bare `require` call.
31
+ const nodeRequire = (0, node_module_1.createRequire)(__filename);
32
+ // Lib registry for `proposeFromLib`: an inventory of named exports of the
33
+ // project's installed dependencies, so a duplicate report can suggest
34
+ // "consider `sortBy` from `lodash`" instead of (or on top of) the local
35
+ // canonical util.
36
+ //
37
+ // Nothing is hardcoded: the dependency list is read from the project's
38
+ // package.json (dependencies + devDependencies) on every build, the type
39
+ // entry of each package is resolved through its own package.json
40
+ // (types/typings, the exports map, or index.d.ts), and the exports are
41
+ // parsed from the .d.ts with ts-morph. Any library — lodash, radix, a
42
+ // private monorepo package — works the same way.
43
+ //
44
+ // The inventory is cached in os.tmpdir() keyed by the project root and
45
+ // invalidated when the root package.json mtime changes, so the parse cost
46
+ // (one ts-morph Project over all .d.ts entries) is paid once per
47
+ // dependency change, not per lint.
48
+ const fs = __importStar(require("node:fs"));
49
+ const os = __importStar(require("node:os"));
50
+ const path = __importStar(require("node:path"));
51
+ const crypto = __importStar(require("node:crypto"));
52
+ const MAX_LIBS = 80;
53
+ const MAX_EXPORTS_PER_LIB = 2000;
54
+ const BUDGET_MS = 30000;
55
+ const hash = (s) => crypto.createHash("md5").update(s).digest("hex");
56
+ const cachePathFor = (root) => path.join(os.tmpdir(), ".md-code-cache", `lib-registry-${hash(path.resolve(root))}.json`);
57
+ const readCache = (cachePath) => {
58
+ try {
59
+ const parsed = JSON.parse(fs.readFileSync(cachePath, "utf8"));
60
+ return parsed && typeof parsed.libs === "object" ? parsed : null;
61
+ }
62
+ catch {
63
+ return null;
64
+ }
65
+ };
66
+ // Resolve the .d.ts entry of an installed package: top-level types/typings,
67
+ // then the exports map ("." condition), then index.d.ts / main, then the
68
+ // @types/<name> companion package (lodash ships no types of its own).
69
+ const resolveTypesEntry = (pkgDir, pkg, name, root) => {
70
+ for (const f of [pkg.types, pkg.typings]) {
71
+ if (typeof f === "string") {
72
+ const p = path.join(pkgDir, f);
73
+ if (fs.existsSync(p))
74
+ return { path: p, typesDir: pkgDir };
75
+ }
76
+ }
77
+ const dot = pkg.exports && pkg.exports["."];
78
+ if (dot) {
79
+ const candidates = [];
80
+ if (typeof dot === "string")
81
+ candidates.push(dot);
82
+ else if (dot && typeof dot === "object") {
83
+ const d = dot;
84
+ if (typeof d.types === "string")
85
+ candidates.push(d.types);
86
+ for (const cond of ["require", "import", "default"])
87
+ if (typeof d[cond] === "string")
88
+ candidates.push(d[cond]);
89
+ for (const v of Object.values(d))
90
+ if (v && typeof v === "object" && typeof v.types === "string")
91
+ candidates.push(v.types);
92
+ }
93
+ for (const c of candidates) {
94
+ const p = path.join(pkgDir, c);
95
+ if (fs.existsSync(p))
96
+ return { path: p, typesDir: pkgDir };
97
+ }
98
+ }
99
+ for (const f of ["index.d.ts", pkg.main && pkg.main.endsWith(".js") ? pkg.main.replace(/\.js$/, ".d.ts") : null]) {
100
+ if (f) {
101
+ const p = path.join(pkgDir, f);
102
+ if (fs.existsSync(p))
103
+ return { path: p, typesDir: pkgDir };
104
+ }
105
+ }
106
+ // @types/<name> companion (lodash, express, …): the types live in a
107
+ // separate package, so the entry is @types/<name>/index.d.ts.
108
+ try {
109
+ const typesPkg = nodeRequire.resolve(`@types/${name}/package.json`, { paths: [root] });
110
+ const typesDir = path.dirname(typesPkg);
111
+ const t = JSON.parse(fs.readFileSync(typesPkg, "utf8"));
112
+ for (const f of [t.types, t.typings, "index.d.ts"]) {
113
+ if (typeof f === "string") {
114
+ const p = path.join(typesDir, f);
115
+ if (fs.existsSync(p))
116
+ return { path: p, typesDir };
117
+ }
118
+ }
119
+ }
120
+ catch {
121
+ // No @types package for this dependency — no types to parse.
122
+ }
123
+ return null;
124
+ };
125
+ // Classify a declaration node for the inventory.
126
+ const classify = (ts, d) => {
127
+ const k = d.getKind();
128
+ if (k === ts.SyntaxKind.FunctionDeclaration || k === ts.SyntaxKind.FunctionExpression || k === ts.SyntaxKind.ArrowFunction)
129
+ return "function";
130
+ if (k === ts.SyntaxKind.ClassDeclaration)
131
+ return "class";
132
+ if (k === ts.SyntaxKind.InterfaceDeclaration || k === ts.SyntaxKind.TypeAliasDeclaration)
133
+ return "type";
134
+ if (k === ts.SyntaxKind.EnumDeclaration)
135
+ return "enum";
136
+ return "value";
137
+ };
138
+ const pushDecl = (ts, items, name, d) => {
139
+ const kind = classify(ts, d);
140
+ let paramCount = null;
141
+ if (kind === "function" && typeof d.getParameters === "function")
142
+ paramCount = d.getParameters().length;
143
+ items.push({ name, kind, paramCount });
144
+ };
145
+ // Some @types packages (lodash) ship one tiny .d.ts per export next to a
146
+ // stub index.d.ts. When that happens, the file name IS the export name.
147
+ const scanTypesDir = (typesDir) => {
148
+ const items = [];
149
+ let entries = [];
150
+ try {
151
+ entries = fs.readdirSync(typesDir, { withFileTypes: true });
152
+ }
153
+ catch {
154
+ return items;
155
+ }
156
+ for (const e of entries) {
157
+ if (!e.isFile() || !e.name.endsWith(".d.ts") || e.name === "index.d.ts")
158
+ continue;
159
+ const name = e.name.slice(0, -5);
160
+ // Sub-namespace files (lodash/common/array.d.ts) are not exports.
161
+ if (name.includes("/") || name.includes("-"))
162
+ continue;
163
+ items.push({ name, kind: "value", paramCount: null });
164
+ if (items.length >= MAX_EXPORTS_PER_LIB)
165
+ break;
166
+ }
167
+ return items;
168
+ };
169
+ const isContainer = (ts, d) => {
170
+ const k = d.getKind();
171
+ return k === ts.SyntaxKind.InterfaceDeclaration || k === ts.SyntaxKind.ModuleDeclaration;
172
+ };
173
+ const buildForLib = (ts, project, libName, { path: dtsPath, typesDir }) => {
174
+ const sf = project.addSourceFileAtPath(dtsPath);
175
+ const items = [];
176
+ const decls = sf.getExportedDeclarations();
177
+ const seen = new Set();
178
+ const push = (name, d) => {
179
+ if (!name || name.startsWith("_") || seen.has(name))
180
+ return;
181
+ seen.add(name);
182
+ pushDecl(ts, items, name, d);
183
+ };
184
+ // Named exports (mobx, typescript): the export key IS the public name.
185
+ // A container export (interface/namespace) is NOT a public name — its
186
+ // members are (see below), so skip the key itself.
187
+ for (const [name, list] of decls) {
188
+ for (const d of list || []) {
189
+ if (isContainer(ts, d))
190
+ continue;
191
+ push(name, d);
192
+ }
193
+ }
194
+ // `export = <interface|namespace>` style (lodash, express): the public
195
+ // API is the container's members (LoDashStatic → sortBy, debounce, …).
196
+ for (const list of decls.values())
197
+ for (const d of list || []) {
198
+ if (!isContainer(ts, d))
199
+ continue;
200
+ const members = typeof d.getMembers === "function" ? d.getMembers() : [];
201
+ for (const m of members) {
202
+ const name = typeof m.getName === "function" ? m.getName() : "";
203
+ push(name, m);
204
+ if (items.length >= MAX_EXPORTS_PER_LIB)
205
+ break;
206
+ }
207
+ if (items.length >= MAX_EXPORTS_PER_LIB)
208
+ break;
209
+ }
210
+ // Per-file @types layout (lodash): the entry is a stub and every export
211
+ // is its own sibling .d.ts file next to a `common/` sub-namespace. Only
212
+ // used when the container carried no visible members.
213
+ if (items.length === 0 && typesDir && fs.existsSync(path.join(typesDir, "common"))) {
214
+ const scanned = scanTypesDir(typesDir);
215
+ if (scanned.length > 0)
216
+ return scanned;
217
+ }
218
+ return items;
219
+ };
220
+ // Collect dependency names from the root package.json and from workspace
221
+ // packages (apps/*, packages/*, core/*) — in a monorepo the interesting
222
+ // deps (mobx, lodash, radix) usually live in a workspace, not the root.
223
+ // Returns { deps: Map<name, dir>, stamps: {dir: mtimeMs} }.
224
+ const collectDeps = (root) => {
225
+ const deps = new Map();
226
+ const stamps = {};
227
+ const read = (dir) => {
228
+ const pkgPath = path.join(dir, "package.json");
229
+ let stat;
230
+ try {
231
+ stat = fs.statSync(pkgPath);
232
+ }
233
+ catch {
234
+ return;
235
+ }
236
+ stamps[pkgPath] = stat.mtimeMs;
237
+ let pkg;
238
+ try {
239
+ pkg = JSON.parse(fs.readFileSync(pkgPath, "utf8"));
240
+ }
241
+ catch {
242
+ return;
243
+ }
244
+ for (const [name] of Object.entries({ ...(pkg.dependencies || {}), ...(pkg.devDependencies || {}) })) {
245
+ // @types/* are type stubs for other packages, not libraries.
246
+ if (name.startsWith("@types/"))
247
+ continue;
248
+ if (!deps.has(name))
249
+ deps.set(name, dir);
250
+ }
251
+ };
252
+ read(root);
253
+ for (const group of ["apps", "packages", "core"]) {
254
+ let entries = [];
255
+ try {
256
+ entries = fs.readdirSync(path.join(root, group), { withFileTypes: true });
257
+ }
258
+ catch {
259
+ continue;
260
+ }
261
+ for (const e of entries)
262
+ if (e.isDirectory())
263
+ read(path.join(root, group, e.name));
264
+ }
265
+ return { deps, stamps };
266
+ };
267
+ // Build (or read from cache) the lib registry for a project root.
268
+ // Returns Map<libName, Array<{name, kind, paramCount}>>.
269
+ //
270
+ // The cache is PER-LIB: when the budget is hit mid-build, the libs parsed so
271
+ // far stay cached and the next lint picks up where this one stopped, so a
272
+ // big dependency tree (typescript, react…) converges over a few lints
273
+ // instead of being re-parsed from scratch every time.
274
+ const buildLibRegistry = (root) => {
275
+ const empty = new Map();
276
+ const cachePath = cachePathFor(root);
277
+ const { deps, stamps } = collectDeps(root);
278
+ if (deps.size === 0)
279
+ return empty;
280
+ const cached = readCache(cachePath);
281
+ const libs = cached && cached.stamps && JSON.stringify(cached.stamps) === JSON.stringify(stamps) && cached.libs ? cached.libs : {};
282
+ if (deps.size === Object.keys(libs).length)
283
+ return new Map(Object.entries(libs));
284
+ const started = Date.now();
285
+ let budgetHit = false;
286
+ let { Project, ts } = {};
287
+ try {
288
+ ({ Project } = nodeRequire("ts-morph"));
289
+ ts = nodeRequire("typescript");
290
+ }
291
+ catch (err) {
292
+ console.warn(`[lib-registry] ts-morph/typescript unavailable: ${err && err.message ? err.message : err}`);
293
+ return new Map(Object.entries(libs));
294
+ }
295
+ const project = new Project({ skipAddingFilesFromTsConfig: true });
296
+ for (const [name, fromDir] of deps) {
297
+ if (libs[name])
298
+ continue;
299
+ if (Object.keys(libs).length >= MAX_LIBS)
300
+ break;
301
+ if (Date.now() - started > BUDGET_MS) {
302
+ budgetHit = true;
303
+ break;
304
+ }
305
+ try {
306
+ const pkgJsonPath = nodeRequire.resolve(`${name}/package.json`, { paths: [fromDir, root] });
307
+ const depPkg = JSON.parse(fs.readFileSync(pkgJsonPath, "utf8"));
308
+ const dtsPath = resolveTypesEntry(path.dirname(pkgJsonPath), depPkg, name, root);
309
+ if (!dtsPath) {
310
+ libs[name] = [];
311
+ continue;
312
+ }
313
+ const items = buildForLib(ts, project, name, dtsPath);
314
+ libs[name] = items.length > 0 ? items : [];
315
+ }
316
+ catch {
317
+ // Unresolvable or unparseable package — leave it uncached so a
318
+ // transient failure (disk busy, half-installed node_modules) is
319
+ // retried on the next lint.
320
+ }
321
+ }
322
+ try {
323
+ fs.mkdirSync(path.dirname(cachePath), { recursive: true });
324
+ fs.writeFileSync(cachePath, JSON.stringify({ stamps, libs }), "utf8");
325
+ }
326
+ catch {
327
+ // Cache write failure is not fatal: the registry is returned in
328
+ // memory, the next lint simply rebuilds it.
329
+ }
330
+ if (budgetHit)
331
+ console.warn("[lib-registry] budget exhausted, remaining libs will be parsed on the next lint");
332
+ return new Map(Object.entries(libs));
333
+ };
334
+ exports.buildLibRegistry = buildLibRegistry;
335
+ // The bare specifiers a file imports (from/import()/require) — used by the
336
+ // wrapper filter: if the candidate file already imports the lib, the local
337
+ // function is likely EXTENDING it, not duplicating it.
338
+ const fileImportSpecifiers = (sourceText) => {
339
+ const out = new Set();
340
+ if (typeof sourceText !== "string")
341
+ return out;
342
+ const re = /(?:from\s*|import\s*\(\s*|require\s*\(\s*)["']([^"']+)["']/g;
343
+ let m;
344
+ while ((m = re.exec(sourceText)) !== null) {
345
+ const spec = m[1];
346
+ if (!spec.startsWith(".")) {
347
+ const parts = spec.split("/");
348
+ out.add(spec.startsWith("@") ? parts.slice(0, 2).join("/") : parts[0]);
349
+ }
350
+ }
351
+ return out;
352
+ };
353
+ exports.fileImportSpecifiers = fileImportSpecifiers;
354
+ // Suggest lib exports whose name matches the candidate (case-insensitive).
355
+ // Returns up to `max` {lib, name, kind} suggestions, skipping libs the file
356
+ // already imports (extension, not duplication).
357
+ const suggestFromLib = (candidateName, libRegistry, fileImports = new Set(), max = 3) => {
358
+ const lower = String(candidateName || "").toLowerCase();
359
+ if (!lower)
360
+ return [];
361
+ const out = [];
362
+ for (const [lib, items] of libRegistry) {
363
+ if (fileImports.has(lib))
364
+ continue;
365
+ for (const it of items) {
366
+ if (it.name.toLowerCase() === lower) {
367
+ out.push({ lib, name: it.name, kind: it.kind });
368
+ break;
369
+ }
370
+ }
371
+ if (out.length >= max)
372
+ break;
373
+ }
374
+ return out.slice(0, max);
375
+ };
376
+ exports.suggestFromLib = suggestFromLib;
@@ -0,0 +1,7 @@
1
+ declare const enabled: () => boolean;
2
+ declare const enable: (file: any) => void;
3
+ declare const disable: () => void;
4
+ declare const write: (entry: any) => void;
5
+ declare const stage: (name: any, data: any) => void;
6
+ declare const flush: () => void;
7
+ export { enable, disable, enabled, stage, write, flush };
package/dist/logger.js ADDED
@@ -0,0 +1,70 @@
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.flush = exports.write = exports.stage = exports.enabled = exports.disable = exports.enable = void 0;
27
+ const fs = __importStar(require("node:fs"));
28
+ const path = __importStar(require("node:path"));
29
+ const state = {
30
+ enabled: false,
31
+ stream: null,
32
+ file: null,
33
+ };
34
+ const enabled = () => state.enabled;
35
+ exports.enabled = enabled;
36
+ const enable = (file) => {
37
+ if (!file)
38
+ return;
39
+ const abs = path.resolve(process.cwd(), file);
40
+ fs.mkdirSync(path.dirname(abs), { recursive: true });
41
+ if (state.stream)
42
+ state.stream.end();
43
+ state.stream = fs.createWriteStream(abs, { flags: "w" });
44
+ state.file = abs;
45
+ state.enabled = true;
46
+ };
47
+ exports.enable = enable;
48
+ const disable = () => {
49
+ if (state.stream)
50
+ state.stream.end();
51
+ state.stream = null;
52
+ state.file = null;
53
+ state.enabled = false;
54
+ };
55
+ exports.disable = disable;
56
+ const write = (entry) => {
57
+ if (!state.enabled || !state.stream)
58
+ return;
59
+ state.stream.write(`${JSON.stringify(entry)}\n`);
60
+ };
61
+ exports.write = write;
62
+ const stage = (name, data) => {
63
+ write({ ts: Date.now(), stage: name, ...data });
64
+ };
65
+ exports.stage = stage;
66
+ const flush = () => {
67
+ if (state.stream)
68
+ state.stream.end();
69
+ };
70
+ exports.flush = flush;
package/dist/main.d.ts ADDED
@@ -0,0 +1,25 @@
1
+ #!/usr/bin/env node
2
+ import { buildCandidate } from "./normalize/candidate.js";
3
+ declare const frameworkMatcher: any;
4
+ declare const parseComponents: (files: any, canonNames: any, config: any, role?: string) => any[];
5
+ declare const matchPairs: (appComponents: any, canonComponents: any, config: any) => any[];
6
+ declare const applyFilters: (matches: any) => {
7
+ kept: any[];
8
+ dropped: any[];
9
+ };
10
+ declare const collectRawHtml: (appFiles: any, canonComponents: any, config: any, canonNames: any) => any[];
11
+ declare const comparableCanons: (part: any, canonComponents: any) => any;
12
+ declare const findParts: (file: any, rel: any, canonComponents: any, config: any, canonNames: any) => any[];
13
+ declare const buildComponentReport: (args: any, repoRoot: any, roots: any, shouldSkip: any, config: any, registry: any, catalogComponents: any) => Promise<{
14
+ matches: any[];
15
+ dropped: any[];
16
+ missingClusters: any[];
17
+ rawHtml: any[];
18
+ parts: any[];
19
+ layerFolders: any;
20
+ files: any;
21
+ canonCount: number;
22
+ appCount: number;
23
+ candidates: any[];
24
+ }>;
25
+ export { buildCandidate, parseComponents, matchPairs, applyFilters, collectRawHtml, findParts, frameworkMatcher, comparableCanons, buildComponentReport, };