-
Notifications
You must be signed in to change notification settings - Fork 779
Refactor copy API in async/await
#1021
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
Conversation
4fe8f1d to
f04093f
Compare
copy API in async/awaitcopy API in async/await
|
@RyanZim The PR is ready to be reviewed now. |
a948dc0 to
d9f8ef9
Compare
| const path = require('path') | ||
| const assert = require('assert') | ||
| const copy = require('../copy') | ||
| const { copy } = require('../') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I need to change the import here. lib/copy/copy.js now exports the promise-only API (instead of the callback-only API), while lib/copy/index.js now exports the unified API.
| // reset stubs | ||
| gracefulFsStub = {} | ||
| utimes = proxyquire('../utimes', { 'graceful-fs': gracefulFsStub }) | ||
| utimes = proxyquire('../utimes', { '../fs': gracefulFsStub }) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The mock here has to be replaced, as lib/util/utimes.js no longer uses graceful-fs directly. It now uses the unified API from lib/fs/index.js.
RyanZim
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've left a several code comments. Additionally, I have a few other concerns:
copyis not expected to return a value, yet we usereturnthroughout the code for final async calls inside functions; this could result in unintentionally returning a value in the future; perhaps we should useawaitinstead?- Is there a reason for duplicating the util functions vs. just wrapping them in universalify? We could wrap them in
fromCallbackhere, then port them to promise implementations and wrap infromPromisein a separate PR. Anything I'm missing? (I have not reviewed those changes yet)
e4b7aa1 to
bc8ee0b
Compare
| const fakeFd = Math.random() | ||
|
|
||
| gracefulFsStub.open = (pathIgnored, flagsIgnored, modeIgnored, callback) => { | ||
| gracefulFsStub.open = u((pathIgnored, flagsIgnored, modeIgnored, callback) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The gracefulFsStub needs to be universalify as the utimesMillis is now Promise-based and then universalized.
|
@RyanZim I've addressed all the code review suggestions. I've also universalized the related internal utility functions to reduce the duplicated implementations. The CI still passes after the latest changes: https://github.com/SukkaW/node-fs-extra/actions/runs/6598480115 Note that the |
RyanZim
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a couple comments
The PR is the first part of proposal #1020:
copyAPI. Other APIs will be migrated in the following PRs