@fabr-client/core 0.1.0 → 0.1.2

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 CHANGED
@@ -39,6 +39,10 @@ Set the shared Rust and npm package version first:
39
39
  pwsh ./scripts/set-package-version.ps1 -Version 0.0.3
40
40
  ```
41
41
 
42
+ ```bash
43
+ bash ./scripts/set-package-version.sh 0.0.3
44
+ ```
45
+
42
46
  For maintainers, build the Windows payload with PowerShell:
43
47
 
44
48
  ```powershell
@@ -39,13 +39,18 @@ const candidates = [
39
39
 
40
40
  const binary = candidates.find((candidate) => fs.existsSync(candidate));
41
41
 
42
- if (!binary) {
43
- console.error(
44
- `Fabr Client does not include a binary for ${platformDir}.\n` +
45
- "Please reinstall @fabr-client/core, or install the matching platform package."
46
- );
47
- process.exit(1);
48
- }
42
+ if (!binary) {
43
+ const pkg = packageByPlatform[platformDir];
44
+ const installHint = pkg
45
+ ? `Try: npm install -g ${pkg}`
46
+ : "This platform is not currently supported by @fabr-client/core.";
47
+ console.error(
48
+ `Fabr Client does not include a binary for ${platformDir}.\n` +
49
+ "Please reinstall @fabr-client/core with optional dependencies enabled, or install the matching platform package.\n" +
50
+ installHint
51
+ );
52
+ process.exit(1);
53
+ }
49
54
 
50
55
  const result = spawnSync(binary, process.argv.slice(2), {
51
56
  stdio: "inherit",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fabr-client/core",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
4
  "description": "Cross-platform launcher for Fabr Client",
5
5
  "license": "MIT",
6
6
  "homepage": "https://pivot.enclaws.com",
@@ -15,15 +15,17 @@
15
15
  "fabr-client": "bin/fabr-client.js"
16
16
  },
17
17
  "scripts": {
18
+ "postinstall": "node postinstall.js",
18
19
  "smoke": "node bin/fabr-client.js --help"
19
20
  },
20
21
  "optionalDependencies": {
21
- "@fabr-client/core-win32-x64": "0.1.0",
22
- "@fabr-client/core-darwin-x64": "0.1.0",
23
- "@fabr-client/core-darwin-arm64": "0.1.0"
22
+ "@fabr-client/core-win32-x64": "0.1.2",
23
+ "@fabr-client/core-darwin-x64": "0.1.2",
24
+ "@fabr-client/core-darwin-arm64": "0.1.2"
24
25
  },
25
26
  "files": [
26
27
  "bin/",
28
+ "postinstall.js",
27
29
  "README.md"
28
30
  ],
29
31
  "engines": {
package/postinstall.js ADDED
@@ -0,0 +1,93 @@
1
+ "use strict";
2
+
3
+ const { spawnSync } = require("node:child_process");
4
+ const fs = require("node:fs");
5
+ const path = require("node:path");
6
+
7
+ const platform = process.platform;
8
+ const arch = process.arch;
9
+ const exe = platform === "win32" ? "fabr-client.exe" : "fabr-client";
10
+ const platformDir = `${platform}-${arch}`;
11
+ const packageByPlatform = {
12
+ "win32-x64": "@fabr-client/core-win32-x64",
13
+ "darwin-x64": "@fabr-client/core-darwin-x64",
14
+ "darwin-arm64": "@fabr-client/core-darwin-arm64",
15
+ };
16
+
17
+ function resolvePlatformPackageBinary(pkg) {
18
+ try {
19
+ return path.join(path.dirname(require.resolve(`${pkg}/package.json`)), "bin", exe);
20
+ } catch {
21
+ return null;
22
+ }
23
+ }
24
+
25
+ function npmCommand() {
26
+ const npmExecPath = process.env.npm_execpath;
27
+ if (npmExecPath) {
28
+ return { command: process.execPath, args: [npmExecPath] };
29
+ }
30
+ return {
31
+ command: platform === "win32" ? "npm.cmd" : "npm",
32
+ args: [],
33
+ };
34
+ }
35
+
36
+ function packageSpec(pkg) {
37
+ if (process.env.FABR_CLIENT_PLATFORM_PACKAGE_SPEC) {
38
+ return process.env.FABR_CLIENT_PLATFORM_PACKAGE_SPEC;
39
+ }
40
+ if (process.env.FABR_CLIENT_PLATFORM_PACKAGE_TARBALL) {
41
+ return process.env.FABR_CLIENT_PLATFORM_PACKAGE_TARBALL;
42
+ }
43
+
44
+ const ownPackage = require("./package.json");
45
+ const version = ownPackage.optionalDependencies?.[pkg] || ownPackage.version;
46
+ return `${pkg}@${version}`;
47
+ }
48
+
49
+ const pkg = packageByPlatform[platformDir];
50
+ if (!pkg || process.env.FABR_CLIENT_SKIP_PLATFORM_INSTALL === "1") {
51
+ process.exit(0);
52
+ }
53
+
54
+ const existingBinary = resolvePlatformPackageBinary(pkg);
55
+ if (existingBinary && fs.existsSync(existingBinary)) {
56
+ process.exit(0);
57
+ }
58
+
59
+ const spec = packageSpec(pkg);
60
+ const npm = npmCommand();
61
+ const args = [
62
+ ...npm.args,
63
+ "install",
64
+ spec,
65
+ "--no-save",
66
+ "--package-lock=false",
67
+ "--include=optional",
68
+ ];
69
+
70
+ console.log(`Installing Fabr Client native payload: ${spec}`);
71
+ const result = spawnSync(npm.command, args, {
72
+ cwd: __dirname,
73
+ env: process.env,
74
+ stdio: "inherit",
75
+ windowsHide: true,
76
+ });
77
+
78
+ if (result.error || result.status !== 0) {
79
+ const message = result.error ? result.error.message : `npm exited with status ${result.status}`;
80
+ console.warn(
81
+ `Unable to install ${pkg} automatically: ${message}\n` +
82
+ `Run "npm install -g ${pkg}" if "fabr-client" cannot find its native binary.`
83
+ );
84
+ process.exit(0);
85
+ }
86
+
87
+ const installedBinary = resolvePlatformPackageBinary(pkg);
88
+ if (!installedBinary || !fs.existsSync(installedBinary)) {
89
+ console.warn(
90
+ `Installed ${pkg}, but ${exe} was not found.\n` +
91
+ `Run "npm install -g ${pkg}" if "fabr-client" cannot find its native binary.`
92
+ );
93
+ }