|
1 | 1 | export const env = {
|
2 | 2 | TAILWIND_MODE: process.env.TAILWIND_MODE,
|
3 | 3 | NODE_ENV: process.env.NODE_ENV,
|
4 |
| - DEBUG: process.env.DEBUG !== undefined && process.env.DEBUG !== '0', |
| 4 | + DEBUG: resolveDebug(process.env.DEBUG), |
5 | 5 | TAILWIND_DISABLE_TOUCH: process.env.TAILWIND_DISABLE_TOUCH !== undefined,
|
6 | 6 | TAILWIND_TOUCH_DIR: process.env.TAILWIND_TOUCH_DIR,
|
7 | 7 | }
|
8 | 8 | export const contextMap = new Map()
|
9 | 9 | export const configContextMap = new Map()
|
10 | 10 | export const contextSourcesMap = new Map()
|
| 11 | + |
| 12 | +export function resolveDebug(debug) { |
| 13 | + if (debug === undefined) { |
| 14 | + return false |
| 15 | + } |
| 16 | + |
| 17 | + // Environment variables are strings, so convert to boolean |
| 18 | + if (debug === 'true' || debug === '1') { |
| 19 | + return true |
| 20 | + } |
| 21 | + |
| 22 | + if (debug === 'false' || debug === '0') { |
| 23 | + return false |
| 24 | + } |
| 25 | + |
| 26 | + // Keep the debug convention into account: |
| 27 | + // DEBUG=* -> This enables all debug modes |
| 28 | + // DEBUG=projectA,projectB,projectC -> This enables debug for projectA, projectB and projectC |
| 29 | + // DEBUG=projectA:* -> This enables all debug modes for projectA (if you have sub-types) |
| 30 | + // DEBUG=projectA,-projectB -> This enables debug for projectA and explicitly disables it for projectB |
| 31 | + |
| 32 | + if (debug === '*') { |
| 33 | + return true |
| 34 | + } |
| 35 | + |
| 36 | + let debuggers = debug.split(',').map((d) => d.split(':')[0]) |
| 37 | + |
| 38 | + // Ignoring tailwind / tailwindcss |
| 39 | + if (debuggers.includes('-tailwindcss') || debuggers.includes('-tailwind')) { |
| 40 | + return false |
| 41 | + } |
| 42 | + |
| 43 | + // Definitely including tailwind / tailwindcss |
| 44 | + if (debuggers.includes('tailwindcss') || debuggers.includes('tailwind')) { |
| 45 | + return true |
| 46 | + } |
| 47 | + |
| 48 | + return false |
| 49 | +} |
0 commit comments