-
Notifications
You must be signed in to change notification settings - Fork 9
fix: support bun old and new lockfiles #227
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
fix: support bun old and new lockfiles #227
Conversation
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is great :) Massaged a bit to show the detected file names rather than a list of possible ones.
I didn't test it yet though, so could have made a mistake. If it looks good to you, commit the suggestions and I'll do another test before merging.
const lockfiles = Array.isArray(JS_PACKAGE_MANAGERS[pm].lockfile) | ||
? JS_PACKAGE_MANAGERS[pm].lockfile | ||
: [JS_PACKAGE_MANAGERS[pm].lockfile as string]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const lockfiles = Array.isArray(JS_PACKAGE_MANAGERS[pm].lockfile) | |
? JS_PACKAGE_MANAGERS[pm].lockfile | |
: [JS_PACKAGE_MANAGERS[pm].lockfile as string]; | |
const possibleLockFiles = _.castArray(JS_PACKAGE_MANAGERS[pm].lockfile)); |
let lockFileExists = false; | ||
for (const lockfile of lockfiles) { | ||
const lockFilePath = path.join(cwd, lockfile); | ||
if (pathExistsSync(lockFilePath)) { | ||
lockFileExists = true; | ||
break; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let lockFileExists = false; | |
for (const lockfile of lockfiles) { | |
const lockFilePath = path.join(cwd, lockfile); | |
if (pathExistsSync(lockFilePath)) { | |
lockFileExists = true; | |
break; | |
} | |
} | |
const thisPmLockFile = _.find(possibleLockFiles, (lockFileName) => pathExistsSync(path.join(cwd, lockFileName))); |
} | ||
} | ||
|
||
if (lockFileExists) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (lockFileExists) { | |
if (thisPmlockFile) { |
const cwdParts = cwd.split('/'); | ||
do { | ||
let pm: JsPackageManager; | ||
let detectedPm: JsPackageManager | undefined; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let detectedPm: JsPackageManager | undefined; | |
let detectedPm: JsPackageManager | undefined; | |
let detectedPmLockFile: string | undefined; |
if (detectedPm) { | ||
const currentLockfiles = Array.isArray(JS_PACKAGE_MANAGERS[pm].lockfile) | ||
? (JS_PACKAGE_MANAGERS[pm].lockfile as string[]).join(' or ') | ||
: JS_PACKAGE_MANAGERS[pm].lockfile; | ||
const detectedLockfiles = Array.isArray(JS_PACKAGE_MANAGERS[detectedPm].lockfile) | ||
? (JS_PACKAGE_MANAGERS[detectedPm].lockfile as string[]).join(' or ') | ||
: JS_PACKAGE_MANAGERS[detectedPm].lockfile; | ||
throw new Error(`Found multiple js package manager lockfiles - ${currentLockfiles} and ${detectedLockfiles}`); | ||
} | ||
detectedPm = pm; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (detectedPm) { | |
const currentLockfiles = Array.isArray(JS_PACKAGE_MANAGERS[pm].lockfile) | |
? (JS_PACKAGE_MANAGERS[pm].lockfile as string[]).join(' or ') | |
: JS_PACKAGE_MANAGERS[pm].lockfile; | |
const detectedLockfiles = Array.isArray(JS_PACKAGE_MANAGERS[detectedPm].lockfile) | |
? (JS_PACKAGE_MANAGERS[detectedPm].lockfile as string[]).join(' or ') | |
: JS_PACKAGE_MANAGERS[detectedPm].lockfile; | |
throw new Error(`Found multiple js package manager lockfiles - ${currentLockfiles} and ${detectedLockfiles}`); | |
} | |
detectedPm = pm; | |
if (detectedPmLockFile) { | |
throw new Error(`Found multiple js package manager lockfiles - ${thisPmLockFile} and ${detectedPmLockFile}`); | |
} | |
detectedPmLockFile = thisPmLockFile; |
Modern bun uses .lock instead of .lockb files. This updates detect-package-manager to detect both.