dart-decimate 0.0.48 → 0.0.51
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 +5 -5
- package/Cargo.toml +1 -1
- package/README.md +8 -8
- package/npm/bin/runner.js +11 -2
- package/npm/scripts/postinstall.js +16 -9
- package/package.json +11 -7
- package/src/dependencies/discovery.rs +15 -46
- package/src/dependencies/tests.rs +66 -0
- package/src/package_map.rs +41 -26
- package/src/scan.rs +34 -25
- package/npm/scripts/test-npx-local.js +0 -62
- package/npm/scripts/test-npx-mcp-local.js +0 -66
- package/npm/scripts/test-npx-prebuilt.js +0 -146
- package/npm/scripts/test-postinstall-prebuilt.js +0 -142
- package/npm/scripts/test-release-install-parity.js +0 -237
package/Cargo.lock
CHANGED
|
@@ -51,18 +51,18 @@ checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801"
|
|
|
51
51
|
|
|
52
52
|
[[package]]
|
|
53
53
|
name = "clap"
|
|
54
|
-
version = "4.6.
|
|
54
|
+
version = "4.6.7"
|
|
55
55
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
56
|
-
checksum = "
|
|
56
|
+
checksum = "aa8876b300ab35ba921adea3dfd70157a46249b33f95c9084ae5709785478946"
|
|
57
57
|
dependencies = [
|
|
58
58
|
"clap_builder",
|
|
59
59
|
]
|
|
60
60
|
|
|
61
61
|
[[package]]
|
|
62
62
|
name = "clap_builder"
|
|
63
|
-
version = "4.6.
|
|
63
|
+
version = "4.6.7"
|
|
64
64
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
65
|
-
checksum = "
|
|
65
|
+
checksum = "ec0797fb7aeb1406c84efac526901f7ec3ead2124f946b494e72879d4b54704d"
|
|
66
66
|
dependencies = [
|
|
67
67
|
"anstyle",
|
|
68
68
|
"clap_lex",
|
|
@@ -102,7 +102,7 @@ checksum = "a31eee39dddec8330830986fcd7625edb5a24ec90ea038215273bbc3adb08ac6"
|
|
|
102
102
|
|
|
103
103
|
[[package]]
|
|
104
104
|
name = "dart-decimate"
|
|
105
|
-
version = "0.0.
|
|
105
|
+
version = "0.0.51"
|
|
106
106
|
dependencies = [
|
|
107
107
|
"clap",
|
|
108
108
|
"glob",
|
package/Cargo.toml
CHANGED
package/README.md
CHANGED
|
@@ -90,7 +90,7 @@ You do not need to install anything permanently. Use the command above.
|
|
|
90
90
|
For repeatable automation, pin the version:
|
|
91
91
|
|
|
92
92
|
```bash
|
|
93
|
-
npx --yes dart-decimate@0.0.
|
|
93
|
+
npx --yes dart-decimate@0.0.51
|
|
94
94
|
```
|
|
95
95
|
|
|
96
96
|
Add this to `package.json` if you want a short project command:
|
|
@@ -101,7 +101,7 @@ Add this to `package.json` if you want a short project command:
|
|
|
101
101
|
"dart-decimate": "dart-decimate json ."
|
|
102
102
|
},
|
|
103
103
|
"devDependencies": {
|
|
104
|
-
"dart-decimate": "0.0.
|
|
104
|
+
"dart-decimate": "0.0.51"
|
|
105
105
|
}
|
|
106
106
|
}
|
|
107
107
|
```
|
|
@@ -115,7 +115,7 @@ npm run dart-decimate
|
|
|
115
115
|
If you prefer Cargo, install the matching tagged source:
|
|
116
116
|
|
|
117
117
|
```bash
|
|
118
|
-
cargo install --git https://github.com/sgaabdu4/dart-decimate.git --tag v0.0.
|
|
118
|
+
cargo install --git https://github.com/sgaabdu4/dart-decimate.git --tag v0.0.51 --locked
|
|
119
119
|
```
|
|
120
120
|
|
|
121
121
|
The npm release `X.Y.Z` and Cargo tag `vX.Y.Z` are verified against each other
|
|
@@ -126,7 +126,7 @@ Confirm a Cargo build's version with:
|
|
|
126
126
|
|
|
127
127
|
```bash
|
|
128
128
|
dart-decimate --version
|
|
129
|
-
# dart-decimate 0.0.
|
|
129
|
+
# dart-decimate 0.0.51
|
|
130
130
|
```
|
|
131
131
|
|
|
132
132
|
## npx
|
|
@@ -536,7 +536,7 @@ Example shape:
|
|
|
536
536
|
{
|
|
537
537
|
"schema_version": "dart-decimate.report.v1",
|
|
538
538
|
"kind": "combined",
|
|
539
|
-
"tool": "dart-decimate 0.0.
|
|
539
|
+
"tool": "dart-decimate 0.0.51",
|
|
540
540
|
"command": "check",
|
|
541
541
|
"verdict": "fail",
|
|
542
542
|
"summary": {
|
|
@@ -552,7 +552,7 @@ Example shape:
|
|
|
552
552
|
|
|
553
553
|
The `dart-decimate.report.v1` field layout is unchanged. Its existing `tool`
|
|
554
554
|
string includes the producing version so saved reports identify the exact
|
|
555
|
-
build, for example `dart-decimate 0.0.
|
|
555
|
+
build, for example `dart-decimate 0.0.51`.
|
|
556
556
|
|
|
557
557
|
When grouped security findings hide additional occurrences, `next_steps` can
|
|
558
558
|
include `review-security-surface`, which reruns
|
|
@@ -640,7 +640,7 @@ you need the installed binary's exact list.
|
|
|
640
640
|
For a complete repository check, including discovered local packages:
|
|
641
641
|
|
|
642
642
|
```bash
|
|
643
|
-
npx --yes dart-decimate@0.0.
|
|
643
|
+
npx --yes dart-decimate@0.0.51 --strict
|
|
644
644
|
```
|
|
645
645
|
|
|
646
646
|
This runs every enabled check from the repository root. The default duplication
|
|
@@ -683,7 +683,7 @@ This repository forbids `unsafe_code`.
|
|
|
683
683
|
|
|
684
684
|
## Release Flow
|
|
685
685
|
|
|
686
|
-
Current source version: `0.0.
|
|
686
|
+
Current source version: `0.0.51`.
|
|
687
687
|
|
|
688
688
|
After the first public release, changes should go through pull requests. Every
|
|
689
689
|
PR to `main` must bump both `Cargo.toml` and `package.json` above the base
|
package/npm/bin/runner.js
CHANGED
|
@@ -2,6 +2,7 @@ const { spawnSync } = require("node:child_process");
|
|
|
2
2
|
const fs = require("node:fs");
|
|
3
3
|
const path = require("node:path");
|
|
4
4
|
|
|
5
|
+
/** @param {string} binaryName @param {string[]} args */
|
|
5
6
|
function runBinary(binaryName, args) {
|
|
6
7
|
const root = path.resolve(__dirname, "../..");
|
|
7
8
|
const exeName =
|
|
@@ -23,6 +24,7 @@ function runBinary(binaryName, args) {
|
|
|
23
24
|
);
|
|
24
25
|
}
|
|
25
26
|
|
|
27
|
+
/** @param {string[]} candidates @param {string[]} args */
|
|
26
28
|
function runFirstExisting(candidates, args) {
|
|
27
29
|
for (const candidate of candidates) {
|
|
28
30
|
if (fs.existsSync(candidate)) {
|
|
@@ -31,6 +33,7 @@ function runFirstExisting(candidates, args) {
|
|
|
31
33
|
}
|
|
32
34
|
}
|
|
33
35
|
|
|
36
|
+
/** @param {string} root */
|
|
34
37
|
function installCachedBinary(root) {
|
|
35
38
|
if (process.env.DART_DECIMATE_SKIP_BUILD === "1") {
|
|
36
39
|
return;
|
|
@@ -49,15 +52,19 @@ function installCachedBinary(root) {
|
|
|
49
52
|
handleInstallerResult(result);
|
|
50
53
|
}
|
|
51
54
|
|
|
55
|
+
/** @param {import("node:child_process").SpawnSyncReturns<Buffer>} result */
|
|
52
56
|
function handleInstallerResult(result) {
|
|
53
|
-
|
|
57
|
+
/** @type {NodeJS.ErrnoException | undefined} */
|
|
58
|
+
const error = result.error;
|
|
59
|
+
if (error && error.code !== "ENOENT") {
|
|
54
60
|
console.error(
|
|
55
|
-
`dart-decimate: install step failed to start: ${
|
|
61
|
+
`dart-decimate: install step failed to start: ${error.message}`,
|
|
56
62
|
);
|
|
57
63
|
}
|
|
58
64
|
forwardSignal(result.signal);
|
|
59
65
|
}
|
|
60
66
|
|
|
67
|
+
/** @param {string} command @param {string[]} commandArgs @param {string | undefined} [cwd] @param {string} [label] */
|
|
61
68
|
function run(command, commandArgs, cwd = undefined, label = command) {
|
|
62
69
|
const result = spawnSync(command, commandArgs, {
|
|
63
70
|
cwd,
|
|
@@ -76,6 +83,7 @@ function run(command, commandArgs, cwd = undefined, label = command) {
|
|
|
76
83
|
process.exit(result.status ?? 1);
|
|
77
84
|
}
|
|
78
85
|
|
|
86
|
+
/** @param {NodeJS.ErrnoException} error @param {string} command @param {string} label */
|
|
79
87
|
function handleRunError(error, command, label) {
|
|
80
88
|
if (error.code === "ENOENT") {
|
|
81
89
|
console.error(
|
|
@@ -88,6 +96,7 @@ function handleRunError(error, command, label) {
|
|
|
88
96
|
process.exit(1);
|
|
89
97
|
}
|
|
90
98
|
|
|
99
|
+
/** @param {NodeJS.Signals | null} signal */
|
|
91
100
|
function forwardSignal(signal) {
|
|
92
101
|
if (!signal) {
|
|
93
102
|
return false;
|
|
@@ -33,6 +33,7 @@ install()
|
|
|
33
33
|
async function install() {
|
|
34
34
|
fs.mkdirSync(cacheDir, { recursive: true });
|
|
35
35
|
|
|
36
|
+
/** @type {unknown} */
|
|
36
37
|
let prebuiltError = null;
|
|
37
38
|
if (process.env.DART_DECIMATE_SKIP_DOWNLOAD !== "1") {
|
|
38
39
|
try {
|
|
@@ -61,6 +62,7 @@ async function installPrebuilt() {
|
|
|
61
62
|
return true;
|
|
62
63
|
}
|
|
63
64
|
|
|
65
|
+
/** @param {string} assetName @param {string} archivePath */
|
|
64
66
|
function extractArchive(assetName, archivePath) {
|
|
65
67
|
const extract = spawnSync("tar", ["-xzf", archivePath, "-C", cacheDir], {
|
|
66
68
|
stdio: "pipe",
|
|
@@ -79,6 +81,7 @@ function extractArchive(assetName, archivePath) {
|
|
|
79
81
|
}
|
|
80
82
|
}
|
|
81
83
|
|
|
84
|
+
/** @param {string} assetName */
|
|
82
85
|
function activateCachedBinaries(assetName) {
|
|
83
86
|
for (const binary of ["dart-decimate", "dart-decimate-mcp"]) {
|
|
84
87
|
const cachedBinary = path.join(cacheDir, `${binary}${exeExt}`);
|
|
@@ -117,10 +120,12 @@ function prebuiltArchitecture() {
|
|
|
117
120
|
return new Set(["x64", "arm64"]).has(process.arch) ? process.arch : null;
|
|
118
121
|
}
|
|
119
122
|
|
|
123
|
+
/** @param {string} platform @param {string} arch */
|
|
120
124
|
function supportsPrebuiltTarget(platform, arch) {
|
|
121
125
|
return !new Set(["linux:arm64", "windows:arm64"]).has(`${platform}:${arch}`);
|
|
122
126
|
}
|
|
123
127
|
|
|
128
|
+
/** @param {string} url @param {string} destination @param {number} redirectCount @returns {Promise<unknown>} */
|
|
124
129
|
function download(url, destination, redirectCount) {
|
|
125
130
|
if (redirectCount > 5) {
|
|
126
131
|
return Promise.reject(
|
|
@@ -144,6 +149,7 @@ function download(url, destination, redirectCount) {
|
|
|
144
149
|
});
|
|
145
150
|
}
|
|
146
151
|
|
|
152
|
+
/** @param {import("node:http").IncomingMessage} response @param {string} url @param {string} destination @param {number} redirectCount @param {(value: unknown) => void} resolve @param {(reason: unknown) => void} reject */
|
|
147
153
|
function handleDownloadResponse(
|
|
148
154
|
response,
|
|
149
155
|
url,
|
|
@@ -152,9 +158,10 @@ function handleDownloadResponse(
|
|
|
152
158
|
resolve,
|
|
153
159
|
reject,
|
|
154
160
|
) {
|
|
155
|
-
|
|
161
|
+
const location = redirectLocation(response);
|
|
162
|
+
if (location) {
|
|
156
163
|
response.resume();
|
|
157
|
-
const nextUrl = new URL(
|
|
164
|
+
const nextUrl = new URL(location, url).toString();
|
|
158
165
|
download(nextUrl, destination, redirectCount + 1).then(resolve, reject);
|
|
159
166
|
return;
|
|
160
167
|
}
|
|
@@ -169,14 +176,13 @@ function handleDownloadResponse(
|
|
|
169
176
|
);
|
|
170
177
|
}
|
|
171
178
|
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
Boolean(response.headers.location)
|
|
177
|
-
);
|
|
179
|
+
/** @param {import("node:http").IncomingMessage} response */
|
|
180
|
+
function redirectLocation(response) {
|
|
181
|
+
const status = response.statusCode ?? 0;
|
|
182
|
+
return status >= 300 && status < 400 ? response.headers.location : undefined;
|
|
178
183
|
}
|
|
179
184
|
|
|
185
|
+
/** @param {unknown} prebuiltError */
|
|
180
186
|
function buildFromSource(prebuiltError) {
|
|
181
187
|
const build = spawnSync(cargo, ["build", "--release", "--locked"], {
|
|
182
188
|
cwd: root,
|
|
@@ -190,12 +196,13 @@ function buildFromSource(prebuiltError) {
|
|
|
190
196
|
cacheBuiltBinaries();
|
|
191
197
|
}
|
|
192
198
|
|
|
199
|
+
/** @param {NodeJS.ErrnoException | undefined} error @param {unknown} prebuiltError */
|
|
193
200
|
function handleBuildStartError(error, prebuiltError) {
|
|
194
201
|
if (!error) {
|
|
195
202
|
return;
|
|
196
203
|
}
|
|
197
204
|
if (error.code === "ENOENT") {
|
|
198
|
-
if (prebuiltError) {
|
|
205
|
+
if (prebuiltError instanceof Error) {
|
|
199
206
|
console.error(
|
|
200
207
|
`dart-decimate: prebuilt install failed: ${prebuiltError.message}`,
|
|
201
208
|
);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dart-decimate",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.51",
|
|
4
4
|
"description": "Rust-native codebase intelligence for Dart and Flutter module graphs.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"bin": {
|
|
@@ -28,6 +28,8 @@
|
|
|
28
28
|
"scripts": {
|
|
29
29
|
"postinstall": "node npm/scripts/postinstall.js",
|
|
30
30
|
"test": "node --test tests/js/*.test.mjs",
|
|
31
|
+
"test:coverage": "node --test --experimental-test-coverage --test-reporter=spec --test-reporter-destination=stdout --test-reporter=junit --test-reporter-destination=coverage/junit.xml --test-reporter=lcov --test-reporter-destination=coverage/lcov.info tests/js/*.test.mjs",
|
|
32
|
+
"test:performance": "cargo build --release --locked --bin dart-decimate && node --test --test-reporter=spec --test-reporter-destination=stdout --test-reporter=junit --test-reporter-destination=coverage/performance.xml tests/performance/*.test.mjs",
|
|
31
33
|
"typecheck": "node scripts/typecheck-js.mjs",
|
|
32
34
|
"version:check": "node scripts/check-version-sync.mjs",
|
|
33
35
|
"lint": "npm run version:check && npm run migration:check && npm run lint:js && npm run format:check",
|
|
@@ -40,19 +42,21 @@
|
|
|
40
42
|
"pack:check": "npm pack --dry-run",
|
|
41
43
|
"test:npm": "node npm/bin/dart-decimate.js --help",
|
|
42
44
|
"test:npm:mcp": "printf '{\"jsonrpc\":\"2.0\",\"id\":1,\"method\":\"initialize\",\"params\":{\"protocolVersion\":\"2025-11-25\"}}\\n' | node npm/bin/dart-decimate-mcp.js",
|
|
43
|
-
"test:postinstall:prebuilt": "node npm/
|
|
44
|
-
"test:npx:prebuilt": "node npm/
|
|
45
|
-
"test:release:parity": "node npm/
|
|
46
|
-
"test:npx:local": "node npm/
|
|
47
|
-
"test:npx:mcp:local": "node npm/
|
|
45
|
+
"test:postinstall:prebuilt": "node tests/npm/test-postinstall-prebuilt.js",
|
|
46
|
+
"test:npx:prebuilt": "node tests/npm/test-npx-prebuilt.js",
|
|
47
|
+
"test:release:parity": "node tests/npm/test-release-install-parity.js",
|
|
48
|
+
"test:npx:local": "node tests/npm/test-npx-local.js",
|
|
49
|
+
"test:npx:mcp:local": "node tests/npm/test-npx-mcp-local.js"
|
|
48
50
|
},
|
|
49
51
|
"engines": {
|
|
50
52
|
"node": ">=22.12.0"
|
|
51
53
|
},
|
|
54
|
+
"packageManager": "pnpm@12.6.0",
|
|
52
55
|
"publishConfig": {
|
|
53
56
|
"access": "public"
|
|
54
57
|
},
|
|
55
58
|
"devDependencies": {
|
|
56
|
-
"@biomejs/biome": "2.5.
|
|
59
|
+
"@biomejs/biome": "2.5.14",
|
|
60
|
+
"@types/node": "22.20.4"
|
|
57
61
|
}
|
|
58
62
|
}
|
|
@@ -1,13 +1,25 @@
|
|
|
1
|
-
use std::
|
|
2
|
-
use std::path::{Path, PathBuf};
|
|
1
|
+
use std::path::Path;
|
|
3
2
|
|
|
4
3
|
use crate::graph::normalize_path;
|
|
4
|
+
use crate::scan::{IgnoreMatcher, project_walk};
|
|
5
5
|
|
|
6
6
|
use super::{DependencyHygieneError, PubPackage, read_package};
|
|
7
7
|
|
|
8
8
|
pub(super) fn discover_packages(root: &Path) -> Result<Vec<PubPackage>, DependencyHygieneError> {
|
|
9
9
|
let mut pubspecs = Vec::new();
|
|
10
|
-
|
|
10
|
+
for entry in project_walk(root, root, &IgnoreMatcher::default()) {
|
|
11
|
+
let entry = entry.map_err(|error| DependencyHygieneError::ReadDir {
|
|
12
|
+
path: root.to_path_buf(),
|
|
13
|
+
source: std::io::Error::other(error),
|
|
14
|
+
})?;
|
|
15
|
+
if entry
|
|
16
|
+
.file_type()
|
|
17
|
+
.is_some_and(|file_type| file_type.is_file())
|
|
18
|
+
&& entry.file_name() == "pubspec.yaml"
|
|
19
|
+
{
|
|
20
|
+
pubspecs.push(normalize_path(entry.path()));
|
|
21
|
+
}
|
|
22
|
+
}
|
|
11
23
|
let mut packages = pubspecs
|
|
12
24
|
.into_iter()
|
|
13
25
|
.filter_map(|path| read_package(&path).transpose())
|
|
@@ -15,46 +27,3 @@ pub(super) fn discover_packages(root: &Path) -> Result<Vec<PubPackage>, Dependen
|
|
|
15
27
|
packages.sort_by(|left, right| left.root.cmp(&right.root));
|
|
16
28
|
Ok(packages)
|
|
17
29
|
}
|
|
18
|
-
|
|
19
|
-
fn discover_pubspecs(
|
|
20
|
-
dir: &Path,
|
|
21
|
-
pubspecs: &mut Vec<PathBuf>,
|
|
22
|
-
) -> Result<(), DependencyHygieneError> {
|
|
23
|
-
let entries = fs::read_dir(dir).map_err(|source| DependencyHygieneError::ReadDir {
|
|
24
|
-
path: dir.to_path_buf(),
|
|
25
|
-
source,
|
|
26
|
-
})?;
|
|
27
|
-
|
|
28
|
-
for entry in entries {
|
|
29
|
-
let entry = entry.map_err(|source| DependencyHygieneError::ReadDirEntry {
|
|
30
|
-
path: dir.to_path_buf(),
|
|
31
|
-
source,
|
|
32
|
-
})?;
|
|
33
|
-
let path = entry.path();
|
|
34
|
-
let file_type = entry
|
|
35
|
-
.file_type()
|
|
36
|
-
.map_err(|source| DependencyHygieneError::FileType {
|
|
37
|
-
path: path.clone(),
|
|
38
|
-
source,
|
|
39
|
-
})?;
|
|
40
|
-
|
|
41
|
-
if file_type.is_dir() {
|
|
42
|
-
if should_skip_dir(&path) {
|
|
43
|
-
continue;
|
|
44
|
-
}
|
|
45
|
-
discover_pubspecs(&path, pubspecs)?;
|
|
46
|
-
} else if file_type.is_file() && path.file_name().is_some_and(|name| name == "pubspec.yaml")
|
|
47
|
-
{
|
|
48
|
-
pubspecs.push(normalize_path(&path));
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
Ok(())
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
pub(super) fn should_skip_dir(path: &Path) -> bool {
|
|
56
|
-
matches!(
|
|
57
|
-
path.file_name().and_then(|name| name.to_str()),
|
|
58
|
-
Some(".dart_tool" | ".git" | ".idea" | ".pub-cache" | "build" | "target")
|
|
59
|
-
)
|
|
60
|
-
}
|
|
@@ -629,6 +629,72 @@ fn analyzes_workspace_packages_independently() -> Result<(), Box<dyn std::error:
|
|
|
629
629
|
Ok(())
|
|
630
630
|
}
|
|
631
631
|
|
|
632
|
+
#[test]
|
|
633
|
+
fn skips_nested_checkout_packages_and_sources() -> Result<(), Box<dyn std::error::Error>> {
|
|
634
|
+
let fixture = tempfile::tempdir()?;
|
|
635
|
+
let app_pubspec = "name: app\ndependencies:\n path: ^1.0.0\n";
|
|
636
|
+
let app_main = "import 'package:path/path.dart';\nvoid main() {}\n";
|
|
637
|
+
write(&fixture, "pubspec.yaml", app_pubspec)?;
|
|
638
|
+
write(&fixture, "lib/main.dart", app_main)?;
|
|
639
|
+
write(&fixture, "packages/feature/pubspec.yaml", "name: feature\n")?;
|
|
640
|
+
write(
|
|
641
|
+
&fixture,
|
|
642
|
+
"packages/feature/lib/feature.dart",
|
|
643
|
+
"class Feature {}\n",
|
|
644
|
+
)?;
|
|
645
|
+
write(
|
|
646
|
+
&fixture,
|
|
647
|
+
"worktrees/wt1/.git",
|
|
648
|
+
"gitdir: ../../.git/worktrees/wt1\n",
|
|
649
|
+
)?;
|
|
650
|
+
write(&fixture, "worktrees/wt1/pubspec.yaml", app_pubspec)?;
|
|
651
|
+
write(&fixture, "worktrees/wt1/test/main_test.dart", app_main)?;
|
|
652
|
+
let project = scan_project(fixture.path())?;
|
|
653
|
+
|
|
654
|
+
let packages = discover_packages(&project.root)?;
|
|
655
|
+
let report = analyze_dependency_hygiene(&project)?;
|
|
656
|
+
|
|
657
|
+
assert_eq!(
|
|
658
|
+
packages
|
|
659
|
+
.iter()
|
|
660
|
+
.map(|package| package.name.as_str())
|
|
661
|
+
.collect::<Vec<_>>(),
|
|
662
|
+
vec!["app", "feature"]
|
|
663
|
+
);
|
|
664
|
+
assert!(
|
|
665
|
+
project
|
|
666
|
+
.files
|
|
667
|
+
.iter()
|
|
668
|
+
.all(|file| !file.path.to_string_lossy().contains("worktrees"))
|
|
669
|
+
);
|
|
670
|
+
assert!(report.unused_dependencies.is_empty());
|
|
671
|
+
|
|
672
|
+
Ok(())
|
|
673
|
+
}
|
|
674
|
+
|
|
675
|
+
#[test]
|
|
676
|
+
fn skips_gitignored_nested_package_dependencies() -> Result<(), Box<dyn std::error::Error>> {
|
|
677
|
+
let fixture = tempfile::tempdir()?;
|
|
678
|
+
write(&fixture, ".gitignore", "scratch/\n")?;
|
|
679
|
+
write(&fixture, "pubspec.yaml", "name: app\n")?;
|
|
680
|
+
write(&fixture, "lib/main.dart", "void main() {}\n")?;
|
|
681
|
+
write(
|
|
682
|
+
&fixture,
|
|
683
|
+
"scratch/pkg/pubspec.yaml",
|
|
684
|
+
"name: pkg\ndependencies:\n http: ^1.0.0\n",
|
|
685
|
+
)?;
|
|
686
|
+
let project = scan_project(fixture.path())?;
|
|
687
|
+
|
|
688
|
+
let packages = discover_packages(&project.root)?;
|
|
689
|
+
let report = analyze_dependency_hygiene(&project)?;
|
|
690
|
+
|
|
691
|
+
assert_eq!(packages.len(), 1);
|
|
692
|
+
assert_eq!(packages[0].name, "app");
|
|
693
|
+
assert!(report.unused_dependencies.is_empty());
|
|
694
|
+
|
|
695
|
+
Ok(())
|
|
696
|
+
}
|
|
697
|
+
|
|
632
698
|
#[test]
|
|
633
699
|
fn reports_dev_dependency_in_production_for_owning_workspace_package()
|
|
634
700
|
-> Result<(), Box<dyn std::error::Error>> {
|
package/src/package_map.rs
CHANGED
|
@@ -6,6 +6,7 @@ use serde::Deserialize;
|
|
|
6
6
|
use serde_yaml_ng::{Mapping, Value};
|
|
7
7
|
|
|
8
8
|
use crate::graph::{GraphError, normalize_path};
|
|
9
|
+
use crate::scan::{IgnoreMatcher, project_walk};
|
|
9
10
|
|
|
10
11
|
#[derive(Debug, Clone, Default)]
|
|
11
12
|
pub(crate) struct PackageMap {
|
|
@@ -199,28 +200,15 @@ impl PackageMap {
|
|
|
199
200
|
dir: &Path,
|
|
200
201
|
visited: &mut BTreeSet<PathBuf>,
|
|
201
202
|
) -> Result<(), GraphError> {
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
source,
|
|
205
|
-
})?;
|
|
206
|
-
|
|
207
|
-
for entry in entries {
|
|
208
|
-
let entry = entry.map_err(|source| GraphError::ReadDirEntry {
|
|
203
|
+
for entry in project_walk(dir, dir, &IgnoreMatcher::default()) {
|
|
204
|
+
let entry = entry.map_err(|error| GraphError::ReadDir {
|
|
209
205
|
path: dir.to_path_buf(),
|
|
210
|
-
source,
|
|
206
|
+
source: std::io::Error::other(error),
|
|
211
207
|
})?;
|
|
212
208
|
let path = entry.path();
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
})?;
|
|
217
|
-
|
|
218
|
-
if file_type.is_dir() {
|
|
219
|
-
if should_skip_dir(&path) {
|
|
220
|
-
continue;
|
|
221
|
-
}
|
|
222
|
-
self.discover_nested_pubspecs(&path, visited)?;
|
|
223
|
-
} else if file_type.is_file()
|
|
209
|
+
if entry
|
|
210
|
+
.file_type()
|
|
211
|
+
.is_some_and(|file_type| file_type.is_file())
|
|
224
212
|
&& path.file_name().is_some_and(|name| name == "pubspec.yaml")
|
|
225
213
|
&& let Some(package_root) = path.parent()
|
|
226
214
|
{
|
|
@@ -565,13 +553,6 @@ fn contains_glob_pattern(value: &str) -> bool {
|
|
|
565
553
|
value.contains('*') || value.contains('?') || value.contains('[')
|
|
566
554
|
}
|
|
567
555
|
|
|
568
|
-
fn should_skip_dir(path: &Path) -> bool {
|
|
569
|
-
matches!(
|
|
570
|
-
path.file_name().and_then(|name| name.to_str()),
|
|
571
|
-
Some(".dart_tool" | ".git" | ".idea" | ".pub-cache" | "build" | "target")
|
|
572
|
-
)
|
|
573
|
-
}
|
|
574
|
-
|
|
575
556
|
#[cfg(test)]
|
|
576
557
|
mod tests {
|
|
577
558
|
use tempfile::TempDir;
|
|
@@ -676,6 +657,40 @@ mod tests {
|
|
|
676
657
|
Ok(())
|
|
677
658
|
}
|
|
678
659
|
|
|
660
|
+
#[test]
|
|
661
|
+
fn skips_nested_checkouts_but_keeps_nested_local_packages()
|
|
662
|
+
-> Result<(), Box<dyn std::error::Error>> {
|
|
663
|
+
let fixture = TempDir::new()?;
|
|
664
|
+
write(&fixture, "pubspec.yaml", "name: app\n")?;
|
|
665
|
+
write(&fixture, "packages/feature/pubspec.yaml", "name: feature\n")?;
|
|
666
|
+
write(
|
|
667
|
+
&fixture,
|
|
668
|
+
"worktrees/wt1/.git",
|
|
669
|
+
"gitdir: ../../.git/worktrees/wt1\n",
|
|
670
|
+
)?;
|
|
671
|
+
write(&fixture, "worktrees/wt1/pubspec.yaml", "name: app_copy\n")?;
|
|
672
|
+
|
|
673
|
+
let packages = PackageMap::discover(fixture.path())?;
|
|
674
|
+
|
|
675
|
+
assert_eq!(packages.names(), vec!["app", "feature"]);
|
|
676
|
+
|
|
677
|
+
Ok(())
|
|
678
|
+
}
|
|
679
|
+
|
|
680
|
+
#[test]
|
|
681
|
+
fn skips_gitignored_nested_pubspecs() -> Result<(), Box<dyn std::error::Error>> {
|
|
682
|
+
let fixture = TempDir::new()?;
|
|
683
|
+
write(&fixture, ".gitignore", "scratch/\n")?;
|
|
684
|
+
write(&fixture, "pubspec.yaml", "name: app\n")?;
|
|
685
|
+
write(&fixture, "scratch/pkg/pubspec.yaml", "name: pkg\n")?;
|
|
686
|
+
|
|
687
|
+
let packages = PackageMap::discover(fixture.path())?;
|
|
688
|
+
|
|
689
|
+
assert_eq!(packages.names(), vec!["app"]);
|
|
690
|
+
|
|
691
|
+
Ok(())
|
|
692
|
+
}
|
|
693
|
+
|
|
679
694
|
fn write(fixture: &TempDir, path: &str, source: &str) -> Result<(), std::io::Error> {
|
|
680
695
|
let path = fixture.path().join(path);
|
|
681
696
|
if let Some(parent) = path.parent() {
|
package/src/scan.rs
CHANGED
|
@@ -2,8 +2,8 @@ use std::collections::{BTreeMap, BTreeSet};
|
|
|
2
2
|
use std::path::{Path, PathBuf};
|
|
3
3
|
|
|
4
4
|
use glob::Pattern;
|
|
5
|
-
use ignore::WalkBuilder;
|
|
6
5
|
use ignore::gitignore::GitignoreBuilder;
|
|
6
|
+
use ignore::{Walk, WalkBuilder};
|
|
7
7
|
use rayon::prelude::*;
|
|
8
8
|
use serde::{Deserialize, Serialize};
|
|
9
9
|
use thiserror::Error;
|
|
@@ -177,7 +177,7 @@ pub fn scan_project_with_options(
|
|
|
177
177
|
fn ignored_by_parent_gitignore(root: &Path, scan_root: &Path) -> bool {
|
|
178
178
|
let Some(repository_root) = root
|
|
179
179
|
.ancestors()
|
|
180
|
-
.find(|ancestor|
|
|
180
|
+
.find(|ancestor| is_repository_root(ancestor))
|
|
181
181
|
else {
|
|
182
182
|
return false;
|
|
183
183
|
};
|
|
@@ -222,27 +222,7 @@ fn discover_dart_files(
|
|
|
222
222
|
ignore_matcher: &IgnoreMatcher,
|
|
223
223
|
paths: &mut BTreeSet<PathBuf>,
|
|
224
224
|
) -> Result<(), ScanError> {
|
|
225
|
-
|
|
226
|
-
let filter_matcher = ignore_matcher.clone();
|
|
227
|
-
let has_repository_ancestor = dir
|
|
228
|
-
.ancestors()
|
|
229
|
-
.any(|ancestor| ancestor.join(".git").exists() || ancestor.join(".jj").exists());
|
|
230
|
-
let mut builder = WalkBuilder::new(dir);
|
|
231
|
-
builder
|
|
232
|
-
.standard_filters(false)
|
|
233
|
-
.git_ignore(true)
|
|
234
|
-
.parents(has_repository_ancestor)
|
|
235
|
-
.require_git(has_repository_ancestor)
|
|
236
|
-
.filter_entry(move |entry| {
|
|
237
|
-
entry.depth() == 0
|
|
238
|
-
|| !(filter_matcher.matches(&filter_root, entry.path())
|
|
239
|
-
|| entry
|
|
240
|
-
.file_type()
|
|
241
|
-
.is_some_and(|file_type| file_type.is_dir())
|
|
242
|
-
&& should_skip_dir(entry.path()))
|
|
243
|
-
});
|
|
244
|
-
|
|
245
|
-
for result in builder.build() {
|
|
225
|
+
for result in project_walk(root, dir, ignore_matcher) {
|
|
246
226
|
let entry = result.map_err(|source| ScanError::Walk {
|
|
247
227
|
path: dir.to_path_buf(),
|
|
248
228
|
source,
|
|
@@ -262,6 +242,29 @@ fn discover_dart_files(
|
|
|
262
242
|
Ok(())
|
|
263
243
|
}
|
|
264
244
|
|
|
245
|
+
/// Walk `dir` with the project's ignore rules: `.gitignore`, the configured
|
|
246
|
+
/// ignore patterns, skipped tool directories and nested checkouts.
|
|
247
|
+
pub(crate) fn project_walk(root: &Path, dir: &Path, ignore_matcher: &IgnoreMatcher) -> Walk {
|
|
248
|
+
let filter_root = root.to_path_buf();
|
|
249
|
+
let filter_matcher = ignore_matcher.clone();
|
|
250
|
+
let has_repository_ancestor = dir.ancestors().any(is_repository_root);
|
|
251
|
+
let mut builder = WalkBuilder::new(dir);
|
|
252
|
+
builder
|
|
253
|
+
.standard_filters(false)
|
|
254
|
+
.git_ignore(true)
|
|
255
|
+
.parents(has_repository_ancestor)
|
|
256
|
+
.require_git(has_repository_ancestor)
|
|
257
|
+
.filter_entry(move |entry| {
|
|
258
|
+
entry.depth() == 0
|
|
259
|
+
|| !(filter_matcher.matches(&filter_root, entry.path())
|
|
260
|
+
|| entry
|
|
261
|
+
.file_type()
|
|
262
|
+
.is_some_and(|file_type| file_type.is_dir())
|
|
263
|
+
&& (should_skip_dir(entry.path()) || is_repository_root(entry.path())))
|
|
264
|
+
});
|
|
265
|
+
builder.build()
|
|
266
|
+
}
|
|
267
|
+
|
|
265
268
|
fn tracked_dart_files(
|
|
266
269
|
root: &Path,
|
|
267
270
|
scan_root: &Path,
|
|
@@ -301,6 +304,12 @@ fn has_skipped_directory(root: &Path, path: &Path) -> bool {
|
|
|
301
304
|
.is_some_and(|parent| parent.ancestors().any(should_skip_dir))
|
|
302
305
|
}
|
|
303
306
|
|
|
307
|
+
/// Whether `dir` is the root of its own Git or Jujutsu checkout, such as a
|
|
308
|
+
/// nested worktree or clone, which belongs to a separate package graph.
|
|
309
|
+
pub(crate) fn is_repository_root(dir: &Path) -> bool {
|
|
310
|
+
dir.join(".git").exists() || dir.join(".jj").exists()
|
|
311
|
+
}
|
|
312
|
+
|
|
304
313
|
fn should_skip_dir(path: &Path) -> bool {
|
|
305
314
|
matches!(
|
|
306
315
|
path.file_name().and_then(|name| name.to_str()),
|
|
@@ -308,8 +317,8 @@ fn should_skip_dir(path: &Path) -> bool {
|
|
|
308
317
|
)
|
|
309
318
|
}
|
|
310
319
|
|
|
311
|
-
#[derive(Debug, Clone)]
|
|
312
|
-
struct IgnoreMatcher {
|
|
320
|
+
#[derive(Debug, Clone, Default)]
|
|
321
|
+
pub(crate) struct IgnoreMatcher {
|
|
313
322
|
patterns: Vec<Pattern>,
|
|
314
323
|
}
|
|
315
324
|
|
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
const { mkdtempSync, readFileSync, rmSync } = require("node:fs");
|
|
4
|
-
const { tmpdir } = require("node:os");
|
|
5
|
-
const { join } = require("node:path");
|
|
6
|
-
const { spawnSync } = require("node:child_process");
|
|
7
|
-
|
|
8
|
-
const root = join(__dirname, "..", "..");
|
|
9
|
-
const tempDir = mkdtempSync(join(tmpdir(), "dart-decimate-npx-"));
|
|
10
|
-
const npmEnv = {
|
|
11
|
-
...process.env,
|
|
12
|
-
npm_config_cache: join(tempDir, "npm-cache"),
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
try {
|
|
16
|
-
const pack = spawnSync(
|
|
17
|
-
"npm",
|
|
18
|
-
["pack", "--json", "--pack-destination", tempDir],
|
|
19
|
-
{ cwd: root, encoding: "utf8", env: npmEnv },
|
|
20
|
-
);
|
|
21
|
-
if (pack.error) {
|
|
22
|
-
process.stderr.write(`failed to execute npm: ${pack.error.message}\n`);
|
|
23
|
-
process.exit(pack.error.code === "ENOENT" ? 127 : 1);
|
|
24
|
-
}
|
|
25
|
-
if (pack.status !== 0) {
|
|
26
|
-
process.stderr.write(pack.stderr || "");
|
|
27
|
-
process.exit(pack.status || 1);
|
|
28
|
-
}
|
|
29
|
-
const [metadata] = JSON.parse(pack.stdout);
|
|
30
|
-
const tarball = join(tempDir, metadata.filename);
|
|
31
|
-
readFileSync(tarball);
|
|
32
|
-
|
|
33
|
-
const result = spawnSync(
|
|
34
|
-
"npx",
|
|
35
|
-
["--yes", "--package", tarball, "--", "dart-decimate", "--help"],
|
|
36
|
-
{
|
|
37
|
-
encoding: "utf8",
|
|
38
|
-
env: { ...npmEnv, DART_DECIMATE_SKIP_DOWNLOAD: "1" },
|
|
39
|
-
},
|
|
40
|
-
);
|
|
41
|
-
if (result.stdout) {
|
|
42
|
-
process.stdout.write(result.stdout);
|
|
43
|
-
}
|
|
44
|
-
if (result.stderr) {
|
|
45
|
-
process.stderr.write(result.stderr);
|
|
46
|
-
}
|
|
47
|
-
if (result.error) {
|
|
48
|
-
process.stderr.write(`failed to execute npx: ${result.error.message}\n`);
|
|
49
|
-
process.exit(result.error.code === "ENOENT" ? 127 : 1);
|
|
50
|
-
}
|
|
51
|
-
if (result.status !== 0) {
|
|
52
|
-
process.exit(result.status || 1);
|
|
53
|
-
}
|
|
54
|
-
if (!result.stdout.includes("Usage: dart-decimate")) {
|
|
55
|
-
process.stderr.write(
|
|
56
|
-
"dart-decimate --help did not print the expected usage\n",
|
|
57
|
-
);
|
|
58
|
-
process.exit(1);
|
|
59
|
-
}
|
|
60
|
-
} finally {
|
|
61
|
-
rmSync(tempDir, { recursive: true, force: true });
|
|
62
|
-
}
|
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
const { mkdtempSync, readFileSync, rmSync } = require("node:fs");
|
|
4
|
-
const { tmpdir } = require("node:os");
|
|
5
|
-
const { join } = require("node:path");
|
|
6
|
-
const { spawnSync } = require("node:child_process");
|
|
7
|
-
|
|
8
|
-
const root = join(__dirname, "..", "..");
|
|
9
|
-
const tempDir = mkdtempSync(join(tmpdir(), "dart-decimate-npx-mcp-"));
|
|
10
|
-
const npmEnv = {
|
|
11
|
-
...process.env,
|
|
12
|
-
npm_config_cache: join(tempDir, "npm-cache"),
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
try {
|
|
16
|
-
const pack = spawnSync(
|
|
17
|
-
"npm",
|
|
18
|
-
["pack", "--json", "--pack-destination", tempDir],
|
|
19
|
-
{ cwd: root, encoding: "utf8", env: npmEnv },
|
|
20
|
-
);
|
|
21
|
-
if (pack.error) {
|
|
22
|
-
process.stderr.write(`failed to execute npm: ${pack.error.message}\n`);
|
|
23
|
-
process.exit(pack.error.code === "ENOENT" ? 127 : 1);
|
|
24
|
-
}
|
|
25
|
-
if (pack.status !== 0) {
|
|
26
|
-
process.stderr.write(pack.stderr || "");
|
|
27
|
-
process.exit(pack.status || 1);
|
|
28
|
-
}
|
|
29
|
-
const [metadata] = JSON.parse(pack.stdout);
|
|
30
|
-
const tarball = join(tempDir, metadata.filename);
|
|
31
|
-
readFileSync(tarball);
|
|
32
|
-
|
|
33
|
-
const initialize =
|
|
34
|
-
'{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":"2025-11-25"}}\n';
|
|
35
|
-
const result = spawnSync(
|
|
36
|
-
"npx",
|
|
37
|
-
["--yes", "--package", tarball, "--", "dart-decimate-mcp"],
|
|
38
|
-
{
|
|
39
|
-
input: initialize,
|
|
40
|
-
encoding: "utf8",
|
|
41
|
-
env: { ...npmEnv, DART_DECIMATE_SKIP_DOWNLOAD: "1" },
|
|
42
|
-
},
|
|
43
|
-
);
|
|
44
|
-
if (result.stdout) {
|
|
45
|
-
process.stdout.write(result.stdout);
|
|
46
|
-
}
|
|
47
|
-
if (result.stderr) {
|
|
48
|
-
process.stderr.write(result.stderr);
|
|
49
|
-
}
|
|
50
|
-
if (result.error) {
|
|
51
|
-
process.stderr.write(`failed to execute npx: ${result.error.message}\n`);
|
|
52
|
-
process.exit(result.error.code === "ENOENT" ? 127 : 1);
|
|
53
|
-
}
|
|
54
|
-
if (result.status !== 0) {
|
|
55
|
-
process.exit(result.status || 1);
|
|
56
|
-
}
|
|
57
|
-
const response = JSON.parse(result.stdout.trim());
|
|
58
|
-
if (response.result?.protocolVersion !== "2025-11-25") {
|
|
59
|
-
process.stderr.write(
|
|
60
|
-
"dart-decimate-mcp did not negotiate MCP 2025-11-25\n",
|
|
61
|
-
);
|
|
62
|
-
process.exit(1);
|
|
63
|
-
}
|
|
64
|
-
} finally {
|
|
65
|
-
rmSync(tempDir, { recursive: true, force: true });
|
|
66
|
-
}
|
|
@@ -1,146 +0,0 @@
|
|
|
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
|
-
if (process.platform === "win32") {
|
|
10
|
-
console.log("skipping npx prebuilt fixture on Windows");
|
|
11
|
-
process.exit(0);
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
const root = path.resolve(__dirname, "../..");
|
|
15
|
-
const tempRoot = fs.mkdtempSync(
|
|
16
|
-
path.join(tmpdir(), "dart-decimate-npx-prebuilt-"),
|
|
17
|
-
);
|
|
18
|
-
|
|
19
|
-
main().catch((error) => {
|
|
20
|
-
console.error(error.message);
|
|
21
|
-
process.exit(1);
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
async function main() {
|
|
25
|
-
const packageJson = JSON.parse(
|
|
26
|
-
fs.readFileSync(path.join(root, "package.json"), "utf8"),
|
|
27
|
-
);
|
|
28
|
-
const platform = process.platform === "win32" ? "windows" : process.platform;
|
|
29
|
-
const arch = process.arch === "x64" ? "x64" : process.arch;
|
|
30
|
-
const assetName = `dart-decimate-${platform}-${arch}.tar.gz`;
|
|
31
|
-
|
|
32
|
-
const projectDir = path.join(tempRoot, "project");
|
|
33
|
-
const payloadDir = path.join(tempRoot, "payload");
|
|
34
|
-
const assetDir = path.join(tempRoot, "assets");
|
|
35
|
-
fs.mkdirSync(projectDir, { recursive: true });
|
|
36
|
-
fs.mkdirSync(payloadDir, { recursive: true });
|
|
37
|
-
fs.mkdirSync(assetDir, { recursive: true });
|
|
38
|
-
|
|
39
|
-
for (const binary of ["dart-decimate", "dart-decimate-mcp"]) {
|
|
40
|
-
const binaryPath = path.join(payloadDir, binary);
|
|
41
|
-
fs.writeFileSync(
|
|
42
|
-
binaryPath,
|
|
43
|
-
`#!/usr/bin/env sh\nprintf '${binary} prebuilt'\nfor arg in "$@"; do printf ' %s' "$arg"; done\nprintf '\\n'\n`,
|
|
44
|
-
);
|
|
45
|
-
fs.chmodSync(binaryPath, 0o755);
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
const assetPath = path.join(assetDir, assetName);
|
|
49
|
-
const archive = spawnSync("tar", ["-czf", assetPath, "-C", payloadDir, "."], {
|
|
50
|
-
encoding: "utf8",
|
|
51
|
-
});
|
|
52
|
-
if (archive.status !== 0 || archive.error) {
|
|
53
|
-
throw new Error(
|
|
54
|
-
archive.stderr ||
|
|
55
|
-
archive.error?.message ||
|
|
56
|
-
"failed to create test archive",
|
|
57
|
-
);
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
const pack = spawnSync(
|
|
61
|
-
"npm",
|
|
62
|
-
["pack", "--json", "--pack-destination", tempRoot],
|
|
63
|
-
{
|
|
64
|
-
cwd: root,
|
|
65
|
-
encoding: "utf8",
|
|
66
|
-
},
|
|
67
|
-
);
|
|
68
|
-
if (pack.status !== 0 || pack.error) {
|
|
69
|
-
throw new Error(
|
|
70
|
-
pack.stderr || pack.error?.message || "failed to pack npm package",
|
|
71
|
-
);
|
|
72
|
-
}
|
|
73
|
-
const [metadata] = JSON.parse(pack.stdout);
|
|
74
|
-
const tarball = path.join(tempRoot, metadata.filename);
|
|
75
|
-
|
|
76
|
-
const server = http.createServer((request, response) => {
|
|
77
|
-
if (request.url !== `/v${packageJson.version}/${assetName}`) {
|
|
78
|
-
response.writeHead(404);
|
|
79
|
-
response.end("not found");
|
|
80
|
-
return;
|
|
81
|
-
}
|
|
82
|
-
response.writeHead(200, { "content-type": "application/gzip" });
|
|
83
|
-
fs.createReadStream(assetPath).pipe(response);
|
|
84
|
-
});
|
|
85
|
-
|
|
86
|
-
await new Promise((resolve) => server.listen(0, "127.0.0.1", resolve));
|
|
87
|
-
const { port } = server.address();
|
|
88
|
-
|
|
89
|
-
try {
|
|
90
|
-
const result = await runNpx(tarball, projectDir, {
|
|
91
|
-
...process.env,
|
|
92
|
-
CARGO: path.join(tempRoot, "missing-cargo"),
|
|
93
|
-
DART_DECIMATE_RELEASE_BASE_URL: `http://127.0.0.1:${port}/v${packageJson.version}`,
|
|
94
|
-
npm_config_cache: path.join(tempRoot, "npm-cache"),
|
|
95
|
-
});
|
|
96
|
-
|
|
97
|
-
if (result.stdout) {
|
|
98
|
-
process.stdout.write(result.stdout);
|
|
99
|
-
}
|
|
100
|
-
if (result.stderr) {
|
|
101
|
-
process.stderr.write(result.stderr);
|
|
102
|
-
}
|
|
103
|
-
if (result.status !== 0 || result.error) {
|
|
104
|
-
throw new Error(result.error?.message || `npx exited ${result.status}`);
|
|
105
|
-
}
|
|
106
|
-
if (!result.stdout.includes("dart-decimate prebuilt --help")) {
|
|
107
|
-
throw new Error("npx did not execute the downloaded prebuilt binary");
|
|
108
|
-
}
|
|
109
|
-
if (result.stderr.includes("Rust/Cargo")) {
|
|
110
|
-
throw new Error(
|
|
111
|
-
"npx attempted the Cargo fallback even though a prebuilt binary was available",
|
|
112
|
-
);
|
|
113
|
-
}
|
|
114
|
-
} finally {
|
|
115
|
-
await new Promise((resolve) => server.close(resolve));
|
|
116
|
-
fs.rmSync(tempRoot, { recursive: true, force: true });
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
function runNpx(tarball, cwd, env) {
|
|
121
|
-
return new Promise((resolve) => {
|
|
122
|
-
const child = spawn(
|
|
123
|
-
"npx",
|
|
124
|
-
["--yes", "--package", tarball, "--", "dart-decimate", "--help"],
|
|
125
|
-
{
|
|
126
|
-
cwd,
|
|
127
|
-
env,
|
|
128
|
-
},
|
|
129
|
-
);
|
|
130
|
-
let stdout = "";
|
|
131
|
-
let stderr = "";
|
|
132
|
-
|
|
133
|
-
child.stdout.on("data", (chunk) => {
|
|
134
|
-
stdout += chunk;
|
|
135
|
-
});
|
|
136
|
-
child.stderr.on("data", (chunk) => {
|
|
137
|
-
stderr += chunk;
|
|
138
|
-
});
|
|
139
|
-
child.on("error", (error) => {
|
|
140
|
-
resolve({ error, stdout, stderr, status: null });
|
|
141
|
-
});
|
|
142
|
-
child.on("close", (status) => {
|
|
143
|
-
resolve({ stdout, stderr, status });
|
|
144
|
-
});
|
|
145
|
-
});
|
|
146
|
-
}
|
|
@@ -1,142 +0,0 @@
|
|
|
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(
|
|
11
|
-
path.join(tmpdir(), "dart-decimate-postinstall-"),
|
|
12
|
-
);
|
|
13
|
-
|
|
14
|
-
main().catch((error) => {
|
|
15
|
-
console.error(error.message);
|
|
16
|
-
process.exit(1);
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
async function main() {
|
|
20
|
-
const packageJson = JSON.parse(
|
|
21
|
-
fs.readFileSync(path.join(root, "package.json"), "utf8"),
|
|
22
|
-
);
|
|
23
|
-
const platform = process.platform === "win32" ? "windows" : process.platform;
|
|
24
|
-
const arch = process.arch === "x64" ? "x64" : process.arch;
|
|
25
|
-
const assetName = `dart-decimate-${platform}-${arch}.tar.gz`;
|
|
26
|
-
|
|
27
|
-
const scriptDir = path.join(tempRoot, "npm", "scripts");
|
|
28
|
-
const payloadDir = path.join(tempRoot, "payload");
|
|
29
|
-
const assetDir = path.join(tempRoot, "assets");
|
|
30
|
-
fs.mkdirSync(scriptDir, { recursive: true });
|
|
31
|
-
fs.mkdirSync(payloadDir, { recursive: true });
|
|
32
|
-
fs.mkdirSync(assetDir, { recursive: true });
|
|
33
|
-
|
|
34
|
-
fs.copyFileSync(
|
|
35
|
-
path.join(root, "npm", "scripts", "postinstall.js"),
|
|
36
|
-
path.join(scriptDir, "postinstall.js"),
|
|
37
|
-
);
|
|
38
|
-
fs.writeFileSync(
|
|
39
|
-
path.join(tempRoot, "package.json"),
|
|
40
|
-
JSON.stringify(
|
|
41
|
-
{ name: "dart-decimate", version: packageJson.version },
|
|
42
|
-
null,
|
|
43
|
-
2,
|
|
44
|
-
),
|
|
45
|
-
);
|
|
46
|
-
|
|
47
|
-
for (const binary of ["dart-decimate", "dart-decimate-mcp"]) {
|
|
48
|
-
const binaryPath = path.join(
|
|
49
|
-
payloadDir,
|
|
50
|
-
process.platform === "win32" ? `${binary}.exe` : binary,
|
|
51
|
-
);
|
|
52
|
-
fs.writeFileSync(binaryPath, "#!/usr/bin/env sh\nexit 0\n");
|
|
53
|
-
fs.chmodSync(binaryPath, 0o755);
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
const assetPath = path.join(assetDir, assetName);
|
|
57
|
-
const archive = spawnSync("tar", ["-czf", assetPath, "-C", payloadDir, "."], {
|
|
58
|
-
encoding: "utf8",
|
|
59
|
-
});
|
|
60
|
-
if (archive.status !== 0 || archive.error) {
|
|
61
|
-
throw new Error(
|
|
62
|
-
archive.stderr ||
|
|
63
|
-
archive.error?.message ||
|
|
64
|
-
"failed to create test archive",
|
|
65
|
-
);
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
const server = http.createServer((request, response) => {
|
|
69
|
-
if (request.url !== `/v${packageJson.version}/${assetName}`) {
|
|
70
|
-
response.writeHead(404);
|
|
71
|
-
response.end("not found");
|
|
72
|
-
return;
|
|
73
|
-
}
|
|
74
|
-
response.writeHead(200, { "content-type": "application/gzip" });
|
|
75
|
-
fs.createReadStream(assetPath).pipe(response);
|
|
76
|
-
});
|
|
77
|
-
|
|
78
|
-
await new Promise((resolve) => server.listen(0, "127.0.0.1", resolve));
|
|
79
|
-
const { port } = server.address();
|
|
80
|
-
|
|
81
|
-
try {
|
|
82
|
-
const result = await runPostinstall(
|
|
83
|
-
path.join(scriptDir, "postinstall.js"),
|
|
84
|
-
{
|
|
85
|
-
cwd: tempRoot,
|
|
86
|
-
env: {
|
|
87
|
-
...process.env,
|
|
88
|
-
CARGO: path.join(tempRoot, "missing-cargo"),
|
|
89
|
-
DART_DECIMATE_RELEASE_BASE_URL: `http://127.0.0.1:${port}/v${packageJson.version}`,
|
|
90
|
-
},
|
|
91
|
-
},
|
|
92
|
-
);
|
|
93
|
-
|
|
94
|
-
if (result.stdout) {
|
|
95
|
-
process.stdout.write(result.stdout);
|
|
96
|
-
}
|
|
97
|
-
if (result.stderr) {
|
|
98
|
-
process.stderr.write(result.stderr);
|
|
99
|
-
}
|
|
100
|
-
if (result.status !== 0 || result.error) {
|
|
101
|
-
throw new Error(
|
|
102
|
-
result.error?.message || `postinstall exited ${result.status}`,
|
|
103
|
-
);
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
for (const binary of ["dart-decimate", "dart-decimate-mcp"]) {
|
|
107
|
-
const installed = path.join(
|
|
108
|
-
tempRoot,
|
|
109
|
-
"npm",
|
|
110
|
-
"bin-cache",
|
|
111
|
-
process.platform === "win32" ? `${binary}.exe` : binary,
|
|
112
|
-
);
|
|
113
|
-
if (!fs.existsSync(installed)) {
|
|
114
|
-
throw new Error(`missing installed prebuilt binary ${binary}`);
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
} finally {
|
|
118
|
-
await new Promise((resolve) => server.close(resolve));
|
|
119
|
-
fs.rmSync(tempRoot, { recursive: true, force: true });
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
function runPostinstall(script, options) {
|
|
124
|
-
return new Promise((resolve) => {
|
|
125
|
-
const child = spawn("node", [script], options);
|
|
126
|
-
let stdout = "";
|
|
127
|
-
let stderr = "";
|
|
128
|
-
|
|
129
|
-
child.stdout.on("data", (chunk) => {
|
|
130
|
-
stdout += chunk;
|
|
131
|
-
});
|
|
132
|
-
child.stderr.on("data", (chunk) => {
|
|
133
|
-
stderr += chunk;
|
|
134
|
-
});
|
|
135
|
-
child.on("error", (error) => {
|
|
136
|
-
resolve({ error, stdout, stderr, status: null });
|
|
137
|
-
});
|
|
138
|
-
child.on("close", (status) => {
|
|
139
|
-
resolve({ stdout, stderr, status });
|
|
140
|
-
});
|
|
141
|
-
});
|
|
142
|
-
}
|
|
@@ -1,237 +0,0 @@
|
|
|
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 fixture = path.join(root, "tests", "fixtures", "install-parity");
|
|
11
|
-
const packageJson = JSON.parse(
|
|
12
|
-
fs.readFileSync(path.join(root, "package.json"), "utf8"),
|
|
13
|
-
);
|
|
14
|
-
const tempRoot = fs.mkdtempSync(
|
|
15
|
-
path.join(tmpdir(), "dart-decimate-release-parity-"),
|
|
16
|
-
);
|
|
17
|
-
|
|
18
|
-
main().catch((error) => {
|
|
19
|
-
console.error(error.message);
|
|
20
|
-
process.exitCode = 1;
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
async function main() {
|
|
24
|
-
try {
|
|
25
|
-
const assetDir = path.resolve(
|
|
26
|
-
process.env.DART_DECIMATE_RELEASE_ASSET_DIR ||
|
|
27
|
-
path.join(root, "dist-assets"),
|
|
28
|
-
);
|
|
29
|
-
const assetName = releaseAssetName();
|
|
30
|
-
const assetPath = path.join(assetDir, assetName);
|
|
31
|
-
if (!isFile(assetPath)) {
|
|
32
|
-
throw new Error(`missing release asset ${assetPath}`);
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
const cargoBinary = installWithCargo();
|
|
36
|
-
const tarball = packNpmPackage();
|
|
37
|
-
const projectDir = path.join(tempRoot, "npm-project");
|
|
38
|
-
fs.mkdirSync(projectDir, { recursive: true });
|
|
39
|
-
fs.writeFileSync(
|
|
40
|
-
path.join(projectDir, "package.json"),
|
|
41
|
-
JSON.stringify({ name: "release-parity-probe", private: true }, null, 2),
|
|
42
|
-
);
|
|
43
|
-
|
|
44
|
-
const server = http.createServer((request, response) => {
|
|
45
|
-
if (request.url !== `/v${packageJson.version}/${assetName}`) {
|
|
46
|
-
response.writeHead(404);
|
|
47
|
-
response.end("not found");
|
|
48
|
-
return;
|
|
49
|
-
}
|
|
50
|
-
response.writeHead(200, { "content-type": "application/gzip" });
|
|
51
|
-
fs.createReadStream(assetPath).pipe(response);
|
|
52
|
-
});
|
|
53
|
-
await new Promise((resolve) => server.listen(0, "127.0.0.1", resolve));
|
|
54
|
-
|
|
55
|
-
try {
|
|
56
|
-
const { port } = server.address();
|
|
57
|
-
await installNpmTarball(tarball, projectDir, port);
|
|
58
|
-
} finally {
|
|
59
|
-
await new Promise((resolve) => server.close(resolve));
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
const npmBinary = path.join(
|
|
63
|
-
projectDir,
|
|
64
|
-
"node_modules",
|
|
65
|
-
".bin",
|
|
66
|
-
process.platform === "win32" ? "dart-decimate.cmd" : "dart-decimate",
|
|
67
|
-
);
|
|
68
|
-
assertInstalledPackageVersion(projectDir);
|
|
69
|
-
assertVersion(cargoBinary, "Cargo");
|
|
70
|
-
assertVersion(npmBinary, "npm");
|
|
71
|
-
|
|
72
|
-
const cargoReport = runReport(cargoBinary, "Cargo");
|
|
73
|
-
const npmReport = runReport(npmBinary, "npm");
|
|
74
|
-
if (cargoReport !== npmReport) {
|
|
75
|
-
throw new Error(
|
|
76
|
-
"Cargo and npm installations emitted different JSON reports",
|
|
77
|
-
);
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
const report = JSON.parse(cargoReport);
|
|
81
|
-
if (
|
|
82
|
-
report.schema_version !== "dart-decimate.report.v1" ||
|
|
83
|
-
report.tool !== `dart-decimate ${packageJson.version}` ||
|
|
84
|
-
report.verdict !== "pass" ||
|
|
85
|
-
report.summary?.code_duplications !== 0 ||
|
|
86
|
-
report.summary?.unrendered_widgets !== 0 ||
|
|
87
|
-
report.summary?.findings !== 0 ||
|
|
88
|
-
report.findings?.length !== 0
|
|
89
|
-
) {
|
|
90
|
-
throw new Error(`unexpected parity report: ${cargoReport}`);
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
console.log(
|
|
94
|
-
`release install parity ok: Cargo source and npm ${packageJson.version} emitted identical reports`,
|
|
95
|
-
);
|
|
96
|
-
} finally {
|
|
97
|
-
fs.rmSync(tempRoot, { recursive: true, force: true });
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
function isFile(filePath) {
|
|
102
|
-
try {
|
|
103
|
-
return fs.statSync(filePath).isFile();
|
|
104
|
-
} catch {
|
|
105
|
-
return false;
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
function installWithCargo() {
|
|
110
|
-
const cargoRoot = path.join(tempRoot, "cargo-root");
|
|
111
|
-
const gitUrl = process.env.DART_DECIMATE_CARGO_GIT_URL;
|
|
112
|
-
const tag = process.env.DART_DECIMATE_CARGO_TAG;
|
|
113
|
-
const revision = process.env.DART_DECIMATE_CARGO_REV;
|
|
114
|
-
const args = ["install", "--locked", "--force", "--root", cargoRoot];
|
|
115
|
-
if (gitUrl || tag || revision) {
|
|
116
|
-
if (!gitUrl || Boolean(tag) === Boolean(revision)) {
|
|
117
|
-
throw new Error(
|
|
118
|
-
"DART_DECIMATE_CARGO_GIT_URL and exactly one of DART_DECIMATE_CARGO_TAG or DART_DECIMATE_CARGO_REV must be set together",
|
|
119
|
-
);
|
|
120
|
-
}
|
|
121
|
-
args.push("--git", gitUrl, tag ? "--tag" : "--rev", tag || revision);
|
|
122
|
-
args.push("dart-decimate");
|
|
123
|
-
} else {
|
|
124
|
-
args.push("--path", root);
|
|
125
|
-
}
|
|
126
|
-
run("cargo", args, root, "Cargo install");
|
|
127
|
-
return path.join(
|
|
128
|
-
cargoRoot,
|
|
129
|
-
"bin",
|
|
130
|
-
process.platform === "win32" ? "dart-decimate.exe" : "dart-decimate",
|
|
131
|
-
);
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
function packNpmPackage() {
|
|
135
|
-
const result = run(
|
|
136
|
-
"npm",
|
|
137
|
-
["pack", "--json", "--pack-destination", tempRoot],
|
|
138
|
-
root,
|
|
139
|
-
"npm pack",
|
|
140
|
-
);
|
|
141
|
-
const [metadata] = JSON.parse(result.stdout);
|
|
142
|
-
return path.join(tempRoot, metadata.filename);
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
async function installNpmTarball(tarball, projectDir, port) {
|
|
146
|
-
const result = await spawnResult(
|
|
147
|
-
"npm",
|
|
148
|
-
["install", "--no-audit", "--no-fund", tarball],
|
|
149
|
-
{
|
|
150
|
-
cwd: projectDir,
|
|
151
|
-
env: {
|
|
152
|
-
...process.env,
|
|
153
|
-
CARGO: path.join(tempRoot, "missing-cargo"),
|
|
154
|
-
DART_DECIMATE_RELEASE_BASE_URL: `http://127.0.0.1:${port}/v${packageJson.version}`,
|
|
155
|
-
npm_config_cache: path.join(tempRoot, "npm-cache"),
|
|
156
|
-
},
|
|
157
|
-
},
|
|
158
|
-
);
|
|
159
|
-
if (result.status !== 0 || result.error) {
|
|
160
|
-
throw new Error(
|
|
161
|
-
result.error?.message ||
|
|
162
|
-
result.stderr ||
|
|
163
|
-
`npm install exited ${result.status}`,
|
|
164
|
-
);
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
function assertInstalledPackageVersion(projectDir) {
|
|
169
|
-
const installed = JSON.parse(
|
|
170
|
-
fs.readFileSync(
|
|
171
|
-
path.join(projectDir, "node_modules", "dart-decimate", "package.json"),
|
|
172
|
-
"utf8",
|
|
173
|
-
),
|
|
174
|
-
);
|
|
175
|
-
if (installed.version !== packageJson.version) {
|
|
176
|
-
throw new Error(
|
|
177
|
-
`npm installed dart-decimate ${installed.version}; expected ${packageJson.version}`,
|
|
178
|
-
);
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
function assertVersion(binary, label) {
|
|
183
|
-
const result = run(binary, ["--version"], fixture, `${label} --version`);
|
|
184
|
-
const expected = `dart-decimate ${packageJson.version}`;
|
|
185
|
-
if (result.stdout.trim() !== expected) {
|
|
186
|
-
throw new Error(
|
|
187
|
-
`${label} reported ${result.stdout.trim()}; expected ${expected}`,
|
|
188
|
-
);
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
function runReport(binary, label) {
|
|
193
|
-
return run(
|
|
194
|
-
binary,
|
|
195
|
-
["check", "lib", "--threshold", "0", "--format", "json"],
|
|
196
|
-
fixture,
|
|
197
|
-
`${label} report`,
|
|
198
|
-
).stdout;
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
function releaseAssetName() {
|
|
202
|
-
const platform = process.platform === "win32" ? "windows" : process.platform;
|
|
203
|
-
const arch = process.arch === "x64" ? "x64" : process.arch;
|
|
204
|
-
return `dart-decimate-${platform}-${arch}.tar.gz`;
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
function run(command, args, cwd, label) {
|
|
208
|
-
const result = spawnSync(command, args, { cwd, encoding: "utf8" });
|
|
209
|
-
if (result.status !== 0 || result.error) {
|
|
210
|
-
throw new Error(
|
|
211
|
-
result.error?.message ||
|
|
212
|
-
result.stderr ||
|
|
213
|
-
`${label} exited ${result.status}`,
|
|
214
|
-
);
|
|
215
|
-
}
|
|
216
|
-
return result;
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
function spawnResult(command, args, options) {
|
|
220
|
-
return new Promise((resolve) => {
|
|
221
|
-
const child = spawn(command, args, options);
|
|
222
|
-
let stdout = "";
|
|
223
|
-
let stderr = "";
|
|
224
|
-
child.stdout.on("data", (chunk) => {
|
|
225
|
-
stdout += chunk;
|
|
226
|
-
});
|
|
227
|
-
child.stderr.on("data", (chunk) => {
|
|
228
|
-
stderr += chunk;
|
|
229
|
-
});
|
|
230
|
-
child.on("error", (error) => {
|
|
231
|
-
resolve({ error, status: null, stderr, stdout });
|
|
232
|
-
});
|
|
233
|
-
child.on("close", (status) => {
|
|
234
|
-
resolve({ status, stderr, stdout });
|
|
235
|
-
});
|
|
236
|
-
});
|
|
237
|
-
}
|