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

Commit 2101f84

Browse files
authored
add deno declaration files (#5)
* remove unused files * format code * replace `join` with `resolve` * load lib.deno_runtime.d.ts
1 parent 6b0480e commit 2101f84

File tree

2 files changed

+24
-4
lines changed

2 files changed

+24
-4
lines changed

src/index.ts

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,23 @@ export = function init({ typescript }: { typescript: typeof ts_module }) {
6767
return { ...OPTIONS, ...projectSetting };
6868
};
6969

70+
const getScriptFileNames = info.languageServiceHost.getScriptFileNames!;
71+
info.languageServiceHost.getScriptFileNames = () => {
72+
const scriptFileNames = getScriptFileNames.call(
73+
info.languageServiceHost
74+
);
75+
76+
const denoDir = getDenoDir();
77+
const denoDtsPath = path.resolve(denoDir, "lib.deno_runtime.d.ts");
78+
79+
if (!fs.existsSync(denoDtsPath)) {
80+
// TODO: generate or download lib.deno_runtime.d.ts
81+
}
82+
83+
scriptFileNames.push(denoDtsPath);
84+
return scriptFileNames;
85+
};
86+
7087
return info.languageService;
7188
}
7289
};
@@ -90,7 +107,7 @@ function convertRemoteToLocalCache(moduleName: string): string {
90107

91108
const denoDir = getDenoDir();
92109
// "https://deno.land/x/std/log/mod" to "$DENO_DIR/deps/https/deno.land/x/std/log/mod" (no ".ts" because stripped)
93-
const name = path.join(denoDir, "deps", moduleName.replace("://", "/"));
110+
const name = path.resolve(denoDir, "deps", moduleName.replace("://", "/"));
94111
const redirectedName = fallbackHeader(name);
95112
logger.info(`convert "${moduleName}" to "${redirectedName}".`);
96113

@@ -106,14 +123,18 @@ interface IDenoModuleHeaders {
106123
* If moduleName is not found, recursively search for headers and "redirect_to" property.
107124
*/
108125
function fallbackHeader(modulePath: string): string {
109-
const validPath = modulePath.endsWith(".ts") ? modulePath : `${modulePath}.ts`;
126+
const validPath = modulePath.endsWith(".ts")
127+
? modulePath
128+
: `${modulePath}.ts`;
110129
if (fs.existsSync(validPath)) {
111130
return modulePath;
112131
}
113132

114133
const headersPath = `${validPath}.headers.json`;
115134
if (fs.existsSync(headersPath)) {
116-
const headers: IDenoModuleHeaders = JSON.parse(fs.readFileSync(headersPath, { encoding: "utf-8" }));
135+
const headers: IDenoModuleHeaders = JSON.parse(
136+
fs.readFileSync(headersPath, { encoding: "utf-8" })
137+
);
117138
logger.info(`redirect "${modulePath}" to "${headers.redirect_to}".`);
118139
// TODO: avoid Circular
119140
return convertRemoteToLocalCache(stripExtNameDotTs(headers.redirect_to));

vscode-deno

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)