naver / jsdoc-to-mdx

jsdoc to mdx API document generator
https://naver.github.io/jsdoc-to-mdx/
MIT License
18 stars 4 forks source link

No input files to process. #17

Open thomas-robotham opened 1 year ago

thomas-robotham commented 1 year ago

I have the following file structure:

parentDir
|---config.json
|---package-lock.json
|---package.json
|---example.js
|---node_modules

package.json looks like:

{
  "devDependencies": {
    "jsdoc": "^4.0.2",
    "jsdoc-to-mdx": "^1.2.1"
  },
  "script": {
    "docs": "npx jsdoc-to-mdx -c config.json"
  }
}

config.json looks like (taken from documenation):

{
  "locales": ["ko"],
  "outDir": "./docs/docs/api",
  "localesDir": "./docs/i18n/{locale}/docusaurus-plugin-content-docs/current/api",
  "sidebar": "./docs",
  "jsdoc": "./jsdoc.json",
  "bulma": false
}

Main issue

Additional queries

WoodNeck commented 1 year ago

Hello, @thomas-robotham Looks like the jsdoc.json file is missing, try adding one with the correct include settings.

How can I simply get the example.js rendered .mdx file?

This module is designed to render your jsdoc comments into .mdx(markdown + JSX) format. The main use case we're supposing is to build API documents for your Javascript/Typescript module. So, basically, as this module automates that process, you can't directly transform your .js file into .mdx. The input files are managed from jsdoc config.

If you don't need .mdx features, like using react components, you can try using jsdoc-to-markdown to render your files as markdown instead.

Do I actually need Docusaurus installed under ./docs/ to actually output the files to ./docs/docs/api (like with jsdoc-to-markdown).

Yes. This module is meant to be used with Docusarus and is depending on their structure.

I'm assuming this is something to do with "locales" variable,, but this to me is quite unclear.

locales and localesDir generate i18n documents for you if you have a locale-specific comment in your jsdoc. Like, for example, we're using Korean descriptions like this in our projects.

/**
 * Description, in English
 * @ko 한글로 된 설명
 */
class SomeClass {}

You can also try using typedoc-to-mdx if you're using Typescript.

thomas-robotham commented 1 year ago

Hi @WoodNeck, Thanks for the fast response :D I would like to include some react components on the final .mdx files, so it would be great to use this module.

I included a dummy Docusaurus project under ./docs/ and additonally added a simple jsdoc.json config file.
Folder structure is now as follow:

parentDir
|---docs
|---|---docs
|---|---docusaurus_stuff
|---|---...
|---config.json
|---jsdoc.json
|---package-lock.json
|---package.json
|---example.js
|---node_modules

The jsdoc.json config is (with the include key simply set to the top level dir, so it should catch the example.js file):

{
    "tags": {
      "allowUnknownTags" : false,
      "dictionaries": ["jsdoc", "closure"]
    },
    "source": {
      "include": ["./"],
      "includePattern": ".+\\.(j|t)s(doc|x)?$",
      "excludePattern": "(^|\\/|\\\\)_"
    }
}

A small step forward as it's picking up the input file... but now i have the following error:

PS D:\work\qoevave\testing_mdx> npx jsdoc-to-mdx -c ./config.json
undefined:1

SyntaxError: Unexpected end of JSON input
    at JSON.parse (<anonymous>)
    at D:\work\qoevave\testing_mdx\node_modules\jsdoc-to-mdx\bin\generate.js:527:22
    at Generator.next (<anonymous>)
    at fulfilled (D:\work\qoevave\testing_mdx\node_modules\jsdoc-to-mdx\bin\generate.js:55:58)

All my .json files have correct structure, any clues? (thnx for the help)

WoodNeck commented 1 year ago

SyntaxError: Unexpected end of JSON input happens when the input data is incorrect.

You can try checking:

thomas-robotham commented 1 year ago

No luck. All .json structures are fine and the relative location of the files is correct.

I'll try a completly fresh install in a new directory.

WoodNeck commented 1 year ago

I tried building the project myself with these settings, and looks like it's working fine. Maybe it's Windows/Powershell issue? I never tried building a project in that env.

image

project structure

npx create-docusaurus@latest demo classic

Docusaurus init

