From 3531b98e2b647128518c7d48b0b0d4585b51fa0a Mon Sep 17 00:00:00 2001 From: Nazar Hussain Date: Sun, 4 Feb 2018 01:36:35 +0100 Subject: [PATCH 1/3] Add feature to look for pre-initialized fittings modules before going to look into filesystem --- lib/fittingTypes/user.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lib/fittingTypes/user.js b/lib/fittingTypes/user.js index 3b68179..81e54e2 100644 --- a/lib/fittingTypes/user.js +++ b/lib/fittingTypes/user.js @@ -10,6 +10,12 @@ module.exports = function createFitting(pipes, fittingDef) { assert(fittingDef.name, util.format('name is required on fitting: %j', fittingDef)); if (!pipes.config.userFittingsDirs) { return null; } + // If there is pre-initialized fittings modules available, return these + if (pipes.config.fittings && pipes.config.fittings[fittingDef.name]) { + debug('loaded user fitting %s from pre-initialized modules', fittingDef.name); + return pipes.config.fittings[fittingDef.name](fittingDef, pipes); + } + for (var i = 0; i < pipes.config.userFittingsDirs.length; i++) { var dir = pipes.config.userFittingsDirs[i]; From 70232300f5fce9b0069bf1e0d88f16db2d0b07e0 Mon Sep 17 00:00:00 2001 From: Nazar Hussain Date: Fri, 29 Jun 2018 09:55:48 +0200 Subject: [PATCH 2/3] Fix the order or intialization for user fittings --- lib/fittingTypes/user.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/fittingTypes/user.js b/lib/fittingTypes/user.js index 81e54e2..dfff512 100644 --- a/lib/fittingTypes/user.js +++ b/lib/fittingTypes/user.js @@ -8,7 +8,6 @@ var assert = require('assert'); module.exports = function createFitting(pipes, fittingDef) { assert(fittingDef.name, util.format('name is required on fitting: %j', fittingDef)); - if (!pipes.config.userFittingsDirs) { return null; } // If there is pre-initialized fittings modules available, return these if (pipes.config.fittings && pipes.config.fittings[fittingDef.name]) { @@ -16,6 +15,8 @@ module.exports = function createFitting(pipes, fittingDef) { return pipes.config.fittings[fittingDef.name](fittingDef, pipes); } + if (!pipes.config.userFittingsDirs) { return null; } + for (var i = 0; i < pipes.config.userFittingsDirs.length; i++) { var dir = pipes.config.userFittingsDirs[i]; From a41de9189059dbc950ea155c2010286386c8279e Mon Sep 17 00:00:00 2001 From: Nazar Hussain Date: Fri, 29 Jun 2018 09:56:16 +0200 Subject: [PATCH 3/3] Add test case for pre-initialized fittings generators --- test/bagpipes.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/test/bagpipes.js b/test/bagpipes.js index 4b627fc..8d1dd7b 100644 --- a/test/bagpipes.js +++ b/test/bagpipes.js @@ -45,6 +45,19 @@ describe('bagpipes', function() { done(); }); + it('should load pre-initialized fittings', function(done) { + var emitFitting = function create() { + return function (context, cb) { + cb(null, 'pre-initialized'); + }}; + var pipe = [ 'emit' ]; + var bagpipes = Bagpipes.create({ pipe: pipe }, {fittings: { emit: emitFitting}}); + var context = {}; + bagpipes.play(bagpipes.getPipe('pipe'), context); + context.output.should.eql('pre-initialized'); + done(); + }); + it('should allow user fittings to override system fittings', function(done) { var userFittingsDirs = [ path.resolve(__dirname, './fixtures/fittings') ]; var pipe = [ 'test' ];