Skip to content

Don't rewrite it in Rust. Rewrite the 5% that's slow: profile your app, port the hot functions with your coding agent, prove they behave the same. Python, JS/TS, Ruby, Java, Kotlin, Go, PHP, C/C++, C#, R.

npm: chmod the platform binary before spawn (#37)

podsni2336fd039d40
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index dcdc262..b609902 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -50,6 +50,7 @@ jobs:
- run: cargo fmt --check
- run: cargo clippy --all-targets -- -D warnings
- run: cargo test
+ - run: node --test npm/fast-anything/bin/fast-anything.test.js
- run: cargo build --release
- name: end to end on the demo (reference port instead of an agent)
working-directory: examples/fuzzy-dedupe
diff --git a/npm/fast-anything/bin/fast-anything.js b/npm/fast-anything/bin/fast-anything.js
index 06f1e83..04efbf8 100644
--- a/npm/fast-anything/bin/fast-anything.js
+++ b/npm/fast-anything/bin/fast-anything.js
@@ -2,6 +2,7 @@
// Runs the prebuilt fast-anything binary for this platform (installed as an optional dependency).
"use strict";
const { spawnSync } = require("node:child_process");
+const fs = require("node:fs");
const pkg = `@el4cteo/fast-anything-${process.platform}-${process.arch}`;
const exe = process.platform === "win32" ? "fast-anything.exe" : "fast-anything";
@@ -15,6 +16,14 @@ try {
);
process.exit(1);
}
+// Published tarballs have shipped this file as 0644. Set the bit before spawn.
+if (process.platform !== "win32") {
+ try {
+ fs.chmodSync(bin, 0o755);
+ } catch {
+ // spawnSync reports EACCES if the file still isn't executable
+ }
+}
const run = spawnSync(bin, process.argv.slice(2), { stdio: "inherit" });
if (run.error) {
console.error(`fast-anything: ${run.error.message}`);
diff --git a/npm/fast-anything/bin/fast-anything.test.js b/npm/fast-anything/bin/fast-anything.test.js
new file mode 100644
index 0000000..a91043f
--- /dev/null
+++ b/npm/fast-anything/bin/fast-anything.test.js
@@ -0,0 +1,41 @@
+"use strict";
+const { test } = require("node:test");
+const assert = require("node:assert/strict");
+const { spawnSync } = require("node:child_process");
+const fs = require("node:fs");
+const os = require("node:os");
+const path = require("node:path");
+
+const launcherSrc = path.join(__dirname, "fast-anything.js");
+
+test("launcher runs a platform binary that npm left without the execute bit", {
+ skip: process.platform === "win32" ? "Windows has no execute bit" : false,
+}, () => {
+ const tmp = fs.mkdtempSync(path.join(os.tmpdir(), "fa-eacces-"));
+ try {
+ const plat = `${process.platform}-${process.arch}`;
+ const pkgDir = path.join(tmp, "node_modules", `@el4cteo/fast-anything-${plat}`);
+ const binDir = path.join(pkgDir, "bin");
+ fs.mkdirSync(binDir, { recursive: true });
+ fs.writeFileSync(
+ path.join(pkgDir, "package.json"),
+ JSON.stringify({ name: `@el4cteo/fast-anything-${plat}`, version: "0.0.0" }),
+ );
+
+ const marker = path.join(tmp, "ran");
+ const fakeBin = path.join(binDir, "fast-anything");
+ fs.writeFileSync(fakeBin, `#!/bin/sh\necho ok > '${marker}'\n`);
+ fs.chmodSync(fakeBin, 0o644);
+
+ const launchDir = path.join(tmp, "bin");
+ fs.mkdirSync(launchDir, { recursive: true });
+ const launcher = path.join(launchDir, "fast-anything.js");
+ fs.copyFileSync(launcherSrc, launcher);
+
+ const run = spawnSync(process.execPath, [launcher, "--version"], { encoding: "utf8" });
+ assert.equal(run.status, 0, run.stderr || run.error?.message || "launcher failed");
+ assert.equal(fs.readFileSync(marker, "utf8").trim(), "ok");
+ } finally {
+ fs.rmSync(tmp, { recursive: true, force: true });
+ }
+});