diff options
author | 2023-10-02 12:31:07 -0700 | |
---|---|---|
committer | 2023-10-02 12:31:07 -0700 | |
commit | abbe3916ed5d7b6adb5a4b376e5c563d36e07d31 (patch) | |
tree | 2dba62d3d15c0842eb70067f67bd81d95a4abdad /packages/bun-types/bun.d.ts | |
parent | 4073539837e2fc60860ddb231a71c9a34c388afd (diff) | |
parent | 0a2d490bf8cb0dbfe3ccfc936d71b33fb9c59899 (diff) | |
download | bun-abbe3916ed5d7b6adb5a4b376e5c563d36e07d31.tar.gz bun-abbe3916ed5d7b6adb5a4b376e5c563d36e07d31.tar.zst bun-abbe3916ed5d7b6adb5a4b376e5c563d36e07d31.zip |
Merge remote-tracking branch 'origin/main' into dave/nodemodule-preloadmodules
Diffstat (limited to 'packages/bun-types/bun.d.ts')
-rw-r--r-- | packages/bun-types/bun.d.ts | 37 |
1 files changed, 32 insertions, 5 deletions
diff --git a/packages/bun-types/bun.d.ts b/packages/bun-types/bun.d.ts index a2ccebd8a..9b2d314e8 100644 --- a/packages/bun-types/bun.d.ts +++ b/packages/bun-types/bun.d.ts @@ -2359,11 +2359,7 @@ declare module "bun" { ): ServerWebSocketSendStatus; /** - * Returns the client IP address of the given Request. - * - * @param request The incoming request - * - * @returns An ipv4/ipv6 address string, or null if it couldn't find one. + * Returns the client IP address and port of the given Request. If the request was closed or is a unix socket, returns null. * * @example * ```js @@ -3297,6 +3293,37 @@ declare module "bun" { * The config object passed to `Bun.build` as is. Can be mutated. */ config: BuildConfig & { plugins: BunPlugin[] }; + + /** + * Create a lazy-loaded virtual module that can be `import`ed or `require`d from other modules + * + * @param specifier The module specifier to register the callback for + * @param callback The function to run when the module is imported or required + * + * ### Example + * @example + * ```ts + * Bun.plugin({ + * setup(builder) { + * builder.module("hello:world", () => { + * return { exports: { foo: "bar" }, loader: "object" }; + * }); + * }, + * }); + * + * // sometime later + * const { foo } = await import("hello:world"); + * console.log(foo); // "bar" + * + * // or + * const { foo } = require("hello:world"); + * console.log(foo); // "bar" + * ``` + */ + module( + specifier: string, + callback: () => OnLoadResult | Promise<OnLoadResult>, + ): void; } interface BunPlugin { |