The !include directive¶
Stack's configuration files are in the YAML format. Stack
also supports the use of an !include local tag together with scalar content
that represents an absolute or relative path to another file. This provides a
directive that allows the content of one YAML file to be included in another.
The directive can be used in both project-level and global configuration files.
Note
An included relative file path is relative to the directory containing the
file with the !include directive.
Warning
The stack config set
commands cannot modify a configuration file that excludes the relevant key
and uses !include directives.
Including a value¶
A value for a key can be provided by an included file. For example, given a file
snapshot.yaml in the project directory with the content:
the following project-level configuration file would use lts-24.43 as the
snapshot:
The included file replaces the !include directive with its content, so this is
equivalent to:
Including a sequence¶
The value provided by an included file is not limited to scalar content. It can
be a YAML sequence. For example, given a file extra-deps.yaml in the project
directory with the content:
the following project-level configuration file would use those as extra-deps:
Merging mappings¶
YAML's merge key (<<) is used to indicate that all of the keys of one or more
specified mappings should be inserted into the current mapping.
YAML's merge key can be combined with an !include directive to merge the
content of an included file into the current mapping. For example, given a file
shared-config.yaml in the project directory with the content:
the following project-level configuration file would merge those options:
This is equivalent to:
The !include directive can also be placed on the line after the merge key:
Nested includes¶
Included files can themselves contain !include directives, allowing for nested
composition of configuration.
Note
A file cannot include itself or a file that has already included the file. Stack detects and raises an error for cyclic includes.