bun-types 1.0.23 → 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 +176 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bun-types",
3
- "version": "1.0.23",
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.23
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
@@ -4980,6 +4980,181 @@ declare module "bun" {
4980
4980
  options?: { PATH?: string; cwd?: string },
4981
4981
  ): string | null;
4982
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
+
4983
5158
  interface TOML {
4984
5159
  /**
4985
5160
  * Parse a TOML string into a JavaScript object.