Skip to content

Commit

Permalink
Loads extra arguments from the yarnrc files
Browse files Browse the repository at this point in the history
  • Loading branch information
Maël Nison committed Apr 3, 2017
1 parent 76c9fc1 commit dfebd68
Show file tree
Hide file tree
Showing 2 changed files with 103 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/cli/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import * as network from '../util/network.js';
import {MessageError} from '../errors.js';
import aliases from './aliases.js';
import Config from '../config.js';
import {getRcArgs} from '../rc.js';
import {camelCase} from '../util/misc.js';

const chalk = require('chalk');
Expand Down Expand Up @@ -167,7 +168,7 @@ if (ARGS_THAT_SHARE_NAMES_WITH_OPTIONS.indexOf(commandName) >= 0 && args[0] ===
args.shift();
}

commander.parse(startArgs.concat(args));
commander.parse(getRcArgs().concat(startArgs).concat(args));
commander.args = commander.args.concat(endArgs);

if (command) {
Expand Down
101 changes: 101 additions & 0 deletions src/rc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
import { readFileSync } from 'fs';
import rc from 'rc';

import parse from './lockfile/parse.js';

// Keys that will be propagated into the command line as arguments
const ARG_KEYS = [
'production',

'offline',
'prefer-offline',
'proxy',
'https-proxy',
'network-concurrency',

'strict-semver',
'ignore-engines',
'ignore-optional',
'ignore-platform',
'ignore-scripts',
'skip-integrity-check',

'no-lockfile',
'pure-lockfile',
'frozen-lockfile',

'no-bin-links',
'link-duplicates',
'flat',

'cache-folder',
'modules-folder',
'global-folder',

'mutex',

'no-emoji',
'har',
];

// Keys that will get resolved relative to the path of the rc file they belong to
const PATH_KEYS = [
'cache-folder',
'global-folder',
'modules-folder',
];

// Map old keys to more recent ones
const ALIAS_KEYS = {
//'yarn-offline-mirror': 'mirror-path'
//'skip-integrity-check': 'ignore-integrity'
};

const buildRcConf = () => rc('yarn', {}, [], fileText => {
const values = parse(fileText, null);

for (let key of Object.keys(ALIAS_KEYS)) {
if (Object.prototype.hasOwnProperty.call(values, key)) {
values[ALIAS_KEYS[key]] = values[key];
}
}

for (let key of PATH_KEYS) {
if (Object.prototype.hasOwnProperty.call(values, key)) {
values[key] = resolve(dirname(filePath), values[key]);
}
}

return values;
});

export function getRcConf() {
if (!getRcConf.cache)
getRcConf.cache = buildRcConf();

return getRcConf.cache;
}

const buildRcArgs = () => ARG_KEYS.reduce((args, key) => {
const value = getRcConf()[key];

if (typeof value === 'string') {
args = args.concat([ `--${key}`, value ]);
} else if (typeof value === 'boolean') {
args = args.concat([ `--${key}` ]);
}

return args;
}, []);

export function getRcArgs() {
if (!getRcArgs.cache)
getRcArgs.cache = buildRcArgs();

return getRcArgs.cache;
}

export function clearRcCache() {
getRcConf.cache = null;
getRcArgs.cache = null;
}

0 comments on commit dfebd68

Please sign in to comment.