Skip to content

Commit

Permalink
Ensure adding additional trees does not affect include/exclude results.
Browse files Browse the repository at this point in the history
In a7ed4fa we added support for passing
additional trees to the constructor (to ensure that they can be ready to
read in subclasses), but we didn't ensure that all internal usage of
`this.input` was limited to the first tree passed. This didn't matter
much for the simple symlink srcDir <-> destDir situation, but as soon as
you use custom `include`/`exclude` globs (and we therefore have to walk
all the files) we would trigger errors.

This fixes that oversight by ensuring that all usage of `this.input` is
scoped to `this.input.at(0)`, and adds a previously failing test.
  • Loading branch information
rwjblue committed Jun 17, 2021
1 parent 1ec8bc2 commit cfc238e
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 3 deletions.
6 changes: 3 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ class Funnel extends Plugin {
}
}

let inputPathExists = this.input.existsSync(this.srcDir || './');
let inputPathExists = this.input.at(0).fs.existsSync(this.srcDir || './');

let linkedRoots = false;
if (this.shouldLinkRoots()) {
Expand Down Expand Up @@ -317,9 +317,9 @@ class Funnel extends Plugin {
} else {

if (this._matchedWalk) {
entries = this.input.entries(this.srcDir || './', { globs: this.include, ignore: this.exclude });
entries = this.input.at(0).entries(this.srcDir || './', { globs: this.include, ignore: this.exclude });
} else {
entries = this.input.entries(this.srcDir || './');
entries = this.input.at(0).entries(this.srcDir || './');
}

entries = this._processEntries(entries);
Expand Down
34 changes: 34 additions & 0 deletions tests/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -1167,5 +1167,39 @@ describe('broccoli-funnel', function() {

expect(walkSync(outputPath)).to.eql(['lol/', 'lol/foo.js']);
});

it('providing additional trees does not change matched files', async function() {
class FunnelSubclass extends Funnel.Funnel {
constructor(inputNode, options) {
super([inputNode, input.path('dir1/subdir1/subsubdir2')], options);

this._hasBuilt = false;
}

build() {
if (this._hasBuilt === false) {
if (!fs.existsSync(`${this.inputPaths[1]}/some.js`)) {
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, {
include: ['**/*.js'],
});
output = createBuilder(node);

await output.build();
let outputPath = output.path();

expect(walkSync(outputPath)).to.eql(['lol/', 'lol/foo.js']);
});
});
});

0 comments on commit cfc238e

Please # to comment.