dgeni-packages
dgeni-packages copied to clipboard
feat(typescript): resolve typescript module paths from compilerOptions
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
Do the paths values always point to specific modules or can they be patterns that are replaced in the URL?
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?