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

Commit 6b0480e

Browse files
authored
set default compilation options (#4)
* set default compilation options * reorganize `getDenoDir`
1 parent 0832c6c commit 6b0480e

File tree

2 files changed

+49
-22
lines changed

2 files changed

+49
-22
lines changed

src/index.ts

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,26 @@ import * as mockRequire from "mock-require";
66
import * as ts_module from "typescript/lib/tsserverlibrary";
77

88
import { Logger } from "./logger";
9+
import { getDenoDir } from "./shared";
910

1011
let logger: Logger;
1112

13+
// see https://github.com/denoland/deno/blob/2debbdacb935cfe1eb7bb8d1f40a5063b339d90b/js/compiler.ts#L159-L170
14+
const OPTIONS: ts_module.CompilerOptions = {
15+
allowJs: true,
16+
checkJs: true,
17+
esModuleInterop: true,
18+
module: ts_module.ModuleKind.ESNext,
19+
moduleResolution: ts_module.ModuleResolutionKind.NodeJs,
20+
noEmit: true,
21+
outDir: "$deno$",
22+
removeComments: true,
23+
resolveJsonModule: true,
24+
sourceMap: true,
25+
target: ts_module.ScriptTarget.ESNext,
26+
typeRoots: []
27+
};
28+
1229
export = function init({ typescript }: { typescript: typeof ts_module }) {
1330
// Make sure Deno imports the correct version of TS
1431
mockRequire("typescript", typescript);
@@ -45,6 +62,11 @@ export = function init({ typescript }: { typescript: typeof ts_module }) {
4562
);
4663
};
4764

65+
const projectSetting = info.project.getCompilationSettings();
66+
info.languageServiceHost.getCompilationSettings = () => {
67+
return { ...OPTIONS, ...projectSetting };
68+
};
69+
4870
return info.languageService;
4971
}
5072
};
@@ -66,28 +88,7 @@ function convertRemoteToLocalCache(moduleName: string): string {
6688
return moduleName;
6789
}
6890

69-
// ref https://deno.land/manual.html
70-
// On Linux/Redox: $XDG_CACHE_HOME/deno or $HOME/.cache/deno
71-
// On Windows: %LOCALAPPDATA%/deno (%LOCALAPPDATA% = FOLDERID_LocalAppData)
72-
// On macOS: $HOME/Library/Caches/deno
73-
// If something fails, it falls back to $HOME/.deno
74-
let denoDir = process.env.DENO_DIR;
75-
if (denoDir === undefined) {
76-
switch (process.platform) {
77-
case "win32":
78-
denoDir = `${process.env.LOCALAPPDATA}\\deno`;
79-
break;
80-
case "darwin":
81-
denoDir = `${process.env.HOME}/Library/Caches/deno`;
82-
break;
83-
case "linux":
84-
denoDir = `${process.env.HOME}/.cache/deno`;
85-
break;
86-
default:
87-
denoDir = `${process.env.HOME}/.deno`;
88-
}
89-
}
90-
91+
const denoDir = getDenoDir();
9192
// "https://deno.land/x/std/log/mod" to "$DENO_DIR/deps/https/deno.land/x/std/log/mod" (no ".ts" because stripped)
9293
const name = path.join(denoDir, "deps", moduleName.replace("://", "/"));
9394
const redirectedName = fallbackHeader(name);
@@ -114,6 +115,7 @@ function fallbackHeader(modulePath: string): string {
114115
if (fs.existsSync(headersPath)) {
115116
const headers: IDenoModuleHeaders = JSON.parse(fs.readFileSync(headersPath, { encoding: "utf-8" }));
116117
logger.info(`redirect "${modulePath}" to "${headers.redirect_to}".`);
118+
// TODO: avoid Circular
117119
return convertRemoteToLocalCache(stripExtNameDotTs(headers.redirect_to));
118120
}
119121
return modulePath;

src/shared.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
export function getDenoDir(): string {
2+
// ref https://deno.land/manual.html
3+
// On Linux/Redox: $XDG_CACHE_HOME/deno or $HOME/.cache/deno
4+
// On Windows: %LOCALAPPDATA%/deno (%LOCALAPPDATA% = FOLDERID_LocalAppData)
5+
// On macOS: $HOME/Library/Caches/deno
6+
// If something fails, it falls back to $HOME/.deno
7+
let denoDir = process.env.DENO_DIR;
8+
if (denoDir === undefined) {
9+
switch (process.platform) {
10+
case "win32":
11+
denoDir = `${process.env.LOCALAPPDATA}\\deno`;
12+
break;
13+
case "darwin":
14+
denoDir = `${process.env.HOME}/Library/Caches/deno`;
15+
break;
16+
case "linux":
17+
denoDir = `${process.env.HOME}/.cache/deno`;
18+
break;
19+
default:
20+
denoDir = `${process.env.HOME}/.deno`;
21+
}
22+
}
23+
24+
return denoDir;
25+
}

0 commit comments

Comments
 (0)