Skip to content

Commit

Permalink
fix: use single entry point for @angular/language-service
Browse files Browse the repository at this point in the history
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 angular#1111
  • Loading branch information
kyliau authored and Keen Yee Liau committed Mar 4, 2021
1 parent 4f210f1 commit 98429ed
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 15 deletions.
7 changes: 4 additions & 3 deletions server/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {generateHelpMessage, parseCommandLine} from './cmdline_utils';
import {createLogger} from './logger';
import {ServerHost} from './server_host';
import {Session} from './session';
import {NGLANGSVC, resolveNgLangSvc, resolveTsServer} from './version_provider';
import {resolveNgLangSvc, resolveTsServer} from './version_provider';

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

// ServerHost provides native OS functionality
const host = new ServerHost(options.ivy);
const host = new ServerHost();

// Establish a new server session that encapsulates lsp connection.
const session = new Session({
host,
logger,
ngPlugin: NGLANGSVC, // TypeScript allows only package names as plugin names.
// TypeScript allows only package names as plugin names.
ngPlugin: '@angular/language-service',
resolvedNgLsPath: ng.resolvedPath,
ivy: options.ivy,
logToConsole: options.logToConsole,
Expand Down
9 changes: 2 additions & 7 deletions server/src/server_host.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
*/

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

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

constructor(private ivy: boolean) {
constructor() {
this.args = ts.sys.args;
this.newLine = ts.sys.newLine;
this.useCaseSensitiveFileNames = ts.sys.useCaseSensitiveFileNames;
Expand Down Expand Up @@ -172,13 +171,9 @@ export class ServerHost implements ts.server.ServerHost {

require(initialPath: string, moduleName: string) {
try {
let modulePath = require.resolve(moduleName, {
const modulePath = require.resolve(moduleName, {
paths: [initialPath],
});
// TypeScript allows only package names as plugin names.
if (this.ivy && moduleName === NGLANGSVC) {
modulePath = this.resolvePath(modulePath + '/../ivy.js');
}
return {
module: require(modulePath),
error: undefined,
Expand Down
1 change: 1 addition & 0 deletions server/src/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ export class Session {
pluginName: options.ngPlugin,
configuration: {
angularOnly: true,
ivy: options.ivy,
},
});

Expand Down
6 changes: 4 additions & 2 deletions server/src/tests/version_provider_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,15 @@ describe('Node Module Resolver', () => {
it('should be able to resolve Angular language service', () => {
const result = resolveNgLangSvc(probeLocations, false /* ivy */);
expect(result).toBeDefined();
expect(result.resolvedPath).toMatch(/language-service.js$/);
expect(result.resolvedPath.endsWith('@angular/language-service/index.js')).toBeTrue();
});

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

Expand Down
5 changes: 2 additions & 3 deletions server/src/version_provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import * as path from 'path';

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

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

/**
Expand Down

0 comments on commit 98429ed

Please sign in to comment.