@symbiosis-lab/moss 0.11.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/LICENSE +21 -0
- package/README.md +61 -0
- package/bin/moss.js +42 -0
- package/install.js +15 -0
- package/lib/fetch.js +98 -0
- package/package.json +51 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Symbiosis Lab
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
# @symbiosis-lab/moss
|
|
2
|
+
|
|
3
|
+
moss on your PATH. This package downloads the official [moss](https://@symbiosis-lab/moss.com)
|
|
4
|
+
CLI binary from [moss-releases](https://github.com/Symbiosis-Lab/moss-releases)
|
|
5
|
+
and exposes it as the `moss` command.
|
|
6
|
+
|
|
7
|
+
> **Publishing note:** the package is currently marked `"private": true` in
|
|
8
|
+
> `package.json` so it cannot ship by accident. Flip that (remove the field)
|
|
9
|
+
> at publish time — `publishConfig` is already set up.
|
|
10
|
+
|
|
11
|
+
## Install
|
|
12
|
+
|
|
13
|
+
```sh
|
|
14
|
+
npm install -g @symbiosis-lab/moss
|
|
15
|
+
moss --version
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
The binary is fetched at install time (postinstall). With `--ignore-scripts`,
|
|
19
|
+
or if the download failed (e.g. offline), the first `moss` invocation fetches
|
|
20
|
+
it lazily instead.
|
|
21
|
+
|
|
22
|
+
Supported platforms: macOS (Intel and Apple Silicon, one universal binary)
|
|
23
|
+
and Linux x86_64.
|
|
24
|
+
|
|
25
|
+
## Use
|
|
26
|
+
|
|
27
|
+
```sh
|
|
28
|
+
moss build ~/Sites/my-site
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
All arguments pass straight through to the moss binary; see `moss --help`.
|
|
32
|
+
|
|
33
|
+
## Linux runtime dependency (temporary)
|
|
34
|
+
|
|
35
|
+
The current Linux binary links against WebKitGTK even for headless CLI verbs.
|
|
36
|
+
If `moss` fails with `error while loading shared libraries`, install:
|
|
37
|
+
|
|
38
|
+
```sh
|
|
39
|
+
sudo apt install libwebkit2gtk-4.1-0
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
This requirement is temporary — a moss CLI build without the WebKitGTK
|
|
43
|
+
linkage is planned.
|
|
44
|
+
|
|
45
|
+
## Checksums
|
|
46
|
+
|
|
47
|
+
Downloads are verified against the `SHA256SUMS` file published with each
|
|
48
|
+
release. Releases that predate checksum publishing install with a warning
|
|
49
|
+
instead of verification.
|
|
50
|
+
|
|
51
|
+
## Versioning and overrides
|
|
52
|
+
|
|
53
|
+
The wrapper downloads the moss version matching its own package version;
|
|
54
|
+
they are released in lockstep. `MOSS_VERSION_OVERRIDE=v0.11.1` forces a
|
|
55
|
+
specific release (ops/testing escape hatch).
|
|
56
|
+
|
|
57
|
+
## License
|
|
58
|
+
|
|
59
|
+
The wrapper code in this package is MIT (see LICENSE). The moss binary it
|
|
60
|
+
downloads is a separate work, distributed under its own terms via
|
|
61
|
+
[moss-releases](https://github.com/Symbiosis-Lab/moss-releases).
|
package/bin/moss.js
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// Shim: run the vendored moss binary, downloading it first if it isn't
|
|
3
|
+
// there yet (covers `npm install --ignore-scripts` and a postinstall that
|
|
4
|
+
// failed offline).
|
|
5
|
+
|
|
6
|
+
'use strict';
|
|
7
|
+
|
|
8
|
+
const fs = require('node:fs');
|
|
9
|
+
const { spawnSync } = require('node:child_process');
|
|
10
|
+
const { fetchBinary, vendorBinary } = require('../lib/fetch.js');
|
|
11
|
+
|
|
12
|
+
async function main() {
|
|
13
|
+
if (!fs.existsSync(vendorBinary)) {
|
|
14
|
+
await fetchBinary();
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
// stderr is piped so a loader failure can be recognized, then replayed
|
|
18
|
+
// verbatim. stdin/stdout stay inherited for interactive use.
|
|
19
|
+
const result = spawnSync(vendorBinary, process.argv.slice(2), {
|
|
20
|
+
stdio: ['inherit', 'inherit', 'pipe'],
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
const stderr = result.stderr ? result.stderr.toString() : '';
|
|
24
|
+
if (stderr) process.stderr.write(stderr);
|
|
25
|
+
|
|
26
|
+
if (result.error) throw result.error;
|
|
27
|
+
|
|
28
|
+
if (stderr.includes('error while loading shared libraries')) {
|
|
29
|
+
console.error(
|
|
30
|
+
'\nmoss-npm: the moss binary currently needs the WebKitGTK runtime libraries:\n' +
|
|
31
|
+
' sudo apt install libwebkit2gtk-4.1-0\n' +
|
|
32
|
+
'This is temporary — a moss CLI build without that linkage is planned.'
|
|
33
|
+
);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
process.exit(result.status === null ? 1 : result.status);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
main().catch((err) => {
|
|
40
|
+
console.error(err.message || err);
|
|
41
|
+
process.exit(1);
|
|
42
|
+
});
|
package/install.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
// postinstall: download the moss binary for this platform.
|
|
2
|
+
//
|
|
3
|
+
// Never fails the npm install — an offline machine or a proxy hiccup should
|
|
4
|
+
// not break an unrelated `npm install`. The bin shim (bin/moss.js) retries
|
|
5
|
+
// the download lazily on first run, so exiting 0 here loses nothing.
|
|
6
|
+
|
|
7
|
+
'use strict';
|
|
8
|
+
|
|
9
|
+
const { fetchBinary } = require('./lib/fetch.js');
|
|
10
|
+
|
|
11
|
+
fetchBinary().catch((err) => {
|
|
12
|
+
console.warn(`\nmoss-npm: could not download the moss binary now:\n ${err.message}`);
|
|
13
|
+
console.warn('moss-npm: will retry automatically the first time you run `moss`.\n');
|
|
14
|
+
process.exit(0);
|
|
15
|
+
});
|
package/lib/fetch.js
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
// Downloads the moss CLI binary for this platform from moss-releases.
|
|
2
|
+
//
|
|
3
|
+
// No dependencies: uses the global fetch that ships with Node >= 18.
|
|
4
|
+
// The version defaults to this package's own version (the wrapper is
|
|
5
|
+
// released in lockstep with moss), overridable with MOSS_VERSION_OVERRIDE
|
|
6
|
+
// for ops and testing.
|
|
7
|
+
|
|
8
|
+
'use strict';
|
|
9
|
+
|
|
10
|
+
const crypto = require('node:crypto');
|
|
11
|
+
const fs = require('node:fs');
|
|
12
|
+
const path = require('node:path');
|
|
13
|
+
|
|
14
|
+
const RELEASES = 'https://github.com/Symbiosis-Lab/moss-releases/releases/download';
|
|
15
|
+
|
|
16
|
+
const packageRoot = path.join(__dirname, '..');
|
|
17
|
+
const vendorBinary = path.join(packageRoot, 'vendor', 'moss');
|
|
18
|
+
|
|
19
|
+
function resolveVersion() {
|
|
20
|
+
const override = process.env.MOSS_VERSION_OVERRIDE;
|
|
21
|
+
if (override) return override.replace(/^v/, '');
|
|
22
|
+
return require(path.join(packageRoot, 'package.json')).version;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// Platform → release asset. The darwin binary is a universal (x64 + arm64)
|
|
26
|
+
// build, so both Mac architectures map to the same asset.
|
|
27
|
+
function resolveAsset() {
|
|
28
|
+
const { platform, arch } = process;
|
|
29
|
+
if (platform === 'darwin' && (arch === 'x64' || arch === 'arm64')) {
|
|
30
|
+
return 'moss-darwin-universal';
|
|
31
|
+
}
|
|
32
|
+
if (platform === 'linux' && arch === 'x64') {
|
|
33
|
+
return 'moss-linux-x86_64';
|
|
34
|
+
}
|
|
35
|
+
throw new Error(
|
|
36
|
+
`moss-npm: no moss binary is published for ${platform}-${arch}.\n` +
|
|
37
|
+
'Supported: macOS (x64/arm64) and Linux (x64). ' +
|
|
38
|
+
'See https://github.com/Symbiosis-Lab/moss-releases for available builds.'
|
|
39
|
+
);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
async function download(url) {
|
|
43
|
+
const res = await fetch(url, { redirect: 'follow' });
|
|
44
|
+
if (!res.ok) {
|
|
45
|
+
throw new Error(`moss-npm: download failed (${res.status} ${res.statusText}): ${url}`);
|
|
46
|
+
}
|
|
47
|
+
return Buffer.from(await res.arrayBuffer());
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// Verifies bytes against the release's SHA256SUMS. Releases before v0.11.2
|
|
51
|
+
// published no checksums; a missing SHA256SUMS is a warning, not a failure.
|
|
52
|
+
async function verifyChecksum(bytes, asset, version) {
|
|
53
|
+
let sums;
|
|
54
|
+
try {
|
|
55
|
+
const res = await fetch(`${RELEASES}/v${version}/SHA256SUMS`, { redirect: 'follow' });
|
|
56
|
+
if (!res.ok) {
|
|
57
|
+
console.warn(`moss-npm: no SHA256SUMS published for v${version}; skipping checksum verification`);
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
sums = await res.text();
|
|
61
|
+
} catch (err) {
|
|
62
|
+
console.warn(`moss-npm: could not fetch SHA256SUMS (${err.message}); skipping checksum verification`);
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
const line = sums.split('\n').find((l) => l.trim().endsWith(asset));
|
|
67
|
+
if (!line) {
|
|
68
|
+
console.warn(`moss-npm: SHA256SUMS has no entry for ${asset}; skipping checksum verification`);
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
const expected = line.trim().split(/\s+/)[0];
|
|
73
|
+
const actual = crypto.createHash('sha256').update(bytes).digest('hex');
|
|
74
|
+
if (actual !== expected) {
|
|
75
|
+
throw new Error(
|
|
76
|
+
`moss-npm: checksum mismatch for ${asset} v${version}\n` +
|
|
77
|
+
` expected ${expected}\n got ${actual}\n` +
|
|
78
|
+
'The download may be corrupted or tampered with. Not installing.'
|
|
79
|
+
);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
async function fetchBinary() {
|
|
84
|
+
const version = resolveVersion();
|
|
85
|
+
const asset = resolveAsset();
|
|
86
|
+
const url = `${RELEASES}/v${version}/${asset}`;
|
|
87
|
+
|
|
88
|
+
console.log(`moss-npm: downloading moss v${version} (${asset})...`);
|
|
89
|
+
const bytes = await download(url);
|
|
90
|
+
await verifyChecksum(bytes, asset, version);
|
|
91
|
+
|
|
92
|
+
fs.mkdirSync(path.dirname(vendorBinary), { recursive: true });
|
|
93
|
+
fs.writeFileSync(vendorBinary, bytes, { mode: 0o755 });
|
|
94
|
+
console.log(`moss-npm: installed ${vendorBinary}`);
|
|
95
|
+
return vendorBinary;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
module.exports = { fetchBinary, vendorBinary, resolveAsset, resolveVersion };
|
package/package.json
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@symbiosis-lab/moss",
|
|
3
|
+
"version": "0.11.1",
|
|
4
|
+
"description": "moss on your PATH \u2014 npm wrapper that installs the moss CLI binary from moss-releases",
|
|
5
|
+
"bin": {
|
|
6
|
+
"moss": "bin/moss.js"
|
|
7
|
+
},
|
|
8
|
+
"scripts": {
|
|
9
|
+
"postinstall": "node install.js",
|
|
10
|
+
"test:smoke": "node bin/moss.js --version"
|
|
11
|
+
},
|
|
12
|
+
"files": [
|
|
13
|
+
"bin",
|
|
14
|
+
"lib",
|
|
15
|
+
"install.js",
|
|
16
|
+
"README.md",
|
|
17
|
+
"LICENSE"
|
|
18
|
+
],
|
|
19
|
+
"engines": {
|
|
20
|
+
"node": ">=18.0.0"
|
|
21
|
+
},
|
|
22
|
+
"os": [
|
|
23
|
+
"darwin",
|
|
24
|
+
"linux"
|
|
25
|
+
],
|
|
26
|
+
"cpu": [
|
|
27
|
+
"x64",
|
|
28
|
+
"arm64"
|
|
29
|
+
],
|
|
30
|
+
"keywords": [
|
|
31
|
+
"moss",
|
|
32
|
+
"publishing",
|
|
33
|
+
"static-site",
|
|
34
|
+
"cli"
|
|
35
|
+
],
|
|
36
|
+
"author": "Guo Liu",
|
|
37
|
+
"license": "MIT",
|
|
38
|
+
"repository": {
|
|
39
|
+
"type": "git",
|
|
40
|
+
"url": "git+https://github.com/Symbiosis-Lab/moss-releases.git"
|
|
41
|
+
},
|
|
42
|
+
"bugs": {
|
|
43
|
+
"url": "https://github.com/Symbiosis-Lab/moss-releases/issues"
|
|
44
|
+
},
|
|
45
|
+
"homepage": "https://mosspub.com",
|
|
46
|
+
"publishConfig": {
|
|
47
|
+
"access": "public",
|
|
48
|
+
"registry": "https://registry.npmjs.org/",
|
|
49
|
+
"provenance": false
|
|
50
|
+
}
|
|
51
|
+
}
|