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

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

Open
KyleJune opened this issue Dec 26, 2022 · 1 comment
Open

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

KyleJune opened this issue Dec 26, 2022 · 1 comment
Labels
enhancement New feature or request

Comments

@KyleJune
Copy link

KyleJune commented Dec 26, 2022

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.

@dsherret dsherret transferred this issue from denoland/deno Jan 4, 2023
@dsherret dsherret added the enhancement New feature or request label Jan 4, 2023
@nm004
Copy link

nm004 commented Oct 19, 2023

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants