How to use the cosmiconfig.cosmiconfigSync 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 linthtml / linthtml / lib / cli / read-config.js View on Github external
module.exports.config_from_path = function(file_path) {
  const config_path = path.join(process.cwd(), file_path);
  let isConfigDirectory = false;
  try {
    let config = null;
    isConfigDirectory = fs.lstatSync(config_path).isDirectory();
    if (isConfigDirectory) {
      config = cosmiconfigSync("linthtml", { stopDir: config_path, packageProp: "linthtmlConfig" }).search(config_path);
    } else {
      config = explorer.load(config_path);
    }
    if (config === null) {
      throw new Error();
    }
    return config;
  } catch (error) {
    if (isConfigDirectory) {
      throw new CustomError("CLI-01", { config_path });
      // console.log(`{red Error:} Cannot read config file in directory: {underline ${config_path}}`);
    }
    throw new CustomError("CLI-02", { config_path });
  }
};
github kentcdodds / babel-plugin-macros / src / index.js View on Github external
function getConfigExporer() {
  return (_configExplorer =
    _configExplorer ||
    // Lazy load cosmiconfig since it is a relatively large bundle
    require('cosmiconfig').cosmiconfigSync('babel-plugin-macros', {
      searchPlaces: [
        'package.json',
        '.babel-plugin-macrosrc',
        '.babel-plugin-macrosrc.json',
        '.babel-plugin-macrosrc.yaml',
        '.babel-plugin-macrosrc.yml',
        '.babel-plugin-macrosrc.js',
        'babel-plugin-macros.config.js',
      ],
      packageProp: 'babelMacros',
    }))
}
github wintercounter / mhy / src / resources / babelPluginMacros.js View on Github external
function getConfigExporer() {
    return (_configExplorer =
        _configExplorer || // Lazy load cosmiconfig since it is a relatively large bundle
        require('cosmiconfig').cosmiconfigSync('babel-plugin-macros', {
            searchPlaces: [
                'package.json',
                '.babel-plugin-macrosrc',
                '.babel-plugin-macrosrc.json',
                '.babel-plugin-macrosrc.yaml',
                '.babel-plugin-macrosrc.yml',
                '.babel-plugin-macrosrc.js',
                'babel-plugin-macros.config.js'
            ],
            packageProp: 'babelMacros'
        }))
}
github untool / untool / packages / core / lib / loader.js View on Github external
search(stopDir) {
    const { search } = cosmiconfig(this.namespace, { stopDir });
    return search(stopDir);
  }
  loadPreset(context, preset) {
github FujitsuLaboratories / escapin / src / index.ts View on Github external
private loadConfig() {
    const result = cosmiconfigSync('escapin').search(this.basePath);
    if (result === null) {
      throw new Error('config file not found.');
    }
    result.config.output_dir = Path.join(this.basePath, result.config.output_dir || OUTPUT_DIR);
    if (fs.existsSync(result.config.output_dir)) {
      rimraf(result.config.output_dir);
    }
    mkdirp(result.config.output_dir);

    result.config.platform = result.config.platform || PLATFORM;
    result.config.default_storage = result.config.default_storage || DEFAULT_STORAGE;

    this.config = result.config as IConfig;
  }

cosmiconfig

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

MIT
Latest version published 12 months ago

Package Health Score

83 / 100
Full package analysis