@secretstore/cli 0.0.0-stage → 0.7.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/LICENSE +661 -0
- package/README.md +12 -2
- package/dist/secretstore.js +2015 -0
- package/launcher.cjs +82 -0
- package/package.json +30 -4
package/launcher.cjs
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
// Deliberately Node-compatible (18+ syntax): Bun is embedded in the platform executable. With that executable
|
|
4
|
+
// installed it runs; without it (--omit=optional, an unsupported platform) the bundled JavaScript runs in this process.
|
|
5
|
+
const { spawn } = require("node:child_process");
|
|
6
|
+
const { constants } = require("node:os");
|
|
7
|
+
const { join, dirname } = require("node:path");
|
|
8
|
+
const { readFileSync } = require("node:fs");
|
|
9
|
+
const { pathToFileURL } = require("node:url");
|
|
10
|
+
|
|
11
|
+
// A terminal's Ctrl+C reaches the whole foreground process group on POSIX, and the shared console on Windows, so the
|
|
12
|
+
// child already got that SIGINT; sending it again could abort a graceful shutdown, and on Windows child.kill is
|
|
13
|
+
// TerminateProcess, which skips the CLI's own handling. SIGTERM and SIGHUP are always sent on.
|
|
14
|
+
const forwards = (signal, platform, stdinIsTty) => signal !== "SIGINT" || (platform !== "win32" && !stdinIsTty);
|
|
15
|
+
|
|
16
|
+
// Required by the tests for the rule above; running as the command does the real work below.
|
|
17
|
+
if (require.main !== module) {
|
|
18
|
+
module.exports = { forwards };
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const platforms = { win32: ["x64"], linux: ["x64", "arm64"], darwin: ["x64", "arm64"] };
|
|
23
|
+
const fail = (message) => { process.stderr.write(`secretstore: ${message}\n`); process.exitCode = 1; };
|
|
24
|
+
const version = require("./package.json").version;
|
|
25
|
+
const runtime = process.env.SECRET_STORE_CLI_RUNTIME;
|
|
26
|
+
const supported = platforms[process.platform]?.includes(process.arch);
|
|
27
|
+
const key = `${process.platform === "win32" ? "windows" : process.platform}-${process.arch}`;
|
|
28
|
+
const name = `@secretstore/cli-${key}`;
|
|
29
|
+
|
|
30
|
+
function runJs() {
|
|
31
|
+
// The bundle has no binary to replace, so `update` prints the package-manager instructions.
|
|
32
|
+
process.env.SECRET_STORE_PACKAGE_MANAGED = "1";
|
|
33
|
+
import(pathToFileURL(join(__dirname, "dist", "secretstore.js")).href).catch((error) => fail(`Cannot run the bundled JavaScript: ${error.message}. Reinstall @secretstore/cli.`));
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function runNative(manifest) {
|
|
37
|
+
const installed = JSON.parse(readFileSync(manifest, "utf8"));
|
|
38
|
+
if (installed.version !== version || installed.name !== name) throw new Error(`Expected ${name}@${version}; found ${installed.name}@${installed.version}`);
|
|
39
|
+
const binary = join(dirname(manifest), "bin", process.platform === "win32" ? "secretstore.exe" : "secretstore");
|
|
40
|
+
const child = spawn(binary, process.argv.slice(2), {
|
|
41
|
+
stdio: "inherit",
|
|
42
|
+
env: { ...process.env, SECRET_STORE_PACKAGE_MANAGED: "1" },
|
|
43
|
+
});
|
|
44
|
+
const handlers = new Map();
|
|
45
|
+
for (const signal of ["SIGINT", "SIGTERM", "SIGHUP"]) {
|
|
46
|
+
// Keep a handler for SIGINT either way: without one the launcher would die before the child finished shutting down.
|
|
47
|
+
const forward = () => { if (forwards(signal, process.platform, process.stdin.isTTY === true)) child.kill(signal); };
|
|
48
|
+
handlers.set(signal, forward);
|
|
49
|
+
process.on(signal, forward);
|
|
50
|
+
}
|
|
51
|
+
child.on("error", (error) => fail(`Cannot start ${name}: ${error.message}. Reinstall @secretstore/cli with optional dependencies enabled (omit --omit=optional / --no-optional).`));
|
|
52
|
+
child.on("exit", (code, signal) => {
|
|
53
|
+
for (const [signalName, handler] of handlers) process.off(signalName, handler);
|
|
54
|
+
if (signal && process.platform !== "win32") process.kill(process.pid, signal);
|
|
55
|
+
else process.exitCode = code ?? (128 + (constants.signals[signal] ?? 1));
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
if (runtime && runtime !== "native" && runtime !== "js") {
|
|
60
|
+
fail(`SECRET_STORE_CLI_RUNTIME is "native" or "js", not "${runtime}"`);
|
|
61
|
+
} else if (runtime === "js") {
|
|
62
|
+
runJs();
|
|
63
|
+
} else if (!supported) {
|
|
64
|
+
if (runtime === "native") fail(`Unsupported platform ${process.platform}-${process.arch}. Use a supported Windows x64, Linux x64/arm64 or macOS x64/arm64 machine.`);
|
|
65
|
+
else runJs();
|
|
66
|
+
} else {
|
|
67
|
+
let manifest;
|
|
68
|
+
try {
|
|
69
|
+
manifest = require.resolve(`${name}/package.json`);
|
|
70
|
+
} catch {
|
|
71
|
+
// Not installed: the JavaScript in this package takes over unless the native executable was demanded.
|
|
72
|
+
if (runtime === "native") fail(`Cannot find ${name}. Reinstall @secretstore/cli with optional dependencies enabled (omit --omit=optional / --no-optional).`);
|
|
73
|
+
else runJs();
|
|
74
|
+
}
|
|
75
|
+
if (manifest) {
|
|
76
|
+
try {
|
|
77
|
+
runNative(manifest);
|
|
78
|
+
} catch (error) {
|
|
79
|
+
fail(`${error.message}. Reinstall @secretstore/cli with optional dependencies enabled (omit --omit=optional / --no-optional).`);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,32 @@
|
|
|
1
1
|
{
|
|
2
|
+
"version": "0.7.0",
|
|
3
|
+
"license": "AGPL-3.0-only",
|
|
4
|
+
"repository": {
|
|
5
|
+
"type": "git",
|
|
6
|
+
"url": "git+https://github.com/CodingDiego/secret-store.git"
|
|
7
|
+
},
|
|
8
|
+
"publishConfig": {
|
|
9
|
+
"access": "public",
|
|
10
|
+
"provenance": false
|
|
11
|
+
},
|
|
12
|
+
"engines": {
|
|
13
|
+
"node": ">=20"
|
|
14
|
+
},
|
|
2
15
|
"name": "@secretstore/cli",
|
|
3
|
-
"
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
16
|
+
"description": "Secret Store command line client",
|
|
17
|
+
"type": "module",
|
|
18
|
+
"bin": {
|
|
19
|
+
"secretstore": "launcher.cjs"
|
|
20
|
+
},
|
|
21
|
+
"files": [
|
|
22
|
+
"launcher.cjs",
|
|
23
|
+
"dist/"
|
|
24
|
+
],
|
|
25
|
+
"optionalDependencies": {
|
|
26
|
+
"@secretstore/cli-windows-x64": "0.7.0",
|
|
27
|
+
"@secretstore/cli-linux-x64": "0.7.0",
|
|
28
|
+
"@secretstore/cli-linux-arm64": "0.7.0",
|
|
29
|
+
"@secretstore/cli-darwin-x64": "0.7.0",
|
|
30
|
+
"@secretstore/cli-darwin-arm64": "0.7.0"
|
|
31
|
+
}
|
|
32
|
+
}
|