dart-decimate 0.0.1

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/Cargo.lock +572 -0
  2. package/Cargo.toml +41 -0
  3. package/LICENSE +21 -0
  4. package/README.md +617 -0
  5. package/assets/dart-decimate-banner.png +0 -0
  6. package/npm/bin/dart-decimate-mcp.js +48 -0
  7. package/npm/bin/dart-decimate.js +48 -0
  8. package/npm/scripts/postinstall.js +46 -0
  9. package/npm/scripts/test-npx-local.js +54 -0
  10. package/npm/scripts/test-npx-mcp-local.js +56 -0
  11. package/package.json +45 -0
  12. package/src/baseline.rs +643 -0
  13. package/src/bin/dart-decimate-mcp.rs +11 -0
  14. package/src/boundaries/tests.rs +60 -0
  15. package/src/boundaries.rs +317 -0
  16. package/src/changed_scope.rs +117 -0
  17. package/src/ci_template.rs +399 -0
  18. package/src/cli/analyze.rs +462 -0
  19. package/src/cli/analyzer_options.rs +82 -0
  20. package/src/cli/audit_run.rs +327 -0
  21. package/src/cli/boundary_args.rs +44 -0
  22. package/src/cli/ci_template_run.rs +196 -0
  23. package/src/cli/command_name.rs +20 -0
  24. package/src/cli/common_args.rs +167 -0
  25. package/src/cli/config_run.rs +78 -0
  26. package/src/cli/coverage_run.rs +393 -0
  27. package/src/cli/decision_surface_run.rs +99 -0
  28. package/src/cli/default_command.rs +69 -0
  29. package/src/cli/dupes_args.rs +150 -0
  30. package/src/cli/entry_points.rs +121 -0
  31. package/src/cli/error.rs +149 -0
  32. package/src/cli/error_output.rs +68 -0
  33. package/src/cli/explain_run.rs +72 -0
  34. package/src/cli/fix_run.rs +162 -0
  35. package/src/cli/flags_args.rs +23 -0
  36. package/src/cli/health_args.rs +200 -0
  37. package/src/cli/hooks_run.rs +191 -0
  38. package/src/cli/impact_run.rs +95 -0
  39. package/src/cli/init_run.rs +49 -0
  40. package/src/cli/inspect_args.rs +20 -0
  41. package/src/cli/inspect_run.rs +66 -0
  42. package/src/cli/issue_filter_args.rs +240 -0
  43. package/src/cli/list_run.rs +311 -0
  44. package/src/cli/mode_args.rs +72 -0
  45. package/src/cli/output_format.rs +62 -0
  46. package/src/cli/regression_args.rs +156 -0
  47. package/src/cli/request_args.rs +175 -0
  48. package/src/cli/schema_commands.rs +72 -0
  49. package/src/cli/scope_args.rs +174 -0
  50. package/src/cli/security_args.rs +175 -0
  51. package/src/cli/security_gate_run.rs +66 -0
  52. package/src/cli/security_summary_run.rs +43 -0
  53. package/src/cli/summary_args.rs +12 -0
  54. package/src/cli/tests.rs +516 -0
  55. package/src/cli/trace_args.rs +67 -0
  56. package/src/cli/trace_run.rs +131 -0
  57. package/src/cli/trace_tests.rs +235 -0
  58. package/src/cli/unsupported_run.rs +116 -0
  59. package/src/cli/watch_run.rs +153 -0
  60. package/src/cli.rs +603 -0
  61. package/src/config/boundary_config.rs +235 -0
  62. package/src/config/cache.rs +25 -0
  63. package/src/config/dependencies.rs +114 -0
  64. package/src/config/health.rs +237 -0
  65. package/src/config/jsonc.rs +66 -0
  66. package/src/config/policy.rs +91 -0
  67. package/src/config/rule_aliases.rs +487 -0
  68. package/src/config/rules.rs +339 -0
  69. package/src/config.rs +635 -0
  70. package/src/coverage.rs +469 -0
  71. package/src/dart_parser.rs +673 -0
  72. package/src/decision_surface.rs +405 -0
  73. package/src/dependencies/analyze.rs +218 -0
  74. package/src/dependencies/codegen.rs +118 -0
  75. package/src/dependencies/discovery.rs +60 -0
  76. package/src/dependencies/overrides.rs +76 -0
  77. package/src/dependencies/private_src_imports.rs +32 -0
  78. package/src/dependencies/pubspec_document.rs +86 -0
  79. package/src/dependencies/pubspec_entry.rs +96 -0
  80. package/src/dependencies/tests.rs +544 -0
  81. package/src/dependencies/usage.rs +33 -0
  82. package/src/dependencies.rs +553 -0
  83. package/src/dependency_scripts.rs +91 -0
  84. package/src/dupes/lex.rs +236 -0
  85. package/src/dupes/tests.rs +119 -0
  86. package/src/dupes.rs +625 -0
  87. package/src/explain.rs +692 -0
  88. package/src/extract/directives.rs +252 -0
  89. package/src/extract/error_tests.rs +25 -0
  90. package/src/extract/members.rs +210 -0
  91. package/src/extract/primary_constructors.rs +421 -0
  92. package/src/extract/references.rs +151 -0
  93. package/src/extract/routes.rs +691 -0
  94. package/src/extract/signatures.rs +266 -0
  95. package/src/extract/string_tests.rs +18 -0
  96. package/src/extract/strings.rs +107 -0
  97. package/src/extract/tests.rs +697 -0
  98. package/src/extract.rs +680 -0
  99. package/src/feature_flags/tests.rs +76 -0
  100. package/src/feature_flags.rs +453 -0
  101. package/src/finding_identity.rs +60 -0
  102. package/src/fix.rs +551 -0
  103. package/src/generated.rs +53 -0
  104. package/src/graph/augment_tests.rs +212 -0
  105. package/src/graph/conditionals.rs +74 -0
  106. package/src/graph/package_config_tests.rs +100 -0
  107. package/src/graph/parts.rs +248 -0
  108. package/src/graph/pubspec_tests.rs +119 -0
  109. package/src/graph/tests.rs +837 -0
  110. package/src/graph/uri_tests.rs +102 -0
  111. package/src/graph.rs +644 -0
  112. package/src/health/coverage.rs +309 -0
  113. package/src/health/ownership.rs +175 -0
  114. package/src/health/runtime_coverage.rs +616 -0
  115. package/src/health/runtime_intelligence.rs +511 -0
  116. package/src/health/scores.rs +296 -0
  117. package/src/health/tests.rs +240 -0
  118. package/src/health/threshold_types.rs +163 -0
  119. package/src/health/thresholds.rs +229 -0
  120. package/src/health/types.rs +636 -0
  121. package/src/health.rs +597 -0
  122. package/src/hooks/agent_settings.rs +175 -0
  123. package/src/hooks/templates.rs +51 -0
  124. package/src/hooks.rs +569 -0
  125. package/src/impact.rs +287 -0
  126. package/src/init.rs +237 -0
  127. package/src/inspect.rs +142 -0
  128. package/src/intelligence/tests.rs +232 -0
  129. package/src/intelligence.rs +305 -0
  130. package/src/lib.rs +198 -0
  131. package/src/main.rs +5 -0
  132. package/src/manifest/mcp.rs +565 -0
  133. package/src/manifest.rs +552 -0
  134. package/src/mcp/cli_args/value_args.rs +175 -0
  135. package/src/mcp/cli_args.rs +658 -0
  136. package/src/mcp/cli_args_tests.rs +522 -0
  137. package/src/mcp/code_execute.rs +671 -0
  138. package/src/mcp/tools.rs +660 -0
  139. package/src/mcp.rs +325 -0
  140. package/src/output/audit_risk.rs +135 -0
  141. package/src/output/dependency_findings.rs +327 -0
  142. package/src/output/duplication_findings.rs +114 -0
  143. package/src/output/feature_flag_findings.rs +122 -0
  144. package/src/output/format.rs +31 -0
  145. package/src/output/graph_findings.rs +461 -0
  146. package/src/output/health_findings.rs +612 -0
  147. package/src/output/human.rs +27 -0
  148. package/src/output/next_steps.rs +92 -0
  149. package/src/output/route_findings.rs +76 -0
  150. package/src/output/runtime_coverage.rs +515 -0
  151. package/src/output/scope.rs +183 -0
  152. package/src/output/security_findings.rs +390 -0
  153. package/src/output/security_sarif.rs +150 -0
  154. package/src/output/suppressions.rs +323 -0
  155. package/src/output/symbol_findings.rs +257 -0
  156. package/src/output/tests.rs +114 -0
  157. package/src/output/types.rs +604 -0
  158. package/src/output/widget_findings.rs +213 -0
  159. package/src/output.rs +682 -0
  160. package/src/package_map.rs +495 -0
  161. package/src/policy/packs.rs +232 -0
  162. package/src/policy/tests.rs +134 -0
  163. package/src/policy.rs +640 -0
  164. package/src/project_list.rs +376 -0
  165. package/src/report_schema/inventory.rs +418 -0
  166. package/src/report_schema.rs +488 -0
  167. package/src/routes.rs +354 -0
  168. package/src/scan/tests.rs +250 -0
  169. package/src/scan.rs +275 -0
  170. package/src/security/detect.rs +639 -0
  171. package/src/security/tests.rs +178 -0
  172. package/src/security.rs +373 -0
  173. package/src/security_gate.rs +555 -0
  174. package/src/symbols/path_filters.rs +27 -0
  175. package/src/symbols/private_type_leaks.rs +125 -0
  176. package/src/symbols/riverpod.rs +113 -0
  177. package/src/symbols/tests.rs +692 -0
  178. package/src/symbols.rs +693 -0
  179. package/src/trace/tests.rs +225 -0
  180. package/src/trace.rs +690 -0
  181. package/src/unsupported.rs +47 -0
  182. package/src/widgets/lifecycle.rs +484 -0
  183. package/src/widgets/params.rs +236 -0
  184. package/src/widgets/tests.rs +430 -0
  185. package/src/widgets/top_level.rs +110 -0
  186. package/src/widgets/unrendered.rs +374 -0
  187. package/src/widgets.rs +590 -0
  188. package/src/workspace_scope.rs +358 -0
