Skip to content

Commit

Permalink
Merge pull request #106 from chriskrycho/input-node-105
Browse files Browse the repository at this point in the history
Handle empty input nodes when `include` or `exclude` are set.
  • Loading branch information
rwjblue committed Feb 8, 2019
2 parents bfea8d4 + a793c0b commit 00de4f4
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 3 deletions.
12 changes: 9 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,8 @@ Funnel.prototype.build = function() {
}
}

let inputPathExists = fs.existsSync(inputPath);

let linkedRoots = false;
if (this.shouldLinkRoots()) {
linkedRoots = true;
Expand All @@ -216,8 +218,6 @@ Funnel.prototype.build = function() {
* specifying `this.allowEmpty`.
*/

let inputPathExists = fs.existsSync(inputPath);

// This is specifically looking for broken symlinks.
let outputPathExists = fs.existsSync(this.outputPath);

Expand Down Expand Up @@ -255,8 +255,14 @@ Funnel.prototype.build = function() {
/*eslint-enable no-lonely-if*/

this._isRebuild = true;
} else {
} else if (inputPathExists) {
this.processFilters(inputPath);
} else if (!this.allowEmpty) {
throw new Error(`You specified a \`"srcDir": ${this.srcDir}\` which does not exist and did not specify \`"allowEmpty": true\`.`);
} else { // !inputPathExists && this.allowEmpty
// Just make an empty folder so that any downstream consumers who don't know
// to ignore this on `allowEmpty` don't get trolled.
mkdirp(this.destPath);
}

this._debug('build, %o', {
Expand Down
78 changes: 78 additions & 0 deletions tests/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,84 @@ describe('broccoli-funnel', function() {

expect(node._matchedWalk).to.eql(true);
});

it('throws error on unspecified allowEmpty', function() {
let assertions = 0;
let inputPath = `${FIXTURE_INPUT}/dir1`;
let node = new Funnel(inputPath, {
include: ['*'],
srcDir: 'subdir3',
destDir: 'subdir3',
});

builder = new broccoli.Builder(node);
return builder.build()
.catch(error => {
expect(error.message).to.contain('You specified a `"srcDir": subdir3` which does not exist and did not specify `"allowEmpty": true`.');
assertions++;
})
.then(() => {
expect(assertions).to.equal(1, 'Build threw an error.');
});
});

it('does not error with input node at a missing nested source', function() {
let inputPath = `${FIXTURE_INPUT}/dir1`;
let node = new Funnel(inputPath, {
include: ['*'],
srcDir: 'subdir3',
allowEmpty: true,
});

let expected = [];

builder = new broccoli.Builder(node);
return builder.build()
.then(results => {
let outputPath = results.directory;

expect(walkSync(outputPath)).to.eql(expected);
})
.then(() => builder.build())
.then(results => {
let outputPath = results.directory;

expect(walkSync(outputPath)).to.eql(expected);
});
});

it('creates nested output path when input node at a missing nested source', function() {
let inputPath = `${FIXTURE_INPUT}/dir1`;
let node = new Funnel(inputPath, {
include: ['*'],
srcDir: 'subdir3',
destDir: 'some-place',
allowEmpty: true,
});

let expected = ['some-place/'];

builder = new broccoli.Builder(node);
return builder.build()
.then(results => {
let outputPath = results.directory;

expect(walkSync(outputPath)).to.eql(expected);
})
.then(() => builder.build())
.then(results => {
let outputPath = results.directory;

expect(walkSync(outputPath)).to.eql(expected);

return builder.build();
})
.then(results => {
let outputPath = results.directory;

expect(walkSync(outputPath)).to.eql(expected);
});
});
});

describe('without filtering options', function() {
Expand Down

0 comments on commit 00de4f4

Please sign in to comment.