Skip to content

Commit bd44274

Browse files
committed
Make Config an ES2015 class.
1 parent 57aafc8 commit bd44274

File tree

1 file changed

+29
-27
lines changed

1 file changed

+29
-27
lines changed

lib/Config.js

Lines changed: 29 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -3,33 +3,35 @@
33
const path = require('path');
44
const debug = require('debug')('tree');
55

6-
function Config(options) {
7-
this.filename = options.filename;
8-
this.directory = options.directory || options.root;
9-
this.visited = options.visited || {};
10-
this.nonExistent = options.nonExistent || [];
11-
this.isListForm = options.isListForm;
12-
this.requireConfig = options.config || options.requireConfig;
13-
this.webpackConfig = options.webpackConfig;
14-
this.nodeModulesConfig = options.nodeModulesConfig;
15-
this.detectiveConfig = options.detective || options.detectiveConfig || {};
16-
17-
this.filter = options.filter;
18-
19-
if (!this.filename) { throw new Error('filename not given'); }
20-
if (!this.directory) { throw new Error('directory not given'); }
21-
if (this.filter && typeof this.filter !== 'function') { throw new Error('filter must be a function'); }
22-
23-
debug('given filename: ' + this.filename);
24-
25-
this.filename = path.resolve(process.cwd(), this.filename);
26-
27-
debug('resolved filename: ' + this.filename);
28-
debug('visited: ', this.visited);
6+
class Config {
7+
constructor(options) {
8+
this.filename = options.filename;
9+
this.directory = options.directory || options.root;
10+
this.visited = options.visited || {};
11+
this.nonExistent = options.nonExistent || [];
12+
this.isListForm = options.isListForm;
13+
this.requireConfig = options.config || options.requireConfig;
14+
this.webpackConfig = options.webpackConfig;
15+
this.nodeModulesConfig = options.nodeModulesConfig;
16+
this.detectiveConfig = options.detective || options.detectiveConfig || {};
17+
18+
this.filter = options.filter;
19+
20+
if (!this.filename) { throw new Error('filename not given'); }
21+
if (!this.directory) { throw new Error('directory not given'); }
22+
if (this.filter && typeof this.filter !== 'function') { throw new Error('filter must be a function'); }
23+
24+
debug('given filename: ' + this.filename);
25+
26+
this.filename = path.resolve(process.cwd(), this.filename);
27+
28+
debug('resolved filename: ' + this.filename);
29+
debug('visited: ', this.visited);
30+
}
31+
32+
clone () {
33+
return new Config(this);
34+
}
2935
}
3036

31-
Config.prototype.clone = function() {
32-
return new Config(this);
33-
};
34-
3537
module.exports = Config;

0 commit comments

Comments
 (0)