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

requires are included in the docs #1248

Closed
1 task done
hugomrdias opened this issue Mar 26, 2020 · 7 comments
Closed
1 task done

requires are included in the docs #1248

hugomrdias opened this issue Mar 26, 2020 · 7 comments
Labels
bug Functionality does not match expectation js This issue relates to better TS-in-JS support

Comments

@hugomrdias
Copy link

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
@hugomrdias hugomrdias added the bug Functionality does not match expectation label Mar 26, 2020
@Gerrit0 Gerrit0 added no bug This is expected behavior duplicate This duplicates another issue and removed bug Functionality does not match expectation labels Mar 30, 2020
@Gerrit0
Copy link
Collaborator

Gerrit0 commented Mar 30, 2020

    "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.

@Gerrit0 Gerrit0 closed this as completed Mar 30, 2020
@hugomrdias
Copy link
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
Copy link
Collaborator

Gerrit0 commented Mar 30, 2020

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
Copy link
Author

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

@Gerrit0
Copy link
Collaborator

Gerrit0 commented Apr 5, 2020

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.

@Gerrit0 Gerrit0 reopened this Apr 5, 2020
@Gerrit0 Gerrit0 added bug Functionality does not match expectation and removed duplicate This duplicates another issue no bug This is expected behavior labels Apr 6, 2020
@Gerrit0 Gerrit0 added the js This issue relates to better TS-in-JS support label Apr 12, 2020
@Gerrit0
Copy link
Collaborator

Gerrit0 commented Apr 12, 2020

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

@Gerrit0
Copy link
Collaborator

Gerrit0 commented Dec 26, 2020

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

@Gerrit0 Gerrit0 closed this as completed Dec 28, 2020
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 js This issue relates to better TS-in-JS support
Projects
None yet
Development

No branches or pull requests

2 participants