How to use the cosmiconfig function in cosmiconfig

To help you get started, we’ve selected a few cosmiconfig examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github iopipe / serverless-plugin-iopipe / src / index.js View on Github external
getConfig() {
    const { token } = this.getOptions();
    const { config: cosmi = {} } =
      cosmiconfig('iopipe', {
        cache: false,
        sync: true,
        rcExtensions: true
      }).load(process.cwd()) || {};

    const plugins = (cosmi.plugins || []).map(plugin => {
      // plugins can be specified as strings or as arrays with 2 entries
      // ["@iopipe/trace", ["@iopipe/logger", {"enabled": true}]]
      // create require calls for each scenario
      const pluginModule = _.isArray(plugin) ? plugin[0] : plugin;
      const pluginConfig = _.isArray(plugin) ? JSON.stringify(plugin[1]) : '';
      return `require('${pluginModule}')(${pluginConfig})`;
    });

    const inlineConfigObject = _.pickBy(
      _.assign({}, cosmi, {
github kamilkisiela / graphql-config / src / helpers.ts View on Github external
function createCosmiConfig() {
  // We need to wrap loaders in order to access and transform file content (as string)
  // Cosmiconfig has transform option but at this point config is not a string but an object
  return cosmiconfig('graphql', {
    loaders: {
      '.js': {sync: cosmi.loadJs, async: cosmi.loadJs},
      '.json': loadJson,
      '.yaml': loadYaml,
      '.yml': loadYaml,
      noExt: loadYaml,
    },
  });
}
github Cretezy / Noderize / packages / scripts / src / options.js View on Github external
type => types[type].type === Boolean
  );

  // Parse args
  const args = parseArgs(rawArgs || [], {
    boolean: boleans,
    string: Object.keys(types).filter(
      type => types[type].type === String || types[type].type === Object
    ),
    default: boleans.reduce((total, bool) => ({ ...total, [bool]: null }), {})
  });

  let options = {};
  try {
    // Load from "noderize" key in package.json, .noderizerc, or noderize.config.js
    const results = cosmiconfig("noderize").searchSync();

    if (results) {
      const configOptions = results.config || {};
      Object.keys(configOptions).forEach(configOptionKey => {
        if (types[configOptionKey] !== undefined) {
          const type = types[configOptionKey];
          let value = configOptions[configOptionKey];
          if (type.type === Array && !Array.isArray(value)) {
            value = [value];
          }
          value = run(type.run, value, { options });
          options[configOptionKey] = value;
        } else {
          log.warn(`Config key '${configOptionKey}' doesn't do anything.`);
        }
      });
github CVarisco / create-component-app / src / utils.js View on Github external
function getConfig(configPath, searchPath = process.cwd(), stopDir = homedir()) {
  const useCustomPath = !!configPath
  const explorer = cosmiconfig('cca', { sync: true, stopDir })

  try {
    const searchPathAbsolute = !useCustomPath && searchPath
    const configPathAbsolute = useCustomPath && path.join(process.cwd(), configPath)
    // search from the root of the process if the user didnt specify a config file,
    // or use the custom path if a file is passed.
    const result = explorer.load(searchPathAbsolute, configPathAbsolute)

    // dont throw if the explorer didnt find a configfile,
    // instead use default config
    const config = result ? result.config : {}
    const filepath = result ? result.filepath : {}
    if (!result) Logger.log('No config file detected, using defaults.')

    return { ...config, filepath }
  } catch (error) {
github stylelint / stylelint / src / buildConfig.js View on Github external
function loadExtendedConfig(config, configDir, extendLookup) {
  const extendPath = getModulePath(configDir, extendLookup)
  const extendDir = path.dirname(extendPath)
  return cosmiconfig(null, {
    configPath: extendPath,
    // In case `--config` was used: do not pay attention to it again
    argv: false,
  }).then(result => {
    // Make sure to also augment the config that we're merging in
    // ... but the `ignoreFiles` option only works with the
    // config that is being directly invoked, not any
    // extended configs
    return augmentConfig(stripIgnoreFiles(result.config), extendDir)
  })
}
github conventional-changelog / commitlint / @commitlint / load / src / index.ts View on Github external
async function loadConfig(
	cwd: string,
	configPath?: string
): Promise {
	const explorer = cosmiconfig('commitlint');

	const explicitPath = configPath ? path.resolve(cwd, configPath) : undefined;
	const explore = explicitPath ? explorer.load : explorer.search;
	const searchPath = explicitPath ? explicitPath : cwd;
	const local = await explore(searchPath);

	if (local) {
		return local;
	}

	return null;
}
github gregberge / svgr / packages / core / src / config.js View on Github external
icon: false,
  native: false,
  prettier: true,
  prettierConfig: null,
  ref: false,
  replaceAttrValues: null,
  svgProps: null,
  svgo: true,
  svgoConfig: null,
  template: null,
  titleProp: false,
  runtimeConfig: true,
  plugins: null,
}

const explorer = cosmiconfig('svgr', {
  sync: true,
  cache: true,
  rcExtensions: true,
})

export async function resolveConfig(searchFrom, configFile) {
  if (configFile == null) {
    const result = await explorer.search(searchFrom)
    return result ? result.config : null
  }
  const result = await explorer.load(configFile)
  return result ? result.config : null
}

resolveConfig.sync = (searchFrom, configFile) => {
  if (configFile == null) {
github UnwrittenFun / svelte-language-server / src / plugins / SveltePlugin.ts View on Github external
private async loadConfig(path: string): Promise {
        try {
            const { config } = await cosmic('svelte', {
                packageProp: false,
            }).load(path);
            return { ...DEFAULT_OPTIONS, ...config };
        } catch (err) {
            return { ...DEFAULT_OPTIONS, preprocess: {} };
        }
    }
github conventional-changelog / commitlint / @commitlint / load / src / index.js View on Github external
async function loadConfig(cwd, configPath) {
	const explorer = cosmiconfig('commitlint');

	const explicitPath = configPath ? path.resolve(cwd, configPath) : undefined;
	const explore = explicitPath ? explorer.load : explorer.search;
	const searchPath = explicitPath ? explicitPath : cwd;
	const local = await explore(searchPath);

	if (local) {
		return local;
	}

	return {};
}

cosmiconfig

Find and load configuration from a package.json property, rc file, TypeScript module, and more!

MIT
Latest version published 5 months ago

Package Health Score

84 / 100
Full package analysis