From 474178055eb67336d7d4a158a394b048faa3cf10 Mon Sep 17 00:00:00 2001 From: Jordan Pittman Date: Thu, 30 Mar 2023 15:06:17 -0400 Subject: [PATCH] Fix `@tailwindcss/line-clamp` warning (#10919) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 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 Co-authored-by: Jonathan Reinink --- CHANGELOG.md | 3 ++- src/lib/sharedState.js | 21 +++++++++++++++------ src/util/validateConfig.js | 13 +++++++++++++ 3 files changed, 30 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1b4082780..50b2fc77d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,7 +12,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 diff --git a/src/lib/sharedState.js b/src/lib/sharedState.js index 736a5d8bc..1a4a8d5e5 100644 --- a/src/lib/sharedState.js +++ b/src/lib/sharedState.js @@ -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() diff --git a/src/util/validateConfig.js b/src/util/validateConfig.js index 23b4627fb..8c22e4450 100644 --- a/src/util/validateConfig.js +++ b/src/util/validateConfig.js @@ -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 }