Change npmInstall to support array for lock file names#987
Change npmInstall to support array for lock file names#987garronej merged 1 commit intokeycloakify:mainfrom
Conversation
📝 WalkthroughWalkthroughChange npmInstall.ts to accept multiple lock-file candidate names ( Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
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. Comment |
There was a problem hiding this comment.
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.
|
Hello @Langsdorf, Thank you for the welcome PR. The Regexp however is overkill here. Thank you in advance |
There was a problem hiding this comment.
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.
| binName: "bun", | ||
| lockFileBasename: "bun.lockdb" | ||
| lockFileBasenames: ["bun.lockdb", "bun.lockb", "bun.lock"] | ||
| }, |
There was a problem hiding this comment.
🧩 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 -50Repository: 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.
|
@allcontributors add @Langsdorf for code |
|
I've put up a pull request to add @Langsdorf! 🎉 |
|
Thank you @Langsdorf! |
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.
Summary by CodeRabbit
✏️ Tip: You can customize this high-level summary in your review settings.