Skip to content

Commit

Permalink
🩹 fix(patch): fix browserslist db errors (#2490)
Browse files Browse the repository at this point in the history
- Recent changes to nightly can cause fatal errors if browserslist is not up to date.
- This reverts some of the changes made to nightly but does not reinstitute the `upgrade-browserslist-db` postinstall script.
- 

## Type of change

**PATCH: backwards compatible change**
  • Loading branch information
kellymears committed Oct 27, 2023
1 parent 04aa5bb commit 4dac750
Show file tree
Hide file tree
Showing 12 changed files with 98 additions and 255 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
"ts-node": "10.9.1",
"tslib": "2.6.2",
"typescript": "5.2.2",
"update-browserslist-db": "latest",
"verdaccio": "5.27.0",
"vitest": "0.34.6",
"vitest-github-actions-reporter": "0.10.0",
Expand Down
55 changes: 20 additions & 35 deletions sources/@repo/yarn-plugin-bud/bundles/@yarnpkg/plugin-bud.js

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
import {path} from '@repo/constants'
import {CommandClass} from 'clipanion'
import {execa} from 'execa'
import * as fs from 'fs-jetpack'
import {kebabCase} from 'lodash'

import {Command} from './base.command'

Expand All @@ -16,78 +12,11 @@ export class BrowserslistUpdate extends Command {
category: `@bud`,
description: `update browserslist`,
examples: [
[`browserslist usage info`, `yarn @bud browserslist --help`],
[`update browserslist db`, `yarn @bud browserslist update`],
],
}

public static queries: Array<[string, Array<string>]> = [
[`Default`, []],
[`Last 2 versions`, [`last 2 versions`]],
[`Last 3 versions`, [`last 3 versions`]],
[
`WordPress`,
[
`> 1%`,
`last 1 Android versions`,
`last 1 ChromeAndroid versions`,
`last 2 Chrome versions`,
`last 2 Firefox versions`,
`last 2 Safari versions`,
`last 2 iOS versions`,
`last 2 Edge versions`,
`last 2 Opera versions`,
],
],
]

public async execute() {
this.context.stdout.write(`Updating browserslist...\n`)

await execa(`yarn`, [`browserslist`, `--update-db`]).catch(this.catch)

this.context.stdout.write(`Updating queries...\n`)

await Promise.all(
BrowserslistUpdate.queries.map(
async ([name, query]) => await this.updateQuery(name, query),
),
).catch(this.catch)
}

public async updateQuery(name: string, query: Array<string>) {
const list = await execa(`yarn`, [`browserslist`, query.join(`, `)])
.then(({stdout}) => stdout)
.catch(this.catch)

if (!list) return

const parts = []

// banner
parts.push(`/**\n * ${name}\n */\n`)
// opening module.exports statement
parts.push(`module.exports = [\n`)
// each line from stdout
list.split(`\n`).map(item => parts.push(` \`${item}\`,\n`))
// closing bracket
parts.push(`]`)

// file name
const filename = `${kebabCase(name.toLowerCase())}.cjs`
// file path
const writePath = path(
`sources`,
`@roots`,
`browserslist-config`,
filename,
)
// file contents
const contents = parts.join(``)

// write output
await fs.writeAsync(writePath, contents).catch(this.catch)

// log
this.context.stdout.write(`Updated ${filename}\n`)
await this.cli.run([`update-browserslist-db`])
}
}
37 changes: 2 additions & 35 deletions sources/@roots/browserslist-config/default.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,38 +2,5 @@
* Default
**/
module.exports = [
`and_chr 118`,
`and_ff 118`,
`and_qq 13.1`,
`and_uc 15.5`,
`android 118`,
`chrome 118`,
`chrome 117`,
`chrome 116`,
`chrome 115`,
`chrome 114`,
`chrome 109`,
`edge 118`,
`edge 117`,
`edge 116`,
`firefox 118`,
`firefox 117`,
`firefox 115`,
`ios_saf 17.0`,
`ios_saf 16.6`,
`ios_saf 16.3`,
`ios_saf 16.1`,
`ios_saf 15.6-15.7`,
`kaios 3.0-3.1`,
`kaios 2.5`,
`op_mini all`,
`op_mob 73`,
`opera 103`,
`opera 102`,
`opera 101`,
`safari 17.0`,
`safari 16.6`,
`safari 15.6`,
`samsung 22`,
`samsung 21`,
]
`defaults`,
]
33 changes: 1 addition & 32 deletions sources/@roots/browserslist-config/last-2-versions.cjs
Original file line number Diff line number Diff line change
@@ -1,35 +1,4 @@
/**
* Last 2 versions
*/
module.exports = [
`and_chr 118`,
`and_ff 118`,
`and_qq 13.1`,
`and_uc 15.5`,
`android 118`,
`baidu 13.18`,
`bb 10`,
`bb 7`,
`chrome 118`,
`chrome 117`,
`edge 118`,
`edge 117`,
`firefox 118`,
`firefox 117`,
`ie 11`,
`ie 10`,
`ie_mob 11`,
`ie_mob 10`,
`ios_saf 17.0`,
`ios_saf 16.6`,
`kaios 3.0-3.1`,
`kaios 2.5`,
`op_mini all`,
`op_mob 73`,
`opera 103`,
`opera 102`,
`safari 17.0`,
`safari 16.6`,
`samsung 22`,
`samsung 21`,
]
module.exports = [`last 2 versions`]
41 changes: 1 addition & 40 deletions sources/@roots/browserslist-config/last-3-versions.cjs
Original file line number Diff line number Diff line change
@@ -1,43 +1,4 @@
/**
* Last 3 versions
*/
module.exports = [
`and_chr 118`,
`and_ff 118`,
`and_qq 13.1`,
`and_uc 15.5`,
`android 118`,
`baidu 13.18`,
`bb 10`,
`bb 7`,
`chrome 118`,
`chrome 117`,
`chrome 116`,
`edge 118`,
`edge 117`,
`edge 116`,
`firefox 118`,
`firefox 117`,
`firefox 116`,
`ie 11`,
`ie 10`,
`ie 9`,
`ie_mob 11`,
`ie_mob 10`,
`ios_saf 17.0`,
`ios_saf 16.6`,
`ios_saf 16.5`,
`kaios 3.0-3.1`,
`kaios 2.5`,
`op_mini all`,
`op_mob 73`,
`opera 103`,
`opera 102`,
`opera 101`,
`safari 17.0`,
`safari 16.6`,
`safari 16.5`,
`samsung 22`,
`samsung 21`,
`samsung 20`,
]
module.exports = [`last 3 versions`]
2 changes: 1 addition & 1 deletion sources/@roots/browserslist-config/types.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
/**
* null
* No types for this package
*/
32 changes: 10 additions & 22 deletions sources/@roots/browserslist-config/wordpress.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,13 @@
* WordPress
*/
module.exports = [
`and_chr 118`,
`android 118`,
`chrome 118`,
`chrome 117`,
`chrome 116`,
`chrome 115`,
`chrome 109`,
`edge 118`,
`edge 117`,
`edge 116`,
`firefox 118`,
`firefox 117`,
`ios_saf 17.0`,
`ios_saf 16.6`,
`ios_saf 15.6-15.7`,
`op_mini all`,
`opera 103`,
`opera 102`,
`safari 17.0`,
`safari 16.6`,
`samsung 22`,
]
`> 1%`,
`last 1 Android versions`,
`last 1 ChromeAndroid versions`,
`last 2 Chrome versions`,
`last 2 Firefox versions`,
`last 2 Safari versions`,
`last 2 iOS versions`,
`last 2 Edge versions`,
`last 2 Opera versions`,
]
4 changes: 1 addition & 3 deletions sources/@roots/bud-support/src/which-pm/pmString.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@ export const parse = (
): `npm` | `pnpm` | `yarn-classic` | `yarn` | false => {
if (!pmString) return false

if (pmString.includes(`yarn/3`) || pmString.includes(`yarn@3`))
return `yarn`

if (pmString.match(/yarn(\/|@)(3|4).*/)) return `yarn`
if (pmString.includes(`yarn`)) return `yarn-classic`
if (pmString.includes(`npm`)) return `npm`
if (pmString.includes(`pnpm`)) return `pnpm`
Expand Down
1 change: 1 addition & 0 deletions sources/@roots/bud/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@
"@roots/bud-minify": "workspace:*",
"@roots/bud-server": "workspace:*",
"@roots/bud-support": "workspace:*",
"browserslist": "4.22.1",
"caniuse-lite": "1.0.30001553",
"tslib": "2.6.2"
},
Expand Down
Loading

0 comments on commit 4dac750

Please sign in to comment.