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

v6: odd semantics for using a different "noExt" loader #226

Open
boneskull opened this issue Jan 7, 2020 · 0 comments
Open

v6: odd semantics for using a different "noExt" loader #226

boneskull opened this issue Jan 7, 2020 · 0 comments

Comments

@boneskull
Copy link

I want to use the JS loader for files without extension.

Before v6:

import cosmiconfig from 'cosmiconfig';

cosmiconfig(namespace, {
  loaders: {
    noExt: cosmiconfig.loadJs
  }
});

After:

import {cosmiconfig, defaultLoaders} from 'cosmiconfig';

cosmiconfig(namespace, {
  loaders: {
    noExt: defaultLoaders['.js']
  }
});
  1. Because I am not looking to implement my own loader, I need to dig into the defaultLoaders object to get at function I need. It's buried pretty deep in there.
  2. Having to use bracket notation to reference the function is also less-than-ideal

I'm not sure what the impetus was behind changing this, but a suggestion to make this use case more ergonomic would be a nice shortcut like so:

import {cosmiconfig} from 'cosmiconfig';

cosmiconfig(namespace, {
  loaders: {
    noExt: '.js' // use the default .js loader
  }
});

This should work with custom loaders:

import {cosmiconfig} from 'cosmiconfig';
import {myLoader} from 'somewhere';

cosmiconfig(namespace, {
  loaders: {
    '.js': myLoader,
    noExt: '.js' // use myLoader
  }
});

Alternatively, expose the default loader functions at the module level, as previously named in v5.x; loadJson, loadYaml, etc.

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

No branches or pull requests

2 participants