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

Fix issue #11 #56

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

Fix issue #11 #56

wants to merge 3 commits into from

Conversation

moos
Copy link

@moos moos commented May 2, 2017

Tested on OSX and CentOS & old tests pass on Windows.

@neekey
Copy link
Owner

neekey commented May 2, 2017 via email

@moos
Copy link
Author

moos commented May 9, 2017

ping - have you had a chance to look at this yet?

if (cmd.length > 1) {
args = cmd.slice(1);
if (cmd.length > 0) {
args = cmd;
}
Copy link
Owner

Choose a reason for hiding this comment

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

it's not a good practice to change the parameter cmd and even use it later, too implicit. I would suggest you write a command parser like:

function commandParser(cmd) { ... }

var ret = commandParser(cmd);
var command = ret.command;
var args = ret.args; 

function ensureCommand(cmd) {
var command = cmd.shift();
var fs = require('fs');

Copy link
Owner

Choose a reason for hiding this comment

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

Still, I would not change the cmd directly, I would either get a copy of cmd or just use an index to do the shifting.

@neekey
Copy link
Owner

neekey commented May 10, 2017

Sorry for the late reply : )

I think the file existence checking is a brilliant idea, but my concern is that it may create performance issue if there's a huge number of results returned and you will have to check every command segment, which will end up with a lot of IO workload.

Since I don't have a better solution for this issue, I think there are two things that can do to make the situation better for most of the users:

  • the issue is actually an edge case, most of the users may not even notice this issue, so I will suggest making this solution as an optional feature, we can create an option for the user to toggle it
  • for the performance issue, you can actually cache the exists check result by saving a key-value object with a key as the command segment and the value as a boolean to indicate the command segment exists or not, it will be helpful if the result contains a lot of same commands or the module is run by multiple times

@moos
Copy link
Author

moos commented May 10, 2017

No problem. It's an edge case if you don't run into it :). Working on Google Chrome I ran into this very early. So well anyone else working with paths that have spaces.

As for performance, I was concerned too so I ran a rudimentary test and noticed no difference. This fixes a fundamental flaw in the module -- I really don't think making it optional is the right path.

I've recently published npm/chromate which fails due to this issue.

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.

2 participants