puxadinho 0.1.0 → 0.1.2

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/bin/puxadinho.js CHANGED
@@ -12,8 +12,9 @@ const path = require("node:path");
12
12
 
13
13
  const pkg = require("../package.json");
14
14
  const version = pkg.version;
15
- // TODO(release): troque pelo repositório definitivo das releases (hoje: origin do git).
16
- const DEFAULT_BASE = "https://github.com/hightech-company/puxadinho/releases/download";
15
+ const zlib = require("node:zlib");
16
+ // Reserva: o mesmo pacote da plataforma, baixado direto do registro do npm (.tgz).
17
+ const DEFAULT_REGISTRY = "https://registry.npmjs.org";
17
18
 
18
19
  const OS = { darwin: "darwin", linux: "linux" };
19
20
  const ARCH = { arm64: "arm64", x64: "amd64" };
@@ -41,6 +42,22 @@ function platformBinary() {
41
42
  }
42
43
  }
43
44
 
45
+ /** Extrai um arquivo de um tar (ustar) já descompactado. */
46
+ function fileFromTar(buf, want) {
47
+ for (let off = 0; off + 512 <= buf.length; ) {
48
+ const h = buf.subarray(off, off + 512);
49
+ if (h.every((b) => b === 0)) break;
50
+ const str = (a, b) => h.subarray(a, b).toString("utf8").replace(/\0.*$/s, "");
51
+ const prefix = str(345, 500);
52
+ const name = prefix ? `${prefix}/${str(0, 100)}` : str(0, 100);
53
+ const size = parseInt(str(124, 136).trim() || "0", 8);
54
+ const start = off + 512;
55
+ if (name === want) return buf.subarray(start, start + size);
56
+ off = start + Math.ceil(size / 512) * 512;
57
+ }
58
+ return null;
59
+ }
60
+
44
61
  async function ensureBinary() {
45
62
  const local = platformBinary();
46
63
  if (local) return local;
@@ -62,14 +79,22 @@ async function ensureBinary() {
62
79
  } catch {
63
80
  fail("este pacote veio sem checksums.txt; reinstale o puxadinho (npm i -g puxadinho@latest).");
64
81
  }
65
- const base = (process.env.PUXADINHO_DOWNLOAD_BASE || DEFAULT_BASE).replace(/\/+$/, "");
66
- const root = `${base}/v${version}`;
67
82
  process.stderr.write(`puxadinho: baixando ${name} v${version}…\n`);
68
83
  let bin;
69
84
  try {
70
- bin = await fetchBuffer(`${root}/${name}`);
85
+ if (process.env.PUXADINHO_DOWNLOAD_BASE) {
86
+ // Espelho com o layout de release: <base>/v<versão>/<binário>.
87
+ const base = process.env.PUXADINHO_DOWNLOAD_BASE.replace(/\/+$/, "");
88
+ bin = await fetchBuffer(`${base}/v${version}/${name}`);
89
+ } else {
90
+ const reg = (process.env.npm_config_registry || DEFAULT_REGISTRY).replace(/\/+$/, "");
91
+ const plat = `cli-${process.platform}-${process.arch}`;
92
+ const tgz = await fetchBuffer(`${reg}/@puxadinho/${plat}/-/${plat}-${version}.tgz`);
93
+ bin = fileFromTar(zlib.gunzipSync(tgz), "package/bin/puxadinho");
94
+ if (!bin) throw new Error(`o pacote @puxadinho/${plat} veio sem bin/puxadinho`);
95
+ }
71
96
  } catch (err) {
72
- fail(`não consegui baixar o binário (${err.message}). Verifique a rede ou PUXADINHO_DOWNLOAD_BASE.`, 75);
97
+ fail(`não consegui baixar o binário (${err.message}). Verifique a rede ou o registro do npm.`, 75);
73
98
  }
74
99
  const line = sums.split("\n").map((l) => l.trim().split(/\s+/)).find((p) => p[1] === name || p[1] === `*${name}`);
75
100
  if (!line) fail(`o checksums.txt do pacote não lista ${name}.`);
package/checksums.txt CHANGED
@@ -1,4 +1,4 @@
1
- 95aabc79a3485810ff19ef30a63a34247c562bf0fba0087299d46f3996d56eef puxadinho_darwin_arm64
2
- 4b9555625a55de9bf7b69ff9fd2aafa182862abd36942e2cae15551aed74d637 puxadinho_darwin_amd64
3
- 85b066761a6c08d78e74b24ef41d0069520e77d7c84a69cd70f6eba987d86d78 puxadinho_linux_amd64
4
- 7ba1a5024a0ed7ff2ce518081b62f2edda59f3f663b15649b2bc74aac4e8c954 puxadinho_linux_arm64
1
+ ea5c344486c00400d54c7f4202422e2d4f1995da88157ed79ee84ded75137c5c puxadinho_darwin_arm64
2
+ 8cf1444e65c635a7d1566108a2b545f7b9c05ce48b97ec83b1d77d3843c67bde puxadinho_darwin_amd64
3
+ 98b09949ee575579df8b6c07631c084569e85238023ea8e209bfdec8358c0999 puxadinho_linux_amd64
4
+ 6ab321cdf5d054fcec5fc751b977c34400d2351b9564aa18fa73ddde3f26d789 puxadinho_linux_arm64
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "puxadinho",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
4
  "description": "CLI do puxadinho: boxes Linux na nuvem para você e seus agentes.",
5
5
  "license": "SEE LICENSE IN README.md",
6
6
  "type": "commonjs",
@@ -22,9 +22,9 @@
22
22
  "build:binaries": "node scripts/build-binaries.js"
23
23
  },
24
24
  "optionalDependencies": {
25
- "@puxadinho/cli-darwin-arm64": "0.1.0",
26
- "@puxadinho/cli-darwin-x64": "0.1.0",
27
- "@puxadinho/cli-linux-arm64": "0.1.0",
28
- "@puxadinho/cli-linux-x64": "0.1.0"
25
+ "@puxadinho/cli-darwin-arm64": "0.1.2",
26
+ "@puxadinho/cli-darwin-x64": "0.1.2",
27
+ "@puxadinho/cli-linux-arm64": "0.1.2",
28
+ "@puxadinho/cli-linux-x64": "0.1.2"
29
29
  }
30
30
  }