Search code examples
ecmascript-6jsdocjsdoc3

JSDoc not working in .MJS file with Rollup


I have the following...

/**
 * Represents a base element
 * @extends HTMLElement
 * @constructor
 */
export class Base extends HTMLElement {
...
}

When I run...

jsdoc src/jrg-base-element.mjs

Then I get...

There are no input files to process.

I tried --debug and got...

{"env":{"conf":{"plugins":[],"recurseDepth":10,"source":{"includePattern":".+\.js(doc|x)?$","excludePattern":"(^|\/|\\)"},"sourceType":"module","tags":{"allowUnknownTags":true,"dictionaries":["jsdoc","closure"]},"templates":{"monospaceLinks":false,"cleverLinks":false,"default":{"outputSourceFiles":true}}},"opts":{"":["src/jrg-base-element.mjs"],"debug":true,"destination":"./out/","encoding":"utf8"}}}

Which seems to be close to (The error message "There are no input files to process" from jsdoc) but I don't know what to do.

Any ideas?


Solution

  • I just tried it myself:

    1. Install JSDoc:

       npm install -g jsdoc => OK
      
    2. Create a dummy file, src/x.js:

       /**
        * Represents a base element
        * @extends HTMLElement
        * @constructor
        */
       function hello () {
         console.log ('Hello world!');
       }
      
    3. Run jsdoc src

    4. Check the results (default directory "out/"):

      enter image description here

    In other words:

    a) You may specify a JS file, but you'll typically specify a JS package directory.

    b) By default, JSDoc doesn't recognize ".mjs"

    Suggestion:

    Specify a configuration file, and edit source.includePatter=n:

    https://jsdoc.app/about-configuring-jsdoc.html#specifying-input-files

    Specifying input files

    The source set of options, in combination with paths given to JSDoc on the command line, determines the set of input files that JSDoc uses to generate documentation.

    {
        "source": {
            "include": [ /* array of paths to files to generate documentation for */ ],
            "exclude": [ /* array of paths to exclude */ ],
            "includePattern": ".+\\.js(doc|x)?$",
            "excludePattern": "(^|\\/|\\\\)_"
        }
    }
    
    • source.include: An optional array of paths that contain files for which JSDoc should generate documentation. The paths given to JSDoc on the command line are combined with these paths. You can use the -r command-line option to recurse into subdirectories.
    • source.exclude: An optional array of paths that JSDoc should ignore. In JSDoc 3.3.0 and later, this array may include subdirectories of the paths in source.include.
    • source.includePattern: An optional string, interpreted as a regular expression. If present, all filenames must match this regular expression to be processed by JSDoc. By default, this option is set to ".+.js(doc|x)?$", meaning that only files with the extensions .js, .jsdoc, and .jsx will be processed.
    • source.excludePattern: An optional string, interpreted as a regular expression. If present, any file matching this regular expression will be ignored. By default, this option is set so that files beginning with an underscore (or anything under a directory beginning with an underscore) is ignored.