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

Add support for Promises in file transformers #124

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions src/builtins/map.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Copy link
Author

@cprecioso cprecioso Jun 9, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this promise chain be returned so if there's an error it'll propagate? I copied the current implementation, but I think it might be an error.


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 => {
Expand Down
14 changes: 14 additions & 0 deletions test/transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -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' ) );
});
});
});
};