Skip to content

script-utils/env-toggle

Shared environment-variable off switches for the CLI scripts.

Every npm script can be skipped by setting an environment variable named after it — the script name uppercased, with every non-alphanumeric character replaced by _:

| Script | Switch | |---------------------|---------------------| | lint | LINT=0 | | lint:md:fix | LINT_MD_FIX=0 | | format:check | FORMAT_CHECK=0 | | find-overexposed | FIND_OVEREXPOSED=0|

This mirrors the pre-existing NANO_STAGED=0 / HUSKY=0 escape hatches, and reuses their notion of an “off” value, so there is a single answer to what counts as off across the whole tool set.

FunctionDescription
getDisabledScriptEnvVariableNameResolves the off switch for the npm script that is currently running, loading ENV_FILE_PATH first. The script name comes from npm itself, so no script has to declare its own switch. When the script was started directly rather than through npm, there is no name to derive from and nothing is ever skipped.
isEnvVariableOffDetermines whether the environment variable is set to an off value (0, false, no, or off, case-insensitively and ignoring surrounding whitespace).
loadEnvFileIfExistsLoads the optional ENV_FILE_PATH file into process.env when it exists, so a developer can park a switch such as LINT_MD=0 there instead of prefixing every command.