Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use cosmiconfig to read config #71

Open
rikhoffbauer opened this issue Mar 27, 2020 · 0 comments
Open

Use cosmiconfig to read config #71

rikhoffbauer opened this issue Mar 27, 2020 · 0 comments

Comments

@rikhoffbauer
Copy link

rikhoffbauer commented Mar 27, 2020

Some advantages:

This would add support for more ways to configure nollup:

  • a nollup property in package.json
  • a .nolluprc file in JSON or YAML format
  • a .nolluprc.json file
  • a .nolluprc.yaml, .nolluprc.yml, or .nolluprc.js file
  • a nollup.config.js file exporting a JS object

It is widely adapted; used by 3.3m github repositories.

It has a documented order in which it will look for configuration.

Starting from process.cwd() it will look for:

  1. a package.json property
  2. a JSON or YAML, extensionless "rc file"
  3. an "rc file" with the extensions .json, .yaml, .yml, or .js.
  4. a .config.js CommonJS module

This should be backwards compatible with the current implementation where the .nolluprc file has precedence over the nolluprc.js file:

nollup/lib/cli.js

Lines 93 to 97 in 1411a03

if (fs.existsSync('.nolluprc')) {
options = Object.assign({}, options, JSON.parse(fs.readFileSync('.nolluprc')));
} else if (fs.existsSync('.nolluprc.js')) {
options = Object.assign({}, options, require(path.resolve(process.cwd(), './.nolluprc.js')));
}

Is there a specific reason the current implementation loads the configuration synchronously (i.e. using fs.existsSync and fs.readFileSync)?

Could be replaced with

const cosmiconfigResult = require('cosmiconfig').cosmiconfigSync('nollup').search();
if (cosmiconfigResult && cosmiconfigResult.config) {
    options = Object.assign({}, options, cosmiconfigResult.config); 
}

cosmiconfig can be used synchronously as well as asynchronously.

See https://github.com/davidtheclark/cosmiconfig for more information.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant