-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Loads extra arguments from the yarnrc files
- Loading branch information
Maël Nison
committed
Apr 3, 2017
1 parent
76c9fc1
commit dfebd68
Showing
2 changed files
with
103 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |