Skip to content

Commit

Permalink
Basic types for Bun.build (#2713)
Browse files Browse the repository at this point in the history
* Basic types for Bun.build

* Tweaks

* Updates
  • Loading branch information
colinhacks authored Apr 26, 2023
1 parent ab447e4 commit 68ab71e
Showing 1 changed file with 46 additions and 5 deletions.
51 changes: 46 additions & 5 deletions packages/bun-types/bun.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -750,7 +750,7 @@ declare module "bun" {
paths?: Record<string, string[]>;
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;
Expand Down Expand Up @@ -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<string>;
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<T = Blob> = {
outputs: Array<{ path: string; result: T }>;
};

function build(config: BuildConfig): BuildResult<Blob>;

/**
* **0** means the message was **dropped**
*
Expand Down Expand Up @@ -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
*/
Expand All @@ -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 {
/**
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -2637,7 +2678,7 @@ declare module "bun" {
/**
* The current target environment
*/
target: PluginTarget;
target: Target;
}

interface BunPlugin {
Expand All @@ -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.
*
Expand Down

0 comments on commit 68ab71e

Please sign in to comment.