Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(config): use XDG config specification #3674

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions end_to_end_tests/data/run-yarn-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
4 changes: 3 additions & 1 deletion src/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand Down
2 changes: 2 additions & 0 deletions src/util/rc.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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');
Expand Down