Skip to content
This repository has been archived by the owner on May 27, 2020. It is now read-only.

Commit

Permalink
refactor: rewrite typescript-deno-plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
axetroy committed Feb 9, 2020
1 parent 499b119 commit 8c4cc59
Show file tree
Hide file tree
Showing 8 changed files with 518 additions and 486 deletions.
36 changes: 36 additions & 0 deletions typescript-deno-plugin/src/configuration.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import merge from "deepmerge";

export type DenoPluginConfig = {
enable: boolean;
dtsFilepaths?: string[];
import_map: string;
};

export class ConfigurationManager {
private static readonly defaultConfiguration: DenoPluginConfig = {
enable: true,
dtsFilepaths: [],
import_map: ""
};

private readonly _configUpdatedListeners = new Set<() => void>();

public get config(): DenoPluginConfig {
return this._configuration;
}

private _configuration: DenoPluginConfig = ConfigurationManager
.defaultConfiguration;

public update(c: DenoPluginConfig) {
this._configuration = merge(this.config, c);

for (const listener of this._configUpdatedListeners) {
listener();
}
}

public onUpdatedConfig(listener: () => void) {
this._configUpdatedListeners.add(listener);
}
}
35 changes: 35 additions & 0 deletions typescript-deno-plugin/src/deno.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import * as path from "path";

export class Deno {
static get DENO_DEPS(): string {
return path.join(Deno.DENO_DIR, "deps");
}
static get DENO_DIR(): string {
// ref https://deno.land/manual.html
// On Linux/Redox: $XDG_CACHE_HOME/deno or $HOME/.cache/deno
// On Windows: %LOCALAPPDATA%/deno (%LOCALAPPDATA% = FOLDERID_LocalAppData)
// On macOS: $HOME/Library/Caches/deno
// If something fails, it falls back to $HOME/.deno
let denoDir = process.env.DENO_DIR;
if (denoDir === undefined) {
switch (process.platform) {
case "win32":
denoDir = `${process.env.LOCALAPPDATA}\\deno`;
break;
case "darwin":
denoDir = `${process.env.HOME}/Library/Caches/deno`;
break;
case "linux":
denoDir = `${process.env.HOME}/.cache/deno`;
break;
default:
denoDir = `${process.env.HOME}/.deno`;
}
}

return denoDir;
}
static get declarationFile(): string[] {
return ["lib.deno_runtime.d.ts"].map(v => path.join(Deno.DENO_DIR, v));
}
}
Loading

0 comments on commit 8c4cc59

Please sign in to comment.