Skip to content
This repository was archived by the owner on Mar 31, 2025. It is now read-only.

Conversation

@dherges
Copy link
Contributor

@dherges dherges commented Jan 23, 2018

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

path: string;
outputPath: string;
content: string;
importFrom?: string;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is adding this property a good way to solve my use case?

basePath = path.resolve(__dirname, '../../mocks');
});

it('should return the resolved module path derived by compilerOptions.paths', () => {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should I add another test w/o options.paths?

@petebacondarwin
Copy link
Contributor

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

@petebacondarwin
Copy link
Contributor

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?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants