Startec

Startec

Bun v0.6.0

Mai 16, às 18:04

·

4 min de leitura

·

0 leituras

We're hiring C/C++ and Zig engineers to build the future of JavaScript! See job listings →This is the biggest release of Bun yet.Bun now has a built-in JavaScript and TypeScript bundler and minifier. Use it...
Bun v0.6.0

We're hiring C/C++ and Zig engineers to build the future of JavaScript! See job listings →

This is the biggest release of Bun yet.

Bun now has a built-in JavaScript and TypeScript bundler and minifier. Use it to bundle frontend apps or bundle your code into a standalone executable.

We've also been busy improving performance and fixing bugs as-per usual: writeFile() gets up to 20% faster on Linux, lots of bug fixes to Node.js compatiblity and Web API compatiblity, support for TypeScript 5.0 syntax, and various fixes to bun install.

Bun's new JavaScript bundler & minifier

The focus of this release is Bun's new JavaScript bundler, but the bundler is just the beginning of a larger project. In the next couple months, we'll be announcing Bun.App — a "super-API" that stitches together Bun's native-speed bundler, HTTP server, and file system router into a cohesive whole.

It can be used using the bun build CLI command or the new Bun.build() JavaScript API.

JavaScript

Bun.build({
 entrypoints: ["./src/index.tsx"],
 outdir: "./build",
 minify: true,
 // ...
});

CLI

bun build ./src/index.tsx --outdir ./build --minify

To learn more, check out our blog post introducing the Bun bundler.

Standalone executables

You can now create standalone executables with bun build.

bun build --compile ./foo.ts

This lets you distribute your app as a single executable file, without requiring users to install Bun.

You can also minify it to improve startup performance for large apps:

bun build --minify --compile ./three.ts
 [32ms] minify -123 KB (estimate)
 [50ms] bundle 456 modules
 [107ms] compile three

This is powered by Bun's new JavaScript bundler and minifier.

import.meta.main

You can now use import.meta.main to check if the current file is the entry point that started bun. This is useful for CLIs to determine if the current file is what started the app.

For example, if you have a file called index.ts:

index.ts

console.log(import.meta.main);

And you run it:

But if you import it:

And run it:

Improvements to bun test

  • bun test now reports time taken to run tests
  • describe.skip has been implemented (thanks to _yogr)

  • expect().toBeEven() and expect().toBeOdd() has been implemented (thanks to will-richards-ii)

Faster fs.writeFile on Linux

Transpiler improvements

This release also introduces many improvements to the transpiler. Here are some of the highlights:

  • Parser support for TypeScript 5.0.
  • Parser support for import attributes.
  • Some npm packages threw "ReferenceError: Cannot access uninitialized variable" errors on import due to a bug with cyclical imports in Bun's transpiler. This has been fixed.
  • Support for // @jsx, // @jsxImportSource, and // @jsxFragment comments.
  • Dead code elimination for unused global constructor function calls like new Set().
  • String template literal concatenation like foo${1}${"2"}${'3'} -> foo123.
  • Parser bugfixes for the deprecated ES5 with statement.

A big thanks to @kzc for many helpful bug reports.

Node.js compatibility

  • tls.Server has basic support (previously, not implemented)
  • fs.promises.constants is now exported correctly (previously, it was missing)
  • node:http's server module now (correctly) accepts a callback argument
  • Timer.refresh() now works as expected
  • Fixed mkdtemp and mkdtempSync errors

Web API compatibility

  • new Request("http://example.com", otherRequest).url would previously return the url of otherRequest instead of "http://example.com". This has been fixed.
  • Bun.file(path).lastModified has been added, which is similar to the File API's lastModified property
  • Supported redirect: "error" in fetch()
  • Fixed fetch.bind, fetch.call, and fetch.apply not working

Changelog

Contributors

And finally, thank you to all the contributors from the community that helped improve Bun this release: @privatenumber, @Lawlzer, @jakeboone02, @zhongweiy, @xHyroM, @rmorey, @marktani, @Kruithne, @will-richards-ii, @simon04, @alexlamsl, @flakey5, @MaanuVazquez, @Plecra, @silversquirl, @beeburrt, @aquapi, @blackmann


Continue lendo

Showmetech

Motorola Razr Plus é o novo dobrável rival do Galaxy Z Flip
Após duas tentativas da Motorola em emplacar — novamente — telefones dobráveis, eis que temos aqui a terceira, e aparentemente bem-vinda, tentativa. Estamos falando do Motorola Razr Plus, um smartphone...

Hoje, às 15:20

DEV

Mentoring for the LGBTQ+ Community
Once unpublished, all posts by chetanan will become hidden and only accessible to themselves. If chetanan is not suspended, they can still re-publish their posts from their dashboard. Note: Once...

Hoje, às 15:13

TabNews

IA: mais um arrependido / Déficit de TI / Apple: acusação grave · NewsletterOficial
Mais um pioneiro da IA se arrepende de seu trabalho: Yoshua Bengio teria priorizado segurança em vez de utilidade se soubesse o ritmo em que a tecnologia evoluiria – ele junta-se a Geoffr...

Hoje, às 14:37

Hacker News

The Analog Thing: Analog Computing for the Future
THE ANALOG THING (THAT) THE ANALOG THING (THAT) is a high-quality, low-cost, open-source, and not-for-profit cutting-edge analog computer. THAT allows modeling dynamic systems with great speed,...

Hoje, às 14:25

TabNews

[DISCUSÃO/OPINIÕES] – Outsourcing! O que, para quem, por que sim, por que não! · dougg
Quero tentar trazer nesta minha primeira publicação, uma mistura de um breve esclarecimento sobre o que são empresas de outsourcing, como elas funcionam e ganham dinheiro, mas também, ven...

Hoje, às 13:58

TabNews

Duvida: JavaScript - Desenvolver uma aplicação que vai ler um arquivo *.json · RafaelMesquita
Bom dia a todos Estou estudando javascript e me deparei com uma dificuldade e preciso de ajuda *Objetivo do estudo: *desenvolver uma aplicação que vai ler um arquivo *.json Conteudo do in...

Hoje, às 13:43

Showmetech

Automatize suas negociações com um robô de criptomoedas
Índice Como o robô de criptomoedas Bitsgap funciona?Qual a vantagem de utilizar um robô de criptomoedas?Bitsgap é confiável? O mercado de trading tem se tornado cada vez mais popular e as possibilidades de...

Hoje, às 13:13

Hacker News

Sketch of a Post-ORM
I’ve been writing a lot of database access code as of late. It’s frustrating that in 2023, my choices are still to either write all of the boilerplate by hand, or hand all database access over to some...

Hoje, às 13:11

Showmetech

14 chuveiros elétricos para o banho dos seus sonhos
Índice Chuveiro ou Ducha?Tipos de chuveiro elétrico9 fatores importantes para considerar na hora de comprar chuveiros elétricosMelhores chuveiros elétricosDuo Shower LorenzettiFit HydraAcqua Storm Ultra...

Hoje, às 11:00

DEV

Learn about the difference between var, let, and const keywords in JavaScript and when to use them.
var, let, and const: What's the Difference in JavaScript? JavaScript is a dynamic and flexible language that allows you to declare variables in different ways. You can use var, let, or const keywords to...

Hoje, às 10:21