From 3f0a3521c14d424bc594e93f8a652c61a2fe2d1f Mon Sep 17 00:00:00 2001 From: Thiago da Rosa de Bustamante Date: Wed, 28 Mar 2018 19:06:23 -0300 Subject: [PATCH] Fix the search for ioc.config file --- src/index.ts | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/src/index.ts b/src/index.ts index c36721f..af0beb2 100644 --- a/src/index.ts +++ b/src/index.ts @@ -4,11 +4,24 @@ const isBrowser = new Function('try {return this===window;}catch(e){return false let useES6 = false; if (!isBrowser()) { - const fs = require('fs'); useES6 = process.env.ES6 === 'true'; if (!useES6) { - const CONFIG_FILE = process.cwd() + '/ioc.config'; - if (fs.existsSync(CONFIG_FILE)) { + const fs = require('fs'); + const path = require('path'); + const searchConfigFile = function() { + let configFile = path.join(__dirname, 'ioc.config'); + const ROOT = path.join('/', 'ioc.config'); + while (!fs.existsSync(configFile)) { + if (configFile === ROOT) { + return null; + } + configFile = path.normalize(path.join(path.dirname(configFile), '..', 'ioc.config')); + } + return configFile; + }; + + const CONFIG_FILE = searchConfigFile(); + if (CONFIG_FILE && fs.existsSync(CONFIG_FILE)) { const config = JSON.parse(fs.readFileSync(CONFIG_FILE)); if (config.es6) { useES6 = true;