Skip to content

Commit

Permalink
Merge pull request #40 from pornoiya/feat/bun-support
Browse files Browse the repository at this point in the history
Bun support for update-browserslist-db
  • Loading branch information
ai committed Jul 1, 2024
2 parents d6116f1 + 7f84d23 commit 89e2180
Show file tree
Hide file tree
Showing 6 changed files with 1,413 additions and 1,580 deletions.
10 changes: 10 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ function detectLockfile() {
let lockfileShrinkwrap = join(packageDir, 'npm-shrinkwrap.json')
let lockfileYarn = join(packageDir, 'yarn.lock')
let lockfilePnpm = join(packageDir, 'pnpm-lock.yaml')
let lockfileBun = join(packageDir, 'bun.lockb')

if (existsSync(lockfilePnpm)) {
return { file: lockfilePnpm, mode: 'pnpm' }
Expand All @@ -54,6 +55,8 @@ function detectLockfile() {
return lock
} else if (existsSync(lockfileShrinkwrap)) {
return { file: lockfileShrinkwrap, mode: 'npm' }
} else if (existsSync(lockfileBun)) {
return { file: lockfileBun, mode: 'bun' }
}
throw new BrowserslistUpdateError(
'No lockfile found. Run "npm install", "yarn install" or "pnpm install"'
Expand All @@ -75,6 +78,11 @@ function getLatestInfo(lock) {
if (lock.mode === 'pnpm') {
return JSON.parse(execSync('pnpm info caniuse-lite --json').toString())
}
if (lock.mode === 'bun') {
// TO-DO: No 'bun info' yet. Created issue: https://github.com/oven-sh/bun/issues/12280
return JSON.parse(execSync(' npm info caniuse-lite --json').toString())
}

return JSON.parse(execSync('npm show caniuse-lite --json').toString())
}

Expand Down Expand Up @@ -287,6 +295,8 @@ module.exports = function updateDB(print = defaultPrint) {
updateWith(print, yarnCommand + ' up -R caniuse-lite')
} else if (lock.mode === 'pnpm') {
updateWith(print, 'pnpm up caniuse-lite')
} else if (lock.mode === 'bun') {
updateWith(print, 'bun update caniuse-lite')
} else {
updatePackageManually(print, lock, latest)
}
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
"test": "pnpm run /^test:/"
},
"dependencies": {
"bun": "^1.1.17",
"escalade": "^3.1.2",
"picocolors": "^1.0.1"
},
Expand Down
Loading

0 comments on commit 89e2180

Please sign in to comment.