Skip to content

Commit 93c541f

Browse files
kyliauKeen Yee Liau
authored andcommitted
fix: use single entry point for @angular/language-service
Starting from `@angular/language-service` v12.0.0-next.3, the package will dynamically load View Engine or Ivy LS based on the config passed to the plugin. This reverts #1111
1 parent 4f210f1 commit 93c541f

File tree

5 files changed

+13
-15
lines changed

5 files changed

+13
-15
lines changed

server/src/server.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {generateHelpMessage, parseCommandLine} from './cmdline_utils';
1010
import {createLogger} from './logger';
1111
import {ServerHost} from './server_host';
1212
import {Session} from './session';
13-
import {NGLANGSVC, resolveNgLangSvc, resolveTsServer} from './version_provider';
13+
import {resolveNgLangSvc, resolveTsServer} from './version_provider';
1414

1515
// Parse command line arguments
1616
const options = parseCommandLine(process.argv);
@@ -30,13 +30,14 @@ const ts = resolveTsServer(options.tsProbeLocations);
3030
const ng = resolveNgLangSvc(options.ngProbeLocations, options.ivy);
3131

3232
// ServerHost provides native OS functionality
33-
const host = new ServerHost(options.ivy);
33+
const host = new ServerHost();
3434

3535
// Establish a new server session that encapsulates lsp connection.
3636
const session = new Session({
3737
host,
3838
logger,
39-
ngPlugin: NGLANGSVC, // TypeScript allows only package names as plugin names.
39+
// TypeScript allows only package names as plugin names.
40+
ngPlugin: '@angular/language-service',
4041
resolvedNgLsPath: ng.resolvedPath,
4142
ivy: options.ivy,
4243
logToConsole: options.logToConsole,

server/src/server_host.ts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
*/
88

99
import * as ts from 'typescript/lib/tsserverlibrary';
10-
import {NGLANGSVC} from './version_provider';
1110

1211
/**
1312
* `ServerHost` is a wrapper around `ts.sys` for the Node system. In Node, all
@@ -20,7 +19,7 @@ export class ServerHost implements ts.server.ServerHost {
2019
readonly newLine: string;
2120
readonly useCaseSensitiveFileNames: boolean;
2221

23-
constructor(private ivy: boolean) {
22+
constructor() {
2423
this.args = ts.sys.args;
2524
this.newLine = ts.sys.newLine;
2625
this.useCaseSensitiveFileNames = ts.sys.useCaseSensitiveFileNames;
@@ -172,13 +171,9 @@ export class ServerHost implements ts.server.ServerHost {
172171

173172
require(initialPath: string, moduleName: string) {
174173
try {
175-
let modulePath = require.resolve(moduleName, {
174+
const modulePath = require.resolve(moduleName, {
176175
paths: [initialPath],
177176
});
178-
// TypeScript allows only package names as plugin names.
179-
if (this.ivy && moduleName === NGLANGSVC) {
180-
modulePath = this.resolvePath(modulePath + '/../ivy.js');
181-
}
182177
return {
183178
module: require(modulePath),
184179
error: undefined,

server/src/session.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ export class Session {
114114
pluginName: options.ngPlugin,
115115
configuration: {
116116
angularOnly: true,
117+
ivy: options.ivy,
117118
},
118119
});
119120

server/src/tests/version_provider_spec.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,15 @@ describe('Node Module Resolver', () => {
3030
it('should be able to resolve Angular language service', () => {
3131
const result = resolveNgLangSvc(probeLocations, false /* ivy */);
3232
expect(result).toBeDefined();
33-
expect(result.resolvedPath).toMatch(/language-service.js$/);
33+
expect(result.resolvedPath.endsWith('@angular/language-service/index.js')).toBeTrue();
3434
});
3535

3636
it('should be able to resolve Ivy version of Angular language service', () => {
3737
const result = resolveNgLangSvc(probeLocations, true /* ivy */);
3838
expect(result).toBeDefined();
39-
expect(result.resolvedPath).toMatch(/ivy.js$/);
39+
// Starting from v12.0.0-next.3 @angular/language-service provides a single
40+
// entry point
41+
expect(result.resolvedPath.endsWith('@angular/language-service/index.js')).toBeTrue();
4042
});
4143
});
4244

server/src/version_provider.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import * as path from 'path';
1111

1212
const MIN_TS_VERSION = '4.1';
1313
const MIN_NG_VERSION = '12.0';
14-
export const NGLANGSVC = '@angular/language-service';
1514
const TSSERVERLIB = 'typescript/lib/tsserverlibrary';
1615

1716
/**
@@ -120,8 +119,8 @@ function resolveTsServerFromTsdk(tsdk: string): NodeModule|undefined {
120119
* @param ivy true if Ivy language service is requested
121120
*/
122121
export function resolveNgLangSvc(probeLocations: string[], ivy: boolean): NodeModule {
123-
const packageName = ivy ? `${NGLANGSVC}/bundles/ivy` : NGLANGSVC;
124-
return resolveWithMinVersion(packageName, MIN_NG_VERSION, probeLocations, NGLANGSVC);
122+
const ngls = '@angular/language-service';
123+
return resolveWithMinVersion(ngls, MIN_NG_VERSION, probeLocations, ngls);
125124
}
126125

127126
/**

0 commit comments

Comments
 (0)