mirror of
https://github.com/oven-sh/bun
synced 2026-02-09 10:28:47 +00:00
package.json
Former-commit-id: 2299f44cc9092dad2ef48ea54af2555c192a723e
This commit is contained in:
4
.gitignore
vendored
4
.gitignore
vendored
@@ -6,7 +6,6 @@ zig-cache
|
||||
*.a
|
||||
profile.json
|
||||
|
||||
/package.json
|
||||
node_modules
|
||||
.swcrc
|
||||
yarn.lock
|
||||
@@ -62,4 +61,5 @@ src/node-fallbacks/out/*
|
||||
src/node-fallbacks/node_modules
|
||||
sign.json
|
||||
release/
|
||||
*.dmg
|
||||
*.dmg
|
||||
sign.*.json
|
||||
11
Makefile
11
Makefile
@@ -36,7 +36,11 @@ jsc-copy-headers:
|
||||
find src/JavaScript/jsc/WebKit/WebKitBuild/Release/JavaScriptCore/Headers/JavaScriptCore/ -name "*.h" -exec cp {} src/JavaScript/jsc/WebKit/WebKitBuild/Release/JavaScriptCore/PrivateHeaders/JavaScriptCore \;
|
||||
|
||||
jsc-build-mac-compile:
|
||||
cd src/javascript/jsc/WebKit && ICU_INCLUDE_DIRS="/usr/local/opt/icu4c/include" ./Tools/Scripts/build-jsc --jsc-only --cmakeargs="-DENABLE_STATIC_JSC=ON -DCMAKE_BUILD_TYPE=relwithdebinfo" && echo "Ignore the \"has no symbols\" errors"
|
||||
cd src/javascript/jsc/WebKit && ICU_INCLUDE_DIRS="/usr/local/opt/icu4c/include" ./Tools/Scripts/build-jsc --jsc-only --cmakeargs="-DENABLE_STATIC_JSC=ON -DCMAKE_BUILD_TYPE=relwithdebinfo -DCMAKE_OSX_ARCHITECTURES=arm64;x86_64" && echo "Ignore the \"has no symbols\" errors"
|
||||
|
||||
jsc-build-linux-compile:
|
||||
cd src/javascript/jsc/WebKit && ./Tools/Scripts/build-jsc --jsc-only --cmakeargs="-DENABLE_STATIC_JSC=ON -DCMAKE_BUILD_TYPE=relwithdebinfo
|
||||
|
||||
|
||||
jsc-build-mac: jsc-build-mac-compile jsc-build-mac-copy
|
||||
|
||||
@@ -103,7 +107,10 @@ mimalloc:
|
||||
bun-link-lld-debug:
|
||||
clang++ $(BUN_LLD_FLAGS) \
|
||||
build/debug/macos-x86_64/bun.o \
|
||||
-o build/debug/macos-x86_64/bun
|
||||
-Wl,-dead_strip \
|
||||
-ftls-model=local-exec \
|
||||
-flto \
|
||||
-o build/debug/macos-x86_64/bun
|
||||
|
||||
bun-link-lld-release:
|
||||
clang++ $(BUN_LLD_FLAGS) \
|
||||
|
||||
32
README.md
32
README.md
@@ -23,9 +23,9 @@ npm install -g bun-cli
|
||||
In your project folder root (where `package.json` is):
|
||||
|
||||
```bash
|
||||
npm install bun-framework-next
|
||||
npm install -D bun-framework-next
|
||||
bun bun --use next
|
||||
open http://localhost:3000; bun
|
||||
bun
|
||||
```
|
||||
|
||||
Here are some features of Next.js that **aren't supported** yet:
|
||||
@@ -69,34 +69,9 @@ Here are examples of routing source code file paths:
|
||||
| src/index.tsx | /src/index.tsx |
|
||||
| pages/index.js | /pages/index.js |
|
||||
|
||||
## Using Bun without `bun dev`
|
||||
|
||||
`bun dev` is the recommended way to use Bun. Today, Bun is primarily intended to speed up your frontend development iteration cycle. `bun` does not implement a JavaScript minifier yet, and does not implement all the optimizations other tools do for shrinking bundle size. That means you probably should look to other tools for bundling in production. To make this split smoother, Bun strives for ecosystem compatibility (e.g. by integrating with Next.js)
|
||||
|
||||
```
|
||||
bun bun ./entry-point-1.js ./entry-point-2.jsx
|
||||
bun build ./entry-point-1.js ./entry-point-2.jsx --origin https://localhost:3000 --outdir=./out
|
||||
```
|
||||
|
||||
You can also pass Bun a folder, and it will assume all JavaScript-like files are entry-points. This lets you use Bun's native filesystem router without a framework.
|
||||
|
||||
For a `routes` directory with these files:
|
||||
|
||||
- `routes/index.js`
|
||||
- `routes/hello/bar.js`
|
||||
- `routes/hello/baz.jsx`
|
||||
- `routes/wut/wat.jsx`
|
||||
|
||||
This would be the corresponding command:
|
||||
|
||||
```bash
|
||||
bun bun ./routes
|
||||
bun build ./routes --outdir=./out
|
||||
```
|
||||
|
||||
# The Bun Bundling Format
|
||||
|
||||
`bun bun` generates a `node_modules.bun` and (optionally) a `node_modules.server.bun`. This is a new binary file format that makes it very efficient to serialize/deserialize `node_modules`. With a 2.4 GHz 8-Core Intel Core i9, metadata for
|
||||
`bun bun` generates a `node_modules.bun` and (optionally) a `node_modules.server.bun`. This is a new binary file format that makes it very efficient to serialize/deserialize `node_modules`.
|
||||
|
||||
Unlike many other bundlers, `Bun` only bundles `node_modules`. This is great for development, where most people add/update packages much less frequently than app code (which is also great for caching in browsers). To make that distinction clear, the filename defaults to `node_modules.bun`. We recommend storing `node_modules.bun` in your git repository. Since it's a binary file, it shouldn't clutter your git history and it will make your entire frontend development team move faster if they don't have to re-bundle dependencies.
|
||||
|
||||
@@ -114,7 +89,6 @@ Bun is a project with incredibly large scope, and it's early days.
|
||||
| [jsx](https://www.typescriptlang.org/tsconfig)\* in tsconfig.json | TypeScript Transpiler |
|
||||
| [TypeScript Decorators](https://www.typescriptlang.org/docs/handbook/decorators.html) | TypeScript Transpiler |
|
||||
| `@jsxPragma` comments | JavaScript Transpiler |
|
||||
| Un-quoted `.env` string values | .env loader |
|
||||
| Sharing `.bun` files | JavaScript Bundler |
|
||||
| [fetch](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API) (in SSR) | Bun.js |
|
||||
| [setTimeout](https://developer.mozilla.org/en-US/docs/Web/API/setTimeout) (in SSR) | Bun.js |
|
||||
|
||||
9
package.json
Normal file
9
package.json
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"dependencies": {
|
||||
"peechy": "^0.4.18"
|
||||
},
|
||||
"scripts": {
|
||||
"build-runtime": "esbuild --target=esnext --bundle src/runtime/index.ts --format=iife --platform=browser --global-name=BUN_RUNTIME > src/runtime.out.js; cat src/runtime.footer.js >> src/runtime.out.js",
|
||||
"build-fallback": "esbuild --target=esnext --bundle src/fallback.ts --format=iife --platform=browser --minify > src/fallback.out.js"
|
||||
}
|
||||
}
|
||||
@@ -258,43 +258,48 @@ pub fn NewWatcher(comptime ContextType: type) type {
|
||||
parent_hash: HashType,
|
||||
comptime copy_file_path: bool,
|
||||
) !void {
|
||||
// https://developer.apple.com/library/archive/documentation/System/Conceptual/ManPages_iPhoneOS/man2/kqueue.2.html
|
||||
var event = std.mem.zeroes(KEvent);
|
||||
|
||||
event.flags = os.EV_ADD | os.EV_CLEAR | os.EV_ENABLE;
|
||||
// we want to know about the vnode
|
||||
event.filter = std.os.EVFILT_VNODE;
|
||||
|
||||
// monitor:
|
||||
// - Write
|
||||
// - Rename
|
||||
|
||||
// we should monitor:
|
||||
// - Delete
|
||||
event.fflags = std.os.NOTE_WRITE | std.os.NOTE_RENAME | std.os.NOTE_DELETE;
|
||||
|
||||
// id
|
||||
event.ident = @intCast(usize, fd);
|
||||
|
||||
const index = this.eventlist_used;
|
||||
this.eventlist_used += 1;
|
||||
const watchlist_id = this.watchlist.len;
|
||||
// Store the hash for fast filtering later
|
||||
event.udata = @intCast(usize, watchlist_id);
|
||||
this.eventlist[index] = event;
|
||||
|
||||
// This took a lot of work to figure out the right permutation
|
||||
// Basically:
|
||||
// - We register the event here.
|
||||
// our while(true) loop above receives notification of changes to any of the events created here.
|
||||
_ = std.os.system.kevent(
|
||||
try this.getQueue(),
|
||||
this.eventlist[index .. index + 1].ptr,
|
||||
1,
|
||||
this.eventlist[index .. index + 1].ptr,
|
||||
0,
|
||||
null,
|
||||
);
|
||||
if (isMac) {
|
||||
|
||||
// https://developer.apple.com/library/archive/documentation/System/Conceptual/ManPages_iPhoneOS/man2/kqueue.2.html
|
||||
var event = std.mem.zeroes(KEvent);
|
||||
|
||||
event.flags = os.EV_ADD | os.EV_CLEAR | os.EV_ENABLE;
|
||||
// we want to know about the vnode
|
||||
event.filter = std.os.EVFILT_VNODE;
|
||||
|
||||
// monitor:
|
||||
// - Write
|
||||
// - Rename
|
||||
|
||||
// we should monitor:
|
||||
// - Delete
|
||||
event.fflags = std.os.NOTE_WRITE | std.os.NOTE_RENAME | std.os.NOTE_DELETE;
|
||||
|
||||
// id
|
||||
event.ident = @intCast(usize, fd);
|
||||
|
||||
this.eventlist_used += 1;
|
||||
|
||||
// Store the hash for fast filtering later
|
||||
event.udata = @intCast(usize, watchlist_id);
|
||||
this.eventlist[index] = event;
|
||||
|
||||
// This took a lot of work to figure out the right permutation
|
||||
// Basically:
|
||||
// - We register the event here.
|
||||
// our while(true) loop above receives notification of changes to any of the events created here.
|
||||
_ = std.os.system.kevent(
|
||||
try this.getQueue(),
|
||||
this.eventlist[index .. index + 1].ptr,
|
||||
1,
|
||||
this.eventlist[index .. index + 1].ptr,
|
||||
0,
|
||||
null,
|
||||
);
|
||||
}
|
||||
|
||||
this.watchlist.appendAssumeCapacity(.{
|
||||
.file_path = if (copy_file_path) try this.allocator.dupe(u8, file_path) else file_path,
|
||||
@@ -323,6 +328,8 @@ pub fn NewWatcher(comptime ContextType: type) type {
|
||||
};
|
||||
|
||||
const parent_hash = Watcher.getHash(Fs.PathName.init(file_path).dirWithTrailingSlash());
|
||||
const index = this.eventlist_used;
|
||||
const watchlist_id = this.watchlist.len;
|
||||
|
||||
// https://developer.apple.com/library/archive/documentation/System/Conceptual/ManPages_iPhoneOS/man2/kqueue.2.html
|
||||
var event = std.mem.zeroes(KEvent);
|
||||
@@ -334,17 +341,13 @@ pub fn NewWatcher(comptime ContextType: type) type {
|
||||
// monitor:
|
||||
// - Write
|
||||
// - Rename
|
||||
|
||||
// we should monitor:
|
||||
// - Delete
|
||||
event.fflags = std.os.NOTE_WRITE | std.os.NOTE_RENAME | std.os.NOTE_DELETE;
|
||||
|
||||
// id
|
||||
event.ident = @intCast(usize, fd);
|
||||
|
||||
const index = this.eventlist_used;
|
||||
this.eventlist_used += 1;
|
||||
const watchlist_id = this.watchlist.len;
|
||||
// Store the hash for fast filtering later
|
||||
event.udata = @intCast(usize, watchlist_id);
|
||||
this.eventlist[index] = event;
|
||||
|
||||
Reference in New Issue
Block a user