Skip to content

Change npmInstall to support array for lock file names#987

Merged
garronej merged 1 commit intokeycloakify:mainfrom
Langsdorf:main
Jan 22, 2026
Merged

Change npmInstall to support array for lock file names#987
garronej merged 1 commit intokeycloakify:mainfrom
Langsdorf:main

Conversation

@Langsdorf
Copy link
Copy Markdown

@Langsdorf Langsdorf commented Jan 22, 2026

I was trying to set up the shadcn starter theme with Bun, but encountered this error:

Error: No lock file found, cannot tell which package manager to use for installing dependencies.

After reviewing the code, I found that the npmInstall function is checking for the file bun.lockdb.
However, starting from Bun v1.2, the default lockfile format changed to the text-based bun.lock:
https://bun.com/docs/pm/lockfile

Using a regex, we can support both the new and older lockfile formats.

image

Summary by CodeRabbit

  • Bug Fixes
    • Improved lock-file detection to check multiple candidate lock filenames, immediately selecting the corresponding tool when any candidate is found and continuing to exhaust candidates before reporting failure.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Jan 22, 2026

📝 Walkthrough

Walkthrough

Change npmInstall.ts to accept multiple lock-file candidate names (lockFileBasenames: string[]) per package manager, iterate through candidates, and return the first matching binName when a candidate exists in either the package directory or CWD.

Changes

Cohort / File(s) Change Summary
Package manager lock-file candidate handling
src/bin/tools/npmInstall.ts
Replace single lockFileBasename string with lockFileBasenames: string[]; iterate candidates with nested loop; check each candidate in packageJsonDirPath and process.cwd() and return corresponding binName on first match; adjust control flow to continue checking candidates before throwing.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰
I sniffed the folder, many names to see,
Bun and pals now share a candidate spree.
First match I find, I shout with delight —
One quick hop and the install is right! 🎉

🚥 Pre-merge checks | ✅ 2 | ❌ 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%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: converting lock file handling from a single string to an array of candidate names for improved package manager detection.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings

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 and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Fix all issues with AI agents
In `@src/bin/tools/npmInstall.ts`:
- Around line 32-34: The regex for Bun lockfiles in the npmInstall tool
currently uses new RegExp(`^bun\.lock.*$`) where the backslash is lost, turning
`\.` into `.`; update the lockFileBasename for the "bun" entry (the
lockFileBasename property) to use a correctly escaped dot (either double-escape
in the string form or switch to a regex literal like /^bun\.lock.*$/) so the `.`
matches a literal dot instead of any character.
- Around line 41-57: The RegExp branch that checks lockFileBasename (used for
Bun) only tests filesInJsonDirPath and therefore misses lockfiles in
process.cwd(); update the RegExp branch in the function handling packageMangers
so it also scans the cwd: obtain the filenames from process.cwd() (or combine
fs.readdirSync(packageJsonDirPath) and fs.readdirSync(process.cwd())), test
lockFileBasename.test(basename) against both sets, and return binName if any
match, matching the behavior of the string branch that checks both
packageJsonDirPath and process.cwd(); reference symbols: packageMangers,
lockFileBasename, binName, packageJsonDirPath, filesInJsonDirPath.

Comment thread src/bin/tools/npmInstall.ts Outdated
@garronej
Copy link
Copy Markdown
Collaborator

Hello @Langsdorf,

Thank you for the welcome PR.

The Regexp however is overkill here.
I'd prefer if you coulld turn lockFileBasename into lockFileBasenames and make it an array.
Keep the exact same logic otherwise.

Thank you in advance

@Langsdorf Langsdorf changed the title Change npmInstall to support regex for lock file names Change npmInstall to support array for lock file names Jan 22, 2026
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In `@src/bin/tools/npmInstall.ts`:
- Around line 32-34: The lockFileBasenames list for the bun tool includes a
non-existent entry "bun.lockdb"; in the object where binName is "bun" and
lockFileBasenames is defined (in npmInstall.ts), remove "bun.lockdb" so the
array only contains the valid Bun lockfile names ("bun.lockb" and "bun.lock");
update the lockFileBasenames property accordingly to avoid unnecessary
filesystem checks.

