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

[feature request] deno task default args #27864

Open
andykais opened this issue Jan 29, 2025 · 1 comment
Open

[feature request] deno task default args #27864

andykais opened this issue Jan 29, 2025 · 1 comment

Comments

@andykais
Copy link

Hi all, I often find myself writing task scripts like so:

{
  "tasks": {
    "test:watch": "deno test --watch --fail-fast --unstable-ffi --allow-read --allow-write --allow-run=ffprobe,ffmpeg --allow-ffi --allow-net=github.com,objects.githubusercontent.com --import-map=test/import-map.json"
    "test": "deno test --fail-fast --unstable-ffi --allow-read --allow-write --allow-run=ffprobe,ffmpeg --allow-ffi --allow-net=github.com,objects.githubusercontent.com --import-map=test/import-map.json test"
  }
}

where I run these tasks like so: deno task test:watch <mytest> (run a specific test, and watch for changes) or deno task test (run the whole test suite). In both cases though, I sometimes want to run the command with a specific test in mind, and other times the whole test suite. Since there is no mechanism for default args in deno, this would mean creating separate commands for each of these workflows:

{
  "tasks": {
    "test:watch": "deno test --watch --fail-fast --unstable-ffi --allow-read --allow-write --allow-run=ffprobe,ffmpeg --allow-ffi --allow-net=github.com,objects.githubusercontent.com --import-map=test/import-map.json"
    "test:watch:all": "deno test --watch --fail-fast --unstable-ffi --allow-read --allow-write --allow-run=ffprobe,ffmpeg --allow-ffi --allow-net=github.com,objects.githubusercontent.com --import-map=test/import-map.json test/**/*.test.ts"
    "test": "deno test --fail-fast --unstable-ffi --allow-read --allow-write --allow-run=ffprobe,ffmpeg --allow-ffi --allow-net=github.com,objects.githubusercontent.com --import-map=test/import-map.json"
    "test:all": "deno test --fail-fast --unstable-ffi --allow-read --allow-write --allow-run=ffprobe,ffmpeg --allow-ffi --allow-net=github.com,objects.githubusercontent.com --import-map=test/import-map.json test"
  }
}

so that I can use them like so:

deno task test:all # run the whole test suite
deno task test tests/mod.test.ts # run a specific test
deno task test:watch tests/mod.test.ts # run a specific test and watch for changes
deno task test:watch:all # run the whole test suite and watch for changes

This means a ton of boilerplate for what is essentially two different commands. What I would like to propose is a way to define default args for a task when args are not specified:

{
  "tasks": {
    "test:watch": {
      "default_args": ["test/**/*.test.ts"],
      "command": "deno test --watch --fail-fast --unstable-ffi --allow-read --allow-write --allow-run=ffprobe,ffmpeg --allow-ffi --allow-net=github.com,objects.githubusercontent.com --import-map=test/import-map.json"
    },
    {
      "default_args": ["test"],
      "command": "test": "deno test --fail-fast --unstable-ffi --allow-read --allow-write --allow-run=ffprobe,ffmpeg --allow-ffi --allow-net=github.com,objects.githubusercontent.com --import-map=test/import-map.json"
    }
  }
}

which can be used like so:

deno task test # run the whole test suite
deno task test tests/mod.test.ts # run a specific test
deno task test:watch tests/mod.test.ts # run a specific test and watch for changes
deno task test:watch # run the whole test suite and watch for changes
@dsherret dsherret transferred this issue from denoland/deno_task_shell Jan 29, 2025
@dsherret
Copy link
Member

dsherret commented Jan 29, 2025

Transfered to deno because it's not specific to the shell.

Can't this be rewritten like so or what am I missing?

{
  "tasks": {
    "test:watch": "deno task test --watch"
    "test:watch:all": "deno task test:watch test/**/*.test.ts"
    "test": "deno test --fail-fast --unstable-ffi --allow-read --allow-write --allow-run=ffprobe,ffmpeg --allow-ffi --allow-net=github.com,objects.githubusercontent.com --import-map=test/import-map.json"
    "test:all": "deno task test test"
  }
}

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