agentty 0.19.5 → 0.19.6

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/binary-install.js DELETED
@@ -1,212 +0,0 @@
1
- const { createWriteStream, existsSync, mkdirSync, mkdtemp } = require("fs");
2
- const { join, sep } = require("path");
3
- const { spawnSync } = require("child_process");
4
- const { tmpdir } = require("os");
5
-
6
- const axios = require("axios");
7
- const rimraf = require("rimraf");
8
- const tmpDir = tmpdir();
9
-
10
- const error = (msg) => {
11
- console.error(msg);
12
- process.exit(1);
13
- };
14
-
15
- class Package {
16
- constructor(platform, name, url, filename, zipExt, binaries) {
17
- let errors = [];
18
- if (typeof url !== "string") {
19
- errors.push("url must be a string");
20
- } else {
21
- try {
22
- new URL(url);
23
- } catch (e) {
24
- errors.push(e);
25
- }
26
- }
27
- if (name && typeof name !== "string") {
28
- errors.push("package name must be a string");
29
- }
30
- if (!name) {
31
- errors.push("You must specify the name of your package");
32
- }
33
- if (binaries && typeof binaries !== "object") {
34
- errors.push("binaries must be a string => string map");
35
- }
36
- if (!binaries) {
37
- errors.push("You must specify the binaries in the package");
38
- }
39
-
40
- if (errors.length > 0) {
41
- let errorMsg =
42
- "One or more of the parameters you passed to the Binary constructor are invalid:\n";
43
- errors.forEach((error) => {
44
- errorMsg += error;
45
- });
46
- errorMsg +=
47
- '\n\nCorrect usage: new Package("my-binary", "https://example.com/binary/download.tar.gz", {"my-binary": "my-binary"})';
48
- error(errorMsg);
49
- }
50
-
51
- this.platform = platform;
52
- this.url = url;
53
- this.name = name;
54
- this.filename = filename;
55
- this.zipExt = zipExt;
56
- this.installDirectory = join(__dirname, "node_modules", ".bin_real");
57
- this.binaries = binaries;
58
-
59
- if (!existsSync(this.installDirectory)) {
60
- mkdirSync(this.installDirectory, { recursive: true });
61
- }
62
- }
63
-
64
- exists() {
65
- for (const binaryName in this.binaries) {
66
- const binRelPath = this.binaries[binaryName];
67
- const binPath = join(this.installDirectory, binRelPath);
68
- if (!existsSync(binPath)) {
69
- return false;
70
- }
71
- }
72
- return true;
73
- }
74
-
75
- install(fetchOptions, suppressLogs = false) {
76
- if (this.exists()) {
77
- if (!suppressLogs) {
78
- console.error(
79
- `${this.name} is already installed, skipping installation.`,
80
- );
81
- }
82
- return Promise.resolve();
83
- }
84
-
85
- if (existsSync(this.installDirectory)) {
86
- rimraf.sync(this.installDirectory);
87
- }
88
-
89
- mkdirSync(this.installDirectory, { recursive: true });
90
-
91
- if (!suppressLogs) {
92
- console.error(`Downloading release from ${this.url}`);
93
- }
94
-
95
- return axios({ ...fetchOptions, url: this.url, responseType: "stream" })
96
- .then((res) => {
97
- return new Promise((resolve, reject) => {
98
- mkdtemp(`${tmpDir}${sep}`, (err, directory) => {
99
- let tempFile = join(directory, this.filename);
100
- const sink = res.data.pipe(createWriteStream(tempFile));
101
- sink.on("error", (err) => reject(err));
102
- sink.on("close", () => {
103
- if (/\.tar\.*/.test(this.zipExt)) {
104
- const result = spawnSync("tar", [
105
- "xf",
106
- tempFile,
107
- // The tarballs are stored with a leading directory
108
- // component; we strip one component in the
109
- // shell installers too.
110
- "--strip-components",
111
- "1",
112
- "-C",
113
- this.installDirectory,
114
- ]);
115
- if (result.status == 0) {
116
- resolve();
117
- } else if (result.error) {
118
- reject(result.error);
119
- } else {
120
- reject(
121
- new Error(
122
- `An error occurred untarring the artifact: stdout: ${result.stdout}; stderr: ${result.stderr}`,
123
- ),
124
- );
125
- }
126
- } else if (this.zipExt == ".zip") {
127
- let result;
128
- if (this.platform.artifactName.includes("windows")) {
129
- // Windows does not have "unzip" by default on many installations, instead
130
- // we use Expand-Archive from powershell
131
- result = spawnSync("powershell.exe", [
132
- "-NoProfile",
133
- "-NonInteractive",
134
- "-Command",
135
- `& {
136
- param([string]$LiteralPath, [string]$DestinationPath)
137
- Expand-Archive -LiteralPath $LiteralPath -DestinationPath $DestinationPath -Force
138
- }`,
139
- tempFile,
140
- this.installDirectory,
141
- ]);
142
- } else {
143
- result = spawnSync("unzip", [
144
- "-q",
145
- tempFile,
146
- "-d",
147
- this.installDirectory,
148
- ]);
149
- }
150
-
151
- if (result.status == 0) {
152
- resolve();
153
- } else if (result.error) {
154
- reject(result.error);
155
- } else {
156
- reject(
157
- new Error(
158
- `An error occurred unzipping the artifact: stdout: ${result.stdout}; stderr: ${result.stderr}`,
159
- ),
160
- );
161
- }
162
- } else {
163
- reject(
164
- new Error(`Unrecognized file extension: ${this.zipExt}`),
165
- );
166
- }
167
- });
168
- });
169
- });
170
- })
171
- .then(() => {
172
- if (!suppressLogs) {
173
- console.error(`${this.name} has been installed!`);
174
- }
175
- })
176
- .catch((e) => {
177
- error(`Error fetching release: ${e.message}`);
178
- });
179
- }
180
-
181
- run(binaryName, fetchOptions) {
182
- const promise = !this.exists()
183
- ? this.install(fetchOptions, true)
184
- : Promise.resolve();
185
-
186
- promise
187
- .then(() => {
188
- const [, , ...args] = process.argv;
189
-
190
- const options = { cwd: process.cwd(), stdio: "inherit" };
191
-
192
- const binRelPath = this.binaries[binaryName];
193
- if (!binRelPath) {
194
- error(`${binaryName} is not a known binary in ${this.name}`);
195
- }
196
- const binPath = join(this.installDirectory, binRelPath);
197
- const result = spawnSync(binPath, args, options);
198
-
199
- if (result.error) {
200
- error(result.error);
201
- }
202
-
203
- process.exit(result.status);
204
- })
205
- .catch((e) => {
206
- error(e.message);
207
- process.exit(1);
208
- });
209
- }
210
- }
211
-
212
- module.exports.Package = Package;