You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/blog/2022-07-20-bun-first-look.mdx
+28-11Lines changed: 28 additions & 11 deletions
Original file line number
Diff line number
Diff line change
@@ -1,9 +1,9 @@
1
1
---
2
2
title: "Bun: A Complete Overhaul of the JavaScript Ecosystem"
3
-
description: A security expert's analysis of the malicious code added to ctx and Phpass, Python and PHP dependencies, that turned them into malware by sending environment variables and credentials to a third party attacker.
3
+
description: A first look at Bun, the new framework trying to replace node and just about everything else too.
@@ -124,7 +125,9 @@ This isn't the first time someone has tried to speed up NPM. You might be famili
124
125
faster installs. It does *work* but in practice,
125
126
it's really hard to get working, and requires a lot of polyfilling and escape-hatches. We bit-the-bullet to use it, but I probably wouldn't recommend it or use it again.
126
127
127
-
Bun works the way NPM does, just faster. It uses its own lockfile format, but node_modules and the package.json look normal.
128
+
Bun works the way NPM does, just faster. It uses its own lockfile format, but node_modules and the package.json look
129
+
normal. A developer with a good understanding of filesystem calls combined with low-level access and a
130
+
fast language makes for a really quick solution, without any fancy tricks.
128
131
129
132
Now, Bun [doesn't have](https://github.com/oven-sh/bun/issues/533) workspace support yet, meaning it won't work for a lot of the big monorepos
130
133
that could really benefit from it (ahem, us). That said, Bun development seems to be moving at a lightning pace. Workspace support is mentioned on the roadmap as of a couple of weeks ago.
@@ -140,7 +143,8 @@ Perhaps some more people will learn about the project that way.
140
143
Bun includes a transpiler for web browsers, to compete with webpack and esbuild. By the way, the parser in Bun is a Zig port
141
144
of esbuild's parser. Neat.
142
145
143
-
It already supports quite an impressive array of file types. Css, SVG, tsx, jsx, ts. They're all supported. Advanced options like CSS in JS appear to work fine.
146
+
It already supports quite an impressive array of file types. Css, Svg, Tsx, Jsx, Ts. They're all supported. Advanced
147
+
options like CSS in JS appear to work fine.
144
148
145
149
Since Bun includes a project scaffolder with a few built in templates, I simply called:
146
150
@@ -156,14 +160,19 @@ which has become a must-have for frontend devs coming from webpack.
156
160
### What's missing from the transpiler?
157
161
A lot of things you probably need for production, unfortunately. Minification is the biggest one I see still on the roadmap that real-world users will need.
158
162
Having a large plugin ecosystem is kind of critical for a bundler to support different file formats. For instance, .vue files and .scss are still on the roadmap.
159
-
Just about everyone and their grandma uses .scss, so that's a deal-breaker.
163
+
Just about everyone and their grandma uses .scss, so that's a deal-breaker. I'm not sure how pluggable Bun's
164
+
bundler is at the moment, but it seems that the focus is mainly on building solutions directing into the framework,
165
+
rather than
166
+
relying on a lot of other Open Source packages for solutions.
160
167
161
168
## Other features - Web server and sqlite client
162
169
163
170
Bun also adds some things you'd usually think of as frameworks to the standard library. Personally, I'm less excited about these more library type features. There are a lot of very good options available in Node for http servers.
164
171
165
172
Bun's webserver looks pretty bare-bones. Express still works fine for most of the community, even if it is a bit behind the times. (They just added promise support this year).
166
173
Bun's server appears to be very similar to a Cloudflare Worker. Maybe Bun's creator will circle back around to more work on the webserver once every other problem in the entire JavaScript world is fixed.
174
+
It's worth noting that clever system calls can make Bun's webserver [twice as fast in some cases](https://twitter.
175
+
com/jarredsumner/status/1506182333459693571), particularly when working with files.
167
176
168
177
As for the new SQLite adapter, I guess the normal way to do sqlite in Node is a bit confusing. Most people combine the older `sqlite3` package with the `sqlite` wrapper to add promise support,
169
178
but it's not that bad. Bun's solution looks a bit cleaner, and I won't even bother checking if it's faster.
@@ -182,15 +191,23 @@ You can probably skip this part if you don't know what Deno is or don't care. Pe
182
191
183
192
[Deno](https://deno.land/), written by the original creator of Node, does claim to resolve some outstanding issues.
184
193
It makes es-modules the default, adds first-party TypeScript support (no need to transpile NPM modules before publishing), and so on. In my opinion
185
-
it introduces other serious shortcomings along the way. The elephant in the room is that Deno has made enough breaking changes to package resolution and syntax that **it isn't
194
+
it introduces other serious shortcomings along the way.
195
+
196
+
The elephant in the room is that Deno has made enough breaking changes to package resolution and syntax that **it isn't
186
197
compatible with the existing NPM ecosystem.** This means that Deno needs to be a completely new ecosystem of libraries. There has been a bit of development with some early library support,
187
-
but I'd say that clout can only get you so much buy-in, especially when so much momentum is involved. There are a few other things in Deno that strike me as half-baked, like the [lack of a package.json](https://deno.land/manual/examples/manage_dependencies),
188
-
both from a module resolution perspective, and also because without a manifest file, there is nowhere to write extensible metadata about your package. Even GoLang has added `pom.xml` for this reason.
198
+
but I'd say that clout can only get you so much buy-in, especially when so much momentum is involved. There are also
199
+
some workarounds, like [CDNs that transpile NPM packages into Deno packages](https://deno.land/[email protected]/npm_nodejs/cdns#esmsh), but that doesn't smell very good to me.
200
+
201
+
There are a
202
+
few other things in Deno that strike me as half-baked, like the [lack of a package.json](https://deno.land/manual/examples/manage_dependencies),
203
+
both from a module resolution perspective, and also because without a manifest file, there is nowhere to write
204
+
extensible metadata about your package. Even GoLang has added `go.mod` for this reason.
189
205
190
-
Also, I just want to point at that the sandboxing / permission system in Deno is the right idea but isn't fine-grained enough. It lives at the top level of the entire project, not at the package level, meaning a big app ends up needing all permissions and you're back to square one.
206
+
Also, I just want to point at that the [sandboxing / permission system](https://deno.land/manual/getting_started/permissions#:~:text=Deno%20is%20secure%20by%20default,or%20a%20runtime%20permission%20prompt.) in Deno is the right idea but isn't
207
+
fine-grained enough. It lives at the top level of the entire project, not at the package level, meaning a big app ends up needing all permissions and you're back to square one.
191
208
As a security company, we were disappointed in its potential to protect large, real world apps from supply-chain attacks. Bun isn't claiming to solve this problem either (yet), I just wanted to vent.
192
209
193
-
I should probably write a whole post about this, but the short answer is:
210
+
I should probably write a whole post about my problems with Deno, but the short answer is:
0 commit comments