@owenlamont/ryl 0.4.2 → 0.4.4

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/ryl.js +42 -141
  2. package/npm-platforms.json +124 -0
  3. package/package.json +13 -1
package/bin/ryl.js CHANGED
@@ -1,175 +1,76 @@
1
1
  #!/usr/bin/env node
2
2
 
3
- const fs = require('fs');
4
3
  const path = require('path');
5
- const https = require('https');
6
- const os = require('os');
7
4
  const { spawnSync } = require('child_process');
8
5
 
9
6
  const pkg = require('../package.json');
10
- const version = pkg.version;
7
+ const platforms = require('../npm-platforms.json');
11
8
  const binName = process.platform === 'win32' ? 'ryl.exe' : 'ryl';
12
-
13
- // Support user-writable cache directory to avoid EACCES in global installs
14
- function getCacheDir() {
15
- if (process.platform === 'win32') {
16
- return process.env.LOCALAPPDATA || path.join(os.homedir(), 'AppData', 'Local');
17
- }
18
- if (process.platform === 'darwin') {
19
- return path.join(os.homedir(), 'Library', 'Caches');
20
- }
21
- return process.env.XDG_CACHE_HOME || path.join(os.homedir(), '.cache');
22
- }
23
-
24
- const rylCacheDir = path.join(getCacheDir(), 'ryl', version);
25
- const cacheBinPath = path.join(rylCacheDir, binName);
26
9
  const localBinPath = path.join(__dirname, binName);
27
10
 
