@snap/valdi 1.0.8 → 1.1.5

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 (121) hide show
  1. package/.bootstrap/apps/cli_application/BUILD.bazel.template +7 -0
  2. package/.bootstrap/apps/cli_application/modules/{{MODULE_NAME}}/BUILD.bazel.template +11 -0
  3. package/.bootstrap/apps/cli_application/modules/{{MODULE_NAME}}/src/index.ts +1 -0
  4. package/.bootstrap/apps/ui_application/.eslint.rc +27 -0
  5. package/.bootstrap/apps/ui_application/BUILD.bazel.template +19 -0
  6. package/.bootstrap/apps/ui_application/modules/{{MODULE_NAME}}/BUILD.bazel.template +21 -0
  7. package/.bootstrap/apps/ui_application/modules/{{MODULE_NAME}}/res/valdi@3x.png +0 -0
  8. package/.bootstrap/apps/ui_application/modules/{{MODULE_NAME}}/src/App.tsx +133 -0
  9. package/.bootstrap/apps/ui_application/package.json +24 -0
  10. package/.bootstrap/modules/polyglot_bridge_module/BUILD.bazel.template +54 -0
  11. package/.bootstrap/modules/polyglot_bridge_module/android/CalculatorModuleFactory.kt.template +18 -0
  12. package/.bootstrap/modules/polyglot_bridge_module/ios/SCCCalculatorModuleFactory.m.template +31 -0
  13. package/.bootstrap/modules/polyglot_bridge_module/src/Calculator.d.ts +4 -0
  14. package/.bootstrap/modules/polyglot_bridge_module/web/Calculator.ts +11 -0
  15. package/.bootstrap/modules/polyglot_bridge_module/web/tsconfig.json +16 -0
  16. package/.bootstrap/modules/polyglot_view_module/BUILD.bazel.template +75 -0
  17. package/.bootstrap/modules/polyglot_view_module/android/PolyglotNativeView.kt.template +41 -0
  18. package/.bootstrap/modules/polyglot_view_module/android/PolyglotNativeViewAttributesBinder.kt.template +17 -0
  19. package/.bootstrap/modules/polyglot_view_module/ios/SCPolyglotView.h +8 -0
  20. package/.bootstrap/modules/polyglot_view_module/ios/SCPolyglotView.m +23 -0
  21. package/.bootstrap/modules/polyglot_view_module/macos/SCPolyglotView.h +8 -0
  22. package/.bootstrap/modules/polyglot_view_module/macos/SCPolyglotView.m +23 -0
  23. package/.bootstrap/modules/polyglot_view_module/src/PolyglotCustomView.tsx.template +23 -0
  24. package/.bootstrap/modules/polyglot_view_module/web/PolyglotWeb.ts.template +30 -0
  25. package/.bootstrap/modules/polyglot_view_module/web/tsconfig.json +16 -0
  26. package/.bootstrap/modules/ui_component/BUILD.bazel.template +34 -0
  27. package/.bootstrap/modules/ui_component/src/NewModuleComponent.tsx +45 -0
  28. package/.metadata/.bazelrc.template +92 -0
  29. package/.metadata/.bazelversion.template +1 -0
  30. package/.metadata/.editorconfig.template +37 -0
  31. package/.metadata/.eslintrc.js.template +27 -0
  32. package/.metadata/.gitignore.template +4 -0
  33. package/.metadata/.prettierrc.json.template +7 -0
  34. package/.metadata/.watchmanconfig.template +8 -0
  35. package/.metadata/AGENTS.md.template +16 -0
  36. package/.metadata/MODULE.bazel.template +62 -0
  37. package/.metadata/README.md.template +31 -0
  38. package/.metadata/config.yaml.template +1 -0
  39. package/.metadata/package.json.template +23 -0
  40. package/.metadata/skill-reference.tsx.template +8 -0
  41. package/.metadata/skill-tests-BUILD.bazel.template +21 -0
  42. package/.metadata/skill-tests-README.md.template +17 -0
  43. package/.metadata/skill.md.template +27 -0
  44. package/bundled-skills/registry.json +14 -2
  45. package/bundled-skills/skills/valdi-animations/skill.md +197 -0
  46. package/bundled-skills/skills/valdi-async/tests/src/reference.tsx +1 -1
  47. package/bundled-skills/skills/valdi-bazel/skill.md +21 -2
  48. package/bundled-skills/skills/valdi-component-dedup/skill.md +263 -0
  49. package/bundled-skills/skills/valdi-component-tests/tests/test/ProfileCardTest.spec.tsx +1 -1
  50. package/bundled-skills/skills/valdi-custom-view/skill.md +49 -5
  51. package/bundled-skills/skills/valdi-error-handling/skill.md +238 -0
  52. package/bundled-skills/skills/valdi-gestures/skill.md +198 -0
  53. package/bundled-skills/skills/valdi-inspect/skill.md +217 -0
  54. package/bundled-skills/skills/valdi-localization/skill.md +142 -0
  55. package/bundled-skills/skills/valdi-mock-breakdown/skill.md +327 -0
  56. package/bundled-skills/skills/valdi-mock-iterate/skill.md +216 -0
  57. package/bundled-skills/skills/valdi-mock-to-module/scripts/diff.py +392 -0
  58. package/bundled-skills/skills/valdi-mock-to-module/scripts/extract_colors.py +277 -0
  59. package/bundled-skills/skills/valdi-mock-to-module/scripts/find_icon.py +303 -0
  60. package/bundled-skills/skills/valdi-mock-to-module/scripts/snapshot-and-diff.sh +53 -0
  61. package/bundled-skills/skills/valdi-mock-to-module/scripts/test_diff.py +207 -0
  62. package/bundled-skills/skills/valdi-mock-to-module/scripts/test_extract_colors.py +167 -0
  63. package/bundled-skills/skills/valdi-mock-to-module/scripts/test_find_icon.py +188 -0
  64. package/bundled-skills/skills/valdi-mock-to-module/scripts/watch-and-diff.sh +181 -0
  65. package/bundled-skills/skills/valdi-mock-to-module/skill.md +451 -0
  66. package/bundled-skills/skills/valdi-navigation/skill.md +187 -0
  67. package/bundled-skills/skills/valdi-overview/skill.md +7 -4
  68. package/bundled-skills/skills/valdi-perf/skill.md +223 -0
  69. package/bundled-skills/skills/valdi-polyglot-module/skill.md +131 -12
  70. package/bundled-skills/skills/valdi-preview/skill.md +303 -0
  71. package/bundled-skills/skills/valdi-profile/skill.md +126 -0
  72. package/bundled-skills/skills/valdi-setup/skill.md +55 -5
  73. package/bundled-skills/skills/valdi-testing/skill.md +23 -7
  74. package/bundled-skills/skills/valdi-tsx/skill.md +69 -5
  75. package/bundled-skills/skills/valdi-tsx/tests/src/reference.tsx +29 -5
  76. package/dist/commands/agentCheck.js +184 -0
  77. package/dist/commands/analyze.js +16 -0
  78. package/dist/commands/analyze_commands/duplicates.js +134 -0
  79. package/dist/commands/bootstrap.js +57 -73
  80. package/dist/commands/doctor.js +40 -203
  81. package/dist/commands/hotreload.js +15 -0
  82. package/dist/commands/inspect.js +16 -0
  83. package/dist/commands/inspect_commands/contexts.js +55 -0
  84. package/dist/commands/inspect_commands/devices.js +53 -0
  85. package/dist/commands/inspect_commands/heap.js +59 -0
  86. package/dist/commands/inspect_commands/select.js +43 -0
  87. package/dist/commands/inspect_commands/snapshot.js +129 -0
  88. package/dist/commands/inspect_commands/snapshot.spec.js +105 -0
  89. package/dist/commands/inspect_commands/status.js +68 -0
  90. package/dist/commands/inspect_commands/tree.js +86 -0
  91. package/dist/commands/preview.js +81 -0
  92. package/dist/commands/profile.js +16 -0
  93. package/dist/commands/profile_commands/capture.js +106 -0
  94. package/dist/commands/projectsync.js +9 -7
  95. package/dist/commands/skills_commands/install.js +6 -1
  96. package/dist/commands/skills_commands/update.js +2 -1
  97. package/dist/core/analyze/clusterer.js +150 -0
  98. package/dist/core/analyze/fingerprint.js +2 -0
  99. package/dist/core/analyze/knownPatterns.js +76 -0
  100. package/dist/core/analyze/parser.js +177 -0
  101. package/dist/core/analyze/reporter.js +83 -0
  102. package/dist/core/analyze/scanner.js +172 -0
  103. package/dist/core/analyze/similarity.js +56 -0
  104. package/dist/core/constants.js +1 -1
  105. package/dist/core/packageFiles.spec.js +29 -0
  106. package/dist/preview/previewGenerator.js +240 -0
  107. package/dist/preview/previewGenerator.spec.js +203 -0
  108. package/dist/preview/viewModelParser.js +86 -0
  109. package/dist/preview/viewModelParser.spec.js +171 -0
  110. package/dist/setup/DevSetupHelper.js +0 -51
  111. package/dist/setup/linuxSetup.js +0 -2
  112. package/dist/setup/macOSSetup.js +1 -4
  113. package/dist/utils/BazelClient.js +15 -0
  114. package/dist/utils/daemonClient.js +344 -0
  115. package/dist/utils/hermesClient.js +252 -0
  116. package/dist/utils/skillsAdapters.js +86 -5
  117. package/dist/utils/skillsAdapters.spec.js +60 -0
  118. package/dist/utils/skillsRegistry.js +8 -0
  119. package/dist/utils/stringUtils.spec.js +1 -1
  120. package/package.json +30 -12
  121. package/dist/setup/versions.js +0 -8
