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

win: fix spawning npm #635

Closed
wants to merge 1 commit into from
Closed

Conversation

bzoz
Copy link
Contributor

@bzoz bzoz commented Dec 6, 2018

Fixes spawning npm under Windows. CITGM would try to spawn npm-cli.js directly, causing Windows Script Host to get used to run the npm code.

Fixes: #634

Checklist
  • npm test passes (linter passes, tests are broken on Windows)
  • contribution guidelines followed here

Fixes spawning NPM under Windows.

Fixes: nodejs#634
@codecov-io
Copy link

codecov-io commented Dec 6, 2018

Codecov Report

Merging #635 into master will decrease coverage by 0.21%.
The diff coverage is 77.77%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #635      +/-   ##
==========================================
- Coverage   95.46%   95.24%   -0.22%     
==========================================
  Files          26       26              
  Lines         816      821       +5     
==========================================
+ Hits          779      782       +3     
- Misses         37       39       +2
Impacted Files Coverage Δ
lib/package-manager/install.js 95.12% <77.77%> (-4.88%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 0909e23...b3b60c3. Read the comment docs.

@bzoz
Copy link
Contributor Author

bzoz commented Dec 6, 2018

/cc @nodejs/citgm

if (context.options.testPath) {
options.env.PATH = `${context.options.testPath}:${process.env.PATH}`;
nodeBin = which('node', {
path: options.env.PATH || process.env.PATH
Copy link
Member

Choose a reason for hiding this comment

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

Can options.env.PATH ever not be process.env.PATH outside of this if? (i.e. does the nodeBin calculation need to occur outside of the if statement?)

@targos
Copy link
Member

targos commented Dec 6, 2018

The code being very similar to what we have in https:/nodejs/citgm/blob/b3b60c38152925661362e2f725ca8e7e8e52ab0a/lib/package-manager/test.js, would it make sense to extract it to a common function?

const binDirectory = path.dirname(packageManagerBin);
options.env.PATH = `${binDirectory}:${process.env.PATH}`;

const proc = spawn(packageManagerBin, args, options);
const proc = spawn(nodeBin, args, options);
Copy link
Member

Choose a reason for hiding this comment

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

does this still work if the package manager is a script? Say I halve aliased npm to some

#!/usr/bin/env bash

node /path/to/npm.js --log-level=silly $0

More real script - the recommended way of installing yarn on mac is through brew - and they use a script not a JS file. So node cannot execute the file. See #560 (comment)

@targos
Copy link
Member

targos commented Dec 8, 2018

There is an alternative fix already proposed here: 84b5048

@bzoz
Copy link
Contributor Author

bzoz commented Dec 11, 2018

@refack fix from #619 is far better, I'm gonna close this in favor of his PR.

@bzoz bzoz closed this Dec 11, 2018
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.

5 participants