aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Jozef Steinhübl <generalkubo@gmail.com> 2023-06-02 21:48:19 +0200
committerGravatar GitHub <noreply@github.com> 2023-06-02 12:48:19 -0700
commit4d1c900cac3291952a3328a1c1ebe40840e249b7 (patch)
treeea08cd019143f44b442cd554737b51b3ba5eae8b
parent97c522517c5dc631d77f035f0c5ae089ba0068aa (diff)
downloadbun-4d1c900cac3291952a3328a1c1ebe40840e249b7.tar.gz
bun-4d1c900cac3291952a3328a1c1ebe40840e249b7.tar.zst
bun-4d1c900cac3291952a3328a1c1ebe40840e249b7.zip
types: expose Bun.Env (#3111)
* expose Bun.Env * export bun.Env * fix: use import instead namespace access * fix(child_process): use import * tests(env): use module instead namespace
-rw-r--r--packages/bun-types/bun.d.ts43
-rw-r--r--packages/bun-types/child_process.d.ts2
-rw-r--r--packages/bun-types/globals.d.ts2
-rw-r--r--packages/bun-types/tests/env.test-d.ts8
4 files changed, 26 insertions, 29 deletions
diff --git a/packages/bun-types/bun.d.ts b/packages/bun-types/bun.d.ts
index 40dce6bf4..7721a4846 100644
--- a/packages/bun-types/bun.d.ts
+++ b/packages/bun-types/bun.d.ts
@@ -2,27 +2,6 @@ interface VoidFunction {
(): void;
}
-declare namespace Bun {
- interface Env extends Dict<string> {
- NODE_ENV: string;
-
- /**
- * The timezone used by Intl, Date, etc.
- *
- * To change the timezone, set `Bun.env.TZ` or `process.env.TZ` to the time zone you want to use.
- *
- * You can view the current timezone with `Intl.DateTimeFormat().resolvedOptions().timeZone`
- *
- * @example
- * ```js
- * Bun.env.TZ = "America/Los_Angeles";
- * console.log(Intl.DateTimeFormat().resolvedOptions().timeZone); // "America/Los_Angeles"
- * ```
- */
- TZ?: string;
- }
-}
-
/**
*
* Bun.js runtime APIs
@@ -43,6 +22,26 @@ declare namespace Bun {
declare module "bun" {
type ArrayBufferView = TypedArray | DataView;
import { Encoding as CryptoEncoding } from "crypto";
+
+ export interface Env extends Dict<string> {
+ NODE_ENV: string;
+
+ /**
+ * The timezone used by Intl, Date, etc.
+ *
+ * To change the timezone, set `Bun.env.TZ` or `process.env.TZ` to the time zone you want to use.
+ *
+ * You can view the current timezone with `Intl.DateTimeFormat().resolvedOptions().timeZone`
+ *
+ * @example
+ * ```js
+ * Bun.env.TZ = "America/Los_Angeles";
+ * console.log(Intl.DateTimeFormat().resolvedOptions().timeZone); // "America/Los_Angeles"
+ * ```
+ */
+ TZ?: string;
+ }
+
/**
* The environment variables of the process
*
@@ -51,7 +50,7 @@ declare module "bun" {
* Changes to `process.env` at runtime won't automatically be reflected in the default value. For that, you can pass `process.env` explicitly.
*
*/
- export const env: Bun.Env;
+ export const env: Env;
export const origin: string;
/**
diff --git a/packages/bun-types/child_process.d.ts b/packages/bun-types/child_process.d.ts
index 04389986f..58dc69f06 100644
--- a/packages/bun-types/child_process.d.ts
+++ b/packages/bun-types/child_process.d.ts
@@ -704,7 +704,7 @@ declare module "child_process" {
uid?: number | undefined;
gid?: number | undefined;
cwd?: string | URL | undefined;
- env?: Partial<Bun.Env> | undefined;
+ env?: Partial<import("bun").Env> | undefined;
}
interface CommonOptions extends ProcessEnvOptions {
/**
diff --git a/packages/bun-types/globals.d.ts b/packages/bun-types/globals.d.ts
index 47ccb85e7..f99378101 100644
--- a/packages/bun-types/globals.d.ts
+++ b/packages/bun-types/globals.d.ts
@@ -367,7 +367,7 @@ interface Process {
platform: Platform;
argv: string[];
execArgv: string[];
- env: Bun.Env;
+ env: import("bun").Env;
/** Whether you are using Bun */
isBun: 1; // FIXME: this should actually return a boolean
diff --git a/packages/bun-types/tests/env.test-d.ts b/packages/bun-types/tests/env.test-d.ts
index c2611e1a7..a09d7c596 100644
--- a/packages/bun-types/tests/env.test-d.ts
+++ b/packages/bun-types/tests/env.test-d.ts
@@ -1,10 +1,8 @@
import { expectType } from "tsd";
-declare global {
- namespace Bun {
- interface Env {
- WHATEVER: "WHATEVER";
- }
+declare module "bun" {
+ export interface Env {
+ WHATEVER: "WHATEVER";
}
}