1414// TODO locale for validation messages
1515
1616const { promisify } = require ( "util" ) ;
17- const path = require ( "path" ) ;
17+ const pathlib = require ( "path" ) ;
1818const { readFile } = require ( "fs" ) ;
1919const VError = require ( "verror" ) ;
2020const yaml = require ( "yaml" ) ;
@@ -31,7 +31,7 @@ const { Semaphore } = require("./shared/semaphore");
3131const ENV_UNIQUE_NAME = process . env [ ENV . UNIQUE_NAME ] ;
3232const DEFAULT_REDIS_CHANNEL = process . env [ ENV . REDIS_CHANNEL ] || "features" ;
3333const DEFAULT_REDIS_KEY = process . env [ ENV . REDIS_KEY ] || "features" ;
34- const DEFAULT_CONFIG_FILEPATH = path . join ( process . cwd ( ) , ".features.yaml" ) ;
34+ const DEFAULT_CONFIG_FILEPATH = pathlib . join ( process . cwd ( ) , ".features.yaml" ) ;
3535const FEATURE_VALID_TYPES = [ "string" , "number" , "boolean" ] ;
3636
3737const SUPER_SCOPE_CACHE_SIZE_LIMIT = 15 ;
@@ -110,8 +110,7 @@ class FeatureToggles {
110110 // ========================================
111111
112112 _processValidations ( featureKey , validations , configFilepath ) {
113- const workingDir = process . cwd ( ) ;
114- const configDir = configFilepath ? path . dirname ( configFilepath ) : workingDir ;
113+ const configDir = configFilepath ? pathlib . dirname ( configFilepath ) : process . cwd ( ) ;
115114
116115 const validationsScopesMap = { } ;
117116 const validationsRegex = [ ] ;
@@ -130,15 +129,9 @@ class FeatureToggles {
130129 }
131130
132131 if ( validation . module ) {
133- let modulePath = validation . module . replace ( "$CONFIG_DIR" , configDir ) ;
134- if ( ! path . isAbsolute ( modulePath ) ) {
135- modulePath = path . join ( workingDir , modulePath ) ;
136- }
137- let validator = tryRequire ( modulePath ) ;
138-
139- if ( validation . call ) {
140- validator = validator ?. [ validation . call ] ;
141- }
132+ const modulePath = validation . module . replace ( "$CONFIG_DIR" , configDir ) ;
133+ const validatorModule = tryRequire ( pathlib . resolve ( modulePath ) ) ;
134+ const validator = validation . call ? validatorModule ?. [ validation . call ] : validatorModule ;
142135
143136 const validatorType = typeof validator ;
144137 if ( validatorType === "function" ) {
0 commit comments