nollup icon indicating copy to clipboard operation
nollup copied to clipboard

Use cosmiconfig to read config

Open rikhoffbauer opened this issue 4 years ago • 0 comments

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:

https://github.com/PepsRyuu/nollup/blob/1411a03ea3f63a2d398cc3416bdb9566b11056ce/lib/cli.js#L93-L97

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.

rikhoffbauer avatar Mar 27 '20 03:03 rikhoffbauer