{
  "locales": ["ko"],
  "outDir": "./demo/docs/api",
  "localesDir": "./demo/i18n/{locale}/docusaurus-plugin-content-docs/current/api",
  "sidebar": "./demo",
  "jsdoc": "./jsdoc.json",
  "bulma": false
}

config.json

{
    "tags": {
      "allowUnknownTags" : true,
      "dictionaries": ["jsdoc", "closure"]
    },
    "source": {
      "include": ["src"],
      "includePattern": ".+\\.(j|t)s(doc|x)?$",
      "excludePattern": "(^|\\/|\\\\)_"
    }
  }

jsdoc.json

/**
 * Description of A
 */
class A {

}

export default A;

src/index.ts

image

image

result

thomas-robotham commented 1 year ago

Delayed response but back again. So I tried on my Mac M1 and here's the following...

Folder structure

Screenshot 2023-05-29 at 20 06 56

npm installing jsdoc, there's no issues.

npm installing jsdoc-to-mdx there are some critical errors.

Screenshot 2023-05-29 at 20 06 24

Ignoring the errors and trying `npx jsdoc-to-mdx -c config.json will lead to the error we've previously mentioned regarding the .json file (See below again).

Screenshot 2023-05-29 at 20 06 40

npm audit fix leaves you with the following:

Screenshot 2023-05-29 at 20 08 16

If i force update this package this I get the following error.

image

Have you guys tried installing the packages fresh too?

WoodNeck commented 1 year ago

I've fresh installed the package while testing that. I've also tested on the Apple Silicon chip, so that's not might be the issue. Try the template below, it works in my environment.

daybrush commented 1 year ago

@thomas-robotham

The version of jsdoc-to-mdx was version down while audit was executed.

Would you like to test the version of jsdoc-to-mdx again with the latest version?

Try installing @daybrush/jsdoc manually if you are going to use a downgraded version.

selankon commented 10 months ago

Hello,

Same error for us, the code generation suddenly stops working with the same error when yarn run npx jsdoc-to-mdx -c jsdoc-to-mdx.config.json:

SyntaxError: Unexpected end of JSON input

I tried to upgrade all the packages without success, currently using the "jsdoc-to-mdx": "^1.2.1" version.

I tried the https://github.com/WoodNeck/jsdoc-to-mdx-test and it works properly.

  "devDependencies": {
    "@babel/cli": "^7.19.3",
    "@babel/core": "^7.20.5",
    "@babel/preset-env": "^7.20.2",
    "@babel/preset-typescript": "^7.18.6",
    "@daybrush/jsdoc": "^0.4.5",
    "jsdoc-babel": "^0.5.0",
    "jsdoc-to-markdown": "^8.0.0",
    "jsdoc-to-mdx": "^1.1.3"
  }

I tried also the 1.2.1 version of jsdoc-to-mdx

{
  "locales": [],
  "outDir": "./temp_docs",
  "localesDir": "./temp_docs/i18n/{locale}/docusaurus-plugin-content-docs/current/sdk",
  "sidebar": "./temp_docs",
  "prefix": "sdk/",
  "jsdoc": "./jsdoc.json"
}

I tried adding "en" locale to the locales array.

{
  "tags": {
    "allowUnknownTags" : true,
    "dictionaries": ["jsdoc", "closure"]
  },
  "source": {
    "include": ["../src"],
    "exclude": ["../src/dvote-protobuf"],
    "includePattern": ".+\\.(j|t)s(doc|x)?$",
    "excludePattern": "(^|\\/|\\\\)_"
  }
}

No idea why stop working suddenly. Any help will be welcome.

smallsaucepan commented 3 months ago

Experiencing this problem also. Digging into it a little SyntaxError: Unexpected end of JSON input was happening because the temp file was empty and didn't parse as JSON.

The temp file was empty because the forked child process couldn't successfully parse some of our code:

/Users/s/Code/turf-www-span/node_modules/@daybrush/jsdoc/lib/jsdoc/src/parser.js:226
if (this._extras[filename][name].every(function(tsInfo) {
                                 ^

TypeError: this._extras[filename][name].every is not a function

Whatever was winding up in this._extras[filename][name] wasn't what the parser was expecting. Was able to work around the issue by setting recurseDepth to 2 (the file tripping up the parser was a util class several layers deep we didn't need documented). This allowed jsdoc to run all the way through. Didn't investigate much further.

Maybe this will help someone track down the issue in future. Or at least present a workaround.