Skip to content

Commit

Permalink
Simplify browserslist setup by relying on defaults (#11412)
Browse files Browse the repository at this point in the history
* use `defaults` for `browserslist`

+ some features that we require for Tailwind to work.

* simplify Lightning CSS features

Always transpile `Nesting`, never transpile `LogicalProperties`.

* bump caniuse-lite (`npx browserslist@latest --update-db`)

* reflect changes in the tests

* update changelog
  • Loading branch information
RobinMalfait committed Jun 12, 2023
1 parent 3be258c commit 86f9c6f
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 41 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Add `svh`, `lvh`, and `dvh` values to default `height`/`min-height`/`max-height` theme ([#11317](https://github.com/tailwindlabs/tailwindcss/pull/11317))
- Add `has-*` variants for `:has(...)` pseudo-class ([#11318](https://github.com/tailwindlabs/tailwindcss/pull/11318))
- Add `text-wrap` utilities including `text-balance` ([#11320](https://github.com/tailwindlabs/tailwindcss/pull/11320))
- Explicitly configure Lightning CSS features, and prefer user browserslist over default browserslist ([#11402](https://github.com/tailwindlabs/tailwindcss/pull/11402))
- Explicitly configure Lightning CSS features, and prefer user browserslist over default browserslist ([#11402](https://github.com/tailwindlabs/tailwindcss/pull/11402), [#11412](https://github.com/tailwindlabs/tailwindcss/pull/11412))

### Changed

Expand Down
18 changes: 9 additions & 9 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,7 @@
"sucrase": "^3.32.0"
},
"browserslist": [
"chrome >= 103",
"firefox >= 102",
"defaults and supports css-variables and supports css-matches-pseudo",
"safari >= 14"
],
"jest": {
Expand Down
15 changes: 2 additions & 13 deletions src/cli/build/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,23 +28,12 @@ import { flagEnabled } from '../../featureFlags'

async function lightningcss(result, { map = true, minify = true } = {}) {
try {
let includeFeatures = Features.Nesting
let excludeFeatures = 0

let resolvedBrowsersListConfig = browserslist.findConfig(
result.opts.from ?? process.cwd()
)?.defaults
let defaultBrowsersListConfig = pkg.browserslist
let browsersListConfig = resolvedBrowsersListConfig ?? defaultBrowsersListConfig

if (browsersListConfig.join(',') === defaultBrowsersListConfig.join(',')) {
includeFeatures |=
Features.ColorFunction | Features.OklabColors | Features.LabColors | Features.P3Colors

excludeFeatures |=
Features.HexAlphaColors | Features.LogicalProperties | Features.SpaceSeparatedColorNotation
}

let transformed = lightning.transform({
filename: result.opts.from || 'input.css',
code: Buffer.from(result.css, 'utf-8'),
Expand All @@ -55,8 +44,8 @@ async function lightningcss(result, { map = true, minify = true } = {}) {
drafts: {
nesting: true,
},
include: includeFeatures,
exclude: excludeFeatures,
include: Features.Nesting,
exclude: Features.LogicalProperties,
})

return Object.assign(result, {
Expand Down
17 changes: 2 additions & 15 deletions src/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,25 +49,12 @@ module.exports = function tailwindcss(configOrPath) {
let intermediateMap = intermediateResult.map?.toJSON?.() ?? map

try {
let includeFeatures = Features.Nesting
let excludeFeatures = 0

let resolvedBrowsersListConfig = browserslist.findConfig(
result.opts.from ?? process.cwd()
)?.defaults
let defaultBrowsersListConfig = require('../package.json').browserslist
let browsersListConfig = resolvedBrowsersListConfig ?? defaultBrowsersListConfig

if (browsersListConfig.join(',') === defaultBrowsersListConfig.join(',')) {
includeFeatures |=
Features.ColorFunction | Features.OklabColors | Features.LabColors | Features.P3Colors

excludeFeatures |=
Features.HexAlphaColors |
Features.LogicalProperties |
Features.SpaceSeparatedColorNotation
}

let transformed = lightningcss.transform({
filename: result.opts.from,
code: Buffer.from(intermediateResult.css),
Expand All @@ -81,8 +68,8 @@ module.exports = function tailwindcss(configOrPath) {
nonStandard: {
deepSelectorCombinator: true,
},
include: includeFeatures,
exclude: excludeFeatures,
include: Features.Nesting,
exclude: Features.LogicalProperties,
})

let code = transformed.code.toString()
Expand Down
4 changes: 3 additions & 1 deletion tests/variants.test.css
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,9 @@
.marker\:flex::marker {
display: flex;
}
.selection\:flex ::selection,
.selection\:flex ::selection {
display: flex;
}
.selection\:flex::selection {
display: flex;
}
Expand Down

0 comments on commit 86f9c6f

Please sign in to comment.