Skip to content

requires are included in the docs #1248

@hugomrdias

Description

@hugomrdias
  • I have checked issues with bug label and found no duplicates

Expected Behavior

Generated docs should include only exported functions

Actual Behavior

Generated docs include exported functions plus const's from require's

Steps to reproduce the bug

input file

'use strict'

const fs = require('fs')
const os = require('os')
const path = require('path')
const nanoid = require('nanoid')

/**
 * Temporary folder
 *
 * @param {(d: string) => string} transform - Transform function to add prefixes or sufixes to the unique id
 * @returns {string} - Full real path to a temporary folder
 */
const tempdir = (transform = d => d) => {
  const osTmpDir = fs.realpathSync(os.tmpdir())
  return path.join(osTmpDir, transform(nanoid()))
}

module.exports = {
  tempdir
}

config

{
    "compilerOptions": {
        "allowJs": true,
        "checkJs": true,
        "target": "es2018",
        "moduleResolution": "node",
        "resolveJsonModule": true,
        "stripInternal": true,
        "strict": false,
        "alwaysStrict": true,
        "strictNullChecks": true,
        "noUnusedLocals": true,
        "noUnusedParameters": true,
        "noFallthroughCasesInSwitch": true,
        "noEmitOnError": true,
        "emitDeclarationOnly": true,
        "declaration": true,
        "outDir": "types",
        "removeComments": true,
        "skipLibCheck": true,
        "lib": [
            "WebWorker.ImportScripts",
            "DOM"
        ]
    },
    "files": [
        "src/temp-dir.js"
    ],
    "exclude": [
        "__tests__",
        "node_modules",
        "types"
    ],
    "typedocOptions": {
        "mode": "file",
        "out": "docs",
        "includeDeclarations": true,
        "excludeExternals": true,
        "excludeNotExported": true,
        "theme": "minimal",
        "exclude": [
            "**/node_modules/**"
        ],
        "externalPattern":[
            "**/node_modules/**"
        ]
    }
}

Screenshot 2020-03-26 at 15 55 59

How can i remove those const in the previous pic ? They are not exported and they are external and still they should up in the docs.

Thank you for your help.

Environment

  • Typedoc version: 0.17.3
  • Node.js version: 12
  • OS: mac os

Activity

added
no bugThis is expected behavior
and removed on Mar 30, 2020
Gerrit0

Gerrit0 commented on Mar 30, 2020

@Gerrit0
Collaborator
    "mode": "file",

When you specify this, you tell TS that your files are not modules and everything defined in them is global. File mode should only be used for projects compiled with tsc --module none.
See #1195.

hugomrdias

hugomrdias commented on Mar 30, 2020

@hugomrdias
Author

@Gerrit0 didn't help
Screenshot 2020-03-30 at 10 53 06

Managed to remove the require with excludeNotDocumented but that is not ideal.

From the PR you mentioned seems like another approach i tried before, generate declaration with tsc and feed typedoc the declarations and not the source. This works up to a point because i loose almost all the JSDocs comments not related to types, things like examples, param descriptions etc.

Also with typedoc@next i get

Warning: File /Users/hugomrdias/code/pl/js-ipfs-utils/src/temp-dir.js is not a module and cannot be converted in library mode
Warning: File /Users/hugomrdias/code/pl/js-ipfs-utils/src/env.js is not a module and cannot be converted in library mode

and docs are empty.

Gerrit0

Gerrit0 commented on Mar 30, 2020

@Gerrit0
Collaborator

Ooh, that's good to know thanks! I thought TypeScript would allow CommonJS style exports to produce a symbol at the source file symbol... That's a bug with library mode then, we need to get module symbols for CommonJS modules some other way.

hugomrdias

hugomrdias commented on Apr 3, 2020

@hugomrdias
Author

@Gerrit0 mode: 'modules' still doesnt remove requires using excludeNotDocumented is a workaround and i dont even think this option is documented

Gerrit0

Gerrit0 commented on Apr 5, 2020

@Gerrit0
Collaborator

Looks like you're right! PR welcome if you'd like to fix the docs.

Modules mode should exclude it, but the issue with not being able to get the module symbol in library mode also applies to modules mode.

let parentNode = node.parent;
while (![ts.SyntaxKind.SourceFile, ts.SyntaxKind.ModuleDeclaration].includes(parentNode.kind)) {
parentNode = parentNode.parent;
}
const parentSymbol = context.getSymbolAtLocation(parentNode);
if (!parentSymbol) {
// This is a file with no imports/exports, so everything is
// global and therefore exported.
isExported = true;
} else {
isExported = !!parentSymbol.exports?.get(symbol.escapedName);
}

This is an issue that our tests didn't catch since they all use ES modules. Re-opening to track fixing it.

reopened this on Apr 5, 2020
added and removed
no bugThis is expected behavior
on Apr 6, 2020
added
jsThis issue relates to better TS-in-JS support
on Apr 12, 2020
Gerrit0

Gerrit0 commented on Apr 12, 2020

@Gerrit0
Collaborator

So, I spent a couple hours digging into this. Unfortunately without success...

TS knows that said file is a module, and it knows that it exports stuff, but I can't seem to figure out where to extract this information... I'm beginning to think it isn't exposed anywhere.

You can work around this issue by documenting declaration files instead of the JS source. Not ideal, but...

tsc --declaration --allowJS temp-dir.js
typedoc --includeDeclarations --excludeExternals temp-dir.d.ts
added and removed on Nov 2, 2020
Gerrit0

Gerrit0 commented on Dec 26, 2020

@Gerrit0
Collaborator

Apparently TS 4.1 has improved this under the covers - the example file in - 0.20 beta 28 works as expected.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    jsThis issue relates to better TS-in-JS support

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @hugomrdias@Gerrit0

        Issue actions

          requires are included in the docs · Issue #1248 · TypeStrong/typedoc