How to use the cosmiconfig.loadJs 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 IBM / report-toolkit / packages / fs / src / fs-config-loader.js View on Github external
const getExplorer = _.memoize(opts =>
  cosmiconfig(
    RC_NAMESPACE,
    _.defaultsDeep(
      {
        // @ts-ignore
        loaders: {noExt: cosmiconfig.loadJs}
      },
      opts
    )
  )
);
github facebook / metro / packages / metro-config / src / loadConfig.js View on Github external
}

const explorer = cosmiconfig('metro', {
  searchPlaces: [
    'metro.config.js',
    'metro.config.json',
    'package.json',
    'rn-cli.config.js',
  ],

  loaders: {
    '.json': cosmiconfig.loadJson,
    '.yaml': cosmiconfig.loadYaml,
    '.yml': cosmiconfig.loadYaml,
    '.js': cosmiconfig.loadJs,
    '.es6': cosmiconfig.loadJs,
    noExt: cosmiconfig.loadYaml,
  },
});

async function resolveConfig(
  path?: string,
  cwd?: string,
): Promise {
  if (path) {
    return explorer.load(path);
  }

  const result = await explorer.search(cwd);
  if (result == null) {
    // No config file found, return a default
    return {
github facebook / metro / packages / metro-config / src / loadConfig.js View on Github external
return arg;
}

const explorer = cosmiconfig('metro', {
  searchPlaces: [
    'metro.config.js',
    'metro.config.json',
    'package.json',
    'rn-cli.config.js',
  ],

  loaders: {
    '.json': cosmiconfig.loadJson,
    '.yaml': cosmiconfig.loadYaml,
    '.yml': cosmiconfig.loadYaml,
    '.js': cosmiconfig.loadJs,
    '.es6': cosmiconfig.loadJs,
    noExt: cosmiconfig.loadYaml,
  },
});

async function resolveConfig(
  path?: string,
  cwd?: string,
): Promise {
  if (path) {
    return explorer.load(path);
  }

  const result = await explorer.search(cwd);
  if (result == null) {
    // No config file found, return a default
github facebook / relay / packages / relay-config / index.js View on Github external
// flowlint ambiguous-object-type:error

'use strict';

const cosmiconfig = require('cosmiconfig');

import type {Config} from '../relay-compiler/bin/RelayCompilerMain';

const explorer = cosmiconfig('relay', {
  searchPlaces: ['relay.config.js', 'relay.config.json', 'package.json'],

  loaders: {
    '.json': cosmiconfig.loadJson,
    '.yaml': cosmiconfig.loadYaml,
    '.yml': cosmiconfig.loadYaml,
    '.js': cosmiconfig.loadJs,
    '.es6': cosmiconfig.loadJs,
    noExt: cosmiconfig.loadYaml,
  },
});

function loadConfig(): ?Config {
  const result = explorer.searchSync();
  if (result) {
    return result.config;
  }
}

module.exports = {loadConfig};
github alan-ai / alan-sdk-reactnative / testtools / node_modules / metro-config / src / loadConfig.js View on Github external
return arg;
}

const explorer = cosmiconfig("metro", {
  searchPlaces: [
    "metro.config.js",
    "metro.config.json",
    "package.json",
    "rn-cli.config.js"
  ],
  loaders: {
    ".json": cosmiconfig.loadJson,
    ".yaml": cosmiconfig.loadYaml,
    ".yml": cosmiconfig.loadYaml,
    ".js": cosmiconfig.loadJs,
    ".es6": cosmiconfig.loadJs,
    noExt: cosmiconfig.loadYaml
  }
});

function resolveConfig(_x, _x2) {
  return _resolveConfig.apply(this, arguments);
}

function _resolveConfig() {
  _resolveConfig = _asyncToGenerator(function*(path, cwd) {
    if (path) {
      return explorer.load(path);
    }

    const result = yield explorer.search(cwd);
github alan-ai / alan-sdk-reactnative / testtools / node_modules / metro-config / src / loadConfig.js View on Github external
return arg;
}

const explorer = cosmiconfig("metro", {
  searchPlaces: [
    "metro.config.js",
    "metro.config.json",
    "package.json",
    "rn-cli.config.js"
  ],
  loaders: {
    ".json": cosmiconfig.loadJson,
    ".yaml": cosmiconfig.loadYaml,
    ".yml": cosmiconfig.loadYaml,
    ".js": cosmiconfig.loadJs,
    ".es6": cosmiconfig.loadJs,
    noExt: cosmiconfig.loadYaml
  }
});

function resolveConfig(_x, _x2) {
  return _resolveConfig.apply(this, arguments);
}

function _resolveConfig() {
  _resolveConfig = _asyncToGenerator(function*(path, cwd) {
    if (path) {
      return explorer.load(path);
    }

    const result = yield explorer.search(cwd);
github samdenty / gqless / packages / cli / src / utils / config.ts View on Github external
const MODULE_NAME = 'gqless'
const defaultFileNames = [
  'package.json',
  `.${MODULE_NAME}rc`,
  `.${MODULE_NAME}rc.json`,
  `.${MODULE_NAME}rc.yaml`,
  `.${MODULE_NAME}rc.yml`,
  `${MODULE_NAME}.config.js`,
  `${MODULE_NAME}.config.ts`,
]

const loaders = {
  '.json': cosmiconfig.loadJson,
  '.yaml': cosmiconfig.loadYaml,
  '.yml': cosmiconfig.loadYaml,
  '.js': cosmiconfig.loadJs,
  '.ts': {
    async: TypeScriptLoader,
  },
  noExt: cosmiconfig.loadYaml
}

export const getConfig = async (path?: string) => {
  const configPath = path && parse(resolve(path)).dir
  const explorer = cosmiconfig(MODULE_NAME, {
    searchPlaces: path ? [path] : defaultFileNames,
    loaders,
  })

  let loadedConfig
  try {
    loadedConfig = await explorer.search(configPath)
github Marwan01 / food-converter / node_modules / metro-config / src / loadConfig.js View on Github external
return arg;
}

const explorer = cosmiconfig("metro", {
  searchPlaces: [
    "metro.config.js",
    "metro.config.json",
    "package.json",
    "rn-cli.config.js"
  ],
  loaders: {
    ".json": cosmiconfig.loadJson,
    ".yaml": cosmiconfig.loadYaml,
    ".yml": cosmiconfig.loadYaml,
    ".js": cosmiconfig.loadJs,
    ".es6": cosmiconfig.loadJs,
    noExt: cosmiconfig.loadYaml
  }
});

function resolveConfig(_x, _x2) {
  return _resolveConfig.apply(this, arguments);
}

function _resolveConfig() {
  _resolveConfig = _asyncToGenerator(function*(path, cwd) {
    if (path) {
      return explorer.load(path);
    }

    const result = yield explorer.search(cwd);
github facebook / relay / packages / relay-config / index.js View on Github external

'use strict';

const cosmiconfig = require('cosmiconfig');

import type {Config} from '../relay-compiler/bin/RelayCompilerMain';

const explorer = cosmiconfig('relay', {
  searchPlaces: ['relay.config.js', 'relay.config.json', 'package.json'],

  loaders: {
    '.json': cosmiconfig.loadJson,
    '.yaml': cosmiconfig.loadYaml,
    '.yml': cosmiconfig.loadYaml,
    '.js': cosmiconfig.loadJs,
    '.es6': cosmiconfig.loadJs,
    noExt: cosmiconfig.loadYaml,
  },
});

function loadConfig(): ?Config {
  const result = explorer.searchSync();
  if (result) {
    return result.config;
  }
}

module.exports = {loadConfig};
github Marwan01 / food-converter / node_modules / metro-config / src / loadConfig.js View on Github external
return arg;
}

const explorer = cosmiconfig("metro", {
  searchPlaces: [
    "metro.config.js",
    "metro.config.json",
    "package.json",
    "rn-cli.config.js"
  ],
  loaders: {
    ".json": cosmiconfig.loadJson,
    ".yaml": cosmiconfig.loadYaml,
    ".yml": cosmiconfig.loadYaml,
    ".js": cosmiconfig.loadJs,
    ".es6": cosmiconfig.loadJs,
    noExt: cosmiconfig.loadYaml
  }
});

function resolveConfig(_x, _x2) {
  return _resolveConfig.apply(this, arguments);
}

function _resolveConfig() {
  _resolveConfig = _asyncToGenerator(function*(path, cwd) {
    if (path) {
      return explorer.load(path);
    }

    const result = yield explorer.search(cwd);

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