Comment on lines 32 to 34
binName: "bun",
lockFileBasename: "bun.lockdb"
lockFileBasenames: ["bun.lockdb", "bun.lockb", "bun.lock"]
},
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

🧩 Analysis chain

🌐 Web query:

Bun lockfile naming bun.lockb bun.lockdb bun.lock versions

💡 Result:

Summary — Bun lockfile names and versions

  • bun.lockb — Bun’s original binary lockfile (fast, compact, not human-readable). [1][4]
  • bun.lock — New text-based JSONC lockfile introduced in Bun v1.1.39 (human-readable, git-diffable); became the default in v1.2.0. [1][2][3]
  • How to create/migrate:
    • Create text lockfile: bun install --save-text-lockfile. [1][3]
    • Migrate existing bun.lockb to bun.lock: bun install --save-text-lockfile --frozen-lockfile --lockfile-only and then delete bun.lockb. [2][11]
    • bun bun.lockb prints a yarn-compatible yarn.lock. [2]
  • Config: you can set install.saveTextLockfile = true in bunfig.toml to prefer text lockfiles before v1.2.0. [3]

Sources:
[1] Bun blog — “Bun's new text-based lockfile” (Dec 17, 2024).
[2] Bun docs — Lockfile / install pages.
[3] Bun blog / release notes (v1.1.40) about install.saveTextLockfile.


🌐 Web query:

Bun package manager lockfile format history

💡 Result:

Summary timeline of Bun lockfile formats

  • Early Bun used a binary lockfile named bun.lockb as the package manager’s lockfile. [1]
  • Bun introduced a text/JSONC lockfile (bun.lock) in v1.1.39 (announced Dec 17, 2024) as opt-in via --save-text-lockfile; bun.lockb remained supported. [2]
  • v1.1.39/v1.1.40 added config options (e.g., install.saveTextLockfile) to prefer the text lockfile without waiting for v1.2. [3]
  • Bun planned to make the text-based bun.lock the default in v1.2; docs show v1.2 defaults to bun.lock and document migration steps from bun.lockb and other package managers. [1][4]

Notes / how to migrate

  • Generate text lockfile: bun install --save-text-lockfile (or set install.saveTextLockfile in bunfig.toml) and migrate existing bun.lockb with bun install --save-text-lockfile --frozen-lockfile --lockfile-only, then delete bun.lockb. [2][3][1]

Sources
[1] Bun docs — Lockfile.
[2] Bun blog — "Bun's new text-based lockfile" (Dec 17, 2024).
[3] Bun release notes (v1.1.40).
[4] Bun docs — install / yarnlock guide.


🏁 Script executed:

cd src/bin/tools && cat -n npmInstall.ts | head -50

Repository: keycloakify/keycloakify

Length of output: 2170


Remove the non-existent bun.lockdb from the lockfile candidates.

According to Bun's official documentation and release notes, only bun.lockb (original binary format) and bun.lock (text-based format introduced in v1.1.39) are valid lockfile names. bun.lockdb does not exist and should be removed to avoid unnecessary filesystem checks and potential false positives.

Update line 33 to:

lockFileBasenames: ["bun.lockb", "bun.lock"]
🤖 Prompt for AI Agents
In `@src/bin/tools/npmInstall.ts` around lines 32 - 34, The lockFileBasenames list
for the bun tool includes a non-existent entry "bun.lockdb"; in the object where
binName is "bun" and lockFileBasenames is defined (in npmInstall.ts), remove
"bun.lockdb" so the array only contains the valid Bun lockfile names
("bun.lockb" and "bun.lock"); update the lockFileBasenames property accordingly
to avoid unnecessary filesystem checks.

@garronej
Copy link
Copy Markdown
Collaborator

@allcontributors add @Langsdorf for code

@allcontributors
Copy link
Copy Markdown
Contributor

@garronej

I've put up a pull request to add @Langsdorf! 🎉

@garronej garronej merged commit 032557b into keycloakify:main Jan 22, 2026
2 checks passed
@garronej
Copy link
Copy Markdown
Collaborator

Thank you @Langsdorf!
I just released a new version

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants