denoland / deno

A modern runtime for JavaScript and TypeScript.
https://deno.com
MIT License
97.17k stars 5.37k forks source link

deno workspace: --filter or -r (recursive) #24991

Open birkskyum opened 2 months ago

birkskyum commented 2 months ago

With pnpm / bun workspace, there is a way to use --filter to select multiple packages or to select all packages bun --filter '*' or pnpm -r to run a task in all of them, typically dev, build or start.

Also, the -r flag is super convenient in pnpm update -r -i for recursively making interactive dependency updates across the entire workspace.

iceglober commented 1 month ago

I second this. I'm finding myself either having to create redundant tasks at the root level, or cd'ing into my packages for running tasks.

birkskyum commented 1 month ago

A good test for this functionality would be moving the repo below from pnpm workspace to npm workspace, building all the packages and running an example: https://github.com/histoire-dev/histoire

bartlomieju commented 1 week ago

Firstly we should check other package managers (npm, yarn, pnpm) and how they handle it and come up with a solution that best fits the needs.

shanipribadi commented 3 hours ago

Run tasks/scripts in specific package in a workspace

  1. pnpm --filter pkgA run command
  2. npm run command --workspace=pkgA
  3. yarn workspace pkgA run command
  4. bun --filter pkgA run command

Run tasks/scripts in all packages under the workspace

  1. pnpm run command -r
  2. npm run command --workspaces
  3. yarn workspaces foreach run command
  4. bun --filter ‘*’ run command

Run tasks/scripts in multiple selected packages under the workspace

  1. pnpm run command -r --filter <pattern>
  2. npm run command --workspace=pkgA --workspace=pkgB
  3. yarn workspaces foreach --from <pattern> run command
  4. bun --filter <pattern> run command

Summary

  1. bun follows pnpm approach of using filter, yarn also has glob pattern support using the from arg
  2. npm have explicit workspace arg selection that support multiple args
  3. pnpm and yarn execute commands in order of dependencies, couldn't find docs for execution order for bun/npm
  4. pnpm and yarn workspace selection is not limited to running just scripts (e.g. can do install and other commands)
  5. pnpm and yarn supports running in parallel (for pnpm it ignores topological sorting if asked to do parallel run, for yarn it is optional)
  6. pnpm and yarn has the ability to buffer the output of multiple tasks (to avoid interleaving the logs/outputs which will be hard to read)

I could see this issue split into three main things

  1. the ability to execute commands in one, multiple, or all packages under the workspace
  2. sequentially executes them with a defined ordering (topological sort based on dependency graph?)
  3. parallel execution, while keeping topological sorting or not (depending on the command to run either one of them can be preferrable)