@seqra/opentaint 0.0.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.
Files changed (2) hide show
  1. package/bin/opentaint.js +94 -0
  2. package/package.json +28 -0
@@ -0,0 +1,94 @@
1
+ #!/usr/bin/env node
2
+ 'use strict';
3
+
4
+ const path = require('node:path');
5
+ const os = require('node:os');
6
+ const { spawnSync } = require('node:child_process');
7
+
8
+ const SCOPE = '@seqra';
9
+
10
+ // Node's process.platform / process.arch tokens (linux|darwin|win32, x64|arm64)
11
+ // are exactly the suffixes used for the per-platform packages, so the package
12
+ // name is derived directly rather than looked up. This set is purely an
13
+ // allowlist of the platforms we publish binaries for — it exists so an
14
+ // unsupported host gets a clear error instead of a failed resolve of a
15
+ // package that was never published. Keep it in sync with the platform matrix
16
+ // in cli/scripts/build-npm-packages.sh.
17
+ const SUPPORTED_PLATFORMS = new Set([
18
+ 'linux x64',
19
+ 'linux arm64',
20
+ 'darwin x64',
21
+ 'darwin arm64',
22
+ 'win32 x64',
23
+ 'win32 arm64',
24
+ ]);
25
+
26
+ function platformPackage(platform, arch) {
27
+ if (!SUPPORTED_PLATFORMS.has(`${platform} ${arch}`)) {
28
+ return undefined;
29
+ }
30
+ return `${SCOPE}/opentaint-${platform}-${arch}`;
31
+ }
32
+
33
+ function resolveBinary(platform, arch, resolve) {
34
+ resolve = resolve || ((id) => require.resolve(id));
35
+ const pkg = platformPackage(platform, arch);
36
+ if (!pkg) {
37
+ throw new Error(
38
+ `opentaint does not ship a prebuilt binary for ${platform}/${arch}. ` +
39
+ `Supported platforms: ${Array.from(SUPPORTED_PLATFORMS).map((p) => p.replace(' ', '/')).join(', ')}.`
40
+ );
41
+ }
42
+ const binName = platform === 'win32' ? 'opentaint.exe' : 'opentaint';
43
+ let pkgJsonPath;
44
+ try {
45
+ pkgJsonPath = resolve(`${pkg}/package.json`);
46
+ } catch (_e) {
47
+ throw new Error(
48
+ `The platform package ${pkg} is not installed. This usually means ` +
49
+ `optional dependencies were skipped (e.g. "npm install --no-optional" ` +
50
+ `or "--omit=optional"). Reinstall opentaint without omitting optional dependencies.`
51
+ );
52
+ }
53
+ return path.join(path.dirname(pkgJsonPath), binName);
54
+ }
55
+
56
+ function signalExitCode(signal) {
57
+ const num = os.constants.signals[signal];
58
+ return num ? 128 + num : 1;
59
+ }
60
+
61
+ function run(argv, opts) {
62
+ opts = opts || {};
63
+ const platform = opts.platform || process.platform;
64
+ const arch = opts.arch || process.arch;
65
+ const spawn = opts.spawn || spawnSync;
66
+ const stderr = opts.stderr || process.stderr;
67
+
68
+ let binary;
69
+ try {
70
+ binary = resolveBinary(platform, arch, opts.resolve);
71
+ } catch (e) {
72
+ stderr.write(`opentaint: ${e.message}\n`);
73
+ return 1;
74
+ }
75
+
76
+ const result = spawn(binary, argv, { stdio: 'inherit' });
77
+ if (result.error) {
78
+ stderr.write(`opentaint: failed to launch ${binary}: ${result.error.message}\n`);
79
+ return 1;
80
+ }
81
+ if (typeof result.status === 'number') {
82
+ return result.status;
83
+ }
84
+ if (result.signal) {
85
+ return signalExitCode(result.signal);
86
+ }
87
+ return 1;
88
+ }
89
+
90
+ module.exports = { SCOPE, SUPPORTED_PLATFORMS, platformPackage, resolveBinary, signalExitCode, run };
91
+
92
+ if (require.main === module) {
93
+ process.exit(run(process.argv.slice(2)));
94
+ }
package/package.json ADDED
@@ -0,0 +1,28 @@
1
+ {
2
+ "name": "@seqra/opentaint",
3
+ "version": "0.0.0",
4
+ "description": "The open source taint analysis engine for the AI era.",
5
+ "license": "Apache-2.0",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "https://github.com/seqra/opentaint.git"
9
+ },
10
+ "homepage": "https://github.com/seqra/opentaint",
11
+ "bin": {
12
+ "opentaint": "bin/opentaint.js"
13
+ },
14
+ "files": [
15
+ "bin/"
16
+ ],
17
+ "optionalDependencies": {
18
+ "@seqra/opentaint-linux-x64": "0.0.0",
19
+ "@seqra/opentaint-linux-arm64": "0.0.0",
20
+ "@seqra/opentaint-darwin-x64": "0.0.0",
21
+ "@seqra/opentaint-darwin-arm64": "0.0.0",
22
+ "@seqra/opentaint-win32-x64": "0.0.0",
23
+ "@seqra/opentaint-win32-arm64": "0.0.0"
24
+ },
25
+ "publishConfig": {
26
+ "access": "public"
27
+ }
28
+ }