slugsocial 0.0.43 → 0.0.45
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/bin/slugsocial.js +41 -18
- package/package.json +9 -5
- package/scripts/ensure-platform.js +96 -0
package/bin/slugsocial.js
CHANGED
|
@@ -1,16 +1,13 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
// Ultra-thin shim: exec the Rust `slugsocial` binary bundled via platform packages.
|
|
3
3
|
//
|
|
4
|
-
//
|
|
5
|
-
//
|
|
6
|
-
// - @sortersocial/slugsocial-darwin-x64
|
|
7
|
-
// - @sortersocial/slugsocial-linux-arm64
|
|
8
|
-
// - @sortersocial/slugsocial-linux-x64
|
|
9
|
-
// - @sortersocial/slugsocial-win32-arm64
|
|
10
|
-
// - @sortersocial/slugsocial-win32-x64
|
|
4
|
+
// Binary comes from optionalDependencies for this platform (darwin/linux × arm64/x64).
|
|
5
|
+
// postinstall also installs the platform package if npm skipped optional deps (npx / omit=optional).
|
|
11
6
|
|
|
7
|
+
const fs = require("node:fs");
|
|
12
8
|
const path = require("node:path");
|
|
13
9
|
const childProcess = require("node:child_process");
|
|
10
|
+
const { ensurePlatformInstalled } = require("../scripts/ensure-platform.js");
|
|
14
11
|
|
|
15
12
|
function die(msg) {
|
|
16
13
|
console.error(msg);
|
|
@@ -21,7 +18,8 @@ function platformTriple() {
|
|
|
21
18
|
const p = process.platform;
|
|
22
19
|
const a = process.arch;
|
|
23
20
|
|
|
24
|
-
|
|
21
|
+
// Package names use darwin/linux only (see optionalDependencies).
|
|
22
|
+
const plat = p === "darwin" ? "darwin" : p === "linux" ? "linux" : null;
|
|
25
23
|
const arch = a === "x64" ? "x64" : a === "arm64" ? "arm64" : null;
|
|
26
24
|
if (!plat || !arch) {
|
|
27
25
|
die(`unsupported platform/arch: ${p}/${a}`);
|
|
@@ -32,18 +30,43 @@ function platformTriple() {
|
|
|
32
30
|
function resolvePlatformPackage() {
|
|
33
31
|
const { plat, arch } = platformTriple();
|
|
34
32
|
const name = `@sortersocial/slugsocial-${plat}-${arch}`;
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
33
|
+
const pkgRoot = path.join(__dirname, "..");
|
|
34
|
+
function tryResolve() {
|
|
35
|
+
try {
|
|
36
|
+
const pkgJson = require.resolve(`${name}/package.json`, {
|
|
37
|
+
paths: [pkgRoot],
|
|
38
|
+
});
|
|
39
|
+
return path.dirname(pkgJson);
|
|
40
|
+
} catch (_) {
|
|
41
|
+
/* continue */
|
|
42
|
+
}
|
|
43
|
+
const sibling = path.join(
|
|
44
|
+
pkgRoot,
|
|
45
|
+
"..",
|
|
46
|
+
"@sortersocial",
|
|
47
|
+
`slugsocial-${plat}-${arch}`,
|
|
48
|
+
"package.json",
|
|
45
49
|
);
|
|
50
|
+
if (fs.existsSync(sibling)) {
|
|
51
|
+
return path.dirname(sibling);
|
|
52
|
+
}
|
|
53
|
+
return null;
|
|
46
54
|
}
|
|
55
|
+
let dir = tryResolve();
|
|
56
|
+
if (!dir) {
|
|
57
|
+
ensurePlatformInstalled(pkgRoot);
|
|
58
|
+
dir = tryResolve();
|
|
59
|
+
}
|
|
60
|
+
if (dir) {
|
|
61
|
+
return dir;
|
|
62
|
+
}
|
|
63
|
+
die(
|
|
64
|
+
[
|
|
65
|
+
`missing platform package ${name}.`,
|
|
66
|
+
`Reinstall with optional deps, e.g. npm install slugsocial --include=optional`,
|
|
67
|
+
`or: npm install ${name}@<same version as slugsocial>`,
|
|
68
|
+
].join("\n"),
|
|
69
|
+
);
|
|
47
70
|
}
|
|
48
71
|
|
|
49
72
|
async function main() {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "slugsocial",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.45",
|
|
4
4
|
"description": "Slug Social CLI shim (execs bundled Rust slugsocial) — npx-friendly",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -10,16 +10,20 @@
|
|
|
10
10
|
"bin": {
|
|
11
11
|
"slugsocial": "bin/slugsocial.js"
|
|
12
12
|
},
|
|
13
|
+
"scripts": {
|
|
14
|
+
"postinstall": "node scripts/ensure-platform.js"
|
|
15
|
+
},
|
|
13
16
|
"files": [
|
|
14
17
|
"bin/slugsocial.js",
|
|
18
|
+
"scripts/ensure-platform.js",
|
|
15
19
|
"README.md",
|
|
16
20
|
"package.json"
|
|
17
21
|
],
|
|
18
22
|
"optionalDependencies": {
|
|
19
|
-
"@sortersocial/slugsocial-darwin-arm64": "0.0.
|
|
20
|
-
"@sortersocial/slugsocial-darwin-x64": "0.0.
|
|
21
|
-
"@sortersocial/slugsocial-linux-arm64": "0.0.
|
|
22
|
-
"@sortersocial/slugsocial-linux-x64": "0.0.
|
|
23
|
+
"@sortersocial/slugsocial-darwin-arm64": "0.0.45",
|
|
24
|
+
"@sortersocial/slugsocial-darwin-x64": "0.0.45",
|
|
25
|
+
"@sortersocial/slugsocial-linux-arm64": "0.0.45",
|
|
26
|
+
"@sortersocial/slugsocial-linux-x64": "0.0.45"
|
|
23
27
|
},
|
|
24
28
|
"engines": {
|
|
25
29
|
"node": ">=18"
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* npm/npx sometimes skip optionalDependencies (omit=optional) or lifecycle scripts
|
|
4
|
+
* (npm exec). We run this from postinstall when possible, and from the bin shim
|
|
5
|
+
* before spawning the native binary so `npx slugsocial` always works.
|
|
6
|
+
*/
|
|
7
|
+
const fs = require("fs");
|
|
8
|
+
const path = require("path");
|
|
9
|
+
const { spawnSync } = require("child_process");
|
|
10
|
+
|
|
11
|
+
function platformPkgName() {
|
|
12
|
+
const p = process.platform;
|
|
13
|
+
const a = process.arch;
|
|
14
|
+
const plat =
|
|
15
|
+
p === "darwin" ? "darwin" : p === "linux" ? "linux" : null;
|
|
16
|
+
const arch = a === "x64" ? "x64" : a === "arm64" ? "arm64" : null;
|
|
17
|
+
if (!plat || !arch) {
|
|
18
|
+
return null;
|
|
19
|
+
}
|
|
20
|
+
return `@sortersocial/slugsocial-${plat}-${arch}`;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* @param {string} pkgRoot absolute path to slugsocial package root (…/node_modules/slugsocial)
|
|
25
|
+
* @returns {boolean} true if the platform package is available after any install attempt
|
|
26
|
+
*/
|
|
27
|
+
function ensurePlatformInstalled(pkgRoot) {
|
|
28
|
+
const name = platformPkgName();
|
|
29
|
+
if (!name) {
|
|
30
|
+
return false;
|
|
31
|
+
}
|
|
32
|
+
try {
|
|
33
|
+
require.resolve(`${name}/package.json`, { paths: [pkgRoot] });
|
|
34
|
+
return true;
|
|
35
|
+
} catch (_) {
|
|
36
|
+
/* continue */
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const pkgJsonPath = path.join(pkgRoot, "package.json");
|
|
40
|
+
if (!fs.existsSync(pkgJsonPath)) {
|
|
41
|
+
return false;
|
|
42
|
+
}
|
|
43
|
+
const pkg = JSON.parse(fs.readFileSync(pkgJsonPath, "utf8"));
|
|
44
|
+
const version = pkg.version;
|
|
45
|
+
if (!version) {
|
|
46
|
+
return false;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const nm = path.join(pkgRoot, "..");
|
|
50
|
+
const installRoot = path.dirname(nm);
|
|
51
|
+
const npm = process.platform === "win32" ? "npm.cmd" : "npm";
|
|
52
|
+
const args = [
|
|
53
|
+
"install",
|
|
54
|
+
"--no-fund",
|
|
55
|
+
"--no-audit",
|
|
56
|
+
"--no-package-lock",
|
|
57
|
+
"--prefer-online",
|
|
58
|
+
"--include=optional",
|
|
59
|
+
"--prefix",
|
|
60
|
+
installRoot,
|
|
61
|
+
`${name}@${version}`,
|
|
62
|
+
];
|
|
63
|
+
const r = spawnSync(npm, args, {
|
|
64
|
+
stdio: "inherit",
|
|
65
|
+
env: process.env,
|
|
66
|
+
});
|
|
67
|
+
if (r.status !== 0) {
|
|
68
|
+
return false;
|
|
69
|
+
}
|
|
70
|
+
try {
|
|
71
|
+
require.resolve(`${name}/package.json`, { paths: [pkgRoot] });
|
|
72
|
+
return true;
|
|
73
|
+
} catch (_) {
|
|
74
|
+
return false;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
function main() {
|
|
79
|
+
const pkgRoot = path.join(__dirname, "..");
|
|
80
|
+
if (!ensurePlatformInstalled(pkgRoot)) {
|
|
81
|
+
const name = platformPkgName();
|
|
82
|
+
const pkg = JSON.parse(
|
|
83
|
+
fs.readFileSync(path.join(pkgRoot, "package.json"), "utf8"),
|
|
84
|
+
);
|
|
85
|
+
console.warn(
|
|
86
|
+
`slugsocial: postinstall could not install ${name}@${pkg.version}. ` +
|
|
87
|
+
`The CLI will retry on first run.`,
|
|
88
|
+
);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
if (require.main === module) {
|
|
93
|
+
main();
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
module.exports = { ensurePlatformInstalled, platformPkgName };
|