Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
port env.DEBUG from v3
  • Loading branch information
RobinMalfait committed Sep 30, 2024
commit 8accc9c048f2765f8a485a6f0467414560af1066
40 changes: 40 additions & 0 deletions packages/tailwindcss/src/env.ts
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What are your thoughts of moving this into the node specific library instead? This way we don't need to be too defensive with accessing process.env and we can use a proper export for the three clients instead of having to rely on private bundled imports:

import * as env from '../../tailwindcss/src/env'

Could also be maybe a tailwindcss-shared private package that we only use for this. It just seems strange that this file is in the tailwindcss package but not part of the released tailwindcss npm package at all

Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
export const DEBUG = typeof process !== 'undefined' ? resolveDebug(process.env.DEBUG) : false

function resolveDebug(debug: typeof process.env.DEBUG) {
if (debug === undefined) {
return false
}

// Environment variables are strings, so convert to boolean
if (debug === 'true' || debug === '1') {
return true
}

if (debug === 'false' || debug === '0') {
return false
}

// Keep the debug convention into account:
// DEBUG=* -> This enables all debug modes
// DEBUG=projectA,projectB,projectC -> This enables debug for projectA, projectB and projectC
// DEBUG=projectA:* -> This enables all debug modes for projectA (if you have sub-types)
// DEBUG=projectA,-projectB -> This enables debug for projectA and explicitly disables it for projectB

if (debug === '*') {
return true
}

let debuggers = debug.split(',').map((d) => d.split(':')[0])

// Ignoring tailwindcss
if (debuggers.includes('-tailwindcss')) {
return false
}

// Including tailwindcss
if (debuggers.includes('tailwindcss')) {
return true
}

return false
}