28
- const PLATFORMS = {
29
- darwin: {
30
- arm64: 'aarch64-apple-darwin'
31
- },
32
- linux: {
33
- x64: 'x86_64-unknown-linux-musl',
34
- arm64: 'aarch64-unknown-linux-musl',
35
- arm: 'armv7-unknown-linux-gnueabihf',
36
- ia32: 'i686-unknown-linux-gnu',
37
- ppc64: 'powerpc64le-unknown-linux-gnu',
38
- s390x: 's390x-unknown-linux-gnu'
39
- },
40
- win32: {
41
- x64: 'x86_64-pc-windows-msvc',
42
- arm64: 'aarch64-pc-windows-msvc'
43
- }
44
- };
45
-
46
- function getBinaryName() {
47
- const platform = PLATFORMS[process.platform];
48
- if (!platform) return null;
49
- const target = platform[process.arch];
50
- if (!target) return null;
51
-
52
- if (process.platform === 'win32') {
53
- return `ryl-${target}.zip`;
54
- }
55
- return `ryl-${target}.tar.gz`;
56
- }
57
-
58
- function download(url, dest) {
59
- return new Promise((resolve, reject) => {
60
- const file = fs.createWriteStream(dest);
61
- https.get(url, (response) => {
62
- if (response.statusCode === 302 || response.statusCode === 301) {
63
- file.close(() => {
64
- fs.unlink(dest, () => {
65
- download(response.headers.location, dest).then(resolve).catch(reject);
66
- });
67
- });
68
- return;
69
- }
70
- if (response.statusCode !== 200) {
71
- file.close(() => {
72
- fs.unlink(dest, () => {
73
- reject(new Error(`Failed to download binary: ${response.statusCode}`));
74
- });
75
- });
76
- return;
77
- }
78
- response.pipe(file);
79
- file.on('finish', () => {
80
- file.close();
81
- resolve();
82
- });
83
- }).on('error', (err) => {
84
- file.close(() => {
85
- fs.unlink(dest, () => reject(err));
86
- });
87
- });
88
- });
89
- }
90
-
91
11
  async function run() {
92
- // 0. Try Environment Variable Override
93
12
  if (process.env.RYL_BINARY_PATH) {
94
13
  execute(process.env.RYL_BINARY_PATH);
95
14
  return;
96
15
  }
97
16
 
98
- // 1. Try Local Bin (for dev/local installs)
99
- if (fs.existsSync(localBinPath)) {
17
+ if (exists(localBinPath)) {
100
18
  execute(localBinPath);
101
19
  return;
102
20
  }
103
21
 
104
- // 2. Try Cache Bin
105
- if (fs.existsSync(cacheBinPath)) {
106
- execute(cacheBinPath);
107
- return;
108
- }
109
-
110
- // 3. Install and Execute
111
- await install();
112
- execute(cacheBinPath);
113
- }
114
-
115
- async function install() {
116
- const binaryAsset = getBinaryName();
117
- if (!binaryAsset) {
118
- console.error(`Unsupported platform/architecture: ${process.platform}/${process.arch}`);
22
+ const platformPackage = resolvePlatformPackage();
23
+ const platformPackageJson = resolveInstalledPackageJson(platformPackage.packageName);
24
+ if (!platformPackageJson) {
25
+ console.error(
26
+ [
27
+ `No installed npm platform package matches ${process.platform}/${process.arch}.`,
28
+ `Expected optional dependency: ${platformPackage.packageName}`,
29
+ 'This package requires npm optionalDependencies; installs done with',
30
+ '--omit=optional or npm_config_optional=false are not supported.',
31
+ `Reinstall ${pkg.name} with optional dependencies enabled.`
32
+ ].join('\n')
33
+ );
119
34
  process.exit(1);
120
35
  }
121
36
 
122
- // Ensure cache directory exists
123
- try {
124
- fs.mkdirSync(rylCacheDir, { recursive: true });
125
- } catch (err) {
126
- console.error(`Error creating cache directory ${rylCacheDir}: ${err.message}`);
37
+ const packageRoot = path.dirname(platformPackageJson);
38
+ const binaryPath = path.join(packageRoot, 'bin', platformPackage.binaryName);
39
+ if (!exists(binaryPath)) {
40
+ console.error(
41
+ `Installed package ${platformPackage.packageName} is missing binary ${platformPackage.binaryName}.`
42
+ );
127
43
  process.exit(1);
128
44
  }
129
45
 
130
- const url = `https://github.com/owenlamont/ryl/releases/download/v${version}/${binaryAsset}`;
131
- const archivePath = path.join(rylCacheDir, `${binaryAsset}.tmp`);
132
- const extractDir = path.join(rylCacheDir, `extract-${Date.now()}`);
133
-
134
- console.log(`Downloading ryl v${version} for ${process.platform}/${process.arch}...`);
135
- console.log(`Installing to: ${cacheBinPath}`);
46
+ execute(binaryPath);
47
+ }
136
48
 
49
+ function exists(candidatePath) {
137
50
  try {
138
- await download(url, archivePath);
139
- fs.mkdirSync(extractDir, { recursive: true });
140
-
141
- if (process.platform === 'win32') {
142
- spawnSync('powershell.exe', ['-Command', `Expand-Archive -Path "${archivePath}" -DestinationPath "${extractDir}" -Force`], { stdio: 'inherit' });
143
- } else {
144
- spawnSync('tar', ['-xzf', archivePath, '-C', extractDir], { stdio: 'inherit' });
145
- }
51
+ require('fs').accessSync(candidatePath);
52
+ return true;
53
+ } catch {
54
+ return false;
55
+ }
56
+ }
146
57
 
147
- const extractedBinPath = path.join(extractDir, binName);
148
- if (!fs.existsSync(extractedBinPath)) {
149
- throw new Error(`Binary not found in archive: ${binName}`);
58
+ function resolvePlatformPackage() {
59
+ for (const platform of platforms.platforms) {
60
+ if (platform.os.includes(process.platform) && platform.cpu.includes(process.arch)) {
61
+ return platform;
150
62
  }
63
+ }
151
64
 
152
- // Atomic move
153
- fs.renameSync(extractedBinPath, cacheBinPath);
154
-
155
- // Cleanup
156
- fs.unlinkSync(archivePath);
157
- fs.rmSync(extractDir, { recursive: true, force: true });
65
+ console.error(`Unsupported platform/architecture: ${process.platform}/${process.arch}`);
66
+ process.exit(1);
67
+ }
158
68
 
159
- if (process.platform !== 'win32') {
160
- fs.chmodSync(cacheBinPath, 0o755);
161
- }
162
- console.log('Successfully installed ryl!');
163
- } catch (err) {
164
- console.error(`Error installing ryl binary: ${err.message}`);
165
- // Cleanup on failure
166
- if (fs.existsSync(archivePath)) fs.unlinkSync(archivePath);
167
- if (fs.existsSync(extractDir)) fs.rmSync(extractDir, { recursive: true, force: true });
168
-
169
- if (process.env.HTTPS_PROXY || process.env.https_proxy || process.env.HTTP_PROXY || process.env.http_proxy) {
170
- console.error('Note: You are using a proxy; please ensure your environment is configured correctly for Node.js https.get().');
171
- }
172
- process.exit(1);
69
+ function resolveInstalledPackageJson(packageName) {
70
+ try {
71
+ return require.resolve(`${packageName}/package.json`);
72
+ } catch {
73
+ return null;
173
74
  }
174
75
  }
175
76
 
@@ -0,0 +1,124 @@
1
+ {
2
+ "binaryName": "ryl",
3
+ "metaPackageName": "@owenlamont/ryl",
4
+ "packageScope": "@owenlamont",
5
+ "platforms": [
6
+ {
7
+ "archiveName": "ryl-aarch64-apple-darwin.tar.gz",
8
+ "binaryName": "ryl",
9
+ "cpu": [
10
+ "arm64"
11
+ ],
12
+ "folderName": "ryl-darwin-arm64",
13
+ "os": [
14
+ "darwin"
15
+ ],
16
+ "packageName": "@owenlamont/ryl-darwin-arm64",
17
+ "target": "aarch64-apple-darwin"
18
+ },
19
+ {
20
+ "archiveName": "ryl-x86_64-unknown-linux-musl.tar.gz",
21
+ "binaryName": "ryl",
22
+ "cpu": [
23
+ "x64"
24
+ ],
25
+ "folderName": "ryl-linux-x64-musl",
26
+ "os": [
27
+ "linux"
28
+ ],
29
+ "packageName": "@owenlamont/ryl-linux-x64-musl",
30
+ "target": "x86_64-unknown-linux-musl"
31
+ },
32
+ {
33
+ "archiveName": "ryl-aarch64-unknown-linux-musl.tar.gz",
34
+ "binaryName": "ryl",
35
+ "cpu": [
36
+ "arm64"
37
+ ],
38
+ "folderName": "ryl-linux-arm64-musl",
39
+ "os": [
40
+ "linux"
41
+ ],
42
+ "packageName": "@owenlamont/ryl-linux-arm64-musl",
43
+ "target": "aarch64-unknown-linux-musl"
44
+ },
45
+ {
46
+ "archiveName": "ryl-armv7-unknown-linux-gnueabihf.tar.gz",
47
+ "binaryName": "ryl",
48
+ "cpu": [
49
+ "arm"
50
+ ],
51
+ "folderName": "ryl-linux-armv7-gnu",
52
+ "os": [
53
+ "linux"
54
+ ],
55
+ "packageName": "@owenlamont/ryl-linux-armv7-gnu",
56
+ "target": "armv7-unknown-linux-gnueabihf"
57
+ },
58
+ {
59
+ "archiveName": "ryl-i686-unknown-linux-gnu.tar.gz",
60
+ "binaryName": "ryl",
61
+ "cpu": [
62
+ "ia32"
63
+ ],
64
+ "folderName": "ryl-linux-ia32-gnu",
65
+ "os": [
66
+ "linux"
67
+ ],
68
+ "packageName": "@owenlamont/ryl-linux-ia32-gnu",
69
+ "target": "i686-unknown-linux-gnu"
70
+ },
71
+ {
72
+ "archiveName": "ryl-powerpc64le-unknown-linux-gnu.tar.gz",
73
+ "binaryName": "ryl",
74
+ "cpu": [
75
+ "ppc64"
76
+ ],
77
+ "folderName": "ryl-linux-ppc64le-gnu",
78
+ "os": [
79
+ "linux"
80
+ ],
81
+ "packageName": "@owenlamont/ryl-linux-ppc64le-gnu",
82
+ "target": "powerpc64le-unknown-linux-gnu"
83
+ },
84
+ {
85
+ "archiveName": "ryl-s390x-unknown-linux-gnu.tar.gz",
86
+ "binaryName": "ryl",
87
+ "cpu": [
88
+ "s390x"
89
+ ],
90
+ "folderName": "ryl-linux-s390x-gnu",
91
+ "os": [
92
+ "linux"
93
+ ],
94
+ "packageName": "@owenlamont/ryl-linux-s390x-gnu",
95
+ "target": "s390x-unknown-linux-gnu"
96
+ },
97
+ {
98
+ "archiveName": "ryl-x86_64-pc-windows-msvc.zip",
99
+ "binaryName": "ryl.exe",
100
+ "cpu": [
101
+ "x64"
102
+ ],
103
+ "folderName": "ryl-win32-x64-msvc",
104
+ "os": [
105
+ "win32"
106
+ ],
107
+ "packageName": "@owenlamont/ryl-win32-x64-msvc",
108
+ "target": "x86_64-pc-windows-msvc"
109
+ },
110
+ {
111
+ "archiveName": "ryl-aarch64-pc-windows-msvc.zip",
112
+ "binaryName": "ryl.exe",
113
+ "cpu": [
114
+ "arm64"
115
+ ],
116
+ "folderName": "ryl-win32-arm64-msvc",
117
+ "os": [
118
+ "win32"
119
+ ],
120
+ "packageName": "@owenlamont/ryl-win32-arm64-msvc",
121
+ "target": "aarch64-pc-windows-msvc"
122
+ }
123
+ ]
124
+ }
package/package.json CHANGED
@@ -20,6 +20,7 @@
20
20
  },
21
21
  "files": [
22
22
  "bin/",
23
+ "npm-platforms.json",
23
24
  "README.md",
24
25
  "LICENSE"
25
26
  ],
@@ -46,5 +47,16 @@
46
47
  },
47
48
  "sideEffects": false,
48
49
  "type": "commonjs",
49
- "version": "0.4.2"
50
+ "version": "0.4.4",
51
+ "optionalDependencies": {
52
+ "@owenlamont/ryl-darwin-arm64": "0.4.4",
53
+ "@owenlamont/ryl-linux-x64-musl": "0.4.4",
54
+ "@owenlamont/ryl-linux-arm64-musl": "0.4.4",
55
+ "@owenlamont/ryl-linux-armv7-gnu": "0.4.4",
56
+ "@owenlamont/ryl-linux-ia32-gnu": "0.4.4",
57
+ "@owenlamont/ryl-linux-ppc64le-gnu": "0.4.4",
58
+ "@owenlamont/ryl-linux-s390x-gnu": "0.4.4",
59
+ "@owenlamont/ryl-win32-x64-msvc": "0.4.4",
60
+ "@owenlamont/ryl-win32-arm64-msvc": "0.4.4"
61
+ }
50
62
  }