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

fix(config): allow global-folder to be set in .yarnrc #7056

Merged
merged 4 commits into from Feb 28, 2019
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Expand Up @@ -4,6 +4,10 @@ Please add one entry in this file for each change in Yarn's behavior. Use the sa

## Master

- Allow `global-folder` to be set in `.yarnrc`.

[#7056](https://github.com/yarnpkg/yarn/pull/7056) - [**Hsiao-nan Cheung**](https://github.com/niheaven)

- Fix yarn `upgrade --scope` when using exotic (github) dependencies.

[#7017](https://github.com/yarnpkg/yarn/pull/7017) - [**Jeff Valore**](https://twitter.com/codingwithspike)
Expand Down
18 changes: 18 additions & 0 deletions __tests__/commands/config.js
Expand Up @@ -36,6 +36,24 @@ test('cache-folder flag has higher priorities than .yarnrc file', (): Promise<vo
);
});

test('write global-folder config into .yarnrc file', (): Promise<void> => {
return runConfig(['set', 'global-folder', 'folder_dir_for_test'], {}, '', async config => {
const configFile = await fs.readFile(config.registries.yarn.homeConfigLoc);
expect(configFile).toContain('folder_dir_for_test');
});
});

test('global-folder flag has higher priorities than .yarnrc file', (): Promise<void> => {
return runConfig(
['set', 'global-folder', 'set_config_folder_dir'],
{globalFolder: 'flag_config_folder_dir'},
'',
config => {
expect(config.globalFolder).toContain('flag_config_folder_dir');
},
);
});

test('bin-links flag has higher priorities than .yarnrc file', (): Promise<void> => {
return runConfig(['set', 'bin-links', 'true'], {binLinks: false}, '', config => {
expect(config.binLinks).toBe(false);
Expand Down
8 changes: 6 additions & 2 deletions src/config.js
Expand Up @@ -353,6 +353,11 @@ export default class Config {
networkTimeout: this.networkTimeout,
});

this.globalFolder = opts.globalFolder || String(this.getOption('global-folder', true));
if (this.globalFolder === 'undefined') {
this.globalFolder = constants.GLOBAL_MODULE_DIRECTORY;
}

let cacheRootFolder = opts.cacheFolder || this.getOption('cache-folder', true);

if (!cacheRootFolder) {
Expand Down Expand Up @@ -397,7 +402,7 @@ export default class Config {
this.plugnplayPersist = false;
} else {
this.plugnplayEnabled = false;
this.plugnplayEnabled = false;
this.plugnplayPersist = false;
}

if (process.platform === 'win32') {
Expand Down Expand Up @@ -472,7 +477,6 @@ export default class Config {

this.preferOffline = !!opts.preferOffline;
this.modulesFolder = opts.modulesFolder;
this.globalFolder = opts.globalFolder || constants.GLOBAL_MODULE_DIRECTORY;
this.linkFolder = opts.linkFolder || constants.LINK_REGISTRY_DIRECTORY;
this.offline = !!opts.offline;
this.binLinks = !!opts.binLinks;
Expand Down
4 changes: 2 additions & 2 deletions src/registries/yarn-registry.js
Expand Up @@ -31,8 +31,8 @@ export const DEFAULTS = {
'user-agent': [`yarn/${version}`, 'npm/?', `node/${process.version}`, process.platform, process.arch].join(' '),
};

const RELATIVE_KEYS = ['yarn-offline-mirror', 'cache-folder', 'offline-cache-folder', 'yarn-path'];
const FOLDER_KEY = ['yarn-offline-mirror', 'cache-folder', 'offline-cache-folder'];
const RELATIVE_KEYS = ['yarn-offline-mirror', 'cache-folder', 'global-folder', 'offline-cache-folder', 'yarn-path'];
const FOLDER_KEY = ['yarn-offline-mirror', 'cache-folder', 'global-folder', 'offline-cache-folder'];

const npmMap = {
'version-git-sign': 'sign-git-tag',
Expand Down