Ensure configuration options, flags, and environment settings are handled consistently across all commands and modules. This includes supporting the same configuration flags across CLI commands, using standardized approaches for environment detection, and implementing clear precedence rules.
Ensure configuration options, flags, and environment settings are handled consistently across all commands and modules. This includes supporting the same configuration flags across CLI commands, using standardized approaches for environment detection, and implementing clear precedence rules.
Key principles:
--config
flag)__DEV__
) instead of runtime environment checks (process.env.NODE_ENV
) for library codeExample of good configuration precedence:
function resolveRootDirectory(root?: string, flags?: { config?: string }) {
if (root) {
return path.resolve(root); // Explicit root takes precedence
}
// Fall back to inferring from config file location
return inferRootFromConfig(flags?.config);
}
Example of consistent environment handling:
// Good: Build-time constant for libraries
if (__DEV__ && !alreadyWarned[message]) {
console.warn(message);
}
// Good: Runtime environment for CLI tools
process.env.NODE_ENV = process.env.NODE_ENV ??
(command === "dev" ? "development" : "production");
This ensures predictable behavior and reduces confusion when the same configuration concepts are used in different parts of the system.
Enter the URL of a public GitHub repository