keyman-cli 0.1.0 → 0.1.1

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
@@ -23,4 +23,4 @@ keyman inject my-app /path/to/existing/project
23
23
 
24
24
  `load` remembers the master file path. `inject` replaces the project's `.env` file. Keep the master file private and ignore `.env` in Git.
25
25
 
26
- Prebuilt binaries are included for Windows x64, macOS Intel and Apple Silicon, and Linux x64 and ARM64. No Rust installation is needed. [Source and full documentation](https://github.com/moonmangit/keyman-cli).
26
+ Prebuilt binaries are included for Windows x64, macOS Intel and Apple Silicon, and Linux x64 and ARM64. No Rust installation is needed. On Windows systems that block the native executable, the command can use WSL if it is installed. The executable is available as both `keyman` and `keyman-cli`. [Source and full documentation](https://github.com/moonmangit/keyman-cli).
package/bin/keyman.cjs CHANGED
@@ -1,6 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
 
3
3
  const fs = require('node:fs');
4
+ const os = require('node:os');
4
5
  const path = require('node:path');
5
6
  const { spawnSync } = require('node:child_process');
6
7
 
@@ -25,7 +26,16 @@ if (!fs.existsSync(binary)) {
25
26
  process.exit(1);
26
27
  }
27
28
 
28
- const result = spawnSync(binary, process.argv.slice(2), { stdio: 'inherit' });
29
+ const args = process.argv.slice(2);
30
+ let result = spawnSync(binary, args, { stdio: 'inherit' });
31
+ if (process.platform === 'win32' && result.error && ['UNKNOWN', 'EPERM', 'EACCES'].includes(result.error.code)) {
32
+ try {
33
+ result = runWithWsl(args);
34
+ } catch (error) {
35
+ console.error(`keyman: Windows blocked the native executable and WSL fallback failed: ${error.message}`);
36
+ process.exit(1);
37
+ }
38
+ }
29
39
  if (result.error) {
30
40
  console.error(`keyman: ${result.error.message}`);
31
41
  process.exit(1);
@@ -35,3 +45,36 @@ if (result.signal) {
35
45
  } else {
36
46
  process.exitCode = result.status ?? 1;
37
47
  }
48
+
49
+ function runWithWsl(args) {
50
+ const linuxBinary = path.join(__dirname, 'native', 'x86_64-unknown-linux-gnu', 'keyman');
51
+ if (!fs.existsSync(linuxBinary)) {
52
+ throw new Error('the Linux x64 binary is missing from this package');
53
+ }
54
+
55
+ const linuxArgs = [...args];
56
+ if (linuxArgs[0] === 'load' && linuxArgs.length === 2) {
57
+ linuxArgs[1] = toWslPath(linuxArgs[1]);
58
+ } else if (linuxArgs[0] === 'inject' && linuxArgs.length === 3) {
59
+ linuxArgs[2] = toWslPath(linuxArgs[2]);
60
+ }
61
+
62
+ const linuxHome = toWslPath(process.env.USERPROFILE || os.homedir());
63
+ return spawnSync('wsl.exe', [
64
+ '--exec', 'env', `HOME=${linuxHome}`, toWslPath(linuxBinary), ...linuxArgs,
65
+ ], { stdio: 'inherit' });
66
+ }
67
+
68
+ function toWslPath(input) {
69
+ const gitBashPath = /^\/([a-zA-Z])\//.exec(input);
70
+ const windowsPath = gitBashPath
71
+ ? `${gitBashPath[1].toUpperCase()}:${input.slice(2)}`
72
+ : path.win32.resolve(input);
73
+ const converted = spawnSync('wsl.exe', ['--exec', 'wslpath', '-u', windowsPath], {
74
+ encoding: 'utf8',
75
+ });
76
+ if (converted.error || converted.status !== 0) {
77
+ throw new Error(converted.error?.message || converted.stderr?.trim() || 'wslpath could not convert the path');
78
+ }
79
+ return converted.stdout.replace(/\r?\n$/, '');
80
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "keyman-cli",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "Manage project .env files from one private YAML file",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -10,7 +10,8 @@
10
10
  "homepage": "https://github.com/moonmangit/keyman-cli#readme",
11
11
  "bugs": "https://github.com/moonmangit/keyman-cli/issues",
12
12
  "bin": {
13
- "keyman": "bin/keyman.cjs"
13
+ "keyman": "bin/keyman.cjs",
14
+ "keyman-cli": "bin/keyman.cjs"
14
15
  },
15
16
  "files": [
16
17
  "bin/",