@sachinthapa572/fast 0.1.6-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.6-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,98 +0,0 @@
1
- const { execSync } = require("child_process");
2
- const { createWriteStream, existsSync, mkdirSync } = require("fs");
3
- const { chmod, unlink } = require("fs").promises;
4
- const { join } = require("path");
5
- const { platform, arch } = require("os");
6
- const https = require("https");
7
- const http = require("http");
8
-
9
- const pkg = require("./package.json");
10
- const BIN_DIR = join(__dirname, "bin");
11
- const BINARY_NAME = process.platform === "win32" ? "fast.exe" : "fast";
12
- const BINARY_PATH = join(BIN_DIR, BINARY_NAME);
13
-
14
- const OS_MAP = { win32: "Windows", darwin: "Darwin", linux: "Linux" };
15
- const ARCH_MAP = { x64: "x86_64", arm64: "aarch64" };
16
- const EXT_MAP = { win32: ".zip", darwin: ".tar.gz", linux: ".tar.gz" };
17
-
18
- const GH_OWNER = "sachinthapa572";
19
- const GH_REPO = "fast-release";
20
- const DOWNLOAD_BASE =
21
- process.env.FAST_DOWNLOAD_URL ||
22
- `https://github.com/${GH_OWNER}/${GH_REPO}/releases/download`;
23
-
24
- function downloadUrl() {
25
- const os = OS_MAP[platform()];
26
- const cpu = ARCH_MAP[arch()];
27
- const ext = EXT_MAP[platform()];
28
-
29
- if (!os || !cpu) {
30
- throw new Error(`Unsupported platform: ${platform()}/${arch()}`);
31
- }
32
-
33
- return `${DOWNLOAD_BASE}/v${pkg.version}/fast_${os}_${cpu}${ext}`;
34
- }
35
-
36
- function download(url, dest) {
37
- return new Promise((resolve, reject) => {
38
- const mod = url.startsWith("https") ? https : http;
39
- mod
40
- .get(url, (res) => {
41
- if (
42
- res.statusCode >= 300 &&
43
- res.statusCode < 400 &&
44
- res.headers.location
45
- ) {
46
- download(res.headers.location, dest).then(resolve).catch(reject);
47
- return;
48
- }
49
- if (res.statusCode !== 200) {
50
- reject(
51
- new Error(`Download failed: HTTP ${res.statusCode} for ${url}`),
52
- );
53
- return;
54
- }
55
- const file = createWriteStream(dest);
56
- res.pipe(file);
57
- file.on("finish", () => file.close(resolve));
58
- file.on("error", reject);
59
- })
60
- .on("error", reject);
61
- });
62
- }
63
-
64
- function extractArchive(src, dest) {
65
- if (process.platform === "win32") {
66
- execSync(
67
- `powershell -NoProfile -Command "Expand-Archive -Path '${src}' -DestinationPath '${dest}' -Force"`,
68
- { stdio: "ignore" },
69
- );
70
- return;
71
- }
72
- execSync(`tar xzf "${src}" -C "${dest}" --strip-components 1`, {
73
- stdio: "ignore",
74
- });
75
- }
76
-
77
- async function ensureBinary() {
78
- if (existsSync(BINARY_PATH)) return;
79
-
80
- if (!existsSync(BIN_DIR)) mkdirSync(BIN_DIR, { recursive: true });
81
-
82
- const url = downloadUrl();
83
- const ext = EXT_MAP[platform()];
84
- const tmpArchive = join(BIN_DIR, `download${ext}`);
85
-
86
- console.error(`Downloading fast v${pkg.version}...`);
87
- await download(url, tmpArchive);
88
-
89
- console.error("Extracting...");
90
- extractArchive(tmpArchive, BIN_DIR);
91
- await unlink(tmpArchive);
92
-
93
- if (process.platform !== "win32") {
94
- await chmod(BINARY_PATH, 0o755);
95
- }
96
- }
97
-
98
- 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
- }