How to use the pkg-conf.filepath function in pkg-conf

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 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 dempfi / ava-playback / src / index.ts View on Github external
import * as fs from 'fs'
import * as path from 'path'
import * as config from 'pkg-conf'
import playback from './playback'
import record from './record'

const avaConfing = config.sync<{ playbacks?: string }>('ava', { defaults: { playbacks: 'playbacks' } })
const projectPath = path.dirname(config.filepath(avaConfing))
const playbacksPath = path.join(projectPath, avaConfing.playbacks)

if (!fs.existsSync(playbacksPath)) fs.mkdirSync(playbacksPath)

const mode = process.env.AVA_PLAYBACK
if (mode === 'record') record(playbacksPath)
if (mode === 'play') playback(playbacksPath)

pkg-conf

Get namespaced config from the closest package.json

MIT
Latest version published 1 year ago

Package Health Score

58 / 100
Full package analysis

Popular pkg-conf functions