yarn-completion: Breaks when there is }, in scripts

Having }, inside one of the scripts breaks autocompletion. MWE:

{
  "scripts": {
    "hello1": "echo 'hello1'",
    "hello2": "echo 'hello2'",
    "hello3": "echo 'hello3'",
    "hello4": "echo 'hello4'",
    "hello5": "echo 'hello5'"
  }
}

yarn run hello →tab hello1 hello2 hello3 hello4 hello5 (ok) npm run hello →tab hello1 hello2 hello3 hello4 hello5 (ok)


{
  "scripts": {
    "hello1": "echo 'hello1'",
    "hello2": "echo '},'",
    "hello3": "echo 'hello3'",
    "hello4": "echo 'hello4'",
    "hello5": "echo 'hello5'"
  }
}

yarn run hello →tab hello1 hello2 (broken) npm run hello →tab hello1 hello2 hello3 hello4 hello5 (still ok)


A real-world script that broke yarn completion was:

    `"format": "prettier --write --ignore-path .gitignore \"{.,src/**,test/**}/{*.{j,t}s{x,},*.md,ts*.json}\"",

Could the reason be in this line? https://github.com/dsifford/yarn-completion/blob/689daceca5a3b9d3dea157bd30b59bd86fa3d09b/yarn-completion.bash#L42

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Comments: 19 (19 by maintainers)

Commits related to this issue

Most upvoted comments

Version 0.6.1 should work in BSD sed now.

Urrrrgh! BSD utils are going to be the death of me, I swear…

Glad to hear we’ve found the culprit. I’ll try and get this compatible with BSD as soon as feasible. Thanks for your patience.

Thanks for for your hint about GNU sed – turns out this is exactly what caused trouble! Originally, even after installing GNU bash, man sed was starting like:

screen shot 2018-02-24 at 19 11 57

After I did brew install gnu-sed --with-default-names and restarted the Terminal, it changed to:

screen shot 2018-02-24 at 19 11 42

Consequently, yarn autocompletion 0.6.0 began to work! 🎉

I’m a frequent user of the command line, but am no way an expert in bash versions and flavours of other standard tools. All this is pretty foggy to me, so thanks for your help with sorting things out! To summarise, this is what I had to do in order to get yarn-completion on macOS High Sierra working:

brew install bash
brew install gnu-sed --with-default-names

brew install bash-completion
## + copy a few commands to ~/.bash_profile as instructed by brew after bash-completion setup

curl -L https://raw.githubusercontent.com/dsifford/yarn-completion/master/yarn-completion.bash > `brew --prefix`/etc/bash_completion.d/yarn

## restart Terminal

Hope this helps someone else in a similar situation!

@kachkaev I have no idea why this isn’t working for you. I just matched all my shell options to the ones you have enabled and it still works perfectly fine on my end.

The only thing I can think of that it might still be is that you’re using BSD sed. If you can confirm that the issue is still persisting even using GNU sed, then I’m out of ideas and will have to unfortunately wait until more people report this issue.

I’ll try in on my macbook here in the next hour or so and see if it’s a mac quirk or something.