synclet 2.0.3 → 2.2.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/index.js +16 -14
- package/package.json +13 -4
- package/update_check.js +15 -2
- package/postinstall.js +0 -177
package/index.js
CHANGED
|
@@ -1,16 +1,14 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
const fs = require("fs");
|
|
3
|
-
const
|
|
4
|
-
const { spawn, spawnSync } = require("child_process");
|
|
3
|
+
const { spawn } = require("child_process");
|
|
5
4
|
|
|
6
|
-
const RUNNER = path.join(__dirname, "update_check_runner.js");
|
|
7
5
|
const {
|
|
8
6
|
maybePrintCachedNotice,
|
|
9
7
|
spawnUpdateCheckRunner,
|
|
10
8
|
} = require("./update_check");
|
|
11
9
|
|
|
12
10
|
const exe = process.platform === "win32" ? "synclet.exe" : "synclet";
|
|
13
|
-
const
|
|
11
|
+
const platformPackage = `@digitalvibeshq/synclet-${process.platform}-${process.arch}`;
|
|
14
12
|
|
|
15
13
|
const PKG = (() => {
|
|
16
14
|
try {
|
|
@@ -20,17 +18,16 @@ const PKG = (() => {
|
|
|
20
18
|
}
|
|
21
19
|
})();
|
|
22
20
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
{
|
|
21
|
+
let binPath;
|
|
22
|
+
try {
|
|
23
|
+
binPath = require.resolve(`${platformPackage}/bin/${exe}`);
|
|
24
|
+
} catch {
|
|
25
|
+
console.error(
|
|
26
|
+
`synclet: ${platformPackage} is not installed. ` +
|
|
27
|
+
"Either this platform is unsupported or optional dependencies were " +
|
|
28
|
+
"omitted (--omit=optional / --no-optional).",
|
|
29
29
|
);
|
|
30
|
-
|
|
31
|
-
console.error("Failed to download binary.");
|
|
32
|
-
process.exit(1);
|
|
33
|
-
}
|
|
30
|
+
process.exit(1);
|
|
34
31
|
}
|
|
35
32
|
|
|
36
33
|
if (process.platform !== "win32") {
|
|
@@ -44,6 +41,11 @@ const child = spawn(binPath, process.argv.slice(2), {
|
|
|
44
41
|
windowsHide: true,
|
|
45
42
|
});
|
|
46
43
|
|
|
44
|
+
// A caller that signals only the wrapper would otherwise orphan the binary.
|
|
45
|
+
for (const sig of ["SIGINT", "SIGTERM", "SIGHUP"]) {
|
|
46
|
+
process.on(sig, () => child.kill(sig));
|
|
47
|
+
}
|
|
48
|
+
|
|
47
49
|
// Best-effort update notice.
|
|
48
50
|
try {
|
|
49
51
|
maybePrintCachedNotice({ installedVersion: PKG && PKG.version });
|
package/package.json
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "synclet",
|
|
3
|
-
"version": "2.0
|
|
3
|
+
"version": "2.2.0",
|
|
4
4
|
"description": "CLI interface for syncing with Synclet (formerly ConfigMesh)",
|
|
5
5
|
"homepage": "https://synclet.dev",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
8
|
-
"url": "git+https://github.com/
|
|
8
|
+
"url": "git+https://github.com/digitalvibeshq/synclet-cli.git",
|
|
9
|
+
"directory": "npm"
|
|
9
10
|
},
|
|
10
11
|
"keywords": [
|
|
11
12
|
"synclet",
|
|
@@ -16,7 +17,6 @@
|
|
|
16
17
|
],
|
|
17
18
|
"files": [
|
|
18
19
|
"index.js",
|
|
19
|
-
"postinstall.js",
|
|
20
20
|
"update_check.js",
|
|
21
21
|
"update_check_runner.js"
|
|
22
22
|
],
|
|
@@ -30,6 +30,15 @@
|
|
|
30
30
|
"synclet": "index.js"
|
|
31
31
|
},
|
|
32
32
|
"scripts": {
|
|
33
|
-
"
|
|
33
|
+
"test": "node --test"
|
|
34
|
+
},
|
|
35
|
+
"optionalDependencies": {
|
|
36
|
+
"@digitalvibeshq/synclet-darwin-arm64": "2.2.0",
|
|
37
|
+
"@digitalvibeshq/synclet-darwin-x64": "2.2.0",
|
|
38
|
+
"@digitalvibeshq/synclet-linux-arm64": "2.2.0",
|
|
39
|
+
"@digitalvibeshq/synclet-linux-x64": "2.2.0",
|
|
40
|
+
"@digitalvibeshq/synclet-linux-arm": "2.2.0",
|
|
41
|
+
"@digitalvibeshq/synclet-win32-arm64": "2.2.0",
|
|
42
|
+
"@digitalvibeshq/synclet-win32-x64": "2.2.0"
|
|
34
43
|
}
|
|
35
44
|
}
|
package/update_check.js
CHANGED
|
@@ -6,13 +6,25 @@ const { spawn } = require('child_process');
|
|
|
6
6
|
const semver = require('semver');
|
|
7
7
|
|
|
8
8
|
const DEFAULT_PACKAGE_NAME = 'synclet';
|
|
9
|
-
const DEFAULT_UPDATE_COMMAND = 'npm install -g synclet';
|
|
10
9
|
|
|
11
10
|
const UPDATE_CHECK_INTERVAL_MS = 24 * 60 * 60 * 1000;
|
|
12
11
|
const UPDATE_CHECK_TIMEOUT_MS = 1200;
|
|
13
12
|
|
|
14
13
|
const RUNNER_FILE = 'update_check_runner.js';
|
|
15
14
|
|
|
15
|
+
// Prefer mise upgrade for mise installs: npm install -g adds a copy the mise shim never runs.
|
|
16
|
+
function detectUpdateCommand(packageName = DEFAULT_PACKAGE_NAME, dir = __dirname) {
|
|
17
|
+
const toSlashes = (p) => p.replace(/\\/g, '/');
|
|
18
|
+
const installDir = toSlashes(dir);
|
|
19
|
+
const miseNpmInstalls = process.env.MISE_DATA_DIR
|
|
20
|
+
? toSlashes(path.join(process.env.MISE_DATA_DIR, 'installs')) + '/npm-'
|
|
21
|
+
: '';
|
|
22
|
+
if (installDir.includes('/mise/installs/npm-') || (miseNpmInstalls && installDir.startsWith(miseNpmInstalls))) {
|
|
23
|
+
return `mise upgrade npm:${packageName}`;
|
|
24
|
+
}
|
|
25
|
+
return `npm install -g ${packageName}`;
|
|
26
|
+
}
|
|
27
|
+
|
|
16
28
|
function isDisabled() {
|
|
17
29
|
return (
|
|
18
30
|
process.env.SYNCLET_NO_UPDATE_NOTICE === '1' ||
|
|
@@ -157,7 +169,7 @@ function getCachedUpdate({ installedVersion, now = Date.now() }) {
|
|
|
157
169
|
function maybePrintCachedNotice({
|
|
158
170
|
packageName = DEFAULT_PACKAGE_NAME,
|
|
159
171
|
installedVersion,
|
|
160
|
-
updateCommand =
|
|
172
|
+
updateCommand = detectUpdateCommand(packageName),
|
|
161
173
|
} = {}) {
|
|
162
174
|
if (!shouldPrintNotice()) return false;
|
|
163
175
|
|
|
@@ -215,6 +227,7 @@ function spawnUpdateCheckRunner() {
|
|
|
215
227
|
}
|
|
216
228
|
|
|
217
229
|
module.exports = {
|
|
230
|
+
detectUpdateCommand,
|
|
218
231
|
maybePrintCachedNotice,
|
|
219
232
|
refreshCache,
|
|
220
233
|
spawnUpdateCheckRunner,
|
package/postinstall.js
DELETED
|
@@ -1,177 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
const fs = require("fs");
|
|
3
|
-
const path = require("path");
|
|
4
|
-
const os = require("os");
|
|
5
|
-
const https = require("https");
|
|
6
|
-
const crypto = require("crypto");
|
|
7
|
-
const { spawnSync } = require("child_process");
|
|
8
|
-
|
|
9
|
-
const OWNER = "dvcrn";
|
|
10
|
-
const REPO = "synclet-cli";
|
|
11
|
-
const BIN = "synclet";
|
|
12
|
-
|
|
13
|
-
// Synclet was previously named ConfigMesh. Each override is read as SYNCLET_*
|
|
14
|
-
// first and falls back to the legacy CONFIGMESH_* name.
|
|
15
|
-
function envOverride(suffix) {
|
|
16
|
-
const current = process.env[`SYNCLET_${suffix}`];
|
|
17
|
-
if (current) return current;
|
|
18
|
-
return process.env[`CONFIGMESH_${suffix}`] || "";
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
function httpGet(url, { headers } = {}) {
|
|
22
|
-
return new Promise((resolve, reject) => {
|
|
23
|
-
const req = https.get(url, { headers }, (res) => {
|
|
24
|
-
if (
|
|
25
|
-
res.statusCode &&
|
|
26
|
-
res.statusCode >= 300 &&
|
|
27
|
-
res.statusCode < 400 &&
|
|
28
|
-
res.headers.location
|
|
29
|
-
) {
|
|
30
|
-
resolve(httpGet(res.headers.location, { headers }));
|
|
31
|
-
return;
|
|
32
|
-
}
|
|
33
|
-
if (res.statusCode !== 200) {
|
|
34
|
-
reject(new Error(`GET ${url} -> ${res.statusCode}`));
|
|
35
|
-
return;
|
|
36
|
-
}
|
|
37
|
-
const chunks = [];
|
|
38
|
-
res.on("data", (c) => chunks.push(c));
|
|
39
|
-
res.on("end", () => resolve(Buffer.concat(chunks)));
|
|
40
|
-
});
|
|
41
|
-
req.on("error", reject);
|
|
42
|
-
});
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
function sha256(buf) {
|
|
46
|
-
const h = crypto.createHash("sha256");
|
|
47
|
-
h.update(buf);
|
|
48
|
-
return h.digest("hex");
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
function parseChecksums(text) {
|
|
52
|
-
const map = new Map();
|
|
53
|
-
const lines = text
|
|
54
|
-
.split(/\r?\n/)
|
|
55
|
-
.map((l) => l.trim())
|
|
56
|
-
.filter(Boolean);
|
|
57
|
-
for (const line of lines) {
|
|
58
|
-
let m = line.match(/^([a-f0-9]{64})\s+(.+)$/i);
|
|
59
|
-
if (m) {
|
|
60
|
-
map.set(m[2], m[1]);
|
|
61
|
-
continue;
|
|
62
|
-
}
|
|
63
|
-
m = line.match(/^sha256:([a-f0-9]{64})\s+(.+)$/i);
|
|
64
|
-
if (m) {
|
|
65
|
-
map.set(m[2], m[1]);
|
|
66
|
-
continue;
|
|
67
|
-
}
|
|
68
|
-
m = line.match(/^SHA256\s+\((.+)\)\s+=\s+([a-f0-9]{64})$/i);
|
|
69
|
-
if (m) {
|
|
70
|
-
map.set(m[1], m[2]);
|
|
71
|
-
continue;
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
return map;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
(async function main() {
|
|
78
|
-
try {
|
|
79
|
-
// Release assets name Windows "windows", while Node reports "win32".
|
|
80
|
-
const rawPlatform = envOverride("PLATFORM") || process.platform;
|
|
81
|
-
const platform = rawPlatform === "win32" ? "windows" : rawPlatform;
|
|
82
|
-
if (!["darwin", "linux", "windows"].includes(platform)) {
|
|
83
|
-
console.error(
|
|
84
|
-
"synclet: npm install supports macOS (darwin), Linux and Windows only",
|
|
85
|
-
);
|
|
86
|
-
process.exit(1);
|
|
87
|
-
}
|
|
88
|
-
const isWindows = platform === "windows";
|
|
89
|
-
|
|
90
|
-
const pkg = JSON.parse(
|
|
91
|
-
fs.readFileSync(path.join(__dirname, "package.json"), "utf8"),
|
|
92
|
-
);
|
|
93
|
-
const version = envOverride("VERSION") || pkg.version || "";
|
|
94
|
-
if (!version) {
|
|
95
|
-
console.error("postinstall: could not determine version");
|
|
96
|
-
process.exit(1);
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
const detectedArch =
|
|
100
|
-
process.arch === "x64"
|
|
101
|
-
? "amd64"
|
|
102
|
-
: process.arch === "arm64"
|
|
103
|
-
? "arm64"
|
|
104
|
-
: process.arch === "arm"
|
|
105
|
-
? "armv7"
|
|
106
|
-
: process.arch;
|
|
107
|
-
const arch = envOverride("ARCH") || detectedArch;
|
|
108
|
-
if (!["amd64", "arm64", "armv7"].includes(arch)) {
|
|
109
|
-
console.error(`Unsupported arch: ${arch}`);
|
|
110
|
-
process.exit(1);
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
const ext = isWindows ? "zip" : "tar.gz";
|
|
114
|
-
const assetName = `${BIN}_${version}_${platform}_${arch}.${ext}`;
|
|
115
|
-
const base =
|
|
116
|
-
envOverride("BASE_URL") ||
|
|
117
|
-
`https://github.com/${OWNER}/${REPO}/releases/download/${version}`;
|
|
118
|
-
const url = `${base}/${assetName}`;
|
|
119
|
-
const checksumsUrl = `${base}/checksums.txt`;
|
|
120
|
-
const headers = { "User-Agent": `${REPO}-postinstall` };
|
|
121
|
-
const outDir = __dirname;
|
|
122
|
-
const exe = isWindows ? `${BIN}.exe` : BIN;
|
|
123
|
-
const binPath = path.join(outDir, exe);
|
|
124
|
-
|
|
125
|
-
if (fs.existsSync(binPath)) {
|
|
126
|
-
try {
|
|
127
|
-
fs.chmodSync(binPath, 0o755);
|
|
128
|
-
} catch {}
|
|
129
|
-
return;
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
console.log(`postinstall: downloading ${assetName} from ${url}`);
|
|
133
|
-
const archive = await httpGet(url, { headers });
|
|
134
|
-
|
|
135
|
-
// checksum (best effort)
|
|
136
|
-
try {
|
|
137
|
-
const checksumsBuf = await httpGet(checksumsUrl, { headers });
|
|
138
|
-
const checksums = parseChecksums(checksumsBuf.toString("utf8"));
|
|
139
|
-
const sumExpected = checksums.get(assetName);
|
|
140
|
-
if (!sumExpected) throw new Error("asset not in checksums.txt");
|
|
141
|
-
const sumActual = sha256(archive);
|
|
142
|
-
if (sumActual.toLowerCase() !== sumExpected.toLowerCase())
|
|
143
|
-
throw new Error("checksum mismatch");
|
|
144
|
-
console.log("postinstall: checksum OK");
|
|
145
|
-
} catch (e) {
|
|
146
|
-
console.warn(`postinstall: checksum skipped/failed: ${e.message}`);
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
// extract only the binary into npm directory (archive contains binary at root)
|
|
150
|
-
const tmpFile = path.join(os.tmpdir(), `${REPO}-${Date.now()}.${ext}`);
|
|
151
|
-
fs.writeFileSync(tmpFile, archive);
|
|
152
|
-
// Windows 10+ ships bsdtar as System32\tar.exe, which can read zip files.
|
|
153
|
-
// Use it by full path so a GNU tar from Git Bash on PATH doesn't win.
|
|
154
|
-
const tarCmd = isWindows
|
|
155
|
-
? path.join(process.env.SystemRoot || "C:\\Windows", "System32", "tar.exe")
|
|
156
|
-
: "tar";
|
|
157
|
-
const tarArgs = isWindows
|
|
158
|
-
? ["-xf", tmpFile, "-C", outDir, exe]
|
|
159
|
-
: ["-xzf", tmpFile, "-C", outDir, exe];
|
|
160
|
-
const tarRes = spawnSync(tarCmd, tarArgs, { stdio: "inherit" });
|
|
161
|
-
if (tarRes.status !== 0) {
|
|
162
|
-
console.error("postinstall: failed to extract binary");
|
|
163
|
-
process.exit(1);
|
|
164
|
-
}
|
|
165
|
-
try {
|
|
166
|
-
fs.chmodSync(binPath, 0o755);
|
|
167
|
-
} catch {}
|
|
168
|
-
try {
|
|
169
|
-
fs.unlinkSync(tmpFile);
|
|
170
|
-
} catch {}
|
|
171
|
-
console.log(`postinstall: installed ${exe} to ${outDir}`);
|
|
172
|
-
process.exit(0);
|
|
173
|
-
} catch (err) {
|
|
174
|
-
console.error(`postinstall error: ${err.message}`);
|
|
175
|
-
process.exit(1);
|
|
176
|
-
}
|
|
177
|
-
})();
|