Skip to content
This repository has been archived by the owner on Dec 6, 2023. It is now read-only.

Rework profile.js to use shellInitScriptChooser() #51

Open
wants to merge 10 commits into
base: master
Choose a base branch
from

Conversation

edsfocci
Copy link

Rework 'avn setup' to use .bashrc or .bash_profile according to the algorithm @wbyoung talked about in #50

@coveralls
Copy link

coveralls commented Jan 12, 2017

Coverage Status

Coverage decreased (-11.4%) to 88.593% when pulling a4df2f8 on edsfocci:add-bashrc-to-setup-attempt-2 into 24e1b1d on wbyoung:master.

Copy link
Owner

@wbyoung wbyoung left a comment

Choose a reason for hiding this comment

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

A few first thoughts have been left here. In addition to addressing this feedback, the following needs to be done before this is merged:

  • Bring back support for .zshrc as well… we probably want to setup both bash as well as zsh.
  • Address the checklist here
  • Get all tests passing & write new tests to ensure code coverage is up to the current standard

bashrcExists = !err;
resolve();
});
});
Copy link
Owner

Choose a reason for hiding this comment

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

Since we have mz, you should be able to just do:

var bashrcPromise = fs.access(bashrcFile).then(function() { bashrcExists = true; });

bashProfileExists = !err;
resolve();
});
});
Copy link
Owner

Choose a reason for hiding this comment

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

Same as above comment.

}

if (bashrcExists && bashProfileExists) {
var innerPromise = new Promise(function(resolve) {
Copy link
Owner

Choose a reason for hiding this comment

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

Again, no need for innerPromise via mz.

return appendFile;
}

var innerInnerPromise = new Promise(function(resolve) {
Copy link
Owner

Choose a reason for hiding this comment

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

mz

darwin: bashProfileFile,
};

return platformsToInitScript[process.platform];
Copy link
Owner

Choose a reason for hiding this comment

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

There should probably be a fallback here in case the platform is not in this list.

@coveralls
Copy link

coveralls commented Jan 18, 2017

Coverage Status

Coverage decreased (-9.2%) to 90.775% when pulling 3a12d2b on edsfocci:add-bashrc-to-setup-attempt-2 into 24e1b1d on wbyoung:master.

@coveralls
Copy link

coveralls commented Jan 23, 2017

Coverage Status

Coverage decreased (-8.0%) to 92.015% when pulling 569aa22 on edsfocci:add-bashrc-to-setup-attempt-2 into 24e1b1d on wbyoung:master.

@coveralls
Copy link

coveralls commented Jan 23, 2017

Coverage Status

Coverage decreased (-8.0%) to 92.015% when pulling 6441064 on edsfocci:add-bashrc-to-setup-attempt-2 into 24e1b1d on wbyoung:master.

@coveralls
Copy link

coveralls commented Jan 23, 2017

Coverage Status

Coverage decreased (-8.0%) to 92.015% when pulling 5bca4a7 on edsfocci:add-bashrc-to-setup-attempt-2 into 24e1b1d on wbyoung:master.

@edsfocci
Copy link
Author

I made the changes you suggested, and the code currently passes in Travis. I'll work on adding the tests later.

.then(function(initScript) {
appendFile = initScript;

if (appendFile === bashProfileFileName) {
Copy link
Owner

Choose a reason for hiding this comment

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

What's the purpose of this if/else here?

Why can't it just update both .bash_profile and .zshrc or .bashrc and .zshrc? I know it's uncommon, but some people will use multiple shells, so if they have both config files, why not support them both?

@wbyoung
Copy link
Owner

wbyoung commented Jan 24, 2017

@edsfocci I just stumbled across this resolution of init scripts by yarn. It seems as though they'd probably have worked out most platform idiosyncrasies and it does seem quite simple.

@@ -8,6 +8,9 @@ var util = require('util');
var chalk = require('chalk');
var isNoEntry = require('../util/codes').isNoEntry;

var bashProfileFileName = '.bash_profile';
var bashrcFileName = '.bashrc';

Copy link
Owner

Choose a reason for hiding this comment

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

Given the comment about removing the branching condition, I think these globals can go away.

if (changed) {
console.log('%s: %s', chalk.bold.magenta('avn'),
chalk.bold.cyan('restart your terminal to start using avn'));
}
});

return promise;
Copy link
Owner

Choose a reason for hiding this comment

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

This should not change — the returned promise resolution would occur before the final log message is output (which is not desirable & shouldn't be required for this PR).

var bashrcNotExist;

// Notice: will change fs.stat to fs.access in the future
// Reason: NodeJS 0.10 doesn't have fs.access (added in NodeJS 0.11.15)
Copy link
Owner

Choose a reason for hiding this comment

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

Since avn always uses the active node version, we'll likely support 0.10 for a long time. This comment could be removed.

.then(function(data) {
// RegExp to detect "~/.bashrc",
// "$HOME/.bashrc", or "/home/user/.bashrc"
var bashrcRe = new RegExp(' ?source +(\\\\\\n)? *(~\/.bashrc|' +
Copy link
Owner

Choose a reason for hiding this comment

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

  • . is an alias of source
  • All space checks should probably use \s
  • Whitespace checks that can span a line should use the multiline workaround of [\s\S]
  • Checking for the full path seems unnecessary (~ vs $HOME vs /platform/specific/prefix) and error prone… for instance, I could write ${HOME} or ${HOME:/home}.

* @function setup.profile.~shellInitScriptChooser
* @return {Promise}
*/
var shellInitScriptChooser = function() {
Copy link
Owner

Choose a reason for hiding this comment

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

Since this is bash specific, let's name it as such.

Copy link
Owner

@wbyoung wbyoung left a comment

Choose a reason for hiding this comment

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

Looking good!

@evenfrost
Copy link

Any update on this? Ubuntu uses .profile instead of .bash_profile, and avn doesn't work for me at all until moving scripts to .bashrc.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants