dart-decimate 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Cargo.lock +22 -27
- package/Cargo.toml +2 -2
- package/README.md +70 -10
- package/assets/dart-decimate-banner.png +0 -0
- package/npm/scripts/postinstall.js +159 -25
- package/npm/scripts/test-npx-local.js +1 -2
- package/npm/scripts/test-npx-mcp-local.js +5 -1
- package/npm/scripts/test-postinstall-prebuilt.js +122 -0
- package/package.json +2 -1
- package/src/cli/coverage_run.rs +12 -12
- package/src/cli/request_args.rs +4 -4
- package/src/dart_parser.rs +17 -14
- package/src/extract/members.rs +4 -4
- package/src/extract/primary_constructors.rs +5 -5
- package/src/extract/references.rs +7 -7
- package/src/extract/routes.rs +40 -38
- package/src/extract/signatures.rs +8 -8
- package/src/extract/strings.rs +3 -2
- package/src/extract.rs +8 -8
- package/src/graph.rs +25 -24
- package/src/health/runtime_coverage.rs +5 -5
- package/src/output/next_steps.rs +14 -14
- package/src/output/security_sarif.rs +4 -4
- package/src/output/suppressions.rs +12 -12
- package/src/package_map.rs +4 -3
- package/src/security/detect.rs +6 -7
- package/src/widgets/unrendered.rs +8 -9
package/Cargo.lock
CHANGED
|
@@ -92,7 +92,7 @@ checksum = "d0a5c400df2834b80a4c3327b3aad3a4c4cd4de0629063962b03235697506a28"
|
|
|
92
92
|
|
|
93
93
|
[[package]]
|
|
94
94
|
name = "dart-decimate"
|
|
95
|
-
version = "0.0.
|
|
95
|
+
version = "0.0.2"
|
|
96
96
|
dependencies = [
|
|
97
97
|
"clap",
|
|
98
98
|
"glob",
|
|
@@ -376,11 +376,11 @@ dependencies = [
|
|
|
376
376
|
|
|
377
377
|
[[package]]
|
|
378
378
|
name = "serde_spanned"
|
|
379
|
-
version = "
|
|
379
|
+
version = "1.1.1"
|
|
380
380
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
381
|
-
checksum = "
|
|
381
|
+
checksum = "6662b5879511e06e8999a8a235d848113e942c9124f211511b16466ee2995f26"
|
|
382
382
|
dependencies = [
|
|
383
|
-
"
|
|
383
|
+
"serde_core",
|
|
384
384
|
]
|
|
385
385
|
|
|
386
386
|
[[package]]
|
|
@@ -460,44 +460,42 @@ dependencies = [
|
|
|
460
460
|
|
|
461
461
|
[[package]]
|
|
462
462
|
name = "toml"
|
|
463
|
-
version = "
|
|
463
|
+
version = "1.1.2+spec-1.1.0"
|
|
464
464
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
465
|
-
checksum = "
|
|
465
|
+
checksum = "81f3d15e84cbcd896376e6730314d59fb5a87f31e4b038454184435cd57defee"
|
|
466
466
|
dependencies = [
|
|
467
|
-
"
|
|
467
|
+
"indexmap",
|
|
468
|
+
"serde_core",
|
|
468
469
|
"serde_spanned",
|
|
469
470
|
"toml_datetime",
|
|
470
|
-
"
|
|
471
|
+
"toml_parser",
|
|
472
|
+
"toml_writer",
|
|
473
|
+
"winnow",
|
|
471
474
|
]
|
|
472
475
|
|
|
473
476
|
[[package]]
|
|
474
477
|
name = "toml_datetime"
|
|
475
|
-
version = "
|
|
478
|
+
version = "1.1.1+spec-1.1.0"
|
|
476
479
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
477
|
-
checksum = "
|
|
480
|
+
checksum = "3165f65f62e28e0115a00b2ebdd37eb6f3b641855f9d636d3cd4103767159ad7"
|
|
478
481
|
dependencies = [
|
|
479
|
-
"
|
|
482
|
+
"serde_core",
|
|
480
483
|
]
|
|
481
484
|
|
|
482
485
|
[[package]]
|
|
483
|
-
name = "
|
|
484
|
-
version = "
|
|
486
|
+
name = "toml_parser"
|
|
487
|
+
version = "1.1.2+spec-1.1.0"
|
|
485
488
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
486
|
-
checksum = "
|
|
489
|
+
checksum = "a2abe9b86193656635d2411dc43050282ca48aa31c2451210f4202550afb7526"
|
|
487
490
|
dependencies = [
|
|
488
|
-
"indexmap",
|
|
489
|
-
"serde",
|
|
490
|
-
"serde_spanned",
|
|
491
|
-
"toml_datetime",
|
|
492
|
-
"toml_write",
|
|
493
491
|
"winnow",
|
|
494
492
|
]
|
|
495
493
|
|
|
496
494
|
[[package]]
|
|
497
|
-
name = "
|
|
498
|
-
version = "
|
|
495
|
+
name = "toml_writer"
|
|
496
|
+
version = "1.1.1+spec-1.1.0"
|
|
499
497
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
500
|
-
checksum = "
|
|
498
|
+
checksum = "756daf9b1013ebe47a8776667b466417e2d4c5679d441c26230efd9ef78692db"
|
|
501
499
|
|
|
502
500
|
[[package]]
|
|
503
501
|
name = "tree-sitter"
|
|
@@ -558,12 +556,9 @@ dependencies = [
|
|
|
558
556
|
|
|
559
557
|
[[package]]
|
|
560
558
|
name = "winnow"
|
|
561
|
-
version = "0.
|
|
559
|
+
version = "1.0.3"
|
|
562
560
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
563
|
-
checksum = "
|
|
564
|
-
dependencies = [
|
|
565
|
-
"memchr",
|
|
566
|
-
]
|
|
561
|
+
checksum = "0592e1c9d151f854e6fd382574c3a0855250e1d9b2f99d9281c6e6391af352f1"
|
|
567
562
|
|
|
568
563
|
[[package]]
|
|
569
564
|
name = "zmij"
|
package/Cargo.toml
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[package]
|
|
2
2
|
name = "dart-decimate"
|
|
3
|
-
version = "0.0.
|
|
3
|
+
version = "0.0.2"
|
|
4
4
|
edition = "2024"
|
|
5
5
|
rust-version = "1.85"
|
|
6
6
|
description = "Rust-native codebase intelligence for Dart and Flutter module graphs."
|
|
@@ -22,7 +22,7 @@ serde = { version = "1", features = ["derive"] }
|
|
|
22
22
|
serde_json = "1"
|
|
23
23
|
serde_yaml_ng = "0.10"
|
|
24
24
|
thiserror = "2"
|
|
25
|
-
toml = "
|
|
25
|
+
toml = "1.1"
|
|
26
26
|
tree-sitter = "0.26"
|
|
27
27
|
tree-sitter-dart = "0.2"
|
|
28
28
|
|
package/README.md
CHANGED
|
@@ -33,16 +33,21 @@ It answers practical questions:
|
|
|
33
33
|
|
|
34
34
|
## Start Here
|
|
35
35
|
|
|
36
|
-
Inside any Dart or Flutter project:
|
|
36
|
+
Inside any Dart or Flutter project, run this:
|
|
37
37
|
|
|
38
38
|
```bash
|
|
39
|
-
dart-decimate check . --format json --summary
|
|
39
|
+
npx --yes dart-decimate check . --format json --summary
|
|
40
40
|
```
|
|
41
41
|
|
|
42
|
-
|
|
42
|
+
That is the easiest command. It checks the whole repo for dead code, circular
|
|
43
|
+
dependencies, duplicated code, complex functions, dependency hygiene,
|
|
44
|
+
architecture drift, Flutter graph issues, security candidates, and PR-risk
|
|
45
|
+
signals.
|
|
46
|
+
|
|
47
|
+
For a shorter human-readable report:
|
|
43
48
|
|
|
44
49
|
```bash
|
|
45
|
-
dart-decimate check .
|
|
50
|
+
npx --yes dart-decimate check .
|
|
46
51
|
```
|
|
47
52
|
|
|
48
53
|
If the report says `"verdict": "fail"`, Dart Decimate worked. It means it found
|
|
@@ -57,7 +62,32 @@ Exit codes:
|
|
|
57
62
|
|
|
58
63
|
## Install
|
|
59
64
|
|
|
60
|
-
|
|
65
|
+
You do not need to install anything permanently. Use `npx`:
|
|
66
|
+
|
|
67
|
+
```bash
|
|
68
|
+
npx --yes dart-decimate check . --format json --summary
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
Add this to `package.json` if you want a short project command:
|
|
72
|
+
|
|
73
|
+
```json
|
|
74
|
+
{
|
|
75
|
+
"scripts": {
|
|
76
|
+
"dart-decimate": "dart-decimate check . --format json --summary"
|
|
77
|
+
},
|
|
78
|
+
"devDependencies": {
|
|
79
|
+
"dart-decimate": "^0.0.2"
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
Then run:
|
|
85
|
+
|
|
86
|
+
```bash
|
|
87
|
+
npm run dart-decimate
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
If you prefer Cargo:
|
|
61
91
|
|
|
62
92
|
```bash
|
|
63
93
|
cargo install --git https://github.com/sgaabdu4/dart-decimate
|
|
@@ -94,10 +124,19 @@ dart-decimate check . --format json
|
|
|
94
124
|
|
|
95
125
|
## npx
|
|
96
126
|
|
|
97
|
-
The npm package name is `dart-decimate`.
|
|
127
|
+
The npm package name is `dart-decimate`. These commands do not require a global
|
|
128
|
+
install.
|
|
129
|
+
|
|
130
|
+
Check everything:
|
|
98
131
|
|
|
99
132
|
```bash
|
|
100
|
-
npx dart-decimate check . --format json
|
|
133
|
+
npx --yes dart-decimate check . --format json --summary
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
Human-readable output:
|
|
137
|
+
|
|
138
|
+
```bash
|
|
139
|
+
npx --yes dart-decimate check .
|
|
101
140
|
```
|
|
102
141
|
|
|
103
142
|
To run the GitHub version directly:
|
|
@@ -532,10 +571,31 @@ missing-suppression-reason
|
|
|
532
571
|
|
|
533
572
|
## CI
|
|
534
573
|
|
|
535
|
-
|
|
574
|
+
Add Dart Decimate to CI so every PR gets the same repo health check:
|
|
575
|
+
|
|
576
|
+
```yaml
|
|
577
|
+
- name: Dart Decimate
|
|
578
|
+
run: npx --yes dart-decimate check . --format json --summary
|
|
579
|
+
```
|
|
580
|
+
|
|
581
|
+
That is the easiest CI command. It checks everything Dart Decimate knows how to
|
|
582
|
+
check in one pass.
|
|
583
|
+
|
|
584
|
+
For PR-only regression checks, use:
|
|
585
|
+
|
|
586
|
+
```bash
|
|
587
|
+
npx --yes dart-decimate audit . --base origin/main --format json --summary --gate new-only
|
|
588
|
+
```
|
|
589
|
+
|
|
590
|
+
You can also put the full check in a git hook:
|
|
536
591
|
|
|
537
592
|
```bash
|
|
538
|
-
|
|
593
|
+
mkdir -p .git/hooks
|
|
594
|
+
cat > .git/hooks/pre-commit <<'SH'
|
|
595
|
+
#!/usr/bin/env sh
|
|
596
|
+
npx --yes dart-decimate check . --format json --summary
|
|
597
|
+
SH
|
|
598
|
+
chmod +x .git/hooks/pre-commit
|
|
539
599
|
```
|
|
540
600
|
|
|
541
601
|
This repository already runs:
|
|
@@ -596,7 +656,7 @@ This repository forbids `unsafe_code`.
|
|
|
596
656
|
|
|
597
657
|
## Release Flow
|
|
598
658
|
|
|
599
|
-
Current version: `0.0.
|
|
659
|
+
Current version: `0.0.2`.
|
|
600
660
|
|
|
601
661
|
After the first public release, changes should go through pull requests.
|
|
602
662
|
|
|
Binary file
|
|
@@ -2,7 +2,11 @@
|
|
|
2
2
|
|
|
3
3
|
const { spawnSync } = require("node:child_process");
|
|
4
4
|
const fs = require("node:fs");
|
|
5
|
+
const http = require("node:http");
|
|
6
|
+
const https = require("node:https");
|
|
7
|
+
const os = require("node:os");
|
|
5
8
|
const path = require("node:path");
|
|
9
|
+
const { pipeline } = require("node:stream/promises");
|
|
6
10
|
|
|
7
11
|
if (process.env.DART_DECIMATE_SKIP_BUILD === "1") {
|
|
8
12
|
process.exit(0);
|
|
@@ -12,35 +16,165 @@ const root = path.resolve(__dirname, "../..");
|
|
|
12
16
|
const exeExt = process.platform === "win32" ? ".exe" : "";
|
|
13
17
|
const cargo = process.env.CARGO || "cargo";
|
|
14
18
|
const cacheDir = path.join(root, "npm", "bin-cache");
|
|
19
|
+
const packageJson = JSON.parse(fs.readFileSync(path.join(root, "package.json"), "utf8"));
|
|
20
|
+
const releaseBaseUrl =
|
|
21
|
+
process.env.DART_DECIMATE_RELEASE_BASE_URL ||
|
|
22
|
+
`https://github.com/sgaabdu4/dart-decimate/releases/download/v${packageJson.version}`;
|
|
15
23
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
24
|
+
install()
|
|
25
|
+
.then(() => process.exit(0))
|
|
26
|
+
.catch((error) => {
|
|
27
|
+
console.error(`dart-decimate: install failed: ${error.message}`);
|
|
28
|
+
process.exit(1);
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
async function install() {
|
|
32
|
+
fs.mkdirSync(cacheDir, { recursive: true });
|
|
33
|
+
|
|
34
|
+
let prebuiltError = null;
|
|
35
|
+
if (process.env.DART_DECIMATE_SKIP_DOWNLOAD !== "1") {
|
|
36
|
+
try {
|
|
37
|
+
if (await installPrebuilt()) {
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
} catch (error) {
|
|
41
|
+
prebuiltError = error;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
buildFromSource(prebuiltError);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
async function installPrebuilt() {
|
|
49
|
+
const assetName = prebuiltAssetName();
|
|
50
|
+
if (!assetName) {
|
|
51
|
+
return false;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const archivePath = path.join(os.tmpdir(), assetName);
|
|
55
|
+
const url = `${releaseBaseUrl.replace(/\/$/, "")}/${assetName}`;
|
|
56
|
+
await download(url, archivePath, 0);
|
|
57
|
+
|
|
58
|
+
const extract = spawnSync("tar", ["-xzf", archivePath, "-C", cacheDir], {
|
|
59
|
+
stdio: "pipe",
|
|
60
|
+
windowsHide: false
|
|
61
|
+
});
|
|
62
|
+
fs.rmSync(archivePath, { force: true });
|
|
63
|
+
|
|
64
|
+
if (extract.error) {
|
|
65
|
+
throw new Error(`could not extract ${assetName}: ${extract.error.message}`);
|
|
66
|
+
}
|
|
67
|
+
if (extract.status !== 0) {
|
|
68
|
+
const stderr = extract.stderr?.toString().trim();
|
|
69
|
+
throw new Error(`could not extract ${assetName}${stderr ? `: ${stderr}` : ""}`);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
for (const binary of ["dart-decimate", "dart-decimate-mcp"]) {
|
|
73
|
+
const cachedBinary = path.join(cacheDir, `${binary}${exeExt}`);
|
|
74
|
+
if (!fs.existsSync(cachedBinary)) {
|
|
75
|
+
throw new Error(`${assetName} did not contain ${binary}${exeExt}`);
|
|
76
|
+
}
|
|
77
|
+
if (process.platform !== "win32") {
|
|
78
|
+
fs.chmodSync(cachedBinary, 0o755);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
return true;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
function prebuiltAssetName() {
|
|
86
|
+
const platform =
|
|
87
|
+
process.platform === "darwin"
|
|
88
|
+
? "darwin"
|
|
89
|
+
: process.platform === "linux"
|
|
90
|
+
? "linux"
|
|
91
|
+
: process.platform === "win32"
|
|
92
|
+
? "windows"
|
|
93
|
+
: null;
|
|
94
|
+
const arch = process.arch === "x64" ? "x64" : process.arch === "arm64" ? "arm64" : null;
|
|
95
|
+
|
|
96
|
+
if (!platform || !arch) {
|
|
97
|
+
return null;
|
|
98
|
+
}
|
|
99
|
+
if (platform === "linux" && arch === "arm64") {
|
|
100
|
+
return null;
|
|
101
|
+
}
|
|
102
|
+
if (platform === "windows" && arch === "arm64") {
|
|
103
|
+
return null;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
return `dart-decimate-${platform}-${arch}.tar.gz`;
|
|
32
107
|
}
|
|
33
108
|
|
|
34
|
-
|
|
35
|
-
|
|
109
|
+
function download(url, destination, redirectCount) {
|
|
110
|
+
if (redirectCount > 5) {
|
|
111
|
+
return Promise.reject(new Error(`too many redirects while downloading ${url}`));
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
return new Promise((resolve, reject) => {
|
|
115
|
+
const client = url.startsWith("http://") ? http : https;
|
|
116
|
+
const request = client.get(url, async (response) => {
|
|
117
|
+
if (
|
|
118
|
+
response.statusCode >= 300 &&
|
|
119
|
+
response.statusCode < 400 &&
|
|
120
|
+
response.headers.location
|
|
121
|
+
) {
|
|
122
|
+
response.resume();
|
|
123
|
+
const nextUrl = new URL(response.headers.location, url).toString();
|
|
124
|
+
download(nextUrl, destination, redirectCount + 1).then(resolve, reject);
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
if (response.statusCode !== 200) {
|
|
129
|
+
response.resume();
|
|
130
|
+
reject(new Error(`download ${url} returned HTTP ${response.statusCode}`));
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
try {
|
|
135
|
+
await pipeline(response, fs.createWriteStream(destination, { mode: 0o600 }));
|
|
136
|
+
resolve();
|
|
137
|
+
} catch (error) {
|
|
138
|
+
reject(error);
|
|
139
|
+
}
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
request.on("error", reject);
|
|
143
|
+
});
|
|
36
144
|
}
|
|
37
145
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
146
|
+
function buildFromSource(prebuiltError) {
|
|
147
|
+
const build = spawnSync(cargo, ["build", "--release", "--locked"], {
|
|
148
|
+
cwd: root,
|
|
149
|
+
stdio: "inherit",
|
|
150
|
+
windowsHide: false
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
if (build.error) {
|
|
154
|
+
if (build.error.code === "ENOENT") {
|
|
155
|
+
if (prebuiltError) {
|
|
156
|
+
console.error(`dart-decimate: prebuilt install failed: ${prebuiltError.message}`);
|
|
157
|
+
}
|
|
158
|
+
console.error(
|
|
159
|
+
"dart-decimate: Rust/Cargo is required as a fallback because a prebuilt binary " +
|
|
160
|
+
"could not be installed for this platform. Install Rust from https://rustup.rs."
|
|
161
|
+
);
|
|
162
|
+
process.exit(127);
|
|
163
|
+
}
|
|
164
|
+
console.error(`dart-decimate: cargo build failed to start: ${build.error.message}`);
|
|
165
|
+
process.exit(1);
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
if (build.status !== 0) {
|
|
169
|
+
process.exit(build.status ?? 1);
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
for (const binary of ["dart-decimate", "dart-decimate-mcp"]) {
|
|
173
|
+
const builtBinary = path.join(root, "target", "release", `${binary}${exeExt}`);
|
|
174
|
+
const cachedBinary = path.join(cacheDir, `${binary}${exeExt}`);
|
|
175
|
+
fs.copyFileSync(builtBinary, cachedBinary);
|
|
176
|
+
if (process.platform !== "win32") {
|
|
177
|
+
fs.chmodSync(cachedBinary, 0o755);
|
|
178
|
+
}
|
|
45
179
|
}
|
|
46
180
|
}
|
|
@@ -29,7 +29,7 @@ try {
|
|
|
29
29
|
const result = spawnSync(
|
|
30
30
|
"npx",
|
|
31
31
|
["--yes", "--package", tarball, "--", "dart-decimate", "--help"],
|
|
32
|
-
{ encoding: "utf8" },
|
|
32
|
+
{ encoding: "utf8", env: { ...process.env, DART_DECIMATE_SKIP_DOWNLOAD: "1" } },
|
|
33
33
|
);
|
|
34
34
|
if (result.stdout) {
|
|
35
35
|
process.stdout.write(result.stdout);
|
|
@@ -51,4 +51,3 @@ try {
|
|
|
51
51
|
} finally {
|
|
52
52
|
rmSync(tempDir, { recursive: true, force: true });
|
|
53
53
|
}
|
|
54
|
-
|
|
@@ -31,7 +31,11 @@ try {
|
|
|
31
31
|
const result = spawnSync(
|
|
32
32
|
"npx",
|
|
33
33
|
["--yes", "--package", tarball, "--", "dart-decimate-mcp"],
|
|
34
|
-
{
|
|
34
|
+
{
|
|
35
|
+
input: initialize,
|
|
36
|
+
encoding: "utf8",
|
|
37
|
+
env: { ...process.env, DART_DECIMATE_SKIP_DOWNLOAD: "1" },
|
|
38
|
+
},
|
|
35
39
|
);
|
|
36
40
|
if (result.stdout) {
|
|
37
41
|
process.stdout.write(result.stdout);
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
const { spawn, spawnSync } = require("node:child_process");
|
|
4
|
+
const fs = require("node:fs");
|
|
5
|
+
const http = require("node:http");
|
|
6
|
+
const { tmpdir } = require("node:os");
|
|
7
|
+
const path = require("node:path");
|
|
8
|
+
|
|
9
|
+
const root = path.resolve(__dirname, "../..");
|
|
10
|
+
const tempRoot = fs.mkdtempSync(path.join(tmpdir(), "dart-decimate-postinstall-"));
|
|
11
|
+
|
|
12
|
+
main().catch((error) => {
|
|
13
|
+
console.error(error.message);
|
|
14
|
+
process.exit(1);
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
async function main() {
|
|
18
|
+
const packageJson = JSON.parse(fs.readFileSync(path.join(root, "package.json"), "utf8"));
|
|
19
|
+
const platform = process.platform === "win32" ? "windows" : process.platform;
|
|
20
|
+
const arch = process.arch === "x64" ? "x64" : process.arch;
|
|
21
|
+
const assetName = `dart-decimate-${platform}-${arch}.tar.gz`;
|
|
22
|
+
|
|
23
|
+
const scriptDir = path.join(tempRoot, "npm", "scripts");
|
|
24
|
+
const payloadDir = path.join(tempRoot, "payload");
|
|
25
|
+
const assetDir = path.join(tempRoot, "assets");
|
|
26
|
+
fs.mkdirSync(scriptDir, { recursive: true });
|
|
27
|
+
fs.mkdirSync(payloadDir, { recursive: true });
|
|
28
|
+
fs.mkdirSync(assetDir, { recursive: true });
|
|
29
|
+
|
|
30
|
+
fs.copyFileSync(
|
|
31
|
+
path.join(root, "npm", "scripts", "postinstall.js"),
|
|
32
|
+
path.join(scriptDir, "postinstall.js"),
|
|
33
|
+
);
|
|
34
|
+
fs.writeFileSync(
|
|
35
|
+
path.join(tempRoot, "package.json"),
|
|
36
|
+
JSON.stringify({ name: "dart-decimate", version: packageJson.version }, null, 2),
|
|
37
|
+
);
|
|
38
|
+
|
|
39
|
+
for (const binary of ["dart-decimate", "dart-decimate-mcp"]) {
|
|
40
|
+
const binaryPath = path.join(payloadDir, process.platform === "win32" ? `${binary}.exe` : binary);
|
|
41
|
+
fs.writeFileSync(binaryPath, "#!/usr/bin/env sh\nexit 0\n");
|
|
42
|
+
fs.chmodSync(binaryPath, 0o755);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const assetPath = path.join(assetDir, assetName);
|
|
46
|
+
const archive = spawnSync("tar", ["-czf", assetPath, "-C", payloadDir, "."], {
|
|
47
|
+
encoding: "utf8",
|
|
48
|
+
});
|
|
49
|
+
if (archive.status !== 0 || archive.error) {
|
|
50
|
+
throw new Error(archive.stderr || archive.error?.message || "failed to create test archive");
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const server = http.createServer((request, response) => {
|
|
54
|
+
if (request.url !== `/v${packageJson.version}/${assetName}`) {
|
|
55
|
+
response.writeHead(404);
|
|
56
|
+
response.end("not found");
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
response.writeHead(200, { "content-type": "application/gzip" });
|
|
60
|
+
fs.createReadStream(assetPath).pipe(response);
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
await new Promise((resolve) => server.listen(0, "127.0.0.1", resolve));
|
|
64
|
+
const { port } = server.address();
|
|
65
|
+
|
|
66
|
+
try {
|
|
67
|
+
const result = await runPostinstall(path.join(scriptDir, "postinstall.js"), {
|
|
68
|
+
cwd: tempRoot,
|
|
69
|
+
env: {
|
|
70
|
+
...process.env,
|
|
71
|
+
CARGO: path.join(tempRoot, "missing-cargo"),
|
|
72
|
+
DART_DECIMATE_RELEASE_BASE_URL: `http://127.0.0.1:${port}/v${packageJson.version}`,
|
|
73
|
+
},
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
if (result.stdout) {
|
|
77
|
+
process.stdout.write(result.stdout);
|
|
78
|
+
}
|
|
79
|
+
if (result.stderr) {
|
|
80
|
+
process.stderr.write(result.stderr);
|
|
81
|
+
}
|
|
82
|
+
if (result.status !== 0 || result.error) {
|
|
83
|
+
throw new Error(result.error?.message || `postinstall exited ${result.status}`);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
for (const binary of ["dart-decimate", "dart-decimate-mcp"]) {
|
|
87
|
+
const installed = path.join(
|
|
88
|
+
tempRoot,
|
|
89
|
+
"npm",
|
|
90
|
+
"bin-cache",
|
|
91
|
+
process.platform === "win32" ? `${binary}.exe` : binary,
|
|
92
|
+
);
|
|
93
|
+
if (!fs.existsSync(installed)) {
|
|
94
|
+
throw new Error(`missing installed prebuilt binary ${binary}`);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
} finally {
|
|
98
|
+
await new Promise((resolve) => server.close(resolve));
|
|
99
|
+
fs.rmSync(tempRoot, { recursive: true, force: true });
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
function runPostinstall(script, options) {
|
|
104
|
+
return new Promise((resolve) => {
|
|
105
|
+
const child = spawn("node", [script], options);
|
|
106
|
+
let stdout = "";
|
|
107
|
+
let stderr = "";
|
|
108
|
+
|
|
109
|
+
child.stdout.on("data", (chunk) => {
|
|
110
|
+
stdout += chunk;
|
|
111
|
+
});
|
|
112
|
+
child.stderr.on("data", (chunk) => {
|
|
113
|
+
stderr += chunk;
|
|
114
|
+
});
|
|
115
|
+
child.on("error", (error) => {
|
|
116
|
+
resolve({ error, stdout, stderr, status: null });
|
|
117
|
+
});
|
|
118
|
+
child.on("close", (status) => {
|
|
119
|
+
resolve({ stdout, stderr, status });
|
|
120
|
+
});
|
|
121
|
+
});
|
|
122
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dart-decimate",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.2",
|
|
4
4
|
"description": "Rust-native codebase intelligence for Dart and Flutter module graphs.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"bin": {
|
|
@@ -33,6 +33,7 @@
|
|
|
33
33
|
"pack:check": "npm pack --dry-run",
|
|
34
34
|
"test:npm": "node npm/bin/dart-decimate.js --help",
|
|
35
35
|
"test:npm:mcp": "printf '{\"jsonrpc\":\"2.0\",\"id\":1,\"method\":\"initialize\",\"params\":{\"protocolVersion\":\"2025-11-25\"}}\\n' | node npm/bin/dart-decimate-mcp.js",
|
|
36
|
+
"test:postinstall:prebuilt": "node npm/scripts/test-postinstall-prebuilt.js",
|
|
36
37
|
"test:npx:local": "node npm/scripts/test-npx-local.js",
|
|
37
38
|
"test:npx:mcp:local": "node npm/scripts/test-npx-mcp-local.js"
|
|
38
39
|
},
|
package/src/cli/coverage_run.rs
CHANGED
|
@@ -314,20 +314,20 @@ fn coverage_health_options(subcommand: &ArgMatches, mut options: HealthOptions)
|
|
|
314
314
|
options.ownership = false.into();
|
|
315
315
|
|
|
316
316
|
options.runtime_coverage_path = subcommand.get_one::<PathBuf>("runtime-coverage").cloned();
|
|
317
|
-
if subcommand.value_source("min-invocations-hot") == Some(ValueSource::CommandLine)
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
317
|
+
if subcommand.value_source("min-invocations-hot") == Some(ValueSource::CommandLine) {
|
|
318
|
+
if let Some(value) = subcommand.get_one::<usize>("min-invocations-hot") {
|
|
319
|
+
options.min_invocations_hot = (*value).max(1);
|
|
320
|
+
}
|
|
321
321
|
}
|
|
322
|
-
if subcommand.value_source("min-observation-volume") == Some(ValueSource::CommandLine)
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
322
|
+
if subcommand.value_source("min-observation-volume") == Some(ValueSource::CommandLine) {
|
|
323
|
+
if let Some(value) = subcommand.get_one::<usize>("min-observation-volume") {
|
|
324
|
+
options.min_observation_volume = (*value).max(1);
|
|
325
|
+
}
|
|
326
326
|
}
|
|
327
|
-
if subcommand.value_source("low-traffic-threshold") == Some(ValueSource::CommandLine)
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
327
|
+
if subcommand.value_source("low-traffic-threshold") == Some(ValueSource::CommandLine) {
|
|
328
|
+
if let Some(value) = subcommand.get_one::<f64>("low-traffic-threshold") {
|
|
329
|
+
options.low_traffic_threshold = LowTrafficThreshold::from_ratio(*value);
|
|
330
|
+
}
|
|
331
331
|
}
|
|
332
332
|
if let Some(top) = subcommand.get_one::<usize>("top") {
|
|
333
333
|
options.top = Some(*top);
|
package/src/cli/request_args.rs
CHANGED
|
@@ -50,10 +50,10 @@ pub(super) fn policy_pack_paths(
|
|
|
50
50
|
config: &DartDecimateConfig,
|
|
51
51
|
) -> Vec<PathBuf> {
|
|
52
52
|
let mut paths = config.policy_packs.clone();
|
|
53
|
-
if matches!(command, ReportCommand::Check | ReportCommand::Audit)
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
53
|
+
if matches!(command, ReportCommand::Check | ReportCommand::Audit) {
|
|
54
|
+
if let Some(values) = subcommand.get_many::<PathBuf>("policy-pack") {
|
|
55
|
+
paths.extend(values.cloned());
|
|
56
|
+
}
|
|
57
57
|
}
|
|
58
58
|
paths
|
|
59
59
|
}
|
package/src/dart_parser.rs
CHANGED
|
@@ -167,10 +167,11 @@ fn primary_constructor_header(
|
|
|
167
167
|
let class_name = source[name_start..name_end].to_owned();
|
|
168
168
|
let mut header_cursor = skip_whitespace(source, name_end).unwrap_or(name_end);
|
|
169
169
|
|
|
170
|
-
if source.as_bytes().get(header_cursor).copied() == Some(b'<')
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
170
|
+
if source.as_bytes().get(header_cursor).copied() == Some(b'<') {
|
|
171
|
+
if let Some(type_params_end) = matching_delimiter(source, header_cursor, b'<', b'>') {
|
|
172
|
+
header_cursor =
|
|
173
|
+
skip_whitespace(source, type_params_end + 1).unwrap_or(type_params_end + 1);
|
|
174
|
+
}
|
|
174
175
|
}
|
|
175
176
|
|
|
176
177
|
let replacement_start = primary_constructor_replacement_start(source, &mut header_cursor)?;
|
|
@@ -259,16 +260,18 @@ fn push_constructor_body_replacement(
|
|
|
259
260
|
replacements: &mut Vec<Replacement>,
|
|
260
261
|
header: &PrimaryConstructorHeader,
|
|
261
262
|
) {
|
|
262
|
-
if let Some((terminator_start, _)) = header.terminator
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
263
|
+
if let Some((terminator_start, _)) = header.terminator {
|
|
264
|
+
if let Some(body_end) = matching_delimiter(source, terminator_start, b'{', b'}') {
|
|
265
|
+
if let Some(this_start) =
|
|
266
|
+
find_primary_constructor_body(source, terminator_start + 1, body_end)
|
|
267
|
+
{
|
|
268
|
+
replacements.push(Replacement {
|
|
269
|
+
start: this_start,
|
|
270
|
+
end: this_start + "this".len(),
|
|
271
|
+
kind: ReplacementKind::ConstructorBody(header.class_name.clone()),
|
|
272
|
+
});
|
|
273
|
+
}
|
|
274
|
+
}
|
|
272
275
|
}
|
|
273
276
|
}
|
|
274
277
|
|
package/src/extract/members.rs
CHANGED
|
@@ -195,10 +195,10 @@ fn collect_member_field_names(node: Node<'_>, source: &str, names: &mut Vec<Stri
|
|
|
195
195
|
&["static_final_declaration", "initialized_identifier"],
|
|
196
196
|
names,
|
|
197
197
|
);
|
|
198
|
-
if names.is_empty()
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
198
|
+
if names.is_empty() {
|
|
199
|
+
if let Some(identifier_list) = find_first_named_descendant(node, "identifier_list") {
|
|
200
|
+
collect_direct_identifier_children(identifier_list, source, names);
|
|
201
|
+
}
|
|
202
202
|
}
|
|
203
203
|
}
|
|
204
204
|
|
|
@@ -75,11 +75,11 @@ fn primary_constructor_headers(source: &str) -> Vec<PrimaryConstructorHeader> {
|
|
|
75
75
|
};
|
|
76
76
|
let declaration = source[name_start..name_end].to_owned();
|
|
77
77
|
let mut header_cursor = skip_whitespace(source, name_end).unwrap_or(name_end);
|
|
78
|
-
if source.as_bytes().get(header_cursor).copied() == Some(b'<')
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
78
|
+
if source.as_bytes().get(header_cursor).copied() == Some(b'<') {
|
|
79
|
+
if let Some(type_params_end) = matching_delimiter(source, header_cursor, b'<', b'>') {
|
|
80
|
+
header_cursor =
|
|
81
|
+
skip_whitespace(source, type_params_end + 1).unwrap_or(type_params_end + 1);
|
|
82
|
+
}
|
|
83
83
|
}
|
|
84
84
|
if source.as_bytes().get(header_cursor).copied() == Some(b'.') {
|
|
85
85
|
let suffix_start =
|
|
@@ -16,13 +16,13 @@ fn collect_identifier_references(
|
|
|
16
16
|
source: &str,
|
|
17
17
|
references: &mut Vec<IdentifierReference>,
|
|
18
18
|
) {
|
|
19
|
-
if is_reference_identifier(node, source)
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
}
|
|
19
|
+
if is_reference_identifier(node, source) {
|
|
20
|
+
if let Ok(name) = node.utf8_text(source.as_bytes()) {
|
|
21
|
+
references.push(IdentifierReference {
|
|
22
|
+
name: name.to_owned(),
|
|
23
|
+
location: node.start_position().into(),
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
26
|
}
|
|
27
27
|
|
|
28
28
|
let mut cursor = node.walk();
|
package/src/extract/routes.rs
CHANGED
|
@@ -72,35 +72,35 @@ fn collect_raw_routes_in(
|
|
|
72
72
|
parent_resolved: bool,
|
|
73
73
|
routes: &mut Vec<DartRouteDeclaration>,
|
|
74
74
|
) {
|
|
75
|
-
if is_object_constructor(node)
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
75
|
+
if is_object_constructor(node) {
|
|
76
|
+
if let Some(route_kind) = raw_route_constructor_kind(node, source) {
|
|
77
|
+
let next_parent = match route_kind {
|
|
78
|
+
RawRouteKind::GoRoute => collect_go_route(
|
|
79
|
+
node,
|
|
80
|
+
source,
|
|
81
|
+
constants,
|
|
82
|
+
parent_path,
|
|
83
|
+
parent_resolved,
|
|
84
|
+
routes,
|
|
85
|
+
),
|
|
86
|
+
RawRouteKind::RouteContainer => None,
|
|
87
|
+
};
|
|
88
|
+
let next_parent_resolved = match route_kind {
|
|
89
|
+
RawRouteKind::GoRoute => next_parent.is_some(),
|
|
90
|
+
RawRouteKind::RouteContainer => parent_resolved,
|
|
91
|
+
};
|
|
92
|
+
for child_routes_arg in route_child_argument_nodes(node, source) {
|
|
93
|
+
collect_raw_routes_in(
|
|
94
|
+
child_routes_arg,
|
|
95
|
+
source,
|
|
96
|
+
constants,
|
|
97
|
+
next_parent.as_deref().or(parent_path),
|
|
98
|
+
next_parent_resolved,
|
|
99
|
+
routes,
|
|
100
|
+
);
|
|
101
|
+
}
|
|
102
|
+
return;
|
|
102
103
|
}
|
|
103
|
-
return;
|
|
104
104
|
}
|
|
105
105
|
|
|
106
106
|
let mut cursor = node.walk();
|
|
@@ -235,17 +235,19 @@ fn collect_string_constants_in(
|
|
|
235
235
|
node.kind(),
|
|
236
236
|
"static_final_declaration" | "initialized_identifier"
|
|
237
237
|
) && is_const_string_declaration(node, source)
|
|
238
|
-
&& let Some(name) = field_text(node, "name", source)
|
|
239
|
-
&& let Some(value) = node.child_by_field_name("value").and_then(|value| {
|
|
240
|
-
value
|
|
241
|
-
.utf8_text(source.as_bytes())
|
|
242
|
-
.ok()
|
|
243
|
-
.and_then(unquote_dart_string)
|
|
244
|
-
})
|
|
245
238
|
{
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
239
|
+
if let Some(name) = field_text(node, "name", source) {
|
|
240
|
+
if let Some(value) = node.child_by_field_name("value").and_then(|value| {
|
|
241
|
+
value
|
|
242
|
+
.utf8_text(source.as_bytes())
|
|
243
|
+
.ok()
|
|
244
|
+
.and_then(unquote_dart_string)
|
|
245
|
+
}) {
|
|
246
|
+
constants.insert(name.clone(), value.clone());
|
|
247
|
+
if let Some(class_name) = containing_class_name(node, source) {
|
|
248
|
+
constants.insert(format!("{class_name}.{name}"), value);
|
|
249
|
+
}
|
|
250
|
+
}
|
|
249
251
|
}
|
|
250
252
|
}
|
|
251
253
|
|
|
@@ -192,10 +192,10 @@ fn variable_names(node: Node<'_>, source: &str) -> Vec<String> {
|
|
|
192
192
|
&mut names,
|
|
193
193
|
);
|
|
194
194
|
|
|
195
|
-
if names.is_empty()
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
195
|
+
if names.is_empty() {
|
|
196
|
+
if let Some(identifier_list) = find_first_named_descendant(node, "identifier_list") {
|
|
197
|
+
collect_direct_identifier_children(identifier_list, source, &mut names);
|
|
198
|
+
}
|
|
199
199
|
}
|
|
200
200
|
|
|
201
201
|
names
|
|
@@ -218,10 +218,10 @@ fn collect_named_fields(
|
|
|
218
218
|
owner_kinds: &[&str],
|
|
219
219
|
names: &mut Vec<String>,
|
|
220
220
|
) {
|
|
221
|
-
if owner_kinds.contains(&node.kind())
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
221
|
+
if owner_kinds.contains(&node.kind()) {
|
|
222
|
+
if let Some(name) = field_text(node, "name", source) {
|
|
223
|
+
names.push(name);
|
|
224
|
+
}
|
|
225
225
|
}
|
|
226
226
|
|
|
227
227
|
let mut cursor = node.walk();
|
package/src/extract/strings.rs
CHANGED
|
@@ -13,9 +13,10 @@ fn quoted_dart_string_body(trimmed: &str) -> Option<(&str, bool)> {
|
|
|
13
13
|
if let Some(raw) = trimmed
|
|
14
14
|
.strip_prefix('r')
|
|
15
15
|
.or_else(|| trimmed.strip_prefix('R'))
|
|
16
|
-
&& let Some(quoted) = quoted_dart_string_body_without_prefix(raw)
|
|
17
16
|
{
|
|
18
|
-
|
|
17
|
+
if let Some(quoted) = quoted_dart_string_body_without_prefix(raw) {
|
|
18
|
+
return Some((quoted, true));
|
|
19
|
+
}
|
|
19
20
|
}
|
|
20
21
|
|
|
21
22
|
quoted_dart_string_body_without_prefix(trimmed).map(|quoted| (quoted, false))
|
package/src/extract.rs
CHANGED
|
@@ -536,10 +536,10 @@ fn push_variable_declarations(
|
|
|
536
536
|
&mut names,
|
|
537
537
|
);
|
|
538
538
|
|
|
539
|
-
if names.is_empty()
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
539
|
+
if names.is_empty() {
|
|
540
|
+
if let Some(identifier_list) = find_first_named_descendant(node, "identifier_list") {
|
|
541
|
+
collect_direct_identifier_children(identifier_list, source, &mut names);
|
|
542
|
+
}
|
|
543
543
|
}
|
|
544
544
|
|
|
545
545
|
declarations.extend(names.into_iter().map(|name| TopLevelDeclaration {
|
|
@@ -587,10 +587,10 @@ fn collect_named_fields(
|
|
|
587
587
|
owner_kinds: &[&str],
|
|
588
588
|
names: &mut Vec<String>,
|
|
589
589
|
) {
|
|
590
|
-
if owner_kinds.contains(&node.kind())
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
590
|
+
if owner_kinds.contains(&node.kind()) {
|
|
591
|
+
if let Some(name) = field_text(node, "name", source) {
|
|
592
|
+
names.push(name);
|
|
593
|
+
}
|
|
594
594
|
}
|
|
595
595
|
|
|
596
596
|
let mut cursor = node.walk();
|
package/src/graph.rs
CHANGED
|
@@ -388,23 +388,23 @@ fn add_file_dependencies(
|
|
|
388
388
|
return;
|
|
389
389
|
};
|
|
390
390
|
|
|
391
|
-
if let Some(library) = &file.library
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
391
|
+
if let Some(library) = &file.library {
|
|
392
|
+
if let Some(augment_uri) = &library.augment_uri {
|
|
393
|
+
add_dependency(
|
|
394
|
+
root,
|
|
395
|
+
packages,
|
|
396
|
+
known_paths,
|
|
397
|
+
nodes_by_path,
|
|
398
|
+
graph,
|
|
399
|
+
unresolved,
|
|
400
|
+
from_index,
|
|
401
|
+
&from_path,
|
|
402
|
+
augment_uri,
|
|
403
|
+
DependencyKind::Augment,
|
|
404
|
+
library.location,
|
|
405
|
+
DependencyVisibility::default(),
|
|
406
|
+
);
|
|
407
|
+
}
|
|
408
408
|
}
|
|
409
409
|
|
|
410
410
|
let imports = selected_imports(&file.imports, &options.conditional_environment);
|
|
@@ -572,13 +572,14 @@ fn percent_decode_uri_path(value: &str) -> String {
|
|
|
572
572
|
let mut index = 0;
|
|
573
573
|
|
|
574
574
|
while index < bytes.len() {
|
|
575
|
-
if bytes[index] == b'%'
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
575
|
+
if bytes[index] == b'%' {
|
|
576
|
+
if let (Some(high), Some(low)) = (bytes.get(index + 1), bytes.get(index + 2)) {
|
|
577
|
+
if let Some(decoded_byte) = decode_hex_pair(*high, *low) {
|
|
578
|
+
decoded.push(decoded_byte);
|
|
579
|
+
index += 3;
|
|
580
|
+
continue;
|
|
581
|
+
}
|
|
582
|
+
}
|
|
582
583
|
}
|
|
583
584
|
|
|
584
585
|
decoded.push(bytes[index]);
|
|
@@ -535,11 +535,11 @@ fn decode_runtime_path(raw_path: &str) -> String {
|
|
|
535
535
|
if byte == b'%' {
|
|
536
536
|
let high = bytes.next();
|
|
537
537
|
let low = bytes.next();
|
|
538
|
-
if let (Some(high), Some(low)) = (high, low)
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
538
|
+
if let (Some(high), Some(low)) = (high, low) {
|
|
539
|
+
if let Some(decoded) = decode_hex_pair(high, low) {
|
|
540
|
+
output.push(char::from(decoded));
|
|
541
|
+
continue;
|
|
542
|
+
}
|
|
543
543
|
}
|
|
544
544
|
output.push('%');
|
|
545
545
|
if let Some(high) = high {
|
package/src/output/next_steps.rs
CHANGED
|
@@ -72,20 +72,20 @@ pub(super) fn next_steps(root: &Path, results: &AnalysisResults) -> Vec<NextStep
|
|
|
72
72
|
});
|
|
73
73
|
}
|
|
74
74
|
|
|
75
|
-
if let Some(health) = &results.health
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
)
|
|
88
|
-
}
|
|
75
|
+
if let Some(health) = &results.health {
|
|
76
|
+
if let Some(complexity) = health.complexity.first() {
|
|
77
|
+
steps.push(NextStep {
|
|
78
|
+
id: "complexity-breakdown".to_owned(),
|
|
79
|
+
command: format!(
|
|
80
|
+
"dart-decimate health --format json --complexity-breakdown --top 1 --max-cyclomatic {} --max-cognitive {}",
|
|
81
|
+
health.options.max_cyclomatic, health.options.max_cognitive
|
|
82
|
+
),
|
|
83
|
+
reason: format!(
|
|
84
|
+
"Explain the decision points driving complexity in {}",
|
|
85
|
+
display_path(root, &complexity.path)
|
|
86
|
+
),
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
89
|
}
|
|
90
90
|
|
|
91
91
|
steps
|
|
@@ -127,10 +127,10 @@ fn result_properties(
|
|
|
127
127
|
properties.insert("safeToDelete".to_owned(), json!(finding.safe_to_delete));
|
|
128
128
|
properties.insert("files".to_owned(), json!(&finding.files));
|
|
129
129
|
properties.insert("actions".to_owned(), json!(&finding.actions));
|
|
130
|
-
if let Some(fingerprint) = &finding.fingerprint
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
130
|
+
if let Some(fingerprint) = &finding.fingerprint {
|
|
131
|
+
if let Some(reachability) = reachability_by_fingerprint.get(fingerprint) {
|
|
132
|
+
properties.insert("securityReachability".to_owned(), reachability.clone());
|
|
133
|
+
}
|
|
134
134
|
}
|
|
135
135
|
Value::Object(properties)
|
|
136
136
|
}
|
|
@@ -222,18 +222,18 @@ struct ParsedSuppression {
|
|
|
222
222
|
fn parse_suppression(line: &str) -> Option<ParsedSuppression> {
|
|
223
223
|
let comment = line.trim_start().strip_prefix("//")?.trim_start();
|
|
224
224
|
for directive in ["dart-decimate-ignore-next-line"] {
|
|
225
|
-
if let Some(rest) = comment.strip_prefix(directive)
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
.
|
|
235
|
-
|
|
236
|
-
}
|
|
225
|
+
if let Some(rest) = comment.strip_prefix(directive) {
|
|
226
|
+
if rest.chars().next().is_none_or(char::is_whitespace) {
|
|
227
|
+
let (rules, reason) = split_reason(rest.trim_start());
|
|
228
|
+
return Some(ParsedSuppression {
|
|
229
|
+
rules: rules
|
|
230
|
+
.split(|character: char| character == ',' || character.is_whitespace())
|
|
231
|
+
.filter(|rule| !rule.is_empty())
|
|
232
|
+
.map(str::to_owned)
|
|
233
|
+
.collect(),
|
|
234
|
+
has_reason: reason.is_some_and(|value| !value.trim().is_empty()),
|
|
235
|
+
});
|
|
236
|
+
}
|
|
237
237
|
}
|
|
238
238
|
}
|
|
239
239
|
None
|
package/src/package_map.rs
CHANGED
|
@@ -155,9 +155,10 @@ impl PackageMap {
|
|
|
155
155
|
self.discover_nested_pubspecs(&path, visited)?;
|
|
156
156
|
} else if file_type.is_file()
|
|
157
157
|
&& path.file_name().is_some_and(|name| name == "pubspec.yaml")
|
|
158
|
-
&& let Some(package_root) = path.parent()
|
|
159
158
|
{
|
|
160
|
-
|
|
159
|
+
if let Some(package_root) = path.parent() {
|
|
160
|
+
self.discover_pubspec(package_root, visited)?;
|
|
161
|
+
}
|
|
161
162
|
}
|
|
162
163
|
}
|
|
163
164
|
|
|
@@ -315,7 +316,7 @@ fn percent_decode(value: &str) -> Option<String> {
|
|
|
315
316
|
if bytes[index] == b'%' {
|
|
316
317
|
let high = hex_value(*bytes.get(index + 1)?)?;
|
|
317
318
|
let low = hex_value(*bytes.get(index + 2)?)?;
|
|
318
|
-
decoded.push(high << 4 | low);
|
|
319
|
+
decoded.push((high << 4) | low);
|
|
319
320
|
index += 3;
|
|
320
321
|
} else {
|
|
321
322
|
decoded.push(bytes[index]);
|
package/src/security/detect.rs
CHANGED
|
@@ -311,13 +311,12 @@ fn string_literals(source: &str) -> Vec<StringLiteral> {
|
|
|
311
311
|
let mut index = 0;
|
|
312
312
|
let bytes = source.as_bytes();
|
|
313
313
|
while index < bytes.len() {
|
|
314
|
-
if matches!(bytes[index], b'\'' | b'"')
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
continue;
|
|
314
|
+
if matches!(bytes[index], b'\'' | b'"') && !is_comment_match(source, index) {
|
|
315
|
+
if let Some((value, end)) = read_string(source, index) {
|
|
316
|
+
literals.push(StringLiteral { index, value });
|
|
317
|
+
index = end;
|
|
318
|
+
continue;
|
|
319
|
+
}
|
|
321
320
|
}
|
|
322
321
|
index += 1;
|
|
323
322
|
}
|
|
@@ -116,15 +116,14 @@ fn is_abstract_class(class: Node<'_>, source: &str) -> bool {
|
|
|
116
116
|
fn object_constructor_names(root: Node<'_>, source: &str) -> Vec<String> {
|
|
117
117
|
let mut constructors = Vec::new();
|
|
118
118
|
visit_named(root, &mut |node| {
|
|
119
|
-
if is_object_constructor(node)
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
constructors.extend(constructor_name_candidates(constructor));
|
|
119
|
+
if is_object_constructor(node) && !has_ancestor_kind(node, &["annotation"]) {
|
|
120
|
+
if let Some(constructor) = constructor_type_name(node, source) {
|
|
121
|
+
constructors.extend(constructor_name_candidates(&constructor));
|
|
122
|
+
}
|
|
123
|
+
} else if is_arrow_body_constructor_identifier(node, source) {
|
|
124
|
+
if let Ok(constructor) = node.utf8_text(source.as_bytes()) {
|
|
125
|
+
constructors.extend(constructor_name_candidates(constructor));
|
|
126
|
+
}
|
|
128
127
|
}
|
|
129
128
|
});
|
|
130
129
|
constructors
|