diff --git a/index.js b/index.js index 39ffab4..b9869cc 100644 --- a/index.js +++ b/index.js @@ -50,8 +50,9 @@ function existsSync(path) { } class Funnel extends Plugin { - constructor(inputNode, options = {}) { - super([inputNode], { + constructor(inputs, options = {}) { + let inputNodes = Array.isArray(inputs) ? inputs : [inputs]; + super(inputNodes, { annotation: options.annotation, persistentOutput: true, needsCache: false, diff --git a/tests/index.js b/tests/index.js index 40671c5..a4367ed 100644 --- a/tests/index.js +++ b/tests/index.js @@ -1106,4 +1106,66 @@ describe('broccoli-funnel', function() { expect(getDestPathCalled).to.be.equal(1); }); }); + + describe('subclassing', function() { + it('can be subclassed, simple destDir modification', async function() { + class FunnelSubclass extends Funnel.Funnel { + constructor(input, options) { + super(input, options); + + this._hasBuilt = false; + } + + build() { + if (this._hasBuilt === false) { + this.destDir = 'lol'; + this._hasBuilt = true; + } + + return super.build(); + } + } + + let inputPath = input.path('lib/utils'); + let node = new FunnelSubclass(inputPath, {}); + output = createBuilder(node); + + await output.build(); + let outputPath = output.path(); + + expect(walkSync(outputPath)).to.eql(['lol/', 'lol/foo.js']); + }); + + it('subclasses can provide additional trees', async function() { + class FunnelSubclass extends Funnel.Funnel { + constructor(inputNode, options) { + super([inputNode, input.path('dir1/subdir2')], options); + + this._hasBuilt = false; + } + + build() { + if (this._hasBuilt === false) { + if (!fs.existsSync(`${this.inputPaths[1]}/bar.css`)) { + throw new Error('Could not find file!!!'); + } + // set custom destDir to ensure our custom build code ran + this.destDir = 'lol'; + this._hasBuilt = true; + } + + return super.build(); + } + } + + let inputPath = input.path('lib/utils'); + let node = new FunnelSubclass(inputPath, {}); + output = createBuilder(node); + + await output.build(); + let outputPath = output.path(); + + expect(walkSync(outputPath)).to.eql(['lol/', 'lol/foo.js']); + }); + }); });