@symbiosis-lab/moss 0.11.1 → 0.11.5
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 +18 -0
- package/bin/moss.js +13 -3
- package/install.js +13 -4
- package/lib/fetch.js +53 -1
- package/package.json +3 -2
package/README.md
CHANGED
|
@@ -54,6 +54,24 @@ The wrapper downloads the moss version matching its own package version;
|
|
|
54
54
|
they are released in lockstep. `MOSS_VERSION_OVERRIDE=v0.11.1` forces a
|
|
55
55
|
specific release (ops/testing escape hatch).
|
|
56
56
|
|
|
57
|
+
## Controlling the download
|
|
58
|
+
|
|
59
|
+
| Variable | Effect |
|
|
60
|
+
|---|---|
|
|
61
|
+
| `MOSS_SKIP_BINARY_DOWNLOAD=1` | Install the wrapper without fetching a binary. `moss` then fetches it on first run. |
|
|
62
|
+
| `MOSS_BINARY_PATH=/path/to/moss` | Run that binary instead of the vendored one, and skip the download entirely. |
|
|
63
|
+
| `MOSS_FORCE_BINARY_DOWNLOAD=1` | Download even where the wrapper would otherwise skip. |
|
|
64
|
+
|
|
65
|
+
Each also reads from `.npmrc` under its lowercased name (`moss_skip_binary_download=true`),
|
|
66
|
+
because npm passes config keys to lifecycle scripts as `npm_config_*`.
|
|
67
|
+
|
|
68
|
+
**Inside the moss repo the download is skipped automatically.** A checkout is
|
|
69
|
+
not an install: `packages/moss` sits in the workspace rather than under
|
|
70
|
+
`node_modules`, so `pnpm install` at the repo root would otherwise pull a
|
|
71
|
+
release binary that no moss developer wants — they build from source. Point
|
|
72
|
+
`MOSS_BINARY_PATH` at `src-tauri/target/release/moss` to exercise the wrapper
|
|
73
|
+
against your own build.
|
|
74
|
+
|
|
57
75
|
## License
|
|
58
76
|
|
|
59
77
|
The wrapper code in this package is MIT (see LICENSE). The moss binary it
|
package/bin/moss.js
CHANGED
|
@@ -7,16 +7,26 @@
|
|
|
7
7
|
|
|
8
8
|
const fs = require('node:fs');
|
|
9
9
|
const { spawnSync } = require('node:child_process');
|
|
10
|
-
const { fetchBinary,
|
|
10
|
+
const { fetchBinary, resolveBinary } = require('../lib/fetch.js');
|
|
11
11
|
|
|
12
12
|
async function main() {
|
|
13
|
-
|
|
13
|
+
const binary = resolveBinary();
|
|
14
|
+
|
|
15
|
+
if (!fs.existsSync(binary)) {
|
|
16
|
+
// An explicit MOSS_BINARY_PATH that isn't there is a mistake to report,
|
|
17
|
+
// not a cue to download a release binary over the top of the developer's
|
|
18
|
+
// intent.
|
|
19
|
+
if (process.env.MOSS_BINARY_PATH) {
|
|
20
|
+
throw new Error(
|
|
21
|
+
`moss-npm: MOSS_BINARY_PATH is set to ${binary}, but no file is there.`
|
|
22
|
+
);
|
|
23
|
+
}
|
|
14
24
|
await fetchBinary();
|
|
15
25
|
}
|
|
16
26
|
|
|
17
27
|
// stderr is piped so a loader failure can be recognized, then replayed
|
|
18
28
|
// verbatim. stdin/stdout stay inherited for interactive use.
|
|
19
|
-
const result = spawnSync(
|
|
29
|
+
const result = spawnSync(binary, process.argv.slice(2), {
|
|
20
30
|
stdio: ['inherit', 'inherit', 'pipe'],
|
|
21
31
|
});
|
|
22
32
|
|
package/install.js
CHANGED
|
@@ -1,12 +1,21 @@
|
|
|
1
1
|
// postinstall: download the moss binary for this platform.
|
|
2
2
|
//
|
|
3
|
-
//
|
|
4
|
-
// not break an unrelated `npm install
|
|
5
|
-
// the download lazily on first run, so
|
|
3
|
+
// Two things it will not do. It never fails the npm install — an offline
|
|
4
|
+
// machine or a proxy hiccup should not break an unrelated `npm install`, and
|
|
5
|
+
// the bin shim (bin/moss.js) retries the download lazily on first run, so
|
|
6
|
+
// exiting 0 here loses nothing. And it does not download at all when nobody
|
|
7
|
+
// asked for a release binary: inside the moss repo itself, or when the
|
|
8
|
+
// developer has pointed MOSS_BINARY_PATH at their own build.
|
|
6
9
|
|
|
7
10
|
'use strict';
|
|
8
11
|
|
|
9
|
-
const { fetchBinary } = require('./lib/fetch.js');
|
|
12
|
+
const { fetchBinary, skipDownloadReason } = require('./lib/fetch.js');
|
|
13
|
+
|
|
14
|
+
const skip = skipDownloadReason();
|
|
15
|
+
if (skip) {
|
|
16
|
+
console.log(`moss-npm: skipping the binary download — ${skip}.`);
|
|
17
|
+
process.exit(0);
|
|
18
|
+
}
|
|
10
19
|
|
|
11
20
|
fetchBinary().catch((err) => {
|
|
12
21
|
console.warn(`\nmoss-npm: could not download the moss binary now:\n ${err.message}`);
|
package/lib/fetch.js
CHANGED
|
@@ -16,6 +16,51 @@ const RELEASES = 'https://github.com/Symbiosis-Lab/moss-releases/releases/downlo
|
|
|
16
16
|
const packageRoot = path.join(__dirname, '..');
|
|
17
17
|
const vendorBinary = path.join(packageRoot, 'vendor', 'moss');
|
|
18
18
|
|
|
19
|
+
// npm and pnpm expose every `.npmrc` key to lifecycle scripts as `npm_config_<key>`,
|
|
20
|
+
// so one lookup covers both the environment variable and the config file. This is
|
|
21
|
+
// the mechanism Cypress documents for `CYPRESS_INSTALL_BINARY` and puppeteer for
|
|
22
|
+
// `PUPPETEER_SKIP_DOWNLOAD`.
|
|
23
|
+
function flag(name) {
|
|
24
|
+
const value =
|
|
25
|
+
process.env[name] ?? process.env[`npm_config_${name.toLowerCase()}`];
|
|
26
|
+
if (value === undefined || value === '') return false;
|
|
27
|
+
return !/^(0|false|no)$/i.test(value);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// True when this copy of the package was installed as somebody's dependency.
|
|
31
|
+
// Every package manager unpacks a published tarball into a directory with a
|
|
32
|
+
// `node_modules` segment in its path — npm and pnpm's store both, and Yarn PnP's
|
|
33
|
+
// unplugged cache. A checkout of the moss repo has no such segment, so the
|
|
34
|
+
// absence of one means we are running from source, not from an install.
|
|
35
|
+
function isInstalledAsDependency() {
|
|
36
|
+
return packageRoot.split(path.sep).includes('node_modules');
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Why the postinstall download should not run, or null to go ahead.
|
|
41
|
+
*
|
|
42
|
+
* Returns a reason suitable for printing — the caller decides whether that is
|
|
43
|
+
* a log line or an error.
|
|
44
|
+
*/
|
|
45
|
+
function skipDownloadReason() {
|
|
46
|
+
if (flag('MOSS_FORCE_BINARY_DOWNLOAD')) return null;
|
|
47
|
+
if (flag('MOSS_SKIP_BINARY_DOWNLOAD')) return 'MOSS_SKIP_BINARY_DOWNLOAD is set';
|
|
48
|
+
if (process.env.MOSS_BINARY_PATH) {
|
|
49
|
+
return `MOSS_BINARY_PATH points at ${process.env.MOSS_BINARY_PATH}`;
|
|
50
|
+
}
|
|
51
|
+
if (!isInstalledAsDependency()) {
|
|
52
|
+
return 'running from a source checkout, not an install — build moss yourself, ' +
|
|
53
|
+
'or set MOSS_FORCE_BINARY_DOWNLOAD=1 to fetch the release binary anyway';
|
|
54
|
+
}
|
|
55
|
+
return null;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// Which binary `moss` should execute. `MOSS_BINARY_PATH` wins so a developer can
|
|
59
|
+
// point the wrapper at a locally built moss (esbuild's `ESBUILD_BINARY_PATH`).
|
|
60
|
+
function resolveBinary() {
|
|
61
|
+
return process.env.MOSS_BINARY_PATH || vendorBinary;
|
|
62
|
+
}
|
|
63
|
+
|
|
19
64
|
function resolveVersion() {
|
|
20
65
|
const override = process.env.MOSS_VERSION_OVERRIDE;
|
|
21
66
|
if (override) return override.replace(/^v/, '');
|
|
@@ -95,4 +140,11 @@ async function fetchBinary() {
|
|
|
95
140
|
return vendorBinary;
|
|
96
141
|
}
|
|
97
142
|
|
|
98
|
-
module.exports = {
|
|
143
|
+
module.exports = {
|
|
144
|
+
fetchBinary,
|
|
145
|
+
vendorBinary,
|
|
146
|
+
resolveAsset,
|
|
147
|
+
resolveBinary,
|
|
148
|
+
resolveVersion,
|
|
149
|
+
skipDownloadReason,
|
|
150
|
+
};
|
package/package.json
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@symbiosis-lab/moss",
|
|
3
|
-
"version": "0.11.
|
|
4
|
-
"description": "moss on your PATH
|
|
3
|
+
"version": "0.11.5",
|
|
4
|
+
"description": "moss on your PATH — npm wrapper that installs the moss CLI binary from moss-releases",
|
|
5
5
|
"bin": {
|
|
6
6
|
"moss": "bin/moss.js"
|
|
7
7
|
},
|
|
8
8
|
"scripts": {
|
|
9
9
|
"postinstall": "node install.js",
|
|
10
|
+
"test": "node --test test/*.test.js",
|
|
10
11
|
"test:smoke": "node bin/moss.js --version"
|
|
11
12
|
},
|
|
12
13
|
"files": [
|