@jaccard-ai/cli 0.6.0-linux-arm64 → 0.6.0
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/bin/jaccard.js +73 -0
- package/lib/platform.js +38 -0
- package/package.json +17 -10
- package/bin/jaccard +0 -0
package/bin/jaccard.js
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// @ts-check
|
|
3
|
+
// Runs the native jaccard binary from the platform build that npm installed
|
|
4
|
+
// through optionalDependencies. CommonJS with no dependencies: it must start
|
|
5
|
+
// on every Node the `engines` field admits.
|
|
6
|
+
'use strict';
|
|
7
|
+
|
|
8
|
+
const { spawn } = require('node:child_process');
|
|
9
|
+
const os = require('node:os');
|
|
10
|
+
const path = require('node:path');
|
|
11
|
+
|
|
12
|
+
const { binaryPackage } = require('../lib/platform.js');
|
|
13
|
+
// Only the staged manifest lists the platform builds; the workspace one has none.
|
|
14
|
+
/** @type {{ version: string, optionalDependencies?: Record<string, string> }} */
|
|
15
|
+
const manifest = require('../package.json');
|
|
16
|
+
const optionalDependencies = manifest.optionalDependencies || {};
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* @param {string} message
|
|
20
|
+
* @returns {never}
|
|
21
|
+
*/
|
|
22
|
+
function fail(message) {
|
|
23
|
+
process.stderr.write(`jaccard: ${message}\n`);
|
|
24
|
+
process.exit(1);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/** @returns {string} */
|
|
28
|
+
function resolveBinary() {
|
|
29
|
+
let alias;
|
|
30
|
+
try {
|
|
31
|
+
alias = binaryPackage(process.platform, process.arch, optionalDependencies);
|
|
32
|
+
} catch (err) {
|
|
33
|
+
return fail(err instanceof Error ? err.message : String(err));
|
|
34
|
+
}
|
|
35
|
+
try {
|
|
36
|
+
return path.join(path.dirname(require.resolve(`${alias}/package.json`)), 'bin', 'jaccard');
|
|
37
|
+
} catch {
|
|
38
|
+
return fail(
|
|
39
|
+
`${alias} is not installed. npm leaves it out under --omit=optional, and so can a ` +
|
|
40
|
+
'lockfile written on another OS or CPU. Reinstall with optional dependencies: ' +
|
|
41
|
+
'npm install -g @jaccard-ai/cli',
|
|
42
|
+
);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const binary = resolveBinary();
|
|
47
|
+
|
|
48
|
+
// Without forwarding, `kill` on this process (as timeout(1) and process
|
|
49
|
+
// supervisors do) would exit Node and leave the binary running. The handlers
|
|
50
|
+
// must be in place before spawn: until then a signal still kills Node outright.
|
|
51
|
+
/** @type {NodeJS.Signals[]} */
|
|
52
|
+
const SIGNALS = ['SIGINT', 'SIGTERM', 'SIGHUP'];
|
|
53
|
+
/** @type {import('node:child_process').ChildProcess | undefined} */
|
|
54
|
+
let child;
|
|
55
|
+
/** @param {NodeJS.Signals} signal */
|
|
56
|
+
const forward = (signal) => {
|
|
57
|
+
if (child && child.exitCode === null && child.signalCode === null) child.kill(signal);
|
|
58
|
+
};
|
|
59
|
+
for (const signal of SIGNALS) process.on(signal, forward);
|
|
60
|
+
|
|
61
|
+
child = spawn(binary, process.argv.slice(2), { stdio: 'inherit' });
|
|
62
|
+
child.on('error', (err) => fail(`could not run ${binary}: ${err.message}`));
|
|
63
|
+
|
|
64
|
+
child.on('exit', (code, signal) => {
|
|
65
|
+
if (signal === null) {
|
|
66
|
+
process.exit(code === null ? 1 : code);
|
|
67
|
+
}
|
|
68
|
+
// Dying by the same signal, not exiting 128+n, is what stops a shell loop on Ctrl-C.
|
|
69
|
+
for (const s of SIGNALS) process.removeListener(s, forward);
|
|
70
|
+
process.kill(process.pid, signal);
|
|
71
|
+
// Reached only for a signal Node ignores, such as SIGPIPE.
|
|
72
|
+
process.exitCode = 128 + (os.constants.signals[signal] || 0);
|
|
73
|
+
});
|
package/lib/platform.js
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
// Each platform build is an optionalDependencies alias named PREFIX + `<os>-<cpu>`,
|
|
5
|
+
// with `os`/`cpu` from Node's process.platform and process.arch.
|
|
6
|
+
const PREFIX = '@jaccard-ai/cli-';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Names the alias that carries the binary for this machine.
|
|
10
|
+
*
|
|
11
|
+
* @param {string} platform process.platform
|
|
12
|
+
* @param {string} arch process.arch
|
|
13
|
+
* @param {Record<string, string>} optionalDependencies this package's manifest field
|
|
14
|
+
* @returns {string}
|
|
15
|
+
* @throws {Error} when no published build fits this machine
|
|
16
|
+
*/
|
|
17
|
+
function binaryPackage(platform, arch, optionalDependencies) {
|
|
18
|
+
if (platform === 'win32') {
|
|
19
|
+
throw new Error(
|
|
20
|
+
'Windows is not supported yet. Run jaccard inside WSL: ' +
|
|
21
|
+
'https://learn.microsoft.com/windows/wsl/install',
|
|
22
|
+
);
|
|
23
|
+
}
|
|
24
|
+
const alias = `${PREFIX}${platform}-${arch}`;
|
|
25
|
+
if (!Object.prototype.hasOwnProperty.call(optionalDependencies, alias)) {
|
|
26
|
+
const supported = Object.keys(optionalDependencies)
|
|
27
|
+
.filter((name) => name.startsWith(PREFIX))
|
|
28
|
+
.map((name) => name.slice(PREFIX.length))
|
|
29
|
+
.sort();
|
|
30
|
+
throw new Error(
|
|
31
|
+
`there is no jaccard build for ${platform}-${arch}. ` +
|
|
32
|
+
`Supported: ${supported.join(', ') || 'none'}.`,
|
|
33
|
+
);
|
|
34
|
+
}
|
|
35
|
+
return alias;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
module.exports = { binaryPackage };
|
package/package.json
CHANGED
|
@@ -1,19 +1,26 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jaccard-ai/cli",
|
|
3
|
-
"version": "0.6.0
|
|
4
|
-
"description": "The
|
|
3
|
+
"version": "0.6.0",
|
|
4
|
+
"description": "The Jaccard platform CLI.",
|
|
5
5
|
"license": "SEE LICENSE IN README.md",
|
|
6
|
-
"
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
"arm64"
|
|
11
|
-
],
|
|
6
|
+
"homepage": "https://www.jaccard.ai",
|
|
7
|
+
"bin": {
|
|
8
|
+
"jaccard": "bin/jaccard.js"
|
|
9
|
+
},
|
|
12
10
|
"files": [
|
|
13
|
-
"bin
|
|
11
|
+
"bin",
|
|
12
|
+
"lib"
|
|
14
13
|
],
|
|
15
|
-
"
|
|
14
|
+
"engines": {
|
|
15
|
+
"node": ">=18"
|
|
16
|
+
},
|
|
16
17
|
"publishConfig": {
|
|
17
18
|
"access": "public"
|
|
19
|
+
},
|
|
20
|
+
"optionalDependencies": {
|
|
21
|
+
"@jaccard-ai/cli-darwin-arm64": "npm:@jaccard-ai/cli@0.6.0-darwin-arm64",
|
|
22
|
+
"@jaccard-ai/cli-darwin-x64": "npm:@jaccard-ai/cli@0.6.0-darwin-x64",
|
|
23
|
+
"@jaccard-ai/cli-linux-arm64": "npm:@jaccard-ai/cli@0.6.0-linux-arm64",
|
|
24
|
+
"@jaccard-ai/cli-linux-x64": "npm:@jaccard-ai/cli@0.6.0-linux-x64"
|
|
18
25
|
}
|
|
19
26
|
}
|
package/bin/jaccard
DELETED
|
Binary file
|