-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
Pass extra arguments to npmClient during bootstrap #834
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good start.
I'd really like to see an integration test to validate our usage of yargs
.
README.md
Outdated
Pass extra arguments to npm client. | ||
|
||
```sh | ||
$ lerna bootstrap --npm-client=yarn --npm-client-args=--ignore-engine |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How do you pass multiple flags to --npm-client-args
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As --npm-client-args
is just a string and simply proxies everything to underlying npm client, it'll be:
lerna bootstrap --npm-client=yarn --npm-client-args='--ignore-engine --flag1 --flag2 ...'
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately that's not how execa
works, you need to pass an array of arguments (or push multiple, in this case) if there are multiple arguments.
README.md
Outdated
@@ -790,6 +790,24 @@ May also be configured in `lerna.json`: | |||
} | |||
``` | |||
|
|||
#### --npm-client-args [client] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This needs to be defined for yargs in the builder
export of BootstrapCommand.
Even better, why not just accept all args after a --
to lerna bootstrap
to be passed to the client execution?
lerna bootstrap -- --ignore-engine --silent
To pass it via lerna.json, you'd need to pass an array of strings instead of a string:
"npmClientArgs": ["--ignore-engine", "--silent"]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we want to isolate it to bootstrap
command only? I thought it should be for all of them regardless of where npm client is used.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
bootstrap
is currently the only place we alternate on the value of npmClient
, and it seems cleaner that way (supporting multiple arguments properly without re-implementing yargs, for example)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems accepting all args after --
is the lottery winner. My only concern is it's not very explicit and bootstrap isn't just a proxy of [npm | yarn] install
so it might be confusing whether args get appended to entire flow of bootstrap or particular parts of it.
I can live with that :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@evocateur what if both npmClientArgs and --
are provided, should we append one to another or replace? I vote for append as it'll work like "common arguments you always want to pass".
ec62e81
to
e049d41
Compare
@evocateur please take another look; i wanted to add integration tests, but couldn't find proper way to capture arguments and do assertion - feels like there is need for mock npm client for that |
It would be sufficient to test whether it respects |
Good call. Will do. |
src/commands/BootstrapCommand.js
Outdated
@@ -46,13 +46,19 @@ export default class BootstrapCommand extends Command { | |||
} | |||
|
|||
initialize(callback) { | |||
const { registry, npmClient } = this.options; | |||
const { registry, npmClient, npmClientArgs } = this.options; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This needs a npm-client-args
config in the builder
object above
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Specifically, using this block starting at line 12:
export function handler(argv) {
return new BootstrapCommand([...argv.npmClientArgs], argv).run();
}
export const command = "bootstrap [npm-client-args..]";
This pattern is used in lerna exec
(and run
): https://github.com/lerna/lerna/blob/master/src/commands/ExecCommand.js#L8
Thus you can alias a collection of all unparsed positional arguments, as well as unparsed remainders behind --
.
lerna bootstrap --scope foo -- --bar
lerna bootstrap --hoist -- --no-optional
It should still be retrievable from this.options.npmClientArgs
, but it's also always present as an array (which might be empty).
Also, don't worry about making several commits, I'll be squashing the PR anyway. |
D'oh! Unfortunately we cannot move forward with yargs until there is fix for yargs/yargs#682. Next version (hasn't been released yet) adds |
@evocateur ready for another round with integration tests included! thanks for patience 🍻 |
"packages/package-1/node_modules/clone", | ||
"packages/package-1/node_modules/columnify", | ||
"packages/package-1/node_modules/defaults", | ||
"packages/package-1/node_modules/pify", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pify shouldn't be here, hmm
b1bec8c
to
0304745
Compare
One test is failing and it says |
Turned out it was |
Yeah, it's because
That being said, you're correct! We might want to focus on different flags, perhaps? Perhaps it would be easier to use |
765374b
to
17a9bce
Compare
I ended up using fake npm client, which is less error prone, doesn't have side effects and comes with predictable behavior. Everything should stable now. |
import normalizePath from "normalize-path"; | ||
import path from "path"; | ||
import tempy from "tempy"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I sorted everything as I didn't know where to put new imports
@evocateur knock knock! |
@xaka thanks alot! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we're going to need to change part of the bootstrap algorithm to make this fully-functional. (the part where we mangle the temporary package.jsons)
@@ -65,6 +67,22 @@ describe("lerna bootstrap", () => { | |||
const stdout = await execa.stdout(LERNA_BIN, ["run", "test", "--", "--silent"], { cwd }); | |||
expect(stdout).toMatchSnapshot("--npm-client yarn: stdout"); | |||
}); | |||
|
|||
test.concurrent("passes remaining arguments to npm client", async () => { | |||
const cwd = await initFixture("BootstrapCommand/npm-client-args"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We also need an integration test that doesn't employ the npmClientArgs
key in lerna.json (using the BootstrapCommand/basic
fixture, for example). I'm pretty sure that fails right now, as is.
@@ -0,0 +1,3 @@ | |||
#!/usr/bin/env node | |||
|
|||
require("fs").writeFileSync(require("path").resolve(__dirname, "npm-debug.log"), process.argv.slice(2)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we need to write a file, just console.log
the argv and assert on the command's stdout
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unfortunately bootstrap doesn't proxy npm client output
Of course, you're right! I apologize for my scattered attention.
… On Jun 7, 2017, at 09:09, Pavel Strashkin ***@***.***> wrote:
@xaka commented on this pull request.
In test/fixtures/BootstrapCommand/npm-client-args/npm:
> @@ -0,0 +1,3 @@
+#!/usr/bin/env node
+
+require("fs").writeFileSync(require("path").resolve(__dirname, "npm-debug.log"), process.argv.slice(2));
unfortunately bootstrap doesn't proxy npm client output
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or mute the thread.
|
@evocateur added another integration test for remaining arguments without |
Hi! We'd love to see this merged for facebook/create-react-app#2673; is there anything I can do to help? Specifically, we're trying to run If not, take this as a friendly bump! 😄 |
I didn't realize the durable Thanks @xaka for your patience. :) |
@evocateur just couple months, no prob man 🍻 😄 next time i'll start with FB to bribe you first, hehe |
Augh, AppVeyor is exasperating. 2 out of 3 pass, so I'm calling it good. |
Cheers, thanks so much! |
This thread has been automatically locked because there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Description
Allow to pass npmClient arguments.
Motivation and Context
#813
How Has This Been Tested?
Types of changes
Checklist: