emacs-lsp-proxy 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.
Files changed (3) hide show
  1. package/bin/cli +59 -0
  2. package/install.js +85 -0
  3. package/package.json +24 -0
package/bin/cli ADDED
@@ -0,0 +1,59 @@
1
+ #!/usr/bin/env node
2
+ const childProcess = require('child_process');
3
+ const path = require('path');
4
+ const fs = require('fs');
5
+ const os = require('os');
6
+
7
+ // Platform-specific package mappings - same as install.js
8
+ const platformPackages = {
9
+ 'darwin-arm64': '@emacs-lsp-proxy/darwin-arm64',
10
+ 'darwin-x64': '@emacs-lsp-proxy/darwin-x64',
11
+ 'linux-arm64': '@emacs-lsp-proxy/linux-arm64',
12
+ 'linux-x64': '@emacs-lsp-proxy/linux-x64',
13
+ 'win32-x64': '@emacs-lsp-proxy/win32-x64'
14
+ };
15
+
16
+ function getBinaryPath() {
17
+ // First try local bin directory (after install.js has run)
18
+ const platform = os.platform();
19
+ const binaryName = platform === 'win32' ? 'emacs-lsp-proxy.exe' : 'emacs-lsp-proxy';
20
+ const localBin = path.join(__dirname, '..', 'bin', binaryName);
21
+
22
+ if (fs.existsSync(localBin)) {
23
+ return localBin;
24
+ }
25
+
26
+ // Fallback: try to resolve from platform package directly
27
+ const platformKey = `${platform}-${os.arch()}`;
28
+ const packageName = platformPackages[platformKey];
29
+
30
+ if (!packageName) {
31
+ throw new Error(`Unsupported platform: ${platformKey}`);
32
+ }
33
+
34
+ try {
35
+ const packageDir = path.dirname(require.resolve(packageName + '/package.json'));
36
+ const possiblePaths = [
37
+ path.join(packageDir, binaryName),
38
+ path.join(packageDir, 'bin', binaryName)
39
+ ];
40
+
41
+ for (const binPath of possiblePaths) {
42
+ if (fs.existsSync(binPath)) {
43
+ return binPath;
44
+ }
45
+ }
46
+ } catch (e) {
47
+ // Package not found
48
+ }
49
+
50
+ throw new Error(`Binary not found for platform: ${platformKey}`);
51
+ }
52
+
53
+ try {
54
+ const binaryPath = getBinaryPath();
55
+ childProcess.execFileSync(binaryPath, process.argv.slice(2), { stdio: 'inherit' });
56
+ } catch (error) {
57
+ console.error('[emacs-lsp-proxy]', error.message);
58
+ process.exit(1);
59
+ }
package/install.js ADDED
@@ -0,0 +1,85 @@
1
+ const fs = require('fs');
2
+ const path = require('path');
3
+ const os = require('os');
4
+
5
+ // Platform-specific package mappings
6
+ const platformPackages = {
7
+ 'darwin-arm64': '@emacs-lsp-proxy/darwin-arm64',
8
+ 'darwin-x64': '@emacs-lsp-proxy/darwin-x64',
9
+ 'linux-arm64': '@emacs-lsp-proxy/linux-arm64',
10
+ 'linux-x64': '@emacs-lsp-proxy/linux-x64',
11
+ 'win32-x64': '@emacs-lsp-proxy/win32-x64'
12
+ };
13
+
14
+ function getPlatformKey() {
15
+ const platform = os.platform();
16
+ const arch = os.arch();
17
+
18
+ // Normalize architecture names
19
+ const normalizedArch = arch === 'x64' ? 'x64' :
20
+ arch === 'arm64' ? 'arm64' : arch;
21
+
22
+ return `${platform}-${normalizedArch}`;
23
+ }
24
+
25
+ function findBinary() {
26
+ const platformKey = getPlatformKey();
27
+ const packageName = platformPackages[platformKey];
28
+
29
+ if (!packageName) {
30
+ console.error(`[emacs-lsp-proxy] Unsupported platform: ${platformKey}`);
31
+ process.exit(1);
32
+ }
33
+
34
+ try {
35
+ // Try to resolve the platform-specific package
36
+ const packagePath = require.resolve(packageName + '/package.json');
37
+ const packageDir = path.dirname(packagePath);
38
+
39
+ // Look for binary in expected locations
40
+ const binaryName = platformKey.startsWith('win32') ? 'emacs-lsp-proxy.exe' : 'emacs-lsp-proxy';
41
+ const possiblePaths = [
42
+ path.join(packageDir, binaryName),
43
+ path.join(packageDir, 'bin', binaryName)
44
+ ];
45
+
46
+ for (const binPath of possiblePaths) {
47
+ if (fs.existsSync(binPath)) {
48
+ // Create symlink or copy to expected location
49
+ const targetPath = path.join(__dirname, 'bin', 'emacs-lsp-proxy' + (platformKey.startsWith('win32') ? '.exe' : ''));
50
+
51
+ fs.mkdirSync(path.dirname(targetPath), { recursive: true });
52
+
53
+ try {
54
+ // Try to create a hard link first (faster)
55
+ if (fs.existsSync(targetPath)) fs.unlinkSync(targetPath);
56
+ fs.linkSync(binPath, targetPath);
57
+ } catch (e) {
58
+ // Fall back to copying
59
+ fs.copyFileSync(binPath, targetPath);
60
+ }
61
+
62
+ // Make executable on Unix systems
63
+ if (!platformKey.startsWith('win32')) {
64
+ fs.chmodSync(targetPath, 0o755);
65
+ }
66
+
67
+ console.log(`[emacs-lsp-proxy] Binary installed successfully for ${platformKey}`);
68
+ return;
69
+ }
70
+ }
71
+
72
+ console.error(`[emacs-lsp-proxy] Binary not found in package ${packageName}`);
73
+ process.exit(1);
74
+
75
+ } catch (e) {
76
+ console.error(`[emacs-lsp-proxy] Platform package ${packageName} not found. This usually means the package wasn't installed properly.`);
77
+ console.error('Make sure your platform is supported and npm installed the optional dependencies.');
78
+ process.exit(1);
79
+ }
80
+ }
81
+
82
+ // Only run if this is the main package being installed
83
+ if (require.main === module) {
84
+ findBinary();
85
+ }
package/package.json ADDED
@@ -0,0 +1,24 @@
1
+ {
2
+ "name": "emacs-lsp-proxy",
3
+ "version": "0.1.1",
4
+ "scripts": {
5
+ "postinstall": "node ./install.js"
6
+ },
7
+ "bin": {
8
+ "emacs-lsp-proxy": "./bin/cli"
9
+ },
10
+ "publicConfig": {
11
+ "access": "public"
12
+ },
13
+ "keywords": ["emacs", "lsp", "rust"],
14
+ "author": "jadestrong",
15
+ "optionalDependencies": {
16
+ "@emacs-lsp-proxy/darwin-x64": "0.1.0",
17
+ "@emacs-lsp-proxy/darwin-arm64": "0.1.0",
18
+ "@emacs-lsp-proxy/linux-x64": "0.1.0",
19
+ "@emacs-lsp-proxy/linux-arm64": "0.1.0",
20
+ "@emacs-lsp-proxy/win32-x64": "0.1.0"
21
+ },
22
+ "license": "ISC",
23
+ "description": "An LSP client for Emacs implemented in Rust."
24
+ }