diff options
author | 2021-09-03 13:01:36 -0700 | |
---|---|---|
committer | 2021-09-03 13:01:36 -0700 | |
commit | a90760b597b5fa8eff001e82dfa9d80a4af00581 (patch) | |
tree | f692b0a72bc17dfe5d1ae10e6f87b747d02780ff | |
parent | 3fc0c899c97977cc7843bf809c36dcdafb369144 (diff) | |
download | bun-a90760b597b5fa8eff001e82dfa9d80a4af00581.tar.gz bun-a90760b597b5fa8eff001e82dfa9d80a4af00581.tar.zst bun-a90760b597b5fa8eff001e82dfa9d80a4af00581.zip |
Fix logging in bun bun + bump
Former-commit-id: 19275a07342879d9b02b9d9527b762c8bfadb9e6
-rw-r--r-- | .gitignore | 5 | ||||
-rw-r--r-- | .vscode/launch.json | 151 | ||||
-rw-r--r-- | Makefile | 5 | ||||
-rw-r--r-- | README.md | 54 | ||||
-rw-r--r-- | src/allocators.zig | 25 | ||||
-rw-r--r-- | src/fs.zig | 6 | ||||
-rw-r--r-- | src/js_parser/js_parser.zig | 10 | ||||
-rw-r--r-- | src/logger.zig | 61 | ||||
-rw-r--r-- | src/resolver/dir_info.zig | 2 | ||||
-rw-r--r-- | src/test/fixtures/tsx-bug.tsx | 1 |
10 files changed, 257 insertions, 63 deletions
diff --git a/.gitignore b/.gitignore index 71367f134..8c53f9735 100644 --- a/.gitignore +++ b/.gitignore @@ -59,4 +59,7 @@ examples/lotta-modules/bun-old examples/lotta-modules/bun-nofscache src/node-fallbacks/out/* -src/node-fallbacks/node_modules
\ No newline at end of file +src/node-fallbacks/node_modules +sign.json +release/ +*.dmg
\ No newline at end of file diff --git a/.vscode/launch.json b/.vscode/launch.json index 912ebf7b6..22a2be395 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -83,10 +83,20 @@ { "type": "lldb", "request": "launch", + "name": "Release Serve", + "program": "${workspaceFolder}/build/macos-x86_64/bun", + // "args": ["--serve", "--origin=http://localhost:3000"], + "args": ["dev", "--origin=http://localhost:3000"], + "cwd": "${workspaceFolder}/examples/hello-next", + "console": "internalConsole" + }, + { + "type": "lldb", + "request": "launch", "name": "Demo Serve", "program": "${workspaceFolder}/build/debug/macos-x86_64/bun", // "args": ["--serve", "--origin=http://localhost:3000"], - "args": ["dev", "--origin=http://localhost:3006"], + "args": ["dev", "--origin=http://localhost:3000"], "cwd": "${workspaceFolder}/examples/hello-next", "console": "internalConsole" }, @@ -119,24 +129,47 @@ "cwd": "${workspaceFolder}/examples/css-stress-test", "console": "internalConsole" }, + { + "type": "lldb", + "request": "launch", + "name": "Fixture serve", + "program": "${workspaceFolder}/build/debug/macos-x86_64/bun", + "args": [], + "cwd": "${workspaceFolder}/src/test/fixtures", + "console": "internalConsole" + }, { "type": "lldb", "request": "launch", "name": "Demo .bun", "program": "${workspaceFolder}/build/debug/macos-x86_64/bun", - "args": [ - "./src/index.tsx", - "--resolve=lazy", - "--origin=http://localhost:9000/" - ], - "cwd": "${workspaceFolder}/examples/simple-react", + "args": ["bun", "--use=./bun-framework-next"], + "cwd": "${workspaceFolder}/examples/hello-next", + "console": "internalConsole" + }, + { + "type": "lldb", + "request": "launch", + "name": "PNPM .bun", + "program": "${workspaceFolder}/build/debug/macos-x86_64/bun", + "args": ["bun", "./pages/index.tsx"], + "cwd": "/Users/jarred/Build/pnpm-bun/packages/app", "console": "internalConsole" }, { "type": "lldb", "request": "launch", + "name": "PNPM serve", + "program": "${workspaceFolder}/build/debug/macos-x86_64/bun", + "args": [], + "cwd": "/Users/jarred/Build/pnpm-bun/packages/app", + "console": "internalConsole" + }, + { + "type": "lldb", + "request": "launch", "name": "Mixed case resolve", "program": "${workspaceFolder}/build/debug/macos-x86_64/bun", "args": [ @@ -161,6 +194,110 @@ { "type": "lldb", "request": "launch", + "name": "Dev CRA", + "program": "${workspaceFolder}/build/debug/macos-x86_64/bun", + "args": ["dev", "./index.js", "--platform=browser"], + "cwd": "${workspaceFolder}/examples/hello-create-react-app/", + "console": "internalConsole" + }, + { + "type": "lldb", + "request": "launch", + "name": "Fragment", + "program": "${workspaceFolder}/build/debug/macos-x86_64/bun", + "args": [], + "cwd": "${workspaceFolder}/src/test/fixtures", + "console": "internalConsole" + }, + { + "type": "lldb", + "request": "launch", + "name": "Context Bun Bug", + "program": "${workspaceFolder}/build/debug/macos-x86_64/bun", + "args": ["bun", "./code.js"], + "cwd": "/Users/jarred/Build/context/www", + "console": "internalConsole" + }, + { + "type": "lldb", + "request": "launch", + "name": "Context Bun", + "program": "${workspaceFolder}/build/debug/macos-x86_64/bun", + "args": ["bun", "--use=next"], + "cwd": "/Users/jarred/Build/context/www", + "console": "internalConsole" + }, + { + "type": "lldb", + "request": "launch", + "name": "Fixtures Dev", + "program": "${workspaceFolder}/build/debug/macos-x86_64/bun", + "args": ["dev"], + "cwd": "${workspaceFolder}/src/test/fixtures", + "console": "internalConsole" + }, + { + "type": "lldb", + "request": "launch", + "name": "Fixtures Rel", + "program": "${workspaceFolder}/build/macos-x86_64/bun", + "args": ["dev"], + "cwd": "${workspaceFolder}/src/test/fixtures", + "console": "internalConsole" + }, + { + "type": "lldb", + "request": "launch", + "name": "Context Dev", + "program": "${workspaceFolder}/build/debug/macos-x86_64/bun", + "args": [], + "cwd": "/Users/jarred/Build/context/www", + "console": "internalConsole" + }, + { + "type": "lldb", + "request": "launch", + "name": "Context Rel", + "program": "${workspaceFolder}/build/macos-x86_64/bun", + "args": [], + "cwd": "/Users/jarred/Build/context/www", + "console": "internalConsole" + }, + + { + "type": "lldb", + "request": "launch", + "name": "Debug Dev", + "program": "${workspaceFolder}/build/debug/macos-x86_64/bun", + "args": ["dev"], + "cwd": "${workspaceFolder}/examples/hello-next/bun-framework-next", + "console": "internalConsole" + }, + { + "type": "lldb", + "request": "launch", + "name": "Type-only import", + "program": "${workspaceFolder}/build/debug/macos-x86_64/bun", + "args": [ + "bun", + "./src/test/fixtures/type-only-import.ts", + "--external=react" + ], + "cwd": "${workspaceFolder}", + "console": "internalConsole" + }, + { + "type": "lldb", + "request": "launch", + "name": "Dev lotta-modules", + "program": "${workspaceFolder}/build/debug/macos-x86_64/bun", + "args": ["dev", "./index.js", "--platform=browser"], + "cwd": "${workspaceFolder}/examples/lotta-modules/", + "console": "internalConsole" + }, + { + "type": "lldb", + "request": "launch", "name": "Demo Build .bun", "program": "${workspaceFolder}/build/debug/macos-x86_64/bun", "args": [ @@ -4,7 +4,7 @@ bun: vendor bun-prod-native bun-prod-wasi bun-prod-wasm vendor: api node-fallbacks runtime_js fallback_decoder mimalloc picohttp jsc api: - peechy --schema src/api/schema.peechy --esm src/api/schema.js --ts src/api/schema.d.ts --zig src/api/schema.zig + npm install peechy; npm run peechy --schema src/api/schema.peechy --esm src/api/schema.js --ts src/api/schema.d.ts --zig src/api/schema.zig node-fallbacks: cd src/node-fallbacks; npm install; npm run --silent build @@ -85,6 +85,7 @@ BUN_LLD_FLAGS := $(OBJ_FILES) \ ${MACOS_ICU_FLAGS} \ ${JSC_FILES} \ src/deps/picohttpparser.o \ + src/deps/mimalloc/libmimalloc.a \ $(CLANG_FLAGS) \ -fpie \ @@ -99,7 +100,6 @@ bun-link-lld-debug: bun-link-lld-release: clang++ $(BUN_LLD_FLAGS) \ build/macos-x86_64/bun.o \ - /usr/local/lib/mimalloc-1.7/libmimalloc.a \ -o build/macos-x86_64/bun \ -Wl,-dead_strip \ -ftls-model=local-exec \ @@ -117,7 +117,6 @@ sizegen: clang++ src/javascript/jsc/headergen/sizegen.cpp -o /tmp/sizegen $(CLANG_FLAGS) /tmp/sizegen > src/javascript/jsc/bindings/sizes.zig - picohttp: clang -O3 -g -c src/deps/picohttpparser.c -Isrc/deps -o src/deps/picohttpparser.o; cd ../../ @@ -2,15 +2,12 @@ Bun is a new: -- JavaScript/TypeScript/JSX transpiler (`bun ./file.tsx`) -- JavaScript bundler (run `bun bun ./file1.ts ./file2.jsx` and it will flatten node_module imports into one `.bun`) -- Development server with 60fps Hot Module Reloading (& WIP support for React Fast Refresh) (run `bun dev`) -- CSS bundler `bun ./file.css` (it flattens `@import` into one file) +- JavaScript/TypeScript/JSX transpiler +- JavaScript & CSS bundler +- Development server with 60fps Hot Module Reloading (& WIP support for React Fast Refresh) - JavaScript Runtime Environment (powered by JavaScriptCore, what WebKit/Safari uses) -All in one simple tool. - -Most of Bun is written in [Zig](https://), a fast low-level programming language with manual memory management. +All in one easy-to-use tool. ## Install: @@ -33,7 +30,7 @@ open http://localhost:3000; bun dev --origin "http://localhost:3000" Here are some features of Next.js that **aren't supported** yet: -- `getStaticProps`,`getServerSideProps`, `getInitialProps`, `getStaticPaths`. These functions will not be called. +- `getStaticPaths`. These functions will not be called. - locales, zones, `assetPrefix` (workaround: change `--origin \"http://localhsot:3000/assetPrefixInhere\"`) - `next/image` - `<Image />` component @@ -125,17 +122,9 @@ In `bun`: ```bash git submodule update --init --recursive --progress --depth=1 -``` - -You - -Now go back to the folder with `Bun`'s repository. - -Run: - -``` +make vendor zig build headers -zig build +zig build -Drelease-fast ``` # Credits @@ -160,9 +149,34 @@ You can find the patched version of WebKit used by Bun here: https://github.com/ This compiles JavaScriptCore, compiles Bun's `.cpp` bindings for JavaScriptCore (which are the object files using JavaScriptCore) and outputs a new `bun` binary with your changes. -To successfully run `zig build`, you will need to install a fork of Zig you can find here: https://github.com/jarred-sumner/zig/tree/jarred/zig-sloppy. +To successfully run `zig build`, you will need to install a patched version of Zig available here: https://github.com/jarred-sumner/zig/tree/jarred/zig-sloppy. -Bun also statically links: +Bun also statically links these libraries: - `libicu`, which can be found here: https://github.com/unicode-org/icu/blob/main/icu4c/LICENSE - [`picohttp`](https://github.com/h2o/picohttpparser), which is dual-licensed under the Perl License or the MIT License +- [`mimalloc`](https://github.com/microsoft/mimalloc), which is MIT licensed + +For compatibiltiy reasons, these NPM packages are embedded into Bun's binary and injected if imported. + +- [`assert`](https://npmjs.com/package/assert) (MIT license) +- [`browserify-zlib`](https://npmjs.com/package/browserify-zlib) (MIT license) +- [`buffer`](https://npmjs.com/package/buffer) (MIT license) +- [`constants-browserify`](https://npmjs.com/package/constants-browserify) (MIT license) +- [`crypto-browserify`](https://npmjs.com/package/crypto-browserify) (MIT license) +- [`domain-browser`](https://npmjs.com/package/domain-browser) (MIT license) +- [`events`](https://npmjs.com/package/events) (MIT license) +- [`https-browserify`](https://npmjs.com/package/https-browserify) (MIT license) +- [`os-browserify`](https://npmjs.com/package/os-browserify) (MIT license) +- [`path-browserify`](https://npmjs.com/package/path-browserify) (MIT license) +- [`process`](https://npmjs.com/package/process) (MIT license) +- [`punycode`](https://npmjs.com/package/punycode) (MIT license) +- [`querystring-es3`](https://npmjs.com/package/querystring-es3) (MIT license) +- [`stream-browserify`](https://npmjs.com/package/stream-browserify) (MIT license) +- [`stream-http`](https://npmjs.com/package/stream-http) (MIT license) +- [`string_decoder`](https://npmjs.com/package/string_decoder) (MIT license) +- [`timers-browserify`](https://npmjs.com/package/timers-browserify) (MIT license) +- [`tty-browserify`](https://npmjs.com/package/tty-browserify) (MIT license) +- [`url`](https://npmjs.com/package/url) (MIT license) +- [`util`](https://npmjs.com/package/util) (MIT license) +- [`vm-browserify`](https://npmjs.com/package/vm-browserify) (MIT license) diff --git a/src/allocators.zig b/src/allocators.zig index b2b8244f4..29f660a12 100644 --- a/src/allocators.zig +++ b/src/allocators.zig @@ -134,6 +134,7 @@ pub fn BSSList(comptime ValueType: type, comptime _count: anytype) type { const max_index = count - 1; var list_type: type = undefined; var list_count = count; + const overflow_init_count = std.math.max(count / 8, 32); return struct { pub var backing_buf: [count]ValueType = undefined; pub var backing_buf_used: u16 = 0; @@ -183,7 +184,7 @@ pub fn BSSList(comptime ValueType: type, comptime _count: anytype) type { backing_buf[result.index] = value; backing_buf_used += 1; if (backing_buf_used >= max_index) { - self.overflow_list = try @TypeOf(self.overflow_list).initCapacity(self.allocator, count); + self.overflow_list = try @TypeOf(self.overflow_list).initCapacity(self.allocator, overflow_init_count); } } @@ -201,7 +202,7 @@ pub fn BSSList(comptime ValueType: type, comptime _count: anytype) type { backing_buf[result.index] = value; backing_buf_used += 1; if (backing_buf_used >= max_index) { - self.overflow_list = try @TypeOf(self.overflow_list).initCapacity(self.allocator, count); + self.overflow_list = try @TypeOf(self.overflow_list).initCapacity(self.allocator, overflow_init_count); } return Pair{ .index = result, .value = &backing_buf[result.index] }; } @@ -216,7 +217,7 @@ pub fn BSSList(comptime ValueType: type, comptime _count: anytype) type { result.index.index = backing_buf_used; backing_buf_used += 1; if (backing_buf_used >= max_index) { - self.overflow_list = try @TypeOf(self.overflow_list).initCapacity(self.allocator, count); + self.overflow_list = try @TypeOf(self.overflow_list).initCapacity(self.allocator, overflow_init_count); } } } @@ -282,6 +283,7 @@ pub fn BSSStringList(comptime _count: usize, comptime _item_length: usize) type const count = _count * 2; const max_index = count - 1; const ValueType = []const u8; + const overflow_init_count = std.math.max(count / 8, 32); return struct { pub var slice_buf: [count][]const u8 = undefined; @@ -417,7 +419,7 @@ pub fn BSSStringList(comptime _count: usize, comptime _item_length: usize) type result.index = slice_buf_used; slice_buf_used += 1; if (slice_buf_used >= max_index) { - self.overflow_list = try @TypeOf(self.overflow_list).initCapacity(self.allocator, count); + self.overflow_list = try @TypeOf(self.overflow_list).initCapacity(self.allocator, overflow_init_count); } } @@ -466,8 +468,9 @@ pub fn BSSStringList(comptime _count: usize, comptime _item_length: usize) type }; } -pub fn BSSMap(comptime ValueType: type, comptime count: anytype, store_keys: bool, estimated_key_length: usize) type { +pub fn BSSMap(comptime ValueType: type, comptime count: anytype, store_keys: bool, estimated_key_length: usize, remove_trailing_slashes: bool) type { const max_index = count - 1; + const overflow_init_count = std.math.max(count / 8, 32); const BSSMapType = struct { pub var backing_buf: [count]ValueType = undefined; pub var backing_buf_used: u16 = 0; @@ -494,7 +497,8 @@ pub fn BSSMap(comptime ValueType: type, comptime count: anytype, store_keys: boo return backing_buf_used >= @as(u16, count); } - pub fn getOrPut(self: *Self, key: []const u8) !Result { + pub fn getOrPut(self: *Self, denormalized_key: []const u8) !Result { + const key = if (comptime remove_trailing_slashes) std.mem.trimRight(u8, denormalized_key, "/") else denormalized_key; const _key = Wyhash.hash(Seed, key); var index = try self.index.getOrPut(self.allocator, _key); @@ -518,7 +522,8 @@ pub fn BSSMap(comptime ValueType: type, comptime count: anytype, store_keys: boo }; } - pub fn get(self: *const Self, key: []const u8) ?*ValueType { + pub fn get(self: *const Self, denormalized_key: []const u8) ?*ValueType { + const key = if (comptime remove_trailing_slashes) std.mem.trimRight(u8, denormalized_key, "/") else denormalized_key; const _key = Wyhash.hash(Seed, key); const index = self.index.get(_key) orelse return null; return self.atIndex(index); @@ -547,7 +552,7 @@ pub fn BSSMap(comptime ValueType: type, comptime count: anytype, store_keys: boo result.index.index = backing_buf_used; backing_buf_used += 1; if (backing_buf_used >= max_index) { - self.overflow_list = try @TypeOf(self.overflow_list).initCapacity(self.allocator, count); + self.overflow_list = try @TypeOf(self.overflow_list).initCapacity(self.allocator, overflow_init_count); } } } @@ -570,7 +575,9 @@ pub fn BSSMap(comptime ValueType: type, comptime count: anytype, store_keys: boo } } - pub fn remove(self: *Self, key: []const u8) void { + pub fn remove(self: *Self, denormalized_key: []const u8) void { + const key = if (comptime remove_trailing_slashes) std.mem.trimRight(u8, denormalized_key, "/") else denormalized_key; + const _key = Wyhash.hash(Seed, key); _ = self.index.remove(_key); // const index = self.index.get(_key) orelse return; diff --git a/src/fs.zig b/src/fs.zig index 80473692b..2bed1ee47 100644 --- a/src/fs.zig +++ b/src/fs.zig @@ -15,8 +15,8 @@ const hash_map = @import("hash_map.zig"); pub const Preallocate = struct { pub const Counts = struct { - pub const dir_entry: usize = 512; - pub const files: usize = 4096; + pub const dir_entry: usize = 4096; + pub const files: usize = 8096; }; }; @@ -665,7 +665,7 @@ pub const FileSystem = struct { // This custom map implementation: // - Preallocates a fixed amount of directory name space // - Doesn't store directory names which don't exist. - pub const Map = allocators.BSSMap(EntriesOption, Preallocate.Counts.dir_entry, false, 128); + pub const Map = allocators.BSSMap(EntriesOption, Preallocate.Counts.dir_entry, false, 128, true); }; // Limit the number of files open simultaneously to avoid ulimit issues diff --git a/src/js_parser/js_parser.zig b/src/js_parser/js_parser.zig index 957da2857..ca6e38edb 100644 --- a/src/js_parser/js_parser.zig +++ b/src/js_parser/js_parser.zig @@ -3698,7 +3698,7 @@ pub fn NewParser( .is_computed = item.flags.is_computed, }, .key = (if (is_spread) item.value orelse item.key else item.key) orelse p.panic("Internal error: Expected {s} to have a key.", .{item}), - .value = tup.binding orelse p.panic("Internal error: Expected {s} to have a binding.", .{tup}), + .value = tup.binding orelse p.b(B.Missing{}, expr.loc), .default_value = initializer, }); } @@ -8498,9 +8498,11 @@ pub fn NewParser( } } - // Stop now if this token is forbidden to follow a TypeScript "as" cast - if (p.forbid_suffix_after_as_loc.start > -1 and p.lexer.loc().start == p.forbid_suffix_after_as_loc.start) { - return left; + if (comptime is_typescript_enabled) { + // Stop now if this token is forbidden to follow a TypeScript "as" cast + if (p.forbid_suffix_after_as_loc.start > -1 and p.lexer.loc().start == p.forbid_suffix_after_as_loc.start) { + return left; + } } // Reset the optional chain flag by default. That way we won't accidentally diff --git a/src/logger.zig b/src/logger.zig index 8ccffd06f..397a49a11 100644 --- a/src/logger.zig +++ b/src/logger.zig @@ -454,6 +454,39 @@ pub const Log = struct { }); } + inline fn _addResolveError(log: *Log, source: *const Source, r: Range, allocator: *std.mem.Allocator, comptime fmt: string, args: anytype, import_kind: ImportKind, comptime dupe_text: bool) !void { + const text = try std.fmt.allocPrint(allocator, fmt, args); + // TODO: fix this. this is stupid, it should be returned in allocPrint. + const specifier = BabyString.in(text, args.@"0"); + log.errors += 1; + + const data = if (comptime dupe_text) brk: { + var _data = rangeData( + source, + r, + text, + ); + if (_data.location != null) { + if (_data.location.?.line_text) |line| { + _data.location.?.line_text = allocator.dupe(u8, line) catch unreachable; + } + } + break :brk _data; + } else rangeData( + source, + r, + text, + ); + + const msg = Msg{ + .kind = .err, + .data = data, + .metadata = .{ .resolve = Msg.Metadata.Resolve{ .specifier = specifier, .import_kind = import_kind } }, + }; + + try log.addMsg(msg); + } + pub fn addResolveError( log: *Log, source: *const Source, @@ -463,21 +496,19 @@ pub const Log = struct { args: anytype, import_kind: ImportKind, ) !void { - const text = try std.fmt.allocPrint(allocator, fmt, args); - // TODO: fix this. this is stupid, it should be returned in allocPrint. - const specifier = BabyString.in(text, args.@"0"); - log.errors += 1; - try log.addMsg( - Msg{ - .kind = .err, - .data = rangeData( - source, - r, - text, - ), - .metadata = .{ .resolve = Msg.Metadata.Resolve{ .specifier = specifier, .import_kind = import_kind } }, - }, - ); + return try _addResolveError(log, source, r, allocator, fmt, args, import_kind, false); + } + + pub fn addResolveErrorWithTextDupe( + log: *Log, + source: *const Source, + r: Range, + allocator: *std.mem.Allocator, + comptime fmt: string, + args: anytype, + import_kind: ImportKind, + ) !void { + return try _addResolveError(log, source, r, allocator, fmt, args, import_kind, true); } pub fn addRangeError(log: *Log, source: ?*const Source, r: Range, text: string) !void { diff --git a/src/resolver/dir_info.zig b/src/resolver/dir_info.zig index c175cf2f2..5d3c53f96 100644 --- a/src/resolver/dir_info.zig +++ b/src/resolver/dir_info.zig @@ -71,4 +71,4 @@ pub fn getEnclosingBrowserScope(i: *const DirInfo) ?*DirInfo { // 2. Don't expect a provided key to exist after it's queried // 3. Store whether a directory has been queried and whether that query was successful. // 4. Allocate onto the https://en.wikipedia.org/wiki/.bss#BSS_in_C instead of the heap, so we can avoid memory leaks -pub const HashMap = allocators.BSSMap(DirInfo, Fs.Preallocate.Counts.dir_entry, false, 128); +pub const HashMap = allocators.BSSMap(DirInfo, Fs.Preallocate.Counts.dir_entry, false, 128, true); diff --git a/src/test/fixtures/tsx-bug.tsx b/src/test/fixtures/tsx-bug.tsx new file mode 100644 index 000000000..9018b1514 --- /dev/null +++ b/src/test/fixtures/tsx-bug.tsx @@ -0,0 +1 @@ +const subtitleProps = searchQuery ? ({ mt: 3, size: "sm" } as const) : {}; |