@@ -0,0 +1,150 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.clusterFingerprints = clusterFingerprints;
4
+ const scanner_1 = require("./scanner");
5
+ const similarity_1 = require("./similarity");
6
+ function clusterFingerprints(fingerprints, config, threshold) {
7
+ const nonSharedFingerprints = fingerprints.filter(fp => !(0, scanner_1.isSharedLibFile)(fp.filePath, config));
8
+ const buckets = bucketBySharedImports(nonSharedFingerprints);
9
+ const allPairs = [];
10
+ for (const bucket of buckets.values()) {
11
+ if (bucket.length < 2)
12
+ continue;
13
+ for (let i = 0; i < bucket.length; i++) {
14
+ for (let j = i + 1; j < bucket.length; j++) {
15
+ if (bucket[i].moduleName === bucket[j].moduleName)
16
+ continue;
17
+ const similarity = (0, similarity_1.computeSimilarity)(bucket[i], bucket[j]);
18
+ if (similarity >= threshold) {
19
+ allPairs.push({ a: bucket[i], b: bucket[j], similarity });
20
+ }
21
+ }
22
+ }
23
+ }
24
+ const clusters = singleLinkageMerge(allPairs, threshold);
25
+ return clusters
26
+ .filter(c => c.length >= 2)
27
+ .map((cluster, idx) => buildCluster(idx, cluster))
28
+ .sort((a, b) => b.files.length - a.files.length);
29
+ }
30
+ function bucketBySharedImports(fingerprints) {
31
+ const buckets = new Map();
32
+ for (const fp of fingerprints) {
33
+ const key = fp.sharedLibImports.length > 0 ? [...fp.sharedLibImports].sort().join('|') : '__no_shared_imports__';
34
+ let bucket = buckets.get(key);
35
+ if (!bucket) {
36
+ bucket = [];
37
+ buckets.set(key, bucket);
38
+ }
39
+ bucket.push(fp);
40
+ }
41
+ const noShared = buckets.get('__no_shared_imports__');
42
+ if (noShared && noShared.length > 0) {
43
+ const subBuckets = bucketByRenderSignature(noShared);
44
+ buckets.delete('__no_shared_imports__');
45
+ for (const [key, bucket] of subBuckets) {
46
+ buckets.set(`render:${key}`, bucket);
47
+ }
48
+ }
49
+ return buckets;
50
+ }
51
+ function bucketByRenderSignature(fingerprints) {
52
+ const buckets = new Map();
53
+ for (const fp of fingerprints) {
54
+ const nativeElements = fp.renderElements.filter(el => el === el.toLowerCase());
55
+ const key = nativeElements.length > 0 ? [...new Set(nativeElements)].sort().join('|') : '__misc__';
56
+ let bucket = buckets.get(key);
57
+ if (!bucket) {
58
+ bucket = [];
59
+ buckets.set(key, bucket);
60
+ }
61
+ bucket.push(fp);
62
+ }
63
+ return buckets;
64
+ }
65
+ function singleLinkageMerge(pairs, _threshold) {
66
+ const parent = new Map();
67
+ const nodes = new Map();
68
+ function find(x) {
69
+ let root = x;
70
+ while (parent.get(root) !== root)
71
+ root = parent.get(root);
72
+ let curr = x;
73
+ while (curr !== root) {
74
+ const next = parent.get(curr);
75
+ parent.set(curr, root);
76
+ curr = next;
77
+ }
78
+ return root;
79
+ }
80
+ function union(x, y) {
81
+ const rx = find(x);
82
+ const ry = find(y);
83
+ if (rx !== ry)
84
+ parent.set(rx, ry);
85
+ }
86
+ for (const { a, b } of pairs) {
87
+ if (!parent.has(a.filePath))
88
+ parent.set(a.filePath, a.filePath);
89
+ if (!parent.has(b.filePath))
90
+ parent.set(b.filePath, b.filePath);
91
+ nodes.set(a.filePath, a);
92
+ nodes.set(b.filePath, b);
93
+ union(a.filePath, b.filePath);
94
+ }
95
+ const clusters = new Map();
96
+ for (const [filePath, fp] of nodes) {
97
+ const root = find(filePath);
98
+ let cluster = clusters.get(root);
99
+ if (!cluster) {
100
+ cluster = [];
101
+ clusters.set(root, cluster);
102
+ }
103
+ cluster.push(fp);
104
+ }
105
+ return [...clusters.values()];
106
+ }
107
+ function buildCluster(id, members) {
108
+ let totalSim = 0;
109
+ let pairCount = 0;
110
+ for (let i = 0; i < members.length; i++) {
111
+ for (let j = i + 1; j < members.length; j++) {
112
+ totalSim += (0, similarity_1.computeSimilarity)(members[i], members[j]);
113
+ pairCount++;
114
+ }
115
+ }
116
+ const allVmProps = members.map(m => m.viewModelProps);
117
+ const sharedVmProps = intersectAll(allVmProps);
118
+ const allImports = members.map(m => m.importPaths);
119
+ const sharedImports = intersectAll(allImports);
120
+ const avgSimilarity = pairCount > 0 ? totalSim / pairCount : 0;
121
+ return {
122
+ id,
123
+ avgSimilarity: Math.round(avgSimilarity * 1000) / 1000,
124
+ files: members.map(m => ({ path: m.filePath, module: m.moduleName, className: m.className })),
125
+ sharedViewModelProps: sharedVmProps,
126
+ sharedImports,
127
+ suggestedExtraction: suggestExtraction(members, sharedVmProps, sharedImports),
128
+ };
129
+ }
130
+ function intersectAll(arrays) {
131
+ if (arrays.length === 0)
132
+ return [];
133
+ let result = new Set(arrays[0]);
134
+ for (let i = 1; i < arrays.length; i++) {
135
+ const current = new Set(arrays[i]);
136
+ result = new Set([...result].filter(x => current.has(x)));
137
+ }
138
+ return [...result];
139
+ }
140
+ function suggestExtraction(members, sharedProps, sharedImports) {
141
+ const allStateful = members.every(m => m.flags.isStateful);
142
+ const allLoading = members.every(m => m.flags.hasLoadingState);
143
+ if (allLoading)
144
+ return 'Extract async state container with loading/error/content rendering';
145
+ if (allStateful && sharedProps.length >= 3)
146
+ return `Extract stateful component with shared props: ${sharedProps.slice(0, 5).join(', ')}`;
147
+ if (sharedImports.length >= 2)
148
+ return `Extract shared component reusing: ${sharedImports.slice(0, 3).join(', ')}`;
149
+ return `Extract shared pattern across ${members.length} modules`;
150
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,76 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.detectKnownPatterns = detectKnownPatterns;
4
+ const scanner_1 = require("./scanner");
5
+ const DETECTORS = {
6
+ async: detectAsyncStatePattern,
7
+ button: detectButtonWrapperPattern,
8
+ shimmer: detectShimmerPattern,
9
+ };
10
+ function detectKnownPatterns(fingerprints, config, patternFilter) {
11
+ const nonShared = fingerprints.filter(fp => !(0, scanner_1.isSharedLibFile)(fp.filePath, config));
12
+ const results = [];
13
+ const detectorsToRun = patternFilter ? { [patternFilter]: DETECTORS[patternFilter] } : DETECTORS;
14
+ for (const [name, detector] of Object.entries(detectorsToRun)) {
15
+ if (!detector)
16
+ continue;
17
+ const match = detector(nonShared, config);
18
+ if (match)
19
+ results.push(match);
20
+ }
21
+ return results.sort((a, b) => severityRank(a.severity) - severityRank(b.severity));
22
+ }
23
+ function severityRank(s) {
24
+ return s === 'HIGH' ? 0 : s === 'MEDIUM' ? 1 : 2;
25
+ }
26
+ function detectAsyncStatePattern(fingerprints, _config) {
27
+ const loadingOnly = fingerprints.filter(fp => fp.flags.hasLoadingState);
28
+ const existingImpls = fingerprints.filter(fp => fp.className.includes('AsyncContentContainer') || fp.className.includes('AsyncStateContainer'));
29
+ if (loadingOnly.length < 3)
30
+ return undefined;
31
+ return {
32
+ patternName: 'Async State Container',
33
+ severity: loadingOnly.length >= 50 ? 'HIGH' : loadingOnly.length >= 15 ? 'MEDIUM' : 'LOW',
34
+ matchCount: loadingOnly.length,
35
+ files: loadingOnly.map(fp => fp.filePath),
36
+ existingImplementations: existingImpls.map(fp => fp.filePath),
37
+ recommendation: `${loadingOnly.length} components implement loading/error/content state machines. ` +
38
+ (existingImpls.length > 0
39
+ ? `${existingImpls.length} shared implementation(s) already exist — consolidate into one and migrate consumers.`
40
+ : `Extract a generic AsyncStateContainer to the shared component library.`),
41
+ };
42
+ }
43
+ function detectButtonWrapperPattern(fingerprints, _config) {
44
+ const buttonComponentNames = ['CoreButton', 'PillButton'];
45
+ const matches = fingerprints.filter(fp => {
46
+ const importsButton = fp.sharedLibImports.some(imp => buttonComponentNames.some(name => imp.includes(name))) ||
47
+ fp.importPaths.some(imp => buttonComponentNames.some(name => imp.includes(name)));
48
+ const isWrapper = fp.renderElements.length <= 5 && fp.className.toLowerCase().includes('button');
49
+ return importsButton && isWrapper;
50
+ });
51
+ if (matches.length < 5)
52
+ return undefined;
53
+ return {
54
+ patternName: 'Button Wrapper',
55
+ severity: matches.length >= 30 ? 'HIGH' : matches.length >= 10 ? 'MEDIUM' : 'LOW',
56
+ matchCount: matches.length,
57
+ files: matches.map(fp => fp.filePath),
58
+ existingImplementations: [],
59
+ recommendation: `${matches.length} thin button wrapper components found. Add preset enums to the shared button component instead of per-module wrappers.`,
60
+ };
61
+ }
62
+ function detectShimmerPattern(fingerprints, _config) {
63
+ const matches = fingerprints.filter(fp => fp.flags.usesAnimationShimmer ||
64
+ fp.className.toLowerCase().includes('shimmer') ||
65
+ fp.className.toLowerCase().includes('skeleton'));
66
+ if (matches.length < 3)
67
+ return undefined;
68
+ return {
69
+ patternName: 'Shimmer / Skeleton Layout',
70
+ severity: matches.length >= 20 ? 'HIGH' : matches.length >= 8 ? 'MEDIUM' : 'LOW',
71
+ matchCount: matches.length,
72
+ files: matches.map(fp => fp.filePath),
73
+ existingImplementations: [],
74
+ recommendation: `${matches.length} shimmer/skeleton components found. Extract a configurable ShimmerLayout to the shared component library.`,
75
+ };
76
+ }
@@ -0,0 +1,177 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.parseFile = parseFile;
4
+ const tslib_1 = require("tslib");
5
+ const fs = tslib_1.__importStar(require("fs"));
6
+ const ts = tslib_1.__importStar(require("typescript"));
7
+ const scanner_1 = require("./scanner");
8
+ function parseFile(filePath, config) {
9
+ let content;
10
+ try {
11
+ content = fs.readFileSync(filePath, 'utf8');
12
+ }
13
+ catch {
14
+ return undefined;
15
+ }
16
+ const sourceFile = ts.createSourceFile(filePath, content, ts.ScriptTarget.Latest, false, ts.ScriptKind.TSX);
17
+ const imports = extractImports(sourceFile);
18
+ const sharedLibImports = imports.filter(imp => isSharedLibImport(imp, config));
19
+ const className = findComponentClassName(sourceFile);
20
+ if (!className)
21
+ return undefined;
22
+ const viewModelProps = extractViewModelProps(sourceFile);
23
+ const stateProps = extractStateProps(sourceFile);
24
+ const renderElements = extractRenderElements(sourceFile);
25
+ const flags = detectFlags(sourceFile, content, imports);
26
+ return {
27
+ filePath,
28
+ moduleName: (0, scanner_1.extractModuleName)(filePath, config) ?? 'unknown',
29
+ className,
30
+ viewModelProps,
31
+ stateProps,
32
+ importPaths: imports,
33
+ sharedLibImports,
34
+ renderElements,
35
+ flags,
36
+ };
37
+ }
38
+ function extractImports(sourceFile) {
39
+ const imports = [];
40
+ for (const statement of sourceFile.statements) {
41
+ if (ts.isImportDeclaration(statement) &&
42
+ statement.moduleSpecifier &&
43
+ ts.isStringLiteral(statement.moduleSpecifier)) {
44
+ imports.push(statement.moduleSpecifier.text);
45
+ }
46
+ }
47
+ return imports;
48
+ }
49
+ function isSharedLibImport(importPath, config) {
50
+ return config.sharedLibNames.some(name => importPath.startsWith(`${name}/`) || importPath === name);
51
+ }
52
+ function findComponentClassName(sourceFile) {
53
+ for (const statement of sourceFile.statements) {
54
+ if (!ts.isClassDeclaration(statement) || !statement.name)
55
+ continue;
56
+ if (statement.heritageClauses) {
57
+ for (const clause of statement.heritageClauses) {
58
+ if (clause.token !== ts.SyntaxKind.ExtendsKeyword)
59
+ continue;
60
+ for (const type of clause.types) {
61
+ const text = type.expression.getText(sourceFile);
62
+ if (text === 'Component' || text === 'StatefulComponent') {
63
+ return statement.name.text;
64
+ }
65
+ }
66
+ }
67
+ }
68
+ }
69
+ return undefined;
70
+ }
71
+ function extractViewModelProps(sourceFile) {
72
+ const props = [];
73
+ for (const statement of sourceFile.statements) {
74
+ if (!ts.isInterfaceDeclaration(statement))
75
+ continue;
76
+ const name = statement.name.text;
77
+ if (!name.endsWith('ViewModel') && !name.endsWith('VM') && !name.endsWith('Props'))
78
+ continue;
79
+ for (const member of statement.members) {
80
+ if (ts.isPropertySignature(member) && member.name && ts.isIdentifier(member.name)) {
81
+ props.push(member.name.text);
82
+ }
83
+ }
84
+ if (props.length > 0)
85
+ break;
86
+ }
87
+ return props;
88
+ }
89
+ function extractStateProps(sourceFile) {
90
+ const props = [];
91
+ for (const statement of sourceFile.statements) {
92
+ if (!ts.isInterfaceDeclaration(statement))
93
+ continue;
94
+ const name = statement.name.text;
95
+ if (!name.endsWith('State') && !name.includes('State'))
96
+ continue;
97
+ if (name.endsWith('ViewModel') || name.endsWith('VM'))
98
+ continue;
99
+ for (const member of statement.members) {
100
+ if (ts.isPropertySignature(member) && member.name && ts.isIdentifier(member.name)) {
101
+ props.push(member.name.text);
102
+ }
103
+ }
104
+ if (props.length > 0)
105
+ break;
106
+ }
107
+ return props;
108
+ }
109
+ function extractRenderElements(sourceFile) {
110
+ const elements = [];
111
+ function visit(node) {
112
+ if (ts.isJsxOpeningElement(node) || ts.isJsxSelfClosingElement(node)) {
113
+ const tagName = node.tagName.getText(sourceFile);
114
+ elements.push(tagName);
115
+ }
116
+ ts.forEachChild(node, visit);
117
+ }
118
+ const onRender = findMethod(sourceFile, 'onRender');
119
+ if (onRender) {
120
+ ts.forEachChild(onRender, visit);
121
+ }
122
+ return elements;
123
+ }
124
+ function findMethod(sourceFile, methodName) {
125
+ for (const statement of sourceFile.statements) {
126
+ if (!ts.isClassDeclaration(statement))
127
+ continue;
128
+ for (const member of statement.members) {
129
+ if (ts.isMethodDeclaration(member) &&
130
+ member.name &&
131
+ ts.isIdentifier(member.name) &&
132
+ member.name.text === methodName) {
133
+ return member.body;
134
+ }
135
+ }
136
+ }
137
+ return undefined;
138
+ }
139
+ function detectFlags(sourceFile, content, imports) {
140
+ const hasLoadingKeywords = /\bloading\b/i.test(content) &&
141
+ (/\bshimmer\b/i.test(content) ||
142
+ /\bspinner\b/i.test(content) ||
143
+ /isLoading\b/.test(content) ||
144
+ /\bLoadingState\b/.test(content));
145
+ const hasErrorKeywords = /\berror\b/i.test(content) &&
146
+ (/\bretry\b/i.test(content) || /\berrorState\b/.test(content) || /\bshowError\b/i.test(content));
147
+ const hasLoadingEnum = /loading|loaded|error|empty/i.test(content) && /enum\s+\w*[Ss]tate/i.test(content);
148
+ const usesPromise = imports.some(imp => imp.includes('CancelablePromise')) || /\bCancelablePromise\b/.test(content);
149
+ const usesObservable = imports.some(imp => imp.includes('Observable') || imp.includes('observable')) || /\bObservable\b/.test(content);
150
+ const usesAnimationShimmer = imports.some(imp => imp.includes('AnimationShimmer')) || /\bAnimationShimmer\b/.test(content);
151
+ let isStateful = false;
152
+ let extendsComponent = false;
153
+ for (const statement of sourceFile.statements) {
154
+ if (!ts.isClassDeclaration(statement) || !statement.heritageClauses)
155
+ continue;
156
+ for (const clause of statement.heritageClauses) {
157
+ if (clause.token !== ts.SyntaxKind.ExtendsKeyword)
158
+ continue;
159
+ for (const type of clause.types) {
160
+ const text = type.expression.getText(sourceFile);
161
+ if (text === 'StatefulComponent')
162
+ isStateful = true;
163
+ if (text === 'Component' || text === 'StatefulComponent')
164
+ extendsComponent = true;
165
+ }
166
+ }
167
+ }
168
+ return {
169
+ hasLoadingState: hasLoadingKeywords || hasLoadingEnum,
170
+ hasErrorState: hasErrorKeywords,
171
+ usesPromise,
172
+ usesObservable,
173
+ usesAnimationShimmer,
174
+ isStateful,
175
+ extendsComponent,
176
+ };
177
+ }
@@ -0,0 +1,83 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.printHumanReport = printHumanReport;
4
+ exports.formatJsonReport = formatJsonReport;
5
+ const constants_1 = require("../constants");
6
+ const logUtils_1 = require("../../utils/logUtils");
7
+ function printHumanReport(report, verbose) {
8
+ console.log((0, logUtils_1.wrapInColor)('Valdi Component Duplication Report', constants_1.ANSI_COLORS.BLUE_COLOR));
9
+ console.log('='.repeat(50));
10
+ console.log();
11
+ const { scanStats } = report;
12
+ console.log(`Scanned ${(0, logUtils_1.wrapInColor)(String(scanStats.filesScanned), constants_1.ANSI_COLORS.GREEN_COLOR)} files across ${(0, logUtils_1.wrapInColor)(String(scanStats.modulesScanned), constants_1.ANSI_COLORS.GREEN_COLOR)} modules in ${scanStats.durationMs}ms`);
13
+ console.log(`Scan roots: ${report.config.scanRoots.join(', ')}`);
14
+ console.log(`Shared libraries: ${report.config.sharedLibNames.join(', ') || '(none configured)'}`);
15
+ console.log();
16
+ if (report.knownPatterns.length > 0) {
17
+ console.log((0, logUtils_1.wrapInColor)('Known Patterns', constants_1.ANSI_COLORS.BLUE_COLOR));
18
+ console.log('-'.repeat(30));
19
+ for (const pattern of report.knownPatterns) {
20
+ printKnownPattern(pattern, verbose);
21
+ }
22
+ console.log();
23
+ }
24
+ if (report.genericClusters.length > 0) {
25
+ console.log((0, logUtils_1.wrapInColor)('Similar Component Clusters', constants_1.ANSI_COLORS.BLUE_COLOR));
26
+ console.log('-'.repeat(30));
27
+ const clustersToShow = verbose ? report.genericClusters : report.genericClusters.slice(0, 10);
28
+ for (const cluster of clustersToShow) {
29
+ printCluster(cluster, verbose);
30
+ }
31
+ if (!verbose && report.genericClusters.length > 10) {
32
+ console.log((0, logUtils_1.wrapInColor)(` ... and ${report.genericClusters.length - 10} more clusters (use --verbose to see all)`, constants_1.ANSI_COLORS.GRAY_COLOR));
33
+ }
34
+ console.log();
35
+ }
36
+ console.log('='.repeat(50));
37
+ console.log((0, logUtils_1.wrapInColor)('Summary', constants_1.ANSI_COLORS.BLUE_COLOR));
38
+ console.log(` Known pattern matches: ${report.summary.totalKnownPatternMatches}`);
39
+ console.log(` Similar clusters: ${report.summary.totalClusters}`);
40
+ console.log(` Total duplicated files: ${report.summary.totalDuplicatedFiles}`);
41
+ }
42
+ function printKnownPattern(pattern, verbose) {
43
+ const severityColor = pattern.severity === 'HIGH'
44
+ ? constants_1.ANSI_COLORS.RED_COLOR
45
+ : pattern.severity === 'MEDIUM'
46
+ ? constants_1.ANSI_COLORS.YELLOW_COLOR
47
+ : constants_1.ANSI_COLORS.GRAY_COLOR;
48
+ console.log(` ${(0, logUtils_1.wrapInColor)(`[${pattern.severity}]`, severityColor)} ${pattern.patternName} — ${pattern.matchCount} matches`);
49
+ console.log(` ${pattern.recommendation}`);
50
+ if (pattern.existingImplementations.length > 0) {
51
+ console.log(` Existing implementations:`);
52
+ for (const impl of pattern.existingImplementations) {
53
+ console.log(` ${(0, logUtils_1.wrapInColor)('→', constants_1.ANSI_COLORS.GREEN_COLOR)} ${impl}`);
54
+ }
55
+ }
56
+ if (verbose) {
57
+ const filesToShow = pattern.files.slice(0, 20);
58
+ for (const file of filesToShow) {
59
+ console.log(` ${(0, logUtils_1.wrapInColor)('·', constants_1.ANSI_COLORS.GRAY_COLOR)} ${file}`);
60
+ }
61
+ if (pattern.files.length > 20) {
62
+ console.log((0, logUtils_1.wrapInColor)(` ... and ${pattern.files.length - 20} more`, constants_1.ANSI_COLORS.GRAY_COLOR));
63
+ }
64
+ }
65
+ console.log();
66
+ }
67
+ function printCluster(cluster, verbose) {
68
+ console.log(` Cluster #${cluster.id} (${cluster.files.length} files, avg similarity: ${(cluster.avgSimilarity * 100).toFixed(0)}%)`);
69
+ console.log(` ${cluster.suggestedExtraction}`);
70
+ if (cluster.sharedViewModelProps.length > 0) {
71
+ console.log(` Shared ViewModel props: ${cluster.sharedViewModelProps.join(', ')}`);
72
+ }
73
+ for (const file of cluster.files) {
74
+ console.log(` ${(0, logUtils_1.wrapInColor)('·', constants_1.ANSI_COLORS.GRAY_COLOR)} ${file.module}/${file.className} — ${file.path}`);
75
+ }
76
+ if (verbose && cluster.sharedImports.length > 0) {
77
+ console.log(` Shared imports: ${cluster.sharedImports.slice(0, 5).join(', ')}`);
78
+ }
79
+ console.log();
80
+ }
81
+ function formatJsonReport(report) {
82
+ return JSON.stringify(report, null, 2);
83
+ }
@@ -0,0 +1,172 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.resolveScanConfig = resolveScanConfig;
4
+ exports.discoverTsxFiles = discoverTsxFiles;
5
+ exports.extractModuleName = extractModuleName;
6
+ exports.isSharedLibFile = isSharedLibFile;
7
+ const tslib_1 = require("tslib");
8
+ const fs = tslib_1.__importStar(require("fs"));
9
+ const path = tslib_1.__importStar(require("path"));
10
+ const INTERNAL_SCAN_ROOT = 'src/composer_modules/src/composer';
11
+ const INTERNAL_SHARED_LIBS = ['coreui'];
12
+ const EXTERNAL_SHARED_LIBS = ['valdi_widgets'];
13
+ function resolveScanConfig(cwd, scanRootOverrides, sharedLibOverrides) {
14
+ if (scanRootOverrides && scanRootOverrides.length > 0) {
15
+ const resolvedRoots = scanRootOverrides.map(r => path.resolve(cwd, r));
16
+ const libNames = sharedLibOverrides ?? EXTERNAL_SHARED_LIBS;
17
+ const libPaths = libNames.map(name => discoverSharedLibPath(cwd, resolvedRoots, name));
18
+ return {
19
+ scanRoots: resolvedRoots,
20
+ sharedLibPaths: libPaths.filter((p) => p !== undefined),
21
+ sharedLibNames: libNames,
22
+ };
23
+ }
24
+ const internalRoot = path.join(cwd, INTERNAL_SCAN_ROOT);
25
+ if (fs.existsSync(internalRoot)) {
26
+ const libNames = sharedLibOverrides ?? INTERNAL_SHARED_LIBS;
27
+ const libPaths = libNames.map(name => discoverSharedLibPath(cwd, [internalRoot], name));
28
+ return {
29
+ scanRoots: [internalRoot],
30
+ sharedLibPaths: libPaths.filter((p) => p !== undefined),
31
+ sharedLibNames: libNames,
32
+ };
33
+ }
34
+ const srcDir = path.join(cwd, 'src');
35
+ if (fs.existsSync(srcDir)) {
36
+ const libNames = sharedLibOverrides ?? EXTERNAL_SHARED_LIBS;
37
+ const libPaths = libNames.map(name => discoverSharedLibPath(cwd, [srcDir], name));
38
+ return {
39
+ scanRoots: [srcDir],
40
+ sharedLibPaths: libPaths.filter((p) => p !== undefined),
41
+ sharedLibNames: libNames,
42
+ };
43
+ }
44
+ const libNames = sharedLibOverrides ?? EXTERNAL_SHARED_LIBS;
45
+ const libPaths = libNames.map(name => discoverSharedLibPath(cwd, [cwd], name));
46
+ return {
47
+ scanRoots: [cwd],
48
+ sharedLibPaths: libPaths.filter((p) => p !== undefined),
49
+ sharedLibNames: libNames,
50
+ };
51
+ }
52
+ function discoverSharedLibPath(workspaceRoot, scanRoots, libName) {
53
+ for (const root of scanRoots) {
54
+ const candidate = path.join(root, libName);
55
+ if (fs.existsSync(candidate))
56
+ return candidate;
57
+ }
58
+ const parentDir = path.dirname(workspaceRoot);
59
+ const siblingCandidates = [
60
+ libName,
61
+ libName
62
+ .split('_')
63
+ .map(s => s.charAt(0).toUpperCase() + s.slice(1))
64
+ .join('_'),
65
+ libName.replace(/_/g, '-'),
66
+ libName.replace(/_([a-z])/g, (_, c) => c.toUpperCase()),
67
+ ];
68
+ for (const name of siblingCandidates) {
69
+ const candidate = path.join(parentDir, name);
70
+ if (fs.existsSync(candidate))
71
+ return candidate;
72
+ }
73
+ const bazelSymlinks = findBazelWorkspaceSymlinks(workspaceRoot);
74
+ for (const bazelDir of bazelSymlinks) {
75
+ const externalDir = path.join(bazelDir, 'external');
76
+ if (!fs.existsSync(externalDir))
77
+ continue;
78
+ try {
79
+ const entries = fs.readdirSync(externalDir);
80
+ for (const entry of entries) {
81
+ if (entry.includes(libName)) {
82
+ const candidate = path.join(externalDir, entry);
83
+ if (fs.statSync(candidate).isDirectory())
84
+ return candidate;
85
+ }
86
+ }
87
+ }
88
+ catch {
89
+ }
90
+ }
91
+ const nodeModules = path.join(workspaceRoot, 'node_modules', libName);
92
+ if (fs.existsSync(nodeModules))
93
+ return nodeModules;
94
+ return undefined;
95
+ }
96
+ function findBazelWorkspaceSymlinks(workspaceRoot) {
97
+ const results = [];
98
+ try {
99
+ const entries = fs.readdirSync(workspaceRoot);
100
+ for (const entry of entries) {
101
+ if (entry.startsWith('bazel-') &&
102
+ !entry.startsWith('bazel-out') &&
103
+ !entry.startsWith('bazel-bin') &&
104
+ !entry.startsWith('bazel-testlogs')) {
105
+ const fullPath = path.join(workspaceRoot, entry);
106
+ try {
107
+ if (fs.lstatSync(fullPath).isSymbolicLink() || fs.statSync(fullPath).isDirectory()) {
108
+ results.push(fullPath);
109
+ }
110
+ }
111
+ catch {
112
+ }
113
+ }
114
+ }
115
+ }
116
+ catch {
117
+ }
118
+ return results;
119
+ }
120
+ function discoverTsxFiles(config, moduleFilter) {
121
+ const files = [];
122
+ for (const root of config.scanRoots) {
123
+ if (!fs.existsSync(root))
124
+ continue;
125
+ walkDir(root, config, moduleFilter, files);
126
+ }
127
+ return files;
128
+ }
129
+ function walkDir(dir, config, moduleFilter, out) {
130
+ let entries;
131
+ try {
132
+ entries = fs.readdirSync(dir, { withFileTypes: true });
133
+ }
134
+ catch {
135
+ return;
136
+ }
137
+ for (const entry of entries) {
138
+ const fullPath = path.join(dir, entry.name);
139
+ if (entry.isDirectory()) {
140
+ if (entry.name === 'node_modules' || entry.name === '.git' || entry.name === 'bazel-out')
141
+ continue;
142
+ if (moduleFilter) {
143
+ const moduleName = extractModuleName(fullPath, config);
144
+ if (moduleName && moduleName !== moduleFilter)
145
+ continue;
146
+ }
147
+ walkDir(fullPath, config, moduleFilter, out);
148
+ }
149
+ else if (entry.name.endsWith('.tsx') && !entry.name.endsWith('.spec.tsx') && !entry.name.endsWith('.test.tsx')) {
150
+ if (!isInTestDir(fullPath)) {
151
+ out.push(fullPath);
152
+ }
153
+ }
154
+ }
155
+ }
156
+ function isInTestDir(filePath) {
157
+ const parts = filePath.split(path.sep);
158
+ return parts.includes('test') || parts.includes('__tests__');
159
+ }
160
+ function extractModuleName(filePath, config) {
161
+ for (const root of config.scanRoots) {
162
+ if (filePath === root || filePath.startsWith(root + path.sep)) {
163
+ const relative = path.relative(root, filePath);
164
+ const firstSegment = relative.split(path.sep)[0];
165
+ return firstSegment;
166
+ }
167
+ }
168
+ return undefined;
169
+ }
170
+ function isSharedLibFile(filePath, config) {
171
+ return config.sharedLibPaths.some(libPath => filePath === libPath || filePath.startsWith(libPath + path.sep));
172
+ }