by eyelidlessness · 4y ago · 0 comments
A thing that’s not clear in the article, or indeed obvious in Bun’s launch material, is that it was originally (or at least as close to its origin as I can trace in personal memory) scoped as a TypeScript/JS/JSX compiler and generally as a bundler. This is where it got its name, as I recall. In any case, as you say it was a greenfield compiler with ESBuild as a reference.
Jarred can correct me if he’s here and I’m wrong (about this or anything), but I believe the runtime scope grew organically out of:
1. Bun’s nascent macro system (which last I checked is novel and quite clever, using JSX as the abstract macro it is). Macros need a runtime to macro anything, after all.
2. Prioritizing development before production, and ecosystem compatibility (e.g. Next.js is frequently used in example benchmarks), again where a runtime is expected.
Of very few nits I’d pick, I think “based on” should very probably be reworded to reflect the inspiration. It’s easy to misinterpret in a software context. The only nits remaining to pick, I’ve already picked them on Twitter and they’re generally about not introducing API inconsistencies for performance wins (and AFAICT that’s always been persuasive).
If Bun’s future is primarily as a runtime rather than a build tool, it’s probably fine that its roots as a transpiler/bundler is left to curious esoteria. Maybe even for the best, because that category of software has such a poor reputation. Even if the cute name references a hopefully not distant future where so much churn and worry about JS build tooling might become an afterthought.
In Zig, code can run at compile time, and thats amazing. That's one of the main things I want in TypeScript. Once you have that, everything from type reflection to native graphql types without codegen is just a library away.
Yeah, I'd really, really like to hear more about that if you can point me at anything. Overall, all of the decisions Bun is making, in just about every part of the ecosystem it touches, are things that I have been really excited about. I've got a good feeling about this and I'm trying to scrape some time together to help out.
As for esbuild, I don't think you're correcting the article because it said that the parser is a `port` of esbuild, not "based on". You're probably just replying to the other comment :)
[macros]
# Remap any import like this:
# import {graphql} from 'react-relay';
# To:
# import {graphql} from 'macro:bun-macro-relay';
react-relay = { "graphql" = "bun-macro-relay" }
..Or as a transpiler option: const transpiler = new Bun.Transpiler({
loader: "tsx",
define: {
"process.env.NODE_ENV": JSON.stringify("development"),
user_undefined: "undefined",
},
platform: "bun",
macro: {
inline: {
whatDidIPass: `${import.meta.dir}/inline.macro.js`,
},
react: {
bacon: `${import.meta.dir}/macro-check.js`,
},
},
});
..But not within the transpiled code itself.Ooh, hold on - there's more in /test/macro. Here's hello-fetch-macro.tsx.
import { fetchSync } from "macro:./fetchSync.tsx";
const synchronousFetch = fetchSync(`https://example.com`);
console.log(synchronousFetch);
Looks like the special import syntax converts the function to run at build time.https://github.com/oven-sh/bun/blob/c3bf97002d6f0b117060dabf...
https://stackoverflow.com/questions/27309412/what-is-the-dif...