-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(process): support
process.versions
- Loading branch information
Showing
2 changed files
with
23 additions
and
2 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 |
---|---|---|
@@ -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]; | ||
} | ||
}, | ||
}); |
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,4 @@ | ||
// @ts-ignore | ||
import * as stdEnv from "../dist/index.mjs"; | ||
|
||
console.log(stdEnv.process.env.HOME); |