offwatch 0.5.16 → 0.5.17
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/lib/downloader.js +23 -7
- package/package.json +1 -1
package/lib/downloader.js
CHANGED
|
@@ -2,7 +2,7 @@ import got from "got";
|
|
|
2
2
|
import fs from "fs";
|
|
3
3
|
import fsa from "fs-extra";
|
|
4
4
|
import * as os from "node:os";
|
|
5
|
-
import
|
|
5
|
+
import { spawn } from "child_process";
|
|
6
6
|
import stream from "node:stream";
|
|
7
7
|
import { promisify } from "node:util";
|
|
8
8
|
import path from "node:path";
|
|
@@ -83,13 +83,29 @@ const downloadRelease = async (versionDir) => {
|
|
|
83
83
|
// For .js files, rename to expected name
|
|
84
84
|
fs.renameSync(tempPath, filePath);
|
|
85
85
|
} else {
|
|
86
|
-
// For compressed files, decompress
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
86
|
+
// For compressed files, decompress using tar via spawn
|
|
87
|
+
// The tar archive contains just offwatch.js without a directory prefix
|
|
88
|
+
const toGitPath = (p) => p.replace(/\\/g, "/").replace(/^([A-Za-z]):/, (_, d) => `/${d.toLowerCase()}`);
|
|
89
|
+
const tarPath = toGitPath(tempPath);
|
|
90
|
+
const tarCwd = toGitPath(versionDir);
|
|
91
|
+
|
|
92
|
+
await new Promise((resolve, reject) => {
|
|
93
|
+
// Archive contains offwatch.js directly, so don't use --strip=1
|
|
94
|
+
const args = ["-xzf", tarPath, "-C", tarCwd];
|
|
95
|
+
logDebug(`Running: tar ${args.join(" ")}`);
|
|
96
|
+
const proc = spawn("tar", args);
|
|
97
|
+
let stderr = "";
|
|
98
|
+
proc.stderr.on("data", (data) => { stderr += data.toString(); });
|
|
99
|
+
proc.on("close", (code) => {
|
|
100
|
+
if (code === 0) {
|
|
101
|
+
fs.unlinkSync(tempPath);
|
|
102
|
+
resolve();
|
|
103
|
+
} else {
|
|
104
|
+
reject(new Error(`tar exited with code ${code}: ${stderr}`));
|
|
105
|
+
}
|
|
106
|
+
});
|
|
107
|
+
proc.on("error", reject);
|
|
91
108
|
});
|
|
92
|
-
fs.unlinkSync(tempPath);
|
|
93
109
|
}
|
|
94
110
|
|
|
95
111
|
// Copy package.json to bin directory so bundled code can find it
|