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

Extract config processing. #700

Closed
jamestalmage opened this issue Apr 2, 2016 · 6 comments
Closed

Extract config processing. #700

jamestalmage opened this issue Apr 2, 2016 · 6 comments
Labels

Comments

@jamestalmage
Copy link
Contributor

Pull out our option handling into a sub-module that can be used by some of the other tooling that we are building. It would also include some utility methods for determining if a given file was a test or helper or source, etc:

var Config = require('ava/config');

var config = new Config({
  // defaults
  args: process.argv.slice(2),
  cwd: process.cwd(),
  pkg: pkgConf.sync('ava', {cwd})
});

// config.options would simply be our merged options
config.options.serial // boolean
config.options.watch // boolean

// convenience methods
config.isTest('/some/path');
config.isSource('/some/path');
config.isHelper('/some/path');

// Maybe move some of the file watching here? I don't know that anything needs this yet. 
var watcher = config.watchChanges();

// events are not immediate (like with chokidar), but debounced like we already do in watcher.
watcher.on('source-changed', filename => {});
watcher.on('sources-changed', filenameArray => {});

watcher.on('test-changed', filename => {});
watcher.on('helper-changed', filename => {});

watcher.on('files-changed', obj => {
  obj.tests // a array
  obj.sources // a array
  obj.helpers // a array
});
@sindresorhus
Copy link
Member

Is there anything that actually needs this? If so, I think we should limit the scope to what's actually needed, and drop anything that might-be-useful.

@jamestalmage
Copy link
Contributor Author

we should limit the scope to what's actually needed

Yeah - drop the watcher stuff. The rest is definitely useful (I'm thinking ava-codemods and eslint-plugin-ava could both benefit).

@sindresorhus
Copy link
Member

config.isTest('/some/path');
config.isSource('/some/path');
config.isHelper('/some/path');

This doesn't look config related though. More like util.

@jamestalmage
Copy link
Contributor Author

This doesn't look config related though. More like util.

Except the answer depends on your config. Those are the methods we really need. Actually, I missed the important ones:

getTestFiles(), getSourceFiles(), getHelperFiles().

@sindresorhus
Copy link
Member

👍 Alright

@novemberborn
Copy link
Member

We should do this on a case-by-case basis, if and when it makes sense for an external module. No need to keep the issue open.

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

No branches or pull requests

3 participants