Mutations

A mutation is a value that describes how to change another value. Mutations are used throughout Tangram to enable easy composition of arguments and environments. For example, the mutation tg.mutation("prefix", "/usr/bin:") might be used to add the path /usr/bin to the beginning of the PATH environment variable.

// A mutation which will unset the value.
let mutation = tg.Mutation.unset();
// A mutation which will set the value.
tg.Mutation.set(value);
// A mutation which will set the value if it is not set.
tg.Mutation.setIfUnset(value);
// A mutation which will prepend to the value. The value must be an array.
tg.Mutation.prepend(value);
// A mutation which will append to the value. The value must be an array.
tg.Mutation.append(value);
// A mutation which will prefix the value with an optional separator. The value must be a string.
tg.Mutation.prefix(string, separator);
// A mutation which will suffix the value with an optional separator. The value must be a string.
tg.Mutation.suffix(string, separator);
// Add flags to the arguments.
const args = tg.Mutation.append(["--verbose", "--debug"])
const env = {
// Unset the environment variable.
CPATH: tg.Mutation.unset(),
// Always use this compiler, overrides any existing value.
CC: tg.Mutation.set("gcc"),
// Only use this compiler if none was specified.
CXX: tg.Mutation.setIfUnset("g++"),
// Prefix the value with a space separator.
CFLAGS: tg.Mutation.prefix("-Wl,-undefined-version", " ")
// Add node_modules to the end of the PATH with a colon separator.
PATH: tg.Mutation.suffix(tg`${dependencies}/node_modules`, ":");
};