Skip to content

Commit e4173e1

Browse files
seanchas116basarat
authored andcommitted
Load lib.d.ts from typescriptServices path (#951)
1 parent de5aca9 commit e4173e1

File tree

7 files changed

+39
-4
lines changed

7 files changed

+39
-4
lines changed

dist/main/lang/core/languageServiceHost2.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ var path = require('path');
33
var fs = require('fs');
44
var os = require('os');
55
var textBuffer = require('basarat-text-buffer');
6+
var typescriptServices_1 = require("../typescriptServices");
67
function createScriptInfo(fileName, text, isOpen) {
78
if (isOpen === void 0) { isOpen = false; }
89
var version = 1;
@@ -118,11 +119,19 @@ function getScriptSnapShot(scriptInfo) {
118119
getChangeRange: getChangeRange,
119120
};
120121
}
122+
function getTypescriptLocation() {
123+
if (typescriptServices_1.typescriptServices) {
124+
return path.dirname(typescriptServices_1.typescriptServices);
125+
}
126+
else {
127+
return path.dirname(require.resolve('ntypescript'));
128+
}
129+
}
121130
exports.getDefaultLibFilePath = function (options) {
122131
var filename = ts.getDefaultLibFileName(options);
123-
return (path.join(path.dirname(require.resolve('ntypescript')), filename)).split('\\').join('/');
132+
return (path.join(getTypescriptLocation(), filename)).split('\\').join('/');
124133
};
125-
exports.typescriptDirectory = path.dirname(require.resolve('ntypescript')).split('\\').join('/');
134+
exports.typescriptDirectory = getTypescriptLocation().split('\\').join('/');
126135
var LanguageServiceHost = (function () {
127136
function LanguageServiceHost(config) {
128137
var _this = this;

dist/main/lang/typescriptServices.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
"use strict";
2+
exports.typescriptServices = '';
3+
function setTypescriptServices(path) {
4+
exports.typescriptServices = path;
5+
}
6+
exports.setTypescriptServices = setTypescriptServices;

dist/worker/child.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ if (process.argv.length > 2) {
55
}
66
var makeTypeScriptGlobal_1 = require("../typescript/makeTypeScriptGlobal");
77
makeTypeScriptGlobal_1.makeTsGlobal(typescriptServices);
8+
var typescriptServices_1 = require("../main/lang/typescriptServices");
9+
typescriptServices_1.setTypescriptServices(typescriptServices);
810
var workerLib = require('./lib/workerLib');
911
var child = new workerLib.Child();
1012
var projectCache = require("../main/lang/projectCache");

lib/main/lang/core/languageServiceHost2.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import os = require('os')
55
import textBuffer = require('basarat-text-buffer');
66

77
import tsconfig = require('../../tsconfig/tsconfig');
8+
import {typescriptServices} from "../typescriptServices";
89

910
interface ScriptInfo {
1011
getFileName(): string;
@@ -203,12 +204,21 @@ function getScriptSnapShot(scriptInfo: ScriptInfo): ts.IScriptSnapshot {
203204
}
204205
}
205206

207+
function getTypescriptLocation() {
208+
if (typescriptServices) {
209+
return path.dirname(typescriptServices);
210+
}
211+
else {
212+
return path.dirname(require.resolve('ntypescript'));
213+
}
214+
}
215+
206216
export var getDefaultLibFilePath = (options: ts.CompilerOptions) => {
207217
var filename = ts.getDefaultLibFileName(options);
208-
return (path.join(path.dirname(require.resolve('ntypescript')), filename)).split('\\').join('/');
218+
return (path.join(getTypescriptLocation(), filename)).split('\\').join('/');
209219
}
210220

211-
export var typescriptDirectory = path.dirname(require.resolve('ntypescript')).split('\\').join('/');
221+
export var typescriptDirectory = getTypescriptLocation().split('\\').join('/');
212222

213223

214224
// NOTES:

lib/main/lang/typescriptServices.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
export var typescriptServices = '';
2+
3+
export function setTypescriptServices(path: string) {
4+
typescriptServices = path;
5+
}

lib/tsconfig.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@
9292
"./main/lang/transformers/implementations/nullTransformer.ts",
9393
"./main/lang/transformers/transformer.ts",
9494
"./main/lang/transformers/transformerRegistry.ts",
95+
"./main/lang/typescriptServices.ts",
9596
"./main/lang/utils.ts",
9697
"./main/react/htmltotsx.ts",
9798
"./main/tsconfig/dts-generator.ts",

lib/worker/child.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ if (process.argv.length > 2) {
55
// setup typescript
66
import {makeTsGlobal} from "../typescript/makeTypeScriptGlobal";
77
makeTsGlobal(typescriptServices);
8+
import {setTypescriptServices} from "../main/lang/typescriptServices";
9+
setTypescriptServices(typescriptServices);
810

911
import workerLib = require('./lib/workerLib');
1012

0 commit comments

Comments
 (0)