Skip to content

Commit 3bfafd0

Browse files
committed
fix: improve binary download handling for npx usage
- Remove circular dependency from package.json - Make doplan.js attempt to download binary if missing - Improve error messages for missing binaries - Allow postinstall to succeed in development/CI even if download fails - Binary will be downloaded on first CLI execution if missing
1 parent 8f1cb50 commit 3bfafd0

4 files changed

Lines changed: 44 additions & 13 deletions

File tree

bin/doplan.js

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,31 @@ if (platform === 'win32') {
2121
const binaryPath = path.join(binDir, binaryName);
2222

2323
if (!fs.existsSync(binaryPath)) {
24-
console.error('Error: DoPlan CLI binary not found.');
25-
console.error(`Expected: ${binaryPath}`);
26-
console.error('Please run: npm install');
27-
process.exit(1);
24+
console.log('Binary not found. Attempting to download...');
25+
const downloadScript = path.join(__dirname, '..', 'scripts', 'download.js');
26+
if (fs.existsSync(downloadScript)) {
27+
try {
28+
require(downloadScript).main();
29+
// Check again after download attempt
30+
if (!fs.existsSync(binaryPath)) {
31+
console.error('Error: DoPlan CLI binary not found.');
32+
console.error(`Expected: ${binaryPath}`);
33+
console.error('Please ensure the GitHub release exists with binaries.');
34+
console.error('Or build from source: https://github.com/DoPlan-dev/CLI');
35+
process.exit(1);
36+
}
37+
} catch (error) {
38+
console.error('Error downloading binary:', error.message);
39+
console.error('Please ensure the GitHub release exists with binaries.');
40+
console.error('Or build from source: https://github.com/DoPlan-dev/CLI');
41+
process.exit(1);
42+
}
43+
} else {
44+
console.error('Error: DoPlan CLI binary not found.');
45+
console.error(`Expected: ${binaryPath}`);
46+
console.error('Please run: npm install');
47+
process.exit(1);
48+
}
2849
}
2950

3051
// Make executable on Unix systems

package-lock.json

Lines changed: 4 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,3 @@
2828
"scripts"
2929
]
3030
}
31-

scripts/download.js

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -121,15 +121,25 @@ async function main() {
121121

122122
console.log('Installation complete!');
123123
} catch (error) {
124-
// In CI environments or when release doesn't exist yet, don't fail
124+
// In CI environments or development, don't fail
125125
const isCI = process.env.CI === 'true' || process.env.GITHUB_ACTIONS === 'true' || process.env.CI === '1';
126-
if (isCI || error.message.includes('404')) {
127-
console.warn('Warning: Could not download binary (this is normal in CI or before first release):', error.message);
128-
console.warn('Binary will be downloaded on first use or when release is available.');
126+
const isDev = process.env.NODE_ENV === 'development' || !process.env.npm_config_user_config;
127+
128+
if (isCI || isDev || error.message.includes('404')) {
129+
console.warn('Warning: Could not download binary:', error.message);
130+
if (error.message.includes('404')) {
131+
console.warn('The GitHub release may not exist yet or binaries are not available.');
132+
console.warn('The binary will be downloaded automatically when you run the CLI.');
133+
console.warn('Or check: https://github.com/DoPlan-dev/CLI/releases');
134+
} else {
135+
console.warn('Binary will be downloaded on first use or when release is available.');
136+
}
129137
process.exit(0);
130138
}
139+
// For production npm installs, fail so they know something is wrong
131140
console.error('Installation failed:', error.message);
132-
console.error('This may be normal if the release is not yet available.');
141+
console.error('Please check: https://github.com/DoPlan-dev/CLI/releases');
142+
console.error('Or build from source: https://github.com/DoPlan-dev/CLI');
133143
process.exit(1);
134144
}
135145
}

0 commit comments

Comments
 (0)