mirror of
https://github.com/oven-sh/bun
synced 2026-02-24 18:47:18 +01:00
Compare commits
3 Commits
cursor/ena
...
codex/impl
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8e3c46a56c | ||
|
|
244513116f | ||
|
|
776cf69a1d |
@@ -1,78 +0,0 @@
|
||||
import { spawnSync } from "node:child_process";
|
||||
import { readFileSync, existsSync } from "node:fs";
|
||||
import { parseArgs } from "node:util";
|
||||
|
||||
const { positionals, values } = parseArgs({
|
||||
allowPositionals: true,
|
||||
options: {
|
||||
help: {
|
||||
type: "boolean",
|
||||
short: "h",
|
||||
default: false,
|
||||
},
|
||||
interactive: {
|
||||
type: "boolean",
|
||||
short: "i",
|
||||
default: false,
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
if (values.help || positionals.length === 0) {
|
||||
console.log("Usage: node agent.mjs <prompt_name> [extra_args...]");
|
||||
console.log("Example: node agent.mjs triage fix bug in authentication");
|
||||
console.log("Options:");
|
||||
console.log(" -h, --help Show this help message");
|
||||
console.log(" -i, --interactive Run in interactive mode");
|
||||
process.exit(0);
|
||||
}
|
||||
|
||||
const promptName = positionals[0].toUpperCase();
|
||||
const promptFile = `.agent/${promptName}.md`;
|
||||
const extraArgs = positionals.slice(1);
|
||||
|
||||
if (!existsSync(promptFile)) {
|
||||
console.error(`Error: Prompt file "${promptFile}" not found`);
|
||||
console.error(`Available prompts should be named like: .agent/triage.md, .agent/debug.md, etc.`);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
try {
|
||||
let prompt = readFileSync(promptFile, "utf-8");
|
||||
|
||||
const githubEnvs = Object.entries(process.env)
|
||||
.filter(([key]) => key.startsWith("GITHUB_"))
|
||||
.sort(([a], [b]) => a.localeCompare(b));
|
||||
|
||||
if (githubEnvs.length > 0) {
|
||||
const githubContext = `## GitHub Environment\n\n${githubEnvs
|
||||
.map(([key, value]) => `**${key}**: \`${value}\``)
|
||||
.join("\n")}\n\n---\n\n`;
|
||||
prompt = githubContext + prompt;
|
||||
}
|
||||
|
||||
if (extraArgs.length > 0) {
|
||||
const extraArgsContext = `\n\n## Additional Arguments\n\n${extraArgs.join(" ")}\n\n---\n\n`;
|
||||
prompt = prompt + extraArgsContext;
|
||||
}
|
||||
|
||||
const claudeArgs = [prompt, "--allowedTools=Edit,Write,Replace,Search", "--output-format=json"];
|
||||
if (!values.interactive) {
|
||||
claudeArgs.unshift("--print");
|
||||
}
|
||||
|
||||
const { status, error } = spawnSync("claude", claudeArgs, {
|
||||
stdio: "inherit",
|
||||
encoding: "utf-8",
|
||||
});
|
||||
|
||||
if (error) {
|
||||
console.error("Error running claude:", error);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
process.exit(status || 0);
|
||||
} catch (error) {
|
||||
console.error(`Error reading prompt file "${promptFile}":`, error);
|
||||
process.exit(1);
|
||||
}
|
||||
@@ -228,7 +228,13 @@ function getRetry(limit = 0) {
|
||||
manual: {
|
||||
permit_on_passed: true,
|
||||
},
|
||||
automatic: false,
|
||||
automatic: [
|
||||
{ exit_status: 1, limit },
|
||||
{ exit_status: -1, limit: 1 },
|
||||
{ exit_status: 255, limit: 1 },
|
||||
{ signal_reason: "cancel", limit: 1 },
|
||||
{ signal_reason: "agent_stop", limit: 1 },
|
||||
],
|
||||
};
|
||||
}
|
||||
|
||||
@@ -309,19 +315,6 @@ function getCppAgent(platform, options) {
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @returns {Platform}
|
||||
*/
|
||||
function getZigPlatform() {
|
||||
return {
|
||||
os: "linux",
|
||||
arch: "aarch64",
|
||||
abi: "musl",
|
||||
distro: "alpine",
|
||||
release: "3.21",
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Platform} platform
|
||||
* @param {PipelineOptions} options
|
||||
@@ -335,9 +328,19 @@ function getZigAgent(platform, options) {
|
||||
// queue: "build-zig",
|
||||
// };
|
||||
|
||||
return getEc2Agent(getZigPlatform(), options, {
|
||||
instanceType: "r8g.large",
|
||||
});
|
||||
return getEc2Agent(
|
||||
{
|
||||
os: "linux",
|
||||
arch: "aarch64",
|
||||
abi: "musl",
|
||||
distro: "alpine",
|
||||
release: "3.21",
|
||||
},
|
||||
options,
|
||||
{
|
||||
instanceType: "r8g.large",
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -450,7 +453,7 @@ function getBuildCppStep(platform, options) {
|
||||
BUN_CPP_ONLY: "ON",
|
||||
...getBuildEnv(platform, options),
|
||||
},
|
||||
// We used to build the C++ dependencies and bun in separate steps.
|
||||
// We used to build the C++ dependencies and bun in seperate steps.
|
||||
// However, as long as the zig build takes longer than both sequentially,
|
||||
// it's cheaper to run them in the same step. Can be revisited in the future.
|
||||
command: [`${command} --target bun`, `${command} --target dependencies`],
|
||||
@@ -569,7 +572,7 @@ function getTestBunStep(platform, options, testOptions = {}) {
|
||||
retry: getRetry(),
|
||||
cancel_on_build_failing: isMergeQueue(),
|
||||
parallelism: unifiedTests ? undefined : os === "darwin" ? 2 : 10,
|
||||
timeout_in_minutes: profile === "asan" ? 45 : 30,
|
||||
timeout_in_minutes: profile === "asan" ? 90 : 30,
|
||||
command:
|
||||
os === "windows"
|
||||
? `node .\\scripts\\runner.node.mjs ${args.join(" ")}`
|
||||
@@ -922,7 +925,7 @@ function getOptionsStep() {
|
||||
{
|
||||
key: "unified-builds",
|
||||
select: "Do you want to build each platform in a single step?",
|
||||
hint: "If true, builds will not be split into separate steps (this will likely slow down the build)",
|
||||
hint: "If true, builds will not be split into seperate steps (this will likely slow down the build)",
|
||||
required: false,
|
||||
default: "false",
|
||||
options: booleanOptions,
|
||||
@@ -930,7 +933,7 @@ function getOptionsStep() {
|
||||
{
|
||||
key: "unified-tests",
|
||||
select: "Do you want to run tests in a single step?",
|
||||
hint: "If true, tests will not be split into separate steps (this will be very slow)",
|
||||
hint: "If true, tests will not be split into seperate steps (this will be very slow)",
|
||||
required: false,
|
||||
default: "false",
|
||||
options: booleanOptions,
|
||||
@@ -1108,11 +1111,6 @@ async function getPipeline(options = {}) {
|
||||
steps.push(
|
||||
...relevantBuildPlatforms.map(target => {
|
||||
const imageKey = getImageKey(target);
|
||||
const zigImageKey = getImageKey(getZigPlatform());
|
||||
const dependsOn = imagePlatforms.has(zigImageKey) ? [`${zigImageKey}-build-image`] : [];
|
||||
if (imagePlatforms.has(imageKey)) {
|
||||
dependsOn.push(`${imageKey}-build-image`);
|
||||
}
|
||||
|
||||
return getStepWithDependsOn(
|
||||
{
|
||||
@@ -1122,7 +1120,7 @@ async function getPipeline(options = {}) {
|
||||
? [getBuildBunStep(target, options)]
|
||||
: [getBuildCppStep(target, options), getBuildZigStep(target, options), getLinkBunStep(target, options)],
|
||||
},
|
||||
...dependsOn,
|
||||
imagePlatforms.has(imageKey) ? `${imageKey}-build-image` : undefined,
|
||||
);
|
||||
}),
|
||||
);
|
||||
|
||||
@@ -1,23 +0,0 @@
|
||||
Upgrade Bun's Webkit fork to the latest upstream version of Webkit.
|
||||
|
||||
To do that:
|
||||
|
||||
- cd vendor/WebKit
|
||||
- git fetch upstream
|
||||
- git merge upstream main
|
||||
- Fix the merge conflicts
|
||||
- cd ../../ (back to bun)
|
||||
- make jsc-build (this will take about 7 minutes)
|
||||
- While it compiles, in another task review the JSC commits between the last version of Webkit and the new version. Write up a summary of the webkit changes in a file called "webkit-changes.md"
|
||||
- bun run build:local (build a build of Bun with the new Webkit, make sure it compiles)
|
||||
- After making sure it compiles, run some code to make sure things work. something like ./build/debug-local/bun-debug --print '42' should be all you need
|
||||
- cd vendor/WebKit
|
||||
- git commit -am "Upgrade Webkit to the latest version"
|
||||
- git push
|
||||
- get the commit SHA in the vendor/WebKit directory of your new commit
|
||||
- cd ../../ (back to bun)
|
||||
- Update WEBKIT_VERSION in cmake/tools/SetupWebKit.cmake to the commit SHA of your new commit
|
||||
- git checkout -b bun/webkit-upgrade-<commit-sha>
|
||||
- commit + push (without adding the webkit-changes.md file)
|
||||
- create PR titled "Upgrade Webkit to the <commit-sha>", paste your webkit-changes.md into the PR description
|
||||
- delete the webkit-changes.md file
|
||||
@@ -1,10 +0,0 @@
|
||||
{
|
||||
"snapshot": "snapshot-20250630-a406baa4-6bb1-41d9-a125-85176851e05b",
|
||||
"install": "bun install",
|
||||
"terminals": [
|
||||
{
|
||||
"name": "bun build",
|
||||
"command": "bun run build"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -1,13 +1,27 @@
|
||||
---
|
||||
description: How to build Bun
|
||||
globs:
|
||||
alwaysApply: false
|
||||
globs:
|
||||
---
|
||||
|
||||
# How to build Bun
|
||||
|
||||
Run:
|
||||
## CMake
|
||||
|
||||
```bash
|
||||
bun bd
|
||||
Bun is built using CMake, which you can find in `CMakeLists.txt` and in the `cmake/` directory.
|
||||
|
||||
* `CMakeLists.txt`
|
||||
* `cmake/`
|
||||
* `Globals.cmake` - macros and functions used by all the other files
|
||||
* `Options.cmake` - build options for configuring the build (e.g. debug/release mode)
|
||||
* `CompilerFlags.cmake` - compiler and linker flags used by all the targets
|
||||
* `tools/` - setup scripts for various build tools (e.g. llvm, zig, webkit, rust, etc.)
|
||||
* `targets/` - targets for bun and its dependencies (e.g. brotli, boringssl, libuv, etc.)
|
||||
|
||||
## How to
|
||||
|
||||
There are `package.json` scripts that make it easy to build Bun without calling CMake directly, for example:
|
||||
|
||||
```sh
|
||||
bun run build # builds a debug build: `build/debug/bun-debug`
|
||||
bun run build:release # builds a release build: `build/release/bun`
|
||||
bun run build:assert # builds a release build with debug assertions: `build/assert/bun`
|
||||
```
|
||||
|
||||
@@ -91,7 +91,7 @@ devTest("html file is watched", {
|
||||
|
||||
`files` holds the initial state, and the callback runs with the server running. `dev.fetch()` runs HTTP requests, while `dev.client()` opens a browser instance to the code.
|
||||
|
||||
Functions `dev.write` and `dev.patch` and `dev.delete` mutate the filesystem. Do not use `node:fs` APIs, as the dev server ones are hooked to wait for hot-reload, and all connected clients to receive changes.
|
||||
Functions `dev.write` and `dev.patch` and `dev.delete` mutate the filesystem. Do not use `node:fs` APIs, as the dev server ones are hooked to wait for hot-reload, and all connected clients to recieve changes.
|
||||
|
||||
When a change performs a hard-reload, that must be explicitly annotated with `expectReload`. This tells `client-fixture.mjs` that the test is meant to reload the page once; All other hard reloads automatically fail the test.
|
||||
|
||||
|
||||
@@ -1,203 +0,0 @@
|
||||
# Registering Functions, Objects, and Modules in Bun
|
||||
|
||||
This guide documents the process of adding new functionality to the Bun global object and runtime.
|
||||
|
||||
## Overview
|
||||
|
||||
Bun's architecture exposes functionality to JavaScript through a set of carefully registered functions, objects, and modules. Most core functionality is implemented in Zig, with JavaScript bindings that make these features accessible to users.
|
||||
|
||||
There are several key ways to expose functionality in Bun:
|
||||
|
||||
1. **Global Functions**: Direct methods on the `Bun` object (e.g., `Bun.serve()`)
|
||||
2. **Getter Properties**: Lazily initialized properties on the `Bun` object (e.g., `Bun.sqlite`)
|
||||
3. **Constructor Classes**: Classes available through the `Bun` object (e.g., `Bun.ValkeyClient`)
|
||||
4. **Global Modules**: Modules that can be imported directly (e.g., `import {X} from "bun:*"`)
|
||||
|
||||
## The Registration Process
|
||||
|
||||
Adding new functionality to Bun involves several coordinated steps across multiple files:
|
||||
|
||||
### 1. Implement the Core Functionality in Zig
|
||||
|
||||
First, implement your feature in Zig, typically in its own directory in `src/`. Examples:
|
||||
|
||||
- `src/valkey/` for Redis/Valkey client
|
||||
- `src/semver/` for SemVer functionality
|
||||
- `src/smtp/` for SMTP client
|
||||
|
||||
### 2. Create JavaScript Bindings
|
||||
|
||||
Create bindings that expose your Zig functionality to JavaScript:
|
||||
|
||||
- Create a class definition file (e.g., `js_bindings.classes.ts`) to define the JavaScript interface
|
||||
- Implement `JSYourFeature` struct in a file like `js_your_feature.zig`
|
||||
|
||||
Example from a class definition file:
|
||||
|
||||
```typescript
|
||||
// Example from a .classes.ts file
|
||||
import { define } from "../../codegen/class-definitions";
|
||||
|
||||
export default [
|
||||
define({
|
||||
name: "YourFeature",
|
||||
construct: true,
|
||||
finalize: true,
|
||||
hasPendingActivity: true,
|
||||
memoryCost: true,
|
||||
klass: {},
|
||||
JSType: "0b11101110",
|
||||
proto: {
|
||||
yourMethod: {
|
||||
fn: "yourZigMethod",
|
||||
length: 1,
|
||||
},
|
||||
property: {
|
||||
getter: "getProperty",
|
||||
},
|
||||
},
|
||||
values: ["cachedValues"],
|
||||
}),
|
||||
];
|
||||
```
|
||||
|
||||
### 3. Register with BunObject in `src/bun.js/bindings/BunObject+exports.h`
|
||||
|
||||
Add an entry to the `FOR_EACH_GETTER` macro:
|
||||
|
||||
```c
|
||||
// In BunObject+exports.h
|
||||
#define FOR_EACH_GETTER(macro) \
|
||||
macro(CSRF) \
|
||||
macro(CryptoHasher) \
|
||||
... \
|
||||
macro(YourFeature) \
|
||||
```
|
||||
|
||||
### 4. Create a Getter Function in `src/bun.js/api/BunObject.zig`
|
||||
|
||||
Implement a getter function in `BunObject.zig` that returns your feature:
|
||||
|
||||
```zig
|
||||
// In BunObject.zig
|
||||
pub const YourFeature = toJSGetter(Bun.getYourFeatureConstructor);
|
||||
|
||||
// In the exportAll() function:
|
||||
@export(&BunObject.YourFeature, .{ .name = getterName("YourFeature") });
|
||||
```
|
||||
|
||||
### 5. Implement the Getter Function in a Relevant Zig File
|
||||
|
||||
Implement the function that creates your object:
|
||||
|
||||
```zig
|
||||
// In your main module file (e.g., src/your_feature/your_feature.zig)
|
||||
pub fn getYourFeatureConstructor(globalThis: *JSC.JSGlobalObject, _: *JSC.JSObject) JSC.JSValue {
|
||||
return JSC.API.YourFeature.getConstructor(globalThis);
|
||||
}
|
||||
```
|
||||
|
||||
### 6. Add to Build System
|
||||
|
||||
Ensure your files are included in the build system by adding them to the appropriate targets.
|
||||
|
||||
## Example: Adding a New Module
|
||||
|
||||
Here's a comprehensive example of adding a hypothetical SMTP module:
|
||||
|
||||
1. Create implementation files in `src/smtp/`:
|
||||
|
||||
- `index.zig`: Main entry point that exports everything
|
||||
- `SmtpClient.zig`: Core SMTP client implementation
|
||||
- `js_smtp.zig`: JavaScript bindings
|
||||
- `js_bindings.classes.ts`: Class definition
|
||||
|
||||
2. Define your JS class in `js_bindings.classes.ts`:
|
||||
|
||||
```typescript
|
||||
import { define } from "../../codegen/class-definitions";
|
||||
|
||||
export default [
|
||||
define({
|
||||
name: "EmailClient",
|
||||
construct: true,
|
||||
finalize: true,
|
||||
hasPendingActivity: true,
|
||||
configurable: false,
|
||||
memoryCost: true,
|
||||
klass: {},
|
||||
JSType: "0b11101110",
|
||||
proto: {
|
||||
send: {
|
||||
fn: "send",
|
||||
length: 1,
|
||||
},
|
||||
verify: {
|
||||
fn: "verify",
|
||||
length: 0,
|
||||
},
|
||||
close: {
|
||||
fn: "close",
|
||||
length: 0,
|
||||
},
|
||||
},
|
||||
values: ["connectionPromise"],
|
||||
}),
|
||||
];
|
||||
```
|
||||
|
||||
3. Add getter to `BunObject+exports.h`:
|
||||
|
||||
```c
|
||||
#define FOR_EACH_GETTER(macro) \
|
||||
macro(CSRF) \
|
||||
... \
|
||||
macro(SMTP) \
|
||||
```
|
||||
|
||||
4. Add getter function to `BunObject.zig`:
|
||||
|
||||
```zig
|
||||
pub const SMTP = toJSGetter(Bun.getSmtpConstructor);
|
||||
|
||||
// In exportAll:
|
||||
@export(&BunObject.SMTP, .{ .name = getterName("SMTP") });
|
||||
```
|
||||
|
||||
5. Implement getter in your module:
|
||||
|
||||
```zig
|
||||
pub fn getSmtpConstructor(globalThis: *JSC.JSGlobalObject, _: *JSC.JSObject) JSC.JSValue {
|
||||
return JSC.API.JSEmailClient.getConstructor(globalThis);
|
||||
}
|
||||
```
|
||||
|
||||
## Best Practices
|
||||
|
||||
1. **Follow Naming Conventions**: Align your naming with existing patterns
|
||||
2. **Reference Existing Modules**: Study similar modules like Valkey or S3Client for guidance
|
||||
3. **Memory Management**: Be careful with memory management and reference counting
|
||||
4. **Error Handling**: Use `bun.JSError!JSValue` for proper error propagation
|
||||
5. **Documentation**: Add JSDoc comments to your JavaScript bindings
|
||||
6. **Testing**: Add tests for your new functionality
|
||||
|
||||
## Common Gotchas
|
||||
|
||||
- Be sure to handle reference counting properly with `ref()`/`deref()`
|
||||
- Always implement proper cleanup in `deinit()` and `finalize()`
|
||||
- For network operations, manage socket lifetimes correctly
|
||||
- Use `JSC.Codegen` correctly to generate necessary binding code
|
||||
|
||||
## Related Files
|
||||
|
||||
- `src/bun.js/bindings/BunObject+exports.h`: Registration of getters and functions
|
||||
- `src/bun.js/api/BunObject.zig`: Implementation of getters and object creation
|
||||
- `src/bun.js/api/BunObject.classes.ts`: Class definitions
|
||||
- `.cursor/rules/zig-javascriptcore-classes.mdc`: More details on class bindings
|
||||
|
||||
## Additional Resources
|
||||
|
||||
For more detailed information on specific topics:
|
||||
|
||||
- See `zig-javascriptcore-classes.mdc` for details on creating JS class bindings
|
||||
- Review existing modules like `valkey`, `sqlite`, or `s3` for real-world examples
|
||||
@@ -11,10 +11,10 @@ You'll find all of Bun's tests in the `test/` directory.
|
||||
* `test/`
|
||||
* `cli/` - CLI command tests, like `bun install` or `bun init`
|
||||
* `js/` - JavaScript & TypeScript tests
|
||||
* `bun/` - `Bun` APIs tests, separated by category, for example: `glob/` for `Bun.Glob` tests
|
||||
* `node/` - Node.js module tests, separated by module, for example: `assert/` for `node:assert` tests
|
||||
* `bun/` - `Bun` APIs tests, seperated by category, for example: `glob/` for `Bun.Glob` tests
|
||||
* `node/` - Node.js module tests, seperated by module, for example: `assert/` for `node:assert` tests
|
||||
* `test/` - Vendored Node.js tests, taken from the Node.js repository (does not conform to Bun's test style)
|
||||
* `web/` - Web API tests, separated by category, for example: `fetch/` for `Request` and `Response` tests
|
||||
* `web/` - Web API tests, seperated by category, for example: `fetch/` for `Request` and `Response` tests
|
||||
* `third_party/` - npm package tests, to validate that basic usage works in Bun
|
||||
* `napi/` - N-API tests
|
||||
* `v8/` - V8 C++ API tests
|
||||
|
||||
@@ -5,6 +5,4 @@
|
||||
#
|
||||
# git config blame.ignoreRevsFile .git-blame-ignore-revs
|
||||
#
|
||||
4ec410e0d7c5f6a712c323444edbf56b48d432d8 # make @import("bun") work in zig (#19096)
|
||||
dedd433cbf2e2fe38e51bc166e08fbcc601ad42b # JSValue.undefined -> .jsUndefined()
|
||||
6b4662ff55f58247cc2fd22e85b4f9805b0950a5 # JSValue.jsUndefined() -> .js_undefined
|
||||
4ec410e0d7c5f6a712c323444edbf56b48d432d8 # make @import("bun") work in zig (#19096)
|
||||
13
.github/CODEOWNERS
vendored
13
.github/CODEOWNERS
vendored
@@ -1,5 +1,18 @@
|
||||
# Project
|
||||
/.github/CODEOWNERS @Jarred-Sumner
|
||||
|
||||
# Build system
|
||||
/CMakeLists.txt @Electroid
|
||||
/cmake/*.cmake @Electroid
|
||||
/scripts/ @Electroid
|
||||
|
||||
# CI
|
||||
/.buildkite/ @Electroid
|
||||
/.github/workflows/ @Electroid
|
||||
|
||||
# Debugger protocol
|
||||
/packages/bun-inspector-protocol/ @Electroid
|
||||
/packages/bun-debug-adapter-protocol/ @Electroid
|
||||
|
||||
# Tests
|
||||
/test/expectations.txt @Jarred-Sumner
|
||||
|
||||
1
.github/ISSUE_TEMPLATE/6-crash-report.yml
vendored
1
.github/ISSUE_TEMPLATE/6-crash-report.yml
vendored
@@ -2,7 +2,6 @@ name: Prefilled crash report
|
||||
description: Report a crash in Bun
|
||||
labels:
|
||||
- crash
|
||||
- needs triage
|
||||
body:
|
||||
- type: markdown
|
||||
attributes:
|
||||
|
||||
58
.github/workflows/codex-test-sync.yml
vendored
58
.github/workflows/codex-test-sync.yml
vendored
@@ -1,58 +0,0 @@
|
||||
name: Codex Test Sync
|
||||
|
||||
on:
|
||||
pull_request:
|
||||
types: [labeled, opened]
|
||||
|
||||
env:
|
||||
BUN_VERSION: "1.2.15"
|
||||
|
||||
jobs:
|
||||
sync-node-tests:
|
||||
runs-on: ubuntu-latest
|
||||
if: |
|
||||
(github.event.action == 'labeled' && github.event.label.name == 'codex') ||
|
||||
(github.event.action == 'opened' && contains(github.event.pull_request.labels.*.name, 'codex')) ||
|
||||
contains(github.head_ref, 'codex')
|
||||
permissions:
|
||||
contents: write
|
||||
pull-requests: write
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
token: ${{ secrets.GITHUB_TOKEN }}
|
||||
fetch-depth: 0
|
||||
|
||||
- name: Setup Bun
|
||||
uses: ./.github/actions/setup-bun
|
||||
with:
|
||||
bun-version: ${{ env.BUN_VERSION }}
|
||||
|
||||
- name: Get changed files
|
||||
id: changed-files
|
||||
uses: tj-actions/changed-files@v44
|
||||
with:
|
||||
files: |
|
||||
test/js/node/test/parallel/**/*.{js,mjs,ts}
|
||||
test/js/node/test/sequential/**/*.{js,mjs,ts}
|
||||
|
||||
- name: Sync tests
|
||||
if: steps.changed-files.outputs.any_changed == 'true'
|
||||
shell: bash
|
||||
run: |
|
||||
echo "Changed test files:"
|
||||
echo "${{ steps.changed-files.outputs.all_changed_files }}"
|
||||
|
||||
# Process each changed test file
|
||||
for file in ${{ steps.changed-files.outputs.all_changed_files }}; do
|
||||
# Extract test name from file path
|
||||
test_name=$(basename "$file" | sed 's/\.[^.]*$//')
|
||||
echo "Syncing test: $test_name"
|
||||
bun node:test:cp "$test_name"
|
||||
done
|
||||
|
||||
- name: Commit changes
|
||||
uses: stefanzweifel/git-auto-commit-action@v5
|
||||
with:
|
||||
commit_message: "Sync Node.js tests with upstream"
|
||||
5
.github/workflows/format.yml
vendored
5
.github/workflows/format.yml
vendored
@@ -44,10 +44,7 @@ jobs:
|
||||
version: 0.14.0
|
||||
- name: Zig Format
|
||||
run: |
|
||||
bun scripts/zig-remove-unreferenced-top-level-decls.ts src/
|
||||
zig fmt src
|
||||
bun scripts/sortImports src
|
||||
zig fmt src
|
||||
zig fmt src/**.zig
|
||||
- name: Commit
|
||||
uses: stefanzweifel/git-auto-commit-action@v5
|
||||
with:
|
||||
|
||||
41
.github/workflows/glob-sources.yml
vendored
41
.github/workflows/glob-sources.yml
vendored
@@ -1,41 +0,0 @@
|
||||
name: Glob Sources
|
||||
|
||||
permissions:
|
||||
contents: write
|
||||
|
||||
on:
|
||||
workflow_call:
|
||||
workflow_dispatch:
|
||||
pull_request:
|
||||
|
||||
env:
|
||||
BUN_VERSION: "1.2.11"
|
||||
|
||||
jobs:
|
||||
glob-sources:
|
||||
name: Glob Sources
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
fetch-depth: 0
|
||||
- name: Configure Git
|
||||
run: |
|
||||
git config --global core.autocrlf true
|
||||
git config --global core.ignorecase true
|
||||
git config --global core.precomposeUnicode true
|
||||
- name: Setup Bun
|
||||
uses: ./.github/actions/setup-bun
|
||||
with:
|
||||
bun-version: ${{ env.BUN_VERSION }}
|
||||
- name: Setup Dependencies
|
||||
run: |
|
||||
bun install
|
||||
- name: Glob sources
|
||||
run: bun scripts/glob-sources.mjs
|
||||
- name: Commit
|
||||
uses: stefanzweifel/git-auto-commit-action@v5
|
||||
with:
|
||||
commit_message: "`bun scripts/glob-sources.mjs`"
|
||||
|
||||
4
.github/workflows/update-cares.yml
vendored
4
.github/workflows/update-cares.yml
vendored
@@ -50,12 +50,12 @@ jobs:
|
||||
exit 1
|
||||
fi
|
||||
|
||||
LATEST_TAG_SHA=$(curl -sL "https://api.github.com/repos/c-ares/c-ares/git/refs/tags/$LATEST_TAG" | jq -r '.object.sha')
|
||||
LATEST_TAG_SHA=$(curl -sL "https://api.github.com/repos/c-ares/c-ares/git/ref/tags/$LATEST_TAG" | jq -r '.object.sha')
|
||||
if [ -z "$LATEST_TAG_SHA" ] || [ "$LATEST_TAG_SHA" = "null" ]; then
|
||||
echo "Error: Could not fetch SHA for tag $LATEST_TAG"
|
||||
exit 1
|
||||
fi
|
||||
LATEST_SHA=$(curl -sL "https://api.github.com/repos/c-ares/c-ares/git/tags/$LATEST_TAG_SHA" | jq -r '.object.sha')
|
||||
LATEST_SHA=$(curl -sL "https://api.github.com/repos/c-ares/c-ares/git/ref/tags/$LATEST_TAG_SHA" | jq -r '.object.sha')
|
||||
if [ -z "$LATEST_SHA" ] || [ "$LATEST_SHA" = "null" ]; then
|
||||
echo "Error: Could not fetch SHA for tag $LATEST_TAG @ $LATEST_TAG_SHA"
|
||||
exit 1
|
||||
|
||||
2
.github/workflows/update-libarchive.yml
vendored
2
.github/workflows/update-libarchive.yml
vendored
@@ -50,7 +50,7 @@ jobs:
|
||||
exit 1
|
||||
fi
|
||||
|
||||
LATEST_TAG_SHA=$(curl -sL "https://api.github.com/repos/libarchive/libarchive/git/refs/tags/$LATEST_TAG" | jq -r '.object.sha')
|
||||
LATEST_TAG_SHA=$(curl -sL "https://api.github.com/repos/libarchive/libarchive/git/ref/tags/$LATEST_TAG" | jq -r '.object.sha')
|
||||
if [ -z "$LATEST_TAG_SHA" ] || [ "$LATEST_TAG_SHA" = "null" ]; then
|
||||
echo "Error: Could not fetch SHA for tag $LATEST_TAG"
|
||||
exit 1
|
||||
|
||||
2
.github/workflows/update-libdeflate.yml
vendored
2
.github/workflows/update-libdeflate.yml
vendored
@@ -50,7 +50,7 @@ jobs:
|
||||
exit 1
|
||||
fi
|
||||
|
||||
LATEST_TAG_SHA=$(curl -sL "https://api.github.com/repos/ebiggers/libdeflate/git/refs/tags/$LATEST_TAG" | jq -r '.object.sha')
|
||||
LATEST_TAG_SHA=$(curl -sL "https://api.github.com/repos/ebiggers/libdeflate/git/ref/tags/$LATEST_TAG" | jq -r '.object.sha')
|
||||
if [ -z "$LATEST_TAG_SHA" ] || [ "$LATEST_TAG_SHA" = "null" ]; then
|
||||
echo "Error: Could not fetch SHA for tag $LATEST_TAG"
|
||||
exit 1
|
||||
|
||||
2
.github/workflows/update-lolhtml.yml
vendored
2
.github/workflows/update-lolhtml.yml
vendored
@@ -50,7 +50,7 @@ jobs:
|
||||
exit 1
|
||||
fi
|
||||
|
||||
LATEST_TAG_SHA=$(curl -sL "https://api.github.com/repos/cloudflare/lol-html/git/refs/tags/$LATEST_TAG" | jq -r '.object.sha')
|
||||
LATEST_TAG_SHA=$(curl -sL "https://api.github.com/repos/cloudflare/lol-html/git/ref/tags/$LATEST_TAG" | jq -r '.object.sha')
|
||||
if [ -z "$LATEST_TAG_SHA" ] || [ "$LATEST_TAG_SHA" = "null" ]; then
|
||||
echo "Error: Could not fetch SHA for tag $LATEST_TAG"
|
||||
exit 1
|
||||
|
||||
2
.github/workflows/update-lshpack.yml
vendored
2
.github/workflows/update-lshpack.yml
vendored
@@ -50,7 +50,7 @@ jobs:
|
||||
exit 1
|
||||
fi
|
||||
|
||||
LATEST_TAG_SHA=$(curl -sL "https://api.github.com/repos/litespeedtech/ls-hpack/git/refs/tags/$LATEST_TAG" | jq -r '.object.sha')
|
||||
LATEST_TAG_SHA=$(curl -sL "https://api.github.com/repos/litespeedtech/ls-hpack/git/ref/tags/$LATEST_TAG" | jq -r '.object.sha')
|
||||
if [ -z "$LATEST_TAG_SHA" ] || [ "$LATEST_TAG_SHA" = "null" ]; then
|
||||
echo "Error: Could not fetch SHA for tag $LATEST_TAG"
|
||||
exit 1
|
||||
|
||||
99
.github/workflows/update-zstd.yml
vendored
99
.github/workflows/update-zstd.yml
vendored
@@ -1,99 +0,0 @@
|
||||
name: Update zstd
|
||||
|
||||
on:
|
||||
schedule:
|
||||
- cron: "0 1 * * 0"
|
||||
workflow_dispatch:
|
||||
|
||||
jobs:
|
||||
check-update:
|
||||
runs-on: ubuntu-latest
|
||||
permissions:
|
||||
contents: write
|
||||
pull-requests: write
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- name: Check zstd version
|
||||
id: check-version
|
||||
run: |
|
||||
set -euo pipefail
|
||||
|
||||
# Extract the commit hash from the line after COMMIT
|
||||
CURRENT_VERSION=$(awk '/[[:space:]]*COMMIT[[:space:]]*$/{getline; gsub(/^[[:space:]]+|[[:space:]]+$/,"",$0); print}' cmake/targets/CloneZstd.cmake)
|
||||
|
||||
if [ -z "$CURRENT_VERSION" ]; then
|
||||
echo "Error: Could not find COMMIT line in CloneZstd.cmake"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Validate that it looks like a git hash
|
||||
if ! [[ $CURRENT_VERSION =~ ^[0-9a-f]{40}$ ]]; then
|
||||
echo "Error: Invalid git hash format in CloneZstd.cmake"
|
||||
echo "Found: $CURRENT_VERSION"
|
||||
echo "Expected: 40 character hexadecimal string"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "current=$CURRENT_VERSION" >> $GITHUB_OUTPUT
|
||||
|
||||
LATEST_RELEASE=$(curl -sL https://api.github.com/repos/facebook/zstd/releases/latest)
|
||||
if [ -z "$LATEST_RELEASE" ]; then
|
||||
echo "Error: Failed to fetch latest release from GitHub API"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
LATEST_TAG=$(echo "$LATEST_RELEASE" | jq -r '.tag_name')
|
||||
if [ -z "$LATEST_TAG" ] || [ "$LATEST_TAG" = "null" ]; then
|
||||
echo "Error: Could not extract tag name from GitHub API response"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
LATEST_TAG_SHA=$(curl -sL "https://api.github.com/repos/facebook/zstd/git/refs/tags/$LATEST_TAG" | jq -r '.object.sha')
|
||||
if [ -z "$LATEST_TAG_SHA" ] || [ "$LATEST_TAG_SHA" = "null" ]; then
|
||||
echo "Error: Could not fetch SHA for tag $LATEST_TAG"
|
||||
exit 1
|
||||
fi
|
||||
LATEST_SHA=$(curl -sL "https://api.github.com/repos/facebook/zstd/git/tags/$LATEST_TAG_SHA" | jq -r '.object.sha')
|
||||
if [ -z "$LATEST_SHA" ] || [ "$LATEST_SHA" = "null" ]; then
|
||||
echo "Error: Could not fetch SHA for tag $LATEST_TAG @ $LATEST_TAG_SHA"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if ! [[ $LATEST_SHA =~ ^[0-9a-f]{40}$ ]]; then
|
||||
echo "Error: Invalid SHA format received from GitHub"
|
||||
echo "Found: $LATEST_SHA"
|
||||
echo "Expected: 40 character hexadecimal string"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "latest=$LATEST_SHA" >> $GITHUB_OUTPUT
|
||||
echo "tag=$LATEST_TAG" >> $GITHUB_OUTPUT
|
||||
|
||||
- name: Update version if needed
|
||||
if: success() && steps.check-version.outputs.current != steps.check-version.outputs.latest
|
||||
run: |
|
||||
set -euo pipefail
|
||||
# Handle multi-line format where COMMIT and its value are on separate lines
|
||||
sed -i -E '/[[:space:]]*COMMIT[[:space:]]*$/{n;s/[[:space:]]*([0-9a-f]+)[[:space:]]*$/ ${{ steps.check-version.outputs.latest }}/}' cmake/targets/CloneZstd.cmake
|
||||
|
||||
- name: Create Pull Request
|
||||
if: success() && steps.check-version.outputs.current != steps.check-version.outputs.latest
|
||||
uses: peter-evans/create-pull-request@v4
|
||||
with:
|
||||
token: ${{ secrets.GITHUB_TOKEN }}
|
||||
add-paths: |
|
||||
cmake/targets/CloneZstd.cmake
|
||||
commit-message: "deps: update zstd to ${{ steps.check-version.outputs.tag }} (${{ steps.check-version.outputs.latest }})"
|
||||
title: "deps: update zstd to ${{ steps.check-version.outputs.tag }}"
|
||||
delete-branch: true
|
||||
branch: deps/update-zstd-${{ github.run_number }}
|
||||
body: |
|
||||
## What does this PR do?
|
||||
|
||||
Updates zstd to version ${{ steps.check-version.outputs.tag }}
|
||||
|
||||
Compare: https://github.com/facebook/zstd/compare/${{ steps.check-version.outputs.current }}...${{ steps.check-version.outputs.latest }}
|
||||
|
||||
Auto-updated by [this workflow](https://github.com/oven-sh/bun/actions/workflows/update-zstd.yml)
|
||||
17
.lldbinit
17
.lldbinit
@@ -1 +1,16 @@
|
||||
command source -C -s true -e true misctools/lldb/init.lldb
|
||||
# Tell LLDB what to do when the debugged process receives SIGPWR: pass it through to the process
|
||||
# (-p), but do not stop the process (-s) or notify the user (-n).
|
||||
#
|
||||
# JSC's garbage collector sends this signal (as configured by Bun WebKit in
|
||||
# Thread::initializePlatformThreading() in ThreadingPOSIX.cpp) to the JS thread to suspend or resume
|
||||
# it. So stopping the process would just create noise when debugging any long-running script.
|
||||
process handle -p true -s false -n false SIGPWR
|
||||
|
||||
command script import misctools/lldb/lldb_pretty_printers.py
|
||||
type category enable zig.lang
|
||||
type category enable zig.std
|
||||
|
||||
command script import misctools/lldb/lldb_webkit.py
|
||||
|
||||
command script delete btjs
|
||||
command alias btjs p {printf("gathering btjs trace...\n");printf("%s\n", (char*)dumpBtjsTrace())}
|
||||
56
.vscode/launch.json
generated
vendored
56
.vscode/launch.json
generated
vendored
@@ -16,7 +16,7 @@
|
||||
"request": "launch",
|
||||
"name": "bun test [file]",
|
||||
"program": "${workspaceFolder}/build/debug/bun-debug",
|
||||
"args": ["test", "--timeout=3600000", "${file}"],
|
||||
"args": ["test", "${file}"],
|
||||
"cwd": "${workspaceFolder}",
|
||||
"env": {
|
||||
"BUN_DEBUG_QUIET_LOGS": "1",
|
||||
@@ -38,7 +38,7 @@
|
||||
"request": "launch",
|
||||
"name": "bun test [file] --only",
|
||||
"program": "${workspaceFolder}/build/debug/bun-debug",
|
||||
"args": ["test", "--timeout=3600000", "--only", "${file}"],
|
||||
"args": ["test", "--only", "${file}"],
|
||||
"cwd": "${workspaceFolder}",
|
||||
"env": {
|
||||
"BUN_DEBUG_QUIET_LOGS": "1",
|
||||
@@ -74,7 +74,7 @@
|
||||
"request": "launch",
|
||||
"name": "bun test [file] (fast)",
|
||||
"program": "${workspaceFolder}/build/debug/bun-debug",
|
||||
"args": ["test", "--timeout=3600000", "${file}"],
|
||||
"args": ["test", "${file}"],
|
||||
"cwd": "${workspaceFolder}",
|
||||
"env": {
|
||||
"BUN_DEBUG_QUIET_LOGS": "1",
|
||||
@@ -96,7 +96,7 @@
|
||||
"request": "launch",
|
||||
"name": "bun test [file] (verbose)",
|
||||
"program": "${workspaceFolder}/build/debug/bun-debug",
|
||||
"args": ["test", "--timeout=3600000", "${file}"],
|
||||
"args": ["test", "${file}"],
|
||||
"cwd": "${workspaceFolder}",
|
||||
"env": {
|
||||
"BUN_DEBUG_QUIET_LOGS": "0",
|
||||
@@ -118,7 +118,7 @@
|
||||
"request": "launch",
|
||||
"name": "bun test [file] --watch",
|
||||
"program": "${workspaceFolder}/build/debug/bun-debug",
|
||||
"args": ["test", "--timeout=3600000", "--watch", "${file}"],
|
||||
"args": ["test", "--watch", "${file}"],
|
||||
"cwd": "${workspaceFolder}",
|
||||
"env": {
|
||||
"BUN_DEBUG_QUIET_LOGS": "1",
|
||||
@@ -140,7 +140,7 @@
|
||||
"request": "launch",
|
||||
"name": "bun test [file] --hot",
|
||||
"program": "${workspaceFolder}/build/debug/bun-debug",
|
||||
"args": ["test", "--timeout=3600000", "--hot", "${file}"],
|
||||
"args": ["test", "--hot", "${file}"],
|
||||
"cwd": "${workspaceFolder}",
|
||||
"env": {
|
||||
"BUN_DEBUG_QUIET_LOGS": "1",
|
||||
@@ -162,7 +162,7 @@
|
||||
"request": "launch",
|
||||
"name": "bun test [file] --inspect",
|
||||
"program": "${workspaceFolder}/build/debug/bun-debug",
|
||||
"args": ["test", "--timeout=3600000", "${file}"],
|
||||
"args": ["test", "${file}"],
|
||||
"cwd": "${workspaceFolder}",
|
||||
"env": {
|
||||
"BUN_DEBUG_QUIET_LOGS": "1",
|
||||
@@ -190,7 +190,7 @@
|
||||
"request": "launch",
|
||||
"name": "bun test [file] --inspect-brk",
|
||||
"program": "${workspaceFolder}/build/debug/bun-debug",
|
||||
"args": ["test", "--timeout=3600000", "${file}"],
|
||||
"args": ["test", "${file}"],
|
||||
"cwd": "${workspaceFolder}",
|
||||
"env": {
|
||||
"BUN_DEBUG_QUIET_LOGS": "1",
|
||||
@@ -386,7 +386,7 @@
|
||||
"request": "launch",
|
||||
"name": "bun test [...]",
|
||||
"program": "${workspaceFolder}/build/debug/bun-debug",
|
||||
"args": ["test", "--timeout=3600000", "${input:testName}"],
|
||||
"args": ["test", "${input:testName}"],
|
||||
"cwd": "${workspaceFolder}",
|
||||
"env": {
|
||||
"BUN_DEBUG_QUIET_LOGS": "1",
|
||||
@@ -408,7 +408,7 @@
|
||||
"request": "launch",
|
||||
"name": "bun test [...] (fast)",
|
||||
"program": "${workspaceFolder}/build/debug/bun-debug",
|
||||
"args": ["test", "--timeout=3600000", "${input:testName}"],
|
||||
"args": ["test", "${input:testName}"],
|
||||
"cwd": "${workspaceFolder}",
|
||||
"env": {
|
||||
"BUN_DEBUG_QUIET_LOGS": "1",
|
||||
@@ -430,7 +430,7 @@
|
||||
"request": "launch",
|
||||
"name": "bun test [...] (verbose)",
|
||||
"program": "${workspaceFolder}/build/debug/bun-debug",
|
||||
"args": ["test", "--timeout=3600000", "${input:testName}"],
|
||||
"args": ["test", "${input:testName}"],
|
||||
"cwd": "${workspaceFolder}",
|
||||
"env": {
|
||||
"BUN_DEBUG_QUIET_LOGS": "1",
|
||||
@@ -452,7 +452,7 @@
|
||||
"request": "launch",
|
||||
"name": "bun test [...] --watch",
|
||||
"program": "${workspaceFolder}/build/debug/bun-debug",
|
||||
"args": ["test", "--timeout=3600000", "--watch", "${input:testName}"],
|
||||
"args": ["test", "--watch", "${input:testName}"],
|
||||
"cwd": "${workspaceFolder}",
|
||||
"env": {
|
||||
"BUN_DEBUG_QUIET_LOGS": "1",
|
||||
@@ -474,7 +474,7 @@
|
||||
"request": "launch",
|
||||
"name": "bun test [...] --hot",
|
||||
"program": "${workspaceFolder}/build/debug/bun-debug",
|
||||
"args": ["test", "--timeout=3600000", "--hot", "${input:testName}"],
|
||||
"args": ["test", "--hot", "${input:testName}"],
|
||||
"cwd": "${workspaceFolder}",
|
||||
"env": {
|
||||
"BUN_DEBUG_QUIET_LOGS": "1",
|
||||
@@ -496,7 +496,7 @@
|
||||
"request": "launch",
|
||||
"name": "bun test [...] --inspect",
|
||||
"program": "${workspaceFolder}/build/debug/bun-debug",
|
||||
"args": ["test", "--timeout=3600000", "${input:testName}"],
|
||||
"args": ["test", "${input:testName}"],
|
||||
"cwd": "${workspaceFolder}",
|
||||
"env": {
|
||||
"BUN_DEBUG_QUIET_LOGS": "1",
|
||||
@@ -524,7 +524,7 @@
|
||||
"request": "launch",
|
||||
"name": "bun test [...] --inspect-brk",
|
||||
"program": "${workspaceFolder}/build/debug/bun-debug",
|
||||
"args": ["test", "--timeout=3600000", "${input:testName}"],
|
||||
"args": ["test", "${input:testName}"],
|
||||
"cwd": "${workspaceFolder}",
|
||||
"env": {
|
||||
"BUN_DEBUG_QUIET_LOGS": "1",
|
||||
@@ -690,7 +690,7 @@
|
||||
"request": "launch",
|
||||
"name": "Windows: bun test [file]",
|
||||
"program": "${workspaceFolder}/build/debug/bun-debug.exe",
|
||||
"args": ["test", "--timeout=3600000", "${file}"],
|
||||
"args": ["test", "${file}"],
|
||||
"cwd": "${workspaceFolder}",
|
||||
"environment": [
|
||||
{
|
||||
@@ -715,7 +715,7 @@
|
||||
"request": "launch",
|
||||
"name": "Windows: bun test --only [file]",
|
||||
"program": "${workspaceFolder}/build/debug/bun-debug.exe",
|
||||
"args": ["test", "--timeout=3600000", "--only", "${file}"],
|
||||
"args": ["test", "--only", "${file}"],
|
||||
"cwd": "${workspaceFolder}",
|
||||
"environment": [
|
||||
{
|
||||
@@ -740,7 +740,7 @@
|
||||
"request": "launch",
|
||||
"name": "Windows: bun test [file] (fast)",
|
||||
"program": "${workspaceFolder}/build/debug/bun-debug.exe",
|
||||
"args": ["test", "--timeout=3600000", "${file}"],
|
||||
"args": ["test", "${file}"],
|
||||
"cwd": "${workspaceFolder}",
|
||||
"environment": [
|
||||
{
|
||||
@@ -765,7 +765,7 @@
|
||||
"request": "launch",
|
||||
"name": "Windows: bun test [file] (verbose)",
|
||||
"program": "${workspaceFolder}/build/debug/bun-debug.exe",
|
||||
"args": ["test", "--timeout=3600000", "${file}"],
|
||||
"args": ["test", "${file}"],
|
||||
"cwd": "${workspaceFolder}",
|
||||
"environment": [
|
||||
{
|
||||
@@ -790,7 +790,7 @@
|
||||
"request": "launch",
|
||||
"name": "Windows: bun test [file] --inspect",
|
||||
"program": "${workspaceFolder}/build/debug/bun-debug.exe",
|
||||
"args": ["test", "--timeout=3600000", "${file}"],
|
||||
"args": ["test", "${file}"],
|
||||
"cwd": "${workspaceFolder}",
|
||||
"environment": [
|
||||
{
|
||||
@@ -824,7 +824,7 @@
|
||||
"request": "launch",
|
||||
"name": "Windows: bun test [file] --inspect-brk",
|
||||
"program": "${workspaceFolder}/build/debug/bun-debug.exe",
|
||||
"args": ["test", "--timeout=3600000", "${file}"],
|
||||
"args": ["test", "${file}"],
|
||||
"cwd": "${workspaceFolder}",
|
||||
"environment": [
|
||||
{
|
||||
@@ -991,7 +991,7 @@
|
||||
"request": "launch",
|
||||
"name": "Windows: bun test [...]",
|
||||
"program": "${workspaceFolder}/build/debug/bun-debug.exe",
|
||||
"args": ["test", "--timeout=3600000", "${input:testName}"],
|
||||
"args": ["test", "${input:testName}"],
|
||||
"cwd": "${workspaceFolder}",
|
||||
"environment": [
|
||||
{
|
||||
@@ -1016,7 +1016,7 @@
|
||||
"request": "launch",
|
||||
"name": "Windows: bun test [...] (fast)",
|
||||
"program": "${workspaceFolder}/build/debug/bun-debug.exe",
|
||||
"args": ["test", "--timeout=3600000", "${input:testName}"],
|
||||
"args": ["test", "${input:testName}"],
|
||||
"cwd": "${workspaceFolder}",
|
||||
"environment": [
|
||||
{
|
||||
@@ -1041,7 +1041,7 @@
|
||||
"request": "launch",
|
||||
"name": "Windows: bun test [...] (verbose)",
|
||||
"program": "${workspaceFolder}/build/debug/bun-debug.exe",
|
||||
"args": ["test", "--timeout=3600000", "${input:testName}"],
|
||||
"args": ["test", "${input:testName}"],
|
||||
"cwd": "${workspaceFolder}",
|
||||
"environment": [
|
||||
{
|
||||
@@ -1066,7 +1066,7 @@
|
||||
"request": "launch",
|
||||
"name": "Windows: bun test [...] --watch",
|
||||
"program": "${workspaceFolder}/build/debug/bun-debug.exe",
|
||||
"args": ["test", "--timeout=3600000", "--watch", "${input:testName}"],
|
||||
"args": ["test", "--watch", "${input:testName}"],
|
||||
"cwd": "${workspaceFolder}",
|
||||
"environment": [
|
||||
{
|
||||
@@ -1091,7 +1091,7 @@
|
||||
"request": "launch",
|
||||
"name": "Windows: bun test [...] --hot",
|
||||
"program": "${workspaceFolder}/build/debug/bun-debug.exe",
|
||||
"args": ["test", "--timeout=3600000", "--hot", "${input:testName}"],
|
||||
"args": ["test", "--hot", "${input:testName}"],
|
||||
"cwd": "${workspaceFolder}",
|
||||
"environment": [
|
||||
{
|
||||
@@ -1116,7 +1116,7 @@
|
||||
"request": "launch",
|
||||
"name": "Windows: bun test [...] --inspect",
|
||||
"program": "${workspaceFolder}/build/debug/bun-debug.exe",
|
||||
"args": ["test", "--timeout=3600000", "${input:testName}"],
|
||||
"args": ["test", "${input:testName}"],
|
||||
"cwd": "${workspaceFolder}",
|
||||
"environment": [
|
||||
{
|
||||
@@ -1150,7 +1150,7 @@
|
||||
"request": "launch",
|
||||
"name": "Windows: bun test [...] --inspect-brk",
|
||||
"program": "${workspaceFolder}/build/debug/bun-debug.exe",
|
||||
"args": ["test", "--timeout=3600000", "${input:testName}"],
|
||||
"args": ["test", "${input:testName}"],
|
||||
"cwd": "${workspaceFolder}",
|
||||
"environment": [
|
||||
{
|
||||
|
||||
36
AGENTS.md
Normal file
36
AGENTS.md
Normal file
@@ -0,0 +1,36 @@
|
||||
## bun tests
|
||||
|
||||
**IMPORTANT**: use the `bun agent` command instead of the `bun` command. For example:
|
||||
|
||||
✅ Good
|
||||
|
||||
```sh
|
||||
bun agent test internal/ban-words.test.ts
|
||||
bun agent ./foo.ts
|
||||
```
|
||||
|
||||
The `bun agent` command runs the DEBUG build. If you forget to run the debug build, your changes will not be reflected..
|
||||
|
||||
### Run a file
|
||||
|
||||
To run a file, you can use the `bun agent <file-path>` command.
|
||||
|
||||
```sh
|
||||
bun agent ./foo.ts
|
||||
```
|
||||
|
||||
### Run tests
|
||||
|
||||
To run a single test, you need to use the `bun agent test <test-name>` command.
|
||||
|
||||
```sh
|
||||
bun agent test internal/ban-words.test.ts
|
||||
```
|
||||
|
||||
You must ALWAYS make sure to pass a file path to the `bun agent test <file-path>` command. DO NOT try to run ALL the tests at once unless you're in a specific subdirectory.
|
||||
|
||||
### Run a Node.js test
|
||||
|
||||
```sh
|
||||
bun agent --silent node:test test-fs-link
|
||||
```
|
||||
245
CLAUDE.md
245
CLAUDE.md
@@ -1,245 +0,0 @@
|
||||
This is the Bun repository - an all-in-one JavaScript runtime & toolkit designed for speed, with a bundler, test runner, and Node.js-compatible package manager. It's written primarily in Zig with C++ for JavaScriptCore integration, powered by WebKit's JavaScriptCore engine.
|
||||
|
||||
## Building and Running Bun
|
||||
|
||||
### Build Commands
|
||||
|
||||
- **Build debug version**: `bun bd` or `bun run build:debug`
|
||||
- Creates a debug build at `./build/debug/bun-debug`
|
||||
- Compilation takes ~2.5 minutes
|
||||
- **Run tests with your debug build**: `bun bd test <test-file>`
|
||||
- **CRITICAL**: Never use `bun test` directly - it won't include your changes
|
||||
- **Run any command with debug build**: `bun bd <command>`
|
||||
|
||||
### Other Build Variants
|
||||
|
||||
- `bun run build:release` - Release build
|
||||
|
||||
Address sanitizer is enabled by default in debug builds of Bun.
|
||||
|
||||
## Testing
|
||||
|
||||
### Running Tests
|
||||
|
||||
- **Single test file**: `bun bd test test/js/bun/http/serve.test.ts`
|
||||
- **Fuzzy match test file**: `bun bd test http/serve.test.ts`
|
||||
- **With filter**: `bun bd test test/js/bun/http/serve.test.ts -t "should handle"`
|
||||
|
||||
### Test Organization
|
||||
|
||||
- `test/js/bun/` - Bun-specific API tests (http, crypto, ffi, shell, etc.)
|
||||
- `test/js/node/` - Node.js compatibility tests
|
||||
- `test/js/web/` - Web API tests (fetch, WebSocket, streams, etc.)
|
||||
- `test/cli/` - CLI command tests (install, run, test, etc.)
|
||||
- `test/regression/issue/` - Regression tests (create one per bug fix)
|
||||
- `test/bundler/` - Bundler and transpiler tests
|
||||
- `test/integration/` - End-to-end integration tests
|
||||
- `test/napi/` - N-API compatibility tests
|
||||
- `test/v8/` - V8 C++ API compatibility tests
|
||||
|
||||
### Writing Tests
|
||||
|
||||
Tests use Bun's Jest-compatible test runner with proper test fixtures:
|
||||
|
||||
```typescript
|
||||
import { test, expect } from "bun:test";
|
||||
import { bunEnv, bunExe, tempDirWithFiles } from "harness";
|
||||
|
||||
test("my feature", async () => {
|
||||
// Create temp directory with test files
|
||||
const dir = tempDirWithFiles("test-prefix", {
|
||||
"index.js": `console.log("hello");`,
|
||||
});
|
||||
|
||||
// Spawn Bun process
|
||||
await using proc = Bun.spawn({
|
||||
cmd: [bunExe(), "index.js"],
|
||||
env: bunEnv,
|
||||
cwd: dir,
|
||||
});
|
||||
|
||||
const [stdout, stderr, exitCode] = await Promise.all([
|
||||
new Response(proc.stdout).text(),
|
||||
new Response(proc.stderr).text(),
|
||||
proc.exited,
|
||||
]);
|
||||
|
||||
expect(exitCode).toBe(0);
|
||||
expect(stdout).toBe("hello\n");
|
||||
});
|
||||
```
|
||||
|
||||
## Code Architecture
|
||||
|
||||
### Language Structure
|
||||
|
||||
- **Zig code** (`src/*.zig`): Core runtime, JavaScript bindings, package manager
|
||||
- **C++ code** (`src/bun.js/bindings/*.cpp`): JavaScriptCore bindings, Web APIs
|
||||
- **TypeScript** (`src/js/`): Built-in JavaScript modules with special syntax (see JavaScript Modules section)
|
||||
- **Generated code**: Many files are auto-generated from `.classes.ts` and other sources
|
||||
|
||||
### Core Source Organization
|
||||
|
||||
#### Runtime Core (`src/`)
|
||||
|
||||
- `bun.zig` - Main entry point
|
||||
- `cli.zig` - CLI command orchestration
|
||||
- `js_parser.zig`, `js_lexer.zig`, `js_printer.zig` - JavaScript parsing/printing
|
||||
- `transpiler.zig` - Wrapper around js_parser with sourcemap support
|
||||
- `resolver/` - Module resolution system
|
||||
- `allocators/` - Custom memory allocators for performance
|
||||
|
||||
#### JavaScript Runtime (`src/bun.js/`)
|
||||
|
||||
- `bindings/` - C++ JavaScriptCore bindings
|
||||
- Generated classes from `.classes.ts` files
|
||||
- Manual bindings for complex APIs
|
||||
- `api/` - Bun-specific APIs
|
||||
- `server.zig` - HTTP server implementation
|
||||
- `FFI.zig` - Foreign Function Interface
|
||||
- `crypto.zig` - Cryptographic operations
|
||||
- `glob.zig` - File pattern matching
|
||||
- `node/` - Node.js compatibility layer
|
||||
- Module implementations (fs, path, crypto, etc.)
|
||||
- Process and Buffer APIs
|
||||
- `webcore/` - Web API implementations
|
||||
- `fetch.zig` - Fetch API
|
||||
- `streams.zig` - Web Streams
|
||||
- `Blob.zig`, `Response.zig`, `Request.zig`
|
||||
- `event_loop/` - Event loop and task management
|
||||
|
||||
#### Build Tools & Package Manager
|
||||
|
||||
- `src/bundler/` - JavaScript bundler
|
||||
- Advanced tree-shaking
|
||||
- CSS processing
|
||||
- HTML handling
|
||||
- `src/install/` - Package manager
|
||||
- `lockfile/` - Lockfile handling
|
||||
- `npm.zig` - npm registry client
|
||||
- `lifecycle_script_runner.zig` - Package scripts
|
||||
|
||||
#### Other Key Components
|
||||
|
||||
- `src/shell/` - Cross-platform shell implementation
|
||||
- `src/css/` - CSS parser and processor
|
||||
- `src/http/` - HTTP client implementation
|
||||
- `websocket_client/` - WebSocket client (including deflate support)
|
||||
- `src/sql/` - SQL database integrations
|
||||
- `src/bake/` - Server-side rendering framework
|
||||
|
||||
### JavaScript Class Implementation (C++)
|
||||
|
||||
When implementing JavaScript classes in C++:
|
||||
|
||||
1. Create three classes if there's a public constructor:
|
||||
|
||||
- `class Foo : public JSC::JSDestructibleObject` (if has C++ fields)
|
||||
- `class FooPrototype : public JSC::JSNonFinalObject`
|
||||
- `class FooConstructor : public JSC::InternalFunction`
|
||||
|
||||
2. Define properties using HashTableValue arrays
|
||||
3. Add iso subspaces for classes with C++ fields
|
||||
4. Cache structures in ZigGlobalObject
|
||||
|
||||
## Development Workflow
|
||||
|
||||
### Code Formatting
|
||||
|
||||
- `bun run prettier` - Format JS/TS files
|
||||
- `bun run zig-format` - Format Zig files
|
||||
- `bun run clang-format` - Format C++ files
|
||||
|
||||
### Watching for Changes
|
||||
|
||||
- `bun run watch` - Incremental Zig compilation with error checking
|
||||
- `bun run watch-windows` - Windows-specific watch mode
|
||||
|
||||
### Code Generation
|
||||
|
||||
Code generation happens automatically as part of the build process. The main scripts are:
|
||||
|
||||
- `src/codegen/generate-classes.ts` - Generates Zig & C++ bindings from `*.classes.ts` files
|
||||
- `src/codegen/generate-jssink.ts` - Generates stream-related classes
|
||||
- `src/codegen/bundle-modules.ts` - Bundles built-in modules like `node:fs`
|
||||
- `src/codegen/bundle-functions.ts` - Bundles global functions like `ReadableStream`
|
||||
|
||||
In development, bundled modules can be reloaded without rebuilding Zig by running `bun run build`.
|
||||
|
||||
## JavaScript Modules (`src/js/`)
|
||||
|
||||
Built-in JavaScript modules use special syntax and are organized as:
|
||||
|
||||
- `node/` - Node.js compatibility modules (`node:fs`, `node:path`, etc.)
|
||||
- `bun/` - Bun-specific modules (`bun:ffi`, `bun:sqlite`, etc.)
|
||||
- `thirdparty/` - NPM modules we replace (like `ws`)
|
||||
- `internal/` - Internal modules not exposed to users
|
||||
- `builtins/` - Core JavaScript builtins (streams, console, etc.)
|
||||
|
||||
### Special Syntax in Built-in Modules
|
||||
|
||||
1. **`$` prefix** - Access to private properties and JSC intrinsics:
|
||||
|
||||
```js
|
||||
const arr = $Array.from(...); // Private global
|
||||
map.$set(...); // Private method
|
||||
const arr2 = $newArrayWithSize(5); // JSC intrinsic
|
||||
```
|
||||
|
||||
2. **`require()`** - Must use string literals, resolved at compile time:
|
||||
|
||||
```js
|
||||
const fs = require("fs"); // Directly loads by numeric ID
|
||||
```
|
||||
|
||||
3. **Debug helpers**:
|
||||
|
||||
- `$debug()` - Like console.log but stripped in release builds
|
||||
- `$assert()` - Assertions stripped in release builds
|
||||
- `if($debug) {}` - Check if debug env var is set
|
||||
|
||||
4. **Platform detection**: `process.platform` and `process.arch` are inlined and dead-code eliminated
|
||||
|
||||
5. **Export syntax**: Use `export default` which gets converted to a return statement:
|
||||
```js
|
||||
export default {
|
||||
readFile,
|
||||
writeFile,
|
||||
};
|
||||
```
|
||||
|
||||
Note: These are NOT ES modules. The preprocessor converts `$` to `@` (JSC's actual syntax) and handles the special functions.
|
||||
|
||||
## CI
|
||||
|
||||
Bun uses BuildKite for CI. To get the status of a PR, you can use the following command:
|
||||
|
||||
```bash
|
||||
bun ci
|
||||
```
|
||||
|
||||
## Important Development Notes
|
||||
|
||||
1. **Never use `bun test` or `bun <file>` directly** - always use `bun bd test` or `bun bd <command>`. `bun bd` compiles & runs the debug build.
|
||||
2. **Use `await using`** for proper resource cleanup with Bun APIs (Bun.spawn, Bun.serve, Bun.connect, etc.)
|
||||
3. **Follow existing code style** - check neighboring files for patterns
|
||||
4. **Create regression tests** in `test/regression/issue/` when fixing bugs
|
||||
5. **Use absolute paths** - Always use absolute paths in file operations
|
||||
6. **Avoid shell commands** - Don't use `find` or `grep` in tests; use Bun's Glob and built-in tools
|
||||
7. **Memory management** - In Zig code, be careful with allocators and use defer for cleanup
|
||||
8. **Cross-platform** - Test on macOS, Linux, and Windows when making platform-specific changes
|
||||
9. **Debug builds** - Use `BUN_DEBUG_QUIET_LOGS=1` to disable debug logging, or `BUN_DEBUG_<scope>=1` to enable specific scopes
|
||||
10. **Transpiled source** - Find transpiled files in `/tmp/bun-debug-src/` for debugging
|
||||
|
||||
## Key APIs and Features
|
||||
|
||||
### Bun-Specific APIs
|
||||
|
||||
- **Bun.serve()** - High-performance HTTP server
|
||||
- **Bun.spawn()** - Process spawning with better performance than Node.js
|
||||
- **Bun.file()** - Fast file I/O operations
|
||||
- **Bun.write()** - Unified API for writing to files, stdout, etc.
|
||||
- **Bun.$ (Shell)** - Cross-platform shell scripting
|
||||
- **Bun.SQLite** - Native SQLite integration
|
||||
- **Bun.FFI** - Call native libraries from JavaScript
|
||||
- **Bun.Glob** - Fast file pattern matching
|
||||
@@ -144,14 +144,6 @@ $ bun bd test foo.test.ts
|
||||
$ bun bd ./foo.ts
|
||||
```
|
||||
|
||||
Bun generally takes about 2.5 minutes to compile a debug build when there are Zig changes. If your development workflow is "change one line, save, rebuild", you will spend too much time waiting for the build to finish. Instead:
|
||||
|
||||
- Batch up your changes
|
||||
- Ensure zls is running with incremental watching for LSP errors (if you use VSCode and install Zig and run `bun run build` once to download Zig, this should just work)
|
||||
- Prefer using the debugger ("CodeLLDB" in VSCode) to step through the code.
|
||||
- Use debug logs. `BUN_DEBUG_<scope>=1` will enable debug logging for the corresponding `Output.scoped(.<scope>, false)` logs. You can also set `BUN_DEBUG_QUIET_LOGS=1` to disable all debug logging that isn't explicitly enabled. To dump debug lgos into a file, `BUN_DEBUG=<path-to-file>.log`. Debug logs are aggressively removed in release builds.
|
||||
- src/js/\*\*.ts changes are pretty much instant to rebuild. C++ changes are a bit slower, but still much faster than the Zig code (Zig is one compilation unit, C++ is many).
|
||||
|
||||
## Code generation scripts
|
||||
|
||||
Several code generation scripts are used during Bun's build process. These are run automatically when changes are made to certain files.
|
||||
@@ -187,7 +179,6 @@ To run a release build from a pull request, you can use the `bun-pr` npm package
|
||||
bunx bun-pr <pr-number>
|
||||
bunx bun-pr <branch-name>
|
||||
bunx bun-pr "https://github.com/oven-sh/bun/pull/1234566"
|
||||
bunx bun-pr --asan <pr-number> # Linux x64 only
|
||||
```
|
||||
|
||||
This will download the release build from the pull request and add it to `$PATH` as `bun-${pr-number}`. You can then run the build with `bun-${pr-number}`.
|
||||
@@ -198,18 +189,24 @@ bun-1234566 --version
|
||||
|
||||
This works by downloading the release build from the GitHub Actions artifacts on the linked pull request. You may need the `gh` CLI installed to authenticate with GitHub.
|
||||
|
||||
## AddressSanitizer
|
||||
## Valgrind
|
||||
|
||||
[AddressSanitizer](https://en.wikipedia.org/wiki/AddressSanitizer) helps find memory issues, and is enabled by default in debug builds of Bun on Linux and macOS. This includes the Zig code and all dependencies. It makes the Zig code take about 2x longer to build, if that's stopping you from being productive you can disable it by setting `-Denable_asan=$<IF:$<BOOL:${ENABLE_ASAN}>,true,false>` to `-Denable_asan=false` in the `cmake/targets/BuildBun.cmake` file, but generally we recommend batching your changes up between builds.
|
||||
On Linux, valgrind can help find memory issues.
|
||||
|
||||
To build a release build with Address Sanitizer, run:
|
||||
Keep in mind:
|
||||
|
||||
- JavaScriptCore doesn't support valgrind. It will report spurious errors.
|
||||
- Valgrind is slow
|
||||
- Mimalloc will sometimes cause spurious errors when debug build is enabled
|
||||
|
||||
You'll need a very recent version of Valgrind due to DWARF 5 debug symbols. You may need to manually compile Valgrind instead of using it from your Linux package manager.
|
||||
|
||||
`--fair-sched=try` is necessary if running multithreaded code in Bun (such as the bundler). Otherwise it will hang.
|
||||
|
||||
```bash
|
||||
$ bun run build:release:asan
|
||||
$ valgrind --fair-sched=try --track-origins=yes bun-debug <args>
|
||||
```
|
||||
|
||||
In CI, we run our test suite with at least one target that is built with Address Sanitizer.
|
||||
|
||||
## Building WebKit locally + Debug mode of JSC
|
||||
|
||||
WebKit is not cloned by default (to save time and disk space). To clone and build WebKit locally, run:
|
||||
|
||||
2
Makefile
2
Makefile
@@ -482,7 +482,7 @@ STATIC_MUSL_FLAG ?=
|
||||
WRAP_SYMBOLS_ON_LINUX =
|
||||
|
||||
ifeq ($(OS_NAME), linux)
|
||||
WRAP_SYMBOLS_ON_LINUX = -Wl,--wrap=fcntl -Wl,--wrap=fcntl64 -Wl,--wrap=stat64 -Wl,--wrap=pow -Wl,--wrap=exp -Wl,--wrap=exp2 -Wl,--wrap=log -Wl,--wrap=log2 \
|
||||
WRAP_SYMBOLS_ON_LINUX = -Wl,--wrap=fcntl -Wl,--wrap=fcntl64 -Wl,--wrap=stat64 -Wl,--wrap=pow -Wl,--wrap=exp -Wl,--wrap=log -Wl,--wrap=log2 \
|
||||
-Wl,--wrap=lstat \
|
||||
-Wl,--wrap=stat \
|
||||
-Wl,--wrap=fstat \
|
||||
|
||||
@@ -47,8 +47,6 @@ Bun supports Linux (x64 & arm64), macOS (x64 & Apple Silicon) and Windows (x64).
|
||||
|
||||
> **Linux users** — Kernel version 5.6 or higher is strongly recommended, but the minimum is 5.1.
|
||||
|
||||
> **x64 users** — if you see "illegal instruction" or similar errors, check our [CPU requirements](https://bun.sh/docs/installation#cpu-requirements-and-baseline-builds)
|
||||
|
||||
```sh
|
||||
# with install script (recommended)
|
||||
curl -fsSL https://bun.sh/install | bash
|
||||
|
||||
@@ -50,10 +50,6 @@ bench("murmur64v2 (short)", () => {
|
||||
Bun.hash.murmur64v2(shortStr);
|
||||
});
|
||||
|
||||
bench("rapidhash (short)", () => {
|
||||
Bun.hash.rapidhash(shortStr);
|
||||
});
|
||||
|
||||
bench("wyhash (128 KB)", () => {
|
||||
Bun.hash.wyhash(longStr);
|
||||
});
|
||||
@@ -98,8 +94,4 @@ bench("murmur64v2 (128 KB)", () => {
|
||||
Bun.hash.murmur64v2(longStr);
|
||||
});
|
||||
|
||||
bench("rapidhash (128 KB)", () => {
|
||||
Bun.hash.rapidhash(longStr);
|
||||
});
|
||||
|
||||
run();
|
||||
|
||||
27
build.zig
27
build.zig
@@ -63,7 +63,6 @@ const BunBuildOptions = struct {
|
||||
/// `./build/codegen` or equivalent
|
||||
codegen_path: []const u8,
|
||||
no_llvm: bool,
|
||||
override_no_export_cpp_apis: bool,
|
||||
|
||||
cached_options_module: ?*Module = null,
|
||||
windows_shim: ?WindowsShim = null,
|
||||
@@ -96,7 +95,6 @@ const BunBuildOptions = struct {
|
||||
opts.addOption(bool, "enable_asan", this.enable_asan);
|
||||
opts.addOption([]const u8, "reported_nodejs_version", b.fmt("{}", .{this.reported_nodejs_version}));
|
||||
opts.addOption(bool, "zig_self_hosted_backend", this.no_llvm);
|
||||
opts.addOption(bool, "override_no_export_cpp_apis", this.override_no_export_cpp_apis);
|
||||
|
||||
const mod = opts.createModule();
|
||||
this.cached_options_module = mod;
|
||||
@@ -208,7 +206,6 @@ pub fn build(b: *Build) !void {
|
||||
const obj_format = b.option(ObjectFormat, "obj_format", "Output file for object files") orelse .obj;
|
||||
|
||||
const no_llvm = b.option(bool, "no_llvm", "Experiment with Zig self hosted backends. No stability guaranteed") orelse false;
|
||||
const override_no_export_cpp_apis = b.option(bool, "override-no-export-cpp-apis", "Override the default export_cpp_apis logic to disable exports") orelse false;
|
||||
|
||||
var build_options = BunBuildOptions{
|
||||
.target = target,
|
||||
@@ -220,7 +217,6 @@ pub fn build(b: *Build) !void {
|
||||
.codegen_path = codegen_path,
|
||||
.codegen_embed = codegen_embed,
|
||||
.no_llvm = no_llvm,
|
||||
.override_no_export_cpp_apis = override_no_export_cpp_apis,
|
||||
|
||||
.version = try Version.parse(bun_version),
|
||||
.canary_revision = canary: {
|
||||
@@ -390,12 +386,6 @@ pub fn build(b: *Build) !void {
|
||||
.{ .os = .windows, .arch = .x86_64 },
|
||||
}, &.{ .Debug, .ReleaseFast });
|
||||
}
|
||||
{
|
||||
const step = b.step("check-windows-debug", "Check for semantic analysis errors on Windows");
|
||||
addMultiCheck(b, step, build_options, &.{
|
||||
.{ .os = .windows, .arch = .x86_64 },
|
||||
}, &.{.Debug});
|
||||
}
|
||||
{
|
||||
const step = b.step("check-macos", "Check for semantic analysis errors on Windows");
|
||||
addMultiCheck(b, step, build_options, &.{
|
||||
@@ -403,13 +393,6 @@ pub fn build(b: *Build) !void {
|
||||
.{ .os = .mac, .arch = .aarch64 },
|
||||
}, &.{ .Debug, .ReleaseFast });
|
||||
}
|
||||
{
|
||||
const step = b.step("check-macos-debug", "Check for semantic analysis errors on Windows");
|
||||
addMultiCheck(b, step, build_options, &.{
|
||||
.{ .os = .mac, .arch = .x86_64 },
|
||||
.{ .os = .mac, .arch = .aarch64 },
|
||||
}, &.{.Debug});
|
||||
}
|
||||
{
|
||||
const step = b.step("check-linux", "Check for semantic analysis errors on Windows");
|
||||
addMultiCheck(b, step, build_options, &.{
|
||||
@@ -417,13 +400,6 @@ pub fn build(b: *Build) !void {
|
||||
.{ .os = .linux, .arch = .aarch64 },
|
||||
}, &.{ .Debug, .ReleaseFast });
|
||||
}
|
||||
{
|
||||
const step = b.step("check-linux-debug", "Check for semantic analysis errors on Windows");
|
||||
addMultiCheck(b, step, build_options, &.{
|
||||
.{ .os = .linux, .arch = .x86_64 },
|
||||
.{ .os = .linux, .arch = .aarch64 },
|
||||
}, &.{.Debug});
|
||||
}
|
||||
|
||||
// zig build translate-c-headers
|
||||
{
|
||||
@@ -500,7 +476,6 @@ fn addMultiCheck(
|
||||
.codegen_path = root_build_options.codegen_path,
|
||||
.no_llvm = root_build_options.no_llvm,
|
||||
.enable_asan = root_build_options.enable_asan,
|
||||
.override_no_export_cpp_apis = root_build_options.override_no_export_cpp_apis,
|
||||
};
|
||||
|
||||
var obj = addBunObject(b, &options);
|
||||
@@ -533,8 +508,6 @@ fn getTranslateC(b: *Build, initial_target: std.Build.ResolvedTarget, optimize:
|
||||
translate_c.defineCMacroRaw(b.fmt("{s}={d}", .{ str, @intFromBool(value) }));
|
||||
}
|
||||
|
||||
translate_c.addIncludePath(b.path("vendor/zstd/lib"));
|
||||
|
||||
if (target.result.os.tag == .windows) {
|
||||
// translate-c is unable to translate the unsuffixed windows functions
|
||||
// like `SetCurrentDirectory` since they are defined with an odd macro
|
||||
|
||||
@@ -44,12 +44,10 @@
|
||||
"src/bun.js/bindings/webcrypto/*/*.cpp",
|
||||
"src/bun.js/bindings/node/*.cpp",
|
||||
"src/bun.js/bindings/node/crypto/*.cpp",
|
||||
"src/bun.js/bindings/node/http/*.cpp",
|
||||
"src/bun.js/bindings/v8/*.cpp",
|
||||
"src/bun.js/bindings/v8/shim/*.cpp",
|
||||
"src/bake/*.cpp",
|
||||
"src/deps/*.cpp",
|
||||
"src/vm/*.cpp",
|
||||
"packages/bun-usockets/src/crypto/*.cpp"
|
||||
]
|
||||
},
|
||||
@@ -61,9 +59,7 @@
|
||||
"packages/bun-usockets/src/internal/*.c",
|
||||
"packages/bun-usockets/src/crypto/*.c",
|
||||
"src/bun.js/bindings/uv-posix-polyfills.c",
|
||||
"src/bun.js/bindings/uv-posix-stubs.c",
|
||||
"src/*.c",
|
||||
"src/bun.js/bindings/node/http/llhttp/*.c"
|
||||
"src/bun.js/bindings/uv-posix-stubs.c"
|
||||
]
|
||||
}
|
||||
]
|
||||
|
||||
@@ -20,4 +20,4 @@ src/bake/hmr-runtime-client.ts
|
||||
src/bake/hmr-runtime-error.ts
|
||||
src/bake/hmr-runtime-server.ts
|
||||
src/bake/server/stack-trace-stub.ts
|
||||
src/bake/shared.ts
|
||||
src/bake/shared.ts
|
||||
@@ -4,4 +4,4 @@ src/bun.js/api/BunObject.bind.ts
|
||||
src/bun.js/bindgen_test.bind.ts
|
||||
src/bun.js/bindings/NodeModuleModule.bind.ts
|
||||
src/bun.js/node/node_os.bind.ts
|
||||
src/fmt.bind.ts
|
||||
src/fmt.bind.ts
|
||||
@@ -9,4 +9,4 @@ packages/bun-error/package.json
|
||||
packages/bun-error/runtime-error.ts
|
||||
packages/bun-error/sourcemap.ts
|
||||
packages/bun-error/stack-trace-parser.ts
|
||||
packages/bun-error/tsconfig.json
|
||||
packages/bun-error/tsconfig.json
|
||||
@@ -7,9 +7,5 @@ packages/bun-usockets/src/loop.c
|
||||
packages/bun-usockets/src/quic.c
|
||||
packages/bun-usockets/src/socket.c
|
||||
packages/bun-usockets/src/udp.c
|
||||
src/asan-config.c
|
||||
src/bun.js/bindings/node/http/llhttp/api.c
|
||||
src/bun.js/bindings/node/http/llhttp/http.c
|
||||
src/bun.js/bindings/node/http/llhttp/llhttp.c
|
||||
src/bun.js/bindings/uv-posix-polyfills.c
|
||||
src/bun.js/bindings/uv-posix-stubs.c
|
||||
src/bun.js/bindings/uv-posix-stubs.c
|
||||
@@ -28,7 +28,6 @@ src/bun.js/bindings/BunWorkerGlobalScope.cpp
|
||||
src/bun.js/bindings/c-bindings.cpp
|
||||
src/bun.js/bindings/CallSite.cpp
|
||||
src/bun.js/bindings/CallSitePrototype.cpp
|
||||
src/bun.js/bindings/CatchScopeBinding.cpp
|
||||
src/bun.js/bindings/CodeCoverage.cpp
|
||||
src/bun.js/bindings/ConsoleObject.cpp
|
||||
src/bun.js/bindings/Cookie.cpp
|
||||
@@ -81,9 +80,6 @@ src/bun.js/bindings/JSEnvironmentVariableMap.cpp
|
||||
src/bun.js/bindings/JSFFIFunction.cpp
|
||||
src/bun.js/bindings/JSMockFunction.cpp
|
||||
src/bun.js/bindings/JSNextTickQueue.cpp
|
||||
src/bun.js/bindings/JSNodePerformanceHooksHistogram.cpp
|
||||
src/bun.js/bindings/JSNodePerformanceHooksHistogramConstructor.cpp
|
||||
src/bun.js/bindings/JSNodePerformanceHooksHistogramPrototype.cpp
|
||||
src/bun.js/bindings/JSPropertyIterator.cpp
|
||||
src/bun.js/bindings/JSS3File.cpp
|
||||
src/bun.js/bindings/JSSocketAddressDTO.cpp
|
||||
@@ -100,9 +96,6 @@ src/bun.js/bindings/napi_finalizer.cpp
|
||||
src/bun.js/bindings/napi_handle_scope.cpp
|
||||
src/bun.js/bindings/napi_type_tag.cpp
|
||||
src/bun.js/bindings/napi.cpp
|
||||
src/bun.js/bindings/NapiClass.cpp
|
||||
src/bun.js/bindings/NapiRef.cpp
|
||||
src/bun.js/bindings/NapiWeakValue.cpp
|
||||
src/bun.js/bindings/ncrpyto_engine.cpp
|
||||
src/bun.js/bindings/ncrypto.cpp
|
||||
src/bun.js/bindings/node/crypto/CryptoDhJob.cpp
|
||||
@@ -148,13 +141,6 @@ src/bun.js/bindings/node/crypto/JSSign.cpp
|
||||
src/bun.js/bindings/node/crypto/JSVerify.cpp
|
||||
src/bun.js/bindings/node/crypto/KeyObject.cpp
|
||||
src/bun.js/bindings/node/crypto/node_crypto_binding.cpp
|
||||
src/bun.js/bindings/node/http/JSConnectionsList.cpp
|
||||
src/bun.js/bindings/node/http/JSConnectionsListConstructor.cpp
|
||||
src/bun.js/bindings/node/http/JSConnectionsListPrototype.cpp
|
||||
src/bun.js/bindings/node/http/JSHTTPParser.cpp
|
||||
src/bun.js/bindings/node/http/JSHTTPParserConstructor.cpp
|
||||
src/bun.js/bindings/node/http/JSHTTPParserPrototype.cpp
|
||||
src/bun.js/bindings/node/http/NodeHTTPParser.cpp
|
||||
src/bun.js/bindings/node/NodeTimers.cpp
|
||||
src/bun.js/bindings/NodeAsyncHooks.cpp
|
||||
src/bun.js/bindings/NodeDirent.cpp
|
||||
@@ -167,10 +153,6 @@ src/bun.js/bindings/NodeTLS.cpp
|
||||
src/bun.js/bindings/NodeURL.cpp
|
||||
src/bun.js/bindings/NodeValidator.cpp
|
||||
src/bun.js/bindings/NodeVM.cpp
|
||||
src/bun.js/bindings/NodeVMModule.cpp
|
||||
src/bun.js/bindings/NodeVMScript.cpp
|
||||
src/bun.js/bindings/NodeVMSourceTextModule.cpp
|
||||
src/bun.js/bindings/NodeVMSyntheticModule.cpp
|
||||
src/bun.js/bindings/NoOpForTesting.cpp
|
||||
src/bun.js/bindings/ObjectBindings.cpp
|
||||
src/bun.js/bindings/objects.cpp
|
||||
@@ -179,7 +161,6 @@ src/bun.js/bindings/Path.cpp
|
||||
src/bun.js/bindings/ProcessBindingBuffer.cpp
|
||||
src/bun.js/bindings/ProcessBindingConstants.cpp
|
||||
src/bun.js/bindings/ProcessBindingFs.cpp
|
||||
src/bun.js/bindings/ProcessBindingHTTPParser.cpp
|
||||
src/bun.js/bindings/ProcessBindingNatives.cpp
|
||||
src/bun.js/bindings/ProcessBindingTTYWrap.cpp
|
||||
src/bun.js/bindings/ProcessBindingUV.cpp
|
||||
@@ -427,8 +408,8 @@ src/bun.js/bindings/webcrypto/CryptoAlgorithmSHA1.cpp
|
||||
src/bun.js/bindings/webcrypto/CryptoAlgorithmSHA224.cpp
|
||||
src/bun.js/bindings/webcrypto/CryptoAlgorithmSHA256.cpp
|
||||
src/bun.js/bindings/webcrypto/CryptoAlgorithmSHA384.cpp
|
||||
src/bun.js/bindings/webcrypto/CryptoAlgorithmSHA512.cpp
|
||||
src/bun.js/bindings/webcrypto/CryptoAlgorithmX25519.cpp
|
||||
src/bun.js/bindings/webcrypto/CryptoAlgorithmSHA512.cpp
|
||||
src/bun.js/bindings/webcrypto/CryptoDigest.cpp
|
||||
src/bun.js/bindings/webcrypto/CryptoKey.cpp
|
||||
src/bun.js/bindings/webcrypto/CryptoKeyAES.cpp
|
||||
@@ -462,6 +443,7 @@ src/bun.js/bindings/webcrypto/JSHkdfParams.cpp
|
||||
src/bun.js/bindings/webcrypto/JSHmacKeyParams.cpp
|
||||
src/bun.js/bindings/webcrypto/JSJsonWebKey.cpp
|
||||
src/bun.js/bindings/webcrypto/JSPbkdf2Params.cpp
|
||||
src/bun.js/bindings/webcrypto/JSX25519Params.cpp
|
||||
src/bun.js/bindings/webcrypto/JSRsaHashedImportParams.cpp
|
||||
src/bun.js/bindings/webcrypto/JSRsaHashedKeyGenParams.cpp
|
||||
src/bun.js/bindings/webcrypto/JSRsaKeyGenParams.cpp
|
||||
@@ -469,7 +451,6 @@ src/bun.js/bindings/webcrypto/JSRsaOaepParams.cpp
|
||||
src/bun.js/bindings/webcrypto/JSRsaOtherPrimesInfo.cpp
|
||||
src/bun.js/bindings/webcrypto/JSRsaPssParams.cpp
|
||||
src/bun.js/bindings/webcrypto/JSSubtleCrypto.cpp
|
||||
src/bun.js/bindings/webcrypto/JSX25519Params.cpp
|
||||
src/bun.js/bindings/webcrypto/OpenSSLUtilities.cpp
|
||||
src/bun.js/bindings/webcrypto/PhonyWorkQueue.cpp
|
||||
src/bun.js/bindings/webcrypto/SerializedCryptoKeyWrapOpenSSL.cpp
|
||||
@@ -484,6 +465,4 @@ src/bun.js/modules/NodeTTYModule.cpp
|
||||
src/bun.js/modules/NodeUtilTypesModule.cpp
|
||||
src/bun.js/modules/ObjectModule.cpp
|
||||
src/deps/libuwsockets.cpp
|
||||
src/io/io_darwin.cpp
|
||||
src/vm/Semaphore.cpp
|
||||
src/vm/SigintWatcher.cpp
|
||||
src/io/io_darwin.cpp
|
||||
@@ -15,4 +15,4 @@ src/codegen/generate-jssink.ts
|
||||
src/codegen/generate-node-errors.ts
|
||||
src/codegen/helpers.ts
|
||||
src/codegen/internal-module-registry-scanner.ts
|
||||
src/codegen/replacements.ts
|
||||
src/codegen/replacements.ts
|
||||
@@ -52,7 +52,6 @@ src/js/internal/debugger.ts
|
||||
src/js/internal/errors.ts
|
||||
src/js/internal/fifo.ts
|
||||
src/js/internal/fixed_queue.ts
|
||||
src/js/internal/freelist.ts
|
||||
src/js/internal/fs/cp-sync.ts
|
||||
src/js/internal/fs/cp.ts
|
||||
src/js/internal/fs/glob.ts
|
||||
@@ -161,4 +160,4 @@ src/js/thirdparty/node-fetch.ts
|
||||
src/js/thirdparty/undici.js
|
||||
src/js/thirdparty/vercel_fetch.js
|
||||
src/js/thirdparty/ws.js
|
||||
src/js/wasi-runner.js
|
||||
src/js/wasi-runner.js
|
||||
@@ -21,4 +21,4 @@ src/node-fallbacks/timers.promises.js
|
||||
src/node-fallbacks/tty.js
|
||||
src/node-fallbacks/url.js
|
||||
src/node-fallbacks/util.js
|
||||
src/node-fallbacks/zlib.js
|
||||
src/node-fallbacks/zlib.js
|
||||
@@ -7,7 +7,6 @@ src/bun.js/api/h2.classes.ts
|
||||
src/bun.js/api/html_rewriter.classes.ts
|
||||
src/bun.js/api/JSBundler.classes.ts
|
||||
src/bun.js/api/postgres.classes.ts
|
||||
src/bun.js/api/ResumableSink.classes.ts
|
||||
src/bun.js/api/S3Client.classes.ts
|
||||
src/bun.js/api/S3Stat.classes.ts
|
||||
src/bun.js/api/server.classes.ts
|
||||
@@ -21,4 +20,4 @@ src/bun.js/node/node.classes.ts
|
||||
src/bun.js/resolve_message.classes.ts
|
||||
src/bun.js/test/jest.classes.ts
|
||||
src/bun.js/webcore/encoding.classes.ts
|
||||
src/bun.js/webcore/response.classes.ts
|
||||
src/bun.js/webcore/response.classes.ts
|
||||
@@ -10,26 +10,7 @@ src/allocators/NullableAllocator.zig
|
||||
src/analytics/analytics_schema.zig
|
||||
src/analytics/analytics_thread.zig
|
||||
src/api/schema.zig
|
||||
src/ast/Ast.zig
|
||||
src/ast/ASTMemoryAllocator.zig
|
||||
src/ast/B.zig
|
||||
src/ast/base.zig
|
||||
src/ast/Binding.zig
|
||||
src/ast/BundledAst.zig
|
||||
src/ast/CharFreq.zig
|
||||
src/ast/E.zig
|
||||
src/ast/Expr.zig
|
||||
src/ast/G.zig
|
||||
src/ast/Macro.zig
|
||||
src/ast/NewStore.zig
|
||||
src/ast/Op.zig
|
||||
src/ast/S.zig
|
||||
src/ast/Scope.zig
|
||||
src/ast/ServerComponentBoundary.zig
|
||||
src/ast/Stmt.zig
|
||||
src/ast/Symbol.zig
|
||||
src/ast/TS.zig
|
||||
src/ast/UseDirective.zig
|
||||
src/async/posix_event_loop.zig
|
||||
src/async/stub_event_loop.zig
|
||||
src/async/windows_event_loop.zig
|
||||
@@ -51,11 +32,7 @@ src/bun.js/api/bun/h2_frame_parser.zig
|
||||
src/bun.js/api/bun/lshpack.zig
|
||||
src/bun.js/api/bun/process.zig
|
||||
src/bun.js/api/bun/socket.zig
|
||||
src/bun.js/api/bun/socket/Handlers.zig
|
||||
src/bun.js/api/bun/socket/Listener.zig
|
||||
src/bun.js/api/bun/socket/SocketAddress.zig
|
||||
src/bun.js/api/bun/socket/tls_socket_functions.zig
|
||||
src/bun.js/api/bun/socket/WindowsNamedPipeContext.zig
|
||||
src/bun.js/api/bun/spawn.zig
|
||||
src/bun.js/api/bun/spawn/stdio.zig
|
||||
src/bun.js/api/bun/ssl_wrapper.zig
|
||||
@@ -78,24 +55,13 @@ src/bun.js/api/html_rewriter.zig
|
||||
src/bun.js/api/JSBundler.zig
|
||||
src/bun.js/api/JSTranspiler.zig
|
||||
src/bun.js/api/server.zig
|
||||
src/bun.js/api/server/AnyRequestContext.zig
|
||||
src/bun.js/api/server/FileRoute.zig
|
||||
src/bun.js/api/server/HTMLBundle.zig
|
||||
src/bun.js/api/server/HTTPStatusText.zig
|
||||
src/bun.js/api/server/InspectorBunFrontendDevServerAgent.zig
|
||||
src/bun.js/api/server/NodeHTTPResponse.zig
|
||||
src/bun.js/api/server/RequestContext.zig
|
||||
src/bun.js/api/server/ServerConfig.zig
|
||||
src/bun.js/api/server/ServerWebSocket.zig
|
||||
src/bun.js/api/server/SSLConfig.zig
|
||||
src/bun.js/api/server/StaticRoute.zig
|
||||
src/bun.js/api/server/WebSocketServerContext.zig
|
||||
src/bun.js/api/streams.classes.zig
|
||||
src/bun.js/api/Timer.zig
|
||||
src/bun.js/api/Timer/EventLoopTimer.zig
|
||||
src/bun.js/api/Timer/ImmediateObject.zig
|
||||
src/bun.js/api/Timer/TimeoutObject.zig
|
||||
src/bun.js/api/Timer/TimerObjectInternals.zig
|
||||
src/bun.js/api/TOMLObject.zig
|
||||
src/bun.js/api/UnsafeObject.zig
|
||||
src/bun.js/bindgen_test.zig
|
||||
@@ -104,7 +70,6 @@ src/bun.js/bindings/AnyPromise.zig
|
||||
src/bun.js/bindings/bun-simdutf.zig
|
||||
src/bun.js/bindings/CachedBytecode.zig
|
||||
src/bun.js/bindings/CallFrame.zig
|
||||
src/bun.js/bindings/CatchScope.zig
|
||||
src/bun.js/bindings/codegen.zig
|
||||
src/bun.js/bindings/CommonAbortReason.zig
|
||||
src/bun.js/bindings/CommonStrings.zig
|
||||
@@ -121,6 +86,8 @@ src/bun.js/bindings/Exception.zig
|
||||
src/bun.js/bindings/FetchHeaders.zig
|
||||
src/bun.js/bindings/FFI.zig
|
||||
src/bun.js/bindings/generated_classes_list.zig
|
||||
src/bun.js/bindings/GeneratedBindings.zig
|
||||
src/bun.js/bindings/GeneratedJS2Native.zig
|
||||
src/bun.js/bindings/GetterSetter.zig
|
||||
src/bun.js/bindings/HTTPServerAgent.zig
|
||||
src/bun.js/bindings/JSArray.zig
|
||||
@@ -140,7 +107,6 @@ src/bun.js/bindings/JSPropertyIterator.zig
|
||||
src/bun.js/bindings/JSRef.zig
|
||||
src/bun.js/bindings/JSRuntimeType.zig
|
||||
src/bun.js/bindings/JSString.zig
|
||||
src/bun.js/bindings/JSType.zig
|
||||
src/bun.js/bindings/JSUint8Array.zig
|
||||
src/bun.js/bindings/JSValue.zig
|
||||
src/bun.js/bindings/NodeModuleModule.zig
|
||||
@@ -169,21 +135,6 @@ src/bun.js/ConsoleObject.zig
|
||||
src/bun.js/Counters.zig
|
||||
src/bun.js/Debugger.zig
|
||||
src/bun.js/event_loop.zig
|
||||
src/bun.js/event_loop/AnyEventLoop.zig
|
||||
src/bun.js/event_loop/AnyTask.zig
|
||||
src/bun.js/event_loop/AnyTaskWithExtraContext.zig
|
||||
src/bun.js/event_loop/ConcurrentPromiseTask.zig
|
||||
src/bun.js/event_loop/ConcurrentTask.zig
|
||||
src/bun.js/event_loop/CppTask.zig
|
||||
src/bun.js/event_loop/DeferredTaskQueue.zig
|
||||
src/bun.js/event_loop/EventLoopHandle.zig
|
||||
src/bun.js/event_loop/GarbageCollectionController.zig
|
||||
src/bun.js/event_loop/JSCScheduler.zig
|
||||
src/bun.js/event_loop/ManagedTask.zig
|
||||
src/bun.js/event_loop/MiniEventLoop.zig
|
||||
src/bun.js/event_loop/PosixSignalHandle.zig
|
||||
src/bun.js/event_loop/Task.zig
|
||||
src/bun.js/event_loop/WorkTask.zig
|
||||
src/bun.js/hot_reloader.zig
|
||||
src/bun.js/ipc.zig
|
||||
src/bun.js/javascript_core_c_api.zig
|
||||
@@ -227,9 +178,6 @@ src/bun.js/node/util/parse_args_utils.zig
|
||||
src/bun.js/node/util/parse_args.zig
|
||||
src/bun.js/node/util/validators.zig
|
||||
src/bun.js/node/win_watcher.zig
|
||||
src/bun.js/node/zlib/NativeBrotli.zig
|
||||
src/bun.js/node/zlib/NativeZlib.zig
|
||||
src/bun.js/node/zlib/NativeZstd.zig
|
||||
src/bun.js/ProcessAutoKiller.zig
|
||||
src/bun.js/rare_data.zig
|
||||
src/bun.js/ResolveMessage.zig
|
||||
@@ -271,7 +219,6 @@ src/bun.js/webcore/prompt.zig
|
||||
src/bun.js/webcore/ReadableStream.zig
|
||||
src/bun.js/webcore/Request.zig
|
||||
src/bun.js/webcore/Response.zig
|
||||
src/bun.js/webcore/ResumableSink.zig
|
||||
src/bun.js/webcore/S3Client.zig
|
||||
src/bun.js/webcore/S3File.zig
|
||||
src/bun.js/webcore/S3Stat.zig
|
||||
@@ -283,48 +230,14 @@ src/bun.js/webcore/TextEncoder.zig
|
||||
src/bun.js/webcore/TextEncoderStreamEncoder.zig
|
||||
src/bun.js/WTFTimer.zig
|
||||
src/bun.zig
|
||||
src/bundler/AstBuilder.zig
|
||||
src/bundler/bundle_v2.zig
|
||||
src/bundler/BundleThread.zig
|
||||
src/bundler/Chunk.zig
|
||||
src/bundler/DeferredBatchTask.zig
|
||||
src/bundler/entry_points.zig
|
||||
src/bundler/Graph.zig
|
||||
src/bundler/HTMLImportManifest.zig
|
||||
src/bundler/linker_context/computeChunks.zig
|
||||
src/bundler/linker_context/computeCrossChunkDependencies.zig
|
||||
src/bundler/linker_context/convertStmtsForChunk.zig
|
||||
src/bundler/linker_context/convertStmtsForChunkForDevServer.zig
|
||||
src/bundler/linker_context/doStep5.zig
|
||||
src/bundler/linker_context/findAllImportedPartsInJSOrder.zig
|
||||
src/bundler/linker_context/findImportedCSSFilesInJSOrder.zig
|
||||
src/bundler/linker_context/findImportedFilesInCSSOrder.zig
|
||||
src/bundler/linker_context/generateChunksInParallel.zig
|
||||
src/bundler/linker_context/generateCodeForFileInChunkJS.zig
|
||||
src/bundler/linker_context/generateCodeForLazyExport.zig
|
||||
src/bundler/linker_context/generateCompileResultForCssChunk.zig
|
||||
src/bundler/linker_context/generateCompileResultForHtmlChunk.zig
|
||||
src/bundler/linker_context/generateCompileResultForJSChunk.zig
|
||||
src/bundler/linker_context/postProcessCSSChunk.zig
|
||||
src/bundler/linker_context/postProcessHTMLChunk.zig
|
||||
src/bundler/linker_context/postProcessJSChunk.zig
|
||||
src/bundler/linker_context/prepareCssAstsForChunk.zig
|
||||
src/bundler/linker_context/renameSymbolsInChunk.zig
|
||||
src/bundler/linker_context/scanImportsAndExports.zig
|
||||
src/bundler/linker_context/writeOutputFilesToDisk.zig
|
||||
src/bundler/LinkerContext.zig
|
||||
src/bundler/LinkerGraph.zig
|
||||
src/bundler/ParseTask.zig
|
||||
src/bundler/ServerComponentParseTask.zig
|
||||
src/bundler/ThreadPool.zig
|
||||
src/bunfig.zig
|
||||
src/cache.zig
|
||||
src/ci_info.zig
|
||||
src/cli.zig
|
||||
src/cli/add_command.zig
|
||||
src/cli/add_completions.zig
|
||||
src/cli/Arguments.zig
|
||||
src/cli/audit_command.zig
|
||||
src/cli/build_command.zig
|
||||
src/cli/bunx_command.zig
|
||||
src/cli/colon_list_type.zig
|
||||
@@ -344,7 +257,6 @@ src/cli/package_manager_command.zig
|
||||
src/cli/patch_command.zig
|
||||
src/cli/patch_commit_command.zig
|
||||
src/cli/pm_trusted_command.zig
|
||||
src/cli/pm_view_command.zig
|
||||
src/cli/publish_command.zig
|
||||
src/cli/remove_command.zig
|
||||
src/cli/run_command.zig
|
||||
@@ -472,22 +384,7 @@ src/deps/picohttp.zig
|
||||
src/deps/picohttpparser.zig
|
||||
src/deps/tcc.zig
|
||||
src/deps/uws.zig
|
||||
src/deps/uws/App.zig
|
||||
src/deps/uws/BodyReaderMixin.zig
|
||||
src/deps/uws/ConnectingSocket.zig
|
||||
src/deps/uws/InternalLoopData.zig
|
||||
src/deps/uws/ListenSocket.zig
|
||||
src/deps/uws/Loop.zig
|
||||
src/deps/uws/Request.zig
|
||||
src/deps/uws/Response.zig
|
||||
src/deps/uws/socket.zig
|
||||
src/deps/uws/SocketContext.zig
|
||||
src/deps/uws/Timer.zig
|
||||
src/deps/uws/udp.zig
|
||||
src/deps/uws/UpgradedDuplex.zig
|
||||
src/deps/uws/us_socket_t.zig
|
||||
src/deps/uws/WebSocket.zig
|
||||
src/deps/uws/WindowsNamedPipe.zig
|
||||
src/deps/zig-clap/clap.zig
|
||||
src/deps/zig-clap/clap/args.zig
|
||||
src/deps/zig-clap/clap/comptime.zig
|
||||
@@ -508,7 +405,6 @@ src/fd.zig
|
||||
src/feature_flags.zig
|
||||
src/fmt.zig
|
||||
src/fs.zig
|
||||
src/fs/stat_hash.zig
|
||||
src/futex.zig
|
||||
src/generated_perf_trace_events.zig
|
||||
src/generated_versions_list.zig
|
||||
@@ -523,29 +419,12 @@ src/hive_array.zig
|
||||
src/hmac.zig
|
||||
src/HTMLScanner.zig
|
||||
src/http.zig
|
||||
src/http/AsyncHTTP.zig
|
||||
src/http/CertificateInfo.zig
|
||||
src/http/Decompressor.zig
|
||||
src/http/Encoding.zig
|
||||
src/http/FetchRedirect.zig
|
||||
src/http/HeaderBuilder.zig
|
||||
src/http/Headers.zig
|
||||
src/http/HTTPCertError.zig
|
||||
src/http/HTTPContext.zig
|
||||
src/http/HTTPRequestBody.zig
|
||||
src/http/HTTPThread.zig
|
||||
src/http/InitError.zig
|
||||
src/http/InternalState.zig
|
||||
src/http/Method.zig
|
||||
src/http/MimeType.zig
|
||||
src/http/ProxyTunnel.zig
|
||||
src/http/SendFile.zig
|
||||
src/http/Signals.zig
|
||||
src/http/ThreadSafeStreamBuffer.zig
|
||||
src/http/URLPath.zig
|
||||
src/http/header_builder.zig
|
||||
src/http/method.zig
|
||||
src/http/mime_type.zig
|
||||
src/http/url_path.zig
|
||||
src/http/websocket_client.zig
|
||||
src/http/websocket_client/CppWebSocket.zig
|
||||
src/http/websocket_client/WebSocketDeflate.zig
|
||||
src/http/websocket_client/WebSocketUpgradeClient.zig
|
||||
src/http/websocket_http_client.zig
|
||||
src/http/websocket.zig
|
||||
@@ -554,51 +433,15 @@ src/identity_context.zig
|
||||
src/import_record.zig
|
||||
src/ini.zig
|
||||
src/install/bin.zig
|
||||
src/install/bun.lock.zig
|
||||
src/install/dependency.zig
|
||||
src/install/ExternalSlice.zig
|
||||
src/install/extract_tarball.zig
|
||||
src/install/hoisted_install.zig
|
||||
src/install/install_binding.zig
|
||||
src/install/install.zig
|
||||
src/install/integrity.zig
|
||||
src/install/lifecycle_script_runner.zig
|
||||
src/install/lockfile.zig
|
||||
src/install/lockfile/Buffers.zig
|
||||
src/install/lockfile/bun.lock.zig
|
||||
src/install/lockfile/bun.lockb.zig
|
||||
src/install/lockfile/CatalogMap.zig
|
||||
src/install/lockfile/lockfile_json_stringify_for_debugging.zig
|
||||
src/install/lockfile/OverrideMap.zig
|
||||
src/install/lockfile/Package.zig
|
||||
src/install/lockfile/Package/Meta.zig
|
||||
src/install/lockfile/Package/Scripts.zig
|
||||
src/install/lockfile/Package/WorkspaceMap.zig
|
||||
src/install/lockfile/printer/tree_printer.zig
|
||||
src/install/lockfile/printer/Yarn.zig
|
||||
src/install/lockfile/Tree.zig
|
||||
src/install/migration.zig
|
||||
src/install/NetworkTask.zig
|
||||
src/install/npm.zig
|
||||
src/install/PackageInstall.zig
|
||||
src/install/PackageInstaller.zig
|
||||
src/install/PackageManager.zig
|
||||
src/install/PackageManager/CommandLineArguments.zig
|
||||
src/install/PackageManager/install_with_manager.zig
|
||||
src/install/PackageManager/PackageJSONEditor.zig
|
||||
src/install/PackageManager/PackageManagerDirectories.zig
|
||||
src/install/PackageManager/PackageManagerEnqueue.zig
|
||||
src/install/PackageManager/PackageManagerLifecycle.zig
|
||||
src/install/PackageManager/PackageManagerOptions.zig
|
||||
src/install/PackageManager/PackageManagerResolution.zig
|
||||
src/install/PackageManager/patchPackage.zig
|
||||
src/install/PackageManager/processDependencyList.zig
|
||||
src/install/PackageManager/ProgressStrings.zig
|
||||
src/install/PackageManager/runTasks.zig
|
||||
src/install/PackageManager/updatePackageJSONAndInstall.zig
|
||||
src/install/PackageManager/UpdateRequest.zig
|
||||
src/install/PackageManager/WorkspacePackageJSONCache.zig
|
||||
src/install/PackageManagerTask.zig
|
||||
src/install/PackageManifestMap.zig
|
||||
src/install/padding_checker.zig
|
||||
src/install/patch_install.zig
|
||||
src/install/repository.zig
|
||||
@@ -610,11 +453,11 @@ src/install/windows-shim/bun_shim_impl.zig
|
||||
src/io/heap.zig
|
||||
src/io/io.zig
|
||||
src/io/MaxBuf.zig
|
||||
src/io/openForWriting.zig
|
||||
src/io/PipeReader.zig
|
||||
src/io/pipes.zig
|
||||
src/io/PipeWriter.zig
|
||||
src/io/source.zig
|
||||
src/io/time.zig
|
||||
src/js_ast.zig
|
||||
src/js_lexer_tables.zig
|
||||
src/js_lexer.zig
|
||||
@@ -681,7 +524,6 @@ src/semver/SemverString.zig
|
||||
src/semver/SlicedString.zig
|
||||
src/semver/Version.zig
|
||||
src/sha.zig
|
||||
src/shell/AllocScope.zig
|
||||
src/shell/braces.zig
|
||||
src/shell/Builtin.zig
|
||||
src/shell/builtin/basename.zig
|
||||
@@ -706,27 +548,12 @@ src/shell/builtin/yes.zig
|
||||
src/shell/EnvMap.zig
|
||||
src/shell/EnvStr.zig
|
||||
src/shell/interpreter.zig
|
||||
src/shell/IO.zig
|
||||
src/shell/IOReader.zig
|
||||
src/shell/IOWriter.zig
|
||||
src/shell/ParsedShellScript.zig
|
||||
src/shell/RefCountedStr.zig
|
||||
src/shell/shell.zig
|
||||
src/shell/states/Assigns.zig
|
||||
src/shell/states/Async.zig
|
||||
src/shell/states/Base.zig
|
||||
src/shell/states/Binary.zig
|
||||
src/shell/states/Cmd.zig
|
||||
src/shell/states/CondExpr.zig
|
||||
src/shell/states/Expansion.zig
|
||||
src/shell/states/If.zig
|
||||
src/shell/states/Pipeline.zig
|
||||
src/shell/states/Script.zig
|
||||
src/shell/states/Stmt.zig
|
||||
src/shell/states/Subshell.zig
|
||||
src/shell/subproc.zig
|
||||
src/shell/util.zig
|
||||
src/shell/Yield.zig
|
||||
src/sourcemap/CodeCoverage.zig
|
||||
src/sourcemap/LineOffsetTable.zig
|
||||
src/sourcemap/sourcemap.zig
|
||||
@@ -740,16 +567,12 @@ src/StaticHashMap.zig
|
||||
src/string_immutable.zig
|
||||
src/string_types.zig
|
||||
src/string.zig
|
||||
src/string/escapeHTML.zig
|
||||
src/string/HashedString.zig
|
||||
src/string/MutableString.zig
|
||||
src/string/paths.zig
|
||||
src/string/PathString.zig
|
||||
src/string/SmolStr.zig
|
||||
src/string/StringBuilder.zig
|
||||
src/string/StringJoiner.zig
|
||||
src/string/unicode.zig
|
||||
src/string/visible.zig
|
||||
src/string/WTFStringImpl.zig
|
||||
src/sync.zig
|
||||
src/sys_uv.zig
|
||||
@@ -785,4 +608,4 @@ src/windows.zig
|
||||
src/work_pool.zig
|
||||
src/workaround_missing_symbols.zig
|
||||
src/wyhash.zig
|
||||
src/zlib.zig
|
||||
src/zlib.zig
|
||||
@@ -42,29 +42,6 @@ else()
|
||||
set(CONFIGURE_DEPENDS "")
|
||||
endif()
|
||||
|
||||
# --- Dependencies ---
|
||||
|
||||
set(BUN_DEPENDENCIES
|
||||
BoringSSL
|
||||
Brotli
|
||||
Cares
|
||||
Highway
|
||||
LibDeflate
|
||||
LolHtml
|
||||
Lshpack
|
||||
Mimalloc
|
||||
TinyCC
|
||||
Zlib
|
||||
LibArchive # must be loaded after zlib
|
||||
HdrHistogram # must be loaded after zlib
|
||||
Zstd
|
||||
)
|
||||
|
||||
include(CloneZstd)
|
||||
# foreach(dependency ${BUN_DEPENDENCIES})
|
||||
# include(Clone${dependency})
|
||||
# endforeach()
|
||||
|
||||
# --- Codegen ---
|
||||
|
||||
set(BUN_ERROR_SOURCE ${CWD}/packages/bun-error)
|
||||
@@ -431,7 +408,6 @@ set(BUN_OBJECT_LUT_SOURCES
|
||||
${CWD}/src/bun.js/bindings/ProcessBindingConstants.cpp
|
||||
${CWD}/src/bun.js/bindings/ProcessBindingFs.cpp
|
||||
${CWD}/src/bun.js/bindings/ProcessBindingNatives.cpp
|
||||
${CWD}/src/bun.js/bindings/ProcessBindingHTTPParser.cpp
|
||||
${CWD}/src/bun.js/modules/NodeModuleModule.cpp
|
||||
${CODEGEN_PATH}/ZigGeneratedClasses.lut.txt
|
||||
)
|
||||
@@ -445,7 +421,6 @@ set(BUN_OBJECT_LUT_OUTPUTS
|
||||
${CODEGEN_PATH}/ProcessBindingConstants.lut.h
|
||||
${CODEGEN_PATH}/ProcessBindingFs.lut.h
|
||||
${CODEGEN_PATH}/ProcessBindingNatives.lut.h
|
||||
${CODEGEN_PATH}/ProcessBindingHTTPParser.lut.h
|
||||
${CODEGEN_PATH}/NodeModuleModule.lut.h
|
||||
${CODEGEN_PATH}/ZigGeneratedClasses.lut.h
|
||||
)
|
||||
@@ -605,7 +580,6 @@ register_command(
|
||||
${BUN_ZIG_OUTPUT}
|
||||
TARGETS
|
||||
clone-zig
|
||||
clone-zstd
|
||||
SOURCES
|
||||
${BUN_ZIG_SOURCES}
|
||||
${BUN_ZIG_GENERATED_SOURCES}
|
||||
@@ -673,14 +647,20 @@ if(WIN32)
|
||||
else()
|
||||
set(Bun_VERSION_WITH_TAG ${VERSION})
|
||||
endif()
|
||||
set(BUN_ICO_PATH ${CWD}/src/bun.ico)
|
||||
configure_file(${CWD}/src/bun.ico ${CODEGEN_PATH}/bun.ico COPYONLY)
|
||||
set(BUN_ICO_PATH ${CODEGEN_PATH}/bun.ico)
|
||||
configure_file(
|
||||
${CWD}/src/windows-app-info.rc
|
||||
${CODEGEN_PATH}/windows-app-info.rc
|
||||
@ONLY
|
||||
)
|
||||
set(WINDOWS_RESOURCES ${CODEGEN_PATH}/windows-app-info.rc)
|
||||
add_custom_command(
|
||||
OUTPUT ${CODEGEN_PATH}/windows-app-info.res
|
||||
COMMAND rc.exe /fo ${CODEGEN_PATH}/windows-app-info.res ${CODEGEN_PATH}/windows-app-info.rc
|
||||
DEPENDS ${CODEGEN_PATH}/windows-app-info.rc ${CODEGEN_PATH}/bun.ico
|
||||
COMMENT "Adding Windows resource file ${CODEGEN_PATH}/windows-app-info.res with ico in ${CODEGEN_PATH}/bun.ico"
|
||||
)
|
||||
set(WINDOWS_RESOURCES ${CODEGEN_PATH}/windows-app-info.res)
|
||||
endif()
|
||||
|
||||
# --- Executable ---
|
||||
@@ -752,7 +732,6 @@ target_include_directories(${bun} PRIVATE
|
||||
${CWD}/src/bun.js/bindings/webcore
|
||||
${CWD}/src/bun.js/bindings/webcrypto
|
||||
${CWD}/src/bun.js/bindings/node/crypto
|
||||
${CWD}/src/bun.js/bindings/node/http
|
||||
${CWD}/src/bun.js/bindings/sqlite
|
||||
${CWD}/src/bun.js/bindings/v8
|
||||
${CWD}/src/bun.js/modules
|
||||
@@ -765,7 +744,7 @@ target_include_directories(${bun} PRIVATE
|
||||
${NODEJS_HEADERS_PATH}/include
|
||||
)
|
||||
|
||||
if(NOT WIN32)
|
||||
if(NOT WIN32)
|
||||
target_include_directories(${bun} PRIVATE ${CWD}/src/bun.js/bindings/libuv)
|
||||
endif()
|
||||
|
||||
@@ -898,7 +877,7 @@ if(NOT WIN32)
|
||||
-Wno-nullability-completeness
|
||||
-Werror
|
||||
)
|
||||
|
||||
|
||||
if(ENABLE_ASAN)
|
||||
target_compile_options(${bun} PUBLIC
|
||||
-fsanitize=address
|
||||
@@ -911,9 +890,6 @@ if(NOT WIN32)
|
||||
else()
|
||||
target_compile_options(${bun} PUBLIC
|
||||
-Wno-nullability-completeness
|
||||
-Wno-inconsistent-dllimport
|
||||
-Wno-incompatible-pointer-types
|
||||
-Wno-deprecated-declarations
|
||||
)
|
||||
endif()
|
||||
|
||||
@@ -959,7 +935,6 @@ if(LINUX)
|
||||
if(NOT ABI STREQUAL "musl")
|
||||
target_link_options(${bun} PUBLIC
|
||||
-Wl,--wrap=exp
|
||||
-Wl,--wrap=exp2
|
||||
-Wl,--wrap=expf
|
||||
-Wl,--wrap=fcntl64
|
||||
-Wl,--wrap=log
|
||||
@@ -1039,7 +1014,6 @@ if(WIN32)
|
||||
target_link_libraries(${bun} PRIVATE
|
||||
${WEBKIT_LIB_PATH}/WTF.lib
|
||||
${WEBKIT_LIB_PATH}/JavaScriptCore.lib
|
||||
${WEBKIT_LIB_PATH}/bmalloc.lib
|
||||
${WEBKIT_LIB_PATH}/sicudtd.lib
|
||||
${WEBKIT_LIB_PATH}/sicuind.lib
|
||||
${WEBKIT_LIB_PATH}/sicuucd.lib
|
||||
@@ -1048,7 +1022,6 @@ if(WIN32)
|
||||
target_link_libraries(${bun} PRIVATE
|
||||
${WEBKIT_LIB_PATH}/WTF.lib
|
||||
${WEBKIT_LIB_PATH}/JavaScriptCore.lib
|
||||
${WEBKIT_LIB_PATH}/bmalloc.lib
|
||||
${WEBKIT_LIB_PATH}/sicudt.lib
|
||||
${WEBKIT_LIB_PATH}/sicuin.lib
|
||||
${WEBKIT_LIB_PATH}/sicuuc.lib
|
||||
@@ -1072,6 +1045,21 @@ endif()
|
||||
|
||||
# --- Dependencies ---
|
||||
|
||||
set(BUN_DEPENDENCIES
|
||||
BoringSSL
|
||||
Brotli
|
||||
Cares
|
||||
Highway
|
||||
LibDeflate
|
||||
LolHtml
|
||||
Lshpack
|
||||
Mimalloc
|
||||
TinyCC
|
||||
Zlib
|
||||
LibArchive # must be loaded after zlib
|
||||
Zstd
|
||||
)
|
||||
|
||||
if(WIN32)
|
||||
list(APPEND BUN_DEPENDENCIES Libuv)
|
||||
endif()
|
||||
|
||||
@@ -4,7 +4,7 @@ register_repository(
|
||||
REPOSITORY
|
||||
c-ares/c-ares
|
||||
COMMIT
|
||||
d3a507e920e7af18a5efb7f9f1d8044ed4750013
|
||||
4f4912bce7374f787b10576851b687935f018e17
|
||||
)
|
||||
|
||||
register_cmake_command(
|
||||
|
||||
@@ -1,24 +0,0 @@
|
||||
register_repository(
|
||||
NAME
|
||||
hdrhistogram
|
||||
REPOSITORY
|
||||
HdrHistogram/HdrHistogram_c
|
||||
COMMIT
|
||||
652d51bcc36744fd1a6debfeb1a8a5f58b14022c
|
||||
)
|
||||
|
||||
register_cmake_command(
|
||||
TARGET
|
||||
hdrhistogram
|
||||
LIBRARIES
|
||||
hdr_histogram_static
|
||||
INCLUDES
|
||||
include
|
||||
LIB_PATH
|
||||
src
|
||||
ARGS
|
||||
-DHDR_HISTOGRAM_BUILD_SHARED=OFF
|
||||
-DHDR_HISTOGRAM_BUILD_STATIC=ON
|
||||
-DHDR_LOG_REQUIRED=DISABLED
|
||||
-DHDR_HISTOGRAM_BUILD_PROGRAMS=OFF
|
||||
)
|
||||
@@ -1,3 +1,12 @@
|
||||
register_repository(
|
||||
NAME
|
||||
zstd
|
||||
REPOSITORY
|
||||
facebook/zstd
|
||||
COMMIT
|
||||
f8745da6ff1ad1e7bab384bd1f9d742439278e99
|
||||
)
|
||||
|
||||
register_cmake_command(
|
||||
TARGET
|
||||
zstd
|
||||
@@ -14,6 +23,4 @@ register_cmake_command(
|
||||
LIBRARIES
|
||||
zstd_static WIN32
|
||||
zstd UNIX
|
||||
INCLUDES
|
||||
lib
|
||||
)
|
||||
|
||||
@@ -1,8 +0,0 @@
|
||||
register_repository(
|
||||
NAME
|
||||
zstd
|
||||
REPOSITORY
|
||||
facebook/zstd
|
||||
COMMIT
|
||||
f8745da6ff1ad1e7bab384bd1f9d742439278e99
|
||||
)
|
||||
@@ -2,7 +2,7 @@ option(WEBKIT_VERSION "The version of WebKit to use")
|
||||
option(WEBKIT_LOCAL "If a local version of WebKit should be used instead of downloading")
|
||||
|
||||
if(NOT WEBKIT_VERSION)
|
||||
set(WEBKIT_VERSION f98cecf7d6d1528fcf0da3dc6a23ce95650d2e0c)
|
||||
set(WEBKIT_VERSION eda8b0fb4fb1aa23db9c2b00933df8b58bcdd289)
|
||||
endif()
|
||||
|
||||
string(SUBSTRING ${WEBKIT_VERSION} 0 16 WEBKIT_VERSION_PREFIX)
|
||||
@@ -41,6 +41,14 @@ if(WEBKIT_LOCAL)
|
||||
return()
|
||||
endif()
|
||||
|
||||
if(EXISTS ${WEBKIT_PATH}/package.json)
|
||||
file(READ ${WEBKIT_PATH}/package.json WEBKIT_PACKAGE_JSON)
|
||||
|
||||
if(WEBKIT_PACKAGE_JSON MATCHES ${WEBKIT_VERSION})
|
||||
return()
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if(WIN32)
|
||||
set(WEBKIT_OS "windows")
|
||||
elseif(APPLE)
|
||||
@@ -78,18 +86,10 @@ if(ENABLE_ASAN)
|
||||
set(WEBKIT_SUFFIX "${WEBKIT_SUFFIX}-asan")
|
||||
endif()
|
||||
|
||||
setx(WEBKIT_NAME bun-webkit-${WEBKIT_OS}-${WEBKIT_ARCH}${WEBKIT_SUFFIX})
|
||||
set(WEBKIT_NAME bun-webkit-${WEBKIT_OS}-${WEBKIT_ARCH}${WEBKIT_SUFFIX})
|
||||
set(WEBKIT_FILENAME ${WEBKIT_NAME}.tar.gz)
|
||||
setx(WEBKIT_DOWNLOAD_URL https://github.com/oven-sh/WebKit/releases/download/autobuild-${WEBKIT_VERSION}/${WEBKIT_FILENAME})
|
||||
|
||||
if(EXISTS ${WEBKIT_PATH}/package.json)
|
||||
file(READ ${WEBKIT_PATH}/package.json WEBKIT_PACKAGE_JSON)
|
||||
|
||||
if(WEBKIT_PACKAGE_JSON MATCHES ${WEBKIT_VERSION})
|
||||
return()
|
||||
endif()
|
||||
endif()
|
||||
|
||||
file(DOWNLOAD ${WEBKIT_DOWNLOAD_URL} ${CACHE_PATH}/${WEBKIT_FILENAME} SHOW_PROGRESS)
|
||||
file(ARCHIVE_EXTRACT INPUT ${CACHE_PATH}/${WEBKIT_FILENAME} DESTINATION ${CACHE_PATH} TOUCH)
|
||||
file(REMOVE ${CACHE_PATH}/${WEBKIT_FILENAME})
|
||||
|
||||
@@ -20,7 +20,7 @@ else()
|
||||
unsupported(CMAKE_SYSTEM_NAME)
|
||||
endif()
|
||||
|
||||
set(ZIG_COMMIT "0a0120fa92cd7f6ab244865688b351df634f0707")
|
||||
set(ZIG_COMMIT "a207204ee57a061f2fb96c7bae0c491b609e73a5")
|
||||
optionx(ZIG_TARGET STRING "The zig target to use" DEFAULT ${DEFAULT_ZIG_TARGET})
|
||||
|
||||
if(CMAKE_BUILD_TYPE STREQUAL "Release")
|
||||
@@ -55,13 +55,13 @@ optionx(ZIG_OBJECT_FORMAT "obj|bc" "Output file format for Zig object files" DEF
|
||||
optionx(ZIG_LOCAL_CACHE_DIR FILEPATH "The path to local the zig cache directory" DEFAULT ${CACHE_PATH}/zig/local)
|
||||
optionx(ZIG_GLOBAL_CACHE_DIR FILEPATH "The path to the global zig cache directory" DEFAULT ${CACHE_PATH}/zig/global)
|
||||
|
||||
if(CI)
|
||||
if(CI AND CMAKE_HOST_APPLE)
|
||||
set(ZIG_COMPILER_SAFE_DEFAULT ON)
|
||||
else()
|
||||
set(ZIG_COMPILER_SAFE_DEFAULT OFF)
|
||||
endif()
|
||||
|
||||
optionx(ZIG_COMPILER_SAFE BOOL "Download a ReleaseSafe build of the Zig compiler." DEFAULT ${ZIG_COMPILER_SAFE_DEFAULT})
|
||||
optionx(ZIG_COMPILER_SAFE BOOL "Download a ReleaseSafe build of the Zig compiler. Only availble on macos aarch64." DEFAULT ${ZIG_COMPILER_SAFE_DEFAULT})
|
||||
|
||||
setenv(ZIG_LOCAL_CACHE_DIR ${ZIG_LOCAL_CACHE_DIR})
|
||||
setenv(ZIG_GLOBAL_CACHE_DIR ${ZIG_GLOBAL_CACHE_DIR})
|
||||
|
||||
@@ -539,7 +539,6 @@ _bun_update_completion() {
|
||||
'--save[Save to package.json]' \
|
||||
'--dry-run[Don'"'"'t install anything]' \
|
||||
'--frozen-lockfile[Disallow changes to lockfile]' \
|
||||
'--latest[Updates dependencies to latest version, regardless of compatibility]' \
|
||||
'-f[Always request the latest versions from the registry & reinstall all dependencies]' \
|
||||
'--force[Always request the latest versions from the registry & reinstall all dependencies]' \
|
||||
'--cache-dir[Store & load cached data from a specific directory path]:cache-dir' \
|
||||
@@ -573,7 +572,7 @@ _bun_outdated_completion() {
|
||||
'--no-progress[Disable the progress bar]' \
|
||||
'--help[Print this help menu]' &&
|
||||
ret=0
|
||||
|
||||
|
||||
case $state in
|
||||
config)
|
||||
_bun_list_bunfig_toml
|
||||
|
||||
@@ -175,7 +175,6 @@ Bun.hash.xxHash3("data", 1234);
|
||||
Bun.hash.murmur32v3("data", 1234);
|
||||
Bun.hash.murmur32v2("data", 1234);
|
||||
Bun.hash.murmur64v2("data", 1234);
|
||||
Bun.hash.rapidhash("data", 1234);
|
||||
```
|
||||
|
||||
## `Bun.CryptoHasher`
|
||||
|
||||
@@ -326,11 +326,7 @@ Bun.serve({
|
||||
|
||||
### HTML imports
|
||||
|
||||
Bun supports importing HTML files directly into your server code, enabling full-stack applications with both server-side and client-side code. HTML imports work in two modes:
|
||||
|
||||
**Development (`bun --hot`):** Assets are bundled on-demand at runtime, enabling hot module replacement (HMR) for a fast, iterative development experience. When you change your frontend code, the browser automatically updates without a full page reload.
|
||||
|
||||
**Production (`bun build`):** When building with `bun build --target=bun`, the `import index from "./index.html"` statement resolves to a pre-built manifest object containing all bundled client assets. `Bun.serve` consumes this manifest to serve optimized assets with zero runtime bundling overhead. This is ideal for deploying to production.
|
||||
To add a client-side single-page app, you can use an HTML import:
|
||||
|
||||
```ts
|
||||
import myReactSinglePageApp from "./index.html";
|
||||
@@ -342,9 +338,9 @@ Bun.serve({
|
||||
});
|
||||
```
|
||||
|
||||
HTML imports don't just serve HTML — it's a full-featured frontend bundler, transpiler, and toolkit built using Bun's [bundler](https://bun.sh/docs/bundler), JavaScript transpiler and CSS parser. You can use this to build full-featured frontends with React, TypeScript, Tailwind CSS, and more.
|
||||
HTML imports don't just serve HTML. It's a full-featured frontend bundler, transpiler, and toolkit built using Bun's [bundler](https://bun.sh/docs/bundler), JavaScript transpiler and CSS parser.
|
||||
|
||||
For a complete guide on building full-stack applications with HTML imports, including detailed examples and best practices, see [/docs/bundler/fullstack](https://bun.sh/docs/bundler/fullstack).
|
||||
You can use this to build a full-featured frontend with React, TypeScript, Tailwind CSS, and more. Check out [/docs/bundler/fullstack](https://bun.sh/docs/bundler/fullstack) to learn more.
|
||||
|
||||
### Practical example: REST API
|
||||
|
||||
|
||||
@@ -160,8 +160,7 @@ const writer = s3file.writer({
|
||||
partSize: 5 * 1024 * 1024,
|
||||
});
|
||||
for (let i = 0; i < 10; i++) {
|
||||
writer.write(bigFile);
|
||||
await writer.flush();
|
||||
await writer.write(bigFile);
|
||||
}
|
||||
await writer.end();
|
||||
```
|
||||
|
||||
@@ -34,7 +34,7 @@ const proc = Bun.spawn(["cat"], {
|
||||
),
|
||||
});
|
||||
|
||||
const text = await proc.stdout.text();
|
||||
const text = await new Response(proc.stdout).text();
|
||||
console.log(text); // "const input = "hello world".repeat(400); ..."
|
||||
```
|
||||
|
||||
@@ -113,34 +113,14 @@ proc.stdin.flush();
|
||||
proc.stdin.end();
|
||||
```
|
||||
|
||||
Passing a `ReadableStream` to `stdin` lets you pipe data from a JavaScript `ReadableStream` directly to the subprocess's input:
|
||||
|
||||
```ts
|
||||
const stream = new ReadableStream({
|
||||
start(controller) {
|
||||
controller.enqueue("Hello from ");
|
||||
controller.enqueue("ReadableStream!");
|
||||
controller.close();
|
||||
},
|
||||
});
|
||||
|
||||
const proc = Bun.spawn(["cat"], {
|
||||
stdin: stream,
|
||||
stdout: "pipe",
|
||||
});
|
||||
|
||||
const output = await new Response(proc.stdout).text();
|
||||
console.log(output); // "Hello from ReadableStream!"
|
||||
```
|
||||
|
||||
## Output streams
|
||||
|
||||
You can read results from the subprocess via the `stdout` and `stderr` properties. By default these are instances of `ReadableStream`.
|
||||
|
||||
```ts
|
||||
const proc = Bun.spawn(["bun", "--version"]);
|
||||
const text = await proc.stdout.text();
|
||||
console.log(text); // => "$BUN_LATEST_VERSION\n"
|
||||
const text = await new Response(proc.stdout).text();
|
||||
console.log(text); // => "$BUN_LATEST_VERSION"
|
||||
```
|
||||
|
||||
Configure the output stream by passing one of the following values to `stdout/stderr`:
|
||||
|
||||
1
docs/api/test.md
Normal file
1
docs/api/test.md
Normal file
@@ -0,0 +1 @@
|
||||
See the [`bun test`](https://bun.sh/docs/cli/test) documentation.
|
||||
@@ -582,11 +582,11 @@ Compresses a `Uint8Array` using zlib's DEFLATE algorithm.
|
||||
const buf = Buffer.from("hello".repeat(100));
|
||||
const compressed = Bun.deflateSync(buf);
|
||||
|
||||
buf; // => Buffer(500)
|
||||
compressed; // => Uint8Array(12)
|
||||
buf; // => Uint8Array(25)
|
||||
compressed; // => Uint8Array(10)
|
||||
```
|
||||
|
||||
The second argument supports the same set of configuration options as [`Bun.gzipSync`](#bun-gzipsync).
|
||||
The second argument supports the same set of configuration options as [`Bun.gzipSync`](#bungzipsync).
|
||||
|
||||
## `Bun.inflateSync()`
|
||||
|
||||
|
||||
@@ -126,81 +126,6 @@ The `--sourcemap` argument embeds a sourcemap compressed with zstd, so that erro
|
||||
|
||||
The `--bytecode` argument enables bytecode compilation. Every time you run JavaScript code in Bun, JavaScriptCore (the engine) will compile your source code into bytecode. We can move this parsing work from runtime to bundle time, saving you startup time.
|
||||
|
||||
## Full-stack executables
|
||||
|
||||
{% note %}
|
||||
|
||||
New in Bun v1.2.17
|
||||
|
||||
{% /note %}
|
||||
|
||||
Bun's `--compile` flag can create standalone executables that contain both server and client code, making it ideal for full-stack applications. When you import an HTML file in your server code, Bun automatically bundles all frontend assets (JavaScript, CSS, etc.) and embeds them into the executable. When Bun sees the HTML import on the server, it kicks off a frontend build process to bundle JavaScript, CSS, and other assets.
|
||||
|
||||
{% codetabs %}
|
||||
|
||||
```ts#server.ts
|
||||
import { serve } from "bun";
|
||||
import index from "./index.html";
|
||||
|
||||
const server = serve({
|
||||
routes: {
|
||||
"/": index,
|
||||
"/api/hello": { GET: () => Response.json({ message: "Hello from API" }) },
|
||||
},
|
||||
});
|
||||
|
||||
console.log(`Server running at http://localhost:${server.port}`);
|
||||
```
|
||||
|
||||
```html#index.html
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>My App</title>
|
||||
<link rel="stylesheet" href="./styles.css">
|
||||
</head>
|
||||
<body>
|
||||
<h1>Hello World</h1>
|
||||
<script src="./app.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
```
|
||||
|
||||
```js#app.js
|
||||
console.log("Hello from the client!");
|
||||
```
|
||||
|
||||
```css#styles.css
|
||||
body {
|
||||
background-color: #f0f0f0;
|
||||
}
|
||||
```
|
||||
|
||||
{% /codetabs %}
|
||||
|
||||
To build this into a single executable:
|
||||
|
||||
```sh
|
||||
bun build --compile ./server.ts --outfile myapp
|
||||
```
|
||||
|
||||
This creates a self-contained binary that includes:
|
||||
|
||||
- Your server code
|
||||
- The Bun runtime
|
||||
- All frontend assets (HTML, CSS, JavaScript)
|
||||
- Any npm packages used by your server
|
||||
|
||||
The result is a single file that can be deployed anywhere without needing Node.js, Bun, or any dependencies installed. Just run:
|
||||
|
||||
```sh
|
||||
./myapp
|
||||
```
|
||||
|
||||
Bun automatically handles serving the frontend assets with proper MIME types and cache headers. The HTML import is replaced with a manifest object that `Bun.serve` uses to efficiently serve pre-bundled assets.
|
||||
|
||||
For more details on building full-stack applications with Bun, see the [full-stack guide](/docs/bundler/fullstack).
|
||||
|
||||
## Worker
|
||||
|
||||
To use workers in a standalone executable, add the worker's entrypoint to the CLI arguments:
|
||||
@@ -249,7 +174,7 @@ $ ./hello
|
||||
|
||||
Standalone executables support embedding files.
|
||||
|
||||
To embed files into an executable with `bun build --compile`, import the file in your code.
|
||||
To embed files into an executable with `bun build --compile`, import the file in your code
|
||||
|
||||
```ts
|
||||
// this becomes an internal file path
|
||||
@@ -428,4 +353,5 @@ Currently, the `--compile` flag can only accept a single entrypoint at a time an
|
||||
- `--splitting`
|
||||
- `--public-path`
|
||||
- `--target=node` or `--target=browser`
|
||||
- `--format` - always outputs a binary executable. Internally, it's almost esm.
|
||||
- `--no-bundle` - we always bundle everything into the executable.
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
Using `Bun.serve()`'s `routes` option, you can run your frontend and backend in the same app with no extra steps.
|
||||
|
||||
To get started, import HTML files and pass them to the `routes` option in `Bun.serve()`.
|
||||
|
||||
```ts
|
||||
@@ -232,92 +234,7 @@ When `console: true` is set, Bun will stream console logs from the browser to th
|
||||
|
||||
#### Production mode
|
||||
|
||||
Hot reloading and `development: true` helps you iterate quickly, but in production, your server should be as fast as possible and have as few external dependencies as possible.
|
||||
|
||||
##### Ahead of time bundling (recommended)
|
||||
|
||||
As of Bun v1.2.17, you can use `Bun.build` or `bun build` to bundle your full-stack application ahead of time.
|
||||
|
||||
```sh
|
||||
$ bun build --target=bun --production --outdir=dist ./src/index.ts
|
||||
```
|
||||
|
||||
When Bun's bundler sees an HTML import from server-side code, it will bundle the referenced JavaScript/TypeScript/TSX/JSX and CSS files into a manifest object that Bun.serve() can use to serve the assets.
|
||||
|
||||
```ts
|
||||
import { serve } from "bun";
|
||||
import index from "./index.html";
|
||||
|
||||
serve({
|
||||
routes: { "/": index },
|
||||
});
|
||||
```
|
||||
|
||||
{% details summary="Internally, the `index` variable is a manifest object that looks something like this" %}
|
||||
|
||||
```json
|
||||
{
|
||||
"index": "./index.html",
|
||||
"files": [
|
||||
{
|
||||
"input": "index.html",
|
||||
"path": "./index-f2me3qnf.js",
|
||||
"loader": "js",
|
||||
"isEntry": true,
|
||||
"headers": {
|
||||
"etag": "eet6gn75",
|
||||
"content-type": "text/javascript;charset=utf-8"
|
||||
}
|
||||
},
|
||||
{
|
||||
"input": "index.html",
|
||||
"path": "./index.html",
|
||||
"loader": "html",
|
||||
"isEntry": true,
|
||||
"headers": {
|
||||
"etag": "r9njjakd",
|
||||
"content-type": "text/html;charset=utf-8"
|
||||
}
|
||||
},
|
||||
{
|
||||
"input": "index.html",
|
||||
"path": "./index-gysa5fmk.css",
|
||||
"loader": "css",
|
||||
"isEntry": true,
|
||||
"headers": {
|
||||
"etag": "50zb7x61",
|
||||
"content-type": "text/css;charset=utf-8"
|
||||
}
|
||||
},
|
||||
{
|
||||
"input": "logo.svg",
|
||||
"path": "./logo-kygw735p.svg",
|
||||
"loader": "file",
|
||||
"isEntry": false,
|
||||
"headers": {
|
||||
"etag": "kygw735p",
|
||||
"content-type": "application/octet-stream"
|
||||
}
|
||||
},
|
||||
{
|
||||
"input": "react.svg",
|
||||
"path": "./react-ck11dneg.svg",
|
||||
"loader": "file",
|
||||
"isEntry": false,
|
||||
"headers": {
|
||||
"etag": "ck11dneg",
|
||||
"content-type": "application/octet-stream"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
{% /details %}
|
||||
|
||||
##### Runtime bundling
|
||||
|
||||
When adding a build step is too complicated, you can set `development: false` in `Bun.serve()`.
|
||||
When serving your app in production, set `development: false` in `Bun.serve()`.
|
||||
|
||||
- Enable in-memory caching of bundled assets. Bun will bundle assets lazily on the first request to an `.html` file, and cache the result in memory until the server restarts.
|
||||
- Enables `Cache-Control` headers and `ETag` headers
|
||||
@@ -381,6 +298,7 @@ Note: this is currently in `bunfig.toml` to make it possible to know statically
|
||||
Bun uses [`HTMLRewriter`](/docs/api/html-rewriter) to scan for `<script>` and `<link>` tags in HTML files, uses them as entrypoints for [Bun's bundler](/docs/bundler), generates an optimized bundle for the JavaScript/TypeScript/TSX/JSX and CSS files, and serves the result.
|
||||
|
||||
1. **`<script>` processing**
|
||||
|
||||
- Transpiles TypeScript, JSX, and TSX in `<script>` tags
|
||||
- Bundles imported dependencies
|
||||
- Generates sourcemaps for debugging
|
||||
@@ -391,6 +309,7 @@ Bun uses [`HTMLRewriter`](/docs/api/html-rewriter) to scan for `<script>` and `<
|
||||
```
|
||||
|
||||
2. **`<link>` processing**
|
||||
|
||||
- Processes CSS imports and `<link>` tags
|
||||
- Concatenates CSS files
|
||||
- Rewrites `url` and asset paths to include content-addressable hashes in URLs
|
||||
@@ -400,15 +319,18 @@ Bun uses [`HTMLRewriter`](/docs/api/html-rewriter) to scan for `<script>` and `<
|
||||
```
|
||||
|
||||
3. **`<img>` & asset processing**
|
||||
|
||||
- Links to assets are rewritten to include content-addressable hashes in URLs
|
||||
- Small assets in CSS files are inlined into `data:` URLs, reducing the total number of HTTP requests sent over the wire
|
||||
|
||||
4. **Rewrite HTML**
|
||||
|
||||
- Combines all `<script>` tags into a single `<script>` tag with a content-addressable hash in the URL
|
||||
- Combines all `<link>` tags into a single `<link>` tag with a content-addressable hash in the URL
|
||||
- Outputs a new HTML file
|
||||
|
||||
5. **Serve**
|
||||
|
||||
- All the output files from the bundler are exposed as static routes, using the same mechanism internally as when you pass a `Response` object to [`static` in `Bun.serve()`](/docs/api/http#static-routes).
|
||||
|
||||
This works similarly to how [`Bun.build` processes HTML files](/docs/bundler/html).
|
||||
|
||||
@@ -206,38 +206,6 @@ Each call to `console.log` or `console.error` will be broadcast to the terminal
|
||||
|
||||
Internally, this reuses the existing WebSocket connection from hot module reloading to send the logs.
|
||||
|
||||
### Edit files in the browser
|
||||
|
||||
Bun's frontend dev server has support for [Automatic Workspace Folders](https://chromium.googlesource.com/devtools/devtools-frontend/+/main/docs/ecosystem/automatic_workspace_folders.md) in Chrome DevTools, which lets you save edits to files in the browser.
|
||||
|
||||
{% image src="/images/bun-chromedevtools.gif" alt="Bun's frontend dev server has support for Automatic Workspace Folders in Chrome DevTools, which lets you save edits to files in the browser." /%}
|
||||
|
||||
{% details summary="How it works" %}
|
||||
|
||||
Bun's dev server automatically adds a `/.well-known/appspecific/com.chrome.devtools.json` route to the server.
|
||||
|
||||
This route returns a JSON object with the following shape:
|
||||
|
||||
```json
|
||||
{
|
||||
"workspace": {
|
||||
"root": "/path/to/your/project",
|
||||
"uuid": "a-unique-identifier-for-this-workspace"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
For security reasons, this is only enabled when:
|
||||
|
||||
1. The request is coming from localhost, 127.0.0.1, or ::1.
|
||||
2. Hot Module Reloading is enabled.
|
||||
3. The `chromeDevToolsAutomaticWorkspaceFolders` flag is set to `true` or `undefined`.
|
||||
4. There are no other routes that match the request.
|
||||
|
||||
You can disable this by passing `development: { chromeDevToolsAutomaticWorkspaceFolders: false }` in `Bun.serve`'s options.
|
||||
|
||||
{% /details %}
|
||||
|
||||
## Keyboard Shortcuts
|
||||
|
||||
While the server is running:
|
||||
|
||||
@@ -26,7 +26,6 @@ The bundler is a key piece of infrastructure in the JavaScript ecosystem. As a b
|
||||
- **Reducing HTTP requests.** A single package in `node_modules` may consist of hundreds of files, and large applications may have dozens of such dependencies. Loading each of these files with a separate HTTP request becomes untenable very quickly, so bundlers are used to convert our application source code into a smaller number of self-contained "bundles" that can be loaded with a single request.
|
||||
- **Code transforms.** Modern apps are commonly built with languages or tools like TypeScript, JSX, and CSS modules, all of which must be converted into plain JavaScript and CSS before they can be consumed by a browser. The bundler is the natural place to configure these transformations.
|
||||
- **Framework features.** Frameworks rely on bundler plugins & code transformations to implement common patterns like file-system routing, client-server code co-location (think `getServerSideProps` or Remix loaders), and server components.
|
||||
- **Full-stack Applications.** Bun's bundler can handle both server and client code in a single command, enabling optimized production builds and single-file executables. With build-time HTML imports, you can bundle your entire application — frontend assets and backend server — into a single deployable unit.
|
||||
|
||||
Let's jump into the bundler API.
|
||||
|
||||
@@ -325,7 +324,7 @@ Depending on the target, Bun will apply different module resolution rules and op
|
||||
---
|
||||
|
||||
- `bun`
|
||||
- For generating bundles that are intended to be run by the Bun runtime. In many cases, it isn't necessary to bundle server-side code; you can directly execute the source code without modification. However, bundling your server code can reduce startup times and improve running performance. This is the target to use for building full-stack applications with build-time HTML imports, where both server and client code are bundled together.
|
||||
- For generating bundles that are intended to be run by the Bun runtime. In many cases, it isn't necessary to bundle server-side code; you can directly execute the source code without modification. However, bundling your server code can reduce startup times and improve running performance.
|
||||
|
||||
All bundles generated with `target: "bun"` are marked with a special `// @bun` pragma, which indicates to the Bun runtime that there's no need to re-transpile the file before execution.
|
||||
|
||||
|
||||
@@ -262,20 +262,6 @@ Currently, the list of selectors is:
|
||||
- `video[poster]`
|
||||
- `video[src]`
|
||||
|
||||
{% callout %}
|
||||
|
||||
**HTML Loader Behavior in Different Contexts**
|
||||
|
||||
The `html` loader behaves differently depending on how it's used:
|
||||
|
||||
1. **Static Build:** When you run `bun build ./index.html`, Bun produces a static site with all assets bundled and hashed.
|
||||
|
||||
2. **Runtime:** When you run `bun run server.ts` (where `server.ts` imports an HTML file), Bun bundles assets on-the-fly during development, enabling features like hot module replacement.
|
||||
|
||||
3. **Full-stack Build:** When you run `bun build --target=bun server.ts` (where `server.ts` imports an HTML file), the import resolves to a manifest object that `Bun.serve` uses to efficiently serve pre-bundled assets in production.
|
||||
|
||||
{% /callout %}
|
||||
|
||||
### `sh` loader
|
||||
|
||||
**Bun Shell loader**. Default for `.sh` files
|
||||
|
||||
@@ -125,7 +125,7 @@ In Bun's CLI, simple boolean flags like `--minify` do not accept an argument. Ot
|
||||
|
||||
- `--target`
|
||||
- n/a
|
||||
- Not supported. Bun's bundler performs no syntactic down-leveling at this time.
|
||||
- No supported. Bun's bundler performs no syntactic down-leveling at this time.
|
||||
|
||||
---
|
||||
|
||||
|
||||
@@ -308,12 +308,14 @@ IF remote template
|
||||
1. GET `registry.npmjs.org/@bun-examples/${template}/latest` and parse it
|
||||
2. GET `registry.npmjs.org/@bun-examples/${template}/-/${template}-${latestVersion}.tgz`
|
||||
3. Decompress & extract `${template}-${latestVersion}.tgz` into `${destination}`
|
||||
|
||||
- If there are files that would overwrite, warn and exit unless `--force` is passed
|
||||
|
||||
IF GitHub repo
|
||||
|
||||
1. Download the tarball from GitHub’s API
|
||||
2. Decompress & extract into `${destination}`
|
||||
|
||||
- If there are files that would overwrite, warn and exit unless `--force` is passed
|
||||
|
||||
ELSE IF local template
|
||||
@@ -331,6 +333,7 @@ ELSE IF local template
|
||||
7. Run `${npmClient} install` unless `--no-install` is passed OR no dependencies are in package.json
|
||||
8. Run any tasks defined in `"bun-create": { "postinstall" }` with the npm client
|
||||
9. Run `git init; git add -A .; git commit -am "Initial Commit";`
|
||||
|
||||
- Rename `gitignore` to `.gitignore`. NPM automatically removes `.gitignore` files from appearing in packages.
|
||||
- If there are dependencies, this runs in a separate thread concurrently while node_modules are being installed
|
||||
- Using libgit2 if available was tested and performed 3x slower in microbenchmarks
|
||||
|
||||
@@ -1,65 +0,0 @@
|
||||
`bun info` displays package metadata from the npm registry.
|
||||
|
||||
## Usage
|
||||
|
||||
```bash
|
||||
$ bun info react
|
||||
```
|
||||
|
||||
This will display information about the `react` package, including its latest version, description, homepage, dependencies, and more.
|
||||
|
||||
## Viewing specific versions
|
||||
|
||||
To view information about a specific version:
|
||||
|
||||
```bash
|
||||
$ bun info react@18.0.0
|
||||
```
|
||||
|
||||
## Viewing specific properties
|
||||
|
||||
You can also query specific properties from the package metadata:
|
||||
|
||||
```bash
|
||||
$ bun info react version
|
||||
$ bun info react dependencies
|
||||
$ bun info react repository.url
|
||||
```
|
||||
|
||||
## JSON output
|
||||
|
||||
To get the output in JSON format, use the `--json` flag:
|
||||
|
||||
```bash
|
||||
$ bun info react --json
|
||||
```
|
||||
|
||||
## Alias
|
||||
|
||||
`bun pm view` is an alias for `bun info`:
|
||||
|
||||
```bash
|
||||
$ bun pm view react # equivalent to: bun info react
|
||||
```
|
||||
|
||||
## Examples
|
||||
|
||||
```bash
|
||||
# View basic package information
|
||||
$ bun info is-number
|
||||
|
||||
# View a specific version
|
||||
$ bun info is-number@7.0.0
|
||||
|
||||
# View all available versions
|
||||
$ bun info is-number versions
|
||||
|
||||
# View package dependencies
|
||||
$ bun info express dependencies
|
||||
|
||||
# View package homepage
|
||||
$ bun info lodash homepage
|
||||
|
||||
# Get JSON output
|
||||
$ bun info react --json
|
||||
```
|
||||
@@ -67,6 +67,16 @@ $ bun pm ls --all
|
||||
├── ...
|
||||
```
|
||||
|
||||
To output the list in JSON format, use `--json`. This can be combined with `--all`.
|
||||
|
||||
```bash
|
||||
$ bun pm ls --json
|
||||
["eslint@8.38.0", "react@18.2.0", ...]
|
||||
|
||||
$ bun pm ls --all --json
|
||||
["@eslint-community/eslint-utils@4.4.0", ...]
|
||||
```
|
||||
|
||||
## whoami
|
||||
|
||||
Print your npm username. Requires you to be logged in (`bunx npm login`) with credentials in either `bunfig.toml` or `.npmrc`:
|
||||
|
||||
@@ -30,7 +30,7 @@ $ bun add @prisma/client
|
||||
We'll use the Prisma CLI with `bunx` to initialize our schema and migration directory. For simplicity we'll be using an in-memory SQLite database.
|
||||
|
||||
```bash
|
||||
$ bunx --bun prisma init --datasource-provider sqlite
|
||||
$ bunx prisma init --datasource-provider sqlite
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
@@ -1,50 +1,49 @@
|
||||
---
|
||||
name: Build a React app with Bun
|
||||
name: Use React and JSX
|
||||
---
|
||||
|
||||
Bun supports `.jsx` and `.tsx` files out of the box. React just works with Bun.
|
||||
React just works with Bun. Bun supports `.jsx` and `.tsx` files out of the box.
|
||||
|
||||
Create a new React app with `bun init --react`. This gives you a template with a simple React app and a simple API server together in one full-stack app.
|
||||
Remember that JSX is just a special syntax for including HTML-like syntax in JavaScript files. React uses JSX syntax, as do alternatives like [Preact](https://preactjs.com/) and [Solid](https://www.solidjs.com/). Bun's internal transpiler converts JSX syntax into vanilla JavaScript before execution.
|
||||
|
||||
---
|
||||
|
||||
Bun _assumes_ you're using React (unless you [configure it otherwise](https://bun.sh/docs/runtime/bunfig#jsx)) so a line like this:
|
||||
|
||||
```
|
||||
const element = <h1>Hello, world!</h1>;
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
is internally converted into something like this:
|
||||
|
||||
```ts
|
||||
// jsxDEV
|
||||
import { jsx } from "react/jsx-dev-runtime";
|
||||
|
||||
const element = jsx("h1", { children: "Hello, world!" });
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
This code requires `react` to run, so make sure you've installed React.
|
||||
|
||||
```bash
|
||||
# Create a new React app
|
||||
$ bun init --react
|
||||
|
||||
# Run the app in development mode
|
||||
$ bun dev
|
||||
|
||||
# Build as a static site for production
|
||||
$ bun run build
|
||||
|
||||
# Run the server in production
|
||||
$ bun start
|
||||
$ bun install react
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### Hot Reloading
|
||||
|
||||
Run `bun dev` to start the app in development mode. This will start the API server and the React app with hot reloading.
|
||||
|
||||
### Full-Stack App
|
||||
|
||||
Run `bun start` to start the API server and frontend together in one process.
|
||||
|
||||
### Static Site
|
||||
|
||||
Run `bun run build` to build the app as a static site. This will create a `dist` directory with the built app and all the assets.
|
||||
Bun implements special logging for JSX components to make debugging easier.
|
||||
|
||||
```bash
|
||||
$ bun run log-my-component.tsx
|
||||
<Component message="Hello world!" />
|
||||
```
|
||||
├── src/
|
||||
│ ├── index.tsx # Server entry point with API routes
|
||||
│ ├── frontend.tsx # React app entry point with HMR
|
||||
│ ├── App.tsx # Main React component
|
||||
│ ├── APITester.tsx # Component for testing API endpoints
|
||||
│ ├── index.html # HTML template
|
||||
│ ├── index.css # Styles
|
||||
│ └── *.svg # Static assets
|
||||
├── package.json # Dependencies and scripts
|
||||
├── tsconfig.json # TypeScript configuration
|
||||
├── bunfig.toml # Bun configuration
|
||||
└── bun.lock # Lock file
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
As far as "official support" for React goes, that's it. React is a library like any other, and Bun can run that library. Bun is not a framework, so you should use a framework like [Vite](https://vitejs.dev/) to build an app with server-side rendering and hot reloading in the browser.
|
||||
|
||||
Refer to [Runtime > JSX](https://bun.sh/docs/runtime/jsx) for complete documentation on configuring JSX.
|
||||
|
||||
@@ -166,6 +166,13 @@ my-pkg node_modules
|
||||
...
|
||||
```
|
||||
|
||||
You can output the list in JSON format with `--json`:
|
||||
|
||||
```sh
|
||||
$ bun pm ls --json
|
||||
["@types/node@20.16.5", "@types/react@18.3.8", ...]
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Create a package tarball
|
||||
|
||||
@@ -13,14 +13,14 @@ proc.stderr; // => ReadableStream
|
||||
|
||||
---
|
||||
|
||||
To read `stderr` until the child process exits, use .text()
|
||||
To read `stderr` until the child process exits, use the [`Bun.readableStreamToText()`](https://bun.sh/docs/api/utils#bun-readablestreamto) convenience function.
|
||||
|
||||
```ts
|
||||
const proc = Bun.spawn(["echo", "hello"], {
|
||||
stderr: "pipe",
|
||||
});
|
||||
|
||||
const errors: string = await proc.stderr.text();
|
||||
const errors: string = await Bun.readableStreamToText(proc.stderr);
|
||||
if (errors) {
|
||||
// handle errors
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ When using [`Bun.spawn()`](https://bun.sh/docs/api/spawn), the `stdout` of the c
|
||||
```ts
|
||||
const proc = Bun.spawn(["echo", "hello"]);
|
||||
|
||||
const output = await proc.stdout.text();
|
||||
const output = await new Response(proc.stdout).text();
|
||||
output; // => "hello"
|
||||
```
|
||||
|
||||
|
||||
@@ -32,8 +32,8 @@ By default, the `stdout` of the child process can be consumed as a `ReadableStre
|
||||
```ts
|
||||
const proc = Bun.spawn(["echo", "hello"]);
|
||||
|
||||
const output = await proc.stdout.text();
|
||||
output; // => "hello\n"
|
||||
const output = await new Response(proc.stdout).text();
|
||||
output; // => "hello"
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
@@ -1,37 +0,0 @@
|
||||
`bun audit` checks your installed packages for known security vulnerabilities.
|
||||
|
||||
Run the command in a project with a `bun.lock` file:
|
||||
|
||||
```bash
|
||||
$ bun audit
|
||||
```
|
||||
|
||||
Bun sends the list of installed packages and versions to NPM, and prints a report of any vulnerabilities that were found. Packages installed from registries other than the default registry are skipped.
|
||||
|
||||
If no vulnerabilities are found, the command prints:
|
||||
|
||||
```
|
||||
No vulnerabilities found
|
||||
```
|
||||
|
||||
When vulnerabilities are detected, each affected package is listed along with the severity, a short description and a link to the advisory. At the end of the report Bun prints a summary and hints for updating:
|
||||
|
||||
```
|
||||
3 vulnerabilities (1 high, 2 moderate)
|
||||
To update all dependencies to the latest compatible versions:
|
||||
bun update
|
||||
To update all dependencies to the latest versions (including breaking changes):
|
||||
bun update --latest
|
||||
```
|
||||
|
||||
### `--json`
|
||||
|
||||
Use the `--json` flag to print the raw JSON response from the registry instead of the formatted report:
|
||||
|
||||
```bash
|
||||
$ bun audit --json
|
||||
```
|
||||
|
||||
### Exit code
|
||||
|
||||
`bun audit` will exit with code `0` if no vulnerabilities are found and `1` if the report lists any vulnerabilities. This will still happen even if `--json` is passed.
|
||||
@@ -206,7 +206,7 @@ $ iex "& {$(irm https://bun.sh/install.ps1)} -Version $BUN_LATEST_VERSION"
|
||||
|
||||
## Downloading Bun binaries directly
|
||||
|
||||
To download Bun binaries directly, you can visit the [releases page](https://github.com/oven-sh/bun/releases) on GitHub.
|
||||
To download Bun binaries directly, you can visit the [releases page](https://github.com/oven-sh/bun/releases) page on GitHub.
|
||||
|
||||
For convenience, here are download links for the latest version:
|
||||
|
||||
@@ -223,16 +223,7 @@ For convenience, here are download links for the latest version:
|
||||
|
||||
The `musl` binaries are built for distributions that do not ship with the glibc libraries by default, instead relying on musl. The two most popular distros are Void Linux and Alpine Linux, with the latter is used heavily in Docker containers. If you encounter an error like the following: `bun: /lib/x86_64-linux-gnu/libm.so.6: version GLIBC_2.29' not found (required by bun)`, try using the musl binary. Bun's install script automatically chooses the correct binary for your system.
|
||||
|
||||
### CPU requirements and `baseline` builds
|
||||
|
||||
Bun's `x64` binaries target the Haswell CPU architecture, which means they require AVX and AVX2 instructions. For Linux and Windows, the `x64-baseline` binaries are also available which target the Nehalem architecture. If you run into an "Illegal Instruction" error when running Bun, try using the `baseline` binaries instead. Bun's install script automatically chooses the correct binary for your system which helps avoid this issue. Baseline builds are slower than regular builds, so use them only if necessary.
|
||||
|
||||
| Build | Intel requirement | AMD requirement |
|
||||
| ------------ | ------------------------------------------------------------------ | ------------------ |
|
||||
| x64 | Haswell (4th generation Core) or newer, except some low-end models | Excavator or newer |
|
||||
| x64-baseline | Nehalem (1st generation Core) or newer | Bulldozer or newer |
|
||||
|
||||
Bun does not currently support any CPUs older than the `baseline` target, which mandates the SSE4.2 extension.
|
||||
Bun's `x64` binaries target the Haswell CPU architecture, which means they require AVX and AVX2 instructions. For Linux and Windows, the `x64-baseline` binaries are also available which target the Nehalem architecture. If you run into an "Illegal Instruction" error when running Bun, try using the `baseline` binaries instead. Bun's install scripts automatically chooses the correct binary for your system which helps avoid this issue. Baseline builds are slower than regular builds, so use them only if necessary.
|
||||
|
||||
Bun also publishes `darwin-x64-baseline` binaries, but these are just a copy of the `darwin-x64` ones so they still have the same CPU requirement. We only maintain these since some tools expect them to exist. Bun requires macOS 13.0 or later, which does not support any CPUs that don't meet our requirement.
|
||||
|
||||
|
||||
@@ -207,9 +207,6 @@ export default {
|
||||
description:
|
||||
"Patch dependencies in your project to fix bugs or add features without vendoring the entire package.",
|
||||
}),
|
||||
page("install/audit", "Audit dependencies", {
|
||||
description: "Check installed packages for vulnerabilities.",
|
||||
}),
|
||||
page("install/npmrc", ".npmrc support", {
|
||||
description: "Bun supports loading some configuration options from .npmrc",
|
||||
}),
|
||||
@@ -395,7 +392,7 @@ export default {
|
||||
page("api/cc", "C Compiler", {
|
||||
description: `Build & run native C from JavaScript with Bun's native C compiler API`,
|
||||
}), // "`bun:ffi`"),
|
||||
page("cli/test", "Testing", {
|
||||
page("api/test", "Testing", {
|
||||
description: `Bun's built-in test runner is fast and uses Jest-compatible syntax.`,
|
||||
}), // "`bun:test`"),
|
||||
page("api/utils", "Utils", {
|
||||
|
||||
@@ -19,43 +19,31 @@ Click the link in the right column to jump to the associated documentation.
|
||||
|
||||
---
|
||||
|
||||
- HTTP Server
|
||||
- HTTP server
|
||||
- [`Bun.serve`](https://bun.sh/docs/api/http#bun-serve)
|
||||
|
||||
---
|
||||
|
||||
- Shell
|
||||
- [`$`](https://bun.sh/docs/runtime/shell)
|
||||
|
||||
---
|
||||
|
||||
- Bundler
|
||||
- [`Bun.build`](https://bun.sh/docs/bundler)
|
||||
|
||||
---
|
||||
|
||||
- File I/O
|
||||
- [`Bun.file`](https://bun.sh/docs/api/file-io#reading-files-bun-file), [`Bun.write`](https://bun.sh/docs/api/file-io#writing-files-bun-write), `Bun.stdin`, `Bun.stdout`, `Bun.stderr`
|
||||
- [`Bun.file`](https://bun.sh/docs/api/file-io#reading-files-bun-file)
|
||||
[`Bun.write`](https://bun.sh/docs/api/file-io#writing-files-bun-write)
|
||||
|
||||
---
|
||||
|
||||
- Child Processes
|
||||
- [`Bun.spawn`](https://bun.sh/docs/api/spawn#spawn-a-process-bun-spawn), [`Bun.spawnSync`](https://bun.sh/docs/api/spawn#blocking-api-bun-spawnsync)
|
||||
- Child processes
|
||||
- [`Bun.spawn`](https://bun.sh/docs/api/spawn#spawn-a-process-bun-spawn)
|
||||
[`Bun.spawnSync`](https://bun.sh/docs/api/spawn#blocking-api-bun-spawnsync)
|
||||
|
||||
---
|
||||
|
||||
- TCP Sockets
|
||||
- [`Bun.listen`](https://bun.sh/docs/api/tcp#start-a-server-bun-listen), [`Bun.connect`](https://bun.sh/docs/api/tcp#start-a-server-bun-listen)
|
||||
|
||||
---
|
||||
|
||||
- UDP Sockets
|
||||
- [`Bun.udpSocket`](https://bun.sh/docs/api/udp)
|
||||
|
||||
---
|
||||
|
||||
- WebSockets
|
||||
- `new WebSocket()` (client), [`Bun.serve`](https://bun.sh/docs/api/websockets) (server)
|
||||
- TCP
|
||||
- [`Bun.listen`](https://bun.sh/docs/api/tcp#start-a-server-bun-listen)
|
||||
[`Bun.connect`](https://bun.sh/docs/api/tcp#start-a-server-bun-listen)
|
||||
|
||||
---
|
||||
|
||||
@@ -69,53 +57,44 @@ Click the link in the right column to jump to the associated documentation.
|
||||
|
||||
---
|
||||
|
||||
- Streaming HTML
|
||||
- Streaming HTML Transformations
|
||||
- [`HTMLRewriter`](https://bun.sh/docs/api/html-rewriter)
|
||||
|
||||
---
|
||||
|
||||
- Hashing
|
||||
- [`Bun.password`](https://bun.sh/docs/api/hashing#bun-password), [`Bun.hash`](https://bun.sh/docs/api/hashing#bun-hash), [`Bun.CryptoHasher`](https://bun.sh/docs/api/hashing#bun-cryptohasher), `Bun.sha`
|
||||
- [`Bun.hash`](https://bun.sh/docs/api/hashing#bun-hash)
|
||||
[`Bun.CryptoHasher`](https://bun.sh/docs/api/hashing#bun-cryptohasher)
|
||||
|
||||
---
|
||||
|
||||
- import.meta
|
||||
- [`import.meta`](https://bun.sh/docs/api/import-meta)
|
||||
|
||||
---
|
||||
|
||||
<!-- - [DNS](https://bun.sh/docs/api/dns)
|
||||
- `Bun.dns`
|
||||
|
||||
--- -->
|
||||
|
||||
- SQLite
|
||||
- [`bun:sqlite`](https://bun.sh/docs/api/sqlite)
|
||||
|
||||
---
|
||||
|
||||
- PostgreSQL Client
|
||||
- [`Bun.SQL`](https://bun.sh/docs/api/sql), `Bun.sql`
|
||||
|
||||
---
|
||||
|
||||
- Redis (Valkey) Client
|
||||
- [`Bun.RedisClient`](https://bun.sh/docs/api/redis), `Bun.redis`
|
||||
|
||||
---
|
||||
|
||||
- FFI (Foreign Function Interface)
|
||||
- FFI
|
||||
- [`bun:ffi`](https://bun.sh/docs/api/ffi)
|
||||
|
||||
---
|
||||
|
||||
- DNS
|
||||
- [`Bun.dns.lookup`](https://bun.sh/docs/api/dns), `Bun.dns.prefetch`, `Bun.dns.getCacheStats`
|
||||
|
||||
---
|
||||
|
||||
- Testing
|
||||
- [`bun:test`](https://bun.sh/docs/cli/test)
|
||||
|
||||
---
|
||||
|
||||
- Workers
|
||||
- [`new Worker()`](https://bun.sh/docs/api/workers)
|
||||
|
||||
---
|
||||
|
||||
- Module Loaders
|
||||
- [`Bun.plugin`](https://bun.sh/docs/bundler/plugins)
|
||||
- Node-API
|
||||
- [`Node-API`](https://bun.sh/docs/api/node-api)
|
||||
|
||||
---
|
||||
|
||||
@@ -124,84 +103,27 @@ Click the link in the right column to jump to the associated documentation.
|
||||
|
||||
---
|
||||
|
||||
- Cookies
|
||||
- [`Bun.Cookie`](https://bun.sh/docs/api/cookie), [`Bun.CookieMap`](https://bun.sh/docs/api/cookie)
|
||||
|
||||
---
|
||||
|
||||
- Node-API
|
||||
- [`Node-API`](https://bun.sh/docs/api/node-api)
|
||||
|
||||
---
|
||||
|
||||
- `import.meta`
|
||||
- [`import.meta`](https://bun.sh/docs/api/import-meta)
|
||||
|
||||
---
|
||||
|
||||
- Utilities
|
||||
- [`Bun.version`](https://bun.sh/docs/api/utils#bun-version), [`Bun.revision`](https://bun.sh/docs/api/utils#bun-revision), [`Bun.env`](https://bun.sh/docs/api/utils#bun-env), [`Bun.main`](https://bun.sh/docs/api/utils#bun-main)
|
||||
|
||||
---
|
||||
|
||||
- Sleep & Timing
|
||||
- [`Bun.sleep()`](https://bun.sh/docs/api/utils#bun-sleep), [`Bun.sleepSync()`](https://bun.sh/docs/api/utils#bun-sleepsync), [`Bun.nanoseconds()`](https://bun.sh/docs/api/utils#bun-nanoseconds)
|
||||
|
||||
---
|
||||
|
||||
- Random & UUID
|
||||
- [`Bun.randomUUIDv7()`](https://bun.sh/docs/api/utils#bun-randomuuidv7)
|
||||
|
||||
---
|
||||
|
||||
- System & Environment
|
||||
- [`Bun.which()`](https://bun.sh/docs/api/utils#bun-which)
|
||||
|
||||
---
|
||||
|
||||
- Comparison & Inspection
|
||||
- [`Bun.peek()`](https://bun.sh/docs/api/utils#bun-peek), [`Bun.deepEquals()`](https://bun.sh/docs/api/utils#bun-deepequals), `Bun.deepMatch`, [`Bun.inspect()`](https://bun.sh/docs/api/utils#bun-inspect)
|
||||
|
||||
---
|
||||
|
||||
- String & Text Processing
|
||||
- [`Bun.escapeHTML()`](https://bun.sh/docs/api/utils#bun-escapehtml), [`Bun.stringWidth()`](https://bun.sh/docs/api/utils#bun-stringwidth), `Bun.indexOfLine`
|
||||
|
||||
---
|
||||
|
||||
- URL & Path Utilities
|
||||
- [`Bun.fileURLToPath()`](https://bun.sh/docs/api/utils#bun-fileurltopath), [`Bun.pathToFileURL()`](https://bun.sh/docs/api/utils#bun-pathtofileurl)
|
||||
|
||||
---
|
||||
|
||||
- Compression
|
||||
- [`Bun.gzipSync()`](https://bun.sh/docs/api/utils#bun-gzipsync), [`Bun.gunzipSync()`](https://bun.sh/docs/api/utils#bun-gunzipsync), [`Bun.deflateSync()`](https://bun.sh/docs/api/utils#bun-deflatesync), [`Bun.inflateSync()`](https://bun.sh/docs/api/utils#bun-inflatesync), `Bun.zstdCompressSync()`, `Bun.zstdDecompressSync()`, `Bun.zstdCompress()`, `Bun.zstdDecompress()`
|
||||
|
||||
---
|
||||
|
||||
- Stream Processing
|
||||
- [`Bun.readableStreamTo*()`](https://bun.sh/docs/api/utils#bun-readablestreamto), `Bun.readableStreamToBytes()`, `Bun.readableStreamToBlob()`, `Bun.readableStreamToFormData()`, `Bun.readableStreamToJSON()`, `Bun.readableStreamToArray()`
|
||||
|
||||
---
|
||||
|
||||
- Memory & Buffer Management
|
||||
- `Bun.ArrayBufferSink`, `Bun.allocUnsafe`, `Bun.concatArrayBuffers`
|
||||
|
||||
---
|
||||
|
||||
- Module Resolution
|
||||
- [`Bun.resolveSync()`](https://bun.sh/docs/api/utils#bun-resolvesync)
|
||||
|
||||
---
|
||||
|
||||
- Parsing & Formatting
|
||||
- [`Bun.semver`](https://bun.sh/docs/api/semver), `Bun.TOML.parse`, [`Bun.color`](https://bun.sh/docs/api/color)
|
||||
|
||||
---
|
||||
|
||||
- Low-level / Internals
|
||||
- `Bun.mmap`, `Bun.gc`, `Bun.generateHeapSnapshot`, [`bun:jsc`](https://bun.sh/docs/api/bun-jsc)
|
||||
|
||||
---
|
||||
- [`Bun.version`](https://bun.sh/docs/api/utils#bun-version)
|
||||
[`Bun.revision`](https://bun.sh/docs/api/utils#bun-revision)
|
||||
[`Bun.env`](https://bun.sh/docs/api/utils#bun-env)
|
||||
[`Bun.main`](https://bun.sh/docs/api/utils#bun-main)
|
||||
[`Bun.sleep()`](https://bun.sh/docs/api/utils#bun-sleep)
|
||||
[`Bun.sleepSync()`](https://bun.sh/docs/api/utils#bun-sleepsync)
|
||||
[`Bun.which()`](https://bun.sh/docs/api/utils#bun-which)
|
||||
[`Bun.peek()`](https://bun.sh/docs/api/utils#bun-peek)
|
||||
[`Bun.openInEditor()`](https://bun.sh/docs/api/utils#bun-openineditor)
|
||||
[`Bun.deepEquals()`](https://bun.sh/docs/api/utils#bun-deepequals)
|
||||
[`Bun.escapeHTML()`](https://bun.sh/docs/api/utils#bun-escapehtml)
|
||||
[`Bun.fileURLToPath()`](https://bun.sh/docs/api/utils#bun-fileurltopath)
|
||||
[`Bun.pathToFileURL()`](https://bun.sh/docs/api/utils#bun-pathtofileurl)
|
||||
[`Bun.gzipSync()`](https://bun.sh/docs/api/utils#bun-gzipsync)
|
||||
[`Bun.gunzipSync()`](https://bun.sh/docs/api/utils#bun-gunzipsync)
|
||||
[`Bun.deflateSync()`](https://bun.sh/docs/api/utils#bun-deflatesync)
|
||||
[`Bun.inflateSync()`](https://bun.sh/docs/api/utils#bun-inflatesync)
|
||||
[`Bun.inspect()`](https://bun.sh/docs/api/utils#bun-inspect)
|
||||
[`Bun.nanoseconds()`](https://bun.sh/docs/api/utils#bun-nanoseconds)
|
||||
[`Bun.readableStreamTo*()`](https://bun.sh/docs/api/utils#bun-readablestreamto)
|
||||
[`Bun.resolveSync()`](https://bun.sh/docs/api/utils#bun-resolvesync)
|
||||
|
||||
{% /table %}
|
||||
|
||||
@@ -76,7 +76,7 @@ The `define` field allows you to replace certain global identifiers with constan
|
||||
|
||||
### `loader`
|
||||
|
||||
Configure how Bun maps file extensions to loaders. This is useful for loading files that aren't natively supported by Bun.
|
||||
Configure how Bun maps file extensions to loaders. This is useful for loading files that aren't natively supported by Bun. If
|
||||
|
||||
```toml
|
||||
[loader]
|
||||
@@ -353,8 +353,6 @@ dryRun = false
|
||||
|
||||
To configure the directory where Bun puts globally installed packages.
|
||||
|
||||
Environment variable: `BUN_INSTALL_GLOBAL_DIR`
|
||||
|
||||
```toml
|
||||
[install]
|
||||
# where `bun install --global` installs packages
|
||||
@@ -365,8 +363,6 @@ globalDir = "~/.bun/install/global"
|
||||
|
||||
To configure the directory where Bun installs globally installed binaries and CLIs.
|
||||
|
||||
Environment variable: `BUN_INSTALL_BIN`
|
||||
|
||||
```toml
|
||||
# where globally-installed package bins are linked
|
||||
globalBinDir = "~/.bun/bin"
|
||||
@@ -386,17 +382,6 @@ registry = { url = "https://registry.npmjs.org", token = "123456" }
|
||||
registry = "https://username:password@registry.npmjs.org"
|
||||
```
|
||||
|
||||
### `install.linkWorkspacePackages`
|
||||
|
||||
To configure how workspace packages are linked, use the `install.linkWorkspacePackages` option.
|
||||
|
||||
Whether to link workspace packages from the monorepo root to their respective `node_modules` directories. Default `true`.
|
||||
|
||||
```toml
|
||||
[install]
|
||||
linkWorkspacePackages = true
|
||||
```
|
||||
|
||||
### `install.scopes`
|
||||
|
||||
To configure a registry for a particular scope (e.g. `@myorg/<package>`) use `install.scopes`. You can reference environment variables with `$variable` notation.
|
||||
|
||||
@@ -120,7 +120,7 @@ This page is updated regularly to reflect compatibility status of the latest ver
|
||||
|
||||
### [`node:net`](https://nodejs.org/api/net.html)
|
||||
|
||||
🟢 Fully implemented.
|
||||
🟡 `SocketAddress` class not exposed (but implemented). `BlockList` exists but is a no-op.
|
||||
|
||||
### [`node:perf_hooks`](https://nodejs.org/api/perf_hooks.html)
|
||||
|
||||
|
||||
@@ -102,7 +102,7 @@ Once the plugin is registered, `.yaml` and `.yml` files can be directly imported
|
||||
{% codetabs %}
|
||||
|
||||
```ts#index.ts
|
||||
import * as data from "./data.yml"
|
||||
import data from "./data.yml"
|
||||
|
||||
console.log(data);
|
||||
```
|
||||
|
||||
@@ -206,11 +206,13 @@ Understanding how `mock.module()` works helps you use it more effectively:
|
||||
2. **Lazy Evaluation**: The mock factory callback is only evaluated when the module is actually imported or required.
|
||||
|
||||
3. **Path Resolution**: Bun automatically resolves the module specifier as though you were doing an import, supporting:
|
||||
|
||||
- Relative paths (`'./module'`)
|
||||
- Absolute paths (`'/path/to/module'`)
|
||||
- Package names (`'lodash'`)
|
||||
|
||||
4. **Import Timing Effects**:
|
||||
|
||||
- When mocking before first import: No side effects from the original module occur
|
||||
- When mocking after import: The original module's side effects have already happened
|
||||
- For this reason, using `--preload` is recommended for mocks that need to prevent side effects
|
||||
|
||||
@@ -17,7 +17,6 @@ console.log(Bun.hash.xxHash3(input)); // bigint
|
||||
console.log(Bun.hash.murmur32v3(input)); // number
|
||||
console.log(Bun.hash.murmur32v2(input)); // number
|
||||
console.log(Bun.hash.murmur64v2(input)); // bigint
|
||||
console.log(Bun.hash.rapidhash(input)); // bigint
|
||||
|
||||
// Second argument accepts a seed where relevant
|
||||
console.log(Bun.hash(input, 12345));
|
||||
|
||||
@@ -12,7 +12,7 @@ const C = bun.C;
|
||||
const clap = @import("../src/deps/zig-clap/clap.zig");
|
||||
|
||||
const URL = @import("../src/url.zig").URL;
|
||||
const Method = @import("../src/http/Method.zig").Method;
|
||||
const Method = @import("../src/http/method.zig").Method;
|
||||
const ColonListType = @import("../src/cli/colon_list_type.zig").ColonListType;
|
||||
const HeadersTuple = ColonListType(string, noop_resolver);
|
||||
const path_handler = @import("../src/resolver/resolve_path.zig");
|
||||
|
||||
@@ -1,19 +0,0 @@
|
||||
# This file is separate from .lldbinit because it has to be in the same directory as the Python
|
||||
# modules in order for the "attach" action to work.
|
||||
|
||||
# Tell LLDB what to do when the debugged process receives SIGPWR: pass it through to the process
|
||||
# (-p), but do not stop the process (-s) or notify the user (-n).
|
||||
#
|
||||
# JSC's garbage collector sends this signal (as configured by Bun WebKit in
|
||||
# Thread::initializePlatformThreading() in ThreadingPOSIX.cpp) to the JS thread to suspend or resume
|
||||
# it. So stopping the process would just create noise when debugging any long-running script.
|
||||
process handle -p true -s false -n false SIGPWR
|
||||
|
||||
command script import -c lldb_pretty_printers.py
|
||||
type category enable zig.lang
|
||||
type category enable zig.std
|
||||
|
||||
command script import -c lldb_webkit.py
|
||||
|
||||
command script delete btjs
|
||||
command alias btjs p {printf("gathering btjs trace...\n");printf("%s\n", (char*)dumpBtjsTrace())}
|
||||
@@ -14,7 +14,7 @@ const clap = @import("../src/deps/zig-clap/clap.zig");
|
||||
|
||||
const URL = @import("../src/url.zig").URL;
|
||||
const Headers = bun.http.Headers;
|
||||
const Method = @import("../src/http/Method.zig").Method;
|
||||
const Method = @import("../src/http/method.zig").Method;
|
||||
const ColonListType = @import("../src/cli/colon_list_type.zig").ColonListType;
|
||||
const HeadersTuple = ColonListType(string, noop_resolver);
|
||||
const path_handler = @import("../src/resolver/resolve_path.zig");
|
||||
|
||||
11
package.json
11
package.json
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"private": true,
|
||||
"name": "bun",
|
||||
"version": "1.2.18",
|
||||
"version": "1.2.14",
|
||||
"workspaces": [
|
||||
"./packages/bun-types",
|
||||
"./packages/@types/bun"
|
||||
@@ -24,11 +24,9 @@
|
||||
},
|
||||
"scripts": {
|
||||
"build": "bun run build:debug",
|
||||
"ci": "bun scripts/buildkite-failures.ts ",
|
||||
"watch": "bun run zig build check --watch -fincremental --prominent-compile-errors --global-cache-dir build/debug/zig-check-cache --zig-lib-dir vendor/zig/lib",
|
||||
"watch-windows": "bun run zig build check-windows --watch -fincremental --prominent-compile-errors --global-cache-dir build/debug/zig-check-cache --zig-lib-dir vendor/zig/lib",
|
||||
"bd:v": "(bun run --silent build:debug &> /tmp/bun.debug.build.log || (cat /tmp/bun.debug.build.log && rm -rf /tmp/bun.debug.build.log && exit 1)) && rm -f /tmp/bun.debug.build.log && ./build/debug/bun-debug",
|
||||
"bd": "BUN_DEBUG_QUIET_LOGS=1 bun bd:v",
|
||||
"watch": "zig build check --watch -fincremental --prominent-compile-errors --global-cache-dir build/debug/zig-check-cache --zig-lib-dir vendor/zig/lib",
|
||||
"watch-windows": "zig build check-windows --watch -fincremental --prominent-compile-errors --global-cache-dir build/debug/zig-check-cache --zig-lib-dir vendor/zig/lib",
|
||||
"agent": "(bun run --silent build:debug &> /tmp/bun.debug.build.log || (cat /tmp/bun.debug.build.log && rm -rf /tmp/bun.debug.build.log && exit 1)) && rm -f /tmp/bun.debug.build.log && ./build/debug/bun-debug",
|
||||
"build:debug": "bun ./scripts/build.mjs -GNinja -DCMAKE_BUILD_TYPE=Debug -B build/debug",
|
||||
"build:debug:asan": "bun ./scripts/build.mjs -GNinja -DCMAKE_BUILD_TYPE=Debug -DENABLE_ASAN=ON -B build/debug-asan",
|
||||
"build:valgrind": "bun ./scripts/build.mjs -GNinja -DCMAKE_BUILD_TYPE=Debug -DENABLE_BASELINE=ON -ENABLE_VALGRIND=ON -B build/debug-valgrind",
|
||||
@@ -77,7 +75,6 @@
|
||||
"zig-format:check": "bun run analysis:no-llvm --target zig-format-check",
|
||||
"prettier": "bunx prettier@latest --plugin=prettier-plugin-organize-imports --config .prettierrc --write scripts packages src docs 'test/**/*.{test,spec}.{ts,tsx,js,jsx,mts,mjs,cjs,cts}' '!test/**/*fixture*.*'",
|
||||
"node:test": "node ./scripts/runner.node.mjs --quiet --exec-path=$npm_execpath --node-tests ",
|
||||
"node:test:cp": "bun ./scripts/fetch-node-test.ts ",
|
||||
"clean:zig": "rm -rf build/debug/cache/zig build/debug/CMakeCache.txt 'build/debug/*.o' .zig-cache zig-out || true",
|
||||
"sync-webkit-source": "bun ./scripts/sync-webkit-source.ts"
|
||||
}
|
||||
|
||||
@@ -743,7 +743,7 @@ export abstract class BaseDebugAdapter<T extends Inspector = Inspector>
|
||||
source,
|
||||
request,
|
||||
// It is theoretically possible for a breakpoint to resolve to multiple locations.
|
||||
// In that case, send a separate `breakpoint` event for each one, excluding the first.
|
||||
// In that case, send a seperate `breakpoint` event for each one, excluding the first.
|
||||
notify: i > 0,
|
||||
}),
|
||||
);
|
||||
|
||||
@@ -850,7 +850,7 @@ const Summary = ({ errorCount, onClose }: { errorCount: number; onClose: () => v
|
||||
|
||||
<a href="https://bun.sh/discord" target="_blank" className="BunError-Summary-help">
|
||||
<svg width="18" viewBox="0 0 71 55" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||
<g clipPath="url(#clip0)">
|
||||
<g clip-path="url(#clip0)">
|
||||
<path
|
||||
d="M60.1045 4.8978C55.5792 2.8214 50.7265 1.2916 45.6527 0.41542C45.5603 0.39851 45.468 0.440769 45.4204 0.525289C44.7963 1.6353 44.105 3.0834 43.6209 4.2216C38.1637 3.4046 32.7345 3.4046 27.3892 4.2216C26.905 3.0581 26.1886 1.6353 25.5617 0.525289C25.5141 0.443589 25.4218 0.40133 25.3294 0.41542C20.2584 1.2888 15.4057 2.8186 10.8776 4.8978C10.8384 4.9147 10.8048 4.9429 10.7825 4.9795C1.57795 18.7309 -0.943561 32.1443 0.293408 45.3914C0.299005 45.4562 0.335386 45.5182 0.385761 45.5576C6.45866 50.0174 12.3413 52.7249 18.1147 54.5195C18.2071 54.5477 18.305 54.5139 18.3638 54.4378C19.7295 52.5728 20.9469 50.6063 21.9907 48.5383C22.0523 48.4172 21.9935 48.2735 21.8676 48.2256C19.9366 47.4931 18.0979 46.6 16.3292 45.5858C16.1893 45.5041 16.1781 45.304 16.3068 45.2082C16.679 44.9293 17.0513 44.6391 17.4067 44.3461C17.471 44.2926 17.5606 44.2813 17.6362 44.3151C29.2558 49.6202 41.8354 49.6202 53.3179 44.3151C53.3935 44.2785 53.4831 44.2898 53.5502 44.3433C53.9057 44.6363 54.2779 44.9293 54.6529 45.2082C54.7816 45.304 54.7732 45.5041 54.6333 45.5858C52.8646 46.6197 51.0259 47.4931 49.0921 48.2228C48.9662 48.2707 48.9102 48.4172 48.9718 48.5383C50.038 50.6034 51.2554 52.5699 52.5959 54.435C52.6519 54.5139 52.7526 54.5477 52.845 54.5195C58.6464 52.7249 64.529 50.0174 70.6019 45.5576C70.6551 45.5182 70.6887 45.459 70.6943 45.3942C72.1747 30.0791 68.2147 16.7757 60.1968 4.9823C60.1772 4.9429 60.1437 4.9147 60.1045 4.8978ZM23.7259 37.3253C20.2276 37.3253 17.3451 34.1136 17.3451 30.1693C17.3451 26.225 20.1717 23.0133 23.7259 23.0133C27.308 23.0133 30.1626 26.2532 30.1066 30.1693C30.1066 34.1136 27.28 37.3253 23.7259 37.3253ZM47.3178 37.3253C43.8196 37.3253 40.9371 34.1136 40.9371 30.1693C40.9371 26.225 43.7636 23.0133 47.3178 23.0133C50.9 23.0133 53.7545 26.2532 53.6986 30.1693C53.6986 34.1136 50.9 37.3253 47.3178 37.3253Z"
|
||||
fill="#5865F2"
|
||||
|
||||
@@ -72,7 +72,6 @@ async function buildRootModule(dryRun?: boolean) {
|
||||
},
|
||||
});
|
||||
write(join(cwd, "bin", "bun.exe"), "");
|
||||
write(join(cwd, "bin", "bunx.exe"), "");
|
||||
write(
|
||||
join(cwd, "bin", "README.txt"),
|
||||
`The 'bun.exe' file is a placeholder for the binary file, which
|
||||
@@ -106,7 +105,7 @@ without *requiring* a postinstall script.
|
||||
),
|
||||
bin: {
|
||||
bun: "bin/bun.exe",
|
||||
bunx: "bin/bunx.exe",
|
||||
bunx: "bin/bun.exe",
|
||||
},
|
||||
os,
|
||||
cpu,
|
||||
|
||||
@@ -157,15 +157,3 @@ export function exists(path: string): boolean {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
export function link(path: string, newPath: string): void {
|
||||
debug("link", path, newPath);
|
||||
try {
|
||||
fs.unlinkSync(newPath);
|
||||
fs.linkSync(path, newPath);
|
||||
return;
|
||||
} catch (error) {
|
||||
copy(path, newPath);
|
||||
debug("fs.linkSync failed, reverting to copy", error);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { unzipSync } from "zlib";
|
||||
import { debug, error } from "../console";
|
||||
import { fetch } from "../fetch";
|
||||
import { chmod, join, link, rename, rm, tmp, write } from "../fs";
|
||||
import { chmod, join, rename, rm, tmp, write } from "../fs";
|
||||
import type { Platform } from "../platform";
|
||||
import { abi, arch, os, supportedPlatforms } from "../platform";
|
||||
import { spawn } from "../spawn";
|
||||
@@ -125,7 +125,6 @@ export function optimizeBun(path: string): void {
|
||||
os === "win32" ? 'powershell -c "irm bun.sh/install.ps1 | iex"' : "curl -fsSL https://bun.sh/install | bash";
|
||||
try {
|
||||
rename(path, join(__dirname, "bin", "bun.exe"));
|
||||
link(join(__dirname, "bin", "bun.exe"), join(__dirname, "bin", "bunx.exe"));
|
||||
return;
|
||||
} catch (error) {
|
||||
debug("optimizeBun failed", error);
|
||||
|
||||
@@ -65,11 +65,13 @@ Note: The order of references in `index.d.ts` is important - `bun.ns.d.ts` must
|
||||
### Best Practices
|
||||
|
||||
1. **Type Safety**
|
||||
|
||||
- Please use strict types instead of `any` where possible
|
||||
- Leverage TypeScript's type system features (generics, unions, etc.)
|
||||
- Document complex types with JSDoc comments
|
||||
|
||||
2. **Compatibility**
|
||||
|
||||
- Use `Bun.__internal.UseLibDomIfAvailable<LibDomName extends string, OurType>` for types that might conflict with lib.dom.d.ts (see [`./fetch.d.ts`](./fetch.d.ts) for a real example)
|
||||
- `@types/node` often expects variables to always be defined (this was the biggest cause of most of the conflicts in the past!), so we use the `UseLibDomIfAvailable` type to make sure we don't overwrite `lib.dom.d.ts` but still provide Bun types while simultaneously declaring the variable exists (for Node to work) in the cases that we can.
|
||||
|
||||
|
||||
323
packages/bun-types/bun.d.ts
vendored
323
packages/bun-types/bun.d.ts
vendored
@@ -346,17 +346,6 @@ declare module "bun" {
|
||||
|
||||
type WorkerType = "classic" | "module";
|
||||
|
||||
/**
|
||||
* This type-only interface is identical at runtime to {@link ReadableStream},
|
||||
* and exists to document types that do not exist yet in libdom.
|
||||
*/
|
||||
interface BunReadableStream<T = any> extends ReadableStream<T> {
|
||||
text(): Promise<string>;
|
||||
bytes(): Promise<Uint8Array>;
|
||||
json(): Promise<any>;
|
||||
blob(): Promise<Blob>;
|
||||
}
|
||||
|
||||
interface AbstractWorker {
|
||||
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/ServiceWorker/error_event) */
|
||||
onerror: ((this: AbstractWorker, ev: ErrorEvent) => any) | null;
|
||||
@@ -1137,7 +1126,6 @@ declare module "bun" {
|
||||
* This will be used by fetch() and Bun.connect() to avoid DNS lookups.
|
||||
*
|
||||
* @param hostname The hostname to prefetch
|
||||
* @param port The port to prefetch. Default is 443. Port helps distinguish between IPv6 vs IPv4-only connections.
|
||||
*
|
||||
* @example
|
||||
* ```js
|
||||
@@ -1147,7 +1135,7 @@ declare module "bun" {
|
||||
* await fetch('https://example.com');
|
||||
* ```
|
||||
*/
|
||||
function prefetch(hostname: string, port?: number): void;
|
||||
function prefetch(hostname: string): void;
|
||||
|
||||
/**
|
||||
* **Experimental API**
|
||||
@@ -1253,7 +1241,7 @@ declare module "bun" {
|
||||
*/
|
||||
writer(options?: { highWaterMark?: number }): FileSink;
|
||||
|
||||
readonly readable: BunReadableStream;
|
||||
readonly readable: ReadableStream;
|
||||
|
||||
// TODO: writable: WritableStream;
|
||||
|
||||
@@ -1877,7 +1865,6 @@ declare module "bun" {
|
||||
murmur32v3: (data: string | ArrayBufferView | ArrayBuffer | SharedArrayBuffer, seed?: number) => number;
|
||||
murmur32v2: (data: string | ArrayBufferView | ArrayBuffer | SharedArrayBuffer, seed?: number) => number;
|
||||
murmur64v2: (data: string | ArrayBufferView | ArrayBuffer | SharedArrayBuffer, seed?: bigint) => bigint;
|
||||
rapidhash: (data: string | ArrayBufferView | ArrayBuffer | SharedArrayBuffer, seed?: bigint) => bigint;
|
||||
}
|
||||
|
||||
type JavaScriptLoader = "jsx" | "js" | "ts" | "tsx";
|
||||
@@ -3317,8 +3304,6 @@ declare module "bun" {
|
||||
interface BunRequest<T extends string = string> extends Request {
|
||||
params: RouterTypes.ExtractRouteParams<T>;
|
||||
readonly cookies: CookieMap;
|
||||
|
||||
clone(): BunRequest<T>;
|
||||
}
|
||||
|
||||
interface GenericServeOptions {
|
||||
@@ -3370,30 +3355,6 @@ declare module "bun" {
|
||||
* @default false
|
||||
*/
|
||||
console?: boolean;
|
||||
|
||||
/**
|
||||
* Enable automatic workspace folders for Chrome DevTools
|
||||
*
|
||||
* This lets you persistently edit files in the browser. It works by adding the following route to the server:
|
||||
* `/.well-known/appspecific/com.chrome.devtools.json`
|
||||
*
|
||||
* The response is a JSON object with the following shape:
|
||||
* ```json
|
||||
* {
|
||||
* "workspace": {
|
||||
* "root": "<cwd>",
|
||||
* "uuid": "<uuid>"
|
||||
* }
|
||||
* }
|
||||
* ```
|
||||
*
|
||||
* The `root` field is the current working directory of the server.
|
||||
* The `"uuid"` field is a hash of the file that started the server and a hash of the current working directory.
|
||||
*
|
||||
* For security reasons, if the remote socket address is not from localhost, 127.0.0.1, or ::1, the request is ignored.
|
||||
* @default true
|
||||
*/
|
||||
chromeDevToolsAutomaticWorkspaceFolders?: boolean;
|
||||
};
|
||||
|
||||
error?: (this: Server, error: ErrorLike) => Response | Promise<Response> | void | Promise<void>;
|
||||
@@ -3699,7 +3660,7 @@ declare module "bun" {
|
||||
* the well-known CAs curated by Mozilla. Mozilla's CAs are completely
|
||||
* replaced when CAs are explicitly specified using this option.
|
||||
*/
|
||||
ca?: string | BufferSource | BunFile | Array<string | BufferSource | BunFile> | undefined;
|
||||
ca?: string | Buffer | BunFile | Array<string | Buffer | BunFile> | undefined;
|
||||
/**
|
||||
* Cert chains in PEM format. One cert chain should be provided per
|
||||
* private key. Each cert chain should consist of the PEM formatted
|
||||
@@ -3711,7 +3672,7 @@ declare module "bun" {
|
||||
* intermediate certificates are not provided, the peer will not be
|
||||
* able to validate the certificate, and the handshake will fail.
|
||||
*/
|
||||
cert?: string | BufferSource | BunFile | Array<string | BufferSource | BunFile> | undefined;
|
||||
cert?: string | Buffer | BunFile | Array<string | Buffer | BunFile> | undefined;
|
||||
/**
|
||||
* Private keys in PEM format. PEM allows the option of private keys
|
||||
* being encrypted. Encrypted keys will be decrypted with
|
||||
@@ -3722,25 +3683,13 @@ declare module "bun" {
|
||||
* object.passphrase is optional. Encrypted keys will be decrypted with
|
||||
* object.passphrase if provided, or options.passphrase if it is not.
|
||||
*/
|
||||
key?: string | BufferSource | BunFile | Array<string | BufferSource | BunFile> | undefined;
|
||||
key?: string | Buffer | BunFile | Array<string | Buffer | BunFile> | undefined;
|
||||
/**
|
||||
* Optionally affect the OpenSSL protocol behavior, which is not
|
||||
* usually necessary. This should be used carefully if at all! Value is
|
||||
* a numeric bitmask of the SSL_OP_* options from OpenSSL Options
|
||||
*/
|
||||
secureOptions?: number | undefined; // Value is a numeric bitmask of the `SSL_OP_*` options
|
||||
|
||||
keyFile?: string;
|
||||
|
||||
certFile?: string;
|
||||
|
||||
ALPNProtocols?: string | BufferSource;
|
||||
|
||||
ciphers?: string;
|
||||
|
||||
clientRenegotiationLimit?: number;
|
||||
|
||||
clientRenegotiationWindow?: number;
|
||||
}
|
||||
|
||||
// Note for contributors: TLSOptionsAsDeprecated should be considered immutable
|
||||
@@ -4935,7 +4884,7 @@ declare module "bun" {
|
||||
*
|
||||
* @param force Synchronously run the garbage collector
|
||||
*/
|
||||
function gc(force?: boolean): void;
|
||||
function gc(force: boolean): void;
|
||||
|
||||
/**
|
||||
* JavaScriptCore engine's internal heap snapshot
|
||||
@@ -5884,76 +5833,31 @@ declare module "bun" {
|
||||
index: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Represents a TCP or TLS socket connection used for network communication.
|
||||
* This interface provides methods for reading, writing, managing the connection state,
|
||||
* and handling TLS-specific features if applicable.
|
||||
*
|
||||
* Sockets are created using `Bun.connect()` or accepted by a `Bun.listen()` server.
|
||||
*
|
||||
* @category HTTP & Networking
|
||||
*/
|
||||
interface Socket<Data = undefined> extends Disposable {
|
||||
/**
|
||||
* Writes `data` to the socket. This method is unbuffered and non-blocking. This uses the `sendto(2)` syscall internally.
|
||||
* Write `data` to the socket
|
||||
*
|
||||
* For optimal performance with multiple small writes, consider batching multiple
|
||||
* writes together into a single `socket.write()` call.
|
||||
* @param data The data to write to the socket
|
||||
* @param byteOffset The offset in the buffer to start writing from (defaults to 0)
|
||||
* @param byteLength The number of bytes to write (defaults to the length of the buffer)
|
||||
*
|
||||
* @param data The data to write. Can be a string (encoded as UTF-8), `ArrayBuffer`, `TypedArray`, or `DataView`.
|
||||
* @param byteOffset The offset in bytes within the buffer to start writing from. Defaults to 0. Ignored for strings.
|
||||
* @param byteLength The number of bytes to write from the buffer. Defaults to the remaining length of the buffer from the offset. Ignored for strings.
|
||||
* @returns The number of bytes written. Returns `-1` if the socket is closed or shutting down. Can return less than the input size if the socket's buffer is full (backpressure).
|
||||
* @example
|
||||
* ```ts
|
||||
* // Send a string
|
||||
* const bytesWritten = socket.write("Hello, world!\n");
|
||||
* When passed a string, `byteOffset` and `byteLength` refer to the UTF-8 offset, not the string character offset.
|
||||
*
|
||||
* // Send binary data
|
||||
* const buffer = new Uint8Array([0x01, 0x02, 0x03]);
|
||||
* socket.write(buffer);
|
||||
*
|
||||
* // Send part of a buffer
|
||||
* const largeBuffer = new Uint8Array(1024);
|
||||
* // ... fill largeBuffer ...
|
||||
* socket.write(largeBuffer, 100, 50); // Write 50 bytes starting from index 100
|
||||
* ```
|
||||
* This is unbuffered as of Bun v0.2.2. That means individual write() calls
|
||||
* will be slow. In the future, Bun will buffer writes and flush them at the
|
||||
* end of the tick, when the event loop is idle, or sooner if the buffer is full.
|
||||
*/
|
||||
write(data: string | BufferSource, byteOffset?: number, byteLength?: number): number;
|
||||
|
||||
/**
|
||||
* The user-defined data associated with this socket instance.
|
||||
* This can be set when the socket is created via `Bun.connect({ data: ... })`.
|
||||
* It can be read or updated at any time.
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* // In a socket handler
|
||||
* function open(socket: Socket<{ userId: string }>) {
|
||||
* console.log(`Socket opened for user: ${socket.data.userId}`);
|
||||
* socket.data.lastActivity = Date.now(); // Update data
|
||||
* }
|
||||
* ```
|
||||
* The data context for the socket.
|
||||
*/
|
||||
data: Data;
|
||||
|
||||
/**
|
||||
* Sends the final data chunk and initiates a graceful shutdown of the socket's write side.
|
||||
* After calling `end()`, no more data can be written using `write()` or `end()`.
|
||||
* The socket remains readable until the remote end also closes its write side or the connection is terminated.
|
||||
* This sends a TCP FIN packet after writing the data.
|
||||
* Like {@link Socket.write} except it includes a TCP FIN packet
|
||||
*
|
||||
* @param data Optional final data to write before closing. Same types as `write()`.
|
||||
* @param byteOffset Optional offset for buffer data.
|
||||
* @param byteLength Optional length for buffer data.
|
||||
* @returns The number of bytes written for the final chunk. Returns `-1` if the socket was already closed or shutting down.
|
||||
* @example
|
||||
* ```ts
|
||||
* // send some data and close the write side
|
||||
* socket.end("Goodbye!");
|
||||
* // or close write side without sending final data
|
||||
* socket.end();
|
||||
* ```
|
||||
* Use it to send your last message and close the connection.
|
||||
*/
|
||||
end(data?: string | BufferSource, byteOffset?: number, byteLength?: number): number;
|
||||
|
||||
@@ -5980,33 +5884,20 @@ declare module "bun" {
|
||||
timeout(seconds: number): void;
|
||||
|
||||
/**
|
||||
* Forcefully closes the socket connection immediately. This is an abrupt termination, unlike the graceful shutdown initiated by `end()`.
|
||||
* It uses `SO_LINGER` with `l_onoff=1` and `l_linger=0` before calling `close(2)`.
|
||||
* Consider using {@link close close()} or {@link end end()} for graceful shutdowns.
|
||||
* Forcefully close the socket. The other end may not receive all data, and
|
||||
* the socket will be closed immediately.
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* socket.terminate();
|
||||
* ```
|
||||
* This passes `SO_LINGER` with `l_onoff` set to `1` and `l_linger` set to
|
||||
* `0` and then calls `close(2)`.
|
||||
*/
|
||||
terminate(): void;
|
||||
|
||||
/**
|
||||
* Shuts down the write-half or both halves of the connection.
|
||||
* This allows the socket to enter a half-closed state where it can still receive data
|
||||
* but can no longer send data (`halfClose = true`), or close both read and write
|
||||
* (`halfClose = false`, similar to `end()` but potentially more immediate depending on OS).
|
||||
* Calls `shutdown(2)` syscall internally.
|
||||
* Shutdown writes to a socket
|
||||
*
|
||||
* @param halfClose If `true`, only shuts down the write side (allows receiving). If `false` or omitted, shuts down both read and write. Defaults to `false`.
|
||||
* @example
|
||||
* ```ts
|
||||
* // Stop sending data, but allow receiving
|
||||
* socket.shutdown(true);
|
||||
* This makes the socket a half-closed socket. It can still receive data.
|
||||
*
|
||||
* // Shutdown both reading and writing
|
||||
* socket.shutdown();
|
||||
* ```
|
||||
* This calls [shutdown(2)](https://man7.org/linux/man-pages/man2/shutdown.2.html) internally
|
||||
*/
|
||||
shutdown(halfClose?: boolean): void;
|
||||
|
||||
@@ -6032,11 +5923,6 @@ declare module "bun" {
|
||||
|
||||
/**
|
||||
* Flush any buffered data to the socket
|
||||
* This attempts to send the data immediately, but success depends on the network conditions
|
||||
* and the receiving end.
|
||||
* It might be necessary after several `write` calls if immediate sending is critical,
|
||||
* though often the OS handles flushing efficiently. Note that `write` calls outside
|
||||
* `open`/`data`/`drain` might benefit from manual `cork`/`flush`.
|
||||
*/
|
||||
flush(): void;
|
||||
|
||||
@@ -6058,31 +5944,17 @@ declare module "bun" {
|
||||
|
||||
/**
|
||||
* Remote IP address connected to the socket
|
||||
* @example "192.168.1.100" | "2001:db8::1"
|
||||
*/
|
||||
readonly remoteAddress: string;
|
||||
|
||||
/**
|
||||
* Remote port connected to the socket
|
||||
* @example 8080
|
||||
*/
|
||||
readonly remotePort: number;
|
||||
|
||||
/**
|
||||
* IP protocol family used for the local endpoint of the socket
|
||||
* @example "IPv4" | "IPv6"
|
||||
*/
|
||||
readonly localFamily: "IPv4" | "IPv6";
|
||||
|
||||
/**
|
||||
* Local IP address connected to the socket
|
||||
* @example "192.168.1.100" | "2001:db8::1"
|
||||
*/
|
||||
readonly localAddress: string;
|
||||
|
||||
/**
|
||||
* local port connected to the socket
|
||||
* @example 8080
|
||||
*/
|
||||
readonly localPort: number;
|
||||
|
||||
@@ -6186,7 +6058,7 @@ declare module "bun" {
|
||||
* certificate.
|
||||
* @return A certificate object.
|
||||
*/
|
||||
getPeerCertificate(): import("node:tls").PeerCertificate;
|
||||
getPeerCertificate(): import("tls").PeerCertificate;
|
||||
getPeerX509Certificate(): import("node:crypto").X509Certificate;
|
||||
|
||||
/**
|
||||
@@ -6246,8 +6118,6 @@ declare module "bun" {
|
||||
/**
|
||||
* See `Session Resumption` for more information.
|
||||
* @return `true` if the session was reused, `false` otherwise.
|
||||
* **TLS Only:** Checks if the current TLS session was resumed from a previous session.
|
||||
* Returns `true` if the session was resumed, `false` otherwise.
|
||||
*/
|
||||
isSessionReused(): boolean;
|
||||
|
||||
@@ -6290,98 +6160,9 @@ declare module "bun" {
|
||||
setKeepAlive(enable?: boolean, initialDelay?: number): boolean;
|
||||
|
||||
/**
|
||||
* The total number of bytes successfully written to the socket since it was established.
|
||||
* This includes data currently buffered by the OS but not yet acknowledged by the remote peer.
|
||||
* The number of bytes written to the socket.
|
||||
*/
|
||||
readonly bytesWritten: number;
|
||||
|
||||
/**
|
||||
* Alias for `socket.end()`. Allows the socket to be used with `using` declarations
|
||||
* for automatic resource management.
|
||||
* @example
|
||||
* ```ts
|
||||
* async function processSocket() {
|
||||
* using socket = await Bun.connect({ ... });
|
||||
* socket.write("Data");
|
||||
* // socket.end() is called automatically when exiting the scope
|
||||
* }
|
||||
* ```
|
||||
*/
|
||||
[Symbol.dispose](): void;
|
||||
|
||||
resume(): void;
|
||||
|
||||
pause(): void;
|
||||
|
||||
/**
|
||||
* If this is a TLS Socket
|
||||
*/
|
||||
renegotiate(): void;
|
||||
|
||||
/**
|
||||
* Sets the verify mode of the socket.
|
||||
*
|
||||
* @param requestCert Whether to request a certificate.
|
||||
* @param rejectUnauthorized Whether to reject unauthorized certificates.
|
||||
*/
|
||||
setVerifyMode(requestCert: boolean, rejectUnauthorized: boolean): void;
|
||||
|
||||
getSession(): void;
|
||||
|
||||
/**
|
||||
* Sets the session of the socket.
|
||||
*
|
||||
* @param session The session to set.
|
||||
*/
|
||||
setSession(session: string | Buffer | BufferSource): void;
|
||||
|
||||
/**
|
||||
* Exports the keying material of the socket.
|
||||
*
|
||||
* @param length The length of the keying material to export.
|
||||
* @param label The label of the keying material to export.
|
||||
* @param context The context of the keying material to export.
|
||||
*/
|
||||
exportKeyingMaterial(length: number, label: string, context?: string | BufferSource): void;
|
||||
|
||||
/**
|
||||
* Upgrades the socket to a TLS socket.
|
||||
*
|
||||
* @param options The options for the upgrade.
|
||||
* @returns A tuple containing the raw socket and the TLS socket.
|
||||
* @see {@link TLSUpgradeOptions}
|
||||
*/
|
||||
upgradeTLS<Data>(options: TLSUpgradeOptions<Data>): [raw: Socket<Data>, tls: Socket<Data>];
|
||||
|
||||
/**
|
||||
* Closes the socket.
|
||||
*
|
||||
* This is a wrapper around `end()` and `shutdown()`.
|
||||
*
|
||||
* @see {@link end}
|
||||
* @see {@link shutdown}
|
||||
*/
|
||||
close(): void;
|
||||
|
||||
/**
|
||||
* Returns the servername of the socket.
|
||||
*
|
||||
* @see {@link setServername}
|
||||
*/
|
||||
getServername(): string;
|
||||
|
||||
/**
|
||||
* Sets the servername of the socket.
|
||||
*
|
||||
* @see {@link getServername}
|
||||
*/
|
||||
setServername(name: string): void;
|
||||
}
|
||||
|
||||
interface TLSUpgradeOptions<Data> {
|
||||
data?: Data;
|
||||
tls: TLSOptions | boolean;
|
||||
socket: SocketHandler<Data>;
|
||||
}
|
||||
|
||||
interface SocketListener<Data = undefined> extends Disposable {
|
||||
@@ -6482,22 +6263,6 @@ declare module "bun" {
|
||||
* The per-instance data context
|
||||
*/
|
||||
data?: Data;
|
||||
/**
|
||||
* Whether to allow half-open connections.
|
||||
*
|
||||
* A half-open connection occurs when one end of the connection has called `close()`
|
||||
* or sent a FIN packet, while the other end remains open. When set to `true`:
|
||||
*
|
||||
* - The socket won't automatically send FIN when the remote side closes its end
|
||||
* - The local side can continue sending data even after the remote side has closed
|
||||
* - The application must explicitly call `end()` to fully close the connection
|
||||
*
|
||||
* When `false`, the socket automatically closes both ends of the connection when
|
||||
* either side closes.
|
||||
*
|
||||
* @default false
|
||||
*/
|
||||
allowHalfOpen?: boolean;
|
||||
}
|
||||
|
||||
interface TCPSocketListenOptions<Data = undefined> extends SocketOptions<Data> {
|
||||
@@ -6512,7 +6277,7 @@ declare module "bun" {
|
||||
/**
|
||||
* The TLS configuration object with which to create the server
|
||||
*/
|
||||
tls?: TLSOptions | boolean;
|
||||
tls?: TLSOptions;
|
||||
/**
|
||||
* Whether to use exclusive mode.
|
||||
*
|
||||
@@ -6558,7 +6323,7 @@ declare module "bun" {
|
||||
/**
|
||||
* TLS Configuration with which to create the socket
|
||||
*/
|
||||
tls?: TLSOptions | boolean;
|
||||
tls?: boolean;
|
||||
/**
|
||||
* Whether to use exclusive mode.
|
||||
*
|
||||
@@ -6574,8 +6339,22 @@ declare module "bun" {
|
||||
* @default false
|
||||
*/
|
||||
exclusive?: boolean;
|
||||
reusePort?: boolean;
|
||||
ipv6Only?: boolean;
|
||||
/**
|
||||
* Whether to allow half-open connections.
|
||||
*
|
||||
* A half-open connection occurs when one end of the connection has called `close()`
|
||||
* or sent a FIN packet, while the other end remains open. When set to `true`:
|
||||
*
|
||||
* - The socket won't automatically send FIN when the remote side closes its end
|
||||
* - The local side can continue sending data even after the remote side has closed
|
||||
* - The application must explicitly call `end()` to fully close the connection
|
||||
*
|
||||
* When `false` (default), the socket automatically closes both ends of the connection
|
||||
* when either side closes.
|
||||
*
|
||||
* @default false
|
||||
*/
|
||||
allowHalfOpen?: boolean;
|
||||
}
|
||||
|
||||
interface UnixSocketOptions<Data = undefined> extends SocketOptions<Data> {
|
||||
@@ -6586,14 +6365,14 @@ declare module "bun" {
|
||||
/**
|
||||
* TLS Configuration with which to create the socket
|
||||
*/
|
||||
tls?: TLSOptions | boolean;
|
||||
tls?: TLSOptions;
|
||||
}
|
||||
|
||||
interface FdSocketOptions<Data = undefined> extends SocketOptions<Data> {
|
||||
/**
|
||||
* TLS Configuration with which to create the socket
|
||||
*/
|
||||
tls?: TLSOptions | boolean;
|
||||
tls?: TLSOptions;
|
||||
/**
|
||||
* The file descriptor to connect to
|
||||
*/
|
||||
@@ -6778,7 +6557,7 @@ declare module "bun" {
|
||||
*
|
||||
* For stdout and stdin you may pass:
|
||||
*
|
||||
* - `"pipe"`, `undefined`: The process will have a {@link BunReadableStream} for standard output/error
|
||||
* - `"pipe"`, `undefined`: The process will have a {@link ReadableStream} for standard output/error
|
||||
* - `"ignore"`, `null`: The process will have no standard output/error
|
||||
* - `"inherit"`: The process will inherit the standard output/error of the current process
|
||||
* - `ArrayBufferView`: The process write to the preallocated buffer. Not implemented.
|
||||
@@ -6804,7 +6583,7 @@ declare module "bun" {
|
||||
/**
|
||||
* The file descriptor for the standard output. It may be:
|
||||
*
|
||||
* - `"pipe"`, `undefined`: The process will have a {@link BunReadableStream} for standard output/error
|
||||
* - `"pipe"`, `undefined`: The process will have a {@link ReadableStream} for standard output/error
|
||||
* - `"ignore"`, `null`: The process will have no standard output/error
|
||||
* - `"inherit"`: The process will inherit the standard output/error of the current process
|
||||
* - `ArrayBufferView`: The process write to the preallocated buffer. Not implemented.
|
||||
@@ -6816,7 +6595,7 @@ declare module "bun" {
|
||||
/**
|
||||
* The file descriptor for the standard error. It may be:
|
||||
*
|
||||
* - `"pipe"`, `undefined`: The process will have a {@link BunReadableStream} for standard output/error
|
||||
* - `"pipe"`, `undefined`: The process will have a {@link ReadableStream} for standard output/error
|
||||
* - `"ignore"`, `null`: The process will have no standard output/error
|
||||
* - `"inherit"`: The process will inherit the standard output/error of the current process
|
||||
* - `ArrayBufferView`: The process write to the preallocated buffer. Not implemented.
|
||||
@@ -6862,7 +6641,7 @@ declare module "bun" {
|
||||
* incoming messages, and `subprocess.send` can send messages to the subprocess. Messages are serialized
|
||||
* using the JSC serialize API, which allows for the same types that `postMessage`/`structuredClone` supports.
|
||||
*
|
||||
* The subprocess can send and receive messages by using `process.send` and `process.on("message")`,
|
||||
* The subprocess can send and recieve messages by using `process.send` and `process.on("message")`,
|
||||
* respectively. This is the same API as what Node.js exposes when `child_process.fork()` is used.
|
||||
*
|
||||
* Currently, this is only compatible with processes that are other `bun` instances.
|
||||
@@ -6979,7 +6758,7 @@ declare module "bun" {
|
||||
type ReadableIO = ReadableStream<Uint8Array> | number | undefined;
|
||||
|
||||
type ReadableToIO<X extends Readable> = X extends "pipe" | undefined
|
||||
? BunReadableStream
|
||||
? ReadableStream<Uint8Array>
|
||||
: X extends BunFile | ArrayBufferView | number
|
||||
? number
|
||||
: undefined;
|
||||
|
||||
3
packages/bun-types/globals.d.ts
vendored
3
packages/bun-types/globals.d.ts
vendored
@@ -10,7 +10,6 @@ declare module "bun" {
|
||||
|
||||
type NodeCryptoWebcryptoSubtleCrypto = import("crypto").webcrypto.SubtleCrypto;
|
||||
type NodeCryptoWebcryptoCryptoKey = import("crypto").webcrypto.CryptoKey;
|
||||
type NodeCryptoWebcryptoCryptoKeyPair = import("crypto").webcrypto.CryptoKeyPair;
|
||||
|
||||
type LibEmptyOrBunWebSocket = LibDomIsLoaded extends true ? {} : Bun.WebSocket;
|
||||
|
||||
@@ -885,8 +884,6 @@ declare var CryptoKey: {
|
||||
new (): CryptoKey;
|
||||
};
|
||||
|
||||
interface CryptoKeyPair extends Bun.__internal.NodeCryptoWebcryptoCryptoKeyPair {}
|
||||
|
||||
interface Position {
|
||||
lineText: string;
|
||||
file: string;
|
||||
|
||||
@@ -11,9 +11,7 @@
|
||||
"files": [
|
||||
"./*.d.ts",
|
||||
"docs/**/*.md",
|
||||
"docs/*.md",
|
||||
"CLAUDE.md",
|
||||
"README.md"
|
||||
"docs/*.md"
|
||||
],
|
||||
"homepage": "https://bun.sh",
|
||||
"dependencies": {
|
||||
@@ -25,7 +23,7 @@
|
||||
"scripts": {
|
||||
"prebuild": "echo $(pwd)",
|
||||
"copy-docs": "rm -rf docs && cp -rL ../../docs/ ./docs && find ./docs -type f -name '*.md' -exec sed -i 's/\\$BUN_LATEST_VERSION/'\"${BUN_VERSION#bun-v}\"'/g' {} +",
|
||||
"build": "bun run copy-docs && cp ../../src/init/rule.md CLAUDE.md && bun scripts/build.ts",
|
||||
"build": "bun run copy-docs && bun scripts/build.ts",
|
||||
"test": "tsc",
|
||||
"fmt": "echo $(which biome) && biome format --write ."
|
||||
},
|
||||
|
||||
168
packages/bun-types/redis.d.ts
vendored
168
packages/bun-types/redis.d.ts
vendored
@@ -50,10 +50,6 @@ declare module "bun" {
|
||||
enableAutoPipelining?: boolean;
|
||||
}
|
||||
|
||||
export namespace RedisClient {
|
||||
type KeyLike = string | ArrayBufferView | Blob;
|
||||
}
|
||||
|
||||
export class RedisClient {
|
||||
/**
|
||||
* Creates a new Redis client
|
||||
@@ -116,14 +112,14 @@ declare module "bun" {
|
||||
* @param key The key to get
|
||||
* @returns Promise that resolves with the key's value as a string, or null if the key doesn't exist
|
||||
*/
|
||||
get(key: RedisClient.KeyLike): Promise<string | null>;
|
||||
get(key: string | ArrayBufferView | Blob): Promise<string | null>;
|
||||
|
||||
/**
|
||||
* Get the value of a key as a Uint8Array
|
||||
* @param key The key to get
|
||||
* @returns Promise that resolves with the key's value as a Uint8Array, or null if the key doesn't exist
|
||||
*/
|
||||
getBuffer(key: RedisClient.KeyLike): Promise<Uint8Array<ArrayBuffer> | null>;
|
||||
getBuffer(key: string | ArrayBufferView | Blob): Promise<Uint8Array<ArrayBuffer> | null>;
|
||||
|
||||
/**
|
||||
* Set key to hold the string value
|
||||
@@ -131,7 +127,7 @@ declare module "bun" {
|
||||
* @param value The value to set
|
||||
* @returns Promise that resolves with "OK" on success
|
||||
*/
|
||||
set(key: RedisClient.KeyLike, value: RedisClient.KeyLike): Promise<"OK">;
|
||||
set(key: string | ArrayBufferView | Blob, value: string | ArrayBufferView | Blob): Promise<"OK">;
|
||||
|
||||
/**
|
||||
* Set key to hold the string value with expiration
|
||||
@@ -140,7 +136,12 @@ declare module "bun" {
|
||||
* @param ex Set the specified expire time, in seconds
|
||||
* @returns Promise that resolves with "OK" on success
|
||||
*/
|
||||
set(key: RedisClient.KeyLike, value: RedisClient.KeyLike, ex: "EX", seconds: number): Promise<"OK">;
|
||||
set(
|
||||
key: string | ArrayBufferView | Blob,
|
||||
value: string | ArrayBufferView | Blob,
|
||||
ex: "EX",
|
||||
seconds: number,
|
||||
): Promise<"OK">;
|
||||
|
||||
/**
|
||||
* Set key to hold the string value with expiration
|
||||
@@ -149,7 +150,12 @@ declare module "bun" {
|
||||
* @param px Set the specified expire time, in milliseconds
|
||||
* @returns Promise that resolves with "OK" on success
|
||||
*/
|
||||
set(key: RedisClient.KeyLike, value: RedisClient.KeyLike, px: "PX", milliseconds: number): Promise<"OK">;
|
||||
set(
|
||||
key: string | ArrayBufferView | Blob,
|
||||
value: string | ArrayBufferView | Blob,
|
||||
px: "PX",
|
||||
milliseconds: number,
|
||||
): Promise<"OK">;
|
||||
|
||||
/**
|
||||
* Set key to hold the string value with expiration at a specific Unix timestamp
|
||||
@@ -158,7 +164,12 @@ declare module "bun" {
|
||||
* @param exat Set the specified Unix time at which the key will expire, in seconds
|
||||
* @returns Promise that resolves with "OK" on success
|
||||
*/
|
||||
set(key: RedisClient.KeyLike, value: RedisClient.KeyLike, exat: "EXAT", timestampSeconds: number): Promise<"OK">;
|
||||
set(
|
||||
key: string | ArrayBufferView | Blob,
|
||||
value: string | ArrayBufferView | Blob,
|
||||
exat: "EXAT",
|
||||
timestampSeconds: number,
|
||||
): Promise<"OK">;
|
||||
|
||||
/**
|
||||
* Set key to hold the string value with expiration at a specific Unix timestamp
|
||||
@@ -168,8 +179,8 @@ declare module "bun" {
|
||||
* @returns Promise that resolves with "OK" on success
|
||||
*/
|
||||
set(
|
||||
key: RedisClient.KeyLike,
|
||||
value: RedisClient.KeyLike,
|
||||
key: string | ArrayBufferView | Blob,
|
||||
value: string | ArrayBufferView | Blob,
|
||||
pxat: "PXAT",
|
||||
timestampMilliseconds: number,
|
||||
): Promise<"OK">;
|
||||
@@ -181,7 +192,7 @@ declare module "bun" {
|
||||
* @param nx Only set the key if it does not already exist
|
||||
* @returns Promise that resolves with "OK" on success, or null if the key already exists
|
||||
*/
|
||||
set(key: RedisClient.KeyLike, value: RedisClient.KeyLike, nx: "NX"): Promise<"OK" | null>;
|
||||
set(key: string | ArrayBufferView | Blob, value: string | ArrayBufferView | Blob, nx: "NX"): Promise<"OK" | null>;
|
||||
|
||||
/**
|
||||
* Set key to hold the string value only if key already exists
|
||||
@@ -190,7 +201,7 @@ declare module "bun" {
|
||||
* @param xx Only set the key if it already exists
|
||||
* @returns Promise that resolves with "OK" on success, or null if the key does not exist
|
||||
*/
|
||||
set(key: RedisClient.KeyLike, value: RedisClient.KeyLike, xx: "XX"): Promise<"OK" | null>;
|
||||
set(key: string | ArrayBufferView | Blob, value: string | ArrayBufferView | Blob, xx: "XX"): Promise<"OK" | null>;
|
||||
|
||||
/**
|
||||
* Set key to hold the string value and return the old value
|
||||
@@ -199,7 +210,11 @@ declare module "bun" {
|
||||
* @param get Return the old string stored at key, or null if key did not exist
|
||||
* @returns Promise that resolves with the old value, or null if key did not exist
|
||||
*/
|
||||
set(key: RedisClient.KeyLike, value: RedisClient.KeyLike, get: "GET"): Promise<string | null>;
|
||||
set(
|
||||
key: string | ArrayBufferView | Blob,
|
||||
value: string | ArrayBufferView | Blob,
|
||||
get: "GET",
|
||||
): Promise<string | null>;
|
||||
|
||||
/**
|
||||
* Set key to hold the string value and retain the time to live
|
||||
@@ -208,7 +223,11 @@ declare module "bun" {
|
||||
* @param keepttl Retain the time to live associated with the key
|
||||
* @returns Promise that resolves with "OK" on success
|
||||
*/
|
||||
set(key: RedisClient.KeyLike, value: RedisClient.KeyLike, keepttl: "KEEPTTL"): Promise<"OK">;
|
||||
set(
|
||||
key: string | ArrayBufferView | Blob,
|
||||
value: string | ArrayBufferView | Blob,
|
||||
keepttl: "KEEPTTL",
|
||||
): Promise<"OK">;
|
||||
|
||||
/**
|
||||
* Set key to hold the string value with various options
|
||||
@@ -217,35 +236,39 @@ declare module "bun" {
|
||||
* @param options Array of options (EX, PX, EXAT, PXAT, NX, XX, KEEPTTL, GET)
|
||||
* @returns Promise that resolves with "OK" on success, null if NX/XX condition not met, or the old value if GET is specified
|
||||
*/
|
||||
set(key: RedisClient.KeyLike, value: RedisClient.KeyLike, ...options: string[]): Promise<"OK" | string | null>;
|
||||
set(
|
||||
key: string | ArrayBufferView | Blob,
|
||||
value: string | ArrayBufferView | Blob,
|
||||
...options: string[]
|
||||
): Promise<"OK" | string | null>;
|
||||
|
||||
/**
|
||||
* Delete a key(s)
|
||||
* @param keys The keys to delete
|
||||
* Delete a key
|
||||
* @param key The key to delete
|
||||
* @returns Promise that resolves with the number of keys removed
|
||||
*/
|
||||
del(...keys: RedisClient.KeyLike[]): Promise<number>;
|
||||
del(key: string | ArrayBufferView | Blob): Promise<number>;
|
||||
|
||||
/**
|
||||
* Increment the integer value of a key by one
|
||||
* @param key The key to increment
|
||||
* @returns Promise that resolves with the new value
|
||||
*/
|
||||
incr(key: RedisClient.KeyLike): Promise<number>;
|
||||
incr(key: string | ArrayBufferView | Blob): Promise<number>;
|
||||
|
||||
/**
|
||||
* Decrement the integer value of a key by one
|
||||
* @param key The key to decrement
|
||||
* @returns Promise that resolves with the new value
|
||||
*/
|
||||
decr(key: RedisClient.KeyLike): Promise<number>;
|
||||
decr(key: string | ArrayBufferView | Blob): Promise<number>;
|
||||
|
||||
/**
|
||||
* Determine if a key exists
|
||||
* @param key The key to check
|
||||
* @returns Promise that resolves with true if the key exists, false otherwise
|
||||
*/
|
||||
exists(key: RedisClient.KeyLike): Promise<boolean>;
|
||||
exists(key: string | ArrayBufferView | Blob): Promise<boolean>;
|
||||
|
||||
/**
|
||||
* Set a key's time to live in seconds
|
||||
@@ -253,14 +276,14 @@ declare module "bun" {
|
||||
* @param seconds The number of seconds until expiration
|
||||
* @returns Promise that resolves with 1 if the timeout was set, 0 if not
|
||||
*/
|
||||
expire(key: RedisClient.KeyLike, seconds: number): Promise<number>;
|
||||
expire(key: string | ArrayBufferView | Blob, seconds: number): Promise<number>;
|
||||
|
||||
/**
|
||||
* Get the time to live for a key in seconds
|
||||
* @param key The key to get the TTL for
|
||||
* @returns Promise that resolves with the TTL, -1 if no expiry, or -2 if key doesn't exist
|
||||
*/
|
||||
ttl(key: RedisClient.KeyLike): Promise<number>;
|
||||
ttl(key: string | ArrayBufferView | Blob): Promise<number>;
|
||||
|
||||
/**
|
||||
* Set multiple hash fields to multiple values
|
||||
@@ -268,7 +291,7 @@ declare module "bun" {
|
||||
* @param fieldValues An array of alternating field names and values
|
||||
* @returns Promise that resolves with "OK" on success
|
||||
*/
|
||||
hmset(key: RedisClient.KeyLike, fieldValues: string[]): Promise<string>;
|
||||
hmset(key: string | ArrayBufferView | Blob, fieldValues: string[]): Promise<string>;
|
||||
|
||||
/**
|
||||
* Get the values of all the given hash fields
|
||||
@@ -276,7 +299,7 @@ declare module "bun" {
|
||||
* @param fields The fields to get
|
||||
* @returns Promise that resolves with an array of values
|
||||
*/
|
||||
hmget(key: RedisClient.KeyLike, fields: string[]): Promise<Array<string | null>>;
|
||||
hmget(key: string | ArrayBufferView | Blob, fields: string[]): Promise<Array<string | null>>;
|
||||
|
||||
/**
|
||||
* Check if a value is a member of a set
|
||||
@@ -284,7 +307,7 @@ declare module "bun" {
|
||||
* @param member The member to check
|
||||
* @returns Promise that resolves with true if the member exists, false otherwise
|
||||
*/
|
||||
sismember(key: RedisClient.KeyLike, member: string): Promise<boolean>;
|
||||
sismember(key: string | ArrayBufferView | Blob, member: string): Promise<boolean>;
|
||||
|
||||
/**
|
||||
* Add a member to a set
|
||||
@@ -292,7 +315,7 @@ declare module "bun" {
|
||||
* @param member The member to add
|
||||
* @returns Promise that resolves with 1 if the member was added, 0 if it already existed
|
||||
*/
|
||||
sadd(key: RedisClient.KeyLike, member: string): Promise<number>;
|
||||
sadd(key: string | ArrayBufferView | Blob, member: string): Promise<number>;
|
||||
|
||||
/**
|
||||
* Remove a member from a set
|
||||
@@ -300,28 +323,28 @@ declare module "bun" {
|
||||
* @param member The member to remove
|
||||
* @returns Promise that resolves with 1 if the member was removed, 0 if it didn't exist
|
||||
*/
|
||||
srem(key: RedisClient.KeyLike, member: string): Promise<number>;
|
||||
srem(key: string | ArrayBufferView | Blob, member: string): Promise<number>;
|
||||
|
||||
/**
|
||||
* Get all the members in a set
|
||||
* @param key The set key
|
||||
* @returns Promise that resolves with an array of all members
|
||||
*/
|
||||
smembers(key: RedisClient.KeyLike): Promise<string[]>;
|
||||
smembers(key: string | ArrayBufferView | Blob): Promise<string[]>;
|
||||
|
||||
/**
|
||||
* Get a random member from a set
|
||||
* @param key The set key
|
||||
* @returns Promise that resolves with a random member, or null if the set is empty
|
||||
*/
|
||||
srandmember(key: RedisClient.KeyLike): Promise<string | null>;
|
||||
srandmember(key: string | ArrayBufferView | Blob): Promise<string | null>;
|
||||
|
||||
/**
|
||||
* Remove and return a random member from a set
|
||||
* @param key The set key
|
||||
* @returns Promise that resolves with the removed member, or null if the set is empty
|
||||
*/
|
||||
spop(key: RedisClient.KeyLike): Promise<string | null>;
|
||||
spop(key: string | ArrayBufferView | Blob): Promise<string | null>;
|
||||
|
||||
/**
|
||||
* Increment the integer value of a hash field by the given number
|
||||
@@ -330,7 +353,7 @@ declare module "bun" {
|
||||
* @param increment The amount to increment by
|
||||
* @returns Promise that resolves with the new value
|
||||
*/
|
||||
hincrby(key: RedisClient.KeyLike, field: string, increment: string | number): Promise<number>;
|
||||
hincrby(key: string | ArrayBufferView | Blob, field: string, increment: string | number): Promise<number>;
|
||||
|
||||
/**
|
||||
* Increment the float value of a hash field by the given amount
|
||||
@@ -339,35 +362,35 @@ declare module "bun" {
|
||||
* @param increment The amount to increment by
|
||||
* @returns Promise that resolves with the new value as a string
|
||||
*/
|
||||
hincrbyfloat(key: RedisClient.KeyLike, field: string, increment: string | number): Promise<string>;
|
||||
hincrbyfloat(key: string | ArrayBufferView | Blob, field: string, increment: string | number): Promise<string>;
|
||||
|
||||
/**
|
||||
* Get all the fields and values in a hash
|
||||
* @param key The hash key
|
||||
* @returns Promise that resolves with an object containing all fields and values
|
||||
*/
|
||||
hgetall(key: RedisClient.KeyLike): Promise<Record<string, string> | null>;
|
||||
hgetall(key: string | ArrayBufferView | Blob): Promise<Record<string, string> | null>;
|
||||
|
||||
/**
|
||||
* Get all field names in a hash
|
||||
* @param key The hash key
|
||||
* @returns Promise that resolves with an array of field names
|
||||
*/
|
||||
hkeys(key: RedisClient.KeyLike): Promise<string[]>;
|
||||
hkeys(key: string | ArrayBufferView | Blob): Promise<string[]>;
|
||||
|
||||
/**
|
||||
* Get the number of fields in a hash
|
||||
* @param key The hash key
|
||||
* @returns Promise that resolves with the number of fields
|
||||
*/
|
||||
hlen(key: RedisClient.KeyLike): Promise<number>;
|
||||
hlen(key: string | ArrayBufferView | Blob): Promise<number>;
|
||||
|
||||
/**
|
||||
* Get all values in a hash
|
||||
* @param key The hash key
|
||||
* @returns Promise that resolves with an array of values
|
||||
*/
|
||||
hvals(key: RedisClient.KeyLike): Promise<string[]>;
|
||||
hvals(key: string | ArrayBufferView | Blob): Promise<string[]>;
|
||||
|
||||
/**
|
||||
* Find all keys matching the given pattern
|
||||
@@ -381,84 +404,84 @@ declare module "bun" {
|
||||
* @param key The list key
|
||||
* @returns Promise that resolves with the length of the list
|
||||
*/
|
||||
llen(key: RedisClient.KeyLike): Promise<number>;
|
||||
llen(key: string | ArrayBufferView | Blob): Promise<number>;
|
||||
|
||||
/**
|
||||
* Remove and get the first element in a list
|
||||
* @param key The list key
|
||||
* @returns Promise that resolves with the first element, or null if the list is empty
|
||||
*/
|
||||
lpop(key: RedisClient.KeyLike): Promise<string | null>;
|
||||
lpop(key: string | ArrayBufferView | Blob): Promise<string | null>;
|
||||
|
||||
/**
|
||||
* Remove the expiration from a key
|
||||
* @param key The key to persist
|
||||
* @returns Promise that resolves with 1 if the timeout was removed, 0 if the key doesn't exist or has no timeout
|
||||
*/
|
||||
persist(key: RedisClient.KeyLike): Promise<number>;
|
||||
persist(key: string | ArrayBufferView | Blob): Promise<number>;
|
||||
|
||||
/**
|
||||
* Get the expiration time of a key as a UNIX timestamp in milliseconds
|
||||
* @param key The key to check
|
||||
* @returns Promise that resolves with the timestamp, or -1 if the key has no expiration, or -2 if the key doesn't exist
|
||||
*/
|
||||
pexpiretime(key: RedisClient.KeyLike): Promise<number>;
|
||||
pexpiretime(key: string | ArrayBufferView | Blob): Promise<number>;
|
||||
|
||||
/**
|
||||
* Get the time to live for a key in milliseconds
|
||||
* @param key The key to check
|
||||
* @returns Promise that resolves with the TTL in milliseconds, or -1 if the key has no expiration, or -2 if the key doesn't exist
|
||||
*/
|
||||
pttl(key: RedisClient.KeyLike): Promise<number>;
|
||||
pttl(key: string | ArrayBufferView | Blob): Promise<number>;
|
||||
|
||||
/**
|
||||
* Remove and get the last element in a list
|
||||
* @param key The list key
|
||||
* @returns Promise that resolves with the last element, or null if the list is empty
|
||||
*/
|
||||
rpop(key: RedisClient.KeyLike): Promise<string | null>;
|
||||
rpop(key: string | ArrayBufferView | Blob): Promise<string | null>;
|
||||
|
||||
/**
|
||||
* Get the number of members in a set
|
||||
* @param key The set key
|
||||
* @returns Promise that resolves with the cardinality (number of elements) of the set
|
||||
*/
|
||||
scard(key: RedisClient.KeyLike): Promise<number>;
|
||||
scard(key: string | ArrayBufferView | Blob): Promise<number>;
|
||||
|
||||
/**
|
||||
* Get the length of the value stored in a key
|
||||
* @param key The key to check
|
||||
* @returns Promise that resolves with the length of the string value, or 0 if the key doesn't exist
|
||||
*/
|
||||
strlen(key: RedisClient.KeyLike): Promise<number>;
|
||||
strlen(key: string | ArrayBufferView | Blob): Promise<number>;
|
||||
|
||||
/**
|
||||
* Get the number of members in a sorted set
|
||||
* @param key The sorted set key
|
||||
* @returns Promise that resolves with the cardinality (number of elements) of the sorted set
|
||||
*/
|
||||
zcard(key: RedisClient.KeyLike): Promise<number>;
|
||||
zcard(key: string | ArrayBufferView | Blob): Promise<number>;
|
||||
|
||||
/**
|
||||
* Remove and return members with the highest scores in a sorted set
|
||||
* @param key The sorted set key
|
||||
* @returns Promise that resolves with the removed member and its score, or null if the set is empty
|
||||
*/
|
||||
zpopmax(key: RedisClient.KeyLike): Promise<string | null>;
|
||||
zpopmax(key: string | ArrayBufferView | Blob): Promise<string | null>;
|
||||
|
||||
/**
|
||||
* Remove and return members with the lowest scores in a sorted set
|
||||
* @param key The sorted set key
|
||||
* @returns Promise that resolves with the removed member and its score, or null if the set is empty
|
||||
*/
|
||||
zpopmin(key: RedisClient.KeyLike): Promise<string | null>;
|
||||
zpopmin(key: string | ArrayBufferView | Blob): Promise<string | null>;
|
||||
|
||||
/**
|
||||
* Get one or multiple random members from a sorted set
|
||||
* @param key The sorted set key
|
||||
* @returns Promise that resolves with a random member, or null if the set is empty
|
||||
*/
|
||||
zrandmember(key: RedisClient.KeyLike): Promise<string | null>;
|
||||
zrandmember(key: string | ArrayBufferView | Blob): Promise<string | null>;
|
||||
|
||||
/**
|
||||
* Append a value to a key
|
||||
@@ -466,7 +489,7 @@ declare module "bun" {
|
||||
* @param value The value to append
|
||||
* @returns Promise that resolves with the length of the string after the append operation
|
||||
*/
|
||||
append(key: RedisClient.KeyLike, value: RedisClient.KeyLike): Promise<number>;
|
||||
append(key: string | ArrayBufferView | Blob, value: string | ArrayBufferView | Blob): Promise<number>;
|
||||
|
||||
/**
|
||||
* Set the value of a key and return its old value
|
||||
@@ -474,7 +497,7 @@ declare module "bun" {
|
||||
* @param value The value to set
|
||||
* @returns Promise that resolves with the old value, or null if the key didn't exist
|
||||
*/
|
||||
getset(key: RedisClient.KeyLike, value: RedisClient.KeyLike): Promise<string | null>;
|
||||
getset(key: string | ArrayBufferView | Blob, value: string | ArrayBufferView | Blob): Promise<string | null>;
|
||||
|
||||
/**
|
||||
* Prepend one or multiple values to a list
|
||||
@@ -482,7 +505,7 @@ declare module "bun" {
|
||||
* @param value The value to prepend
|
||||
* @returns Promise that resolves with the length of the list after the push operation
|
||||
*/
|
||||
lpush(key: RedisClient.KeyLike, value: RedisClient.KeyLike): Promise<number>;
|
||||
lpush(key: string | ArrayBufferView | Blob, value: string | ArrayBufferView | Blob): Promise<number>;
|
||||
|
||||
/**
|
||||
* Prepend a value to a list, only if the list exists
|
||||
@@ -490,7 +513,7 @@ declare module "bun" {
|
||||
* @param value The value to prepend
|
||||
* @returns Promise that resolves with the length of the list after the push operation, or 0 if the list doesn't exist
|
||||
*/
|
||||
lpushx(key: RedisClient.KeyLike, value: RedisClient.KeyLike): Promise<number>;
|
||||
lpushx(key: string | ArrayBufferView | Blob, value: string | ArrayBufferView | Blob): Promise<number>;
|
||||
|
||||
/**
|
||||
* Add one or more members to a HyperLogLog
|
||||
@@ -498,7 +521,7 @@ declare module "bun" {
|
||||
* @param element The element to add
|
||||
* @returns Promise that resolves with 1 if the HyperLogLog was altered, 0 otherwise
|
||||
*/
|
||||
pfadd(key: RedisClient.KeyLike, element: string): Promise<number>;
|
||||
pfadd(key: string | ArrayBufferView | Blob, element: string): Promise<number>;
|
||||
|
||||
/**
|
||||
* Append one or multiple values to a list
|
||||
@@ -506,7 +529,7 @@ declare module "bun" {
|
||||
* @param value The value to append
|
||||
* @returns Promise that resolves with the length of the list after the push operation
|
||||
*/
|
||||
rpush(key: RedisClient.KeyLike, value: RedisClient.KeyLike): Promise<number>;
|
||||
rpush(key: string | ArrayBufferView | Blob, value: string | ArrayBufferView | Blob): Promise<number>;
|
||||
|
||||
/**
|
||||
* Append a value to a list, only if the list exists
|
||||
@@ -514,7 +537,7 @@ declare module "bun" {
|
||||
* @param value The value to append
|
||||
* @returns Promise that resolves with the length of the list after the push operation, or 0 if the list doesn't exist
|
||||
*/
|
||||
rpushx(key: RedisClient.KeyLike, value: RedisClient.KeyLike): Promise<number>;
|
||||
rpushx(key: string | ArrayBufferView | Blob, value: string | ArrayBufferView | Blob): Promise<number>;
|
||||
|
||||
/**
|
||||
* Set the value of a key, only if the key does not exist
|
||||
@@ -522,7 +545,7 @@ declare module "bun" {
|
||||
* @param value The value to set
|
||||
* @returns Promise that resolves with 1 if the key was set, 0 if the key was not set
|
||||
*/
|
||||
setnx(key: RedisClient.KeyLike, value: RedisClient.KeyLike): Promise<number>;
|
||||
setnx(key: string | ArrayBufferView | Blob, value: string | ArrayBufferView | Blob): Promise<number>;
|
||||
|
||||
/**
|
||||
* Get the score associated with the given member in a sorted set
|
||||
@@ -530,62 +553,49 @@ declare module "bun" {
|
||||
* @param member The member to get the score for
|
||||
* @returns Promise that resolves with the score of the member as a string, or null if the member or key doesn't exist
|
||||
*/
|
||||
zscore(key: RedisClient.KeyLike, member: string): Promise<string | null>;
|
||||
zscore(key: string | ArrayBufferView | Blob, member: string): Promise<string | null>;
|
||||
|
||||
/**
|
||||
* Get the values of all specified keys
|
||||
* @param keys The keys to get
|
||||
* @returns Promise that resolves with an array of values, with null for keys that don't exist
|
||||
*/
|
||||
mget(...keys: RedisClient.KeyLike[]): Promise<(string | null)[]>;
|
||||
mget(...keys: (string | ArrayBufferView | Blob)[]): Promise<(string | null)[]>;
|
||||
|
||||
/**
|
||||
* Count the number of set bits (population counting) in a string
|
||||
* @param key The key to count bits in
|
||||
* @returns Promise that resolves with the number of bits set to 1
|
||||
*/
|
||||
bitcount(key: RedisClient.KeyLike): Promise<number>;
|
||||
bitcount(key: string | ArrayBufferView | Blob): Promise<number>;
|
||||
|
||||
/**
|
||||
* Return a serialized version of the value stored at the specified key
|
||||
* @param key The key to dump
|
||||
* @returns Promise that resolves with the serialized value, or null if the key doesn't exist
|
||||
*/
|
||||
dump(key: RedisClient.KeyLike): Promise<string | null>;
|
||||
dump(key: string | ArrayBufferView | Blob): Promise<string | null>;
|
||||
|
||||
/**
|
||||
* Get the expiration time of a key as a UNIX timestamp in seconds
|
||||
* @param key The key to check
|
||||
* @returns Promise that resolves with the timestamp, or -1 if the key has no expiration, or -2 if the key doesn't exist
|
||||
*/
|
||||
expiretime(key: RedisClient.KeyLike): Promise<number>;
|
||||
expiretime(key: string | ArrayBufferView | Blob): Promise<number>;
|
||||
|
||||
/**
|
||||
* Get the value of a key and delete the key
|
||||
* @param key The key to get and delete
|
||||
* @returns Promise that resolves with the value of the key, or null if the key doesn't exist
|
||||
*/
|
||||
getdel(key: RedisClient.KeyLike): Promise<string | null>;
|
||||
getdel(key: string | ArrayBufferView | Blob): Promise<string | null>;
|
||||
|
||||
/**
|
||||
* Get the value of a key and optionally set its expiration
|
||||
* @param key The key to get
|
||||
* @returns Promise that resolves with the value of the key, or null if the key doesn't exist
|
||||
*/
|
||||
getex(key: RedisClient.KeyLike): Promise<string | null>;
|
||||
|
||||
/**
|
||||
* Ping the server
|
||||
* @returns Promise that resolves with "PONG" if the server is reachable, or throws an error if the server is not reachable
|
||||
*/
|
||||
ping(): Promise<"PONG">;
|
||||
|
||||
/**
|
||||
* Ping the server with a message
|
||||
* @param message The message to send to the server
|
||||
* @returns Promise that resolves with the message if the server is reachable, or throws an error if the server is not reachable
|
||||
*/
|
||||
ping(message: RedisClient.KeyLike): Promise<string>;
|
||||
getex(key: string | ArrayBufferView | Blob): Promise<string | null>;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -4,16 +4,4 @@ import pkg from "../package.json";
|
||||
|
||||
const BUN_VERSION = (process.env.BUN_VERSION || Bun.version || process.versions.bun).replace(/^.*v/, "");
|
||||
|
||||
let claude = Bun.file(join(import.meta.dir, "..", "CLAUDE.md"));
|
||||
if (await claude.exists()) {
|
||||
let original = await claude.text();
|
||||
const endOfFrontMatter = original.lastIndexOf("---\n");
|
||||
original = original.replaceAll("node_modules/bun-types/", "");
|
||||
if (endOfFrontMatter > -1) {
|
||||
original = original.slice(endOfFrontMatter + "---\n".length).trim() + "\n";
|
||||
}
|
||||
|
||||
await claude.write(original);
|
||||
}
|
||||
|
||||
await Bun.write(join(import.meta.dir, "..", "package.json"), JSON.stringify({ version: BUN_VERSION, ...pkg }, null, 2));
|
||||
Bun.write(join(import.meta.dir, "..", "package.json"), JSON.stringify({ version: BUN_VERSION, ...pkg }, null, 2));
|
||||
|
||||
79
packages/bun-types/sqlite.d.ts
vendored
79
packages/bun-types/sqlite.d.ts
vendored
@@ -764,79 +764,6 @@ declare module "bun:sqlite" {
|
||||
*/
|
||||
readonly paramsCount: number;
|
||||
|
||||
/**
|
||||
* The actual SQLite column types from the first row of the result set.
|
||||
* Useful for expressions and computed columns, which are not covered by `declaredTypes`
|
||||
*
|
||||
* Returns an array of SQLite type constants as uppercase strings:
|
||||
* - `"INTEGER"` for integer values
|
||||
* - `"FLOAT"` for floating-point values
|
||||
* - `"TEXT"` for text values
|
||||
* - `"BLOB"` for binary data
|
||||
* - `"NULL"` for null values
|
||||
* - `null` for unknown/unsupported types
|
||||
*
|
||||
* **Requirements:**
|
||||
* - Only available for read-only statements (SELECT queries)
|
||||
* - For non-read-only statements, throws an error
|
||||
*
|
||||
* **Behavior:**
|
||||
* - Uses `sqlite3_column_type()` to get actual data types from the first row
|
||||
* - Returns `null` for columns with unknown SQLite type constants
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* const stmt = db.prepare("SELECT id, name, age FROM users WHERE id = 1");
|
||||
*
|
||||
* console.log(stmt.columnTypes);
|
||||
* // => ["INTEGER", "TEXT", "INTEGER"]
|
||||
*
|
||||
* // For expressions:
|
||||
* const exprStmt = db.prepare("SELECT length('bun') AS str_length");
|
||||
* console.log(exprStmt.columnTypes);
|
||||
* // => ["INTEGER"]
|
||||
* ```
|
||||
*
|
||||
* @throws Error if statement is not read-only (INSERT, UPDATE, DELETE, etc.)
|
||||
* @since Bun v1.2.13
|
||||
*/
|
||||
readonly columnTypes: Array<"INTEGER" | "FLOAT" | "TEXT" | "BLOB" | "NULL" | null>;
|
||||
|
||||
/**
|
||||
* The declared column types from the table schema.
|
||||
*
|
||||
* Returns an array of declared type strings from `sqlite3_column_decltype()`:
|
||||
* - Raw type strings as declared in the CREATE TABLE statement
|
||||
* - `null` for columns without declared types (e.g., expressions, computed columns)
|
||||
*
|
||||
* **Requirements:**
|
||||
* - Statement must be executed at least once before accessing this property
|
||||
* - Available for both read-only and read-write statements
|
||||
*
|
||||
* **Behavior:**
|
||||
* - Uses `sqlite3_column_decltype()` to get schema-declared types
|
||||
* - Returns the exact type string from the table definition
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* // For table columns:
|
||||
* const stmt = db.prepare("SELECT id, name, weight FROM products");
|
||||
* stmt.get();
|
||||
* console.log(stmt.declaredTypes);
|
||||
* // => ["INTEGER", "TEXT", "REAL"]
|
||||
*
|
||||
* // For expressions (no declared types):
|
||||
* const exprStmt = db.prepare("SELECT length('bun') AS str_length");
|
||||
* exprStmt.get();
|
||||
* console.log(exprStmt.declaredTypes);
|
||||
* // => [null]
|
||||
* ```
|
||||
*
|
||||
* @throws Error if statement hasn't been executed
|
||||
* @since Bun v1.2.13
|
||||
*/
|
||||
readonly declaredTypes: Array<string | null>;
|
||||
|
||||
/**
|
||||
* Finalize the prepared statement, freeing the resources used by the
|
||||
* statement and preventing it from being executed again.
|
||||
@@ -913,12 +840,6 @@ declare module "bun:sqlite" {
|
||||
* Native object representing the underlying `sqlite3_stmt`
|
||||
*
|
||||
* This is left untyped because the ABI of the native bindings may change at any time.
|
||||
*
|
||||
* For stable, typed access to statement metadata, use the typed properties on the Statement class:
|
||||
* - {@link columnNames} for column names
|
||||
* - {@link paramsCount} for parameter count
|
||||
* - {@link columnTypes} for actual data types from the first row
|
||||
* - {@link declaredTypes} for schema-declared column types
|
||||
*/
|
||||
readonly native: any;
|
||||
}
|
||||
|
||||
22
packages/bun-types/test.d.ts
vendored
22
packages/bun-types/test.d.ts
vendored
@@ -88,19 +88,15 @@ declare module "bun:test" {
|
||||
*/
|
||||
export function setSystemTime(now?: Date | number): ThisType<void>;
|
||||
|
||||
interface Jest {
|
||||
restoreAllMocks(): void;
|
||||
clearAllMocks(): void;
|
||||
fn<T extends (...args: any[]) => any>(func?: T): Mock<T>;
|
||||
setSystemTime(now?: number | Date): void;
|
||||
setTimeout(milliseconds: number): void;
|
||||
}
|
||||
export const jest: Jest;
|
||||
export namespace jest {
|
||||
function restoreAllMocks(): void;
|
||||
function clearAllMocks(): void;
|
||||
function fn<T extends (...args: any[]) => any>(func?: T): Mock<T>;
|
||||
function setSystemTime(now?: number | Date): void;
|
||||
function setTimeout(milliseconds: number): void;
|
||||
function useFakeTimers(): void;
|
||||
function useRealTimers(): void;
|
||||
function spyOn<T extends object, K extends keyof T>(
|
||||
obj: T,
|
||||
methodOrPropertyValue: K,
|
||||
): Mock<Extract<T[K], (...args: any[]) => any>>;
|
||||
|
||||
/**
|
||||
* Constructs the type of a mock function, e.g. the return type of `jest.fn()`.
|
||||
*/
|
||||
@@ -150,7 +146,7 @@ declare module "bun:test" {
|
||||
export function spyOn<T extends object, K extends keyof T>(
|
||||
obj: T,
|
||||
methodOrPropertyValue: K,
|
||||
): Mock<Extract<T[K], (...args: any[]) => any>>;
|
||||
): Mock<T[K] extends (...args: any[]) => any ? T[K] : never>;
|
||||
|
||||
interface FunctionLike {
|
||||
readonly name: string;
|
||||
|
||||
@@ -95,7 +95,8 @@ WIN32_EXPORT struct us_socket_context_t *us_create_child_socket_context(int ssl,
|
||||
|
||||
```c
|
||||
/* Write up to length bytes of data. Returns actual bytes written. Will call the on_writable callback of active socket context on failure to write everything off in one go.
|
||||
WIN32_EXPORT int us_socket_write(int ssl, struct us_socket_t *s, const char *data, int length);
|
||||
* Set hint msg_more if you have more immediate data to write. */
|
||||
WIN32_EXPORT int us_socket_write(int ssl, struct us_socket_t *s, const char *data, int length, int msg_more);
|
||||
|
||||
/* Set a low precision, high performance timer on a socket. A socket can only have one single active timer at any given point in time. Will remove any such pre set timer */
|
||||
WIN32_EXPORT void us_socket_timeout(int ssl, struct us_socket_t *s, unsigned int seconds);
|
||||
|
||||
@@ -762,9 +762,9 @@ ssize_t bsd_write2(LIBUS_SOCKET_DESCRIPTOR fd, const char *header, int header_le
|
||||
}
|
||||
#else
|
||||
ssize_t bsd_write2(LIBUS_SOCKET_DESCRIPTOR fd, const char *header, int header_length, const char *payload, int payload_length) {
|
||||
ssize_t written = bsd_send(fd, header, header_length);
|
||||
ssize_t written = bsd_send(fd, header, header_length, 0);
|
||||
if (written == header_length) {
|
||||
ssize_t second_write = bsd_send(fd, payload, payload_length);
|
||||
ssize_t second_write = bsd_send(fd, payload, payload_length, 0);
|
||||
if (second_write > 0) {
|
||||
written += second_write;
|
||||
}
|
||||
@@ -773,7 +773,7 @@ ssize_t bsd_write2(LIBUS_SOCKET_DESCRIPTOR fd, const char *header, int header_le
|
||||
}
|
||||
#endif
|
||||
|
||||
ssize_t bsd_send(LIBUS_SOCKET_DESCRIPTOR fd, const char *buf, int length) {
|
||||
ssize_t bsd_send(LIBUS_SOCKET_DESCRIPTOR fd, const char *buf, int length, int msg_more) {
|
||||
while (1) {
|
||||
// MSG_MORE (Linux), MSG_PARTIAL (Windows), TCP_NOPUSH (BSD)
|
||||
|
||||
@@ -781,8 +781,13 @@ ssize_t bsd_send(LIBUS_SOCKET_DESCRIPTOR fd, const char *buf, int length) {
|
||||
#define MSG_NOSIGNAL 0
|
||||
#endif
|
||||
|
||||
// use TCP_NOPUSH
|
||||
ssize_t rc = send(fd, buf, length, MSG_NOSIGNAL | MSG_DONTWAIT);
|
||||
#ifdef MSG_MORE
|
||||
// for Linux we do not want signals
|
||||
ssize_t rc = send(fd, buf, length, ((msg_more != 0) * MSG_MORE) | MSG_NOSIGNAL | MSG_DONTWAIT);
|
||||
#else
|
||||
// use TCP_NOPUSH
|
||||
ssize_t rc = send(fd, buf, length, MSG_NOSIGNAL | MSG_DONTWAIT);
|
||||
#endif
|
||||
|
||||
if (UNLIKELY(IS_EINTR(rc))) {
|
||||
continue;
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
#ifndef _WIN32
|
||||
#include <arpa/inet.h>
|
||||
#endif
|
||||
|
||||
#define CONCURRENT_CONNECTIONS 4
|
||||
|
||||
// clang-format off
|
||||
@@ -42,20 +43,17 @@ int us_raw_root_certs(struct us_cert_string_t**out){
|
||||
|
||||
void us_listen_socket_close(int ssl, struct us_listen_socket_t *ls) {
|
||||
/* us_listen_socket_t extends us_socket_t so we close in similar ways */
|
||||
struct us_socket_t* s = &ls->s;
|
||||
if (!us_socket_is_closed(0, s)) {
|
||||
struct us_socket_context_t* context = s->context;
|
||||
struct us_loop_t* loop = context->loop;
|
||||
us_internal_socket_context_unlink_listen_socket(ssl, context, ls);
|
||||
us_poll_stop((struct us_poll_t *) s, loop);
|
||||
bsd_close_socket(us_poll_fd((struct us_poll_t *) s));
|
||||
if (!us_socket_is_closed(0, &ls->s)) {
|
||||
us_internal_socket_context_unlink_listen_socket(ssl, ls->s.context, ls);
|
||||
us_poll_stop((struct us_poll_t *) &ls->s, ls->s.context->loop);
|
||||
bsd_close_socket(us_poll_fd((struct us_poll_t *) &ls->s));
|
||||
|
||||
/* Link this socket to the close-list and let it be deleted after this iteration */
|
||||
s->next = loop->data.closed_head;
|
||||
loop->data.closed_head = s;
|
||||
ls->s.next = ls->s.context->loop->data.closed_head;
|
||||
ls->s.context->loop->data.closed_head = &ls->s;
|
||||
|
||||
/* Any socket with prev = context is marked as closed */
|
||||
s->prev = (struct us_socket_t *) context;
|
||||
ls->s.prev = (struct us_socket_t *) ls->s.context;
|
||||
}
|
||||
|
||||
/* We cannot immediately free a listen socket as we can be inside an accept loop */
|
||||
@@ -93,18 +91,16 @@ void us_internal_socket_context_unlink_listen_socket(int ssl, struct us_socket_c
|
||||
context->iterator = ls->s.next;
|
||||
}
|
||||
|
||||
struct us_socket_t* prev = ls->s.prev;
|
||||
struct us_socket_t* next = ls->s.next;
|
||||
if (prev == next) {
|
||||
if (ls->s.prev == ls->s.next) {
|
||||
context->head_listen_sockets = 0;
|
||||
} else {
|
||||
if (prev) {
|
||||
prev->next = next;
|
||||
if (ls->s.prev) {
|
||||
ls->s.prev->next = ls->s.next;
|
||||
} else {
|
||||
context->head_listen_sockets = (struct us_listen_socket_t *) next;
|
||||
context->head_listen_sockets = (struct us_listen_socket_t *) ls->s.next;
|
||||
}
|
||||
if (next) {
|
||||
next->prev = prev;
|
||||
if (ls->s.next) {
|
||||
ls->s.next->prev = ls->s.prev;
|
||||
}
|
||||
}
|
||||
us_socket_context_unref(ssl, context);
|
||||
@@ -116,35 +112,31 @@ void us_internal_socket_context_unlink_socket(int ssl, struct us_socket_context_
|
||||
context->iterator = s->next;
|
||||
}
|
||||
|
||||
struct us_socket_t* prev = s->prev;
|
||||
struct us_socket_t* next = s->next;
|
||||
if (prev == next) {
|
||||
if (s->prev == s->next) {
|
||||
context->head_sockets = 0;
|
||||
} else {
|
||||
if (prev) {
|
||||
prev->next = next;
|
||||
if (s->prev) {
|
||||
s->prev->next = s->next;
|
||||
} else {
|
||||
context->head_sockets = next;
|
||||
context->head_sockets = s->next;
|
||||
}
|
||||
if (next) {
|
||||
next->prev = prev;
|
||||
if (s->next) {
|
||||
s->next->prev = s->prev;
|
||||
}
|
||||
}
|
||||
us_socket_context_unref(ssl, context);
|
||||
}
|
||||
void us_internal_socket_context_unlink_connecting_socket(int ssl, struct us_socket_context_t *context, struct us_connecting_socket_t *c) {
|
||||
struct us_connecting_socket_t* prev = c->prev_pending;
|
||||
struct us_connecting_socket_t* next = c->next_pending;
|
||||
if (prev == next) {
|
||||
if (c->prev_pending == c->next_pending) {
|
||||
context->head_connecting_sockets = 0;
|
||||
} else {
|
||||
if (prev) {
|
||||
prev->next_pending = next;
|
||||
if (c->prev_pending) {
|
||||
c->prev_pending->next_pending = c->next_pending;
|
||||
} else {
|
||||
context->head_connecting_sockets = next;
|
||||
context->head_connecting_sockets = c->next_pending;
|
||||
}
|
||||
if (next) {
|
||||
next->prev_pending = prev;
|
||||
if (c->next_pending) {
|
||||
c->next_pending->prev_pending = c->prev_pending;
|
||||
}
|
||||
}
|
||||
us_socket_context_unref(ssl, context);
|
||||
@@ -152,12 +144,11 @@ void us_internal_socket_context_unlink_connecting_socket(int ssl, struct us_sock
|
||||
|
||||
/* We always add in the top, so we don't modify any s.next */
|
||||
void us_internal_socket_context_link_listen_socket(struct us_socket_context_t *context, struct us_listen_socket_t *ls) {
|
||||
struct us_socket_t* s = &ls->s;
|
||||
s->context = context;
|
||||
s->next = (struct us_socket_t *) context->head_listen_sockets;
|
||||
s->prev = 0;
|
||||
ls->s.context = context;
|
||||
ls->s.next = (struct us_socket_t *) context->head_listen_sockets;
|
||||
ls->s.prev = 0;
|
||||
if (context->head_listen_sockets) {
|
||||
context->head_listen_sockets->s.prev = s;
|
||||
context->head_listen_sockets->s.prev = &ls->s;
|
||||
}
|
||||
context->head_listen_sockets = ls;
|
||||
us_socket_context_ref(0, context);
|
||||
@@ -375,15 +366,15 @@ struct us_listen_socket_t *us_socket_context_listen(int ssl, struct us_socket_co
|
||||
us_poll_start(p, context->loop, LIBUS_SOCKET_READABLE);
|
||||
|
||||
struct us_listen_socket_t *ls = (struct us_listen_socket_t *) p;
|
||||
struct us_socket_t* s = &ls->s;
|
||||
s->context = context;
|
||||
s->timeout = 255;
|
||||
s->long_timeout = 255;
|
||||
s->flags.low_prio_state = 0;
|
||||
s->flags.is_paused = 0;
|
||||
s->flags.is_ipc = 0;
|
||||
s->next = 0;
|
||||
s->flags.allow_half_open = (options & LIBUS_SOCKET_ALLOW_HALF_OPEN);
|
||||
|
||||
ls->s.context = context;
|
||||
ls->s.timeout = 255;
|
||||
ls->s.long_timeout = 255;
|
||||
ls->s.flags.low_prio_state = 0;
|
||||
ls->s.flags.is_paused = 0;
|
||||
ls->s.flags.is_ipc = 0;
|
||||
ls->s.next = 0;
|
||||
ls->s.flags.allow_half_open = (options & LIBUS_SOCKET_ALLOW_HALF_OPEN);
|
||||
us_internal_socket_context_link_listen_socket(context, ls);
|
||||
|
||||
ls->socket_ext_size = socket_ext_size;
|
||||
@@ -409,16 +400,15 @@ struct us_listen_socket_t *us_socket_context_listen_unix(int ssl, struct us_sock
|
||||
us_poll_start(p, context->loop, LIBUS_SOCKET_READABLE);
|
||||
|
||||
struct us_listen_socket_t *ls = (struct us_listen_socket_t *) p;
|
||||
struct us_socket_t* s = &ls->s;
|
||||
s->connect_state = NULL;
|
||||
s->context = context;
|
||||
s->timeout = 255;
|
||||
s->long_timeout = 255;
|
||||
s->flags.low_prio_state = 0;
|
||||
s->flags.allow_half_open = (options & LIBUS_SOCKET_ALLOW_HALF_OPEN);
|
||||
s->flags.is_paused = 0;
|
||||
s->flags.is_ipc = 0;
|
||||
s->next = 0;
|
||||
ls->s.connect_state = NULL;
|
||||
ls->s.context = context;
|
||||
ls->s.timeout = 255;
|
||||
ls->s.long_timeout = 255;
|
||||
ls->s.flags.low_prio_state = 0;
|
||||
ls->s.flags.allow_half_open = (options & LIBUS_SOCKET_ALLOW_HALF_OPEN);
|
||||
ls->s.flags.is_paused = 0;
|
||||
ls->s.flags.is_ipc = 0;
|
||||
ls->s.next = 0;
|
||||
us_internal_socket_context_link_listen_socket(context, ls);
|
||||
|
||||
ls->socket_ext_size = socket_ext_size;
|
||||
@@ -450,7 +440,7 @@ struct us_socket_t* us_socket_context_connect_resolved_dns(struct us_socket_cont
|
||||
socket->flags.is_paused = 0;
|
||||
socket->flags.is_ipc = 0;
|
||||
socket->connect_state = NULL;
|
||||
socket->connect_next = NULL;
|
||||
|
||||
|
||||
us_internal_socket_context_link_socket(context, socket);
|
||||
|
||||
@@ -469,7 +459,7 @@ static void init_addr_with_port(struct addrinfo* info, int port, struct sockaddr
|
||||
}
|
||||
}
|
||||
|
||||
static bool try_parse_ip(const char *ip_str, int port, struct sockaddr_storage *storage) {
|
||||
static int try_parse_ip(const char *ip_str, int port, struct sockaddr_storage *storage) {
|
||||
memset(storage, 0, sizeof(struct sockaddr_storage));
|
||||
// Try to parse as IPv4
|
||||
struct sockaddr_in *addr4 = (struct sockaddr_in *)storage;
|
||||
@@ -479,7 +469,7 @@ static bool try_parse_ip(const char *ip_str, int port, struct sockaddr_storage *
|
||||
#ifdef __APPLE__
|
||||
addr4->sin_len = sizeof(struct sockaddr_in);
|
||||
#endif
|
||||
return 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Try to parse as IPv6
|
||||
@@ -490,17 +480,17 @@ static bool try_parse_ip(const char *ip_str, int port, struct sockaddr_storage *
|
||||
#ifdef __APPLE__
|
||||
addr6->sin6_len = sizeof(struct sockaddr_in6);
|
||||
#endif
|
||||
return 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
// If we reach here, the input is neither IPv4 nor IPv6
|
||||
return 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
void *us_socket_context_connect(int ssl, struct us_socket_context_t *context, const char *host, int port, int options, int socket_ext_size, int* has_dns_resolved) {
|
||||
void *us_socket_context_connect(int ssl, struct us_socket_context_t *context, const char *host, int port, int options, int socket_ext_size, int* is_connecting) {
|
||||
#ifndef LIBUS_NO_SSL
|
||||
if (ssl == 1) {
|
||||
return us_internal_ssl_socket_context_connect((struct us_internal_ssl_socket_context_t *) context, host, port, options, socket_ext_size, has_dns_resolved);
|
||||
return us_internal_ssl_socket_context_connect((struct us_internal_ssl_socket_context_t *) context, host, port, options, socket_ext_size, is_connecting);
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -508,13 +498,13 @@ void *us_socket_context_connect(int ssl, struct us_socket_context_t *context, co
|
||||
|
||||
// fast path for IP addresses in text form
|
||||
struct sockaddr_storage addr;
|
||||
if (try_parse_ip(host, port, &addr)) {
|
||||
*has_dns_resolved = 1;
|
||||
if (try_parse_ip(host, port, &addr) == 0) {
|
||||
*is_connecting = 1;
|
||||
return us_socket_context_connect_resolved_dns(context, &addr, options, socket_ext_size);
|
||||
}
|
||||
|
||||
struct addrinfo_request* ai_req;
|
||||
if (Bun__addrinfo_get(loop, host, (uint16_t)port, &ai_req) == 0) {
|
||||
if (Bun__addrinfo_get(loop, host, &ai_req) == 0) {
|
||||
// fast path for cached results
|
||||
struct addrinfo_result *result = Bun__addrinfo_getRequestResult(ai_req);
|
||||
// fast failure path
|
||||
@@ -525,11 +515,10 @@ void *us_socket_context_connect(int ssl, struct us_socket_context_t *context, co
|
||||
}
|
||||
|
||||
// if there is only one result we can immediately connect
|
||||
struct addrinfo_result_entry* entries = result->entries;
|
||||
if (entries && entries->info.ai_next == NULL) {
|
||||
if (result->entries && result->entries->info.ai_next == NULL) {
|
||||
struct sockaddr_storage addr;
|
||||
init_addr_with_port(&entries->info, port, &addr);
|
||||
*has_dns_resolved = 1;
|
||||
init_addr_with_port(&result->entries->info, port, &addr);
|
||||
*is_connecting = 1;
|
||||
struct us_socket_t *s = us_socket_context_connect_resolved_dns(context, &addr, options, socket_ext_size);
|
||||
Bun__addrinfo_freeRequest(ai_req, s == NULL);
|
||||
return s;
|
||||
@@ -568,19 +557,17 @@ int start_connections(struct us_connecting_socket_t *c, int count) {
|
||||
}
|
||||
++opened;
|
||||
bsd_socket_nodelay(connect_socket_fd, 1);
|
||||
struct us_loop_t* loop = c->context->loop;
|
||||
struct us_socket_context_t* context = c->context;
|
||||
struct us_socket_t *s = (struct us_socket_t *)us_create_poll(loop, 0, sizeof(struct us_socket_t) + c->socket_ext_size);
|
||||
s->context = context;
|
||||
|
||||
struct us_socket_t *s = (struct us_socket_t *)us_create_poll(c->context->loop, 0, sizeof(struct us_socket_t) + c->socket_ext_size);
|
||||
s->context = c->context;
|
||||
s->timeout = c->timeout;
|
||||
s->long_timeout = c->long_timeout;
|
||||
struct us_socket_flags* flags = &s->flags;
|
||||
flags->low_prio_state = 0;
|
||||
flags->allow_half_open = (c->options & LIBUS_SOCKET_ALLOW_HALF_OPEN);
|
||||
flags->is_paused = 0;
|
||||
flags->is_ipc = 0;
|
||||
s->flags.low_prio_state = 0;
|
||||
s->flags.allow_half_open = (c->options & LIBUS_SOCKET_ALLOW_HALF_OPEN);
|
||||
s->flags.is_paused = 0;
|
||||
s->flags.is_ipc = 0;
|
||||
/* Link it into context so that timeout fires properly */
|
||||
us_internal_socket_context_link_socket(context, s);
|
||||
us_internal_socket_context_link_socket(s->context, s);
|
||||
|
||||
// TODO check this, specifically how it interacts with the SSL code
|
||||
// does this work when we create multiple sockets at once? will we need multiple SSL contexts?
|
||||
@@ -592,10 +579,10 @@ int start_connections(struct us_connecting_socket_t *c, int count) {
|
||||
c->connecting_head = s;
|
||||
|
||||
s->connect_state = c;
|
||||
struct us_poll_t* poll = &s->p;
|
||||
|
||||
/* Connect sockets are semi-sockets just like listen sockets */
|
||||
us_poll_init(poll, connect_socket_fd, POLL_TYPE_SEMI_SOCKET);
|
||||
us_poll_start(poll, loop, LIBUS_SOCKET_WRITABLE);
|
||||
us_poll_init(&s->p, connect_socket_fd, POLL_TYPE_SEMI_SOCKET);
|
||||
us_poll_start(&s->p, s->context->loop, LIBUS_SOCKET_WRITABLE);
|
||||
}
|
||||
return opened;
|
||||
}
|
||||
@@ -787,50 +774,42 @@ struct us_socket_t *us_socket_context_adopt_socket(int ssl, struct us_socket_con
|
||||
if (us_socket_is_closed(ssl, s) || us_socket_is_shut_down(ssl, s)) {
|
||||
return s;
|
||||
}
|
||||
struct us_socket_context_t *old_context = s->context;
|
||||
struct us_loop_t *loop = old_context->loop;
|
||||
/* We need to be sure that we still holding a reference*/
|
||||
us_socket_context_ref(ssl, old_context);
|
||||
|
||||
if (s->flags.low_prio_state != 1) {
|
||||
/* We need to be sure that we still holding a reference*/
|
||||
us_socket_context_ref(ssl, context);
|
||||
/* This properly updates the iterator if in on_timeout */
|
||||
us_internal_socket_context_unlink_socket(ssl, old_context, s);
|
||||
} else {
|
||||
/* We manually ref/unref context to handle context life cycle with low-priority queue */
|
||||
us_socket_context_unref(ssl, old_context);
|
||||
us_internal_socket_context_unlink_socket(ssl, s->context, s);
|
||||
}
|
||||
|
||||
|
||||
struct us_connecting_socket_t *c = s->connect_state;
|
||||
|
||||
|
||||
struct us_socket_t *new_s = s;
|
||||
|
||||
if (ext_size != -1) {
|
||||
struct us_poll_t *pool_ref = &s->p;
|
||||
|
||||
new_s = (struct us_socket_t *) us_poll_resize(pool_ref, loop, sizeof(struct us_socket_t) + ext_size);
|
||||
new_s = (struct us_socket_t *) us_poll_resize(&s->p, s->context->loop, sizeof(struct us_socket_t) + ext_size);
|
||||
if (c) {
|
||||
c->connecting_head = new_s;
|
||||
struct us_socket_context_t *old_context = s->context;
|
||||
c->context = context;
|
||||
us_internal_socket_context_unlink_connecting_socket(ssl, old_context, c);
|
||||
us_internal_socket_context_link_connecting_socket(ssl, context, c);
|
||||
us_internal_socket_context_unlink_connecting_socket(ssl, old_context, c);
|
||||
}
|
||||
}
|
||||
new_s->context = context;
|
||||
new_s->timeout = 255;
|
||||
new_s->long_timeout = 255;
|
||||
|
||||
if (new_s->flags.low_prio_state == 1) {
|
||||
/* update pointers in low-priority queue */
|
||||
if (!new_s->prev) loop->data.low_prio_head = new_s;
|
||||
if (!new_s->prev) new_s->context->loop->data.low_prio_head = new_s;
|
||||
else new_s->prev->next = new_s;
|
||||
|
||||
if (new_s->next) new_s->next->prev = new_s;
|
||||
/* We manually ref/unref context to handle context life cycle with low-priority queue */
|
||||
us_socket_context_ref(ssl, context);
|
||||
} else {
|
||||
us_internal_socket_context_link_socket(context, new_s);
|
||||
us_socket_context_unref(ssl, context);
|
||||
}
|
||||
/* We can safely unref the old context here with can potentially be freed */
|
||||
us_socket_context_unref(ssl, old_context);
|
||||
|
||||
return new_s;
|
||||
}
|
||||
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user