Skip to content

Commit

Permalink
Enable .d.ts generation from .js source
Browse files Browse the repository at this point in the history
  • Loading branch information
cspotcode committed Jan 17, 2020
1 parent 0e1ccbb commit 3144e43
Show file tree
Hide file tree
Showing 12 changed files with 1,660 additions and 22 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ docs/_dist
mocha.js
.karma/
!lib/mocha.js
/types

#########################################
# NON-MOCHA STUFF GOES BELOW THIS THING #
Expand Down
1 change: 1 addition & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export = import('./types/mocha');
17 changes: 7 additions & 10 deletions lib/cli/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,9 +165,8 @@ const parseMochaOpts = content =>

/**
* Given filepath in `args.opts`, attempt to load and parse a `mocha.opts` file.
* @param {Object} [args] - Arguments object
* @param {string|boolean} [args.opts] - Filepath to mocha.opts; defaults to whatever's in `mocharc.opts`, or `false` to skip
* @returns {external:yargsParser.Arguments|void} If read, object containing parsed arguments
* @param {import('./options_t').MochaArgs} [args] - Arguments object
* @returns {import('yargs-parser').Arguments | void} If read, object containing parsed arguments
* @memberof module:lib/cli/options
* @see {@link /#mochaopts|mocha.opts}
* @public
Expand Down Expand Up @@ -210,11 +209,10 @@ module.exports.loadMochaOpts = loadMochaOpts;

/**
* Given path to config file in `args.config`, attempt to load & parse config file.
* @param {Object} [args] - Arguments object
* @param {string|boolean} [args.config] - Path to config file or `false` to skip
* @param {import('./options_t').MochaArgs} [args] - Arguments object
* @public
* @memberof module:lib/cli/options
* @returns {external:yargsParser.Arguments|void} Parsed config, or nothing if `args.config` is `false`
* @returns {import('yargs-parser').Arguments | void} Parsed config, or nothing if `args.config` is `false`
*/
const loadRc = (args = {}) => {
if (args.config !== false) {
Expand All @@ -227,11 +225,10 @@ module.exports.loadRc = loadRc;

/**
* Given path to `package.json` in `args.package`, attempt to load config from `mocha` prop.
* @param {Object} [args] - Arguments object
* @param {string|boolean} [args.config] - Path to `package.json` or `false` to skip
* @param {import('./options_t').MochaArgs} [args] - Arguments object
* @public
* @memberof module:lib/cli/options
* @returns {external:yargsParser.Arguments|void} Parsed config, or nothing if `args.package` is `false`
* @returns {import('yargs-parser').Arguments | void} Parsed config, or nothing if `args.package` is `false`
*/
const loadPkgRc = (args = {}) => {
let result;
Expand Down Expand Up @@ -275,7 +272,7 @@ module.exports.loadPkgRc = loadPkgRc;
* @param {string|string[]} [argv] - Arguments to parse
* @public
* @memberof module:lib/cli/options
* @returns {external:yargsParser.Arguments} Parsed args from everything
* @returns {import('yargs-parser').Arguments} Parsed args from everything
*/
const loadOptions = (argv = []) => {
let args = parse(argv);
Expand Down
7 changes: 7 additions & 0 deletions lib/cli/options_t.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export interface MochaArgs {
/** Path to `package.json` or `false` to skip */
config?: string | false;
package?: boolean;
/** Filepath to mocha.opts; defaults to whatever's in `mocharc.opts`, or `false` to skip */
opts?: string | false;
}
4 changes: 2 additions & 2 deletions lib/cli/run-option-metadata.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

/**
* Dictionary of yargs option types to list of options having said type
* @type {{string:string[]}}
* @type {Record<string, string[]>}
* @private
*/
exports.types = {
Expand Down Expand Up @@ -63,7 +63,7 @@ exports.types = {
/**
* Option aliases keyed by canonical option name.
* Arrays used to reduce
* @type {{string:string[]}}
* @type {Record<string, string[]>}
* @private
*/
exports.aliases = {
Expand Down
2 changes: 1 addition & 1 deletion lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -708,7 +708,7 @@ exports.isPromise = function isPromise(value) {
* Clamps a numeric value to an inclusive range.
*
* @param {number} value - Value to be clamped.
* @param {numer[]} range - Two element array specifying [min, max] range.
* @param {number[]} range - Two element array specifying [min, max] range.
* @returns {number} clamped value
*/
exports.clamp = function clamp(value, range) {
Expand Down
Loading

0 comments on commit 3144e43

Please sign in to comment.