@fastmoss/cli 0.1.0 → 0.1.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/README.md CHANGED
@@ -4,6 +4,14 @@ FastMoss CLI launcher for npm and npx.
4
4
 
5
5
  This package does not bundle the Go binary itself. On first run it downloads the matching `fastmoss` binary from GitHub Releases, stores it in a local cache directory, and then forwards all CLI arguments to that binary.
6
6
 
7
+ During `npm install`, the package tries to predownload the matching binary for the current platform. If the download fails, installation still completes and the wrapper will retry the download on first run.
8
+
9
+ If your npm configuration blocks lifecycle scripts, allow this package's postinstall script to predownload during install:
10
+
11
+ ```bash
12
+ npm install -g --allow-scripts=@fastmoss/cli @fastmoss/cli
13
+ ```
14
+
7
15
  ## Usage
8
16
 
9
17
  Run without installing:
@@ -49,6 +57,12 @@ You can override the cache directory:
49
57
  FASTMOSS_CACHE_DIR=/custom/cache/dir npx @fastmoss/cli
50
58
  ```
51
59
 
60
+ You can skip the install-time download:
61
+
62
+ ```bash
63
+ FASTMOSS_SKIP_DOWNLOAD=1 npm install -g @fastmoss/cli
64
+ ```
65
+
52
66
  ## Download Source
53
67
 
54
68
  By default the wrapper downloads binaries from the public GitHub release repository configured in `package.json`.
package/bin/fastmoss.js CHANGED
File without changes
@@ -0,0 +1,12 @@
1
+ #!/usr/bin/env node
2
+
3
+ const packageJSON = require("../package.json");
4
+ const { installCLI } = require("../lib/runtime");
5
+
6
+ installCLI({
7
+ version: packageJSON.version,
8
+ configuredDownloadBaseURL: packageJSON.fastmoss?.downloadBaseURL,
9
+ }).catch((error) => {
10
+ process.stderr.write(`fastmoss postinstall warning: ${error.message}\n`);
11
+ process.stderr.write("The binary will be downloaded on first run.\n");
12
+ });
package/lib/runtime.js CHANGED
@@ -104,6 +104,8 @@ async function ensureBinary({
104
104
  arch = process.arch,
105
105
  homeDir = os.homedir(),
106
106
  configuredDownloadBaseURL = "",
107
+ onDownloadStart = () => {},
108
+ downloadFileFn = downloadFile,
107
109
  }) {
108
110
  const target = resolvePlatformTarget({ platform, arch });
109
111
  const cacheRoot = resolveCacheRoot({ env, homeDir });
@@ -122,7 +124,8 @@ async function ensureBinary({
122
124
  });
123
125
  const tempPath = `${binaryPath}.download`;
124
126
 
125
- await downloadFile(downloadURL, tempPath);
127
+ onDownloadStart(downloadURL);
128
+ await downloadFileFn(downloadURL, tempPath);
126
129
 
127
130
  if (platform !== "win32") {
128
131
  await fs.promises.chmod(tempPath, 0o755);
@@ -132,6 +135,40 @@ async function ensureBinary({
132
135
  return { binaryPath, downloaded: true, downloadURL };
133
136
  }
134
137
 
138
+ function shouldSkipDownload(env = process.env) {
139
+ const value = String(env.FASTMOSS_SKIP_DOWNLOAD || "").trim().toLowerCase();
140
+ return value !== "" && value !== "0" && value !== "false";
141
+ }
142
+
143
+ async function installCLI({
144
+ version,
145
+ env = process.env,
146
+ platform = process.platform,
147
+ arch = process.arch,
148
+ homeDir = os.homedir(),
149
+ stderr = process.stderr,
150
+ configuredDownloadBaseURL = "",
151
+ } = {}) {
152
+ if (shouldSkipDownload(env)) {
153
+ stderr.write(
154
+ "Skipping fastmoss binary download because FASTMOSS_SKIP_DOWNLOAD is set.\n",
155
+ );
156
+ return { skipped: true };
157
+ }
158
+
159
+ return ensureBinary({
160
+ version,
161
+ env,
162
+ platform,
163
+ arch,
164
+ homeDir,
165
+ configuredDownloadBaseURL,
166
+ onDownloadStart(downloadURL) {
167
+ stderr.write(`Downloading fastmoss ${version} from ${downloadURL}\n`);
168
+ },
169
+ });
170
+ }
171
+
135
172
  async function fileExists(filePath) {
136
173
  try {
137
174
  const stat = await fs.promises.stat(filePath);
@@ -239,10 +276,13 @@ async function runCLI({
239
276
  arch,
240
277
  homeDir,
241
278
  configuredDownloadBaseURL,
279
+ onDownloadStart(downloadURL) {
280
+ stderr.write(`Downloading fastmoss ${version} from ${downloadURL}\n`);
281
+ },
242
282
  });
243
283
 
244
284
  if (downloaded) {
245
- stderr.write(`Downloading fastmoss ${version} from ${downloadURL}\n`);
285
+ stderr.write(`Downloaded fastmoss ${version} to ${binaryPath}\n`);
246
286
  }
247
287
 
248
288
  await new Promise((resolve, reject) => {
@@ -266,6 +306,7 @@ module.exports = {
266
306
  DEFAULT_DOWNLOAD_BASE_URL,
267
307
  buildDownloadURL,
268
308
  ensureBinary,
309
+ installCLI,
269
310
  resolveBinaryPath,
270
311
  resolveCacheRoot,
271
312
  resolveDownloadBaseURL,
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "@fastmoss/cli",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "FastMoss CLI launcher for npm and npx",
5
5
  "license": "UNLICENSED",
6
6
  "private": false,
7
7
  "bin": {
8
- "fastmoss": "./bin/fastmoss.js"
8
+ "fastmoss": "bin/fastmoss.js"
9
9
  },
10
10
  "files": [
11
11
  "bin",
@@ -13,6 +13,7 @@
13
13
  "README.md"
14
14
  ],
15
15
  "scripts": {
16
+ "postinstall": "node ./bin/postinstall.js",
16
17
  "test": "node --test ./test/*.test.js"
17
18
  },
18
19
  "engines": {