typedoc2md / typedoc-plugin-markdown

A plugin for TypeDoc that enables TypeScript API documentation to be generated in Markdown.
https://typedoc-plugin-markdown.org
MIT License
691 stars 171 forks source link

TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string. Received undefined #509

Closed jyunhongsu closed 7 months ago

jyunhongsu commented 7 months ago

OS: Windows Shell: power shell

It's a bit strange that this command sometimes succeeds and sometimes fails.

error

TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string. Received undefined
    at new NodeError (node:internal/errors:405:5)
    at validateString (node:internal/validators:162:11)
    at Object.dirname (node:path:654:5)
    at MarkdownTheme.getRelativeUrl (...\node_modules\.pnpm\typedoc-plugin-markdown@3.17.1_typedoc@0.25.3\node_modules\typedoc-plugin-markdown\dist\theme.js:155:49)
    at Object.relativeURL (...\node_modules\.pnpm\typedoc-plugin-markdown@3.17.1_typedoc@0.25.3\node_modules\typedoc-plugin-markdown\dist\resources\helpers\relative-url.js:32:25)
    at ...\node_modules\.pnpm\typedoc-plugin-markdown@3.17.1_typedoc@0.25.3\node_modules\typedoc-plugin-markdown\dist\resources\helpers\toc.js:35:126    
    at Array.map (<anonymous>)
    at pushGroup (...\node_modules\.pnpm\typedoc-plugin-markdown@3.17.1_typedoc@0.25.3\node_modules\typedoc-plugin-markdown\dist\resources\helpers\toc.js:35:45)
    at ...\node_modules\.pnpm\typedoc-plugin-markdown@3.17.1_typedoc@0.25.3\node_modules\typedoc-plugin-markdown\dist\resources\helpers\toc.js:55:25     
    at Array.forEach (<anonymous>) {
  code: 'ERR_INVALID_ARG_TYPE'
}

code

    const entryFile = srcPaths[0];
    const typeDocConfig = {
      // typedoc configs: https://github.com/TypeStrong/typedoc/blob/master/src/lib/utils/options/declaration.ts#L89
      // Meta Data
      tsconfig: getPathFromRoot('tsconfig.json'),
      plugin: ['typedoc-plugin-markdown'],

      // Input
      name: 'XHIS Data Store',
      entryPoints: [entryFile],
      readme: 'none',
      disableSources: true,
      excludeInternal: true,
      excludePrivate: true,
      excludeProtected: true,

      // Output
      theme: 'markdown',

      // additional configs from typedoc-plugin-markdown: https://github.com/tgreyuk/typedoc-plugin-markdown/blob/master/packages/docusaurus-plugin-typedoc/src/types.ts#L1
      hideInPageTOC: true,
      hideBreadcrumbs: true,
      hideMembersSymbol: true,
    };

    const app = await TypeDoc.Application.bootstrapWithPlugins(typeDocConfig);
    const project = await app.convert();

    if (!project) {
      return;
    }

    const outputDir = path.join(tmpDir, sideBarLinkPath);
    console.info(`[INFO]: docs will be generated at ${outputDir}.`);
    const outputDataNodeDir = path.join(outputDir, 'classes');
    const outputParsedDoc = path.join(outputDir, 'documentation.json');

    await app.generateDocs(project, outputDir);
    await app.generateJson(project, outputParsedDoc);

    const outputDataNodeFileNames = fs.readdirSync(outputDataNodeDir);

    if (Array.isArray(outputDataNodeFileNames) && outputDataNodeFileNames.length > 0) {
      const outputDataNodeDocPath = path.join(outputDataNodeDir, outputDataNodeFileNames[0]);
      fs.copyFileSync(outputDataNodeDocPath, destPath);
      console.info(`[INFO]: copied ${outputDataNodeDocPath} to ${destPath}`);
    }