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

'no such file' error on first save at LOCAL_FILE_PATH #41

Merged
merged 8 commits into from
Oct 3, 2017

Conversation

Jan-Ka
Copy link
Contributor

@Jan-Ka Jan-Ka commented Oct 1, 2017

This request resolves #38, possible even #33.

This change requires the package.json to be updated to the latest versions just to be save.

constants.js Outdated

exports.LOCAL_SAVE_DIR = localSaveDir;
exports.LOCAL_FILE_PATH = localFilePath;
exports.PUSHED_FILE_PATH = pushedFilePath;
Copy link
Owner

Choose a reason for hiding this comment

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

Although these changes are fine, I don't see the need for them. Can you please explain your rationale? Since the path is basically a constant for a particular OS, I don't see any reason to introduce the three new function calls. Thanks! 🙂

Copy link
Owner

Choose a reason for hiding this comment

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

Your LOCAL_SAVE_DIR idea is required! Thanks for that, but I would just define it as a constant instead of using path.join.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hi,

This is a best practice in my opinion since it ensures that the path is not malformed or at least normalized. Using path should handle all use cases but on the other hand it boils down to preference.

I will honor your opinion on this and change it accordingly.

Copy link
Owner

Choose a reason for hiding this comment

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

Hmm, I think xdg-basedir is dependable. 🙂 I know what they say about micro-optimizations, but it's still a few function calls I would avoid.

(If things go bad and a bug comes up in the future, because of this, then I will be sure to own up to my error in judgment 😸 )

file-module.js Outdated
var filepath = require('./constants').LOCAL_FILE_PATH;

if (!fileExists(filepath)) {
if(!fileExists.sync(filepath)) {
Copy link
Owner

Choose a reason for hiding this comment

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

Drop the file-exists dependency and use fs.existsSync instead.

file-module.js Outdated
@@ -49,7 +49,7 @@ exports.writeToPushed = function (glob) {
var xdg = require('xdg-basedir');
var filepath = require('./constants').PUSHED_FILE_PATH;

if (!fileExists(filepath)) {
if(!fileExists(filepath)) {
Copy link
Owner

Choose a reason for hiding this comment

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

Use fs.existsSync here. Drop file-exists.

file-module.js Outdated
@@ -49,7 +49,7 @@ exports.writeToPushed = function (glob) {
var xdg = require('xdg-basedir');
var filepath = require('./constants').PUSHED_FILE_PATH;

if (!fileExists(filepath)) {
if(!fileExists(filepath)) {
var mkdirp = require('mkdirp');
mkdirp(xdg.data + '/cube');
Copy link
Owner

Choose a reason for hiding this comment

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

Use mkdirp.sync here.

package.json Outdated
"pretty-ms": "^1.2.0",
"read": "^1.0.6",
"pretty-ms": "^3.0.1",
"read": "^1.0.7",
Copy link
Owner

Choose a reason for hiding this comment

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

Whoa whoa. This is too much of a change! Bumping major versions is a gamble, and I don't want to do it without thorough testing. So, let's keep this out of the scope of this particular PR. As I mentioned in the other issue's comment, I will freeze versions after merging this PR, test the whole module and if everything works, make a release.

Deprecated warnings suck, but not as much as a module that stops working!

@icyflame
Copy link
Owner

icyflame commented Oct 3, 2017

Hey, thanks for all your changes. I want to refocus this PR on just creating a new constant in the constants.js file, using fs.existsSync and mkdirp.sync everywhere and removing the file-exists dependency.

The unit test you added is fine and required. Once I merge the template, I will add a few more tests.

@Jan-Ka
Copy link
Contributor Author

Jan-Ka commented Oct 3, 2017

@icyflame I just pushed the changes we have discussed. I hope you find everything in order now.

@icyflame icyflame merged commit 64ef8bd into icyflame:master Oct 3, 2017
@icyflame
Copy link
Owner

icyflame commented Oct 3, 2017

Indeed, everything is in order now. I have merged it into master. I am going to let it be there till maybe tomorrow before freezing everything. Doing a thorough test and then publishing a new version to NPM! Thanks a lot for the time you spent working on this 😄

@Jan-Ka
Copy link
Contributor Author

Jan-Ka commented Oct 3, 2017

Glad I was able to help, I enjoyed it very much and can hopefully provide more help in the future.

@Jan-Ka Jan-Ka deleted the issue38 branch October 3, 2017 18:38
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.

'no such file' error on first save at LOCAL_FILE_PATH
2 participants