@@ -169,38 +169,62 @@ jobs:
169
169
const path = require('path');
170
170
const { getBinaryPath } = require('./index');
171
171
172
- if (require.main === module) {
173
- const { spawn } = require('child_process');
174
- try {
175
- const binaryPath = getBinaryPath();
176
-
177
- // CRITICAL FIX: Make binary executable BEFORE trying to spawn it
172
+ // Check if we're running as part of npm postinstall
173
+ const isPostInstall = process.env.npm_lifecycle_event === 'postinstall';
174
+
175
+ try {
176
+ const binaryPath = getBinaryPath();
177
+
178
+ // During postinstall, just set permissions and exit
179
+ if (isPostInstall) {
178
180
if (process.platform !== 'win32') {
179
181
try {
180
182
fs.chmodSync(binaryPath, 0o755);
181
- } catch (chmodError) {
182
- console.error(`Warning: Could not set execute permissions: ${chmodError.message}`);
183
+ } catch (e) {
184
+ // Permission setting failed, but don't fail the install
185
+ console.error('Warning: Could not set executable permissions:', e.message);
183
186
}
184
187
}
188
+ console.log(`ProofOfAccess binary installed: ${binaryPath}`);
189
+ process.exit(0);
190
+ }
191
+
192
+ // When called as CLI tool, execute the binary
193
+ if (require.main === module) {
194
+ const { spawn } = require('child_process');
195
+
196
+ // Show usage if no arguments provided
197
+ if (process.argv.length === 2) {
198
+ console.log('ProofOfAccess CLI');
199
+ console.log('Usage: proofofaccess [options]');
200
+ console.log('Run with --help for more information');
201
+ process.exit(0);
202
+ }
185
203
204
+ // Execute binary with provided arguments
186
205
const proc = spawn(binaryPath, process.argv.slice(2), {
187
206
stdio: 'inherit'
188
207
});
189
208
209
+ proc.on('exit', (code) => {
210
+ process.exit(code || 0);
211
+ });
212
+
190
213
proc.on('error', (error) => {
214
+ console.error('Error executing binary:', error.message);
191
215
if (error.code === 'EACCES') {
192
- console.error(`Error: Binary at ${binaryPath} is not executable.`);
193
- console.error('Try running: chmod +x ' + binaryPath);
194
- } else {
195
- console.error('Error spawning process:', error.message);
216
+ console.error('Permission denied. Try running: chmod +x', binaryPath);
196
217
}
197
218
process.exit(1);
198
219
});
199
-
200
- proc.on('exit', (code) => {
201
- process.exit(code || 0);
202
- });
203
- } catch (error) {
220
+ }
221
+ } catch (error) {
222
+ // During install, don't fail; during CLI usage, report error
223
+ if (isPostInstall) {
224
+ console.error('Warning: Could not set up binary for your platform');
225
+ console.error(error.message);
226
+ process.exit(0);
227
+ } else {
204
228
console.error('Error:', error.message);
205
229
process.exit(1);
206
230
}
0 commit comments