diff --git a/CHANGELOG.md b/CHANGELOG.md index 8a0dfba..f7ac67c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Changelog +## 0.2.2 (2018-09-12) +For hoast version 0.1.0. + +## Fixed +- `engine` parameter had critical error in asynchronous operation. + ## 0.2.1 (2018-09-12) For hoast version 0.1.0. diff --git a/index.js b/index.js index 4c05714..1aae556 100644 --- a/index.js +++ b/index.js @@ -39,18 +39,19 @@ module.exports = function(options) { return async function(hoast, files) { debug(`Running module.`); + let filtered; if (options.engine) { debug(`Using engine filter method.`); - Promise.all(files.map(function(file) { + await Promise.all(files.map(async function(file) { // First check nanomatch filter whether it should be filtered. if (options.patterns && nanomatch.any(file.path, options.patterns) === options.invert) { return true; } // Else use the specified engine function. - return options.engine(file); + return await options.engine(file); })).then(function(result) { - files = files.filter(function(file, index) { + filtered = files.filter(function(file, index) { return result[index]; }); }); @@ -58,13 +59,13 @@ module.exports = function(options) { debug(`Using standard filter method.`); // Filter using nanomatch based of patterns. - files = files.filter(function(file) { + filtered = files.filter(function(file) { debug(`Filtering file '${file.path}'.`); return nanomatch.any(file.path, options.patterns) ? !options.invert : options.invert; }); } debug(`Finished filtering files.`); - return files; + return filtered; }; }; \ No newline at end of file diff --git a/package.json b/package.json index f175863..aa5f282 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "author": "Ron Dekker", "name": "hoast-filter", - "version": "0.2.1", + "version": "0.2.2", "description": "Hoast module used to filter out files from further processing.", "license": "ISC", "keywords": [ diff --git a/test.js b/test.js index 0172b89..a7df2b3 100644 --- a/test.js +++ b/test.js @@ -4,7 +4,7 @@ const test = require(`ava`); const Filter = require(`.`); // Test patterns option with a string. -test(`pattern`, function(t) { +test(`pattern`, async function(t) { // Create dummy files. let files = [{ path: `a.txt` @@ -18,7 +18,7 @@ test(`pattern`, function(t) { }]; // Test module. - files = Filter({ + files = await Filter({ patterns: `**/*.txt` })({}, files); @@ -27,7 +27,7 @@ test(`pattern`, function(t) { }); // Test patterns option with an array. -test(`patterns`, function(t) { +test(`patterns`, async function(t) { // Create dummy files. let files = [{ path: `a.txt` @@ -45,7 +45,7 @@ test(`patterns`, function(t) { }]; // Test module. - files = Filter({ + files = await Filter({ patterns: [ `**/*.txt`, `**/*.md` @@ -57,7 +57,7 @@ test(`patterns`, function(t) { }); // Test invert option. -test(`invert`, function(t) { +test(`invert`, async function(t) { // Create dummy files. let files = [{ path: `a.txt` @@ -73,7 +73,7 @@ test(`invert`, function(t) { }]; // Test module. - files = Filter({ + files = await Filter({ invert: true, patterns: [ `**/*.txt`, @@ -86,7 +86,7 @@ test(`invert`, function(t) { }); // Test engine option. -test(`engine`, function(t) { +test(`engine`, async function(t) { // Create dummy files. let files = [{ path: `a.txt` @@ -102,7 +102,7 @@ test(`engine`, function(t) { }]; // Test module. - files = Filter({ + files = await Filter({ engine: function(file) { return file.path === `a.txt`; } @@ -113,7 +113,7 @@ test(`engine`, function(t) { }); // Test engine option in combination with a pattern. -test(`engine-pattern`, function(t) { +test(`engine-pattern`, async function(t) { // Create dummy files. let files = [{ path: `a.txt` @@ -131,7 +131,7 @@ test(`engine-pattern`, function(t) { }]; // Test module. - files = Filter({ + files = await Filter({ engine: function(file) { return file.path === `a.txt`; }, @@ -143,7 +143,7 @@ test(`engine-pattern`, function(t) { }); // Test engine option in combination with an inverted pattern. -test(`engine-invert`, function(t) { +test(`engine-invert`, async function(t) { // Create dummy files. let files = [{ path: `a.txt` @@ -161,7 +161,7 @@ test(`engine-invert`, function(t) { }]; // Test module. - files = Filter({ + files = await Filter({ engine: function(file) { return file.path === `b.md`; },