2016-11-22 12:10:23 -05:00
|
|
|
/**
|
|
|
|
* @license
|
2020-05-19 15:08:49 -04:00
|
|
|
* Copyright Google LLC All Rights Reserved.
|
2016-11-22 12:10:23 -05:00
|
|
|
*
|
|
|
|
* Use of this source code is governed by an MIT-style license that can be
|
|
|
|
* found in the LICENSE file at https://angular.io/license
|
|
|
|
*/
|
|
|
|
|
2021-02-23 13:51:23 -05:00
|
|
|
import * as ts from 'typescript/lib/tsserverlibrary';
|
2021-03-02 18:46:11 -05:00
|
|
|
import {NgLanguageService, PluginConfig} from './api';
|
2021-02-23 13:51:23 -05:00
|
|
|
|
2021-01-28 15:43:37 -05:00
|
|
|
export * from './api';
|
2021-02-23 13:51:23 -05:00
|
|
|
|
|
|
|
interface PluginModule extends ts.server.PluginModule {
|
|
|
|
create(createInfo: ts.server.PluginCreateInfo): NgLanguageService;
|
2021-03-02 18:46:11 -05:00
|
|
|
onConfigurationChanged?(config: PluginConfig): void;
|
2021-02-23 13:51:23 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
const factory: ts.server.PluginModuleFactory = (tsModule): PluginModule => {
|
|
|
|
let plugin: PluginModule;
|
|
|
|
|
|
|
|
return {
|
|
|
|
create(info: ts.server.PluginCreateInfo): NgLanguageService {
|
2021-03-02 18:46:11 -05:00
|
|
|
const config: PluginConfig = info.config;
|
2021-02-23 13:51:23 -05:00
|
|
|
const bundleName = config.ivy ? 'ivy.js' : 'language-service.js';
|
|
|
|
plugin = require(`./bundles/${bundleName}`)(tsModule);
|
|
|
|
return plugin.create(info);
|
|
|
|
},
|
|
|
|
getExternalFiles(project: ts.server.Project): string[] {
|
|
|
|
return plugin?.getExternalFiles?.(project) ?? [];
|
|
|
|
},
|
2021-03-02 18:46:11 -05:00
|
|
|
onConfigurationChanged(config: PluginConfig): void {
|
2021-02-23 13:51:23 -05:00
|
|
|
plugin?.onConfigurationChanged?.(config);
|
|
|
|
},
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = factory;
|