@apollo/rover 0.23.0-rc.0 → 0.23.0-rc.1
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.js +121 -3
- package/package.json +7 -6
package/binary.js
CHANGED
@@ -1,8 +1,14 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
const axios = require("axios");
|
3
4
|
const cTable = require("console.table");
|
4
5
|
const libc = require("detect-libc");
|
6
|
+
const os = require("os");
|
7
|
+
const tar = require("tar");
|
5
8
|
const { configureProxy } = require("axios-proxy-builder");
|
9
|
+
const { existsSync, mkdirSync, rmSync } = require("fs");
|
10
|
+
const { join } = require("path");
|
11
|
+
const { spawnSync } = require("child_process");
|
6
12
|
|
7
13
|
const error = (msg) => {
|
8
14
|
console.error(msg);
|
@@ -49,7 +55,7 @@ const getPlatform = () => {
|
|
49
55
|
const type = os.type();
|
50
56
|
const architecture = os.arch();
|
51
57
|
|
52
|
-
for (supportedPlatform of supportedPlatforms) {
|
58
|
+
for (let supportedPlatform of supportedPlatforms) {
|
53
59
|
if (
|
54
60
|
type === supportedPlatform.TYPE &&
|
55
61
|
architecture === supportedPlatform.ARCHITECTURE
|
@@ -93,6 +99,118 @@ const getPlatform = () => {
|
|
93
99
|
);
|
94
100
|
};
|
95
101
|
|
102
|
+
/*! Copyright (c) 2019 Avery Harnish - MIT License */
|
103
|
+
class Binary {
|
104
|
+
constructor(name, url, config) {
|
105
|
+
let errors = [];
|
106
|
+
if (typeof url !== "string") {
|
107
|
+
errors.push("url must be a string");
|
108
|
+
} else {
|
109
|
+
try {
|
110
|
+
new URL(url);
|
111
|
+
} catch (e) {
|
112
|
+
errors.push(e);
|
113
|
+
}
|
114
|
+
}
|
115
|
+
if (name && typeof name !== "string") {
|
116
|
+
errors.push("name must be a string");
|
117
|
+
}
|
118
|
+
|
119
|
+
if (!name) {
|
120
|
+
errors.push("You must specify the name of your binary");
|
121
|
+
}
|
122
|
+
if (errors.length > 0) {
|
123
|
+
let errorMsg =
|
124
|
+
"One or more of the parameters you passed to the Binary constructor are invalid:\n";
|
125
|
+
errors.forEach(error => {
|
126
|
+
errorMsg += error;
|
127
|
+
});
|
128
|
+
errorMsg +=
|
129
|
+
'\n\nCorrect usage: new Binary("my-binary", "https://example.com/binary/download.tar.gz")';
|
130
|
+
error(errorMsg);
|
131
|
+
}
|
132
|
+
this.url = url;
|
133
|
+
this.name = name;
|
134
|
+
this.installDirectory =
|
135
|
+
config?.installDirectory || join(__dirname, "node_modules", ".bin");
|
136
|
+
|
137
|
+
if (!existsSync(this.installDirectory)) {
|
138
|
+
mkdirSync(this.installDirectory, { recursive: true });
|
139
|
+
}
|
140
|
+
|
141
|
+
this.binaryPath = join(this.installDirectory, this.name);
|
142
|
+
}
|
143
|
+
|
144
|
+
exists() {
|
145
|
+
return existsSync(this.binaryPath);
|
146
|
+
}
|
147
|
+
|
148
|
+
install(fetchOptions, suppressLogs = false) {
|
149
|
+
if (this.exists()) {
|
150
|
+
if (!suppressLogs) {
|
151
|
+
console.error(
|
152
|
+
`${this.name} is already installed, skipping installation.`
|
153
|
+
);
|
154
|
+
}
|
155
|
+
return Promise.resolve();
|
156
|
+
}
|
157
|
+
|
158
|
+
if (existsSync(this.installDirectory)) {
|
159
|
+
rmSync(this.installDirectory, { recursive: true });
|
160
|
+
}
|
161
|
+
|
162
|
+
mkdirSync(this.installDirectory, { recursive: true });
|
163
|
+
|
164
|
+
if (!suppressLogs) {
|
165
|
+
console.error(`Downloading release from ${this.url}`);
|
166
|
+
}
|
167
|
+
|
168
|
+
return axios({ ...fetchOptions, url: this.url, responseType: "stream" })
|
169
|
+
.then(res => {
|
170
|
+
return new Promise((resolve, reject) => {
|
171
|
+
const sink = res.data.pipe(
|
172
|
+
tar.x({ strip: 1, C: this.installDirectory })
|
173
|
+
);
|
174
|
+
sink.on("finish", () => resolve());
|
175
|
+
sink.on("error", err => reject(err));
|
176
|
+
});
|
177
|
+
})
|
178
|
+
.then(() => {
|
179
|
+
if (!suppressLogs) {
|
180
|
+
console.error(`${this.name} has been installed!`);
|
181
|
+
}
|
182
|
+
})
|
183
|
+
.catch(e => {
|
184
|
+
error(`Error fetching release: ${e.message}`);
|
185
|
+
});
|
186
|
+
}
|
187
|
+
|
188
|
+
run(fetchOptions) {
|
189
|
+
const promise = !this.exists()
|
190
|
+
? this.install(fetchOptions, true)
|
191
|
+
: Promise.resolve();
|
192
|
+
|
193
|
+
promise
|
194
|
+
.then(() => {
|
195
|
+
const [, , ...args] = process.argv;
|
196
|
+
|
197
|
+
const options = { cwd: process.cwd(), stdio: "inherit" };
|
198
|
+
|
199
|
+
const result = spawnSync(this.binaryPath, args, options);
|
200
|
+
|
201
|
+
if (result.error) {
|
202
|
+
error(result.error);
|
203
|
+
}
|
204
|
+
|
205
|
+
process.exit(result.status);
|
206
|
+
})
|
207
|
+
.catch(e => {
|
208
|
+
error(e.message);
|
209
|
+
process.exit(1);
|
210
|
+
});
|
211
|
+
}
|
212
|
+
}
|
213
|
+
|
96
214
|
const getBinary = () => {
|
97
215
|
const platform = getPlatform();
|
98
216
|
const download_host = process.env.npm_config_apollo_rover_download_host || process.env.APOLLO_ROVER_DOWNLOAD_HOST || 'https://rover.apollo.dev'
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@apollo/rover",
|
3
|
-
"version": "0.23.0-rc.
|
3
|
+
"version": "0.23.0-rc.1",
|
4
4
|
"description": "The new Apollo CLI",
|
5
5
|
"main": "index.js",
|
6
6
|
"bin": {
|
@@ -32,17 +32,18 @@
|
|
32
32
|
"npm": ">=6"
|
33
33
|
},
|
34
34
|
"volta": {
|
35
|
-
"node": "18.
|
36
|
-
"npm": "10.
|
35
|
+
"node": "18.19.0",
|
36
|
+
"npm": "10.3.0"
|
37
37
|
},
|
38
38
|
"homepage": "https://github.com/apollographql/rover#readme",
|
39
39
|
"dependencies": {
|
40
|
+
"axios": "^1.6.5",
|
40
41
|
"axios-proxy-builder": "^0.1.1",
|
41
|
-
"binary-install": "^1.0.6",
|
42
42
|
"console.table": "^0.10.0",
|
43
|
-
"detect-libc": "^2.0.0"
|
43
|
+
"detect-libc": "^2.0.0",
|
44
|
+
"tar": "^6.2.0"
|
44
45
|
},
|
45
46
|
"devDependencies": {
|
46
|
-
"prettier": "3.
|
47
|
+
"prettier": "3.2.4"
|
47
48
|
}
|
48
49
|
}
|