-
-
Notifications
You must be signed in to change notification settings - Fork 137
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
remove fs-plus from image-view package #305
remove fs-plus from image-view package #305
Conversation
One thing is that We are essentially only using We also use Which could pretty easily be replaced by If this file reasonably will never call |
Edit: I messed up with uncommitet changes |
The problems should now be fixed |
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.
Thanks for replacingfs.isFileSync()
. That part looks good to me. 👍
And sorry for multiple rounds of feedback hours apart.
I think we can safely use fs.existsSync()
from the Node/Electron fs
API, and without try/catch? -- I don't think that ever throws errors?
For spec/image-editor-status-view-spec.js
and spec/image-editor-view-spec.js
, the second commit removes fs.existsSync()
in favor of fs.statSync()
in a try{}
block.
I would personally prefer to just go back to fs.existsSync()
for the two spec files. I would approve at that point.
You are right. That never throws. I changed that now |
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.
LGTM!
Glad to see you guys were able to get everything else sorted, but otherwise as of now this looks great!
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.
Approving because: This PR removes an unnecessary dependency, and replaces it with simpler stuff that looks just as functional, IMO.
I'll go ahead and merge this now.
Thank you!
if (fs.isFileSync(filePath)) { | ||
let fileStats; | ||
try { | ||
fileStats = fs.statSync(filePath); | ||
} catch (e) {} | ||
if (fileStats?.isFile()) { |
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 want to specifically comment why this is fine 👍 :
The optional chaining thing with ?
(object?.method()
) on a declared variable won't throw even if the method doesn't exist.
Some docs: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Optional_chaining
If the object accessed or function called is
undefined
ornull
, it returnsundefined
instead of throwing an error.
Given let fileStats
above, fileStats
is declared. If some error happened with fs.statSync()
above, and there is no fileStats.isFile()
method, the if (fileStats?.isFile())
below will effectively be if(undefined)
, which is okay and doesn't throw. The undefined
is just another falsy value.
(I did test this, also.)
This removes the
fs-plus
package from the dependencies of theimage-view
package.