Yarn 2 only supports those env variables (see official doc)
npm_package_namenpm_package_versionnpm_execpathnpm_config_user_agentnpm_node_execpathnpm_lifecycle_event
But they use to support many more when running scripts.
This plugin aims to add them.
If you're using yarn berry (yarn 2 and more), you can run:
yarn plugin import https://raw.githubusercontent.com/Ayc0/yarn-plugin-envs/v0.0.3/src/index.js to install it.
All fields (except exceptions) present in the package.json will be available, in a serialized way.
For instance, if you have this package.json:
{
"name": "hello",
"version": "1.2.3",
"keywords": ["roses", "are", "red"],
"scripts": {
"hello": "world"
}
}will generates those env vars:
npm_package_name=hello
npm_package_version=1.2.3
npm_package_keywords_0=roses
npm_package_keywords_1=are
npm_package_keywords_2=red
npm_package_scripts_hello=world(note: all values will be converted to strings)
We don't want to get the default global NPM configs, So, we won't inject env like npm_config_version_git_tag, or npm_config_version_tag_prefix, or npm_config_init_license for instance.
In yarn 1, yarn was generating mappings and making them available as env vars. But we don't want to support those.
For instance if you were running yarn hello, yarn was injecting:
npm_config_argv='{"remain":[],"cooked":["run","hello"],"original":["hello"]}'As we don't see the point of those, we decided to not supporting them.
In the package.json, some fields can be written in multiple ways.
For instance, you can write:
{
"author": "Ayc0 <ayc0.benj@gmail.com>",
"author": {
"name": "Ayc0",
"email": "ayc0.benj@gmail.com"
}
}As we don't want to include complex text parsers and keep this plugin as simple as possible, we won't support neither author, nor contributors, nor repository nor funding (different syntax but same idea).
In addition to having multiple string patterns in the package.json, the license could also be defined based on a LICENSE file present alongside the package.json.
As said before, we want to keep this plugin as simple as possible, so if we don't support string patterns, we won't check for files present on the disk.
So we won't support npm_package_license nor npm_package_readmeFilename (even if they are written in the package.json)
npm_config_version_git_tagnpm_config_registrynpm_config_pythonnpm_config_ignore_scriptsnpm_config_ignore_optionalnpm_config_init_licensenpm_config_strict_sslnpm_config_save_prefixnpm_config_user_agentnpm_config_version_git_signnpm_node_execpathnpm_execpathnpm_config_emailnpm_config_usernamenpm_config_version_git_messagenpm_config_version_tag_prefixnpm_config_version_commit_hooksnpm_config_bin_linksnpm_config_init_version
npm_config_argv
npm_package_repository_*npm_package_author_*npm_package_contributors_*npm_package_funding_*
npm_package_readmeFilenamenpm_package_license