Skip to content

Commit

Permalink
feat(process): support process.versions
Browse files Browse the repository at this point in the history
  • Loading branch information
pi0 committed Aug 9, 2023
1 parent 581c674 commit 1ad71f6
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
21 changes: 19 additions & 2 deletions src/process.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,28 @@
import { env } from "./env";

type StdProcess = Partial<typeof globalThis.process> & { env: typeof env };
export interface Process
extends Partial<Omit<typeof globalThis.process, "versions">> {
env: Record<string, string | undefined>;
versions: Record<string, string>;
}

export const process = new Proxy<StdProcess>(globalThis.process || { env }, {
const _process = (globalThis.process ||
Object.create(null)) as unknown as Process;

const processShims = {
versions: {},
};

export const process = new Proxy<Process>(_process, {
get(target, prop) {
if (prop === "env") {
return env;
}
if (prop in target) {
return target[prop];
}
if (prop in processShims) {
return processShims[prop as keyof typeof processShims];
}
},
});
4 changes: 4 additions & 0 deletions test/deno.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// @ts-ignore
import * as stdEnv from "../dist/index.mjs";

console.log(stdEnv.process.env.HOME);

0 comments on commit 1ad71f6

Please sign in to comment.