diff options
author | 2022-04-10 04:30:09 -0700 | |
---|---|---|
committer | 2022-04-10 04:30:09 -0700 | |
commit | ac76e3b004c86255daf79410827fad69c5b60a96 (patch) | |
tree | 3300ac28c525632bf4cea7eed75492a83132f03a | |
parent | 43b18663fdc763c24ae8fa0940019f2aee37c6aa (diff) | |
download | bun-ac76e3b004c86255daf79410827fad69c5b60a96.tar.gz bun-ac76e3b004c86255daf79410827fad69c5b60a96.tar.zst bun-ac76e3b004c86255daf79410827fad69c5b60a96.zip |
Move some types around
-rw-r--r-- | src/linker.zig | 6 | ||||
-rw-r--r-- | tsconfig.json | 3 | ||||
-rw-r--r-- | types/bun/bun-test.d.ts | 3 | ||||
-rw-r--r-- | types/bun/bun.d.ts | 309 |
4 files changed, 165 insertions, 156 deletions
diff --git a/src/linker.zig b/src/linker.zig index 7bc682a17..d13a61a88 100644 --- a/src/linker.zig +++ b/src/linker.zig @@ -265,6 +265,11 @@ pub const Linker = struct { continue; } + if (strings.eqlComptime(import_record.path.text, "bun")) { + import_record.tag = .bun; + continue; + } + if (strings.eqlComptime(import_record.path.text, "path") or strings.eqlComptime(import_record.path.text, "node:path")) { import_record.path.text = "node:path"; externals.append(record_index) catch unreachable; @@ -287,6 +292,7 @@ pub const Linker = struct { "vitest", )) { import_record.path.namespace = "bun"; + import_record.tag = .bun_test; import_record.path.text = "test"; continue; } diff --git a/tsconfig.json b/tsconfig.json index 6b0a42469..1bd313fae 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -5,5 +5,6 @@ "target": "esnext", "typeRoots": ["./types"], "types": ["bun"] - } + }, + "exclude": ["src"] } diff --git a/types/bun/bun-test.d.ts b/types/bun/bun-test.d.ts index 0f9fd48db..76ded893b 100644 --- a/types/bun/bun-test.d.ts +++ b/types/bun/bun-test.d.ts @@ -1,6 +1,6 @@ /** * - * This isn't really designed for third-party usage yet + * This isn't really designed for third-party usage yet. * You can try it if you want though! * * To run the tests, run `bun wiptest` @@ -16,6 +16,7 @@ * $ bun wiptest file-name * ``` */ + declare module "bun:test" { export function describe(label: string, body: () => {}): any; export function it(label: string, test: () => void | Promise<any>): any; diff --git a/types/bun/bun.d.ts b/types/bun/bun.d.ts index 023ccb7c8..2ce763b91 100644 --- a/types/bun/bun.d.ts +++ b/types/bun/bun.d.ts @@ -1,4 +1,159 @@ declare module "bun" { + /** + * Start a fast HTTP server. + * + * @param options Server options (port defaults to $PORT || 8080) + * + * ----- + * + * @example + * + * ```ts + * Bun.serve({ + * fetch(req: Request): Response | Promise<Response> { + * return new Response("Hello World!"); + * }, + * + * // Optional port number - the default value is 3000 + * port: process.env.PORT || 3000, + * }); + * ``` + * ----- + * + * @example + * + * Send a file + * + * ```ts + * Bun.serve({ + * fetch(req: Request): Response | Promise<Response> { + * return new Response(Bun.file("./package.json")); + * }, + * + * // Optional port number - the default value is 3000 + * port: process.env.PORT || 3000, + * }); + * ``` + */ + export function serve(options: Serve): void; + + /** + * Synchronously resolve a `moduleId` as though it were imported from `parent` + * + * On failure, throws a `ResolveError` + */ + // tslint:disable-next-line:unified-signatures + export function resolveSync(moduleId: string, parent: string): string; + + /** + * Resolve a `moduleId` as though it were imported from `parent` + * + * On failure, throws a `ResolveError` + * + * For now, use the sync version. There is zero performance benefit to using this async version. It exists for future-proofing. + */ + // tslint:disable-next-line:unified-signatures + export function resolve(moduleId: string, parent: string): Promise<string>; + + /** + * + * Use the fastest syscalls available to copy from `input` into `destination`. + * + * If `destination` exists, it must be a regular file or symlink to a file. + * + * @param destination The file or file path to write to + * @param input The data to copy into `destination`. + * @returns A promise that resolves with the number of bytes written. + */ + // tslint:disable-next-line:unified-signatures + export function write( + destination: FileBlob | PathLike, + input: Blob | TypedArray | string | BlobPart[] + ): Promise<number>; + + /** + * + * Persist a {@link Response} body to disk. + * + * @param destination The file to write to. If the file doesn't exist, + * it will be created and if the file does exist, it will be + * overwritten. If `input`'s size is less than `destination`'s size, + * `destination` will be truncated. + * @param input - `Response` object + * @returns A promise that resolves with the number of bytes written. + */ + export function write( + destination: FileBlob, + input: Response + ): Promise<number>; + + /** + * + * Persist a {@link Response} body to disk. + * + * @param destinationPath The file path to write to. If the file doesn't + * exist, it will be created and if the file does exist, it will be + * overwritten. If `input`'s size is less than `destination`'s size, + * `destination` will be truncated. + * @param input - `Response` object + * @returns A promise that resolves with the number of bytes written. + */ + // tslint:disable-next-line:unified-signatures + export function write( + destinationPath: PathLike, + input: Response + ): Promise<number>; + + /** + * + * Use the fastest syscalls available to copy from `input` into `destination`. + * + * If `destination` exists, it must be a regular file or symlink to a file. + * + * On Linux, this uses `copy_file_range`. + * + * On macOS, when the destination doesn't already exist, this uses + * [`clonefile()`](https://www.manpagez.com/man/2/clonefile/) and falls + * back to [`fcopyfile()`](https://www.manpagez.com/man/2/fcopyfile/) + * + * @param destination The file to write to. If the file doesn't exist, + * it will be created and if the file does exist, it will be + * overwritten. If `input`'s size is less than `destination`'s size, + * `destination` will be truncated. + * @param input The file to copy from. + * @returns A promise that resolves with the number of bytes written. + */ + // tslint:disable-next-line:unified-signatures + export function write( + destination: FileBlob, + input: FileBlob + ): Promise<number>; + + /** + * + * Use the fastest syscalls available to copy from `input` into `destination`. + * + * If `destination` exists, it must be a regular file or symlink to a file. + * + * On Linux, this uses `copy_file_range`. + * + * On macOS, when the destination doesn't already exist, this uses + * [`clonefile()`](https://www.manpagez.com/man/2/clonefile/) and falls + * back to [`fcopyfile()`](https://www.manpagez.com/man/2/fcopyfile/) + * + * @param destinationPath The file path to write to. If the file doesn't + * exist, it will be created and if the file does exist, it will be + * overwritten. If `input`'s size is less than `destination`'s size, + * `destination` will be truncated. + * @param input The file to copy from. + * @returns A promise that resolves with the number of bytes written. + */ + // tslint:disable-next-line:unified-signatures + export function write( + destinationPath: PathLike, + input: FileBlob + ): Promise<number>; + export interface SystemError extends Error { errno?: number | undefined; code?: string | undefined; @@ -390,160 +545,6 @@ declare module "bun" { }; export type Serve = SSLServeOptions | ServeOptions; - /** - * Start a fast HTTP server. - * - * @param options Server options (port defaults to $PORT || 8080) - * - * ----- - * - * @example - * - * ```ts - * Bun.serve({ - * fetch(req: Request): Response | Promise<Response> { - * return new Response("Hello World!"); - * }, - * - * // Optional port number - the default value is 3000 - * port: process.env.PORT || 3000, - * }); - * ``` - * ----- - * - * @example - * - * Send a file - * - * ```ts - * Bun.serve({ - * fetch(req: Request): Response | Promise<Response> { - * return new Response(Bun.file("./package.json")); - * }, - * - * // Optional port number - the default value is 3000 - * port: process.env.PORT || 3000, - * }); - * ``` - */ - export function serve(options: Serve): void; - - /** - * - * Use the fastest syscalls available to copy from `input` into `destination`. - * - * If `destination` exists, it must be a regular file or symlink to a file. - * - * @param destination The file or file path to write to - * @param input The data to copy into `destination`. - * @returns A promise that resolves with the number of bytes written. - */ - // tslint:disable-next-line:unified-signatures - export function write( - destination: FileBlob | PathLike, - input: Blob | TypedArray | string | BlobPart[] - ): Promise<number>; - - /** - * - * Persist a {@link Response} body to disk. - * - * @param destination The file to write to. If the file doesn't exist, - * it will be created and if the file does exist, it will be - * overwritten. If `input`'s size is less than `destination`'s size, - * `destination` will be truncated. - * @param input - `Response` object - * @returns A promise that resolves with the number of bytes written. - */ - export function write( - destination: FileBlob, - input: Response - ): Promise<number>; - - /** - * - * Persist a {@link Response} body to disk. - * - * @param destinationPath The file path to write to. If the file doesn't - * exist, it will be created and if the file does exist, it will be - * overwritten. If `input`'s size is less than `destination`'s size, - * `destination` will be truncated. - * @param input - `Response` object - * @returns A promise that resolves with the number of bytes written. - */ - // tslint:disable-next-line:unified-signatures - export function write( - destinationPath: PathLike, - input: Response - ): Promise<number>; - - /** - * - * Use the fastest syscalls available to copy from `input` into `destination`. - * - * If `destination` exists, it must be a regular file or symlink to a file. - * - * On Linux, this uses `copy_file_range`. - * - * On macOS, when the destination doesn't already exist, this uses - * [`clonefile()`](https://www.manpagez.com/man/2/clonefile/) and falls - * back to [`fcopyfile()`](https://www.manpagez.com/man/2/fcopyfile/) - * - * @param destination The file to write to. If the file doesn't exist, - * it will be created and if the file does exist, it will be - * overwritten. If `input`'s size is less than `destination`'s size, - * `destination` will be truncated. - * @param input The file to copy from. - * @returns A promise that resolves with the number of bytes written. - */ - // tslint:disable-next-line:unified-signatures - export function write( - destination: FileBlob, - input: FileBlob - ): Promise<number>; - - /** - * - * Use the fastest syscalls available to copy from `input` into `destination`. - * - * If `destination` exists, it must be a regular file or symlink to a file. - * - * On Linux, this uses `copy_file_range`. - * - * On macOS, when the destination doesn't already exist, this uses - * [`clonefile()`](https://www.manpagez.com/man/2/clonefile/) and falls - * back to [`fcopyfile()`](https://www.manpagez.com/man/2/fcopyfile/) - * - * @param destinationPath The file path to write to. If the file doesn't - * exist, it will be created and if the file does exist, it will be - * overwritten. If `input`'s size is less than `destination`'s size, - * `destination` will be truncated. - * @param input The file to copy from. - * @returns A promise that resolves with the number of bytes written. - */ - // tslint:disable-next-line:unified-signatures - export function write( - destinationPath: PathLike, - input: FileBlob - ): Promise<number>; - - /** - * Resolve a `moduleId` as though it were imported from `parent` - * - * On failure, throws a `ResolveError` - * - * For now, use the sync version. There is zero performance benefit to using this async version. It exists for future-proofing. - */ - // tslint:disable-next-line:unified-signatures - export function resolve(moduleId: string, parent: string): Promise<string>; - - /** - * Synchronously resolve a `moduleId` as though it were imported from `parent` - * - * On failure, throws a `ResolveError` - */ - // tslint:disable-next-line:unified-signatures - export function resolveSync(moduleId: string, parent: string): string; /** * [`Blob`](https://developer.mozilla.org/en-US/docs/Web/API/Blob) powered by the fastest system calls available for operating on files. |