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

feat: yarn version berry workspace autocompletion #54

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

devthejo
Copy link

@devthejo devthejo commented Apr 3, 2022

Hello @dsifford ,
first I want to thank you for this great autocompletion script,
I use yarn berry version (v2/v3) and the completion work for most of commands except for yarn workspace, this PR solve this, detecting yarn v2/v3 and use correct completion command for workspaces adressing this issue and makin my life easier ;):
#49

@devthejo devthejo mentioned this pull request Apr 3, 2022
Copy link
Owner

@dsifford dsifford left a comment

Choose a reason for hiding this comment

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

Thanks for the contribution! This looks pretty good, except that it will not work under certain circumstances. See comments for explanation.

sed -n 's/^ \{2\}"\([^"]*\)": {$/\1/p' <<< "$workspaces_info"
)
COMPREPLY=($(compgen -W "${MAPFILE[*]}" -- "$cur"))
if [ -f .yarnrc.yml ]; then
Copy link
Owner

Choose a reason for hiding this comment

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

This will only work properly if you are completing yarn from the root of the project. If you call yarn workspace <Tab> from any child directories, this will fail.

See the following snippet for how the script locates the package.json file.

while [[ -n $cwd ]]; do
if [[ -f "$cwd/package.json" ]]; then
package_dot_json="$cwd/package.json"
break
fi
cwd="${cwd%/*}"
done

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.

2 participants