diff --git a/docs/api/sql.md b/docs/api/sql.md index 01d4d8acd3..20c05f866c 100644 --- a/docs/api/sql.md +++ b/docs/api/sql.md @@ -377,6 +377,22 @@ const users = [ await sql`SELECT * FROM users WHERE id IN ${sql(users, "id")}`; ``` +### `sql.array` helper + +The `sql.array` helper creates PostgreSQL array literals from JavaScript arrays: + +```ts +// Create array literals for PostgreSQL +await sql`INSERT INTO tags (items) VALUES (${sql.array(["red", "blue", "green"])})`; +// Generates: INSERT INTO tags (items) VALUES (ARRAY['red', 'blue', 'green']) + +// Works with numeric arrays too +await sql`SELECT * FROM products WHERE ids = ANY(${sql.array([1, 2, 3])})`; +// Generates: SELECT * FROM products WHERE ids = ANY(ARRAY[1, 2, 3]) +``` + +**Note**: `sql.array` is PostgreSQL-only. Multi-dimensional arrays and NULL elements may not be supported yet. + ## `sql``.simple()` The PostgreSQL wire protocol supports two types of queries: "simple" and "extended". Simple queries can contain multiple statements but don't support parameters, while extended queries (the default) support parameters but only allow one statement. diff --git a/docs/bundler/index.md b/docs/bundler/index.md index 68ef436040..53a5eaab2e 100644 --- a/docs/bundler/index.md +++ b/docs/bundler/index.md @@ -400,6 +400,55 @@ $ bun build ./index.tsx --outdir ./out --format cjs TODO: document IIFE once we support globalNames. +### `jsx` + +Configure JSX transform behavior. Allows fine-grained control over how JSX is compiled. + +**Classic runtime example** (uses `factory` and `fragment`): + +{% codetabs %} + +```ts#JavaScript +await Bun.build({ + entrypoints: ['./app.tsx'], + outdir: './out', + jsx: { + factory: 'h', + fragment: 'Fragment', + runtime: 'classic', + }, +}) +``` + +```bash#CLI +# JSX configuration is handled via bunfig.toml or tsconfig.json +$ bun build ./app.tsx --outdir ./out +``` + +{% /codetabs %} + +**Automatic runtime example** (uses `importSource`): + +{% codetabs %} + +```ts#JavaScript +await Bun.build({ + entrypoints: ['./app.tsx'], + outdir: './out', + jsx: { + importSource: 'preact', + runtime: 'automatic', + }, +}) +``` + +```bash#CLI +# JSX configuration is handled via bunfig.toml or tsconfig.json +$ bun build ./app.tsx --outdir ./out +``` + +{% /codetabs %} + ### `splitting` Whether to enable code splitting. @@ -1527,6 +1576,15 @@ interface BuildConfig { * @default "esm" */ format?: "esm" | "cjs" | "iife"; + /** + * JSX configuration object for controlling JSX transform behavior + */ + jsx?: { + factory?: string; + fragment?: string; + importSource?: string; + runtime?: "automatic" | "classic"; + }; naming?: | string | { diff --git a/docs/cli/bun-install.md b/docs/cli/bun-install.md index fba186e6c9..c3311cd1a7 100644 --- a/docs/cli/bun-install.md +++ b/docs/cli/bun-install.md @@ -176,7 +176,21 @@ When a `bun.lock` exists and `package.json` hasn’t changed, Bun downloads miss ## Platform-specific dependencies? -bun stores normalized `cpu` and `os` values from npm in the lockfile, along with the resolved packages. It skips downloading, extracting, and installing packages disabled for the current target at runtime. This means the lockfile won’t change between platforms/architectures even if the packages ultimately installed do change. +bun stores normalized `cpu` and `os` values from npm in the lockfile, along with the resolved packages. It skips downloading, extracting, and installing packages disabled for the current target at runtime. This means the lockfile won't change between platforms/architectures even if the packages ultimately installed do change. + +### `--cpu` and `--os` flags + +You can override the target platform for package selection: + +```bash +bun install --cpu=x64 --os=linux +``` + +This installs packages for the specified platform instead of the current system. Useful for cross-platform builds or when preparing deployments for different environments. + +**Accepted values for `--cpu`**: `arm64`, `x64`, `ia32`, `ppc64`, `s390x` + +**Accepted values for `--os`**: `linux`, `darwin`, `win32`, `freebsd`, `openbsd`, `sunos`, `aix` ## Peer dependencies? @@ -245,3 +259,91 @@ bun uses a binary format for caching NPM registry responses. This loads much fas You will see these files in `~/.bun/install/cache/*.npm`. The filename pattern is `${hash(packageName)}.npm`. It’s a hash so that extra directories don’t need to be created for scoped packages. Bun's usage of `Cache-Control` ignores `Age`. This improves performance, but means bun may be about 5 minutes out of date to receive the latest package version metadata from npm. + +## pnpm migration + +Bun automatically migrates projects from pnpm to bun. When a `pnpm-lock.yaml` file is detected and no `bun.lock` file exists, Bun will automatically migrate the lockfile to `bun.lock` during installation. The original `pnpm-lock.yaml` file remains unmodified. + +```bash +bun install +``` + +**Note**: Migration only runs when `bun.lock` is absent. There is currently no opt-out flag for pnpm migration. + +The migration process handles: + +### Lockfile Migration + +- Converts `pnpm-lock.yaml` to `bun.lock` format +- Preserves package versions and resolution information +- Maintains dependency relationships and peer dependencies +- Handles patched dependencies with integrity hashes + +### Workspace Configuration + +When a `pnpm-workspace.yaml` file exists, Bun migrates workspace settings to your root `package.json`: + +```yaml +# pnpm-workspace.yaml +packages: + - "apps/*" + - "packages/*" + +catalog: + react: ^18.0.0 + typescript: ^5.0.0 + +catalogs: + build: + webpack: ^5.0.0 + babel: ^7.0.0 +``` + +The workspace packages list and catalogs are moved to the `workspaces` field in `package.json`: + +```json +{ + "workspaces": { + "packages": ["apps/*", "packages/*"], + "catalog": { + "react": "^18.0.0", + "typescript": "^5.0.0" + }, + "catalogs": { + "build": { + "webpack": "^5.0.0", + "babel": "^7.0.0" + } + } + } +} +``` + +### Catalog Dependencies + +Dependencies using pnpm's `catalog:` protocol are preserved: + +```json +{ + "dependencies": { + "react": "catalog:", + "webpack": "catalog:build" + } +} +``` + +### Configuration Migration + +The following pnpm configuration is migrated from both `pnpm-lock.yaml` and `pnpm-workspace.yaml`: + +- **Overrides**: Moved from `pnpm.overrides` to root-level `overrides` in `package.json` +- **Patched Dependencies**: Moved from `pnpm.patchedDependencies` to root-level `patchedDependencies` in `package.json` +- **Workspace Overrides**: Applied from `pnpm-workspace.yaml` to root `package.json` + +### Requirements + +- Requires pnpm lockfile version 7 or higher +- Workspace packages must have a `name` field in their `package.json` +- All catalog entries referenced by dependencies must exist in the catalogs definition + +After migration, you can safely remove `pnpm-lock.yaml` and `pnpm-workspace.yaml` files. diff --git a/docs/cli/test.md b/docs/cli/test.md index 6539a4b7a3..f266166a59 100644 --- a/docs/cli/test.md +++ b/docs/cli/test.md @@ -188,6 +188,11 @@ test.serial("second serial test", () => { test("independent test", () => { expect(true).toBe(true); }); + +// Chaining test qualifiers +test.failing.each([1, 2, 3])("chained qualifiers %d", input => { + expect(input).toBe(0); // This test is expected to fail for each input +}); ``` ## Rerun tests