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

Promisify fs methods #62

Merged
merged 7 commits into from
Apr 22, 2017
Merged

Promisify fs methods #62

merged 7 commits into from
Apr 22, 2017

Conversation

adamkiss
Copy link
Contributor

@adamkiss adamkiss commented Apr 1, 2017

I want to reuse this plugin elsewhere, so in the spirit of Open Source I took a crack at one of the 'help wanted' issues to familiarize myself with the codebase.

Please let me know your thoughts. Should close #59.

@adamkiss adamkiss changed the title Promisify fs methods (#59) Promisify fs methods - #59 Apr 1, 2017
@adamkiss adamkiss changed the title Promisify fs methods - #59 Promisify fs methods Apr 1, 2017
@adamkiss
Copy link
Contributor Author

Bump @sindresorhus ?

index.js Outdated
});
})
.catch(err => fsOperationFailed(stream, sourceFile, err))
.then(() => cb());
Copy link
Owner

Choose a reason for hiding this comment

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

The point of promisifying is so that we can drop the cb() here and in the function signature and just return a promise from the function.

@sindresorhus
Copy link
Owner

Thanks for working on this :)

@sindresorhus sindresorhus changed the title Promisify fs methods Promisify fs methods Apr 17, 2017
@adamkiss
Copy link
Contributor Author

No problem, thanks for making it in the first place :)

index.js Outdated
.then(targetData => {
if (sourceFile.isNull()) {
cb(null, sourceFile);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not sure if this is okay, but after Promise we run cb() either way?

Copy link
Owner

Choose a reason for hiding this comment

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

No. You still need to pass the file down the stream even though its contents is null.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Right, thanks! Fixed it now.

index.js Outdated
@@ -86,7 +82,7 @@ module.exports = (dest, opts) => {
}
}

opts.hasChanged(this, cb, file, newPath);
opts.hasChanged(this, file, newPath).then(() => cb());
Copy link
Owner

Choose a reason for hiding this comment

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

You can now move the fsOperationFailed error handling here instead of catching it in both compareLastModifiedTime and compareSha1Digest.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Right! Thank you, and sorry for doing this line by line!

Will do in 20

@sindresorhus
Copy link
Owner

Last thing that I forgot earlier. You need to update the hasChanged documentation, to remove callback and mention that it needs to return a Promise.

@adamkiss
Copy link
Contributor Author

adamkiss commented Apr 19, 2017

@sindresorhus Yeah, I wasn't sure what's the accepted/usual open source way of doing changes in docs, and other non-code things. Should I go ahead and change the docs, and you'll do the rest afterwards?

edited to sound less like I just woke up

@sindresorhus
Copy link
Owner

Shall I go ahead and change the docs, and the rest (like up version in package, …) will you do?

Only the docs. I'll do the up version when publishing a new version.

@adamkiss
Copy link
Contributor Author

@sindresorhus sorry, had a busy few days. Updated the readme.

@sindresorhus sindresorhus merged commit 84af83e into sindresorhus:master Apr 22, 2017
@sindresorhus
Copy link
Owner

Thank you @adamkiss. I really appreciate this contribution :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Promisify the code
2 participants