slugsocial 0.0.43 → 0.0.44

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 CHANGED
@@ -1,14 +1,10 @@
1
1
  #!/usr/bin/env node
2
2
  // Ultra-thin shim: exec the Rust `slugsocial` binary bundled via platform packages.
3
3
  //
4
- // npm will download exactly one optionalDependency for this platform:
5
- // - @sortersocial/slugsocial-darwin-arm64
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");
14
10
 
@@ -21,7 +17,8 @@ function platformTriple() {
21
17
  const p = process.platform;
22
18
  const a = process.arch;
23
19
 
24
- const plat = p === "darwin" ? "darwin" : p === "linux" ? "linux" : p === "win32" ? "windows" : null;
20
+ // Package names use darwin/linux only (see optionalDependencies).
21
+ const plat = p === "darwin" ? "darwin" : p === "linux" ? "linux" : null;
25
22
  const arch = a === "x64" ? "x64" : a === "arm64" ? "arm64" : null;
26
23
  if (!plat || !arch) {
27
24
  die(`unsupported platform/arch: ${p}/${a}`);
@@ -32,18 +29,30 @@ function platformTriple() {
32
29
  function resolvePlatformPackage() {
33
30
  const { plat, arch } = platformTriple();
34
31
  const name = `@sortersocial/slugsocial-${plat}-${arch}`;
32
+ const pkgRoot = path.join(__dirname, "..");
35
33
  try {
36
- const pkgJson = require.resolve(`${name}/package.json`);
34
+ const pkgJson = require.resolve(`${name}/package.json`, { paths: [pkgRoot] });
37
35
  return path.dirname(pkgJson);
38
- } catch {
39
- die(
40
- [
41
- `missing platform package ${name}.`,
42
- `This usually means npm didn't install optionalDependencies for your platform.`,
43
- `Try: npm_config_optional=true npx slugsocial --help`,
44
- ].join("\n")
45
- );
36
+ } catch (_) {
37
+ /* optionalDependency missing or hoisted oddly */
46
38
  }
39
+ const sibling = path.join(
40
+ pkgRoot,
41
+ "..",
42
+ "@sortersocial",
43
+ `slugsocial-${plat}-${arch}`,
44
+ "package.json",
45
+ );
46
+ if (fs.existsSync(sibling)) {
47
+ return path.dirname(sibling);
48
+ }
49
+ die(
50
+ [
51
+ `missing platform package ${name}.`,
52
+ `Reinstall with optional deps, e.g. npm install slugsocial --include=optional`,
53
+ `or: npm install ${name}@<same version as slugsocial>`,
54
+ ].join("\n"),
55
+ );
47
56
  }
48
57
 
49
58
  async function main() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "slugsocial",
3
- "version": "0.0.43",
3
+ "version": "0.0.44",
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.43",
20
- "@sortersocial/slugsocial-darwin-x64": "0.0.43",
21
- "@sortersocial/slugsocial-linux-arm64": "0.0.43",
22
- "@sortersocial/slugsocial-linux-x64": "0.0.43"
23
+ "@sortersocial/slugsocial-darwin-arm64": "0.0.44",
24
+ "@sortersocial/slugsocial-darwin-x64": "0.0.44",
25
+ "@sortersocial/slugsocial-linux-arm64": "0.0.44",
26
+ "@sortersocial/slugsocial-linux-x64": "0.0.44"
23
27
  },
24
28
  "engines": {
25
29
  "node": ">=18"
@@ -0,0 +1,69 @@
1
+ "use strict";
2
+ /**
3
+ * npm/npx sometimes skip optionalDependencies (e.g. omit=optional, or exec cache).
4
+ * This postinstall pulls the correct @sortersocial/slugsocial-* for this OS/arch
5
+ * into the same node_modules tree as slugsocial.
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
+ function main() {
24
+ const pkgRoot = path.join(__dirname, "..");
25
+ const pkgJsonPath = path.join(pkgRoot, "package.json");
26
+ const pkg = JSON.parse(fs.readFileSync(pkgJsonPath, "utf8"));
27
+ const name = platformPkgName();
28
+ if (!name) {
29
+ return;
30
+ }
31
+ try {
32
+ require.resolve(`${name}/package.json`, { paths: [pkgRoot] });
33
+ return;
34
+ } catch (_) {
35
+ /* fall through */
36
+ }
37
+
38
+ const version = pkg.version;
39
+ if (!version) {
40
+ return;
41
+ }
42
+
43
+ const nm = path.join(pkgRoot, "..");
44
+ // Parent of node_modules (works for npx cache and normal installs).
45
+ const installRoot = path.dirname(nm);
46
+ const npm = process.platform === "win32" ? "npm.cmd" : "npm";
47
+ const args = [
48
+ "install",
49
+ "--no-fund",
50
+ "--no-audit",
51
+ "--no-package-lock",
52
+ "--include=optional",
53
+ "--prefix",
54
+ installRoot,
55
+ `${name}@${version}`,
56
+ ];
57
+ const r = spawnSync(npm, args, {
58
+ stdio: "inherit",
59
+ env: process.env,
60
+ });
61
+ if (r.status !== 0) {
62
+ console.warn(
63
+ `slugsocial: postinstall could not install ${name}@${version} (exit ${r.status}). ` +
64
+ `Try: npm install ${name}@${version}`,
65
+ );
66
+ }
67
+ }
68
+
69
+ main();