angular / dgeni-packages

A collection of dgeni packages for generating documentation from source code.
MIT License
142 stars 101 forks source link

feat(typescript): resolve typescript module paths from compilerOptions #258

Open dherges opened 6 years ago

dherges commented 6 years ago

How It's Used

Configure TypeScript compilerOptions.paths to resolve (and eventually display) a module path for a npm package.

myPackage.config((readTypeScriptModules: ReadTypeScriptModules, tsParser: TsParser) => {
  const typescriptPathMap: any = {
    '@foo/bar': ['./packages/bar/index.ts']
  };

  tsParser.options.paths = typescriptPathMap;

  readTypeScriptModules.sourceFiles = Object.keys(typescriptPathMap)
    .map((path) => typescriptPathMap[path])
    .reduce((prev, current) => prev.concat(current), [])
)}

Similar to Material: https://github.com/angular/material2/blob/master/tools/dgeni/index.ts#L112

petebacondarwin commented 6 years ago

Do the paths values always point to specific modules or can they be patterns that are replaced in the URL?

petebacondarwin commented 6 years ago

I am worried that this reverse lookup for every call is needlessly expensive. If it is the case that the paths values are always specific files, then we could invert this hash just once and then get fast lookups as needed; perhaps storing it alongside the other information that comes from TsParser?