How to use pkg-conf - 10 common examples

To help you get started, we’ve selected a few pkg-conf 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 jxnblk / ok-mdx / cli.js View on Github external
// const log = require('./lib/log')

const log = (...args) => {
  console.log(
    chalk.cyan('[mdx]'),
    ...args
  )
}
log.error = (...args) => {
  console.log(
    chalk.red('[err]'),
    ...args
  )
}

const config = require('pkg-conf').sync('ok-mdx')

const cli = meow(`
  Usage:

    $ mdx docs

  Options:

    -o --open     Opens development server in default browser
    -p --port     Port for development server
    --vim         Enable editor Vim mode

`, {
  flags: {
    open: {
      type: 'boolean',
github traveloka / javascript / packages / marlint / lib / getOptionsForPath.js View on Github external
const absolutePath =
    filePath.charAt(0) === '/' ? filePath : path.resolve(cwd, filePath);

  if (absolutePath.indexOf('/packages/') === -1) {
    // Not a lerna package, use single package.json
    const packageOptions = pkgConf.sync('marlint', { cwd });
    return buildOptions(packageOptions, runtimeOptions);
  }

  // Get lerna root directory and package root directory to find specific config
  // in package.json. Package specific config will overrides root specific config
  const [rootLernaDir, relativeFilePath] = absolutePath.split('/packages/');
  const [packageName, ..._] = relativeFilePath.split('/');
  const packageDir = `${rootLernaDir}/packages/${packageName}`;

  const packageConfig = pkgConf.sync('marlint', { cwd: packageDir });
  const rootConfig = pkgConf.sync('marlint', { cwd: rootLernaDir });
  const packageOptions = merge({}, rootConfig, packageConfig);

  return buildOptions(packageOptions, runtimeOptions);
}
github SwellRT / swellrt / pad / node_modules / lite-server / node_modules / browser-sync / node_modules / yargs / yargs.js View on Github external
function parseArgs (args, shortCircuit) {
    options.__ = y18n.__
    options.configuration = pkgConf.sync('yargs', {
      defaults: {},
      cwd: requireMainFilename(require)
    })
    const parsed = Parser.detailed(args, options)
    const argv = parsed.argv
    var aliases = parsed.aliases

    argv.$0 = self.$0
    self.parsed = parsed

    guessLocale() // guess locale lazily, so that it can be turned off in chain.

    // while building up the argv object, there
    // are two passes through the parser. If completion
    // is being performed short-circuit on the first pass.
    if (shortCircuit) {
github ranjithprabhuk / ng2-Dashboard / node_modules / yargs / yargs.js View on Github external
function parseArgs (args, shortCircuit) {
    options.__ = y18n.__
    options.configuration = pkgConf.sync('yargs', {
      defaults: {},
      cwd: requireMainFilename(require)
    })
    const parsed = Parser.detailed(args, options)
    const argv = parsed.argv
    var aliases = parsed.aliases

    argv.$0 = self.$0
    self.parsed = parsed

    guessLocale() // guess locale lazily, so that it can be turned off in chain.

    // while building up the argv object, there
    // are two passes through the parser. If completion
    // is being performed short-circuit on the first pass.
    if (shortCircuit) {
github walrusjs / walrus / packages / walrus-plugin-eslint / src / linter.ts View on Github external
const self = this;

    if (opts) {
      opts = {};
    }
    opts = Object.assign({}, opts);
    opts.eslintConfig = Object.assign({}, self.eslintConfig);
    opts.eslintConfig.fix = !!opts.fix;

    if (!opts.cwd) opts.cwd = self.cwd;

    // 如果未提供usePackageJson选择,默认为true
    const usePackageJson = !_.isNil(opts.usePackageJson) ? opts.usePackageJson : true;

    // package.json中的配置
    const packageOpts = usePackageJson ? pkgConf.sync(self.cmd, { cwd: opts.cwd }) : {};

    // ignore
    if (!opts.ignore) opts.ignore = [];
    addIgnore(packageOpts.ignore);
    if (!packageOpts.noDefaultIgnore) {
      addIgnore(DEFAULT_IGNORE);
    }

    // globals
    addGlobals(packageOpts.globals || packageOpts.global);
    addGlobals(opts.globals || opts.global);

    // plugins
    addPlugins(packageOpts.plugins || packageOpts.plugin);
    addPlugins(opts.plugins || opts.plugin);
github avajs / ava / lib / load-config.js View on Github external
function loadConfig({configFile, resolveFrom = process.cwd(), defaults = {}} = {}) { // eslint-disable-line complexity
	let packageConf = pkgConf.sync('ava', {cwd: resolveFrom});
	const filepath = pkgConf.filepath(packageConf);
	const projectDir = filepath === null ? resolveFrom : path.dirname(filepath);

	const fileForErrorMessage = configFile || 'ava.config.js';
	const allowConflictWithPackageJson = Boolean(configFile);

	if (configFile) {
		configFile = path.resolve(configFile); // Relative to CWD
		if (path.basename(configFile) !== path.relative(projectDir, configFile)) {
			throw new Error('Config files must be located next to the package.json file');
		}
	} else {
		configFile = path.join(projectDir, 'ava.config.js');
	}

	let fileConf;
	try {
github avajs / ava / test / fixture / process-cwd-default.js View on Github external
test('test', t => {
	const conf = pkgConf.sync('ava');
	const pkgDir = path.dirname(pkgConf.filepath(conf));
	t.is(process.cwd(), pkgDir);
});
github xojs / xo / lib / options-manager.js View on Github external
const mergeWithPackageConfig = options => {
	options = {
		cwd: process.cwd(),
		...options
	};

	options.cwd = path.resolve(options.cwd);
	const config = pkgConf.sync('xo', {cwd: options.cwd, skipOnFalse: true});
	const engines = pkgConf.sync('engines', {cwd: options.cwd});

	return {
		...config,
		nodeVersion: engines && engines.node && semver.validRange(engines.node),
		...options
	};
};
github c8r / kit / cli / cli.js View on Github external
#!/usr/bin/env node
'use strict'

const fs= require('fs')
const path = require('path')
const importJsx = require('import-jsx')
const { h, render } = require('ink')
const meow = require('meow')
const open = require('react-dev-utils/openBrowser')
const log = require('@compositor/log')
const chalk = require('chalk')
const clipboard = require('clipboardy')
const findup = require('find-up')
const config = require('pkg-conf').sync('kit')

const Init = importJsx('./src/Init')
const parseArgs = require('./lib/parse-args')

const cli = meow(`
  Usage

    $ kit  [options]

  Examples
    $ kit examples
    $ kit dev examples
    $ kit init

  Options
github avajs / ava / lib / babel-pipeline.js View on Github external
function hashPartialTestConfig({babelrc, config, options: {plugins, presets}}, projectDir, pluginAndPresetHashes) {
	const inputs = [];
	if (babelrc) {
		inputs.push(babelrc);

		const filename = path.basename(babelrc);
		if (filename === 'package.json') {
			inputs.push(JSON.stringify(pkgConf.sync('babel', {cwd: path.dirname(filename)})));
		} else {
			inputs.push(stripBomBuf(fs.readFileSync(babelrc)));
		}
	}

	if (config) {
		inputs.push(config, stripBomBuf(fs.readFileSync(config)));
	}

	for (const item of [...plugins, ...presets]) {
		if (!item.file) {
			continue;
		}

		const {file: {resolved: filename}} = item;
		if (pluginAndPresetHashes.has(filename)) {

pkg-conf

Get namespaced config from the closest package.json

MIT
Latest version published 6 months ago

Package Health Score

58 / 100
Full package analysis

Popular pkg-conf functions