@eggplanty/mycli 0.1.20 → 0.1.22

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/scripts/install.js +12 -4
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eggplanty/mycli",
3
- "version": "0.1.20",
3
+ "version": "0.1.22",
4
4
  "description": "A simple CLI demo built with Go",
5
5
  "bin": {
6
6
  "mycli": "scripts/run.js"
@@ -33,18 +33,26 @@ const isWindows = process.platform === "win32";
33
33
  const ext = isWindows ? ".zip" : ".tar.gz";
34
34
  const archiveName = `${NAME}-${VERSION}-${platform}-${arch}${ext}`;
35
35
  const url = `https://github.com/${REPO}/releases/download/v${VERSION}/${archiveName}`;
36
+ const token = process.env.MYCLI_TOKEN || "";
36
37
  const binDir = path.join(__dirname, "..", "bin");
37
38
  const dest = path.join(binDir, NAME + (isWindows ? ".exe" : ""));
38
39
 
39
40
  fs.mkdirSync(binDir, { recursive: true });
40
41
 
41
- function download(url, destPath) {
42
+ function download(url, destPath, useAuth = true) {
42
43
  return new Promise((resolve, reject) => {
43
- const client = url.startsWith("https") ? https : require("http");
44
+ const parsed = new URL(url);
45
+ const client = parsed.protocol === "https:" ? https : require("http");
46
+ const headers = {};
47
+ if (token && useAuth) {
48
+ headers["Authorization"] = `token ${token}`;
49
+ headers["Accept"] = "application/octet-stream";
50
+ }
44
51
  client
45
- .get(url, (res) => {
52
+ .get({ hostname: parsed.hostname, path: parsed.pathname + parsed.search, headers }, (res) => {
46
53
  if (res.statusCode === 302 || res.statusCode === 301) {
47
- return download(res.headers.location, destPath).then(
54
+ // Do not send auth token to redirected hosts (e.g. S3)
55
+ return download(res.headers.location, destPath, false).then(
48
56
  resolve,
49
57
  reject
50
58
  );