Skip to content
This repository was archived by the owner on Sep 21, 2022. It is now read-only.

Commit 8e6bf55

Browse files
author
Alexandr Ishchenko
committed
Changed require configuration to path relative to current working directory
For example working directory is `/home/foo/project_with_gemini/gemini/`. We use js or json default path configuration or use `-c` option. Run `./gemini` or `./gemini -c .very_special_configuration.json`. And we get configuration relative to current working directory: /home/foo/project_with_gemini/gemini/.gemini.conf.json /home/foo/project_with_gemini/gemini/.gemini.conf.js /home/foo/project_with_gemini/gemini/.very_special_configuration.json not in directory anywhere in the node_modules. Fixed #418.
1 parent d11c52c commit 8e6bf55

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

lib/config/index.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,11 @@ function getDefaultConfig() {
8181

8282
function requireModule(file) {
8383
try {
84-
return require(file);
84+
if (file.indexOf('./') === 0 || file.indexOf('/') !== 0) {
85+
return require(process.cwd() + '/' + file);
86+
} else {
87+
return require(file);
88+
}
8589
} catch (e) {
8690
if (e.code === 'MODULE_NOT_FOUND') {
8791
throw new GeminiError('Config file does not exist: ' + file);

test/functional/config.test.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,16 @@ describe('config', function() {
5151
return new Config(configPath('notExists.js'));
5252
}, GeminiError);
5353
});
54+
55+
it('should read relative to current working directory', function() {
56+
assert.deepPropertyVal(
57+
new Config(configPath('validConfig.js').replace(process.cwd() + '/', '')),
58+
'system.projectRoot', '/it/works');
59+
60+
assert.deepPropertyVal(
61+
new Config(configPath('validConfig.js').replace(process.cwd() + '/', './')),
62+
'system.projectRoot', '/it/works');
63+
});
5464
});
5565

5666
describe('.json', function() {
@@ -64,6 +74,16 @@ describe('config', function() {
6474
return new Config(configPath('notExists.json'));
6575
}, GeminiError);
6676
});
77+
78+
it('should read relative to current working directory', function() {
79+
assert.deepPropertyVal(
80+
new Config(configPath('validConfig.json').replace(process.cwd() + '/', '')),
81+
'system.projectRoot', '/it/works');
82+
83+
assert.deepPropertyVal(
84+
new Config(configPath('validConfig.json').replace(process.cwd() + '/', './')),
85+
'system.projectRoot', '/it/works');
86+
});
6787
});
6888
});
6989
});

0 commit comments

Comments
 (0)