deno_task_shell icon indicating copy to clipboard operation
deno_task_shell copied to clipboard

Support ?= short hand for setting variable if not already set

Open KyleJune opened this issue 3 years ago • 1 comments

https://www.gnu.org/software/make/manual/html_node/Setting.html#Setting

This would make it easier to re-use deno tasks in other tasks that have different environment variables.

{
  "tasks": {
    "run": "export APP_ENV ?= production && deno run --allow-read=. --allow-write=. scripts/run.js",
    "run-dev": "export APP_ENV = development && deno task run"
  },
}

Currently that short hand won't work and will give you the following error.

$ deno task run
Task run export APP_ENV ?= production && deno run --allow-read=. --allow-write=. scripts/run.js
error: Error parsing script 'run'.

Caused by:
    Globs are currently not supported, but will be soon.
      ?= production && deno run --allow-read=. --allow-write=. scripts/run.js
      ~

Since the shorthand doesn't work currently, you have to either repeat or move the common part to a separate task. The downside to the second shorthand example below is that people might use run without APP_ENV set.

{
  "tasks": {
    "run": "export APP_ENV = production && deno run --allow-read=. --allow-write=. scripts/run.js",
    "run-dev": "export APP_ENV = development && deno  run --allow-read=. --allow-write=. scripts/run.js"
  },
}
{
  "tasks": {
    "run": "deno run --allow-read=. --allow-write=. scripts/run.js",
    "run-prod": "export APP_ENV = production && deno task run"
    "run-dev": "export APP_ENV = development && deno task run"
  },
}

I was told by @bartlomieju to ping @dsherret on this feature request.

KyleJune avatar Dec 26 '22 23:12 KyleJune

Since the shorthand doesn't work currently, you have to either repeat or move the common part to a separate task. The downside to the second shorthand example below is that people might use run without APP_ENV set.

How about using a name run-template instead of run?

nm004 avatar Oct 19 '23 07:10 nm004