From 545cb546cc25ac1cdc0e4fc021f710e36e1296ed Mon Sep 17 00:00:00 2001 From: Georgijs <48869301+gvilums@users.noreply.github.com> Date: Thu, 11 Apr 2024 19:06:50 -0700 Subject: [PATCH] feat(cli): --filter flag (#8185) * Skeleton code for `bun run --workspace` * Update run_command.zig * implement directory traversal to find workspace root * finish --workspace implementation * clean up changes in run_command.zig * add workspace tests, update harness to handle nested dirs * [autofix.ci] apply automated fixes * basic filtering * [autofix.ci] apply automated fixes * working filter without patterns * update tests, filter mostly working * simplify package name parsing, commit tests * support filter even without workspace setup * move filter arg handling to separate source file * use bun.sys.chdir, match root package for scripts * fix exit code handling * ignore node_modules and directories starting with . in --filter * progress converting --filter to use iterators * convert filtering to use iterators * cleanup * implement DirEntry access method for glob (currently crashing) * cleanup and fixes * run js files in subprocess when filter flag passed * clean up dead code * fix fd leak in run_command.zig * [autofix.ci] apply automated fixes * fix issues after merge * use posix-spawn in runBinary, fix resource PATH variable resource leak * move filter argument to runtime category * fix test harness * add js and binary tests to filter-workspace * [autofix.ci] apply automated fixes * fix compile after merge * [autofix.ci] apply automated fixes * clean up filter-workspace test * [autofix.ci] apply automated fixes * fixes to running binaries * fix actually setting cwd_override * windows fixes * address some review comments * handle malformed JSON * add various tests * [autofix.ci] apply automated fixes * update docs for filter * [autofix.ci] apply automated fixes * reset tinycc commit * filtered run prototype * make pretty * implement abort handler (not working) * make prettier * prep for windows * windows path and printing fixes * implement log-style output (not tui) * fix issues when logging to file * revert a bunch of unecessary changes * cleanup * implement dependency order execution * detect circular dependencies, fix cancel hang * Fix `$PATH` * ignore dep order on loop, stream on linux, sort pkgs * support pre and post scripts * add more filter tests, print elapsed time * enable 'bun --filter' without run * fix harness after merge * [autofix.ci] apply automated fixes * print number of scripts we're waiting for * update docs, fix windows build * fix tests on windows * [autofix.ci] apply automated fixes * fix uninitialized memory * use terminal synchronized update sequences * Add skip list * Preallocate * Use current bun in tests --------- Co-authored-by: Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com> Co-authored-by: Jarred Sumner --- docs/cli/filter.md | 58 +++ docs/cli/run.md | 13 + docs/install/workspaces.md | 1 + docs/nav.ts | 3 + src/bun.js/api/bun/process.zig | 6 + src/cli.zig | 26 ++ src/cli/filter_arg.zig | 258 +++++++++++ src/cli/filter_run.zig | 639 ++++++++++++++++++++++++++ src/cli/run_command.zig | 39 +- src/glob.zig | 242 ++++++++-- src/json_parser.zig | 3 - src/logger.zig | 8 + src/shell/interpreter.zig | 2 +- test/cli/run/filter-workspace.test.ts | 371 +++++++++++++++ test/harness.ts | 48 +- 15 files changed, 1635 insertions(+), 82 deletions(-) create mode 100644 docs/cli/filter.md create mode 100644 src/cli/filter_arg.zig create mode 100644 src/cli/filter_run.zig create mode 100644 test/cli/run/filter-workspace.test.ts diff --git a/docs/cli/filter.md b/docs/cli/filter.md new file mode 100644 index 0000000000000..4869c69a72e81 --- /dev/null +++ b/docs/cli/filter.md @@ -0,0 +1,58 @@ +Use the `--filter` flag to execute lifecycle scripts in multiple packages at once: + +```bash +bun --filter