Skip to content

fix(install): ensure bin directory exists before copying binary - #2592

Open
iF2007 wants to merge 1 commit into
larksuite:mainfrom
iF2007:fix/install-ensure-bindir-exists
Open

fix(install): ensure bin directory exists before copying binary#2592
iF2007 wants to merge 1 commit into
larksuite:mainfrom
iF2007:fix/install-ensure-bindir-exists

Conversation

@iF2007

@iF2007 iF2007 commented Sep 1, 2026

Copy link
Copy Markdown

Summary

Fixes an ENOENT: no such file or directory installation/update failure in scripts/install.js where the bin/ destination directory could disappear during download due to a race condition with npm package lifecycle reification.

  • Affected versions: <= v1.0.92
  • Observed Environment:
    • OS / Platform: macOS (Darwin 25.6.0, darwin-arm64 / Apple Silicon)
    • Node.js: v26.8.1
    • npm: v12.0.2
  • Symptom:
    npm error Failed to install lark-cli: ENOENT: no such file or directory, copyfile '/tmp/.../lark-cli' -> '/opt/homebrew/lib/node_modules/@larksuite/cli/bin/lark-cli'
    

Problem & Root Cause

In scripts/install.js, fs.mkdirSync(binDir, { recursive: true }) was called at the start of install(), prior to fetching the ~13.8MB release asset over the network.

During the remote asset download (which can take 5–30s depending on network/mirror latency), npm's global install/update pipeline (e.g. npm install -g @larksuite/cli or lark-cli update --force) continues extracting and reifying the package. Because bin/ is not listed in package.json's files field (it is populated purely post-install), npm can prune or recreate the package directory tree while the download is in-flight.

When the download finishes and the archive is extracted, fs.copyFileSync(extractedBinary, dest) executes while the target ../bin directory is missing, resulting in ENOENT.

Changes

  • Add fs.mkdirSync(binDir, { recursive: true }) immediately before fs.copyFileSync(extractedBinary, dest) in scripts/install.js to guarantee destination directory existence at copy time regardless of download duration or npm tree modifications.

Test Plan

  • Ran make script-test (165/165 tests passing across all test suites including scripts/install.test.js).
  • Verified manual binary extraction and installation locally on macOS (darwin-arm64).
  • Verified lark-cli --version (v1.0.92) and lark-cli --help execute correctly.

Related Issues

  • None

Summary by CodeRabbit

  • Bug Fixes
    • Improved installation reliability by ensuring the required executable directory exists before files are copied.

@CLAassistant

CLAassistant commented Sep 1, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@github-actions github-actions Bot added the size/M Single-domain feat or fix with limited business impact label Sep 1, 2026
@coderabbitai

coderabbitai Bot commented Sep 1, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Team

Run ID: 009dbc26-ba79-41fa-ae31-1e35e4562db6

📥 Commits

Reviewing files that changed from the base of the PR and between 835b52c and d00fcca.

📒 Files selected for processing (1)
  • scripts/install.js

Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review.


📝 Walkthrough

Walkthrough

The installer now recreates the bin directory immediately before copying the extracted binary to its destination.

Changes

Installer directory handling

Layer / File(s) Summary
Ensure bin directory before copy
scripts/install.js
install() calls fs.mkdirSync(binDir, { recursive: true }) before fs.copyFileSync().

Estimated code review effort: 1 (Trivial) | ~2 minutes

Merge Risk: ⚪ Minimal · up to d00fc

The installer now ensures the binary destination directory exists immediately before copying, preventing the reported installation failure without changing broader product behavior. No actionable merge-blocking risk remains after normal checks and review.

Suggested reviewers: tantanz20020918

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 1 functions across 1 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title clearly and concisely describes the main change: recreating the bin directory before copying the binary during installation.
Description check ✅ Passed The description includes all required sections: Summary, Changes, Test Plan, and Related Issues. It explains the root cause, the code change, and verification results in sufficient detail.
  • Fix all pre-merge checks with AI
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/M Single-domain feat or fix with limited business impact

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants