Skip to content

Commit

Permalink
fix: unable to load ivy native plugin
Browse files Browse the repository at this point in the history
In typescript 4.1.4, ts allows only package names as plugin names,
so `@angular/language-service/bundles/ivy` is disabled by ts. This
PR will resolve `@angular/language-service` to path `./bundles/ivy.js`

fixed angular#1109
  • Loading branch information
ivanwonder committed Feb 16, 2021
1 parent 18291b8 commit 8060202
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 11 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@
},
"dependencies": {
"@angular/language-service": "11.2.0",
"typescript": "~4.1.0",
"typescript": "4.1.5",
"vscode-jsonrpc": "6.0.0",
"vscode-languageclient": "7.0.0",
"vscode-languageserver": "7.0.0",
Expand Down
6 changes: 3 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 {resolveNgLangSvc, resolveTsServer} from './version_provider';
import {nglangsvc, resolveNgLangSvc, resolveTsServer} from './version_provider';

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

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

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

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 @@ -19,7 +20,7 @@ export class ServerHost implements ts.server.ServerHost {
readonly newLine: string;
readonly useCaseSensitiveFileNames: boolean;

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

require(initialPath: string, moduleName: string) {
try {
const modulePath = require.resolve(moduleName, {
let 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
2 changes: 1 addition & 1 deletion server/src/version_provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import * as fs from 'fs';

const MIN_TS_VERSION = '4.1';
const MIN_NG_VERSION = '11.2';
export const nglangsvc = '@angular/language-service';

/**
* Represents a valid node module that has been successfully resolved.
Expand Down Expand Up @@ -84,7 +85,6 @@ export function resolveTsServer(probeLocations: string[]): NodeModule {
* @param ivy true if Ivy language service is requested
*/
export function resolveNgLangSvc(probeLocations: string[], ivy: boolean): NodeModule {
const nglangsvc = '@angular/language-service';
const packageName = ivy ? `${nglangsvc}/bundles/ivy` : nglangsvc;
return resolveWithMinVersion(packageName, MIN_NG_VERSION, probeLocations, nglangsvc);
}
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -907,10 +907,10 @@ typed-rest-client@1.2.0:
tunnel "0.0.4"
underscore "1.8.3"

typescript@~4.1.0:
version "4.1.3"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.1.3.tgz#519d582bd94cba0cf8934c7d8e8467e473f53bb7"
integrity sha512-B3ZIOf1IKeH2ixgHhj6la6xdwR9QrLC5d1VKeCSY4tvkqhF2eqd9O7txNlS0PO3GrBAFIdr3L1ndNwteUbZLYg==
typescript@4.1.5:
version "4.1.5"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.1.5.tgz#123a3b214aaff3be32926f0d8f1f6e704eb89a72"
integrity sha512-6OSu9PTIzmn9TCDiovULTnET6BgXtDYL4Gg4szY+cGsc3JP1dQL8qvE8kShTRx1NIw4Q9IBHlwODjkjWEtMUyA==

uc.micro@^1.0.1, uc.micro@^1.0.5:
version "1.0.6"
Expand Down

0 comments on commit 8060202

Please sign in to comment.