slugsocial 0.0.44 → 0.0.46
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 +28 -14
- package/package.json +5 -5
- package/scripts/ensure-platform.js +42 -15
package/bin/slugsocial.js
CHANGED
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
const fs = require("node:fs");
|
|
8
8
|
const path = require("node:path");
|
|
9
9
|
const childProcess = require("node:child_process");
|
|
10
|
+
const { ensurePlatformInstalled } = require("../scripts/ensure-platform.js");
|
|
10
11
|
|
|
11
12
|
function die(msg) {
|
|
12
13
|
console.error(msg);
|
|
@@ -30,21 +31,34 @@ function resolvePlatformPackage() {
|
|
|
30
31
|
const { plat, arch } = platformTriple();
|
|
31
32
|
const name = `@sortersocial/slugsocial-${plat}-${arch}`;
|
|
32
33
|
const pkgRoot = path.join(__dirname, "..");
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
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",
|
|
49
|
+
);
|
|
50
|
+
if (fs.existsSync(sibling)) {
|
|
51
|
+
return path.dirname(sibling);
|
|
52
|
+
}
|
|
53
|
+
return null;
|
|
38
54
|
}
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
if (fs.existsSync(sibling)) {
|
|
47
|
-
return path.dirname(sibling);
|
|
55
|
+
let dir = tryResolve();
|
|
56
|
+
if (!dir) {
|
|
57
|
+
ensurePlatformInstalled(pkgRoot);
|
|
58
|
+
dir = tryResolve();
|
|
59
|
+
}
|
|
60
|
+
if (dir) {
|
|
61
|
+
return dir;
|
|
48
62
|
}
|
|
49
63
|
die(
|
|
50
64
|
[
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "slugsocial",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.46",
|
|
4
4
|
"description": "Slug Social CLI shim (execs bundled Rust slugsocial) — npx-friendly",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -20,10 +20,10 @@
|
|
|
20
20
|
"package.json"
|
|
21
21
|
],
|
|
22
22
|
"optionalDependencies": {
|
|
23
|
-
"@sortersocial/slugsocial-darwin-arm64": "0.0.
|
|
24
|
-
"@sortersocial/slugsocial-darwin-x64": "0.0.
|
|
25
|
-
"@sortersocial/slugsocial-linux-arm64": "0.0.
|
|
26
|
-
"@sortersocial/slugsocial-linux-x64": "0.0.
|
|
23
|
+
"@sortersocial/slugsocial-darwin-arm64": "0.0.46",
|
|
24
|
+
"@sortersocial/slugsocial-darwin-x64": "0.0.46",
|
|
25
|
+
"@sortersocial/slugsocial-linux-arm64": "0.0.46",
|
|
26
|
+
"@sortersocial/slugsocial-linux-x64": "0.0.46"
|
|
27
27
|
},
|
|
28
28
|
"engines": {
|
|
29
29
|
"node": ">=18"
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/**
|
|
3
|
-
* npm/npx sometimes skip optionalDependencies (
|
|
4
|
-
*
|
|
5
|
-
*
|
|
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
6
|
*/
|
|
7
7
|
const fs = require("fs");
|
|
8
8
|
const path = require("path");
|
|
@@ -20,28 +20,33 @@ function platformPkgName() {
|
|
|
20
20
|
return `@sortersocial/slugsocial-${plat}-${arch}`;
|
|
21
21
|
}
|
|
22
22
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
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) {
|
|
27
28
|
const name = platformPkgName();
|
|
28
29
|
if (!name) {
|
|
29
|
-
return;
|
|
30
|
+
return false;
|
|
30
31
|
}
|
|
31
32
|
try {
|
|
32
33
|
require.resolve(`${name}/package.json`, { paths: [pkgRoot] });
|
|
33
|
-
return;
|
|
34
|
+
return true;
|
|
34
35
|
} catch (_) {
|
|
35
|
-
/*
|
|
36
|
+
/* continue */
|
|
36
37
|
}
|
|
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"));
|
|
38
44
|
const version = pkg.version;
|
|
39
45
|
if (!version) {
|
|
40
|
-
return;
|
|
46
|
+
return false;
|
|
41
47
|
}
|
|
42
48
|
|
|
43
49
|
const nm = path.join(pkgRoot, "..");
|
|
44
|
-
// Parent of node_modules (works for npx cache and normal installs).
|
|
45
50
|
const installRoot = path.dirname(nm);
|
|
46
51
|
const npm = process.platform === "win32" ? "npm.cmd" : "npm";
|
|
47
52
|
const args = [
|
|
@@ -49,6 +54,7 @@ function main() {
|
|
|
49
54
|
"--no-fund",
|
|
50
55
|
"--no-audit",
|
|
51
56
|
"--no-package-lock",
|
|
57
|
+
"--prefer-online",
|
|
52
58
|
"--include=optional",
|
|
53
59
|
"--prefix",
|
|
54
60
|
installRoot,
|
|
@@ -59,11 +65,32 @@ function main() {
|
|
|
59
65
|
env: process.env,
|
|
60
66
|
});
|
|
61
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
|
+
);
|
|
62
85
|
console.warn(
|
|
63
|
-
`slugsocial: postinstall could not install ${name}@${version}
|
|
64
|
-
`
|
|
86
|
+
`slugsocial: postinstall could not install ${name}@${pkg.version}. ` +
|
|
87
|
+
`The CLI will retry on first run.`,
|
|
65
88
|
);
|
|
66
89
|
}
|
|
67
90
|
}
|
|
68
91
|
|
|
69
|
-
main
|
|
92
|
+
if (require.main === module) {
|
|
93
|
+
main();
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
module.exports = { ensurePlatformInstalled, platformPkgName };
|