Skip to content

Commit

Permalink
sync with Haraka & lint updates (#14)
Browse files Browse the repository at this point in the history
* config: add overrides handling (sync with Haraka)
* configfile: add win64 watching (sync with Haraka)
* remove grunt
* use haraka-eslint plugin (vs local copy of .eslintrc)
* lint updates
  • Loading branch information
msimerson committed Jan 27, 2017
1 parent 87d0107 commit 5bbadcd
Show file tree
Hide file tree
Showing 13 changed files with 62 additions and 90 deletions.
24 changes: 4 additions & 20 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,26 +1,10 @@
{
"env": {
"node": true,
"mocha": true
},
"extends": "eslint:recommended",
"plugins": [
"haraka"
],
"installedESLint": true,
"root": true,
"extends": ["eslint:recommended", "plugin:haraka/recommended"],
"rules": {
"comma-dangle": [2, "only-multiline"],
"dot-notation": 2,
"indent": [2, 4, {"SwitchCase": 1}],
"one-var": [2, "never"],
"no-trailing-spaces": [2, { "skipBlankLines": false }],
"keyword-spacing": [2, {
"before": true,
"after": true
}],
"no-delete-var": 2,
"no-empty": ["error", { "allowEmptyCatch": true }],
"no-label-var": 2,
"no-shadow": 2,
"no-unused-vars": [ 1, { "args": "none" }],
"no-console": 0
}
}
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ node_js:
- "6"

before_script:
# - npm install -g grunt-cli

script:
- npm run lint
Expand Down
11 changes: 8 additions & 3 deletions Changes.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@

# 1.0.9 - 2017-__-__
# 1.0.9 - 2017-01-27

* config cache fix (see haraka/Haraka#1738)
- config cache fix (see haraka/Haraka#1738)
- config: add overrides handling (sync with Haraka)
- configfile: add win64 watching (sync with Haraka)
- remove grunt
- use haraka-eslint plugin (vs local copy of .eslintrc)
- lint updates

# 1.0.8 - 2017-01-02

Expand All @@ -20,7 +25,7 @@

* do not leave behind a `*` section in config (due to wildcard boolean)

# 1.0.3
# 1.0.3

* added wildcard boolean support
* reduce node required 4.3 -> 0.10.43
22 changes: 0 additions & 22 deletions Gruntfile.js

This file was deleted.

1 change: 0 additions & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ install:
- ps: Install-Product node $env:nodejs_version
# install modules
- npm install
- npm install -g grunt-cli

# Post-install test scripts.
test_script:
Expand Down
11 changes: 7 additions & 4 deletions config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,19 @@ var cfreader = require('./configfile');

module.exports = new Config();

function Config (root_path) {
function Config (root_path, no_overrides) {
this.root_path = root_path || cfreader.config_path;
// console.log('root_path: ' + this.root_path);
this.module_config = function (defaults_path, overrides_path) {
var cfg = new Config(path.join(defaults_path, 'config'));
var cfg = new Config(path.join(defaults_path, 'config'), true);
if (overrides_path) {
cfg.overrides_path = path.join(overrides_path, 'config');
}
return cfg;
};
if (process.env.HARAKA && !no_overrides) {
this.overrides_path = root_path || cfreader.config_path;
this.root_path = path.join(process.env.HARAKA, 'config');
}
}

Config.prototype.get = function (name, type, cb, options) {
Expand Down Expand Up @@ -47,7 +50,7 @@ function merge_config (defaults, overrides, type) {
return merge_struct(JSON.parse(JSON.stringify(defaults)), overrides);
}
else if (Array.isArray(overrides) && Array.isArray(defaults) &&
overrides.length > 0) {
overrides.length > 0) {
return overrides;
}
else if (overrides != null) {
Expand Down
42 changes: 23 additions & 19 deletions configfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,15 @@ var regex = exports.regex = {

var cfreader = exports;

cfreader.watch_files = true;
cfreader._config_cache = {};
cfreader._read_args = {};
cfreader._watchers = {};
cfreader._enoent_timer = false;
cfreader._enoent_files = {};
cfreader._sedation_timers = {};
cfreader._overrides = {};

var config_dir_candidates = [
path.join(__dirname, 'config'), // Haraka ./config dir
__dirname, // npm packaged plugins
Expand All @@ -44,11 +53,12 @@ function get_path_to_config_dir () {
return;
}

for (var i=0; i < config_dir_candidates.length; i++) {
for (let i=0; i < config_dir_candidates.length; i++) {
let candidate = config_dir_candidates[i];
try {
var stat = fs.statSync(config_dir_candidates[i]);
var stat = fs.statSync(candidate);
if (stat && stat.isDirectory()) {
cfreader.config_path = config_dir_candidates[i];
cfreader.config_path = candidate;
return;
}
}
Expand All @@ -60,15 +70,6 @@ function get_path_to_config_dir () {
get_path_to_config_dir();
// console.log('cfreader.config_path: ' + cfreader.config_path);

cfreader.watch_files = true;
cfreader._config_cache = {};
cfreader._read_args = {};
cfreader._watchers = {};
cfreader._enoent_timer = false;
cfreader._enoent_files = {};
cfreader._sedation_timers = {};
cfreader._overrides = {};

cfreader.on_watch_event = function (name, type, options, cb) {
return function (fse, filename) {
if (cfreader._sedation_timers[name]) {
Expand Down Expand Up @@ -179,7 +180,7 @@ cfreader.get_cache_key = function (name, options) {
return result;
};

cfreader.read_config = function(name, type, cb, options) {
cfreader.read_config = function (name, type, cb, options) {
// Store arguments used so we can re-use them by filename later
// and so we know which files we've attempted to read so that
// we can ignore any other files written to the same directory.
Expand All @@ -206,14 +207,17 @@ cfreader.read_config = function(name, type, cb, options) {

// We can watch the directory on these platforms which
// allows us to notice when files are newly created.
var os = process.platform;
if (os === 'linux' || os === 'win32') {
cfreader.watch_dir();
return result;
switch (process.platform) {
case 'win32':
case 'win64':
case 'linux':
cfreader.watch_dir();
break;
default:
// All other operating systems
cfreader.watch_file(name, type, cb, options);
}

// All other operating systems
cfreader.watch_file(name, type, cb, options);
return result;
};

Expand Down
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"name": "haraka-config",
"license": "MIT",
"description": "Haraka's config file loader",
"version": "1.0.8",
"version": "1.0.9",
"homepage": "http://haraka.github.io",
"repository": {
"type": "git",
Expand All @@ -19,8 +19,7 @@
"optionalDependencies": {},
"devDependencies": {
"eslint": "*",
"grunt": "*",
"grunt-eslint": "*",
"eslint-plugin-haraka": "*",
"nodeunit": "*"
},
"bugs": {
Expand All @@ -29,7 +28,8 @@
},
"scripts": {
"test": "./run_tests",
"lint": "./node_modules/.bin/grunt lint",
"lint": "./node_modules/.bin/eslint *.js test/**/*.js",
"lintfix": "./node_modules/.bin/eslint --fix *.js test/**/*.js",
"cover": "./node_modules/.bin/istanbul cov run_tests"
}
}
6 changes: 3 additions & 3 deletions test/readers/binary.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ exports.load = {
test.ok(this.bin);
test.done();
},
'has a load function': function(test) {
'has a load function': function (test) {
test.expect(1);
test.ok(typeof this.bin.load === 'function');
test.done();
},
'throws when file is non-existent': function(test) {
'throws when file is non-existent': function (test) {
test.expect(2);
try {
this.bin.load('test/config/non-existent.bin');
Expand All @@ -30,7 +30,7 @@ exports.load = {
}
test.done();
},
'loads the test binary file': function(test) {
'loads the test binary file': function (test) {
test.expect(3);
var testBin = 'test/config/test.binary';
var result = this.bin.load(testBin);
Expand Down
10 changes: 5 additions & 5 deletions test/readers/flat.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ exports.load = {
test.ok(this.flat);
test.done();
},
'has a load function': function(test) {
'has a load function': function (test) {
test.expect(1);
test.ok(typeof this.flat.load === 'function');
test.done();
},
'throws when file is non-existent': function(test) {
'throws when file is non-existent': function (test) {
test.expect(2);
try {
this.flat.load('test/config/non-existent.flat');
Expand All @@ -30,21 +30,21 @@ exports.load = {
}
test.done();
},
'loads the test flat file, as list': function(test) {
'loads the test flat file, as list': function (test) {
test.expect(1);
var result = this.flat.load(
'test/config/test.flat', 'list', null, regex);
test.deepEqual(result, [ 'line1', 'line2', 'line3', 'line5' ]);
test.done();
},
'loads the test flat file, unspecified type': function(test) {
'loads the test flat file, unspecified type': function (test) {
test.expect(1);
var result = this.flat.load(
'test/config/test.flat', null, null, regex);
test.deepEqual(result, 'line1');
test.done();
},
'returns hostname for empty "me"': function(test) {
'returns hostname for empty "me"': function (test) {
test.expect(1);
var result = this.flat.load( 'test/config/me', null, null, regex);
console.log(result);
Expand Down
4 changes: 2 additions & 2 deletions test/readers/ini.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ exports.load = {
test.ok(this.ini);
test.done();
},
'has a load function': function(test) {
'has a load function': function (test) {
test.expect(1);
test.ok(typeof this.ini.load === 'function');
test.done();
},
'loads the test ini file': function(test) {
'loads the test ini file': function (test) {
test.expect(1);
var result = this.ini.load('test/config/test.ini', {}, regex);
// console.log(result);
Expand Down
6 changes: 3 additions & 3 deletions test/readers/json.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ exports.load = {
test.ok(this.json);
test.done();
},
'has a load function': function(test) {
'has a load function': function (test) {
test.expect(1);
test.ok(typeof this.json.load === 'function');
test.done();
},
'throws when file is non-existent': function(test) {
'throws when file is non-existent': function (test) {
test.expect(2);
try {
this.json.load('test/config/non-existent.json');
Expand All @@ -28,7 +28,7 @@ exports.load = {
}
test.done();
},
'loads the test JSON file': function(test) {
'loads the test JSON file': function (test) {
test.expect(3);
var result = this.json.load('test/config/test.json');
// console.log(result);
Expand Down
6 changes: 3 additions & 3 deletions test/readers/yaml.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ exports.load = {
test.ok(this.yaml);
test.done();
},
'has a load function': function(test) {
'has a load function': function (test) {
test.expect(1);
test.ok(typeof this.yaml.load === 'function');
test.done();
},
'throws when file is non-existent': function(test) {
'throws when file is non-existent': function (test) {
test.expect(2);
try {
this.yaml.load('test/config/non-existent.haml');
Expand All @@ -28,7 +28,7 @@ exports.load = {
}
test.done();
},
'loads the test yaml file': function(test) {
'loads the test yaml file': function (test) {
test.expect(4);
var result = this.yaml.load('test/config/test.yaml');
// console.log(result);
Expand Down

0 comments on commit 5bbadcd

Please sign in to comment.