-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
3 changed files
with
71 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,49 @@ | ||
export const env = { | ||
TAILWIND_MODE: process.env.TAILWIND_MODE, | ||
NODE_ENV: process.env.NODE_ENV, | ||
DEBUG: process.env.DEBUG !== undefined && process.env.DEBUG !== '0', | ||
DEBUG: resolveDebug(process.env.DEBUG), | ||
TAILWIND_DISABLE_TOUCH: process.env.TAILWIND_DISABLE_TOUCH !== undefined, | ||
TAILWIND_TOUCH_DIR: process.env.TAILWIND_TOUCH_DIR, | ||
} | ||
export const contextMap = new Map() | ||
export const configContextMap = new Map() | ||
export const contextSourcesMap = new Map() | ||
|
||
export function resolveDebug(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 tailwind / tailwindcss | ||
if (debuggers.includes('-tailwindcss') || debuggers.includes('-tailwind')) { | ||
return false | ||
} | ||
|
||
// Definitely including tailwind / tailwindcss | ||
if (debuggers.includes('tailwindcss') || debuggers.includes('tailwind')) { | ||
return true | ||
} | ||
|
||
return false | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { resolveDebug } from '../src/lib/sharedState' | ||
|
||
it.each` | ||
value | expected | ||
${'true'} | ${true} | ||
${'1'} | ${true} | ||
${'false'} | ${false} | ||
${'0'} | ${false} | ||
${'*'} | ${true} | ||
${'tailwind'} | ${true} | ||
${'tailwind:*'} | ${true} | ||
${'tailwindcss'} | ${true} | ||
${'tailwindcss:*'} | ${true} | ||
${'other,tailwind'} | ${true} | ||
${'other,tailwind:*'} | ${true} | ||
${'other,tailwindcss'} | ${true} | ||
${'other,tailwindcss:*'} | ${true} | ||
${'other,-tailwind'} | ${false} | ||
${'other,-tailwind:*'} | ${false} | ||
${'other,-tailwindcss'} | ${false} | ||
${'other,-tailwindcss:*'} | ${false} | ||
${'-tailwind'} | ${false} | ||
${'-tailwind:*'} | ${false} | ||
${'-tailwindcss'} | ${false} | ||
${'-tailwindcss:*'} | ${false} | ||
`('should resolve the debug ($value) flag correctly ($expected)', ({ value, expected }) => { | ||
expect(resolveDebug(value)).toBe(expected) | ||
}) |