This repository has been archived by the owner on May 27, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: rewrite typescript-deno-plugin
- Loading branch information
Showing
8 changed files
with
518 additions
and
486 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
} | ||
} |
Oops, something went wrong.