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

add support for execute typescript subcommand via ts-node #849

Merged
merged 1 commit into from Aug 28, 2018
Merged

add support for execute typescript subcommand via ts-node #849

merged 1 commit into from Aug 28, 2018

Conversation

KillWolfVlad
Copy link
Contributor

Command.prototype.executeSubCommand doesn't support .ts extension for scripts. It is bad if you want run something via ts-node.

var bin = basename(f, '.js') + '-' + args[0];

First, hardcoded .js extension is bad. I suggest use real file extension.

commander.js/index.js

Lines 544 to 546 in e5b27cc

if (exists(localBin + '.js')) {
bin = localBin + '.js';
isExplicitJS = true;

Second, I suggest use similar block of code for check exists file with .ts extension. I don't think that this duplication is serious.

@joeferraro
Copy link

Exactly what I was looking for, thanks @abetomo

@roman-vanesyan
Copy link
Collaborator

LGTM

@abetomo abetomo merged commit 8bcc493 into tj:master Aug 28, 2018
@KillWolfVlad KillWolfVlad deleted the feature/executeSubCommand-tsnode branch September 27, 2018 18:20
@taschmidt
Copy link

Should this be working in commander v2.20.0? Do I need to do anything to make it work? It works with .js files but I can't get it to work once I switch them to .ts. The top-level one works but my 'cmd-subcommand' shows nothing.

@KillWolfVlad
Copy link
Contributor Author

Should this be working in commander v2.20.0?

Yes.

Do I need to do anything to make it work?

No.

It works with .js files but I can't get it to work once I switch them to .ts.

Just have directure structure like this (see test fixture):

.
└── bin
    ├── pm-install.ts
    ├── pm-remove.ts
    └── pm.ts

Thereafter you can execute script:

node -r ts-node/register bin/pm.ts

The top-level one works but my 'cmd-subcommand' shows nothing.

Can you reproduce your issue?

@taschmidt
Copy link

Thanks for the reply, @KillWolfVlad! I fixed my problem although I'm not really sure why. I'm doing a #! script and it wasn't working with #!/bin/usr/env ts-node. But based on your response, I tried #!/bin/usr/env node --require ts-node/register and it works!

@davidonlaptop
Copy link

These solutions didn't work for my use case, nothing was getting executed and no errors were thrown.

But here's something that worked:

Changing line 795 from

proc = spawn(process.argv[0], args, { stdio: 'inherit' });

to

proc = spawn(args.shift(), args, { stdio: 'inherit' });

However, I don't know if this would break something else, I just thought to post this here if others encounter the same problem.

@davidonlaptop
Copy link

I've submitted a new PR: #1243

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

6 participants