bun-types-no-globals 1.3.4 → 1.3.6-canary.20260110T140659
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.
- package/lib/bun.d.ts +934 -28
- package/lib/bundle.d.ts +74 -0
- package/lib/globals.d.ts +7 -2
- package/lib/index.d.ts +1 -0
- package/lib/overrides.d.ts +16 -2
- package/lib/s3.d.ts +42 -0
- package/lib/sqlite.d.ts +17 -16
- package/lib/test.d.ts +10 -8
- package/package.json +1 -1
package/lib/bun.d.ts
CHANGED
|
@@ -625,6 +625,33 @@ declare module "bun" {
|
|
|
625
625
|
export function parse(input: string): object;
|
|
626
626
|
}
|
|
627
627
|
|
|
628
|
+
/**
|
|
629
|
+
* JSONC related APIs
|
|
630
|
+
*/
|
|
631
|
+
namespace JSONC {
|
|
632
|
+
/**
|
|
633
|
+
* Parse a JSONC (JSON with Comments) string into a JavaScript value.
|
|
634
|
+
*
|
|
635
|
+
* Supports both single-line (`//`) and block comments (`/* ... *\/`), as well as
|
|
636
|
+
* trailing commas in objects and arrays.
|
|
637
|
+
*
|
|
638
|
+
* @category Utilities
|
|
639
|
+
*
|
|
640
|
+
* @param input The JSONC string to parse
|
|
641
|
+
* @returns A JavaScript value
|
|
642
|
+
*
|
|
643
|
+
* @example
|
|
644
|
+
* ```js
|
|
645
|
+
* const result = Bun.JSONC.parse(`{
|
|
646
|
+
* // This is a comment
|
|
647
|
+
* "name": "my-app",
|
|
648
|
+
* "version": "1.0.0", // trailing comma is allowed
|
|
649
|
+
* }`);
|
|
650
|
+
* ```
|
|
651
|
+
*/
|
|
652
|
+
export function parse(input: string): unknown;
|
|
653
|
+
}
|
|
654
|
+
|
|
628
655
|
/**
|
|
629
656
|
* YAML related APIs
|
|
630
657
|
*/
|
|
@@ -815,6 +842,20 @@ declare module "bun" {
|
|
|
815
842
|
destination: BunFile,
|
|
816
843
|
input: BunFile,
|
|
817
844
|
options?: {
|
|
845
|
+
/**
|
|
846
|
+
* Set the file permissions of the destination when it is created or overwritten.
|
|
847
|
+
*
|
|
848
|
+
* Must be a valid Unix permission mode (0 to 0o777 / 511 in decimal).
|
|
849
|
+
* If omitted, defaults to the system default based on umask (typically 0o644).
|
|
850
|
+
*
|
|
851
|
+
* @throws {RangeError} If the mode is outside the valid range (0 to 0o777).
|
|
852
|
+
*
|
|
853
|
+
* @example
|
|
854
|
+
* ```ts
|
|
855
|
+
* await Bun.write(Bun.file("./secret.txt"), Bun.file("./source.txt"), { mode: 0o600 });
|
|
856
|
+
* ```
|
|
857
|
+
*/
|
|
858
|
+
mode?: number;
|
|
818
859
|
/**
|
|
819
860
|
* If `true`, create the parent directory if it doesn't exist. By default, this is `true`.
|
|
820
861
|
*
|
|
@@ -848,6 +889,20 @@ declare module "bun" {
|
|
|
848
889
|
destinationPath: PathLike,
|
|
849
890
|
input: BunFile,
|
|
850
891
|
options?: {
|
|
892
|
+
/**
|
|
893
|
+
* Set the file permissions of the destination when it is created or overwritten.
|
|
894
|
+
*
|
|
895
|
+
* Must be a valid Unix permission mode (0 to 0o777 / 511 in decimal).
|
|
896
|
+
* If omitted, defaults to the system default based on umask (typically 0o644).
|
|
897
|
+
*
|
|
898
|
+
* @throws {RangeError} If the mode is outside the valid range (0 to 0o777).
|
|
899
|
+
*
|
|
900
|
+
* @example
|
|
901
|
+
* ```ts
|
|
902
|
+
* await Bun.write("./secret.txt", Bun.file("./source.txt"), { mode: 0o600 });
|
|
903
|
+
* ```
|
|
904
|
+
*/
|
|
905
|
+
mode?: number;
|
|
851
906
|
/**
|
|
852
907
|
* If `true`, create the parent directory if it doesn't exist. By default, this is `true`.
|
|
853
908
|
*
|
|
@@ -1740,9 +1795,9 @@ declare module "bun" {
|
|
|
1740
1795
|
* @default "esm"
|
|
1741
1796
|
*/
|
|
1742
1797
|
format?: /**
|
|
1743
|
-
|
|
1744
|
-
|
|
1745
|
-
|
|
1798
|
+
* ECMAScript Module format
|
|
1799
|
+
*/
|
|
1800
|
+
| "esm"
|
|
1746
1801
|
/**
|
|
1747
1802
|
* CommonJS format
|
|
1748
1803
|
* **Experimental**
|
|
@@ -1891,6 +1946,24 @@ declare module "bun" {
|
|
|
1891
1946
|
*/
|
|
1892
1947
|
drop?: string[];
|
|
1893
1948
|
|
|
1949
|
+
/**
|
|
1950
|
+
* Enable feature flags for dead-code elimination via `import { feature } from "bun:bundle"`.
|
|
1951
|
+
*
|
|
1952
|
+
* When `feature("FLAG_NAME")` is called, it returns `true` if FLAG_NAME is in this array,
|
|
1953
|
+
* or `false` otherwise. This enables static dead-code elimination at bundle time.
|
|
1954
|
+
*
|
|
1955
|
+
* Equivalent to the CLI `--feature` flag.
|
|
1956
|
+
*
|
|
1957
|
+
* @example
|
|
1958
|
+
* ```ts
|
|
1959
|
+
* await Bun.build({
|
|
1960
|
+
* entrypoints: ['./src/index.ts'],
|
|
1961
|
+
* features: ['FEATURE_A', 'FEATURE_B'],
|
|
1962
|
+
* });
|
|
1963
|
+
* ```
|
|
1964
|
+
*/
|
|
1965
|
+
features?: string[];
|
|
1966
|
+
|
|
1894
1967
|
/**
|
|
1895
1968
|
* - When set to `true`, the returned promise rejects with an AggregateError when a build failure happens.
|
|
1896
1969
|
* - When set to `false`, returns a {@link BuildOutput} with `{success: false}`
|
|
@@ -1924,6 +1997,107 @@ declare module "bun" {
|
|
|
1924
1997
|
development?: boolean;
|
|
1925
1998
|
};
|
|
1926
1999
|
|
|
2000
|
+
/**
|
|
2001
|
+
* Enable React Fast Refresh transform.
|
|
2002
|
+
*
|
|
2003
|
+
* This adds the necessary code transformations for React Fast Refresh (hot module
|
|
2004
|
+
* replacement for React components), but does not emit hot-module code itself.
|
|
2005
|
+
*
|
|
2006
|
+
* @default false
|
|
2007
|
+
*/
|
|
2008
|
+
reactFastRefresh?: boolean;
|
|
2009
|
+
|
|
2010
|
+
/**
|
|
2011
|
+
* A map of file paths to their contents for in-memory bundling.
|
|
2012
|
+
*
|
|
2013
|
+
* This allows you to bundle virtual files that don't exist on disk, or override
|
|
2014
|
+
* the contents of files that do exist on disk. The keys are file paths (which should
|
|
2015
|
+
* match how they're imported) and the values are the file contents.
|
|
2016
|
+
*
|
|
2017
|
+
* File contents can be provided as:
|
|
2018
|
+
* - `string` - The source code as a string
|
|
2019
|
+
* - `Blob` - A Blob containing the source code
|
|
2020
|
+
* - `NodeJS.TypedArray` - A typed array (e.g., `Uint8Array`) containing the source code
|
|
2021
|
+
* - `ArrayBufferLike` - An ArrayBuffer containing the source code
|
|
2022
|
+
*
|
|
2023
|
+
* @example
|
|
2024
|
+
* ```ts
|
|
2025
|
+
* // Bundle entirely from memory (no files on disk needed)
|
|
2026
|
+
* await Bun.build({
|
|
2027
|
+
* entrypoints: ["/app/index.ts"],
|
|
2028
|
+
* files: {
|
|
2029
|
+
* "/app/index.ts": `
|
|
2030
|
+
* import { helper } from "./helper.ts";
|
|
2031
|
+
* console.log(helper());
|
|
2032
|
+
* `,
|
|
2033
|
+
* "/app/helper.ts": `
|
|
2034
|
+
* export function helper() {
|
|
2035
|
+
* return "Hello from memory!";
|
|
2036
|
+
* }
|
|
2037
|
+
* `,
|
|
2038
|
+
* },
|
|
2039
|
+
* });
|
|
2040
|
+
* ```
|
|
2041
|
+
*
|
|
2042
|
+
* @example
|
|
2043
|
+
* ```ts
|
|
2044
|
+
* // Override a file on disk with in-memory contents
|
|
2045
|
+
* await Bun.build({
|
|
2046
|
+
* entrypoints: ["./src/index.ts"],
|
|
2047
|
+
* files: {
|
|
2048
|
+
* // This will be used instead of the actual ./src/config.ts file
|
|
2049
|
+
* "./src/config.ts": `export const API_URL = "https://production.api.com";`,
|
|
2050
|
+
* },
|
|
2051
|
+
* });
|
|
2052
|
+
* ```
|
|
2053
|
+
*
|
|
2054
|
+
* @example
|
|
2055
|
+
* ```ts
|
|
2056
|
+
* // Mix disk files with in-memory files
|
|
2057
|
+
* // Entry point is on disk, but imports a virtual file
|
|
2058
|
+
* await Bun.build({
|
|
2059
|
+
* entrypoints: ["./src/index.ts"], // Real file on disk
|
|
2060
|
+
* files: {
|
|
2061
|
+
* // Virtual file that ./src/index.ts can import via "./generated.ts"
|
|
2062
|
+
* "./src/generated.ts": `export const BUILD_TIME = ${Date.now()};`,
|
|
2063
|
+
* },
|
|
2064
|
+
* });
|
|
2065
|
+
* ```
|
|
2066
|
+
*/
|
|
2067
|
+
files?: Record<string, string | Blob | NodeJS.TypedArray | ArrayBufferLike>;
|
|
2068
|
+
|
|
2069
|
+
/**
|
|
2070
|
+
* Generate a JSON file containing metadata about the build.
|
|
2071
|
+
*
|
|
2072
|
+
* The metafile contains information about inputs, outputs, imports, and exports
|
|
2073
|
+
* which can be used for bundle analysis, visualization, or integration with
|
|
2074
|
+
* other tools.
|
|
2075
|
+
*
|
|
2076
|
+
* When `true`, the metafile JSON string is included in the {@link BuildOutput.metafile} property.
|
|
2077
|
+
*
|
|
2078
|
+
* @default false
|
|
2079
|
+
*
|
|
2080
|
+
* @example
|
|
2081
|
+
* ```ts
|
|
2082
|
+
* const result = await Bun.build({
|
|
2083
|
+
* entrypoints: ['./src/index.ts'],
|
|
2084
|
+
* outdir: './dist',
|
|
2085
|
+
* metafile: true,
|
|
2086
|
+
* });
|
|
2087
|
+
*
|
|
2088
|
+
* // Write metafile to disk for analysis
|
|
2089
|
+
* if (result.metafile) {
|
|
2090
|
+
* await Bun.write('./dist/meta.json', result.metafile);
|
|
2091
|
+
* }
|
|
2092
|
+
*
|
|
2093
|
+
* // Parse and analyze the metafile
|
|
2094
|
+
* const meta = JSON.parse(result.metafile!);
|
|
2095
|
+
* console.log('Input files:', Object.keys(meta.inputs));
|
|
2096
|
+
* console.log('Output files:', Object.keys(meta.outputs));
|
|
2097
|
+
* ```
|
|
2098
|
+
*/
|
|
2099
|
+
metafile?: boolean;
|
|
2100
|
+
|
|
1927
2101
|
outdir?: string;
|
|
1928
2102
|
}
|
|
1929
2103
|
|
|
@@ -1952,6 +2126,26 @@ declare module "bun" {
|
|
|
1952
2126
|
* @default true
|
|
1953
2127
|
*/
|
|
1954
2128
|
autoloadBunfig?: boolean;
|
|
2129
|
+
/**
|
|
2130
|
+
* Whether to autoload tsconfig.json when the standalone executable runs
|
|
2131
|
+
*
|
|
2132
|
+
* Standalone-only: applies only when building/running the standalone executable.
|
|
2133
|
+
*
|
|
2134
|
+
* Equivalent CLI flags: `--compile-autoload-tsconfig`, `--no-compile-autoload-tsconfig`
|
|
2135
|
+
*
|
|
2136
|
+
* @default false
|
|
2137
|
+
*/
|
|
2138
|
+
autoloadTsconfig?: boolean;
|
|
2139
|
+
/**
|
|
2140
|
+
* Whether to autoload package.json when the standalone executable runs
|
|
2141
|
+
*
|
|
2142
|
+
* Standalone-only: applies only when building/running the standalone executable.
|
|
2143
|
+
*
|
|
2144
|
+
* Equivalent CLI flags: `--compile-autoload-package-json`, `--no-compile-autoload-package-json`
|
|
2145
|
+
*
|
|
2146
|
+
* @default false
|
|
2147
|
+
*/
|
|
2148
|
+
autoloadPackageJson?: boolean;
|
|
1955
2149
|
windows?: {
|
|
1956
2150
|
hideConsole?: boolean;
|
|
1957
2151
|
icon?: string;
|
|
@@ -2555,6 +2749,106 @@ declare module "bun" {
|
|
|
2555
2749
|
outputs: BuildArtifact[];
|
|
2556
2750
|
success: boolean;
|
|
2557
2751
|
logs: Array<BuildMessage | ResolveMessage>;
|
|
2752
|
+
/**
|
|
2753
|
+
* Metadata about the build including inputs, outputs, and their relationships.
|
|
2754
|
+
*
|
|
2755
|
+
* Only present when {@link BuildConfig.metafile} is `true`.
|
|
2756
|
+
*
|
|
2757
|
+
* The metafile contains detailed information about:
|
|
2758
|
+
* - **inputs**: All source files that were bundled, their byte sizes, imports, and format
|
|
2759
|
+
* - **outputs**: All generated output files, their byte sizes, which inputs contributed to each output, imports between chunks, and exports
|
|
2760
|
+
*
|
|
2761
|
+
* This can be used for:
|
|
2762
|
+
* - Bundle size analysis and visualization
|
|
2763
|
+
* - Detecting unused code or dependencies
|
|
2764
|
+
* - Understanding the dependency graph
|
|
2765
|
+
* - Integration with bundle analyzer tools
|
|
2766
|
+
*
|
|
2767
|
+
* @example
|
|
2768
|
+
* ```ts
|
|
2769
|
+
* const result = await Bun.build({
|
|
2770
|
+
* entrypoints: ['./src/index.ts'],
|
|
2771
|
+
* outdir: './dist',
|
|
2772
|
+
* metafile: true,
|
|
2773
|
+
* });
|
|
2774
|
+
*
|
|
2775
|
+
* if (result.metafile) {
|
|
2776
|
+
* // Analyze input files
|
|
2777
|
+
* for (const [path, input] of Object.entries(result.metafile.inputs)) {
|
|
2778
|
+
* console.log(`${path}: ${input.bytes} bytes, ${input.imports.length} imports`);
|
|
2779
|
+
* }
|
|
2780
|
+
*
|
|
2781
|
+
* // Analyze output files
|
|
2782
|
+
* for (const [path, output] of Object.entries(result.metafile.outputs)) {
|
|
2783
|
+
* console.log(`${path}: ${output.bytes} bytes`);
|
|
2784
|
+
* for (const [inputPath, info] of Object.entries(output.inputs)) {
|
|
2785
|
+
* console.log(` - ${inputPath}: ${info.bytesInOutput} bytes`);
|
|
2786
|
+
* }
|
|
2787
|
+
* }
|
|
2788
|
+
*
|
|
2789
|
+
* // Write to disk for external analysis tools
|
|
2790
|
+
* await Bun.write('./dist/meta.json', JSON.stringify(result.metafile));
|
|
2791
|
+
* }
|
|
2792
|
+
* ```
|
|
2793
|
+
*/
|
|
2794
|
+
metafile?: BuildMetafile;
|
|
2795
|
+
}
|
|
2796
|
+
|
|
2797
|
+
/**
|
|
2798
|
+
* Metafile structure containing build metadata for analysis.
|
|
2799
|
+
*
|
|
2800
|
+
* @category Bundler
|
|
2801
|
+
*/
|
|
2802
|
+
interface BuildMetafile {
|
|
2803
|
+
/** Information about all input source files */
|
|
2804
|
+
inputs: {
|
|
2805
|
+
[path: string]: {
|
|
2806
|
+
/** Size of the input file in bytes */
|
|
2807
|
+
bytes: number;
|
|
2808
|
+
/** List of imports from this file */
|
|
2809
|
+
imports: Array<{
|
|
2810
|
+
/** Resolved path of the imported file */
|
|
2811
|
+
path: string;
|
|
2812
|
+
/** Type of import statement */
|
|
2813
|
+
kind: ImportKind;
|
|
2814
|
+
/** Original import specifier before resolution (if different from path) */
|
|
2815
|
+
original?: string;
|
|
2816
|
+
/** Whether this import is external to the bundle */
|
|
2817
|
+
external?: boolean;
|
|
2818
|
+
/** Import attributes (e.g., `{ type: "json" }`) */
|
|
2819
|
+
with?: Record<string, string>;
|
|
2820
|
+
}>;
|
|
2821
|
+
/** Module format of the input file */
|
|
2822
|
+
format?: "esm" | "cjs" | "json" | "css";
|
|
2823
|
+
};
|
|
2824
|
+
};
|
|
2825
|
+
/** Information about all output files */
|
|
2826
|
+
outputs: {
|
|
2827
|
+
[path: string]: {
|
|
2828
|
+
/** Size of the output file in bytes */
|
|
2829
|
+
bytes: number;
|
|
2830
|
+
/** Map of input files to their contribution in this output */
|
|
2831
|
+
inputs: {
|
|
2832
|
+
[path: string]: {
|
|
2833
|
+
/** Number of bytes this input contributed to the output */
|
|
2834
|
+
bytesInOutput: number;
|
|
2835
|
+
};
|
|
2836
|
+
};
|
|
2837
|
+
/** List of imports to other chunks */
|
|
2838
|
+
imports: Array<{
|
|
2839
|
+
/** Path to the imported chunk */
|
|
2840
|
+
path: string;
|
|
2841
|
+
/** Type of import */
|
|
2842
|
+
kind: ImportKind;
|
|
2843
|
+
}>;
|
|
2844
|
+
/** List of exported names from this output */
|
|
2845
|
+
exports: string[];
|
|
2846
|
+
/** Entry point path if this output is an entry point */
|
|
2847
|
+
entryPoint?: string;
|
|
2848
|
+
/** Path to the associated CSS bundle (for JS entry points with CSS) */
|
|
2849
|
+
cssBundle?: string;
|
|
2850
|
+
};
|
|
2851
|
+
};
|
|
2558
2852
|
}
|
|
2559
2853
|
|
|
2560
2854
|
/**
|
|
@@ -3024,16 +3318,29 @@ declare module "bun" {
|
|
|
3024
3318
|
|
|
3025
3319
|
type WebSocketOptionsTLS = {
|
|
3026
3320
|
/**
|
|
3027
|
-
* Options for the TLS connection
|
|
3321
|
+
* Options for the TLS connection.
|
|
3322
|
+
*
|
|
3323
|
+
* Supports full TLS configuration including custom CA certificates,
|
|
3324
|
+
* client certificates, and other TLS settings (same as fetch).
|
|
3325
|
+
*
|
|
3326
|
+
* @example
|
|
3327
|
+
* ```ts
|
|
3328
|
+
* // Using BunFile for certificates
|
|
3329
|
+
* const ws = new WebSocket("wss://example.com", {
|
|
3330
|
+
* tls: {
|
|
3331
|
+
* ca: Bun.file("./ca.pem")
|
|
3332
|
+
* }
|
|
3333
|
+
* });
|
|
3334
|
+
*
|
|
3335
|
+
* // Using Buffer
|
|
3336
|
+
* const ws = new WebSocket("wss://example.com", {
|
|
3337
|
+
* tls: {
|
|
3338
|
+
* ca: fs.readFileSync("./ca.pem")
|
|
3339
|
+
* }
|
|
3340
|
+
* });
|
|
3341
|
+
* ```
|
|
3028
3342
|
*/
|
|
3029
|
-
tls?:
|
|
3030
|
-
/**
|
|
3031
|
-
* Whether to reject the connection if the certificate is not valid
|
|
3032
|
-
*
|
|
3033
|
-
* @default true
|
|
3034
|
-
*/
|
|
3035
|
-
rejectUnauthorized?: boolean;
|
|
3036
|
-
};
|
|
3343
|
+
tls?: TLSOptions;
|
|
3037
3344
|
};
|
|
3038
3345
|
|
|
3039
3346
|
type WebSocketOptionsHeaders = {
|
|
@@ -3043,10 +3350,57 @@ declare module "bun" {
|
|
|
3043
3350
|
headers?: import("node:http").OutgoingHttpHeaders;
|
|
3044
3351
|
};
|
|
3045
3352
|
|
|
3353
|
+
type WebSocketOptionsProxy = {
|
|
3354
|
+
/**
|
|
3355
|
+
* HTTP proxy to use for the WebSocket connection.
|
|
3356
|
+
*
|
|
3357
|
+
* Can be a string URL or an object with `url` and optional `headers`.
|
|
3358
|
+
*
|
|
3359
|
+
* @example
|
|
3360
|
+
* ```ts
|
|
3361
|
+
* // String format
|
|
3362
|
+
* const ws = new WebSocket("wss://example.com", {
|
|
3363
|
+
* proxy: "http://proxy.example.com:8080"
|
|
3364
|
+
* });
|
|
3365
|
+
*
|
|
3366
|
+
* // With credentials
|
|
3367
|
+
* const ws = new WebSocket("wss://example.com", {
|
|
3368
|
+
* proxy: "http://user:pass@proxy.example.com:8080"
|
|
3369
|
+
* });
|
|
3370
|
+
*
|
|
3371
|
+
* // Object format with custom headers
|
|
3372
|
+
* const ws = new WebSocket("wss://example.com", {
|
|
3373
|
+
* proxy: {
|
|
3374
|
+
* url: "http://proxy.example.com:8080",
|
|
3375
|
+
* headers: {
|
|
3376
|
+
* "Proxy-Authorization": "Bearer token"
|
|
3377
|
+
* }
|
|
3378
|
+
* }
|
|
3379
|
+
* });
|
|
3380
|
+
* ```
|
|
3381
|
+
*/
|
|
3382
|
+
proxy?:
|
|
3383
|
+
| string
|
|
3384
|
+
| {
|
|
3385
|
+
/**
|
|
3386
|
+
* The proxy URL (http:// or https://)
|
|
3387
|
+
*/
|
|
3388
|
+
url: string;
|
|
3389
|
+
/**
|
|
3390
|
+
* Custom headers to send to the proxy server.
|
|
3391
|
+
* Supports plain objects or Headers class instances.
|
|
3392
|
+
*/
|
|
3393
|
+
headers?: import("node:http").OutgoingHttpHeaders | Headers;
|
|
3394
|
+
};
|
|
3395
|
+
};
|
|
3396
|
+
|
|
3046
3397
|
/**
|
|
3047
3398
|
* Constructor options for the `Bun.WebSocket` client
|
|
3048
3399
|
*/
|
|
3049
|
-
type WebSocketOptions = WebSocketOptionsProtocolsOrProtocol &
|
|
3400
|
+
type WebSocketOptions = WebSocketOptionsProtocolsOrProtocol &
|
|
3401
|
+
WebSocketOptionsTLS &
|
|
3402
|
+
WebSocketOptionsHeaders &
|
|
3403
|
+
WebSocketOptionsProxy;
|
|
3050
3404
|
|
|
3051
3405
|
interface WebSocketEventMap {
|
|
3052
3406
|
close: CloseEvent;
|
|
@@ -3316,10 +3670,10 @@ declare module "bun" {
|
|
|
3316
3670
|
function color(
|
|
3317
3671
|
input: ColorInput,
|
|
3318
3672
|
outputFormat?: /**
|
|
3319
|
-
|
|
3320
|
-
|
|
3321
|
-
|
|
3322
|
-
|
|
3673
|
+
* True color ANSI color string, for use in terminals
|
|
3674
|
+
* @example \x1b[38;2;100;200;200m
|
|
3675
|
+
*/
|
|
3676
|
+
| "ansi"
|
|
3323
3677
|
| "ansi-16"
|
|
3324
3678
|
| "ansi-16m"
|
|
3325
3679
|
/**
|
|
@@ -3887,6 +4241,9 @@ declare module "bun" {
|
|
|
3887
4241
|
static readonly byteLength: 32;
|
|
3888
4242
|
}
|
|
3889
4243
|
|
|
4244
|
+
/** Extends the standard web formats with `brotli` and `zstd` support. */
|
|
4245
|
+
type CompressionFormat = "gzip" | "deflate" | "deflate-raw" | "brotli" | "zstd";
|
|
4246
|
+
|
|
3890
4247
|
/** Compression options for `Bun.deflateSync` and `Bun.gzipSync` */
|
|
3891
4248
|
interface ZlibCompressionOptions {
|
|
3892
4249
|
/**
|
|
@@ -5287,6 +5644,67 @@ declare module "bun" {
|
|
|
5287
5644
|
ref(): void;
|
|
5288
5645
|
unref(): void;
|
|
5289
5646
|
close(): void;
|
|
5647
|
+
/**
|
|
5648
|
+
* Enable or disable SO_BROADCAST socket option.
|
|
5649
|
+
* @param enabled Whether to enable broadcast
|
|
5650
|
+
* @returns The enabled value
|
|
5651
|
+
*/
|
|
5652
|
+
setBroadcast(enabled: boolean): boolean;
|
|
5653
|
+
/**
|
|
5654
|
+
* Set the IP_TTL socket option.
|
|
5655
|
+
* @param ttl Time to live value
|
|
5656
|
+
* @returns The TTL value
|
|
5657
|
+
*/
|
|
5658
|
+
setTTL(ttl: number): number;
|
|
5659
|
+
/**
|
|
5660
|
+
* Set the IP_MULTICAST_TTL socket option.
|
|
5661
|
+
* @param ttl Time to live value for multicast packets
|
|
5662
|
+
* @returns The TTL value
|
|
5663
|
+
*/
|
|
5664
|
+
setMulticastTTL(ttl: number): number;
|
|
5665
|
+
/**
|
|
5666
|
+
* Enable or disable IP_MULTICAST_LOOP socket option.
|
|
5667
|
+
* @param enabled Whether to enable multicast loopback
|
|
5668
|
+
* @returns The enabled value
|
|
5669
|
+
*/
|
|
5670
|
+
setMulticastLoopback(enabled: boolean): boolean;
|
|
5671
|
+
/**
|
|
5672
|
+
* Set the IP_MULTICAST_IF socket option to specify the outgoing interface
|
|
5673
|
+
* for multicast packets.
|
|
5674
|
+
* @param interfaceAddress The address of the interface to use
|
|
5675
|
+
* @returns true on success
|
|
5676
|
+
*/
|
|
5677
|
+
setMulticastInterface(interfaceAddress: string): boolean;
|
|
5678
|
+
/**
|
|
5679
|
+
* Join a multicast group.
|
|
5680
|
+
* @param multicastAddress The multicast group address
|
|
5681
|
+
* @param interfaceAddress Optional interface address to use
|
|
5682
|
+
* @returns true on success
|
|
5683
|
+
*/
|
|
5684
|
+
addMembership(multicastAddress: string, interfaceAddress?: string): boolean;
|
|
5685
|
+
/**
|
|
5686
|
+
* Leave a multicast group.
|
|
5687
|
+
* @param multicastAddress The multicast group address
|
|
5688
|
+
* @param interfaceAddress Optional interface address to use
|
|
5689
|
+
* @returns true on success
|
|
5690
|
+
*/
|
|
5691
|
+
dropMembership(multicastAddress: string, interfaceAddress?: string): boolean;
|
|
5692
|
+
/**
|
|
5693
|
+
* Join a source-specific multicast group.
|
|
5694
|
+
* @param sourceAddress The source address
|
|
5695
|
+
* @param groupAddress The multicast group address
|
|
5696
|
+
* @param interfaceAddress Optional interface address to use
|
|
5697
|
+
* @returns true on success
|
|
5698
|
+
*/
|
|
5699
|
+
addSourceSpecificMembership(sourceAddress: string, groupAddress: string, interfaceAddress?: string): boolean;
|
|
5700
|
+
/**
|
|
5701
|
+
* Leave a source-specific multicast group.
|
|
5702
|
+
* @param sourceAddress The source address
|
|
5703
|
+
* @param groupAddress The multicast group address
|
|
5704
|
+
* @param interfaceAddress Optional interface address to use
|
|
5705
|
+
* @returns true on success
|
|
5706
|
+
*/
|
|
5707
|
+
dropSourceSpecificMembership(sourceAddress: string, groupAddress: string, interfaceAddress?: string): boolean;
|
|
5290
5708
|
}
|
|
5291
5709
|
|
|
5292
5710
|
export interface ConnectedSocket<DataBinaryType extends BinaryType> extends BaseUDPSocket {
|
|
@@ -5650,17 +6068,11 @@ declare module "bun" {
|
|
|
5650
6068
|
maxBuffer?: number;
|
|
5651
6069
|
}
|
|
5652
6070
|
|
|
5653
|
-
interface SpawnSyncOptions<In extends Writable, Out extends Readable, Err extends Readable>
|
|
5654
|
-
In,
|
|
5655
|
-
|
|
5656
|
-
|
|
5657
|
-
|
|
5658
|
-
|
|
5659
|
-
interface SpawnOptions<In extends Writable, Out extends Readable, Err extends Readable> extends BaseOptions<
|
|
5660
|
-
In,
|
|
5661
|
-
Out,
|
|
5662
|
-
Err
|
|
5663
|
-
> {
|
|
6071
|
+
interface SpawnSyncOptions<In extends Writable, Out extends Readable, Err extends Readable>
|
|
6072
|
+
extends BaseOptions<In, Out, Err> {}
|
|
6073
|
+
|
|
6074
|
+
interface SpawnOptions<In extends Writable, Out extends Readable, Err extends Readable>
|
|
6075
|
+
extends BaseOptions<In, Out, Err> {
|
|
5664
6076
|
/**
|
|
5665
6077
|
* If true, stdout and stderr pipes will not automatically start reading
|
|
5666
6078
|
* data. Reading will only begin when you access the `stdout` or `stderr`
|
|
@@ -5682,6 +6094,44 @@ declare module "bun" {
|
|
|
5682
6094
|
* ```
|
|
5683
6095
|
*/
|
|
5684
6096
|
lazy?: boolean;
|
|
6097
|
+
|
|
6098
|
+
/**
|
|
6099
|
+
* Spawn the subprocess with a pseudo-terminal (PTY) attached.
|
|
6100
|
+
*
|
|
6101
|
+
* When this option is provided:
|
|
6102
|
+
* - `stdin`, `stdout`, and `stderr` are all connected to the terminal
|
|
6103
|
+
* - The subprocess sees itself running in a real terminal (`isTTY = true`)
|
|
6104
|
+
* - Access the terminal via `subprocess.terminal`
|
|
6105
|
+
* - `subprocess.stdin`, `subprocess.stdout`, `subprocess.stderr` return `null`
|
|
6106
|
+
*
|
|
6107
|
+
* Only available on POSIX systems (Linux, macOS).
|
|
6108
|
+
*
|
|
6109
|
+
* @example
|
|
6110
|
+
* ```ts
|
|
6111
|
+
* const proc = Bun.spawn(["bash"], {
|
|
6112
|
+
* terminal: {
|
|
6113
|
+
* cols: 80,
|
|
6114
|
+
* rows: 24,
|
|
6115
|
+
* data: (term, data) => console.log(data.toString()),
|
|
6116
|
+
* },
|
|
6117
|
+
* });
|
|
6118
|
+
*
|
|
6119
|
+
* proc.terminal.write("echo hello\n");
|
|
6120
|
+
* await proc.exited;
|
|
6121
|
+
* proc.terminal.close();
|
|
6122
|
+
* ```
|
|
6123
|
+
*
|
|
6124
|
+
* You can also pass an existing `Terminal` object for reuse across multiple spawns:
|
|
6125
|
+
* ```ts
|
|
6126
|
+
* const terminal = new Bun.Terminal({ ... });
|
|
6127
|
+
* const proc1 = Bun.spawn(["echo", "first"], { terminal });
|
|
6128
|
+
* await proc1.exited;
|
|
6129
|
+
* const proc2 = Bun.spawn(["echo", "second"], { terminal });
|
|
6130
|
+
* await proc2.exited;
|
|
6131
|
+
* terminal.close();
|
|
6132
|
+
* ```
|
|
6133
|
+
*/
|
|
6134
|
+
terminal?: TerminalOptions | Terminal;
|
|
5685
6135
|
}
|
|
5686
6136
|
|
|
5687
6137
|
type ReadableToIO<X extends Readable> = X extends "pipe" | undefined
|
|
@@ -5796,6 +6246,24 @@ declare module "bun" {
|
|
|
5796
6246
|
readonly stdout: SpawnOptions.ReadableToIO<Out>;
|
|
5797
6247
|
readonly stderr: SpawnOptions.ReadableToIO<Err>;
|
|
5798
6248
|
|
|
6249
|
+
/**
|
|
6250
|
+
* The terminal attached to this subprocess, if spawned with the `terminal` option.
|
|
6251
|
+
* Returns `undefined` if no terminal was attached.
|
|
6252
|
+
*
|
|
6253
|
+
* When a terminal is attached, `stdin`, `stdout`, and `stderr` return `null`.
|
|
6254
|
+
* Use `terminal.write()` and the `data` callback instead.
|
|
6255
|
+
*
|
|
6256
|
+
* @example
|
|
6257
|
+
* ```ts
|
|
6258
|
+
* const proc = Bun.spawn(["bash"], {
|
|
6259
|
+
* terminal: { data: (term, data) => console.log(data.toString()) },
|
|
6260
|
+
* });
|
|
6261
|
+
*
|
|
6262
|
+
* proc.terminal?.write("echo hello\n");
|
|
6263
|
+
* ```
|
|
6264
|
+
*/
|
|
6265
|
+
readonly terminal: Terminal | undefined;
|
|
6266
|
+
|
|
5799
6267
|
/**
|
|
5800
6268
|
* Access extra file descriptors passed to the `stdio` option in the options object.
|
|
5801
6269
|
*/
|
|
@@ -6087,6 +6555,154 @@ declare module "bun" {
|
|
|
6087
6555
|
"ignore" | "inherit" | null | undefined
|
|
6088
6556
|
>;
|
|
6089
6557
|
|
|
6558
|
+
/**
|
|
6559
|
+
* Options for creating a pseudo-terminal (PTY).
|
|
6560
|
+
*/
|
|
6561
|
+
interface TerminalOptions {
|
|
6562
|
+
/**
|
|
6563
|
+
* Number of columns for the terminal.
|
|
6564
|
+
* @default 80
|
|
6565
|
+
*/
|
|
6566
|
+
cols?: number;
|
|
6567
|
+
/**
|
|
6568
|
+
* Number of rows for the terminal.
|
|
6569
|
+
* @default 24
|
|
6570
|
+
*/
|
|
6571
|
+
rows?: number;
|
|
6572
|
+
/**
|
|
6573
|
+
* Terminal name (e.g., "xterm-256color").
|
|
6574
|
+
* @default "xterm-256color"
|
|
6575
|
+
*/
|
|
6576
|
+
name?: string;
|
|
6577
|
+
/**
|
|
6578
|
+
* Callback invoked when data is received from the terminal.
|
|
6579
|
+
* @param terminal The terminal instance
|
|
6580
|
+
* @param data The data received as a Uint8Array
|
|
6581
|
+
*/
|
|
6582
|
+
data?: (terminal: Terminal, data: Uint8Array<ArrayBuffer>) => void;
|
|
6583
|
+
/**
|
|
6584
|
+
* Callback invoked when the PTY stream closes (EOF or read error).
|
|
6585
|
+
* Note: exitCode is a PTY lifecycle status (0=clean EOF, 1=error), NOT the subprocess exit code.
|
|
6586
|
+
* Use Subprocess.exited or onExit callback for actual process exit information.
|
|
6587
|
+
* @param terminal The terminal instance
|
|
6588
|
+
* @param exitCode PTY lifecycle status (0 for EOF, 1 for error)
|
|
6589
|
+
* @param signal Reserved for future signal reporting, currently null
|
|
6590
|
+
*/
|
|
6591
|
+
exit?: (terminal: Terminal, exitCode: number, signal: string | null) => void;
|
|
6592
|
+
/**
|
|
6593
|
+
* Callback invoked when the terminal is ready to receive more data.
|
|
6594
|
+
* @param terminal The terminal instance
|
|
6595
|
+
*/
|
|
6596
|
+
drain?: (terminal: Terminal) => void;
|
|
6597
|
+
}
|
|
6598
|
+
|
|
6599
|
+
/**
|
|
6600
|
+
* A pseudo-terminal (PTY) that can be used to spawn interactive terminal programs.
|
|
6601
|
+
*
|
|
6602
|
+
* @example
|
|
6603
|
+
* ```ts
|
|
6604
|
+
* await using terminal = new Bun.Terminal({
|
|
6605
|
+
* cols: 80,
|
|
6606
|
+
* rows: 24,
|
|
6607
|
+
* data(term, data) {
|
|
6608
|
+
* console.log("Received:", new TextDecoder().decode(data));
|
|
6609
|
+
* },
|
|
6610
|
+
* });
|
|
6611
|
+
*
|
|
6612
|
+
* // Spawn a shell connected to the PTY
|
|
6613
|
+
* const proc = Bun.spawn(["bash"], { terminal });
|
|
6614
|
+
*
|
|
6615
|
+
* // Write to the terminal
|
|
6616
|
+
* terminal.write("echo hello\n");
|
|
6617
|
+
*
|
|
6618
|
+
* // Wait for process to exit
|
|
6619
|
+
* await proc.exited;
|
|
6620
|
+
*
|
|
6621
|
+
* // Terminal is closed automatically by `await using`
|
|
6622
|
+
* ```
|
|
6623
|
+
*/
|
|
6624
|
+
class Terminal implements AsyncDisposable {
|
|
6625
|
+
constructor(options: TerminalOptions);
|
|
6626
|
+
|
|
6627
|
+
/**
|
|
6628
|
+
* Whether the terminal is closed.
|
|
6629
|
+
*/
|
|
6630
|
+
readonly closed: boolean;
|
|
6631
|
+
|
|
6632
|
+
/**
|
|
6633
|
+
* Write data to the terminal.
|
|
6634
|
+
* @param data The data to write (string or BufferSource)
|
|
6635
|
+
* @returns The number of bytes written
|
|
6636
|
+
*/
|
|
6637
|
+
write(data: string | BufferSource): number;
|
|
6638
|
+
|
|
6639
|
+
/**
|
|
6640
|
+
* Resize the terminal.
|
|
6641
|
+
* @param cols New number of columns
|
|
6642
|
+
* @param rows New number of rows
|
|
6643
|
+
*/
|
|
6644
|
+
resize(cols: number, rows: number): void;
|
|
6645
|
+
|
|
6646
|
+
/**
|
|
6647
|
+
* Set raw mode on the terminal.
|
|
6648
|
+
* In raw mode, input is passed directly without processing.
|
|
6649
|
+
* @param enabled Whether to enable raw mode
|
|
6650
|
+
*/
|
|
6651
|
+
setRawMode(enabled: boolean): void;
|
|
6652
|
+
|
|
6653
|
+
/**
|
|
6654
|
+
* Reference the terminal to keep the event loop alive.
|
|
6655
|
+
*/
|
|
6656
|
+
ref(): void;
|
|
6657
|
+
|
|
6658
|
+
/**
|
|
6659
|
+
* Unreference the terminal to allow the event loop to exit.
|
|
6660
|
+
*/
|
|
6661
|
+
unref(): void;
|
|
6662
|
+
|
|
6663
|
+
/**
|
|
6664
|
+
* Close the terminal.
|
|
6665
|
+
*/
|
|
6666
|
+
close(): void;
|
|
6667
|
+
|
|
6668
|
+
/**
|
|
6669
|
+
* Async dispose for use with `await using`.
|
|
6670
|
+
*/
|
|
6671
|
+
[Symbol.asyncDispose](): Promise<void>;
|
|
6672
|
+
|
|
6673
|
+
/**
|
|
6674
|
+
* Terminal input flags (c_iflag from termios).
|
|
6675
|
+
* Controls input processing behavior like ICRNL, IXON, etc.
|
|
6676
|
+
* Returns 0 if terminal is closed.
|
|
6677
|
+
* Setting returns true on success, false on failure.
|
|
6678
|
+
*/
|
|
6679
|
+
inputFlags: number;
|
|
6680
|
+
|
|
6681
|
+
/**
|
|
6682
|
+
* Terminal output flags (c_oflag from termios).
|
|
6683
|
+
* Controls output processing behavior like OPOST, ONLCR, etc.
|
|
6684
|
+
* Returns 0 if terminal is closed.
|
|
6685
|
+
* Setting returns true on success, false on failure.
|
|
6686
|
+
*/
|
|
6687
|
+
outputFlags: number;
|
|
6688
|
+
|
|
6689
|
+
/**
|
|
6690
|
+
* Terminal local flags (c_lflag from termios).
|
|
6691
|
+
* Controls local processing like ICANON, ECHO, ISIG, etc.
|
|
6692
|
+
* Returns 0 if terminal is closed.
|
|
6693
|
+
* Setting returns true on success, false on failure.
|
|
6694
|
+
*/
|
|
6695
|
+
localFlags: number;
|
|
6696
|
+
|
|
6697
|
+
/**
|
|
6698
|
+
* Terminal control flags (c_cflag from termios).
|
|
6699
|
+
* Controls hardware characteristics like CSIZE, PARENB, etc.
|
|
6700
|
+
* Returns 0 if terminal is closed.
|
|
6701
|
+
* Setting returns true on success, false on failure.
|
|
6702
|
+
*/
|
|
6703
|
+
controlFlags: number;
|
|
6704
|
+
}
|
|
6705
|
+
|
|
6090
6706
|
// Blocked on https://github.com/oven-sh/bun/issues/8329
|
|
6091
6707
|
// /**
|
|
6092
6708
|
// *
|
|
@@ -6349,6 +6965,296 @@ declare module "bun" {
|
|
|
6349
6965
|
match(str: string): boolean;
|
|
6350
6966
|
}
|
|
6351
6967
|
|
|
6968
|
+
/**
|
|
6969
|
+
* Input data for creating an archive. Can be:
|
|
6970
|
+
* - An object mapping paths to file contents (string, Blob, TypedArray, or ArrayBuffer)
|
|
6971
|
+
* - A Blob containing existing archive data
|
|
6972
|
+
* - A TypedArray or ArrayBuffer containing existing archive data
|
|
6973
|
+
*/
|
|
6974
|
+
type ArchiveInput = Record<string, BlobPart> | Blob | ArrayBufferView | ArrayBufferLike;
|
|
6975
|
+
|
|
6976
|
+
/**
|
|
6977
|
+
* Compression format for archive output.
|
|
6978
|
+
* - `"gzip"` - Compress with gzip
|
|
6979
|
+
* - `true` - Same as `"gzip"`
|
|
6980
|
+
* - `false` - Explicitly disable compression (no compression)
|
|
6981
|
+
* - `undefined` - No compression (default behavior when omitted)
|
|
6982
|
+
*
|
|
6983
|
+
* Both `false` and `undefined` result in no compression; `false` can be used
|
|
6984
|
+
* to explicitly indicate "no compression" in code where the intent should be clear.
|
|
6985
|
+
*/
|
|
6986
|
+
type ArchiveCompression = "gzip" | boolean;
|
|
6987
|
+
|
|
6988
|
+
/**
|
|
6989
|
+
* Options for extracting archive contents.
|
|
6990
|
+
*/
|
|
6991
|
+
interface ArchiveExtractOptions {
|
|
6992
|
+
/**
|
|
6993
|
+
* Glob pattern(s) to filter which entries are extracted.
|
|
6994
|
+
* Uses the same syntax as {@link Bun.Glob}, including support for wildcards (`*`, `**`),
|
|
6995
|
+
* character classes (`[abc]`), alternation (`{a,b}`), and negation (`!pattern`).
|
|
6996
|
+
*
|
|
6997
|
+
* Patterns are matched against archive entry paths normalized to use forward slashes (`/`),
|
|
6998
|
+
* regardless of the host operating system. Always write patterns using `/` as the separator.
|
|
6999
|
+
*
|
|
7000
|
+
* - Positive patterns: Only entries matching at least one pattern will be extracted.
|
|
7001
|
+
* - Negative patterns (prefixed with `!`): Entries matching these patterns will be excluded.
|
|
7002
|
+
* Negative patterns are applied after positive patterns.
|
|
7003
|
+
*
|
|
7004
|
+
* If not specified, all entries are extracted.
|
|
7005
|
+
*
|
|
7006
|
+
* @example
|
|
7007
|
+
* ```ts
|
|
7008
|
+
* // Extract only TypeScript files
|
|
7009
|
+
* await archive.extract("./out", { glob: "**" + "/*.ts" });
|
|
7010
|
+
*
|
|
7011
|
+
* // Extract files from multiple directories
|
|
7012
|
+
* await archive.extract("./out", { glob: ["src/**", "lib/**"] });
|
|
7013
|
+
*
|
|
7014
|
+
* // Exclude node_modules using negative pattern
|
|
7015
|
+
* await archive.extract("./out", { glob: ["**", "!node_modules/**"] });
|
|
7016
|
+
*
|
|
7017
|
+
* // Extract source files but exclude tests
|
|
7018
|
+
* await archive.extract("./out", { glob: ["src/**", "!**" + "/*.test.ts"] });
|
|
7019
|
+
* ```
|
|
7020
|
+
*/
|
|
7021
|
+
glob?: string | readonly string[];
|
|
7022
|
+
}
|
|
7023
|
+
|
|
7024
|
+
/**
|
|
7025
|
+
* A class for creating and extracting tar archives with optional gzip compression.
|
|
7026
|
+
*
|
|
7027
|
+
* `Bun.Archive` provides a fast, native implementation for working with tar archives.
|
|
7028
|
+
* It supports creating archives from in-memory data or extracting existing archives
|
|
7029
|
+
* to disk or memory.
|
|
7030
|
+
*
|
|
7031
|
+
* @example
|
|
7032
|
+
* **Create an archive from an object:**
|
|
7033
|
+
* ```ts
|
|
7034
|
+
* const archive = Bun.Archive.from({
|
|
7035
|
+
* "hello.txt": "Hello, World!",
|
|
7036
|
+
* "data.json": JSON.stringify({ foo: "bar" }),
|
|
7037
|
+
* "binary.bin": new Uint8Array([1, 2, 3, 4]),
|
|
7038
|
+
* });
|
|
7039
|
+
* ```
|
|
7040
|
+
*
|
|
7041
|
+
* @example
|
|
7042
|
+
* **Extract an archive to disk:**
|
|
7043
|
+
* ```ts
|
|
7044
|
+
* const archive = Bun.Archive.from(tarballBytes);
|
|
7045
|
+
* const entryCount = await archive.extract("./output");
|
|
7046
|
+
* console.log(`Extracted ${entryCount} entries`);
|
|
7047
|
+
* ```
|
|
7048
|
+
*
|
|
7049
|
+
* @example
|
|
7050
|
+
* **Get archive contents as a Map of File objects:**
|
|
7051
|
+
* ```ts
|
|
7052
|
+
* const archive = Bun.Archive.from(tarballBytes);
|
|
7053
|
+
* const entries = await archive.files();
|
|
7054
|
+
* for (const [path, file] of entries) {
|
|
7055
|
+
* console.log(path, await file.text());
|
|
7056
|
+
* }
|
|
7057
|
+
* ```
|
|
7058
|
+
*
|
|
7059
|
+
* @example
|
|
7060
|
+
* **Write a gzipped archive directly to disk:**
|
|
7061
|
+
* ```ts
|
|
7062
|
+
* await Bun.Archive.write("bundle.tar.gz", {
|
|
7063
|
+
* "src/index.ts": sourceCode,
|
|
7064
|
+
* "package.json": packageJson,
|
|
7065
|
+
* }, "gzip");
|
|
7066
|
+
* ```
|
|
7067
|
+
*/
|
|
7068
|
+
export class Archive {
|
|
7069
|
+
/**
|
|
7070
|
+
* Create an `Archive` instance from input data.
|
|
7071
|
+
*
|
|
7072
|
+
* @param data - The input data for the archive:
|
|
7073
|
+
* - **Object**: Creates a new tarball with the object's keys as file paths and values as file contents
|
|
7074
|
+
* - **Blob/TypedArray/ArrayBuffer**: Wraps existing archive data (tar or tar.gz)
|
|
7075
|
+
*
|
|
7076
|
+
* @returns A new `Archive` instance
|
|
7077
|
+
*
|
|
7078
|
+
* @example
|
|
7079
|
+
* **From an object (creates new tarball):**
|
|
7080
|
+
* ```ts
|
|
7081
|
+
* const archive = Bun.Archive.from({
|
|
7082
|
+
* "hello.txt": "Hello, World!",
|
|
7083
|
+
* "nested/file.txt": "Nested content",
|
|
7084
|
+
* });
|
|
7085
|
+
* ```
|
|
7086
|
+
*
|
|
7087
|
+
* @example
|
|
7088
|
+
* **From existing archive data:**
|
|
7089
|
+
* ```ts
|
|
7090
|
+
* const response = await fetch("https://example.com/package.tar.gz");
|
|
7091
|
+
* const archive = Bun.Archive.from(await response.blob());
|
|
7092
|
+
* ```
|
|
7093
|
+
*/
|
|
7094
|
+
static from(data: ArchiveInput): Archive;
|
|
7095
|
+
|
|
7096
|
+
/**
|
|
7097
|
+
* Create and write an archive directly to disk in one operation.
|
|
7098
|
+
*
|
|
7099
|
+
* This is more efficient than creating an archive and then writing it separately,
|
|
7100
|
+
* as it streams the data directly to disk.
|
|
7101
|
+
*
|
|
7102
|
+
* @param path - The file path to write the archive to
|
|
7103
|
+
* @param data - The input data for the archive (same as `Archive.from()`)
|
|
7104
|
+
* @param compress - Optional compression: `"gzip"`, `true` for gzip, or `false`/`undefined` for none
|
|
7105
|
+
*
|
|
7106
|
+
* @returns A promise that resolves when the write is complete
|
|
7107
|
+
*
|
|
7108
|
+
* @example
|
|
7109
|
+
* **Write uncompressed tarball:**
|
|
7110
|
+
* ```ts
|
|
7111
|
+
* await Bun.Archive.write("output.tar", {
|
|
7112
|
+
* "file1.txt": "content1",
|
|
7113
|
+
* "file2.txt": "content2",
|
|
7114
|
+
* });
|
|
7115
|
+
* ```
|
|
7116
|
+
*
|
|
7117
|
+
* @example
|
|
7118
|
+
* **Write gzipped tarball:**
|
|
7119
|
+
* ```ts
|
|
7120
|
+
* await Bun.Archive.write("output.tar.gz", files, "gzip");
|
|
7121
|
+
* ```
|
|
7122
|
+
*/
|
|
7123
|
+
static write(path: string, data: ArchiveInput | Archive, compress?: ArchiveCompression): Promise<void>;
|
|
7124
|
+
|
|
7125
|
+
/**
|
|
7126
|
+
* Extract the archive contents to a directory on disk.
|
|
7127
|
+
*
|
|
7128
|
+
* Creates the target directory and any necessary parent directories if they don't exist.
|
|
7129
|
+
* Existing files will be overwritten.
|
|
7130
|
+
*
|
|
7131
|
+
* @param path - The directory path to extract to
|
|
7132
|
+
* @param options - Optional extraction options
|
|
7133
|
+
* @param options.glob - Glob pattern(s) to filter entries (positive patterns include, negative patterns starting with `!` exclude)
|
|
7134
|
+
* @returns A promise that resolves with the number of entries extracted (files, directories, and symlinks)
|
|
7135
|
+
*
|
|
7136
|
+
* @example
|
|
7137
|
+
* **Extract all entries:**
|
|
7138
|
+
* ```ts
|
|
7139
|
+
* const archive = Bun.Archive.from(tarballBytes);
|
|
7140
|
+
* const count = await archive.extract("./extracted");
|
|
7141
|
+
* console.log(`Extracted ${count} entries`);
|
|
7142
|
+
* ```
|
|
7143
|
+
*
|
|
7144
|
+
* @example
|
|
7145
|
+
* **Extract only TypeScript files:**
|
|
7146
|
+
* ```ts
|
|
7147
|
+
* const count = await archive.extract("./src", { glob: "**" + "/*.ts" });
|
|
7148
|
+
* ```
|
|
7149
|
+
*
|
|
7150
|
+
* @example
|
|
7151
|
+
* **Extract everything except tests:**
|
|
7152
|
+
* ```ts
|
|
7153
|
+
* const count = await archive.extract("./dist", { glob: ["**", "!**" + "/*.test.*"] });
|
|
7154
|
+
* ```
|
|
7155
|
+
*
|
|
7156
|
+
* @example
|
|
7157
|
+
* **Extract source files but exclude tests:**
|
|
7158
|
+
* ```ts
|
|
7159
|
+
* const count = await archive.extract("./output", {
|
|
7160
|
+
* glob: ["src/**", "lib/**", "!**" + "/*.test.ts", "!**" + "/__tests__/**"]
|
|
7161
|
+
* });
|
|
7162
|
+
* ```
|
|
7163
|
+
*/
|
|
7164
|
+
extract(path: string, options?: ArchiveExtractOptions): Promise<number>;
|
|
7165
|
+
|
|
7166
|
+
/**
|
|
7167
|
+
* Get the archive contents as a `Blob`.
|
|
7168
|
+
*
|
|
7169
|
+
* @param compress - Optional compression: `"gzip"`, `true` for gzip, or `false`/`undefined` for none
|
|
7170
|
+
* @returns A promise that resolves with the archive data as a Blob
|
|
7171
|
+
*
|
|
7172
|
+
* @example
|
|
7173
|
+
* **Get uncompressed tarball:**
|
|
7174
|
+
* ```ts
|
|
7175
|
+
* const blob = await archive.blob();
|
|
7176
|
+
* ```
|
|
7177
|
+
*
|
|
7178
|
+
* @example
|
|
7179
|
+
* **Get gzipped tarball:**
|
|
7180
|
+
* ```ts
|
|
7181
|
+
* const gzippedBlob = await archive.blob("gzip");
|
|
7182
|
+
* ```
|
|
7183
|
+
*/
|
|
7184
|
+
blob(compress?: ArchiveCompression): Promise<Blob>;
|
|
7185
|
+
|
|
7186
|
+
/**
|
|
7187
|
+
* Get the archive contents as a `Uint8Array`.
|
|
7188
|
+
*
|
|
7189
|
+
* @param compress - Optional compression: `"gzip"`, `true` for gzip, or `false`/`undefined` for none
|
|
7190
|
+
* @returns A promise that resolves with the archive data as a Uint8Array
|
|
7191
|
+
*
|
|
7192
|
+
* @example
|
|
7193
|
+
* **Get uncompressed tarball bytes:**
|
|
7194
|
+
* ```ts
|
|
7195
|
+
* const bytes = await archive.bytes();
|
|
7196
|
+
* ```
|
|
7197
|
+
*
|
|
7198
|
+
* @example
|
|
7199
|
+
* **Get gzipped tarball bytes:**
|
|
7200
|
+
* ```ts
|
|
7201
|
+
* const gzippedBytes = await archive.bytes("gzip");
|
|
7202
|
+
* ```
|
|
7203
|
+
*/
|
|
7204
|
+
bytes(compress?: ArchiveCompression): Promise<Uint8Array<ArrayBuffer>>;
|
|
7205
|
+
|
|
7206
|
+
/**
|
|
7207
|
+
* Get the archive contents as a `Map` of `File` objects.
|
|
7208
|
+
*
|
|
7209
|
+
* Each file in the archive is returned as a `File` object with:
|
|
7210
|
+
* - `name`: The file path within the archive
|
|
7211
|
+
* - `lastModified`: The file's modification time from the archive
|
|
7212
|
+
* - Standard Blob methods (`text()`, `arrayBuffer()`, `stream()`, etc.)
|
|
7213
|
+
*
|
|
7214
|
+
* Only regular files are included; directories are not returned.
|
|
7215
|
+
* File contents are loaded into memory, so for large archives consider using `extract()` instead.
|
|
7216
|
+
*
|
|
7217
|
+
* @param glob - Optional glob pattern(s) to filter files. Supports the same syntax as {@link Bun.Glob},
|
|
7218
|
+
* including negation patterns (prefixed with `!`). Patterns are matched against paths normalized
|
|
7219
|
+
* to use forward slashes (`/`).
|
|
7220
|
+
* @returns A promise that resolves with a Map where keys are file paths (always using forward slashes `/` as separators) and values are File objects
|
|
7221
|
+
*
|
|
7222
|
+
* @example
|
|
7223
|
+
* **Get all files:**
|
|
7224
|
+
* ```ts
|
|
7225
|
+
* const entries = await archive.files();
|
|
7226
|
+
* for (const [path, file] of entries) {
|
|
7227
|
+
* console.log(`${path}: ${file.size} bytes`);
|
|
7228
|
+
* }
|
|
7229
|
+
* ```
|
|
7230
|
+
*
|
|
7231
|
+
* @example
|
|
7232
|
+
* **Filter by glob pattern:**
|
|
7233
|
+
* ```ts
|
|
7234
|
+
* const tsFiles = await archive.files("**" + "/*.ts");
|
|
7235
|
+
* const srcFiles = await archive.files(["src/**", "lib/**"]);
|
|
7236
|
+
* ```
|
|
7237
|
+
*
|
|
7238
|
+
* @example
|
|
7239
|
+
* **Exclude files with negative patterns:**
|
|
7240
|
+
* ```ts
|
|
7241
|
+
* // Get all source files except tests
|
|
7242
|
+
* const srcFiles = await archive.files(["src/**", "!**" + "/*.test.ts"]);
|
|
7243
|
+
* ```
|
|
7244
|
+
*
|
|
7245
|
+
* @example
|
|
7246
|
+
* **Read file contents:**
|
|
7247
|
+
* ```ts
|
|
7248
|
+
* const entries = await archive.files();
|
|
7249
|
+
* const readme = entries.get("README.md");
|
|
7250
|
+
* if (readme) {
|
|
7251
|
+
* console.log(await readme.text());
|
|
7252
|
+
* }
|
|
7253
|
+
* ```
|
|
7254
|
+
*/
|
|
7255
|
+
files(glob?: string | readonly string[]): Promise<Map<string, File>>;
|
|
7256
|
+
}
|
|
7257
|
+
|
|
6352
7258
|
/**
|
|
6353
7259
|
* Generate a UUIDv7, which is a sequential ID based on the current timestamp with a random component.
|
|
6354
7260
|
*
|