Skip to content

Commit

Permalink
Merge pull request #123 from SparshithNR/dest-dir
Browse files Browse the repository at this point in the history
lookupDestinationPath will handle relative path
  • Loading branch information
rwjblue committed Mar 11, 2020
2 parents 8121b58 + 197f662 commit 85498f7
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 4 deletions.
6 changes: 2 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ class Funnel extends Plugin {
// Instead let's remove it:
this.output.rmdirSync('./', { recursive: true });
// And then symlinkOrCopy over top of it:
this._copy(inputPath, this.destPath, this.destDir);
this._copy(inputPath, this.destPath, './');
} else if (!inputPathExists && this.allowEmpty) {
// Can't symlink nothing, so make an empty folder at `destPath`:
this.output.mkdirSync(this.destDir, { recursive: true });
Expand Down Expand Up @@ -484,9 +484,7 @@ class Funnel extends Plugin {
}

_copy(sourcePath, destPath, relativePath) {
if (this.getDestinationPath) {
relativePath = this.lookupDestinationPath(relativePath);
}
relativePath = this.lookupDestinationPath(relativePath);
let destDir = path.dirname(relativePath);

try {
Expand Down
46 changes: 46 additions & 0 deletions tests/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,26 @@ describe('broccoli-funnel', function() {
]);
});

it('accepts destDir with leading slash', async function() {
let inputPath = `${FIXTURE_INPUT}/lib/utils`;

let node = new Funnel(inputPath, {
destDir: '/foo',

processFile() {
/* do nothing */
},
});

output = createBuilder(node);
await output.build();

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

it('works with mixed glob and RegExp includes', async function() {
let inputPath = `${FIXTURE_INPUT}/dir1`;
let node = new Funnel(inputPath, {
Expand Down Expand Up @@ -524,6 +544,32 @@ describe('broccoli-funnel', function() {

expect(walkSync(output.path())).to.eql(expected);
});

it('can take a list of files with destDir', async function() {
let inputPath = `${FIXTURE_INPUT}/dir1`;
let node = new Funnel(inputPath, {
files: [
'subdir1/subsubdir1/foo.png',
'subdir2/bar.css',
],
destDir: 'test/assert',
});

output = createBuilder(node);
await output.build();

let expected = [
'test/',
'test/assert/',
'test/assert/subdir1/',
'test/assert/subdir1/subsubdir1/',
'test/assert/subdir1/subsubdir1/foo.png',
'test/assert/subdir2/',
'test/assert/subdir2/bar.css',
];

expect(walkSync(output.path())).to.eql(expected);
});
});

describe('`files` is incompatible with filters', function() {
Expand Down

0 comments on commit 85498f7

Please sign in to comment.