Skip to content

forever.config Configstore init and usage fixes #1115

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

Merged
merged 1 commit into from
Jun 12, 2021

Conversation

akatona84
Copy link
Contributor

Fixes: TypeError: forever.config.saveSync is not a function

Fixes: TypeError: forever.config.saveSync is not a function
@akatona84
Copy link
Contributor Author

fixes: #1114
@kibertoad, @thenengah could you review my change, please?

@akatona84
Copy link
Contributor Author

@bmeck , @indexzero , @jcrugzz could u take a look too?
Sorry for pushing u guys, but we really need a fix and a new (latest) version.
Many thanks!

@kibertoad
Copy link
Contributor

I'll review today, please let me catch my breath a bit :)

@akatona84
Copy link
Contributor Author

I'll review today, please let me catch my breath a bit :)

Sorrrry 😅

@kibertoad
Copy link
Contributor

@akatona84 Would it be possible to also add test for the main fix, the one related to the configStore error?

@@ -4,7 +4,9 @@ var Configstore = require('configstore');

function initConfigFile(foreverRoot) {
try {
return new Configstore(JSON.parse(fs.readFileSync(path.join(foreverRoot, 'config.json'))));
return new Configstore('config', undefined, {
Copy link
Contributor

Choose a reason for hiding this comment

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

What's the idea behind this change?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

before this nconf was used, like this:

function initConfigFile(foreverRoot) {
  return new nconf.File({file: path.join(foreverRoot, 'config.json')});
}

whatever changes you made in the configuration, it was saved eventually in this config.json file.
The first param should be an id and then the defaults and then options. It passed the parsed json to the first param before, which was used for creating the config file appending a ".json" to it so it became '[object Object].json' in ~/.config/configstore dir.
No backward compatibility, default configs was saved to this oddly named json and config.json in .forever dir was completely ignored.
I made it backward compatible and to use the original config file location.

@@ -554,7 +554,6 @@ app.cmd('columns add :name', cli.addColumn = function (name) {
columns.push(name);

forever.config.set('columns', columns);
forever.config.saveSync();
Copy link
Contributor

Choose a reason for hiding this comment

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

Why are all of save calls removed without any replacement?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Configstore persists the added configs right away, it doesn't require explicit save method call to save it to the file.

Comment on lines +447 to +448
var keys = Object.keys(forever.config.all),
conf = cliff.inspect(forever.config.all);
Copy link
Contributor Author

@akatona84 akatona84 Jun 12, 2021

Choose a reason for hiding this comment

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

Configstore doesn't have store attribute, all() returns the whole

describe('columns', function () {
this.timeout(5000);
it('manages columns successfully', function () {
return execCommand(`node bin/forever columns reset`,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this is testing whether forever columns reset works, it was throwing TypeError: forever.config.saveSync is not a function originally

Comment on lines +14 to +23
return execCommand(`node bin/forever columns rm uptime`,
{
expectedOutput: ['Removing column:', 'uptime']
});
})
.then(function () {
return execCommand(`node bin/forever columns add uptime`,
{
expectedOutput: ['Adding column:', 'uptime']
});
Copy link
Contributor Author

@akatona84 akatona84 Jun 12, 2021

Choose a reason for hiding this comment

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

these two just testing whether these commands are working too, and the config is actually persisted

});
})
.then(function () {
return execCommand(`node bin/forever columns add uptime`,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

also checking config persistence and a bit of functionality

@akatona84
Copy link
Contributor Author

akatona84 commented Jun 12, 2021

@akatona84 Would it be possible to also add test for the main fix, the one related to the configStore error?

The tests I added are using the Configstore and previously those commands are failing with 4.0.0.
(TBH the migration from nconf wasn't a too sophisticated change, this PR is basically finishing it. The errors were happening because forever code was still using some calls which were still nconf specific.)

And thanks for checking! I appreciate it a lot :)

@kibertoad kibertoad merged commit 6c7f0a5 into foreversd:master Jun 12, 2021
@kibertoad
Copy link
Contributor

@akatona84 Thanks a lot for contributing the fix!

@akatona84 akatona84 deleted the issue1114 branch June 12, 2021 15:40
@akatona84
Copy link
Contributor Author

@kibertoad, Thank you for your help and your quick actions! 🍻

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.

None yet

2 participants