fix(language-service): pass compilerOptions.paths to ReflectorHost (#20222)
This commit fixes the options passed to ReflectorHost to include 'paths' if it's specified in compiler options, so that dependency modules can be loaded. PR Close #20222
This commit is contained in:
parent
fb4b90a564
commit
eb8013e853
|
@ -376,6 +376,9 @@ export class TypeScriptServiceHost implements LanguageServiceHost {
|
|||
if (compilerOptions && compilerOptions.baseUrl) {
|
||||
options.baseUrl = compilerOptions.baseUrl;
|
||||
}
|
||||
if (compilerOptions && compilerOptions.paths) {
|
||||
options.paths = compilerOptions.paths;
|
||||
}
|
||||
result = this._reflectorHost =
|
||||
new ReflectorHost(() => this.tsService.getProgram(), this.host, options);
|
||||
}
|
||||
|
|
|
@ -160,6 +160,33 @@ export class MyComponent {
|
|||
|
||||
});
|
||||
|
||||
it('should respect paths configuration', () => {
|
||||
mockHost.overrideOptions(options => {
|
||||
options.baseUrl = '/app';
|
||||
options.paths = {'bar/*': ['foo/bar/*']};
|
||||
return options;
|
||||
});
|
||||
mockHost.addScript('/app/foo/bar/shared.ts', `
|
||||
export interface Node {
|
||||
children: Node[];
|
||||
}
|
||||
`);
|
||||
mockHost.addScript('/app/my.component.ts', `
|
||||
import { Component } from '@angular/core';
|
||||
import { Node } from 'bar/shared';
|
||||
|
||||
@Component({
|
||||
selector: 'my-component',
|
||||
template: '{{tree.~{tree} }}'
|
||||
})
|
||||
export class MyComponent {
|
||||
tree: Node;
|
||||
}
|
||||
`);
|
||||
ngHost.updateAnalyzedModules();
|
||||
contains('/app/my.component.ts', 'tree', 'children');
|
||||
});
|
||||
|
||||
function addCode(code: string, cb: (fileName: string, content?: string) => void) {
|
||||
const fileName = '/app/app.component.ts';
|
||||
const originalContent = mockHost.getFileContent(fileName);
|
||||
|
|
Loading…
Reference in New Issue