Skip to content

Commit

Permalink
Fix @tailwindcss/line-clamp warning (#10919)
Browse files Browse the repository at this point in the history
* WIP

* Move warning to validateConfig

This only happens in setupTrackingContext outside of resolveConfig

* Use original dynamic require approach in `validateConfig`

The important thing is that this happens in Node-land only. It is outside of `resolveConfig` which is public and importable into user projects. That is the scenario that breaks because of static import hoisting.

* Don’t reference process when it might be undefined

The `resolveConfig` dep path is public which should not reference process. However, we have some behavior that changes based on env vars so we need to conditionalize it instead.

* Update changelog

* Formatting

* More formatting

* Update changelog

---------

Co-authored-by: Robin Malfait <malfait.robin@gmail.com>
Co-authored-by: Jonathan Reinink <jonathan@reinink.ca>
  • Loading branch information
3 people committed Mar 30, 2023
1 parent 8a0d1b9 commit 50174f9
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 7 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Try resolving `config.default` before `config` to ensure the config file is resolved correctly ([#10898](https://github.com/tailwindlabs/tailwindcss/pull/10898))
- Pull pseudo elements outside of `:is` and `:has` when using `@apply` ([#10903](https://github.com/tailwindlabs/tailwindcss/pull/10903))
- Update the types for the `safelist` config ([#10901](https://github.com/tailwindlabs/tailwindcss/pull/10901))
- Drop `@tailwindcss/line-clamp` warning ([#10915](https://github.com/tailwindlabs/tailwindcss/pull/10915))
- Fix `@tailwindcss/line-clamp` warning ([#10915](https://github.com/tailwindlabs/tailwindcss/pull/10915), [#10919](https://github.com/tailwindlabs/tailwindcss/pull/10919))
- Fix `process` is not defined error ([#10919](https://github.com/tailwindlabs/tailwindcss/pull/10919))

## [3.3.0] - 2023-03-27

Expand Down
21 changes: 15 additions & 6 deletions src/lib/sharedState.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,21 @@
import pkg from '../../package.json'
let OXIDE_DEFAULT_ENABLED = pkg.tailwindcss.engine === 'oxide'

export const env = {
NODE_ENV: process.env.NODE_ENV,
DEBUG: resolveDebug(process.env.DEBUG),
ENGINE: pkg.tailwindcss.engine,
OXIDE: resolveBoolean(process.env.OXIDE, OXIDE_DEFAULT_ENABLED),
}
export const env =
typeof process !== 'undefined'
? {
NODE_ENV: process.env.NODE_ENV,
DEBUG: resolveDebug(process.env.DEBUG),
ENGINE: pkg.tailwindcss.engine,
OXIDE: resolveBoolean(process.env.OXIDE, OXIDE_DEFAULT_ENABLED),
}
: {
NODE_ENV: 'production',
DEBUG: false,
ENGINE: pkg.tailwindcss.engine,
OXIDE: OXIDE_DEFAULT_ENABLED,
}

export const contextMap = new Map()
export const configContextMap = new Map()
export const contextSourcesMap = new Map()
Expand Down
13 changes: 13 additions & 0 deletions src/util/validateConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,18 @@ export function validateConfig(config) {
])
}

// Warn if the line-clamp plugin is installed
try {
let plugin = require('@tailwindcss/line-clamp')
if (config.plugins.includes(plugin)) {
log.warn('line-clamp-in-core', [
'As of Tailwind CSS v3.3, the `@tailwindcss/line-clamp` plugin is now included by default.',
'Remove it from the `plugins` array in your configuration to eliminate this warning.',
])

config.plugins = config.plugins.filter((p) => p !== plugin)
}
} catch {}

return config
}

0 comments on commit 50174f9

Please sign in to comment.