-
Notifications
You must be signed in to change notification settings - Fork 465
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
spotless/prettier - .npmrc seems to be ignored #619
Comments
What version of Spotless are you using? Our approach to npm changed in |
Probably you'll need to make a change somewhere around here spotless/lib/src/main/java/com/diffplug/spotless/npm/NpmProcess.java Lines 36 to 38 in 5421f58
Happy to take a PR for this. No-obligation ping to @simschla just in case you have a broader vision for how you'd like to handle this :) |
Thanks for the quick response @nedtwigg - I tried both 4.3.0 and 4.3.1 and it pretty much just hangs in
A workaround I found was to have spotless dependOn a custom task that runs |
Personally, I've never used the npmrc. Based on the documentation, the most project-specific approach is to have a I think this would fit into the current api, using a similar approach to the prettier().npmExecutable('/usr/bin/npm').npmrc('/path/to/my/.npmrc').config(...) (Another approach would be to try do autodiscover the What do you think? |
I like the idea of being able to set .npmrc in a chained manner. Seems like the most flexible solution. |
Hi @simschla @nedtwigg - thinking a bit more about this problem, I'd also like to provide the node distribution myself. We're using https://github.com/node-gradle/gradle-node-plugin/issues in addition to spotless and would love to simply point to their node/npm distribution This would ideally mean, that the prettier() chain contains two new parameters:
I can definitely try to open a PR for this, although I'm not 100% sure how the node executable would be handled. I assume instead of calling |
@dlangerenken From within spotless, we only ever call |
As far as I can tell from looking into the code, they do run the node executable followed by npm + additional commands. So essentially See https://github.com/node-gradle/gradle-node-plugin/blob/master/src/main/kotlin/com/github/gradle/node/exec/NodeExecRunner.kt#L37 where it is passed into the execution-context (difficult to understand..) What do you suggest we do? Do you think adding a way to configure the nodeExecutable could be part of this plugin or would you rather have this not handled by spotless? I'm happy to contribute through a PR if this is something desirable. It certainly is for my use case |
Currently I don't have an opinion about this as I'm still trying to understand the usecase and/or benefits. Spotless itself does not trigger the node-executable directly, instead it calls the npm-executable. Are you suggesting that we change that and use the node-executable directly? |
Only as an optional setting. Even the gradle-node-plugin will default to the local node distribution, but it does have a download option. #!/bin/bash
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
$DIR/node $DIR/npm "$@" I actually got around the node-issue with this workaround. Instead of pointing to the npm executable, I'm simply pointing to the executable via the node executable. Currently seeing |
Okay, the Is there any workaround such that I can override this value? |
Ah, now I see your problem. Reading up on the topic it seems that calling npm directly is totally the way to go. npm does a lot in terms of trying to prepare the environment for having correct and as local as possible paths. Based on Stackoverflow, you could problably use your previous workaround
here too:
On spotless side, we could change these Lines spotless/lib/src/main/java/com/diffplug/spotless/npm/NpmProcess.java Lines 40 to 42 in 183c0b4
to Process start() {
return npm("start", "--scripts-prepend-node-path=true");
} and that should make sure, that the node-binary relating to the npm binary in use should always be first on the path. no matter how the user has set things up in his environment. |
Hi @simschla, this might does the trick. Since it's configurable through .npmrc, I suggest we focus on adding the support of this file instead of hardcoding it into NpmProcess.java. I don't know what the implications are, but I assume it could potentially break for other users who don't want the path prepended. |
Sorry I didn’t get around to work on this before my summer holidays. I’ll get to it in about two or three weeks. I hope you can live with the workarounds until then. |
Thanks @simschla - no rush. We are currently not using prettier with spotless and can wait a few more weeks until the .npmrc feature ends in a release! Happy holidays. |
Guys, I have a working prototype: main...simschla:feature/add-support-for-npmrc I'm currently struggling writing an integration test for this |
I'm okay merging it without an integration test. Testing system-level configuration is hard, sometimes there's no substitute for manual testing. |
ok, so I'll update the docs and create the PR. |
Fixed in #727. |
Published in |
My company is using a different registry for npm, specified by .npmrc:
It appears that spotless is not picking those up. Is there any way I can add this as parameter to the prettier format? (essentially it needs to run
npm install -registry=.... ...
)The text was updated successfully, but these errors were encountered: