bun-types 1.0.22 → 1.0.24

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/types.d.ts +196 -15
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bun-types",
3
- "version": "1.0.22",
3
+ "version": "1.0.24",
4
4
  "license": "MIT",
5
5
  "description": "Type definitions for Bun, an incredibly fast JavaScript runtime",
6
6
  "types": "types.d.ts",
package/types.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- // Type definitions for bun 1.0.22
1
+ // Type definitions for bun 1.0.24
2
2
  // Project: https://github.com/oven-sh/bun
3
3
  // Definitions by: Jarred Sumner <https://github.com/Jarred-Sumner>
4
4
  // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
@@ -597,6 +597,12 @@ interface ImportMeta {
597
597
  * ```
598
598
  */
599
599
  readonly main: boolean;
600
+
601
+ /** Alias of `import.meta.dir`. Exists for Node.js compatibility */
602
+ readonly dirname: string;
603
+
604
+ /** Alias of `import.meta.path`. Exists for Node.js compatibility */
605
+ readonly filename: string;
600
606
  }
601
607
 
602
608
  /**
@@ -717,7 +723,7 @@ declare namespace Bun {
717
723
  */
718
724
  env?:
719
725
  | Record<string, string>
720
- | typeof import("node:worker_threads")["SHARE_ENV"]
726
+ | (typeof import("node:worker_threads"))["SHARE_ENV"]
721
727
  | undefined;
722
728
 
723
729
  /**
@@ -3555,8 +3561,8 @@ declare module "bun:ffi" {
3555
3561
  type ToFFIType<T extends FFITypeOrString> = T extends FFIType
3556
3562
  ? T
3557
3563
  : T extends string
3558
- ? FFITypeStringToType[T]
3559
- : never;
3564
+ ? FFITypeStringToType[T]
3565
+ : never;
3560
3566
 
3561
3567
  // eslint-disable-next-line @definitelytyped/no-single-element-tuple-type
3562
3568
  type _Narrow<T, U> = [U] extends [T] ? U : Extract<T, U>;
@@ -3576,9 +3582,9 @@ declare module "bun:ffi" {
3576
3582
  ...args: Fns[K]["args"] extends infer A extends readonly FFITypeOrString[]
3577
3583
  ? { [L in keyof A]: FFITypeToArgsType[ToFFIType<A[L]>] }
3578
3584
  : // eslint-disable-next-line @definitelytyped/no-single-element-tuple-type
3579
- [unknown] extends [Fns[K]["args"]]
3580
- ? []
3581
- : never
3585
+ [unknown] extends [Fns[K]["args"]]
3586
+ ? []
3587
+ : never
3582
3588
  ) => // eslint-disable-next-line @definitelytyped/no-single-element-tuple-type
3583
3589
  [unknown] extends [Fns[K]["returns"]]
3584
3590
  ? undefined
@@ -4974,6 +4980,181 @@ declare module "bun" {
4974
4980
  options?: { PATH?: string; cwd?: string },
4975
4981
  ): string | null;
4976
4982
 
4983
+ export type ShellFunction = (input: Uint8Array) => Uint8Array;
4984
+
4985
+ export type ShellExpression =
4986
+ | string
4987
+ | { raw: string }
4988
+ | Subprocess
4989
+ | SpawnOptions.Readable
4990
+ | SpawnOptions.Writable
4991
+ | ReadableStream;
4992
+
4993
+ class ShellPromise extends Promise<ShellOutput> {
4994
+ get stdin(): WritableStream;
4995
+ /**
4996
+ * Change the current working directory of the shell.
4997
+ * @param newCwd - The new working directory
4998
+ */
4999
+ cwd(newCwd: string): this;
5000
+ /**
5001
+ * Set environment variables for the shell.
5002
+ * @param newEnv - The new environment variables
5003
+ *
5004
+ * @example
5005
+ * ```ts
5006
+ * await $`echo $FOO`.env({ ...process.env, FOO: "LOL!" })
5007
+ * expect(stdout.toString()).toBe("LOL!");
5008
+ * ```
5009
+ */
5010
+ env(newEnv: Record<string, string> | undefined): this;
5011
+ /**
5012
+ * By default, the shell will write to the current process's stdout and stderr, as well as buffering that output.
5013
+ *
5014
+ * This configures the shell to only buffer the output.
5015
+ */
5016
+ quiet(): this;
5017
+
5018
+ /**
5019
+ * Read from stdout as a string, line by line
5020
+ *
5021
+ * Automatically calls {@link quiet} to disable echoing to stdout.
5022
+ */
5023
+ lines(): AsyncIterable<string>;
5024
+
5025
+ /**
5026
+ * Read from stdout as a string
5027
+ *
5028
+ * Automatically calls {@link quiet} to disable echoing to stdout.
5029
+ * @param encoding - The encoding to use when decoding the output
5030
+ * @returns A promise that resolves with stdout as a string
5031
+ * @example
5032
+ *
5033
+ * ## Read as UTF-8 string
5034
+ *
5035
+ * ```ts
5036
+ * const output = await $`echo hello`.text();
5037
+ * console.log(output); // "hello\n"
5038
+ * ```
5039
+ *
5040
+ * ## Read as base64 string
5041
+ *
5042
+ * ```ts
5043
+ * const output = await $`echo ${atob("hello")}`.text("base64");
5044
+ * console.log(output); // "hello\n"
5045
+ * ```
5046
+ *
5047
+ */
5048
+ text(encoding?: BufferEncoding): Promise<string>;
5049
+
5050
+ /**
5051
+ * Read from stdout as a JSON object
5052
+ *
5053
+ * Automatically calls {@link quiet}
5054
+ *
5055
+ * @returns A promise that resolves with stdout as a JSON object
5056
+ * @example
5057
+ *
5058
+ * ```ts
5059
+ * const output = await $`echo '{"hello": 123}'`.json();
5060
+ * console.log(output); // { hello: 123 }
5061
+ * ```
5062
+ *
5063
+ */
5064
+ json(): Promise<any>;
5065
+
5066
+ /**
5067
+ * Read from stdout as an ArrayBuffer
5068
+ *
5069
+ * Automatically calls {@link quiet}
5070
+ * @returns A promise that resolves with stdout as an ArrayBuffer
5071
+ * @example
5072
+ *
5073
+ * ```ts
5074
+ * const output = await $`echo hello`.arrayBuffer();
5075
+ * console.log(output); // ArrayBuffer { byteLength: 6 }
5076
+ * ```
5077
+ */
5078
+ arrayBuffer(): Promise<ArrayBuffer>;
5079
+
5080
+ /**
5081
+ * Read from stdout as a Blob
5082
+ *
5083
+ * Automatically calls {@link quiet}
5084
+ * @returns A promise that resolves with stdout as a Blob
5085
+ * @example
5086
+ * ```ts
5087
+ * const output = await $`echo hello`.blob();
5088
+ * console.log(output); // Blob { size: 6, type: "" }
5089
+ * ```
5090
+ */
5091
+ blob(): Promise<Blob>;
5092
+ }
5093
+
5094
+ interface ShellConstructor {
5095
+ new (): Shell;
5096
+ }
5097
+
5098
+ export interface Shell {
5099
+ (
5100
+ strings: TemplateStringsArray,
5101
+ ...expressions: ShellExpression[]
5102
+ ): ShellPromise;
5103
+
5104
+ /**
5105
+ * Perform bash-like brace expansion on the given pattern.
5106
+ * @param pattern - Brace pattern to expand
5107
+ *
5108
+ * @example
5109
+ * ```js
5110
+ * const result = braces('index.{js,jsx,ts,tsx}');
5111
+ * console.log(result) // ['index.js', 'index.jsx', 'index.ts', 'index.tsx']
5112
+ * ```
5113
+ */
5114
+ braces(pattern: string): string[];
5115
+
5116
+ /**
5117
+ * Escape strings for input into shell commands.
5118
+ * @param input
5119
+ */
5120
+ escape(input: string): string;
5121
+
5122
+ /**
5123
+ *
5124
+ * Change the default environment variables for shells created by this instance.
5125
+ *
5126
+ * @param newEnv Default environment variables to use for shells created by this instance.
5127
+ * @default process.env
5128
+ *
5129
+ * ## Example
5130
+ *
5131
+ * ```js
5132
+ * import {$} from 'bun';
5133
+ * $.env({ BUN: "bun" });
5134
+ * await $`echo $BUN`;
5135
+ * // "bun"
5136
+ * ```
5137
+ */
5138
+ env(newEnv?: Record<string, string | undefined>): this;
5139
+
5140
+ /**
5141
+ *
5142
+ * @param newCwd Default working directory to use for shells created by this instance.
5143
+ */
5144
+ cwd(newCwd?: string): this;
5145
+
5146
+ readonly ShellPromise: typeof ShellPromise;
5147
+ readonly Shell: ShellConstructor;
5148
+ }
5149
+
5150
+ export interface ShellOutput {
5151
+ readonly stdout: Buffer;
5152
+ readonly stderr: Buffer;
5153
+ readonly exitCode: number;
5154
+ }
5155
+
5156
+ export const $: Shell;
5157
+
4977
5158
  interface TOML {
4978
5159
  /**
4979
5160
  * Parse a TOML string into a JavaScript object.
@@ -8877,8 +9058,8 @@ declare module "bun" {
8877
9058
  type ReadableToIO<X extends Readable> = X extends "pipe" | undefined
8878
9059
  ? ReadableStream<Uint8Array>
8879
9060
  : X extends BunFile | ArrayBufferView | number
8880
- ? number
8881
- : undefined;
9061
+ ? number
9062
+ : undefined;
8882
9063
 
8883
9064
  type ReadableToSyncIO<X extends Readable> = X extends "pipe" | undefined
8884
9065
  ? Buffer
@@ -8889,8 +9070,8 @@ declare module "bun" {
8889
9070
  type WritableToIO<X extends Writable> = X extends "pipe"
8890
9071
  ? FileSink
8891
9072
  : X extends BunFile | ArrayBufferView | Blob | Request | Response | number
8892
- ? number
8893
- : undefined;
9073
+ ? number
9074
+ : undefined;
8894
9075
  }
8895
9076
 
8896
9077
  interface ResourceUsage {
@@ -11672,8 +11853,8 @@ declare namespace JestMock {
11672
11853
  export type Spied<T extends ClassLike | FunctionLike> = T extends ClassLike
11673
11854
  ? SpiedClass<T>
11674
11855
  : T extends FunctionLike
11675
- ? SpiedFunction<T>
11676
- : never;
11856
+ ? SpiedFunction<T>
11857
+ : never;
11677
11858
 
11678
11859
  export type SpiedClass<T extends ClassLike = UnknownClass> = MockInstance<
11679
11860
  (...args: ConstructorParameters<T>) => InstanceType<T>
@@ -11714,8 +11895,8 @@ declare namespace JestMock {
11714
11895
  ): A extends "get"
11715
11896
  ? SpiedGetter<V>
11716
11897
  : A extends "set"
11717
- ? SpiedSetter<V>
11718
- : never;
11898
+ ? SpiedSetter<V>
11899
+ : never;
11719
11900
  <
11720
11901
  T_1 extends object,
11721
11902
  K_5 extends