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

Promise support #403

Merged
merged 4 commits into from
Apr 24, 2017
Merged

Promise support #403

merged 4 commits into from
Apr 24, 2017

Conversation

RyanZim
Copy link
Collaborator

@RyanZim RyanZim commented Apr 10, 2017

This uses https://github.com/RyanZim/universalify, a library I wrote for this purpose.

This is a semver-major change.

Needs docs (Done!), and we should add more tests in the future.

🎉 Promises are here! 🎉

@RyanZim
Copy link
Collaborator Author

RyanZim commented Apr 10, 2017

Need to fix my hacky tests since they fail on Node 4 & 5.

@RyanZim
Copy link
Collaborator Author

RyanZim commented Apr 10, 2017

Added basic README docs; should eventually migrate docs/ in a seperate PR.

README.md Outdated
@@ -69,11 +69,20 @@ Example:
```js
const fs = require('fs-extra')

// Async with promises:
fs.copy('/tmp/myfile', '/tmp/mynewfile')
.then(() => console.log("success!"))
Copy link
Collaborator

Choose a reason for hiding this comment

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

Probably not that important, but for the purpose of consistency in using ', wouldn't it be better console.log("success!") replaced with console.log('success!') since we use ' pretty much everywhere else? It actually has been there since the beginning (I guess). I just saw it now and thought that's be nice that we fix it here 😄

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah, we should fix that; thanks for the catch. I also removed an old semicolon in these docs. 😉

Someone ought to make a tool to run eslint on code blocks in markdown.

README.md Outdated

// Sync:
try {
fs.copySync('/tmp/myfile', '/tmp/mynewfile')
console.log("success!")
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same here: console.log("success!") -> console.log('success!')?

README.md Outdated
// Handle error
})

// Async with callbacks:
fs.copy('/tmp/myfile', '/tmp/mynewfile', err => {
if (err) return console.error(err)
console.log("success!")
Copy link
Collaborator

Choose a reason for hiding this comment

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

Also here, console.log("success!") -> console.log('success!')?

@manidlou
Copy link
Collaborator

manidlou commented Apr 12, 2017

Other than that minor thing, LGTM. Nice work @RyanZim 👏

@RyanZim
Copy link
Collaborator Author

RyanZim commented Apr 12, 2017

@manidlou Fixed.


Should also add: I'd appreciate review/improvements to https://github.com/RyanZim/universalify as well.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.5%) to 86.729% when pulling daaa4f0 on promises into 2a4ec71 on develop.

@jprichardson
Copy link
Owner

Nice work @RyanZim!

  1. Will you verify that the test cases for universalify include any additional test cases from https://github.com/sindresorhus/pify/blob/master/test.js and https://github.com/paulmillr/micro-promisify/blob/master/test.js - i.e. I'm just trying to ensure unverisalify doesn't have any edge case bugs that these battle-hardened libraries have already solved.

  2. Maybe I missed it, but will you add some tests demonstrating that a method imported from fs returns a promise?

Thanks!

@RyanZim
Copy link
Collaborator Author

RyanZim commented Apr 12, 2017

@jprichardson

  1. All the cases covered by pify, are already tested; except pify works on entire modules, which is something universalify will never do.

    micro-promisify has a few cases I should add. Thanks for the suggestions!

  2. Already done in lib/fs/__tests__/mz.test.js

@manidlou
Copy link
Collaborator

manidlou commented Apr 13, 2017

Someone ought to make a tool to run eslint on code blocks in markdown.

I believe that's a great idea!

Actually, that is specifically mentioned in standardjs docs:

Can I check code inside of Markdown or HTML files?

As it is mentioned there, they introduce two modules for that:

I tried standard-markdown (on our old README.md), and this was the result:

Linting file 1 of 1

   README.md
         74:15:    Strings must use singlequote.
         75:3:     Extra semicolon.
         79:15:    Strings must use singlequote.

Then, we can add a new scripts something like lintmd to package.json to automate this process.

So, @jprichardson, @RyanZim what do you think?

Edit

Maybe that'd be better I opened a new issue for that, IDK! 😕

@RyanZim
Copy link
Collaborator Author

RyanZim commented Apr 13, 2017

@manidlou Yeah, new issue or PR for that.

@RyanZim
Copy link
Collaborator Author

RyanZim commented Apr 13, 2017

@jprichardson micro-promisify sets the name and length properties on the returned function. I'm fine with setting name, but setting length isn't too straightforward, since we are potentially adding or removing the final callback parameter. I'd just skip setting length IMO. Are you OK with that?

@RyanZim
Copy link
Collaborator Author

RyanZim commented Apr 14, 2017

Updated docs/ to reflect this change.

@louisgv
Copy link

louisgv commented Apr 17, 2017

LGTM 👍

@coveralls
Copy link

Coverage Status

Coverage increased (+0.5%) to 86.729% when pulling e09efe1 on promises into 2a4ec71 on develop.

@RyanZim
Copy link
Collaborator Author

RyanZim commented Apr 22, 2017

@jprichardson Updated PR to use universalify v0.1.0, which sets name for the returned function.

Anything else before the merge?

@jprichardson jprichardson merged commit 33b7f84 into develop Apr 24, 2017
@RyanZim RyanZim deleted the promises branch April 24, 2017 22:06
@jdalton
Copy link
Contributor

jdalton commented Apr 27, 2017

Hurray! I was using pify to wrap fs-extra methods 😸

@rijnhard
Copy link

Hi

This is pretty cool because now i dont need fs-extra-promise but its also kind of annoying that its opinionated. For instance I use Q for pretty much everything and now I have to wrap any fs returns like this Q(fs.close()).
Ideally using a library like any-promise makes it easy for the user to pick his preferred implementation.

@RyanZim
Copy link
Collaborator Author

RyanZim commented May 10, 2017

@rijnhard I'm of the opinion that fs-extra should be as light as possible. Adding any-promise increases weight. I'm firmly opposed to this ATM.

@rijnhard
Copy link

rijnhard commented May 10, 2017

@RyanZim theres another alternative I've seen, where theres some variable or method that accepts an A+ promise implementation, then they use that for all the promise creation.
like

import Q from 'q';
import fs from 'fs-extra';
fs.setPromise(Q.Promise);

and in the code you use the standard es6 style promise as you would normally.

@RyanZim
Copy link
Collaborator Author

RyanZim commented May 10, 2017

Issue filed: #425

Repository owner locked and limited conversation to collaborators May 10, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants