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

Yarn workspaces: autocompletions for scripts, .bin and file paths #847

Open
kachkaev opened this issue Feb 17, 2022 · 1 comment
Open

Yarn workspaces: autocompletions for scripts, .bin and file paths #847

kachkaev opened this issue Feb 17, 2022 · 1 comment

Comments

@kachkaev
Copy link

kachkaev commented Feb 17, 2022

👋 folks! I’ve been a heavy user of yarn workspaces for some time and would like to suggest an improvement to autocompletions. It might be quite a difficult one to implement, but is at least worth tracking.

Let’s take this repo as an example:
https://github.com/ferreiro/example-monorepo

We have two folders: packages/client and packages/server. They correspond to workspaces named client and server, respectively (the names are located in package.json files).

In a broader case, any folder can be a workspace and the name of the package can be anything, e.g. a folder named /apps/docs may map to a workspace named @mycorp/my-docs-app.

This repo’s yarn completion works well up to this point:

yarn workspace c →
yarn workspace client

yarn workspace s →
yarn workspace server

yarn workspace @m →
yarn workspace @mycorp/
yarn workspace @mycorp/m →
yarn workspace @mycorp/my-docs-app

That's useful, especially if a workspace starts with @ and is therefore lengthy. If we press tab after the workspace name, we will always see:

add                  -- Installs a package and any packages that it depends on
bin                  -- Displays the location of the yarn bin folder
list                 -- List installed packages
remove               -- Remove installed package from dependencies updating package.json
upgrade              -- Upgrades packages to their latest version based on the specified range
upgrade-interactive  -- Interactively upgrade packages

That‘s cool, but the list is not as complete as for the root workspace. What would be really cool is to also get autocompletion for scripts, binaries and local file names within a workspace:

yarn workspace client st →
yarn workspace client start
## because we have packges/client/package.json → scripts → start

yarn workspace @mycorp/my-docs-app j →
yarn workspace @mycorp/my-docs-app jest
## because we have apps/docs/node_modules/.bin/jest

yarn workspace @mycorp/my-docs-app jest s→
yarn workspace @mycorp/my-docs-app jest src/
yarn workspace @mycorp/my-docs-app jest src/hello.te →
yarn workspace @mycorp/my-docs-app jest src/hello.test.js
## because we have apps/docs/src/hello.test.js

The are two main challenges:

  • resolve workspace location by name via
    • yarn workspaces info in Yarn 1
    • yarn workspaces list --json in Yarn 2+
  • get the list of scripts, binaries and files relative to a resolved workspace folder

I’d be keep to help if this plugin was written in JavaScript, but my knowledge of shell is way too limited to grab this improvement task. 😅 Happy to take part in testing if needed! 🙌

@jmatsushita
Copy link

Would love to see this too!

Note that in yarn >2.4.3 (also tested in 3.6.0 and 4.0.0-rc.46) yarn workspace client run returns the following which could be used to inform the completions.

> yarn workspace client run
➤ YN0000: clean               'rm -rf node_modules'
➤ YN0000: lint                'tsc --noEmit && eslint "src/**/*.ts*"'
➤ YN0000: start               'node index.js'
➤ YN0000: Done in 0s 2ms

Unfortunately the --json argument doesn't seem to work yet.

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

No branches or pull requests

2 participants