@fabr-client/core 0.1.5 → 0.1.8

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.
@@ -37,6 +37,20 @@ function npmCommand() {
37
37
  };
38
38
  }
39
39
 
40
+ function npmSpawnOptions(cwd) {
41
+ const npm = npmCommand();
42
+ return {
43
+ npm,
44
+ options: {
45
+ cwd,
46
+ env: process.env,
47
+ shell: platform === "win32" && npm.command.endsWith(".cmd"),
48
+ stdio: "inherit",
49
+ windowsHide: true,
50
+ },
51
+ };
52
+ }
53
+
40
54
  function packageSpec(pkg) {
41
55
  if (process.env.FABR_CLIENT_PLATFORM_PACKAGE_SPEC) {
42
56
  return process.env.FABR_CLIENT_PLATFORM_PACKAGE_SPEC;
@@ -50,39 +64,101 @@ function packageSpec(pkg) {
50
64
  return `${pkg}@${version}`;
51
65
  }
52
66
 
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
- });
67
+ function runNpmInstall(label, args, cwd) {
68
+ const { npm, options } = npmSpawnOptions(cwd);
69
+ console.error(label);
70
+ const result = spawnSync(npm.command, [...npm.args, ...args], options);
76
71
 
77
72
  if (result.error || result.status !== 0) {
78
73
  const message = result.error ? result.error.message : `npm exited with status ${result.status}`;
79
- console.error(`Unable to install ${pkg} automatically: ${message}`);
74
+ console.error(`${label} failed: ${message}`);
80
75
  return false;
81
76
  }
82
77
 
83
78
  return true;
84
79
  }
85
80
 
81
+ function installPlatformPackageLocal(spec) {
82
+ return runNpmInstall(
83
+ `Installing Fabr Client native payload: ${spec}`,
84
+ [
85
+ "install",
86
+ spec,
87
+ "--no-save",
88
+ "--package-lock=false",
89
+ "--include=optional",
90
+ ],
91
+ path.join(__dirname, ".."),
92
+ );
93
+ }
94
+
95
+ function installPlatformPackageGlobal(spec) {
96
+ return runNpmInstall(
97
+ `Installing Fabr Client native payload globally: ${spec}`,
98
+ [
99
+ "install",
100
+ "-g",
101
+ spec,
102
+ "--include=optional",
103
+ ],
104
+ path.join(__dirname, ".."),
105
+ );
106
+ }
107
+
108
+ function installPlatformPackageGlobalFromFallbackRegistry(spec) {
109
+ if (process.env.FABR_CLIENT_SKIP_REGISTRY_FALLBACK === "1") {
110
+ return false;
111
+ }
112
+ const registry =
113
+ process.env.FABR_CLIENT_NPM_FALLBACK_REGISTRY || "https://registry.npmjs.org";
114
+ return runNpmInstall(
115
+ `Installing Fabr Client native payload globally from fallback registry: ${spec}`,
116
+ [
117
+ "install",
118
+ "-g",
119
+ spec,
120
+ "--include=optional",
121
+ `--registry=${registry}`,
122
+ ],
123
+ path.join(__dirname, ".."),
124
+ );
125
+ }
126
+
127
+ function resolveInstalledBinary(pkg) {
128
+ const binary = resolvePlatformPackageBinary(pkg);
129
+ return binary && fs.existsSync(binary) ? binary : null;
130
+ }
131
+
132
+ function installAndResolvePlatformPackage(pkg) {
133
+ if (!pkg || process.env.FABR_CLIENT_SKIP_PLATFORM_INSTALL === "1") {
134
+ return null;
135
+ }
136
+
137
+ const spec = packageSpec(pkg);
138
+ if (installPlatformPackageLocal(spec)) {
139
+ const binary = resolveInstalledBinary(pkg);
140
+ if (binary) {
141
+ return binary;
142
+ }
143
+ }
144
+
145
+ if (installPlatformPackageGlobal(spec)) {
146
+ const binary = resolveInstalledBinary(pkg);
147
+ if (binary) {
148
+ return binary;
149
+ }
150
+ }
151
+
152
+ if (installPlatformPackageGlobalFromFallbackRegistry(spec)) {
153
+ const binary = resolveInstalledBinary(pkg);
154
+ if (binary) {
155
+ return binary;
156
+ }
157
+ }
158
+
159
+ return null;
160
+ }
161
+
86
162
  const pkg = packageByPlatform[platformDir];
87
163
  const candidates = [
88
164
  process.env.FABR_CLIENT_BIN,
@@ -96,11 +172,8 @@ const candidates = [
96
172
 
97
173
  let binary = candidates.find((candidate) => fs.existsSync(candidate));
98
174
 
99
- if (!binary && installPlatformPackage(pkg)) {
100
- binary = resolvePlatformPackageBinary(pkg);
101
- if (binary && !fs.existsSync(binary)) {
102
- binary = null;
103
- }
175
+ if (!binary) {
176
+ binary = installAndResolvePlatformPackage(pkg);
104
177
  }
105
178
 
106
179
  if (!binary) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fabr-client/core",
3
- "version": "0.1.5",
3
+ "version": "0.1.8",
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.5",
23
- "@fabr-client/core-darwin-x64": "0.1.5",
24
- "@fabr-client/core-darwin-arm64": "0.1.5"
22
+ "@fabr-client/core-win32-x64": "0.1.8",
23
+ "@fabr-client/core-darwin-x64": "0.1.8",
24
+ "@fabr-client/core-darwin-arm64": "0.1.8"
25
25
  },
26
26
  "files": [
27
27
  "bin/",
package/postinstall.js CHANGED
@@ -71,6 +71,7 @@ console.log(`Installing Fabr Client native payload: ${spec}`);
71
71
  const result = spawnSync(npm.command, args, {
72
72
  cwd: __dirname,
73
73
  env: process.env,
74
+ shell: platform === "win32" && npm.command.endsWith(".cmd"),
74
75
  stdio: "inherit",
75
76
  windowsHide: true,
76
77
  });