Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not able to exclude node_modules folder #319

Closed
Migronon opened this issue Oct 28, 2016 · 9 comments
Closed

Not able to exclude node_modules folder #319

Migronon opened this issue Oct 28, 2016 · 9 comments
Labels
bug Functionality does not match expectation

Comments

@Migronon
Copy link

Migronon commented Oct 28, 2016

I run the following command on an Angular2 project:

typedoc --experimentalDecorators --target 'es5' --module 'commonjs' --externalPattern node_modules --excludeExternals --ignoreCompilerErrors --out docs/ web/

I am apparently not able to properly exclude the node_modules folder from the documentation. Whatever I do, the node_modules packages get documented. This is the folder structure
/web
_ _/app
_ _/assets
_ _/e2e
_ _/node_modules
_ _/typings

I tried using exclude and externalPattern + excludeExternals. I tried many combinations of patterns, but apparently I am doing it wrong. I tried values like this:
node_modules
/node_modules/
node_modules/**
node_modules/*/.ts
etc.

I would be very grateful if someone pointed out my mistake and made a couple of examples how the patterns should be defined?

@jtc10005
Copy link

I used
"externalPattern": "**/node_modules/**",
or
"exclude": "**/node_modules/**"
in my typedoc.json (I can't remember which)

@derushio
Copy link

I succeeded with this command.
typedoc --excludeExternals --externalPattern "**/node_modules/**" --ignoreCompilerErrors --name "$PROJ_NAME" --mode "file" --out "../document/typedoc/" "$SRC_DIR"

but, printed many error logs.

@btgoodwin
Copy link

btgoodwin commented Nov 2, 2017

I left the ignoreCompilerErrors off on mine and didn't have any error logs.

The problem I'm trying to solve is having links/references put into the docs that are to my local project's node_modules directory when I generate the documentation. There doesn't seem to be a way to stop that behavior.

Edit: What I ended up doing was adding a "docs:sanitize" to my package.json:

    "docs": "npm run docs:clean && npm run docs:generate && npm run docs:sanitize",
    "docs:clean": "rimraf docs",
    "docs:generate": "typedoc --options typedoc.json --out docs src/lib",
    "docs:sanitize": "sed -i 's|'$PWD'||g' $(find docs -type f)"

@bluelovers
Copy link

bluelovers commented Feb 17, 2018

i can't exclude too

  "scripts": {
    "doc": "typedoc --theme markdown --out ./docs --ignoreCompilerErrors --exclude **/{node_modules,test,doc}/**/* .",
    "doc2": "typedoc --theme markdown --externalPattern \"**/(node_modules|test|doc)/**\" --out ./docs --ignoreCompilerErrors --exclude \"**/(node_modules|test|doc)/**/*\" .",
    "doc3": "typedoc --theme markdown --out ./docs --ignoreCompilerErrors .",
    "test": "npx mocha \"!(node_modules)\\**\\*.+(test|spec).js\""
  },

they all print

> typedoc --theme markdown --out ./docs --ignoreCompilerErrors .

Loaded plugin typedoc-plugin-markdown

Using TypeScript 2.7.1 from node_modules\typescript\lib
Error: node_modules/@types/node/index.d.ts(41)
 Cannot redeclare block-scoped variable 'Error'.
Error: node_modules/@types/node/index.d.ts(80)
 Cannot redeclare block-scoped variable 'String'.
Error: node_modules/typescript/lib/lib.d.ts(24)
 Cannot redeclare block-scoped variable 'NaN'.
Error: node_modules/typescript/lib/lib.d.ts(25)
 Cannot redeclare block-scoped variable 'Infinity'.
Error: node_modules/typescript/lib/lib.es2018.full.d.ts(15467)
 Duplicate identifier 'VisibilityState'.
Error: node_modules/typescript/lib/lib.es2018.full.d.ts(15468)
 Duplicate identifier 'XMLHttpRequestResponseType'.
Error: node_modules/typescript/lib/lib.es2018.full.d.ts(15684)
 Duplicate identifier 'SafeArray'.
Error: node_modules/typescript/lib/lib.es2018.full.d.ts(15768)
 Duplicate identifier 'VarDate'.
Error: node_modules/typescript/lib/lib.es2018.full.d.ts(15777)
 Cannot redeclare block-scoped variable 'Date'.
Error: node_modules/typescript/lib/lib.es5.d.ts(24)
 Cannot redeclare block-scoped variable 'NaN'.
Error: node_modules/typescript/lib/lib.es5.d.ts(25)
 Cannot redeclare block-scoped variable 'Infinity'.
Error: node_modules/typescript/lib/lib.es5.d.ts(4076)
 Cannot redeclare block-scoped variable 'String'.
Error: node_modules/typescript/lib/lib.es5.d.ts(4086)
 Cannot redeclare block-scoped variable 'Number'.
Error: node_modules/typescript/lib/lib.es5.d.ts(4095)
 Cannot redeclare block-scoped variable 'Date'.
Error: node_modules/typescript/lib/lib.es6.d.ts(24)
 Cannot redeclare block-scoped variable 'NaN'.
Error: node_modules/typescript/lib/lib.es6.d.ts(25)
 Cannot redeclare block-scoped variable 'Infinity'.
Error: node_modules/typescript/lib/lib.es6.d.ts(106)
 Duplicate string index signature.
Error: node_modules/typescript/lib/lib.es6.d.ts(109)
 Cannot redeclare block-scoped variable 'Object'.
Error: node_modules/typescript/lib/lib.es6.d.ts(256)
 Cannot redeclare block-scoped variable 'Object'.
Error: node_modules/typescript/lib/lib.es6.d.ts(261)
 Cannot redeclare block-scoped variable 'Function'.
Error: node_modules/typescript/lib/lib.es6.d.ts(305)
 Cannot redeclare block-scoped variable 'Function'.
Error: node_modules/typescript/lib/lib.es6.d.ts(308)
 Duplicate number index signature.
Error: node_modules/typescript/lib/lib.es6.d.ts(313)
 Cannot redeclare block-scoped variable 'String'.
Error: node_modules/typescript/lib/lib.es6.d.ts(446)
 Cannot redeclare block-scoped variable 'String'.
Error: node_modules/typescript/lib/lib.es6.d.ts(448)
 Cannot redeclare block-scoped variable 'Boolean'.
Error: node_modules/typescript/lib/lib.es6.d.ts(459)
 Cannot redeclare block-scoped variable 'Boolean'.
Error: node_modules/typescript/lib/lib.es6.d.ts(461)
 Cannot redeclare block-scoped variable 'Number'.
Error: node_modules/typescript/lib/lib.es6.d.ts(521)
 Cannot redeclare block-scoped variable 'Number'.
Error: node_modules/typescript/lib/lib.es6.d.ts(527)
 Cannot redeclare block-scoped variable 'Math'.
Error: node_modules/typescript/lib/lib.es6.d.ts(636)
 Cannot redeclare block-scoped variable 'Math'.
Error: node_modules/typescript/lib/lib.es6.d.ts(639)
 Cannot redeclare block-scoped variable 'Date'.
Error: node_modules/typescript/lib/lib.es6.d.ts(818)
 Cannot redeclare block-scoped variable 'Date'.
Error: node_modules/typescript/lib/lib.esnext.full.d.ts(15466)
 Duplicate identifier 'ScopedCredentialType'.
Error: node_modules/typescript/lib/lib.esnext.full.d.ts(15467)
 Duplicate identifier 'ServiceWorkerState'.
Error: node_modules/typescript/lib/lib.esnext.full.d.ts(15468)
 Duplicate identifier 'Transport'.
Error: node_modules/typescript/lib/lib.esnext.full.d.ts(15469)
 Duplicate identifier 'VideoFacingModeEnum'.
Error: node_modules/typescript/lib/lib.esnext.full.d.ts(15470)
 Duplicate identifier 'VisibilityState'.
Error: node_modules/typescript/lib/lib.esnext.full.d.ts(15471)
 Duplicate identifier 'XMLHttpRequestResponseType'.
Error: node_modules/typescript/lib/lib.esnext.full.d.ts(15687)
 Duplicate identifier 'SafeArray'.
Error: node_modules/typescript/lib/lib.esnext.full.d.ts(15771)
 Duplicate identifier 'VarDate'.
Error: node_modules/typescript/lib/lib.scripthost.d.ts(226)
 Duplicate identifier 'SafeArray'.
Error: node_modules/typescript/lib/lib.scripthost.d.ts(310)
 Duplicate identifier 'VarDate'.
Error: node_modules/typescript/lib/lib.webworker.d.ts(1968)
 Duplicate identifier 'ResponseType'.
Error: node_modules/typescript/lib/lib.webworker.d.ts(1969)
 Duplicate identifier 'ServiceWorkerState'.
Error: node_modules/typescript/lib/lib.webworker.d.ts(1970)
 Duplicate identifier 'VisibilityState'.
Error: node_modules/typescript/lib/lib.webworker.d.ts(1971)
 Duplicate identifier 'XMLHttpRequestResponseType'.
Error: test/_local-dev.d.ts(0)
 Cannot find module 'chai'.
Error: test/_local-dev.d.ts(1)
 Cannot find module 'chai'.


Documentation generated at 


Process finished with exit code 0

Edited to shorten comment

@alexisbg
Copy link

alexisbg commented Jun 6, 2018

Add:
"skipLibCheck": true
to tsconfig.json compilerOptions.

@stephan-nordnes-eriksen
Copy link

stephan-nordnes-eriksen commented Aug 17, 2018

I did not have success with any of the proposed solutions here. My specific issue is with @types/bluebird:

...myProject/node_modules/@types/sequelize/node_modules/@types/bluebird/index.d.ts(944)

(of course the --ignoreCompilerErrors works, but that seems wrong. It might skip real issues.)

@StJohn3D
Copy link

StJohn3D commented Oct 15, 2018

Same issue here, none-of the proposed solutions have worked for me, and I am on the latest v0.13.0 as of writing this.

I'm just trying to generate json and it's including all of the node_modules .d.ts files in there.
For now I'm just dealing with it, the other thing is that the node_modules get absolute paths. So I've got a script to transform all of the fileName paths from absolute to relative in the exported jsonFile. I wouldn't need that script and the output would be much faster/smaller if node_modules could actually be ignored.

@aciccarello aciccarello added bug Functionality does not match expectation Priority: 1 labels Nov 1, 2018
@Gerrit0
Copy link
Collaborator

Gerrit0 commented Nov 1, 2018

Here's an overview of how the exclude option works now, and a few notes on potential issues with changing it.

  1. User runs typedoc [options] <files/dirs>

  2. files/dirs are expanded by Application.expandInputFiles

  3. The expanded array of files is passed to ts.createProgram in the Converter.convert function.

  4. TypeScript (not TypeDoc!) resolves any dependencies which are not included in the input files, and loads typing files. By default, this includes all .d.ts files under node_modules/@types.

    It's important to note that this is expected behavior. TypeScript needs those files in order to correctly type the files we provided. Without it, you would likely end up with a lot of any showing up in your docs.

  5. TypeDoc then loops over all project source files, without filtering according to the exclude array. This is what is causing the unexpected behavior here.

The obvious fix is to filter source files based on the exclude pattern... but this raises a few more issues.

  1. We need to silently ignore any errors in files that are excluded... but what should be done about errors that are caused by misusing an imported type in an ignored file?
  2. What happens when we reference a type from an excluded file? Just printing the type name doesn't really help anyone trying to read the docs.

Gerrit0 added a commit that referenced this issue Nov 4, 2018
aciccarello pushed a commit that referenced this issue Dec 19, 2018
aciccarello pushed a commit that referenced this issue Mar 22, 2019
* Avoid documenting excluded files.

Fixes #319
Fixes #839

* Remove grunt

Closes #836

* Add script to test with ts-node

* Correct handling of declaration files

* Delete __events.ts

Unused file

* Update updating instructions

* Correct build & test instructions

* Correct grammar
@agfe2silver
Copy link

Add: "skipLibCheck": true to tsconfig.json compilerOptions.

Still working with TypeDoc version 0.25.6

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Functionality does not match expectation
Projects
None yet
Development

No branches or pull requests