Skip to content

Commit

Permalink
add Platform.Adapter interface
Browse files Browse the repository at this point in the history
  • Loading branch information
rivy committed Jan 11, 2021
1 parent 8d52796 commit 6ee064e
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/platform-adapters/_base.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// eslint-disable-next-line @typescript-eslint/no-namespace
export namespace Platform {
export type Adapter = {
readonly env: { readonly get: (_: string) => string | undefined };
readonly os: { readonly homedir?: () => string; readonly tmpdir?: () => string };
readonly path: {
readonly join: (..._: readonly string[]) => string;
readonly normalize: (_: string) => string;
};
readonly process: {
readonly platform: string;
};
};
}
1 change: 1 addition & 0 deletions src/platform-adapters/browser.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
'use strict';
20 changes: 20 additions & 0 deletions src/platform-adapters/deno.deno.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// spell-checker:ignore Deno

// eslint-disable-next-line @typescript-eslint/triple-slash-reference
/// <reference path="../types/deno.d.ts"/>

// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
import * as path from 'https://deno.land/std@0.81.0/path/mod.ts';

// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
import { Platform } from './_base.ts';

export const adapter: Platform.Adapter = {
env: { get: Deno.env.get },
// Deno (as of v1.6) has no built-in implementation for homedir() or tmpdir()
os: {}, // * module is tolerant of missing homedir()/tmpdir() functions
path,
process: { platform: Deno.build.os },
};
15 changes: 15 additions & 0 deletions src/platform-adapters/node.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import * as os from 'os';
import * as path from 'path';

import { Platform } from './_base';

export const adapter: Platform.Adapter = {
env: {
get: (s) => {
return process.env[s];
},
},
os,
path,
process,
};

0 comments on commit 6ee064e

Please sign in to comment.