Compare commits

...

6 Commits

Author SHA1 Message Date
Colin McDonnell
ca2b196049 Support NodeJS.ProcessEnv as well 2023-06-02 12:43:03 -07:00
Jozef Steinhübl
68a50278ba tests(env): use module instead namespace 2023-05-29 22:35:24 +02:00
Jozef Steinhübl
1bc31498f8 fix(child_process): use import 2023-05-29 22:33:42 +02:00
Jozef Steinhübl
5621a42dfa fix: use import instead namespace access 2023-05-29 22:31:30 +02:00
Jozef Steinhübl
14a49eb8d8 export bun.Env 2023-05-29 22:27:16 +02:00
Jozef Steinhübl
09c4f93a74 expose Bun.Env 2023-05-29 22:17:12 +02:00
4 changed files with 41 additions and 38 deletions

View File

@@ -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>, NodeJS.ProcessEnv {
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;
/**

View File

@@ -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 {
/**

View File

@@ -187,6 +187,8 @@ declare namespace NodeJS {
(id: string): any;
resolve: RequireResolve;
}
interface ProcessEnv {}
type Signals =
| "SIGABRT"
| "SIGALRM"
@@ -367,7 +369,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

View File

@@ -1,22 +1,24 @@
import { expectType } from "tsd";
declare module "bun" {
export interface Env {
FOO: "FOO";
}
}
declare global {
namespace Bun {
interface Env {
WHATEVER: "WHATEVER";
namespace NodeJS {
interface ProcessEnv {
BAR: "BAR";
}
}
}
expectType<"WHATEVER">(process.env.WHATEVER);
expectType<"FOO">(process.env.FOO);
expectType<"BAR">(process.env.BAR);
export {};
new Bun.Transpiler({
macro: {
"react-relay": {
graphql: "bun-macro-relay/bun-macro-relay.tsx",
},
},
});
Event;
process.env.FOO;
process.env.BAR;
process.env.OTHER;
Bun.env.FOO;
Bun.env.BAR;