Skip to content
This repository was archived by the owner on Sep 4, 2020. It is now read-only.

Commit 36a5c30

Browse files
committed
remove dtsPath comfig
Signed-off-by: 迷渡 <[email protected]>
1 parent 89c0613 commit 36a5c30

File tree

3 files changed

+29
-64
lines changed

3 files changed

+29
-64
lines changed

src/index.ts

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,9 @@ import { parseFromString, resolve, ImportMaps } from "import-maps";
99

1010
import { Logger } from "./logger";
1111
import {
12-
getGlobalDtsPath,
13-
getLocalDtsPath,
14-
getDtsPathForVscode,
12+
getDenoDtsPath,
1513
normalizeFilepath,
1614
pathExistsSync,
17-
getWebWorkderDtsPath,
1815
} from "./utils";
1916

2017
import { universalModuleResolver } from "./module_resolver/universal_module_resolver";
@@ -28,7 +25,6 @@ type DenoPluginConfig = {
2825
enable: boolean;
2926
importmap?: string;
3027
tsconfig?: string;
31-
dtsPath?: string;
3228
};
3329

3430
const config: DenoPluginConfig = {
@@ -242,23 +238,21 @@ module.exports = function init(
242238
info.languageServiceHost,
243239
);
244240

245-
const denoDtsPath = getDtsPathForVscode(info) ||
246-
getGlobalDtsPath() ||
247-
getLocalDtsPath(info.languageServiceHost);
248-
249-
if (denoDtsPath) {
250-
scriptFileNames.push(denoDtsPath);
241+
const libDenoDts = getDenoDtsPath(tsLsHost, "lib.deno.d.ts");
242+
if (!libDenoDts) {
243+
logger.info(`Can not load lib.deno.d.ts from ${libDenoDts}.`);
244+
return scriptFileNames;
251245
}
246+
scriptFileNames.push(libDenoDts);
252247

253-
const webworkerDtsPath = getWebWorkderDtsPath(info.languageServiceHost);
254-
if (webworkerDtsPath) {
255-
scriptFileNames.push(webworkerDtsPath);
248+
const libWebworkerDts = getDenoDtsPath(tsLsHost, "lib.webworker.d.ts");
249+
if (!libWebworkerDts) {
250+
logger.info(
251+
`Can not load lib.webworker.d.ts from ${libWebworkerDts}.`,
252+
);
253+
return scriptFileNames;
256254
}
257-
258-
logger.info(`dts path:
259-
deno: ${denoDtsPath}
260-
webworker: ${webworkerDtsPath}
261-
`);
255+
scriptFileNames.push(libWebworkerDts);
262256

263257
return scriptFileNames;
264258
};

src/typescript_host.ts

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,8 @@ import merge from "merge-deep";
44
import { LanguageServiceHost } from "./language_service_host";
55
import { Logger } from "./logger";
66
import {
7-
getGlobalDtsPath,
8-
getLocalDtsPath,
9-
} from "utils";
7+
getDenoDtsPath,
8+
} from "./utils";
109

1110
// see https://github.com/denoland/deno/blob/2debbdacb935cfe1eb7bb8d1f40a5063b339d90b/js/compiler.ts#L159-L170
1211
const OPTIONS: ts_module.CompilerOptions = {
@@ -100,10 +99,7 @@ export class TypeScriptServiceHost implements LanguageServiceHost {
10099
getScriptFileNames(): string[] {
101100
const scriptFileNames: string[] = this.tsLsHost.getScriptFileNames();
102101

103-
const denoDtsPath =
104-
// getDtsPathForVscode(this.tsLsHost) ||
105-
getGlobalDtsPath() ||
106-
getLocalDtsPath(this.tsLsHost);
102+
const denoDtsPath = getDenoDtsPath(this.tsLsHost, "lib.deno.d.ts");
107103

108104
if (denoDtsPath) {
109105
scriptFileNames.push(denoDtsPath);

src/utils.ts

Lines changed: 13 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import * as fs from "fs";
22
import * as path from "path";
33
import crypto from "crypto";
44

5-
import ts_module from "typescript/lib/tsserverlibrary";
5+
import ts from "typescript/lib/tsserverlibrary";
66
import { URL } from "url";
77
import { statSync } from "fs";
88

@@ -38,54 +38,29 @@ export function getDenoDepsDir(): string {
3838
return path.join(getDenoDir(), "deps");
3939
}
4040

41-
export function getGlobalDtsPath(): string | undefined {
42-
const denoDir = getDenoDir();
43-
const globalDtsPath = path.resolve(denoDir, "lib.deno.d.ts");
44-
45-
if (fs.existsSync(globalDtsPath)) {
46-
return globalDtsPath;
47-
}
48-
49-
return undefined;
50-
}
51-
52-
export function getWebWorkderDtsPath(
53-
tsLsHost: ts_module.LanguageServiceHost,
54-
): string | undefined {
41+
export function getPluginPath(
42+
tsLsHost: ts.LanguageServiceHost,
43+
): string {
5544
return path.resolve(
5645
tsLsHost.getCurrentDirectory(),
5746
"node_modules",
5847
"typescript-deno-plugin",
59-
"lib",
60-
"lib.webworker.d.ts",
6148
);
6249
}
6350

64-
export function getLocalDtsPath(
65-
tsLsHost: ts_module.LanguageServiceHost,
51+
export function getDenoDtsPath(
52+
tsLsHost: ts.LanguageServiceHost,
53+
specifier: string,
6654
): string | undefined {
67-
const localDtsPath = path.resolve(
68-
tsLsHost.getCurrentDirectory(),
69-
"node_modules",
70-
"typescript-deno-plugin",
71-
"lib",
72-
"lib.deno.d.ts",
73-
);
55+
let file: string = path.resolve(getDenoDir(), specifier);
7456

75-
if (fs.existsSync(localDtsPath)) {
76-
return localDtsPath;
57+
if (fs.existsSync(file)) {
58+
return file;
7759
}
7860

79-
return undefined;
80-
}
81-
82-
export function getDtsPathForVscode(
83-
info: ts_module.server.PluginCreateInfo,
84-
): string | undefined {
85-
const bundledDtsPath = info.config.dtsPath;
86-
87-
if (bundledDtsPath && fs.existsSync(bundledDtsPath)) {
88-
return bundledDtsPath;
61+
file = path.resolve(getPluginPath(tsLsHost), "lib", specifier);
62+
if (fs.existsSync(file)) {
63+
return file;
8964
}
9065

9166
return undefined;

0 commit comments

Comments
 (0)