-
Notifications
You must be signed in to change notification settings - Fork 774
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
Refactor copy
API in async/await
#1021
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
@@ -5,7 +5,7 @@ const os = require('os') | |||
const fse = require('../..') | |||
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.
@@ -33,7 +33,7 @@ describe('utimes', () => { | |||
fse.emptyDir(TEST_DIR, done) | |||
// 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
.
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:
copy
is not expected to return a value, yet we usereturn
throughout the code for final async calls inside functions; this could result in unintentionally returning a value in the future; perhaps we should useawait
instead?- Is there a reason for duplicating the util functions vs. just wrapping them in universalify? We could wrap them in
fromCallback
here, then port them to promise implementations and wrap infromPromise
in a separate PR. Anything I'm missing? (I have not reviewed those changes yet)
e4b7aa1
to
bc8ee0b
Compare
@@ -68,25 +70,25 @@ describe('utimes', () => { | |||
it('should close open file desciptors after encountering an error', done => { | |||
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 |
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:
copy
API. Other APIs will be migrated in the following PRs