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

Fixing git style subcommands on Windows & allowing subcommands to come from dependency modules #604

Closed
wants to merge 17 commits into from

Conversation

mateodelnorte
Copy link

@mateodelnorte mateodelnorte commented Jan 16, 2017

This PR fixes git style subcommands to work correctly on Windows, and adds logic such that git style subcommands can be inherited from child dependencies, allowing you to break large sets of commands into a multi-repo project. (It should also allow for dynamically varying available subcommands according to what is currently installed under ./node_modules)

I built a command for managing multi-repo projects, which dogfoods this patch to manage its own repos as well: https://github.com/mateodelnorte/meta/blob/master/package.json#L38-L39. meta, itself, has only one command – meta, which loads all child commands by searching through it's node_modules for matching meta-* modules and registering them via their index.js.

This all works fine with the current commander.js, but when attempting to call them commander can't locate them. This patch ensures that commander can find the git subcommands and execute them.

meta --help

  Usage: meta [options] [command]


  Commands:

    git         manage your meta repo and child git repositories 
    npm         run npm commands against your meta and child repositories 
    help [cmd]  display help for [cmd]

  Options:

    -h, --help     output usage information
    -V, --version  output the version number

The git subcommand, above, is provided by https://github.com/mateodelnorte/meta-git.
The npm subcommand, above, is provided by https://github.com/mateodelnorte/meta-npm

Matt Walters added 3 commits December 15, 2016 12:09
…ncies. enables plugin infrastructure where subcommands can be separated into different modules and repos
@mateodelnorte
Copy link
Author

mateodelnorte commented Jan 25, 2017

Do we actually care that this breaks old (v<=0.0.10) versions of node?

@mateodelnorte mateodelnorte changed the title Allow git style subcommands to come from dependencies Fixing git style subcommands on Windows & allowing subcommands to come from dependency modules Feb 7, 2017
@mateodelnorte
Copy link
Author

PING PING

Are Node 0.8 and 0.6 support really required in commander.js? The only thing keeping this PR from passing all tests are engine restrictions in some dependencies.

Thanks.

@mateodelnorte
Copy link
Author

Hi. Howdy. Hello there. This is a pretty popular package. Lots of PR's. Some are months old. Do people respond to them?

@abetomo
Copy link
Collaborator

abetomo commented Jul 11, 2017

@mateodelnorte Would you please resolve the conflict?

@mateodelnorte
Copy link
Author

Conflicts resolved.

index.js Outdated
// add executable arguments to spawn
args = (process.execArgv || []).concat(args);

proc = spawn('node', args, { stdio: 'inherit'});
Copy link
Collaborator

Choose a reason for hiding this comment

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

As for 'node', can you do it like https: //github.com/tj/commander.js/blob/master/index.js#L544?

Copy link
Author

Choose a reason for hiding this comment

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

Should be good to go! Take a peek.

@abetomo
Copy link
Collaborator

abetomo commented Jul 12, 2017

Thank you!

@mateodelnorte
Copy link
Author

mateodelnorte commented Jul 14, 2017

Glad to help!

*not sure what's up with npm 5 not installing the single find-module-bin dependency. yarn installs it just fine.

@mateodelnorte
Copy link
Author

Any timeline on when this will be published to npm? I think a simple rebuild will fix the build errors on node 8. Seemed to be a temporary problem with the registry. The dependency version def exists:

