From 15e0663a1914d2854625159dff8fa29b15743ca2 Mon Sep 17 00:00:00 2001 From: Carlos Precioso Date: Wed, 8 Jun 2016 18:04:21 +0200 Subject: [PATCH 1/2] Add support for Promises in file transformers --- src/builtins/map.js | 17 ++++++++++------- test/transform.js | 12 ++++++++++++ 2 files changed, 22 insertions(+), 7 deletions(-) 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..239e848 100644 --- a/test/transform.js +++ b/test/transform.js @@ -190,5 +190,17 @@ 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( fulfil, input ); + }); + }).build({ + dest: 'tmp/output' + }).then( function () { + assert.equal( read( 'tmp/foo/foo.md' ), read( 'tmp/output/foo.md' ) ); + }); + }); }); }; From 24f7883d1ee1c36de1e84fa948d781e736e194a1 Mon Sep 17 00:00:00 2001 From: Carlos Precioso Date: Thu, 9 Jun 2016 02:16:40 +0200 Subject: [PATCH 2/2] Fix test for node 0.12 process.nextTick doesn't accept `args` argument in node 0.12 --- test/transform.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/test/transform.js b/test/transform.js index 239e848..98295f8 100644 --- a/test/transform.js +++ b/test/transform.js @@ -194,7 +194,9 @@ module.exports = function () { it( 'accepts promises from file transformers', function () { return gobble( 'tmp/foo' ).transform( function ( input ) { return new Promise( function ( fulfil ) { - process.nextTick( fulfil, input ); + process.nextTick( function () { + fulfil(input); + }); }); }).build({ dest: 'tmp/output'