Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix usage of allowEmpty when also using include / exclude #106

Merged
merged 6 commits into from
Feb 8, 2019
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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) {
chriskrycho marked this conversation as resolved.
Show resolved Hide resolved
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);
chriskrycho marked this conversation as resolved.
Show resolved Hide resolved
}

this._debug('build, %o', {
Expand Down
45 changes: 45 additions & 0 deletions tests/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,51 @@ 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);
});
});
});

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