Skip to content

Commit 8f4af5d

Browse files
committed
allow .ext to work if .accept is a regex (fixes #97)
1 parent 6a52bcc commit 8f4af5d

File tree

2 files changed

+30
-8
lines changed

2 files changed

+30
-8
lines changed

src/builtins/map.js

+5-6
Original file line numberDiff line numberDiff line change
@@ -27,19 +27,18 @@ export default function map ( inputdir, outputdir, options ) {
2727
if ( this.aborted ) return;
2828

2929
const ext = extname( filename );
30-
31-
// change extension if necessary, e.g. foo.coffee -> foo.js
32-
const destname = ( options.ext && ~options.accept.indexOf( ext ) ) ? filename.substr( 0, filename.length - ext.length ) + options.ext : filename;
33-
3430
const src = join( inputdir, filename );
35-
const dest = join( outputdir, destname );
3631

3732
// If this mapper only accepts certain extensions, and this isn't
3833
// one of them, just copy the file
3934
if ( shouldSkip( options, ext, filename ) ) {
40-
return symlinkOrCopy( src ).to( dest );
35+
return symlinkOrCopy( src ).to( outputdir, filename );
4136
}
4237

38+
// change extension if necessary, e.g. foo.coffee -> foo.js
39+
const destname = options.ext ? filename.substr( 0, filename.length - ext.length ) + options.ext : filename;
40+
const dest = join( outputdir, destname );
41+
4342
// If this file *does* fall within this transformer's remit, but
4443
// hasn't changed, we just copy the cached file
4544
if ( !changed[ filename ] && options.cache.hasOwnProperty( filename ) ) {

test/scenarios.js

+25-2
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ module.exports = function () {
146146
it( 'should allow file transforms to filter with a RegExp', function () {
147147
var count = 0, source = gobble( 'tmp/foo' ), task;
148148

149-
function checkFilter( input ) {
149+
function checkFilter ( input ) {
150150
count++;
151151
return input;
152152
}
@@ -163,10 +163,33 @@ module.exports = function () {
163163
});
164164
});
165165

166+
it( 'should allow file transforms to filter with a RegExp and an extension', function () {
167+
var count = 0, source = gobble( 'tmp/foo' ), task;
168+
169+
function checkFilter ( input ) {
170+
count++;
171+
return input;
172+
}
173+
checkFilter.defaults = {
174+
accept: /foo\.md/,
175+
ext: '.txt'
176+
};
177+
178+
task = source.transform( checkFilter ).build({
179+
dest: 'tmp/output'
180+
});
181+
182+
return task.then( function () {
183+
assert.equal( count, 1 );
184+
assert.deepEqual( sander.lsrSync( 'tmp/output' ).sort(), [ 'foo.txt', 'bar.md', 'baz.md' ].sort() );
185+
assert.equal( sander.readFileSync( 'tmp/output/foo.txt', { encoding: 'utf-8' }).trim(), 'foo: this is some text' );
186+
});
187+
});
188+
166189
it( 'should skip files for file transforms which return null', function () {
167190
var count = 0, source = gobble( 'tmp/foo' ), task;
168191

169-
function nullFileTransform( input ) {
192+
function nullFileTransform ( input ) {
170193
count++;
171194
return ~input.indexOf('foo') ? input : null;
172195
}

0 commit comments

Comments
 (0)