Compare commits

...

168 Commits

Author SHA1 Message Date
Jarred Sumner
f17345ffe4 Bump the version 2021-10-15 23:05:58 -07:00
Jarred Sumner
4908a63f61 Latest 2021-10-15 23:03:31 -07:00
Jarred Sumner
da7de899e1 📷 2021-10-15 23:02:40 -07:00
Jarred Sumner
44108d6a26 Fix static libarchive build 2021-10-15 22:52:24 -07:00
Jarred Sumner
c7fb978b7b Merge branch 'main' of github.com:Jarred-Sumner/bun 2021-10-15 22:37:29 -07:00
Jarred Sumner
0db94d94d6 Bump s2n-tls 2021-10-15 22:36:28 -07:00
Jarred SUmner
92e489760d Linux build fixes 2021-10-15 22:33:36 -07:00
Jarred Sumner
decee7616f Update Makefile 2021-10-15 20:33:35 -07:00
Jarred Sumner
deafd3d0d4 Cleanup makefile to get libiconv setup for linux 2021-10-15 20:25:23 -07:00
Jarred Sumner
b9bbd819be Update Makefile 2021-10-15 20:14:55 -07:00
Jarred Sumner
b956ea5a5e Update Makefile 2021-10-15 20:13:18 -07:00
Jarred Sumner
cf2e81b036 Merge branch 'jarred/gen' 2021-10-15 20:08:40 -07:00
Jarred Sumner
bf2732599c update makefile 2021-10-15 20:08:21 -07:00
Jarred Sumner
10696680ff Polish 2021-10-15 19:44:53 -07:00
Jarred Sumner
7e159cb5cd ❇️ 2021-10-14 22:10:08 -07:00
Jarred Sumner
74cda61c88 Update README.md 2021-10-14 19:17:44 -07:00
Jarred Sumner
9dfe57a3f7 Update README.md 2021-10-14 19:17:20 -07:00
Jarred Sumner
f10dcd780c Update README.md 2021-10-14 19:08:55 -07:00
Jarred Sumner
bee7efb5d9 Update README.md 2021-10-14 19:07:40 -07:00
Jarred Sumner
0039b53d21 Update README.md 2021-10-14 19:01:51 -07:00
Jarred Sumner
9f86acbe58 Update README.md 2021-10-14 18:58:50 -07:00
Jarred Sumner
bbc1bcbed1 Support local templates 2021-10-14 18:55:41 -07:00
Jarred Sumner
3ed824fe0f Update router.zig 2021-10-14 16:15:04 -07:00
Jarred Sumner
fe24b96d61 Support passing an absolute path 2021-10-14 16:14:48 -07:00
Jarred Sumner
4b6d8a152f Update bun-create.md 2021-10-14 14:51:51 -07:00
Jarred Sumner
e21b9afdf2 Update bun-create.md 2021-10-14 14:50:34 -07:00
Jarred Sumner
901d7d8759 Add doc explaining bun-create 2021-10-14 14:49:48 -07:00
Jarred Sumner
4b618f9ad1 bun create react app is almost done 2021-10-14 05:22:47 -07:00
Jarred Sumner
0f7bc76f39 v0.0.0 2021-10-13 23:13:58 -07:00
Jarred Sumner
6d997ab201 [fetch] Slight perf improvement 2021-10-13 14:29:03 -07:00
Jarred Sumner
8f7f4ae72f --turbo mode for fetch cli, which disables sending TLS shutdown 2021-10-13 14:17:23 -07:00
Jarred Sumner
c85b5f6a87 [fetch] Support Transfer-Encoding: chunked 2021-10-13 14:06:51 -07:00
Jarred Sumner
ba5f9887fb Update build.zig 2021-10-13 00:28:31 -07:00
Jarred Sumner
9e3e9a2d6d Clean up examples a little 2021-10-13 00:28:20 -07:00
Jarred Sumner
88a5e2d34d Add TLS 1.3 support, improve fetch() HTTPS performance 2021-10-13 00:27:35 -07:00
Jarred Sumner
afc346d6f1 s2n.zig 2021-10-12 16:27:32 -07:00
Jarred Sumner
4dd398ca7a ignore = dirty 2021-10-12 16:27:15 -07:00
Jarred Sumner
756bfc9077 Add fetch CLI test app 2021-10-12 16:26:57 -07:00
Jarred Sumner
f646250a91 Add s2n, remove openssl 2021-10-12 16:26:24 -07:00
Jarred Sumner
24c567086f Add OpenSSL 😢 2021-10-11 20:15:15 -07:00
Jarred Sumner
05b1696df7 Add libarchive bindings 2021-10-11 18:31:24 -07:00
Jarred Sumner
0baa3b511e Update README.md 2021-10-11 02:34:54 -07:00
Jarred Sumner
d793088575 Update README.md 2021-10-11 02:34:41 -07:00
Jarred Sumner
9aa7f9ed18 link to fork 2021-10-11 02:33:35 -07:00
Jarred Sumner
e7f6cf12a5 Update .gitmodules 2021-10-10 23:41:49 -07:00
Jarred Sumner
e2ba468924 Update .gitmodules 2021-10-10 23:41:40 -07:00
Jarred Sumner
85760c0a4c Missing fixture 2021-10-10 23:41:27 -07:00
Jarred Sumner
0db7af6166 [fetch] Add support for gzip & deflate to the http client
Powered by Cloudflare's zlib fork
2021-10-10 23:41:18 -07:00
Jarred Sumner
5e3d1dd4b5 Merge pull request #30 from alexkuz/patch-1 2021-10-09 03:47:24 -07:00
Alexander Kuznetsov
6eb9a36a22 Fetch WebKit submodule via https instead of ssh
Fetching submodule via ssh leads to auth error if SSH key is not provided in GitHub settings; all submodules left uninitialized as a result
2021-10-09 11:50:14 +03:00
Jarred Sumner
e88e9401f1 Fix bug where occasionally unary expressions would simplify incorrectly due to an undefined memory issue 2021-10-08 17:24:03 -07:00
Jarred Sumner
829b4287dd Yet Another Packed Struct Bug 2021-10-08 15:48:58 -07:00
Jarred Sumner
2bf7b5a7ab Update readme.md 2021-10-07 22:31:36 -07:00
Jarred Sumner
1c83f3091c Update README.md 2021-10-07 21:31:52 -07:00
Jarred Sumner
dfd08e7c55 Fix potential symbol collision in bun-macro-relay 2021-10-07 21:31:11 -07:00
Jarred Sumner
3b28af17db Fix edgecase when bundling JavaScript that references ESM exported functions before they're defined 2021-10-07 21:30:28 -07:00
Jarred Sumner
5a03dfb9a4 Schema 2021-10-07 21:29:16 -07:00
Jarred Sumner
fa1aa301e8 Add --port CLI flag for setting a port instead of --origin. --port has higher precedence than --origin so that proxies can work 2021-10-07 21:29:07 -07:00
Jarred Sumner
ae7b91efe2 Add CSS HMR benchmark 2021-10-07 21:27:47 -07:00
Jarred Sumner
6d9ccd9b8e Fix package.json file 2021-10-06 20:02:58 -07:00
Jarred Sumner
0d79435ce2 Snapshots 2021-10-06 20:02:40 -07:00
Jarred Sumner
4ee2fdf1c6 uname 2021-10-06 19:32:32 -07:00
Jarred Sumner
cd273daa1b Missing @TypeOf 2021-10-06 19:31:19 -07:00
Jarred Sumner
c2e9d49f69 oops 2021-10-06 19:29:50 -07:00
Jarred Sumner
38a9c92eec Bump it 2021-10-06 19:28:44 -07:00
Jarred Sumner
1d0f442718 📷 2021-10-06 19:26:43 -07:00
Jarred Sumner
1e8babe185 HTTP paths must resolve from ./$PROJECT_ROOT unless explicitly marked absolute.
This fixes the issue with deeply nested PNPM workspace packages. Happened when using @emotion/react inside a PNPM workspace when @emotion/react was hoisted to the workspace root but react was in a child node_modules folder. It would fail to resolve `"react/jsx-dev-runtime"` because it didn't exist in any node_modules folder relative to `@emotion/react`'s real path.
2021-10-06 19:26:28 -07:00
Jarred Sumner
69d3b5ca60 Update browser.js 2021-10-06 19:21:34 -07:00
Jarred Sumner
a493c18193 Fix JSX transform edgecase with static children 2021-10-06 19:21:26 -07:00
Jarred Sumner
5370ea71c0 Add support for reading JSX config from tsconfig.json 2021-10-06 16:49:26 -07:00
Jarred Sumner
0afec7739b Update README.md 2021-10-05 23:09:57 -07:00
Jarred Sumner
a7173d54ce Update README.md 2021-10-05 23:08:11 -07:00
Jarred Sumner
3b10cfae80 analytics is good enough for now 2021-10-05 23:08:06 -07:00
Jarred Sumner
bd14ad9e6e Async analytics works now
Requests are ~60 bytes and the thread mostly sleeps, so it should be pretty low overhead overall.
2021-10-05 17:50:05 -07:00
Jarred Sumner
9507cd8ed6 [fetch] Fix bug with HTTP request bodies 2021-10-05 17:45:32 -07:00
Jarred Sumner
dfe74cb5c4 Add BUN_DISABLE_ANALYTICS flag to disable analytics and automatically disable analytics when running inside hyperfine 2021-10-05 03:11:35 -07:00
Jarred Sumner
00e7b7c3d5 Simple analytics 2021-10-05 02:27:49 -07:00
Jarred SUmner
d2be50bf4d Merge branch 'main' of github.com:Jarred-Sumner/bun into main 2021-10-04 20:42:17 -07:00
Jarred SUmner
f0f3d6d4eb Statically link libicu on Linux so it doesn't require installing icu separately.
this doubles the binary size :(
2021-10-04 20:41:27 -07:00
Jarred SUmner
21d918921a memfd experiment did not yield perf gains on Linux
I suspect the reason why is because we were already using tmpfs. So it was already writing to an in-memory file. O_TMPFILE doesn't seem to do anything for us either here.
2021-10-04 20:01:05 -07:00
Jarred Sumner
55095edee6 Don't pass O_EXCL 2021-10-04 19:07:19 -07:00
Jarred Sumner
6a7deab74d O_TMPFILE 2021-10-04 19:00:18 -07:00
Jarred Sumner
7db27f11d0 memfd_create does not actually make it faster 2021-10-04 18:58:31 -07:00
Jarred Sumner
3ebb4feb98 Attempt to optimize bun bun on Linux by using memfd_create and copying the resulting file via sendfile() 2021-10-04 18:37:51 -07:00
Jarred Sumner
e8dab9bfcf Fix moving files across mount points 2021-10-04 15:35:08 -07:00
Jarred Sumner
dc3eee44a9 Bump 2021-10-04 04:54:23 -07:00
Jarred Sumner
9e8463af33 Bump 2021-10-04 04:31:43 -07:00
Jarred Sumner
dd2bdd09db Bump 2021-10-04 03:33:54 -07:00
Jarred Sumner
0eb3c1d393 Improve Bun's performance by 5%
By making E.Identifier not a pointer, we improve performance by 5%. Heap allocations are bad
2021-10-04 03:28:55 -07:00
Jarred SUmner
cb6a1b7225 Use covid19 example 2021-10-03 23:53:57 -07:00
Jarred SUmner
38c73788e1 Bump 2021-10-03 21:55:50 -07:00
Jarred Sumner
2c89122ce9 Update Makefile 2021-10-03 21:53:21 -07:00
Jarred Sumner
2eae013ebf Update Makefile 2021-10-03 21:50:27 -07:00
Jarred Sumner
1247a9c93d Update Makefile 2021-10-03 21:49:26 -07:00
Jarred Sumner
5c6dd19826 Update Makefile 2021-10-03 21:49:11 -07:00
Jarred Sumner
9d0ee5c5cd Update Makefile 2021-10-03 21:47:34 -07:00
Jarred Sumner
3affc2a2d8 Update Makefile 2021-10-03 21:46:13 -07:00
Jarred Sumner
02bdaa6d10 Fix tmpdir on linux 2021-10-03 21:43:10 -07:00
Jarred Sumner
aee263d050 Update linux build instructions 2021-10-03 21:21:54 -07:00
Jarred Sumner
7ac4abf8a0 Create separate profile binary and strip debug symbols 2021-10-03 20:40:04 -07:00
Jarred Sumner
139622e0b8 llvm-strip 2021-10-03 20:36:59 -07:00
Jarred Sumner
aaa4aaf53f Fix makefile issue 2021-10-03 20:33:47 -07:00
Jarred Sumner
73c27a9a25 Fix various macOS-specific compile errors and run zig fmt 2021-10-03 20:26:54 -07:00
Jarred SUmner
82bf89a946 1% perf improvements on Linux 2021-10-03 18:49:31 -07:00
Jarred SUmner
f4a4e793aa Add Three.js benchmark 2021-10-03 02:22:00 -07:00
Jarred SUmner
cdabcfd9d0 Linux works now. 2021-10-02 22:54:19 -07:00
Jarred Sumner
ac7a96b088 Add support for INotify-based filesystem watcher 2021-10-01 22:41:59 -07:00
Jarred Sumner
6932f3d543 Merge branch 'jarred/linux' of github.com:Jarred-Sumner/bun into jarred/linux 2021-10-01 15:08:14 -07:00
Jarred SUmner
222027991f Build stuff 2021-10-01 15:05:34 -07:00
Jarred Sumner
5bb5091fe0 Bump webkit 2021-10-01 15:02:17 -07:00
Jarred Sumner
c8127d0ae6 Split out the macOS specific parts 2021-10-01 02:06:35 -07:00
Jarred Sumner
8764fa6d4e Update README.md 2021-09-30 23:37:33 -07:00
Jarred Sumner
86b7b5b8d8 Update README.md 2021-09-30 23:37:03 -07:00
Jarred Sumner
127426f506 Update README.md 2021-09-30 23:34:20 -07:00
Jarred Sumner
09cc970b9e Update README.md 2021-09-30 23:33:28 -07:00
Jarred Sumner
03f7c5be1f Fix up readme 2021-09-30 23:29:19 -07:00
Jarred Sumner
4ecf513662 Bump version 2021-09-30 23:22:35 -07:00
Jarred Sumner
76b450386f Add a readme 2021-09-30 23:22:28 -07:00
Jarred Sumner
38a54898a3 Bump build-id 2021-09-30 22:38:03 -07:00
Jarred Sumner
147d1f3951 runtime.version 2021-09-30 22:37:57 -07:00
Jarred Sumner
d47419f471 Snapshots 2021-09-30 22:37:46 -07:00
Jarred Sumner
367f9c9674 Add test that void doesn't delete call expressions 2021-09-30 22:36:06 -07:00
Jarred Sumner
f9a906873e bun-macro-relay works now! 2021-09-30 22:35:34 -07:00
Jarred Sumner
4be8aaeab8 Pass MacroContext in more places 2021-09-30 22:35:20 -07:00
Jarred Sumner
5fdaad9a2f Pass macro_context when appropriate. This needs to be refactored more. 2021-09-30 22:34:54 -07:00
Jarred Sumner
5855fb7cc6 Make sure VM initializes with BUN_* defines 2021-09-30 22:34:36 -07:00
Jarred Sumner
f226f52200 Fix edgecase with cjs -> esm interop runtime code when module.exports was marked as not extensible 2021-09-30 22:34:17 -07:00
Jarred Sumner
db24a27e61 Fix potential infinite loop on calling macros 2021-09-30 22:33:36 -07:00
Jarred Sumner
f8297aee4d Fix jsxDEV transform bug that occurred when not including source and the component rendered an exception 2021-09-30 22:32:03 -07:00
Jarred Sumner
b267aace71 Fix dead-code elimination edgecase with call expressions 2021-09-30 22:30:32 -07:00
Jarred Sumner
b4bd8e4169 Fix edgecase with parsing .env 2021-09-30 22:29:33 -07:00
Jarred Sumner
fdda1078f8 Support remapping macro paths 2021-09-30 18:58:39 -07:00
Jarred Sumner
88e7e12a50 Fix all the compile errors 2021-09-30 14:20:45 -07:00
Jarred Sumner
4cdc8939ab Wire up macro-injected imports and move some structs above the gigantic parser type to reduce bun compile time a little 2021-09-30 13:49:46 -07:00
Jarred Sumner
ec256209a8 flatten fragments 2021-09-30 01:54:53 -07:00
Jarred Sumner
74db7809eb Most of the code & API changes necessary for supporting Relay (GraphQL) 2021-09-29 23:28:54 -07:00
Jarred Sumner
5dac4e6108 Cleanup 2021-09-27 21:25:12 -07:00
Jarred Sumner
e51155d8e6 Remove 2021-09-27 21:25:06 -07:00
Jarred Sumner
2bb7f71b9c Fix up examples 2021-09-27 21:21:51 -07:00
Jarred Sumner
2f8be4f13f () 2021-09-27 21:05:20 -07:00
Jarred Sumner
8e9d85f10f Add fetchCSV() example macro 2021-09-27 21:04:30 -07:00
Jarred Sumner
70bae801dc Bump 2021-09-27 21:03:09 -07:00
Jarred Sumner
37ffe4501c Ignore leading invalid unicode characters in response bodies in Response.text() 2021-09-27 21:03:00 -07:00
Jarred Sumner
13f6297312 Access object properties from macros 2021-09-27 21:01:34 -07:00
Jarred Sumner
f9dfa226a5 Fix bug in string eql check that was never used before 2021-09-27 20:53:57 -07:00
Jarred Sumner
0da19a25cf u16 isn't big enough 2021-09-27 16:28:04 -07:00
Jarred Sumner
3b92a867e2 Pass User-Agent in fetch() by default (but allow overriding) 2021-09-27 16:09:17 -07:00
Jarred Sumner
1ada4a2c67 Fix bug in URL parser 2021-09-27 16:08:57 -07:00
Jarred Sumner
97ad21dc68 Fix typo in error 2021-09-27 16:08:34 -07:00
Jarred Sumner
54dc9cfc8b upgrade 2021-09-27 01:45:53 -07:00
Jarred Sumner
1ed51e8866 Commit build 2021-09-27 01:35:37 -07:00
Jarred Sumner
9e0511995a Merge branch 'jarred/ast-again' 2021-09-27 01:34:12 -07:00
Jarred Sumner
62d51f7d2e Set macros enabled 2021-09-27 01:33:53 -07:00
Jarred Sumner
4f9558dd71 Bundling ignores macros 2021-09-27 01:33:23 -07:00
Jarred Sumner
86109dcfd0 Add a few macros examples 2021-09-27 01:33:15 -07:00
Jarred Sumner
adf22db8b6 bounds checking 2021-09-27 00:40:44 -07:00
Jarred Sumner
eb3473125c Allow nested arrays 2021-09-26 23:04:07 -07:00
Jarred Sumner
b3894994c0 Fix getting object properties 2021-09-26 21:21:51 -07:00
Jarred Sumner
e1306be4be Update Bun.readFileAsBytes and Bun.readFile to also accept an array of filepaths to join
For example:
```
Bun.readFileAsString([Bun.main, "../pages/hi.tsx"]);
```
2021-09-26 20:06:10 -07:00
Jarred Sumner
002d46d0c4 Add JSArrayIterator, don't call JSC::Options after JSC already loaded once (that causes a crash) 2021-09-26 20:04:26 -07:00
Jarred Sumner
018ba2c83b Most of macro implementation 2021-09-26 20:03:49 -07:00
Jarred Sumner
66ed7c1f30 Basic macro impl 2021-09-26 00:14:15 -07:00
Jarred Sumner
a113603f10 Merge pull request #29 from alexkuz/patch-1 2021-09-25 18:03:23 -07:00
Alexander Kuznetsov
6f6d62d915 Check requirements for the build 2021-09-26 03:56:02 +03:00
Jarred Sumner
ff8393ce32 WIP 2021-09-25 14:16:05 -07:00
Jarred Sumner
8b209aecf9 fix incorrect comment 2021-09-25 14:16:05 -07:00
Jarred Sumner
a515a2d039 Add .git 2021-09-25 14:14:33 -07:00
Jarred Sumner
d0fec462c9 Snapshots & package.json 2021-09-25 02:12:01 -07:00
254 changed files with 37872 additions and 32970 deletions

14
.dockerignore Normal file
View File

@@ -0,0 +1,14 @@
node_modules
**/node_modules
src/javascript/jsc/WebKit/LayoutTests
zig-out
zig-build
**/*.o
**/*.a
examples
**/.next
.git
src/javascript/jsc/WebKit/WebKitBuild
**/CMakeCache.txt

8
.gitignore vendored
View File

@@ -30,7 +30,6 @@ cover
coverage
coverv
*.trace
bench
github
out.*
out
@@ -67,4 +66,9 @@ packages/debug-*
packages/bun-cli/postinstall.js
packages/bun-*/bin/*
packages/bun-cli/bin/*
packages/bun-cli/bin/*
bun-test-scratch
misctools/fetch
src/deps/libiconv
src/deps/openssl

18
.gitmodules vendored
View File

@@ -3,13 +3,25 @@
# url = https://github.com/Hejsil/zig-clap
[submodule "src/deps/picohttpparser"]
path = src/deps/picohttpparser
url = https://github.com/h2o/picohttpparser/
url = https://github.com/h2o/picohttpparser.git
ignore = dirty
[submodule "src/javascript/jsc/WebKit"]
path = src/javascript/jsc/WebKit
url = git@github.com:/Jarred-Sumner/WebKit
url = https://github.com/Jarred-Sumner/WebKit.git
ignore = dirty
[submodule "src/deps/mimalloc"]
path = src/deps/mimalloc
url = https://github.com/microsoft/mimalloc
url = https://github.com/microsoft/mimalloc.git
ignore = dirty
[submodule "src/deps/zlib"]
path = src/deps/zlib
url = https://github.com/cloudflare/zlib.git
ignore = dirty
[submodule "src/deps/libarchive"]
path = src/deps/libarchive
url = https://github.com/libarchive/libarchive.git
ignore = dirty
[submodule "src/deps/s2n-tls"]
path = src/deps/s2n-tls
url = https://github.com/Jarred-Sumner/s2n-tls
ignore = dirty

30
.vscode/launch.json vendored
View File

@@ -4,14 +4,19 @@
{
"type": "lldb",
"request": "launch",
"name": "Transpile small",
"program": "${workspaceFolder}/packages/debug-bun-cli-darwin-x64/bin/bun-debug",
"args": [
// "/Users/jarred/Desktop/webpack4.js"
// "/Users/jarred/Code/bun/examples/css-stress-test/nexty/node_modules/next/dist/build/utils.js"
"./dotenv-load-check.ts"
],
"cwd": "${workspaceFolder}/examples/css-stress-test",
"name": "tgz debug",
"program": "${workspaceFolder}/tgz",
"args": ["./bun-examples-all-0.0.1634264480817.tgz"],
"cwd": "${workspaceFolder}",
"console": "internalConsole"
},
{
"type": "lldb",
"request": "launch",
"name": "fetch debug",
"program": "${workspaceFolder}/misctools/fetch",
"args": ["https://example.com"],
"cwd": "${workspaceFolder}",
"console": "internalConsole"
},
{
@@ -79,6 +84,15 @@
"cwd": "${workspaceFolder}/src/test/fixtures",
"console": "internalConsole"
},
{
"type": "lldb",
"request": "launch",
"name": "Linux Launch",
"program": "${workspaceFolder}/packages/debug-bun-cli-linux-x64/bin/bun-debug",
"args": ["--origin=http://jarred-desktop.local:3000/"],
"cwd": "${workspaceFolder}/examples/hello-next",
"console": "internalConsole"
},
{
"type": "lldb",

52
Dockerfile.zig Normal file
View File

@@ -0,0 +1,52 @@
FROM ubuntu:latest
RUN apt-get update && apt-get install --no-install-recommends -y wget gnupg2 curl lsb-release wget software-properties-common
RUN curl -s https://deb.nodesource.com/gpgkey/nodesource.gpg.key | apt-key add -
RUN wget https://apt.llvm.org/llvm.sh --no-check-certificate
RUN chmod +x llvm.sh
RUN ./llvm.sh 12
RUN apt-get update && apt-get install --no-install-recommends -y \
ca-certificates \
curl \
gnupg2 \
software-properties-common \
cmake \
build-essential \
git \
libssl-dev \
ruby \
liblld-12-dev \
libclang-12-dev \
nodejs \
gcc \
g++ \
npm \
clang-12 \
clang-format-12 \
libc++-12-dev \
libc++abi-12-dev \
lld-12 \
libicu-dev
RUN update-alternatives --install /usr/bin/ld ld /usr/bin/lld-12 90 && \
update-alternatives --install /usr/bin/cc cc /usr/bin/clang-12 90 && \
update-alternatives --install /usr/bin/cpp cpp /usr/bin/clang++-12 90 && \
update-alternatives --install /usr/bin/c++ c++ /usr/bin/clang++-12 90
ENV CC=clang-12
ENV CXX=clang++-12
# Compile zig
RUN mkdir -p /home/ubuntu/zig; cd /home/ubuntu; git clone https://github.com/jarred-sumner/zig.git; cd /home/ubuntu/zig && git checkout jarred/zig-sloppy-with-small-structs && cmake . -DCMAKE_BUILD_TYPE=Release && make -j$(nproc)
ENV PATH="/home/ubuntu/zig:$PATH"
RUN npm install -g esbuild

531
Makefile
View File

@@ -1,25 +1,329 @@
OS_NAME := $(shell uname -s | tr '[:upper:]' '[:lower:]')
ARCH_NAME_DENORAMLZIED_1 := $(shell uname -m)
ARCH_NAME_DENORAMLZIED_2 := $(shell tr '[_]' '[--]' <<< $(ARCH_NAME_DENORAMLZIED_1))
ARCH_NAME_DENORAMLZIED_3 := $(shell sed s/x86-64/x64/ <<< $(ARCH_NAME_DENORAMLZIED_2))
ARCH_NAME := $(shell sed s/arm64/aarch64/ <<< $(ARCH_NAME_DENORAMLZIED_3))
TRIPLET := $(OS_NAME)-$(ARCH_NAME)
PACKAGE_DIR := packages/bun-cli-$(TRIPLET)
DEBUG_PACKAGE_DIR := packages/debug-bun-cli-$(TRIPLET)
BIN_DIR := $(PACKAGE_DIR)/bin
RELEASE_BUN := $(shell realpath $(PACKAGE_DIR)/bin/bun)
DEBUG_BIN := $(DEBUG_PACKAGE_DIR)/bin
DEBUG_BIN_REALPATH := $(shell realpath $(DEBUG_PACKAGE_DIR)/bin)
DEBUG_BUN := $(shell realpath $(DEBUG_BIN)/bun-debug)
BUILD_ID := $(shell cat ./build-id)
PACKAGE_JSON_VERSION := 0.0.$(BUILD_ID)
BUN_BUILD_TAG := bun-v$(PACKAGE_JSON_VERSION)
CC := clang
CXX := clang++
ARCH_NAME_RAW := $(shell uname -m)
make-lazy = $(eval $1 = $$(eval $1 := $(value $(1)))$$($1))
ARCH_NAME :=
ifeq ($(ARCH_NAME_RAW),arm64)
ARCH_NAME = aarch64
BREW_PREFIX_PATH = /opt/homebrew
else
ARCH_NAME = x64
BREW_PREFIX_PATH = /usr/local
endif
TRIPLET = $(OS_NAME)-$(ARCH_NAME)
PACKAGE_NAME = bun-cli-$(TRIPLET)
PACKAGES_REALPATH = $(shell realpath packages)
PACKAGE_DIR = $(PACKAGES_REALPATH)/$(PACKAGE_NAME)
DEBUG_PACKAGE_DIR = $(PACKAGES_REALPATH)/debug-$(PACKAGE_NAME)
BIN_DIR = $(PACKAGE_DIR)/bin
RELEASE_BUN = $(PACKAGE_DIR)/bin/bun
DEBUG_BIN = $(DEBUG_PACKAGE_DIR)/bin
DEBUG_BUN = $(DEBUG_BIN)/bun-debug
BUILD_ID = $(shell cat ./build-id)
PACKAGE_JSON_VERSION = 0.0.$(BUILD_ID)
BUN_BUILD_TAG = bun-v$(PACKAGE_JSON_VERSION)
CC ?= $(shell realpath clang)
CXX ?= $(shell realpath clang++)
DEPS_DIR = $(shell pwd)/src/deps
CPUS ?= $(shell nproc)
USER ?= $(echo $USER)
OPENSSL_VERSION = OpenSSL_1_1_1l
LIBICONV_PATH ?= $(BREW_PREFIX_PATH)/opt/libiconv/lib/libiconv.a
OPENSSL_LINUX_DIR = $(DEPS_DIR)/openssl/openssl-OpenSSL_1_1_1l
LIBCRYPTO_PREFIX_DIR = $(BREW_PREFIX_PATH)/opt/openssl@1.1
LIBCRYPTO_STATIC_LIB ?= $(LIBCRYPTO_PREFIX_DIR)/lib/libcrypto.a
LIBCRYPTO_INCLUDE_DIR = $(LIBCRYPTO_PREFIX_DIR)/include
ifeq ($(OS_NAME),linux)
LIBCRYPTO_STATIC_LIB =
LIBICONV_PATH = $(DEPS_DIR)/libiconv.a
endif
# Linux needs to have libcrypto 1.1.1 installed
# download-openssl-linux:
# mkdir -p $(DEPS_DIR)/openssl
# wget https://github.com/openssl/openssl/archive/refs/tags/OpenSSL_1_1_1l.zip
# unzip -o OpenSSL_1_1_1l.zip -d $(DEPS_DIR)/openssl
# rm OpenSSL_1_1_1l.zip
# build-openssl-linux:
# cd $(OPENSSL_LINUX_DIR); \
# ./config -d -fPIC \
# no-md2 no-rc5 no-rfc3779 no-sctp no-ssl-trace no-zlib \
# no-hw no-mdc2 no-seed no-idea enable-ec_nistp_64_gcc_128 no-camellia \
# no-bf no-ripemd no-dsa no-ssl2 no-ssl3 no-capieng \
# -DSSL_FORBID_ENULL -DOPENSSL_NO_DTLS1 -DOPENSSL_NO_HEARTBEATS; \
# make -j $(CPUS) depend; \
# make -j $(CPUS); \
# make -j $(CPUS) install_sw; \
# cp libcrypto.a $(DEPS_DIR)/libcrypto.a
build-iconv-linux:
cd src/deps/libiconv/libiconv-1.16; ./configure --enable-static; make -j 12; cp ./lib/.libs/libiconv.a $(DEPS_DIR)/libiconv.a
BUN_TMP_DIR := /tmp/make-bun
DEFAULT_USE_BMALLOC := 1
# ifeq ($(OS_NAME),linux)
# DEFAULT_USE_BMALLOC = 0
# endif
USE_BMALLOC ?= DEFAULT_USE_BMALLOC
JSC_BASE_DIR ?= ${HOME}/webkit-build
DEFAULT_JSC_LIB :=
ifeq ($(OS_NAME),linux)
DEFAULT_JSC_LIB = $(JSC_BASE_DIR)/lib
endif
ifeq ($(OS_NAME),darwin)
DEFAULT_JSC_LIB = src/deps
endif
JSC_LIB ?= $(DEFAULT_JSC_LIB)
JSC_INCLUDE_DIR ?= $(JSC_BASE_DIR)/include
ZLIB_INCLUDE_DIR ?= $(DEPS_DIR)/zlib
ZLIB_LIB_DIR ?= $(DEPS_DIR)/zlib
JSC_FILES := $(JSC_LIB)/libJavaScriptCore.a $(JSC_LIB)/libWTF.a $(JSC_LIB)/libbmalloc.a
DEFAULT_LINKER_FLAGS =
JSC_BUILD_STEPS :=
ifeq ($(OS_NAME),linux)
JSC_BUILD_STEPS += jsc-check
DEFAULT_LINKER_FLAGS= -lcrypto -pthread -ldl
endif
ifeq ($(OS_NAME),darwin)
JSC_BUILD_STEPS += jsc-build-mac jsc-copy-headers
endif
STRIP ?= $(shell which llvm-strip || which llvm-strip-12 || echo "Missing llvm-strip. Please pass it in the STRIP environment var"; exit 1;)
HOMEBREW_PREFIX ?= $(BREW_PREFIX_PATH)
s2n-ubuntu-deps:
# https://github.com/aws/s2n-tls/blob/main/codebuild/spec/buildspec_ubuntu.yml#L50
sudo apt-get install -y --no-install-recommends indent \
iproute2 \
kwstyle \
lcov \
libssl-dev \
m4 \
make \
net-tools \
nettle-bin \
nettle-dev \
pkg-config \
psmisc \
python3-pip \
shellcheck \
sudo \
tcpdump \
unzip \
valgrind \
zlib1g-dev \
zlibc \
cmake \
tox \
libtool \
ninja-build
s2n-linux:
cd $(DEPS_DIR)/s2n-tls; \
make clean; \
rm -rf build; \
CC=$(CC) CXX=$(CXX) cmake . -Bbuild -GNinja \
-DCMAKE_BUILD_TYPE=Release \
-DBUILD_SHARED_LIBS=OFF \
-DBENCHMARK=0; \
CC=$(CC) CXX=$(CXX) cmake --build ./build -j$(CPUS); \
CC=$(CC) CXX=$(CXX) CTEST_PARALLEL_LEVEL=$(CPUS) ninja -C build;
cp $(DEPS_DIR)/s2n-tls/build/lib/libs2n.a $(DEPS_DIR)/libs2n.a
s2n-linux-debug:
# https://github.com/aws/s2n-tls/blob/main/codebuild/spec/buildspec_ubuntu.yml#L50
sudo apt-get install -y --no-install-recommends indent \
iproute2 \
kwstyle \
lcov \
libssl-dev \
m4 \
make \
net-tools \
nettle-bin \
nettle-dev \
pkg-config \
psmisc \
python3-pip \
shellcheck \
sudo \
tcpdump \
unzip \
valgrind \
zlib1g-dev \
zlibc \
cmake \
tox \
libtool \
ninja-build
cd $(DEPS_DIR)/s2n-tls; \
make clean; \
rm -rf build; \
CC=$(CC) CXX=$(CXX) cmake . -Bbuild -GNinja \
-DCMAKE_BUILD_TYPE=Debug \
-DBUILD_SHARED_LIBS=OFF \
-DBENCHMARK=0; \
CC=$(CC) CXX=$(CXX) cmake --build ./build -j$(CPUS); \
CC=$(CC) CXX=$(CXX) CTEST_PARALLEL_LEVEL=$(CPUS) ninja -C build;
cp $(DEPS_DIR)/s2n-tls/build/lib/libs2n.a $(DEPS_DIR)/libs2n.a
SRC_DIR := src/javascript/jsc/bindings
OBJ_DIR := src/javascript/jsc/bindings-obj
SRC_FILES := $(wildcard $(SRC_DIR)/*.cpp)
OBJ_FILES := $(patsubst $(SRC_DIR)/%.cpp,$(OBJ_DIR)/%.o,$(SRC_FILES))
MAC_INCLUDE_DIRS := -Isrc/javascript/jsc/WebKit/WebKitBuild/Release/JavaScriptCore/PrivateHeaders \
-Isrc/javascript/jsc/WebKit/WebKitBuild/Release/WTF/Headers \
-Isrc/javascript/jsc/WebKit/WebKitBuild/Release/ICU/Headers \
-Isrc/javascript/jsc/WebKit/WebKitBuild/Release/ \
-Isrc/javascript/jsc/bindings/ \
-Isrc/javascript/jsc/WebKit/Source/bmalloc
LINUX_INCLUDE_DIRS := -I$(JSC_INCLUDE_DIR) \
-Isrc/javascript/jsc/bindings/
INCLUDE_DIRS :=
ifeq ($(OS_NAME),linux)
INCLUDE_DIRS += $(LINUX_INCLUDE_DIRS)
endif
ifeq ($(OS_NAME),darwin)
INCLUDE_DIRS += $(MAC_INCLUDE_DIRS)
endif
MACOS_ICU_FILES = $(HOMEBREW_PREFIX)/opt/icu4c/lib/libicudata.a \
$(HOMEBREW_PREFIX)/opt/icu4c/lib/libicui18n.a \
$(HOMEBREW_PREFIX)/opt/icu4c/lib/libicuuc.a
MACOS_ICU_INCLUDE = $(HOMEBREW_PREFIX)opt/icu4c/include
ICU_FLAGS :=
# TODO: find a way to make this more resilient
# Ideally, we could just look up the linker search paths
LIB_ICU_PATH ?= /usr/lib/x86_64-linux-gnu
ifeq ($(OS_NAME),linux)
ICU_FLAGS += $(LIB_ICU_PATH)/libicuuc.a $(LIB_ICU_PATH)/libicudata.a $(LIB_ICU_PATH)/libicui18n.a
endif
ifeq ($(OS_NAME),darwin)
ICU_FLAGS += -l icucore \
$(MACOS_ICU_FILES) \
-I$(MACOS_ICU_INCLUDE)
endif
CLANG_FLAGS = $(INCLUDE_DIRS) \
-std=gnu++17 \
-DSTATICALLY_LINKED_WITH_JavaScriptCore=1 \
-DSTATICALLY_LINKED_WITH_WTF=1 \
-DSTATICALLY_LINKED_WITH_BMALLOC=1 \
-DBUILDING_WITH_CMAKE=1 \
-DNDEBUG=1 \
-DNOMINMAX \
-DIS_BUILD \
-g \
-DENABLE_INSPECTOR_ALTERNATE_DISPATCHERS=0 \
-DBUILDING_JSCONLY__ \
-DASSERT_ENABLED=0 \
-fPIE
# This flag is only added to webkit builds on Apple platforms
# It has something to do with ICU
ifeq ($(OS_NAME), darwin)
CLANG_FLAGS += -DDU_DISABLE_RENAMING=1
endif
BUN_LLD_FLAGS = $(OBJ_FILES) \
${ICU_FLAGS} \
${JSC_FILES} \
src/deps/mimalloc/libmimalloc.a \
src/deps/zlib/libz.a \
src/deps/libarchive.a \
src/deps/libs2n.a \
src/deps/libcrypto.a \
src/deps/picohttpparser.o \
$(LIBICONV_PATH) \
$(CLANG_FLAGS) \
ifeq ($(OS_NAME), linux)
BUN_LLD_FLAGS += -lstdc++fs \
$(DEFAULT_LINKER_FLAGS) \
-lc \
-Wl,-z,now \
-Wl,--as-needed \
-Wl,-z,stack-size=12800000 \
-Wl,-z,notext \
-ffunction-sections \
-fdata-sections \
-Wl,--gc-sections \
-fuse-ld=lld
endif
bun: vendor build-obj bun-link-lld-release
vendor: api node-fallbacks runtime_js fallback_decoder bun_error mimalloc picohttp jsc
vendor-without-check: api analytics node-fallbacks runtime_js fallback_decoder bun_error mimalloc picohttp zlib openssl s2n libarchive
libarchive:
cd src/deps/libarchive; \
(make clean || echo ""); \
./build/clean.sh; \
./build/autogen.sh; \
./configure --disable-shared --enable-static --with-pic --disable-bsdtar --disable-bsdcat --disable-rpath --enable-posix-regex-lib --without-xml2 --without-expat --without-openssl --without-iconv --without-zlib; \
make -j${CPUS}; \
cp ./.libs/libarchive.a $(DEPS_DIR)/libarchive.a;
tgz:
zig build-exe -Drelease-fast --main-pkg-path $(shell pwd) ./misctools/tgz.zig $(DEPS_DIR)/zlib/libz.a $(DEPS_DIR)/libarchive.a $(LIBICONV_PATH) -lc
tgz-debug:
zig build-exe --main-pkg-path $(shell pwd) ./misctools/tgz.zig $(DEPS_DIR)/zlib/libz.a $(DEPS_DIR)/libarchive.a $(LIBICONV_PATH) -lc
vendor: require init-submodules vendor-without-check
zlib:
cd src/deps/zlib; cmake .; make;
require:
@echo "Checking if the required utilities are available..."
@realpath --version >/dev/null 2>&1 || (echo "ERROR: realpath is required."; exit 1)
@cmake --version >/dev/null 2>&1 || (echo "ERROR: cmake is required."; exit 1)
@esbuild --version >/dev/null 2>&1 || (echo "ERROR: esbuild is required."; exit 1)
@npm --version >/dev/null 2>&1 || (echo "ERROR: npm is required."; exit 1)
@aclocal 2>&1 || (echo "ERROR: automake is required. Install on mac with:\nbrew install automake"; exit 1)
@glibtoolize 2>&1 || (echo "ERROR: libtool is required. Install on mac with:\nbrew install libtool"; exit 1)
@stat $(LIBICONV_PATH) >/dev/null 2>&1 || (echo "ERROR: libiconv is required. Please:\nbrew install libiconv"; exit 1)
@stat $(LIBCRYPTO_STATIC_LIB) >/dev/null 2>&1 || (echo "ERROR: OpenSSL 1.1 is required. Please:\nbrew install openssl@1.1"; exit 1)
init-submodules:
git submodule update --init --recursive --progress --depth=1
build-obj:
zig build obj -Drelease-fast
@@ -30,7 +334,12 @@ sign-macos-x64:
sign-macos-aarch64:
gon sign.macos-aarch64.json
release-macos: all-js build-obj jsc-bindings-mac bun-link-lld-release
release: all-js build-obj jsc-bindings-mac bun-link-lld-release
jsc-check:
@ls $(JSC_BASE_DIR) >/dev/null 2>&1 || (echo "Failed to access WebKit build. Please compile the WebKit submodule using the Dockerfile at $(shell pwd)/src/javascript/WebKit/Dockerfile and then copy from /output in the Docker container to $(JSC_BASE_DIR). You can override the directory via JSC_BASE_DIR. \n\n DOCKER_BUILDKIT=1 docker build -t bun-webkit $(shell pwd)/src/javascript/jsc/WebKit -f $(shell pwd)/src/javascript/jsc/WebKit/Dockerfile --progress=plain\n\n docker container create bun-webkit\n\n # Get the container ID\n docker container ls\n\n docker cp DOCKER_CONTAINER_ID_YOU_JUST_FOUND:/output $(JSC_BASE_DIR)" && exit 1)
@ls $(JSC_INCLUDE_DIR) >/dev/null 2>&1 || (echo "Failed to access WebKit include directory at $(JSC_INCLUDE_DIR)." && exit 1)
@ls $(JSC_LIB) >/dev/null 2>&1 || (echo "Failed to access WebKit lib directory at $(JSC_LIB)." && exit 1)
all-js: runtime_js fallback_decoder bun_error node-fallbacks
@@ -52,12 +361,63 @@ runtime_js:
bun_error:
@cd packages/bun-error; npm install; npm run --silent build
JSC_BUILD_STEPS :=
ifeq ($(OS_NAME),linux)
JSC_BUILD_STEPS += jsc-build-linux jsc-copy-headers
endif
fetch:
cd misctools; zig build-obj -Drelease-fast ./fetch.zig -fcompiler-rt -lc --main-pkg-path ../
$(CXX) ./misctools/fetch.o -g -O3 -o ./misctools/fetch $(DEFAULT_LINKER_FLAGS) -lc \
src/deps/mimalloc/libmimalloc.a \
src/deps/zlib/libz.a \
src/deps/libarchive.a \
src/deps/libs2n.a \
src/deps/picohttpparser.o \
$(LIBCRYPTO_STATIC_LIB)
fetch-debug:
cd misctools; zig build-obj ./fetch.zig -fcompiler-rt -lc --main-pkg-path ../
$(CXX) ./misctools/fetch.o -g -o ./misctools/fetch $(DEFAULT_LINKER_FLAGS) -lc \
src/deps/mimalloc/libmimalloc.a \
src/deps/zlib/libz.a \
src/deps/libarchive.a \
src/deps/libs2n.a \
src/deps/picohttpparser.o \
$(LIBCRYPTO_STATIC_LIB)
s2n-mac:
cd $(DEPS_DIR)/s2n-tls; \
make clean; \
CC=$(CC) CXX=$(CXX) cmake . -Bbuild -GNinja \
-DCMAKE_BUILD_TYPE=Release \
-DBUILD_SHARED_LIBS=OFF \
-DLibCrypto_INCLUDE_DIR=$(LIBCRYPTO_INCLUDE_DIR) \
-DLibCrypto_STATIC_LIBRARY=$(LIBCRYPTO_STATIC_LIB) \
-DLibCrypto_LIBRARY=$(LIBCRYPTO_STATIC_LIB) \
-DCMAKE_PREFIX_PATH=$(LIBCRYPTO_PREFIX_DIR); \
CC=$(CC) CXX=$(CXX) cmake --build ./build -j$(CPUS); \
CC=$(CC) CXX=$(CXX) CTEST_PARALLEL_LEVEL=$(CPUS) ninja -C build
cp $(DEPS_DIR)/s2n-tls/build/lib/libs2n.a $(DEPS_DIR)/libs2n.a
unlink $(DEPS_DIR)/libcrypto.a || echo "";
ln $(LIBCRYPTO_STATIC_LIB) $(DEPS_DIR)/libcrypto.a || echo "";
s2n-mac-debug:
cd $(DEPS_DIR)/s2n-tls; \
make clean; \
CC=$(CC) CXX=$(CXX) cmake . -Bbuild -GNinja \
-DCMAKE_BUILD_TYPE=Debug \
-DBUILD_SHARED_LIBS=OFF \
-DLibCrypto_INCLUDE_DIR=$(LIBCRYPTO_INCLUDE_DIR) \
-DLibCrypto_STATIC_LIBRARY=$(LIBCRYPTO_STATIC_LIB) \
-DLibCrypto_LIBRARY=$(LIBCRYPTO_STATIC_LIB) \
-DCMAKE_PREFIX_PATH=$(LIBCRYPTO_PREFIX_DIR); \
CC=$(CC) CXX=$(CXX) cmake --build ./build -j$(CPUS); \
CC=$(CC) CXX=$(CXX) CTEST_PARALLEL_LEVEL=$(CPUS) ninja -C build test
cp $(DEPS_DIR)/s2n-tls/build/lib/libs2n.a $(DEPS_DIR)/libs2n.a
unlink $(DEPS_DIR)/libcrypto.a || echo "";
ln $(LIBCRYPTO_STATIC_LIB) $(DEPS_DIR)/libcrypto.a || echo "";
libcrypto_path:
@echo ${LIBCRYPTO_STATIC_LIB}
ifeq ($(OS_NAME),darwin)
JSC_BUILD_STEPS += jsc-build-mac jsc-copy-headers
s2n: s2n-mac
endif
jsc: jsc-build jsc-bindings
@@ -92,19 +452,32 @@ prepare-release: tag release-create write-package-json-version-cli write-package
release-create:
gh release create --title "Bun v$(PACKAGE_JSON_VERSION)" "$(BUN_BUILD_TAG)"
release-cli-push:
cd packages/bun-cli && npm pack --pack-destination /tmp/
gh release upload $(BUN_BUILD_TAG) --clobber /tmp/bun-cli-$(PACKAGE_JSON_VERSION).tgz
npm publish /tmp/bun-cli-$(PACKAGE_JSON_VERSION).tgz
BUN_DEPLOY_DIR := $(BUN_TMP_DIR)/bun-deploy
BUN_DEPLOY_CLI := $(BUN_TMP_DIR)/bun-cli
BUN_DEPLOY_PKG := $(BUN_DEPLOY_DIR)/$(PACKAGE_NAME)
release-mac-push: write-package-json-version
cd $(PACKAGE_DIR) && npm pack --pack-destination /tmp/
gh release upload $(BUN_BUILD_TAG) --clobber /tmp/bun-cli-$(TRIPLET)-$(PACKAGE_JSON_VERSION).tgz
npm publish /tmp/bun-cli-$(TRIPLET)-$(PACKAGE_JSON_VERSION).tgz
release-cli-push:
rm -rf $(BUN_DEPLOY_CLI)
mkdir -p $(BUN_DEPLOY_CLI)
cp -r packages/bun-cli $(BUN_DEPLOY_CLI)
cd $(BUN_DEPLOY_CLI)/bun-cli; npm pack;
gh release upload $(BUN_BUILD_TAG) --clobber $(BUN_DEPLOY_CLI)//bun-cli/bun-cli-$(PACKAGE_JSON_VERSION).tgz
npm publish $(BUN_DEPLOY_CLI)/bun-cli/bun-cli-$(PACKAGE_JSON_VERSION).tgz --access=public
release-bin-push: write-package-json-version
rm -rf $(BUN_DEPLOY_DIR)
mkdir -p $(BUN_DEPLOY_DIR)
cp -r $(PACKAGE_DIR) $(BUN_DEPLOY_DIR)
cd $(BUN_DEPLOY_PKG); npm pack;
gh release upload $(BUN_BUILD_TAG) --clobber $(BUN_DEPLOY_PKG)/$(PACKAGE_NAME)-$(PACKAGE_JSON_VERSION).tgz
npm publish $(BUN_DEPLOY_PKG)/$(PACKAGE_NAME)-$(PACKAGE_JSON_VERSION).tgz --access=public
dev-obj:
zig build obj
dev-obj-linux:
zig build obj -Dtarget=x86_64-linux-gnu
dev: mkdir-dev dev-obj bun-link-lld-debug
mkdir-dev:
@@ -116,8 +489,8 @@ test-install:
test-all: test-install test-with-hmr test-no-hmr
copy-test-node-modules:
rm -rf integration/snippets/package-json-exports/node_modules
cp -r integration/snippets/package-json-exports/_node_modules_copy integration/snippets/package-json-exports/node_modules
rm -rf integration/snippets/package-json-exports/node_modules || echo "";
cp -r integration/snippets/package-json-exports/_node_modules_copy integration/snippets/package-json-exports/node_modules || echo "";
kill-bun:
-killall -9 bun bun-debug
@@ -141,13 +514,13 @@ test-dev-all: test-dev-with-hmr test-dev-no-hmr
test-dev: test-dev-with-hmr
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 \;
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="$(HOMEBREW_PREFIX)opt/icu4c/include" ./Tools/Scripts/build-jsc --jsc-only --cmakeargs="-DENABLE_STATIC_JSC=ON -DCMAKE_BUILD_TYPE=relwithdebinfo"
jsc-build-linux-compile:
CC=$(CC) CXX=$(CXX) cd src/javascript/jsc/WebKit && ./Tools/Scripts/build-jsc --jsc-only --cmakeargs="-DENABLE_STATIC_JSC=ON -DCMAKE_BUILD_TYPE=relwithdebinfo"
cd src/javascript/jsc/WebKit && ./Tools/Scripts/build-jsc --jsc-only --cmakeargs="-DENABLE_STATIC_JSC=ON -DCMAKE_BUILD_TYPE=relwithdebinfo -DUSE_THIN_ARCHIVES=OFF"
jsc-build-mac: jsc-build-mac-compile jsc-build-mac-copy
@@ -158,81 +531,42 @@ jsc-build-mac-copy:
cp src/javascript/jsc/WebKit/WebKitBuild/Release/lib/libWTF.a src/deps/libWTF.a
cp src/javascript/jsc/WebKit/WebKitBuild/Release/lib/libbmalloc.a src/deps/libbmalloc.a
JSC_FILES := src/deps/libJavaScriptCore.a \
src/deps/libWTF.a \
src/deps/libbmalloc.a
clean-bindings:
rm -rf $(OBJ_DIR)/*.o
clean: clean-bindings
rm src/deps/*.a src/deps/*.o
(cd src/deps/mimalloc && make clean) || echo "";
(cd src/deps/libarchive && make clean) || echo "";
(cd src/deps/s2n-tls && make clean) || echo "";
(cd src/deps/picohttp && make clean) || echo "";
(cd src/deps/zlib && make clean) || echo "";
ifeq ($(OS_NAME),darwin)
HOMEBREW_PREFIX := $(shell brew --prefix)/
endif
SRC_DIR := src/javascript/jsc/bindings
OBJ_DIR := src/javascript/jsc/bindings-obj
SRC_FILES := $(wildcard $(SRC_DIR)/*.cpp)
OBJ_FILES := $(patsubst $(SRC_DIR)/%.cpp,$(OBJ_DIR)/%.o,$(SRC_FILES))
INCLUDE_DIRS := -Isrc/JavaScript/jsc/WebKit/WebKitBuild/Release/JavaScriptCore/PrivateHeaders \
-Isrc/javascript/jsc/WebKit/WebKitBuild/Release/WTF/Headers \
-Isrc/javascript/jsc/WebKit/WebKitBuild/Release/ICU/Headers \
-Isrc/JavaScript/jsc/WebKit/WebKitBuild/Release/ \
-Isrc/JavaScript/jsc/bindings/ \
-Isrc/javascript/jsc/WebKit/Source/bmalloc
CLANG_FLAGS := $(INCLUDE_DIRS) \
-std=gnu++1z \
-stdlib=libc++ \
-DSTATICALLY_LINKED_WITH_JavaScriptCore=1 \
-DSTATICALLY_LINKED_WITH_WTF=1 \
-DBUILDING_WITH_CMAKE=1 \
-DNDEBUG=1 \
-DNOMINMAX \
-DIS_BUILD \
-g \
-DENABLE_INSPECTOR_ALTERNATE_DISPATCHERS=0 \
-DBUILDING_JSCONLY__ \
-DASSERT_ENABLED=0\
-DDU_DISABLE_RENAMING=1
jsc-bindings-mac: $(OBJ_FILES)
MACOS_ICU_FILES := $(HOMEBREW_PREFIX)opt/icu4c/lib/libicudata.a \
$(HOMEBREW_PREFIX)opt/icu4c/lib/libicui18n.a \
$(HOMEBREW_PREFIX)opt/icu4c/lib/libicuuc.a
MACOS_ICU_INCLUDE := $(HOMEBREW_PREFIX)opt/icu4c/include
MACOS_ICU_FLAGS := -l icucore \
$(MACOS_ICU_FILES) \
-I$(MACOS_ICU_INCLUDE)
BUN_LLD_FLAGS := $(OBJ_FILES) \
${MACOS_ICU_FLAGS} \
${JSC_FILES} \
src/deps/picohttpparser.o \
src/deps/mimalloc/libmimalloc.a \
$(CLANG_FLAGS) \
-fpie \
mimalloc:
cd src/deps/mimalloc; cmake .; make;
bun-link-lld-debug:
$(CXX) $(BUN_LLD_FLAGS) \
-g \
$(DEBUG_BIN)/bun-debug.o \
-Wl,-dead_strip \
-ftls-model=local-exec \
-flto \
-o $(DEBUG_BIN)/bun-debug
-W \
-o $(DEBUG_BIN)/bun-debug \
bun-link-lld-release:
$(CXX) $(BUN_LLD_FLAGS) \
$(BIN_DIR)/bun.o \
-o $(BIN_DIR)/bun \
-Wl,-dead_strip \
-ftls-model=local-exec \
-W \
-flto \
-ftls-model=initial-exec \
-O3
cp $(BIN_DIR)/bun $(BIN_DIR)/bun-profile
$(STRIP) $(BIN_DIR)/bun
rm $(BIN_DIR)/bun.o
bun-link-lld-release-aarch64:
@@ -240,7 +574,7 @@ bun-link-lld-release-aarch64:
build/macos-aarch64/bun.o \
-o build/macos-aarch64/bun \
-Wl,-dead_strip \
-ftls-model=local-exec \
-ftls-model=initial-exec \
-flto \
-O3
@@ -252,9 +586,14 @@ $(OBJ_DIR)/%.o: $(SRC_DIR)/%.cpp
-O1
sizegen:
$(CXX) src/javascript/jsc/headergen/sizegen.cpp -o /tmp/sizegen $(CLANG_FLAGS) -O1
/tmp/sizegen > src/javascript/jsc/bindings/sizes.zig
$(CXX) src/javascript/jsc/headergen/sizegen.cpp -o $(BUN_TMP_DIR)/sizegen $(CLANG_FLAGS) -O1
$(BUN_TMP_DIR)/sizegen > src/javascript/jsc/bindings/sizes.zig
picohttp:
$(CC) -O3 -g -c src/deps/picohttpparser.c -Isrc/deps -o src/deps/picohttpparser.o; cd ../../
$(CC) -march=native -O3 -g -fPIE -c src/deps/picohttpparser/picohttpparser.c -Isrc/deps -o src/deps/picohttpparser.o; cd ../../
analytics:
./node_modules/.bin/peechy --schema src/analytics/schema.peechy --zig src/analytics/analytics_schema.zig
analytics-features:
@cd misctools; zig run --main-pkg-path ../ ./features.zig

259
README.md
View File

@@ -18,6 +18,12 @@ All in one fast &amp; easy-to-use tool. Instead of 1,000 node_modules for develo
npm install -g bun-cli
```
## Benchmarks
**CSS**: [Bun is 14x faster](./bench/hot-module-reloading/css-stress-test) than Next.js at hot reloading CSS. TODO: compare Vite
**JavaScript**: TODO
### Getting started
## Using Bun with Next.js
@@ -25,8 +31,8 @@ npm install -g bun-cli
In your project folder root (where `package.json` is):
```bash
npm install -D bun-framework-next
bun bun --use next
bun create next ./app
cd app
bun
```
@@ -71,17 +77,11 @@ If `public/index.html` exists, it becomes the default page instead of a 404 page
#### Using Bun with Create React App
To use Bun with `create-react-app`, there are two changes you will need to make in `public/index.html`:
1. Replace `%PUBLIC_URL%` with `/`
2. Insert `<script type="module" async src="/src/index.js">` just before `</body>`
These changes are (sadly) necessary until Bun supports parsing &amp; transpiling HTML.
In your project folder root (where `package.json` is):
Run this:
```bash
bun bun ./src/index.js
bun create react ./app
cd app
bun
```
@@ -405,7 +405,7 @@ type Router = {
To use a framework, you pass `bun bun --use package-name`.
Your framework's package.json `name` should start with `bun-framework-`. This is so that people can type something like `bun bun --use next` and it will check `bun-framework-next` first. This is similar to how Babel plugins tend to start with `babel-plugin-`.
Your framework's `package.json` `name` should start with `bun-framework-`. This is so that people can type something like `bun bun --use next` and it will check `bun-framework-next` first. This is similar to how Babel plugins tend to start with `babel-plugin-`.
For developing frameworks, you can also do `bun bun --use ./relative-path-to-framework`.
@@ -413,6 +413,170 @@ If you're interested in adding a framework integration, please reach out. There'
# Reference
### `bun create`
`bun create` is a fast way to create a new project from a template.
At the time of writing, `bun create react app` runs ~14x faster on my local computer than `yarn create react-app app`. `bun create` currently does no caching (though your npm client does)
#### Usage
By default, templates are downloaded from folders inside `examples/` in Bun's GitHub repo. Running `bun create react ./local-path` downloads the `react` folder from `examples/react`.
Create a new Next.js project:
```bash
bun create next ./app
```
Create a new React project:
```bash
bun create react ./app
```
To see a list of available templates, run
```bash
bun create
```
Note: you don't need `bun create` to use Bun. You don't need any configuration at all. This command exists to make it a little easier.
##### Local templates
If you have your own boilerplate you prefer using, copy it into `$HOME/.bun-create/my-boilerplate-name`.
Before checking Bun's examples folder, `bun create` checks for a local folder matching the input in:
- `$BUN_CREATE_DIR/`
- `$HOME/.bun-create/`
- `$(pwd)/.bun-create/`
If a folder exists in any of those folders with the input, bun will use that instead of a remote template.
To create a local template, run:
```bash
mkdir -p $HOME/.bun-create/new-template-name
echo '{"name":"new-template-name"}' > $HOME/.bun-create/new-template-name/package.json
```
This lets you run:
```bash
bun create new-template-name ./app
```
Now your new template should appear when you run:
```bash
bun create
```
Warning: unlike with remote templates, **bun will delete the entire destination folder if it already exists.**
##### Flags
| Flag | Description |
| ------------ | -------------------------------------- |
| --npm | Use `npm` for tasks & install |
| --yarn | Use `yarn` for tasks & install |
| --pnpm | Use `pnpm` for tasks & install |
| --force | Overwrite existing files |
| --no-install | Skip installing `node_modules` & tasks |
| --no-git | Don't initialize a git repository |
By default, `bun create` will cancel if there are existing files it would overwrite and its a remote template. You can pass `--force` to disable this behavior.
##### 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.
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.
##### Testing your new template
To test your new template, add it as a local template or pass the absolute path.
```bash
bun create /path/to/my/new/template destination-dir
```
Warning: **This will always delete everything in destination-dir**.
##### Config
The `bun-create` section of `package.json` is automatically removed from the `package.json` on disk. This lets you add create-only steps without waiting for an extra package to install.
There are currently two options:
- `postinstall`
- `preinstall`
They can be an array of strings or one string. An array of steps will be executed in order.
Here is an example:
```json
{
"name": "@bun-examples/next",
"version": "0.0.31",
"main": "index.js",
"dependencies": {
"next": "11.1.2",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"react-is": "^17.0.2"
},
"devDependencies": {
"@types/react": "^17.0.19",
"bun-framework-next": "^0.0.0-21",
"typescript": "^4.3.5"
},
"bun-create": {
"postinstall": ["bun bun --use next"]
}
}
```
By default, all commands run inside the environment exposed by the auto-detected npm client. This incurs a significant performance penalty, something like 150ms spent waiting for the npm client to start on each invocation.
Any command that starts with `"bun "` will be run without npm, relying on the first `bun` binary in `$PATH`.
##### How `bun create` works
When you run `bun create ${template} ${destination}`, here's what happens:
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
ELSE IF local template
1. Open local template folder
2. Delete destination directory recursively
3. Copy files recursively using the fastest system calls available (on macOS `fcopyfile` and Linux, `copy_file_range`). Do not copy or traverse into `node_modules` folder if exists (this alone makes it faster than `cp`)
4. Parse the `package.json` (again!), update `name` to be `${basename(destination)}`, remove the `bun-create` section from the `package.json` and save the updated `package.json` to disk.
5. Auto-detect the npm client, preferring `pnpm`, `yarn` (v1), and lastly `npm`
6. Run any tasks defined in `"bun-create": { "preinstall" }` with the npm client
7. Run `${npmClient} install` unless `--no-install` is passed OR no dependencies are in package.json
8. Run any tasks defined in `"bun-create": { "preinstall" }` 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 roughly 3x slower in microbenchmarks
10. Done
`misctools/publish-examples.js` publishes all examples to npm.
### `bun bun`
Run `bun bun ./path-to.js` to generate a `node_modules.bun` file containing all imported dependencies (recursively).
@@ -516,6 +680,12 @@ Is generated like this:
The implementation details of this module ID hash will vary between versions of Bun. The important part is the metadata contains the module IDs, the package paths, and the package hashes so it shouldn't really matter in practice if other tooling wants to make use of any of this.
### Environment variables
- `GOMAXPROCS`: For `bun bun`, this sets the maximum number of threads to use. If you're experiencing an issue with `bun bun`, try setting `GOMAXPROCS=1` to force bun to run single-threaded
- `DISABLE_BUN_ANALYTICS=1` this disables Bun's analytics. Bun records bundle timings (so we can answer with data, "is bun getting faster?") and feature usage (e.g. "are people actually using macros?"). The request body size is about 60 bytes, so it's not a lot of data
- `TMPDIR`: Before `bun bun` completes, it stores the new `.bun` in `$TMPDIR`. If unset, `TMPDIR` defaults to the platform-specific temporary directory (on Linux, `/tmp` and on macOS `/private/tmp`)
# Credits
- While written in Zig instead of Go, Bun's JS transpiler, CSS lexer, and node module resolver source code is based off of @evanw's esbuild project. @evanw did a fantastic job with esbuild.
@@ -545,6 +715,10 @@ 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
- [`zlib-cloudflare`](https://github.com/cloudflare/zlib), which is zlib licensed
- [`s2n-tls`](https://github.com/aws/s2n-tls), which is MIT licensed
- [`libarchive`](https://github.com/libarchive/libarchive), which has [several licenses](https://github.com/libarchive/libarchive/blob/master/COPYING)
- [`libiconv`](https://www.gnu.org/software/libiconv/), which is LGPL2. It's a dependency of libarchive.
For compatibiltiy reasons, these NPM packages are embedded into Bun's binary and injected if imported.
@@ -574,6 +748,8 @@ For compatibiltiy reasons, these NPM packages are embedded into Bun's binary and
Estimated: 30-90 minutes :(
## macOS
Compile Zig:
```bash
@@ -590,11 +766,64 @@ In `bun`:
```bash
git submodule update --init --recursive --progress --depth=1
make vendor
zig build headers
make jsc-bindings-mac
zig build -Drelease-fast
```
Note that `brew install zig` won't work. Bun uses a build of Zig with a couple patches.
Additionally, you'll need `cmake`, `npm` and `esbuild` installed globally.
## Linux
A Dockerfile with the exact version of Zig used is availble at `Dockerfile.zig`. This installs all the system dependencies you'll need excluding JavaScriptCore, but doesn't currently compile Bun in one command. If you're having trouble compiling Zig, it might be helpful to look at.
Compile Zig:
```bash
git clone https://github.com/jarred-sumner/zig --depth=1
cd zig
git checkout jarred/zig-sloppy-with-small-structs
cmake . -DCMAKE_BUILD_TYPE=Release && make -j $(nproc)
```
Compile JavaScriptCore:
```bash
# This will take a few minutes, depending on how fast your internet is
git submodule update --init --recursive --progress --depth=1
# This will take 10-30 minutes, depending on how many cores your CPU has
DOCKER_BUILDKIT=1 docker build -t bun-webkit $(pwd)/src/javascript/jsc/WebKit -f $(pwd)/src/javascript/jsc/WebKit/Dockerfile --progress=plain
docker container create bun-webkit
# Find the docker container ID manually. If you know a better way, please submit a PR!
docker container ls
docker cp DOCKER_CONTAINER_ID_YOU_JUST_FOUND:/output $HOME/webkit-build
```
Compile Bun:
```bash
make vendor dev
```
Run bun:
```bash
packages/debug-bun-cli-darwin-x64/bin/bun-debug
```
## vscode-zig
You will want to install the fork of `vscode-zig` so you get a `Run test` and a `Debug test` button.
To do that:
```bash
git clone https://github.com/jarred-sumner/vscode-zig
cd vscode-zig
yarn install
yarn vsce package && code --install-extension ./zig-0.2.5.vsix
```
<a target="_blank" href="https://github.com/jarred-sumner/vscode-zig"><img src="https://pbs.twimg.com/media/FBZsKHlUcAYDzm5?format=jpg&name=large"></a>

View File

@@ -0,0 +1,5 @@
bun
next
src/*.mov
src/*.blob

View File

@@ -0,0 +1,77 @@
SLEEP_INTERVAL ?= 32
SCREEN_WIDTH ?= $(shell system_profiler -json SPDisplaysDataType 2>/dev/null | jq -r '.. | objects | select(.spdisplays_main) | ._spdisplays_pixels | split(" ")[0]')
SCREEN_HEIGHT ?= $(shell system_profiler -json SPDisplaysDataType 2>/dev/null | jq -r '.. | objects | select(.spdisplays_main) | ._spdisplays_pixels | split(" ")[2]')
PROJECT ?= bun
PACKAGE_NAME ?= bun-cli
RUN_COUNT ?= 128
ENDPOINT ?= /
ifeq ($(PROJECT),bun)
PACKAGE_NAME := bun-cli
endif
ifeq ($(PROJECT),next)
PACKAGE_NAME := next
endif
generate:
@killall -9 bun next node || echo ""
PROJECT=$(PROJECT) SCREEN_WIDTH=$(SCREEN_WIDTH) SCREEN_HEIGHT=$(SCREEN_HEIGHT) ENDPOINT=$(ENDPOINT) node browser.js
generate-css-in-js:
@killall -9 bun next node || echo ""
PROJECT=$(PROJECT) SCREEN_WIDTH=$(SCREEN_WIDTH) SCREEN_HEIGHT=$(SCREEN_HEIGHT) ENDPOINT=/css-in-js node browser.js
loop:
cp src/colors.css.0 src/colors.css
sleep 3
osascript -e 'tell application "System Events" to tell process "Chromium"' \
-e 'set frontmost to true' \
-e 'if windows is not {} then perform action "AXRaise" of item 1 of windows' \
-e 'end tell'
sleep 0.5
cd src; zig run -Drelease-fast ../color-looper.zig -- ./colors.css:0 $(SLEEP_INTERVAL)
cp src/colors.css.blob $(PROJECT)/colors.css.blob
loop-emotion:
cp src/css-in-js-styles.0 src/css-in-js-styles.tsx
sleep 3
osascript -e 'tell application "System Events" to tell process "Chromium"' \
-e 'set frontmost to true' \
-e 'if windows is not {} then perform action "AXRaise" of item 1 of windows' \
-e 'end tell'
sleep 0.5
cd src; zig run -Drelease-fast ../color-looper.emotion.zig -- ./css-in-js-styles.tsx:0 $(SLEEP_INTERVAL)
cp src/css-in-js-styles.tsx.blob $(PROJECT)/css-in-js-styles.blob
process_video:
rm -rf $(FRAMES_DIR); mkdir -p $(FRAMES_DIR); ffmpeg -i src/colors.css.mov -vf fps=120,format=gray $(FRAMES_DIR)/%d.tif
FRAMES_DIR ?= $(shell mkdir -p ./$(PROJECT)/frames; realpath ./$(PROJECT)/frames)
TIF_FILES := $(wildcard $(FRAMES_DIR)/*.tif)
TXT_FILES := $(wildcard $(FRAMES_DIR)/*.txt)
OBJ_FILES := $(patsubst $(SRC_DIR)/%.tif,$(OBJ_DIR)/%.txt,$(TIF_FILES))
TRIM_FILES := $(patsubst $(SRC_DIR)/%.txt,$(OBJ_DIR)/%.trim,$(TXT_FILES))
frames: $(OBJ_FILES)
$(FRAMES_DIR)/%.txt: $(FRAMES_DIR)/%.tif
tesseract -l eng $< $@
trim: $(TRIM_FILES) cleanup print
$(FRAMES_DIR)/%.trim: $(FRAMES_DIR)/%.txt
(grep "Ran:" $< || echo "\n") >> $(PROJECT)/frames.all
cleanup:
sed 's/^Ran: *//' $(PROJECT)/frames.all | tr -d ' ' | sort | uniq > $(PROJECT)/frames.all.clean
print:
PACKAGE_NAME=$(PACKAGE_NAME) SLEEP_INTERVAL=$(SLEEP_INTERVAL) PROJECT=$(PROJECT) OUTFILE=timings/$(PACKAGE_NAME) node read-frames.js
print-emotion:
PACKAGE_NAME=$(PACKAGE_NAME) SLEEP_INTERVAL=$(SLEEP_INTERVAL) PROJECT=$(PROJECT) OUTFILE=timings/emotion_$(PACKAGE_NAME) node read-frames.js

View File

@@ -0,0 +1,62 @@
# CSS Stress Test
This benchmarks bundler performance for CSS hot reloading.
## Results
Bun is 14x faster than Next.js at hot reloading CSS.
```
Bun v0.0.34
Saving every 16ms
Frame time:
50th percentile: 22.2ms
75th percentile: 23.9ms
90th percentile: 25.3ms
95th percentile: 43.6ms
99th percentile: 49.1ms
Rendered frames: 922 / 1024 (90%)
```
```
Next.js v11.1.2
Saving every 16ms
Frame time:
50th percentile: 312ms
75th percentile: 337.6ms
90th percentile: 387.7ms
95th percentile: 446.9ms
99th percentile: 591.7ms
Rendered frames: 64 / 1024 (6%)
```
## How it works
It times pixels instead of builds. `color-looper.zig` writes color updates and the timestamp to a css file, while simultaneously screen recording a non-headless Chromium instance. After it finishes, it OCRs the video frames and verifies the scanned timestamps against the actual data. This data measures (1) how long each update took from saving to disk up to the pixels visible on the screen and (2) what % of frames were rendered.
The intent is to be as accurate as possible. Measuring times reported client-side is simpler, but lower accuracy since those times may not correspond to pixels on the screen and do not start from when the data was written to disk (at best, they measure when the filesystem watcher detected the update, but often not that either). `color-looper.zig` must run separately from `browser.js` or the results will be innaccurate.
It works like this:
1. `browser.js` loads either Bun or Next.js and a Chromium instance opened to the correct webpage
2. `color-looper.zig` updates [`./src/colors.css`](./src/colors.css) in a loop up to `1024` times (1024 is arbitrary), sleeping every `16`ms or `32`ms (a CLI arg you can pass it). The `var(--timestamp)` CSS variable contains the UTC timestamp with precision of milliseconds and one extra decimal point
3. `color-looper.zig` automatically records the screen via `screencapture` (builtin on macOS) and saves it, along with a `BigUint64Array` containing all the expected timestamps. When it's done, it writes to a designated file on disk which `browser.js` picks up as the signal to close the browser.
4. `ffmpeg` converts each frame into a black and white `.tif` file, which `tesseract` then OCRs
5. Various cleanup scripts extract the timestamp from each of those OCR'd frames into a single file
6. Using the OCR'd data, `./read-frames.js` calculates the 50th, 75th, 90th, 95th, and 99th percentile frame time, along with how many frames were skipped. Frame time is the metric here that matters here because that's how much time elapsed between each update. It includes the artificial sleep interval, so it will not be faster than the sleep interval.
The script `run.sh` runs all the commands necessary to do this work unattended. It takes awhile though. The slow part is OCR'ing all the frames.
To run this, you need:
- `zig`
- `bun-cli`
- `node`
- `tesseract`
- `screencapture` (macOS builtin)
- `ffmpeg`
- `puppeteer` (from the package.json)
You will need to run `bun bun --use next` first, with `next@11.1.2`. It will only run on macOS due to the dependencies on `screencapture`, how it detects screen resolution (so that Chromium is maximized), and how it auto-focuses Chromium (apple script)

View File

@@ -0,0 +1,118 @@
const puppeteer = require("puppeteer");
const http = require("http");
const path = require("path");
const url = require("url");
const fs = require("fs");
const child_process = require("child_process");
const serverURL = process.env.TEST_SERVER_URL || "http://localhost:8080";
if (process.env.PROJECT === "bun") {
const bunFlags = [`--origin=${serverURL}`].filter(Boolean);
const bunExec = process.env.BUN_BIN || "bun";
const bunProcess = child_process.spawn(bunExec, bunFlags, {
cwd: process.cwd(),
stdio: "ignore",
env: {
...process.env,
DISABLE_BUN_ANALYTICS: "1",
},
shell: false,
});
console.log("$", bunExec, bunFlags.join(" "));
const isDebug = bunExec.endsWith("-debug");
// bunProcess.stderr.pipe(process.stderr);
// bunProcess.stdout.pipe(process.stdout);
bunProcess.once("error", (err) => {
console.error("❌ bun error", err);
process.exit(1);
});
process.on("beforeExit", () => {
bunProcess?.kill(0);
});
} else if (process.env.PROJECT === "next") {
const bunProcess = child_process.spawn(
"./node_modules/.bin/next",
["--port", "8080"],
{
cwd: process.cwd(),
stdio: "ignore",
env: {
...process.env,
},
shell: false,
}
);
}
const delay = new Promise((resolve, reject) => {
const watcher = fs.watch(path.resolve(process.cwd(), "src/colors.css.blob"));
watcher.once("change", () => {
setTimeout(() => {
resolve();
}, 1000);
});
});
async function main() {
const browser = await puppeteer.launch({
headless: false,
waitForInitialPage: true,
args: [
`--window-size=${parseInt(process.env.SCREEN_WIDTH || "1024", 10) / 2},${
parseInt(process.env.SCREEN_HEIGHT || "1024", 10) / 2
}`,
],
defaultViewport: {
width: parseInt(process.env.SCREEN_WIDTH || "1024", 10) / 2,
height: parseInt(process.env.SCREEN_HEIGHT || "1024", 10) / 2,
},
});
const promises = [];
let allTestsPassed = true;
async function runPage(key) {
var page;
try {
console.log("Opening page");
page = await browser.newPage();
console.log(`Navigating to "http://localhost:8080/"`);
while (true) {
try {
await page.goto("http://localhost:8080/", { waitUntil: "load" });
break;
} catch (exception) {
if (!exception.toString().includes("ERR_CONNECTION_REFUSED")) break;
}
}
await page.bringToFront();
await delay;
// runner.stdout.pipe(process.stdout);
// runner.stderr.pipe(process.stderr);
var didResolve = false;
console.log(`Completed. Done.`);
} catch (error) {
console.error(error);
} finally {
await page.close();
await browser.close();
}
}
return runPage();
}
main().catch((error) =>
setTimeout(() => {
throw error;
})
);

View File

@@ -0,0 +1,11 @@
SLEEP_INTERVAL=16 PROJECT=bun node read-frames.js
bun
--------------------------------------------------
CSS HMR FRAME TIME
50th percentile: 22.2ms
75th percentile: 23.9ms
90th percentile: 25.3ms
95th percentile: 43.6ms
99th percentile: 49.1ms
Rendered frames: 922 / 1024 (90%)

View File

@@ -0,0 +1,11 @@
SLEEP_INTERVAL=24 PROJECT=bun node read-frames.js
bun
--------------------------------------------------
CSS HMR FRAME TIME
50th percentile: 33.4ms
75th percentile: 34.5ms
90th percentile: 35.8ms
95th percentile: 65.5ms
99th percentile: 87.9ms
Rendered frames: 937 / 1024 (92%)

View File

@@ -0,0 +1,11 @@
SLEEP_INTERVAL=32 PROJECT=bun node read-frames.js
bun
--------------------------------------------------
CSS HMR FRAME TIME
50th percentile: 40.7ms
75th percentile: 42.3ms
90th percentile: 43.5ms
95th percentile: 76.4ms
99th percentile: 118.8ms
Rendered frames: 958 / 1024 (94%)

View File

@@ -0,0 +1,11 @@
SLEEP_INTERVAL=8 PROJECT=bun node read-frames.js
bun
--------------------------------------------------
CSS HMR FRAME TIME
50th percentile: 20ms
75th percentile: 24.4ms
90th percentile: 41ms
95th percentile: 53.9ms
99th percentile: 90.4ms
Rendered frames: 475 / 1024 (46%)

View File

@@ -0,0 +1,218 @@
const std = @import("std");
pub const Counter = extern struct {
timestamp: usize,
percent: f64,
rotate: u32,
color_values: [8 * 3]u32,
};
const RUN_COUNT = 1024;
var counters: [RUN_COUNT]Counter = undefined;
pub const Blob = extern struct {
run_count: u32,
interval: u64,
};
pub var all_timestamps: [RUN_COUNT + 1]usize = undefined;
// usage:
// ./file-path:0 10
// 1 2 3
// 1. file path
// 2. Byte offset in file
// 3. ms update interval
var color_buf: [8096 + SIMULATE_LONG_FILE.len]u8 = undefined;
pub fn main() anyerror!void {
var allocator = std.heap.c_allocator;
var timer = try std.time.Timer.start();
var args = std.mem.span(try std.process.argsAlloc(allocator));
var basepath_with_colon: []u8 = args[args.len - 2];
var basepath: []u8 = "";
var position_str: []u8 = "";
if (std.mem.lastIndexOfScalar(u8, basepath_with_colon, ':')) |colon| {
basepath = basepath_with_colon[0..colon];
position_str = basepath_with_colon[colon + 1 ..];
}
var position = try std.fmt.parseInt(u32, position_str, 10);
const filepath = try std.fs.path.resolve(allocator, &.{basepath});
var file = try std.fs.openFileAbsolute(filepath, .{ .write = true });
var ms = @truncate(u64, (try std.fmt.parseInt(u128, args[args.len - 1], 10)) * std.time.ns_per_ms);
std.debug.assert(ms > 0);
// std.debug.assert(std.math.isFinite(position));
var prng = std.rand.DefaultPrng.init(0);
var stdout = std.io.getStdOut();
var log = stdout.writer();
var colors = std.mem.zeroes([4][3]u32);
var progress_bar: f64 = 0.0;
var destination_count: f64 = 18.0;
// Randomize initial colors
colors[0][0] = prng.random.int(u32);
colors[0][1] = prng.random.int(u32);
colors[0][2] = prng.random.int(u32);
colors[1][0] = prng.random.int(u32);
colors[1][1] = prng.random.int(u32);
colors[1][2] = prng.random.int(u32);
colors[2][0] = prng.random.int(u32);
colors[2][1] = prng.random.int(u32);
colors[2][2] = prng.random.int(u32);
colors[3][0] = prng.random.int(u32);
colors[3][1] = prng.random.int(u32);
colors[3][2] = prng.random.int(u32);
var rotate: u32 = 0;
var counter: usize = 0;
const video = std.fmt.allocPrint(allocator, "{s}.mov", .{filepath}) catch unreachable;
std.fs.deleteFileAbsolute(video) catch {};
var screen_recorder_argv = [_][]const u8{ "screencapture", "-v", video };
var recorder = try std.ChildProcess.init(&screen_recorder_argv, allocator);
recorder.stdin_behavior = .Pipe;
try recorder.spawn();
std.time.sleep(std.time.ns_per_s);
var wrote: []u8 = undefined;
while (counter < RUN_COUNT) {
colors[0][0] += 1;
colors[0][1] += 1;
colors[0][2] += 1;
colors[1][0] += 1;
colors[1][1] += 1;
colors[1][2] += 1;
colors[2][0] += 1;
colors[2][1] += 1;
colors[2][2] += 1;
colors[3][0] += 1;
colors[3][1] += 1;
colors[3][2] += 1;
rotate += 1;
const fmtd: []const u8 = comptime brk: {
break :brk (
\\
\\import {{ Global }} from "@emotion/react";
\\export function CSSInJSStyles() {{
\\ return (
\\ <Global
\\ styles={{`
\\:root {{
\\ --timestamp: "{d}";
\\ --interval: "{s}";
\\ --progress-bar: {d}%;
\\ --spinner-1-muted: rgb({d}, {d}, {d});
\\ --spinner-1-primary: rgb({d}, {d}, {d});
\\ --spinner-2-muted: rgb({d}, {d}, {d});
\\ --spinner-2-primary: rgb({d}, {d}, {d});
\\ --spinner-3-muted: rgb({d}, {d}, {d});
\\ --spinner-3-primary: rgb({d}, {d}, {d});
\\ --spinner-4-muted: rgb({d}, {d}, {d});
\\ --spinner-4-primary: rgb({d}, {d}, {d});
\\ --spinner-rotate: {d}deg;
\\}}
++ SIMULATE_LONG_FILE ++
\\ `}}
\\ />
\\ );
\\}}
\\
);
};
counters[counter].timestamp = @truncate(u64, @intCast(u128, std.time.nanoTimestamp()) / (std.time.ns_per_ms / 10));
counters[counter].rotate = rotate % 360;
counters[counter].percent = std.math.mod(f64, std.math.round(((progress_bar + 1.0) / destination_count) * 1000) / 1000, 100) catch 0;
counters[counter].color_values[0] = @floatToInt(u32, std.math.round(@intToFloat(f64, ((colors[0][0] + 1) % 256)) * 0.8));
counters[counter].color_values[1] = @floatToInt(u32, std.math.round(@intToFloat(f64, ((colors[0][1] + 1) % 256)) * 0.8));
counters[counter].color_values[2] = @floatToInt(u32, std.math.round(@intToFloat(f64, ((colors[0][2] + 1) % 256)) * 0.8));
counters[counter].color_values[3] = (colors[0][0] + 1) % 256;
counters[counter].color_values[4] = (colors[0][1] + 1) % 256;
counters[counter].color_values[5] = (colors[0][2] + 1) % 256;
counters[counter].color_values[6] = @floatToInt(u32, std.math.round(@intToFloat(f64, ((colors[1][0] + 1) % 256)) * 0.8));
counters[counter].color_values[7] = @floatToInt(u32, std.math.round(@intToFloat(f64, ((colors[1][1] + 1) % 256)) * 0.8));
counters[counter].color_values[8] = @floatToInt(u32, std.math.round(@intToFloat(f64, ((colors[1][2] + 1) % 256)) * 0.8));
counters[counter].color_values[9] = (colors[1][0] + 1) % 256;
counters[counter].color_values[10] = (colors[1][1] + 1) % 256;
counters[counter].color_values[11] = (colors[1][2] + 1) % 256;
counters[counter].color_values[12] = @floatToInt(u32, std.math.round(@intToFloat(f64, ((colors[2][0] + 1) % 256)) * 0.8));
counters[counter].color_values[13] = @floatToInt(u32, std.math.round(@intToFloat(f64, ((colors[2][1] + 1) % 256)) * 0.8));
counters[counter].color_values[14] = @floatToInt(u32, std.math.round(@intToFloat(f64, ((colors[2][2] + 1) % 256)) * 0.8));
counters[counter].color_values[15] = (colors[2][0] + 1) % 256;
counters[counter].color_values[16] = (colors[2][1] + 1) % 256;
counters[counter].color_values[17] = (colors[2][2] + 1) % 256;
counters[counter].color_values[18] = @floatToInt(u32, std.math.round(@intToFloat(f64, ((colors[3][0] + 1) % 256)) * 0.8));
counters[counter].color_values[19] = @floatToInt(u32, std.math.round(@intToFloat(f64, ((colors[3][1] + 1) % 256)) * 0.8));
counters[counter].color_values[20] = @floatToInt(u32, std.math.round(@intToFloat(f64, ((colors[3][2] + 1) % 256)) * 0.8));
counters[counter].color_values[21] = (colors[3][0] + 1) % 256;
counters[counter].color_values[22] = (colors[3][1] + 1) % 256;
counters[counter].color_values[23] = (colors[3][2] + 1) % 256;
file = try std.fs.createFileAbsolute(filepath, .{ .truncate = true });
wrote = try std.fmt.bufPrint(&color_buf, fmtd, .{
counters[counter].timestamp,
args[args.len - 1],
counters[counter].percent,
counters[counter].color_values[0],
counters[counter].color_values[1],
counters[counter].color_values[2],
counters[counter].color_values[3],
counters[counter].color_values[4],
counters[counter].color_values[5],
counters[counter].color_values[6],
counters[counter].color_values[7],
counters[counter].color_values[8],
counters[counter].color_values[9],
counters[counter].color_values[10],
counters[counter].color_values[11],
counters[counter].color_values[12],
counters[counter].color_values[13],
counters[counter].color_values[14],
counters[counter].color_values[15],
counters[counter].color_values[16],
counters[counter].color_values[17],
counters[counter].color_values[18],
counters[counter].color_values[19],
counters[counter].color_values[20],
counters[counter].color_values[21],
counters[counter].color_values[22],
counters[counter].color_values[23],
counters[counter].rotate,
});
progress_bar += 1.0;
_ = try file.writeAll(wrote);
try log.print("[{d}] \"{s}\":{d}\n", .{
std.time.nanoTimestamp(),
filepath,
position,
});
counter += 1;
// If we don't close the file, Parcel seems to never recognize it
file.close();
std.time.sleep(ms);
}
try recorder.stdin.?.writeAll(&[_]u8{ 3, ';' });
_ = try recorder.wait();
all_timestamps[0] = wrote.len;
for (counters) |count, i| {
all_timestamps[i + 1] = count.timestamp;
}
std.time.sleep(std.time.ns_per_s);
var blob_file = try std.fs.createFileAbsolute(std.fmt.allocPrint(std.heap.c_allocator, "{s}.blob", .{filepath}) catch unreachable, .{ .truncate = true });
try blob_file.writeAll(std.mem.asBytes(&all_timestamps));
blob_file.close();
}
const SIMULATE_LONG_FILE =
\\
;

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,5 @@
module.exports = {
experimental: {
swcLoader: true,
},
};

View File

@@ -0,0 +1,11 @@
SLEEP_INTERVAL=16 PROJECT=next node read-frames.js
next
--------------------------------------------------
CSS HMR FRAME TIME
50th percentile: 312ms
75th percentile: 337.6ms
90th percentile: 387.7ms
95th percentile: 446.9ms
99th percentile: 591.7ms
Rendered frames: 64 / 1024 (6%)

View File

@@ -0,0 +1,11 @@
SLEEP_INTERVAL=24 PROJECT=next node read-frames.js
next
--------------------------------------------------
CSS HMR FRAME TIME
50th percentile: 310.1ms
75th percentile: 360.3ms
90th percentile: 461.6ms
95th percentile: 660.4ms
99th percentile: 1009.9ms
Rendered frames: 78 / 1024 (8%)

View File

@@ -0,0 +1,11 @@
SLEEP_INTERVAL=32 PROJECT=next node read-frames.js
next
--------------------------------------------------
CSS HMR FRAME TIME
50th percentile: 306.7ms
75th percentile: 324.7ms
90th percentile: 380ms
95th percentile: 483.6ms
99th percentile: 933.6ms
Rendered frames: 116 / 1024 (11%)

View File

@@ -0,0 +1,11 @@
SLEEP_INTERVAL=8 PROJECT=next node read-frames.js
next
--------------------------------------------------
CSS HMR FRAME TIME
50th percentile: 320.4ms
75th percentile: 368.8ms
90th percentile: 527.2ms
95th percentile: 532.4ms
99th percentile: 532.4ms
Rendered frames: 32 / 1024 (3%)

View File

@@ -3,13 +3,19 @@
"version": "1.0.0",
"license": "MIT",
"dependencies": {
"@emotion/core": "^11.0.0",
"@emotion/css": "^11.1.3",
"@emotion/react": "^11.4.1",
"@vitejs/plugin-react-refresh": "^1.3.3",
"antd": "^4.16.1",
"bun-framework-next": "^0.0.0-21",
"left-pad": "^1.3.0",
"next": "^11.0.1",
"next": "canary",
"parcel": "2.0.0-beta.3",
"path-browserify": "^1.0.1",
"percentile": "^1.5.0",
"puppeteer": "^10.4.0",
"puppeteer-video-recorder": "^1.0.5",
"react": "^17.0.2",
"react-bootstrap": "^1.6.1",
"react-dom": "^17.0.2",
@@ -32,6 +38,7 @@
"devDependencies": {
"@microsoft/fetch-event-source": "^2.0.1",
"@snowpack/plugin-react-refresh": "^2.5.0",
"bun-cli": "^0.0.34",
"typescript": "^4.3.4"
}
}

View File

@@ -1,4 +1,4 @@
// import "../src/index.css";
import "../src/index.css";
import App from "next/app";

View File

@@ -0,0 +1,19 @@
import { CSSInJSStyles } from "src/css-in-js-styles";
import { Main } from "src/main";
export function CSSInJS() {
return (
<>
<CSSInJSStyles />
<Main
productName={
typeof location !== "undefined"
? decodeURIComponent(location.search.substring(1))
: ""
}
cssInJS="Emotion"
/>
</>
);
}
export default CSSInJS;

View File

@@ -0,0 +1,12 @@
import { Main } from "src/main";
export function IndexPage() {
return (
<Main
productName={
typeof location !== "undefined" ? location.search.substring(1) : ""
}
/>
);
}
export default IndexPage;

View File

@@ -0,0 +1,107 @@
const fs = require("fs");
const path = require("path");
const PROJECT = process.env.PROJECT || "bun";
const percentile = require("percentile");
const PACKAGE_NAME = process.env.PACKAGE_NAME;
const label = `${PACKAGE_NAME}@${
require(PACKAGE_NAME + "/package.json").version
}`;
const BASEFOLDER = path.resolve(PROJECT);
const OUTFILE = path.join(process.cwd(), process.env.OUTFILE);
const buf = fs.readFileSync(BASEFOLDER + "/colors.css.blob");
const VALID_TIMES = new BigUint64Array(buf.buffer).subarray(1);
const cssFileSize = new BigUint64Array(buf.buffer)[0];
const TOTAL_FRAMES = VALID_TIMES.length;
const timings = fs
.readFileSync(BASEFOLDER + "/frames.all.clean", "utf8")
.split("\n")
.map((a) => a.replace(/[Ran:'\.]?/gm, "").trim())
.filter((a) => parseInt(a, 10))
.filter((a) => a.length > 0 && VALID_TIMES.includes(BigInt(parseInt(a, 10))))
.map((num) => BigInt(num));
timings.sort();
const frameTimesCount = timings.length;
var frameTime = new Array(Math.floor(frameTimesCount / 2));
for (let i = 0; i < frameTime.length; i++) {
const i1 = i * 2;
const i2 = i * 2 + 1;
frameTime[i] = Math.max(Number(timings[i2] - timings[i1]), 0);
}
const report = {
label,
cssFileSize: Number(cssFileSize),
at: new Date().toISOString(),
sleep: process.env.SLEEP_INTERVAL,
package: {
name: PACKAGE_NAME,
version: require(PACKAGE_NAME + "/package.json").version,
},
timestamps: timings.map((a) => Number(a)),
frameTimes: frameTime,
percentileMs: {
50: percentile(50, frameTime) / 10,
75: percentile(75, frameTime) / 10,
90: percentile(90, frameTime) / 10,
95: percentile(95, frameTime) / 10,
99: percentile(99, frameTime) / 10,
},
};
fs.writeFileSync(
path.join(
path.dirname(OUTFILE),
path.basename(OUTFILE) +
"@" +
report.package.version +
"." +
process.env.SLEEP_INTERVAL +
"ms." +
`${process.platform}-${
process.arch === "arm64" ? "aarch64" : process.arch
}` +
".json"
),
JSON.stringify(report, null, 2)
);
console.log(
label + "\n",
"-".repeat(50) + "\n",
"CSS HMR FRAME TIME\n" + "\n",
"50th percentile:",
percentile(50, frameTime) / 10 + "ms",
"\n",
"75th percentile:",
percentile(75, frameTime) / 10 + "ms",
"\n",
"90th percentile:",
percentile(90, frameTime) / 10 + "ms",
"\n",
"95th percentile:",
percentile(95, frameTime) / 10 + "ms",
"\n",
"99th percentile:",
percentile(99, frameTime) / 10 + "ms",
"\n",
"Rendered frames:",
timings.length,
"/",
TOTAL_FRAMES,
"(" +
Math.round(
Math.max(Math.min(1.0, timings.length / TOTAL_FRAMES), 0) * 100
) +
"%)"
);

View File

@@ -0,0 +1,83 @@
#!/bin/bash
echo "Running next at 24ms"
PROJECT=next SLEEP_INTERVAL=24 make generate &
PROJECT=next SLEEP_INTERVAL=24 make loop
killall Chromium || echo "";
PROJECT=next SLEEP_INTERVAL=24 make process_video
PROJECT=next SLEEP_INTERVAL=24 make frames -j$(nproc)
PROJECT=next SLEEP_INTERVAL=24 make trim
cp src/colors.css.blob next/colors.css.blob
PROJECT=next SLEEP_INTERVAL=24 make print > "next.latest.24ms.txt"
echo "Running bun at 24ms"
PROJECT=bun SLEEP_INTERVAL=24 make generate &
PROJECT=bun SLEEP_INTERVAL=24 make loop
killall Chromium || echo "";
PROJECT=bun SLEEP_INTERVAL=24 make process_video
PROJECT=bun SLEEP_INTERVAL=24 make frames -j$(nproc)
PROJECT=bun SLEEP_INTERVAL=24 make trim
cp src/colors.css.blob bun/colors.css.blob
PROJECT=bun SLEEP_INTERVAL=24 make print > "bun.latest.24ms.txt"
echo "Running next at 16ms"
PROJECT=next SLEEP_INTERVAL=16 make generate &
PROJECT=next SLEEP_INTERVAL=16 make loop
killall Chromium || echo "";
PROJECT=next SLEEP_INTERVAL=16 make process_video
PROJECT=next SLEEP_INTERVAL=16 make frames -j$(nproc)
PROJECT=next SLEEP_INTERVAL=16 make trim
cp src/colors.css.blob next/colors.css.blob
PROJECT=next SLEEP_INTERVAL=16 make print > "next.latest.16ms.txt"
echo "Running bun at 16ms"
PROJECT=bun SLEEP_INTERVAL=16 make generate &
PROJECT=bun SLEEP_INTERVAL=16 make loop
killall Chromium || echo "";
PROJECT=bun SLEEP_INTERVAL=16 make process_video
PROJECT=bun SLEEP_INTERVAL=16 make frames -j$(nproc)
PROJECT=bun SLEEP_INTERVAL=16 make trim
cp src/colors.css.blob bun/colors.css.blob
PROJECT=bun SLEEP_INTERVAL=16 make print > "bun.latest.16ms.txt"
echo "Running bun at 8ms"
PROJECT=bun SLEEP_INTERVAL=8 make generate &
PROJECT=bun SLEEP_INTERVAL=8 make loop
killall Chromium || echo "";
PROJECT=bun SLEEP_INTERVAL=8 make process_video
PROJECT=bun SLEEP_INTERVAL=8 make frames -j$(nproc)
PROJECT=bun SLEEP_INTERVAL=8 make trim
cp src/colors.css.blob bun/colors.css.blob
PROJECT=bun SLEEP_INTERVAL=8 make print > "bun.latest.8ms.txt"
echo "Running next at 8ms"
PROJECT=next SLEEP_INTERVAL=8 make generate &
PROJECT=next SLEEP_INTERVAL=8 make loop
killall Chromium || echo "";
PROJECT=next SLEEP_INTERVAL=8 make process_video
PROJECT=next SLEEP_INTERVAL=8 make frames -j$(nproc)
PROJECT=next SLEEP_INTERVAL=8 make trim
cp src/colors.css.blob next/colors.css.blob
PROJECT=next SLEEP_INTERVAL=8 make print > "next.latest.8ms.txt"
echo "Running bun at 32ms"
PROJECT=bun SLEEP_INTERVAL=32 make generate &
PROJECT=bun SLEEP_INTERVAL=32 make loop
killall Chromium || echo "";
PROJECT=bun SLEEP_INTERVAL=32 make process_video
PROJECT=bun SLEEP_INTERVAL=32 make frames -j$(nproc)
PROJECT=bun SLEEP_INTERVAL=32 make trim
cp src/colors.css.blob bun/colors.css.blob
PROJECT=bun SLEEP_INTERVAL=32 make print > "bun.latest.32ms.txt"
echo "Running next at 32ms"
PROJECT=next SLEEP_INTERVAL=32 make generate &
PROJECT=next SLEEP_INTERVAL=32 make loop
killall Chromium || echo "";
PROJECT=next SLEEP_INTERVAL=32 make process_video
PROJECT=next SLEEP_INTERVAL=32 make frames -j$(nproc)
PROJECT=next SLEEP_INTERVAL=32 make trim
cp src/colors.css.blob next/colors.css.blob
PROJECT=next SLEEP_INTERVAL=32 make print > "next.latest.32ms.txt"

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,14 @@
:root {
--timestamp: "0";
--interval: "8";
--progress-bar: 0%;
--spinner-1-muted: rgb(179, 6, 202);
--spinner-1-primary: rgb(224, 8, 253);
--spinner-2-muted: rgb(22, 188, 124);
--spinner-2-primary: rgb(27, 235, 155);
--spinner-3-muted: rgb(89, 72, 0);
--spinner-3-primary: rgb(111, 90, 0);
--spinner-4-muted: rgb(18, 84, 202);
--spinner-4-primary: rgb(23, 105, 253);
--spinner-rotate: 304deg;
}

View File

@@ -0,0 +1,23 @@
import { Global } from "@emotion/react";
export function CSSInJSStyles() {
return (
<Global
styles={`
:root {
--timestamp: "0";
--interval: "8";
--progress-bar: 11.83299999999997%;
--spinner-1-muted: rgb(142, 6, 182);
--spinner-1-primary: rgb(177, 8, 227);
--spinner-2-muted: rgb(110, 148, 190);
--spinner-2-primary: rgb(138, 185, 238);
--spinner-3-muted: rgb(75, 45, 64);
--spinner-3-primary: rgb(94, 56, 80);
--spinner-4-muted: rgb(155, 129, 108);
--spinner-4-primary: rgb(194, 161, 135);
--spinner-rotate: 213deg;
}
`}
/>
);
}

View File

@@ -0,0 +1,23 @@
import { Global } from "@emotion/react";
export function CSSInJSStyles() {
return (
<Global
styles={`
:root {
--timestamp: "16336621338281";
--interval: "16";
--progress-bar: 56.889%;
--spinner-1-muted: rgb(179, 6, 202);
--spinner-1-primary: rgb(224, 8, 253);
--spinner-2-muted: rgb(22, 188, 124);
--spinner-2-primary: rgb(27, 235, 155);
--spinner-3-muted: rgb(89, 72, 0);
--spinner-3-primary: rgb(111, 90, 0);
--spinner-4-muted: rgb(18, 84, 202);
--spinner-4-primary: rgb(23, 105, 253);
--spinner-rotate: 304deg;
} `}
/>
);
}

View File

@@ -112,15 +112,26 @@ section {
flex-direction: column;
}
.ran,
.timer {
font-weight: normal;
white-space: nowrap;
font-weight: bold;
-webkit-text-stroke: white;
-webkit-text-stroke-width: 2px;
color: white;
font-size: 100px;
}
.ran {
}
.ProgressBar-container {
width: 100%;
display: block;
position: relative;
border: 1px solid var(--color-brand-muted);
border-left: 10px solid red;
border-right: 10px solid pink;
border-top: 10px solid yellow;
border-bottom: 10px solid orange;
border-radius: 4px;
height: 92px;

View File

@@ -7,7 +7,7 @@ const Base = ({}) => {
typeof location !== "undefined"
? decodeURIComponent(location.search.substring(1))
: null;
return <Main productName={name || "asdasdasdasdasdasd"} />;
return <Main productName={name} />;
};
function startReact() {

View File

@@ -1,17 +1,17 @@
export const Main = ({ productName }) => {
export const Main = ({ productName, cssInJS }) => {
return (
<>
<header>
<div className="Title">CSS HMR Stress Test!</div>
<p className="Description">
This page visually tests how quickly a bundler can update CSS over Hot
Module Reloading.
This page visually tests how quickly a bundler can update{" "}
{cssInJS ? "CSS-in-JS" : "CSS"} over Hot Module Reloading.
</p>
</header>
<main className="main">
<section className="ProgressSection">
<p className="Subtitle">
<span className="Subtitle-part">
<span className="Subtitle-part ran">
Ran: <span className="timer"></span>
</span>
</p>
@@ -55,10 +55,7 @@ export const Main = ({ productName }) => {
<div className="Bundler-container">
<div className="Bundler">{productName}</div>
<div className="Bundler-updateRate">
{/* This should loose all the styles
<span className="highlight">
<span className="interval"></span>ms
</span> */}
{cssInJS ? "CSS-in-JS framework: " + cssInJS : ""}
</div>
</div>
</footer>

View File

@@ -0,0 +1,292 @@
{
"label": "bun-cli@0.0.34",
"at": "2021-10-08T01:01:18.129Z",
"sleep": "32",
"package": {
"name": "bun-cli",
"version": "0.0.34"
},
"timestamps": [
16336202536562, 16336202536908, 16336202537294, 16336202537705,
16336202538114, 16336202538534, 16336202538941, 16336202539323,
16336202539742, 16336202540159, 16336202540877, 16336202541310,
16336202541749, 16336202542159, 16336202542565, 16336202542996,
16336202543333, 16336202543761, 16336202544159, 16336202544534,
16336202544944, 16336202545345, 16336202545744, 16336202546159,
16336202546573, 16336202546986, 16336202547399, 16336202547781,
16336202548202, 16336202548564, 16336202548949, 16336202549329,
16336202549762, 16336202550168, 16336202550534, 16336202550887,
16336202551305, 16336202551659, 16336202552060, 16336202552449,
16336202552854, 16336202553270, 16336202553609, 16336202554034,
16336202554437, 16336202554783, 16336202555191, 16336202555623,
16336202556034, 16336202556449, 16336202556890, 16336202557283,
16336202557669, 16336202558084, 16336202558496, 16336202558863,
16336202559271, 16336202559659, 16336202560051, 16336202560452,
16336202560873, 16336202561290, 16336202561659, 16336202562035,
16336202562440, 16336202562862, 16336202563284, 16336202563659,
16336202564034, 16336202564444, 16336202564853, 16336202565245,
16336202565659, 16336202566034, 16336202566455, 16336202566873,
16336202567284, 16336202567659, 16336202568034, 16336202568386,
16336202568790, 16336202569204, 16336202569620, 16336202570384,
16336202570768, 16336202571188, 16336202571551, 16336202572327,
16336202572717, 16336202573116, 16336202573541, 16336202573959,
16336202574319, 16336202574682, 16336202575040, 16336202575375,
16336202577001, 16336202577342, 16336202577680, 16336202578066,
16336202578451, 16336202579166, 16336202579534, 16336202579960,
16336202580370, 16336202580789, 16336202581159, 16336202581576,
16336202581949, 16336202582294, 16336202583087, 16336202583496,
16336202583858, 16336202584203, 16336202584606, 16336202585034,
16336202585386, 16336202585788, 16336202586211, 16336202586604,
16336202587034, 16336202587459, 16336202587869, 16336202588295,
16336202588668, 16336202589092, 16336202589452, 16336202589831,
16336202590197, 16336202590608, 16336202591034, 16336202591460,
16336202591880, 16336202592295, 16336202592727, 16336202593172,
16336202593567, 16336202593994, 16336202594397, 16336202594795,
16336202595224, 16336202595659, 16336202596058, 16336202596463,
16336202596890, 16336202597322, 16336202597732, 16336202598159,
16336202598534, 16336202598951, 16336202599365, 16336202599785,
16336202600159, 16336202600593, 16336202601005, 16336202601402,
16336202601807, 16336202602214, 16336202602556, 16336202602895,
16336202603307, 16336202603661, 16336202604075, 16336202604491,
16336202604853, 16336202605268, 16336202605670, 16336202606034,
16336202606393, 16336202606748, 16336202607170, 16336202607568,
16336202607982, 16336202608411, 16336202608836, 16336202609197,
16336202609596, 16336202609965, 16336202610333, 16336202610740,
16336202611159, 16336202611573, 16336202611975, 16336202612317,
16336202612691, 16336202613060, 16336202613474, 16336202613903,
16336202614341, 16336202614707, 16336202615094, 16336202615534,
16336202615883, 16336202616296, 16336202616671, 16336202617034,
16336202617391, 16336202617727, 16336202618159, 16336202618534,
16336202618937, 16336202619360, 16336202619770, 16336202620179,
16336202620716, 16336202621143, 16336202621534, 16336202622303,
16336202622659, 16336202623085, 16336202623498, 16336202623850,
16336202624220, 16336202624606, 16336202625034, 16336202625387,
16336202625805, 16336202626210, 16336202626599, 16336202627034,
16336202627386, 16336202627748, 16336202628159, 16336202628534,
16336202628954, 16336202629373, 16336202629809, 16336202630197,
16336202630535, 16336202630916, 16336202631290, 16336202631666,
16336202632034, 16336202632369, 16336202633152, 16336202633534,
16336202633883, 16336202634309, 16336202634717, 16336202635106,
16336202635871, 16336202636253, 16336202636671, 16336202637070,
16336202637434, 16336202637798, 16336202638184, 16336202638539,
16336202638938, 16336202639307, 16336202639666, 16336202640095,
16336202640534, 16336202640962, 16336202641307, 16336202641659,
16336202642087, 16336202642521, 16336202642886, 16336202643309,
16336202643662, 16336202644067, 16336202644491, 16336202644853,
16336202645226, 16336202645659, 16336202646074, 16336202646497,
16336202646890, 16336202647311, 16336202647749, 16336202648169,
16336202648976, 16336202649378, 16336202649810, 16336202650165,
16336202650534, 16336202650875, 16336202651250, 16336202651659,
16336202652093, 16336202652516, 16336202652921, 16336202653332,
16336202653722, 16336202654142, 16336202654534, 16336202654880,
16336202655221, 16336202655562, 16336202655997, 16336202656378,
16336202656811, 16336202657161, 16336202657588, 16336202657944,
16336202658360, 16336202658708, 16336202659089, 16336202659428,
16336202659849, 16336202660273, 16336202660685, 16336202661105,
16336202661534, 16336202661873, 16336202662228, 16336202662658,
16336202663438, 16336202663843, 16336202664219, 16336202664646,
16336202665050, 16336202665487, 16336202665838, 16336202666211,
16336202666573, 16336202666927, 16336202667334, 16336202667746,
16336202668158, 16336202668563, 16336202668980, 16336202669406,
16336202669753, 16336202670192, 16336202670554, 16336202670903,
16336202671324, 16336202671734, 16336202672159, 16336202672573,
16336202672982, 16336202673346, 16336202673680, 16336202674087,
16336202674499, 16336202674909, 16336202675260, 16336202676110,
16336202676535, 16336202676913, 16336202677312, 16336202677658,
16336202678044, 16336202678413, 16336202678793, 16336202679208,
16336202679604, 16336202680034, 16336202680385, 16336202680799,
16336202681213, 16336202681595, 16336202682004, 16336202682346,
16336202682726, 16336202683158, 16336202683586, 16336202683990,
16336202684323, 16336202684742, 16336202685175, 16336202685578,
16336202685979, 16336202686805, 16336202687206, 16336202687614,
16336202688038, 16336202688473, 16336202688848, 16336202689221,
16336202689559, 16336202689971, 16336202690368, 16336202690776,
16336202691159, 16336202691585, 16336202692010, 16336202692373,
16336202692780, 16336202693179, 16336202693580, 16336202693991,
16336202694324, 16336202694727, 16336202695159, 16336202695588,
16336202695991, 16336202696335, 16336202697160, 16336202697542,
16336202697929, 16336202698323, 16336202698674, 16336202699060,
16336202699492, 16336202699835, 16336202700238, 16336202700658,
16336202701059, 16336202701420, 16336202701815, 16336202702229,
16336202702659, 16336202703857, 16336202704256, 16336202704659,
16336202705497, 16336202706309, 16336202706660, 16336202707085,
16336202707511, 16336202707866, 16336202708210, 16336202708552,
16336202708925, 16336202709287, 16336202709670, 16336202710045,
16336202710402, 16336202710802, 16336202711167, 16336202711533,
16336202712249, 16336202712660, 16336202713088, 16336202713519,
16336202713936, 16336202714355, 16336202714740, 16336202715160,
16336202715533, 16336202715878, 16336202716290, 16336202716708,
16336202717102, 16336202718290, 16336202718699, 16336202719052,
16336202719388, 16336202719808, 16336202720225, 16336202720659,
16336202721052, 16336202721414, 16336202721828, 16336202722925,
16336202723664, 16336202724063, 16336202724405, 16336202726003,
16336202726736, 16336202727158, 16336202727543, 16336202727930,
16336202728336, 16336202728703, 16336202729061, 16336202729483,
16336202729832, 16336202730222, 16336202730659, 16336202731084,
16336202731500, 16336202731911, 16336202732326, 16336202733158,
16336202733585, 16336202734001, 16336202734691, 16336202735042,
16336202735442, 16336202735863, 16336202736255, 16336202736671,
16336202737043, 16336202737884, 16336202738671, 16336202739110,
16336202739533, 16336202739886, 16336202740283, 16336202740706,
16336202741143, 16336202741534, 16336202741942, 16336202742352,
16336202742697, 16336202743103, 16336202743940, 16336202745172,
16336202745542, 16336202745937, 16336202746339, 16336202746758,
16336202747531, 16336202747877, 16336202748232, 16336202748658,
16336202749055, 16336202749468, 16336202749859, 16336202750416,
16336202750839, 16336202751178, 16336202751572, 16336202752002,
16336202752419, 16336202753269, 16336202753678, 16336202754086,
16336202754432, 16336202754835, 16336202755260, 16336202755683,
16336202756059, 16336202756402, 16336202756837, 16336202758084,
16336202758507, 16336202758879, 16336202759270, 16336202759674,
16336202760044, 16336202760400, 16336202760801, 16336202761659,
16336202762053, 16336202762397, 16336202763199, 16336202763547,
16336202763948, 16336202764714, 16336202765113, 16336202765947,
16336202766329, 16336202766664, 16336202767085, 16336202768233,
16336202769056, 16336202769758, 16336202770178, 16336202770585,
16336202770929, 16336202771325, 16336202772158, 16336202772594,
16336202773033, 16336202773403, 16336202773801, 16336202774179,
16336202774555, 16336202774989, 16336202775393, 16336202775809,
16336202776209, 16336202776618, 16336202777033, 16336202777421,
16336202777845, 16336202778246, 16336202778658, 16336202779055,
16336202779411, 16336202779761, 16336202780175, 16336202780594,
16336202781002, 16336202781848, 16336202782658, 16336202783033,
16336202783857, 16336202784211, 16336202784557, 16336202784972,
16336202785377, 16336202785810, 16336202786172, 16336202786934,
16336202787343, 16336202787765, 16336202788201, 16336202788563,
16336202788970, 16336202789329, 16336202789672, 16336202790055,
16336202790456, 16336202790802, 16336202791580, 16336202791920,
16336202792326, 16336202793158, 16336202793953, 16336202794368,
16336202795187, 16336202795622, 16336202796033, 16336202796393,
16336202796777, 16336202797173, 16336202797540, 16336202797975,
16336202798317, 16336202798739, 16336202799158, 16336202799567,
16336202799966, 16336202800378, 16336202800803, 16336202801232,
16336202801658, 16336202802033, 16336202802374, 16336202802759,
16336202803158, 16336202803533, 16336202803947, 16336202804354,
16336202804729, 16336202805158, 16336202805534, 16336202805950,
16336202806390, 16336202806805, 16336202807219, 16336202807643,
16336202808033, 16336202808377, 16336202808790, 16336202809211,
16336202809560, 16336202809920, 16336202810355, 16336202810758,
16336202811187, 16336202811596, 16336202811943, 16336202812348,
16336202812710, 16336202813060, 16336202813398, 16336202813791,
16336202814158, 16336202814533, 16336202814878, 16336202815246,
16336202815658, 16336202816079, 16336202816851, 16336202817202,
16336202817540, 16336202817905, 16336202818244, 16336202818663,
16336202819068, 16336202819418, 16336202819777, 16336202820193,
16336202820599, 16336202821033, 16336202821395, 16336202821745,
16336202822158, 16336202822590, 16336202822996, 16336202823396,
16336202823804, 16336202824210, 16336202824581, 16336202824991,
16336202825406, 16336202825806, 16336202826210, 16336202826598,
16336202827033, 16336202827446, 16336202827839, 16336202828201,
16336202828577, 16336202828968, 16336202829362, 16336202829709,
16336202830096, 16336202830533, 16336202830917, 16336202831290,
16336202831699, 16336202832035, 16336202832406, 16336202832804,
16336202833200, 16336202833604, 16336202834033, 16336202834386,
16336202834759, 16336202835190, 16336202835621, 16336202836033,
16336202836405, 16336202837191, 16336202837613, 16336202838033,
16336202838374, 16336202838798, 16336202839200, 16336202839603,
16336202840034, 16336202840389, 16336202840783, 16336202841200,
16336202841617, 16336202842034, 16336202842390, 16336202842737,
16336202843158, 16336202843585, 16336202843923, 16336202844313,
16336202844724, 16336202845158, 16336202845576, 16336202845939,
16336202846368, 16336202846728, 16336202847158, 16336202847568,
16336202847911, 16336202848291, 16336202848695, 16336202849103,
16336202849533, 16336202849942, 16336202850368, 16336202850747,
16336202851158, 16336202851549, 16336202851978, 16336202852383,
16336202852725, 16336202853158, 16336202853554, 16336202853961,
16336202854308, 16336202854704, 16336202855060, 16336202855418,
16336202855776, 16336202856203, 16336202856617, 16336202857036,
16336202857455, 16336202857884, 16336202858262, 16336202858658,
16336202859071, 16336202859847, 16336202860237, 16336202860658,
16336202861037, 16336202861452, 16336202861869, 16336202862218,
16336202862590, 16336202863001, 16336202863422, 16336202863857,
16336202864219, 16336202864658, 16336202865047, 16336202865404,
16336202865789, 16336202866210, 16336202866624, 16336202867033,
16336202867380, 16336202867797, 16336202868227, 16336202868658,
16336202869083, 16336202869500, 16336202869906, 16336202870246,
16336202870658, 16336202871086, 16336202871441, 16336202871820,
16336202872204, 16336202872546, 16336202872943, 16336202873380,
16336202873811, 16336202874213, 16336202874566, 16336202874918,
16336202875261, 16336202875655, 16336202876047, 16336202876771,
16336202877202, 16336202877612, 16336202878033, 16336202878412,
16336202878846, 16336202879241, 16336202879658, 16336202880072,
16336202880508, 16336202880901, 16336202881308, 16336202881725,
16336202882158, 16336202882579, 16336202882945, 16336202883286,
16336202883657, 16336202884048, 16336202884404, 16336202884752,
16336202885158, 16336202885533, 16336202885938, 16336202886364,
16336202886759, 16336202887175, 16336202887585, 16336202887929,
16336202888345, 16336202888743, 16336202889157, 16336202889570,
16336202889970, 16336202890382, 16336202890761, 16336202891187,
16336202891600, 16336202892033, 16336202892454, 16336202892794,
16336202893178, 16336202893533, 16336202893903, 16336202894264,
16336202894668, 16336202895049, 16336202895400, 16336202895774,
16336202896157, 16336202896537, 16336202896883, 16336202897232,
16336202897658, 16336202898065, 16336202898493, 16336202898884,
16336202899251, 16336202899673, 16336202900047, 16336202900467,
16336202900883, 16336202901300, 16336202901676, 16336202902068,
16336202902479, 16336202902902, 16336202903260, 16336202903675,
16336202904094, 16336202904476, 16336202904824, 16336202905158,
16336202905533, 16336202905934, 16336202906289, 16336202906717,
16336202907158, 16336202907547, 16336202907904, 16336202908294,
16336202908717, 16336202909157, 16336202909582, 16336202910005,
16336202910399, 16336202910800, 16336202911220, 16336202911657,
16336202912064, 16336202912405, 16336202912779, 16336202913158,
16336202913553, 16336202913966, 16336202914376, 16336202914719,
16336202915091, 16336202915515, 16336202915887, 16336202916293,
16336202916649, 16336202917438, 16336202917869, 16336202918221,
16336202919053, 16336202919425, 16336202919833, 16336202920234,
16336202920658, 16336202921033, 16336202921433, 16336202921801,
16336202922161, 16336202922589, 16336202923017, 16336202923418,
16336202923804, 16336202924199, 16336202924593, 16336202925033,
16336202925449, 16336202925818, 16336202926223, 16336202926662,
16336202927431, 16336202927812, 16336202928227, 16336202928658,
16336202929061, 16336202929473, 16336202929891, 16336202930241,
16336202930657, 16336202931057, 16336202931396, 16336202931811,
16336202932225, 16336202932657, 16336202933058, 16336202933445,
16336202933790, 16336202934157, 16336202934562, 16336202934988,
16336202935391, 16336202935777, 16336202936160, 16336202936562,
16336202936986, 16336202937396, 16336202937751, 16336202938158,
16336202938578, 16336202938985, 16336202939396, 16336202939752,
16336202940157, 16336202940585
],
"frameTimes": [
346, 411, 420, 382, 417, 433, 410, 431, 428, 375, 401, 415, 413, 382, 362,
380, 406, 353, 354, 389, 416, 425, 346, 432, 415, 393, 415, 367, 388, 401,
417, 376, 422, 375, 410, 392, 375, 418, 375, 352, 414, 764, 420, 776, 399,
418, 363, 335, 341, 386, 715, 426, 419, 417, 345, 409, 345, 428, 402, 393,
425, 426, 424, 379, 411, 426, 415, 445, 427, 398, 435, 405, 432, 427, 417,
420, 434, 397, 407, 339, 354, 416, 415, 364, 355, 398, 429, 361, 369, 407,
414, 342, 369, 429, 366, 440, 413, 363, 336, 375, 423, 409, 427, 769, 426,
352, 386, 353, 405, 435, 362, 375, 419, 388, 381, 376, 335, 382, 426, 389,
382, 399, 364, 355, 369, 429, 428, 352, 434, 423, 405, 362, 433, 423, 421,
420, 402, 355, 341, 409, 423, 411, 420, 346, 341, 381, 350, 356, 348, 339,
424, 420, 339, 430, 405, 427, 437, 373, 354, 412, 405, 426, 439, 349, 410,
414, 364, 407, 410, 850, 378, 346, 369, 415, 430, 414, 382, 342, 432, 404,
419, 403, 826, 408, 435, 373, 412, 408, 426, 363, 399, 411, 403, 429, 344,
382, 394, 386, 343, 420, 361, 414, 1198, 403, 812, 425, 355, 342, 362, 375,
400, 366, 411, 431, 419, 420, 345, 418, 1188, 353, 420, 434, 362, 1097, 399,
1598, 422, 387, 367, 422, 390, 425, 411, 832, 416, 351, 421, 416, 841, 439,
353, 423, 391, 410, 406, 1232, 395, 419, 346, 426, 413, 557, 339, 430, 850,
408, 403, 423, 343, 1247, 372, 404, 356, 858, 344, 348, 766, 834, 335, 1148,
702, 407, 396, 436, 370, 378, 434, 416, 409, 388, 401, 397, 350, 419, 846,
375, 354, 415, 433, 762, 422, 362, 359, 383, 346, 340, 832, 415, 435, 360,
396, 435, 422, 409, 412, 429, 375, 385, 375, 407, 429, 416, 415, 424, 344,
421, 360, 403, 409, 405, 350, 393, 375, 368, 421, 351, 365, 419, 350, 416,
434, 350, 432, 400, 406, 410, 400, 388, 413, 362, 391, 347, 437, 373, 336,
398, 404, 353, 431, 412, 786, 420, 424, 403, 355, 417, 417, 347, 427, 390,
434, 363, 360, 410, 380, 408, 409, 379, 391, 405, 433, 407, 396, 358, 427,
419, 429, 396, 776, 421, 415, 349, 411, 435, 439, 357, 421, 409, 417, 431,
417, 340, 428, 379, 342, 437, 402, 352, 394, 724, 410, 379, 395, 414, 393,
417, 421, 341, 391, 348, 375, 426, 416, 344, 398, 413, 412, 426, 433, 340,
355, 361, 381, 374, 380, 349, 407, 391, 422, 420, 417, 392, 423, 415, 382,
334, 401, 428, 389, 390, 440, 423, 401, 437, 341, 379, 413, 343, 424, 406,
789, 352, 372, 401, 375, 368, 428, 401, 395, 440, 369, 439, 381, 431, 412,
350, 400, 415, 432, 387, 367, 426, 386, 402, 410, 407, 407, 356, 428
],
"percentileMs": {
"50": 40.7,
"75": 42.3,
"90": 43.5,
"95": 76.4,
"99": 118.8
}
}

View File

@@ -0,0 +1,15 @@
# Benchmarking hot module reloading
## Methodology
How do you benchmark hot module reloading? What do you call "done" and what do you call "start"?
The answer for "done" is certainly not compilation time. Compilation time is one step.
I think the answer should be different depending on the type of content loaded.
For CSS, the answer should be "when the updated stylesheet was drawn on the screen"
For JavaScript, the answer should be "when the rebuilt code completed execution such that any changes are applied"
For images & assets, the answer should be "when the updated asset finished loading"
The start time should be defined as "the timestamp the filesystem set as the write time". As in, the time the developer pressed save in their editor.

View File

@@ -1 +1 @@
24
35

View File

@@ -133,16 +133,6 @@ pub fn build(b: *std.build.Builder) !void {
exe.setOutputDir(output_dir);
var cwd_dir = std.fs.cwd();
if (std.builtin.is_test) {
var walker = cwd_dir.walk(std.heap.c_allocator) catch unreachable;
while (walker.next() catch unreachable) |entry| {
if (std.mem.endsWith(u8, entry.basename, "_test.zig")) {
std.debug.print("[test] Added {s}", .{entry.basename});
_ = b.addTest(entry.path);
}
}
}
const runtime_hash = std.hash.Wyhash.hash(0, @embedFile("./src/runtime.out.js"));
const runtime_version_file = std.fs.cwd().openFile("src/runtime.version", .{ .write = true }) catch unreachable;
@@ -239,7 +229,12 @@ pub fn build(b: *std.build.Builder) !void {
step.addObjectFile("src/deps/libJavaScriptCore.a");
step.addObjectFile("src/deps/libWTF.a");
step.addObjectFile("src/deps/libcrypto.a");
step.addObjectFile("src/deps/libbmalloc.a");
step.addObjectFile("src/deps/libarchive.a");
step.addObjectFile("src/deps/libs2n.a");
step.addObjectFile("src/deps/zlib/libz.a");
step.addObjectFile("src/deps/mimalloc/libmimalloc.a");
step.addLibPath("src/deps/mimalloc");
@@ -257,10 +252,16 @@ pub fn build(b: *std.build.Builder) !void {
step.addObjectFile(homebrew_prefix ++ "opt/icu4c/lib/libicudata.a");
step.addObjectFile(homebrew_prefix ++ "opt/icu4c/lib/libicui18n.a");
step.addObjectFile(homebrew_prefix ++ "opt/icu4c/lib/libicuuc.a");
step.addObjectFile(homebrew_prefix ++ "opt/libiconv/lib/libiconv.a");
// icucore is a weird macOS only library
step.linkSystemLibrary("icucore");
step.addLibPath(homebrew_prefix ++ "opt/icu4c/lib");
step.addIncludeDir(homebrew_prefix ++ "opt/icu4c/include");
} else {
step.linkSystemLibrary("icuuc");
step.linkSystemLibrary("icudata");
step.linkSystemLibrary("icui18n");
step.linkSystemLibrary("iconv");
}
for (bindings_files.items) |binding| {
@@ -272,7 +273,7 @@ pub fn build(b: *std.build.Builder) !void {
var obj_step = b.step("obj", "Build Bun as a .o file");
var obj = b.addObject(bun_executable_name, exe.root_src.?.path);
obj.bundle_compiler_rt = true;
obj.setTarget(target);
addPicoHTTP(obj, false);
obj.addPackage(.{
.name = "clap",
@@ -282,7 +283,16 @@ pub fn build(b: *std.build.Builder) !void {
obj_step.dependOn(&obj.step);
obj.setOutputDir(output_dir);
obj.setBuildMode(mode);
obj.setTarget(target);
obj.linkLibC();
obj.linkLibCpp();
obj.bundle_compiler_rt = true;
if (target.getOsTag() == .linux) {
// obj.want_lto = tar;
obj.link_emit_relocs = true;
obj.link_function_sections = true;
}
} else {
b.default_step.dependOn(&exe.step);
}

1
examples/.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
bun-examples-all

View File

@@ -1,11 +0,0 @@
import { Main } from "../../src/main";
function IndexRoute() {
return (
<div>
<Main productName={"Boom id"} />
</div>
);
}
export { IndexRoute as default };

View File

@@ -1,7 +0,0 @@
import { Main } from "src/main";
export function IndexPage() {
return <Main />;
}
export default IndexPage;

View File

@@ -1,9 +0,0 @@
import { Main } from "../../src/main";
export default function IndexRoute() {
return (
<div>
<Main productName={"nested!"} />
</div>
);
}

View File

@@ -1,13 +0,0 @@
import { Main } from "../src/main";
export function getInitialProps() {
return {};
}
export default function IndexRoute() {
return (
<div>
<Main productName={"Page 2! Next.js (Webpack 5)"} />
</div>
);
}

View File

@@ -1,21 +0,0 @@
// Snowpack Configuration File
// See all supported options: https://www.snowpack.dev/reference/configuration
/** @type {import("snowpack").SnowpackUserConfig } */
module.exports = {
root: "src",
mount: {
public: "/",
src: "/",
},
plugins: ["@snowpack/plugin-react-refresh"],
packageOptions: {
/* ... */
},
devOptions: {
/* ... */
},
buildOptions: {
/* ... */
},
};

File diff suppressed because it is too large Load Diff

View File

@@ -1 +0,0 @@
export const Button = ({ children }) => <div>asdasasd{children}</div>;

View File

@@ -1,14 +0,0 @@
:root {
--timestamp: "596";
--interval: "64";
--progress-bar: 33.167%;
--spinner-1-muted: rgb(42, 74, 66);
--spinner-1-primary: rgb(53, 93, 82);
--spinner-2-muted: rgb(90, 51, 192);
--spinner-2-primary: rgb(112, 64, 240);
--spinner-3-muted: rgb(157, 140, 68);
--spinner-3-primary: rgb(196, 175, 85);
--spinner-4-muted: rgb(86, 152, 66);
--spinner-4-primary: rgb(108, 190, 82);
--spinner-rotate: 237deg;
}

View File

@@ -1,3 +0,0 @@
body {
filter: sepia(50%) brightness(200%);
}

View File

@@ -1,27 +0,0 @@
import React from "react";
import { NewComponent } from "./new-comp";
const Toast = () => {
const [baconyes, baconno] = useBacon();
return <div>false</div>;
};
const Button = ({ label, label2, onClick }) => {
const useCustomHookInsideFunction = (what, arr) => {
return [true, false];
};
const [on, setOn] = React.useState(false);
React.useEffect(() => {
console.log({ on });
}, [on]);
// const [foo1, foo2] = useCustomHookInsideFunction(() => {}, [on]);
return (
<div className="Button" onClick={onClick}>
<Toast>f</Toast>
<div className="Button-label">{label}12</div>
<NewComponent />
</div>
);
};

View File

@@ -1,3 +0,0 @@
export const NewComponent = () => {
return <div>NEW!</div>;
};

View File

@@ -1 +0,0 @@
/* @import "https://fonts.googleapis.com/css2?family=IBM+Plex+Sans:wght@400;700&family=Space+Mono:wght@400;700&display=swap"; */

View File

@@ -1 +0,0 @@
import jsx from "/Users/jarred/Code/bun/demos/css-stress-test/node_modules/react/cjs/react-jsx-dev-runtime.development.js";

View File

@@ -1,23 +0,0 @@
{
"compilerOptions": {
"target": "esnext",
"lib": ["dom", "dom.iterable", "esnext", "WebWorker"],
"allowJs": true,
"skipLibCheck": true,
"strict": false,
"forceConsistentCasingInFileNames": true,
"noEmit": true,
"esModuleInterop": true,
"module": "esnext",
"moduleResolution": "Node",
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "preserve",
"baseUrl": ".",
"paths": {
"path": ["node_modules/path-browserify"]
}
},
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx"],
"exclude": ["node_modules"]
}

View File

@@ -1 +0,0 @@
export const yep = true;

File diff suppressed because it is too large Load Diff

View File

@@ -1,25 +0,0 @@
{
"name": "hello-next",
"version": "1.0.0",
"main": "index.js",
"license": "MIT",
"dependencies": {
"@jarred/react-static-tweets": "0.5.8",
"@jarred/static-tweets": "^0.5.8",
"date-fns": "^2.23.0",
"isomorphic-fetch": "^3.0.0",
"next": "^11.1.0",
"parcel": "2.0.0-rc.0",
"path-browserify": "^1.0.1",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"react-is": "^17.0.2",
"whatwg-url": "^9.1.0"
},
"devDependencies": {
"@babel/standalone": "^7.15.3",
"@types/react": "^17.0.19",
"bun-framework-next": "^0.0.0-21",
"typescript": "^4.3.5"
}
}

View File

@@ -1,5 +0,0 @@
// Next.js API route support: https://nextjs.org/docs/api-routes/introduction
export default function handler(req, res) {
res.status(200).json({ name: 'John Doe' })
}

View File

@@ -1,26 +0,0 @@
import Link from "next/link";
export default function Baz({}) {
return (
<div style={{ padding: 16 }}>
<h1>Third</h1>
<ul>
<li>
<Link href="/">
<a>Root page</a>
</Link>
</li>
<li>
<Link href="/second">
<a>Second page</a>
</Link>
</li>
<li>
<Link href="/posts/123">
<a>Post page 123</a>
</Link>
</li>
</ul>
</div>
);
}

View File

@@ -1,19 +0,0 @@
import { useRouter } from "next/router";
import Link from "next/link";
export default function Post({}) {
const router = useRouter();
return (
<div style={{ padding: 16 }}>
<h1>Post: {router.query.id}</h1>
<ul>
<li>
<Link href="/">
<a>Root page</a>
</Link>
</li>
</ul>
</div>
);
}

View File

@@ -1,11 +0,0 @@
import "three/three1";
import "three/three2";
import "three/three3";
import "three/three4";
import "three/three5";
import "three/three6";
import "three/three7";
import "three/three8";
import "three/three9";
import "three/three10";
// import "@babel/standalone/babel";

View File

@@ -1,11 +0,0 @@
{
"name": "lotta-modules",
"version": "1.0.0",
"license": "MIT",
"dependencies": {
"@babel/standalone": "^7.15.3",
"lodash": "^4.17.21",
"three.js": "^0.77.1",
"underscore": "^1.13.1"
}
}

View File

@@ -1,6 +0,0 @@
<html>
<head> </head>
<body>
<script src="/index.js"></script>
</body>
</html>

View File

@@ -0,0 +1,33 @@
import { fetchCSV } from "macro:fetchCSV";
export const Covid19 = () => {
const rows = fetchCSV(
"https://covid19.who.int/WHO-COVID-19-global-data.csv",
{
last: 100,
columns: ["New_cases", "Date_reported", "Country"],
}
);
return (
<div>
<h2>Covid-19</h2>
<h6>last {rows.length} updates from the WHO</h6>
<div className="Table">
<div className="Header">
<div className="Heading">New Cases</div>
<div className="Heading">Date</div>
<div className="Heading">Country</div>
</div>
{rows.map((row, index) => (
<div className="Row" key={index}>
<div className="Column">{row[0]}</div>
<div className="Column">{row[1]}</div>
<div className="Column">{row[2]}</div>
</div>
))}
</div>
</div>
);
};

View File

@@ -0,0 +1,17 @@
// source code
import { matchInFile } from "macro:matchInFile";
export const IPAddresses = () => (
<div>
<h2>recent ip addresses</h2>
<div className="Lines">
{matchInFile("access.log", /^(?:[0-9]{1,3}\.){3}[0-9]{1,3}/).map(
(ipAddress, index) => (
<div className="Line" key={index}>
{ipAddress}
</div>
)
)}
</div>
</div>
);

View File

@@ -0,0 +1,15 @@
import * as ReactDOM from "react-dom";
import * as React from "react";
import { IPAddresses } from "./example";
import { Covid19 } from "./covid19";
const Start = function () {
const root = document.createElement("div");
document.body.appendChild(root);
// comment out to switch between examples
// ReactDOM.render(<IPAddresses />, root);
ReactDOM.render(<Covid19 />, root);
};
Start();

View File

@@ -0,0 +1,4 @@
// source code
import { mysteryBox } from "macro:./mystery-box";
export default "You roll! " + mysteryBox(123);

View File

@@ -0,0 +1,54 @@
import Pappa from "papaparse";
// Example usage:
// const rows = fetchCSV(
// "https://covid19.who.int/WHO-COVID-19-global-data.csv",
// {
// last: 100,
// columns: ["New_cases", "Date_reported", "Country"],
// }
// );
export async function fetchCSV(callExpression) {
console.time("fetchCSV Total");
const [
urlNode,
{
properties: { last: limit = 10, columns = [] },
},
] = callExpression.arguments;
const url = urlNode.get();
console.time("Fetch");
const response = await fetch(url);
const csvText = await response.text();
console.timeEnd("Fetch");
console.time("Parse");
let rows = Pappa.parse(csvText, { fastMode: true }).data;
console.timeEnd("Parse");
console.time("Render");
const columnIndices = new Array(columns.length);
for (let i = 0; i < columns.length; i++) {
columnIndices[i] = rows[0].indexOf(columns[i]);
}
rows = rows
.slice(Math.max(limit, rows.length) - limit)
.reverse()
.filter((columns) => columns.every(Boolean));
const value = (
<array>
{rows.map((columns) => (
<array>
{columnIndices.map((columnIndex) => (
<string value={columns[columnIndex]} />
))}
</array>
))}
</array>
);
console.timeEnd("Render");
console.timeEnd("fetchCSV Total");
return value;
}

View File

@@ -0,0 +1,23 @@
// macro code
export function matchInFile(callExpression: BunAST.CallExpression) {
const [filePathNode, matcherNode] = callExpression.arguments;
let filePath: string;
filePath = filePathNode.get();
let matcher: RegExp;
matcher = matcherNode.get();
const file: string = Bun.readFile(Bun.cwd + filePath);
return (
<array>
{file
.split("\n")
.map((line) => line.match(matcher))
.filter(Boolean)
.reverse()
.map((line) => (
<string value={line[0]} />
))}
</array>
);
}

10
examples/macros/now.tsx Normal file
View File

@@ -0,0 +1,10 @@
import moment from "moment";
export function now(node) {
var fmt = "HH:mm:ss";
const args = node.arguments;
if (args[0] instanceof <string />) {
fmt = args[0].get();
}
const time = moment().format(fmt);
return <string value={time}></string>;
}

View File

@@ -0,0 +1,17 @@
{
"name": "macros",
"version": "1.0.0",
"main": "index.js",
"license": "MIT",
"dependencies": {
"moment": "^2.29.1",
"papaparse": "^5.3.1",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"react-refresh": "^0.10.0"
},
"devDependencies": {
"@types/react": "^17.0.24",
"@types/react-dom": "^17.0.9"
}
}

View File

@@ -0,0 +1,14 @@
<!DOCTYPE html>
<html>
<head>
<title>Macro test</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="stylesheet" href="/styles.css" type="text/css" />
</head>
<body>
<script async type="module" src="/components/index.tsx"></script>
</body>
</html>

View File

@@ -0,0 +1,47 @@
html {
font-size: 4rem;
margin: 0;
padding: 0;
background-color: black;
color: rgb(0, 255, 0);
font-family: "Courier";
}
body {
margin: 48px auto;
text-align: center;
}
.Line {
font-size: 0.5rem;
font-family: monospace;
}
.Table {
display: grid;
width: fit-content;
}
.Row,
.Header {
display: grid;
grid-template-columns: 2fr 1fr 1fr;
text-align: right;
column-gap: 2rem;
}
.Heading {
text-align: right;
}
.Header {
border-bottom: 1px solid rgb(0, 255, 0);
margin-bottom: 20px;
padding-bottom: 20px;
}
.Heading:nth-of-type(2) {
text-align: left;
}

View File

@@ -0,0 +1,7 @@
{
"compilerOptions": {
"baseUrl": ".",
"paths": {},
"jsx": "preserve"
}
}

View File

@@ -32,3 +32,11 @@ yarn-error.log*
# vercel
.vercel
**/*.trace
**/*.zip
**/*.tar.gz
**/*.tgz
**/*.log
package-lock.json
**/*.bun

42
examples/next/.npmignore Normal file
View File

@@ -0,0 +1,42 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
# dependencies
/node_modules
/.pnp
.pnp.js
# testing
/coverage
# next.js
/.next/
/out/
# production
/build
# misc
.DS_Store
*.pem
# debug
npm-debug.log*
yarn-debug.log*
yarn-error.log*
# local env files
.env.local
.env.development.local
.env.test.local
.env.production.local
# vercel
.vercel
**/*.trace
**/*.zip
**/*.tar.gz
**/*.tgz
**/*.log
package-lock.json
**/*.bun

42
examples/next/gitignore Normal file
View File

@@ -0,0 +1,42 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
# dependencies
/node_modules
/.pnp
.pnp.js
# testing
/coverage
# next.js
/.next/
/out/
# production
/build
# misc
.DS_Store
*.pem
# debug
npm-debug.log*
yarn-debug.log*
yarn-error.log*
# local env files
.env.local
.env.development.local
.env.test.local
.env.production.local
# vercel
.vercel
**/*.trace
**/*.zip
**/*.tar.gz
**/*.tgz
**/*.log
package-lock.json
**/*.bun

View File

@@ -0,0 +1,21 @@
{
"name": "@bun-examples/next",
"version": "0.0.32",
"main": "index.js",
"dependencies": {
"next": "11.1.2",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"react-is": "^17.0.2"
},
"devDependencies": {
"@types/react": "^17.0.19",
"bun-framework-next": "^0.0.0-21",
"typescript": "^4.3.5"
},
"bun-create": {
"postinstall": [
"bun bun --use next"
]
}
}

View File

@@ -5,12 +5,11 @@ import styles from "../styles/Home.module.css";
export async function getStaticProps(ctx) {
return {
props: {
},
props: {},
};
}
export default function Home({ }) {
export default function Home({}) {
return (
<div className={styles.container}>
<Head>
@@ -37,14 +36,6 @@ export default function Home({ }) {
</div>
</Link>
<a
onClick={() => router.push("/foo/bar/third")}
className={styles.card}
>
<h2>Third Page &rarr;</h2>
<p>button, router.push()</p>
</a>
<a
href="https://github.com/vercel/next.js/tree/master/examples"
className={styles.card}

View File

Before

Width:  |  Height:  |  Size: 25 KiB

After

Width:  |  Height:  |  Size: 25 KiB

View File

Before

Width:  |  Height:  |  Size: 1.1 KiB

After

Width:  |  Height:  |  Size: 1.1 KiB

View File

@@ -1,6 +1,5 @@
@import url("./2.css");
.container {
min-height: 100vh;
min-height: 99vh;
padding: 0 0.5rem;
display: flex;
flex-direction: column;
@@ -8,6 +7,7 @@
align-items: center;
height: 100vh;
}
.main {
padding: 5rem 0;
flex: 1;

View File

@@ -14,8 +14,3 @@ a {
* {
box-sizing: border-box;
}
body {
background-image: url(https://wompampsupport.azureedge.net/fetchimage?siteId=7575&v=2&jpgQuality=100&width=700&url=https%3A%2F%2Fi.kym-cdn.com%2Fentries%2Ficons%2Foriginal%2F000%2F013%2F564%2Fdoge.jpg);
background-size: cover;
}

View File

@@ -1,5 +1,5 @@
:root {
--timestamp: "12812";
--timestamp: "0";
--interval: "8";
--progress-bar: 11.83299999999997%;
--spinner-1-muted: rgb(142, 6, 182);
@@ -11,4 +11,4 @@
--spinner-4-muted: rgb(155, 129, 108);
--spinner-4-primary: rgb(194, 161, 135);
--spinner-rotate: 213deg;
}
}

32
examples/react/.gitignore vendored Normal file
View File

@@ -0,0 +1,32 @@
**/*.trace
**/*.zip
**/*.tar.gz
**/*.tgz
**/*.log
package-lock.json
**/*.bun
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
# dependencies
/node_modules
/.pnp
.pnp.js
# testing
/coverage
# production
/build
# misc
.DS_Store
.env.local
.env.development.local
.env.test.local
.env.production.local
npm-debug.log*
yarn-debug.log*
yarn-error.log*

Some files were not shown because too many files have changed in this diff Show More