@sachinthapa572/fast 0.1.7-rc → 0.1.8-rc

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/README.md ADDED
@@ -0,0 +1,35 @@
1
+ # fast
2
+
3
+ Test your internet speed from the command-line, powered by [fast.com](https://fast.com).
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ npm install -g @sachinthapa572/fast
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ```bash
14
+ fast
15
+ ```
16
+
17
+ `fast` measures your download speed against the nearest Netflix Open Connect
18
+ servers and reports it in megabits per second, right inline in your terminal.
19
+
20
+ ## How this package works
21
+
22
+ `@sachinthapa572/fast` ships no binary itself. Instead it declares one
23
+ `optionalDependencies` entry per supported platform
24
+ (`@sachinthapa572/fast-<os>-<cpu>`), and npm installs only the one matching
25
+ your machine. The `fast` command then runs that binary directly — no
26
+ postinstall network download involved.
27
+
28
+ Supported platforms: linux, macOS (darwin), and Windows (win32), each on
29
+ x64 and arm64.
30
+
31
+ ## Links
32
+
33
+ - Source: https://github.com/sachinthapa572/fast
34
+ - Issues: https://github.com/sachinthapa572/fast/issues
35
+ - License: [MIT](https://github.com/sachinthapa572/fast/blob/master/LICENSE)
package/cli.js CHANGED
@@ -1,15 +1,44 @@
1
1
  #!/usr/bin/env node
2
2
  const { spawnSync } = require("child_process");
3
- const { ensureBinary, BINARY_PATH } = require("./download");
4
-
5
- ensureBinary()
6
- .then(() => {
7
- const result = spawnSync(BINARY_PATH, process.argv.slice(2), {
8
- stdio: "inherit",
9
- });
10
- process.exit(result.status ?? 1);
11
- })
12
- .catch((err) => {
13
- console.error("Failed to install fast binary:", err.message);
14
- process.exit(1);
3
+
4
+ const PLATFORM_PACKAGES = {
5
+ "darwin-x64": "@sachinthapa572/fast-darwin-x64",
6
+ "darwin-arm64": "@sachinthapa572/fast-darwin-arm64",
7
+ "linux-x64": "@sachinthapa572/fast-linux-x64",
8
+ "linux-arm64": "@sachinthapa572/fast-linux-arm64",
9
+ "win32-x64": "@sachinthapa572/fast-win32-x64",
10
+ "win32-arm64": "@sachinthapa572/fast-win32-arm64",
11
+ };
12
+
13
+ function binaryPath() {
14
+ const key = `${process.platform}-${process.arch}`;
15
+ const pkg = PLATFORM_PACKAGES[key];
16
+ if (!pkg) {
17
+ throw new Error(
18
+ `fast does not support this platform (${key}). Supported: ${Object.keys(PLATFORM_PACKAGES).join(", ")}`,
19
+ );
20
+ }
21
+
22
+ const binName = process.platform === "win32" ? "fast.exe" : "fast";
23
+ try {
24
+ return require.resolve(`${pkg}/bin/${binName}`);
25
+ } catch {
26
+ throw new Error(
27
+ `Could not find the "${pkg}" package.\n` +
28
+ `This can happen if you installed with --no-optional/--omit=optional, or your ` +
29
+ `package manager doesn't support platform-filtered optionalDependencies.\n` +
30
+ `Try: npm install ${pkg}`,
31
+ );
32
+ }
33
+ }
34
+
35
+ try {
36
+ const result = spawnSync(binaryPath(), process.argv.slice(2), {
37
+ stdio: "inherit",
15
38
  });
39
+ if (result.error) throw result.error;
40
+ process.exit(result.status ?? 1);
41
+ } catch (err) {
42
+ console.error(err.message);
43
+ process.exit(1);
44
+ }
package/package.json CHANGED
@@ -1,18 +1,20 @@
1
1
  {
2
2
  "name": "@sachinthapa572/fast",
3
- "version": "0.1.7-rc",
3
+ "version": "0.1.8-rc",
4
4
  "description": "Test your internet speed from the command-line",
5
5
  "bin": {
6
6
  "fast": "cli.js"
7
7
  },
8
- "scripts": {
9
- "preuninstall": "node uninstall.js"
10
- },
8
+ "files": [
9
+ "cli.js",
10
+ "README.md"
11
+ ],
11
12
  "repository": {
12
13
  "type": "git",
13
- "url": "https://github.com/sachinthapa572/fast-speed"
14
+ "url": "https://github.com/sachinthapa572/fast"
14
15
  },
15
- "homepage": "https://github.com/sachinthapa572/fast-speed",
16
+ "homepage": "https://github.com/sachinthapa572/fast",
17
+ "bugs": "https://github.com/sachinthapa572/fast/issues",
16
18
  "license": "MIT",
17
19
  "keywords": [
18
20
  "cli",
@@ -21,5 +23,25 @@
21
23
  "netflix",
22
24
  "internet-speed",
23
25
  "bandwidth"
24
- ]
26
+ ],
27
+ "engines": {
28
+ "node": ">=18"
29
+ },
30
+ "os": [
31
+ "linux",
32
+ "darwin",
33
+ "win32"
34
+ ],
35
+ "cpu": [
36
+ "x64",
37
+ "arm64"
38
+ ],
39
+ "optionalDependencies": {
40
+ "@sachinthapa572/fast-darwin-arm64": "0.1.8-rc",
41
+ "@sachinthapa572/fast-darwin-x64": "0.1.8-rc",
42
+ "@sachinthapa572/fast-linux-arm64": "0.1.8-rc",
43
+ "@sachinthapa572/fast-linux-x64": "0.1.8-rc",
44
+ "@sachinthapa572/fast-win32-arm64": "0.1.8-rc",
45
+ "@sachinthapa572/fast-win32-x64": "0.1.8-rc"
46
+ }
25
47
  }
package/download.js DELETED
@@ -1,150 +0,0 @@
1
- const { execSync } = require("child_process");
2
- const {
3
- createWriteStream,
4
- existsSync,
5
- mkdirSync,
6
- readdirSync,
7
- openSync,
8
- readSync,
9
- closeSync,
10
- } = require("fs");
11
- const { chmod, unlink } = require("fs").promises;
12
- const { join } = require("path");
13
- const { platform, arch } = require("os");
14
- const https = require("https");
15
- const http = require("http");
16
-
17
- const pkg = require("./package.json");
18
- const BIN_DIR = join(__dirname, "bin");
19
- const BINARY_NAME = process.platform === "win32" ? "fast.exe" : "fast";
20
- const BINARY_PATH = join(BIN_DIR, BINARY_NAME);
21
-
22
- const OS_MAP = { win32: "Windows", darwin: "Darwin", linux: "Linux" };
23
- const ARCH_MAP = { x64: "x86_64", arm64: "aarch64" };
24
- const EXT_MAP = { win32: ".zip", darwin: ".tar.gz", linux: ".tar.gz" };
25
-
26
- const GH_OWNER = "sachinthapa572";
27
- const GH_REPO = "fast-release";
28
- const DOWNLOAD_BASE =
29
- process.env.FAST_DOWNLOAD_URL ||
30
- `https://github.com/${GH_OWNER}/${GH_REPO}/releases/download`;
31
-
32
- function downloadUrl() {
33
- const os = OS_MAP[platform()];
34
- const cpu = ARCH_MAP[arch()];
35
- const ext = EXT_MAP[platform()];
36
-
37
- if (!os || !cpu) {
38
- throw new Error(`Unsupported platform: ${platform()}/${arch()}`);
39
- }
40
-
41
- return `${DOWNLOAD_BASE}/v${pkg.version}/fast_${os}_${cpu}${ext}`;
42
- }
43
-
44
- function download(url, dest) {
45
- return new Promise((resolve, reject) => {
46
- const mod = url.startsWith("https") ? https : http;
47
- mod
48
- .get(url, (res) => {
49
- if (
50
- res.statusCode >= 300 &&
51
- res.statusCode < 400 &&
52
- res.headers.location
53
- ) {
54
- download(res.headers.location, dest).then(resolve).catch(reject);
55
- return;
56
- }
57
- if (res.statusCode !== 200) {
58
- reject(
59
- new Error(`Download failed: HTTP ${res.statusCode} for ${url}`),
60
- );
61
- return;
62
- }
63
- const file = createWriteStream(dest);
64
- res.pipe(file);
65
- file.on("finish", () => file.close(resolve));
66
- file.on("error", reject);
67
- })
68
- .on("error", reject);
69
- });
70
- }
71
-
72
- function extractArchive(src, dest, binaryName) {
73
- if (process.platform === "win32") {
74
- execSync(
75
- `powershell -NoProfile -Command "Expand-Archive -Path '${src}' -DestinationPath '${dest}' -Force"`,
76
- { stdio: "ignore" },
77
- );
78
- // PowerShell puts files in a subfolder named after the archive
79
- const subdirs = readdirSync(dest).filter((f) => f !== binaryName);
80
- for (const dir of subdirs) {
81
- const subpath = join(dest, dir);
82
- if (existsSync(subpath) && existsSync(join(subpath, binaryName))) {
83
- execSync(
84
- `move "${join(subpath, binaryName)}" "${join(dest, binaryName)}"`,
85
- { stdio: "ignore" },
86
- );
87
- execSync(`rmdir /s /q "${subpath}"`, { stdio: "ignore" });
88
- }
89
- }
90
- return;
91
- }
92
-
93
- // Extract to a temp dir so we can find the binary regardless of wrapping
94
- const tmpDir = join(dest, `._extract_${Date.now()}`);
95
- mkdirSync(tmpDir, { recursive: true });
96
-
97
- try {
98
- execSync(`tar xzf "${src}" -C "${tmpDir}"`, { stdio: "ignore" });
99
-
100
- // Find the binary anywhere in the extracted tree
101
- const result = execSync(`find "${tmpDir}" -type f -name "${binaryName}"`, {
102
- encoding: "utf8",
103
- timeout: 5000,
104
- }).trim();
105
-
106
- if (!result) {
107
- throw new Error(`Binary "${binaryName}" not found in archive`);
108
- }
109
-
110
- const found = result.split("\n")[0];
111
- execSync(`mv "${found}" "${join(dest, binaryName)}"`, { stdio: "ignore" });
112
- } finally {
113
- execSync(`rm -rf "${tmpDir}"`, { stdio: "ignore" });
114
- }
115
- }
116
-
117
- async function ensureBinary() {
118
- if (existsSync(BINARY_PATH)) return;
119
-
120
- if (!existsSync(BIN_DIR)) mkdirSync(BIN_DIR, { recursive: true });
121
-
122
- const url = downloadUrl();
123
- const ext = EXT_MAP[platform()];
124
- const tmpArchive = join(BIN_DIR, `download${ext}`);
125
-
126
- console.error(`Downloading fast v${pkg.version}...`);
127
- await download(url, tmpArchive);
128
-
129
- // Quick sanity check: make sure it's actually a gzip, not an HTML error page
130
- const header = Buffer.alloc(2);
131
- const fd = openSync(tmpArchive, "r");
132
- readSync(fd, header, 0, 2, 0);
133
- closeSync(fd);
134
- if (header[0] !== 0x1f || header[1] !== 0x8b) {
135
- await unlink(tmpArchive);
136
- throw new Error(
137
- `Downloaded file is not a valid gzip archive (got 0x${header.toString("hex")}). Release v${pkg.version} may not exist yet.`,
138
- );
139
- }
140
-
141
- console.error("Extracting...");
142
- extractArchive(tmpArchive, BIN_DIR, BINARY_NAME);
143
- await unlink(tmpArchive);
144
-
145
- if (process.platform !== "win32") {
146
- await chmod(BINARY_PATH, 0o755);
147
- }
148
- }
149
-
150
- module.exports = { ensureBinary, BINARY_PATH };
package/install.js DELETED
@@ -1,14 +0,0 @@
1
- #!/usr/bin/env node
2
- const { ensureBinary } = require("./download");
3
-
4
- ensureBinary()
5
- .then(() => console.log("fast installed successfully."))
6
- .catch((err) => {
7
- console.error("Failed to install fast binary:", err.message);
8
- process.exit(1);
9
- });
10
-
11
- install().catch((err) => {
12
- console.error("Failed to install fast binary:", err.message);
13
- process.exit(1);
14
- });
package/uninstall.js DELETED
@@ -1,10 +0,0 @@
1
- #!/usr/bin/env node
2
- const { existsSync, rmSync } = require("fs");
3
- const { join } = require("path");
4
-
5
- const BIN_DIR = join(__dirname, "bin");
6
-
7
- if (existsSync(BIN_DIR)) {
8
- rmSync(BIN_DIR, { recursive: true, force: true });
9
- console.log("Removed fast binary.");
10
- }