Skip to content

Commit

Permalink
alias lookupFiles, loadRc, loadPkgRc and loadOptions to lib/cli module;
Browse files Browse the repository at this point in the history
fixes #4398

- fixes API documentation for all of these (and `module:lib/cli.main`) via JSDoc aliasing
- aliases `lib/cli/cli.js` to `module:lib/cli`; `module:lib/cli/cli` is no longer a thing
- the `lib/cli/options.js` and `lib/cli/lookup-files.js` _modules_ (not necessarily their _contents_) are now private

example usage:

```js
const {loadRc, loadPkgRc, loadOptions, lookupFiles} = require('mocha/lib/cli');
```
  • Loading branch information
boneskull committed Aug 28, 2020
1 parent 4b2b6e0 commit 247d961
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 19 deletions.
27 changes: 19 additions & 8 deletions lib/cli/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,24 @@
'use strict';

/**
* This is where we finally parse and handle arguments passed to the `mocha` executable.
* Option parsing is handled by {@link https://npm.im/yargs yargs}.
* If executed via `node`, this module will run {@linkcode module:lib/cli/cli.main main()}.
*
* @private
* @module
* Contains CLI entry point and public API for programmatic usage in Node.js.
* - Option parsing is handled by {@link https://npm.im/yargs yargs}.
* - If executed via `node`, this module will run {@linkcode module:lib/cli.main main()}.
* @public
* @module lib/cli
*/

const debug = require('debug')('mocha:cli:cli');
const symbols = require('log-symbols');
const yargs = require('yargs/yargs');
const path = require('path');
const {loadOptions, YARGS_PARSER_CONFIG} = require('./options');
const {
loadRc,
loadPkgRc,
loadOptions,
YARGS_PARSER_CONFIG
} = require('./options');
const lookupFiles = require('./lookup-files');
const commands = require('./commands');
const ansi = require('ansi-colors');
const {repository, homepage, version, gitter} = require('../../package.json');
Expand All @@ -25,7 +30,8 @@ const {cwd} = require('../utils');
* - Accepts an `Array` of arguments
* - Modifies {@link https://nodejs.org/api/modules.html#modules_module_paths Node.js' search path} for easy loading of consumer modules
* - Sets {@linkcode https://nodejs.org/api/errors.html#errors_error_stacktracelimit Error.stackTraceLimit} to `Infinity`
* @summary Mocha's main entry point from the command-line.
* @public
* @summary Mocha's main command-line entry-point.
* @param {string[]} argv - Array of arguments to parse, or by default the lovely `process.argv.slice(2)`
*/
exports.main = (argv = process.argv.slice(2)) => {
Expand Down Expand Up @@ -71,6 +77,11 @@ exports.main = (argv = process.argv.slice(2)) => {
.parse(args._);
};

exports.lookupFiles = lookupFiles;
exports.loadOptions = loadOptions;
exports.loadPkgRc = loadPkgRc;
exports.loadRc = loadRc;

// allow direct execution
if (require.main === module) {
exports.main();
Expand Down
6 changes: 0 additions & 6 deletions lib/cli/index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
'use strict';

/**
* Just exports {@link module:lib/cli/cli} for convenience.
* @private
* @module lib/cli
* @exports module:lib/cli/cli
*/
module.exports = require('./cli');
8 changes: 7 additions & 1 deletion lib/cli/lookup-files.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
'use strict';

/**
* Contains `lookupFiles`, which takes some globs/dirs/options and returns a list of files.
* @module
* @private
*/

var fs = require('fs');
var path = require('path');
var glob = require('glob');
Expand Down Expand Up @@ -53,7 +59,7 @@ function hasMatchingExtname(pathname, exts) {
* **Make no assumption that the names will be sorted in any fashion.**
*
* @public
* @memberof Mocha.utils
* @alias module:lib/cli.lookupFiles
* @param {string} filepath - Base path to start searching from.
* @param {string[]} [extensions=[]] - File extensions to look for.
* @param {boolean} [recursive=false] - Whether to recurse into subdirectories.
Expand Down
9 changes: 5 additions & 4 deletions lib/cli/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
/**
* Main entry point for handling filesystem-based configuration,
* whether that's a config file or `package.json` or whatever.
* @module
* @module lib/cli/options
* @private
*/

const fs = require('fs');
Expand Down Expand Up @@ -150,7 +151,7 @@ const parse = (args = [], defaultValues = {}, ...configObjects) => {
* @param {Object} [args] - Arguments object
* @param {string|boolean} [args.config] - Path to config file or `false` to skip
* @public
* @memberof module:lib/cli/options
* @alias module:lib/cli.loadRc
* @returns {external:yargsParser.Arguments|void} Parsed config, or nothing if `args.config` is `false`
*/
const loadRc = (args = {}) => {
Expand All @@ -167,7 +168,7 @@ module.exports.loadRc = loadRc;
* @param {Object} [args] - Arguments object
* @param {string|boolean} [args.config] - Path to `package.json` or `false` to skip
* @public
* @memberof module:lib/cli/options
* @alias module:lib/cli.loadPkgRc
* @returns {external:yargsParser.Arguments|void} Parsed config, or nothing if `args.package` is `false`
*/
const loadPkgRc = (args = {}) => {
Expand Down Expand Up @@ -210,7 +211,7 @@ module.exports.loadPkgRc = loadPkgRc;
* @summary Parses options read from `.mocharc.*` and `package.json`.
* @param {string|string[]} [argv] - Arguments to parse
* @public
* @memberof module:lib/cli/options
* @alias module:lib/cli.loadOptions
* @returns {external:yargsParser.Arguments} Parsed args from everything
*/
const loadOptions = (argv = []) => {
Expand Down

0 comments on commit 247d961

Please sign in to comment.