As @pjasiun pointed out, providing global object to whole package isn't a good practice. There were also contradictory arguments for/against different solutions. This issue hopefully will clear things up.
Example:
const config = {
ROOT_DIR: '.',
IGNORED_FILES: [
'src/lib/**'
]
};
const ckeditor5Lint = require( 'ckeditor5-dev-lint' )( config );
Even providing parameters separately to package is still too broad:
const ROOT_DIR = '.';
const IGNORED_FILES = [
'src/lib/**'
];
const ckeditor5Lint = require( 'ckeditor5-dev-lint' )( ROOT_DIR, IGNORED_FILES);
I would like to discuss idea of tasks with explicit parameters:
const ROOT_DIR = '.';
const IGNORED_FILES = [
'src/lib/**'
];
const ckeditor5Lint = require( 'ckeditor5-dev-lint' );
gulp.task( 'lint', ckeditor5Lint.lint(ROOT_DIR, IGNORED_FILES ); // Or `.bind()` etc.
Current solution is quite comfortable, but rigid. On the other hand complicating code without good reason isn't good idea. I am for something in the middle:
Your examples are fine when we have simple strings as a configuration.
docs-builder is using a complicated configuration. Do you have any idea how pass the configuration in a proper way?
Sometimes I need to get a configuration based on a dynamic key. How do you want to resolve it? Perhaps a current solution isn't good, but the solution is unified between all modules which docs-builder requires.
docs-builder is using a complicated configuration. Do you have any idea how pass the configuration in a proper way?
I see nothing wrong in passing similar configuration to each tool, but separately.
If ckeditor5DevEnv.relink need only WORKSPACE_DIR, passing the whole config to ckeditor5DevEnv seems to be wrong.
In my external project, I use only ckeditor5DevEnv.relink. I should be able to use it, passing to it what it needs. I should not need to create a bigger configuration for the whole ckeditor5DevEnv with options I do not need if I only use ckeditor5DevEnv.relink. Of course, I can pass to ckeditor5DevEnv only options needed by relink and skip other options, but it seems to be hacky.
Another thing to consider: tasks like compile can use parameters passed from command line, for example:
gulp compile --formats esnext
These command-line parameters are parsed inside ckeditor5-dev-compiler. I think that this logic should be a part of a gulpfile, not compiler package itself. When some other project will define it's own tasks, it is forced to use the same command-line parameters defined there. In my opinion all information should be passed as method arguments. Decision how these parameters are passed to the gulp task ( or even if that should be possible ) is up to developer integrating our tools.
This issue got resolved somehow naturally.
Most helpful comment
I see nothing wrong in passing similar configuration to each tool, but separately.
If
ckeditor5DevEnv.relinkneed onlyWORKSPACE_DIR, passing the whole config tockeditor5DevEnvseems to be wrong.In my external project, I use only
ckeditor5DevEnv.relink. I should be able to use it, passing to it what it needs. I should not need to create a bigger configuration for the wholeckeditor5DevEnvwith options I do not need if I only useckeditor5DevEnv.relink. Of course, I can pass tockeditor5DevEnvonly options needed byrelinkand skip other options, but it seems to be hacky.