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

[Windows] Always spawn into new shell on windows + Run npm via node executable #69

Merged
merged 4 commits into from
Jul 12, 2017
Merged

[Windows] Always spawn into new shell on windows + Run npm via node executable #69

merged 4 commits into from
Jul 12, 2017

Conversation

katemihalikova
Copy link
Collaborator

@katemihalikova katemihalikova commented Jul 11, 2017

Fixes for windows-specific issues #60, #58, and #62

@katemihalikova katemihalikova changed the title Windows [Windows] Always spawn into new shell on windows + Run npm via node executable Jul 11, 2017
Copy link
Owner

@zkat zkat left a comment

Choose a reason for hiding this comment

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

The shell: patch is 💯. I think we need to figure out something better for the other part?

child.js Outdated
@@ -8,7 +8,7 @@ function runCommand (command, opts) {
const cmd = opts.call || command || opts.command
const copts = (opts.call ? [] : opts.cmdOpts) || []
return spawn(cmd, copts, {
shell: opts.shell || !!opts.call,
shell: opts.shell || !!opts.call || process.platform === 'win32',
Copy link
Owner

Choose a reason for hiding this comment

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

ahahah Yes

index.js Outdated
return which(opts.npm).then(npmPath => {
const args = ['config', 'get', 'cache', '--parseable']
return which('node').then(nodePath => {
const args = [opts.npm, 'config', 'get', 'cache', '--parseable']
Copy link
Owner

Choose a reason for hiding this comment

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

Does this actually still work if someone does --npm=npm? 🤔 That's why this code was doing this. The opts.npm option can be a path to the npm script itself or to the name of the binary in $PATH.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Oh, makes sense. What about we run it through this way only for windows and only if opts.npm is absolute and/or ends with .js?

Copy link
Owner

Choose a reason for hiding this comment

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

I'm fine trying this out. I think that would probably cover most cases? 🤔

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

What about which(opts.npm).catch(() => args.unshift(opts.npm) && which('node')).then(path => child.exec(path, args))?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This would leave the current implementation untouched and just add a fallback for windows and bundled npm (and .js files in --npm switch).

Copy link
Owner

@zkat zkat Jul 11, 2017

Choose a reason for hiding this comment

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

I think you can skip which('node') altogether and just use process.argv[0], which will always point to a node executable? This otherwise sounds 👍

@zkat
Copy link
Owner

zkat commented Jul 11, 2017

Thanks a bunch for submitting this!! You've been so helpful with Windows stuff and it saves me a ton of time 😻

@zkat
Copy link
Owner

zkat commented Jul 11, 2017

@katemihalikova LGTM once tests on CI are passing~

@katemihalikova
Copy link
Collaborator Author

katemihalikova commented Jul 11, 2017

I've added the fallback also to getEnv function. Without it, npx is still opening the node-bin.js npm-cli.js file in my editor..

Copy link
Owner

@zkat zkat left a comment

Choose a reason for hiding this comment

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

This is some seriously stellar work and I can't tell you how much I appreciate you taking the time to sleuth through all this. I really wish I were doing a better job of treating windows well, and I'm glad it's getting the attention it needs now <3

@zkat zkat merged commit 6cfb8de into zkat:latest Jul 12, 2017
@motss
Copy link

motss commented Jul 12, 2017

@zkat @katemihalikova I've tested the fix on my Windows 10 machine. Unfortunately this fix is not a complete one as this only solves the issue when it's being used on a Windows' CMD. While most of the developers who code on Windows machines use some other consoles like Git Bash, ConEmu, babun, etc, they still suffer from the issue.

The only version of npx is working on Windows machine is ^5.0. It just worked like a charm on this version.

@katemihalikova
Copy link
Collaborator Author

@motss Thanks for the info, we know that already. This is going to be addressed in the near future. Most alternative shells used on Windows work in a way somewhere between unix-like and cmd.exe so it's difficult to sort it out sometimes..

@katemihalikova katemihalikova deleted the windows branch July 12, 2017 17:07
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.

None yet

3 participants