dart-decimate 0.0.1 → 0.0.3
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/bin/dart-decimate-mcp.js +2 -45
- package/npm/bin/dart-decimate.js +2 -45
- package/npm/bin/runner.js +79 -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-npx-prebuilt.js +126 -0
- package/npm/scripts/test-postinstall-prebuilt.js +122 -0
- package/package.json +3 -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.3"
|
|
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.3"
|
|
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.3"
|
|
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.3`.
|
|
600
660
|
|
|
601
661
|
After the first public release, changes should go through pull requests.
|
|
602
662
|
|
|
Binary file
|
|
@@ -1,48 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
|
-
const {
|
|
4
|
-
const fs = require("node:fs");
|
|
5
|
-
const path = require("node:path");
|
|
3
|
+
const { runBinary } = require("./runner");
|
|
6
4
|
|
|
7
|
-
|
|
8
|
-
const exeName = process.platform === "win32" ? "dart-decimate-mcp.exe" : "dart-decimate-mcp";
|
|
9
|
-
const cachedBinary = path.join(root, "npm", "bin-cache", exeName);
|
|
10
|
-
const releaseBinary = path.join(root, "target", "release", exeName);
|
|
11
|
-
const debugBinary = path.join(root, "target", "debug", exeName);
|
|
12
|
-
const args = process.argv.slice(2);
|
|
13
|
-
|
|
14
|
-
for (const candidate of [cachedBinary, releaseBinary, debugBinary]) {
|
|
15
|
-
if (fs.existsSync(candidate)) {
|
|
16
|
-
run(candidate, args);
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
const cargo = process.env.CARGO || "cargo";
|
|
21
|
-
run(cargo, ["run", "--release", "--locked", "--bin", "dart-decimate-mcp", "--", ...args], root);
|
|
22
|
-
|
|
23
|
-
function run(command, commandArgs, cwd = undefined) {
|
|
24
|
-
const result = spawnSync(command, commandArgs, {
|
|
25
|
-
cwd,
|
|
26
|
-
stdio: "inherit",
|
|
27
|
-
windowsHide: false
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
if (result.error) {
|
|
31
|
-
if (result.error.code === "ENOENT") {
|
|
32
|
-
console.error(
|
|
33
|
-
"dart-decimate-mcp: Rust/Cargo is required to build the npm source package. " +
|
|
34
|
-
"Install Rust from https://rustup.rs or use a release package with a prebuilt binary."
|
|
35
|
-
);
|
|
36
|
-
process.exit(127);
|
|
37
|
-
}
|
|
38
|
-
console.error(`dart-decimate-mcp: failed to execute ${command}: ${result.error.message}`);
|
|
39
|
-
process.exit(1);
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
if (result.signal) {
|
|
43
|
-
process.kill(process.pid, result.signal);
|
|
44
|
-
return;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
process.exit(result.status ?? 1);
|
|
48
|
-
}
|
|
5
|
+
runBinary("dart-decimate-mcp", process.argv.slice(2));
|
package/npm/bin/dart-decimate.js
CHANGED
|
@@ -1,48 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
|
-
const {
|
|
4
|
-
const fs = require("node:fs");
|
|
5
|
-
const path = require("node:path");
|
|
3
|
+
const { runBinary } = require("./runner");
|
|
6
4
|
|
|
7
|
-
|
|
8
|
-
const exeName = process.platform === "win32" ? "dart-decimate.exe" : "dart-decimate";
|
|
9
|
-
const cachedBinary = path.join(root, "npm", "bin-cache", exeName);
|
|
10
|
-
const releaseBinary = path.join(root, "target", "release", exeName);
|
|
11
|
-
const debugBinary = path.join(root, "target", "debug", exeName);
|
|
12
|
-
const args = process.argv.slice(2);
|
|
13
|
-
|
|
14
|
-
for (const candidate of [cachedBinary, releaseBinary, debugBinary]) {
|
|
15
|
-
if (fs.existsSync(candidate)) {
|
|
16
|
-
run(candidate, args);
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
const cargo = process.env.CARGO || "cargo";
|
|
21
|
-
run(cargo, ["run", "--release", "--locked", "--bin", "dart-decimate", "--", ...args], root);
|
|
22
|
-
|
|
23
|
-
function run(command, commandArgs, cwd = undefined) {
|
|
24
|
-
const result = spawnSync(command, commandArgs, {
|
|
25
|
-
cwd,
|
|
26
|
-
stdio: "inherit",
|
|
27
|
-
windowsHide: false
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
if (result.error) {
|
|
31
|
-
if (result.error.code === "ENOENT") {
|
|
32
|
-
console.error(
|
|
33
|
-
"dart-decimate: Rust/Cargo is required to build the npm source package. " +
|
|
34
|
-
"Install Rust from https://rustup.rs or use a release package with a prebuilt binary."
|
|
35
|
-
);
|
|
36
|
-
process.exit(127);
|
|
37
|
-
}
|
|
38
|
-
console.error(`dart-decimate: failed to execute ${command}: ${result.error.message}`);
|
|
39
|
-
process.exit(1);
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
if (result.signal) {
|
|
43
|
-
process.kill(process.pid, result.signal);
|
|
44
|
-
return;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
process.exit(result.status ?? 1);
|
|
48
|
-
}
|
|
5
|
+
runBinary("dart-decimate", process.argv.slice(2));
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
const { spawnSync } = require("node:child_process");
|
|
2
|
+
const fs = require("node:fs");
|
|
3
|
+
const path = require("node:path");
|
|
4
|
+
|
|
5
|
+
function runBinary(binaryName, args) {
|
|
6
|
+
const root = path.resolve(__dirname, "../..");
|
|
7
|
+
const exeName = process.platform === "win32" ? `${binaryName}.exe` : binaryName;
|
|
8
|
+
const cachedBinary = path.join(root, "npm", "bin-cache", exeName);
|
|
9
|
+
const releaseBinary = path.join(root, "target", "release", exeName);
|
|
10
|
+
const debugBinary = path.join(root, "target", "debug", exeName);
|
|
11
|
+
|
|
12
|
+
runFirstExisting([cachedBinary, releaseBinary, debugBinary], args);
|
|
13
|
+
installCachedBinary(root);
|
|
14
|
+
runFirstExisting([cachedBinary, releaseBinary, debugBinary], args);
|
|
15
|
+
|
|
16
|
+
const cargo = process.env.CARGO || "cargo";
|
|
17
|
+
run(cargo, ["run", "--release", "--locked", "--bin", binaryName, "--", ...args], root, binaryName);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function runFirstExisting(candidates, args) {
|
|
21
|
+
for (const candidate of candidates) {
|
|
22
|
+
if (fs.existsSync(candidate)) {
|
|
23
|
+
run(candidate, args, undefined, path.basename(candidate));
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function installCachedBinary(root) {
|
|
29
|
+
if (process.env.DART_DECIMATE_SKIP_BUILD === "1") {
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const installer = path.join(root, "npm", "scripts", "postinstall.js");
|
|
34
|
+
if (!fs.existsSync(installer)) {
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const result = spawnSync(process.execPath, [installer], {
|
|
39
|
+
cwd: root,
|
|
40
|
+
stdio: "inherit",
|
|
41
|
+
windowsHide: false,
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
if (result.error && result.error.code !== "ENOENT") {
|
|
45
|
+
console.error(`dart-decimate: install step failed to start: ${result.error.message}`);
|
|
46
|
+
}
|
|
47
|
+
if (result.signal) {
|
|
48
|
+
process.kill(process.pid, result.signal);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function run(command, commandArgs, cwd = undefined, label = command) {
|
|
53
|
+
const result = spawnSync(command, commandArgs, {
|
|
54
|
+
cwd,
|
|
55
|
+
stdio: "inherit",
|
|
56
|
+
windowsHide: false,
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
if (result.error) {
|
|
60
|
+
if (result.error.code === "ENOENT") {
|
|
61
|
+
console.error(
|
|
62
|
+
`${label}: Rust/Cargo is required to build the npm source package. ` +
|
|
63
|
+
"Install Rust from https://rustup.rs or use a release package with a prebuilt binary.",
|
|
64
|
+
);
|
|
65
|
+
process.exit(127);
|
|
66
|
+
}
|
|
67
|
+
console.error(`${label}: failed to execute ${command}: ${result.error.message}`);
|
|
68
|
+
process.exit(1);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
if (result.signal) {
|
|
72
|
+
process.kill(process.pid, result.signal);
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
process.exit(result.status ?? 1);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
module.exports = { runBinary };
|
|
@@ -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);
|