guybedford / chomp

'JS Make' - parallel task runner for the frontend ecosystem with a JS extension system.
https://chompbuild.com
Apache License 2.0
138 stars 7 forks source link

Functions in replacement syntax #165

Open guybedford opened 1 year ago

guybedford commented 1 year ago

We currently support replacement syntax like GitHub actions via ${{ }} which currently is only supported in ENV, but could be extended to further strings.

This replacement syntax currently only supports a single uppercase expression of another ENV var to replace into the string.

The proposal would be to extend the replacement system to support functions - someFunction(...) with comma-separated arguments, including strings and literals.

For example:

[env]
NAME = "${{ readFile('name.txt') }}"

would set an environment variable from the contents of a file.

Common configuration formats could also be supported:

[env]
VERSION = "${{ json('package.json', 'version') }}"

would set the VERSION environment variable to the contents of the package.json "version" field.

There would be no participation in the task graph, so one would still need to add these files into the task graph normally.

Alternatively we could automatically treat any file dependencies caused by these functions as dependencies of all tasks, just like in theory the chompfile.toml itself should really be. Possibly even exposing this feature separately as a top-level global-deps = ["chompfile.toml"], for dependencies of all tasks.

guybedford commented 1 year ago

Global environment functions referencing files would be global dependency additions, while task-local environment functions referencing files would be task-specific dependency additions.