Skip to content

Commit

Permalink
fix: Revert to 1.0.0 behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
Tyler Kellen authored and phated committed Nov 22, 2021
1 parent 3ec6058 commit 3fce7f2
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 37 deletions.
10 changes: 1 addition & 9 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,15 +1,7 @@
v1.0.2:
date: 2014-12-22
changes:
- Refactor for simplification of findConfig.
v1.0.1:
date: 2014-12-22
changes:
- Fix issue where user-specified configName is ignored.
v1.0.0:
date: 2014-12-16
changes:
- Update dependencies.
- Update dependencies
v0.13.6:
date: 2014-11-07
changes:
Expand Down
21 changes: 7 additions & 14 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,24 +55,17 @@ Liftoff.prototype.buildEnvironment = function (opts) {
searchPaths.unshift(cwd);
}

// a list of possible configuration names
var configNameSearch;

if (opts.configName) {
// if a configName has been provided by the user, only look for that
configNameSearch = [opts.configName];
} else {
// otherwise, look for the default configName using all available extensions
configNameSearch = buildConfigName({
configName: this.configName,
extensions: Object.keys(this.extensions)
});
}
// calculate the regex to use for finding the config file
var configNameSearch = buildConfigName({
configName: this.configName,
extensions: Object.keys(this.extensions)
});

// calculate configPath
var configPath = findConfig({
configNameSearch: configNameSearch,
searchPaths: searchPaths
searchPaths: searchPaths,
configPath: opts.configPath
});

// if we have a config path, save the directory it resides in.
Expand Down
16 changes: 10 additions & 6 deletions lib/find_config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,18 @@ const fileSearch = require('./file_search');
module.exports = function (opts) {
opts = opts || {};
var configNameSearch = opts.configNameSearch;
var configPath = opts.configPath;
var searchPaths = opts.searchPaths;
if (!Array.isArray(searchPaths)) {
throw new Error('Please provide an array of paths to search for config in.');
// only search for a config if a path to one wasn't explicitly provided
if (!configPath) {
if (!Array.isArray(searchPaths)) {
throw new Error('Please provide an array of paths to search for config in.');
}
if (!configNameSearch) {
throw new Error('Please provide a configNameSearch.');
}
configPath = fileSearch(configNameSearch, searchPaths);
}
if (!configNameSearch) {
throw new Error('Please provide a configNameSearch.');
}
var configPath = fileSearch(configNameSearch, searchPaths);
// confirm the configPath exists and return an absolute path to it
if (fs.existsSync(configPath)) {
return path.resolve(configPath);
Expand Down
10 changes: 2 additions & 8 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ describe('Liftoff', function () {
expect(app.buildEnvironment().cwd).to.equal(path.resolve('test/fixtures/search_path'));
});


it('should resolve symlinks if config is one', function () {
var env = app.buildEnvironment({
cwd: 'test/fixtures/symlink'
Expand All @@ -102,14 +103,7 @@ describe('Liftoff', function () {
configPath: 'test/fixtures/symlink/mochafile.js'
});
expect(env.cwd).to.equal(path.resolve('test/fixtures/symlink'));
});

it('should be able to find custom configuration file names', function () {
var env = app.buildEnvironment({
configName: 'myconfig.js'
});
expect(env.configNameSearch).to.deep.equal(['myconfig.js']);
});
})

});

Expand Down
6 changes: 6 additions & 0 deletions test/lib/find_config.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ describe('findConfig', function () {
expect(function(){findConfig({configNameRegex:'dude'});}).to.throw;
});

it('if configPath is explicitly provided, return the absolute path to the file or null if it doesn\'t actually exist', function () {
var configPath = path.resolve('test/fixtures/mochafile.js');
expect(findConfig({configPath:configPath})).to.equal(configPath);
expect(findConfig({configPath:'path/to/nowhere'})).to.equal(null);
});

it('should return the absolute path to the first config file found in searchPaths', function () {
expect(findConfig({
configNameSearch: ['mochafile.js', 'mochafile.coffee'],
Expand Down

0 comments on commit 3fce7f2

Please sign in to comment.