{ name: 'find-module-bin',
  description: 'scan known node_modules directories to find installation directory of a particular bin file',
  'dist-tags': { latest: '0.0.2' },
  versions: [ '0.0.0', '0.0.1', '0.0.2' ],

@mateodelnorte
Copy link
Author

When is this going to be merged? The error happening in this build was a bug in npm5.

@mateodelnorte
Copy link
Author

I've fixed the merge issue that happened in package.json as a result of this not being merged since January. Looks like a re-run of the builds works completely (because it was a bug in npm5).

Can we get this merged?

Thx

@mateodelnorte
Copy link
Author

@abetomo Can we please slate this for merge? It's been well over a year.

@abetomo
Copy link
Collaborator

abetomo commented Mar 29, 2018

@mateodelnorte
It was awaiting @vanesyan's approval.

@vanesyan
Could you please review it?

@mateodelnorte
Copy link
Author

So... I updated this from upstream again. @abetomo @vanesyan

Can we get this merged?

@mateodelnorte
Copy link
Author

ping ping

index.js Outdated
@@ -544,26 +545,23 @@ Command.prototype.executeSubCommand = function(argv, args, unknown) {
if (exists(localBin + '.js')) {
bin = localBin + '.js';
isExplicitJS = true;
} else if (exists(localBin)) {
} else if (process.platform === 'win32' ? exists(localBin + '.cmd') : exists(localBin)) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you please put it to own variable, for readability purpose

Copy link
Author

Choose a reason for hiding this comment

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

Sure thing.

@@ -5,6 +5,7 @@
var EventEmitter = require('events').EventEmitter;
var spawn = require('child_process').spawn;
var path = require('path');
var findModuleBin = require('find-module-bin');
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you please inline the module, we trying to keep commander.js dependencies-free

Copy link
Author

Choose a reason for hiding this comment

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

As a curiosity – What's the reason for wanting no dependencies?

Copy link
Author

Choose a reason for hiding this comment

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

find-module-bin uses global-modules, to look up the appropriate os-dependent location of globally installed node modules. this won't be a simple pull-function-up refactor, as the os-specific logic is hidden in here.

perhaps we can merge this and set the refactoring as tech-debt?

personally, I think the reuse is better for the community. you don't want a massive explosion of dependencies, but having well managed dependencies can make your code more DRY and keeps the potential for the dependent packages to continue to evolve and solidify.

Copy link
Author

Choose a reason for hiding this comment

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

@vanesyan

Copy link
Author

Choose a reason for hiding this comment

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

@vanesyan I don't think it makes sense to inline all of this.

This PR has been ready for merge for about a year and six months.

Choose a reason for hiding this comment

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

Hi @vanesyan @abetomo
My team is also interested in this fix.

Is there any reason why this can not be included with the dependency?

@roman-vanesyan
Copy link
Collaborator

Hello there! Sorry for make you waiting. Can you, please, resolve the comments in the review, thanks!

@mateodelnorte
Copy link
Author

Git style subcommands are still broken on Windows in master. This PR fixes them.

Is there any plan to merge? Is the fact this is not merged because it's more important to have zero dependencies than to fix a glaring bug?

@shadowspawn
Copy link
Collaborator

@codyaverett What aspect of this Pull Request is your team interested in?

@shadowspawn
Copy link
Collaborator

shadowspawn commented Apr 11, 2019

@mateodelnorte Sorry this has been open for so long, but unfortunately I think I see why. There are some good and interesting ideas here (thanks!), but multiple potential problems from the point of view of a cautious maintainer. To be clear, I am not willing to recommend this Pull Request be accepted in its current form based on my current understanding.

Some initial comments and questions, but I warn you and apologise in advance there will be more! If you don't want to invest in engaging with a new maintainer that is ok, you proposed this a long time ago. I see ideas in here I want to consider further whether or not you abandon this Pull Request.

Side notes:

  • I suggest you don't put effort into resolving the conflicts yet unless you want to.
  • I would like to add a CONTRIBUTING guide, and some of this discussion might end up there.

This is more a comment than a question or call for action. If you are addressing an issue or adding an enhancement that other people are asking for, it helps to link to the related issues. Otherwise the maintainers are judging the merit of the Pull Request just on your comments and what we recall of the issues we have seen in the past.

  1. Are you doing one thing in this Pull Request or two? Do you consider the Windows "fix" to be separate, or is it an additional lookup method for binaries like the node_modules search?

  2. In what way are Git style subcommands still broken on Windows? Are you referring to *.cmd or a wider issue? (I saw bat mentioned in a commit comment.)

@shadowspawn
Copy link
Collaborator

Is there any reason why this can not be included with the dependency?

This is going to come up again with Pull Requests. My favourite two challenging images:

Commander currently has zero dependencies. That isn't a requirement, but is a simple story. It does mean every suggested dependency will be critically evaluated.

And some insight into what this dependency pulls in:

@mateodelnorte
Copy link
Author

This PR was made LONG before Commander had zero dependencies.

Yes, this PR 1) fixed git style subcommands on Windows and 2) introduced the ability for dependencies to supply git style subcommands. However, this was all done two years before the CONTRIBUTING guide you're proposing and I put in the effort to make PR merge-able multiple times.

All well and good if you don't want to merge, but this entire process has been extremely disheartening.

@mateodelnorte
Copy link
Author

mateodelnorte commented Apr 11, 2019

Frankly, I don't care if this code gets merged. But I would love to see the two issues be fixed.

@codyaverett
Copy link

@shadowspawn Thank you for your time and detailed response.

My motive is directly correlated with this other old issue. mateodelnorte/meta#46

I believe I can work around it, but I wasn't successful in my first attempts. I am still hopeful though. 😅

I will report future related issues in the meta project directly. Thanks!

@shadowspawn
Copy link
Collaborator

Thanks for info @mateodelnorte and @codyaverett

Sorry you had a rough time with this one @mateodelnorte.

I'm closing this Pull Request as problematic, but have noted it in #944 for future reference.

(I think the next direction we want to explore with git-style commands is more control over how the commands are found. Source file naming and directory layout is one form of that, but search paths where the commands are looked for is another as in this Pull Request. i.e. installed node_modules, search path for commands like npm uses, etc.)

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

Successfully merging this pull request may close these issues.

None yet

6 participants