aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.devcontainer/scripts/nice.sh2
-rw-r--r--Dockerfile.base2
-rw-r--r--Makefile2
-rw-r--r--README.md102
-rw-r--r--build-id2
-rw-r--r--examples/discord-interactions/README.md6
-rw-r--r--examples/discord-interactions/gitignore88
-rw-r--r--examples/discord-interactions/package.json2
-rw-r--r--examples/next/README.md20
-rw-r--r--examples/next/package.json8
-rw-r--r--examples/next/pages/index.tsx6
-rw-r--r--examples/next/pages/second.tsx22
-rw-r--r--examples/react/README.md74
-rw-r--r--examples/react/package.json2
-rw-r--r--packages/bun-landing/index.css34
-rw-r--r--packages/bun-landing/page.tsx10
-rw-r--r--src/cli.zig2
-rw-r--r--src/http_client_async.zig29
-rw-r--r--src/install/install.zig14
-rw-r--r--src/napi/napi.zig6
-rw-r--r--src/resolver/tsconfig_json.zig15
-rw-r--r--src/string_immutable.zig2
-rw-r--r--src/thread_pool.zig10
-rw-r--r--types/bun/bun.d.ts4
24 files changed, 277 insertions, 187 deletions
diff --git a/.devcontainer/scripts/nice.sh b/.devcontainer/scripts/nice.sh
index d5f2a0601..4b6499dea 100644
--- a/.devcontainer/scripts/nice.sh
+++ b/.devcontainer/scripts/nice.sh
@@ -1,7 +1,7 @@
#!/bin/bash
chsh -s $(which zsh)
-sh -c "$(curl -fsSL https://starship.rs/install.sh) -- --platform linux_musl"
+sh -c "$(curl -fsSL https://starship.rs/install.sh) -- --platform linux_musl" -- --yes
echo "eval \"$(starship init zsh)\"" >>~/.zshrc
curl https://github.com/Jarred-Sumner/vscode-zig/releases/download/fork-v1/zig-0.2.5.vsix >/home/ubuntu/vscode-zig.vsix
diff --git a/Dockerfile.base b/Dockerfile.base
index 197191edb..cf49aca82 100644
--- a/Dockerfile.base
+++ b/Dockerfile.base
@@ -19,6 +19,7 @@ RUN apt-get update && \
wget https://apt.llvm.org/llvm.sh --no-check-certificate && \
chmod +x llvm.sh && \
./llvm.sh 13 && \
+ curl -fsSL https://deb.nodesource.com/setup_18.x | bash - && \
apt-get update && \
apt-get install --no-install-recommends -y \
ca-certificates \
@@ -35,7 +36,6 @@ RUN apt-get update && \
nodejs \
gcc \
g++ \
- npm \
clang-13 \
clang-format-13 \
libc++-13-dev \
diff --git a/Makefile b/Makefile
index bfdf80ac6..e0009eb38 100644
--- a/Makefile
+++ b/Makefile
@@ -706,7 +706,7 @@ jsc-bindings: jsc-bindings-headers jsc-bindings-mac
clone-submodules:
git -c submodule."src/bun.js/WebKit".update=none submodule update --init --recursive --depth=1 --progress
-devcontainer: clone-submodules mimalloc zlib libarchive boringssl picohttp identifier-cache node-fallbacks jsc-bindings-headers api analytics bun_error fallback_decoder jsc-bindings-mac dev runtime_js_dev
+devcontainer: clone-submodules mimalloc zlib libarchive boringssl picohttp identifier-cache node-fallbacks jsc-bindings-headers api analytics bun_error fallback_decoder jsc-bindings-mac dev runtime_js_dev libarchive libbacktrace lolhtml usockets uws base64 tinycc
CLANG_FORMAT := $(shell command -v clang-format 2> /dev/null)
diff --git a/README.md b/README.md
index 54c7fda8b..6ac5a32ba 100644
--- a/README.md
+++ b/README.md
@@ -49,6 +49,7 @@ If using Linux, kernel version 5.6 or higher is strongly recommended, but the mi
- [Using bun with Create React App](#using-bun-with-create-react-app)
- [Using bun with TypeScript](#using-bun-with-typescript)
- [Transpiling TypeScript with Bun](#transpiling-typescript-with-bun)
+ - [Adding Type Definitions](#adding-type-definitions)
- [Not implemented yet](#not-implemented-yet)
- [Limitations & intended usage](#limitations--intended-usage)
- [Upcoming breaking changes](#upcoming-breaking-changes)
@@ -62,6 +63,7 @@ If using Linux, kernel version 5.6 or higher is strongly recommended, but the mi
- [CSS runtime](#css-runtime)
- [Frameworks](#frameworks)
- [Troubleshooting](#troubleshooting)
+ - [Illegal Instruction (Core Dumped)](#illegal-instruction-core-dumped)
- [bun not running on an M1 (or Apple Silicon)](#bun-not-running-on-an-m1-or-apple-silicon)
- [error: Unexpected](#error-unexpected)
- [bun install is stuck](#bun-install-is-stuck)
@@ -321,7 +323,7 @@ bun add preact
<details> <summary><strong>For Linux users</strong>: <code>bun install</code> needs Linux Kernel 5.6 or higher to work well</summary>
-The minimum Linux Kernel version is 5.1. If you're on Linux kernel 5.1 - 5.5, `bun install` should still work, but HTTP requests will be slow due to lack of support for io_uring's `connect()` operation.
+The minimum Linux Kernel version is 5.1. If you're on Linux kernel 5.1 - 5.5, `bun install` should still work, but HTTP requests will be slow due to a lack of support for io_uring's `connect()` operation.
If you're using Ubuntu 20.04, here's how to install a [newer kernel](https://wiki.ubuntu.com/Kernel/LTSEnablementStack):
@@ -366,7 +368,7 @@ Assuming a package.json with a `"clean"` command in `"scripts"`:
> Application commands are native ways to interact with apps in the Discord client. There are 3 types of commands accessible in different interfaces: the chat input, a message's context menu (top-right menu or right-clicking in a message), and a user's context menu (right-clicking on a user).
-To get started you can use interactions template:
+To get started you can use the interactions template:
```bash
bun create discord-interactions my-interactions-bot
@@ -377,7 +379,7 @@ If you don't have a Discord bot/application yet, you can create one [here (https
Invite bot to your server by visiting `https://discord.com/api/oauth2/authorize?client_id=<your_application_id>&scope=bot%20applications.commands`
-Afterwards you will need to get your bot's token, public key, and application id from application page and put them into `.env.example` file
+Afterwards you will need to get your bot's token, public key, and application id from the application page and put them into `.env.example` file
Then you can run the http server that will handle your interactions:
@@ -388,7 +390,7 @@ mv .env.example .env
bun run.js # listening on port 1337
```
-Discord does not accept insecure http server, so you will need provide SSL certificate or put interactions server behind a secure reverse proxy. For development you can use ngrok/cloudflare tunnel to expose local port as secure URL.
+Discord does not accept an insecure HTTP server, so you will need to provide an SSL certificate or put the interactions server behind a secure reverse proxy. For development you can use ngrok/cloudflare tunnel to expose local ports as secure URL.
## Using bun with Next.js
@@ -420,12 +422,13 @@ Here’s what doesn’t work yet:
- `proxy` and anything else in `next.config.js`
- API routes, middleware (middleware is easier to support though! similar SSR API)
- styled-jsx (technically not Next.js but often used with it)
+- React Server Components
When using Next.js, bun automatically reads configuration from `.env.local`, `.env.development` and `.env` (in that order). `process.env.NEXT_PUBLIC_` and `process.env.NEXT_` automatically are replaced via `--define`.
Currently, any time you import new dependencies from `node_modules`, you will need to re-run `bun bun --use next`. This will eventually be automatic.
-## Using bun with single page apps
+## Using bun with single-page apps
In your project folder root (where `package.json` is):
@@ -456,7 +459,7 @@ To create new a React app:
```bash
bun create react ./app
cd app
-bun
+bun dev # start dev server
```
To use an existing React app:
@@ -469,7 +472,7 @@ npm install -D react-refresh
bun bun ./src/index.js # jsx, tsx, ts also work. can be multiple files
# Start the dev server
-bun
+bun dev
```
From there, bun relies on the filesystem for mapping dev server paths to source files. All URL paths are relative to the project root (where `package.json` is located).
@@ -482,7 +485,7 @@ Here are examples of routing source code file paths:
| /src/index.tsx | src/index.tsx |
| /pages/index.js | pages/index.js |
-You do not need to include file extensions in `import` paths. CommonJS-style import paths without the file extension works.
+You do not need to include file extensions in `import` paths. CommonJS-style import paths without the file extension work.
You can override the public directory by passing `--public-dir="path-to-folder"`.
@@ -490,15 +493,33 @@ If no directory is specified and `./public/` doesn’t exist, bun will try `./st
## Using bun with TypeScript
-#### Transpiling TypeScript with Bun
+### Transpiling TypeScript with Bun
TypeScript just works. There’s nothing to configure and nothing extra to install. If you import a `.ts` or `.tsx` file, bun will transpile it into JavaScript. bun also transpiles `node_modules` containing `.ts` or `.tsx` files. This is powered by bun’s TypeScript transpiler, so it’s fast.
bun also reads `tsconfig.json`, including `baseUrl` and `paths`.
+### Adding Type Definitions
+
+To get TypeScript working with the global API, add `bun-types` to your project:
+
+```sh
+bun add -d bun-types
+```
+
+And to the `types` field in your `tsconfig.json`:
+
+```json
+{
+ "compilerOptions": {
+ "types": ["bun-types"]
+ }
+}
+```
+
## Not implemented yet
-bun is a project with incredibly large scope, and it’s early days.
+bun is a project with an incredibly large scope and still in it's early days.
You can see [Bun's Roadmap](https://github.com/Jarred-Sumner/bun/issues/159), but here are some additional things that are planned:
@@ -543,7 +564,7 @@ Longer-term, bun intends to replace Node.js, Webpack, Babel, yarn, and PostCSS (
### Upcoming breaking changes
- Bun's CLI flags will change to better support bun as a JavaScript runtime. They were chosen when bun was just a frontend development tool.
-- Bun's bundling format will change to accomdate production browser bundles and on-demand production bundling
+- Bun's bundling format will change to accommodate production browser bundles and on-demand production bundling
## Configuration
@@ -881,7 +902,24 @@ For developing frameworks, you can also do `bun bun --use ./relative-path-to-fra
If you’re interested in adding a framework integration, please reach out. There’s a lot here and it’s not entirely documented yet.
## Troubleshooting
-
+### Illegal Instruction (Core Dumped)
+If you get this error while bun is initializing, You probably need to wrap the bun executable with intel-sde
+ 1. Install intel-sde
+ - Arch Linux: `yay -S intel-sde`
+ - Other Distros:
+```
+# wget https://downloadmirror.intel.com/732268/sde-external-9.7.0-2022-05-09-lin.tar.xz -O /tmp/intel-sde.tar.xz
+# cd /tmp
+# tar -xf intel-sde.tar.xz
+# cd sde-external*
+# mkdir /usr/local/bin -p
+# cp sde64 /usr/local/bin/sde
+```
+ 2. Add alias to bashrc
+```
+$ echo "alias bun='sde -chip-check-disable -- bun'" >> ~/.bashrc
+```
+You can replace `.bashrc` with `.zshrc` if you use zsh instead of bash
### bun not running on an M1 (or Apple Silicon)
If you see a message like this
@@ -1084,7 +1122,7 @@ export interface Lockfile {
#### Configuring with environment variables
-Environment variables have higher priority than `bunfig.toml`.
+Environment variables have a higher priority than `bunfig.toml`.
| Name | Description |
| -------------------------------- | ------------------------------------------------------------- |
@@ -1099,7 +1137,7 @@ Environment variables have higher priority than `bunfig.toml`.
bun always tries to use the fastest available installation method for the target platform. On macOS, that’s `clonefile` and on Linux, that’s `hardlink`. You can change which installation method is used with the `--backend` flag. When unavailable or on error, `clonefile` and `hardlink` fallsback to a platform-specific implementation of copying files.
-bun stores installed packages from npm in `~/.bun/install/cache/${name}@${version}`. Note that if the semver version has a `build` or a `pre` tag, it is replaced with a hash of that value instead. This is to reduce chances of errors from long file paths, but unfortunately complicates figuring out where a package was installed on disk.
+bun stores installed packages from npm in `~/.bun/install/cache/${name}@${version}`. Note that if the semver version has a `build` or a `pre` tag, it is replaced with a hash of that value instead. This is to reduce the chances of errors from long file paths but unfortunately complicates figuring out where a package was installed on disk.
When the `node_modules` folder exists, before installing, bun checks if the `"name"` and `"version"` in `package/package.json` in the expected node_modules folder matches the expected `name` and `version`. This is how it determines whether or not it should install. It uses a custom JSON parser which stops parsing as soon as it finds `"name"` and `"version"`.
@@ -1148,11 +1186,11 @@ rm -rf ~/.bun/install/cache
bun uses a binary format for caching NPM registry responses. This loads much faster than JSON and tends to be smaller on disk.
You will see these files in `~/.bun/install/cache/*.npm`. The filename pattern is `${hash(packageName)}.npm`. It’s a hash so that extra directories don’t need to be created for scoped packages
-bun’s usage of `Cache-Control` ignores `Age`. This improves performance, but means bun may be about 5 minutes out of date to receive the the latest package version metadata from npm.
+bun’s usage of `Cache-Control` ignores `Age`. This improves performance but means bun may be about 5 minutes out of date to receive the latest package version metadata from npm.
### `bun run`
-`bun run` is a fast `package.json` scripts runner. Instead of waiting 170ms for your npm client to start every time, you wait 6ms for bun.
+`bun run` is a fast `package.json` script runner. Instead of waiting 170ms for your npm client to start every time, you wait 6ms for bun.
By default, `bun run` prints the script that will be invoked:
@@ -1328,7 +1366,7 @@ By default, `bun create` will cancel if there are existing files it would overwr
#### Publishing a new template
-Clone this repository and a new folder in `examples/` with your new template. The `package.json` must have a `name` that starts with `@bun-examples/`. Do not worry about publishing it, that will happen automaticallly after the PR is merged.
+Clone this repository and a new folder in `examples/` with your new template. The `package.json` must have a `name` that starts with `@bun-examples/`. Do not worry about publishing it, that will happen automatically after the PR is merged.
Make sure to include a `.gitignore` that includes `node_modules` so that `node_modules` aren’t checked in to git when people download the template.
@@ -1452,11 +1490,11 @@ Here are some of the questions `.bun` files answer:
- how big is each imported dependency?
- what is the hash of the bundle’s contents? (for etags)
- what is the name & version of every npm package exported in this bundle?
-- what modules from which packages are used in this project? ("project" defined as all the entry points used to generate the .bun)
+- what modules from which packages are used in this project? ("project" is defined as all the entry points used to generate the .bun)
All in one file.
-It’s a little like a build cache, but designed for reuse across builds.
+It’s a little like a build cache but designed for reuse across builds.
#### Position-independent code
@@ -1498,7 +1536,7 @@ Note that `.bun` is a binary file format, so just opening it in VSCode or vim mi
#### Advanced
-By default, `bun bun` only bundles external dependencies that are `import`ed or `require`d in either app code or another external dependency. An "external depenendency" is defined as, "A JavaScript-like file that has `/node_modules/` in the resolved file path and a corresponding `package.json`".
+By default, `bun bun` only bundles external dependencies that are `import`ed or `require`d in either app code or another external dependency. An "external dependency" is defined as, "A JavaScript-like file that has `/node_modules/` in the resolved file path and a corresponding `package.json`".
To force bun to bundle packages which are not located in a `node_modules` folder (i.e. the final, resolved path following all symlinks), add a `bun` section to the root project’s `package.json` with `alwaysBundle` set to an array of package names to always bundle. Here’s an example:
@@ -1523,7 +1561,7 @@ export var $eb6819b = $$m({
Is generated like this:
-1. Murmur3 32 bit hash of `package.name@package.version`. This is the hash uniquely identifying the npm package.
+1. Murmur3 32-bit hash of `package.name@package.version`. This is the hash uniquely identifying the npm package.
2. Wyhash 64 of the `package.hash` + `package_path`. `package_path` means "relative to the root of the npm package, where is the module imported?". For example, if you imported `react/jsx-dev-runtime.js`, the `package_path` is `jsx-dev-runtime.js`. `react-dom/cjs/react-dom.development.js` would be `cjs/react-dom.development.js`
3. Truncate the hash generated above to a `u32`
@@ -1600,7 +1638,7 @@ Two ways to start an HTTP server with bun.js:
1. `export default` an object with a `fetch` function
-If the file used to start bun has a default export with a `fetch` function, it will start the http server.
+If the file used to start bun has a default export with a `fetch` function, it will start the HTTP server.
```ts
// hi.js
@@ -1613,9 +1651,9 @@ export default {
// bun ./hi.js
```
-`fetch` receives a [`Request`](https://developer.mozilla.org/en-US/docs/Web/API/Request) object and must return either a [`Response` ](https://developer.mozilla.org/en-US/docs/Web/API/Response) or a [`Promise<Response>`](https://developer.mozilla.org/en-US/docs/Web/API/Response). In a future version, it might have an additional arguments for things like cookies.
+`fetch` receives a [`Request`](https://developer.mozilla.org/en-US/docs/Web/API/Request) object and must return either a [`Response` ](https://developer.mozilla.org/en-US/docs/Web/API/Response) or a [`Promise<Response>`](https://developer.mozilla.org/en-US/docs/Web/API/Response). In a future version, it might have additional arguments for things like cookies.
-2. `Bun.serve` starts the http server explicitly
+2. `Bun.serve` starts the HTTP server explicitly
```ts
Bun.serve({
@@ -1776,7 +1814,7 @@ Database: [Northwind Traders](https://github.com/jpwhite3/northwind-SQLite3/blob
This benchmark can be run from [./bench/sqlite](./bench/sqlite).
-Here are results from an M1X on macOS 12.3.1.
+Here are results from an M1 Pro (64GB) on macOS 12.3.1.
**SELECT \* FROM "Order"**
@@ -1905,7 +1943,7 @@ var db = new Database();
db.close();
```
-Note: `close()` is called automatically when the database is garbage collected. It is safe to call multiple times, but has no effect after the first.
+Note: `close()` is called automatically when the database is garbage collected. It is safe to call multiple times but has no effect after the first.
#### Database.prototype.query
@@ -2084,9 +2122,9 @@ insertMany.immediate(cats); // uses "BEGIN IMMEDIATE"
insertMany.exclusive(cats); // uses "BEGIN EXCLUSIVE"
```
-Any arguments passed to the transaction function will be forwarded to the wrapped function, and any values returned from the wrapped function will be returned from the transaction function. The wrapped function will also have access to the same this binding as the transaction function.
+Any arguments passed to the transaction function will be forwarded to the wrapped function, and any values returned from the wrapped function will be returned from the transaction function. The wrapped function will also have access to the same binding as the transaction function.
-bun:sqlite's transaction implementation is based on [better-sqlite3](https://github.com/JoshuaWise/better-sqlite3/blob/master/docs/api.md#transactionfunction---function) (along with this section of the docs), so thanks to Joshua Wise and better-sqlite3 constributors.
+bun:sqlite's transaction implementation is based on [better-sqlite3](https://github.com/JoshuaWise/better-sqlite3/blob/master/docs/api.md#transactionfunction---function) (along with this section of the docs), so thanks to Joshua Wise and better-sqlite3 contributors.
#### Database.prototype.serialize
@@ -2133,7 +2171,7 @@ var db = new Database();
db.loadExtension("myext");
```
-If you're on macOS, you will need to first use a custom SQLite install (you can install with homebrew). By default, bun uses Apple's propietary build of SQLite because it benchmarks about 50% faster. However, they disabled extension support, so you will need to have a custom build of SQLite to use extensions on macOS.
+If you're on macOS, you will need to first use a custom SQLite install (you can install with homebrew). By default, bun uses Apple's proprietary build of SQLite because it benchmarks about 50% faster. However, they disabled extension support, so you will need to have a custom build of SQLite to use extensions on macOS.
```ts
import { Database } from "bun:sqlite";
@@ -2455,7 +2493,7 @@ console.log(`SQLite 3 version: ${sqlite3_libversion()}`);
#### Low-overhead FFI
-3ns to go from JavaScript <> native code with `bun:ffi` (on my machine, an M1X)
+3ns to go from JavaScript <> native code with `bun:ffi` (on my machine, an M1 Pro with 64GB of RAM)
- 5x faster than napi (Node v17.7.1)
- 100x faster than Deno v1.21.1
@@ -2676,7 +2714,7 @@ Bun represents [pointers](<https://en.wikipedia.org/wiki/Pointer_(computer_progr
<summary>How does a 64 bit pointer fit in a JavaScript number?</summary>
-64-bit processors support up to [52 bits of addressible space](https://en.wikipedia.org/wiki/64-bit_computing#Limits_of_processors).
+64-bit processors support up to [52 bits of addressable space](https://en.wikipedia.org/wiki/64-bit_computing#Limits_of_processors).
[JavaScript numbers](https://en.wikipedia.org/wiki/Double-precision_floating-point_format#IEEE_754_double-precision_binary_floating-point_format:_binary64) support 53 bits of usable space, so that leaves us with about 11 bits of extra space.
@@ -2961,7 +2999,7 @@ export default jsx(
);
```
-If a macro is used, it will be run in the same thread as the transpiler, but in a separate event loop from the rest of your application. Currently, globals between macros and regular code are shared, which means it is possible (but not recommended) to share state between macros and regular code. Attempting to use AST nodes outside of a macro is undefined behavior.
+If a macro is used, it will be run in the same thread as the transpiler, but in a separate event loop from the rest of your application. Currently, globals between macros and regular code are shared, which means it is possible (but not recommended) to share states between macros and regular code. Attempting to use AST nodes outside of a macro is undefined behavior.
#### `Bun.Transpiler.transform`
diff --git a/build-id b/build-id
index d00491fd7..0cfbf0888 100644
--- a/build-id
+++ b/build-id
@@ -1 +1 @@
-1
+2
diff --git a/examples/discord-interactions/README.md b/examples/discord-interactions/README.md
index d620cacd1..84e69d9b2 100644
--- a/examples/discord-interactions/README.md
+++ b/examples/discord-interactions/README.md
@@ -10,12 +10,6 @@ A [slash-create](https://npm.im/slash-create) template, using [Bun runtime](http
bun create discord-interactions interactions-bot
```
-After that, make sure to install dependencies using bun or any other npm compatible package manager:
-
-```sh
-bun install
-```
-
### Development
To run this locally, rename `.env.example` to `.env` and fill in the variables, then you can run `bun run.js` to start a local dev environment and use something like ngrok/cloudflare to tunnel it to a URL.
diff --git a/examples/discord-interactions/gitignore b/examples/discord-interactions/gitignore
new file mode 100644
index 000000000..1c22d540a
--- /dev/null
+++ b/examples/discord-interactions/gitignore
@@ -0,0 +1,88 @@
+/data
+
+# Logs
+logs
+*.log
+npm-debug.log*
+yarn-debug.log*
+yarn-error.log*
+lerna-debug.log*
+
+#config file
+config.json
+
+# Diagnostic reports (https://nodejs.org/api/report.html)
+report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
+
+# Runtime data
+pids
+*.pid
+*.seed
+*.pid.lock
+
+# Directory for instrumented libs generated by jscoverage/JSCover
+lib-cov
+
+# Coverage directory used by tools like istanbul
+coverage
+*.lcov
+
+# nyc test coverage
+.nyc_output
+
+# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
+.grunt
+
+# Bower dependency directory (https://bower.io/)
+bower_components
+
+# node-waf configuration
+.lock-wscript
+
+# Compiled binary addons (https://nodejs.org/api/addons.html)
+build/Release
+
+# Dependency directories
+node_modules/
+jspm_packages/
+
+# TypeScript v1 declaration files
+typings/
+
+# TypeScript cache
+*.tsbuildinfo
+
+# Optional npm cache directory
+.npm
+
+# Optional eslint cache
+.eslintcache
+
+# Microbundle cache
+.rpt2_cache/
+.rts2_cache_cjs/
+.rts2_cache_es/
+.rts2_cache_umd/
+
+# Optional REPL history
+.node_repl_history
+
+# Output of 'npm pack'
+*.tgz
+
+# Yarn Integrity file
+.yarn-integrity
+
+# dotenv environment variables file
+.env
+.env.test
+
+# parcel-bundler cache (https://parceljs.org/)
+.cache
+
+# TernJS port file
+.tern-port
+
+# pm2
+.pm2
+.pm2.bak
diff --git a/examples/discord-interactions/package.json b/examples/discord-interactions/package.json
index d31709aa2..5f5213622 100644
--- a/examples/discord-interactions/package.json
+++ b/examples/discord-interactions/package.json
@@ -1,5 +1,5 @@
{
- "version": "0.0.3",
+ "version": "0.0.5",
"name": "@bun-examples/discord-interactions",
"dependencies": {
"slash-create": "^5.7.0"
diff --git a/examples/next/README.md b/examples/next/README.md
index b12f3e33e..cd0b17310 100644
--- a/examples/next/README.md
+++ b/examples/next/README.md
@@ -1,22 +1,24 @@
-This is a [Next.js](https://nextjs.org/) project bootstrapped with [`create-next-app`](https://github.com/vercel/next.js/tree/canary/packages/create-next-app).
+# Next.js with Bun runtime
+
+This is a [Next.js](https://nextjs.org/) project bootstrapped with Bun.
## Getting Started
+### Cloning the repo
+
+```sh
+bun create next ./app
+```
+
First, run the development server:
```bash
-npm run dev
-# or
-yarn dev
+bun dev
```
Open [http://localhost:3000](http://localhost:3000) with your browser to see the result.
-You can start editing the page by modifying `pages/index.js`. The page auto-updates as you edit the file.
-
-[API routes](https://nextjs.org/docs/api-routes/introduction) can be accessed on [http://localhost:3000/api/hello](http://localhost:3000/api/hello). This endpoint can be edited in `pages/api/hello.js`.
-
-The `pages/api` directory is mapped to `/api/*`. Files in this directory are treated as [API routes](https://nextjs.org/docs/api-routes/introduction) instead of React pages.
+You can start editing the page by modifying `pages/index.tsx`. The page auto-updates as you edit the file.
## Learn More
diff --git a/examples/next/package.json b/examples/next/package.json
index 3963ff5cc..870dc2c34 100644
--- a/examples/next/package.json
+++ b/examples/next/package.json
@@ -1,15 +1,15 @@
{
"name": "@bun-examples/next",
- "version": "0.0.51",
+ "version": "0.0.53",
"main": "index.js",
"dependencies": {
"next": "^12.1.0",
- "react": "^17",
- "react-dom": "^17",
+ "react": "^18",
+ "react-dom": "^18",
"react-is": "^17.0.2"
},
"devDependencies": {
- "@types/react": "latest",
+ "@types/react": "^18",
"bun-framework-next": "^12",
"typescript": "latest"
},
diff --git a/examples/next/pages/index.tsx b/examples/next/pages/index.tsx
index 90b988011..fc078404d 100644
--- a/examples/next/pages/index.tsx
+++ b/examples/next/pages/index.tsx
@@ -1,13 +1,7 @@
import Head from "next/head";
-import Link from "next/link";
import React from "react";
import styles from "../styles/Home.module.css";
import nextPackage from "next/package.json";
-export async function getStaticProps(ctx) {
- return {
- props: {},
- };
-}
export default function Home({}) {
return (
diff --git a/examples/next/pages/second.tsx b/examples/next/pages/second.tsx
deleted file mode 100644
index 0e7b5a5cf..000000000
--- a/examples/next/pages/second.tsx
+++ /dev/null
@@ -1,22 +0,0 @@
-import Link from "next/link";
-
-export default function Second({}) {
- return (
- <div style={{ padding: 16 }}>
- <h1>Second</h1>
-
- <ul>
- <li>
- <Link href="/">
- <a>Root page</a>
- </Link>
- </li>
- <li>
- <Link href="/foo/bar/third">
- <a>Third! page</a>
- </Link>
- </li>
- </ul>
- </div>
- );
-}
diff --git a/examples/react/README.md b/examples/react/README.md
index 02aac3f6e..a857d896c 100644
--- a/examples/react/README.md
+++ b/examples/react/README.md
@@ -1,70 +1,24 @@
-# Getting Started with Create React App
+# React with Bun runtime
-This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app).
+This is a React project boostrapped with bun.
-## Available Scripts
+## Getting Started
-In the project directory, you can run:
+### Cloning the repo
-### `yarn start`
+```sh
+bun create react ./app
+```
-Runs the app in the development mode.\
-Open [http://localhost:3000](http://localhost:3000) to view it in the browser.
+### Development
-The page will reload if you make edits.\
-You will also see any lint errors in the console.
+First, run the development server.
-### `yarn test`
+```
+bun dev
+```
-Launches the test runner in the interactive watch mode.\
-See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information.
+Open http://localhost:3000 with your browser to see the result.
-### `yarn build`
+You can start editing the page by modifying src/App.jsx. The page auto-updates as you edit the file.
-Builds the app for production to the `build` folder.\
-It correctly bundles React in production mode and optimizes the build for the best performance.
-
-The build is minified and the filenames include the hashes.\
-Your app is ready to be deployed!
-
-See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information.
-
-### `yarn eject`
-
-**Note: this is a one-way operation. Once you `eject`, you can’t go back!**
-
-If you aren’t satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project.
-
-Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you’re on your own.
-
-You don’t have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn’t feel obligated to use this feature. However we understand that this tool wouldn’t be useful if you couldn’t customize it when you are ready for it.
-
-## Learn More
-
-You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started).
-
-To learn React, check out the [React documentation](https://reactjs.org/).
-
-### Code Splitting
-
-This section has moved here: [https://facebook.github.io/create-react-app/docs/code-splitting](https://facebook.github.io/create-react-app/docs/code-splitting)
-
-### Analyzing the Bundle Size
-
-This section has moved here: [https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size](https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size)
-
-### Making a Progressive Web App
-
-This section has moved here: [https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app](https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app)
-
-### Advanced Configuration
-
-This section has moved here: [https://facebook.github.io/create-react-app/docs/advanced-configuration](https://facebook.github.io/create-react-app/docs/advanced-configuration)
-
-### Deployment
-
-This section has moved here: [https://facebook.github.io/create-react-app/docs/deployment](https://facebook.github.io/create-react-app/docs/deployment)
-
-### `yarn build` fails to minify
-
-This section has moved here: [https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify](https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify)
diff --git a/examples/react/package.json b/examples/react/package.json
index 8e180116e..e3e8e39b3 100644
--- a/examples/react/package.json
+++ b/examples/react/package.json
@@ -1,6 +1,6 @@
{
"name": "@bun-examples/react",
- "version": "0.0.42",
+ "version": "0.0.47",
"dependencies": {
"react": "^17.0.2",
"react-dom": "^17.0.2",
diff --git a/packages/bun-landing/index.css b/packages/bun-landing/index.css
index 3af3361b1..228503ca6 100644
--- a/packages/bun-landing/index.css
+++ b/packages/bun-landing/index.css
@@ -17,9 +17,11 @@
--vertical-padding: 4rem;
--line-height: 1.4;
}
+
* {
box-sizing: border-box;
}
+
head,
body,
:root {
@@ -37,14 +39,17 @@ a {
text-decoration: none;
transition: transform 0.1s linear;
}
+
a:visited {
color: inherit;
}
+
a:hover {
text-decoration: underline;
transform: scale(1.06, 1.06);
transform-origin: middle center;
}
+
#header-wrap,
#pitch {
background-color: var(--black);
@@ -58,6 +63,7 @@ a:hover {
gap: 24px;
align-items: center;
}
+
main {
width: auto;
@@ -96,6 +102,7 @@ header {
.subtitle {
font-size: 1.2rem;
}
+
nav {
white-space: nowrap;
display: flex;
@@ -140,6 +147,7 @@ header {
cursor: pointer;
transform: scale(1.06);
}
+
#HeaderInstallButton {
transition: transform 0.1s linear;
background: #00a6e1;
@@ -266,10 +274,8 @@ header {
#code-box-copy {
height: 100%;
-
display: flex;
align-items: center;
-
color: var(--orange-light);
transition: transform 0.05s linear;
transition-property: color, transform;
@@ -353,6 +359,7 @@ header {
list-style-type: none;
padding: 0;
}
+
.BarGraph,
.ActiveTab,
.Graphs {
@@ -398,10 +405,8 @@ header {
.BarGraphBar {
margin: 0 auto;
-
width: var(--primary);
height: var(--opposite);
-
background-color: rgb(93, 89, 134);
position: relative;
height: calc(200px * var(--level));
@@ -421,9 +426,6 @@ header {
border-right-color: transparent;
}
-.BarGraph--horizontal .BarGraphBar {
-}
-
.BarGraph--vertical .BarGraphBar {
max-width: 90%;
}
@@ -434,8 +436,9 @@ header {
font-family: var(--monospace-font);
width: 100%;
text-align: center;
-
position: relative;
+ display: flex;
+ justify-content: center;
}
.CardContent {
@@ -474,10 +477,8 @@ header {
.BarGraph--vertical .BarGraphBar {
height: var(--primary);
width: var(--opposite);
-
transform: scaleX(var(--level));
transform-origin: bottom left;
-
max-height: 40px;
margin-top: 1rem;
margin-bottom: 1rem;
@@ -549,8 +550,6 @@ header {
display: grid;
}
-#explain-section {
-}
#explain ul {
font-size: 1.2rem;
}
@@ -629,10 +628,6 @@ header {
--background: #ff17ff;
}
-ul,
-li {
-}
-
.mono {
font-family: var(--monospace-font);
border-radius: 6px;
@@ -831,9 +826,6 @@ li {
gap: 2rem;
}
- .Tabs {
- }
-
.tagline,
.subtitle,
.BarGraph-heading,
@@ -876,7 +868,7 @@ li {
.TabButton {
padding-top: 16px;
- padding-bottom: 16px;
+ padding-bottom: 16px;
}
#pitch-content {
@@ -946,4 +938,4 @@ img {
position: absolute;
white-space: nowrap;
width: 1px;
-} \ No newline at end of file
+}
diff --git a/packages/bun-landing/page.tsx b/packages/bun-landing/page.tsx
index 3e2ecb8d9..7599ed6db 100644
--- a/packages/bun-landing/page.tsx
+++ b/packages/bun-landing/page.tsx
@@ -322,19 +322,19 @@ export default ({ inlineCSS }) => (
type="bun"
amount={48936}
label="requests per second"
- max={Math.max(48936, 16288, 12289) * 1.25}
+ max={Math.max(48936, 16288, 15786) * 1.25}
/>
<BarGraphItem
type="node"
amount={16288}
label="requests per second"
- max={Math.max(48936, 16288, 12289) * 1.25}
+ max={Math.max(48936, 16288, 15786) * 1.25}
/>
<BarGraphItem
type="deno"
- amount={12289}
+ amount={15786}
label="requests per second"
- max={Math.max(48936, 16288, 12289) * 1.25}
+ max={Math.max(48936, 16288, 15786) * 1.25}
/>
</ul>
@@ -548,7 +548,7 @@ export default ({ inlineCSS }) => (
<NodeJS href="https://github.com/Jarred-Sumner/bun/issues/158">
Node-API
</NodeJS>{" "}
- bun.js implements most of{' '}
+ bun.js implements most of{" "}
<a
href="https://nodejs.org/api/n-api.html#node-api"
target="_blank"
diff --git a/src/cli.zig b/src/cli.zig
index e9798eba8..32ad9bca5 100644
--- a/src/cli.zig
+++ b/src/cli.zig
@@ -696,7 +696,7 @@ pub const HelpCommand = struct {
\\> <r> <b><magenta>bun <r><d> ./a.ts ./b.jsx<r> Bundle dependencies of input files into a <r><magenta>.bun<r>
\\
\\> <r> <b><cyan>create <r><d>next ./app<r> Start a new project from a template <d>(bun c)<r>
- \\> <r> <b><magenta>run <r><d> test <r> Run a package.json script or executable<r>
+ \\> <r> <b><magenta>run <r><d> test <r> Run JavaScript with bun, a package.json script, or a bin<r>
\\> <r> <b><green>install<r> Install dependencies for a package.json <d>(bun i)<r>
\\> <r> <b><blue>add <r><d> {s:<16}<r> Add a dependency to package.json <d>(bun a)<r>
\\> <r> remove <r><d> {s:<16}<r> Remove a dependency from package.json <d>(bun rm)<r>
diff --git a/src/http_client_async.zig b/src/http_client_async.zig
index f3fbd45cf..33f004f28 100644
--- a/src/http_client_async.zig
+++ b/src/http_client_async.zig
@@ -42,7 +42,34 @@ pub fn onThreadStart(_: ?*anyopaque) ?*anyopaque {
default_allocator = default_arena.allocator();
NetworkThread.address_list_cached = NetworkThread.AddressListCache.init(default_allocator);
AsyncIO.global = AsyncIO.init(1024, 0) catch |err| {
- Output.prettyErrorln("<r><red>error<r>: Failed to initialize network thread: <red><b>{s}<r>.\nHTTP requests will not work. Please file an issue and run strace().", .{@errorName(err)});
+ log: {
+ if (comptime Environment.isLinux) {
+ if (err == error.SystemOutdated) {
+ Output.prettyErrorln(
+ \\<red>error<r>: Linux kernel version doesn't support io_uring, which Bun depends on.
+ \\
+ \\To fix this error: <b>please upgrade to a newer Linux kernel<r>.
+ \\
+ \\If you're using Windows Subsystem for Linux, here's how:
+ \\ 1. Open PowerShell as an administrator
+ \\ 2. Run this:
+ \\ <cyan>wsl --update<r>
+ \\ <cyan>wsl --shutdown<r>
+ \\
+ \\If that doesn't work (and you're on a Windows machine), try this:
+ \\ 1. Open Windows Update
+ \\ 2. Download any updates to Windows Subsystem for Linux
+ \\
+ \\If you're still having trouble, ask for help in bun's discord https://bun.sh/discord
+ \\
+ , .{});
+ break :log;
+ }
+ }
+
+ Output.prettyErrorln("<r><red>error<r>: Failed to initialize network thread: <red><b>{s}<r>.\nHTTP requests will not work. Please file an issue and run strace().", .{@errorName(err)});
+ }
+
Output.flush();
os.exit(1);
};
diff --git a/src/install/install.zig b/src/install/install.zig
index 5f890e832..051eebb03 100644
--- a/src/install/install.zig
+++ b/src/install/install.zig
@@ -185,7 +185,13 @@ const NetworkTask = struct {
PackageManager.instance.network_channel.writeItem(@fieldParentPtr(NetworkTask, "http", http)) catch {};
}
- const default_headers_buf: string = "Acceptapplication/vnd.npm.install-v1+json";
+ // We must use a less restrictive Acccept header value
+ // https://github.com/Jarred-Sumner/bun/issues/341
+ // https://www.jfrog.com/jira/browse/RTFACT-18398
+ const accept_header_value = "application/vnd.npm.install-v1+json; q=1.0, application/json; q=0.8, */*";
+
+ const default_headers_buf: string = "Accept" ++ accept_header_value;
+
pub fn forManifest(
this: *NetworkTask,
name: string,
@@ -218,7 +224,7 @@ const NetworkTask = struct {
}
if (header_builder.header_count > 0) {
- header_builder.count("Accept", "application/vnd.npm.install-v1+json");
+ header_builder.count("Accept", accept_header_value);
if (last_modified.len > 0 and etag.len > 0) {
header_builder.content.count(last_modified);
}
@@ -236,7 +242,7 @@ const NetworkTask = struct {
header_builder.append("If-Modified-Since", last_modified);
}
- header_builder.append("Accept", "application/vnd.npm.install-v1+json");
+ header_builder.append("Accept", accept_header_value);
if (last_modified.len > 0 and etag.len > 0) {
last_modified = header_builder.content.append(last_modified);
@@ -1094,7 +1100,7 @@ const PackageInstall = struct {
return result;
} else |err| {
switch (err) {
- error.NotSameFilesystem, error.NotSupported => {
+ error.NotSameFileSystem, error.NotSupported => {
supported_method = .copyfile;
},
error.FileNotFound => return Result{
diff --git a/src/napi/napi.zig b/src/napi/napi.zig
index 65ef0c45c..c66fd1f32 100644
--- a/src/napi/napi.zig
+++ b/src/napi/napi.zig
@@ -824,10 +824,8 @@ pub export fn napi_get_dataview_info(env: napi_env, dataview: napi_value, bytele
byte_offset.* = array_buffer.offset;
return .ok;
}
-pub export fn napi_get_version(_: napi_env, result: [*]u32) napi_status {
- result[0] = bun.Global.version.major;
- result[1] = bun.Global.version.minor;
- result[2] = bun.Global.version.patch;
+pub export fn napi_get_version(_: napi_env, result: *u32) napi_status {
+ result.* = NAPI_VERSION;
return .ok;
}
pub export fn napi_create_promise(env: napi_env, deferred: *napi_deferred, promise: *napi_value) napi_status {
diff --git a/src/resolver/tsconfig_json.zig b/src/resolver/tsconfig_json.zig
index 68217191a..34732beb8 100644
--- a/src/resolver/tsconfig_json.zig
+++ b/src/resolver/tsconfig_json.zig
@@ -325,9 +325,24 @@ pub const TSConfigJSON = struct {
return &([_]string{});
}
const parts_count = std.mem.count(u8, text, ".");
+
+ if (parts_count == 0) {
+ if (!js_lexer.isIdentifier(text)) {
+ const warn = source.rangeOfString(loc);
+ log.addRangeWarningFmt(source, warn, allocator, "Invalid JSX member expression: \"{s}\"", .{text}) catch {};
+ return &([_]string{});
+ }
+
+ var members = allocator.alloc(string, 1) catch unreachable;
+
+ members[0] = text;
+ return members;
+ }
+
const parts = allocator.alloc(string, parts_count) catch unreachable;
var iter = std.mem.tokenize(u8, text, ".");
var i: usize = 0;
+
while (iter.next()) |part| {
if (!js_lexer.isIdentifier(part)) {
const warn = source.rangeOfString(loc);
diff --git a/src/string_immutable.zig b/src/string_immutable.zig
index 5ee958b40..8f347b047 100644
--- a/src/string_immutable.zig
+++ b/src/string_immutable.zig
@@ -482,7 +482,7 @@ pub fn eqlAnyComptime(self: string, comptime list: []const string) bool {
return false;
}
-/// Count the occurences of a character in an ASCII byte array
+/// Count the occurrences of a character in an ASCII byte array
/// uses SIMD
pub fn countChar(self: string, char: u8) usize {
var total: usize = 0;
diff --git a/src/thread_pool.zig b/src/thread_pool.zig
index 9608c1bca..03fe6f211 100644
--- a/src/thread_pool.zig
+++ b/src/thread_pool.zig
@@ -2,10 +2,12 @@
// https://github.com/kprotty/zap/blob/blog/src/thread_pool.zig
const std = @import("std");
+const bun = @import("./global.zig");
const ThreadPool = @This();
const Futex = @import("./futex.zig");
const AsyncIO = @import("io");
+const Environment = bun.Environment;
const assert = std.debug.assert;
const Atomic = std.atomic.Atomic;
pub const OnSpawnCallback = fn (ctx: ?*anyopaque) ?*anyopaque;
@@ -182,11 +184,13 @@ noinline fn notifySlow(self: *ThreadPool, is_waking: bool) void {
// We signaled to spawn a new thread
if (can_wake and sync.spawned < self.max_threads) {
- const spawn_config = std.Thread.SpawnConfig{
+ const spawn_config = if (Environment.isMac)
// stack size must be a multiple of page_size
// macOS will fail to spawn a thread if the stack size is not a multiple of page_size
- .stack_size = ((self.stack_size + (std.mem.page_size / 2)) / std.mem.page_size) * std.mem.page_size,
- };
+ std.Thread.SpawnConfig{ .stack_size = ((std.Thread.SpawnConfig{}).stack_size + (std.mem.page_size / 2) / std.mem.page_size) * std.mem.page_size }
+ else
+ std.Thread.SpawnConfig{};
+
const thread = std.Thread.spawn(spawn_config, Thread.run, .{self}) catch return self.unregister(null);
// if (self.name.len > 0) thread.setName(self.name) catch {};
return thread.detach();
diff --git a/types/bun/bun.d.ts b/types/bun/bun.d.ts
index 197577579..f99694e01 100644
--- a/types/bun/bun.d.ts
+++ b/types/bun/bun.d.ts
@@ -322,7 +322,7 @@ declare module "bun" {
interface Sink<T> {
write(chunk: string | ArrayBufferView | ArrayBuffer): number;
- drain(): Promise<number> | number;
+ flush(): Promise<number> | number;
end(): T;
}
@@ -339,7 +339,7 @@ declare module "bun" {
} = {}): void;
write(chunk: string | ArrayBufferView | ArrayBuffer): number;
- drain(): number;
+ flush(): number;
end(): ArrayBuffer;
}