diff --git a/src/builtins/map.js b/src/builtins/map.js index 578f0b6..a785d99 100644 --- a/src/builtins/map.js +++ b/src/builtins/map.js @@ -78,16 +78,19 @@ export default function map ( inputdir, outputdir, options ) { return reject( err ); } - if ( result === null ) return fulfil(); + return Promise.resolve( result ) + .then( result => { + if ( result === null ) return fulfil(); - const codepath = resolve( this.cachedir, filename ); + const codepath = resolve( this.cachedir, filename ); - const { code, map } = processResult( result, data, src, dest, codepath ); + const { code, map } = processResult( result, data, src, dest, codepath ); - writeToCacheDir( code, map, codepath, dest ) - .then( () => symlinkOrCopy( codepath ).to( dest ) ) - .then( () => options.cache[ filename ] = codepath ) - .then( fulfil ); + writeToCacheDir( code, map, codepath, dest ) + .then( () => symlinkOrCopy( codepath ).to( dest ) ) + .then( () => options.cache[ filename ] = codepath ) + .then( fulfil ); + }); }) .catch( reject ); }).catch( err => { diff --git a/test/transform.js b/test/transform.js index 3582cd7..98295f8 100644 --- a/test/transform.js +++ b/test/transform.js @@ -190,5 +190,19 @@ module.exports = function () { assert.equal( read( 'tmp/foo/foo.md' ), read( 'tmp/output/foo.md' ) ); }); }); + + it( 'accepts promises from file transformers', function () { + return gobble( 'tmp/foo' ).transform( function ( input ) { + return new Promise( function ( fulfil ) { + process.nextTick( function () { + fulfil(input); + }); + }); + }).build({ + dest: 'tmp/output' + }).then( function () { + assert.equal( read( 'tmp/foo/foo.md' ), read( 'tmp/output/foo.md' ) ); + }); + }); }); };