@fabr-client/core 0.1.3 → 0.1.5

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.
Files changed (2) hide show
  1. package/bin/fabr-client.js +87 -23
  2. package/package.json +4 -4
@@ -15,34 +15,98 @@ const packageByPlatform = {
15
15
  "darwin-arm64": "@fabr-client/core-darwin-arm64",
16
16
  };
17
17
 
18
- function resolvePlatformPackageBinary() {
19
- const pkg = packageByPlatform[platformDir];
20
- if (!pkg) {
21
- return null;
22
- }
23
- try {
24
- return path.join(path.dirname(require.resolve(`${pkg}/package.json`)), "bin", exe);
25
- } catch {
26
- return null;
27
- }
28
- }
29
-
30
- const candidates = [
31
- process.env.FABR_CLIENT_BIN,
32
- resolvePlatformPackageBinary(),
33
- // Local development fallback: package payloads staged next to this repo.
34
- path.join(__dirname, "..", "..", "npm-platforms", platformDir, "bin", exe),
35
- path.join(__dirname, platformDir, exe),
18
+ function resolvePlatformPackageBinary(pkg) {
19
+ if (!pkg) {
20
+ return null;
21
+ }
22
+ try {
23
+ return path.join(path.dirname(require.resolve(`${pkg}/package.json`)), "bin", exe);
24
+ } catch {
25
+ return null;
26
+ }
27
+ }
28
+
29
+ function npmCommand() {
30
+ const npmExecPath = process.env.npm_execpath;
31
+ if (npmExecPath) {
32
+ return { command: process.execPath, args: [npmExecPath] };
33
+ }
34
+ return {
35
+ command: platform === "win32" ? "npm.cmd" : "npm",
36
+ args: [],
37
+ };
38
+ }
39
+
40
+ function packageSpec(pkg) {
41
+ if (process.env.FABR_CLIENT_PLATFORM_PACKAGE_SPEC) {
42
+ return process.env.FABR_CLIENT_PLATFORM_PACKAGE_SPEC;
43
+ }
44
+ if (process.env.FABR_CLIENT_PLATFORM_PACKAGE_TARBALL) {
45
+ return process.env.FABR_CLIENT_PLATFORM_PACKAGE_TARBALL;
46
+ }
47
+
48
+ const ownPackage = require("../package.json");
49
+ const version = ownPackage.optionalDependencies?.[pkg] || ownPackage.version;
50
+ return `${pkg}@${version}`;
51
+ }
52
+
53
+ function installPlatformPackage(pkg) {
54
+ if (!pkg || process.env.FABR_CLIENT_SKIP_PLATFORM_INSTALL === "1") {
55
+ return false;
56
+ }
57
+
58
+ const spec = packageSpec(pkg);
59
+ const npm = npmCommand();
60
+ const args = [
61
+ ...npm.args,
62
+ "install",
63
+ spec,
64
+ "--no-save",
65
+ "--package-lock=false",
66
+ "--include=optional",
67
+ ];
68
+
69
+ console.error(`Installing Fabr Client native payload: ${spec}`);
70
+ const result = spawnSync(npm.command, args, {
71
+ cwd: path.join(__dirname, ".."),
72
+ env: process.env,
73
+ stdio: "inherit",
74
+ windowsHide: true,
75
+ });
76
+
77
+ if (result.error || result.status !== 0) {
78
+ const message = result.error ? result.error.message : `npm exited with status ${result.status}`;
79
+ console.error(`Unable to install ${pkg} automatically: ${message}`);
80
+ return false;
81
+ }
82
+
83
+ return true;
84
+ }
85
+
86
+ const pkg = packageByPlatform[platformDir];
87
+ const candidates = [
88
+ process.env.FABR_CLIENT_BIN,
89
+ resolvePlatformPackageBinary(pkg),
90
+ // Local development fallback: package payloads staged next to this repo.
91
+ path.join(__dirname, "..", "..", "npm-platforms", platformDir, "bin", exe),
92
+ path.join(__dirname, platformDir, exe),
36
93
  path.join(__dirname, "..", platformDir, exe),
37
94
  path.join(__dirname, exe),
38
95
  ].filter(Boolean);
39
-
40
- const binary = candidates.find((candidate) => fs.existsSync(candidate));
41
-
96
+
97
+ let binary = candidates.find((candidate) => fs.existsSync(candidate));
98
+
99
+ if (!binary && installPlatformPackage(pkg)) {
100
+ binary = resolvePlatformPackageBinary(pkg);
101
+ if (binary && !fs.existsSync(binary)) {
102
+ binary = null;
103
+ }
104
+ }
105
+
42
106
  if (!binary) {
43
- const pkg = packageByPlatform[platformDir];
107
+ const spec = pkg ? packageSpec(pkg) : null;
44
108
  const installHint = pkg
45
- ? `Try: npm install -g ${pkg}`
109
+ ? `Try: npm install -g ${spec}`
46
110
  : "This platform is not currently supported by @fabr-client/core.";
47
111
  console.error(
48
112
  `Fabr Client does not include a binary for ${platformDir}.\n` +
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fabr-client/core",
3
- "version": "0.1.3",
3
+ "version": "0.1.5",
4
4
  "description": "Cross-platform launcher for Fabr Client",
5
5
  "license": "MIT",
6
6
  "homepage": "https://pivot.enclaws.com",
@@ -19,9 +19,9 @@
19
19
  "smoke": "node bin/fabr-client.js --help"
20
20
  },
21
21
  "optionalDependencies": {
22
- "@fabr-client/core-win32-x64": "0.1.3",
23
- "@fabr-client/core-darwin-x64": "0.1.3",
24
- "@fabr-client/core-darwin-arm64": "0.1.3"
22
+ "@fabr-client/core-win32-x64": "0.1.5",
23
+ "@fabr-client/core-darwin-x64": "0.1.5",
24
+ "@fabr-client/core-darwin-arm64": "0.1.5"
25
25
  },
26
26
  "files": [
27
27
  "bin/",