New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Explore: Bun for bundling, testing, developing (instead of Vite, vitest, esbuild, rollup, multiple configs, ...) #1290
Comments
cc @bgrgicak @dmsnell @brandonpayton @sejas @wojtekn for context and thoughts. |
this all makes sense to me; I'm glad to see the exploration going as far as it is. |
After reading the docs a bit Bun sounds like magic especially because it does a lot of things well. If #1056 is a success let's explore where would we benefit from Bun the most and start replacing these parts. |
So far, this looks amazing. As an aside, I love how the use of Jest-like APIs apparently lets us switch between various test runners.
Magic is great but always makes me think, "What can we do if the magic fails?". And I guess there is always a last resort of going back to tools that require more config and integration work. It certain seems worth trying to use something that requires much less work and offers the upside of producing standalone native executables. I took a quick look at the Bun codebase to get a feel for the project, and IMO, it is pretty readable at a glance. The Zig language is interesting. And the project seems disciplined and well thought out. |
I've been playing with Bun today. Here's what I've learned. Running testsBun fails where we use Vitest-specific syntax like bun test packages/php-wasm/node/src/test/php.spec.ts The tests were running fast and Bun provided really good visual feedback throughout the test runs. That being said, I saw some failures that didn't happen with Node.js. They could be bugs in Bun or pointers towards a deeper portability issue with PHP.wasm (I believe Bun runs WebKit, not v8): PHP 8.2 > proc_open() > echo "WordPress"; stdin=file (empty), stdout=pipe, stderr=pipe, stream_get_contents [18.03ms]
402 | headers: PHPResponse['headers'];
403 | httpStatusCode: number;
404 | } {
405 | const headersFilePath = '/internal/headers.json';
406 | if (!this.fileExists(headersFilePath)) {
407 | throw new Error(
^
error: SAPI Error: Could not find response headers file. This log message talks about PHP failure and I assume it's logged by one of our
I also saw some timeout errors which I fixed by increasing the timeout. BuildingBun builds extremely fast. I pointed it to the Blueprints package and it gave me a The output file contained all the module dependencies, including code from other packages. This is perfect for the Playground website, but it's not useful for publishing npm packages. We'd have to figure out how to bundle only a single module. The Also, Bun produced an ESM output but we're shipping Playground packages also as CJS. We could either transpile that output using another tool, or drop CJS support. The latter will be more difficult as there's plenty of execution context where you need CJS, e.g. the VS code extension AFAIR. For some inputs, Bun crashed without providing a good error:
We could maybe figure out which asset was missing, but definitely less than ideal. That being said, it's still a far better error message that many messages I saw coming from Vite or its plugins. |
@adamziel those are wonderfully detailed notes!
🤔 It's pretty neat to use different but nearly-equivalent platforms to shake out bugs.
It might be related to this line. await expect(promise1).rejects.toThrow(
'PHP.run() failed with exit code 255'
); This may be a known issue since last year:
Unfortunately, there is some indirection going on in Bun which results in that error: const files = additional_files[index];
if (!(files.len > 0)) {
Output.panic("Internal error: missing asset file", .{});
} So to find out which file, it seems the missing file needs to be noticed earlier in bundling. |
A couple other thoughts:
|
It would have to run the Asyncify version until JSPI is more widely supported
Do you mean fixes in Bun itself? Most likely, yes. Otherwise that executable is no different than the source code itself, it just happens to bundle the runtime. |
I think you're right that it is no different. If we didn't include a package-lock.json, it might be different. In that case, the source code might have a chance of getting security updates for dependencies for new installs, depending on the versions allowed by package.json. |
https://bun.sh/ is amazing – let's explore moving the entire Playground to it.
Bun "just works"
Bun just does the right thing. I can point it to a file deep in a monorepo and it will resolve all the imports etc. without a single config f
It seems like https://bun.sh/docs/bundler has na upper hand over Vite:
bun packages/playground/cli/src/main.ts
just works, while in Vite we don't have a corresponding command so we need to build everything before running.nx
?Here's how Bun performs at specific tasks.
Development run
This single command runs the CLI version of PHP.wasm:
Here's what I didn't do with Bun but had to do with Vite:
cd
into the package directory first – I'm running this from the repo root!Bundling
I ran this command and Bun just bundled the
@php-wasm/cli
package:Here's what I didn't do with Bun but had to do with Vite:
nx
builds –bun build
took only 22ms!Testing
I ran this command and Bun just ran the tests:
Here's what I didn't do with Bun but had to do with Vite:
New features
Single-file executable
Bun can build a TypeScript project into a single executable. We could use it to distribute a Playground CLI tool without worrying about Node versions, node_modules etc.
Related Resources
Concerns
Notes
Let's use #1056 as an excuse to explore switching to Bun for bundling packages
The text was updated successfully, but these errors were encountered: