Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const validateOpts = function({ opts, defaultOpts, forcedOpts }) {
const exampleConfig = filterObj(
{ ...EXAMPLE_OPTS, ...defaultOpts },
key => !hasOwnProperty.call(forcedOpts, key),
)
try {
validate(opts, { exampleConfig, recursiveBlacklist: ['env'] })
} catch (error) {
// `jest-validate` `error.stack` just repeats `error.message`
throwError(error, { showStack: false })
}
validateCustom({ opts })
}
async function loadConfig(
argv?: YargArguments = {},
defaultConfigOverrides?: InputConfigT = {},
): Promise {
argv.config = overrideArgument(argv.config);
const configuration = await loadMetroConfigFromDisk(
argv.config,
argv.cwd,
defaultConfigOverrides,
);
validate(configuration, {
exampleConfig: await validConfig(),
recursiveBlacklist: ['reporter', 'resolver', 'transformer'],
});
// Override the configuration with cli parameters
const configWithArgs = overrideConfigWithArguments(configuration, argv);
const overriddenConfig = {};
// The resolver breaks if "json" is missing from `resolver.sourceExts`
const sourceExts = configWithArgs.resolver.sourceExts;
if (!configWithArgs.resolver.sourceExts.includes('json')) {
overriddenConfig.resolver = {
sourceExts: [...sourceExts, 'json'],
};
}
export default function normalize(
initialOptions: Config.InitialOptions,
argv: Config.Argv,
configPath?: Config.Path | null,
projectIndex: number = Infinity,
): {
hasDeprecationWarnings: boolean;
options: AllOptions;
} {
const {hasDeprecationWarnings} = validate(initialOptions, {
comment: DOCUMENTATION_NOTE,
deprecatedConfig: DEPRECATED_CONFIG,
exampleConfig: VALID_CONFIG,
recursiveBlacklist: [
'collectCoverageOnlyFrom',
// 'coverageThreshold' allows to use 'global' and glob strings on the same
// level, there's currently no way we can deal with such config
'coverageThreshold',
'globals',
'moduleNameMapper',
'testEnvironmentOptions',
'transform',
],
});
let options = normalizePreprocessor(
export function getConfig({ cwd, configPath } = {}) {
const configExplorer = cosmiconfig("lingui")
const defaultRootDir = cwd || process.cwd()
const result = configExists(configPath)
? configExplorer.loadSync(configPath)
: configExplorer.searchSync(defaultRootDir)
const raw = { ...defaultConfig, ...(result ? result.config : {}) }
validate(raw, configValidation)
// Use deprecated fallbackLanguage, if defined
raw.fallbackLocale = raw.fallbackLocale || raw.fallbackLanguage || ""
const rootDir = result ? path.dirname(result.filepath) : defaultRootDir
return replaceRootDir(raw, rootDir)
}
export const getOptions = function({ opts = {} }) {
const optsA = filterObj(opts, isDefined)
validate(optsA, { exampleConfig: EXAMPLE_OPTS })
validateOptions(optsA)
const optsB = applyTesting({ opts: optsA })
const level = applyDefaultLevels({ opts: optsB })
const optsC = { ...DEFAULT_OPTS, ...optsB, level }
const optsD = addChalk({ opts: optsC })
return optsD
}
const getOptions = function({ opts }) {
const optsA = pickBy(opts, value => value !== undefined)
validate(optsA, { exampleConfig: DEFAULT_OPTS })
const optsB = { ...DEFAULT_OPTS, ...optsA }
return optsB
}