fallow-similar-code 3.42.0 → 3.43.1
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/package.json +9 -9
- package/scripts/run-binary.js +28 -6
- package/scripts/run-binary.test.js +22 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "fallow-similar-code",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.43.1",
|
|
4
4
|
"description": "First-party local embedding sidecar for Fallow similar-code analysis",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -26,13 +26,13 @@
|
|
|
26
26
|
"detect-libc": "2.1.2"
|
|
27
27
|
},
|
|
28
28
|
"optionalDependencies": {
|
|
29
|
-
"@fallow-cli/fallow-similar-code-darwin-arm64": "3.
|
|
30
|
-
"@fallow-cli/fallow-similar-code-darwin-x64": "3.
|
|
31
|
-
"@fallow-cli/fallow-similar-code-linux-x64-gnu": "3.
|
|
32
|
-
"@fallow-cli/fallow-similar-code-linux-arm64-gnu": "3.
|
|
33
|
-
"@fallow-cli/fallow-similar-code-linux-x64-musl": "3.
|
|
34
|
-
"@fallow-cli/fallow-similar-code-linux-arm64-musl": "3.
|
|
35
|
-
"@fallow-cli/fallow-similar-code-win32-x64-msvc": "3.
|
|
36
|
-
"@fallow-cli/fallow-similar-code-win32-arm64-msvc": "3.
|
|
29
|
+
"@fallow-cli/fallow-similar-code-darwin-arm64": "3.43.1",
|
|
30
|
+
"@fallow-cli/fallow-similar-code-darwin-x64": "3.43.1",
|
|
31
|
+
"@fallow-cli/fallow-similar-code-linux-x64-gnu": "3.43.1",
|
|
32
|
+
"@fallow-cli/fallow-similar-code-linux-arm64-gnu": "3.43.1",
|
|
33
|
+
"@fallow-cli/fallow-similar-code-linux-x64-musl": "3.43.1",
|
|
34
|
+
"@fallow-cli/fallow-similar-code-linux-arm64-musl": "3.43.1",
|
|
35
|
+
"@fallow-cli/fallow-similar-code-win32-x64-msvc": "3.43.1",
|
|
36
|
+
"@fallow-cli/fallow-similar-code-win32-arm64-msvc": "3.43.1"
|
|
37
37
|
}
|
|
38
38
|
}
|
package/scripts/run-binary.js
CHANGED
|
@@ -20,18 +20,40 @@ const SIGNAL_EXIT_CODES = new Map([
|
|
|
20
20
|
["SIGTERM", 143],
|
|
21
21
|
]);
|
|
22
22
|
|
|
23
|
-
const
|
|
24
|
-
|
|
25
|
-
return
|
|
23
|
+
const detectLibc = () => {
|
|
24
|
+
try {
|
|
25
|
+
return require("detect-libc").familySync();
|
|
26
|
+
} catch {
|
|
27
|
+
return null;
|
|
26
28
|
}
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
const isInstalled = (packageName, resolve) => {
|
|
27
32
|
try {
|
|
28
|
-
|
|
29
|
-
return
|
|
33
|
+
resolve(`${packageName}/package.json`);
|
|
34
|
+
return true;
|
|
30
35
|
} catch {
|
|
31
|
-
return
|
|
36
|
+
return false;
|
|
32
37
|
}
|
|
33
38
|
};
|
|
34
39
|
|
|
40
|
+
// npm installs a Linux platform package only for the libc that it detects at
|
|
41
|
+
// install time. The musl binaries are statically linked and also run on glibc,
|
|
42
|
+
// so a glibc host accepts an installed musl package. A glibc binary does not
|
|
43
|
+
// run on musl, so there is no fallback in that direction. An unknown libc
|
|
44
|
+
// selects musl.
|
|
45
|
+
const resolvePlatformPackage = ({
|
|
46
|
+
platform = process.platform,
|
|
47
|
+
arch = process.arch,
|
|
48
|
+
libc = platform === "linux" ? detectLibc() : undefined,
|
|
49
|
+
resolve = require.resolve,
|
|
50
|
+
} = {}) => {
|
|
51
|
+
const primary = getPlatformPackage(platform, arch, libc);
|
|
52
|
+
if (!primary?.endsWith("-gnu") || isInstalled(primary, resolve)) return primary;
|
|
53
|
+
const musl = primary.replace(/-gnu$/, "-musl");
|
|
54
|
+
return isInstalled(musl, resolve) ? musl : primary;
|
|
55
|
+
};
|
|
56
|
+
|
|
35
57
|
const resolveBinaryArtifact = (
|
|
36
58
|
packageName,
|
|
37
59
|
resolve = require.resolve,
|
|
@@ -230,3 +230,25 @@ test(
|
|
|
230
230
|
assert.equal(status, 143, stderr);
|
|
231
231
|
},
|
|
232
232
|
);
|
|
233
|
+
|
|
234
|
+
test("a glibc host uses the static musl package when the gnu package is missing", () => {
|
|
235
|
+
const installedOnly = (name) => (request) => {
|
|
236
|
+
if (request !== `${name}/package.json`) throw new Error(`Cannot find module '${request}'`);
|
|
237
|
+
return `/nm/${request}`;
|
|
238
|
+
};
|
|
239
|
+
const gnu = "@fallow-cli/fallow-similar-code-linux-x64-gnu";
|
|
240
|
+
const musl = "@fallow-cli/fallow-similar-code-linux-x64-musl";
|
|
241
|
+
const host = { platform: "linux", arch: "x64", libc: "glibc" };
|
|
242
|
+
assert.equal(resolvePlatformPackage({ ...host, resolve: installedOnly(gnu) }), gnu);
|
|
243
|
+
assert.equal(resolvePlatformPackage({ ...host, resolve: installedOnly(musl) }), musl);
|
|
244
|
+
assert.equal(
|
|
245
|
+
resolvePlatformPackage({ ...host, libc: "musl", resolve: installedOnly(gnu) }),
|
|
246
|
+
musl,
|
|
247
|
+
"a musl host never falls back to a glibc binary",
|
|
248
|
+
);
|
|
249
|
+
assert.equal(
|
|
250
|
+
resolvePlatformPackage({ ...host, resolve: installedOnly("none") }),
|
|
251
|
+
gnu,
|
|
252
|
+
"the error names the package that matches the host",
|
|
253
|
+
);
|
|
254
|
+
});
|