From 3b8092c1ce8ca64da9daee646167f14f89085d5c Mon Sep 17 00:00:00 2001 From: Michael Zapata Date: Mon, 3 Jul 2017 16:07:23 +1200 Subject: [PATCH 1/2] feat(xdg_compat): add handling of XDG_CONFIG_HOME Only add paths where needed, keeping all possibilities that were offered before --- src/constants.js | 4 +++- src/util/rc.js | 2 ++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/constants.js b/src/constants.js index 2ab648dda7..119ab82029 100644 --- a/src/constants.js +++ b/src/constants.js @@ -55,7 +55,9 @@ function getCacheDirectory(): string { } export const MODULE_CACHE_DIRECTORY = getCacheDirectory(); -export const CONFIG_DIRECTORY = getDirectory('config'); +export const CONFIG_DIRECTORY = process.env.XDG_CONFIG_HOME + ? path.join(process.env.XDG_CONFIG_HOME, 'yarn') + : getDirectory('config'); export const LINK_REGISTRY_DIRECTORY = path.join(CONFIG_DIRECTORY, 'link'); export const GLOBAL_MODULE_DIRECTORY = path.join(CONFIG_DIRECTORY, 'global'); diff --git a/src/util/rc.js b/src/util/rc.js index 7ee546fd79..79e51a2dcd 100644 --- a/src/util/rc.js +++ b/src/util/rc.js @@ -2,6 +2,7 @@ import {readFileSync} from 'fs'; import {basename, dirname, join} from 'path'; +import {CONFIG_DIRECTORY} from '../constants.js'; const etc = '/etc'; const isWin = process.platform === 'win32'; @@ -49,6 +50,7 @@ export function findRc(name: string, parser: Function): Object { } if (home) { + addConfigPath(CONFIG_DIRECTORY, `${name}rc`); addConfigPath(home, '.config', name, 'config'); addConfigPath(home, '.config', name); addConfigPath(home, `.${name}`, 'config'); From c23a70b4aea580a98c7f98bcb774ec4af384df7c Mon Sep 17 00:00:00 2001 From: Michael Zapata Date: Wed, 5 Jul 2017 14:53:44 +1200 Subject: [PATCH 2/2] test(e2e): ensure non-reg while following xdg spec With `~/.yarnrc` being the historic location, breakage should not occur for current users --- end_to_end_tests/data/run-yarn-test.sh | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/end_to_end_tests/data/run-yarn-test.sh b/end_to_end_tests/data/run-yarn-test.sh index eb4bf1c032..d2afac0e65 100755 --- a/end_to_end_tests/data/run-yarn-test.sh +++ b/end_to_end_tests/data/run-yarn-test.sh @@ -12,6 +12,11 @@ fail_with_log() { exit $exitcode } +check_config() { + XDG_CONFIG_HOME=~/config_path yarn config get $1 > config_output + echo $2 | diff config_output - || fail_with_log +} + cd /tmp mkdir yarntest cd yarntest @@ -23,3 +28,12 @@ yarn --version || fail_with_log rm -rf ~/.cache/yarn yarn add react || fail_with_log + +# Ensure that we follow the xdg spec +mkdir ~/config_path +echo "foo bar" > ~/config_path +check_config foo bar + +# Ensure that compatibility with the old config format is maintained +echo "bar baz" >> ~/.yarnrc +check_config bar baz