TypeStrong/typedoc

How does exclude work ?

ocombe opened this issue ยท 23 comments

Hello,
I use the command line: typedoc --options typedoc.json --exclude *.spec.ts src/app/

But it generates documentation for my file "src/app/app.spec.ts".
Shouldn't it be excluded ?

Hi, I'm on the same boat as @ocombe.
Is the --exclude pattern a RegExp, or a pattern similar those used in Grunt/Gulp, such as directory/**/*.ext?

Hi, got the same problem with exclude trying this: typedoc --media modules/ --exclude modules/**/tests/*

Same issue here. Also how to configure multiple exclusions?

I'm having the exact same issue. I want to ignore spec files. "" is not helpful at all without an example of what a "pattern" is.

@ocombe I think the following should work:

typedoc --options typedoc.json --exclude **/*.spec.ts src/app/

typedoc uses Minimatch for globs. I believe *.spec.ts will only look for files in the current directory.

Hi, you can use for example: "exclude": "**/*+(e2e|spec|index).ts" if you want to have multiple exclusions.

The syntax seems to be +(pattern-list).

Seen here (

exclude = new Minimatch(this.exclude);
), the pattern is a standard minimatch (glob) pattern in Node.js. The existing comments by @caseyhoward should work for you (make sure you quote so it's not automatically expanded by your shell).

Changing the docs to say that patterns are "standard" minimatch patterns would be very helpful.

You are welcome to submit a PR improving the docs.

I know this has been closed but I think that what would be interesting to know in the docs is what is given to minimatch for testing.

If you pass the whole path to the file, the pattern will be different than if you are passing what comes after path/to/typescript/project/. From my understanding, you make a full resolution and give it to the minimatch pattern but correct me if I'm wrong.

Then there is no way to exclude an entire directory?

@Zeioth yup you can via the pattern.
Example: my tree is like this:

| src
  - File1.ts
  - File2.ts
  | tests
    - Test1.ts
    - Test2.ts

To exclude the tests folder under src you would do (from the working directory): typedoc src --out docs --mode modules --exclude \"**/tests/*.ts\"

I managed to exclude several folders,
The syntax was "**/{folder1,folder2}/*.ts"

HTH

For whatever reason this only worked for me when I escaped the path like so:
typedoc --out ./docs ./src --exclude \"**/*+(index|.spec|.e2e).ts\". Otherwise it would throw an error.

Just to add some info to this, if you use typedoc with a javascript config file
(e.g. typedoc --options ./typedoc.js ./src), then you can set an array of exclude paths in the configuration:

typedoc.js:

module.exports = {
    out: './docs/dist/api/',

    readme: 'none',
    includes: './',
    exclude: [
        '**/__tests__/**/*',
        '**/__test_utils__/**/*',
        '**/__fixtures__/**/*',
        '**/testsuite/**/*'
    ],

    mode: 'file',
    excludeExternals: true,
    excludeNotExported: true,
    excludePrivate: true
};

This exclude is not working:

module.exports = {
  mode: 'file',
  out: 'dist/typedoc',
  theme: 'default',
  ignoreCompilerErrors: true,
  excludePrivate: true,
  excludeNotExported: 'true',
  excludeExternals: true,
  target: 'ES5',
  moduleResolution: 'node',
  preserveConstEnums: 'true',
  stripInternal: 'true',
  suppressExcessPropertyErrors: 'true',
  suppressImplicitAnyIndexErrors: 'true',
  module: 'commonjs',
  readme: 'README.md',
  exclude: [
    '**/*.spec.ts',
    '**/*.module.ts',
  ],
};

I don't want to render *.module.ts files because they just import and export things, they don't add nothing to the documentation.

Why the exclude patter is not working?

A lot of users in this thread are actually using shell globs.

I'm finding this to not work (shell does not expand the glob with single quotes): --exclude '**/*.d.ts'

Using the shell glob doesn't work either: --exclude **/*.d.ts

If glob patterns are meant to work, it's broken.

@hoten it actually supports Minimatch globs. Declarations should be handled differently though. There is the --includeDeclarations flag so it already shouldn't be including those if you don't set the flag. You might want to open another issue with a reproduction if that is not working as expected.

Thanks @aciccarello. Yeah, some of us are having issues with declaration files. #820 is the relevant issue.

It is also possible to specify multiple excludes in cli by specifying several exclude arguments:
typedoc --out docs src --ignoreCompilerErrors --exclude **/*__*/** --exclude **/*.test.tsx

is it possible to display specific comments only using typedoc?
I dont want to document variables, functions, classes, just want to display specific comment. Is that possible using Typedoc

This exclude is not working:

module.exports = {
  mode: 'file',
  out: 'dist/typedoc',
  theme: 'default',
  ignoreCompilerErrors: true,
  excludePrivate: true,
  excludeNotExported: 'true',
  excludeExternals: true,
  target: 'ES5',
  moduleResolution: 'node',
  preserveConstEnums: 'true',
  stripInternal: 'true',
  suppressExcessPropertyErrors: 'true',
  suppressImplicitAnyIndexErrors: 'true',
  module: 'commonjs',
  readme: 'README.md',
  exclude: [
    '**/*.spec.ts',
    '**/*.module.ts',
  ],
};

I don't want to render *.module.ts files because they just import and export things, they don't add nothing to the documentation.

Why the exclude patter is not working?

It is not working at all.

you can use it like this,

"exclude": "**/+(yourFile.ts|yourAnotherFile.ts|yetAnotherFile.ts)"