fix: use .cjs extension for bin script to fix ES module compatibility

The package.json has "type": "module" but bin/hapi.js uses CommonJS
require() syntax. Renaming to .cjs forces Node.js to treat it as
CommonJS regardless of the package type setting.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
jiangjiwei
2025-12-25 10:30:58 +08:00
co-authored by Claude Opus 4.5
parent 5a3f10078e
commit cde0a09134
2 changed files with 2 additions and 2 deletions
+48
View File
@@ -0,0 +1,48 @@
#!/usr/bin/env node
const { execFileSync } = require('child_process');
const path = require('path');
const platform = process.platform;
const arch = process.arch;
const pkgName = `@twsxtd/hapi-${platform}-${arch}`;
function getBinaryPath() {
try {
// Try to find the platform-specific package
const pkgPath = require.resolve(`${pkgName}/package.json`);
const binName = platform === 'win32' ? 'hapi.exe' : 'hapi';
return path.join(path.dirname(pkgPath), 'bin', binName);
} catch (e) {
return null;
}
}
const binPath = getBinaryPath();
if (!binPath) {
console.error(`Unsupported platform: ${platform}-${arch}`);
console.error('');
console.error('Supported platforms:');
console.error(' - darwin-arm64 (macOS Apple Silicon)');
console.error(' - darwin-x64 (macOS Intel)');
console.error(' - linux-arm64');
console.error(' - linux-x64');
console.error(' - win32-x64');
console.error('');
console.error('You can download the binary manually from:');
console.error(' https://github.com/anthropics/hapi/releases');
process.exit(1);
}
try {
execFileSync(binPath, process.argv.slice(2), { stdio: 'inherit' });
} catch (e) {
// If the binary execution fails, exit with the same code
if (e.status !== undefined) {
process.exit(e.status);
}
// For other errors (e.g., binary not found), print and exit
console.error(`Failed to execute ${binPath}:`, e.message);
process.exit(1);
}