@@ -0,0 +1,131 @@
1
+ use std::io::Write;
2
+
3
+ use super::{CliError, CommandRequest, ReportOutputFormat};
4
+ use crate::output::ReportCommand;
5
+ use crate::scan::ScannedProject;
6
+ use crate::trace::{
7
+ render_dependency_trace, render_file_trace, render_symbol_trace, trace_dependency, trace_file,
8
+ trace_symbol,
9
+ };
10
+ use crate::{find_dead_code, render_clone_trace, trace_clone};
11
+
12
+ use super::entry_points::entry_points_for_check;
13
+
14
+ pub(super) fn run_trace_request<W: Write>(
15
+ request: &CommandRequest,
16
+ project: &ScannedProject,
17
+ mut writer: W,
18
+ ) -> Result<i32, CliError> {
19
+ match request.command {
20
+ ReportCommand::TraceFile => run_trace_file(request, project, &mut writer)?,
21
+ ReportCommand::TraceSymbol => run_trace_symbol(request, project, &mut writer)?,
22
+ ReportCommand::TraceDependency => run_trace_dependency(request, project, &mut writer)?,
23
+ ReportCommand::TraceClone => run_trace_clone(request, project, &mut writer)?,
24
+ ReportCommand::Check
25
+ | ReportCommand::Audit
26
+ | ReportCommand::DeadCode
27
+ | ReportCommand::Cycles
28
+ | ReportCommand::Dupes
29
+ | ReportCommand::Health
30
+ | ReportCommand::Flags
31
+ | ReportCommand::Security
32
+ | ReportCommand::Inspect => {
33
+ unreachable!("run_trace_request is only called for trace commands")
34
+ }
35
+ }
36
+
37
+ Ok(0)
38
+ }
39
+
40
+ fn run_trace_file<W: Write>(
41
+ request: &CommandRequest,
42
+ project: &ScannedProject,
43
+ writer: &mut W,
44
+ ) -> Result<(), CliError> {
45
+ let dead_code = find_dead_code(
46
+ &project.graph,
47
+ entry_points_for_check(project, &request.entry_points, request.entry_point_mode()),
48
+ );
49
+ let Some(file) = request.trace_file.as_ref() else {
50
+ return Err(CliError::MissingTraceFile);
51
+ };
52
+ let report = trace_file(project, &dead_code, file);
53
+ match request.format {
54
+ ReportOutputFormat::Human => writer.write_all(render_file_trace(&report).as_bytes())?,
55
+ ReportOutputFormat::Json => {
56
+ serde_json::to_writer_pretty(&mut *writer, &report)?;
57
+ writeln!(writer)?;
58
+ }
59
+ ReportOutputFormat::Sarif => unreachable!("SARIF is rejected before trace rendering"),
60
+ }
61
+ Ok(())
62
+ }
63
+
64
+ fn run_trace_symbol<W: Write>(
65
+ request: &CommandRequest,
66
+ project: &ScannedProject,
67
+ writer: &mut W,
68
+ ) -> Result<(), CliError> {
69
+ let dead_code = find_dead_code(
70
+ &project.graph,
71
+ entry_points_for_check(project, &request.entry_points, request.entry_point_mode()),
72
+ );
73
+ let Some(spec) = request.trace_symbol.as_ref() else {
74
+ return Err(CliError::TraceSymbol {
75
+ value: String::new(),
76
+ });
77
+ };
78
+ let report = trace_symbol(project, &dead_code, &spec.file, &spec.symbol);
79
+ match request.format {
80
+ ReportOutputFormat::Human => writer.write_all(render_symbol_trace(&report).as_bytes())?,
81
+ ReportOutputFormat::Json => {
82
+ serde_json::to_writer_pretty(&mut *writer, &report)?;
83
+ writeln!(writer)?;
84
+ }
85
+ ReportOutputFormat::Sarif => unreachable!("SARIF is rejected before trace rendering"),
86
+ }
87
+ Ok(())
88
+ }
89
+
90
+ fn run_trace_dependency<W: Write>(
91
+ request: &CommandRequest,
92
+ project: &ScannedProject,
93
+ writer: &mut W,
94
+ ) -> Result<(), CliError> {
95
+ let Some(dependency) = request.trace_dependency.as_ref() else {
96
+ return Err(CliError::MissingTraceDependency);
97
+ };
98
+ let report = trace_dependency(project, dependency)?;
99
+ match request.format {
100
+ ReportOutputFormat::Human => {
101
+ writer.write_all(render_dependency_trace(&report).as_bytes())?;
102
+ }
103
+ ReportOutputFormat::Json => {
104
+ serde_json::to_writer_pretty(&mut *writer, &report)?;
105
+ writeln!(writer)?;
106
+ }
107
+ ReportOutputFormat::Sarif => unreachable!("SARIF is rejected before trace rendering"),
108
+ }
109
+ Ok(())
110
+ }
111
+
112
+ fn run_trace_clone<W: Write>(
113
+ request: &CommandRequest,
114
+ project: &ScannedProject,
115
+ writer: &mut W,
116
+ ) -> Result<(), CliError> {
117
+ let Some(trace) = request.trace_clone.as_ref() else {
118
+ unreachable!("clap requires --fingerprint for trace-clone");
119
+ };
120
+ let duplicates = crate::detect_duplicates(project, &request.duplicate_options)?;
121
+ let report = trace_clone(project, &duplicates, trace);
122
+ match request.format {
123
+ ReportOutputFormat::Human => writer.write_all(render_clone_trace(&report).as_bytes())?,
124
+ ReportOutputFormat::Json => {
125
+ serde_json::to_writer_pretty(&mut *writer, &report)?;
126
+ writeln!(writer)?;
127
+ }
128
+ ReportOutputFormat::Sarif => unreachable!("SARIF is rejected before trace rendering"),
129
+ }
130
+ Ok(())
131
+ }
@@ -0,0 +1,235 @@
1
+ use std::fs;
2
+
3
+ use serde_json::Value;
4
+ use tempfile::TempDir;
5
+
6
+ use super::run_from;
7
+
8
+ #[test]
9
+ fn trace_file_command_emits_json_contract() -> Result<(), Box<dyn std::error::Error>> {
10
+ let fixture = tempfile::tempdir()?;
11
+ write(&fixture, "pubspec.yaml", "name: app\n")?;
12
+ write(
13
+ &fixture,
14
+ "lib/main.dart",
15
+ "import 'barrel.dart';\nvoid main() { Api(); }\n",
16
+ )?;
17
+ write(&fixture, "lib/barrel.dart", "export 'src/api.dart';\n")?;
18
+ write(&fixture, "lib/src/api.dart", "class Api {}\n")?;
19
+ let mut output = Vec::new();
20
+
21
+ let code = run_from(
22
+ [
23
+ "dart-decimate",
24
+ "trace-file",
25
+ fixture.path().to_str().unwrap_or("."),
26
+ "--format",
27
+ "json",
28
+ "--entry",
29
+ "lib/main.dart",
30
+ "--file",
31
+ "lib/barrel.dart",
32
+ ],
33
+ &mut output,
34
+ )?;
35
+
36
+ let json = serde_json::from_slice::<Value>(&output)?;
37
+ assert_eq!(code, 0);
38
+ assert_eq!(json["schema_version"], "dart-decimate.trace.v1");
39
+ assert_eq!(json["kind"], "trace-file");
40
+ assert_eq!(json["command"], "trace-file");
41
+ assert_eq!(json["path"], "lib/barrel.dart");
42
+ assert_eq!(json["reachable"], true);
43
+ assert_eq!(json["imported_by"][0]["from"], "lib/main.dart");
44
+ assert_eq!(json["re_exports"][0]["to"], "lib/src/api.dart");
45
+
46
+ Ok(())
47
+ }
48
+
49
+ #[test]
50
+ fn trace_file_command_reports_missing_file_without_failure()
51
+ -> Result<(), Box<dyn std::error::Error>> {
52
+ let fixture = tempfile::tempdir()?;
53
+ write(&fixture, "pubspec.yaml", "name: app\n")?;
54
+ write(&fixture, "lib/main.dart", "void main() {}\n")?;
55
+ let mut output = Vec::new();
56
+
57
+ let code = run_from(
58
+ [
59
+ "dart-decimate",
60
+ "trace-file",
61
+ fixture.path().to_str().unwrap_or("."),
62
+ "--format",
63
+ "json",
64
+ "--entry",
65
+ "lib/main.dart",
66
+ "--file",
67
+ "lib/missing.dart",
68
+ ],
69
+ &mut output,
70
+ )?;
71
+
72
+ let json = serde_json::from_slice::<Value>(&output)?;
73
+ assert_eq!(code, 0);
74
+ assert_eq!(json["found"], false);
75
+ assert_eq!(json["reason"], "file is not in the module graph");
76
+
77
+ Ok(())
78
+ }
79
+
80
+ #[test]
81
+ fn trace_symbol_command_emits_json_contract() -> Result<(), Box<dyn std::error::Error>> {
82
+ let fixture = tempfile::tempdir()?;
83
+ write(&fixture, "pubspec.yaml", "name: app\n")?;
84
+ write(
85
+ &fixture,
86
+ "lib/main.dart",
87
+ "import 'barrel.dart';\nvoid main() { Api(); }\n",
88
+ )?;
89
+ write(&fixture, "lib/barrel.dart", "export 'src/api.dart';\n")?;
90
+ write(
91
+ &fixture,
92
+ "lib/src/api.dart",
93
+ "class Api {}\nclass Unused {}\n",
94
+ )?;
95
+ let mut output = Vec::new();
96
+
97
+ let code = run_from(
98
+ [
99
+ "dart-decimate",
100
+ "trace-symbol",
101
+ fixture.path().to_str().unwrap_or("."),
102
+ "--format",
103
+ "json",
104
+ "--entry",
105
+ "lib/main.dart",
106
+ "--file",
107
+ "lib/src/api.dart",
108
+ "--symbol",
109
+ "Api",
110
+ ],
111
+ &mut output,
112
+ )?;
113
+
114
+ let json = serde_json::from_slice::<Value>(&output)?;
115
+ assert_eq!(code, 0);
116
+ assert_eq!(json["command"], "trace-symbol");
117
+ assert_eq!(json["path"], "lib/src/api.dart");
118
+ assert_eq!(json["symbol"], "Api");
119
+ assert_eq!(json["found"], true);
120
+ assert_eq!(json["direct_references"][0]["path"], "lib/main.dart");
121
+ assert_eq!(json["re_export_chains"][0][0], "lib/barrel.dart");
122
+ assert_eq!(json["reason"], "symbol has reachable direct references");
123
+
124
+ Ok(())
125
+ }
126
+
127
+ #[test]
128
+ fn trace_command_alias_emits_symbol_trace_contract() -> Result<(), Box<dyn std::error::Error>> {
129
+ let fixture = tempfile::tempdir()?;
130
+ write(&fixture, "pubspec.yaml", "name: app\n")?;
131
+ write(
132
+ &fixture,
133
+ "lib/main.dart",
134
+ "import 'src/api.dart';\nvoid main() { Api(); }\n",
135
+ )?;
136
+ write(&fixture, "lib/src/api.dart", "class Api {}\n")?;
137
+ let mut output = Vec::new();
138
+
139
+ let code = run_from(
140
+ [
141
+ "dart-decimate",
142
+ "trace",
143
+ "--root",
144
+ fixture.path().to_str().unwrap_or("."),
145
+ "--format",
146
+ "json",
147
+ "--entry",
148
+ "lib/main.dart",
149
+ "lib/src/api.dart:Api",
150
+ ],
151
+ &mut output,
152
+ )?;
153
+
154
+ let json = serde_json::from_slice::<Value>(&output)?;
155
+ assert_eq!(code, 0);
156
+ assert_eq!(json["schema_version"], "dart-decimate.trace.v1");
157
+ assert_eq!(json["kind"], "trace-symbol");
158
+ assert_eq!(json["command"], "trace-symbol");
159
+ assert_eq!(json["path"], "lib/src/api.dart");
160
+ assert_eq!(json["symbol"], "Api");
161
+ assert_eq!(json["found"], true);
162
+ assert_eq!(json["direct_references"][0]["path"], "lib/main.dart");
163
+
164
+ Ok(())
165
+ }
166
+
167
+ #[test]
168
+ fn trace_dependency_command_emits_json_contract() -> Result<(), Box<dyn std::error::Error>> {
169
+ let fixture = tempfile::tempdir()?;
170
+ write(
171
+ &fixture,
172
+ "pubspec.yaml",
173
+ "name: app\n\
174
+ dependencies:\n collection: ^1.18.0\n path: ^1.9.0\n",
175
+ )?;
176
+ write(
177
+ &fixture,
178
+ "lib/main.dart",
179
+ "import 'package:collection/collection.dart' deferred as coll;\n\
180
+ export 'package:collection/equality.dart';\n\
181
+ void main() {}\n",
182
+ )?;
183
+ let mut output = Vec::new();
184
+
185
+ let code = run_from(
186
+ [
187
+ "dart-decimate",
188
+ "trace-dependency",
189
+ fixture.path().to_str().unwrap_or("."),
190
+ "--format",
191
+ "json",
192
+ "--dependency",
193
+ "collection",
194
+ ],
195
+ &mut output,
196
+ )?;
197
+
198
+ let json = serde_json::from_slice::<Value>(&output)?;
199
+ assert_eq!(code, 0);
200
+ assert_eq!(json["schema_version"], "dart-decimate.trace.v1");
201
+ assert_eq!(json["kind"], "trace-dependency");
202
+ assert_eq!(json["command"], "trace-dependency");
203
+ assert_eq!(json["dependency"], "collection");
204
+ assert_eq!(json["found"], true);
205
+ assert_eq!(json["declared"], true);
206
+ assert_eq!(json["is_used"], true);
207
+ assert_eq!(json["used_in_scripts"], false);
208
+ assert_eq!(json["total_import_count"], 2);
209
+ let Some(type_only_importers) = json["type_only_importers"].as_array() else {
210
+ panic!("type_only_importers array");
211
+ };
212
+ assert!(type_only_importers.is_empty());
213
+ assert_eq!(json["declared_in"][0]["pubspec_path"], "pubspec.yaml");
214
+ assert_eq!(json["declared_in"][0]["section"], "dependencies");
215
+ assert_eq!(json["declared_in"][0]["line"], 3);
216
+ assert_eq!(json["importing_files"][0]["package"], "app");
217
+ assert_eq!(json["importing_files"][0]["kind"], "import");
218
+ assert_eq!(
219
+ json["importing_files"][0]["specifier"],
220
+ "package:collection/collection.dart"
221
+ );
222
+ assert_eq!(json["importing_files"][0]["prefix"], "coll");
223
+ assert_eq!(json["importing_files"][0]["deferred"], true);
224
+ assert_eq!(json["importing_files"][1]["kind"], "export");
225
+
226
+ Ok(())
227
+ }
228
+
229
+ fn write(fixture: &TempDir, path: &str, source: &str) -> Result<(), std::io::Error> {
230
+ let path = fixture.path().join(path);
231
+ if let Some(parent) = path.parent() {
232
+ fs::create_dir_all(parent)?;
233
+ }
234
+ fs::write(path, source)
235
+ }
@@ -0,0 +1,116 @@
1
+ use std::io::Write;
2
+
3
+ use clap::{Arg, ArgAction, ArgMatches, Command};
4
+
5
+ use crate::unsupported::{render_unsupported_report, unsupported_report};
6
+
7
+ use super::CliError;
8
+
9
+ pub(super) fn migrate_command() -> Command {
10
+ Command::new("migrate")
11
+ .about("Report Dart support status for Fallow migration helpers")
12
+ .arg(format_arg())
13
+ .arg(
14
+ Arg::new("dry-run")
15
+ .long("dry-run")
16
+ .help("Accepted for Fallow CLI compatibility")
17
+ .action(ArgAction::SetTrue),
18
+ )
19
+ }
20
+
21
+ pub(super) fn telemetry_command() -> Command {
22
+ Command::new("telemetry")
23
+ .about("Report Dart Decimate telemetry support status")
24
+ .subcommand_required(false)
25
+ .arg_required_else_help(false)
26
+ .arg(format_arg())
27
+ .subcommand(unsupported_subcommand("status"))
28
+ .subcommand(unsupported_subcommand("enable"))
29
+ .subcommand(unsupported_subcommand("disable"))
30
+ }
31
+
32
+ pub(super) fn license_command() -> Command {
33
+ Command::new("license")
34
+ .about("Report Dart Decimate license support status")
35
+ .subcommand_required(false)
36
+ .arg_required_else_help(false)
37
+ .arg(format_arg())
38
+ .subcommand(unsupported_subcommand("status"))
39
+ .subcommand(unsupported_subcommand("activate"))
40
+ }
41
+
42
+ pub(super) fn run_migrate<W: Write>(subcommand: &ArgMatches, writer: W) -> Result<i32, CliError> {
43
+ let report = unsupported_report(
44
+ "migrate",
45
+ "not-applicable",
46
+ "Fallow migrate imports JS/TS tool configuration; Dart Decimate has no Dart migration source to convert.",
47
+ vec![
48
+ "Use dart-decimate init --format json to create Dart-native defaults.".to_owned(),
49
+ "Use dart-decimate config --format json to inspect the resolved local configuration."
50
+ .to_owned(),
51
+ ],
52
+ );
53
+ write_report(subcommand, writer, &report)?;
54
+ Ok(2)
55
+ }
56
+
57
+ pub(super) fn run_telemetry<W: Write>(subcommand: &ArgMatches, writer: W) -> Result<i32, CliError> {
58
+ let action = subcommand.subcommand_name().unwrap_or("status");
59
+ let report = unsupported_report(
60
+ format!("telemetry {action}"),
61
+ "disabled",
62
+ "Dart Decimate does not collect telemetry and has no hosted telemetry backend.",
63
+ vec!["No action is required; local analysis runs without telemetry.".to_owned()],
64
+ );
65
+ write_report(subcommand, writer, &report)?;
66
+ Ok(if action == "enable" { 2 } else { 0 })
67
+ }
68
+
69
+ pub(super) fn run_license<W: Write>(subcommand: &ArgMatches, writer: W) -> Result<i32, CliError> {
70
+ let action = subcommand.subcommand_name().unwrap_or("status");
71
+ let report = unsupported_report(
72
+ format!("license {action}"),
73
+ "not-required",
74
+ "This Dart Decimate build has no hosted license service; local Dart analysis is available without activation.",
75
+ vec![
76
+ "Use cargo install or the npm wrapper once published for local installation."
77
+ .to_owned(),
78
+ ],
79
+ );
80
+ write_report(subcommand, writer, &report)?;
81
+ Ok(if action == "activate" { 2 } else { 0 })
82
+ }
83
+
84
+ fn unsupported_subcommand(name: &'static str) -> Command {
85
+ Command::new(name).arg(format_arg())
86
+ }
87
+
88
+ fn format_arg() -> Arg {
89
+ Arg::new("format")
90
+ .long("format")
91
+ .value_name("FORMAT")
92
+ .help("Output format")
93
+ .default_value("json")
94
+ .value_parser(["json", "human"])
95
+ }
96
+
97
+ fn write_report<W: Write>(
98
+ subcommand: &ArgMatches,
99
+ mut writer: W,
100
+ report: &crate::unsupported::UnsupportedReport,
101
+ ) -> Result<(), CliError> {
102
+ match requested_format(subcommand) {
103
+ "human" => writer.write_all(render_unsupported_report(report).as_bytes())?,
104
+ _ => serde_json::to_writer_pretty(&mut writer, report)?,
105
+ }
106
+ writeln!(writer)?;
107
+ Ok(())
108
+ }
109
+
110
+ fn requested_format(subcommand: &ArgMatches) -> &str {
111
+ subcommand
112
+ .subcommand()
113
+ .and_then(|(_, command)| command.get_one::<String>("format"))
114
+ .or_else(|| subcommand.get_one::<String>("format"))
115
+ .map_or("json", String::as_str)
116
+ }
@@ -0,0 +1,153 @@
1
+ use std::collections::BTreeMap;
2
+ use std::ffi::OsString;
3
+ use std::fs;
4
+ use std::io::Write;
5
+ use std::path::{Path, PathBuf};
6
+ use std::thread;
7
+ use std::time::{Duration, SystemTime};
8
+
9
+ use clap::{Arg, ArgAction, ArgMatches, Command, value_parser};
10
+
11
+ use super::common_args::{format_arg, root_arg, root_flag_arg, root_path};
12
+ use super::{CliError, run_from};
13
+
14
+ pub(super) fn watch_command() -> Command {
15
+ Command::new("watch")
16
+ .about("Watch Dart project files and rerun Dart Decimate check")
17
+ .arg(root_arg())
18
+ .arg(root_flag_arg())
19
+ .arg(format_arg())
20
+ .arg(
21
+ Arg::new("no-clear")
22
+ .long("no-clear")
23
+ .help("Do not clear the terminal between watch runs")
24
+ .action(ArgAction::SetTrue),
25
+ )
26
+ .arg(
27
+ Arg::new("once")
28
+ .long("once")
29
+ .help("Run one check pass and exit")
30
+ .action(ArgAction::SetTrue),
31
+ )
32
+ .arg(
33
+ Arg::new("interval-ms")
34
+ .long("interval-ms")
35
+ .value_name("MS")
36
+ .help("Polling interval for watch mode")
37
+ .default_value("1000")
38
+ .value_parser(value_parser!(u64)),
39
+ )
40
+ }
41
+
42
+ pub(super) fn run_watch<W: Write>(subcommand: &ArgMatches, mut writer: W) -> Result<i32, CliError> {
43
+ let root = root_path(subcommand);
44
+ if subcommand.get_flag("once") {
45
+ return run_check_once(&root, subcommand, writer);
46
+ }
47
+ let interval = Duration::from_millis(
48
+ subcommand
49
+ .get_one::<u64>("interval-ms")
50
+ .copied()
51
+ .unwrap_or(1000)
52
+ .max(100),
53
+ );
54
+ let mut snapshot = watch_snapshot(&root)?;
55
+ let _ = run_check_once(&root, subcommand, &mut writer)?;
56
+ loop {
57
+ thread::sleep(interval);
58
+ let next = watch_snapshot(&root)?;
59
+ if next == snapshot {
60
+ continue;
61
+ }
62
+ snapshot = next;
63
+ if !subcommand.get_flag("no-clear") && output_format(subcommand) != "json" {
64
+ writer.write_all(b"\x1b[2J\x1b[H")?;
65
+ }
66
+ let _ = run_check_once(&root, subcommand, &mut writer)?;
67
+ }
68
+ }
69
+
70
+ fn run_check_once<W: Write>(
71
+ root: &Path,
72
+ subcommand: &ArgMatches,
73
+ mut writer: W,
74
+ ) -> Result<i32, CliError> {
75
+ let mut output = Vec::new();
76
+ let code = run_from(
77
+ [
78
+ OsString::from("dart-decimate"),
79
+ OsString::from("check"),
80
+ root.as_os_str().to_os_string(),
81
+ OsString::from("--format"),
82
+ OsString::from(output_format(subcommand)),
83
+ ],
84
+ &mut output,
85
+ )?;
86
+ writer.write_all(&output)?;
87
+ Ok(code)
88
+ }
89
+
90
+ fn output_format(subcommand: &ArgMatches) -> String {
91
+ subcommand
92
+ .get_one::<String>("format")
93
+ .cloned()
94
+ .unwrap_or_else(|| "human".to_owned())
95
+ }
96
+
97
+ fn watch_snapshot(root: &Path) -> Result<BTreeMap<PathBuf, SystemTime>, CliError> {
98
+ let mut snapshot = BTreeMap::new();
99
+ collect_watch_snapshot(root, root, &mut snapshot)?;
100
+ Ok(snapshot)
101
+ }
102
+
103
+ fn collect_watch_snapshot(
104
+ root: &Path,
105
+ path: &Path,
106
+ snapshot: &mut BTreeMap<PathBuf, SystemTime>,
107
+ ) -> Result<(), CliError> {
108
+ if ignored_watch_path(path) {
109
+ return Ok(());
110
+ }
111
+ let metadata = fs::metadata(path)?;
112
+ if metadata.is_file() {
113
+ if watched_file(path) {
114
+ snapshot.insert(
115
+ path.strip_prefix(root).unwrap_or(path).to_path_buf(),
116
+ metadata.modified().unwrap_or(SystemTime::UNIX_EPOCH),
117
+ );
118
+ }
119
+ return Ok(());
120
+ }
121
+ if !metadata.is_dir() {
122
+ return Ok(());
123
+ }
124
+ for entry in fs::read_dir(path)? {
125
+ collect_watch_snapshot(root, &entry?.path(), snapshot)?;
126
+ }
127
+ Ok(())
128
+ }
129
+
130
+ fn watched_file(path: &Path) -> bool {
131
+ let Some(name) = path.file_name().and_then(|name| name.to_str()) else {
132
+ return false;
133
+ };
134
+ path.extension().and_then(|extension| extension.to_str()) == Some("dart")
135
+ || matches!(
136
+ name,
137
+ "pubspec.yaml"
138
+ | "pubspec_overrides.yaml"
139
+ | ".dart-decimaterc"
140
+ | ".dart-decimaterc.json"
141
+ )
142
+ }
143
+
144
+ fn ignored_watch_path(path: &Path) -> bool {
145
+ path.file_name()
146
+ .and_then(|name| name.to_str())
147
+ .is_some_and(|name| {
148
+ matches!(
149
+ name,
150
+ ".git" | ".dart_tool" | "build" | "target" | "node_modules"
151
+ )
152
+ })
153
+ }