Skip to content

Commit d907a22

Browse files
committed
Update npm-publish.yml
1 parent d3aec26 commit d907a22

File tree

1 file changed

+41
-17
lines changed

1 file changed

+41
-17
lines changed

.github/workflows/npm-publish.yml

Lines changed: 41 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -169,38 +169,62 @@ jobs:
169169
const path = require('path');
170170
const { getBinaryPath } = require('./index');
171171
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) {
178180
if (process.platform !== 'win32') {
179181
try {
180182
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);
183186
}
184187
}
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+
}
185203
204+
// Execute binary with provided arguments
186205
const proc = spawn(binaryPath, process.argv.slice(2), {
187206
stdio: 'inherit'
188207
});
189208
209+
proc.on('exit', (code) => {
210+
process.exit(code || 0);
211+
});
212+
190213
proc.on('error', (error) => {
214+
console.error('Error executing binary:', error.message);
191215
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);
196217
}
197218
process.exit(1);
198219
});
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 {
204228
console.error('Error:', error.message);
205229
process.exit(1);
206230
}

0 commit comments

Comments
 (0)