dart-decimate 0.0.2 → 0.0.4

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 CHANGED
@@ -92,7 +92,7 @@ checksum = "d0a5c400df2834b80a4c3327b3aad3a4c4cd4de0629063962b03235697506a28"
92
92
 
93
93
  [[package]]
94
94
  name = "dart-decimate"
95
- version = "0.0.2"
95
+ version = "0.0.4"
96
96
  dependencies = [
97
97
  "clap",
98
98
  "glob",
package/Cargo.toml CHANGED
@@ -1,6 +1,6 @@
1
1
  [package]
2
2
  name = "dart-decimate"
3
- version = "0.0.2"
3
+ version = "0.0.4"
4
4
  edition = "2024"
5
5
  rust-version = "1.85"
6
6
  description = "Rust-native codebase intelligence for Dart and Flutter module graphs."
package/README.md CHANGED
@@ -76,7 +76,7 @@ Add this to `package.json` if you want a short project command:
76
76
  "dart-decimate": "dart-decimate check . --format json --summary"
77
77
  },
78
78
  "devDependencies": {
79
- "dart-decimate": "^0.0.2"
79
+ "dart-decimate": "^0.0.4"
80
80
  }
81
81
  }
82
82
  ```
@@ -656,7 +656,7 @@ This repository forbids `unsafe_code`.
656
656
 
657
657
  ## Release Flow
658
658
 
659
- Current version: `0.0.2`.
659
+ Current version: `0.0.4`.
660
660
 
661
661
  After the first public release, changes should go through pull requests.
662
662
 
@@ -1,48 +1,5 @@
1
1
  #!/usr/bin/env node
2
2
 
3
- const { spawnSync } = require("node:child_process");
4
- const fs = require("node:fs");
5
- const path = require("node:path");
3
+ const { runBinary } = require("./runner");
6
4
 
7
- const root = path.resolve(__dirname, "../..");
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));
@@ -1,48 +1,5 @@
1
1
  #!/usr/bin/env node
2
2
 
3
- const { spawnSync } = require("node:child_process");
4
- const fs = require("node:fs");
5
- const path = require("node:path");
3
+ const { runBinary } = require("./runner");
6
4
 
7
- const root = path.resolve(__dirname, "../..");
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 };
@@ -0,0 +1,126 @@
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(path.join(tmpdir(), "dart-decimate-npx-prebuilt-"));
16
+
17
+ main().catch((error) => {
18
+ console.error(error.message);
19
+ process.exit(1);
20
+ });
21
+
22
+ async function main() {
23
+ const packageJson = JSON.parse(fs.readFileSync(path.join(root, "package.json"), "utf8"));
24
+ const platform = process.platform === "win32" ? "windows" : process.platform;
25
+ const arch = process.arch === "x64" ? "x64" : process.arch;
26
+ const assetName = `dart-decimate-${platform}-${arch}.tar.gz`;
27
+
28
+ const projectDir = path.join(tempRoot, "project");
29
+ const payloadDir = path.join(tempRoot, "payload");
30
+ const assetDir = path.join(tempRoot, "assets");
31
+ fs.mkdirSync(projectDir, { recursive: true });
32
+ fs.mkdirSync(payloadDir, { recursive: true });
33
+ fs.mkdirSync(assetDir, { recursive: true });
34
+
35
+ for (const binary of ["dart-decimate", "dart-decimate-mcp"]) {
36
+ const binaryPath = path.join(payloadDir, binary);
37
+ fs.writeFileSync(
38
+ binaryPath,
39
+ `#!/usr/bin/env sh\nprintf '${binary} prebuilt'\nfor arg in "$@"; do printf ' %s' "$arg"; done\nprintf '\\n'\n`,
40
+ );
41
+ fs.chmodSync(binaryPath, 0o755);
42
+ }
43
+
44
+ const assetPath = path.join(assetDir, assetName);
45
+ const archive = spawnSync("tar", ["-czf", assetPath, "-C", payloadDir, "."], {
46
+ encoding: "utf8",
47
+ });
48
+ if (archive.status !== 0 || archive.error) {
49
+ throw new Error(archive.stderr || archive.error?.message || "failed to create test archive");
50
+ }
51
+
52
+ const pack = spawnSync("npm", ["pack", "--json", "--pack-destination", tempRoot], {
53
+ cwd: root,
54
+ encoding: "utf8",
55
+ });
56
+ if (pack.status !== 0 || pack.error) {
57
+ throw new Error(pack.stderr || pack.error?.message || "failed to pack npm package");
58
+ }
59
+ const [metadata] = JSON.parse(pack.stdout);
60
+ const tarball = path.join(tempRoot, metadata.filename);
61
+
62
+ const server = http.createServer((request, response) => {
63
+ if (request.url !== `/v${packageJson.version}/${assetName}`) {
64
+ response.writeHead(404);
65
+ response.end("not found");
66
+ return;
67
+ }
68
+ response.writeHead(200, { "content-type": "application/gzip" });
69
+ fs.createReadStream(assetPath).pipe(response);
70
+ });
71
+
72
+ await new Promise((resolve) => server.listen(0, "127.0.0.1", resolve));
73
+ const { port } = server.address();
74
+
75
+ try {
76
+ const result = await runNpx(tarball, projectDir, {
77
+ ...process.env,
78
+ CARGO: path.join(tempRoot, "missing-cargo"),
79
+ DART_DECIMATE_RELEASE_BASE_URL: `http://127.0.0.1:${port}/v${packageJson.version}`,
80
+ npm_config_cache: path.join(tempRoot, "npm-cache"),
81
+ });
82
+
83
+ if (result.stdout) {
84
+ process.stdout.write(result.stdout);
85
+ }
86
+ if (result.stderr) {
87
+ process.stderr.write(result.stderr);
88
+ }
89
+ if (result.status !== 0 || result.error) {
90
+ throw new Error(result.error?.message || `npx exited ${result.status}`);
91
+ }
92
+ if (!result.stdout.includes("dart-decimate prebuilt --help")) {
93
+ throw new Error("npx did not execute the downloaded prebuilt binary");
94
+ }
95
+ if (result.stderr.includes("Rust/Cargo")) {
96
+ throw new Error("npx attempted the Cargo fallback even though a prebuilt binary was available");
97
+ }
98
+ } finally {
99
+ await new Promise((resolve) => server.close(resolve));
100
+ fs.rmSync(tempRoot, { recursive: true, force: true });
101
+ }
102
+ }
103
+
104
+ function runNpx(tarball, cwd, env) {
105
+ return new Promise((resolve) => {
106
+ const child = spawn("npx", ["--yes", "--package", tarball, "--", "dart-decimate", "--help"], {
107
+ cwd,
108
+ env,
109
+ });
110
+ let stdout = "";
111
+ let stderr = "";
112
+
113
+ child.stdout.on("data", (chunk) => {
114
+ stdout += chunk;
115
+ });
116
+ child.stderr.on("data", (chunk) => {
117
+ stderr += chunk;
118
+ });
119
+ child.on("error", (error) => {
120
+ resolve({ error, stdout, stderr, status: null });
121
+ });
122
+ child.on("close", (status) => {
123
+ resolve({ stdout, stderr, status });
124
+ });
125
+ });
126
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dart-decimate",
3
- "version": "0.0.2",
3
+ "version": "0.0.4",
4
4
  "description": "Rust-native codebase intelligence for Dart and Flutter module graphs.",
5
5
  "license": "MIT",
6
6
  "bin": {
@@ -34,6 +34,7 @@
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
36
  "test:postinstall:prebuilt": "node npm/scripts/test-postinstall-prebuilt.js",
37
+ "test:npx:prebuilt": "node npm/scripts/test-npx-prebuilt.js",
37
38
  "test:npx:local": "node npm/scripts/test-npx-local.js",
38
39
  "test:npx:mcp:local": "node npm/scripts/test-npx-mcp-local.js"
39
40
  },