synclet 2.0.2 → 2.0.3
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 +1 -1
- package/postinstall.js +22 -12
package/package.json
CHANGED
package/postinstall.js
CHANGED
|
@@ -76,13 +76,16 @@ function parseChecksums(text) {
|
|
|
76
76
|
|
|
77
77
|
(async function main() {
|
|
78
78
|
try {
|
|
79
|
-
|
|
80
|
-
|
|
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)) {
|
|
81
83
|
console.error(
|
|
82
|
-
"synclet: npm install supports macOS (darwin) and
|
|
84
|
+
"synclet: npm install supports macOS (darwin), Linux and Windows only",
|
|
83
85
|
);
|
|
84
86
|
process.exit(1);
|
|
85
87
|
}
|
|
88
|
+
const isWindows = platform === "windows";
|
|
86
89
|
|
|
87
90
|
const pkg = JSON.parse(
|
|
88
91
|
fs.readFileSync(path.join(__dirname, "package.json"), "utf8"),
|
|
@@ -107,7 +110,8 @@ function parseChecksums(text) {
|
|
|
107
110
|
process.exit(1);
|
|
108
111
|
}
|
|
109
112
|
|
|
110
|
-
const
|
|
113
|
+
const ext = isWindows ? "zip" : "tar.gz";
|
|
114
|
+
const assetName = `${BIN}_${version}_${platform}_${arch}.${ext}`;
|
|
111
115
|
const base =
|
|
112
116
|
envOverride("BASE_URL") ||
|
|
113
117
|
`https://github.com/${OWNER}/${REPO}/releases/download/${version}`;
|
|
@@ -115,7 +119,7 @@ function parseChecksums(text) {
|
|
|
115
119
|
const checksumsUrl = `${base}/checksums.txt`;
|
|
116
120
|
const headers = { "User-Agent": `${REPO}-postinstall` };
|
|
117
121
|
const outDir = __dirname;
|
|
118
|
-
const exe = BIN;
|
|
122
|
+
const exe = isWindows ? `${BIN}.exe` : BIN;
|
|
119
123
|
const binPath = path.join(outDir, exe);
|
|
120
124
|
|
|
121
125
|
if (fs.existsSync(binPath)) {
|
|
@@ -126,7 +130,7 @@ function parseChecksums(text) {
|
|
|
126
130
|
}
|
|
127
131
|
|
|
128
132
|
console.log(`postinstall: downloading ${assetName} from ${url}`);
|
|
129
|
-
const
|
|
133
|
+
const archive = await httpGet(url, { headers });
|
|
130
134
|
|
|
131
135
|
// checksum (best effort)
|
|
132
136
|
try {
|
|
@@ -134,7 +138,7 @@ function parseChecksums(text) {
|
|
|
134
138
|
const checksums = parseChecksums(checksumsBuf.toString("utf8"));
|
|
135
139
|
const sumExpected = checksums.get(assetName);
|
|
136
140
|
if (!sumExpected) throw new Error("asset not in checksums.txt");
|
|
137
|
-
const sumActual = sha256(
|
|
141
|
+
const sumActual = sha256(archive);
|
|
138
142
|
if (sumActual.toLowerCase() !== sumExpected.toLowerCase())
|
|
139
143
|
throw new Error("checksum mismatch");
|
|
140
144
|
console.log("postinstall: checksum OK");
|
|
@@ -143,11 +147,17 @@ function parseChecksums(text) {
|
|
|
143
147
|
}
|
|
144
148
|
|
|
145
149
|
// extract only the binary into npm directory (archive contains binary at root)
|
|
146
|
-
const tmpFile = path.join(os.tmpdir(), `${REPO}-${Date.now()}
|
|
147
|
-
fs.writeFileSync(tmpFile,
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
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" });
|
|
151
161
|
if (tarRes.status !== 0) {
|
|
152
162
|
console.error("postinstall: failed to extract binary");
|
|
153
163
|
process.exit(1);
|