Skip to content

fix(@angular/cli): pass arguments to all targets #12673

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

Merged

Conversation

mnahkies
Copy link
Contributor

@mnahkies mnahkies commented Oct 21, 2018

When running a command with args against multiple targets, all targets should be given the args. As parseArguments was mutating the passed args array this wasn't the case.

Fix by making a shallow clone of the array. This was especially noticeable when using the ng lint --fix command on a newly generated project, as files in the app target would be fixed, but e2e target would be only be linted (with no fix).

Possibly closes #10657, #10656, #11005

@filipesilva filipesilva added this to the 7.0.2 milestone Oct 22, 2018
@filipesilva filipesilva requested a review from clydin October 22, 2018 08:48
@imcotton
Copy link
Contributor

ping @clydin

Copy link
Member

@clydin clydin left a comment

Choose a reason for hiding this comment

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

Thank you for the contribution.

This is unfortunately working around the problem and not actually solving the root cause. The algorithm should not be mutating the input array. Can you remove the mutations instead?

Reassigning arguments should also be avoided whenever possible.

@mnahkies
Copy link
Contributor Author

@clydin this is a fair comment - I'll have a look at this tonight

@clydin clydin added the target: patch This PR is targeted for the next patch release label Oct 25, 2018
@mnahkies
Copy link
Contributor Author

@clydin and now I remember why I didn't do this in the first place, not quite the simple fix I had hoped! The file is well covered by unit tests though, so I'm pretty confident that the behaviour has not been changed (aside from stopping the mutation)

@mnahkies
Copy link
Contributor Author

Hi @clydin any chance you could review this soon? Cheers

@@ -270,30 +284,73 @@ export function parseArguments(args: string[], options: Option[] | null): Argume
const ignored: string[] = [];
const errors: string[] = [];

for (let arg = args.shift(); arg !== undefined; arg = args.shift()) {
for (let i = 0; i < args.length; i++) {
Copy link
Member

Choose a reason for hiding this comment

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

Instead of using 'i' which is already used below, use something similar to argIndex. Eliminates the need to change the other loop to use j.

leftovers,
ignored,
errors,
}: {
arg: string,
Copy link
Member

Choose a reason for hiding this comment

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

change the first argument from being the actual argument to the index of the argument. You can then access the current argument and next argument by using the existing args array.

Also, have it return the new index. This would eliminate the extra conditionals present in the calling function.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't think this is possible, as the value for "arg" is computed rather than from the array for one of the function calls (I'll leave a comment pointing out the call in question)

const f = '--' + flag + arg.slice(j + 1);

const consumedNextArg = _assignOption({
arg: f,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

For this usage of _assignOption we pass in a computed value rather than a value from the args array

@ngbot
Copy link

ngbot bot commented Nov 20, 2018

Hi @mnahkies! This PR has merge conflicts due to recent upstream merges.
Please help to unblock it by resolving these conflicts. Thanks!

When running a command with args against multiple targets, all targets
should be given the args. As parseArguments was mutating the passed args
array this wasn't the case. Fix by not mutating the array.

This was especially noticeable when using the `ng lint --fix` command
on a newly generated project, as files in the app target would be fixed,
but e2e target would be only be linted (with no fix)

Possibly closes angular#10657, angular#10656, angular#11005
@mnahkies mnahkies force-pushed the fix-options-for-multi-target-commands branch from 7e86769 to 54bd5ab Compare November 20, 2018 21:05
@mnahkies
Copy link
Contributor Author

Rebased on current master

@alan-agius4
Copy link
Collaborator

This would also fix #13111

@clydin clydin added target: patch This PR is targeted for the next patch release and removed target: patch This PR is targeted for the next patch release labels Dec 6, 2018
@clydin clydin removed this from the 7.0.2 milestone Dec 6, 2018
@alexeagle alexeagle merged commit 7d88182 into angular:master Dec 6, 2018
@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 12, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
target: patch This PR is targeted for the next patch release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ng lint with format flag errors
7 participants