From 68ab71eb13687ebb0889d085bb9c76132e452f60 Mon Sep 17 00:00:00 2001 From: Colin McDonnell Date: Wed, 26 Apr 2023 14:54:05 -0700 Subject: [PATCH] Basic types for Bun.build (#2713) * Basic types for Bun.build * Tweaks * Updates --- packages/bun-types/bun.d.ts | 51 +++++++++++++++++++++++++++++++++---- 1 file changed, 46 insertions(+), 5 deletions(-) diff --git a/packages/bun-types/bun.d.ts b/packages/bun-types/bun.d.ts index 4454f54529314..360efa81394a6 100644 --- a/packages/bun-types/bun.d.ts +++ b/packages/bun-types/bun.d.ts @@ -750,7 +750,7 @@ declare module "bun" { paths?: Record; baseUrl?: string; /** "preserve" is not supported yet */ - jsx?: "preserve" | "react" | "react-jsx" | "react-jsxdev" | "react-native"; + jsx?: "preserve" | "react" | "react-jsx" | "react-jsxdev"; jsxFactory?: string; jsxFragmentFactory?: string; jsxImportSource?: string; @@ -962,6 +962,46 @@ declare module "bun" { | "entry-point"; } + type ModuleFormat = "esm"; // later: "cjs", "iife" + + interface BuildConfig { + entrypoints: string[]; // list of file path + target?: Target; // default: "browser" + // module?: ModuleFormat; // later: "cjs", "iife" + outdir?: string; // output directory + + naming?: { + chunk?: string; + entrypoint?: string; + asset?: string; + }; // | string; + // root?: string; // project root + // transform?: boolean; // default: false, transform instead of bundling + splitting?: boolean; // default true, enable code splitting + bundling?: boolean; // default true, enable bundling + plugins?: BunPlugin[]; + // manifest?: boolean; // whether to return manifest + external?: Array; + publicPath: string; + // origin?: string; // e.g. http://mydomain.com + // loaders?: { [k in string]: Loader }; + // sourcemap?: "none" | "inline" | "external"; // default: "none" + minify?: + | boolean + | { + whitespace?: boolean; + syntax?: boolean; + identifiers?: boolean; + }; + // treeshaking?: boolean; + } + + type BuildResult = { + outputs: Array<{ path: string; result: T }>; + }; + + function build(config: BuildConfig): BuildResult; + /** * **0** means the message was **dropped** * @@ -2470,7 +2510,7 @@ declare module "bun" { */ export function gunzipSync(data: Uint8Array): Uint8Array; - export type PluginTarget = + export type Target = /** * The default environment when using `bun run` or `bun` to load a script */ @@ -2483,6 +2523,7 @@ declare module "bun" { * The plugin will be applied to browser builds */ | "browser"; + type Loader = "js" | "jsx" | "ts" | "tsx" | "json" | "toml"; interface PluginConstraints { /** @@ -2525,7 +2566,7 @@ declare module "bun" { * * "css" will be added in a future version of Bun. */ - loader: "js" | "jsx" | "ts" | "tsx" | "json" | "toml"; + loader: Loader; } interface OnLoadResultObject { @@ -2637,7 +2678,7 @@ declare module "bun" { /** * The current target environment */ - target: PluginTarget; + target: Target; } interface BunPlugin { @@ -2658,7 +2699,7 @@ declare module "bun" { * * If unspecified, it is assumed that the plugin is compatible with the default target. */ - target?: PluginTarget; + target?: Target; /** * A function that will be called when the plugin is loaded. *