Typedoc: CLI vs Application errors

Created on 24 Jan 2019  路  6Comments  路  Source: TypeStrong/typedoc

I've been running a typedoc output via the CLI and all has been working fine. I'm only interested in the JSON output. Recently I tried to do this programmatically, so I could tie into some other workflows of the project.

I am unable to replicate the CLI command using the Application class.

Steps to reproduce the bug

Works fine, produces output as expected:

typedoc --json typedoc.json --mode file --includeDeclarations --excludeExternals

Replicated via Application:

const path = require('path');
const { Application } = require('typedoc');

const output = path.resolve(process.cwd(), `typedoc.json`);

const app = new Application({
  mode: 'file',
  includeDeclarations: true,
  excludeExternals: true,
});

const files = app.expandInputFiles([
  path.resolve(process.cwd())
]);

app.generateJson(files, output);

The typescript now starts to generate, however it takes a VERY long time. I basically think it's generating docs for all of the declarations within node_modules, which I thought excludeExternals was supposed to block.

If I add exclude: '**/node_modules/**', to my app config, it runs instantly but I get all sorts of errors about modules not being found (not being included from node_modules I think).

Any ideas? I have a feeling it's something to do with where the CLI runs from vs my node script.

Environment

  • Typedoc version: 0.14.1
  • Node.js version: 10.7.0
  • OS: Mac
bug

Most helpful comment

Well, I figured it out... unfortunately, I've also learned that TypeDoc's external API is worse than I thought.

This seems to correctly replicate the behavior of the CLI. Unfortunately, it requires the use of the Application.bootstrap method, which is marked as protected. I think the design of the Application class calling this.bootstrap in it's constructor and not making the result of that available is a problem that needs to be fixed...

const path = require('path');
const { Application } = require('typedoc');

const output = path.resolve(process.cwd(), `typedoc.json`);

const app = new Application();

const { inputFiles } = app.bootstrap({
  mode: 'file',
  includeDeclarations: true,
  excludeExternals: true,
  tsconfig: 'tsconfig.json'
});

// Since your input files all come from tsconfig.json - there's no need to pass them through
// app.expandInputFiles

app.generateJson(inputFiles, output);

All 6 comments

This is really odd, the CLI does basically what you are doing.

Was your "exclude" config added to tsconfig.json? If so, try adding it to the typedoc options. I suspect that you are correct that it is documenting node_modules

Alternatively, what is process.cwd()? expandInputFiles recursively searches directories so that could be the issue if you have a ton of files. expandInputFiles will comply with typedoc's exclude option, so that should also help.

@Gerrit0 sorry for the delay. This is the repo I'm running it against: https://github.com/invertase/react-native-firebase/blob/master/tsconfig.json which contains node_modules.

https://github.com/invertase/react-native-firebase/blob/master/package.json#L14 Is the command I'm currently running too.

I'll run the script again and let you know about the cwd.

Thanks! I should have some time to look into what's happening this week.

Well, I figured it out... unfortunately, I've also learned that TypeDoc's external API is worse than I thought.

This seems to correctly replicate the behavior of the CLI. Unfortunately, it requires the use of the Application.bootstrap method, which is marked as protected. I think the design of the Application class calling this.bootstrap in it's constructor and not making the result of that available is a problem that needs to be fixed...

const path = require('path');
const { Application } = require('typedoc');

const output = path.resolve(process.cwd(), `typedoc.json`);

const app = new Application();

const { inputFiles } = app.bootstrap({
  mode: 'file',
  includeDeclarations: true,
  excludeExternals: true,
  tsconfig: 'tsconfig.json'
});

// Since your input files all come from tsconfig.json - there's no need to pass them through
// app.expandInputFiles

app.generateJson(inputFiles, output);

Thanks @Gerrit0 I'll give that a go and let you know!

Yep looks like that works, thanks!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

nidsharm picture nidsharm  路  3Comments

cfischer picture cfischer  路  4Comments

Bibliofile picture Bibliofile  路  3Comments

goodmind picture goodmind  路  3Comments

0815fox picture 0815fox  路  3Comments