Skip to content

Commit

Permalink
fix(config): allow global-folder to be set in .yarnrc (#7056)
Browse files Browse the repository at this point in the history
* fix(config): allow global-folder to be set in .yarnrc

* Update CHANGELOG.md
  • Loading branch information
niheaven authored and arcanis committed Feb 28, 2019
1 parent 595006a commit 9fae32c
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 4 deletions.
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

- Allows `global-folder` to be set in `.yarnrc` files

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

- Makes `yarn version` cancellable via ctrl-c or empty string

[#7064](https://github.com/yarnpkg/yarn/pull/7064) - [**Olle Lauri Boström**](https://github.com/ollelauribostrom)
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

0 comments on commit 9fae32c

Please sign in to comment.