dgeni-packages icon indicating copy to clipboard operation
dgeni-packages copied to clipboard

feat(typescript): resolve typescript module paths from compilerOptions

Open dherges opened this issue 8 years ago • 2 comments

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

dherges avatar Jan 23 '18 12:01 dherges

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

petebacondarwin avatar Feb 24 '18 11:02 petebacondarwin

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?

petebacondarwin avatar Feb 24 '18 11:02 petebacondarwin